Skip to content

Commit 0e2b2da

Browse files
committed
Fix automake warnings and detection of HDF5
git-svn-id: svn+ssh://svn.code.sf.net/p/meteosatlib/code/trunk@932 7b7aedef-af05-4ae1-8915-7847460b892b
1 parent ec24c1b commit 0e2b2da

File tree

4 files changed

+334
-19
lines changed

4 files changed

+334
-19
lines changed

configure.ac

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,24 @@ else
156156
fi
157157
enable_grib=$have_gribapi
158158

159-
dnl HDF5 (which does not use pkg-config)
160-
have_hdf5=yes
161-
AC_CHECK_LIB([hdf5], [H5Fis_hdf5], [], [have_hdf5=no])
162-
AC_CHECK_HEADER([hdf5.h], [], [have_hdf5=no])
163-
if test x"$enable_hdf5" = x"no"; then
164-
AC_MSG_WARN("*** hdf5 support disabled")
159+
dnl Check for hdf5 support
160+
PKG_CHECK_MODULES([HDF5], [hdf5-serial], [have_hdf5=yes], [have_hdf5=no])
161+
if test $have_hdf5 = yes
162+
then
163+
PKG_CHECK_MODULES([HDF5],[hdf5-serial])
165164
else
166-
AC_DEFINE([HAVE_HDF5], 1, [HDF5 functions are available])
167-
HDF5_CFLAGS=""
168-
HDF5_LIBS="-lhdf5"
169-
AC_SUBST(HDF5_CFLAGS)
170-
AC_SUBST(HDF5_LIBS)
165+
AX_LIB_HDF5
166+
if test "$with_hdf5" = yes
167+
then
168+
have_hdf5=yes
169+
else
170+
AC_MSG_WARN("*** hdf5 support disabled")
171+
fi
172+
fi
173+
if test $have_hdf5 = yes
174+
then
175+
AC_DEFINE([HAVE_HDF5], 1, [hdf5 format enabled])
176+
AC_DEFINE([HAVE_HDF5], 1, [HDF5 functions are available])
171177
fi
172178
enable_safh5=$have_hdf5
173179

examples/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# along with this program; if not, write to the Free Software Foundation,
1818
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1919

20-
INCLUDES = -I$(top_srcdir) -I$(top_builddir)
20+
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_builddir)
2121

2222
bin_PROGRAMS =
2323

m4/ax_lib_hdf5.m4

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

0 commit comments

Comments
 (0)