Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

324 lines
11KB

  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 <tbrown@freeshell.org>
  84. # Copyright (c) 2010 Rhys Ulerich <rhys.ulerich@gmail.com>
  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. #serial 18
  91. AC_DEFUN([AX_LIB_HDF5], [
  92. AC_REQUIRE([AC_PROG_SED])
  93. AC_REQUIRE([AC_PROG_AWK])
  94. AC_REQUIRE([AC_PROG_GREP])
  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. dnl Add a default --with-hdf5 configuration option.
  110. AC_ARG_WITH([hdf5],
  111. AS_HELP_STRING(
  112. [--with-hdf5=[yes/no/PATH]],
  113. m4_case(m4_normalize([$1]),
  114. [serial], [location of h5cc for serial HDF5 configuration],
  115. [parallel], [location of h5pcc for parallel HDF5 configuration],
  116. [location of h5cc or h5pcc for HDF5 configuration])
  117. ),
  118. [if test "$withval" = "no"; then
  119. with_hdf5="no"
  120. elif test "$withval" = "yes"; then
  121. with_hdf5="yes"
  122. else
  123. with_hdf5="yes"
  124. H5CC="$withval"
  125. fi],
  126. [with_hdf5="yes"]
  127. )
  128. dnl Set defaults to blank
  129. HDF5_CC=""
  130. HDF5_VERSION=""
  131. HDF5_CFLAGS=""
  132. HDF5_CPPFLAGS=""
  133. HDF5_LDFLAGS=""
  134. HDF5_LIBS=""
  135. HDF5_FC=""
  136. HDF5_FFLAGS=""
  137. HDF5_FLIBS=""
  138. HDF5_TYPE=""
  139. dnl Try and find hdf5 compiler tools and options.
  140. if test "$with_hdf5" = "yes"; then
  141. if test -z "$H5CC"; then
  142. dnl Check to see if H5CC is in the path.
  143. AC_PATH_PROGS(
  144. [H5CC],
  145. m4_case(m4_normalize([$1]),
  146. [serial], [h5cc],
  147. [parallel], [h5pcc],
  148. [h5cc h5pcc]),
  149. [])
  150. else
  151. AC_MSG_CHECKING([Using provided HDF5 C wrapper])
  152. AC_MSG_RESULT([$H5CC])
  153. fi
  154. AC_MSG_CHECKING([for HDF5 type])
  155. AS_CASE([$H5CC],
  156. [*h5pcc], [HDF5_TYPE=parallel],
  157. [*h5cc], [HDF5_TYPE=serial],
  158. [HDF5_TYPE=neither])
  159. AC_MSG_RESULT([$HDF5_TYPE])
  160. AC_MSG_CHECKING([for HDF5 libraries])
  161. if test ! -f "$H5CC" || test ! -x "$H5CC"; then
  162. AC_MSG_RESULT([no])
  163. AC_MSG_WARN(m4_case(m4_normalize([$1]),
  164. [serial], [
  165. Unable to locate serial HDF5 compilation helper script 'h5cc'.
  166. Please specify --with-hdf5=<LOCATION> as the full path to h5cc.
  167. HDF5 support is being disabled (equivalent to --with-hdf5=no).
  168. ], [parallel],[
  169. Unable to locate parallel HDF5 compilation helper script 'h5pcc'.
  170. Please specify --with-hdf5=<LOCATION> as the full path to h5pcc.
  171. HDF5 support is being disabled (equivalent to --with-hdf5=no).
  172. ], [
  173. Unable to locate HDF5 compilation helper scripts 'h5cc' or 'h5pcc'.
  174. Please specify --with-hdf5=<LOCATION> as the full path to h5cc or h5pcc.
  175. HDF5 support is being disabled (equivalent to --with-hdf5=no).
  176. ]))
  177. with_hdf5="no"
  178. with_hdf5_fortran="no"
  179. else
  180. dnl Get the h5cc output
  181. HDF5_SHOW=$(eval $H5CC -show)
  182. dnl Get the actual compiler used
  183. HDF5_CC=$(eval $H5CC -show | $AWK '{print $[]1}')
  184. if test "$HDF5_CC" = "ccache"; then
  185. HDF5_CC=$(eval $H5CC -show | $AWK '{print $[]2}')
  186. fi
  187. dnl h5cc provides both AM_ and non-AM_ options
  188. dnl depending on how it was compiled either one of
  189. dnl these are empty. Lets roll them both into one.
  190. dnl Look for "HDF5 Version: X.Y.Z"
  191. HDF5_VERSION=$(eval $H5CC -showconfig | $GREP 'HDF5 Version:' \
  192. | $AWK '{print $[]3}')
  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. dnl Find the installation directory and append include/
  206. HDF5_tmp_inst=$(eval $H5CC -showconfig \
  207. | $GREP 'Installation point:' \
  208. | $AWK '{print $[]NF}' )
  209. dnl Add this to the CPPFLAGS
  210. HDF5_CPPFLAGS="-I${HDF5_tmp_inst}/include"
  211. dnl Now sort the flags out based upon their prefixes
  212. for arg in $HDF5_SHOW $HDF5_tmp_flags ; do
  213. case "$arg" in
  214. -I*) echo $HDF5_CPPFLAGS | $GREP -e "$arg" 2>&1 >/dev/null \
  215. || HDF5_CPPFLAGS="$arg $HDF5_CPPFLAGS"
  216. ;;
  217. -L*) echo $HDF5_LDFLAGS | $GREP -e "$arg" 2>&1 >/dev/null \
  218. || HDF5_LDFLAGS="$arg $HDF5_LDFLAGS"
  219. ;;
  220. -l*) echo $HDF5_LIBS | $GREP -e "$arg" 2>&1 >/dev/null \
  221. || HDF5_LIBS="$arg $HDF5_LIBS"
  222. ;;
  223. esac
  224. done
  225. HDF5_LIBS="$HDF5_LIBS -lhdf5"
  226. AC_MSG_RESULT([yes (version $[HDF5_VERSION])])
  227. dnl See if we can compile
  228. AC_LANG_PUSH([C])
  229. ax_lib_hdf5_save_CC=$CC
  230. ax_lib_hdf5_save_CPPFLAGS=$CPPFLAGS
  231. ax_lib_hdf5_save_LIBS=$LIBS
  232. ax_lib_hdf5_save_LDFLAGS=$LDFLAGS
  233. CC=$HDF5_CC
  234. CPPFLAGS=$HDF5_CPPFLAGS
  235. LIBS=$HDF5_LIBS
  236. LDFLAGS=$HDF5_LDFLAGS
  237. AC_CHECK_HEADER([hdf5.h], [ac_cv_hadf5_h=yes], [ac_cv_hadf5_h=no])
  238. AC_CHECK_LIB([hdf5], [H5Fcreate], [ac_cv_libhdf5=yes],
  239. [ac_cv_libhdf5=no])
  240. if test "$ac_cv_hadf5_h" = "no" && test "$ac_cv_libhdf5" = "no" ; then
  241. AC_MSG_WARN([Unable to compile HDF5 test program])
  242. fi
  243. dnl Look for HDF5's high level library
  244. AC_HAVE_LIBRARY([hdf5_hl], [HDF5_LIBS="$HDF5_LIBS -lhdf5_hl"], [], [])
  245. CC=$ax_lib_hdf5_save_CC
  246. CPPFLAGS=$ax_lib_hdf5_save_CPPFLAGS
  247. LIBS=$ax_lib_hdf5_save_LIBS
  248. LDFLAGS=$ax_lib_hdf5_save_LDFLAGS
  249. AC_LANG_POP([C])
  250. AC_MSG_CHECKING([for matching HDF5 Fortran wrapper])
  251. dnl Presume HDF5 Fortran wrapper is just a name variant from H5CC
  252. H5FC=$(eval echo -n $H5CC | $SED -n 's/cc$/fc/p')
  253. if test -x "$H5FC"; then
  254. AC_MSG_RESULT([$H5FC])
  255. with_hdf5_fortran="yes"
  256. AC_SUBST([H5FC])
  257. dnl Again, pry any remaining -Idir/-Ldir from compiler wrapper
  258. for arg in `$H5FC -show`
  259. do
  260. case "$arg" in #(
  261. -I*) echo $HDF5_FFLAGS | $GREP -e "$arg" >/dev/null \
  262. || HDF5_FFLAGS="$arg $HDF5_FFLAGS"
  263. ;;#(
  264. -L*) echo $HDF5_FFLAGS | $GREP -e "$arg" >/dev/null \
  265. || HDF5_FFLAGS="$arg $HDF5_FFLAGS"
  266. dnl HDF5 installs .mod files in with libraries,
  267. dnl but some compilers need to find them with -I
  268. echo $HDF5_FFLAGS | $GREP -e "-I${arg#-L}" >/dev/null \
  269. || HDF5_FFLAGS="-I${arg#-L} $HDF5_FFLAGS"
  270. ;;
  271. esac
  272. done
  273. dnl Make Fortran link line by inserting Fortran libraries
  274. for arg in $HDF5_LIBS
  275. do
  276. case "$arg" in #(
  277. -lhdf5_hl) HDF5_FLIBS="$HDF5_FLIBS -lhdf5hl_fortran $arg"
  278. ;; #(
  279. -lhdf5) HDF5_FLIBS="$HDF5_FLIBS -lhdf5_fortran $arg"
  280. ;; #(
  281. *) HDF5_FLIBS="$HDF5_FLIBS $arg"
  282. ;;
  283. esac
  284. done
  285. else
  286. AC_MSG_RESULT([no])
  287. with_hdf5_fortran="no"
  288. fi
  289. AC_SUBST([HDF5_VERSION])
  290. AC_SUBST([HDF5_CC])
  291. AC_SUBST([HDF5_CFLAGS])
  292. AC_SUBST([HDF5_CPPFLAGS])
  293. AC_SUBST([HDF5_LDFLAGS])
  294. AC_SUBST([HDF5_LIBS])
  295. AC_SUBST([HDF5_FC])
  296. AC_SUBST([HDF5_FFLAGS])
  297. AC_SUBST([HDF5_FLIBS])
  298. AC_SUBST([HDF5_TYPE])
  299. AC_DEFINE([HAVE_HDF5], [1], [Defined if you have HDF5 support])
  300. fi
  301. fi
  302. ])