Commit 2b37ce08 authored by Giovanni La Mura's avatar Giovanni La Mura
Browse files

Try using pkg-config to assist in system configuration detection

parent 2a29729a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -463,6 +463,7 @@ ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
ENABLE_ILP64 = @ENABLE_ILP64@
ETAGS = @ETAGS@
EXEEXT = @EXEEXT@
F77 = @F77@
+216 −58
Original line number Diff line number Diff line
@@ -668,6 +668,7 @@ OMPFLAGS
OFFLOADFLAGS
BUILDFORTRAN_FALSE
BUILDFORTRAN_TRUE
ENABLE_ILP64
HDF5_LDFLAGS
CXXCPP
LT_SYS_LIBRARY_PATH
@@ -812,6 +813,7 @@ with_aix_soname
with_gnu_ld
with_sysroot
enable_libtool_lock
enable_ilp64
enable_fortran
enable_offload
enable_openmp
@@ -1477,6 +1479,7 @@ Optional Features:
  --enable-fast-install[=PKGS]
                          optimize for fast installation [default=yes]
  --disable-libtool-lock  avoid locking (might break parallel builds)
  --enable-ilp64          enable 64-bit indexing [default=yes]
  --enable-fortran        enable legacy FORTRAN compilation [default=auto]
  --enable-offload        enable target offloading (requires g++ version >=
                          13) [default=auto]
@@ -24829,6 +24832,30 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
# Environment setup
    if test "x$HDF5_INCLUDE$HDF5_LIB" = "x"; then
      pkg-config --version > /dev/null
      use_pkg_config=$?
      if test "x$use_pkg_config" = "x0"; then
        declare -a pkg_array=$(pkg-config --list-all | grep hdf5-serial)
        for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep hdf5-serial
        result=$?
        if test "x$result" = "x0"; then
          cflags=$(pkg-config --cflags-only-I hdf5-serial)
          export HDF5_INCLUDE=$(echo "${cflags:2}")
          ldflags=$(pkg-config --libs-only-L hdf5-serial)
          export HDF5_LIB=$(echo "${ldflags:2}")
        else
          declare -a pkg_array=$(pkg-config --list-all | grep hdf5)
          for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep hdf5
          result=$?
          if test "x$result" = "x0"; then
            cflags=$(pkg-config --cflags-only-I hdf5)
            export HDF5_INCLUDE=$(echo "${cflags:2}")
            ldflags=$(pkg-config --libs-only-L hdf5)
            export HDF5_LIB=$(echo "${ldflags:2}")
          fi
        fi
      else
        export -p | grep HDF5_ROOT > /dev/null
        result=$?
        if test "x$result" = "x0"; then
@@ -24855,16 +24882,12 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
        if test "x$HDF5_LIB" = "x"; then
          export HDF5_LIB="/usr/lib/x86_64-linux-gnu/hdf5/serial"
        fi
      fi
    fi
# Check for required headers
# AC_CHECK_HEADER(
#  [${HDF5_INCLUDE}/hdf5.h],
#  ,
#  AC_MSG_ERROR([Could not find HDF5 headers!]),
# )
if test -f ${HDF5_INCLUDE}/hdf5.h
if test "x${HDF5_INCLUDE}" != "x"
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: HDF5 headers found in ${HDF5_INCLUDE}" >&5
printf "%s\n" "$as_me: HDF5 headers found in ${HDF5_INCLUDE}" >&6;}
@@ -24873,6 +24896,15 @@ else case e in #(
 ;;
esac
fi
if test "x${HDF5_LIB}" != "x"
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: HDF5 libraries found in ${HDF5_LIB}" >&5
printf "%s\n" "$as_me: HDF5 libraries found in ${HDF5_LIB}" >&6;}
else case e in #(
  e) as_fn_error $? "HDF5 libraries not found!" "$LINENO" 5
 ;;
esac
fi
# Check for required libraries
@@ -24897,12 +24929,34 @@ then :
  HDF5_LDFLAGS="-L${HDF5_LIB} -lhdf5"
else case e in #(
  e) as_fn_error $? "\"HDF5 library not found!\"" "$LINENO" 5
  e) as_fn_error $? "\"HDF5 library not working!\"" "$LINENO" 5
 ;;
esac
fi
# Configure the optional features
# Check whether --enable-ilp64 was given.
if test ${enable_ilp64+y}
then :
  enableval=$enable_ilp64;
    if test "x$enableval" = "xno"; then
      ENABLE_ILP64=""
    else
      ENABLE_ILP64="yes"
    fi
else case e in #(
  e)
    ENABLE_ILP64="yes"
 ;;
esac
fi
# Check whether --enable-fortran was given.
if test ${enable_fortran+y}
then :
@@ -25114,15 +25168,67 @@ then :
    else
    if test "x$ENABLE_ILP64" = "xyes"; then
      # 64-bit indices are enabled
      LAPACK_ILP64_FLAG="-DLAPACK_ILP64 -DUSE_ILP64"
      LAPACK_ILP64_LDSPEC="_ilp64"
      LAPACK_LDSPEC="64"
      MKL_BUILD="mkl-dynamic-ilp64-gomp"
    else
      # 64-bit indices are disabled
      LAPACK_ILP64_FLAG=""
      LAPACK_ILP64_LDSPEC="_lp64"
      LAPACK_LDSPEC=""
      MKL_BUILD="mkl-dynamic-lp64-gomp"
    fi # end of 64-bit decision tree
    pkg-config --version > /dev/null
    use_pkg_config=$?
    if test "x$use_pkg_config" = "x0"; then
      # pkg-config is available
      declare -a pkg_array=$(pkg-config --list-all | grep ${MKL_BUILD})
      for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep ${MKL_BUILD}
      result=$?
      if test "x$result" = "x0"; then
        # MKL was found
        MKL_INCLUDE=$(pkg-config --cflags-only-I ${MKL_BUILD})
        export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL ${LAPACK_ILP64_FLAG} ${MKL_INCLUDE}"
        export LAPACKLDFLAGS=$(pkg-config --libs ${MKL_BUILD})
      else
        # MKL was not found, so configuration searches for LAPACKe
        declare -a pkg_array=$(pkg-config --list-all | grep lapacke${LAPACK_LDSPEC})
        for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep lapacke${LAPACK_LDSPEC}
        result=$?
        if test "x$result" = "x0"; then
          # LAPACKe was found
          LAPACK_INCLUDE=$(pkg-config --cflags-only-I lapacke${LAPACK_LDSPEC})
          export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL ${LAPACK_ILP64_FLAG} ${LAPACK_INCLUDE}"
          export LAPACKLDFLAGS=$(pkg-config --libs lapacke${LAPACK_LDSPEC})
        fi # end of LAPACKe decision tree
        if test "x${LAPACKFLAGS}${LAPACKLDFLAGS}" = "x"; then
          # LAPACKe was not found, so configuration searches for LAPACK
          declare -a pkg_array=$(pkg-config --list-all | grep lapack${LAPACK_LDSPEC})
          for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep lapack${LAPACK_LDSPEC}
          result=$?
          if test "x$result" = "x0"; then
            # LAPACK was found
            LAPACK_INCLUDE=$(pkg-config --cflags-only-I lapack${LAPACK_LDSPEC})
            export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL ${LAPACK_ILP64_FLAG} ${LAPACK_INCLUDE}"
            export LAPACKLDFLAGS=$(pkg-config --libs lapack${LAPACK_LDSPEC})
          fi # end of LAPACK decision tree
        fi # end of LAPACKe decision tree
      fi # end of MKL decision tree
    else
      # pkg-config is not available
      export -p | grep MKL > /dev/null
      MKL_DEF=$?
      if test "x$MKL_DEF" = "x0"; then
      export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL -DLAPACK_ILP64 -DUSE_ILP64 -I{MKLROOT}/include"
      export LAPACKLDFLAGS="-L${MKLROOT}/lib -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl"
        export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL ${LAPACK_ILP64_FLAG} -I{MKLROOT}/include"
        export LAPACKLDFLAGS="-L${MKLROOT}/lib -Wl,--no-as-needed -lmkl_intel${LAPACK_ILP64_LDSPEC} -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl"
      else
        if test -f /usr/include/lapacke.h; then
        export LAPACKFLAGS="-DUSE_LAPACK -DLAPACK_ILP64 -DUSE_ILP64"
	export LAPACKLDFLAGS="-llapacke64"
          export LAPACKFLAGS="-DUSE_LAPACK ${LAPACK_ILP64_FLAG}"
          export LAPACKLDFLAGS="-llapacke${LAPACK_LDSPEC}"
        fi
      fi
    fi
@@ -25146,15 +25252,67 @@ fi
else case e in #(
  e)
    if test "x$ENABLE_ILP64" = "xyes"; then
      # 64-bit indices are enabled
      LAPACK_ILP64_FLAG="-DLAPACK_ILP64 -DUSE_ILP64"
      LAPACK_ILP64_LDSPEC="_ilp64"
      LAPACK_LDSPEC="64"
      MKL_BUILD="mkl-dynamic-ilp64-gomp"
    else
      # 64-bit indices are disabled
      LAPACK_ILP64_FLAG=""
      LAPACK_ILP64_LDSPEC="_lp64"
      LAPACK_LDSPEC=""
      MKL_BUILD="mkl-dynamic-lp64-gomp"
    fi # end of 64-bit decision tree
    pkg-config --version > /dev/null
    use_pkg_config=$?
    if test "x$use_pkg_config" = "x0"; then
      # pkg-config is available
      declare -a pkg_array=$(pkg-config --list-all | grep ${MKL_BUILD})
      for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep ${MKL_BUILD}
      result=$?
      if test "x$result" = "x0"; then
        # MKL was found
        MKL_INCLUDE=$(pkg-config --cflags-only-I ${MKL_BUILD})
        export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL ${LAPACK_ILP64_FLAG} ${MKL_INCLUDE}"
        export LAPACKLDFLAGS=$(pkg-config --libs ${MKL_BUILD})
      else
        # MKL was not found, so configuration searches for LAPACKe
        declare -a pkg_array=$(pkg-config --list-all | grep lapacke${LAPACK_LDSPEC})
        for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep lapacke${LAPACK_LDSPEC}
        result=$?
        if test "x$result" = "x0"; then
          # LAPACKe was found
          LAPACK_INCLUDE=$(pkg-config --cflags-only-I lapacke${LAPACK_LDSPEC})
          export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL ${LAPACK_ILP64_FLAG} ${LAPACK_INCLUDE}"
          export LAPACKLDFLAGS=$(pkg-config --libs lapacke${LAPACK_LDSPEC})
        fi # end of LAPACKe decision tree
        if test "x${LAPACKFLAGS}${LAPACKLDFLAGS}" = "x"; then
          # LAPACKe was not found, so configuration searches for LAPACK
          declare -a pkg_array=$(pkg-config --list-all | grep lapack${LAPACK_LDSPEC})
          for i in "${pkg_array[@]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep lapack${LAPACK_LDSPEC}
          result=$?
          if test "x$result" = "x0"; then
            # LAPACK was found
            LAPACK_INCLUDE=$(pkg-config --cflags-only-I lapack${LAPACK_LDSPEC})
            export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL ${LAPACK_ILP64_FLAG} ${LAPACK_INCLUDE}"
            export LAPACKLDFLAGS=$(pkg-config --libs lapack${LAPACK_LDSPEC})
          fi # end of LAPACK decision tree
        fi # end of LAPACKe decision tree
      fi # end of MKL decision tree
    else
      # pkg-config is not available
      export -p | grep MKL > /dev/null
      MKL_DEF=$?
      if test "x$MKL_DEF" = "x0"; then
      export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL -DLAPACK_ILP64 -DUSE_ILP64 -I{MKLROOT}/include"
      export LAPACKLDFLAGS="-L${MKLROOT}/lib -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl"
        export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL ${LAPACK_ILP64_FLAG} -I{MKLROOT}/include"
        export LAPACKLDFLAGS="-L${MKLROOT}/lib -Wl,--no-as-needed -lmkl_intel${LAPACK_ILP64_LDSPEC} -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl"
      else
        if test -f /usr/include/lapacke.h; then
        export LAPACKFLAGS="-DUSE_LAPACK -DLAPACK_ILP64 -DUSE_ILP64"
	export LAPACKLDFLAGS="-llapacke64"
          export LAPACKFLAGS="-DUSE_LAPACK ${LAPACK_ILP64_FLAG}"
          export LAPACKLDFLAGS="-llapacke${LAPACK_LDSPEC}"
        fi
      fi
    fi
+148 −56
Original line number Diff line number Diff line
# CAPABILITY TESTING MACROS
m4_define(
  [M4_HDF5_LIB],
  [
    cat > nptm_test_hdf5.cpp <<EOF
#include <hdf5.h>
int main(int argc, char **argv) {
  hid_t file_id = 0;
  herr_t status = H5Iis_valid(file_id);
  return (int)status;
}
EOF
    $CXX -o nptm_test_hdf5 nptm_test_hdf5.cpp -I$HDF5_INCLUDE -L$HDF5_LIB -lhdf5 > /dev/null 2>>error.log
    export TEST_HDF5_LIB=$?
    rm nptm_test_hdf5.cpp
    if test "x$TEST_HDF5_LIB" = "x0"; then
      rm nptm_test_hdf5
    fi
  ]
)

m4_define(
  [M4_DETECT_HDF5],
  [
    if test "x$HDF5_INCLUDE$HDF5_LIB" = "x"; then
      pkg-config --version > /dev/null
      use_pkg_config=$?
      if test "x$use_pkg_config" = "x0"; then
        declare -a pkg_array=$(pkg-config --list-all | grep hdf5-serial)
        for i in "${pkg_array[[@]]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep hdf5-serial
        result=$?
        if test "x$result" = "x0"; then
          cflags=$(pkg-config --cflags-only-I hdf5-serial)
          export HDF5_INCLUDE=$(echo "${cflags:2}")
          ldflags=$(pkg-config --libs-only-L hdf5-serial)
          export HDF5_LIB=$(echo "${ldflags:2}")
        else
          declare -a pkg_array=$(pkg-config --list-all | grep hdf5)
          for i in "${pkg_array[[@]]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep hdf5
          result=$?
          if test "x$result" = "x0"; then
            cflags=$(pkg-config --cflags-only-I hdf5)
            export HDF5_INCLUDE=$(echo "${cflags:2}")
            ldflags=$(pkg-config --libs-only-L hdf5)
            export HDF5_LIB=$(echo "${ldflags:2}")
          fi
        fi
      else
        export -p | grep HDF5_ROOT > /dev/null
        result=$?
        if test "x$result" = "x0"; then
@@ -48,21 +52,95 @@ m4_define(
        if test "x$HDF5_LIB" = "x"; then
          export HDF5_LIB="/usr/lib/x86_64-linux-gnu/hdf5/serial"
        fi
      fi
    fi
  ]
)

m4_define(
  [M4_HDF5_LIB],
  [
    cat > nptm_test_hdf5.cpp <<EOF
#include <hdf5.h>
int main(int argc, char **argv) {
  hid_t file_id = 0;
  herr_t status = H5Iis_valid(file_id);
  return (int)status;
}
EOF
    $CXX -o nptm_test_hdf5 nptm_test_hdf5.cpp -I$HDF5_INCLUDE -L$HDF5_LIB -lhdf5 > /dev/null 2>>error.log
    export TEST_HDF5_LIB=$?
    rm nptm_test_hdf5.cpp
    if test "x$TEST_HDF5_LIB" = "x0"; then
      rm nptm_test_hdf5
    fi
  ]
)

m4_define(
  [M4_DETECT_LAPACK],
  [
    if test "x$ENABLE_ILP64" = "xyes"; then
      # 64-bit indices are enabled
      LAPACK_ILP64_FLAG="-DLAPACK_ILP64 -DUSE_ILP64"
      LAPACK_ILP64_LDSPEC="_ilp64"
      LAPACK_LDSPEC="64"
      MKL_BUILD="mkl-dynamic-ilp64-gomp"
    else
      # 64-bit indices are disabled
      LAPACK_ILP64_FLAG=""
      LAPACK_ILP64_LDSPEC="_lp64"
      LAPACK_LDSPEC=""
      MKL_BUILD="mkl-dynamic-lp64-gomp"
    fi # end of 64-bit decision tree
    pkg-config --version > /dev/null
    use_pkg_config=$?
    if test "x$use_pkg_config" = "x0"; then
      # pkg-config is available
      declare -a pkg_array=$(pkg-config --list-all | grep ${MKL_BUILD})
      for i in "${pkg_array[[@]]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep ${MKL_BUILD}
      result=$?
      if test "x$result" = "x0"; then
        # MKL was found
        MKL_INCLUDE=$(pkg-config --cflags-only-I ${MKL_BUILD})
        export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL ${LAPACK_ILP64_FLAG} ${MKL_INCLUDE}"
        export LAPACKLDFLAGS=$(pkg-config --libs ${MKL_BUILD})
      else
        # MKL was not found, so configuration searches for LAPACKe
        declare -a pkg_array=$(pkg-config --list-all | grep lapacke${LAPACK_LDSPEC})
        for i in "${pkg_array[[@]]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep lapacke${LAPACK_LDSPEC}
        result=$?
        if test "x$result" = "x0"; then
          # LAPACKe was found
          LAPACK_INCLUDE=$(pkg-config --cflags-only-I lapacke${LAPACK_LDSPEC})
          export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL ${LAPACK_ILP64_FLAG} ${LAPACK_INCLUDE}"
          export LAPACKLDFLAGS=$(pkg-config --libs lapacke${LAPACK_LDSPEC})
        fi # end of LAPACKe decision tree
        if test "x${LAPACKFLAGS}${LAPACKLDFLAGS}" = "x"; then
          # LAPACKe was not found, so configuration searches for LAPACK
          declare -a pkg_array=$(pkg-config --list-all | grep lapack${LAPACK_LDSPEC})
          for i in "${pkg_array[[@]]}"; do echo "$i" | cut --delimiter=" " -f1; done | grep lapack${LAPACK_LDSPEC}
          result=$?
          if test "x$result" = "x0"; then
            # LAPACK was found
            LAPACK_INCLUDE=$(pkg-config --cflags-only-I lapack${LAPACK_LDSPEC})
            export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL ${LAPACK_ILP64_FLAG} ${LAPACK_INCLUDE}"
            export LAPACKLDFLAGS=$(pkg-config --libs lapack${LAPACK_LDSPEC})
          fi # end of LAPACK decision tree
        fi # end of LAPACKe decision tree
      fi # end of MKL decision tree
    else
      # pkg-config is not available
      export -p | grep MKL > /dev/null
      MKL_DEF=$?
      if test "x$MKL_DEF" = "x0"; then
      export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL -DLAPACK_ILP64 -DUSE_ILP64 -I{MKLROOT}/include"
      export LAPACKLDFLAGS="-L${MKLROOT}/lib -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl"
        export LAPACKFLAGS="-DUSE_LAPACK -DUSE_MKL ${LAPACK_ILP64_FLAG} -I{MKLROOT}/include"
        export LAPACKLDFLAGS="-L${MKLROOT}/lib -Wl,--no-as-needed -lmkl_intel${LAPACK_ILP64_LDSPEC} -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl"
      else
        if test -f /usr/include/lapacke.h; then
        export LAPACKFLAGS="-DUSE_LAPACK -DLAPACK_ILP64 -DUSE_ILP64"
	export LAPACKLDFLAGS="-llapacke64"
          export LAPACKFLAGS="-DUSE_LAPACK ${LAPACK_ILP64_FLAG}"
          export LAPACKLDFLAGS="-llapacke${LAPACK_LDSPEC}"
        fi
      fi
    fi
  ]
@@ -253,27 +331,41 @@ LT_INIT
# Environment setup
M4_DETECT_HDF5

# Check for required headers
# AC_CHECK_HEADER(
#  [${HDF5_INCLUDE}/hdf5.h],
#  ,
#  AC_MSG_ERROR([Could not find HDF5 headers!]),
# )
AS_IF(
  [test -f ${HDF5_INCLUDE}/hdf5.h],
  [test "x${HDF5_INCLUDE}" != "x"],
  [AC_MSG_NOTICE([HDF5 headers found in ${HDF5_INCLUDE}])],
  [AC_MSG_ERROR([HDF5 headers not found!])]
)
AS_IF(
  [test "x${HDF5_LIB}" != "x"],
  [AC_MSG_NOTICE([HDF5 libraries found in ${HDF5_LIB}])],
  [AC_MSG_ERROR([HDF5 libraries not found!])]
)

# Check for required libraries
M4_HDF5_LIB
AS_IF(
  [test "x$TEST_HDF5_LIB" = "x0"],
  [AC_SUBST([HDF5_LDFLAGS], ["-L${HDF5_LIB} -lhdf5"])],
  [AC_MSG_ERROR(["HDF5 library not found!"])]
  [AC_MSG_ERROR(["HDF5 library not working!"])]
)

# Configure the optional features
AC_ARG_ENABLE(
  [ilp64],
  [AS_HELP_STRING([--enable-ilp64], [enable 64-bit indexing [default=yes]])],
  [
    if test "x$enableval" = "xno"; then
      AC_SUBST([ENABLE_ILP64], [""])
    else
      AC_SUBST([ENABLE_ILP64], ["yes"])
    fi
  ],
  [
    AC_SUBST([ENABLE_ILP64], ["yes"])
  ]
)

AC_ARG_ENABLE(
  [fortran],
  [AS_HELP_STRING([--enable-fortran], [enable legacy FORTRAN compilation [default=auto]])],