summaryrefslogtreecommitdiff
path: root/m4/ax_lib_hdf5.m4
diff options
context:
space:
mode:
authorRhys Ulerich <rhys.ulerich@gmail.com>2010-10-20 10:03:39 -0500
committerRhys Ulerich <rhys.ulerich@gmail.com>2010-10-20 10:03:39 -0500
commit82ac11a5e40c32a7c7a30d2868d12e5b6c093d79 (patch)
tree79ed7a7b46fb58986327b54320ba81b4ab80487b /m4/ax_lib_hdf5.m4
parent80651469e9eb553a2cef765bcf1d8e2085fb54d0 (diff)
downloadautoconf-archive-82ac11a5e40c32a7c7a30d2868d12e5b6c093d79.tar.gz
ax_lib_hdf5: improve {C,CPP,LD,F}FLAGS + Fortran
Newer compiler wrapper versions stop providing as much useful information. After attempting to pull everything from them, we now look for -L/-I information in the compiler wrapper's -show output. This greatly improves HDF5_FFLAGS. Also, added HDF5_FLIBS to capture the Fortran-specific link line details.
Diffstat (limited to 'm4/ax_lib_hdf5.m4')
-rw-r--r--m4/ax_lib_hdf5.m4304
1 files changed, 185 insertions, 119 deletions
diff --git a/m4/ax_lib_hdf5.m4 b/m4/ax_lib_hdf5.m4
index 9b92993..c6ef13b 100644
--- a/m4/ax_lib_hdf5.m4
+++ b/m4/ax_lib_hdf5.m4
@@ -28,8 +28,9 @@
# AC_SUBST(HDF5_VERSION)
# AC_SUBST(HDF5_CFLAGS)
# AC_SUBST(HDF5_CPPFLAGS)
-# AC_SUBST(HDF5_FFLAGS)
# AC_SUBST(HDF5_LDFLAGS)
+# AC_SUBST(HDF5_FFLAGS)
+# AC_SUBST(HDF5_FLIBS)
# AC_DEFINE(HAVE_HDF5)
#
# and sets with_hdf5="yes". Additionally, the macro sets
@@ -41,8 +42,9 @@
# If HDF5 is disabled or not found, this macros sets with_hdf5="no" and
# with_hdf5_fortran="no".
#
-# Your configuration script can test $with_hdf to take any further
-# actions.
+# Your configuration script can test $with_hdf to take any further actions.
+# HDF5_{C,CPP,LD}FLAGS may be used when building with C or C++.
+# HDF5_F{FLAGS,LIBS} should be used when building Fortran applications.
#
# To use the macro, one would code one of the following in "configure.ac"
# before AC_OUTPUT:
@@ -70,23 +72,24 @@
# and this notice are preserved. This file is offered as-is, without any
# warranty.
-#serial 3
+#serial 4
AC_DEFUN([AX_LIB_HDF5], [
-dnl TODO Improve H5FC-related checks
AC_REQUIRE([AC_PROG_SED])
+AC_REQUIRE([AC_PROG_AWK])
+AC_REQUIRE([AC_PROG_GREP])
dnl Check first argument is one of the recognized values.
dnl Fail eagerly if is incorrect as this simplifies case statements below.
if test "m4_normalize(m4_default([$1],[]))" = "" ; then
- : # Recognized value
+ : # Recognized value
elif test "m4_normalize(m4_default([$1],[]))" = "serial" ; then
- : # Recognized value
+ : # Recognized value
elif test "m4_normalize(m4_default([$1],[]))" = "parallel"; then
- : # Recognized value
+ : # Recognized value
else
- AC_MSG_ERROR([
+ AC_MSG_ERROR([
Unrecognized value for AX[]_LIB_HDF5 within configure.ac.
If supplied, argument 1 must be either 'serial' or 'parallel'.
])
@@ -116,51 +119,52 @@ dnl Set defaults to blank
HDF5_VERSION=""
HDF5_CFLAGS=""
HDF5_CPPFLAGS=""
-HDF5_FFLAGS=""
HDF5_LDFLAGS=""
+HDF5_FFLAGS=""
+HDF5_FLIBS=""
dnl Try and find hdf5 compiler tools and options.
if test "$with_hdf5" = "yes"; then
- if test -z "$H5CC"; then
- dnl Check to see if H5CC is in the path.
- AC_PATH_PROGS(
- [H5CC],
- m4_case(m4_normalize([$1]),
- [serial], [h5cc],
- [parallel], [h5pcc],
- [h5cc h5pcc]),
- [])
- else
- AC_MSG_CHECKING([Using provided HDF5 C wrapper])
- AC_MSG_RESULT([$H5CC])
- fi
- AC_MSG_CHECKING([for HDF5 libraries])
- if test ! -x "$H5CC"; then
- AC_MSG_RESULT([no])
- AC_MSG_WARN(m4_case(m4_normalize([$1]),
- [serial], [
+ if test -z "$H5CC"; then
+ dnl Check to see if H5CC is in the path.
+ AC_PATH_PROGS(
+ [H5CC],
+ m4_case(m4_normalize([$1]),
+ [serial], [h5cc],
+ [parallel], [h5pcc],
+ [h5cc h5pcc]),
+ [])
+ else
+ AC_MSG_CHECKING([Using provided HDF5 C wrapper])
+ AC_MSG_RESULT([$H5CC])
+ fi
+ AC_MSG_CHECKING([for HDF5 libraries])
+ if test ! -x "$H5CC"; then
+ AC_MSG_RESULT([no])
+ AC_MSG_WARN(m4_case(m4_normalize([$1]),
+ [serial], [
Unable to locate serial HDF5 compilation helper script 'h5cc'.
Please specify --with-hdf5=<LOCATION> as the full path to h5cc.
HDF5 support is being disabled (equivalent to --with-hdf5=no).
-], [parallel],[
+], [parallel],[
Unable to locate parallel HDF5 compilation helper script 'h5pcc'.
Please specify --with-hdf5=<LOCATION> as the full path to h5pcc.
HDF5 support is being disabled (equivalent to --with-hdf5=no).
-], [
+], [
Unable to locate HDF5 compilation helper scripts 'h5cc' or 'h5pcc'.
Please specify --with-hdf5=<LOCATION> as the full path to h5cc or h5pcc.
HDF5 support is being disabled (equivalent to --with-hdf5=no).
]))
- with_hdf5="no"
- with_hdf5_fortran="no"
- else
- dnl h5cc provides both AM_ and non-AM_ options
- dnl depending on how it was compiled either one of
- dnl these are empty. Lets roll them both into one.
+ with_hdf5="no"
+ with_hdf5_fortran="no"
+ else
+ dnl h5cc provides both AM_ and non-AM_ options
+ dnl depending on how it was compiled either one of
+ dnl these are empty. Lets roll them both into one.
- dnl Look for "HDF5 Version: X.Y.Z"
- HDF5_VERSION=$(eval $H5CC -showconfig | grep 'HDF5 Version:' \
- | awk '{print $[]3}')
+ dnl Look for "HDF5 Version: X.Y.Z"
+ HDF5_VERSION=$(eval $H5CC -showconfig | grep 'HDF5 Version:' \
+ | $AWK '{print $[]3}')
dnl A ideal situation would be where everything we needed was
dnl in the AM_* variables. However most systems are not like this
@@ -171,93 +175,155 @@ dnl (1) Look for "NAME:" tags
dnl (2) Look for "NAME/H5_NAME:" tags
dnl (3) Look for "AM_NAME:" tags
dnl
- dnl (1)
- dnl Look for "CFLAGS: "
- HDF5_CFLAGS=$(eval $H5CC -showconfig | grep '\bCFLAGS:' \
- | awk -F: '{print $[]2}')
- dnl Look for "CPPFLAGS"
- HDF5_CPPFLAGS=$(eval $H5CC -showconfig | grep '\bCPPFLAGS:' \
- | awk -F: '{print $[]2}')
- dnl Look for "FFLAGS: "
- HDF5_FFLAGS=$(eval $H5CC -showconfig | grep '\bFFLAGS:' \
- | awk -F: '{print $[]2}')
- dnl Look for "LD_FLAGS"
- HDF5_LDFLAGS=$(eval $H5CC -showconfig | grep '\bLDFLAGS:' \
- | awk -F: '{print $[]2}')
+ dnl (1)
+ dnl Look for "CFLAGS: "
+ HDF5_CFLAGS=$(eval $H5CC -showconfig | grep '\bCFLAGS:' \
+ | $AWK -F: '{print $[]2}')
+ dnl Look for "CPPFLAGS"
+ HDF5_CPPFLAGS=$(eval $H5CC -showconfig | grep '\bCPPFLAGS:' \
+ | $AWK -F: '{print $[]2}')
+ dnl Look for "FFLAGS: "
+ HDF5_FFLAGS=$(eval $H5CC -showconfig | grep '\bFFLAGS:' \
+ | $AWK -F: '{print $[]2}')
+ dnl Look for "LD_FLAGS"
+ HDF5_LDFLAGS=$(eval $H5CC -showconfig | grep '\bLDFLAGS:' \
+ | $AWK -F: '{print $[]2}')
+
+ dnl (2)
+ dnl CFLAGS/H5_CFLAGS: .../....
+ dnl We could use $SED with something like the following
+ dnl 's/CFLAGS.*\/H5_CFLAGS.*[:]\(.*\)\/\(.*\)/\1/p'
+ if test -z "$HDF5_CFLAGS"; then
+ HDF5_CFLAGS=$(eval $H5CC -showconfig \
+ | $SED -n 's/CFLAGS.*[:]\(.*\)\/\(.*\)/\1/p')
+ fi
+ dnl Look for "CPPFLAGS"
+ if test -z "$HDF5_CPPFLAGS"; then
+ HDF5_CPPFLAGS=$(eval $H5CC -showconfig \
+ | $SED -n 's/CPPFLAGS.*[:]\(.*\)\/\(.*\)/\1/p')
+ fi
+ dnl Look for "FFLAGS"
+ if test -z "$HDF5_FFLAGS"; then
+ HDF5_FFLAGS=$(eval $H5CC -showconfig \
+ | $SED -n 's/FFLAGS.*[:]\(.*\)\/\(.*\)/\1/p')
+ fi
+ dnl Look for "LD_FLAGS"
+ if test -z "$HDF5_LDFLAGS"; then
+ HDF5_LDFLAGS=$(eval $H5CC -showconfig \
+ | $SED -n 's/LDFLAGS.*[:]\(.*\)\/\(.*\)/\1/p')
+ fi
+
+ dnl (3)
+ dnl Check to see if these are not empty strings. If so
+ dnl find the AM_ versions and use them.
+ if test -z "$HDF5_CFLAGS"; then
+ HDF5_CFLAGS=$(eval $H5CC -showconfig \
+ | grep 'AM_CFLAGS:' | $AWK -F: '{print $[]2}')
+ fi
+ if test -z "$HDF5_CPPFLAGS"; then
+ HDF5_CPPFLAGS=$(eval $H5CC -showconfig \
+ | grep 'AM_CPPFLAGS:' | $AWK -F: '{print $[]2}')
+ fi
+ dnl No equivalent AM_FFLAGS test in h5cc -showconfig
+ if test -z "$HDF5_LDFLAGS"; then
+ HDF5_LDFLAGS=$(eval $H5CC -showconfig \
+ | grep 'AM_LDFLAGS:' | $AWK -F: '{print $[]2}')
+ fi
+
+ dnl Frustratingly, the necessary -Idir,-Ldir still may not be found!
+ dnl Attempt to pry any more required include directories from wrapper.
+ for arg in `$H5CC -c -show` # Wrapper compile mode
+ do
+ case "$arg" in #(
+ -I*) echo $HDF5_CPPFLAGS | $GREP -e "$arg" 2>&1 >/dev/null \
+ || HDF5_CPPFLAGS="$arg $HDF5_CPPFLAGS"
+ ;;
+ esac
+ done
+ for arg in `$H5CC -show` # Wrapper link mode
+ do
+ case "$arg" in #(
+ -L*) echo $HDF5_LDFLAGS | $GREP -e "$arg" 2>&1 >/dev/null \
+ || HDF5_LDFLAGS="$arg $HDF5_LDFLAGS"
+ ;;
+ esac
+ done
+
+ AC_MSG_RESULT([yes (version $[HDF5_VERSION])])
+
+ dnl Look for any extra libraries also needed to link properly
+ EXTRA_LIBS=$(eval $H5CC -showconfig | grep 'Extra libraries:'\
+ | $AWK -F: '{print $[]2}')
- dnl (2)
- dnl CFLAGS/H5_CFLAGS: .../....
- dnl We could use $SED with something like the following
- dnl 's/CFLAGS.*\/H5_CFLAGS.*[:]\(.*\)\/\(.*\)/\1/p'
- if test -z "$HDF5_CFLAGS"; then
- HDF5_CFLAGS=$(eval $H5CC -showconfig \
- | $SED -n 's/CFLAGS.*[:]\(.*\)\/\(.*\)/\1/p')
- fi
- dnl Look for "CPPFLAGS"
- if test -z "$HDF5_CPPFLAGS"; then
- HDF5_CPPFLAGS=$(eval $H5CC -showconfig \
- | $SED -n 's/CPPFLAGS.*[:]\(.*\)\/\(.*\)/\1/p')
- fi
- dnl Look for "FFLAGS"
- if test -z "$HDF5_FFLAGS"; then
- HDF5_FFLAGS=$(eval $H5CC -showconfig \
- | $SED -n 's/FFLAGS.*[:]\(.*\)\/\(.*\)/\1/p')
- fi
- dnl Look for "LD_FLAGS"
- if test -z "$HDF5_LDFLAGS"; then
- HDF5_LDFLAGS=$(eval $H5CC -showconfig \
- | $SED -n 's/LDFLAGS.*[:]\(.*\)\/\(.*\)/\1/p')
- fi
+ dnl Look for HDF5's high level library
+ ax_lib_hdf5_save_LDFLAGS=$LDFLAGS
+ ax_lib_hdf5_save_LIBS=$LIBS
+ LDFLAGS=$HDF5_LDFLAGS
+ AC_HAVE_LIBRARY([hdf5_hl],
+ [HDF5_LDFLAGS="$HDF5_LDFLAGS -lhdf5_hl"],
+ [],
+ [-lhdf5 $EXTRA_LIBS])
+ LIBS=$ax_lib_hdf5_save_LIBS
+ LDFLAGS=$ax_lib_hdf5_save_LDFLAGS
- dnl (3)
- dnl Check to see if these are not empty strings. If so
- dnl find the AM_ versions and use them.
- if test -z "$HDF5_CFLAGS"; then
- HDF5_CFLAGS=$(eval $H5CC -showconfig \
- | grep 'AM_CFLAGS:' | awk -F: '{print $[]2}')
- fi
- if test -z "$HDF5_CPPFLAGS"; then
- HDF5_CPPFLAGS=$(eval $H5CC -showconfig \
- | grep 'AM_CPPFLAGS:' | awk -F: '{print $[]2}')
- fi
- dnl No equivalent AM_FFLAGS test in h5cc -showconfig
- if test -z "$HDF5_LDFLAGS"; then
- HDF5_LDFLAGS=$(eval $H5CC -showconfig \
- | grep 'AM_LDFLAGS:' | awk -F: '{print $[]2}')
- fi
+ dnl Add the HDF5 library itself
+ HDF5_LDFLAGS="$HDF5_LDFLAGS -lhdf5"
- dnl Add the library
- HDF5_LDFLAGS="$HDF5_LDFLAGS -lhdf5"
+ dnl Add any EXTRA_LIBS afterwards
+ if test "$EXTRA_LIBS"; then
+ HDF5_LDFLAGS="$HDF5_LDFLAGS $EXTRA_LIBS"
+ fi
- dnl Look for and extra libraries we need to link too
- EXTRA_LIBS=$(eval $H5CC -showconfig | grep 'Extra libraries:'\
- | awk -F: '{print $[]2}')
- dnl Add the EXTRA_LIBS
- if test "$EXTRA_LIBS"; then
- HDF5_LDFLAGS="$HDF5_LDFLAGS $EXTRA_LIBS"
- fi
+ AC_MSG_CHECKING([for matching HDF5 Fortran wrapper])
+ dnl Presume HDF5 Fortran wrapper is just a name variant from H5CC
+ H5FC=$(eval echo -n $H5CC | $SED -n 's/cc$/fc/p')
+ if test -x "$H5FC"; then
+ AC_MSG_RESULT([$H5FC])
+ with_hdf5_fortran="yes"
+ AC_SUBST([H5FC])
- AC_MSG_RESULT([yes (version $[HDF5_VERSION])])
+ dnl Again, pry any remaining -Idir/-Ldir from compiler wrapper
+ for arg in `$H5FC -show`
+ do
+ case "$arg" in #(
+ -I*) echo $HDF5_FFLAGS | $GREP -e "$arg" >/dev/null \
+ || HDF5_FFLAGS="$arg $HDF5_FFLAGS"
+ ;;#(
+ -L*) echo $HDF5_FFLAGS | $GREP -e "$arg" >/dev/null \
+ || HDF5_FFLAGS="$arg $HDF5_FFLAGS"
+ dnl HDF5 installs .mod files in with libraries,
+ dnl but some compilers need to find them with -I
+ echo $HDF5_FFLAGS | $GREP -e "-I${arg#-L}" >/dev/null \
+ || HDF5_FFLAGS="-I${arg#-L} $HDF5_FFLAGS"
+ ;;
+ esac
+ done
- AC_MSG_CHECKING([for matching HDF5 Fortran wrapper])
- dnl Presume HDF5 Fortran wrapper is just a name variant from H5CC
- H5FC=$(eval echo -n $H5CC | $SED -n 's/cc$/fc/p')
- if test -x "$H5FC"; then
- AC_MSG_RESULT([$H5FC])
- with_hdf5_fortran="yes"
- AC_SUBST([H5FC])
- else
- AC_MSG_RESULT([no])
- with_hdf5_fortran="no"
- fi
+ dnl Make Fortran link line by inserting Fortran libraries
+ for arg in $HDF5_LDFLAGS
+ do
+ case "$arg" in #(
+ -lhdf5_hl) HDF5_FLIBS="$HDF5_FLIBS -lhdf5hl_fortran $arg"
+ ;; #(
+ -lhdf5) HDF5_FLIBS="$HDF5_FLIBS -lhdf5_fortran $arg"
+ ;; #(
+ *) HDF5_FLIBS="$HDF5_FLIBS $arg"
+ ;;
+ esac
+ done
+ else
+ AC_MSG_RESULT([no])
+ with_hdf5_fortran="no"
+ fi
- fi
- AC_SUBST([HDF5_VERSION])
- AC_SUBST([HDF5_CFLAGS])
- AC_SUBST([HDF5_CPPFLAGS])
- AC_SUBST([HDF5_FFLAGS])
- AC_SUBST([HDF5_LDFLAGS])
- AC_DEFINE([HAVE_HDF5], [1], [Defined if you have HDF5 support])
+ fi
+ AC_SUBST([HDF5_VERSION])
+ AC_SUBST([HDF5_CFLAGS])
+ AC_SUBST([HDF5_CPPFLAGS])
+ AC_SUBST([HDF5_LDFLAGS])
+ AC_SUBST([HDF5_FFLAGS])
+ AC_SUBST([HDF5_FLIBS])
+ AC_DEFINE([HAVE_HDF5], [1], [Defined if you have HDF5 support])
fi
])