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.

Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
This commit is contained in:
Ralf Wildenhues 2010-07-10 18:40:43 +02:00
parent 66fd9a3750
commit 06089e7f3c
5 changed files with 179 additions and 4 deletions

View File

@ -1,5 +1,11 @@
2010-07-10 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
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.
Fix wording about AC_CONFIG_SUBDIRS warning.
* doc/autoconf.texi (Subdirectories): We warn, not error, about
nonexistent config subdirs, but only at configure run time.

2
NEWS
View File

@ -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.*.

View File

@ -7752,10 +7752,10 @@ are for newer programs that can (or must) compile under the newer
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
@code{AC_FC_FIXEDFORM} (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},
@code{AC_FC_FIXEDFORM}, and @code{AC_FC_LINE_LENGTH} (see below), the
@code{FC} 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 @@ calls @var{action-if-failure} (defaults to exiting with an error
message).
@end defmac
@defmac AC_FC_LINE_LENGTH (@ovar{length}, @ovar{action-if-success}, @
@ovar{action-if-failure})
@acindex{FC_LINE_LENGTH}
The @code{AC_FC_LINE_LENGTH} macro 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).
@end defmac
@node System Services
@section System Services

View File

@ -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

View File

@ -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],
[[prog@EXEEXT@: prog.@OBJEXT@
@FC@ @FCFLAGS@ -o $@ prog.@OBJEXT@ @LIBS@
.SUFFIXES: .f .@OBJEXT@
.f.@OBJEXT@:
@FC@ @FCFLAGS@ -c @FCFLAGS_f@ $<
clean:
rm -f *.@OBJEXT@ prog@EEXEXT@
]])
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