* lib/autoconf/fortran.m4 (_AC_FC_LIBRARY_LDFLAGS): Also ignore
[autoconf/tsuna.git] / lib / autoconf / fortran.m4
blob45ce9ab372192ddb144a0b95beb450accf5ff9f9
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 #  lf95: Lahey-Fujitsu F95 compiler
345 #  fl32: Microsoft Fortran 77 "PowerStation" compiler
346 #  af77: Apogee F77 compiler for Intergraph hardware running CLIX
347 #  epcf90: "Edinburgh Portable Compiler" F90
348 #  fort: Compaq (now HP) Fortran 90/95 compiler for Tru64 and Linux/Alpha
349 #  ifort, previously ifc: Intel Fortran 95 compiler for Linux/x86
350 #  efc: Intel Fortran 95 compiler for IA64
351 m4_define([_AC_F95_FC], [gfortran g95 f95 fort xlf95 ifort ifc efc pgf95 lf95 ftn])
352 m4_define([_AC_F90_FC], [f90 xlf90 pgf90 pghpf epcf90])
353 m4_define([_AC_F77_FC], [g77 f77 xlf frt pgf77 cf77 fort77 fl32 af77])
354 AC_DEFUN([_AC_PROG_FC],
355 [_AC_FORTRAN_ASSERT()dnl
356 AC_CHECK_TOOLS([]_AC_FC[],
357       m4_default([$2],
358         m4_case(_AC_FC_DIALECT_YEAR([$1]),
359                 [1995], [_AC_F95_FC],
360                 [1990], [_AC_F90_FC _AC_F95_FC],
361                 [1977], [_AC_F77_FC _AC_F90_FC _AC_F95_FC],
362                 [_AC_F95_FC _AC_F90_FC _AC_F77_FC])))
364 # Provide some information about the compiler.
365 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
366 ac_compiler=`set X $ac_compile; echo $[2]`
367 _AC_DO([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
368 _AC_DO([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
369 _AC_DO([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
370 rm -f a.out
372 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
373 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
374 # If we don't use `.F' as extension, the preprocessor is not run on the
375 # input file.  (Note that this only needs to work for GNU compilers.)
376 ac_save_ext=$ac_ext
377 ac_ext=F
378 _AC_LANG_COMPILER_GNU
379 ac_ext=$ac_save_ext
380 _AC_PROG_FC_G
381 ])# _AC_PROG_FC
384 # AC_PROG_F77([COMPILERS...])
385 # ---------------------------
386 # COMPILERS is a space separated list of Fortran 77 compilers to search
387 # for.  See also _AC_PROG_FC.
388 AC_DEFUN([AC_PROG_F77],
389 [AC_LANG_PUSH(Fortran 77)dnl
390 AC_ARG_VAR([F77],    [Fortran 77 compiler command])dnl
391 AC_ARG_VAR([FFLAGS], [Fortran 77 compiler flags])dnl
392 _AC_ARG_VAR_LDFLAGS()dnl
393 _AC_PROG_FC([Fortran 77], [$1])
394 G77=`test $ac_compiler_gnu = yes && echo yes`
395 AC_LANG_POP(Fortran 77)dnl
396 ])# AC_PROG_F77
399 # AC_PROG_FC([COMPILERS...], [DIALECT])
400 # -------------------------------------
401 # COMPILERS is a space separated list of Fortran 77 compilers to search
402 # for, and [DIALECT] is an optional dialect.  See also _AC_PROG_FC.
403 AC_DEFUN([AC_PROG_FC],
404 [AC_LANG_PUSH(Fortran)dnl
405 AC_ARG_VAR([FC],    [Fortran compiler command])dnl
406 AC_ARG_VAR([FCFLAGS], [Fortran compiler flags])dnl
407 _AC_ARG_VAR_LDFLAGS()dnl
408 _AC_PROG_FC([$2], [$1])
409 AC_LANG_POP(Fortran)dnl
410 ])# AC_PROG_FC
413 # _AC_PROG_FC_G
414 # -------------
415 # Check whether -g works, even if F[C]FLAGS is set, in case the package
416 # plays around with F[C]FLAGS (such as to build both debugging and normal
417 # versions of a library), tasteless as that idea is.
418 m4_define([_AC_PROG_FC_G],
419 [_AC_FORTRAN_ASSERT()dnl
420 ac_test_FFLAGS=${[]_AC_LANG_PREFIX[]FLAGS+set}
421 ac_save_FFLAGS=$[]_AC_LANG_PREFIX[]FLAGS
422 _AC_LANG_PREFIX[]FLAGS=
423 AC_CACHE_CHECK(whether $[]_AC_FC[] accepts -g, ac_cv_prog_[]_AC_LANG_ABBREV[]_g,
424 [_AC_LANG_PREFIX[]FLAGS=-g
425 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
426 [ac_cv_prog_[]_AC_LANG_ABBREV[]_g=yes],
427 [ac_cv_prog_[]_AC_LANG_ABBREV[]_g=no])
429 if test "$ac_test_FFLAGS" = set; then
430   _AC_LANG_PREFIX[]FLAGS=$ac_save_FFLAGS
431 elif test $ac_cv_prog_[]_AC_LANG_ABBREV[]_g = yes; then
432   if test "x$ac_cv_[]_AC_LANG_ABBREV[]_compiler_gnu" = xyes; then
433     _AC_LANG_PREFIX[]FLAGS="-g -O2"
434   else
435     _AC_LANG_PREFIX[]FLAGS="-g"
436   fi
437 else
438   if test "x$ac_cv_[]_AC_LANG_ABBREV[]_compiler_gnu" = xyes; then
439     _AC_LANG_PREFIX[]FLAGS="-O2"
440   else
441     _AC_LANG_PREFIX[]FLAGS=
442   fi
443 fi[]dnl
444 ])# _AC_PROG_FC_G
447 # _AC_PROG_FC_C_O
448 # ---------------
449 # Test if the Fortran compiler accepts the options `-c' and `-o'
450 # simultaneously, and define `[F77/FC]_NO_MINUS_C_MINUS_O' if it does not.
452 # The usefulness of this macro is questionable, as I can't really see
453 # why anyone would use it.  The only reason I include it is for
454 # completeness, since a similar test exists for the C compiler.
456 # FIXME: it seems like we could merge the C/C++/Fortran versions of this.
457 AC_DEFUN([_AC_PROG_FC_C_O],
458 [_AC_FORTRAN_ASSERT()dnl
459 AC_CACHE_CHECK([whether $[]_AC_FC[] understands -c and -o together],
460                [ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o],
461 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
462 # We test twice because some compilers refuse to overwrite an existing
463 # `.o' file with `-o', although they will create one.
464 ac_try='$[]_AC_FC[] $[]_AC_LANG_PREFIX[]FLAGS -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
465 rm -f conftest2.*
466 if _AC_DO_VAR(ac_try) &&
467      test -f conftest2.$ac_objext &&
468      _AC_DO_VAR(ac_try); then
469   ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o=yes
470 else
471   ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o=no
473 rm -f conftest*])
474 if test $ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o = no; then
475   AC_DEFINE([]_AC_FC[]_NO_MINUS_C_MINUS_O, 1,
476             [Define to 1 if your Fortran compiler doesn't accept
477              -c and -o together.])
479 ])# _AC_PROG_FC_C_O
482 # AC_PROG_F77_C_O
483 # ---------------
484 AC_DEFUN([AC_PROG_F77_C_O],
485 [AC_REQUIRE([AC_PROG_F77])dnl
486 AC_LANG_PUSH(Fortran 77)dnl
487 _AC_PROG_FC_C_O
488 AC_LANG_POP(Fortran 77)dnl
489 ])# AC_PROG_F77_C_O
492 # AC_PROG_FC_C_O
493 # ---------------
494 AC_DEFUN([AC_PROG_FC_C_O],
495 [AC_REQUIRE([AC_PROG_FC])dnl
496 AC_LANG_PUSH(Fortran)dnl
497 _AC_PROG_FC_C_O
498 AC_LANG_POP(Fortran)dnl
499 ])# AC_PROG_FC_C_O
502 ## ------------------------------- ##
503 ## 4. Compilers' characteristics.  ##
504 ## ------------------------------- ##
507 # ---------------------------------------- #
508 # 4d. Fortran 77 compiler characteristics. #
509 # ---------------------------------------- #
512 # _AC_PROG_FC_V_OUTPUT([FLAG = $ac_cv_prog_{f77/fc}_v])
513 # -------------------------------------------------
514 # Link a trivial Fortran program, compiling with a verbose output FLAG
515 # (whose default value, $ac_cv_prog_{f77/fc}_v, is computed by
516 # _AC_PROG_FC_V), and return the output in $ac_{f77/fc}_v_output.  This
517 # output is processed in the way expected by _AC_FC_LIBRARY_LDFLAGS,
518 # so that any link flags that are echoed by the compiler appear as
519 # space-separated items.
520 AC_DEFUN([_AC_PROG_FC_V_OUTPUT],
521 [_AC_FORTRAN_ASSERT()dnl
522 AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
524 # Compile and link our simple test program by passing a flag (argument
525 # 1 to this macro) to the Fortran compiler in order to get
526 # "verbose" output that we can then parse for the Fortran linker
527 # flags.
528 ac_save_FFLAGS=$[]_AC_LANG_PREFIX[]FLAGS
529 _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS m4_default([$1], [$ac_cv_prog_[]_AC_LANG_ABBREV[]_v])"
530 eval "set x $ac_link"
531 shift
532 _AS_ECHO_LOG([$[*]])
533 ac_[]_AC_LANG_ABBREV[]_v_output=`eval $ac_link AS_MESSAGE_LOG_FD>&1 2>&1 | grep -v 'Driving:'`
534 echo "$ac_[]_AC_LANG_ABBREV[]_v_output" >&AS_MESSAGE_LOG_FD
535 _AC_LANG_PREFIX[]FLAGS=$ac_save_FFLAGS
537 rm -f conftest*
539 # On HP/UX there is a line like: "LPATH is: /foo:/bar:/baz" where
540 # /foo, /bar, and /baz are search directories for the Fortran linker.
541 # Here, we change these into -L/foo -L/bar -L/baz (and put it first):
542 ac_[]_AC_LANG_ABBREV[]_v_output="`echo $ac_[]_AC_LANG_ABBREV[]_v_output |
543         grep 'LPATH is:' |
544         sed 's,.*LPATH is\(: *[[^ ]]*\).*,\1,;s,: */, -L/,g'` $ac_[]_AC_LANG_ABBREV[]_v_output"
546 # FIXME: we keep getting bitten by quoted arguments; a more general fix
547 #        that detects unbalanced quotes in FLIBS should be implemented
548 #        and (ugh) tested at some point.
549 case $ac_[]_AC_LANG_ABBREV[]_v_output in
550   # If we are using xlf then replace all the commas with spaces.
551   *xlfentry*)
552     ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed 's/,/ /g'` ;;
554   # With Intel ifc, ignore the quoted -mGLOB_options_string stuff (quoted
555   # $LIBS confuse us, and the libraries appear later in the output anyway).
556   *mGLOB_options_string*)
557     ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed 's/"-mGLOB[[^"]]*"/ /g'` ;;
559   # Portland Group compiler has singly- or doubly-quoted -cmdline argument
560   # Singly-quoted arguments were reported for versions 5.2-4 and 6.0-4.
561   # Doubly-quoted arguments were reported for "PGF90/x86 Linux/x86 5.0-2".
562   *-cmdline\ * | *-ignore\ * | *-def\ *)
563     ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed "\
564         s/-cmdline  *'[[^']]*'/ /g; s/-cmdline  *\"[[^\"]]*\"/ /g
565         s/-ignore  *'[[^']]*'/ /g; s/-ignore  *\"[[^\"]]*\"/ /g
566         s/-def  *'[[^']]*'/ /g; s/-def  *\"[[^\"]]*\"/ /g"` ;;
568   # If we are using Cray Fortran then delete quotes.
569   *cft90*)
570     ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed 's/"//g'` ;;
571 esac
573 ])# _AC_PROG_FC_V_OUTPUT
576 # _AC_PROG_FC_V
577 # --------------
579 # Determine the flag that causes the Fortran compiler to print
580 # information of library and object files (normally -v)
581 # Needed for _AC_FC_LIBRARY_FLAGS
582 # Some compilers don't accept -v (Lahey: -verbose, xlf: -V, Fujitsu: -###)
583 AC_DEFUN([_AC_PROG_FC_V],
584 [_AC_FORTRAN_ASSERT()dnl
585 AC_CACHE_CHECK([how to get verbose linking output from $[]_AC_FC[]],
586                 [ac_cv_prog_[]_AC_LANG_ABBREV[]_v],
587 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
588 [ac_cv_prog_[]_AC_LANG_ABBREV[]_v=
589 # Try some options frequently used verbose output
590 for ac_verb in -v -verbose --verbose -V -\#\#\#; do
591   _AC_PROG_FC_V_OUTPUT($ac_verb)
592   # look for -l* and *.a constructs in the output
593   for ac_arg in $ac_[]_AC_LANG_ABBREV[]_v_output; do
594      case $ac_arg in
595         [[\\/]]*.a | ?:[[\\/]]*.a | -[[lLRu]]*)
596           ac_cv_prog_[]_AC_LANG_ABBREV[]_v=$ac_verb
597           break 2 ;;
598      esac
599   done
600 done
601 if test -z "$ac_cv_prog_[]_AC_LANG_ABBREV[]_v"; then
602    AC_MSG_WARN([cannot determine how to obtain linking information from $[]_AC_FC[]])
603 fi],
604                   [AC_MSG_WARN([compilation failed])])
605 ])])# _AC_PROG_FC_V
608 # _AC_FC_LIBRARY_LDFLAGS
609 # ----------------------
611 # Determine the linker flags (e.g. "-L" and "-l") for the Fortran
612 # intrinsic and runtime libraries that are required to successfully
613 # link a Fortran program or shared library.  The output variable
614 # FLIBS/FCLIBS is set to these flags.
616 # This macro is intended to be used in those situations when it is
617 # necessary to mix, e.g. C++ and Fortran, source code into a single
618 # program or shared library.
620 # For example, if object files from a C++ and Fortran compiler must
621 # be linked together, then the C++ compiler/linker must be used for
622 # linking (since special C++-ish things need to happen at link time
623 # like calling global constructors, instantiating templates, enabling
624 # exception support, etc.).
626 # However, the Fortran intrinsic and runtime libraries must be
627 # linked in as well, but the C++ compiler/linker doesn't know how to
628 # add these Fortran libraries.  Hence, the macro
629 # "AC_F77_LIBRARY_LDFLAGS" was created to determine these Fortran
630 # libraries.
632 # This macro was packaged in its current form by Matthew D. Langston.
633 # However, nearly all of this macro came from the "OCTAVE_FLIBS" macro
634 # in "octave-2.0.13/aclocal.m4", and full credit should go to John
635 # W. Eaton for writing this extremely useful macro.  Thank you John.
636 AC_DEFUN([_AC_FC_LIBRARY_LDFLAGS],
637 [_AC_FORTRAN_ASSERT()dnl
638 _AC_PROG_FC_V
639 AC_CACHE_CHECK([for _AC_LANG libraries of $[]_AC_FC[]], ac_cv_[]_AC_LANG_ABBREV[]_libs,
640 [if test "x$[]_AC_LANG_PREFIX[]LIBS" != "x"; then
641   ac_cv_[]_AC_LANG_ABBREV[]_libs="$[]_AC_LANG_PREFIX[]LIBS" # Let the user override the test.
642 else
644 _AC_PROG_FC_V_OUTPUT
646 ac_cv_[]_AC_LANG_ABBREV[]_libs=
648 # Save positional arguments (if any)
649 ac_save_positional="$[@]"
651 set X $ac_[]_AC_LANG_ABBREV[]_v_output
652 while test $[@%:@] != 1; do
653   shift
654   ac_arg=$[1]
655   case $ac_arg in
656         [[\\/]]*.a | ?:[[\\/]]*.a)
657           _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
658               ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg")
659           ;;
660         -bI:*)
661           _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
662              [_AC_LINKER_OPTION([$ac_arg], ac_cv_[]_AC_LANG_ABBREV[]_libs)])
663           ;;
664           # Ignore these flags.
665         -lang* | -lcrt*.o | -lc | -lgcc* | -lSystem | -libmil | -LANG:=* | -LIST:* | -LNO:*)
666           ;;
667         -lkernel32)
668           test x"$CYGWIN" != xyes && ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg"
669           ;;
670         -[[LRuYz]])
671           # These flags, when seen by themselves, take an argument.
672           # We remove the space between option and argument and re-iterate
673           # unless we find an empty arg or a new option (starting with -)
674           case $[2] in
675              "" | -*);;
676              *)
677                 ac_arg="$ac_arg$[2]"
678                 shift; shift
679                 set X $ac_arg "$[@]"
680                 ;;
681           esac
682           ;;
683         -YP,*)
684           for ac_j in `echo $ac_arg | sed -e 's/-YP,/-L/;s/:/ -L/g'`; do
685             _AC_LIST_MEMBER_IF($ac_j, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
686                                [ac_arg="$ac_arg $ac_j"
687                                ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_j"])
688           done
689           ;;
690         -[[lLR]]*)
691           _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
692                              ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg")
693           ;;
694         -zallextract*| -zdefaultextract)
695           ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg"
696           ;;
697           # Ignore everything else.
698   esac
699 done
700 # restore positional arguments
701 set X $ac_save_positional; shift
703 # We only consider "LD_RUN_PATH" on Solaris systems.  If this is seen,
704 # then we insist that the "run path" must be an absolute path (i.e. it
705 # must begin with a "/").
706 case `(uname -sr) 2>/dev/null` in
707    "SunOS 5"*)
708       ac_ld_run_path=`echo $ac_[]_AC_LANG_ABBREV[]_v_output |
709                         sed -n 's,^.*LD_RUN_PATH *= *\(/[[^ ]]*\).*$,-R\1,p'`
710       test "x$ac_ld_run_path" != x &&
711         _AC_LINKER_OPTION([$ac_ld_run_path], ac_cv_[]_AC_LANG_ABBREV[]_libs)
712       ;;
713 esac
714 fi # test "x$[]_AC_LANG_PREFIX[]LIBS" = "x"
716 []_AC_LANG_PREFIX[]LIBS="$ac_cv_[]_AC_LANG_ABBREV[]_libs"
717 AC_SUBST([]_AC_LANG_PREFIX[]LIBS)
718 ])# _AC_FC_LIBRARY_LDFLAGS
721 # AC_F77_LIBRARY_LDFLAGS
722 # ----------------------
723 AC_DEFUN([AC_F77_LIBRARY_LDFLAGS],
724 [AC_REQUIRE([AC_PROG_F77])dnl
725 AC_LANG_PUSH(Fortran 77)dnl
726 _AC_FC_LIBRARY_LDFLAGS
727 AC_LANG_POP(Fortran 77)dnl
728 ])# AC_F77_LIBRARY_LDFLAGS
731 # AC_FC_LIBRARY_LDFLAGS
732 # ----------------------
733 AC_DEFUN([AC_FC_LIBRARY_LDFLAGS],
734 [AC_REQUIRE([AC_PROG_FC])dnl
735 AC_LANG_PUSH(Fortran)dnl
736 _AC_FC_LIBRARY_LDFLAGS
737 AC_LANG_POP(Fortran)dnl
738 ])# AC_FC_LIBRARY_LDFLAGS
741 # _AC_FC_DUMMY_MAIN([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
742 # -----------------------------------------------------------
744 # Detect name of dummy main routine required by the Fortran libraries,
745 # (if any) and define {F77,FC}_DUMMY_MAIN to this name (which should be
746 # used for a dummy declaration, if it is defined).  On some systems,
747 # linking a C program to the Fortran library does not work unless you
748 # supply a dummy function called something like MAIN__.
750 # Execute ACTION-IF-NOT-FOUND if no way of successfully linking a C
751 # program with the {F77,FC} libs is found; default to exiting with an error
752 # message.  Execute ACTION-IF-FOUND if a dummy routine name is needed
753 # and found or if it is not needed (default to defining {F77,FC}_DUMMY_MAIN
754 # when needed).
756 # What is technically happening is that the Fortran libraries provide
757 # their own main() function, which usually initializes Fortran I/O and
758 # similar stuff, and then calls MAIN__, which is the entry point of
759 # your program.  Usually, a C program will override this with its own
760 # main() routine, but the linker sometimes complain if you don't
761 # provide a dummy (never-called) MAIN__ routine anyway.
763 # Of course, programs that want to allow Fortran subroutines to do
764 # I/O, etcetera, should call their main routine MAIN__() (or whatever)
765 # instead of main().  A separate autoconf test (_AC_FC_MAIN) checks
766 # for the routine to use in this case (since the semantics of the test
767 # are slightly different).  To link to e.g. purely numerical
768 # libraries, this is normally not necessary, however, and most C/C++
769 # programs are reluctant to turn over so much control to Fortran.  =)
771 # The name variants we check for are (in order):
772 #   MAIN__ (g77, MAIN__ required on some systems; IRIX, MAIN__ optional)
773 #   MAIN_, __main (SunOS)
774 #   MAIN _MAIN __MAIN main_ main__ _main (we follow DDD and try these too)
775 AC_DEFUN([_AC_FC_DUMMY_MAIN],
776 [_AC_FORTRAN_ASSERT()dnl
777 m4_define(_AC_LANG_PROGRAM_C_[]_AC_FC[]_HOOKS,
778 [#ifdef ]_AC_FC[_DUMMY_MAIN
779 ]AC_LANG_CASE([Fortran], [#ifndef FC_DUMMY_MAIN_EQ_F77])
780 [#  ifdef __cplusplus
781      extern "C"
782 #  endif
783    int ]_AC_FC[_DUMMY_MAIN() { return 1; }
784 ]AC_LANG_CASE([Fortran], [#endif])
785 [#endif
787 AC_CACHE_CHECK([for dummy main to link with _AC_LANG libraries],
788                ac_cv_[]_AC_LANG_ABBREV[]_dummy_main,
789 [ac_[]_AC_LANG_ABBREV[]_dm_save_LIBS=$LIBS
790  LIBS="$LIBS $[]_AC_LANG_PREFIX[]LIBS"
791  ac_fortran_dm_var=[]_AC_FC[]_DUMMY_MAIN
792  AC_LANG_PUSH(C)dnl
794  # First, try linking without a dummy main:
795  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
796                 [ac_cv_fortran_dummy_main=none],
797                 [ac_cv_fortran_dummy_main=unknown])
799  if test $ac_cv_fortran_dummy_main = unknown; then
800    for ac_func in MAIN__ MAIN_ __main MAIN _MAIN __MAIN main_ main__ _main; do
801      AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@define $ac_fortran_dm_var $ac_func]])],
802                     [ac_cv_fortran_dummy_main=$ac_func; break])
803    done
804  fi
805  AC_LANG_POP(C)dnl
806  ac_cv_[]_AC_LANG_ABBREV[]_dummy_main=$ac_cv_fortran_dummy_main
807  rm -f conftest*
808  LIBS=$ac_[]_AC_LANG_ABBREV[]_dm_save_LIBS
810 []_AC_FC[]_DUMMY_MAIN=$ac_cv_[]_AC_LANG_ABBREV[]_dummy_main
811 AS_IF([test "$[]_AC_FC[]_DUMMY_MAIN" != unknown],
812       [m4_default([$1],
813 [if test $[]_AC_FC[]_DUMMY_MAIN != none; then
814   AC_DEFINE_UNQUOTED([]_AC_FC[]_DUMMY_MAIN, $[]_AC_FC[]_DUMMY_MAIN,
815                      [Define to dummy `main' function (if any) required to
816                       link to the Fortran libraries.])
817   if test "x$ac_cv_fc_dummy_main" = "x$ac_cv_f77_dummy_main"; then
818         AC_DEFINE([FC_DUMMY_MAIN_EQ_F77], 1,
819                   [Define if F77 and FC dummy `main' functions are identical.])
820   fi
821 fi])],
822       [m4_default([$2],
823             [AC_MSG_FAILURE([linking to Fortran libraries from C fails])])])
824 ])# _AC_FC_DUMMY_MAIN
827 # AC_F77_DUMMY_MAIN
828 # ----------------------
829 AC_DEFUN([AC_F77_DUMMY_MAIN],
830 [AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
831 AC_LANG_PUSH(Fortran 77)dnl
832 _AC_FC_DUMMY_MAIN($@)
833 AC_LANG_POP(Fortran 77)dnl
834 ])# AC_F77_DUMMY_MAIN
837 # AC_FC_DUMMY_MAIN
838 # ----------------------
839 AC_DEFUN([AC_FC_DUMMY_MAIN],
840 [AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
841 AC_LANG_PUSH(Fortran)dnl
842 _AC_FC_DUMMY_MAIN($@)
843 AC_LANG_POP(Fortran)dnl
844 ])# AC_FC_DUMMY_MAIN
847 # _AC_FC_MAIN
848 # -----------
849 # Define {F77,FC}_MAIN to name of alternate main() function for use with
850 # the Fortran libraries.  (Typically, the libraries may define their
851 # own main() to initialize I/O, etcetera, that then call your own
852 # routine called MAIN__ or whatever.)  See _AC_FC_DUMMY_MAIN, above.
853 # If no such alternate name is found, just define {F77,FC}_MAIN to main.
855 AC_DEFUN([_AC_FC_MAIN],
856 [_AC_FORTRAN_ASSERT()dnl
857 AC_CACHE_CHECK([for alternate main to link with _AC_LANG libraries],
858                ac_cv_[]_AC_LANG_ABBREV[]_main,
859 [ac_[]_AC_LANG_ABBREV[]_m_save_LIBS=$LIBS
860  LIBS="$LIBS $[]_AC_LANG_PREFIX[]LIBS"
861  ac_fortran_dm_var=[]_AC_FC[]_DUMMY_MAIN
862  AC_LANG_PUSH(C)dnl
863  ac_cv_fortran_main="main" # default entry point name
864  for ac_func in MAIN__ MAIN_ __main MAIN _MAIN __MAIN main_ main__ _main; do
865    AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@ifdef FC_DUMMY_MAIN_EQ_F77
866 @%:@  undef F77_DUMMY_MAIN
867 @%:@  undef FC_DUMMY_MAIN
868 @%:@else
869 @%:@  undef $ac_fortran_dm_var
870 @%:@endif
871 @%:@define main $ac_func])],
872                   [ac_cv_fortran_main=$ac_func; break])
873  done
874  AC_LANG_POP(C)dnl
875  ac_cv_[]_AC_LANG_ABBREV[]_main=$ac_cv_fortran_main
876  rm -f conftest*
877  LIBS=$ac_[]_AC_LANG_ABBREV[]_m_save_LIBS
879 AC_DEFINE_UNQUOTED([]_AC_FC[]_MAIN, $ac_cv_[]_AC_LANG_ABBREV[]_main,
880                    [Define to alternate name for `main' routine that is
881                     called from a `main' in the Fortran libraries.])
882 ])# _AC_FC_MAIN
885 # AC_F77_MAIN
886 # -----------
887 AC_DEFUN([AC_F77_MAIN],
888 [AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
889 AC_LANG_PUSH(Fortran 77)dnl
890 _AC_FC_MAIN
891 AC_LANG_POP(Fortran 77)dnl
892 ])# AC_F77_MAIN
895 # AC_FC_MAIN
896 # ----------
897 AC_DEFUN([AC_FC_MAIN],
898 [AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
899 AC_LANG_PUSH(Fortran)dnl
900 _AC_FC_MAIN
901 AC_LANG_POP(Fortran)dnl
902 ])# AC_FC_MAIN
905 # __AC_FC_NAME_MANGLING
906 # ---------------------
907 # Test for the name mangling scheme used by the Fortran compiler.
909 # Sets ac_cv_{f77,fc}_mangling. The value contains three fields, separated
910 # by commas:
912 # lower case / upper case:
913 #    case translation of the Fortran symbols
914 # underscore / no underscore:
915 #    whether the compiler appends "_" to symbol names
916 # extra underscore / no extra underscore:
917 #    whether the compiler appends an extra "_" to symbol names already
918 #    containing at least one underscore
920 AC_DEFUN([__AC_FC_NAME_MANGLING],
921 [_AC_FORTRAN_ASSERT()dnl
922 AC_CACHE_CHECK([for _AC_LANG name-mangling scheme],
923                ac_cv_[]_AC_LANG_ABBREV[]_mangling,
924 [AC_COMPILE_IFELSE(
925 [      subroutine foobar()
926       return
927       end
928       subroutine foo_bar()
929       return
930       end],
931 [mv conftest.$ac_objext cfortran_test.$ac_objext
933   ac_save_LIBS=$LIBS
934   LIBS="cfortran_test.$ac_objext $LIBS $[]_AC_LANG_PREFIX[]LIBS"
936   AC_LANG_PUSH(C)dnl
937   ac_success=no
938   for ac_foobar in foobar FOOBAR; do
939     for ac_underscore in "" "_"; do
940       ac_func="$ac_foobar$ac_underscore"
941       AC_LINK_IFELSE([AC_LANG_CALL([], [$ac_func])],
942                      [ac_success=yes; break 2])
943     done
944   done
945   AC_LANG_POP(C)dnl
947   if test "$ac_success" = "yes"; then
948      case $ac_foobar in
949         foobar)
950            ac_case=lower
951            ac_foo_bar=foo_bar
952            ;;
953         FOOBAR)
954            ac_case=upper
955            ac_foo_bar=FOO_BAR
956            ;;
957      esac
959      AC_LANG_PUSH(C)dnl
960      ac_success_extra=no
961      for ac_extra in "" "_"; do
962         ac_func="$ac_foo_bar$ac_underscore$ac_extra"
963         AC_LINK_IFELSE([AC_LANG_CALL([], [$ac_func])],
964                        [ac_success_extra=yes; break])
965      done
966      AC_LANG_POP(C)dnl
968      if test "$ac_success_extra" = "yes"; then
969         ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_case case"
970         if test -z "$ac_underscore"; then
971            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, no underscore"
972         else
973            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, underscore"
974         fi
975         if test -z "$ac_extra"; then
976            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, no extra underscore"
977         else
978            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, extra underscore"
979         fi
980       else
981         ac_cv_[]_AC_LANG_ABBREV[]_mangling="unknown"
982       fi
983   else
984      ac_cv_[]_AC_LANG_ABBREV[]_mangling="unknown"
985   fi
987   LIBS=$ac_save_LIBS
988   rm -f cfortran_test* conftest*],
989   [AC_MSG_FAILURE([cannot compile a simple Fortran program])])
991 ])# __AC_FC_NAME_MANGLING
993 # The replacement is empty.
994 AU_DEFUN([AC_F77_NAME_MANGLING], [])
997 # _AC_F77_NAME_MANGLING
998 # ----------------------
999 AC_DEFUN([_AC_F77_NAME_MANGLING],
1000 [AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
1001 AC_REQUIRE([AC_F77_DUMMY_MAIN])dnl
1002 AC_LANG_PUSH(Fortran 77)dnl
1003 __AC_FC_NAME_MANGLING
1004 AC_LANG_POP(Fortran 77)dnl
1005 ])# _AC_F77_NAME_MANGLING
1008 # _AC_FC_NAME_MANGLING
1009 # ----------------------
1010 AC_DEFUN([_AC_FC_NAME_MANGLING],
1011 [AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
1012 AC_REQUIRE([AC_FC_DUMMY_MAIN])dnl
1013 AC_LANG_PUSH(Fortran)dnl
1014 __AC_FC_NAME_MANGLING
1015 AC_LANG_POP(Fortran)dnl
1016 ])# _AC_FC_NAME_MANGLING
1019 # _AC_FC_WRAPPERS
1020 # ---------------
1021 # Defines C macros {F77,FC}_FUNC(name,NAME) and {F77,FC}_FUNC_(name,NAME) to
1022 # properly mangle the names of C identifiers, and C identifiers with
1023 # underscores, respectively, so that they match the name mangling
1024 # scheme used by the Fortran compiler.
1025 AC_DEFUN([_AC_FC_WRAPPERS],
1026 [_AC_FORTRAN_ASSERT()dnl
1027 AH_TEMPLATE(_AC_FC[_FUNC],
1028     [Define to a macro mangling the given C identifier (in lower and upper
1029      case), which must not contain underscores, for linking with Fortran.])dnl
1030 AH_TEMPLATE(_AC_FC[_FUNC_],
1031     [As ]_AC_FC[_FUNC, but for C identifiers containing underscores.])dnl
1032 case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in
1033   "lower case, no underscore, no extra underscore")
1034           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name])
1035           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name]) ;;
1036   "lower case, no underscore, extra underscore")
1037           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name])
1038           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name ## _]) ;;
1039   "lower case, underscore, no extra underscore")
1040           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name ## _])
1041           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name ## _]) ;;
1042   "lower case, underscore, extra underscore")
1043           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name ## _])
1044           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name ## __]) ;;
1045   "upper case, no underscore, no extra underscore")
1046           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME])
1047           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME]) ;;
1048   "upper case, no underscore, extra underscore")
1049           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME])
1050           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME ## _]) ;;
1051   "upper case, underscore, no extra underscore")
1052           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME ## _])
1053           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME ## _]) ;;
1054   "upper case, underscore, extra underscore")
1055           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME ## _])
1056           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME ## __]) ;;
1057   *)
1058           AC_MSG_WARN([unknown Fortran name-mangling scheme])
1059           ;;
1060 esac
1061 ])# _AC_FC_WRAPPERS
1064 # AC_F77_WRAPPERS
1065 # ---------------
1066 AC_DEFUN([AC_F77_WRAPPERS],
1067 [AC_REQUIRE([_AC_F77_NAME_MANGLING])dnl
1068 AC_LANG_PUSH(Fortran 77)dnl
1069 _AC_FC_WRAPPERS
1070 AC_LANG_POP(Fortran 77)dnl
1071 ])# AC_F77_WRAPPERS
1074 # AC_FC_WRAPPERS
1075 # --------------
1076 AC_DEFUN([AC_FC_WRAPPERS],
1077 [AC_REQUIRE([_AC_FC_NAME_MANGLING])dnl
1078 AC_LANG_PUSH(Fortran)dnl
1079 _AC_FC_WRAPPERS
1080 AC_LANG_POP(Fortran)dnl
1081 ])# AC_FC_WRAPPERS
1084 # _AC_FC_FUNC(NAME, [SHELLVAR = NAME])
1085 # ------------------------------------
1086 # For a Fortran subroutine of given NAME, define a shell variable
1087 # $SHELLVAR to the Fortran-mangled name.  If the SHELLVAR
1088 # argument is not supplied, it defaults to NAME.
1089 AC_DEFUN([_AC_FC_FUNC],
1090 [_AC_FORTRAN_ASSERT()dnl
1091 case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in
1092   upper*) ac_val="m4_toupper([$1])" ;;
1093   lower*) ac_val="m4_tolower([$1])" ;;
1094   *)      ac_val="unknown" ;;
1095 esac
1096 case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in *," underscore"*) ac_val="$ac_val"_ ;; esac
1097 m4_if(m4_index([$1],[_]),-1,[],
1098 [case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in *," extra underscore"*) ac_val="$ac_val"_ ;; esac
1100 m4_default([$2],[$1])="$ac_val"
1101 ])# _AC_FC_FUNC
1104 # AC_F77_FUNC(NAME, [SHELLVAR = NAME])
1105 # ------------------------------------
1106 AC_DEFUN([AC_F77_FUNC],
1107 [AC_REQUIRE([_AC_F77_NAME_MANGLING])dnl
1108 AC_LANG_PUSH(Fortran 77)dnl
1109 _AC_FC_FUNC([$1],[$2])
1110 AC_LANG_POP(Fortran 77)dnl
1111 ])# AC_F77_FUNC
1114 # AC_FC_FUNC(NAME, [SHELLVAR = NAME])
1115 # -----------------------------------
1116 AC_DEFUN([AC_FC_FUNC],
1117 [AC_REQUIRE([_AC_FC_NAME_MANGLING])dnl
1118 AC_LANG_PUSH(Fortran)dnl
1119 _AC_FC_FUNC([$1],[$2])
1120 AC_LANG_POP(Fortran)dnl
1121 ])# AC_FC_FUNC
1124 # AC_FC_SRCEXT(EXT, [ACTION-IF-SUCCESS], [ACTION-IF-FAILURE])
1125 # -----------------------------------------------------------
1126 # Set the source-code extension used in Fortran (FC) tests to EXT (which
1127 # defaults to f).  Also, look for any necessary additional FCFLAGS needed
1128 # to allow this extension, and store them in the output variable
1129 # FCFLAGS_<EXT> (e.g. FCFLAGS_f90 for EXT=f90).  If successful,
1130 # call ACTION-IF-SUCCESS.  If unable to compile source code with EXT,
1131 # call ACTION-IF-FAILURE, which defaults to failing with an error
1132 # message.
1134 # (The flags for the current source-code extension, if any, are stored in
1135 # $ac_fcflags_srcext and used automatically in subsequent autoconf tests.)
1137 # For ordinary extensions like f90, etcetera, the modified FCFLAGS
1138 # are currently needed for IBM's xlf* and Intel's ifc (grrr).  Unfortunately,
1139 # xlf* will only take flags to recognize one extension at a time, so if the
1140 # user wants to compile multiple extensions (.f90 and .f95, say), she
1141 # will need to use the FCFLAGS_F90 and FCFLAGS_F95 individually rather
1142 # than just adding them all to FCFLAGS, for example.
1144 # Also, for Intel's ifc compiler (which does not accept .f95 by default in
1145 # some versions), the $FCFLAGS_<EXT> variable *must* go immediately before
1146 # the source file on the command line, unlike other $FCFLAGS.  Ugh.
1147 AC_DEFUN([AC_FC_SRCEXT],
1148 [AC_LANG_PUSH(Fortran)dnl
1149 AC_CACHE_CHECK([for Fortran flag to compile .$1 files],
1150                 ac_cv_fc_srcext_$1,
1151 [ac_ext=$1
1152 ac_fcflags_srcext_save=$ac_fcflags_srcext
1153 ac_fcflags_srcext=
1154 ac_cv_fc_srcext_$1=unknown
1155 for ac_flag in none -qsuffix=f=$1 -Tf; do
1156   test "x$ac_flag" != xnone && ac_fcflags_srcext="$ac_flag"
1157   AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [ac_cv_fc_srcext_$1=$ac_flag; break])
1158 done
1159 rm -f conftest.$ac_objext conftest.$1
1160 ac_fcflags_srcext=$ac_fcflags_srcext_save
1162 if test "x$ac_cv_fc_srcext_$1" = xunknown; then
1163   m4_default([$3],[AC_MSG_ERROR([Fortran could not compile .$1 files])])
1164 else
1165   ac_fc_srcext=$1
1166   if test "x$ac_cv_fc_srcext_$1" = xnone; then
1167     ac_fcflags_srcext=""
1168     FCFLAGS_[]$1[]=""
1169   else
1170     ac_fcflags_srcext=$ac_cv_fc_srcext_$1
1171     FCFLAGS_[]$1[]=$ac_cv_fc_srcext_$1
1172   fi
1173   AC_SUBST(FCFLAGS_[]$1)
1174   $2
1176 AC_LANG_POP(Fortran)dnl
1177 ])# AC_FC_SRCEXT
1180 # AC_FC_FREEFORM([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1181 # ------------------------------------------------------------------
1182 # Look for a compiler flag to make the Fortran (FC) compiler accept
1183 # free-format source code, and adds it to FCFLAGS.  Call
1184 # ACTION-IF-SUCCESS (defaults to nothing) if successful (i.e. can
1185 # compile code using new extension) and ACTION-IF-FAILURE (defaults to
1186 # failing with an error message) if not.  (Defined via DEFUN_ONCE to
1187 # prevent flag from being added to FCFLAGS multiple times.)
1189 # The known flags are:
1190 #        -ffree-form: GNU g77
1191 #                -FR: Intel compiler (icc, ecc)
1192 #              -free: Compaq compiler (fort)
1193 #             -qfree: IBM compiler (xlf)
1194 # -Mfree, -Mfreeform: Portland Group compiler
1195 #          -freeform: SGI compiler
1196 #            -f free: Absoft Fortran
1197 # We try to test the "more popular" flags first, by some prejudiced
1198 # notion of popularity.
1199 AC_DEFUN_ONCE([AC_FC_FREEFORM],
1200 [AC_LANG_PUSH(Fortran)dnl
1201 AC_CACHE_CHECK([for Fortran flag needed to allow free-form source],
1202                 ac_cv_fc_freeform,
1203 [ac_cv_fc_freeform=unknown
1204 ac_fc_freeform_FCFLAGS_save=$FCFLAGS
1205 for ac_flag in none -ffree-form -FR -free -qfree -Mfree -Mfreeform \
1206                -freeform "-f free"
1208   test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_freeform_FCFLAGS_save $ac_flag"
1209   AC_COMPILE_IFELSE([
1210   program freeform
1211        ! FIXME: how to best confuse non-freeform compilers?
1212        print *, 'Hello ', &
1213            'world.'
1214        end],
1215                     [ac_cv_fc_freeform=$ac_flag; break])
1216 done
1217 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
1218 FCFLAGS=$ac_fc_freeform_FCFLAGS_save
1220 if test "x$ac_cv_fc_freeform" = xunknown; then
1221   m4_default([$2],
1222              [AC_MSG_ERROR([Fortran does not accept free-form source], 77)])
1223 else
1224   if test "x$ac_cv_fc_freeform" != xnone; then
1225     FCFLAGS="$FCFLAGS $ac_cv_fc_freeform"
1226   fi
1227   $1
1229 AC_LANG_POP(Fortran)dnl
1230 ])# AC_FC_FREEFORM