| 1 |
dnl Based on |
| 2 |
dnl =========================================================================== |
| 3 |
dnl http://www.gnu.org/software/autoconf-archive/ax_lib_hdf5.html |
| 4 |
dnl =========================================================================== |
| 5 |
dnl but modified heavily to get rid of the extra complexity caused by stuff we |
| 6 |
dnl do not want (parallel, Fortran). And renamed. |
| 7 |
dnl |
| 8 |
dnl SYNOPSIS |
| 9 |
dnl |
| 10 |
dnl GWY_LIB_HDF5() |
| 11 |
dnl |
| 12 |
dnl DESCRIPTION |
| 13 |
dnl |
| 14 |
dnl This macro provides tests of the availability of serial HDF5 library. |
| 15 |
dnl |
| 16 |
dnl The macro adds a --with-hdf5 option accepting one of three values: |
| 17 |
dnl |
| 18 |
dnl no - do not check for the HDF5 library. |
| 19 |
dnl yes - do check for HDF5 library in standard locations. |
| 20 |
dnl path - complete path to the HDF5 helper script h5cc or h5pcc. |
| 21 |
dnl |
| 22 |
dnl If HDF5 is successfully found, this macro calls |
| 23 |
dnl |
| 24 |
dnl AC_SUBST(HDF5_VERSION) |
| 25 |
dnl AC_SUBST(HDF5_CC) |
| 26 |
dnl AC_SUBST(HDF5_CFLAGS) |
| 27 |
dnl AC_SUBST(HDF5_CPPFLAGS) |
| 28 |
dnl AC_SUBST(HDF5_LDFLAGS) |
| 29 |
dnl AC_SUBST(HDF5_LIBS) |
| 30 |
dnl AC_DEFINE(HAVE_HDF5) |
| 31 |
dnl |
| 32 |
dnl and sets with_hdf5="yes". |
| 33 |
dnl |
| 34 |
dnl If HDF5 is disabled or not found, this macros sets with_hdf5="no" and |
| 35 |
dnl with_hdf5_fortran="no". |
| 36 |
dnl |
| 37 |
dnl Your configuration script can test $with_hdf to take any further |
| 38 |
dnl actions. HDF5_{C,CPP,LD}FLAGS may be used when building with C or C++. |
| 39 |
dnl |
| 40 |
dnl To use the macro, one would code one of the following in "configure.ac" |
| 41 |
dnl before AC_OUTPUT: |
| 42 |
dnl |
| 43 |
dnl GWY_LIB_HDF5() |
| 44 |
dnl |
| 45 |
dnl One could test $with_hdf5 for the outcome or display it as follows |
| 46 |
dnl |
| 47 |
dnl echo "HDF5 support: $with_hdf5" |
| 48 |
dnl |
| 49 |
dnl LICENSE |
| 50 |
dnl |
| 51 |
dnl Copyright (c) 2009 Timothy Brown <[email protected]> |
| 52 |
dnl Copyright (c) 2010 Rhys Ulerich <[email protected]> |
| 53 |
dnl |
| 54 |
dnl Copying and distribution of this file, with or without modification, are |
| 55 |
dnl permitted in any medium without royalty provided the copyright notice |
| 56 |
dnl and this notice are preserved. This file is offered as-is, without any |
| 57 |
dnl warranty. |
| 58 |
|
| 59 |
dnl serial 8 |
| 60 |
|
| 61 |
AC_DEFUN([GWY_LIB_HDF5], [ |
| 62 |
|
| 63 |
AC_REQUIRE([AC_PROG_SED]) |
| 64 |
AC_REQUIRE([AC_PROG_AWK]) |
| 65 |
AC_REQUIRE([AC_PROG_GREP]) |
| 66 |
|
| 67 |
dnl Add a default --with-hdf5 configuration option. |
| 68 |
AC_ARG_WITH([hdf5], |
| 69 |
AS_HELP_STRING( |
| 70 |
[--with-hdf5=[yes/no/PATH]],[location of h5cc for HDF5 configuration]), |
| 71 |
[if test "$withval" = "no"; then |
| 72 |
with_hdf5="no" |
| 73 |
elif test "$withval" = "yes"; then |
| 74 |
with_hdf5="yes" |
| 75 |
else |
| 76 |
with_hdf5="yes" |
| 77 |
H5CC="$withval" |
| 78 |
fi], |
| 79 |
[with_hdf5="yes"] |
| 80 |
) |
| 81 |
|
| 82 |
dnl Set defaults to blank |
| 83 |
HDF5_CC="" |
| 84 |
HDF5_VERSION="" |
| 85 |
HDF5_CFLAGS="" |
| 86 |
HDF5_CPPFLAGS="" |
| 87 |
HDF5_LDFLAGS="" |
| 88 |
HDF5_LIBS="" |
| 89 |
|
| 90 |
dnl Try and find hdf5 compiler tools and options. |
| 91 |
if test "$with_hdf5" = "yes"; then |
| 92 |
if test -z "$H5CC"; then |
| 93 |
dnl Check to see if H5CC is in the path. |
| 94 |
dnl Do not look for a native one when cross-compiling. |
| 95 |
AC_PATH_TOOL([H5CC],[h5cc],[]) |
| 96 |
else |
| 97 |
AC_MSG_CHECKING([Using provided HDF5 C wrapper]) |
| 98 |
AC_MSG_RESULT([$H5CC]) |
| 99 |
fi |
| 100 |
AC_MSG_CHECKING([for HDF5 libraries]) |
| 101 |
if test ! -f "$H5CC" || test ! -x "$H5CC"; then |
| 102 |
AC_MSG_RESULT([no]) |
| 103 |
AC_MSG_WARN([Unable to locate HDF5 compilation helper script 'h5cc'. |
| 104 |
Please specify --with-hdf5=<LOCATION> as the full path to h5cc. |
| 105 |
HDF5 support is being disabled (equivalent to --with-hdf5=no).]) |
| 106 |
with_hdf5="no" |
| 107 |
with_hdf5_fortran="no" |
| 108 |
else |
| 109 |
dnl Get the h5cc output |
| 110 |
HDF5_SHOW=$(eval $H5CC -show) |
| 111 |
|
| 112 |
dnl Get the actual compiler used |
| 113 |
HDF5_CC=$(eval $H5CC -show | $AWK '{print $[]1}') |
| 114 |
|
| 115 |
dnl h5cc provides both AM_ and non-AM_ options |
| 116 |
dnl depending on how it was compiled either one of |
| 117 |
dnl these are empty. Lets roll them both into one. |
| 118 |
|
| 119 |
dnl Look for "HDF5 Version: X.Y.Z" |
| 120 |
HDF5_VERSION=$(eval $H5CC -showconfig | $GREP 'HDF5 Version:' | $AWK '{print $[]3}') |
| 121 |
|
| 122 |
AS_VERSION_COMPARE($HDF5_VERSION,$1,[HDF5_VERSION=]) |
| 123 |
if test -n "$HDF5_VERSION"; then |
| 124 |
dnl A ideal situation would be where everything we needed was |
| 125 |
dnl in the AM_* variables. However most systems are not like this |
| 126 |
dnl and seem to have the values in the non-AM variables. |
| 127 |
dnl |
| 128 |
dnl We try the following to find the flags: |
| 129 |
dnl (1) Look for "NAME:" tags |
| 130 |
dnl (2) Look for "H5_NAME:" tags |
| 131 |
dnl (3) Look for "AM_NAME:" tags |
| 132 |
dnl |
| 133 |
HDF5_tmp_flags=$(eval $H5CC -showconfig \ |
| 134 |
| $GREP 'FLAGS\|Extra libraries:' \ |
| 135 |
| $AWK -F: '{printf("%s "), $[]2}' ) |
| 136 |
|
| 137 |
dnl Find the installation directory and append include/ |
| 138 |
HDF5_tmp_inst=$(eval $H5CC -showconfig \ |
| 139 |
| $GREP 'Installation point:' \ |
| 140 |
| $AWK -F: '{print $[]2}' ) |
| 141 |
|
| 142 |
dnl Add this to the CPPFLAGS |
| 143 |
HDF5_CPPFLAGS="-I${HDF5_tmp_inst}/include" |
| 144 |
|
| 145 |
dnl Now sort the flags out based upon their prefixes |
| 146 |
for arg in $HDF5_SHOW $HDF5_tmp_flags ; do |
| 147 |
case "$arg" in |
| 148 |
-I*) echo $HDF5_CPPFLAGS | $GREP -e "$arg" 2>&1 >/dev/null \ |
| 149 |
|| HDF5_CPPFLAGS="$arg $HDF5_CPPFLAGS" |
| 150 |
;; |
| 151 |
-L*) echo $HDF5_LDFLAGS | $GREP -e "$arg" 2>&1 >/dev/null \ |
| 152 |
|| HDF5_LDFLAGS="$arg $HDF5_LDFLAGS" |
| 153 |
;; |
| 154 |
-l*) echo $HDF5_LIBS | $GREP -e "$arg" 2>&1 >/dev/null \ |
| 155 |
|| HDF5_LIBS="$arg $HDF5_LIBS" |
| 156 |
;; |
| 157 |
esac |
| 158 |
done |
| 159 |
|
| 160 |
HDF5_LIBS="$HDF5_LIBS -lhdf5" |
| 161 |
AC_MSG_RESULT([yes (version $[HDF5_VERSION])]) |
| 162 |
|
| 163 |
dnl See if we can compile |
| 164 |
gwy_hdf5_save_CC=$CC |
| 165 |
gwy_hdf5_save_CPPFLAGS=$CPPFLAGS |
| 166 |
gwy_hdf5_save_LIBS=$LIBS |
| 167 |
gwy_hdf5_save_LDFLAGS=$LDFLAGS |
| 168 |
CC=$HDF5_CC |
| 169 |
CPPFLAGS=$HDF5_CPPFLAGS |
| 170 |
LIBS=$HDF5_LIBS |
| 171 |
LDFLAGS=$HDF5_LDFLAGS |
| 172 |
AC_CHECK_HEADER([hdf5.h], [ac_cv_hadf5_h=yes], [ac_cv_hadf5_h=no]) |
| 173 |
dnl Check for H5free_memory which we actually require. |
| 174 |
AC_CHECK_LIB([hdf5], [H5free_memory], [ac_cv_libhdf5=yes], [ac_cv_libhdf5=no]) |
| 175 |
if test "$ac_cv_hadf5_h" = "no" && test "$ac_cv_libhdf5" = "no" ; then |
| 176 |
AC_MSG_WARN([Unable to compile HDF5 test program]) |
| 177 |
fi |
| 178 |
dnl Look for HDF5's high level library |
| 179 |
AC_CHECK_LIB([hdf5_hl],[main],[HDF5_LIBS="$HDF5_LIBS -lhdf5_hl"],[],[]) |
| 180 |
ac_cv_lib_hdf5_hl=ac_cv_lib_hdf5_hl_main |
| 181 |
|
| 182 |
CC=$gwy_hdf5_save_CC |
| 183 |
CPPFLAGS=$gwy_hdf5_save_CPPFLAGS |
| 184 |
LIBS=$gwy_hdf5_save_LIBS |
| 185 |
LDFLAGS=$gwy_hdf5_save_LDFLAGS |
| 186 |
|
| 187 |
AC_SUBST([HDF5_VERSION]) |
| 188 |
AC_SUBST([HDF5_CC]) |
| 189 |
AC_SUBST([HDF5_CFLAGS]) |
| 190 |
AC_SUBST([HDF5_CPPFLAGS]) |
| 191 |
AC_SUBST([HDF5_LDFLAGS]) |
| 192 |
AC_SUBST([HDF5_LIBS]) |
| 193 |
AC_DEFINE([HAVE_HDF5], [1], [Defined if you have HDF5 support]) |
| 194 |
else |
| 195 |
AC_MSG_RESULT([no, or too old]) |
| 196 |
H5CC= |
| 197 |
HDF5_CC= |
| 198 |
with_hdf5=no |
| 199 |
fi |
| 200 |
fi |
| 201 |
fi |
| 202 |
]) |