dnl is linked from the top-level documents page. It can also be found at
dnl http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have
dnl access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu.
dnl Macros for HDF5 Fortran
dnl -------------------------------------------------------------------------
dnl -------------------------------------------------------------------------
dnl -------------------------------------------------------------------------
dnl Check for a Fortran 9X compiler.
[AC_CHECK_PROGS(F9X, f90 pgf90 xlf90 f95 g95 xlf95 efc)
test -z "$FC" && AC_MSG_ERROR([no acceptable f9X compiler found in \$PATH])
if test $ac_cv_prog_g9x = yes; then
dnl Check whether -g works, even if FCFLAGS is set, in case the package
dnl plays around with FCFLAGS (such as to build both debugging and
dnl normal versions of a library), tasteless as that idea is.
ac_test_FCFLAGS="${FCFLAGS+set}"
ac_save_FCFLAGS="$FCFLAGS"
if test "$ac_test_FCFLAGS" = set; then
FCFLAGS="$ac_save_FCFLAGS"
elif test $ac_cv_prog_f9x_g = yes; then
test "${FCFLAGS+set}" = set || FCFLAGS="-g"
dnl -------------------------------------------------------------------------
dnl AC_TRY_F9X_COMPILER()
dnl It would be nice if the compiler actually works.
AC_DEFUN(AC_TRY_F9X_COMPILER, [
cat > conftest.$ac_ext << EOF
if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext}; then
# If we can't run a trivial program, we are probably using a cross compiler.
if (./conftest; exit) 2>/dev/null; then
echo "configure: failed program was:" >&AS_MESSAGE_LOG_FD
cat conftest.$ac_ext >&AS_MESSAGE_LOG_FD
dnl -------------------------------------------------------------------------
dnl Generic macro to setup the Fortran 9X specific env variables.
m4_define([AC_LANG(FORTRAN9X)],
ac_compile='${FC-f90} -c $FCFLAGS conftest.$ac_ext 1>&AS_MESSAGE_LOG_FD'
ac_link='${FC-f90} -o conftest${ac_exeext} $FCFLAGS conftest.$ac_ext $LDFLAGS $LIBS 1>&AS_MESSAGE_LOG_FD'
cross_compiling=$ac_cv_prog_f9x_cross
AU_DEFUN([AC_LANG_FORTRAN9X], [AC_LANG(FORTRAN9X)])
dnl -------------------------------------------------------------------------
dnl It would be nice if the compiler actually works.
AC_DEFUN(AC_PROG_F9X_WORKS, [
AC_MSG_CHECKING([whether the Fortran 9X compiler ($FC $FCFLAGS $LDFLAGS) works])
], ac_cv_prog_f9x_works, ac_cv_prog_f9x_cross)
AC_MSG_RESULT($ac_cv_prog_f9x_works)
if test $ac_cv_prog_f9x_works = no; then
AC_MSG_ERROR([installation or configuration problem: Fortran 9X compiler cannot create executables.])
AC_MSG_CHECKING([whether the Fortran 9X compiler ($FC $FCFLAGS $LDFLAGS) is a cross-compiler])
AC_MSG_RESULT($ac_cv_prog_f9x_cross)
cross_compiling=$ac_cv_prog_f9x_cross
dnl -------------------------------------------------------------------------
dnl Test whether for Fortran 9X compiler is `g95' (the GNU Fortran 95
dnl Compiler). This test depends on whether the Fortran 9X compiler
dnl can do CPP pre-processing.
AC_DEFUN(AC_PROG_F9X_GNU,
[AC_CACHE_CHECK(whether we are using GNU Fortran 95, ac_cv_prog_g9x,
[cat > conftest.fpp <<EOF
if AC_TRY_COMMAND($FC -E conftest.fpp) | egrep yes >/dev/null 2>&1; then
dnl -------------------------------------------------------------------------
dnl Test whether the Fortran 9X compiler can accept the `-g' option
[AC_CACHE_CHECK(whether $FC accepts -g, ac_cv_prog_f9x_g,
if test -z "`$FC -g -c conftest.f 2>&1`"; then
dnl -------------------------------------------------------------------------
dnl Check for optimizer flags the Fortran compiler can use.
AC_DEFUN(AC_F9X_OPT_FLAGS,
[AC_MSG_CHECKING([for $FC optimizer flags])
for flags in "-fast" "-O3" "-O" "";do
cat > conftest.$ac_ext <<EOF
ac_compile='${FC-f90} -c $flag $FCFLAGS conftest.$ac_ext 1>&AS_MESSAGE_LOG_FD'
if AC_TRY_EVAL(ac_compile); then
if grep 'passed to ld' conftest.out > /dev/null 2>&1; then :; else
FCFLAGS="$FCFLAGS $flags"
if test -n "$flags"; then
dnl -------------------------------------------------------------------------
dnl Check how F9X handles modules. This macro also checks which
dnl command-line option to use to include the module once it's built.
[AC_MSG_CHECKING(what $FC does with modules)
test -d conftestdir || mkdir conftestdir
cat >conftest.$ac_ext <<EOF
if test -n "$F9XMODFLAG"; then
FCFLAGS="$F9XMODFLAG. $FCFLAGS"
dnl -------------------------------------------------------------------------
dnl Check if we can compile a simple Fortran 90 program.
dnl AC_TRY_FCOMPILE(FUNCTION-BODY,
dnl [ACTION-IF-SUCCESS], [ACTION-IF-NOT-SUCCESS])
AC_DEFUN([AC_TRY_FCOMPILE],
test -d conftestdir || mkdir conftestdir
cat >conftest.$ac_ext <<EOF
if AC_TRY_EVAL(ac_compile); then
dnl -------------------------------------------------------------------------
dnl Check if we can link a simple Fortran 90 program.
dnl AC_TRY_FLINK(INCLUDES, FUNCTION-BODY,
dnl [ACTION-IF-SUCCESS], [ACTION-IF-NOT-SUCCESS])
test -d conftestdir || mkdir conftestdir
cat >conftest.$ac_ext <<EOF
if AC_TRY_EVAL(ac_compile) && AC_TRY_EVAL(ac_link); then
dnl -------------------------------------------------------------------------
dnl Check if we can link a simple Fortran 90 program with the specified library.
dnl AC_CHECK_FLIB(LIBRARY, FUNCTION-BODY,
dnl [ACTION-IF-SUCCESS], [ACTION-IF-NOT-SUCCESS])
AC_DEFUN([AC_CHECK_FLIB],
test -d conftestdir || mkdir conftestdir
cat >conftest.$ac_ext <<EOF
if AC_TRY_EVAL(ac_compile) && AC_TRY_EVAL(ac_link); then
dnl -------------------------------------------------------------------------
dnl -------------------------------------------------------------------------
dnl Possible future tests for the Fortran stuff...
dnl -------------------------------------------------------------------------
dnl -------------------------------------------------------------------------