]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
New macro AC_FC_MODULE_FLAG: Fortran 90 module include path.
authorLuc Maisonobe <luc@spaceroots.org>
Sat, 2 Apr 2011 12:17:55 +0000 (14:17 +0200)
committerRalf Wildenhues <Ralf.Wildenhues@gmx.de>
Sat, 2 Apr 2011 12:18:47 +0000 (14:18 +0200)
* 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>
ChangeLog
NEWS
THANKS
doc/autoconf.texi
lib/autoconf/fortran.m4
tests/fortran.at
tests/local.at

index 5e6f54d5cd83237f053abafeb0354d10dadb0dff..bdbce27c758d7adb79475670e5be39f86b3b18a9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+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 78539773ce3a16885c4ad114de40111a0450fb78..ea4d58689bcb7027f2920d2eadc493542a528c47 100644 (file)
--- 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 def09c8b9801229384d555db702193b88b71ddab..7679b054f9b4fc6509152d7ff559075fd60563a2 100644 (file)
--- 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
index 9f68a61e06e0ef534f9da484d2e2092ffe97b00d..5aa95a37f46a55b7b1a1d665189cc6a340ba69c4 100644 (file)
@@ -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
index 864fcaa590831ca5a4b055568fac09ef4589bb27..25b05403aea747696ac200613124261ca2b1cc6b 100644 (file)
@@ -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
+])
index 4986ee4840ebbce5e74b764b50339798bf54650c..208c4666d97cbad055667b825de622b9f73eae05 100644 (file)
@@ -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
index e08d8b19e44164a4e8c73dcbe2ecbf28a4e99b10..55c7c3617d0376d395d4bbff4ab5036cdf918b75 100644 (file)
@@ -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],