autoconf-patches
[Top][All Lists]
Advanced

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

[PATCH 3/2] New macro AC_FC_MODULE_OUTPUT_FLAG: module output directory.


From: Ralf Wildenhues
Subject: [PATCH 3/2] New macro AC_FC_MODULE_OUTPUT_FLAG: module output directory.
Date: Sat, 2 Apr 2011 14:46:58 +0200
User-agent: Mutt/1.5.20 (2010-08-04)

* lib/autoconf/fortran.m4 (AC_FC_MODULE_OUTPUT_FLAG): New macro.
* doc/autoconf.texi (Fortran Compiler): Document it.
* tests/local.at (_AT_CHECK_ENV): Do not complain about
FC_MODOUT.
* NEWS: Update.
---

Hello,

I gathered that it would make sense to also provide a macro to set the
module output directory, to complete the set of macros.  It is not quite
as portable, as there are a couple of odd (mostly old) Fortran compilers
out there that allow to adjust inclusion but not output directory, but
if projects won't be portable to them anyway, there's little reason not
to use this functionality.

Pushed to master.

I forgot: I added short NEWS entries to each of the patches, as seen in
the diff below.

Thanks,
Ralf

 ChangeLog               |    9 +++++++
 NEWS                    |    1 +
 doc/autoconf.texi       |   30 ++++++++++++++++++++++
 lib/autoconf/fortran.m4 |   62 +++++++++++++++++++++++++++++++++++++++++++++++
 tests/local.at          |    2 +-
 5 files changed, 103 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index bdbce27..2ac8acf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-04-02  Ralf Wildenhues  <address@hidden>
+
+       New macro AC_FC_MODULE_OUTPUT_FLAG: module output directory.
+       * lib/autoconf/fortran.m4 (AC_FC_MODULE_OUTPUT_FLAG): New macro.
+       * doc/autoconf.texi (Fortran Compiler): Document it.
+       * tests/local.at (_AT_CHECK_ENV): Do not complain about
+       FC_MODOUT.
+       * NEWS: Update.
+
 2011-04-02  Luc Maisonobe  <address@hidden>
            Julian C. Cummings  <address@hidden>
            Alexander Pletzer  <address@hidden>
diff --git a/NEWS b/NEWS
index ea4d586..633592c 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,7 @@ GNU Autoconf NEWS - User visible changes.
     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
+    AC_FC_MODULE_OUTPUT_FLAG for the Fortran 90 module output directory flag
 
 * Noteworthy changes in release 2.68 (2010-09-22) [stable]
   Released by Eric Blake, based on git versions 2.67.*.
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 5aa95a3..cfedf1d 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -8428,6 +8428,36 @@ Fortran Compiler
 the significant trailing whitespace in a @file{Makefile}.
 @end defmac
 
address@hidden AC_FC_MODULE_OUTPUT_FLAG (@ovar{action-if-sucess}, @
+  @dvar{action-if-failure, AC_MSG_FAILURE})
address@hidden
address@hidden fc_module_output_flag
address@hidden FC_MODOUT
+
+Find the compiler flag to write Fortran 90 module information to
+another directory, and store that in the @code{FC_MODOUT} variable.
+Call @var{action-if-success} (defaults to nothing) if successful, and
+set @code{FC_MODOUT} to empty and call @var{action-if-failure} (defaults
+to exiting with an error message) if not.
+
+Not all Fortran 90 compilers write module files, and of those that do,
+not all allow writing to a directory other than the current one, nor
+do all have separate flags for writing and reading; see the description
+of @code{AC_FC_MODULE_FLAG} above.  If you need to be able to write to
+another directory, for maximum portability use @code{FC_MODOUT} before
+any @code{FC_MODINC} and include both the current directory and the one
+you write to in the search path:
+
address@hidden
+AM_FCFLAGS = $(FC_MODOUT)../mod $(FC_MODINC)../mod $(FC_MODINC). @dots{}
address@hidden example
+
+The flag is cached in the @code{ac_cv_fc_module_output_flag} variable.
+The substituted value of @code{FC_MODOUT} 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 25b0540..9a37604 100644
--- a/lib/autoconf/fortran.m4
+++ b/lib/autoconf/fortran.m4
@@ -1636,3 +1636,65 @@ AC_CONFIG_COMMANDS_PRE([case $FC_MODINC in #(
   *\ ) FC_MODINC=$FC_MODINC'${ac_empty}' ;;
 esac])dnl
 ])
+
+
+# AC_FC_MODULE_OUTPUT_FLAG([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
+# ----------------------------------------------------------------------------
+# Find a flag to write Fortran 90 module information to 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_output_flag variable.
+# It may contain significant trailing whitespace.
+#
+# For known flags, see the documentation of AC_FC_MODULE_FLAG above.
+AC_DEFUN([AC_FC_MODULE_OUTPUT_FLAG],[
+AC_CACHE_CHECK([Fortran 90 module output flag], [ac_cv_fc_module_output_flag],
+[AC_LANG_PUSH([Fortran])
+mkdir conftest.dir conftest.dir/sub
+cd conftest.dir
+ac_cv_fc_module_output_flag=unknown
+ac_fc_module_output_flag_FCFLAGS_save=$FCFLAGS
+# Flag ordering is significant: put flags late which some compilers use
+# for the search path.
+for ac_flag in -J '-J ' -fmod= -moddir= +moddir= -qmoddir= '-mod ' \
+             '-module ' -M '-Am -M' '-e m -J '; do
+  FCFLAGS="$ac_fc_module_output_flag_FCFLAGS_save ${ac_flag}sub"
+  AC_COMPILE_IFELSE([[
+      module conftest_module
+      contains
+      subroutine conftest_routine
+      write(*,'(a)') 'gotcha!'
+      end subroutine
+      end module]],
+    [cd sub
+     AC_COMPILE_IFELSE([[
+      program main
+      use conftest_module
+      call conftest_routine
+      end program]],
+       [ac_cv_fc_module_output_flag="$ac_flag"])
+     cd ..
+     if test "$ac_cv_fc_module_output_flag" != unknown; then
+       break
+     fi])
+done
+FCFLAGS=$ac_fc_module_output_flag_FCFLAGS_save
+cd ..
+rm -rf conftest.dir
+AC_LANG_POP([Fortran])
+])
+if test "$ac_cv_fc_module_output_flag" != unknown; then
+  FC_MODOUT=$ac_cv_fc_module_output_flag
+  $1
+else
+  FC_MODOUT=
+  m4_default([$2],
+    [AC_MSG_ERROR([unable to find compiler flag to write module information 
to])])
+fi
+AC_SUBST([FC_MODOUT])
+# Ensure trailing whitespace is preserved in a Makefile.
+AC_SUBST([ac_empty], [""])
+AC_CONFIG_COMMANDS_PRE([case $FC_MODOUT in #(
+  *\ ) FC_MODOUT=$FC_MODOUT'${ac_empty}' ;;
+esac])dnl
+])
diff --git a/tests/local.at b/tests/local.at
index 55c7c36..a2efce3 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|_MODINC)?],
+      [FC(_DUMMY_MAIN|FLAGS|LIBS|FLAGS_f|_MODEXT|_MODINC|_MODOUT)?],
       [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.227.gadfe4




reply via email to

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