AC_PROG_CC_STDC: fold into AC_PROG_CC, removing C11 macro
[autoconf.git] / lib / autoconf / fortran.m4
blob38035956ef2533370ce4ab14b1ae253f5889d5ae
1 # This file is part of Autoconf.                       -*- Autoconf -*-
2 # Fortran languages support.
3 # Copyright (C) 2001, 2003-2012 Free Software Foundation, Inc.
5 # This file is part of Autoconf.  This program is free
6 # software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the
8 # Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
16 # Under Section 7 of GPL version 3, you are granted additional
17 # permissions described in the Autoconf Configure Script Exception,
18 # version 3.0, as published by the Free Software Foundation.
20 # You should have received a copy of the GNU General Public License
21 # and a copy of the Autoconf Configure Script Exception along with
22 # this program; see the files COPYINGv3 and COPYING.EXCEPTION
23 # respectively.  If not, see <http://www.gnu.org/licenses/>.
25 # Written by David MacKenzie, with help from
26 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
27 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
30 # Table of Contents:
32 # Preamble
34 # 0. Utility macros
36 # 1. Language selection
37 #    and routines to produce programs in a given language.
39 # 2. Producing programs in a given language.
41 # 3. Looking for a compiler
42 #    And possibly the associated preprocessor.
44 # 4. Compilers' characteristics.
48 ## ---------- ##
49 ## Preamble.  ##
50 ## ---------- ##
52 # Fortran vs. Fortran 77:
53 #   This file contains macros for both "Fortran 77" and "Fortran", where
54 # the former is the "classic" autoconf Fortran interface and is intended
55 # for legacy F77 codes, while the latter is intended to support newer Fortran
56 # dialects.  Fortran 77 uses environment variables F77, FFLAGS, and FLIBS,
57 # while Fortran uses FC, FCFLAGS, and FCLIBS.  For each user-callable AC_*
58 # macro, there is generally both an F77 and an FC version, where both versions
59 # share the same _AC_*_FC_* backend.  This backend macro requires that
60 # the appropriate language be AC_LANG_PUSH'ed, and uses _AC_LANG_ABBREV and
61 # _AC_LANG_PREFIX in order to name cache and environment variables, etc.
65 ## ------------------- ##
66 ## 0. Utility macros.  ##
67 ## ------------------- ##
70 # _AC_LIST_MEMBER_IF(ELEMENT, LIST, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
71 # ---------------------------------------------------------------------------
73 # Processing the elements of a list is tedious in shell programming,
74 # as lists tend to be implemented as space delimited strings.
76 # This macro searches LIST for ELEMENT, and executes ACTION-IF-FOUND
77 # if ELEMENT is a member of LIST, otherwise it executes
78 # ACTION-IF-NOT-FOUND.
79 AC_DEFUN([_AC_LIST_MEMBER_IF],
80 dnl Do some sanity checking of the arguments.
81 [m4_if([$1], , [m4_fatal([$0: missing argument 1])],
82       [$2], , [m4_fatal([$0: missing argument 2])])]dnl
83 [  ac_exists=false
84   for ac_i in $2; do
85     if test x"$1" = x"$ac_i"; then
86       ac_exists=true
87       break
88     fi
89   done
91   AS_IF([test x"$ac_exists" = xtrue], [$3], [$4])[]dnl
92 ])# _AC_LIST_MEMBER_IF
95 # _AC_LINKER_OPTION(LINKER-OPTIONS, SHELL-VARIABLE)
96 # -------------------------------------------------
98 # Specifying options to the compiler (whether it be the C, C++ or
99 # Fortran 77 compiler) that are meant for the linker is compiler
100 # dependent.  This macro lets you give options to the compiler that
101 # are meant for the linker in a portable, compiler-independent way.
103 # This macro take two arguments, a list of linker options that the
104 # compiler should pass to the linker (LINKER-OPTIONS) and the name of
105 # a shell variable (SHELL-VARIABLE).  The list of linker options are
106 # appended to the shell variable in a compiler-dependent way.
108 # For example, if the selected language is C, then this:
110 #   _AC_LINKER_OPTION([-R /usr/local/lib/foo], foo_LDFLAGS)
112 # will expand into this if the selected C compiler is gcc:
114 #   foo_LDFLAGS="-Xlinker -R -Xlinker /usr/local/lib/foo"
116 # otherwise, it will expand into this:
118 #   foo_LDFLAGS"-R /usr/local/lib/foo"
120 # You are encouraged to add support for compilers that this macro
121 # doesn't currently support.
122 # FIXME: Get rid of this macro.
123 AC_DEFUN([_AC_LINKER_OPTION],
124 [if test "$ac_compiler_gnu" = yes; then
125   for ac_link_opt in $1; do
126     $2="[$]$2 -Xlinker $ac_link_opt"
127   done
128 else
129   $2="[$]$2 $1"
130 fi[]dnl
131 ])# _AC_LINKER_OPTION
135 ## ------------------------ ##
136 ## 1a. Language selection.  ##
137 ## ------------------------ ##
140 # AC_LANG(Fortran 77)
141 # -------------------
142 AC_LANG_DEFINE([Fortran 77], [f77], [F], [F77], [],
143 [ac_ext=f
144 ac_compile='$F77 -c $FFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
145 ac_link='$F77 -o conftest$ac_exeext $FFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
146 ac_compiler_gnu=$ac_cv_f77_compiler_gnu
150 # AC_LANG_FORTRAN77
151 # -----------------
152 AU_DEFUN([AC_LANG_FORTRAN77], [AC_LANG(Fortran 77)])
155 # _AC_FORTRAN_ASSERT
156 # ------------------
157 # Current language must be Fortran or Fortran 77.
158 m4_defun([_AC_FORTRAN_ASSERT],
159 [m4_if(_AC_LANG, [Fortran], [],
160        [m4_if(_AC_LANG, [Fortran 77], [],
161               [m4_fatal([$0: current language is not Fortran: ] _AC_LANG)])])])
164 # _AC_FC
165 # ------
166 # Return F77 or FC, depending upon the language.
167 AC_DEFUN([_AC_FC],
168 [_AC_FORTRAN_ASSERT()dnl
169 AC_LANG_CASE([Fortran 77], [F77],
170              [Fortran],    [FC])])
174 ## ----------------------- ##
175 ## 2. Producing programs.  ##
176 ## ----------------------- ##
179 # AC_LANG_PROGRAM(Fortran 77)([PROLOGUE], [BODY])
180 # -----------------------------------------------
181 # Yes, we discard the PROLOGUE.
182 m4_define([AC_LANG_PROGRAM(Fortran 77)],
183 [m4_ifval([$1],
184        [m4_warn([syntax], [$0: ignoring PROLOGUE: $1])])dnl
185       program main
187       end])
190 # _AC_LANG_IO_PROGRAM(Fortran 77)
191 # -------------------------------
192 # Produce source that performs I/O.
193 m4_define([_AC_LANG_IO_PROGRAM(Fortran 77)],
194 [AC_LANG_PROGRAM([],
195 [dnl
196       open(unit=9,file='conftest.out')
197       close(unit=9)
198 ])])
201 # AC_LANG_CALL(Fortran 77)(PROLOGUE, FUNCTION)
202 # --------------------------------------------
203 # FIXME: This is a guess, help!
204 m4_define([AC_LANG_CALL(Fortran 77)],
205 [AC_LANG_PROGRAM([$1],
206 [      call $2])])
209 # AC_LANG_FUNC_LINK_TRY(Fortran 77)(FUNCTION)
210 # -------------------------------------------
211 m4_define([AC_LANG_FUNC_LINK_TRY(Fortran 77)],
212 [AC_LANG_PROGRAM([],
213 [      call $1])])
215 ## ------------------------ ##
216 ## 1b. Language selection.  ##
217 ## ------------------------ ##
220 # AC_LANG(Fortran)
221 # ----------------
222 AC_LANG_DEFINE([Fortran], [fc], [FC], [FC], [Fortran 77],
223 [ac_ext=${ac_fc_srcext-f}
224 ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
225 ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
226 ac_compiler_gnu=$ac_cv_fc_compiler_gnu
230 ## -------------------------------------------- ##
231 ## 3. Looking for Compilers and Preprocessors.  ##
232 ## -------------------------------------------- ##
235 # AC_LANG_PREPROC(Fortran 77)
236 # ---------------------------
237 # Find the Fortran 77 preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
238 AC_DEFUN([AC_LANG_PREPROC(Fortran 77)],
239 [m4_warn([syntax],
240          [$0: No preprocessor defined for ]_AC_LANG)])
242 # AC_LANG_PREPROC(Fortran)
243 # ------------------------
244 # Find the Fortran preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
245 AC_DEFUN([AC_LANG_PREPROC(Fortran)],
246 [m4_warn([syntax],
247          [$0: No preprocessor defined for ]_AC_LANG)])
250 # AC_LANG_COMPILER(Fortran 77)
251 # ----------------------------
252 # Find the Fortran 77 compiler.  Must be AC_DEFUN'd to be
253 # AC_REQUIRE'able.
254 AC_DEFUN([AC_LANG_COMPILER(Fortran 77)],
255 [AC_REQUIRE([AC_PROG_F77])])
257 # AC_LANG_COMPILER(Fortran)
258 # -------------------------
259 # Find the Fortran compiler.  Must be AC_DEFUN'd to be
260 # AC_REQUIRE'able.
261 AC_DEFUN([AC_LANG_COMPILER(Fortran)],
262 [AC_REQUIRE([AC_PROG_FC])])
265 # ac_cv_prog_g77
266 # --------------
267 # We used to name the cache variable this way.
268 AU_DEFUN([ac_cv_prog_g77],
269 [ac_cv_f77_compiler_gnu])
272 # _AC_FC_DIALECT_YEAR([DIALECT])
273 # ------------------------------
274 # Given a Fortran DIALECT, which is Fortran [YY]YY or simply [YY]YY,
275 # convert to a 4-digit year.  The dialect must be one of Fortran 77,
276 # 90, 95, or 2000, currently.  If DIALECT is simply Fortran or the
277 # empty string, returns the empty string.
278 AC_DEFUN([_AC_FC_DIALECT_YEAR],
279 [m4_case(m4_bpatsubsts(m4_tolower([$1]), [fortran],[], [ *],[]),
280          [77],[1977], [1977],[1977],
281          [90],[1990], [1990],[1990],
282          [95],[1995], [1995],[1995],
283          [2000],[2000],
284          [],[],
285          [m4_fatal([unknown Fortran dialect])])])
288 # _AC_PROG_FC([DIALECT], [COMPILERS...])
289 # --------------------------------------
290 # DIALECT is a Fortran dialect, given by Fortran [YY]YY or simply [YY]YY,
291 # and must be one of those supported by _AC_FC_DIALECT_YEAR
293 # If DIALECT is supplied, then we search for compilers of that dialect
294 # first, and then later dialects.  Otherwise, we search for compilers
295 # of the newest dialect first, and then earlier dialects in increasing age.
296 # This search order is necessarily imperfect because the dialect cannot
297 # always be inferred from the compiler name.
299 # Known compilers:
300 #  f77/f90/f95: generic compiler names
301 #  g77: GNU Fortran 77 compiler
302 #  gfortran: GNU Fortran 95+ compiler (released in gcc 4.0)
303 #  g95: original gcc-based f95 compiler (gfortran is a fork)
304 #  ftn: native Fortran 95 compiler on Cray X1
305 #  cf77: native F77 compiler under older Crays (prefer over fort77)
306 #  fort77: native F77 compiler under HP-UX (and some older Crays)
307 #  frt: Fujitsu F77 compiler
308 #  pgf77/pgf90/pghpf/pgf95/pgfortran: Portland Group F77/F90/F95 compilers
309 #  xlf/xlf90/xlf95: IBM (AIX) F77/F90/F95 compilers
310 #    Prefer xlf9x to the generic names because they do not reject files
311 #    with extension `.f'.
312 #  lf95: Lahey-Fujitsu F95 compiler
313 #  fl32: Microsoft Fortran 77 "PowerStation" compiler
314 #  af77: Apogee F77 compiler for Intergraph hardware running CLIX
315 #  epcf90: "Edinburgh Portable Compiler" F90
316 #  fort: Compaq (now HP) Fortran 90/95 compiler for Tru64 and Linux/Alpha
317 #  ifort, previously ifc: Intel Fortran 95 compiler for Linux/x86
318 #  efc: Intel Fortran 95 compiler for IA64
319 #  nagfor: NAGWare Fortran 77/90/95 compiler
320 m4_define([_AC_F95_FC], [gfortran g95 xlf95 f95 fort ifort ifc efc pgfortran pgf95 lf95 ftn nagfor])
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[],
326       m4_default([$2],
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])
335 set X $ac_compile
336 ac_compiler=$[2]
337 for ac_option in --version -v -V -qversion; do
338   _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
339 done
340 rm -f a.out
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.)
346 ac_save_ext=$ac_ext
347 ac_ext=F
348 _AC_LANG_COMPILER_GNU
349 ac_ext=$ac_save_ext
350 _AC_PROG_FC_G
351 ])# _AC_PROG_FC
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
366   G77=yes
367 else
368   G77=
370 AC_LANG_POP(Fortran 77)dnl
371 ])# AC_PROG_F77
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 if test $ac_compiler_gnu = yes; then
386   GFC=yes
387 else
388   GFC=
390 AC_LANG_POP(Fortran)dnl
391 ])# AC_PROG_FC
394 # _AC_PROG_FC_G
395 # -------------
396 # Check whether -g works, even if F[C]FLAGS is set, in case the package
397 # plays around with F[C]FLAGS (such as to build both debugging and normal
398 # versions of a library), tasteless as that idea is.
399 m4_define([_AC_PROG_FC_G],
400 [_AC_FORTRAN_ASSERT()dnl
401 ac_test_[]_AC_LANG_PREFIX[]FLAGS=${[]_AC_LANG_PREFIX[]FLAGS+set}
402 ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
403 _AC_LANG_PREFIX[]FLAGS=
404 AC_CACHE_CHECK(whether $[]_AC_FC[] accepts -g, ac_cv_prog_[]_AC_LANG_ABBREV[]_g,
405 [_AC_LANG_PREFIX[]FLAGS=-g
406 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
407 [ac_cv_prog_[]_AC_LANG_ABBREV[]_g=yes],
408 [ac_cv_prog_[]_AC_LANG_ABBREV[]_g=no])
410 if test "$ac_test_[]_AC_LANG_PREFIX[]FLAGS" = set; then
411   _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
412 elif test $ac_cv_prog_[]_AC_LANG_ABBREV[]_g = yes; then
413   if test "x$ac_cv_[]_AC_LANG_ABBREV[]_compiler_gnu" = xyes; then
414     _AC_LANG_PREFIX[]FLAGS="-g -O2"
415   else
416     _AC_LANG_PREFIX[]FLAGS="-g"
417   fi
418 else
419   if test "x$ac_cv_[]_AC_LANG_ABBREV[]_compiler_gnu" = xyes; then
420     _AC_LANG_PREFIX[]FLAGS="-O2"
421   else
422     _AC_LANG_PREFIX[]FLAGS=
423   fi
424 fi[]dnl
425 ])# _AC_PROG_FC_G
428 # _AC_PROG_FC_C_O
429 # ---------------
430 # Test if the Fortran compiler accepts the options `-c' and `-o'
431 # simultaneously, and define `[F77/FC]_NO_MINUS_C_MINUS_O' if it does not.
433 # The usefulness of this macro is questionable, as I can't really see
434 # why anyone would use it.  The only reason I include it is for
435 # completeness, since a similar test exists for the C compiler.
437 # FIXME: it seems like we could merge the C/C++/Fortran versions of this.
438 AC_DEFUN([_AC_PROG_FC_C_O],
439 [_AC_FORTRAN_ASSERT()dnl
440 AC_CACHE_CHECK([whether $[]_AC_FC[] understands -c and -o together],
441                [ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o],
442 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
443 # We test twice because some compilers refuse to overwrite an existing
444 # `.o' file with `-o', although they will create one.
445 ac_try='$[]_AC_FC[] $[]_AC_LANG_PREFIX[]FLAGS -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
446 rm -f conftest2.*
447 if _AC_DO_VAR(ac_try) &&
448      test -f conftest2.$ac_objext &&
449      _AC_DO_VAR(ac_try); then
450   ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o=yes
451 else
452   ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o=no
454 rm -f conftest*])
455 if test $ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o = no; then
456   AC_DEFINE([]_AC_FC[]_NO_MINUS_C_MINUS_O, 1,
457             [Define to 1 if your Fortran compiler doesn't accept
458              -c and -o together.])
460 ])# _AC_PROG_FC_C_O
463 # AC_PROG_F77_C_O
464 # ---------------
465 AC_DEFUN([AC_PROG_F77_C_O],
466 [AC_REQUIRE([AC_PROG_F77])dnl
467 AC_LANG_PUSH(Fortran 77)dnl
468 _AC_PROG_FC_C_O
469 AC_LANG_POP(Fortran 77)dnl
470 ])# AC_PROG_F77_C_O
473 # AC_PROG_FC_C_O
474 # --------------
475 AC_DEFUN([AC_PROG_FC_C_O],
476 [AC_REQUIRE([AC_PROG_FC])dnl
477 AC_LANG_PUSH(Fortran)dnl
478 _AC_PROG_FC_C_O
479 AC_LANG_POP(Fortran)dnl
480 ])# AC_PROG_FC_C_O
484 ## ------------------------------- ##
485 ## 4. Compilers' characteristics.  ##
486 ## ------------------------------- ##
489 # _AC_PROG_FC_V_OUTPUT([FLAG = $ac_cv_prog_{f77/fc}_v])
490 # -----------------------------------------------------
491 # Link a trivial Fortran program, compiling with a verbose output FLAG
492 # (whose default value, $ac_cv_prog_{f77/fc}_v, is computed by
493 # _AC_PROG_FC_V), and return the output in $ac_{f77/fc}_v_output.  This
494 # output is processed in the way expected by _AC_FC_LIBRARY_LDFLAGS,
495 # so that any link flags that are echoed by the compiler appear as
496 # space-separated items.
497 AC_DEFUN([_AC_PROG_FC_V_OUTPUT],
498 [_AC_FORTRAN_ASSERT()dnl
499 AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
501 # Compile and link our simple test program by passing a flag (argument
502 # 1 to this macro) to the Fortran compiler in order to get
503 # "verbose" output that we can then parse for the Fortran linker
504 # flags.
505 ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
506 _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS m4_default([$1], [$ac_cv_prog_[]_AC_LANG_ABBREV[]_v])"
507 eval "set x $ac_link"
508 shift
509 _AS_ECHO_LOG([$[*]])
510 # gfortran 4.3 outputs lines setting COLLECT_GCC_OPTIONS, COMPILER_PATH,
511 # LIBRARY_PATH; skip all such settings.
512 ac_[]_AC_LANG_ABBREV[]_v_output=`eval $ac_link AS_MESSAGE_LOG_FD>&1 2>&1 |
513   sed '/^Driving:/d; /^Configured with:/d;
514       '"/^[[_$as_cr_Letters]][[_$as_cr_alnum]]*=/d"`
515 AS_ECHO(["$ac_[]_AC_LANG_ABBREV[]_v_output"]) >&AS_MESSAGE_LOG_FD
516 _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
518 rm -rf conftest*
520 # On HP/UX there is a line like: "LPATH is: /foo:/bar:/baz" where
521 # /foo, /bar, and /baz are search directories for the Fortran linker.
522 # Here, we change these into -L/foo -L/bar -L/baz (and put it first):
523 ac_[]_AC_LANG_ABBREV[]_v_output="`echo $ac_[]_AC_LANG_ABBREV[]_v_output |
524         grep 'LPATH is:' |
525         sed 's|.*LPATH is\(: *[[^ ]]*\).*|\1|;s|: */| -L/|g'` $ac_[]_AC_LANG_ABBREV[]_v_output"
527 # FIXME: we keep getting bitten by quoted arguments; a more general fix
528 #        that detects unbalanced quotes in FLIBS should be implemented
529 #        and (ugh) tested at some point.
530 case $ac_[]_AC_LANG_ABBREV[]_v_output in
531   # With xlf replace commas with spaces,
532   # and remove "-link" and closing parenthesis.
533   *xlfentry*)
534     ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output |
535       sed '
536         s/,/ /g
537         s/ -link / /g
538         s/) *$//
539       '
540     ` ;;
542   # With Intel ifc, ignore the quoted -mGLOB_options_string stuff (quoted
543   # $LIBS confuse us, and the libraries appear later in the output anyway).
544   *mGLOB_options_string*)
545     ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed 's/"-mGLOB[[^"]]*"/ /g'` ;;
547   # Portland Group compiler has singly- or doubly-quoted -cmdline argument
548   # Singly-quoted arguments were reported for versions 5.2-4 and 6.0-4.
549   # Doubly-quoted arguments were reported for "PGF90/x86 Linux/x86 5.0-2".
550   *-cmdline\ * | *-ignore\ * | *-def\ *)
551     ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed "\
552         s/-cmdline  *'[[^']]*'/ /g; s/-cmdline  *\"[[^\"]]*\"/ /g
553         s/-ignore  *'[[^']]*'/ /g; s/-ignore  *\"[[^\"]]*\"/ /g
554         s/-def  *'[[^']]*'/ /g; s/-def  *\"[[^\"]]*\"/ /g"` ;;
556   # If we are using fort77 (the f2c wrapper) then filter output and delete quotes.
557   *fort77*f2c*gcc*)
558     ac_[]_AC_LANG_ABBREV[]_v_output=`echo "$ac_[]_AC_LANG_ABBREV[]_v_output" | sed -n '
559         /:[[     ]]\+Running[[   ]]\{1,\}"gcc"/{
560           /"-c"/d
561           /[[.]]c"*/d
562           s/^.*"gcc"/"gcc"/
563           s/"//gp
564         }'` ;;
566   # If we are using Cray Fortran then delete quotes.
567   *cft90*)
568     ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed 's/"//g'` ;;
569 esac
571 ])# _AC_PROG_FC_V_OUTPUT
574 # _AC_PROG_FC_V
575 # -------------
577 # Determine the flag that causes the Fortran compiler to print
578 # information of library and object files (normally -v)
579 # Needed for _AC_FC_LIBRARY_FLAGS
580 # Some compilers don't accept -v (Lahey: (-)-verbose, xlf: -V, Fujitsu: -###)
581 AC_DEFUN([_AC_PROG_FC_V],
582 [_AC_FORTRAN_ASSERT()dnl
583 AC_CACHE_CHECK([how to get verbose linking output from $[]_AC_FC[]],
584                 [ac_cv_prog_[]_AC_LANG_ABBREV[]_v],
585 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
586 [ac_cv_prog_[]_AC_LANG_ABBREV[]_v=
587 # Try some options frequently used verbose output
588 for ac_verb in -v -verbose --verbose -V -\#\#\#; do
589   _AC_PROG_FC_V_OUTPUT($ac_verb)
590   # look for -l* and *.a constructs in the output
591   for ac_arg in $ac_[]_AC_LANG_ABBREV[]_v_output; do
592      case $ac_arg in
593         [[\\/]]*.a | ?:[[\\/]]*.a | -[[lLRu]]*)
594           ac_cv_prog_[]_AC_LANG_ABBREV[]_v=$ac_verb
595           break 2 ;;
596      esac
597   done
598 done
599 if test -z "$ac_cv_prog_[]_AC_LANG_ABBREV[]_v"; then
600    AC_MSG_WARN([cannot determine how to obtain linking information from $[]_AC_FC[]])
601 fi],
602                   [AC_MSG_WARN([compilation failed])])
603 ])])# _AC_PROG_FC_V
606 # _AC_FC_LIBRARY_LDFLAGS
607 # ----------------------
609 # Determine the linker flags (e.g. "-L" and "-l") for the Fortran
610 # intrinsic and runtime libraries that are required to successfully
611 # link a Fortran program or shared library.  The output variable
612 # FLIBS/FCLIBS is set to these flags.
614 # This macro is intended to be used in those situations when it is
615 # necessary to mix, e.g. C++ and Fortran, source code into a single
616 # program or shared library.
618 # For example, if object files from a C++ and Fortran compiler must
619 # be linked together, then the C++ compiler/linker must be used for
620 # linking (since special C++-ish things need to happen at link time
621 # like calling global constructors, instantiating templates, enabling
622 # exception support, etc.).
624 # However, the Fortran intrinsic and runtime libraries must be
625 # linked in as well, but the C++ compiler/linker doesn't know how to
626 # add these Fortran libraries.  Hence, the macro
627 # "AC_F77_LIBRARY_LDFLAGS" was created to determine these Fortran
628 # libraries.
630 # This macro was packaged in its current form by Matthew D. Langston.
631 # However, nearly all of this macro came from the "OCTAVE_FLIBS" macro
632 # in "octave-2.0.13/aclocal.m4", and full credit should go to John
633 # W. Eaton for writing this extremely useful macro.  Thank you John.
634 AC_DEFUN([_AC_FC_LIBRARY_LDFLAGS],
635 [AC_REQUIRE([AC_CANONICAL_HOST])dnl
636 _AC_FORTRAN_ASSERT()dnl
637 _AC_PROG_FC_V
638 AC_CACHE_CHECK([for _AC_LANG libraries of $[]_AC_FC[]], ac_cv_[]_AC_LANG_ABBREV[]_libs,
639 [if test "x$[]_AC_LANG_PREFIX[]LIBS" != "x"; then
640   ac_cv_[]_AC_LANG_ABBREV[]_libs="$[]_AC_LANG_PREFIX[]LIBS" # Let the user override the test.
641 else
643 _AC_PROG_FC_V_OUTPUT
645 ac_cv_[]_AC_LANG_ABBREV[]_libs=
647 # Save positional arguments (if any)
648 ac_save_positional="$[@]"
650 set X $ac_[]_AC_LANG_ABBREV[]_v_output
651 while test $[@%:@] != 1; do
652   shift
653   ac_arg=$[1]
654   case $ac_arg in
655         [[\\/]]*.a | ?:[[\\/]]*.a)
656           _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
657               ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg")
658           ;;
659         -bI:*)
660           _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
661              [_AC_LINKER_OPTION([$ac_arg], ac_cv_[]_AC_LANG_ABBREV[]_libs)])
662           ;;
663           # Ignore these flags.
664         -lang* | -lcrt*.o | -lc | -lgcc* | -lSystem | -libmil | -little \
665           |-LANG:=* | -LIST:* | -LNO:* | -link)
666           ;;
667         -lkernel32)
668           case $host_os in
669           *cygwin*) ;;
670           *) ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg"
671             ;;
672           esac
673           ;;
674         -[[LRuYz]])
675           # These flags, when seen by themselves, take an argument.
676           # We remove the space between option and argument and re-iterate
677           # unless we find an empty arg or a new option (starting with -)
678           case $[2] in
679              "" | -*);;
680              *)
681                 ac_arg="$ac_arg$[2]"
682                 shift; shift
683                 set X $ac_arg "$[@]"
684                 ;;
685           esac
686           ;;
687         -YP,*)
688           for ac_j in `AS_ECHO(["$ac_arg"]) | sed -e 's/-YP,/-L/;s/:/ -L/g'`; do
689             _AC_LIST_MEMBER_IF($ac_j, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
690                                [ac_arg="$ac_arg $ac_j"
691                                ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_j"])
692           done
693           ;;
694         -[[lLR]]*)
695           _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
696                              ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg")
697           ;;
698         -zallextract*| -zdefaultextract)
699           ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg"
700           ;;
701           # Ignore everything else.
702   esac
703 done
704 # restore positional arguments
705 set X $ac_save_positional; shift
707 # We only consider "LD_RUN_PATH" on Solaris systems.  If this is seen,
708 # then we insist that the "run path" must be an absolute path (i.e. it
709 # must begin with a "/").
710 case `(uname -sr) 2>/dev/null` in
711    "SunOS 5"*)
712       ac_ld_run_path=`AS_ECHO(["$ac_[]_AC_LANG_ABBREV[]_v_output"]) |
713                         sed -n 's,^.*LD_RUN_PATH *= *\(/[[^ ]]*\).*$,-R\1,p'`
714       test "x$ac_ld_run_path" != x &&
715         _AC_LINKER_OPTION([$ac_ld_run_path], ac_cv_[]_AC_LANG_ABBREV[]_libs)
716       ;;
717 esac
718 fi # test "x$[]_AC_LANG_PREFIX[]LIBS" = "x"
720 []_AC_LANG_PREFIX[]LIBS="$ac_cv_[]_AC_LANG_ABBREV[]_libs"
721 AC_SUBST([]_AC_LANG_PREFIX[]LIBS)
722 ])# _AC_FC_LIBRARY_LDFLAGS
725 # AC_F77_LIBRARY_LDFLAGS
726 # ----------------------
727 AC_DEFUN([AC_F77_LIBRARY_LDFLAGS],
728 [AC_REQUIRE([AC_PROG_F77])dnl
729 AC_LANG_PUSH(Fortran 77)dnl
730 _AC_FC_LIBRARY_LDFLAGS
731 AC_LANG_POP(Fortran 77)dnl
732 ])# AC_F77_LIBRARY_LDFLAGS
735 # AC_FC_LIBRARY_LDFLAGS
736 # ---------------------
737 AC_DEFUN([AC_FC_LIBRARY_LDFLAGS],
738 [AC_REQUIRE([AC_PROG_FC])dnl
739 AC_LANG_PUSH(Fortran)dnl
740 _AC_FC_LIBRARY_LDFLAGS
741 AC_LANG_POP(Fortran)dnl
742 ])# AC_FC_LIBRARY_LDFLAGS
745 # _AC_FC_DUMMY_MAIN([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
746 # -----------------------------------------------------------
748 # Detect name of dummy main routine required by the Fortran libraries,
749 # (if any) and define {F77,FC}_DUMMY_MAIN to this name (which should be
750 # used for a dummy declaration, if it is defined).  On some systems,
751 # linking a C program to the Fortran library does not work unless you
752 # supply a dummy function called something like MAIN__.
754 # Execute ACTION-IF-NOT-FOUND if no way of successfully linking a C
755 # program with the {F77,FC} libs is found; default to exiting with an error
756 # message.  Execute ACTION-IF-FOUND if a dummy routine name is needed
757 # and found or if it is not needed (default to defining {F77,FC}_DUMMY_MAIN
758 # when needed).
760 # What is technically happening is that the Fortran libraries provide
761 # their own main() function, which usually initializes Fortran I/O and
762 # similar stuff, and then calls MAIN__, which is the entry point of
763 # your program.  Usually, a C program will override this with its own
764 # main() routine, but the linker sometimes complain if you don't
765 # provide a dummy (never-called) MAIN__ routine anyway.
767 # Of course, programs that want to allow Fortran subroutines to do
768 # I/O, etcetera, should call their main routine MAIN__() (or whatever)
769 # instead of main().  A separate autoconf test (_AC_FC_MAIN) checks
770 # for the routine to use in this case (since the semantics of the test
771 # are slightly different).  To link to e.g. purely numerical
772 # libraries, this is normally not necessary, however, and most C/C++
773 # programs are reluctant to turn over so much control to Fortran.  =)
775 # The name variants we check for are (in order):
776 #   MAIN__ (g77, MAIN__ required on some systems; IRIX, MAIN__ optional)
777 #   MAIN_, __main (SunOS)
778 #   MAIN _MAIN __MAIN main_ main__ _main (we follow DDD and try these too)
779 AC_DEFUN([_AC_FC_DUMMY_MAIN],
780 [_AC_FORTRAN_ASSERT()dnl
781 m4_define(_AC_LANG_PROGRAM_C_[]_AC_FC[]_HOOKS,
782 [#ifdef ]_AC_FC[_DUMMY_MAIN
783 ]AC_LANG_CASE([Fortran], [#ifndef FC_DUMMY_MAIN_EQ_F77])
784 [#  ifdef __cplusplus
785      extern "C"
786 #  endif
787    int ]_AC_FC[_DUMMY_MAIN() { return 1; }
788 ]AC_LANG_CASE([Fortran], [#endif])
789 [#endif
791 AC_CACHE_CHECK([for dummy main to link with _AC_LANG libraries],
792                ac_cv_[]_AC_LANG_ABBREV[]_dummy_main,
793 [ac_[]_AC_LANG_ABBREV[]_dm_save_LIBS=$LIBS
794  LIBS="$LIBS $[]_AC_LANG_PREFIX[]LIBS"
795  ac_fortran_dm_var=[]_AC_FC[]_DUMMY_MAIN
796  AC_LANG_PUSH(C)dnl
798  # First, try linking without a dummy main:
799  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
800                 [ac_cv_fortran_dummy_main=none],
801                 [ac_cv_fortran_dummy_main=unknown])
803  if test $ac_cv_fortran_dummy_main = unknown; then
804    for ac_func in MAIN__ MAIN_ __main MAIN _MAIN __MAIN main_ main__ _main; do
805      AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@define $ac_fortran_dm_var $ac_func]])],
806                     [ac_cv_fortran_dummy_main=$ac_func; break])
807    done
808  fi
809  AC_LANG_POP(C)dnl
810  ac_cv_[]_AC_LANG_ABBREV[]_dummy_main=$ac_cv_fortran_dummy_main
811  rm -rf conftest*
812  LIBS=$ac_[]_AC_LANG_ABBREV[]_dm_save_LIBS
814 []_AC_FC[]_DUMMY_MAIN=$ac_cv_[]_AC_LANG_ABBREV[]_dummy_main
815 AS_IF([test "$[]_AC_FC[]_DUMMY_MAIN" != unknown],
816       [m4_default([$1],
817 [if test $[]_AC_FC[]_DUMMY_MAIN != none; then
818   AC_DEFINE_UNQUOTED([]_AC_FC[]_DUMMY_MAIN, $[]_AC_FC[]_DUMMY_MAIN,
819                      [Define to dummy `main' function (if any) required to
820                       link to the Fortran libraries.])
821   if test "x$ac_cv_fc_dummy_main" = "x$ac_cv_f77_dummy_main"; then
822         AC_DEFINE([FC_DUMMY_MAIN_EQ_F77], 1,
823                   [Define if F77 and FC dummy `main' functions are identical.])
824   fi
825 fi])],
826       [m4_default([$2],
827             [AC_MSG_FAILURE([linking to Fortran libraries from C fails])])])
828 ])# _AC_FC_DUMMY_MAIN
831 # AC_F77_DUMMY_MAIN
832 # -----------------
833 AC_DEFUN([AC_F77_DUMMY_MAIN],
834 [AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
835 AC_LANG_PUSH(Fortran 77)dnl
836 _AC_FC_DUMMY_MAIN($@)
837 AC_LANG_POP(Fortran 77)dnl
838 ])# AC_F77_DUMMY_MAIN
841 # AC_FC_DUMMY_MAIN
842 # ----------------
843 AC_DEFUN([AC_FC_DUMMY_MAIN],
844 [AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
845 AC_LANG_PUSH(Fortran)dnl
846 _AC_FC_DUMMY_MAIN($@)
847 AC_LANG_POP(Fortran)dnl
848 ])# AC_FC_DUMMY_MAIN
851 # _AC_FC_MAIN
852 # -----------
853 # Define {F77,FC}_MAIN to name of alternate main() function for use with
854 # the Fortran libraries.  (Typically, the libraries may define their
855 # own main() to initialize I/O, etcetera, that then call your own
856 # routine called MAIN__ or whatever.)  See _AC_FC_DUMMY_MAIN, above.
857 # If no such alternate name is found, just define {F77,FC}_MAIN to main.
859 AC_DEFUN([_AC_FC_MAIN],
860 [_AC_FORTRAN_ASSERT()dnl
861 AC_CACHE_CHECK([for alternate main to link with _AC_LANG libraries],
862                ac_cv_[]_AC_LANG_ABBREV[]_main,
863 [ac_[]_AC_LANG_ABBREV[]_m_save_LIBS=$LIBS
864  LIBS="$LIBS $[]_AC_LANG_PREFIX[]LIBS"
865  ac_fortran_dm_var=[]_AC_FC[]_DUMMY_MAIN
866  AC_LANG_PUSH(C)dnl
867  ac_cv_fortran_main="main" # default entry point name
868  for ac_func in MAIN__ MAIN_ __main MAIN _MAIN __MAIN main_ main__ _main; do
869    AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@ifdef FC_DUMMY_MAIN_EQ_F77
870 @%:@  undef F77_DUMMY_MAIN
871 @%:@  undef FC_DUMMY_MAIN
872 @%:@else
873 @%:@  undef $ac_fortran_dm_var
874 @%:@endif
875 @%:@define main $ac_func])],
876                   [ac_cv_fortran_main=$ac_func; break])
877  done
878  AC_LANG_POP(C)dnl
879  ac_cv_[]_AC_LANG_ABBREV[]_main=$ac_cv_fortran_main
880  rm -rf conftest*
881  LIBS=$ac_[]_AC_LANG_ABBREV[]_m_save_LIBS
883 AC_DEFINE_UNQUOTED([]_AC_FC[]_MAIN, $ac_cv_[]_AC_LANG_ABBREV[]_main,
884                    [Define to alternate name for `main' routine that is
885                     called from a `main' in the Fortran libraries.])
886 ])# _AC_FC_MAIN
889 # AC_F77_MAIN
890 # -----------
891 AC_DEFUN([AC_F77_MAIN],
892 [AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
893 AC_LANG_PUSH(Fortran 77)dnl
894 _AC_FC_MAIN
895 AC_LANG_POP(Fortran 77)dnl
896 ])# AC_F77_MAIN
899 # AC_FC_MAIN
900 # ----------
901 AC_DEFUN([AC_FC_MAIN],
902 [AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
903 AC_LANG_PUSH(Fortran)dnl
904 _AC_FC_MAIN
905 AC_LANG_POP(Fortran)dnl
906 ])# AC_FC_MAIN
909 # __AC_FC_NAME_MANGLING
910 # ---------------------
911 # Test for the name mangling scheme used by the Fortran compiler.
913 # Sets ac_cv_{f77,fc}_mangling. The value contains three fields, separated
914 # by commas:
916 # lower case / upper case:
917 #    case translation of the Fortran symbols
918 # underscore / no underscore:
919 #    whether the compiler appends "_" to symbol names
920 # extra underscore / no extra underscore:
921 #    whether the compiler appends an extra "_" to symbol names already
922 #    containing at least one underscore
924 AC_DEFUN([__AC_FC_NAME_MANGLING],
925 [_AC_FORTRAN_ASSERT()dnl
926 AC_CACHE_CHECK([for _AC_LANG name-mangling scheme],
927                ac_cv_[]_AC_LANG_ABBREV[]_mangling,
928 [AC_COMPILE_IFELSE(
929 [[      subroutine foobar()
930       return
931       end
932       subroutine foo_bar()
933       return
934       end]],
935 [mv conftest.$ac_objext cfortran_test.$ac_objext
937   ac_save_LIBS=$LIBS
938   LIBS="cfortran_test.$ac_objext $LIBS $[]_AC_LANG_PREFIX[]LIBS"
940   AC_LANG_PUSH(C)dnl
941   ac_success=no
942   for ac_foobar in foobar FOOBAR; do
943     for ac_underscore in "" "_"; do
944       ac_func="$ac_foobar$ac_underscore"
945       AC_LINK_IFELSE([AC_LANG_CALL([], [$ac_func])],
946                      [ac_success=yes; break 2])
947     done
948   done
949   AC_LANG_POP(C)dnl
951   if test "$ac_success" = "yes"; then
952      case $ac_foobar in
953         foobar)
954            ac_case=lower
955            ac_foo_bar=foo_bar
956            ;;
957         FOOBAR)
958            ac_case=upper
959            ac_foo_bar=FOO_BAR
960            ;;
961      esac
963      AC_LANG_PUSH(C)dnl
964      ac_success_extra=no
965      for ac_extra in "" "_"; do
966         ac_func="$ac_foo_bar$ac_underscore$ac_extra"
967         AC_LINK_IFELSE([AC_LANG_CALL([], [$ac_func])],
968                        [ac_success_extra=yes; break])
969      done
970      AC_LANG_POP(C)dnl
972      if test "$ac_success_extra" = "yes"; then
973         ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_case case"
974         if test -z "$ac_underscore"; then
975            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, no underscore"
976         else
977            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, underscore"
978         fi
979         if test -z "$ac_extra"; then
980            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, no extra underscore"
981         else
982            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, extra underscore"
983         fi
984       else
985         ac_cv_[]_AC_LANG_ABBREV[]_mangling="unknown"
986       fi
987   else
988      ac_cv_[]_AC_LANG_ABBREV[]_mangling="unknown"
989   fi
991   LIBS=$ac_save_LIBS
992   rm -rf conftest*
993   rm -f cfortran_test*],
994   [AC_MSG_FAILURE([cannot compile a simple Fortran program])])
996 ])# __AC_FC_NAME_MANGLING
998 # The replacement is empty.
999 AU_DEFUN([AC_F77_NAME_MANGLING], [])
1002 # _AC_F77_NAME_MANGLING
1003 # ---------------------
1004 AC_DEFUN([_AC_F77_NAME_MANGLING],
1005 [AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
1006 AC_REQUIRE([AC_F77_DUMMY_MAIN])dnl
1007 AC_LANG_PUSH(Fortran 77)dnl
1008 __AC_FC_NAME_MANGLING
1009 AC_LANG_POP(Fortran 77)dnl
1010 ])# _AC_F77_NAME_MANGLING
1013 # _AC_FC_NAME_MANGLING
1014 # --------------------
1015 AC_DEFUN([_AC_FC_NAME_MANGLING],
1016 [AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
1017 AC_REQUIRE([AC_FC_DUMMY_MAIN])dnl
1018 AC_LANG_PUSH(Fortran)dnl
1019 __AC_FC_NAME_MANGLING
1020 AC_LANG_POP(Fortran)dnl
1021 ])# _AC_FC_NAME_MANGLING
1024 # _AC_FC_WRAPPERS
1025 # ---------------
1026 # Defines C macros {F77,FC}_FUNC(name,NAME) and {F77,FC}_FUNC_(name,NAME) to
1027 # properly mangle the names of C identifiers, and C identifiers with
1028 # underscores, respectively, so that they match the name mangling
1029 # scheme used by the Fortran compiler.
1030 AC_DEFUN([_AC_FC_WRAPPERS],
1031 [_AC_FORTRAN_ASSERT()dnl
1032 AH_TEMPLATE(_AC_FC[_FUNC],
1033     [Define to a macro mangling the given C identifier (in lower and upper
1034      case), which must not contain underscores, for linking with Fortran.])dnl
1035 AH_TEMPLATE(_AC_FC[_FUNC_],
1036     [As ]_AC_FC[_FUNC, but for C identifiers containing underscores.])dnl
1037 case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in
1038   "lower case, no underscore, no extra underscore")
1039           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name])
1040           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name]) ;;
1041   "lower case, no underscore, extra underscore")
1042           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name])
1043           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name [##] _]) ;;
1044   "lower case, underscore, no extra underscore")
1045           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name [##] _])
1046           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name [##] _]) ;;
1047   "lower case, underscore, extra underscore")
1048           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name [##] _])
1049           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name [##] __]) ;;
1050   "upper case, no underscore, no extra underscore")
1051           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME])
1052           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME]) ;;
1053   "upper case, no underscore, extra underscore")
1054           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME])
1055           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME [##] _]) ;;
1056   "upper case, underscore, no extra underscore")
1057           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME [##] _])
1058           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME [##] _]) ;;
1059   "upper case, underscore, extra underscore")
1060           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME [##] _])
1061           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME [##] __]) ;;
1062   *)
1063           AC_MSG_WARN([unknown Fortran name-mangling scheme])
1064           ;;
1065 esac
1066 ])# _AC_FC_WRAPPERS
1069 # AC_F77_WRAPPERS
1070 # ---------------
1071 AC_DEFUN([AC_F77_WRAPPERS],
1072 [AC_REQUIRE([_AC_F77_NAME_MANGLING])dnl
1073 AC_LANG_PUSH(Fortran 77)dnl
1074 _AC_FC_WRAPPERS
1075 AC_LANG_POP(Fortran 77)dnl
1076 ])# AC_F77_WRAPPERS
1079 # AC_FC_WRAPPERS
1080 # --------------
1081 AC_DEFUN([AC_FC_WRAPPERS],
1082 [AC_REQUIRE([_AC_FC_NAME_MANGLING])dnl
1083 AC_LANG_PUSH(Fortran)dnl
1084 _AC_FC_WRAPPERS
1085 AC_LANG_POP(Fortran)dnl
1086 ])# AC_FC_WRAPPERS
1089 # _AC_FC_FUNC(NAME, [SHELLVAR = NAME])
1090 # ------------------------------------
1091 # For a Fortran subroutine of given NAME, define a shell variable
1092 # $SHELLVAR to the Fortran-mangled name.  If the SHELLVAR
1093 # argument is not supplied, it defaults to NAME.
1094 AC_DEFUN([_AC_FC_FUNC],
1095 [_AC_FORTRAN_ASSERT()dnl
1096 case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in
1097   upper*) ac_val="m4_toupper([$1])" ;;
1098   lower*) ac_val="m4_tolower([$1])" ;;
1099   *)      ac_val="unknown" ;;
1100 esac
1101 case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in *," underscore"*) ac_val="$ac_val"_ ;; esac
1102 m4_if(m4_index([$1],[_]),-1,[],
1103 [case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in *," extra underscore"*) ac_val="$ac_val"_ ;; esac
1105 m4_default([$2],[$1])="$ac_val"
1106 ])# _AC_FC_FUNC
1109 # AC_F77_FUNC(NAME, [SHELLVAR = NAME])
1110 # ------------------------------------
1111 AC_DEFUN([AC_F77_FUNC],
1112 [AC_REQUIRE([_AC_F77_NAME_MANGLING])dnl
1113 AC_LANG_PUSH(Fortran 77)dnl
1114 _AC_FC_FUNC([$1],[$2])
1115 AC_LANG_POP(Fortran 77)dnl
1116 ])# AC_F77_FUNC
1119 # AC_FC_FUNC(NAME, [SHELLVAR = NAME])
1120 # -----------------------------------
1121 AC_DEFUN([AC_FC_FUNC],
1122 [AC_REQUIRE([_AC_FC_NAME_MANGLING])dnl
1123 AC_LANG_PUSH(Fortran)dnl
1124 _AC_FC_FUNC([$1],[$2])
1125 AC_LANG_POP(Fortran)dnl
1126 ])# AC_FC_FUNC
1129 # AC_FC_SRCEXT(EXT, [ACTION-IF-SUCCESS], [ACTION-IF-FAILURE])
1130 # -----------------------------------------------------------
1131 # Set the source-code extension used in Fortran (FC) tests to EXT (which
1132 # defaults to f).  Also, look for any necessary additional FCFLAGS needed
1133 # to allow this extension, and store them in the output variable
1134 # FCFLAGS_<EXT> (e.g. FCFLAGS_f90 for EXT=f90).  If successful,
1135 # call ACTION-IF-SUCCESS.  If unable to compile source code with EXT,
1136 # call ACTION-IF-FAILURE, which defaults to failing with an error
1137 # message.
1139 # (The flags for the current source-code extension, if any, are stored in
1140 # $ac_fcflags_srcext and used automatically in subsequent autoconf tests.)
1142 # For ordinary extensions like f90, etcetera, the modified FCFLAGS
1143 # are currently needed for IBM's xlf* and Intel's ifc (grrr).  Unfortunately,
1144 # xlf* will only take flags to recognize one extension at a time, so if the
1145 # user wants to compile multiple extensions (.f90 and .f95, say), she
1146 # will need to use the FCFLAGS_F90 and FCFLAGS_F95 individually rather
1147 # than just adding them all to FCFLAGS, for example.
1149 # Also, for Intel's ifc compiler (which does not accept .f95 by default in
1150 # some versions), the $FCFLAGS_<EXT> variable *must* go immediately before
1151 # the source file on the command line, unlike other $FCFLAGS.  Ugh.
1153 # gfortran requires '-x f77' in order to recognize .f77 files.
1154 AC_DEFUN([AC_FC_SRCEXT],
1155 [AC_LANG_PUSH(Fortran)dnl
1156 AC_CACHE_CHECK([for Fortran flag to compile .$1 files],
1157                 ac_cv_fc_srcext_$1,
1158 [ac_ext=$1
1159 ac_fcflags_srcext_save=$ac_fcflags_srcext
1160 ac_fcflags_srcext=
1161 ac_cv_fc_srcext_$1=unknown
1162 case $ac_ext in #(
1163   [[fF]]77) ac_try=f77;; #(
1164   *) ac_try=f95;;
1165 esac
1166 for ac_flag in none -qsuffix=f=$1 -Tf "-x $ac_try"; do
1167   test "x$ac_flag" != xnone && ac_fcflags_srcext="$ac_flag"
1168   AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [ac_cv_fc_srcext_$1=$ac_flag; break])
1169 done
1170 rm -f conftest.$ac_objext conftest.$1
1171 ac_fcflags_srcext=$ac_fcflags_srcext_save
1173 if test "x$ac_cv_fc_srcext_$1" = xunknown; then
1174   m4_default([$3],[AC_MSG_ERROR([Fortran could not compile .$1 files])])
1175 else
1176   ac_fc_srcext=$1
1177   if test "x$ac_cv_fc_srcext_$1" = xnone; then
1178     ac_fcflags_srcext=""
1179     FCFLAGS_[]$1[]=""
1180   else
1181     ac_fcflags_srcext=$ac_cv_fc_srcext_$1
1182     FCFLAGS_[]$1[]=$ac_cv_fc_srcext_$1
1183   fi
1184   AC_SUBST(FCFLAGS_[]$1)
1185   $2
1187 AC_LANG_POP(Fortran)dnl
1188 ])# AC_FC_SRCEXT
1191 # AC_FC_PP_SRCEXT(EXT, [ACTION-IF-SUCCESS], [ACTION-IF-FAILURE])
1192 # --------------------------------------------------------------
1193 # Like AC_FC_SRCEXT, set the source-code extension used in Fortran (FC) tests
1194 # to EXT (which defaults to f).  Also, look for any necessary additional
1195 # FCFLAGS needed to allow this extension for preprocessed Fortran, and store
1196 # them in the output variable FCFLAGS_<EXT> (e.g. FCFLAGS_f90 for EXT=f90).
1197 # If successful, call ACTION-IF-SUCCESS.  If unable to compile preprocessed
1198 # source code with EXT, call ACTION-IF-FAILURE, which defaults to failing with
1199 # an error message.
1201 # Some compilers allow preprocessing with either a Fortran preprocessor or
1202 # with the C preprocessor (cpp).  Prefer the Fortran preprocessor, to deal
1203 # correctly with continuation lines, `//' (not a comment), and preserve white
1204 # space (for fixed form).
1206 # (The flags for the current source-code extension, if any, are stored in
1207 # $ac_fcflags_srcext and used automatically in subsequent autoconf tests.)
1209 # For ordinary extensions like f90, etcetera, the modified FCFLAGS
1210 # are needed for IBM's xlf*.  Also, for Intel's ifort compiler, the
1211 # $FCFLAGS_<EXT> variable *must* go immediately before the source file on the
1212 # command line, unlike other $FCFLAGS.  Ugh.
1214 # Known extensions that enable preprocessing by default, and flags to force it:
1215 # GNU: .F .F90 .F95 .F03 .F08, -cpp for most others,
1216 #      -x f77-cpp-input for .f77 .F77; -x f95-cpp-input for gfortran < 4.4
1217 # SGI: .F .F90, -ftpp or -cpp for .f .f90, -E write preproc to stdout
1218 #      -macro_expand enable macro expansion everywhere (with -ftpp)
1219 #      -P preproc only, save in .i, no #line's
1220 # SUN: .F .F95, -fpp for others; -xpp={fpp,cpp} for preprocessor selection
1221 #      -F preprocess only (save in lowercase extension)
1222 # IBM: .F .F77 .F90 .F95 .F03, -qsuffix=cpp=EXT for extension .EXT to invoke cpp
1223 #      -WF,-qnofpp -WF,-qfpp=comment:linecont:nocomment:nolinecont
1224 #      -WF,-qlanglvl=classic or not -qnoescape (trigraph problems)
1225 #      -d no #line in output, -qnoobject for preprocessing only (output in .f)
1226 #      -q{no,}ppsuborigarg substitute original macro args before expansion
1227 # HP:  .F, +cpp={yes|no|default} use cpp, -cpp, +cpp_keep save in .i/.i90
1228 # PGI: -Mpreprocess
1229 # Absoft: .F .FOR .F90 .F95, -cpp for others
1230 # Cray: .F .F90 .FTN, -e Z for others; -F enable macro expansion everywhere
1231 # Intel: .F .F90, -fpp for others, but except for .f and .f90, -Tf may also be
1232 #        needed right before the source file name
1233 # PathScale: .F .F90 .F95, -ftpp or -cpp for .f .f90 .f95
1234 #         -macro_expand for expansion everywhere, -P for no #line in output
1235 # Lahey: .F .FOR .F90 .F95, -Cpp
1236 # NAGWare: .F .F90 .F95, .ff .ff90 .ff95 (new), -fpp for others
1237 # Compaq/Tru64: .F .F90, -cpp, -P keep .i file, -P keep .i file
1238 # f2c: .F, -cpp
1239 # g95: .F .FOR .F90 .F95 .F03, -cpp -no-cpp, -E for stdout
1240 AC_DEFUN([AC_FC_PP_SRCEXT],
1241 [AC_LANG_PUSH(Fortran)dnl
1242 AC_CACHE_CHECK([for Fortran flag to compile preprocessed .$1 files],
1243                 ac_cv_fc_pp_srcext_$1,
1244 [ac_ext=$1
1245 ac_fcflags_pp_srcext_save=$ac_fcflags_srcext
1246 ac_fcflags_srcext=
1247 ac_cv_fc_pp_srcext_$1=unknown
1248 case $ac_ext in #(
1249   [[fF]]77) ac_try=f77-cpp-input;; #(
1250   *) ac_try=f95-cpp-input;;
1251 esac
1252 for ac_flag in none -ftpp -fpp -Tf "-fpp -Tf" -xpp=fpp -Mpreprocess "-e Z" \
1253                -cpp -xpp=cpp -qsuffix=cpp=$1 "-x $ac_try" +cpp -Cpp; do
1254   test "x$ac_flag" != xnone && ac_fcflags_srcext="$ac_flag"
1255   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
1256 #if 0
1257 #include <ac_nonexistent.h>
1258       choke me
1259 #endif]])],
1260     [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
1261 #if 1
1262 #include <ac_nonexistent.h>
1263       choke me
1264 #endif]])],
1265        [],
1266        [ac_cv_fc_pp_srcext_$1=$ac_flag; break])])
1267 done
1268 rm -f conftest.$ac_objext conftest.$1
1269 ac_fcflags_srcext=$ac_fcflags_pp_srcext_save
1271 if test "x$ac_cv_fc_pp_srcext_$1" = xunknown; then
1272   m4_default([$3],
1273              [AC_MSG_ERROR([Fortran could not compile preprocessed .$1 files])])
1274 else
1275   ac_fc_srcext=$1
1276   if test "x$ac_cv_fc_pp_srcext_$1" = xnone; then
1277     ac_fcflags_srcext=""
1278     FCFLAGS_[]$1[]=""
1279   else
1280     ac_fcflags_srcext=$ac_cv_fc_pp_srcext_$1
1281     FCFLAGS_[]$1[]=$ac_cv_fc_pp_srcext_$1
1282   fi
1283   AC_SUBST(FCFLAGS_[]$1)
1284   $2
1286 AC_LANG_POP(Fortran)dnl
1287 ])# AC_FC_PP_SRCEXT
1290 # AC_FC_PP_DEFINE([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1291 # -------------------------------------------------------------------
1292 # Find a flag to specify defines for preprocessed Fortran.  Not all
1293 # Fortran compilers use -D.  Substitute FC_DEFINE with the result and
1294 # call ACTION-IF-SUCCESS (defaults to nothing) if successful, and
1295 # ACTION-IF-FAILURE (defaults to failing with an error message) if not.
1297 # Known flags:
1298 # IBM: -WF,-D
1299 # Lahey/Fujitsu: -Wp,-D     older versions???
1300 # f2c: -D or -Wc,-D
1301 # others: -D
1302 AC_DEFUN([AC_FC_PP_DEFINE],
1303 [AC_LANG_PUSH([Fortran])dnl
1304 ac_fc_pp_define_srcext_save=$ac_fc_srcext
1305 AC_FC_PP_SRCEXT([F])
1306 AC_CACHE_CHECK([how to define symbols for preprocessed Fortran],
1307   [ac_cv_fc_pp_define],
1308 [ac_fc_pp_define_srcext_save=$ac_fc_srcext
1309 ac_cv_fc_pp_define=unknown
1310 ac_fc_pp_define_FCFLAGS_save=$FCFLAGS
1311 for ac_flag in -D -WF,-D -Wp,-D -Wc,-D
1313   FCFLAGS="$ac_fc_pp_define_FCFLAGS_save ${ac_flag}FOOBAR ${ac_flag}ZORK=42"
1314   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
1315 #ifndef FOOBAR
1316       choke me
1317 #endif
1318 #if ZORK != 42
1319       choke me
1320 #endif]])],
1321     [ac_cv_fc_pp_define=$ac_flag])
1322   test x"$ac_cv_fc_pp_define" != xunknown && break
1323 done
1324 FCFLAGS=$ac_fc_pp_define_FCFLAGS_save
1326 ac_fc_srcext=$ac_fc_pp_define_srcext_save
1327 if test "x$ac_cv_fc_pp_define" = xunknown; then
1328   FC_DEFINE=
1329   m4_default([$2],
1330              [AC_MSG_ERROR([Fortran does not allow to define preprocessor symbols], 77)])
1331 else
1332   FC_DEFINE=$ac_cv_fc_pp_define
1333   $1
1335 AC_SUBST([FC_DEFINE])dnl
1336 AC_LANG_POP([Fortran])dnl
1340 # AC_FC_FREEFORM([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1341 # ------------------------------------------------------------------
1342 # Look for a compiler flag to make the Fortran (FC) compiler accept
1343 # free-format source code, and adds it to FCFLAGS.  Call
1344 # ACTION-IF-SUCCESS (defaults to nothing) if successful (i.e. can
1345 # compile code using new extension) and ACTION-IF-FAILURE (defaults to
1346 # failing with an error message) if not.  (Defined via DEFUN_ONCE to
1347 # prevent flag from being added to FCFLAGS multiple times.)
1349 # The known flags are:
1350 #        -ffree-form: GNU g77, gfortran, g95
1351 #         -FR, -free: Intel compiler (icc, ecc, ifort)
1352 #              -free: Compaq compiler (fort), Sun compiler (f95)
1353 #             -qfree: IBM compiler (xlf)
1354 # -Mfree, -Mfreeform: Portland Group compiler
1355 #          -freeform: SGI compiler
1356 #        -8, -f free: Absoft Fortran
1357 #       +source=free: HP Fortran
1358 #    (-)-nfix, -Free: Lahey/Fujitsu Fortran
1359 #              -free: NAGWare
1360 #         -f, -Wf,-f: f2c (but only a weak form of "free-form" and long lines)
1361 # We try to test the "more popular" flags first, by some prejudiced
1362 # notion of popularity.
1363 AC_DEFUN_ONCE([AC_FC_FREEFORM],
1364 [AC_LANG_PUSH([Fortran])dnl
1365 AC_CACHE_CHECK([for Fortran flag needed to accept free-form source],
1366                [ac_cv_fc_freeform],
1367 [ac_cv_fc_freeform=unknown
1368 ac_fc_freeform_FCFLAGS_save=$FCFLAGS
1369 for ac_flag in none -ffree-form -FR -free -qfree -Mfree -Mfreeform \
1370                -freeform "-f free" -8 +source=free -nfix --nfix -Free
1372   test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_freeform_FCFLAGS_save $ac_flag"
1373 dnl Use @&t@ below to ensure that editors don't turn 8+ spaces into tab.
1374   AC_COMPILE_IFELSE([[
1375   program freeform
1376        ! FIXME: how to best confuse non-freeform compilers?
1377        print *, 'Hello ', &
1378      @&t@     'world.'
1379        end]],
1380                     [ac_cv_fc_freeform=$ac_flag; break])
1381 done
1382 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
1383 FCFLAGS=$ac_fc_freeform_FCFLAGS_save
1385 if test "x$ac_cv_fc_freeform" = xunknown; then
1386   m4_default([$2],
1387              [AC_MSG_ERROR([Fortran does not accept free-form source], 77)])
1388 else
1389   if test "x$ac_cv_fc_freeform" != xnone; then
1390     FCFLAGS="$FCFLAGS $ac_cv_fc_freeform"
1391   fi
1392   $1
1394 AC_LANG_POP([Fortran])dnl
1395 ])# AC_FC_FREEFORM
1398 # AC_FC_FIXEDFORM([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1399 # ------------------------------------------------------------------
1400 # Look for a compiler flag to make the Fortran (FC) compiler accept
1401 # fixed-format source code, and adds it to FCFLAGS.  Call
1402 # ACTION-IF-SUCCESS (defaults to nothing) if successful (i.e. can
1403 # compile code using new extension) and ACTION-IF-FAILURE (defaults to
1404 # failing with an error message) if not.  (Defined via DEFUN_ONCE to
1405 # prevent flag from being added to FCFLAGS multiple times.)
1407 # The known flags are:
1408 #       -ffixed-form: GNU g77, gfortran, g95
1409 #             -fixed: Intel compiler (ifort), Sun compiler (f95)
1410 #            -qfixed: IBM compiler (xlf*)
1411 #            -Mfixed: Portland Group compiler
1412 #         -fixedform: SGI compiler
1413 #           -f fixed: Absoft Fortran
1414 #      +source=fixed: HP Fortran
1415 #    (-)-fix, -Fixed: Lahey/Fujitsu Fortran
1416 #             -fixed: NAGWare
1417 # Since compilers may accept fixed form based on file name extension,
1418 # but users may want to use it with others as well, call AC_FC_SRCEXT
1419 # with the respective source extension before calling this macro.
1420 AC_DEFUN_ONCE([AC_FC_FIXEDFORM],
1421 [AC_LANG_PUSH([Fortran])dnl
1422 AC_CACHE_CHECK([for Fortran flag needed to accept fixed-form source],
1423                [ac_cv_fc_fixedform],
1424 [ac_cv_fc_fixedform=unknown
1425 ac_fc_fixedform_FCFLAGS_save=$FCFLAGS
1426 for ac_flag in none -ffixed-form -fixed -qfixed -Mfixed -fixedform "-f fixed" \
1427                +source=fixed -fix --fix -Fixed
1429   test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_fixedform_FCFLAGS_save $ac_flag"
1430   AC_COMPILE_IFELSE([[
1431 C     This comment should confuse free-form compilers.
1432       program main
1433       end]],
1434                     [ac_cv_fc_fixedform=$ac_flag; break])
1435 done
1436 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
1437 FCFLAGS=$ac_fc_fixedform_FCFLAGS_save
1439 if test "x$ac_cv_fc_fixedform" = xunknown; then
1440   m4_default([$2],
1441              [AC_MSG_ERROR([Fortran does not accept fixed-form source], 77)])
1442 else
1443   if test "x$ac_cv_fc_fixedform" != xnone; then
1444     FCFLAGS="$FCFLAGS $ac_cv_fc_fixedform"
1445   fi
1446   $1
1448 AC_LANG_POP([Fortran])dnl
1449 ])# AC_FC_FIXEDFORM
1452 # AC_FC_LINE_LENGTH([LENGTH], [ACTION-IF-SUCCESS],
1453 #                   [ACTION-IF-FAILURE = FAILURE])
1454 # ------------------------------------------------
1455 # Look for a compiler flag to make the Fortran (FC) compiler accept long lines
1456 # in the current (free- or fixed-format) source code, and adds it to FCFLAGS.
1457 # The optional LENGTH may be 80, 132 (default), or `unlimited' for longer
1458 # lines.  Note that line lengths above 254 columns are not portable, and some
1459 # compilers (hello ifort) do not accept more than 132 columns at least for
1460 # fixed format.  Call ACTION-IF-SUCCESS (defaults to nothing) if successful
1461 # (i.e. can compile code using new extension) and ACTION-IF-FAILURE (defaults
1462 # to failing with an error message) if not.  (Defined via DEFUN_ONCE to
1463 # prevent flag from being added to FCFLAGS multiple times.)
1464 # You should call AC_FC_FREEFORM or AC_FC_FIXEDFORM to set the desired format
1465 # prior to using this macro.
1467 # The known flags are:
1468 # -f{free,fixed}-line-length-N with N 72, 80, 132, or 0 or none for none.
1469 # -ffree-line-length-none: GNU gfortran
1470 # -ffree-line-length-huge: g95 (also -ffixed-line-length-N as above)
1471 #       -qfixed=132 80 72: IBM compiler (xlf)
1472 #                -Mextend: Cray
1473 #            -132 -80 -72: Intel compiler (ifort)
1474 #                          Needs to come before -extend_source because ifort
1475 #                          accepts that as well with an optional parameter and
1476 #                          doesn't fail but only warns about unknown arguments.
1477 #          -extend_source: SGI compiler
1478 #  -W, -WNN (132, 80, 72): Absoft Fortran
1479 #     +es, +extend_source: HP Fortran (254 in either form, default is 72 fixed,
1480 #                          132 free)
1481 #            -w, (-)-wide: Lahey/Fujitsu Fortran (255 cols in fixed form)
1482 #                      -e: Sun Fortran compiler (132 characters)
1483 #                    -132: NAGWare
1484 #         -72, -f, -Wf,-f: f2c (a weak form of "free-form" and long lines).
1485 #                  /XLine: Open Watcom
1486 AC_DEFUN_ONCE([AC_FC_LINE_LENGTH],
1487 [AC_LANG_PUSH([Fortran])dnl
1488 m4_case(m4_default([$1], [132]),
1489   [unlimited], [ac_fc_line_len_string=unlimited
1490                        ac_fc_line_len=0
1491                        ac_fc_line_length_test='
1492       subroutine longer_than_132(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,'\
1493 'arg9,arg10,arg11,arg12,arg13,arg14,arg15,arg16,arg17,arg18,arg19)'],
1494   [132],            [ac_fc_line_len=132
1495                        ac_fc_line_length_test='
1496       subroutine longer_than_80(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,'\
1497 'arg10)'],
1498   [80],             [ac_fc_line_len=80
1499                        ac_fc_line_length_test='
1500       subroutine longer_than_72(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)'],
1501   [m4_warning([Invalid length argument `$1'])])
1502 : ${ac_fc_line_len_string=$ac_fc_line_len}
1503 AC_CACHE_CHECK(
1504 [for Fortran flag needed to accept $ac_fc_line_len_string column source lines],
1505                [ac_cv_fc_line_length],
1506 [ac_cv_fc_line_length=unknown
1507 ac_fc_line_length_FCFLAGS_save=$FCFLAGS
1508 for ac_flag in none \
1509                -ffree-line-length-none -ffixed-line-length-none \
1510                -ffree-line-length-huge \
1511                -ffree-line-length-$ac_fc_line_len \
1512                -ffixed-line-length-$ac_fc_line_len \
1513                -qfixed=$ac_fc_line_len -Mextend \
1514                -$ac_fc_line_len -extend_source \
1515                -W$ac_fc_line_len -W +extend_source +es -wide --wide -w -e \
1516                -f -Wf,-f -xline
1518   test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_line_length_FCFLAGS_save $ac_flag"
1519   AC_COMPILE_IFELSE([[$ac_fc_line_length_test
1520       end subroutine]],
1521                     [ac_cv_fc_line_length=$ac_flag; break])
1522 done
1523 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
1524 FCFLAGS=$ac_fc_line_length_FCFLAGS_save
1526 if test "x$ac_cv_fc_line_length" = xunknown; then
1527   m4_default([$3],
1528              [AC_MSG_ERROR([Fortran does not accept long source lines], 77)])
1529 else
1530   if test "x$ac_cv_fc_line_length" != xnone; then
1531     FCFLAGS="$FCFLAGS $ac_cv_fc_line_length"
1532   fi
1533   $2
1535 AC_LANG_POP([Fortran])dnl
1536 ])# AC_FC_LINE_LENGTH
1539 # AC_FC_CHECK_BOUNDS([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1540 # ----------------------------------------------------------------------
1541 # Look for a compiler flag to turn on array bounds checking for the
1542 # Fortran (FC) compiler, and adds it to FCFLAGS.  Call
1543 # ACTION-IF-SUCCESS (defaults to nothing) if successful (i.e. can
1544 # compile code using new extension) and ACTION-IF-FAILURE (defaults to
1545 # failing with an error message) if not.  (Defined via DEFUN_ONCE to
1546 # prevent flag from being added to FCFLAGS multiple times.)
1548 # The known flags are:
1549 # -fcheck=all, -fbounds-check: gfortran
1550 #     -fbounds-check: g77, g95
1551 # -CB, -check bounds: Intel compiler (icc, ecc, ifort)
1552 #                 -C: Sun/Oracle compiler (f95)
1553 #        -C, -qcheck: IBM compiler (xlf)
1554 #           -Mbounds: Portland Group compiler
1555 #       -C ,-Mbounds: Cray
1556 #  -C, -check_bounds: SGI compiler
1557 # -check_bounds, +check=all: HP Fortran
1558 #        -C, -Rb -Rc: Absoft (-Rb: array boundaries, -Rc: array conformance)
1559 # --chk e,s -chk (e,s): Lahey
1560 #          -C -C=all: NAGWare
1561 # -C, -ffortran-bounds-check: PathScale pathf90
1562 #                 -C: f2c
1563 #            -BOunds: Open Watcom
1564 AC_DEFUN_ONCE([AC_FC_CHECK_BOUNDS],
1565 [AC_LANG_PUSH([Fortran])dnl
1566 AC_CACHE_CHECK([for Fortran flag to enable array-bounds checking],
1567                [ac_cv_fc_check_bounds],
1568 [ac_cv_fc_check_bounds=unknown
1569 ac_fc_check_bounds_FCFLAGS_save=$FCFLAGS
1570 for ac_flag in -fcheck=bounds -fbounds-check -check_bounds -Mbounds -qcheck \
1571                '-check bounds' +check=all --check '-Rb -Rc' -CB -C=all -C \
1572                -ffortran-bounds-check "--chk e,s" "-chk e -chk s" -bounds
1574   FCFLAGS="$ac_fc_check_bounds_FCFLAGS_save $ac_flag"
1575   # We should be able to link a correct program.
1576   AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
1577     [AC_LINK_IFELSE([[
1578       subroutine sub(a)
1579       integer a(:)
1580       a(8) = 0
1581       end subroutine
1583       program main
1584       integer a(1:7)
1585       interface
1586          subroutine sub(a)
1587          integer a(:)
1588          end subroutine
1589       end interface
1591       call sub(a)
1592       end program]],
1593        [# If we can run the program, require failure at run time.
1594         # In cross-compiling mode, we rely on the compiler not accepting
1595         # unknown options.
1596         AS_IF([test "$cross_compiling" = yes],
1597           [ac_cv_fc_check_bounds=$ac_flag; break],
1598           [AS_IF([_AC_DO_TOKENS(./conftest$ac_exeext)],
1599              [],
1600              [ac_cv_fc_check_bounds=$ac_flag; break])])])])
1601 done
1602 rm -f conftest$ac_exeext conftest.err conftest.$ac_objext conftest.$ac_ext \
1603   core *.core core.conftest.*
1604 FCFLAGS=$ac_fc_check_bounds_FCFLAGS_save
1606 if test "x$ac_cv_fc_check_bounds" = xunknown; then
1607   m4_default([$2],
1608              [AC_MSG_ERROR([no Fortran flag for bounds checking found], 77)])
1609 else
1610   if test "x$ac_cv_fc_check_bounds" != xnone; then
1611     FCFLAGS="$FCFLAGS $ac_cv_fc_check_bounds"
1612   fi
1613   $1
1615 AC_LANG_POP([Fortran])dnl
1616 ])# AC_FC_CHECK_BOUNDS
1619 # _AC_FC_IMPLICIT_NONE([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1620 # ------------------------------------------------------------------------
1621 # Look for a flag to disallow implicit declarations, and add it to FCFLAGS.
1622 # Call ACTION-IF-SUCCESS (defaults to nothing) if successful and
1623 # ACTION-IF-FAILURE (defaults to failing with an error message) if not.
1625 # Known flags:
1626 # GNU gfortran, g95: -fimplicit-none, g77: -Wimplicit
1627 # Intel: -u, -implicitnone; might also need '-warn errors' to turn into error.
1628 # Sun/Oracle: -u
1629 # HP: +implicit_none
1630 # IBM: -u, -qundef
1631 # SGI: -u
1632 # Compaq: -u, -warn declarations
1633 # NAGWare: -u
1634 # Lahey: -in, --in, -AT
1635 # Cray: -Mdclchk -e I
1636 # PGI: -Mcdlchk
1637 # f2c: -u
1638 AC_DEFUN([_AC_FC_IMPLICIT_NONE],
1639 [_AC_FORTRAN_ASSERT()dnl
1640 AC_CACHE_CHECK([for flag to disallow _AC_LANG implicit declarations],
1641                [ac_cv_[]_AC_LANG_ABBREV[]_implicit_none],
1642 [ac_cv_[]_AC_LANG_ABBREV[]_implicit_none=unknown
1643 ac_fc_implicit_none_[]_AC_LANG_PREFIX[]FLAGS_save=$[]_AC_LANG_PREFIX[]FLAGS
1644 for ac_flag in none -fimplicit-none -u -Wimplicit -implicitnone +implicit_none \
1645                -qundef "-warn declarations" -in --in -AT "-e I" -Mdclchk \
1646                "-u -warn errors"
1648   if test "x$ac_flag" != xnone; then
1649     _AC_LANG_PREFIX[]FLAGS="$ac_fc_implicit_none_[]_AC_LANG_PREFIX[]FLAGS_save $ac_flag"
1650   fi
1651   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
1652     [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
1653       i = 0
1654       print *, i]])],
1655        [],
1656        [ac_cv_[]_AC_LANG_ABBREV[]_implicit_none=$ac_flag; break])])
1657 done
1658 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
1659 _AC_LANG_PREFIX[]FLAGS=$ac_fc_implicit_none_[]_AC_LANG_PREFIX[]FLAGS_save
1661 if test "x$ac_cv_[]_AC_LANG_ABBREV[]_implicit_none" = xunknown; then
1662   m4_default([$3],
1663     [AC_MSG_ERROR([no Fortran flag to disallow implicit declarations found], 77)])
1664 else
1665   if test "x$ac_cv_[]_AC_LANG_ABBREV[]_implicit_none" != xnone; then
1666     _AC_LANG_PREFIX[]FLAGS="$_AC_LANG_PREFIX[]FLAGS $ac_cv_[]_AC_LANG_ABBREV[]_implicit_none"
1667   fi
1668   $2
1670 ])# _AC_FC_IMPLICIT_NONE
1673 # AC_F77_IMPLICIT_NONE([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1674 # ------------------------------------------------------------------------
1675 AC_DEFUN([AC_F77_IMPLICIT_NONE],
1676 [AC_LANG_PUSH([Fortran 77])dnl
1677 _AC_FC_IMPLICIT_NONE($@)
1678 AC_LANG_POP([Fortran 77])dnl
1679 ])# AC_F77_IMPLICIT_NONE
1682 # AC_FC_IMPLICIT_NONE([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1683 # -----------------------------------------------------------------------
1684 AC_DEFUN([AC_FC_IMPLICIT_NONE],
1685 [AC_LANG_PUSH([Fortran])dnl
1686 _AC_FC_IMPLICIT_NONE($@)
1687 AC_LANG_POP([Fortran])dnl
1688 ])# AC_FC_IMPLICIT_NONE
1691 # AC_FC_MODULE_EXTENSION
1692 # ----------------------
1693 # Find the Fortran 90 module file extension.  The module extension is stored
1694 # in the variable FC_MODEXT and empty if it cannot be determined.  The result
1695 # or "unknown" is cached in the cache variable ac_cv_fc_module_ext.
1696 AC_DEFUN([AC_FC_MODULE_EXTENSION],
1697 [AC_CACHE_CHECK([Fortran 90 module extension], [ac_cv_fc_module_ext],
1698 [AC_LANG_PUSH(Fortran)
1699 mkdir conftest.dir
1700 cd conftest.dir
1701 ac_cv_fc_module_ext=unknown
1702 AC_COMPILE_IFELSE([[
1703       module conftest_module
1704       contains
1705       subroutine conftest_routine
1706       write(*,'(a)') 'gotcha!'
1707       end subroutine
1708       end module]],
1709   [ac_cv_fc_module_ext=`ls | sed -n 's,conftest_module\.,,p'`
1710    if test x$ac_cv_fc_module_ext = x; then
1711 dnl Some F90 compilers use upper case characters for the module file name.
1712      ac_cv_fc_module_ext=`ls | sed -n 's,CONFTEST_MODULE\.,,p'`
1713    fi])
1714 cd ..
1715 rm -rf conftest.dir
1716 AC_LANG_POP(Fortran)
1718 FC_MODEXT=$ac_cv_fc_module_ext
1719 if test "$FC_MODEXT" = unknown; then
1720   FC_MODEXT=
1722 AC_SUBST([FC_MODEXT])dnl
1726 # AC_FC_MODULE_FLAG([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1727 # ---------------------------------------------------------------------
1728 # Find a flag to include Fortran 90 modules from another directory.
1729 # If successful, run ACTION-IF-SUCCESS (defaults to nothing), otherwise
1730 # run ACTION-IF-FAILURE (defaults to failing with an error message).
1731 # The module flag is cached in the ac_cv_fc_module_flag variable.
1732 # It may contain significant trailing whitespace.
1734 # Known flags:
1735 # gfortran: -Idir, -I dir (-M dir, -Mdir (deprecated), -Jdir for writing)
1736 # g95: -I dir (-fmod=dir for writing)
1737 # SUN: -Mdir, -M dir (-moddir=dir for writing;
1738 #                     -Idir for includes is also searched)
1739 # HP: -Idir, -I dir (+moddir=dir for writing)
1740 # IBM: -Idir (-qmoddir=dir for writing)
1741 # Intel: -Idir -I dir (-mod dir for writing)
1742 # Absoft: -pdir
1743 # Lahey: -mod dir
1744 # Cray: -module dir, -p dir (-J dir for writing)
1745 #       -e m is needed to enable writing .mod files at all
1746 # Compaq: -Idir
1747 # NAGWare: -I dir
1748 # PathScale: -I dir  (but -module dir is looked at first)
1749 # Portland: -module dir (first -module also names dir for writing)
1750 # Fujitsu: -Am -Idir (-Mdir for writing is searched first, then '.', then -I)
1751 #                    (-Am indicates how module information is saved)
1752 AC_DEFUN([AC_FC_MODULE_FLAG],[
1753 AC_CACHE_CHECK([Fortran 90 module inclusion flag], [ac_cv_fc_module_flag],
1754 [AC_LANG_PUSH([Fortran])
1755 ac_cv_fc_module_flag=unknown
1756 mkdir conftest.dir
1757 cd conftest.dir
1758 AC_COMPILE_IFELSE([[
1759       module conftest_module
1760       contains
1761       subroutine conftest_routine
1762       write(*,'(a)') 'gotcha!'
1763       end subroutine
1764       end module]],
1765   [cd ..
1766    ac_fc_module_flag_FCFLAGS_save=$FCFLAGS
1767    # Flag ordering is significant for gfortran and Sun.
1768    for ac_flag in -M -I '-I ' '-M ' -p '-mod ' '-module ' '-Am -I'; do
1769      # Add the flag twice to prevent matching an output flag.
1770      FCFLAGS="$ac_fc_module_flag_FCFLAGS_save ${ac_flag}conftest.dir ${ac_flag}conftest.dir"
1771      AC_COMPILE_IFELSE([[
1772       program main
1773       use conftest_module
1774       call conftest_routine
1775       end program]],
1776        [ac_cv_fc_module_flag="$ac_flag"])
1777      if test "$ac_cv_fc_module_flag" != unknown; then
1778        break
1779      fi
1780    done
1781    FCFLAGS=$ac_fc_module_flag_FCFLAGS_save
1783 rm -rf conftest.dir
1784 AC_LANG_POP([Fortran])
1786 if test "$ac_cv_fc_module_flag" != unknown; then
1787   FC_MODINC=$ac_cv_fc_module_flag
1788   $1
1789 else
1790   FC_MODINC=
1791   m4_default([$2],
1792     [AC_MSG_ERROR([unable to find compiler flag for module search path])])
1794 AC_SUBST([FC_MODINC])
1795 # Ensure trailing whitespace is preserved in a Makefile.
1796 AC_SUBST([ac_empty], [""])
1797 AC_CONFIG_COMMANDS_PRE([case $FC_MODINC in #(
1798   *\ ) FC_MODINC=$FC_MODINC'${ac_empty}' ;;
1799 esac])dnl
1803 # AC_FC_MODULE_OUTPUT_FLAG([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1804 # ----------------------------------------------------------------------------
1805 # Find a flag to write Fortran 90 module information to another directory.
1806 # If successful, run ACTION-IF-SUCCESS (defaults to nothing), otherwise
1807 # run ACTION-IF-FAILURE (defaults to failing with an error message).
1808 # The module flag is cached in the ac_cv_fc_module_output_flag variable.
1809 # It may contain significant trailing whitespace.
1811 # For known flags, see the documentation of AC_FC_MODULE_FLAG above.
1812 AC_DEFUN([AC_FC_MODULE_OUTPUT_FLAG],[
1813 AC_CACHE_CHECK([Fortran 90 module output flag], [ac_cv_fc_module_output_flag],
1814 [AC_LANG_PUSH([Fortran])
1815 mkdir conftest.dir conftest.dir/sub
1816 cd conftest.dir
1817 ac_cv_fc_module_output_flag=unknown
1818 ac_fc_module_output_flag_FCFLAGS_save=$FCFLAGS
1819 # Flag ordering is significant: put flags late which some compilers use
1820 # for the search path.
1821 for ac_flag in -J '-J ' -fmod= -moddir= +moddir= -qmoddir= '-mod ' \
1822               '-module ' -M '-Am -M' '-e m -J '; do
1823   FCFLAGS="$ac_fc_module_output_flag_FCFLAGS_save ${ac_flag}sub"
1824   AC_COMPILE_IFELSE([[
1825       module conftest_module
1826       contains
1827       subroutine conftest_routine
1828       write(*,'(a)') 'gotcha!'
1829       end subroutine
1830       end module]],
1831     [cd sub
1832      AC_COMPILE_IFELSE([[
1833       program main
1834       use conftest_module
1835       call conftest_routine
1836       end program]],
1837        [ac_cv_fc_module_output_flag="$ac_flag"])
1838      cd ..
1839      if test "$ac_cv_fc_module_output_flag" != unknown; then
1840        break
1841      fi])
1842 done
1843 FCFLAGS=$ac_fc_module_output_flag_FCFLAGS_save
1844 cd ..
1845 rm -rf conftest.dir
1846 AC_LANG_POP([Fortran])
1848 if test "$ac_cv_fc_module_output_flag" != unknown; then
1849   FC_MODOUT=$ac_cv_fc_module_output_flag
1850   $1
1851 else
1852   FC_MODOUT=
1853   m4_default([$2],
1854     [AC_MSG_ERROR([unable to find compiler flag to write module information to])])
1856 AC_SUBST([FC_MODOUT])
1857 # Ensure trailing whitespace is preserved in a Makefile.
1858 AC_SUBST([ac_empty], [""])
1859 AC_CONFIG_COMMANDS_PRE([case $FC_MODOUT in #(
1860   *\ ) FC_MODOUT=$FC_MODOUT'${ac_empty}' ;;
1861 esac])dnl