autoconf-patches
[Top][All Lists]
Advanced

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

Long lines in Fortran source code


From: Ralf Wildenhues
Subject: Long lines in Fortran source code
Date: Sat, 10 Jul 2010 09:41:04 +0200
User-agent: Mutt/1.5.20 (2010-04-22)

Tested gfortran ifort sunf95.  This makes a nice addition to
AC_FC_{FIXED,FREE}FORM.  OK to commit?

The testsuite addition is a wee bit weak in that configure will exit 77
when it can't find a suitable flag, and thus the test will skip but not
fail.  This is in line with some of the other Fortran macros though.

Another limitation is that the cache variable used is the same for any
of the lengths, and even for fixed- and free-form source code.  So
mixing them in one project is still a bit ugly in that it requires
unsetting cache variables and munging *FCFLAGS yourself.  This pattern
goes all through the Fortran support however; e.g., several flags depend
on the source extension used, and so on.  I'm not sure how a most
general fix would have to look like, and I think we should be able to
cross that bridge when we come to it.  Probably the easiest way to just
document the cache variables involved, so the user can safely do the
overriding when needed.

I'm not quite sure whether an AC_F77_LINE_LENGTH would be needed as
well.  I'm not too enthusiastic.

Next Fortran items on the plan are module extension, include and
generate path, but those might be sufficient to have in Automake
only, let's see ...

Thanks,
Ralf

    New Fortran macro AC_FC_LINE_LENGTH.
    
    * lib/autoconf/fortran.m4 (AC_FC_LINE_LENGTH): New macro.
    * doc/autoconf.texi (Fortran Compiler): Document it.
    * tests/fortran.at (AC_FC_LINE_LENGTH): New test.
    * NEWS: Update.

diff --git a/NEWS b/NEWS
index 6256d40..a022881 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,8 @@ GNU Autoconf NEWS - User visible changes.
 ** AC_CHECK_SIZEOF of a pointer type works again.  Regression introduced in
    2.66.
 
+** New macro AC_FC_LINE_LENGTH to accept long Fortran source code lines.
+
 * Major changes in Autoconf 2.66 (2010-07-02) [stable]
   Released by Eric Blake, based on git versions 2.65.*.
 
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index ff09d00..68dceb0 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -7752,10 +7752,10 @@ Fortran Compiler
 Fortran standards, and have output variables like @code{FC},
 @code{FCFLAGS}, and @code{FCLIBS}.
 
-Except for the macros @code{AC_FC_SRCEXT}, @code{AC_FC_FREEFORM}, and
address@hidden (see below), the @code{FC} and @code{F77} macros
-behave almost identically, and so they are documented together in this
-section.
+Except for the macros @code{AC_FC_SRCEXT}, @code{AC_FC_FREEFORM},
address@hidden, and @code{AC_FC_LINE_LENGTH} (see below), the
address@hidden and @code{F77} macros behave almost identically, and so they
+are documented together in this section.
 
 
 @defmac AC_PROG_F77 (@ovar{compiler-search-list})
@@ -8133,6 +8133,24 @@ Fortran Compiler
 message).
 @end defmac
 
address@hidden AC_FC_LINE_LENGTH (@ovar{length}, @ovar{action-if-success}, @
+  @ovar{action-if-failure})
address@hidden
+
+The @code{AC_FC_LINE_LENGTH} tries to ensure that the Fortran compiler
+(@code{$FC}) accepts long source code lines.  The @var{length} argument
+may be given as 80, 132, or unlimited, and defaults to 132.  Note that
+line lengths above 254 columns are not portable, and some compilers
+do not accept more than 132 columns at least for fixed format source.
+If necessary, it may add some additional flags to @code{FCFLAGS}.
+
+If @code{AC_FC_LINE_LENGTH} succeeds in compiling fixed-form source, it
+calls @var{action-if-success} (defaults to nothing).  If it fails, it
+calls @var{action-if-failure} (defaults to exiting with an error
+message).
address@hidden defmac
+
+
 @node System Services
 @section System Services
 
diff --git a/lib/autoconf/fortran.m4 b/lib/autoconf/fortran.m4
index f059546..32be8a1 100644
--- a/lib/autoconf/fortran.m4
+++ b/lib/autoconf/fortran.m4
@@ -1261,3 +1261,84 @@ else
 fi
 AC_LANG_POP([Fortran])dnl
 ])# AC_FC_FIXEDFORM
+
+
+# AC_FC_LINE_LENGTH([LENGTH], [ACTION-IF-SUCCESS],
+#                  [ACTION-IF-FAILURE = FAILURE])
+# ------------------------------------------------
+# Look for a compiler flag to make the Fortran (FC) compiler accept long lines
+# in the current (free- or fixed-format) source code, and adds it to FCFLAGS.
+# The optional LENGTH may be 80, 132 (default), or `unlimited' for longer
+# lines.  Note that line lengths above 254 columns are not portable, and some
+# compilers (hello ifort) do not accept more than 132 columns at least for
+# fixed format.  Call ACTION-IF-SUCCESS (defaults to nothing) if successful
+# (i.e. can compile code using new extension) and ACTION-IF-FAILURE (defaults
+# to failing with an error message) if not.  (Defined via DEFUN_ONCE to
+# prevent flag from being added to FCFLAGS multiple times.)
+# You should call AC_FC_FREEFORM or AC_FC_FIXEDFORM to set the desired format
+# prior to using this macro.
+#
+# The known flags are:
+# -f{free,fixed}-line-length-N with N 72, 80, 132, or 0 or none for none.
+# -ffree-line-length-none: GNU gfortran
+#       -qfixed=132 80 72: IBM compiler (xlf)
+#                -Mextend: Cray
+#            -132 -80 -72: Intel compiler (ifort)
+#                          Needs to come before -extend_source because ifort
+#                          accepts that as well with an optional parameter and
+#                          doesn't fail but only warns about unknown arguments.
+#          -extend_source: SGI compiler
+#     -W NN (132, 80, 72): Absoft Fortran
+#          +extend_source: HP Fortran (254 in either form, default is 72 fixed,
+#                         132 free)
+#                   -wide: Lahey/Fujitsu Fortran (255 cols in fixed form)
+#                      -e: Sun Fortran compiler (132 characters)
+AC_DEFUN_ONCE([AC_FC_LINE_LENGTH],
+[AC_LANG_PUSH([Fortran])dnl
+m4_case(m4_default([$1], [132]),
+  [unlimited], [ac_fc_line_len_string=unlimited
+                      ac_fc_line_len=0
+                       ac_fc_line_length_test='
+      subroutine longer_than_132(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,'\
+'arg9,arg10,arg11,arg12,arg13,arg14,arg15,arg16,arg17,arg18,arg19)'],
+  [132],            [ac_fc_line_len=132
+                      ac_fc_line_length_test='
+      subroutine longer_than_80(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,'\
+'arg10)'],
+  [80],             [ac_fc_line_len=80
+                      ac_fc_line_length_test='
+      subroutine 
longer_than_72(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)'],
+  [m4_warning([Invalid length argument `$1'])])
+: ${ac_fc_line_len_string=$ac_fc_line_len}
+AC_CACHE_CHECK(
+[for Fortran flag needed to accept $ac_fc_line_len_string column source lines],
+              [ac_cv_fc_line_length],
+[ac_cv_fc_line_length=unknown
+ac_fc_line_length_FCFLAGS_save=$FCFLAGS
+for ac_flag in none \
+              -ffree-line-length-none -ffixed-line-length-none \
+              -ffree-line-length-$ac_fc_line_len \
+              -ffixed-line-length-$ac_fc_line_len \
+              -qfixed=$ac_fc_line_len -Mextend \
+              -$ac_fc_line_len -extend_source \
+              "-W $ac_fc_line_len" +extend_source -wide -e
+do
+  test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_line_length_FCFLAGS_save 
$ac_flag"
+  AC_COMPILE_IFELSE([$ac_fc_line_length_test
+      end subroutine],
+                   [ac_cv_fc_line_length=$ac_flag; break])
+done
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+FCFLAGS=$ac_fc_line_length_FCFLAGS_save
+])
+if test "x$ac_cv_fc_line_length" = xunknown; then
+  m4_default([$3],
+            [AC_MSG_ERROR([Fortran does not accept long source lines], 77)])
+else
+  if test "x$ac_cv_fc_line_length" != xnone; then
+    FCFLAGS="$FCFLAGS $ac_cv_fc_line_length"
+  fi
+  $2
+fi
+AC_LANG_POP([Fortran])dnl
+])# AC_FC_LINE_LENGTH
diff --git a/tests/fortran.at b/tests/fortran.at
index 24d2a61..990968e 100644
--- a/tests/fortran.at
+++ b/tests/fortran.at
@@ -874,3 +874,71 @@ AT_CHECK([$MAKE], [], [ignore], [ignore])
 dnl AT_CHECK([./prog])
 
 AT_CLEANUP
+
+
+## ------------------ ##
+## AC_FC_LINE_LENGTH. ##
+## ------------------ ##
+
+AT_SETUP([AC_FC_LINE_LENGTH])
+
+AT_DATA([Makefile.in],
address@hidden@: address@hidden@
+       @FC@ @FCFLAGS@ -o $@ address@hidden@ @LIBS@
+
+.SUFFIXES: .f address@hidden@
address@hidden@:
+       @FC@ @FCFLAGS@ -c @FCFLAGS_f@ $<
+
+clean:
+       rm -f address@hidden@ address@hidden@
+]])
+
+line_80=\
+'subroutine foo(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11)'
+line_132=\
+'subroutine foo(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,'\
+'arg12,arg13,arg14,arg15,arg16,arg17,arg18,arg19)'
+line_254=\
+'subroutine foo(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,'\
+'arg12,arg13,arg14,arg15,arg16,arg17,arg18,arg19,arg20,arg21,arg22,arg23,'\
+'arg24,arg25,arg26,arg27,arg28,arg29,arg30,arg31,arg32,arg33,arg34,arg35,'\
+'arg36,arg37,arg38,arg39,arg40)'
+
+for len in 80 132 254
+do
+  if test $len -eq 254; then arg=unlimited; else arg=$len; fi
+  eval long_line=\$line_$len
+
+  # Try free-form first, it has a bigger chance of succeeding.
+  for fixed_or_free in FREEFORM FIXEDFORM
+  do
+
+    cat >configure.ac <<EOF
+AC_INIT
+AC_PROG_FC
+AC_FC_SRCEXT([f])
+AC_FC_$fixed_or_free
+AC_FC_LINE_LENGTH([$arg])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+EOF
+
+    cat >prog.f <<EOF
+       $long_line
+       end subroutine
+       program main
+       end program
+EOF
+
+    AT_CHECK_AUTOCONF
+    AT_CHECK_CONFIGURE
+    : ${MAKE=make}
+    AT_CHECK([$MAKE], [], [ignore], [ignore])
+    dnl AT_CHECK([./prog])
+    AT_CHECK([$MAKE clean], [], [ignore], [ignore])
+
+  done
+done
+
+AT_CLEANUP



reply via email to

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