autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/2] New macro AC_FC_MODULE_FLAG: Fortran 90 module include path.


From: Ralf Wildenhues
Subject: [PATCH 2/2] New macro AC_FC_MODULE_FLAG: Fortran 90 module include path.
Date: Sun, 6 Mar 2011 13:54:07 +0100
User-agent: Mutt/1.5.20 (2010-08-04)

* 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.
* THANKS: Update.
---
 ChangeLog               |   16 ++++++++++
 doc/autoconf.texi       |   45 ++++++++++++++++++++++++++++
 lib/autoconf/fortran.m4 |   75 +++++++++++++++++++++++++++++++++++++++++++++++
 tests/fortran.at        |   71 ++++++++++++++++++++++++++++++++++++++++++++
 tests/local.at          |    2 +-
 5 files changed, 208 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9570ce7..fabd8fb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,20 @@
 2011-03-06  Luc Maisonobe <...>
+           Julian C. Cummings <...>
+           Alexander Pletzer <...>
+           Ralf Wildenhues  <...>
+
+       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.
+       * THANKS: Update.
+
+2011-03-06  Luc Maisonobe <...>
            Alexander Pletzer <...>
            Ralf Wildenhues  <...>
 
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index f3a87d1..65fb9bb 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -8378,6 +8378,51 @@ Fortran Compiler
 @code{ac_cv_fc_module_ext} variable.
 @end defmac
 
address@hidden AC_FC_MODULE_FLAG (@ovar{action-if-sucess}, @
+  @dvar{action-if-failure, AC_MSG_FAILURE})
address@hidden
address@hidden fc_module_flag
address@hidden FC_MODINC
address@hidden 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:
+
address@hidden
+AM_FCFLAGS = $(FC_MODINC). $(FC_MODINC)../lib
address@hidden example
+
+Inside @command{configure} tests, you can use:
+
address@hidden
+if test -n "$FC_MODINC"; then
+  FCFLAGS="$FCFLAGS $FC_MODINC. $FC_MODINC../lib"
+fi
address@hidden 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
address@hidden dummy placeholder empty variable, to avoid losing
+the significant trailing whitespace in a @file{Makefile}.
address@hidden defmac
+
 
 @node Go Compiler
 @subsection Go Compiler Characteristics
diff --git a/lib/autoconf/fortran.m4 b/lib/autoconf/fortran.m4
index 864fcaa..b03af38 100644
--- a/lib/autoconf/fortran.m4
+++ b/lib/autoconf/fortran.m4
@@ -1559,3 +1559,78 @@ 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 (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)
+# 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)
+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_cv_fc_module_flag=unknown
+   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
+     FCFLAGS="$ac_fc_module_flag_FCFLAGS_save ${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 4986ee4..208c466 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 e08d8b1..55c7c36 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],
-- 
1.7.4.1.203.g07873




reply via email to

[Prev in Thread] Current Thread [Next in Thread]