Debian Codegraph @

etc/config/m4/ax_lib_hdf5.m4

raw ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 # ===========================================================================
2 # https://www.gnu.org/software/autoconf-archive/ax_lib_hdf5.html
3 # ===========================================================================
4 #
5 # SYNOPSIS
6 #
7 # AX_LIB_HDF5([serial/parallel])
8 #
9 # DESCRIPTION
10 #
11 # This macro provides tests of the availability of HDF5 library.
12 #
13 # The optional macro argument should be either 'serial' or 'parallel'. The
14 # former only looks for serial HDF5 installations via h5cc. The latter
15 # only looks for parallel HDF5 installations via h5pcc. If the optional
16 # argument is omitted, serial installations will be preferred over
17 # parallel ones.
18 #
19 # The macro adds a --with-hdf5 option accepting one of three values:
20 #
21 # no - do not check for the HDF5 library.
22 # yes - do check for HDF5 library in standard locations.
23 # path - complete path to the HDF5 helper script h5cc or h5pcc.
24 #
25 # If HDF5 is successfully found, this macro calls
26 #
27 # AC_SUBST(HDF5_VERSION)
28 # AC_SUBST(HDF5_CC)
29 # AC_SUBST(HDF5_CFLAGS)
30 # AC_SUBST(HDF5_CPPFLAGS)
31 # AC_SUBST(HDF5_LDFLAGS)
32 # AC_SUBST(HDF5_LIBS)
33 # AC_SUBST(HDF5_FC)
34 # AC_SUBST(HDF5_FFLAGS)
35 # AC_SUBST(HDF5_FLIBS)
36 # AC_SUBST(HDF5_TYPE)
37 # AC_DEFINE(HAVE_HDF5)
38 #
39 # and sets with_hdf5="yes". Additionally, the macro sets
40 # with_hdf5_fortran="yes" if a matching Fortran wrapper script is found.
41 # Note that Autoconf's Fortran support is not used to perform this check.
42 # H5CC and H5FC will contain the appropriate serial or parallel HDF5
43 # wrapper script locations.
44 #
45 # If HDF5 is disabled or not found, this macros sets with_hdf5="no" and
46 # with_hdf5_fortran="no".
47 #
48 # Your configuration script can test $with_hdf to take any further
49 # actions. HDF5_{C,CPP,LD}FLAGS may be used when building with C or C++.
50 # HDF5_F{FLAGS,LIBS} should be used when building Fortran applications.
51 #
52 # To use the macro, one would code one of the following in "configure.ac"
53 # before AC_OUTPUT:
54 #
55 # 1) dnl Check for HDF5 support
56 # AX_LIB_HDF5()
57 #
58 # 2) dnl Check for serial HDF5 support
59 # AX_LIB_HDF5([serial])
60 #
61 # 3) dnl Check for parallel HDF5 support
62 # AX_LIB_HDF5([parallel])
63 #
64 # One could test $with_hdf5 for the outcome or display it as follows
65 #
66 # echo "HDF5 support: $with_hdf5"
67 #
68 # You could also for example, override the default CC in "configure.ac" to
69 # enforce compilation with the compiler that HDF5 uses:
70 #
71 # AX_LIB_HDF5([parallel])
72 # if test "$with_hdf5" = "yes"; then
73 # CC="$HDF5_CC"
74 # else
75 # AC_MSG_ERROR([Unable to find HDF5, we need parallel HDF5.])
76 # fi
77 #
78 # The HDF5_TYPE environment variable returns "parallel" or "serial",
79 # depending on which type of library is found.
80 #
81 # LICENSE
82 #
83 # Copyright (c) 2009 Timothy Brown <[email protected]>
84 # Copyright (c) 2010 Rhys Ulerich <[email protected]>
85 #
86 # Copying and distribution of this file, with or without modification, are
87 # permitted in any medium without royalty provided the copyright notice
88 # and this notice are preserved. This file is offered as-is, without any
89 # warranty.
90
91 #serial 20
92
93 AC_DEFUN([AX_LIB_HDF5], [
94
95 AC_REQUIRE([AC_PROG_SED])
96 AC_REQUIRE([AC_PROG_AWK])
97 AC_REQUIRE([AC_PROG_GREP])
98
99 dnl Check first argument is one of the recognized values.
100 dnl Fail eagerly if is incorrect as this simplifies case statements below.
101 if test "m4_normalize(m4_default([$1],[]))" = "" ; then
102 : # Recognized value
103 elif test "m4_normalize(m4_default([$1],[]))" = "serial" ; then
104 : # Recognized value
105 elif test "m4_normalize(m4_default([$1],[]))" = "parallel"; then
106 : # Recognized value
107 else
108 AC_MSG_ERROR([
109 Unrecognized value for AX[]_LIB_HDF5 within configure.ac.
110 If supplied, argument 1 must be either 'serial' or 'parallel'.
111 ])
112 fi
113
114 dnl Add a default --with-hdf5 configuration option.
115 AC_ARG_WITH([hdf5],
116 AS_HELP_STRING(
117 [--with-hdf5=[yes/no/PATH]],
118 m4_case(m4_normalize([$1]),
119 [serial], [location of h5cc for serial HDF5 configuration],
120 [parallel], [location of h5pcc for parallel HDF5 configuration],
121 [location of h5cc or h5pcc for HDF5 configuration])
122 ),
123 [if test "$withval" = "no"; then
124 with_hdf5="no"
125 elif test "$withval" = "yes"; then
126 with_hdf5="yes"
127 else
128 with_hdf5="yes"
129 H5CC="$withval"
130 fi],
131 [with_hdf5="yes"]
132 )
133
134 dnl Set defaults to blank
135 HDF5_CC=""
136 HDF5_VERSION=""
137 HDF5_CFLAGS=""
138 HDF5_CPPFLAGS=""
139 HDF5_LDFLAGS=""
140 HDF5_LIBS=""
141 HDF5_FC=""
142 HDF5_FFLAGS=""
143 HDF5_FLIBS=""
144 HDF5_TYPE=""
145
146 dnl Try and find hdf5 compiler tools and options.
147 if test "$with_hdf5" = "yes"; then
148 if test -z "$H5CC"; then
149 dnl Check to see if H5CC is in the path.
150 AC_PATH_PROGS(
151 [H5CC],
152 m4_case(m4_normalize([$1]),
153 [serial], [h5cc],
154 [parallel], [h5pcc],
155 [h5cc h5pcc]),
156 [])
157 else
158 AC_MSG_CHECKING([Using provided HDF5 C wrapper])
159 AC_MSG_RESULT([$H5CC])
160 fi
161 AC_MSG_CHECKING([for HDF5 type])
162 AS_CASE([$H5CC],
163 [*h5pcc], [HDF5_TYPE=parallel],
164 [*h5cc], [HDF5_TYPE=serial],
165 [HDF5_TYPE=neither])
166 AC_MSG_RESULT([$HDF5_TYPE])
167 AC_MSG_CHECKING([for HDF5 libraries])
168 if test ! -f "$H5CC" || test ! -x "$H5CC"; then
169 AC_MSG_RESULT([no])
170 AC_MSG_WARN(m4_case(m4_normalize([$1]),
171 [serial], [
172 Unable to locate serial HDF5 compilation helper script 'h5cc'.
173 Please specify --with-hdf5=<LOCATION> as the full path to h5cc.
174 HDF5 support is being disabled (equivalent to --with-hdf5=no).
175 ], [parallel],[
176 Unable to locate parallel HDF5 compilation helper script 'h5pcc'.
177 Please specify --with-hdf5=<LOCATION> as the full path to h5pcc.
178 HDF5 support is being disabled (equivalent to --with-hdf5=no).
179 ], [
180 Unable to locate HDF5 compilation helper scripts 'h5cc' or 'h5pcc'.
181 Please specify --with-hdf5=<LOCATION> as the full path to h5cc or h5pcc.
182 HDF5 support is being disabled (equivalent to --with-hdf5=no).
183 ]))
184 with_hdf5="no"
185 with_hdf5_fortran="no"
186 else
187 dnl Get the h5cc output
188 HDF5_SHOW=$(eval $H5CC -show)
189
190 dnl Get the actual compiler used
191 HDF5_CC=$(eval $H5CC -show | head -n 1 | $AWK '{print $[]1}')
192 if test "$HDF5_CC" = "ccache"; then
193 HDF5_CC=$(eval $H5CC -show | head -n 1 | $AWK '{print $[]2}')
194 fi
195
196 dnl h5cc provides both AM_ and non-AM_ options
197 dnl depending on how it was compiled either one of
198 dnl these are empty. Lets roll them both into one.
199
200 dnl Look for "HDF5 Version: X.Y.Z"
201 HDF5_VERSION=$(eval $H5CC -showconfig | $GREP 'HDF5 Version:' \
202 | $AWK '{print $[]3}')
203
204 dnl A ideal situation would be where everything we needed was
205 dnl in the AM_* variables. However most systems are not like this
206 dnl and seem to have the values in the non-AM variables.
207 dnl
208 dnl We try the following to find the flags:
209 dnl (1) Look for "NAME:" tags
210 dnl (2) Look for "H5_NAME:" tags
211 dnl (3) Look for "AM_NAME:" tags
212 dnl
213 HDF5_tmp_flags=$(eval $H5CC -showconfig \
214 | $GREP 'FLAGS\|Extra libraries:' \
215 | $AWK -F: '{printf("%s "), $[]2}' )
216
217 dnl Find the installation directory and append include/
218 HDF5_tmp_inst=$(eval $H5CC -showconfig \
219 | $GREP 'Installation point:' \
220 | $AWK '{print $[]NF}' )
221
222 dnl Add this to the CPPFLAGS
223 HDF5_CPPFLAGS="-I${HDF5_tmp_inst}/include"
224
225 dnl Now sort the flags out based upon their prefixes
226 for arg in $HDF5_SHOW $HDF5_tmp_flags ; do
227 case "$arg" in
228 -I*) echo $HDF5_CPPFLAGS | $GREP -e "$arg" 2>&1 >/dev/null \
229 || HDF5_CPPFLAGS="$HDF5_CPPFLAGS $arg"
230 ;;
231 -L*) echo $HDF5_LDFLAGS | $GREP -e "$arg" 2>&1 >/dev/null \
232 || HDF5_LDFLAGS="$HDF5_LDFLAGS $arg"
233 ;;
234 -l*) echo $HDF5_LIBS | $GREP -e "$arg" 2>&1 >/dev/null \
235 || HDF5_LIBS="$HDF5_LIBS $arg"
236 ;;
237 esac
238 done
239
240
241 ff_hlib="";
242 # remove -lhdf5
243 for arg in $HDF5_LIBS; do if [ "-lhdf5" != "$arg" ] ;then ff_hlib="$ff_hlib $arg"; fi;done
244 HDF5_LIBS="$ff_hlib -lhdf5" # add -lhdf5
245 AC_MSG_RESULT([yes (version $[HDF5_VERSION])])
246
247 dnl See if we can compile
248 AC_LANG_PUSH([C])
249 ax_lib_hdf5_save_CC=$CC
250 ax_lib_hdf5_save_CPPFLAGS=$CPPFLAGS
251 ax_lib_hdf5_save_LIBS=$LIBS
252 ax_lib_hdf5_save_LDFLAGS=$LDFLAGS
253 CC=$HDF5_CC
254 CPPFLAGS=$HDF5_CPPFLAGS
255 LIBS=$HDF5_LIBS
256 LDFLAGS=$HDF5_LDFLAGS
257 AC_CHECK_HEADER([hdf5.h], [ac_cv_hadf5_h=yes], [ac_cv_hadf5_h=no])
258 AC_CHECK_LIB([hdf5], [H5Fcreate], [ac_cv_libhdf5=yes],
259 [ac_cv_libhdf5=no])
260 if test "$ac_cv_hadf5_h" = "no" && test "$ac_cv_libhdf5" = "no" ; then
261 AC_MSG_WARN([Unable to compile HDF5 test program])
262 fi
263 dnl Look for HDF5's high level library H5PTcreate
264 AC_CHECK_LIB([hdf5_hl],[H5PTcreate], [HDF5_LIBS="-lhdf5_hl $HDF5_LIBS"], [], [])
265
266 CC=$ax_lib_hdf5_save_CC
267 CPPFLAGS=$ax_lib_hdf5_save_CPPFLAGS
268 LIBS=$ax_lib_hdf5_save_LIBS
269 LDFLAGS=$ax_lib_hdf5_save_LDFLAGS
270 AC_LANG_POP([C])
271
272 AC_MSG_CHECKING([for matching HDF5 Fortran wrapper])
273 dnl Presume HDF5 Fortran wrapper is just a name variant from H5CC
274 H5FC=$(eval echo -n $H5CC | $SED -n 's/cc$/fc/p')
275 if test -x "$H5FC"; then
276 AC_MSG_RESULT([$H5FC])
277 with_hdf5_fortran="yes"
278 AC_SUBST([H5FC])
279
280 dnl Again, pry any remaining -Idir/-Ldir from compiler wrapper
281 for arg in `$H5FC -show`
282 do
283 case "$arg" in #(
284 -I*) echo $HDF5_FFLAGS | $GREP -e "$arg" >/dev/null \
285 || HDF5_FFLAGS="$HDF5_FFLAGS $arg"
286 ;;#(
287 -L*) echo $HDF5_FFLAGS | $GREP -e "$arg" >/dev/null \
288 || HDF5_FFLAGS="$HDF5_FFLAGS $arg"
289 dnl HDF5 installs .mod files in with libraries,
290 dnl but some compilers need to find them with -I
291 echo $HDF5_FFLAGS | $GREP -e "-I${arg#-L}" >/dev/null \
292 || HDF5_FFLAGS="$HDF5_FFLAGS -I${arg#-L}"
293 ;;
294 esac
295 done
296
297 dnl Make Fortran link line by inserting Fortran libraries
298 for arg in $HDF5_LIBS
299 do
300 case "$arg" in #(
301 -lhdf5_hl) HDF5_FLIBS="$HDF5_FLIBS -lhdf5hl_fortran $arg"
302 ;; #(
303 -lhdf5) HDF5_FLIBS="$HDF5_FLIBS -lhdf5_fortran $arg"
304 ;; #(
305 *) HDF5_FLIBS="$HDF5_FLIBS $arg"
306 ;;
307 esac
308 done
309 else
310 AC_MSG_RESULT([no])
311 with_hdf5_fortran="no"
312 fi
313
314 AC_SUBST([HDF5_VERSION])
315 AC_SUBST([HDF5_CC])
316 AC_SUBST([HDF5_CFLAGS])
317 AC_SUBST([HDF5_CPPFLAGS])
318 AC_SUBST([HDF5_LDFLAGS])
319 AC_SUBST([HDF5_LIBS])
320 AC_SUBST([HDF5_FC])
321 AC_SUBST([HDF5_FFLAGS])
322 AC_SUBST([HDF5_FLIBS])
323 AC_SUBST([HDF5_TYPE])
324 AC_DEFINE([HAVE_HDF5], [1], [Defined if you have HDF5 support])
325 fi
326 fi
327 ])