1 # This file is part of Autoconf. -*- Autoconf -*-
2 # Fortran languages support.
3 # Copyright (C) 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 # Free Software Foundation, Inc.
6 # This file is part of Autoconf. This program is free
7 # software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the
9 # Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # Under Section 7 of GPL version 3, you are granted additional
18 # permissions described in the Autoconf Configure Script Exception,
19 # version 3.0, as published by the Free Software Foundation.
21 # You should have received a copy of the GNU General Public License
22 # and a copy of the Autoconf Configure Script Exception along with
23 # this program; see the files COPYINGv3 and COPYING.EXCEPTION
24 # respectively. If not, see <http://www.gnu.org/licenses/>.
26 # Written by David MacKenzie, with help from
27 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
28 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
37 # 1. Language selection
38 # and routines to produce programs in a given language.
40 # 2. Producing programs in a given language.
42 # 3. Looking for a compiler
43 # And possibly the associated preprocessor.
45 # 4. Compilers' characteristics.
53 # Fortran vs. Fortran 77:
54 # This file contains macros for both "Fortran 77" and "Fortran", where
55 # the former is the "classic" autoconf Fortran interface and is intended
56 # for legacy F77 codes, while the latter is intended to support newer Fortran
57 # dialects. Fortran 77 uses environment variables F77, FFLAGS, and FLIBS,
58 # while Fortran uses FC, FCFLAGS, and FCLIBS. For each user-callable AC_*
59 # macro, there is generally both an F77 and an FC version, where both versions
60 # share the same _AC_*_FC_* backend. This backend macro requires that
61 # the appropriate language be AC_LANG_PUSH'ed, and uses _AC_LANG_ABBREV and
62 # _AC_LANG_PREFIX in order to name cache and environment variables, etc.
66 ## ------------------- ##
67 ## 0. Utility macros. ##
68 ## ------------------- ##
71 # _AC_LIST_MEMBER_IF(ELEMENT, LIST, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
72 # ---------------------------------------------------------------------------
74 # Processing the elements of a list is tedious in shell programming,
75 # as lists tend to be implemented as space delimited strings.
77 # This macro searches LIST for ELEMENT, and executes ACTION-IF-FOUND
78 # if ELEMENT is a member of LIST, otherwise it executes
79 # ACTION-IF-NOT-FOUND.
80 AC_DEFUN([_AC_LIST_MEMBER_IF],
81 dnl Do some sanity checking of the arguments.
82 [m4_if([$1], , [m4_fatal([$0: missing argument 1])],
83 [$2], , [m4_fatal([$0: missing argument 2])])]dnl
86 if test x"$1" = x"$ac_i"; then
92 AS_IF([test x"$ac_exists" = xtrue], [$3], [$4])[]dnl
93 ])# _AC_LIST_MEMBER_IF
96 # _AC_LINKER_OPTION(LINKER-OPTIONS, SHELL-VARIABLE)
97 # -------------------------------------------------
99 # Specifying options to the compiler (whether it be the C, C++ or
100 # Fortran 77 compiler) that are meant for the linker is compiler
101 # dependent. This macro lets you give options to the compiler that
102 # are meant for the linker in a portable, compiler-independent way.
104 # This macro take two arguments, a list of linker options that the
105 # compiler should pass to the linker (LINKER-OPTIONS) and the name of
106 # a shell variable (SHELL-VARIABLE). The list of linker options are
107 # appended to the shell variable in a compiler-dependent way.
109 # For example, if the selected language is C, then this:
111 # _AC_LINKER_OPTION([-R /usr/local/lib/foo], foo_LDFLAGS)
113 # will expand into this if the selected C compiler is gcc:
115 # foo_LDFLAGS="-Xlinker -R -Xlinker /usr/local/lib/foo"
117 # otherwise, it will expand into this:
119 # foo_LDFLAGS"-R /usr/local/lib/foo"
121 # You are encouraged to add support for compilers that this macro
122 # doesn't currently support.
123 # FIXME: Get rid of this macro.
124 AC_DEFUN([_AC_LINKER_OPTION],
125 [if test "$ac_compiler_gnu" = yes; then
126 for ac_link_opt in $1; do
127 $2="[$]$2 -Xlinker $ac_link_opt"
132 ])# _AC_LINKER_OPTION
136 ## ------------------------ ##
137 ## 1a. Language selection. ##
138 ## ------------------------ ##
141 # AC_LANG(Fortran 77)
142 # -------------------
143 AC_LANG_DEFINE([Fortran 77], [f77], [F], [F77], [],
145 ac_compile='$F77 -c $FFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
146 ac_link='$F77 -o conftest$ac_exeext $FFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
147 ac_compiler_gnu=$ac_cv_f77_compiler_gnu
153 AU_DEFUN([AC_LANG_FORTRAN77], [AC_LANG(Fortran 77)])
158 # Current language must be Fortran or Fortran 77.
159 m4_defun([_AC_FORTRAN_ASSERT],
160 [m4_if(_AC_LANG, [Fortran], [],
161 [m4_if(_AC_LANG, [Fortran 77], [],
162 [m4_fatal([$0: current language is not Fortran: ] _AC_LANG)])])])
167 # Return F77 or FC, depending upon the language.
169 [_AC_FORTRAN_ASSERT()dnl
170 AC_LANG_CASE([Fortran 77], [F77],
175 ## ----------------------- ##
176 ## 2. Producing programs. ##
177 ## ----------------------- ##
180 # AC_LANG_PROGRAM(Fortran 77)([PROLOGUE], [BODY])
181 # -----------------------------------------------
182 # Yes, we discard the PROLOGUE.
183 m4_define([AC_LANG_PROGRAM(Fortran 77)],
185 [m4_warn([syntax], [$0: ignoring PROLOGUE: $1])])dnl
191 # _AC_LANG_IO_PROGRAM(Fortran 77)
192 # -------------------------------
193 # Produce source that performs I/O.
194 m4_define([_AC_LANG_IO_PROGRAM(Fortran 77)],
197 open(unit=9,file='conftest.out')
202 # AC_LANG_CALL(Fortran 77)(PROLOGUE, FUNCTION)
203 # --------------------------------------------
204 # FIXME: This is a guess, help!
205 m4_define([AC_LANG_CALL(Fortran 77)],
206 [AC_LANG_PROGRAM([$1],
210 # AC_LANG_FUNC_LINK_TRY(Fortran 77)(FUNCTION)
211 # -------------------------------------------
212 m4_define([AC_LANG_FUNC_LINK_TRY(Fortran 77)],
216 ## ------------------------ ##
217 ## 1b. Language selection. ##
218 ## ------------------------ ##
223 AC_LANG_DEFINE([Fortran], [fc], [FC], [FC], [Fortran 77],
224 [ac_ext=${ac_fc_srcext-f}
225 ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
226 ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
227 ac_compiler_gnu=$ac_cv_fc_compiler_gnu
231 ## -------------------------------------------- ##
232 ## 3. Looking for Compilers and Preprocessors. ##
233 ## -------------------------------------------- ##
236 # AC_LANG_PREPROC(Fortran 77)
237 # ---------------------------
238 # Find the Fortran 77 preprocessor. Must be AC_DEFUN'd to be AC_REQUIRE'able.
239 AC_DEFUN([AC_LANG_PREPROC(Fortran 77)],
241 [$0: No preprocessor defined for ]_AC_LANG)])
243 # AC_LANG_PREPROC(Fortran)
244 # ------------------------
245 # Find the Fortran preprocessor. Must be AC_DEFUN'd to be AC_REQUIRE'able.
246 AC_DEFUN([AC_LANG_PREPROC(Fortran)],
248 [$0: No preprocessor defined for ]_AC_LANG)])
251 # AC_LANG_COMPILER(Fortran 77)
252 # ----------------------------
253 # Find the Fortran 77 compiler. Must be AC_DEFUN'd to be
255 AC_DEFUN([AC_LANG_COMPILER(Fortran 77)],
256 [AC_REQUIRE([AC_PROG_F77])])
258 # AC_LANG_COMPILER(Fortran)
259 # -------------------------
260 # Find the Fortran compiler. Must be AC_DEFUN'd to be
262 AC_DEFUN([AC_LANG_COMPILER(Fortran)],
263 [AC_REQUIRE([AC_PROG_FC])])
268 # We used to name the cache variable this way.
269 AU_DEFUN([ac_cv_prog_g77],
270 [ac_cv_f77_compiler_gnu])
273 # _AC_FC_DIALECT_YEAR([DIALECT])
274 # ------------------------------
275 # Given a Fortran DIALECT, which is Fortran [YY]YY or simply [YY]YY,
276 # convert to a 4-digit year. The dialect must be one of Fortran 77,
277 # 90, 95, or 2000, currently. If DIALECT is simply Fortran or the
278 # empty string, returns the empty string.
279 AC_DEFUN([_AC_FC_DIALECT_YEAR],
280 [m4_case(m4_bpatsubsts(m4_tolower([$1]), [fortran],[], [ *],[]),
281 [77],[1977], [1977],[1977],
282 [90],[1990], [1990],[1990],
283 [95],[1995], [1995],[1995],
286 [m4_fatal([unknown Fortran dialect])])])
289 # _AC_PROG_FC([DIALECT], [COMPILERS...])
290 # --------------------------------------
291 # DIALECT is a Fortran dialect, given by Fortran [YY]YY or simply [YY]YY,
292 # and must be one of those supported by _AC_FC_DIALECT_YEAR
294 # If DIALECT is supplied, then we search for compilers of that dialect
295 # first, and then later dialects. Otherwise, we search for compilers
296 # of the newest dialect first, and then earlier dialects in increasing age.
297 # This search order is necessarily imperfect because the dialect cannot
298 # always be inferred from the compiler name.
301 # f77/f90/f95: generic compiler names
302 # g77: GNU Fortran 77 compiler
303 # gfortran: GNU Fortran 95+ compiler (released in gcc 4.0)
304 # g95: original gcc-based f95 compiler (gfortran is a fork)
305 # ftn: native Fortran 95 compiler on Cray X1
306 # cf77: native F77 compiler under older Crays (prefer over fort77)
307 # fort77: native F77 compiler under HP-UX (and some older Crays)
308 # frt: Fujitsu F77 compiler
309 # pgf77/pgf90/pghpf/pgf95/pgfortran: Portland Group F77/F90/F95 compilers
310 # xlf/xlf90/xlf95: IBM (AIX) F77/F90/F95 compilers
311 # Prefer xlf9x to the generic names because they do not reject files
312 # with extension `.f'.
313 # lf95: Lahey-Fujitsu F95 compiler
314 # fl32: Microsoft Fortran 77 "PowerStation" compiler
315 # af77: Apogee F77 compiler for Intergraph hardware running CLIX
316 # epcf90: "Edinburgh Portable Compiler" F90
317 # fort: Compaq (now HP) Fortran 90/95 compiler for Tru64 and Linux/Alpha
318 # ifort, previously ifc: Intel Fortran 95 compiler for Linux/x86
319 # efc: Intel Fortran 95 compiler for IA64
320 m4_define([_AC_F95_FC], [gfortran g95 xlf95 f95 fort ifort ifc efc pgfortran pgf95 lf95 ftn])
321 m4_define([_AC_F90_FC], [xlf90 f90 pgf90 pghpf epcf90])
322 m4_define([_AC_F77_FC], [g77 xlf f77 frt pgf77 cf77 fort77 fl32 af77])
323 AC_DEFUN([_AC_PROG_FC],
324 [_AC_FORTRAN_ASSERT()dnl
325 AC_CHECK_TOOLS([]_AC_FC[],
327 m4_case(_AC_FC_DIALECT_YEAR([$1]),
328 [1995], [_AC_F95_FC],
329 [1990], [_AC_F90_FC _AC_F95_FC],
330 [1977], [_AC_F77_FC _AC_F90_FC _AC_F95_FC],
331 [_AC_F95_FC _AC_F90_FC _AC_F77_FC])))
333 # Provide some information about the compiler.
334 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
337 for ac_option in --version -v -V -qversion; do
338 _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
342 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
343 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
344 # If we don't use `.F' as extension, the preprocessor is not run on the
345 # input file. (Note that this only needs to work for GNU compilers.)
348 _AC_LANG_COMPILER_GNU
354 # AC_PROG_F77([COMPILERS...])
355 # ---------------------------
356 # COMPILERS is a space separated list of Fortran 77 compilers to search
357 # for. See also _AC_PROG_FC.
358 AC_DEFUN([AC_PROG_F77],
359 [AC_LANG_PUSH(Fortran 77)dnl
360 AC_ARG_VAR([F77], [Fortran 77 compiler command])dnl
361 AC_ARG_VAR([FFLAGS], [Fortran 77 compiler flags])dnl
362 _AC_ARG_VAR_LDFLAGS()dnl
363 _AC_ARG_VAR_LIBS()dnl
364 _AC_PROG_FC([Fortran 77], [$1])
365 if test $ac_compiler_gnu = yes; then
370 AC_LANG_POP(Fortran 77)dnl
374 # AC_PROG_FC([COMPILERS...], [DIALECT])
375 # -------------------------------------
376 # COMPILERS is a space separated list of Fortran 77 compilers to search
377 # for, and [DIALECT] is an optional dialect. See also _AC_PROG_FC.
378 AC_DEFUN([AC_PROG_FC],
379 [AC_LANG_PUSH(Fortran)dnl
380 AC_ARG_VAR([FC], [Fortran compiler command])dnl
381 AC_ARG_VAR([FCFLAGS], [Fortran compiler flags])dnl
382 _AC_ARG_VAR_LDFLAGS()dnl
383 _AC_ARG_VAR_LIBS()dnl
384 _AC_PROG_FC([$2], [$1])
385 AC_LANG_POP(Fortran)dnl
391 # Check whether -g works, even if F[C]FLAGS is set, in case the package
392 # plays around with F[C]FLAGS (such as to build both debugging and normal
393 # versions of a library), tasteless as that idea is.
394 m4_define([_AC_PROG_FC_G],
395 [_AC_FORTRAN_ASSERT()dnl
396 ac_test_[]_AC_LANG_PREFIX[]FLAGS=${[]_AC_LANG_PREFIX[]FLAGS+set}
397 ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
398 _AC_LANG_PREFIX[]FLAGS=
399 AC_CACHE_CHECK(whether $[]_AC_FC[] accepts -g, ac_cv_prog_[]_AC_LANG_ABBREV[]_g,
400 [_AC_LANG_PREFIX[]FLAGS=-g
401 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
402 [ac_cv_prog_[]_AC_LANG_ABBREV[]_g=yes],
403 [ac_cv_prog_[]_AC_LANG_ABBREV[]_g=no])
405 if test "$ac_test_[]_AC_LANG_PREFIX[]FLAGS" = set; then
406 _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
407 elif test $ac_cv_prog_[]_AC_LANG_ABBREV[]_g = yes; then
408 if test "x$ac_cv_[]_AC_LANG_ABBREV[]_compiler_gnu" = xyes; then
409 _AC_LANG_PREFIX[]FLAGS="-g -O2"
411 _AC_LANG_PREFIX[]FLAGS="-g"
414 if test "x$ac_cv_[]_AC_LANG_ABBREV[]_compiler_gnu" = xyes; then
415 _AC_LANG_PREFIX[]FLAGS="-O2"
417 _AC_LANG_PREFIX[]FLAGS=
425 # Test if the Fortran compiler accepts the options `-c' and `-o'
426 # simultaneously, and define `[F77/FC]_NO_MINUS_C_MINUS_O' if it does not.
428 # The usefulness of this macro is questionable, as I can't really see
429 # why anyone would use it. The only reason I include it is for
430 # completeness, since a similar test exists for the C compiler.
432 # FIXME: it seems like we could merge the C/C++/Fortran versions of this.
433 AC_DEFUN([_AC_PROG_FC_C_O],
434 [_AC_FORTRAN_ASSERT()dnl
435 AC_CACHE_CHECK([whether $[]_AC_FC[] understands -c and -o together],
436 [ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o],
437 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
438 # We test twice because some compilers refuse to overwrite an existing
439 # `.o' file with `-o', although they will create one.
440 ac_try='$[]_AC_FC[] $[]_AC_LANG_PREFIX[]FLAGS -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
442 if _AC_DO_VAR(ac_try) &&
443 test -f conftest2.$ac_objext &&
444 _AC_DO_VAR(ac_try); then
445 ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o=yes
447 ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o=no
450 if test $ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o = no; then
451 AC_DEFINE([]_AC_FC[]_NO_MINUS_C_MINUS_O, 1,
452 [Define to 1 if your Fortran compiler doesn't accept
453 -c and -o together.])
460 AC_DEFUN([AC_PROG_F77_C_O],
461 [AC_REQUIRE([AC_PROG_F77])dnl
462 AC_LANG_PUSH(Fortran 77)dnl
464 AC_LANG_POP(Fortran 77)dnl
470 AC_DEFUN([AC_PROG_FC_C_O],
471 [AC_REQUIRE([AC_PROG_FC])dnl
472 AC_LANG_PUSH(Fortran)dnl
474 AC_LANG_POP(Fortran)dnl
479 ## ------------------------------- ##
480 ## 4. Compilers' characteristics. ##
481 ## ------------------------------- ##
484 # _AC_PROG_FC_V_OUTPUT([FLAG = $ac_cv_prog_{f77/fc}_v])
485 # -----------------------------------------------------
486 # Link a trivial Fortran program, compiling with a verbose output FLAG
487 # (whose default value, $ac_cv_prog_{f77/fc}_v, is computed by
488 # _AC_PROG_FC_V), and return the output in $ac_{f77/fc}_v_output. This
489 # output is processed in the way expected by _AC_FC_LIBRARY_LDFLAGS,
490 # so that any link flags that are echoed by the compiler appear as
491 # space-separated items.
492 AC_DEFUN([_AC_PROG_FC_V_OUTPUT],
493 [_AC_FORTRAN_ASSERT()dnl
494 AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
496 # Compile and link our simple test program by passing a flag (argument
497 # 1 to this macro) to the Fortran compiler in order to get
498 # "verbose" output that we can then parse for the Fortran linker
500 ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
501 _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS m4_default([$1], [$ac_cv_prog_[]_AC_LANG_ABBREV[]_v])"
502 eval "set x $ac_link"
505 # gfortran 4.3 outputs lines setting COLLECT_GCC_OPTIONS, COMPILER_PATH,
506 # LIBRARY_PATH; skip all such settings.
507 ac_[]_AC_LANG_ABBREV[]_v_output=`eval $ac_link AS_MESSAGE_LOG_FD>&1 2>&1 |
508 grep -v 'Driving:' | grep -v "^[[_$as_cr_Letters]][[_$as_cr_alnum]]*="`
509 AS_ECHO(["$ac_[]_AC_LANG_ABBREV[]_v_output"]) >&AS_MESSAGE_LOG_FD
510 _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
514 # On HP/UX there is a line like: "LPATH is: /foo:/bar:/baz" where
515 # /foo, /bar, and /baz are search directories for the Fortran linker.
516 # Here, we change these into -L/foo -L/bar -L/baz (and put it first):
517 ac_[]_AC_LANG_ABBREV[]_v_output="`echo $ac_[]_AC_LANG_ABBREV[]_v_output |
519 sed 's|.*LPATH is\(: *[[^ ]]*\).*|\1|;s|: */| -L/|g'` $ac_[]_AC_LANG_ABBREV[]_v_output"
521 # FIXME: we keep getting bitten by quoted arguments; a more general fix
522 # that detects unbalanced quotes in FLIBS should be implemented
523 # and (ugh) tested at some point.
524 case $ac_[]_AC_LANG_ABBREV[]_v_output in
525 # If we are using xlf then replace all the commas with spaces.
527 ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed 's/,/ /g'` ;;
529 # With Intel ifc, ignore the quoted -mGLOB_options_string stuff (quoted
530 # $LIBS confuse us, and the libraries appear later in the output anyway).
531 *mGLOB_options_string*)
532 ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed 's/"-mGLOB[[^"]]*"/ /g'` ;;
534 # Portland Group compiler has singly- or doubly-quoted -cmdline argument
535 # Singly-quoted arguments were reported for versions 5.2-4 and 6.0-4.
536 # Doubly-quoted arguments were reported for "PGF90/x86 Linux/x86 5.0-2".
537 *-cmdline\ * | *-ignore\ * | *-def\ *)
538 ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed "\
539 s/-cmdline *'[[^']]*'/ /g; s/-cmdline *\"[[^\"]]*\"/ /g
540 s/-ignore *'[[^']]*'/ /g; s/-ignore *\"[[^\"]]*\"/ /g
541 s/-def *'[[^']]*'/ /g; s/-def *\"[[^\"]]*\"/ /g"` ;;
543 # If we are using Cray Fortran then delete quotes.
545 ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed 's/"//g'` ;;
548 ])# _AC_PROG_FC_V_OUTPUT
554 # Determine the flag that causes the Fortran compiler to print
555 # information of library and object files (normally -v)
556 # Needed for _AC_FC_LIBRARY_FLAGS
557 # Some compilers don't accept -v (Lahey: -verbose, xlf: -V, Fujitsu: -###)
558 AC_DEFUN([_AC_PROG_FC_V],
559 [_AC_FORTRAN_ASSERT()dnl
560 AC_CACHE_CHECK([how to get verbose linking output from $[]_AC_FC[]],
561 [ac_cv_prog_[]_AC_LANG_ABBREV[]_v],
562 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
563 [ac_cv_prog_[]_AC_LANG_ABBREV[]_v=
564 # Try some options frequently used verbose output
565 for ac_verb in -v -verbose --verbose -V -\#\#\#; do
566 _AC_PROG_FC_V_OUTPUT($ac_verb)
567 # look for -l* and *.a constructs in the output
568 for ac_arg in $ac_[]_AC_LANG_ABBREV[]_v_output; do
570 [[\\/]]*.a | ?:[[\\/]]*.a | -[[lLRu]]*)
571 ac_cv_prog_[]_AC_LANG_ABBREV[]_v=$ac_verb
576 if test -z "$ac_cv_prog_[]_AC_LANG_ABBREV[]_v"; then
577 AC_MSG_WARN([cannot determine how to obtain linking information from $[]_AC_FC[]])
579 [AC_MSG_WARN([compilation failed])])
583 # _AC_FC_LIBRARY_LDFLAGS
584 # ----------------------
586 # Determine the linker flags (e.g. "-L" and "-l") for the Fortran
587 # intrinsic and runtime libraries that are required to successfully
588 # link a Fortran program or shared library. The output variable
589 # FLIBS/FCLIBS is set to these flags.
591 # This macro is intended to be used in those situations when it is
592 # necessary to mix, e.g. C++ and Fortran, source code into a single
593 # program or shared library.
595 # For example, if object files from a C++ and Fortran compiler must
596 # be linked together, then the C++ compiler/linker must be used for
597 # linking (since special C++-ish things need to happen at link time
598 # like calling global constructors, instantiating templates, enabling
599 # exception support, etc.).
601 # However, the Fortran intrinsic and runtime libraries must be
602 # linked in as well, but the C++ compiler/linker doesn't know how to
603 # add these Fortran libraries. Hence, the macro
604 # "AC_F77_LIBRARY_LDFLAGS" was created to determine these Fortran
607 # This macro was packaged in its current form by Matthew D. Langston.
608 # However, nearly all of this macro came from the "OCTAVE_FLIBS" macro
609 # in "octave-2.0.13/aclocal.m4", and full credit should go to John
610 # W. Eaton for writing this extremely useful macro. Thank you John.
611 AC_DEFUN([_AC_FC_LIBRARY_LDFLAGS],
612 [_AC_FORTRAN_ASSERT()dnl
614 AC_CACHE_CHECK([for _AC_LANG libraries of $[]_AC_FC[]], ac_cv_[]_AC_LANG_ABBREV[]_libs,
615 [if test "x$[]_AC_LANG_PREFIX[]LIBS" != "x"; then
616 ac_cv_[]_AC_LANG_ABBREV[]_libs="$[]_AC_LANG_PREFIX[]LIBS" # Let the user override the test.
621 ac_cv_[]_AC_LANG_ABBREV[]_libs=
623 # Save positional arguments (if any)
624 ac_save_positional="$[@]"
626 set X $ac_[]_AC_LANG_ABBREV[]_v_output
627 while test $[@%:@] != 1; do
631 [[\\/]]*.a | ?:[[\\/]]*.a)
632 _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
633 ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg")
636 _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
637 [_AC_LINKER_OPTION([$ac_arg], ac_cv_[]_AC_LANG_ABBREV[]_libs)])
639 # Ignore these flags.
640 -lang* | -lcrt*.o | -lc | -lgcc* | -lSystem | -libmil | -little \
641 |-LANG:=* | -LIST:* | -LNO:* | -link)
644 test x"$CYGWIN" != xyes && ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg"
647 # These flags, when seen by themselves, take an argument.
648 # We remove the space between option and argument and re-iterate
649 # unless we find an empty arg or a new option (starting with -)
660 for ac_j in `AS_ECHO(["$ac_arg"]) | sed -e 's/-YP,/-L/;s/:/ -L/g'`; do
661 _AC_LIST_MEMBER_IF($ac_j, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
662 [ac_arg="$ac_arg $ac_j"
663 ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_j"])
667 _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
668 ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg")
670 -zallextract*| -zdefaultextract)
671 ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg"
673 # Ignore everything else.
676 # restore positional arguments
677 set X $ac_save_positional; shift
679 # We only consider "LD_RUN_PATH" on Solaris systems. If this is seen,
680 # then we insist that the "run path" must be an absolute path (i.e. it
681 # must begin with a "/").
682 case `(uname -sr) 2>/dev/null` in
684 ac_ld_run_path=`AS_ECHO(["$ac_[]_AC_LANG_ABBREV[]_v_output"]) |
685 sed -n 's,^.*LD_RUN_PATH *= *\(/[[^ ]]*\).*$,-R\1,p'`
686 test "x$ac_ld_run_path" != x &&
687 _AC_LINKER_OPTION([$ac_ld_run_path], ac_cv_[]_AC_LANG_ABBREV[]_libs)
690 fi # test "x$[]_AC_LANG_PREFIX[]LIBS" = "x"
692 []_AC_LANG_PREFIX[]LIBS="$ac_cv_[]_AC_LANG_ABBREV[]_libs"
693 AC_SUBST([]_AC_LANG_PREFIX[]LIBS)
694 ])# _AC_FC_LIBRARY_LDFLAGS
697 # AC_F77_LIBRARY_LDFLAGS
698 # ----------------------
699 AC_DEFUN([AC_F77_LIBRARY_LDFLAGS],
700 [AC_REQUIRE([AC_PROG_F77])dnl
701 AC_LANG_PUSH(Fortran 77)dnl
702 _AC_FC_LIBRARY_LDFLAGS
703 AC_LANG_POP(Fortran 77)dnl
704 ])# AC_F77_LIBRARY_LDFLAGS
707 # AC_FC_LIBRARY_LDFLAGS
708 # ---------------------
709 AC_DEFUN([AC_FC_LIBRARY_LDFLAGS],
710 [AC_REQUIRE([AC_PROG_FC])dnl
711 AC_LANG_PUSH(Fortran)dnl
712 _AC_FC_LIBRARY_LDFLAGS
713 AC_LANG_POP(Fortran)dnl
714 ])# AC_FC_LIBRARY_LDFLAGS
717 # _AC_FC_DUMMY_MAIN([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
718 # -----------------------------------------------------------
720 # Detect name of dummy main routine required by the Fortran libraries,
721 # (if any) and define {F77,FC}_DUMMY_MAIN to this name (which should be
722 # used for a dummy declaration, if it is defined). On some systems,
723 # linking a C program to the Fortran library does not work unless you
724 # supply a dummy function called something like MAIN__.
726 # Execute ACTION-IF-NOT-FOUND if no way of successfully linking a C
727 # program with the {F77,FC} libs is found; default to exiting with an error
728 # message. Execute ACTION-IF-FOUND if a dummy routine name is needed
729 # and found or if it is not needed (default to defining {F77,FC}_DUMMY_MAIN
732 # What is technically happening is that the Fortran libraries provide
733 # their own main() function, which usually initializes Fortran I/O and
734 # similar stuff, and then calls MAIN__, which is the entry point of
735 # your program. Usually, a C program will override this with its own
736 # main() routine, but the linker sometimes complain if you don't
737 # provide a dummy (never-called) MAIN__ routine anyway.
739 # Of course, programs that want to allow Fortran subroutines to do
740 # I/O, etcetera, should call their main routine MAIN__() (or whatever)
741 # instead of main(). A separate autoconf test (_AC_FC_MAIN) checks
742 # for the routine to use in this case (since the semantics of the test
743 # are slightly different). To link to e.g. purely numerical
744 # libraries, this is normally not necessary, however, and most C/C++
745 # programs are reluctant to turn over so much control to Fortran. =)
747 # The name variants we check for are (in order):
748 # MAIN__ (g77, MAIN__ required on some systems; IRIX, MAIN__ optional)
749 # MAIN_, __main (SunOS)
750 # MAIN _MAIN __MAIN main_ main__ _main (we follow DDD and try these too)
751 AC_DEFUN([_AC_FC_DUMMY_MAIN],
752 [_AC_FORTRAN_ASSERT()dnl
753 m4_define(_AC_LANG_PROGRAM_C_[]_AC_FC[]_HOOKS,
754 [#ifdef ]_AC_FC[_DUMMY_MAIN
755 ]AC_LANG_CASE([Fortran], [#ifndef FC_DUMMY_MAIN_EQ_F77])
759 int ]_AC_FC[_DUMMY_MAIN() { return 1; }
760 ]AC_LANG_CASE([Fortran], [#endif])
763 AC_CACHE_CHECK([for dummy main to link with _AC_LANG libraries],
764 ac_cv_[]_AC_LANG_ABBREV[]_dummy_main,
765 [ac_[]_AC_LANG_ABBREV[]_dm_save_LIBS=$LIBS
766 LIBS="$LIBS $[]_AC_LANG_PREFIX[]LIBS"
767 ac_fortran_dm_var=[]_AC_FC[]_DUMMY_MAIN
770 # First, try linking without a dummy main:
771 AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
772 [ac_cv_fortran_dummy_main=none],
773 [ac_cv_fortran_dummy_main=unknown])
775 if test $ac_cv_fortran_dummy_main = unknown; then
776 for ac_func in MAIN__ MAIN_ __main MAIN _MAIN __MAIN main_ main__ _main; do
777 AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@define $ac_fortran_dm_var $ac_func]])],
778 [ac_cv_fortran_dummy_main=$ac_func; break])
782 ac_cv_[]_AC_LANG_ABBREV[]_dummy_main=$ac_cv_fortran_dummy_main
784 LIBS=$ac_[]_AC_LANG_ABBREV[]_dm_save_LIBS
786 []_AC_FC[]_DUMMY_MAIN=$ac_cv_[]_AC_LANG_ABBREV[]_dummy_main
787 AS_IF([test "$[]_AC_FC[]_DUMMY_MAIN" != unknown],
789 [if test $[]_AC_FC[]_DUMMY_MAIN != none; then
790 AC_DEFINE_UNQUOTED([]_AC_FC[]_DUMMY_MAIN, $[]_AC_FC[]_DUMMY_MAIN,
791 [Define to dummy `main' function (if any) required to
792 link to the Fortran libraries.])
793 if test "x$ac_cv_fc_dummy_main" = "x$ac_cv_f77_dummy_main"; then
794 AC_DEFINE([FC_DUMMY_MAIN_EQ_F77], 1,
795 [Define if F77 and FC dummy `main' functions are identical.])
799 [AC_MSG_FAILURE([linking to Fortran libraries from C fails])])])
800 ])# _AC_FC_DUMMY_MAIN
805 AC_DEFUN([AC_F77_DUMMY_MAIN],
806 [AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
807 AC_LANG_PUSH(Fortran 77)dnl
808 _AC_FC_DUMMY_MAIN($@)
809 AC_LANG_POP(Fortran 77)dnl
810 ])# AC_F77_DUMMY_MAIN
815 AC_DEFUN([AC_FC_DUMMY_MAIN],
816 [AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
817 AC_LANG_PUSH(Fortran)dnl
818 _AC_FC_DUMMY_MAIN($@)
819 AC_LANG_POP(Fortran)dnl
825 # Define {F77,FC}_MAIN to name of alternate main() function for use with
826 # the Fortran libraries. (Typically, the libraries may define their
827 # own main() to initialize I/O, etcetera, that then call your own
828 # routine called MAIN__ or whatever.) See _AC_FC_DUMMY_MAIN, above.
829 # If no such alternate name is found, just define {F77,FC}_MAIN to main.
831 AC_DEFUN([_AC_FC_MAIN],
832 [_AC_FORTRAN_ASSERT()dnl
833 AC_CACHE_CHECK([for alternate main to link with _AC_LANG libraries],
834 ac_cv_[]_AC_LANG_ABBREV[]_main,
835 [ac_[]_AC_LANG_ABBREV[]_m_save_LIBS=$LIBS
836 LIBS="$LIBS $[]_AC_LANG_PREFIX[]LIBS"
837 ac_fortran_dm_var=[]_AC_FC[]_DUMMY_MAIN
839 ac_cv_fortran_main="main" # default entry point name
840 for ac_func in MAIN__ MAIN_ __main MAIN _MAIN __MAIN main_ main__ _main; do
841 AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@ifdef FC_DUMMY_MAIN_EQ_F77
842 @%:@ undef F77_DUMMY_MAIN
843 @%:@ undef FC_DUMMY_MAIN
845 @%:@ undef $ac_fortran_dm_var
847 @%:@define main $ac_func])],
848 [ac_cv_fortran_main=$ac_func; break])
851 ac_cv_[]_AC_LANG_ABBREV[]_main=$ac_cv_fortran_main
853 LIBS=$ac_[]_AC_LANG_ABBREV[]_m_save_LIBS
855 AC_DEFINE_UNQUOTED([]_AC_FC[]_MAIN, $ac_cv_[]_AC_LANG_ABBREV[]_main,
856 [Define to alternate name for `main' routine that is
857 called from a `main' in the Fortran libraries.])
863 AC_DEFUN([AC_F77_MAIN],
864 [AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
865 AC_LANG_PUSH(Fortran 77)dnl
867 AC_LANG_POP(Fortran 77)dnl
873 AC_DEFUN([AC_FC_MAIN],
874 [AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
875 AC_LANG_PUSH(Fortran)dnl
877 AC_LANG_POP(Fortran)dnl
881 # __AC_FC_NAME_MANGLING
882 # ---------------------
883 # Test for the name mangling scheme used by the Fortran compiler.
885 # Sets ac_cv_{f77,fc}_mangling. The value contains three fields, separated
888 # lower case / upper case:
889 # case translation of the Fortran symbols
890 # underscore / no underscore:
891 # whether the compiler appends "_" to symbol names
892 # extra underscore / no extra underscore:
893 # whether the compiler appends an extra "_" to symbol names already
894 # containing at least one underscore
896 AC_DEFUN([__AC_FC_NAME_MANGLING],
897 [_AC_FORTRAN_ASSERT()dnl
898 AC_CACHE_CHECK([for _AC_LANG name-mangling scheme],
899 ac_cv_[]_AC_LANG_ABBREV[]_mangling,
901 [ subroutine foobar()
907 [mv conftest.$ac_objext cfortran_test.$ac_objext
910 LIBS="cfortran_test.$ac_objext $LIBS $[]_AC_LANG_PREFIX[]LIBS"
914 for ac_foobar in foobar FOOBAR; do
915 for ac_underscore in "" "_"; do
916 ac_func="$ac_foobar$ac_underscore"
917 AC_LINK_IFELSE([AC_LANG_CALL([], [$ac_func])],
918 [ac_success=yes; break 2])
923 if test "$ac_success" = "yes"; then
937 for ac_extra in "" "_"; do
938 ac_func="$ac_foo_bar$ac_underscore$ac_extra"
939 AC_LINK_IFELSE([AC_LANG_CALL([], [$ac_func])],
940 [ac_success_extra=yes; break])
944 if test "$ac_success_extra" = "yes"; then
945 ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_case case"
946 if test -z "$ac_underscore"; then
947 ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, no underscore"
949 ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, underscore"
951 if test -z "$ac_extra"; then
952 ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, no extra underscore"
954 ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, extra underscore"
957 ac_cv_[]_AC_LANG_ABBREV[]_mangling="unknown"
960 ac_cv_[]_AC_LANG_ABBREV[]_mangling="unknown"
965 rm -f cfortran_test*],
966 [AC_MSG_FAILURE([cannot compile a simple Fortran program])])
968 ])# __AC_FC_NAME_MANGLING
970 # The replacement is empty.
971 AU_DEFUN([AC_F77_NAME_MANGLING], [])
974 # _AC_F77_NAME_MANGLING
975 # ---------------------
976 AC_DEFUN([_AC_F77_NAME_MANGLING],
977 [AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
978 AC_REQUIRE([AC_F77_DUMMY_MAIN])dnl
979 AC_LANG_PUSH(Fortran 77)dnl
980 __AC_FC_NAME_MANGLING
981 AC_LANG_POP(Fortran 77)dnl
982 ])# _AC_F77_NAME_MANGLING
985 # _AC_FC_NAME_MANGLING
986 # --------------------
987 AC_DEFUN([_AC_FC_NAME_MANGLING],
988 [AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
989 AC_REQUIRE([AC_FC_DUMMY_MAIN])dnl
990 AC_LANG_PUSH(Fortran)dnl
991 __AC_FC_NAME_MANGLING
992 AC_LANG_POP(Fortran)dnl
993 ])# _AC_FC_NAME_MANGLING
998 # Defines C macros {F77,FC}_FUNC(name,NAME) and {F77,FC}_FUNC_(name,NAME) to
999 # properly mangle the names of C identifiers, and C identifiers with
1000 # underscores, respectively, so that they match the name mangling
1001 # scheme used by the Fortran compiler.
1002 AC_DEFUN([_AC_FC_WRAPPERS],
1003 [_AC_FORTRAN_ASSERT()dnl
1004 AH_TEMPLATE(_AC_FC[_FUNC],
1005 [Define to a macro mangling the given C identifier (in lower and upper
1006 case), which must not contain underscores, for linking with Fortran.])dnl
1007 AH_TEMPLATE(_AC_FC[_FUNC_],
1008 [As ]_AC_FC[_FUNC, but for C identifiers containing underscores.])dnl
1009 case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in
1010 "lower case, no underscore, no extra underscore")
1011 AC_DEFINE(_AC_FC[_FUNC(name,NAME)], [name])
1012 AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name]) ;;
1013 "lower case, no underscore, extra underscore")
1014 AC_DEFINE(_AC_FC[_FUNC(name,NAME)], [name])
1015 AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name [##] _]) ;;
1016 "lower case, underscore, no extra underscore")
1017 AC_DEFINE(_AC_FC[_FUNC(name,NAME)], [name [##] _])
1018 AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name [##] _]) ;;
1019 "lower case, underscore, extra underscore")
1020 AC_DEFINE(_AC_FC[_FUNC(name,NAME)], [name [##] _])
1021 AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name [##] __]) ;;
1022 "upper case, no underscore, no extra underscore")
1023 AC_DEFINE(_AC_FC[_FUNC(name,NAME)], [NAME])
1024 AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME]) ;;
1025 "upper case, no underscore, extra underscore")
1026 AC_DEFINE(_AC_FC[_FUNC(name,NAME)], [NAME])
1027 AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME [##] _]) ;;
1028 "upper case, underscore, no extra underscore")
1029 AC_DEFINE(_AC_FC[_FUNC(name,NAME)], [NAME [##] _])
1030 AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME [##] _]) ;;
1031 "upper case, underscore, extra underscore")
1032 AC_DEFINE(_AC_FC[_FUNC(name,NAME)], [NAME [##] _])
1033 AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME [##] __]) ;;
1035 AC_MSG_WARN([unknown Fortran name-mangling scheme])
1043 AC_DEFUN([AC_F77_WRAPPERS],
1044 [AC_REQUIRE([_AC_F77_NAME_MANGLING])dnl
1045 AC_LANG_PUSH(Fortran 77)dnl
1047 AC_LANG_POP(Fortran 77)dnl
1053 AC_DEFUN([AC_FC_WRAPPERS],
1054 [AC_REQUIRE([_AC_FC_NAME_MANGLING])dnl
1055 AC_LANG_PUSH(Fortran)dnl
1057 AC_LANG_POP(Fortran)dnl
1061 # _AC_FC_FUNC(NAME, [SHELLVAR = NAME])
1062 # ------------------------------------
1063 # For a Fortran subroutine of given NAME, define a shell variable
1064 # $SHELLVAR to the Fortran-mangled name. If the SHELLVAR
1065 # argument is not supplied, it defaults to NAME.
1066 AC_DEFUN([_AC_FC_FUNC],
1067 [_AC_FORTRAN_ASSERT()dnl
1068 case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in
1069 upper*) ac_val="m4_toupper([$1])" ;;
1070 lower*) ac_val="m4_tolower([$1])" ;;
1071 *) ac_val="unknown" ;;
1073 case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in *," underscore"*) ac_val="$ac_val"_ ;; esac
1074 m4_if(m4_index([$1],[_]),-1,[],
1075 [case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in *," extra underscore"*) ac_val="$ac_val"_ ;; esac
1077 m4_default([$2],[$1])="$ac_val"
1081 # AC_F77_FUNC(NAME, [SHELLVAR = NAME])
1082 # ------------------------------------
1083 AC_DEFUN([AC_F77_FUNC],
1084 [AC_REQUIRE([_AC_F77_NAME_MANGLING])dnl
1085 AC_LANG_PUSH(Fortran 77)dnl
1086 _AC_FC_FUNC([$1],[$2])
1087 AC_LANG_POP(Fortran 77)dnl
1091 # AC_FC_FUNC(NAME, [SHELLVAR = NAME])
1092 # -----------------------------------
1093 AC_DEFUN([AC_FC_FUNC],
1094 [AC_REQUIRE([_AC_FC_NAME_MANGLING])dnl
1095 AC_LANG_PUSH(Fortran)dnl
1096 _AC_FC_FUNC([$1],[$2])
1097 AC_LANG_POP(Fortran)dnl
1101 # AC_FC_SRCEXT(EXT, [ACTION-IF-SUCCESS], [ACTION-IF-FAILURE])
1102 # -----------------------------------------------------------
1103 # Set the source-code extension used in Fortran (FC) tests to EXT (which
1104 # defaults to f). Also, look for any necessary additional FCFLAGS needed
1105 # to allow this extension, and store them in the output variable
1106 # FCFLAGS_<EXT> (e.g. FCFLAGS_f90 for EXT=f90). If successful,
1107 # call ACTION-IF-SUCCESS. If unable to compile source code with EXT,
1108 # call ACTION-IF-FAILURE, which defaults to failing with an error
1111 # (The flags for the current source-code extension, if any, are stored in
1112 # $ac_fcflags_srcext and used automatically in subsequent autoconf tests.)
1114 # For ordinary extensions like f90, etcetera, the modified FCFLAGS
1115 # are currently needed for IBM's xlf* and Intel's ifc (grrr). Unfortunately,
1116 # xlf* will only take flags to recognize one extension at a time, so if the
1117 # user wants to compile multiple extensions (.f90 and .f95, say), she
1118 # will need to use the FCFLAGS_F90 and FCFLAGS_F95 individually rather
1119 # than just adding them all to FCFLAGS, for example.
1121 # Also, for Intel's ifc compiler (which does not accept .f95 by default in
1122 # some versions), the $FCFLAGS_<EXT> variable *must* go immediately before
1123 # the source file on the command line, unlike other $FCFLAGS. Ugh.
1124 AC_DEFUN([AC_FC_SRCEXT],
1125 [AC_LANG_PUSH(Fortran)dnl
1126 AC_CACHE_CHECK([for Fortran flag to compile .$1 files],
1129 ac_fcflags_srcext_save=$ac_fcflags_srcext
1131 ac_cv_fc_srcext_$1=unknown
1132 for ac_flag in none -qsuffix=f=$1 -Tf; do
1133 test "x$ac_flag" != xnone && ac_fcflags_srcext="$ac_flag"
1134 AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [ac_cv_fc_srcext_$1=$ac_flag; break])
1136 rm -f conftest.$ac_objext conftest.$1
1137 ac_fcflags_srcext=$ac_fcflags_srcext_save
1139 if test "x$ac_cv_fc_srcext_$1" = xunknown; then
1140 m4_default([$3],[AC_MSG_ERROR([Fortran could not compile .$1 files])])
1143 if test "x$ac_cv_fc_srcext_$1" = xnone; then
1144 ac_fcflags_srcext=""
1147 ac_fcflags_srcext=$ac_cv_fc_srcext_$1
1148 FCFLAGS_[]$1[]=$ac_cv_fc_srcext_$1
1150 AC_SUBST(FCFLAGS_[]$1)
1153 AC_LANG_POP(Fortran)dnl
1157 # AC_FC_FREEFORM([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1158 # ------------------------------------------------------------------
1159 # Look for a compiler flag to make the Fortran (FC) compiler accept
1160 # free-format source code, and adds it to FCFLAGS. Call
1161 # ACTION-IF-SUCCESS (defaults to nothing) if successful (i.e. can
1162 # compile code using new extension) and ACTION-IF-FAILURE (defaults to
1163 # failing with an error message) if not. (Defined via DEFUN_ONCE to
1164 # prevent flag from being added to FCFLAGS multiple times.)
1166 # The known flags are:
1167 # -ffree-form: GNU g77, gfortran
1168 # -FR, -free: Intel compiler (icc, ecc, ifort)
1169 # -free: Compaq compiler (fort), Sun compiler (f95)
1170 # -qfree: IBM compiler (xlf)
1171 # -Mfree, -Mfreeform: Portland Group compiler
1172 # -freeform: SGI compiler
1173 # -f free: Absoft Fortran
1174 # +source=free: HP Fortran
1175 # -nfix: Lahey/Fujitsu Fortran
1176 # We try to test the "more popular" flags first, by some prejudiced
1177 # notion of popularity.
1178 AC_DEFUN_ONCE([AC_FC_FREEFORM],
1179 [AC_LANG_PUSH([Fortran])dnl
1180 AC_CACHE_CHECK([for Fortran flag needed to accept free-form source],
1181 [ac_cv_fc_freeform],
1182 [ac_cv_fc_freeform=unknown
1183 ac_fc_freeform_FCFLAGS_save=$FCFLAGS
1184 for ac_flag in none -ffree-form -FR -free -qfree -Mfree -Mfreeform \
1185 -freeform "-f free" +source=free -nfix
1187 test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_freeform_FCFLAGS_save $ac_flag"
1188 dnl Use @&t@ below to ensure that editors don't turn 8+ spaces into tab.
1191 ! FIXME: how to best confuse non-freeform compilers?
1192 print *, 'Hello ', &
1195 [ac_cv_fc_freeform=$ac_flag; break])
1197 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
1198 FCFLAGS=$ac_fc_freeform_FCFLAGS_save
1200 if test "x$ac_cv_fc_freeform" = xunknown; then
1202 [AC_MSG_ERROR([Fortran does not accept free-form source], 77)])
1204 if test "x$ac_cv_fc_freeform" != xnone; then
1205 FCFLAGS="$FCFLAGS $ac_cv_fc_freeform"
1209 AC_LANG_POP([Fortran])dnl
1213 # AC_FC_FIXEDFORM([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1214 # ------------------------------------------------------------------
1215 # Look for a compiler flag to make the Fortran (FC) compiler accept
1216 # fixed-format source code, and adds it to FCFLAGS. Call
1217 # ACTION-IF-SUCCESS (defaults to nothing) if successful (i.e. can
1218 # compile code using new extension) and ACTION-IF-FAILURE (defaults to
1219 # failing with an error message) if not. (Defined via DEFUN_ONCE to
1220 # prevent flag from being added to FCFLAGS multiple times.)
1222 # The known flags are:
1223 # -ffixed-form: GNU g77, gfortran
1224 # -fixed: Intel compiler (ifort), Sun compiler (f95)
1225 # -qfixed: IBM compiler (xlf*)
1226 # -Mfixed: Portland Group compiler
1227 # -fixedform: SGI compiler
1228 # -f fixed: Absoft Fortran
1229 # +source=fixed: HP Fortran
1230 # -fix: Lahey/Fujitsu Fortran
1231 # Since compilers may accept fixed form based on file name extension,
1232 # but users may want to use it with others as well, call AC_FC_SRCEXT
1233 # with the respective source extension before calling this macro.
1234 AC_DEFUN_ONCE([AC_FC_FIXEDFORM],
1235 [AC_LANG_PUSH([Fortran])dnl
1236 AC_CACHE_CHECK([for Fortran flag needed to accept fixed-form source],
1237 [ac_cv_fc_fixedform],
1238 [ac_cv_fc_fixedform=unknown
1239 ac_fc_fixedform_FCFLAGS_save=$FCFLAGS
1240 for ac_flag in none -ffixed-form -fixed -qfixed -Mfixed -fixedform "-f fixed" \
1243 test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_fixedform_FCFLAGS_save $ac_flag"
1245 C This comment should confuse free-form compilers.
1248 [ac_cv_fc_fixedform=$ac_flag; break])
1250 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
1251 FCFLAGS=$ac_fc_fixedform_FCFLAGS_save
1253 if test "x$ac_cv_fc_fixedform" = xunknown; then
1255 [AC_MSG_ERROR([Fortran does not accept fixed-form source], 77)])
1257 if test "x$ac_cv_fc_fixedform" != xnone; then
1258 FCFLAGS="$FCFLAGS $ac_cv_fc_fixedform"
1262 AC_LANG_POP([Fortran])dnl
1266 # AC_FC_LINE_LENGTH([LENGTH], [ACTION-IF-SUCCESS],
1267 # [ACTION-IF-FAILURE = FAILURE])
1268 # ------------------------------------------------
1269 # Look for a compiler flag to make the Fortran (FC) compiler accept long lines
1270 # in the current (free- or fixed-format) source code, and adds it to FCFLAGS.
1271 # The optional LENGTH may be 80, 132 (default), or `unlimited' for longer
1272 # lines. Note that line lengths above 254 columns are not portable, and some
1273 # compilers (hello ifort) do not accept more than 132 columns at least for
1274 # fixed format. Call ACTION-IF-SUCCESS (defaults to nothing) if successful
1275 # (i.e. can compile code using new extension) and ACTION-IF-FAILURE (defaults
1276 # to failing with an error message) if not. (Defined via DEFUN_ONCE to
1277 # prevent flag from being added to FCFLAGS multiple times.)
1278 # You should call AC_FC_FREEFORM or AC_FC_FIXEDFORM to set the desired format
1279 # prior to using this macro.
1281 # The known flags are:
1282 # -f{free,fixed}-line-length-N with N 72, 80, 132, or 0 or none for none.
1283 # -ffree-line-length-none: GNU gfortran
1284 # -qfixed=132 80 72: IBM compiler (xlf)
1286 # -132 -80 -72: Intel compiler (ifort)
1287 # Needs to come before -extend_source because ifort
1288 # accepts that as well with an optional parameter and
1289 # doesn't fail but only warns about unknown arguments.
1290 # -extend_source: SGI compiler
1291 # -W NN (132, 80, 72): Absoft Fortran
1292 # +extend_source: HP Fortran (254 in either form, default is 72 fixed,
1294 # -wide: Lahey/Fujitsu Fortran (255 cols in fixed form)
1295 # -e: Sun Fortran compiler (132 characters)
1296 AC_DEFUN_ONCE([AC_FC_LINE_LENGTH],
1297 [AC_LANG_PUSH([Fortran])dnl
1298 m4_case(m4_default([$1], [132]),
1299 [unlimited], [ac_fc_line_len_string=unlimited
1301 ac_fc_line_length_test='
1302 subroutine longer_than_132(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,'\
1303 'arg9,arg10,arg11,arg12,arg13,arg14,arg15,arg16,arg17,arg18,arg19)'],
1304 [132], [ac_fc_line_len=132
1305 ac_fc_line_length_test='
1306 subroutine longer_than_80(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,'\
1308 [80], [ac_fc_line_len=80
1309 ac_fc_line_length_test='
1310 subroutine longer_than_72(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)'],
1311 [m4_warning([Invalid length argument `$1'])])
1312 : ${ac_fc_line_len_string=$ac_fc_line_len}
1314 [for Fortran flag needed to accept $ac_fc_line_len_string column source lines],
1315 [ac_cv_fc_line_length],
1316 [ac_cv_fc_line_length=unknown
1317 ac_fc_line_length_FCFLAGS_save=$FCFLAGS
1318 for ac_flag in none \
1319 -ffree-line-length-none -ffixed-line-length-none \
1320 -ffree-line-length-$ac_fc_line_len \
1321 -ffixed-line-length-$ac_fc_line_len \
1322 -qfixed=$ac_fc_line_len -Mextend \
1323 -$ac_fc_line_len -extend_source \
1324 "-W $ac_fc_line_len" +extend_source -wide -e
1326 test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_line_length_FCFLAGS_save $ac_flag"
1327 AC_COMPILE_IFELSE([$ac_fc_line_length_test
1329 [ac_cv_fc_line_length=$ac_flag; break])
1331 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
1332 FCFLAGS=$ac_fc_line_length_FCFLAGS_save
1334 if test "x$ac_cv_fc_line_length" = xunknown; then
1336 [AC_MSG_ERROR([Fortran does not accept long source lines], 77)])
1338 if test "x$ac_cv_fc_line_length" != xnone; then
1339 FCFLAGS="$FCFLAGS $ac_cv_fc_line_length"
1343 AC_LANG_POP([Fortran])dnl
1344 ])# AC_FC_LINE_LENGTH