summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuc Maisonobe <luc@spaceroots.org>2011-04-02 14:17:55 +0200
committerRalf Wildenhues <Ralf.Wildenhues@gmx.de>2011-04-02 14:18:47 +0200
commit3e3412d3dd1ff7734f0a9ccd1a55252bd7ea8790 (patch)
tree54aa9289896018f30bcf7076f112fd3620472872
parentbf140a4c8c457d9fc5876076c69c6e34598c39fe (diff)
downloadautoconf-3e3412d3dd1ff7734f0a9ccd1a55252bd7ea8790.tar.gz
New macro AC_FC_MODULE_FLAG: Fortran 90 module include path.
* lib/autoconf/fortran.m4 (AC_FC_MODULE_FLAG): New macro, adjusted and rewritten from the AX_F90_MODULE_FLAG macro from the Autoconf Macro Archive by Luc Maisonobe, Julian C. Cummings, and Alexander Pletzer. * doc/autoconf.texi (Fortran Compiler): Document it. * tests/fortran.at (AC_FC_MODULE_FLAG): New test. * tests/local.at (AT_CHECK_ENV): Do not complain about FC_MODINC setting. * NEWS, THANKS: Update. Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
-rw-r--r--ChangeLog16
-rw-r--r--NEWS1
-rw-r--r--THANKS1
-rw-r--r--doc/autoconf.texi45
-rw-r--r--lib/autoconf/fortran.m477
-rw-r--r--tests/fortran.at71
-rw-r--r--tests/local.at2
7 files changed, 212 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 5e6f54d5..bdbce27c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,20 @@
2011-04-02 Luc Maisonobe <luc@spaceroots.org>
+ Julian C. Cummings <cummings@cacr.caltech.edu>
+ Alexander Pletzer <pletzer@txcorp.com>
+ Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
+
+ New macro AC_FC_MODULE_FLAG: Fortran 90 module include path.
+ * lib/autoconf/fortran.m4 (AC_FC_MODULE_FLAG): New macro,
+ adjusted and rewritten from the AX_F90_MODULE_FLAG macro from
+ the Autoconf Macro Archive by Luc Maisonobe, Julian C. Cummings,
+ and Alexander Pletzer.
+ * doc/autoconf.texi (Fortran Compiler): Document it.
+ * tests/fortran.at (AC_FC_MODULE_FLAG): New test.
+ * tests/local.at (AT_CHECK_ENV): Do not complain about FC_MODINC
+ setting.
+ * NEWS, THANKS: Update.
+
+2011-04-02 Luc Maisonobe <luc@spaceroots.org>
Alexander Pletzer <pletzer@txcorp.com>
Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
diff --git a/NEWS b/NEWS
index 78539773..ea4d5868 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,7 @@ GNU Autoconf NEWS - User visible changes.
AC_FC_CHECK_BOUNDS to enable array bounds checking
AC_F77_IMPLICIT_NONE and AC_FC_IMPLICIT_NONE to disable implicit integer
AC_FC_MODULE_EXTENSION to compute the Fortran 90 module name extension
+ AC_FC_MODULE_FLAG for the Fortran 90 module search path flag
* Noteworthy changes in release 2.68 (2010-09-22) [stable]
Released by Eric Blake, based on git versions 2.67.*.
diff --git a/THANKS b/THANKS
index def09c8b..7679b054 100644
--- a/THANKS
+++ b/THANKS
@@ -213,6 +213,7 @@ Joseph S. Myers jsm28@cam.ac.uk
Joshua G. Hale jgh.emc@gmail.com
Juan Carlos Hurtado adso.lists@gmail.com
Jules Colding colding@42tools.com
+Julian C. Cummings cummings@cacr.caltech.edu
Julian Onions j.onions@nexor.co.uk
Julien Danjou acid@debian.org
Julien Élie julien@trigofacile.com
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 9f68a61e..5aa95a37 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -8383,6 +8383,51 @@ The extension, or @samp{unknown}, is cached in the
@code{ac_cv_fc_module_ext} variable.
@end defmac
+@defmac AC_FC_MODULE_FLAG (@ovar{action-if-sucess}, @
+ @dvar{action-if-failure, AC_MSG_FAILURE})
+@acindex{FC_MODULE_FLAG}
+@caindex fc_module_flag
+@ovindex FC_MODINC
+@ovindex ac_empty
+
+Find the compiler flag to include Fortran 90 module information from
+another directory, and store that in the @code{FC_MODINC} variable.
+Call @var{action-if-success} (defaults to nothing) if successful, and
+set @code{FC_MODINC} to empty and call @var{action-if-failure} (defaults
+to exiting with an error message) if not.
+
+Most Fortran 90 compilers provide a way to specify module directories.
+Some have separate flags for the directory to write module files to,
+and directories to search them in, whereas others only allow writing to
+the current directory or to the first directory specified in the include
+path. Further, with some compilers, the module search path and the
+preprocessor search path can only be modified with the same flag. Thus,
+for portability, write module files to the current directory only and
+list that as first directory in the search path.
+
+There may be no whitespace between @code{FC_MODINC} and the following
+directory name, but @code{FC_MODINC} may contain trailing white space.
+For example, if you use Automake and would like to search @file{../lib}
+for module files, you can use the following:
+
+@example
+AM_FCFLAGS = $(FC_MODINC). $(FC_MODINC)../lib
+@end example
+
+Inside @command{configure} tests, you can use:
+
+@example
+if test -n "$FC_MODINC"; then
+ FCFLAGS="$FCFLAGS $FC_MODINC. $FC_MODINC../lib"
+fi
+@end example
+
+The flag is cached in the @code{ac_cv_fc_module_flag} variable.
+The substituted value of @code{FC_MODINC} may refer to the
+@code{ac_empty} dummy placeholder empty variable, to avoid losing
+the significant trailing whitespace in a @file{Makefile}.
+@end defmac
+
@node Go Compiler
@subsection Go Compiler Characteristics
diff --git a/lib/autoconf/fortran.m4 b/lib/autoconf/fortran.m4
index 864fcaa5..25b05403 100644
--- a/lib/autoconf/fortran.m4
+++ b/lib/autoconf/fortran.m4
@@ -1559,3 +1559,80 @@ if test "$FC_MODEXT" = unknown; then
fi
AC_SUBST([FC_MODEXT])dnl
])
+
+
+# AC_FC_MODULE_FLAG([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
+# ---------------------------------------------------------------------
+# Find a flag to include Fortran 90 modules from another directory.
+# If successful, run ACTION-IF-SUCCESS (defaults to nothing), otherwise
+# run ACTION-IF-FAILURE (defaults to failing with an error message).
+# The module flag is cached in the ac_cv_fc_module_flag variable.
+# It may contain significant trailing whitespace.
+#
+# Known flags:
+# gfortran: -Idir, -I dir (-M dir, -Mdir (deprecated), -Jdir for writing)
+# g95: -I dir (-fmod=dir for writing)
+# SUN: -Mdir, -M dir (-moddir=dir for writing;
+# -Idir for includes is also searched)
+# HP: -Idir, -I dir (+moddir=dir for writing)
+# IBM: -Idir (-qmoddir=dir for writing)
+# Intel: -Idir -I dir (-mod dir for writing)
+# Absoft: -pdir
+# Lahey: -mod dir
+# Cray: -module dir, -p dir (-J dir for writing)
+# -e m is needed to enable writing .mod files at all
+# Compaq: -Idir
+# NAGWare: -I dir
+# PathScale: -I dir (but -module dir is looked at first)
+# Portland: -module dir (first -module also names dir for writing)
+# Fujitsu: -Am -Idir (-Mdir for writing is searched first, then '.', then -I)
+# (-Am indicates how module information is saved)
+AC_DEFUN([AC_FC_MODULE_FLAG],[
+AC_CACHE_CHECK([Fortran 90 module inclusion flag], [ac_cv_fc_module_flag],
+[AC_LANG_PUSH([Fortran])
+ac_cv_fc_module_flag=unknown
+mkdir conftest.dir
+cd conftest.dir
+AC_COMPILE_IFELSE([[
+ module conftest_module
+ contains
+ subroutine conftest_routine
+ write(*,'(a)') 'gotcha!'
+ end subroutine
+ end module]],
+ [cd ..
+ ac_fc_module_flag_FCFLAGS_save=$FCFLAGS
+ # Flag ordering is significant for gfortran and Sun.
+ for ac_flag in -M -I '-I ' '-M ' -p '-mod ' '-module ' '-Am -I'; do
+ # Add the flag twice to prevent matching an output flag.
+ FCFLAGS="$ac_fc_module_flag_FCFLAGS_save ${ac_flag}conftest.dir ${ac_flag}conftest.dir"
+ AC_COMPILE_IFELSE([[
+ program main
+ use conftest_module
+ call conftest_routine
+ end program]],
+ [ac_cv_fc_module_flag="$ac_flag"])
+ if test "$ac_cv_fc_module_flag" != unknown; then
+ break
+ fi
+ done
+ FCFLAGS=$ac_fc_module_flag_FCFLAGS_save
+])
+rm -rf conftest.dir
+AC_LANG_POP([Fortran])
+])
+if test "$ac_cv_fc_module_flag" != unknown; then
+ FC_MODINC=$ac_cv_fc_module_flag
+ $1
+else
+ FC_MODINC=
+ m4_default([$2],
+ [AC_MSG_ERROR([unable to find compiler flag for module search path])])
+fi
+AC_SUBST([FC_MODINC])
+# Ensure trailing whitespace is preserved in a Makefile.
+AC_SUBST([ac_empty], [""])
+AC_CONFIG_COMMANDS_PRE([case $FC_MODINC in #(
+ *\ ) FC_MODINC=$FC_MODINC'${ac_empty}' ;;
+esac])dnl
+])
diff --git a/tests/fortran.at b/tests/fortran.at
index 4986ee48..208c4666 100644
--- a/tests/fortran.at
+++ b/tests/fortran.at
@@ -991,3 +991,74 @@ AT_CHECK([./prog || exit 1], [1], [ignore], [ignore])
AT_CHECK([$MAKE clean], [], [ignore], [ignore])
AT_CLEANUP
+
+
+## ------------------ ##
+## AC_FC_MODULE_FLAG. ##
+## ------------------ ##
+
+AT_SETUP([AC_FC_MODULE_FLAG])
+
+AT_DATA([Makefile.in],
+[[OBJEXT = @OBJEXT@
+EXEEXT = @EXEEXT@
+LIBS = @LIBS@
+ac_empty = @ac_empty@
+FC = @FC@
+FC_MODEXT = @FC_MODEXT@
+FC_MODINC = @FC_MODINC@
+FCFLAGS = @FCFLAGS@
+FCFLAGS_f = @FCFLAGS_f@
+
+prog$(EXEEXT): sub/mod.$(OBJEXT) prog.$(OBJEXT)
+ $(FC) $(FCFLAGS) -o $@ prog.$(OBJEXT) sub/mod.$(OBJEXT) $(LIBS)
+
+sub/mod.$(OBJEXT): sub/mod.f
+ cd sub && $(FC) $(FCFLAGS) -c $(FCFLAGS_f) mod.f
+
+# Depend on the object, for the module dependency.
+prog.$(OBJEXT): prog.f sub/mod.$(OBJEXT)
+ $(FC) $(FCFLAGS) $(FC_MODINC). $(FC_MODINC)sub -c $(FCFLAGS_f) $<
+
+clean:
+ -test -z "$(FC_MODEXT)" || rm -f *.$(FC_MODEXT) sub/*.$(FC_MODEXT)
+ -rm -f *.$(OBJEXT) sub/*.$(OBJEXT) prog$(EXEEXT)
+]])
+
+AT_DATA([configure.ac],
+[[AC_INIT
+AC_PROG_FC
+AC_FC_SRCEXT([f])
+AC_FC_MODULE_FLAG
+if test -n "$FC_MODINC"; then
+ FCFLAGS="$FCFLAGS $FC_MODINC. ${FC_MODINC}sub"
+fi
+AC_FC_MODULE_EXTENSION
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+]])
+
+mkdir sub
+
+AT_DATA([sub/mod.f],
+[[ module foobar
+ end module foobar
+]])
+
+AT_DATA([prog.f],
+[[ program main
+ use foobar
+ end program
+]])
+
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE
+: "${MAKE=make}"
+AT_CHECK([$MAKE], [], [stdout], [stderr])
+# Both the FCFLAGS setting from configure.ac, and the Makefile rule
+# should add to the module search path.
+AT_CHECK([grep 'sub .*sub ' stdout stderr], [], [ignore])
+AT_CHECK([./prog], [], [ignore], [ignore])
+AT_CHECK([$MAKE clean], [], [ignore], [ignore])
+
+AT_CLEANUP
diff --git a/tests/local.at b/tests/local.at
index e08d8b19..55c7c361 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -317,7 +317,7 @@ if test -f state-env.before && test -f state-env.after; then
[cross_compiling|U],
[interpval|PATH_SEPARATOR],
[F77_DUMMY_MAIN|f77_(case|underscore)],
- [FC(_DUMMY_MAIN|FLAGS|LIBS|FLAGS_f|_MODEXT)?],
+ [FC(_DUMMY_MAIN|FLAGS|LIBS|FLAGS_f|_MODEXT|_MODINC)?],
[ALLOCA|GETLOADAVG_LIBS|KMEM_GROUP|NEED_SETGID|POW_LIB],
[AWK|LEX|LEXLIB|LEX_OUTPUT_ROOT|LN_S|M4|MKDIR_P|RANLIB|SET_MAKE|YACC],
[GREP|[EF]GREP|SED],