Document that Autoconf relies on IFS.
[autoconf.git] / lib / autoconf / fortran.m4
blob4cfebe6e2373dc1eac4ae0e5ab964395f9b17167
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.
31 # Table of Contents:
33 # Preamble
35 # 0. Utility macros
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.
49 ## ---------- ##
50 ## Preamble.  ##
51 ## ---------- ##
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
84 [  ac_exists=false
85   for ac_i in $2; do
86     if test x"$1" = x"$ac_i"; then
87       ac_exists=true
88       break
89     fi
90   done
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"
128   done
129 else
130   $2="[$]$2 $1"
131 fi[]dnl
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], [],
144 [ac_ext=f
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
151 # AC_LANG_FORTRAN77
152 # -----------------
153 AU_DEFUN([AC_LANG_FORTRAN77], [AC_LANG(Fortran 77)])
156 # _AC_FORTRAN_ASSERT
157 # ------------------
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)])])])
165 # _AC_FC
166 # ------
167 # Return F77 or FC, depending upon the language.
168 AC_DEFUN([_AC_FC],
169 [_AC_FORTRAN_ASSERT()dnl
170 AC_LANG_CASE([Fortran 77], [F77],
171              [Fortran],    [FC])])
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)],
184 [m4_ifval([$1],
185        [m4_warn([syntax], [$0: ignoring PROLOGUE: $1])])dnl
186       program main
188       end])
191 # _AC_LANG_IO_PROGRAM(Fortran 77)
192 # -------------------------------
193 # Produce source that performs I/O.
194 m4_define([_AC_LANG_IO_PROGRAM(Fortran 77)],
195 [AC_LANG_PROGRAM([],
196 [dnl
197       open(unit=9,file='conftest.out')
198       close(unit=9)
199 ])])
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],
207 [      call $2])])
210 # AC_LANG_FUNC_LINK_TRY(Fortran 77)(FUNCTION)
211 # -------------------------------------------
212 m4_define([AC_LANG_FUNC_LINK_TRY(Fortran 77)],
213 [AC_LANG_PROGRAM([],
214 [      call $1])])
216 ## ------------------------ ##
217 ## 1b. Language selection.  ##
218 ## ------------------------ ##
221 # AC_LANG(Fortran)
222 # ----------------
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)],
240 [m4_warn([syntax],
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)],
247 [m4_warn([syntax],
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
254 # AC_REQUIRE'able.
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
261 # AC_REQUIRE'able.
262 AC_DEFUN([AC_LANG_COMPILER(Fortran)],
263 [AC_REQUIRE([AC_PROG_FC])])
266 # ac_cv_prog_g77
267 # --------------
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],
284          [2000],[2000],
285          [],[],
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.
300 # Known compilers:
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 file
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[],
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 AC_LANG_POP(Fortran)dnl
386 ])# AC_PROG_FC
389 # _AC_PROG_FC_G
390 # -------------
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"
410   else
411     _AC_LANG_PREFIX[]FLAGS="-g"
412   fi
413 else
414   if test "x$ac_cv_[]_AC_LANG_ABBREV[]_compiler_gnu" = xyes; then
415     _AC_LANG_PREFIX[]FLAGS="-O2"
416   else
417     _AC_LANG_PREFIX[]FLAGS=
418   fi
419 fi[]dnl
420 ])# _AC_PROG_FC_G
423 # _AC_PROG_FC_C_O
424 # ---------------
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'
441 rm -f conftest2.*
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
446 else
447   ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o=no
449 rm -f conftest*])
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.])
455 ])# _AC_PROG_FC_C_O
458 # AC_PROG_F77_C_O
459 # ---------------
460 AC_DEFUN([AC_PROG_F77_C_O],
461 [AC_REQUIRE([AC_PROG_F77])dnl
462 AC_LANG_PUSH(Fortran 77)dnl
463 _AC_PROG_FC_C_O
464 AC_LANG_POP(Fortran 77)dnl
465 ])# AC_PROG_F77_C_O
468 # AC_PROG_FC_C_O
469 # ---------------
470 AC_DEFUN([AC_PROG_FC_C_O],
471 [AC_REQUIRE([AC_PROG_FC])dnl
472 AC_LANG_PUSH(Fortran)dnl
473 _AC_PROG_FC_C_O
474 AC_LANG_POP(Fortran)dnl
475 ])# AC_PROG_FC_C_O
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
499 # flags.
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"
503 shift
504 _AS_ECHO_LOG([$[*]])
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
512 rm -rf conftest*
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 |
518         grep 'LPATH is:' |
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.
526   *xlfentry*)
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.
544   *cft90*)
545     ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed 's/"//g'` ;;
546 esac
548 ])# _AC_PROG_FC_V_OUTPUT
551 # _AC_PROG_FC_V
552 # --------------
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
569      case $ac_arg in
570         [[\\/]]*.a | ?:[[\\/]]*.a | -[[lLRu]]*)
571           ac_cv_prog_[]_AC_LANG_ABBREV[]_v=$ac_verb
572           break 2 ;;
573      esac
574   done
575 done
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[]])
578 fi],
579                   [AC_MSG_WARN([compilation failed])])
580 ])])# _AC_PROG_FC_V
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
605 # libraries.
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
613 _AC_PROG_FC_V
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.
617 else
619 _AC_PROG_FC_V_OUTPUT
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
628   shift
629   ac_arg=$[1]
630   case $ac_arg in
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")
634           ;;
635         -bI:*)
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)])
638           ;;
639           # Ignore these flags.
640         -lang* | -lcrt*.o | -lc | -lgcc* | -lSystem | -libmil | -little \
641           |-LANG:=* | -LIST:* | -LNO:*)
642           ;;
643         -lkernel32)
644           test x"$CYGWIN" != xyes && ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg"
645           ;;
646         -[[LRuYz]])
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 -)
650           case $[2] in
651              "" | -*);;
652              *)
653                 ac_arg="$ac_arg$[2]"
654                 shift; shift
655                 set X $ac_arg "$[@]"
656                 ;;
657           esac
658           ;;
659         -YP,*)
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"])
664           done
665           ;;
666         -[[lLR]]*)
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")
669           ;;
670         -zallextract*| -zdefaultextract)
671           ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg"
672           ;;
673           # Ignore everything else.
674   esac
675 done
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
683    "SunOS 5"*)
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)
688       ;;
689 esac
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
730 # when needed).
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])
756 [#  ifdef __cplusplus
757      extern "C"
758 #  endif
759    int ]_AC_FC[_DUMMY_MAIN() { return 1; }
760 ]AC_LANG_CASE([Fortran], [#endif])
761 [#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
768  AC_LANG_PUSH(C)dnl
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])
779    done
780  fi
781  AC_LANG_POP(C)dnl
782  ac_cv_[]_AC_LANG_ABBREV[]_dummy_main=$ac_cv_fortran_dummy_main
783  rm -rf conftest*
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],
788       [m4_default([$1],
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.])
796   fi
797 fi])],
798       [m4_default([$2],
799             [AC_MSG_FAILURE([linking to Fortran libraries from C fails])])])
800 ])# _AC_FC_DUMMY_MAIN
803 # AC_F77_DUMMY_MAIN
804 # ----------------------
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
813 # AC_FC_DUMMY_MAIN
814 # ----------------------
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
820 ])# AC_FC_DUMMY_MAIN
823 # _AC_FC_MAIN
824 # -----------
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
838  AC_LANG_PUSH(C)dnl
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
844 @%:@else
845 @%:@  undef $ac_fortran_dm_var
846 @%:@endif
847 @%:@define main $ac_func])],
848                   [ac_cv_fortran_main=$ac_func; break])
849  done
850  AC_LANG_POP(C)dnl
851  ac_cv_[]_AC_LANG_ABBREV[]_main=$ac_cv_fortran_main
852  rm -rf conftest*
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.])
858 ])# _AC_FC_MAIN
861 # AC_F77_MAIN
862 # -----------
863 AC_DEFUN([AC_F77_MAIN],
864 [AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
865 AC_LANG_PUSH(Fortran 77)dnl
866 _AC_FC_MAIN
867 AC_LANG_POP(Fortran 77)dnl
868 ])# AC_F77_MAIN
871 # AC_FC_MAIN
872 # ----------
873 AC_DEFUN([AC_FC_MAIN],
874 [AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
875 AC_LANG_PUSH(Fortran)dnl
876 _AC_FC_MAIN
877 AC_LANG_POP(Fortran)dnl
878 ])# AC_FC_MAIN
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
886 # by commas:
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,
900 [AC_COMPILE_IFELSE(
901 [      subroutine foobar()
902       return
903       end
904       subroutine foo_bar()
905       return
906       end],
907 [mv conftest.$ac_objext cfortran_test.$ac_objext
909   ac_save_LIBS=$LIBS
910   LIBS="cfortran_test.$ac_objext $LIBS $[]_AC_LANG_PREFIX[]LIBS"
912   AC_LANG_PUSH(C)dnl
913   ac_success=no
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])
919     done
920   done
921   AC_LANG_POP(C)dnl
923   if test "$ac_success" = "yes"; then
924      case $ac_foobar in
925         foobar)
926            ac_case=lower
927            ac_foo_bar=foo_bar
928            ;;
929         FOOBAR)
930            ac_case=upper
931            ac_foo_bar=FOO_BAR
932            ;;
933      esac
935      AC_LANG_PUSH(C)dnl
936      ac_success_extra=no
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])
941      done
942      AC_LANG_POP(C)dnl
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"
948         else
949            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, underscore"
950         fi
951         if test -z "$ac_extra"; then
952            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, no extra underscore"
953         else
954            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, extra underscore"
955         fi
956       else
957         ac_cv_[]_AC_LANG_ABBREV[]_mangling="unknown"
958       fi
959   else
960      ac_cv_[]_AC_LANG_ABBREV[]_mangling="unknown"
961   fi
963   LIBS=$ac_save_LIBS
964   rm -rf conftest*
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
996 # _AC_FC_WRAPPERS
997 # ---------------
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 [##] __]) ;;
1034   *)
1035           AC_MSG_WARN([unknown Fortran name-mangling scheme])
1036           ;;
1037 esac
1038 ])# _AC_FC_WRAPPERS
1041 # AC_F77_WRAPPERS
1042 # ---------------
1043 AC_DEFUN([AC_F77_WRAPPERS],
1044 [AC_REQUIRE([_AC_F77_NAME_MANGLING])dnl
1045 AC_LANG_PUSH(Fortran 77)dnl
1046 _AC_FC_WRAPPERS
1047 AC_LANG_POP(Fortran 77)dnl
1048 ])# AC_F77_WRAPPERS
1051 # AC_FC_WRAPPERS
1052 # --------------
1053 AC_DEFUN([AC_FC_WRAPPERS],
1054 [AC_REQUIRE([_AC_FC_NAME_MANGLING])dnl
1055 AC_LANG_PUSH(Fortran)dnl
1056 _AC_FC_WRAPPERS
1057 AC_LANG_POP(Fortran)dnl
1058 ])# AC_FC_WRAPPERS
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" ;;
1072 esac
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"
1078 ])# _AC_FC_FUNC
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
1088 ])# AC_F77_FUNC
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
1098 ])# AC_FC_FUNC
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
1109 # message.
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],
1127                 ac_cv_fc_srcext_$1,
1128 [ac_ext=$1
1129 ac_fcflags_srcext_save=$ac_fcflags_srcext
1130 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])
1135 done
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])])
1141 else
1142   ac_fc_srcext=$1
1143   if test "x$ac_cv_fc_srcext_$1" = xnone; then
1144     ac_fcflags_srcext=""
1145     FCFLAGS_[]$1[]=""
1146   else
1147     ac_fcflags_srcext=$ac_cv_fc_srcext_$1
1148     FCFLAGS_[]$1[]=$ac_cv_fc_srcext_$1
1149   fi
1150   AC_SUBST(FCFLAGS_[]$1)
1151   $2
1153 AC_LANG_POP(Fortran)dnl
1154 ])# AC_FC_SRCEXT
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
1168 #                -FR: Intel compiler (icc, ecc)
1169 #              -free: Compaq compiler (fort)
1170 #             -qfree: IBM compiler (xlf)
1171 # -Mfree, -Mfreeform: Portland Group compiler
1172 #          -freeform: SGI compiler
1173 #            -f free: Absoft Fortran
1174 # We try to test the "more popular" flags first, by some prejudiced
1175 # notion of popularity.
1176 AC_DEFUN_ONCE([AC_FC_FREEFORM],
1177 [AC_LANG_PUSH(Fortran)dnl
1178 AC_CACHE_CHECK([for Fortran flag needed to allow free-form source],
1179                 ac_cv_fc_freeform,
1180 [ac_cv_fc_freeform=unknown
1181 ac_fc_freeform_FCFLAGS_save=$FCFLAGS
1182 for ac_flag in none -ffree-form -FR -free -qfree -Mfree -Mfreeform \
1183                -freeform "-f free"
1185   test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_freeform_FCFLAGS_save $ac_flag"
1186 dnl Use @&t@ below to ensure that editors don't turn 8+ spaces into tab.
1187   AC_COMPILE_IFELSE([
1188   program freeform
1189        ! FIXME: how to best confuse non-freeform compilers?
1190        print *, 'Hello ', &
1191      @&t@     'world.'
1192        end],
1193                     [ac_cv_fc_freeform=$ac_flag; break])
1194 done
1195 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
1196 FCFLAGS=$ac_fc_freeform_FCFLAGS_save
1198 if test "x$ac_cv_fc_freeform" = xunknown; then
1199   m4_default([$2],
1200              [AC_MSG_ERROR([Fortran does not accept free-form source], 77)])
1201 else
1202   if test "x$ac_cv_fc_freeform" != xnone; then
1203     FCFLAGS="$FCFLAGS $ac_cv_fc_freeform"
1204   fi
1205   $1
1207 AC_LANG_POP(Fortran)dnl
1208 ])# AC_FC_FREEFORM