1dnl  This file is part of MED.
2dnl
3dnl  COPYRIGHT (C) 1999 - 2019  EDF R&D, CEA/DEN
4dnl  MED is free software: you can redistribute it and/or modify
5dnl  it under the terms of the GNU Lesser General Public License as published by
6dnl  the Free Software Foundation, either version 3 of the License, or
7dnl  (at your option) any later version.
8dnl
9dnl  MED is distributed in the hope that it will be useful,
10dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
11dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12dnl  GNU Lesser General Public License for more details.
13dnl
14dnl  You should have received a copy of the GNU Lesser General Public License
15dnl  along with MED.  If not, see <http://www.gnu.org/licenses/>.
16dnl
17
18AC_DEFUN([_MED_DEFINE_HDF5_ARGS],[
19## Guess where as hdf5 is located by the HDF5HOME environement variable
20## or by the --with-hdf5 option
21 AC_ARG_WITH([hdf5],
22             AC_HELP_STRING([--with-hdf5=<path>],
23	                   [Use <path> for HDF5 path.]),
24	    [],
25[with_hdf5=yes])
26
27 AC_ARG_WITH([hdf5-include],
28             AC_HELP_STRING([--with-hdf5-include=<include path>],
29	                   [Use <include path> for HDF5 include path.]),
30	    [],
31[with_hdf5_include=no])
32
33 AC_ARG_WITH([hdf5-lib],
34             AC_HELP_STRING([--with-hdf5-lib=<lib path>],
35	                   [Use <lib path> for lib HDF5 path.]),
36	    [],
37[with_hdf5_lib=no])
38
39 AC_ARG_WITH([hdf5-bin],
40             AC_HELP_STRING([--with-hdf5-bin=<bin path>],
41	                   [Use <bin path> for bin HDF5 path.]),
42	    [hdf5bin=$with_hdf5_bin],
43[with_hdf5_bin=no])
44
45])
46
47AC_DEFUN([_MED_BEFORE_ENABLE_PMED], [
48AC_REQUIRE([_MED_DEFINE_HDF5_ARGS])
49
50dnl ## If user hasn't provided hdf5 path try using "$HDF5HOME"
51    test "x$with_hdf5" = "xyes" && hdf5home=${HDF5HOME} || hdf5home=$with_hdf5
52
53    if test ! "x$with_hdf5" = "xno"; then
54dnl ## If user has  neither provided hdf5 path (--with-hdf5 or "$HDF5HOME"=="") nor --with-hdf5-include and --with-hdf5-lib then try to use system path /usr as HDF5 home
55       test -z "$hdf5home"  &&  test "x$with_hdf5_include" = "xno" && test "x$with_hdf5_lib" = "xno"  && hdf5home="/usr/"
56
57dnl #If user specified a specific hdf5home, be careful to not detect an hdf5 package in the system
58dnl #Vérify that the hdf5 directory structure exist
59       if test -z "$hdf5home" && (test "x$with_hdf5_include" = "xno" || test "x$with_hdf5_lib" = "xno") ; then
60         AC_MSG_ERROR([The hdf5 path |$hdf5home| isn't specified, please verify either HDF5HOME or --with-hdf5=<path>. You may also use --with-hdf5-include and --with-hdf5-lib.])
61       fi
62       if test ! -d "$hdf5home" && (test "x$with_hdf5_include" = "xno" || test "x$with_hdf5_lib" = "xno") ; then
63         AC_MSG_ERROR([The directory hdf5 home |$hdf5home| doesn't exist, please verify either HDF5HOME or --with-hdf5=<path>])
64       fi
65
66       found_H5pubconf_h=no
67       hdf5home_save=$hdf5home
68       #if user has provided a specific hdf5 path for include or lib don't try to guess specific system path
69       if test "x$with_hdf5_include" = "xno" && test "x$with_hdf5_lib" = "xno"; then
70         #Search for H5pubconf.h in $hdf5home and some other standard paths if user doesn't provide hdf5_include
71       	# H5pubconf.h is used further to detect serial or parallel hdf5
72       	#Cette approche ne prend pas en compte CPPFLAGS, inconvénient mineur de  au vu du test d'arborescence précédent
73         for hdf5home in "$hdf5home_save" "$hdf5home_save/lib/x86_64-linux-gnu/hdf5/serial/"  "$hdf5home_save/lib/x86_64-linux-gnu/hdf5/parallel/"
74         do
75          AC_MSG_NOTICE([Trying $hdf5home home path for searching H5pubconf.h file.])
76          test -e $hdf5home/include/H5pubconf.h && found_H5pubconf_h=yes && break
77         done
78       fi
79
80       test "x$with_hdf5_include" = "xno" && hdf5include=$hdf5home/include || hdf5include=$with_hdf5_include
81       if test ! -d "$hdf5include" ; then
82         AC_MSG_ERROR([The directory hdf5 include |$hdf5include| doesn't exist, please verify either HDF5HOME, --with-hdf5=<path> or --with-hdf5-include])
83       fi
84
85       test ! "x$found_H5pubconf_h" = "xyes" || test -e ${hdf5include}/H5pubconf.h || AC_MSG_ERROR([Can't find H5pubconf.h file, please verify either HDF5HOME, --with-hdf5=<path> or --with-hdf5-include.])
86
87       test "x$with_hdf5_lib" = "xno" && hdf5lib=$hdf5home/lib || hdf5lib=$with_hdf5_lib
88       if test ! -d "$hdf5lib" ; then
89         AC_MSG_ERROR([The directory hdf5 lib |$hdf5lib| doesn't exist, please verify either HDF5HOME, --with-hdf5=<path> or --with-hdf5-lib])
90       fi
91
92       test "x$with_hdf5_bin" = "xno" && hdf5bin=$hdf5home_save/bin || hdf5bin=$with_hdf5_bin
93       if test ! -d "$hdf5bin" ; then
94         AC_MSG_ERROR([The directory hdf5 bin |$hdf5bin| doesn't exist, please verify either HDF5HOME, --with-hdf5=<path> or --with-hdf5-bin])
95       fi
96
97    else
98## In case user explicitly ask to not use hdf5 !
99      AC_MSG_WARN([Can't compile MED without hdf5])
100      AC_MSG_ERROR([either use HDF5HOME env. var. or --with-hdf5=<path> even if you use all the specific --with-hdf5-... paths.])
101    fi
102])
103
104
105AC_DEFUN([MED_CHECK_HDF5],dnl
106[
107#La localisation d'hdf5 doit être établie avant
108AC_REQUIRE([_MED_BEFORE_ENABLE_PMED])
109#de tester l'aspect parallel de la bibliothèque (H5pubconf.h).
110AC_REQUIRE([MED_ENABLE_PMED])
111
112AC_REQUIRE([AC_PROG_SED])
113AC_REQUIRE([AC_PROG_GREP])
114
115
116      LDFLAGS_save="$LDFLAGS"
117      LIBS_save="$LIBS"
118      CPPFLAGS_save="$CPPFLAGS"
119
120      #Cette macro a au minimum besoin du préprocesseur dont la detection appelle malheureusement aussi la detection du compilateur
121      #Elle ne peut donc pas être appelée avant de connaître l'aspect serial/parallel d'hdf (pour le choix du frontend mpi ou compilateur direct).
122      #On ne test donc la version d'HDF qu'après l'aspect // ou séquentiel
123      LDFLAGS="-L$hdf5lib $LDFLAGS"
124      CPPFLAGS="-I$hdf5include $CPPFLAGS"
125      AX_ABSOLUTE_HEADER([H5public.h])
126
127      #Use H5public.h in order to find the HDF version we are using.
128      HDF5_ABS_PATH="$gl_cv_absolute_H5public_h"
129      HDF5_USED_VER="unknown"
130      HDF5_VERSION="0"
131      if test -n "$HDF5_ABS_PATH" ; then
132         HDF5_USED_VER=` grep H5_VERS_INFO $HDF5_ABS_PATH | sed  's/\([[^"]]*\)\(".*"\)\([[^"]]*\)/\2/g' `
133         H5_VER_MAJOR=`  grep '#define *H5_VERS_MAJOR' $HDF5_ABS_PATH | sed  's/^.*H5_VERS_MAJOR[[ \t]]*\([0-9]*\)[[ \t]]*.*$/\1/g' `
134         H5_VER_MINOR=`  grep '#define *H5_VERS_MINOR' $HDF5_ABS_PATH | sed  's/^.*H5_VERS_MINOR[[ \t]]*\([0-9]*\)[[ \t]]*.*$/\1/g' `
135         H5_VER_RELEASE=`grep '#define *H5_VERS_RELEASE' $HDF5_ABS_PATH | sed  's/^.*H5_VERS_RELEASE[[ \t]]*\([0-9]*\)[[ \t]]*.*$/\1/g' `
136         HDF5_VERSION=`  expr 10000 \* ${H5_VER_MAJOR} + 100 \* ${H5_VER_MINOR} + ${H5_VER_RELEASE} `
137         test "0${HDF5_VERSION}" -gt "11100" || test "0${HDF5_VERSION}" -lt "11002" && AC_MSG_ERROR([
138This HDF5 version ${H5_VER_MAJOR}.${H5_VER_MINOR}.${H5_VER_RELEASE} must not be used with med-fichier${MED_NUM_MAJEUR}.${MED_NUM_MINEUR}.${MED_NUM_RELEASE}.
139The HDF5 library version used by med-fichier${MED_NUM_MAJEUR}.y.z MUST NOT be > 1.10 and have to be at least HDF${HDF_VERSION_REF}.
140DO NOT TRY TO COMPILE med-fichier${MED_NUM_MAJEUR}.${MED_NUM_MINEUR}.${MED_NUM_RELEASE} version with an HDF5 library which would generate an hdf5 file not compliant with HDF5-${HDF_VERSION_MAJOR_REF}.${HDF_VERSION_MINOR_REF}.z library.
141This would BREAK med-fichier compatibility between files with the same revision number !
142      ])
143     else
144## In case user explicitly ask to not use hdf5 !
145      AC_MSG_WARN([Can't compile MED without hdf5])
146      AC_MSG_ERROR([either use HDF5HOME env. var. or --with-hdf5=<path>.])
147     fi
148
149      HDF5_TYPEDEF_HERR_T=` sed -n '/^[[ \t]]*typedef .*herr_t[[ \t]]*;/p' $HDF5_ABS_PATH `
150      HDF5_TYPEDEF_HSIZE_T=` sed -n '/^[[ \t]]*typedef .*hsize_t[[ \t]]*;/p' $HDF5_ABS_PATH `
151      AX_ABSOLUTE_HEADER([H5Ipublic.h])
152      HDF5_TYPEDEF_HID_T=` sed -n '/^[[ \t]]*typedef .*hid_t[[ \t]]*;/p' $gl_cv_absolute_H5Ipublic_h `
153
154#      AC_CHECK_LIB([m],[sin],[],[AC_MSG_ERROR([Can't find C math library.])],[])
155#      AC_CHECK_LIB([z],[compress],[],[AC_MSG_ERROR([Can't find z library.])],[])
156      AC_CHECK_LIB([hdf5],[H5open],[],[AC_MSG_ERROR([Can't find hdf5 library, either use HDF5HOME env. var. , --with-hdf5=<path> or --with-hdf5-lib=<libpath>])],[-lm -lz])
157      test "x$mpi_wanted_test" = "xyes" &&  AC_CHECK_FUNCS(H5Pset_fapl_mpio, [],[AC_MSG_ERROR([HDF5 is detected as a parallel version but can't find H5Pset_fapl_mpio function.])] )
158
159      if test "x$with_hdf5_include" = "xno"; then
160        AC_PATH_PROG([H5DUMP],[h5dump],[no],[$hdf5bin$PATH_SEPARATOR$PATH$PATH_SEPARATOR])
161      else
162        AC_PATH_PROG([H5DUMP],[h5dump],[no],[$hdf5bin])
163      fi
164      if test "X$H5DUMP" = "Xno"; then
165         AC_MSG_ERROR([Can't find h5dump, please verify your env. var. PATH or use of --with-hdf5bin=<binpath>.])
166      fi
167
168
169#      AC_DEFINE(H5_USE_16_API,[],[Using HDF5-1.6 API compatibility with HDF5 1.8 libraries])
170      HDF5_CPPFLAGS="-DH5_USE_16_API"
171      HDF5_CPPFLAGS="$HDF5_CPPFLAGS -I$hdf5include"
172      HDF5_LDFLAGS="-L$hdf5lib"
173      LDFLAGS="$LDFLAGS_save"
174      CPPFLAGS="$CPPFLAGS_save"
175      LIBS="$LIBS_save"
176
177      AC_SUBST(HDF5_CPPFLAGS)
178      AC_SUBST(HDF5_LDFLAGS)
179#La ligne suivante est inutile car effectuée par AC_CHECK_PROG
180#      AC_SUBST(H5DUMP)
181      AC_SUBST([HDF5_USED_VER])
182      HDF5_LIBS="-lhdf5"
183      AC_SUBST([HDF5_LIBS])
184
185      AC_SUBST(HDF5_TYPEDEF_HERR_T)
186      AC_SUBST(HDF5_TYPEDEF_HID_T)
187      AC_SUBST(HDF5_TYPEDEF_HSIZE_T)
188])
189
190