From f272d27863fb14c6965b9cf7d5eb49f7f9038fe5 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 5 May 2021 12:17:15 +0200 Subject: [PATCH] pkgconfig --- Makefile.in | 1 + configure.ac | 39 +++++++++++++++++++++++++++++---------- src/Makefile.in | 12 +++++++++--- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/Makefile.in b/Makefile.in index 68ef166..a4ace5d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -75,6 +75,7 @@ $(distdir): FORCE cp $(srcdir)/tests/test.f90 $(distdir)/tests cp $(srcdir)/tests/Makefile.in $(distdir)/tests cp $(srcdir)/Makefile.in $(distdir) + cp $(srcdir)/trexio.pc.in $(distdir) cp $(srcdir)/LICENSE $(distdir) diff --git a/configure.ac b/configure.ac index d10f2be..1244fed 100644 --- a/configure.ac +++ b/configure.ac @@ -17,6 +17,7 @@ fi AC_CONFIG_SRCDIR([src/Makefile.in]) AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_FILES([trexio.pc]) PKG_PROG_PKG_CONFIG() # Checks for programs. AC_PROG_CC @@ -59,17 +60,21 @@ AC_MSG_ERROR([ fi AC_ARG_WITH([hdf5], - AS_HELP_STRING([--with-hdf5], + AS_HELP_STRING([--with-hdf5], [Include HDF5 functionality @<:@default: yes@:>@])], [hdf5=${withval}], [hdf5=yes]) -if test "x${hdf5}" = xno; then - AC_MSG_WARN([ - ------------------------------------------ - Configuring with the HDF5 library is - recommended to build efficient TREXIO. - ------------------------------------------]) +if test "x${hdf5}" = xno; then + AC_MSG_WARN([ + ------------------------------------------ + Configuring with the HDF5 library is + recommended to build efficient TREXIO. + ------------------------------------------]) + PKG_HDF5="" + PKG_HDF5_LIBS="" + PKG_HDF5_CFLAGS="" + elif test "x${hdf5}" = xyes; then # Check if HDF5 is already configured (e.g. after calling `module load hdf5-`) @@ -85,17 +90,24 @@ elif test "x${hdf5}" = xyes; then CFLAGS="${HDF5_CFLAGS} ${CFLAGS}" FCFLAGS="${HDF5_CFLAGS} ${FCFLAGS}" LIBS="${HDF5_LIBS} -lhdf5_hl ${LIBS}" + PKG_HDF5="hdf5" + PKG_HDF5_LIBS="" + PKG_HDF5_CFLAGS="" + else + PKG_HDF5="" + PKG_HDF5_LIBS="${HDF5_LIBS} -lhdf5_hl" + PKG_HDF5_CFLAGS="${HDF5_CFLAGS}" fi else if test "x${hdf5}" = x; then - AC_MSG_ERROR([ + AC_MSG_ERROR([ ------------------------------------------ The path to HDF5 library is required. Maybe you forgot to pass --with-hdf5="/your/path/" to configure script. Stopping... - ------------------------------------------]) + ------------------------------------------]) fi CPPFLAGS="-I${hdf5}/include ${CPPFLAGS}" @@ -107,7 +119,14 @@ else AC_CHECK_HEADERS([hdf5.h]) AC_CHECK_LIB([hdf5], [H5open], [], [have_hdf5=no]) + PKG_HDF5="" + PKG_HDF5_LIBS="-L${hdf5} -lhdf5_hl" + PKG_HDF5_CFLAGS="-I${hdf5}/include" fi +AC_SUBST([PKG_HDF5]) +AC_SUBST([PKG_HDF5_LIBS]) +AC_SUBST([PKG_HDF5_CFLAGS]) + # add -fPIC if not present in CFLAGS, necessary to compile TREXIO # TODO: replace with AM_CFLAGS for appropriate targer once Automake is introduced @@ -116,7 +135,7 @@ case "${CFLAGS}" in ;; *) AC_MSG_WARN([ - ------------------------------------------ + ------------------------------------------ Adding -fPIC option to CFLAGS. This is necessary to build TREXIO. ------------------------------------------]) diff --git a/src/Makefile.in b/src/Makefile.in index 67eed1b..32ccb74 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -12,6 +12,8 @@ includedir = @includedir@ docdir = @docdir@ htmldir = @htmldir@ libdir = @libdir@ +pkgconfigdir= $(libdir)/pkgconfig + # Supplementary exec_prefix = @exec_prefix@ libexecdir = @libexecdir@ @@ -74,7 +76,7 @@ HEADER_FILES= $(trexio_h) trexio_text.h trexio_hdf5.h trexio_s.h all: $(libtrexio) fortran -$(libtrexio): $(OBJECT_FILES) $(HEADER_FILES) +$(libtrexio): $(OBJECT_FILES) $(HEADER_FILES) $(CC) -shared $(OBJECT_FILES) -o $(libtrexio) @@ -99,20 +101,24 @@ cppcheck.out: $(HEADER_FILES) $(SOURCE_FILES) # $(DESTDIR) is needed for future support of package managers # install should avoid build target due to possible conflict when prefix overriden install: - $(INSTALL) -d $(DESTDIR)$(libdir) $(DESTDIR)$(includedir) + $(INSTALL) -d $(DESTDIR)$(libdir) + $(INSTALL) -d $(DESTDIR)$(includedir) + $(INSTALL) -d $(DESTDIR)$(pkgconfigdir) cp $(libtrexio) $(DESTDIR)$(libdir) cp $(trexio_h) $(DESTDIR)$(includedir) cp $(trexio_f) $(DESTDIR)$(includedir) + cp ../trexio.pc $(DESTDIR)$(pkgconfigdir) uninstall: -$(RM) -- $(DESTDIR)$(libdir)/$(libtrexio_so) -$(RM) -- $(DESTDIR)$(includedir)/$(trexio_h_file) -$(RM) -- $(DESTDIR)$(includedir)/$(trexio_f_file) + -$(RM) -- $(DESTDIR)$(pkgconfigdir)/trexio.pc clean: - $(RM) -- *.o $(libtrexio) trexio.mod + $(RM) -- *.o $(libtrexio) trexio.mod maintainer-clean: