Debian Codegraph @

etc/config/m4/ax_lib_hdf5.m4

raw ◀ ▶
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 *top_srcdir*) echo Ignoring $arg
229 ;;
230 -I*) echo $HDF5_CPPFLAGS | $GREP -e "$arg" 2>&1 >/dev/null \
231 || HDF5_CPPFLAGS="$HDF5_CPPFLAGS $arg"
232 ;;
233 -L*) echo $HDF5_LDFLAGS | $GREP -e "$arg" 2>&1 >/dev/null \
234 || HDF5_LDFLAGS="$HDF5_LDFLAGS $arg"
235 ;;
236 -l*) echo $HDF5_LIBS | $GREP -e "$arg" 2>&1 >/dev/null \
237 || HDF5_LIBS="$HDF5_LIBS $arg"
238 ;;
239 esac
240 done
241
242
243 ff_hlib="";
244 # remove -lhdf5
245 for arg in $HDF5_LIBS; do if [ "-lhdf5" != "$arg" ] ;then ff_hlib="$ff_hlib $arg"; fi;done
•246 HDF5_LIBS="${HDF5_LIBS#"${HDF5_LIBS%%[![:space:]]*}"}"
247 HDF5_INFIX=
248 case "$HDF5_LIBS" in
249 -lhdf5_*)
250 HDF5_INFIX="${HDF5_LIBS#-lhdf5_}"
251 HDF5_INFIX="_${HDF5_INFIX%%_*}"
252 ;;
253 esac
254 HDF5_LIBS="-lhdf5$HDF5_INFIX $HDF5_LIBS"
255 AC_MSG_RESULT([yes (version $[HDF5_VERSION])])
256
257 dnl See if we can compile
258 AC_LANG_PUSH([C])
259 ax_lib_hdf5_save_CC=$CC
260 ax_lib_hdf5_save_CPPFLAGS=$CPPFLAGS
261 ax_lib_hdf5_save_LIBS=$LIBS
262 ax_lib_hdf5_save_LDFLAGS=$LDFLAGS
263 CC=$HDF5_CC
264 CPPFLAGS=$HDF5_CPPFLAGS
265 LIBS=$HDF5_LIBS
266 LDFLAGS=$HDF5_LDFLAGS
267 AC_CHECK_HEADER([hdf5.h], [ac_cv_hadf5_h=yes], [ac_cv_hadf5_h=no])
•268 AC_CHECK_LIB([hdf5${HDF5_INFIX}_hl],[H5PTcreate], [HDF5_LIBS="-lhdf5${HDF5_INFIX}_hl $HDF5_LIBS"], [], [])
269 if test "$ac_cv_hadf5_h" = "no" && test "$ac_cv_libhdf5" = "no" ; then
270 AC_MSG_WARN([Unable to compile HDF5 test program])
271 fi
272 dnl Look for HDF5's high level library H5PTcreate
273 AC_CHECK_LIB([hdf5_hl],[H5PTcreate], [HDF5_LIBS="-lhdf5_hl $HDF5_LIBS"], [], [])
274
275 CC=$ax_lib_hdf5_save_CC
276 CPPFLAGS=$ax_lib_hdf5_save_CPPFLAGS
277 LIBS=$ax_lib_hdf5_save_LIBS
278 LDFLAGS=$ax_lib_hdf5_save_LDFLAGS
279 AC_LANG_POP([C])
280
281 AC_MSG_CHECKING([for matching HDF5 Fortran wrapper])
282 dnl Presume HDF5 Fortran wrapper is just a name variant from H5CC
283 H5FC=$(eval echo -n $H5CC | $SED -n 's/cc$/fc/p')
284 if test -x "$H5FC"; then
285 AC_MSG_RESULT([$H5FC])
286 with_hdf5_fortran="yes"
287 AC_SUBST([H5FC])
288
289 dnl Again, pry any remaining -Idir/-Ldir from compiler wrapper
290 for arg in `$H5FC -show`
291 do
292 case "$arg" in #(
293 -I*) echo $HDF5_FFLAGS | $GREP -e "$arg" >/dev/null \
294 || HDF5_FFLAGS="$HDF5_FFLAGS $arg"
295 ;;#(
296 -L*) echo $HDF5_FFLAGS | $GREP -e "$arg" >/dev/null \
297 || HDF5_FFLAGS="$HDF5_FFLAGS $arg"
298 dnl HDF5 installs .mod files in with libraries,
299 dnl but some compilers need to find them with -I
300 echo $HDF5_FFLAGS | $GREP -e "-I${arg#-L}" >/dev/null \
301 || HDF5_FFLAGS="$HDF5_FFLAGS -I${arg#-L}"
302 ;;
303 esac
304 done
305
306 dnl Make Fortran link line by inserting Fortran libraries
307 for arg in $HDF5_LIBS
308 do
309 case "$arg" in #(
•310 -lhdf5${HDF5_INFIX}_hl) HDF5_FLIBS="$HDF5_FLIBS -lhdf5${HDF5_INFIX}_hl_fortran $arg"
311 ;; #(
•312 -lhdf5${HDF5_INFIX}) HDF5_FLIBS="$HDF5_FLIBS -lhdf5${HDF5_INFIX}_fortran $arg"
313 ;; #(
314 *) HDF5_FLIBS="$HDF5_FLIBS $arg"
315 ;;
316 esac
317 done
318 else
319 AC_MSG_RESULT([no])
320 with_hdf5_fortran="no"
321 fi
322
323 AC_SUBST([HDF5_VERSION])
324 AC_SUBST([HDF5_CC])
325 AC_SUBST([HDF5_CFLAGS])
326 AC_SUBST([HDF5_CPPFLAGS])
327 AC_SUBST([HDF5_LDFLAGS])
328 AC_SUBST([HDF5_LIBS])
329 AC_SUBST([HDF5_FC])
330 AC_SUBST([HDF5_FFLAGS])
331 AC_SUBST([HDF5_FLIBS])
332 AC_SUBST([HDF5_TYPE])
333 AC_DEFINE([HAVE_HDF5], [1], [Defined if you have HDF5 support])
334 fi
335 fi
336 ])