This change prompted by a problem report by Andrey Simonenko in
[autoconf.git] / lib / autoconf / fortran.m4
bloba5005e005cbe115a79a7b5675defd9e4a661c46a
1 # This file is part of Autoconf.                       -*- Autoconf -*-
2 # Fortran languages support.
3 # Copyright (C) 2001, 2003, 2004, 2005, 2006
4 # Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
9 # 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 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
21 # As a special exception, the Free Software Foundation gives unlimited
22 # permission to copy, distribute and modify the configure scripts that
23 # are the output of Autoconf.  You need not follow the terms of the GNU
24 # General Public License when using or distributing such scripts, even
25 # though portions of the text of Autoconf appear in them.  The GNU
26 # General Public License (GPL) does govern all other use of the material
27 # that constitutes the Autoconf program.
29 # Certain portions of the Autoconf source text are designed to be copied
30 # (in certain cases, depending on the input) into the output of
31 # Autoconf.  We call these the "data" portions.  The rest of the Autoconf
32 # source text consists of comments plus executable code that decides which
33 # of the data portions to output in any given case.  We call these
34 # comments and executable code the "non-data" portions.  Autoconf never
35 # copies any of the non-data portions into its output.
37 # This special exception to the GPL applies to versions of Autoconf
38 # released by the Free Software Foundation.  When you make and
39 # distribute a modified version of Autoconf, you may extend this special
40 # exception to the GPL to apply to your modified version as well, *unless*
41 # your modified version has the potential to copy into its output some
42 # of the text that was the non-data portion of the version that you started
43 # with.  (In other words, unless your change moves or copies text from
44 # the non-data portions to the data portions.)  If your modification has
45 # such potential, you must delete any notice of this special exception
46 # to the GPL from your modified version.
48 # Written by David MacKenzie, with help from
49 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
50 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
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.
64 # _AC_LIST_MEMBER_IF(ELEMENT, LIST, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
65 # ---------------------------------------------------------------------------
67 # Processing the elements of a list is tedious in shell programming,
68 # as lists tend to be implemented as space delimited strings.
70 # This macro searches LIST for ELEMENT, and executes ACTION-IF-FOUND
71 # if ELEMENT is a member of LIST, otherwise it executes
72 # ACTION-IF-NOT-FOUND.
73 AC_DEFUN([_AC_LIST_MEMBER_IF],
74 [dnl Do some sanity checking of the arguments.
75 m4_if([$1], , [AC_FATAL([$0: missing argument 1])])dnl
76 m4_if([$2], , [AC_FATAL([$0: missing argument 2])])dnl
77   ac_exists=false
78   for ac_i in $2; do
79     if test x"$1" = x"$ac_i"; then
80       ac_exists=true
81       break
82     fi
83   done
85   AS_IF([test x"$ac_exists" = xtrue], [$3], [$4])[]dnl
86 ])# _AC_LIST_MEMBER_IF
89 # _AC_LINKER_OPTION(LINKER-OPTIONS, SHELL-VARIABLE)
90 # -------------------------------------------------
92 # Specifying options to the compiler (whether it be the C, C++ or
93 # Fortran 77 compiler) that are meant for the linker is compiler
94 # dependent.  This macro lets you give options to the compiler that
95 # are meant for the linker in a portable, compiler-independent way.
97 # This macro take two arguments, a list of linker options that the
98 # compiler should pass to the linker (LINKER-OPTIONS) and the name of
99 # a shell variable (SHELL-VARIABLE).  The list of linker options are
100 # appended to the shell variable in a compiler-dependent way.
102 # For example, if the selected language is C, then this:
104 #   _AC_LINKER_OPTION([-R /usr/local/lib/foo], foo_LDFLAGS)
106 # will expand into this if the selected C compiler is gcc:
108 #   foo_LDFLAGS="-Xlinker -R -Xlinker /usr/local/lib/foo"
110 # otherwise, it will expand into this:
112 #   foo_LDFLAGS"-R /usr/local/lib/foo"
114 # You are encouraged to add support for compilers that this macro
115 # doesn't currently support.
116 # FIXME: Get rid of this macro.
117 AC_DEFUN([_AC_LINKER_OPTION],
118 [if test "$ac_compiler_gnu" = yes; then
119   for ac_link_opt in $1; do
120     $2="[$]$2 -Xlinker $ac_link_opt"
121   done
122 else
123   $2="[$]$2 $1"
124 fi[]dnl
125 ])# _AC_LINKER_OPTION
129 ## ----------------------- ##
130 ## 1. Language selection.  ##
131 ## ----------------------- ##
134 # -------------------------- #
135 # 1d. The Fortran language.  #
136 # -------------------------- #
139 # AC_LANG(Fortran 77)
140 # -------------------
141 m4_define([AC_LANG(Fortran 77)],
142 [ac_ext=f
143 ac_compile='$F77 -c $FFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
144 ac_link='$F77 -o conftest$ac_exeext $FFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
145 ac_compiler_gnu=$ac_cv_f77_compiler_gnu
149 # AC_LANG(Fortran)
150 # ----------------
151 m4_define([AC_LANG(Fortran)],
152 [ac_ext=${ac_fc_srcext-f}
153 ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
154 ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
155 ac_compiler_gnu=$ac_cv_fc_compiler_gnu
158 # AC_LANG_FORTRAN77
159 # -----------------
160 AU_DEFUN([AC_LANG_FORTRAN77], [AC_LANG(Fortran 77)])
163 # _AC_FORTRAN_ASSERT
164 # ------------------
165 # Current language must be Fortran or Fortran 77.
166 m4_defun([_AC_FORTRAN_ASSERT],
167 [m4_if(_AC_LANG, [Fortran], [],
168        [m4_if(_AC_LANG, [Fortran 77], [],
169               [m4_fatal([$0: current language is not Fortran: ] _AC_LANG)])])])
172 # _AC_LANG_ABBREV(Fortran 77)
173 # ---------------------------
174 m4_define([_AC_LANG_ABBREV(Fortran 77)], [f77])
176 # _AC_LANG_ABBREV(Fortran)
177 # ------------------------
178 m4_define([_AC_LANG_ABBREV(Fortran)], [fc])
181 # _AC_LANG_PREFIX(Fortran 77)
182 # ---------------------------
183 m4_define([_AC_LANG_PREFIX(Fortran 77)], [F])
185 # _AC_LANG_PREFIX(Fortran)
186 # ------------------------
187 m4_define([_AC_LANG_PREFIX(Fortran)], [FC])
190 # _AC_FC
191 # ------
192 # Return F77 or FC, depending upon the language.
193 AC_DEFUN([_AC_FC],
194 [_AC_FORTRAN_ASSERT()dnl
195 AC_LANG_CASE([Fortran 77], [F77],
196              [Fortran],    [FC])])
199 ## ---------------------- ##
200 ## 2.Producing programs.  ##
201 ## ---------------------- ##
204 # --------------------- #
205 # 2d. Fortran sources.  #
206 # --------------------- #
208 # AC_LANG_SOURCE(Fortran 77)(BODY)
209 # AC_LANG_SOURCE(Fortran)(BODY)
210 # --------------------------------
211 # FIXME: Apparently, according to former AC_TRY_COMPILER, the CPP
212 # directives must not be included.  But AC_TRY_RUN_NATIVE was not
213 # avoiding them, so?
214 m4_define([AC_LANG_SOURCE(Fortran 77)],
215 [$1])
216 m4_define([AC_LANG_SOURCE(Fortran)],
217 [$1])
220 # AC_LANG_PROGRAM(Fortran 77)([PROLOGUE], [BODY])
221 # -----------------------------------------------
222 # Yes, we discard the PROLOGUE.
223 m4_define([AC_LANG_PROGRAM(Fortran 77)],
224 [m4_ifval([$1],
225        [m4_warn([syntax], [$0: ignoring PROLOGUE: $1])])dnl
226       program main
228       end])
231 # AC_LANG_PROGRAM(Fortran)([PROLOGUE], [BODY])
232 # -----------------------------------------------
233 # FIXME: can the PROLOGUE be used?
234 m4_define([AC_LANG_PROGRAM(Fortran)],
235 [m4_ifval([$1],
236        [m4_warn([syntax], [$0: ignoring PROLOGUE: $1])])dnl
237       program main
239       end])
242 # AC_LANG_CALL(Fortran 77)(PROLOGUE, FUNCTION)
243 # --------------------------------------------
244 # FIXME: This is a guess, help!
245 m4_define([AC_LANG_CALL(Fortran 77)],
246 [AC_LANG_PROGRAM([$1],
247 [      call $2])])
250 # AC_LANG_CALL(Fortran)(PROLOGUE, FUNCTION)
251 # --------------------------------------------
252 # FIXME: This is a guess, help!
253 m4_define([AC_LANG_CALL(Fortran)],
254 [AC_LANG_PROGRAM([$1],
255 [      call $2])])
259 ## -------------------------------------------- ##
260 ## 3. Looking for Compilers and Preprocessors.  ##
261 ## -------------------------------------------- ##
264 # -------------------------- #
265 # 3d. The Fortran compiler.  #
266 # -------------------------- #
269 # AC_LANG_PREPROC(Fortran 77)
270 # ---------------------------
271 # Find the Fortran 77 preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
272 AC_DEFUN([AC_LANG_PREPROC(Fortran 77)],
273 [m4_warn([syntax],
274          [$0: No preprocessor defined for ]_AC_LANG)])
276 # AC_LANG_PREPROC(Fortran)
277 # ---------------------------
278 # Find the Fortran preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
279 AC_DEFUN([AC_LANG_PREPROC(Fortran)],
280 [m4_warn([syntax],
281          [$0: No preprocessor defined for ]_AC_LANG)])
284 # AC_LANG_COMPILER(Fortran 77)
285 # ----------------------------
286 # Find the Fortran 77 compiler.  Must be AC_DEFUN'd to be
287 # AC_REQUIRE'able.
288 AC_DEFUN([AC_LANG_COMPILER(Fortran 77)],
289 [AC_REQUIRE([AC_PROG_F77])])
291 # AC_LANG_COMPILER(Fortran)
292 # ----------------------------
293 # Find the Fortran compiler.  Must be AC_DEFUN'd to be
294 # AC_REQUIRE'able.
295 AC_DEFUN([AC_LANG_COMPILER(Fortran)],
296 [AC_REQUIRE([AC_PROG_FC])])
299 # ac_cv_prog_g77
300 # --------------
301 # We used to name the cache variable this way.
302 AU_DEFUN([ac_cv_prog_g77],
303 [ac_cv_f77_compiler_gnu])
306 # _AC_FC_DIALECT_YEAR([DIALECT])
307 # ------------------------------
308 # Given a Fortran DIALECT, which is Fortran [YY]YY or simply [YY]YY,
309 # convert to a 4-digit year.  The dialect must be one of Fortran 77,
310 # 90, 95, or 2000, currently.  If DIALECT is simply Fortran or the
311 # empty string, returns the empty string.
312 AC_DEFUN([_AC_FC_DIALECT_YEAR],
313 [m4_case(m4_bpatsubsts(m4_tolower([$1]), [fortran],[], [ *],[]),
314          [77],[1977], [1977],[1977],
315          [90],[1990], [1990],[1990],
316          [95],[1995], [1995],[1995],
317          [2000],[2000],
318          [],[],
319          [m4_fatal([unknown Fortran dialect])])])
322 # _AC_PROG_FC([DIALECT], [COMPILERS...])
323 # --------------------------------------
324 # DIALECT is a Fortran dialect, given by Fortran [YY]YY or simply [YY]YY,
325 # and must be one of those supported by _AC_FC_DIALECT_YEAR
327 # If DIALECT is supplied, then we search for compilers of that dialect
328 # first, and then later dialects.  Otherwise, we search for compilers
329 # of the newest dialect first, and then earlier dialects in increasing age.
330 # This search order is necessarily imperfect because the dialect cannot
331 # always be inferred from the compiler name.
333 # Known compilers:
334 #  f77/f90/f95: generic compiler names
335 #  g77: GNU Fortran 77 compiler
336 #  gfortran: GNU Fortran 95+ compiler (released in gcc 4.0)
337 #  g95: original gcc-based f95 compiler (gfortran is a fork)
338 #  ftn: native Fortran 95 compiler on Cray X1
339 #  cf77: native F77 compiler under older Crays (prefer over fort77)
340 #  fort77: native F77 compiler under HP-UX (and some older Crays)
341 #  frt: Fujitsu F77 compiler
342 #  pgf77/pgf90/pghpf/pgf95: Portland Group F77/F90/F95 compilers
343 #  xlf/xlf90/xlf95: IBM (AIX) F77/F90/F95 compilers
344 #    Prefer xlf9x to the generic names because they do not reject file
345 #    with extension `.f'.
346 #  lf95: Lahey-Fujitsu F95 compiler
347 #  fl32: Microsoft Fortran 77 "PowerStation" compiler
348 #  af77: Apogee F77 compiler for Intergraph hardware running CLIX
349 #  epcf90: "Edinburgh Portable Compiler" F90
350 #  fort: Compaq (now HP) Fortran 90/95 compiler for Tru64 and Linux/Alpha
351 #  ifort, previously ifc: Intel Fortran 95 compiler for Linux/x86
352 #  efc: Intel Fortran 95 compiler for IA64
353 m4_define([_AC_F95_FC], [gfortran g95 xlf95 f95 fort ifort ifc efc pgf95 lf95 ftn])
354 m4_define([_AC_F90_FC], [xlf90 f90 pgf90 pghpf epcf90])
355 m4_define([_AC_F77_FC], [g77 xlf f77 frt pgf77 cf77 fort77 fl32 af77])
356 AC_DEFUN([_AC_PROG_FC],
357 [_AC_FORTRAN_ASSERT()dnl
358 AC_CHECK_TOOLS([]_AC_FC[],
359       m4_default([$2],
360         m4_case(_AC_FC_DIALECT_YEAR([$1]),
361                 [1995], [_AC_F95_FC],
362                 [1990], [_AC_F90_FC _AC_F95_FC],
363                 [1977], [_AC_F77_FC _AC_F90_FC _AC_F95_FC],
364                 [_AC_F95_FC _AC_F90_FC _AC_F77_FC])))
366 # Provide some information about the compiler.
367 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
368 set X $ac_compile
369 ac_compiler=$[2]
370 _AC_DO([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
371 _AC_DO([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
372 _AC_DO([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
373 rm -f a.out
375 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
376 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
377 # If we don't use `.F' as extension, the preprocessor is not run on the
378 # input file.  (Note that this only needs to work for GNU compilers.)
379 ac_save_ext=$ac_ext
380 ac_ext=F
381 _AC_LANG_COMPILER_GNU
382 ac_ext=$ac_save_ext
383 _AC_PROG_FC_G
384 ])# _AC_PROG_FC
387 # AC_PROG_F77([COMPILERS...])
388 # ---------------------------
389 # COMPILERS is a space separated list of Fortran 77 compilers to search
390 # for.  See also _AC_PROG_FC.
391 AC_DEFUN([AC_PROG_F77],
392 [AC_LANG_PUSH(Fortran 77)dnl
393 AC_ARG_VAR([F77],    [Fortran 77 compiler command])dnl
394 AC_ARG_VAR([FFLAGS], [Fortran 77 compiler flags])dnl
395 _AC_ARG_VAR_LDFLAGS()dnl
396 _AC_ARG_VAR_LIBS()dnl
397 _AC_PROG_FC([Fortran 77], [$1])
398 if test $ac_compiler_gnu = yes; then
399   G77=yes
400 else
401   G77=
403 AC_LANG_POP(Fortran 77)dnl
404 ])# AC_PROG_F77
407 # AC_PROG_FC([COMPILERS...], [DIALECT])
408 # -------------------------------------
409 # COMPILERS is a space separated list of Fortran 77 compilers to search
410 # for, and [DIALECT] is an optional dialect.  See also _AC_PROG_FC.
411 AC_DEFUN([AC_PROG_FC],
412 [AC_LANG_PUSH(Fortran)dnl
413 AC_ARG_VAR([FC],    [Fortran compiler command])dnl
414 AC_ARG_VAR([FCFLAGS], [Fortran compiler flags])dnl
415 _AC_ARG_VAR_LDFLAGS()dnl
416 _AC_ARG_VAR_LIBS()dnl
417 _AC_PROG_FC([$2], [$1])
418 AC_LANG_POP(Fortran)dnl
419 ])# AC_PROG_FC
422 # _AC_PROG_FC_G
423 # -------------
424 # Check whether -g works, even if F[C]FLAGS is set, in case the package
425 # plays around with F[C]FLAGS (such as to build both debugging and normal
426 # versions of a library), tasteless as that idea is.
427 m4_define([_AC_PROG_FC_G],
428 [_AC_FORTRAN_ASSERT()dnl
429 ac_test_FFLAGS=${[]_AC_LANG_PREFIX[]FLAGS+set}
430 ac_save_FFLAGS=$[]_AC_LANG_PREFIX[]FLAGS
431 _AC_LANG_PREFIX[]FLAGS=
432 AC_CACHE_CHECK(whether $[]_AC_FC[] accepts -g, ac_cv_prog_[]_AC_LANG_ABBREV[]_g,
433 [_AC_LANG_PREFIX[]FLAGS=-g
434 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
435 [ac_cv_prog_[]_AC_LANG_ABBREV[]_g=yes],
436 [ac_cv_prog_[]_AC_LANG_ABBREV[]_g=no])
438 if test "$ac_test_FFLAGS" = set; then
439   _AC_LANG_PREFIX[]FLAGS=$ac_save_FFLAGS
440 elif test $ac_cv_prog_[]_AC_LANG_ABBREV[]_g = yes; then
441   if test "x$ac_cv_[]_AC_LANG_ABBREV[]_compiler_gnu" = xyes; then
442     _AC_LANG_PREFIX[]FLAGS="-g -O2"
443   else
444     _AC_LANG_PREFIX[]FLAGS="-g"
445   fi
446 else
447   if test "x$ac_cv_[]_AC_LANG_ABBREV[]_compiler_gnu" = xyes; then
448     _AC_LANG_PREFIX[]FLAGS="-O2"
449   else
450     _AC_LANG_PREFIX[]FLAGS=
451   fi
452 fi[]dnl
453 ])# _AC_PROG_FC_G
456 # _AC_PROG_FC_C_O
457 # ---------------
458 # Test if the Fortran compiler accepts the options `-c' and `-o'
459 # simultaneously, and define `[F77/FC]_NO_MINUS_C_MINUS_O' if it does not.
461 # The usefulness of this macro is questionable, as I can't really see
462 # why anyone would use it.  The only reason I include it is for
463 # completeness, since a similar test exists for the C compiler.
465 # FIXME: it seems like we could merge the C/C++/Fortran versions of this.
466 AC_DEFUN([_AC_PROG_FC_C_O],
467 [_AC_FORTRAN_ASSERT()dnl
468 AC_CACHE_CHECK([whether $[]_AC_FC[] understands -c and -o together],
469                [ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o],
470 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
471 # We test twice because some compilers refuse to overwrite an existing
472 # `.o' file with `-o', although they will create one.
473 ac_try='$[]_AC_FC[] $[]_AC_LANG_PREFIX[]FLAGS -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
474 rm -f conftest2.*
475 if _AC_DO_VAR(ac_try) &&
476      test -f conftest2.$ac_objext &&
477      _AC_DO_VAR(ac_try); then
478   ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o=yes
479 else
480   ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o=no
482 rm -f conftest*])
483 if test $ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o = no; then
484   AC_DEFINE([]_AC_FC[]_NO_MINUS_C_MINUS_O, 1,
485             [Define to 1 if your Fortran compiler doesn't accept
486              -c and -o together.])
488 ])# _AC_PROG_FC_C_O
491 # AC_PROG_F77_C_O
492 # ---------------
493 AC_DEFUN([AC_PROG_F77_C_O],
494 [AC_REQUIRE([AC_PROG_F77])dnl
495 AC_LANG_PUSH(Fortran 77)dnl
496 _AC_PROG_FC_C_O
497 AC_LANG_POP(Fortran 77)dnl
498 ])# AC_PROG_F77_C_O
501 # AC_PROG_FC_C_O
502 # ---------------
503 AC_DEFUN([AC_PROG_FC_C_O],
504 [AC_REQUIRE([AC_PROG_FC])dnl
505 AC_LANG_PUSH(Fortran)dnl
506 _AC_PROG_FC_C_O
507 AC_LANG_POP(Fortran)dnl
508 ])# AC_PROG_FC_C_O
511 ## ------------------------------- ##
512 ## 4. Compilers' characteristics.  ##
513 ## ------------------------------- ##
516 # ---------------------------------------- #
517 # 4d. Fortran 77 compiler characteristics. #
518 # ---------------------------------------- #
521 # _AC_PROG_FC_V_OUTPUT([FLAG = $ac_cv_prog_{f77/fc}_v])
522 # -------------------------------------------------
523 # Link a trivial Fortran program, compiling with a verbose output FLAG
524 # (whose default value, $ac_cv_prog_{f77/fc}_v, is computed by
525 # _AC_PROG_FC_V), and return the output in $ac_{f77/fc}_v_output.  This
526 # output is processed in the way expected by _AC_FC_LIBRARY_LDFLAGS,
527 # so that any link flags that are echoed by the compiler appear as
528 # space-separated items.
529 AC_DEFUN([_AC_PROG_FC_V_OUTPUT],
530 [_AC_FORTRAN_ASSERT()dnl
531 AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
533 # Compile and link our simple test program by passing a flag (argument
534 # 1 to this macro) to the Fortran compiler in order to get
535 # "verbose" output that we can then parse for the Fortran linker
536 # flags.
537 ac_save_FFLAGS=$[]_AC_LANG_PREFIX[]FLAGS
538 _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS m4_default([$1], [$ac_cv_prog_[]_AC_LANG_ABBREV[]_v])"
539 eval "set x $ac_link"
540 shift
541 _AS_ECHO_LOG([$[*]])
542 ac_[]_AC_LANG_ABBREV[]_v_output=`eval $ac_link AS_MESSAGE_LOG_FD>&1 2>&1 | grep -v 'Driving:'`
543 AS_ECHO(["$ac_[]_AC_LANG_ABBREV[]_v_output"]) >&AS_MESSAGE_LOG_FD
544 _AC_LANG_PREFIX[]FLAGS=$ac_save_FFLAGS
546 rm -f conftest*
548 # On HP/UX there is a line like: "LPATH is: /foo:/bar:/baz" where
549 # /foo, /bar, and /baz are search directories for the Fortran linker.
550 # Here, we change these into -L/foo -L/bar -L/baz (and put it first):
551 ac_[]_AC_LANG_ABBREV[]_v_output="`echo $ac_[]_AC_LANG_ABBREV[]_v_output |
552         grep 'LPATH is:' |
553         sed 's,.*LPATH is\(: *[[^ ]]*\).*,\1,;s,: */, -L/,g'` $ac_[]_AC_LANG_ABBREV[]_v_output"
555 # FIXME: we keep getting bitten by quoted arguments; a more general fix
556 #        that detects unbalanced quotes in FLIBS should be implemented
557 #        and (ugh) tested at some point.
558 case $ac_[]_AC_LANG_ABBREV[]_v_output in
559   # If we are using xlf then replace all the commas with spaces.
560   *xlfentry*)
561     ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed 's/,/ /g'` ;;
563   # With Intel ifc, ignore the quoted -mGLOB_options_string stuff (quoted
564   # $LIBS confuse us, and the libraries appear later in the output anyway).
565   *mGLOB_options_string*)
566     ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed 's/"-mGLOB[[^"]]*"/ /g'` ;;
568   # Portland Group compiler has singly- or doubly-quoted -cmdline argument
569   # Singly-quoted arguments were reported for versions 5.2-4 and 6.0-4.
570   # Doubly-quoted arguments were reported for "PGF90/x86 Linux/x86 5.0-2".
571   *-cmdline\ * | *-ignore\ * | *-def\ *)
572     ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed "\
573         s/-cmdline  *'[[^']]*'/ /g; s/-cmdline  *\"[[^\"]]*\"/ /g
574         s/-ignore  *'[[^']]*'/ /g; s/-ignore  *\"[[^\"]]*\"/ /g
575         s/-def  *'[[^']]*'/ /g; s/-def  *\"[[^\"]]*\"/ /g"` ;;
577   # If we are using Cray Fortran then delete quotes.
578   *cft90*)
579     ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed 's/"//g'` ;;
580 esac
582 ])# _AC_PROG_FC_V_OUTPUT
585 # _AC_PROG_FC_V
586 # --------------
588 # Determine the flag that causes the Fortran compiler to print
589 # information of library and object files (normally -v)
590 # Needed for _AC_FC_LIBRARY_FLAGS
591 # Some compilers don't accept -v (Lahey: -verbose, xlf: -V, Fujitsu: -###)
592 AC_DEFUN([_AC_PROG_FC_V],
593 [_AC_FORTRAN_ASSERT()dnl
594 AC_CACHE_CHECK([how to get verbose linking output from $[]_AC_FC[]],
595                 [ac_cv_prog_[]_AC_LANG_ABBREV[]_v],
596 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
597 [ac_cv_prog_[]_AC_LANG_ABBREV[]_v=
598 # Try some options frequently used verbose output
599 for ac_verb in -v -verbose --verbose -V -\#\#\#; do
600   _AC_PROG_FC_V_OUTPUT($ac_verb)
601   # look for -l* and *.a constructs in the output
602   for ac_arg in $ac_[]_AC_LANG_ABBREV[]_v_output; do
603      case $ac_arg in
604         [[\\/]]*.a | ?:[[\\/]]*.a | -[[lLRu]]*)
605           ac_cv_prog_[]_AC_LANG_ABBREV[]_v=$ac_verb
606           break 2 ;;
607      esac
608   done
609 done
610 if test -z "$ac_cv_prog_[]_AC_LANG_ABBREV[]_v"; then
611    AC_MSG_WARN([cannot determine how to obtain linking information from $[]_AC_FC[]])
612 fi],
613                   [AC_MSG_WARN([compilation failed])])
614 ])])# _AC_PROG_FC_V
617 # _AC_FC_LIBRARY_LDFLAGS
618 # ----------------------
620 # Determine the linker flags (e.g. "-L" and "-l") for the Fortran
621 # intrinsic and runtime libraries that are required to successfully
622 # link a Fortran program or shared library.  The output variable
623 # FLIBS/FCLIBS is set to these flags.
625 # This macro is intended to be used in those situations when it is
626 # necessary to mix, e.g. C++ and Fortran, source code into a single
627 # program or shared library.
629 # For example, if object files from a C++ and Fortran compiler must
630 # be linked together, then the C++ compiler/linker must be used for
631 # linking (since special C++-ish things need to happen at link time
632 # like calling global constructors, instantiating templates, enabling
633 # exception support, etc.).
635 # However, the Fortran intrinsic and runtime libraries must be
636 # linked in as well, but the C++ compiler/linker doesn't know how to
637 # add these Fortran libraries.  Hence, the macro
638 # "AC_F77_LIBRARY_LDFLAGS" was created to determine these Fortran
639 # libraries.
641 # This macro was packaged in its current form by Matthew D. Langston.
642 # However, nearly all of this macro came from the "OCTAVE_FLIBS" macro
643 # in "octave-2.0.13/aclocal.m4", and full credit should go to John
644 # W. Eaton for writing this extremely useful macro.  Thank you John.
645 AC_DEFUN([_AC_FC_LIBRARY_LDFLAGS],
646 [_AC_FORTRAN_ASSERT()dnl
647 _AC_PROG_FC_V
648 AC_CACHE_CHECK([for _AC_LANG libraries of $[]_AC_FC[]], ac_cv_[]_AC_LANG_ABBREV[]_libs,
649 [if test "x$[]_AC_LANG_PREFIX[]LIBS" != "x"; then
650   ac_cv_[]_AC_LANG_ABBREV[]_libs="$[]_AC_LANG_PREFIX[]LIBS" # Let the user override the test.
651 else
653 _AC_PROG_FC_V_OUTPUT
655 ac_cv_[]_AC_LANG_ABBREV[]_libs=
657 # Save positional arguments (if any)
658 ac_save_positional="$[@]"
660 set X $ac_[]_AC_LANG_ABBREV[]_v_output
661 while test $[@%:@] != 1; do
662   shift
663   ac_arg=$[1]
664   case $ac_arg in
665         [[\\/]]*.a | ?:[[\\/]]*.a)
666           _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
667               ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg")
668           ;;
669         -bI:*)
670           _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
671              [_AC_LINKER_OPTION([$ac_arg], ac_cv_[]_AC_LANG_ABBREV[]_libs)])
672           ;;
673           # Ignore these flags.
674         -lang* | -lcrt*.o | -lc | -lgcc* | -lSystem | -libmil | -LANG:=* | -LIST:* | -LNO:*)
675           ;;
676         -lkernel32)
677           test x"$CYGWIN" != xyes && ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg"
678           ;;
679         -[[LRuYz]])
680           # These flags, when seen by themselves, take an argument.
681           # We remove the space between option and argument and re-iterate
682           # unless we find an empty arg or a new option (starting with -)
683           case $[2] in
684              "" | -*);;
685              *)
686                 ac_arg="$ac_arg$[2]"
687                 shift; shift
688                 set X $ac_arg "$[@]"
689                 ;;
690           esac
691           ;;
692         -YP,*)
693           for ac_j in `AS_ECHO(["$ac_arg"]) | sed -e 's/-YP,/-L/;s/:/ -L/g'`; do
694             _AC_LIST_MEMBER_IF($ac_j, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
695                                [ac_arg="$ac_arg $ac_j"
696                                ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_j"])
697           done
698           ;;
699         -[[lLR]]*)
700           _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
701                              ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg")
702           ;;
703         -zallextract*| -zdefaultextract)
704           ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg"
705           ;;
706           # Ignore everything else.
707   esac
708 done
709 # restore positional arguments
710 set X $ac_save_positional; shift
712 # We only consider "LD_RUN_PATH" on Solaris systems.  If this is seen,
713 # then we insist that the "run path" must be an absolute path (i.e. it
714 # must begin with a "/").
715 case `(uname -sr) 2>/dev/null` in
716    "SunOS 5"*)
717       ac_ld_run_path=`AS_ECHO(["$ac_[]_AC_LANG_ABBREV[]_v_output"]) |
718                         sed -n 's,^.*LD_RUN_PATH *= *\(/[[^ ]]*\).*$,-R\1,p'`
719       test "x$ac_ld_run_path" != x &&
720         _AC_LINKER_OPTION([$ac_ld_run_path], ac_cv_[]_AC_LANG_ABBREV[]_libs)
721       ;;
722 esac
723 fi # test "x$[]_AC_LANG_PREFIX[]LIBS" = "x"
725 []_AC_LANG_PREFIX[]LIBS="$ac_cv_[]_AC_LANG_ABBREV[]_libs"
726 AC_SUBST([]_AC_LANG_PREFIX[]LIBS)
727 ])# _AC_FC_LIBRARY_LDFLAGS
730 # AC_F77_LIBRARY_LDFLAGS
731 # ----------------------
732 AC_DEFUN([AC_F77_LIBRARY_LDFLAGS],
733 [AC_REQUIRE([AC_PROG_F77])dnl
734 AC_LANG_PUSH(Fortran 77)dnl
735 _AC_FC_LIBRARY_LDFLAGS
736 AC_LANG_POP(Fortran 77)dnl
737 ])# AC_F77_LIBRARY_LDFLAGS
740 # AC_FC_LIBRARY_LDFLAGS
741 # ----------------------
742 AC_DEFUN([AC_FC_LIBRARY_LDFLAGS],
743 [AC_REQUIRE([AC_PROG_FC])dnl
744 AC_LANG_PUSH(Fortran)dnl
745 _AC_FC_LIBRARY_LDFLAGS
746 AC_LANG_POP(Fortran)dnl
747 ])# AC_FC_LIBRARY_LDFLAGS
750 # _AC_FC_DUMMY_MAIN([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
751 # -----------------------------------------------------------
753 # Detect name of dummy main routine required by the Fortran libraries,
754 # (if any) and define {F77,FC}_DUMMY_MAIN to this name (which should be
755 # used for a dummy declaration, if it is defined).  On some systems,
756 # linking a C program to the Fortran library does not work unless you
757 # supply a dummy function called something like MAIN__.
759 # Execute ACTION-IF-NOT-FOUND if no way of successfully linking a C
760 # program with the {F77,FC} libs is found; default to exiting with an error
761 # message.  Execute ACTION-IF-FOUND if a dummy routine name is needed
762 # and found or if it is not needed (default to defining {F77,FC}_DUMMY_MAIN
763 # when needed).
765 # What is technically happening is that the Fortran libraries provide
766 # their own main() function, which usually initializes Fortran I/O and
767 # similar stuff, and then calls MAIN__, which is the entry point of
768 # your program.  Usually, a C program will override this with its own
769 # main() routine, but the linker sometimes complain if you don't
770 # provide a dummy (never-called) MAIN__ routine anyway.
772 # Of course, programs that want to allow Fortran subroutines to do
773 # I/O, etcetera, should call their main routine MAIN__() (or whatever)
774 # instead of main().  A separate autoconf test (_AC_FC_MAIN) checks
775 # for the routine to use in this case (since the semantics of the test
776 # are slightly different).  To link to e.g. purely numerical
777 # libraries, this is normally not necessary, however, and most C/C++
778 # programs are reluctant to turn over so much control to Fortran.  =)
780 # The name variants we check for are (in order):
781 #   MAIN__ (g77, MAIN__ required on some systems; IRIX, MAIN__ optional)
782 #   MAIN_, __main (SunOS)
783 #   MAIN _MAIN __MAIN main_ main__ _main (we follow DDD and try these too)
784 AC_DEFUN([_AC_FC_DUMMY_MAIN],
785 [_AC_FORTRAN_ASSERT()dnl
786 m4_define(_AC_LANG_PROGRAM_C_[]_AC_FC[]_HOOKS,
787 [#ifdef ]_AC_FC[_DUMMY_MAIN
788 ]AC_LANG_CASE([Fortran], [#ifndef FC_DUMMY_MAIN_EQ_F77])
789 [#  ifdef __cplusplus
790      extern "C"
791 #  endif
792    int ]_AC_FC[_DUMMY_MAIN() { return 1; }
793 ]AC_LANG_CASE([Fortran], [#endif])
794 [#endif
796 AC_CACHE_CHECK([for dummy main to link with _AC_LANG libraries],
797                ac_cv_[]_AC_LANG_ABBREV[]_dummy_main,
798 [ac_[]_AC_LANG_ABBREV[]_dm_save_LIBS=$LIBS
799  LIBS="$LIBS $[]_AC_LANG_PREFIX[]LIBS"
800  ac_fortran_dm_var=[]_AC_FC[]_DUMMY_MAIN
801  AC_LANG_PUSH(C)dnl
803  # First, try linking without a dummy main:
804  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
805                 [ac_cv_fortran_dummy_main=none],
806                 [ac_cv_fortran_dummy_main=unknown])
808  if test $ac_cv_fortran_dummy_main = unknown; then
809    for ac_func in MAIN__ MAIN_ __main MAIN _MAIN __MAIN main_ main__ _main; do
810      AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@define $ac_fortran_dm_var $ac_func]])],
811                     [ac_cv_fortran_dummy_main=$ac_func; break])
812    done
813  fi
814  AC_LANG_POP(C)dnl
815  ac_cv_[]_AC_LANG_ABBREV[]_dummy_main=$ac_cv_fortran_dummy_main
816  rm -f conftest*
817  LIBS=$ac_[]_AC_LANG_ABBREV[]_dm_save_LIBS
819 []_AC_FC[]_DUMMY_MAIN=$ac_cv_[]_AC_LANG_ABBREV[]_dummy_main
820 AS_IF([test "$[]_AC_FC[]_DUMMY_MAIN" != unknown],
821       [m4_default([$1],
822 [if test $[]_AC_FC[]_DUMMY_MAIN != none; then
823   AC_DEFINE_UNQUOTED([]_AC_FC[]_DUMMY_MAIN, $[]_AC_FC[]_DUMMY_MAIN,
824                      [Define to dummy `main' function (if any) required to
825                       link to the Fortran libraries.])
826   if test "x$ac_cv_fc_dummy_main" = "x$ac_cv_f77_dummy_main"; then
827         AC_DEFINE([FC_DUMMY_MAIN_EQ_F77], 1,
828                   [Define if F77 and FC dummy `main' functions are identical.])
829   fi
830 fi])],
831       [m4_default([$2],
832             [AC_MSG_FAILURE([linking to Fortran libraries from C fails])])])
833 ])# _AC_FC_DUMMY_MAIN
836 # AC_F77_DUMMY_MAIN
837 # ----------------------
838 AC_DEFUN([AC_F77_DUMMY_MAIN],
839 [AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
840 AC_LANG_PUSH(Fortran 77)dnl
841 _AC_FC_DUMMY_MAIN($@)
842 AC_LANG_POP(Fortran 77)dnl
843 ])# AC_F77_DUMMY_MAIN
846 # AC_FC_DUMMY_MAIN
847 # ----------------------
848 AC_DEFUN([AC_FC_DUMMY_MAIN],
849 [AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
850 AC_LANG_PUSH(Fortran)dnl
851 _AC_FC_DUMMY_MAIN($@)
852 AC_LANG_POP(Fortran)dnl
853 ])# AC_FC_DUMMY_MAIN
856 # _AC_FC_MAIN
857 # -----------
858 # Define {F77,FC}_MAIN to name of alternate main() function for use with
859 # the Fortran libraries.  (Typically, the libraries may define their
860 # own main() to initialize I/O, etcetera, that then call your own
861 # routine called MAIN__ or whatever.)  See _AC_FC_DUMMY_MAIN, above.
862 # If no such alternate name is found, just define {F77,FC}_MAIN to main.
864 AC_DEFUN([_AC_FC_MAIN],
865 [_AC_FORTRAN_ASSERT()dnl
866 AC_CACHE_CHECK([for alternate main to link with _AC_LANG libraries],
867                ac_cv_[]_AC_LANG_ABBREV[]_main,
868 [ac_[]_AC_LANG_ABBREV[]_m_save_LIBS=$LIBS
869  LIBS="$LIBS $[]_AC_LANG_PREFIX[]LIBS"
870  ac_fortran_dm_var=[]_AC_FC[]_DUMMY_MAIN
871  AC_LANG_PUSH(C)dnl
872  ac_cv_fortran_main="main" # default entry point name
873  for ac_func in MAIN__ MAIN_ __main MAIN _MAIN __MAIN main_ main__ _main; do
874    AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@ifdef FC_DUMMY_MAIN_EQ_F77
875 @%:@  undef F77_DUMMY_MAIN
876 @%:@  undef FC_DUMMY_MAIN
877 @%:@else
878 @%:@  undef $ac_fortran_dm_var
879 @%:@endif
880 @%:@define main $ac_func])],
881                   [ac_cv_fortran_main=$ac_func; break])
882  done
883  AC_LANG_POP(C)dnl
884  ac_cv_[]_AC_LANG_ABBREV[]_main=$ac_cv_fortran_main
885  rm -f conftest*
886  LIBS=$ac_[]_AC_LANG_ABBREV[]_m_save_LIBS
888 AC_DEFINE_UNQUOTED([]_AC_FC[]_MAIN, $ac_cv_[]_AC_LANG_ABBREV[]_main,
889                    [Define to alternate name for `main' routine that is
890                     called from a `main' in the Fortran libraries.])
891 ])# _AC_FC_MAIN
894 # AC_F77_MAIN
895 # -----------
896 AC_DEFUN([AC_F77_MAIN],
897 [AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
898 AC_LANG_PUSH(Fortran 77)dnl
899 _AC_FC_MAIN
900 AC_LANG_POP(Fortran 77)dnl
901 ])# AC_F77_MAIN
904 # AC_FC_MAIN
905 # ----------
906 AC_DEFUN([AC_FC_MAIN],
907 [AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
908 AC_LANG_PUSH(Fortran)dnl
909 _AC_FC_MAIN
910 AC_LANG_POP(Fortran)dnl
911 ])# AC_FC_MAIN
914 # __AC_FC_NAME_MANGLING
915 # ---------------------
916 # Test for the name mangling scheme used by the Fortran compiler.
918 # Sets ac_cv_{f77,fc}_mangling. The value contains three fields, separated
919 # by commas:
921 # lower case / upper case:
922 #    case translation of the Fortran symbols
923 # underscore / no underscore:
924 #    whether the compiler appends "_" to symbol names
925 # extra underscore / no extra underscore:
926 #    whether the compiler appends an extra "_" to symbol names already
927 #    containing at least one underscore
929 AC_DEFUN([__AC_FC_NAME_MANGLING],
930 [_AC_FORTRAN_ASSERT()dnl
931 AC_CACHE_CHECK([for _AC_LANG name-mangling scheme],
932                ac_cv_[]_AC_LANG_ABBREV[]_mangling,
933 [AC_COMPILE_IFELSE(
934 [      subroutine foobar()
935       return
936       end
937       subroutine foo_bar()
938       return
939       end],
940 [mv conftest.$ac_objext cfortran_test.$ac_objext
942   ac_save_LIBS=$LIBS
943   LIBS="cfortran_test.$ac_objext $LIBS $[]_AC_LANG_PREFIX[]LIBS"
945   AC_LANG_PUSH(C)dnl
946   ac_success=no
947   for ac_foobar in foobar FOOBAR; do
948     for ac_underscore in "" "_"; do
949       ac_func="$ac_foobar$ac_underscore"
950       AC_LINK_IFELSE([AC_LANG_CALL([], [$ac_func])],
951                      [ac_success=yes; break 2])
952     done
953   done
954   AC_LANG_POP(C)dnl
956   if test "$ac_success" = "yes"; then
957      case $ac_foobar in
958         foobar)
959            ac_case=lower
960            ac_foo_bar=foo_bar
961            ;;
962         FOOBAR)
963            ac_case=upper
964            ac_foo_bar=FOO_BAR
965            ;;
966      esac
968      AC_LANG_PUSH(C)dnl
969      ac_success_extra=no
970      for ac_extra in "" "_"; do
971         ac_func="$ac_foo_bar$ac_underscore$ac_extra"
972         AC_LINK_IFELSE([AC_LANG_CALL([], [$ac_func])],
973                        [ac_success_extra=yes; break])
974      done
975      AC_LANG_POP(C)dnl
977      if test "$ac_success_extra" = "yes"; then
978         ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_case case"
979         if test -z "$ac_underscore"; then
980            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, no underscore"
981         else
982            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, underscore"
983         fi
984         if test -z "$ac_extra"; then
985            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, no extra underscore"
986         else
987            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, extra underscore"
988         fi
989       else
990         ac_cv_[]_AC_LANG_ABBREV[]_mangling="unknown"
991       fi
992   else
993      ac_cv_[]_AC_LANG_ABBREV[]_mangling="unknown"
994   fi
996   LIBS=$ac_save_LIBS
997   rm -f cfortran_test* conftest*],
998   [AC_MSG_FAILURE([cannot compile a simple Fortran program])])
1000 ])# __AC_FC_NAME_MANGLING
1002 # The replacement is empty.
1003 AU_DEFUN([AC_F77_NAME_MANGLING], [])
1006 # _AC_F77_NAME_MANGLING
1007 # ----------------------
1008 AC_DEFUN([_AC_F77_NAME_MANGLING],
1009 [AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
1010 AC_REQUIRE([AC_F77_DUMMY_MAIN])dnl
1011 AC_LANG_PUSH(Fortran 77)dnl
1012 __AC_FC_NAME_MANGLING
1013 AC_LANG_POP(Fortran 77)dnl
1014 ])# _AC_F77_NAME_MANGLING
1017 # _AC_FC_NAME_MANGLING
1018 # ----------------------
1019 AC_DEFUN([_AC_FC_NAME_MANGLING],
1020 [AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
1021 AC_REQUIRE([AC_FC_DUMMY_MAIN])dnl
1022 AC_LANG_PUSH(Fortran)dnl
1023 __AC_FC_NAME_MANGLING
1024 AC_LANG_POP(Fortran)dnl
1025 ])# _AC_FC_NAME_MANGLING
1028 # _AC_FC_WRAPPERS
1029 # ---------------
1030 # Defines C macros {F77,FC}_FUNC(name,NAME) and {F77,FC}_FUNC_(name,NAME) to
1031 # properly mangle the names of C identifiers, and C identifiers with
1032 # underscores, respectively, so that they match the name mangling
1033 # scheme used by the Fortran compiler.
1034 AC_DEFUN([_AC_FC_WRAPPERS],
1035 [_AC_FORTRAN_ASSERT()dnl
1036 case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in
1037   'lower case, no underscore, extra underscore' | \
1038   'lower case, underscore, no extra underscore' | \
1039   'lower case, underscore, extra underscore' | \
1040   'upper case, no underscore, no extra underscore' | \
1041   'upper case, no underscore, extra underscore' | \
1042   'upper case, underscore, no extra underscore' | \
1043   'upper case, underscore, extra underscore') ;;
1044   *)
1045           AC_MSG_WARN([unknown Fortran name-mangling scheme])
1046           ;;
1047 esac
1048 case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in #(
1049   'upper case',*,)
1050      AC_DEFINE(_AC_FC[_UPPER_CASE], 1,
1051        [Define to 1 if upper case spelling should be used.]);;
1052 esac
1053 case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in #(
1054   *,'underscore',*)
1055      AC_DEFINE(_AC_FC[_UNDERSCORE], 1,
1056        [Define to 1 if an underscore should be appended.]);;
1057 esac
1058 case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in #(
1059   *,*,'extra underscore')
1060      AC_DEFINE(_AC_FC[_EXTRA_UNDERSCORE], 1,
1061        [Define to 1 if an extra underscore should be appended.]);;
1062 esac
1063 AH_VERBATIM(_AC_FC[_FUNC],
1064 [/* Define to 1 if upper case spelling should be used. */
1065 #undef ]_AC_FC[_UPPER_CASE
1067 /* Define to 1 if an underscore should be appended. */
1068 #undef ]_AC_FC[_UNDERSCORE
1070 /* Define to 1 if an extra underscore should be appended. */
1071 #undef ]_AC_FC[_EXTRA_UNDERSCORE
1073 /* Define to a macro mangling the given C identifier (in lower and upper
1074    case), which must not contain underscores, for linking with Fortran.
1075 #ifdef ]_AC_FC[_UPPER_CASE
1076 # ifdef ]_AC_FC[_UNDERSCORE
1077 #  ifdef ]_AC_FC[_EXTRA_UNDERSCORE
1078 #   define ]_AC_FC[_FUNC(name, NAME)    NAME ## _
1079 #   define ]_AC_FC[_FUNC_(name, NAME)   NAME ## __
1080 #  else
1081 #   define ]_AC_FC[_FUNC(name, NAME)    NAME ## _
1082 #   define ]_AC_FC[_FUNC_(name, NAME)   NAME ## _
1083 #  endif
1084 # else
1085 #  ifdef ]_AC_FC[_EXTRA_UNDERSCORE
1086 #   define ]_AC_FC[_FUNC(name, NAME)    NAME
1087 #   define ]_AC_FC[_FUNC_(name, NAME)   NAME ## _
1088 #  else
1089 #   define ]_AC_FC[_FUNC(name, NAME)    NAME
1090 #   define ]_AC_FC[_FUNC_(name, NAME)   NAME
1091 #  endif
1092 # endif
1093 #else
1094 # ifdef ]_AC_FC[_UNDERSCORE
1095 #  ifdef ]_AC_FC[_EXTRA_UNDERSCORE
1096 #   define ]_AC_FC[_FUNC(name, NAME)    name ## _
1097 #   define ]_AC_FC[_FUNC_(name, NAME)   name ## __
1098 #  else
1099 #   define ]_AC_FC[_FUNC(name, NAME)    name ## _
1100 #   define ]_AC_FC[_FUNC_(name, NAME)   name ## _
1101 #  endif
1102 # else
1103 #  ifdef ]_AC_FC[_EXTRA_UNDERSCORE
1104 #   define ]_AC_FC[_FUNC(name, NAME)    name
1105 #   define ]_AC_FC[_FUNC_(name, NAME)   name ## _
1106 #  else
1107 #   define ]_AC_FC[_FUNC(name, NAME)    name
1108 #   define ]_AC_FC[_FUNC_(name, NAME)   name
1109 #  endif
1110 # endif
1111 #endif])
1112 ])# _AC_FC_WRAPPERS
1115 # AC_F77_WRAPPERS
1116 # ---------------
1117 AC_DEFUN([AC_F77_WRAPPERS],
1118 [AC_REQUIRE([_AC_F77_NAME_MANGLING])dnl
1119 AC_LANG_PUSH(Fortran 77)dnl
1120 _AC_FC_WRAPPERS
1121 AC_LANG_POP(Fortran 77)dnl
1122 ])# AC_F77_WRAPPERS
1125 # AC_FC_WRAPPERS
1126 # --------------
1127 AC_DEFUN([AC_FC_WRAPPERS],
1128 [AC_REQUIRE([_AC_FC_NAME_MANGLING])dnl
1129 AC_LANG_PUSH(Fortran)dnl
1130 _AC_FC_WRAPPERS
1131 AC_LANG_POP(Fortran)dnl
1132 ])# AC_FC_WRAPPERS
1135 # _AC_FC_FUNC(NAME, [SHELLVAR = NAME])
1136 # ------------------------------------
1137 # For a Fortran subroutine of given NAME, define a shell variable
1138 # $SHELLVAR to the Fortran-mangled name.  If the SHELLVAR
1139 # argument is not supplied, it defaults to NAME.
1140 AC_DEFUN([_AC_FC_FUNC],
1141 [_AC_FORTRAN_ASSERT()dnl
1142 case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in
1143   upper*) ac_val="m4_toupper([$1])" ;;
1144   lower*) ac_val="m4_tolower([$1])" ;;
1145   *)      ac_val="unknown" ;;
1146 esac
1147 case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in *," underscore"*) ac_val="$ac_val"_ ;; esac
1148 m4_if(m4_index([$1],[_]),-1,[],
1149 [case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in *," extra underscore"*) ac_val="$ac_val"_ ;; esac
1151 m4_default([$2],[$1])="$ac_val"
1152 ])# _AC_FC_FUNC
1155 # AC_F77_FUNC(NAME, [SHELLVAR = NAME])
1156 # ------------------------------------
1157 AC_DEFUN([AC_F77_FUNC],
1158 [AC_REQUIRE([_AC_F77_NAME_MANGLING])dnl
1159 AC_LANG_PUSH(Fortran 77)dnl
1160 _AC_FC_FUNC([$1],[$2])
1161 AC_LANG_POP(Fortran 77)dnl
1162 ])# AC_F77_FUNC
1165 # AC_FC_FUNC(NAME, [SHELLVAR = NAME])
1166 # -----------------------------------
1167 AC_DEFUN([AC_FC_FUNC],
1168 [AC_REQUIRE([_AC_FC_NAME_MANGLING])dnl
1169 AC_LANG_PUSH(Fortran)dnl
1170 _AC_FC_FUNC([$1],[$2])
1171 AC_LANG_POP(Fortran)dnl
1172 ])# AC_FC_FUNC
1175 # AC_FC_SRCEXT(EXT, [ACTION-IF-SUCCESS], [ACTION-IF-FAILURE])
1176 # -----------------------------------------------------------
1177 # Set the source-code extension used in Fortran (FC) tests to EXT (which
1178 # defaults to f).  Also, look for any necessary additional FCFLAGS needed
1179 # to allow this extension, and store them in the output variable
1180 # FCFLAGS_<EXT> (e.g. FCFLAGS_f90 for EXT=f90).  If successful,
1181 # call ACTION-IF-SUCCESS.  If unable to compile source code with EXT,
1182 # call ACTION-IF-FAILURE, which defaults to failing with an error
1183 # message.
1185 # (The flags for the current source-code extension, if any, are stored in
1186 # $ac_fcflags_srcext and used automatically in subsequent autoconf tests.)
1188 # For ordinary extensions like f90, etcetera, the modified FCFLAGS
1189 # are currently needed for IBM's xlf* and Intel's ifc (grrr).  Unfortunately,
1190 # xlf* will only take flags to recognize one extension at a time, so if the
1191 # user wants to compile multiple extensions (.f90 and .f95, say), she
1192 # will need to use the FCFLAGS_F90 and FCFLAGS_F95 individually rather
1193 # than just adding them all to FCFLAGS, for example.
1195 # Also, for Intel's ifc compiler (which does not accept .f95 by default in
1196 # some versions), the $FCFLAGS_<EXT> variable *must* go immediately before
1197 # the source file on the command line, unlike other $FCFLAGS.  Ugh.
1198 AC_DEFUN([AC_FC_SRCEXT],
1199 [AC_LANG_PUSH(Fortran)dnl
1200 AC_CACHE_CHECK([for Fortran flag to compile .$1 files],
1201                 ac_cv_fc_srcext_$1,
1202 [ac_ext=$1
1203 ac_fcflags_srcext_save=$ac_fcflags_srcext
1204 ac_fcflags_srcext=
1205 ac_cv_fc_srcext_$1=unknown
1206 for ac_flag in none -qsuffix=f=$1 -Tf; do
1207   test "x$ac_flag" != xnone && ac_fcflags_srcext="$ac_flag"
1208   AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [ac_cv_fc_srcext_$1=$ac_flag; break])
1209 done
1210 rm -f conftest.$ac_objext conftest.$1
1211 ac_fcflags_srcext=$ac_fcflags_srcext_save
1213 if test "x$ac_cv_fc_srcext_$1" = xunknown; then
1214   m4_default([$3],[AC_MSG_ERROR([Fortran could not compile .$1 files])])
1215 else
1216   ac_fc_srcext=$1
1217   if test "x$ac_cv_fc_srcext_$1" = xnone; then
1218     ac_fcflags_srcext=""
1219     FCFLAGS_[]$1[]=""
1220   else
1221     ac_fcflags_srcext=$ac_cv_fc_srcext_$1
1222     FCFLAGS_[]$1[]=$ac_cv_fc_srcext_$1
1223   fi
1224   AC_SUBST(FCFLAGS_[]$1)
1225   $2
1227 AC_LANG_POP(Fortran)dnl
1228 ])# AC_FC_SRCEXT
1231 # AC_FC_FREEFORM([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1232 # ------------------------------------------------------------------
1233 # Look for a compiler flag to make the Fortran (FC) compiler accept
1234 # free-format source code, and adds it to FCFLAGS.  Call
1235 # ACTION-IF-SUCCESS (defaults to nothing) if successful (i.e. can
1236 # compile code using new extension) and ACTION-IF-FAILURE (defaults to
1237 # failing with an error message) if not.  (Defined via DEFUN_ONCE to
1238 # prevent flag from being added to FCFLAGS multiple times.)
1240 # The known flags are:
1241 #        -ffree-form: GNU g77
1242 #                -FR: Intel compiler (icc, ecc)
1243 #              -free: Compaq compiler (fort)
1244 #             -qfree: IBM compiler (xlf)
1245 # -Mfree, -Mfreeform: Portland Group compiler
1246 #          -freeform: SGI compiler
1247 #            -f free: Absoft Fortran
1248 # We try to test the "more popular" flags first, by some prejudiced
1249 # notion of popularity.
1250 AC_DEFUN_ONCE([AC_FC_FREEFORM],
1251 [AC_LANG_PUSH(Fortran)dnl
1252 AC_CACHE_CHECK([for Fortran flag needed to allow free-form source],
1253                 ac_cv_fc_freeform,
1254 [ac_cv_fc_freeform=unknown
1255 ac_fc_freeform_FCFLAGS_save=$FCFLAGS
1256 for ac_flag in none -ffree-form -FR -free -qfree -Mfree -Mfreeform \
1257                -freeform "-f free"
1259   test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_freeform_FCFLAGS_save $ac_flag"
1260   AC_COMPILE_IFELSE([
1261   program freeform
1262        ! FIXME: how to best confuse non-freeform compilers?
1263        print *, 'Hello ', &
1264            'world.'
1265        end],
1266                     [ac_cv_fc_freeform=$ac_flag; break])
1267 done
1268 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
1269 FCFLAGS=$ac_fc_freeform_FCFLAGS_save
1271 if test "x$ac_cv_fc_freeform" = xunknown; then
1272   m4_default([$2],
1273              [AC_MSG_ERROR([Fortran does not accept free-form source], 77)])
1274 else
1275   if test "x$ac_cv_fc_freeform" != xnone; then
1276     FCFLAGS="$FCFLAGS $ac_cv_fc_freeform"
1277   fi
1278   $1
1280 AC_LANG_POP(Fortran)dnl
1281 ])# AC_FC_FREEFORM