Update to GPLv3.
[autoconf.git] / lib / autoconf / fortran.m4
blob8624526b8235e069d0d53bf0e29ec26e521385f6
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 3, 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.
53 # Table of Contents:
55 # Preamble
57 # 0. Utility macros
59 # 1. Language selection
60 #    and routines to produce programs in a given language.
62 # 2. Producing programs in a given language.
64 # 3. Looking for a compiler
65 #    And possibly the associated preprocessor.
67 # 4. Compilers' characteristics.
71 ## ---------- ##
72 ## Preamble.  ##
73 ## ---------- ##
75 # Fortran vs. Fortran 77:
76 #   This file contains macros for both "Fortran 77" and "Fortran", where
77 # the former is the "classic" autoconf Fortran interface and is intended
78 # for legacy F77 codes, while the latter is intended to support newer Fortran
79 # dialects.  Fortran 77 uses environment variables F77, FFLAGS, and FLIBS,
80 # while Fortran uses FC, FCFLAGS, and FCLIBS.  For each user-callable AC_*
81 # macro, there is generally both an F77 and an FC version, where both versions
82 # share the same _AC_*_FC_* backend.  This backend macro requires that
83 # the appropriate language be AC_LANG_PUSH'ed, and uses _AC_LANG_ABBREV and
84 # _AC_LANG_PREFIX in order to name cache and environment variables, etc.
88 ## ------------------- ##
89 ## 0. Utility macros.  ##
90 ## ------------------- ##
93 # _AC_LIST_MEMBER_IF(ELEMENT, LIST, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
94 # ---------------------------------------------------------------------------
96 # Processing the elements of a list is tedious in shell programming,
97 # as lists tend to be implemented as space delimited strings.
99 # This macro searches LIST for ELEMENT, and executes ACTION-IF-FOUND
100 # if ELEMENT is a member of LIST, otherwise it executes
101 # ACTION-IF-NOT-FOUND.
102 AC_DEFUN([_AC_LIST_MEMBER_IF],
103 [dnl Do some sanity checking of the arguments.
104 m4_if([$1], , [AC_FATAL([$0: missing argument 1])])dnl
105 m4_if([$2], , [AC_FATAL([$0: missing argument 2])])dnl
106   ac_exists=false
107   for ac_i in $2; do
108     if test x"$1" = x"$ac_i"; then
109       ac_exists=true
110       break
111     fi
112   done
114   AS_IF([test x"$ac_exists" = xtrue], [$3], [$4])[]dnl
115 ])# _AC_LIST_MEMBER_IF
118 # _AC_LINKER_OPTION(LINKER-OPTIONS, SHELL-VARIABLE)
119 # -------------------------------------------------
121 # Specifying options to the compiler (whether it be the C, C++ or
122 # Fortran 77 compiler) that are meant for the linker is compiler
123 # dependent.  This macro lets you give options to the compiler that
124 # are meant for the linker in a portable, compiler-independent way.
126 # This macro take two arguments, a list of linker options that the
127 # compiler should pass to the linker (LINKER-OPTIONS) and the name of
128 # a shell variable (SHELL-VARIABLE).  The list of linker options are
129 # appended to the shell variable in a compiler-dependent way.
131 # For example, if the selected language is C, then this:
133 #   _AC_LINKER_OPTION([-R /usr/local/lib/foo], foo_LDFLAGS)
135 # will expand into this if the selected C compiler is gcc:
137 #   foo_LDFLAGS="-Xlinker -R -Xlinker /usr/local/lib/foo"
139 # otherwise, it will expand into this:
141 #   foo_LDFLAGS"-R /usr/local/lib/foo"
143 # You are encouraged to add support for compilers that this macro
144 # doesn't currently support.
145 # FIXME: Get rid of this macro.
146 AC_DEFUN([_AC_LINKER_OPTION],
147 [if test "$ac_compiler_gnu" = yes; then
148   for ac_link_opt in $1; do
149     $2="[$]$2 -Xlinker $ac_link_opt"
150   done
151 else
152   $2="[$]$2 $1"
153 fi[]dnl
154 ])# _AC_LINKER_OPTION
158 ## ----------------------- ##
159 ## 1. Language selection.  ##
160 ## ----------------------- ##
163 # AC_LANG(Fortran 77)
164 # -------------------
165 m4_define([AC_LANG(Fortran 77)],
166 [ac_ext=f
167 ac_compile='$F77 -c $FFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
168 ac_link='$F77 -o conftest$ac_exeext $FFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
169 ac_compiler_gnu=$ac_cv_f77_compiler_gnu
173 # AC_LANG(Fortran)
174 # ----------------
175 m4_define([AC_LANG(Fortran)],
176 [ac_ext=${ac_fc_srcext-f}
177 ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
178 ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
179 ac_compiler_gnu=$ac_cv_fc_compiler_gnu
182 # AC_LANG_FORTRAN77
183 # -----------------
184 AU_DEFUN([AC_LANG_FORTRAN77], [AC_LANG(Fortran 77)])
187 # _AC_FORTRAN_ASSERT
188 # ------------------
189 # Current language must be Fortran or Fortran 77.
190 m4_defun([_AC_FORTRAN_ASSERT],
191 [m4_if(_AC_LANG, [Fortran], [],
192        [m4_if(_AC_LANG, [Fortran 77], [],
193               [m4_fatal([$0: current language is not Fortran: ] _AC_LANG)])])])
196 # _AC_LANG_ABBREV(Fortran 77)
197 # ---------------------------
198 m4_define([_AC_LANG_ABBREV(Fortran 77)], [f77])
200 # _AC_LANG_ABBREV(Fortran)
201 # ------------------------
202 m4_define([_AC_LANG_ABBREV(Fortran)], [fc])
205 # _AC_LANG_PREFIX(Fortran 77)
206 # ---------------------------
207 m4_define([_AC_LANG_PREFIX(Fortran 77)], [F])
209 # _AC_LANG_PREFIX(Fortran)
210 # ------------------------
211 m4_define([_AC_LANG_PREFIX(Fortran)], [FC])
214 # _AC_FC
215 # ------
216 # Return F77 or FC, depending upon the language.
217 AC_DEFUN([_AC_FC],
218 [_AC_FORTRAN_ASSERT()dnl
219 AC_LANG_CASE([Fortran 77], [F77],
220              [Fortran],    [FC])])
224 ## ----------------------- ##
225 ## 2. Producing programs.  ##
226 ## ----------------------- ##
229 # AC_LANG_SOURCE(Fortran 77)(BODY)
230 # AC_LANG_SOURCE(Fortran)(BODY)
231 # --------------------------------
232 # FIXME: Apparently, according to former AC_TRY_COMPILER, the CPP
233 # directives must not be included.  But AC_TRY_RUN_NATIVE was not
234 # avoiding them, so?
235 m4_define([AC_LANG_SOURCE(Fortran 77)],
236 [$1])
237 m4_define([AC_LANG_SOURCE(Fortran)],
238 [$1])
241 # AC_LANG_PROGRAM(Fortran 77)([PROLOGUE], [BODY])
242 # -----------------------------------------------
243 # Yes, we discard the PROLOGUE.
244 m4_define([AC_LANG_PROGRAM(Fortran 77)],
245 [m4_ifval([$1],
246        [m4_warn([syntax], [$0: ignoring PROLOGUE: $1])])dnl
247       program main
249       end])
252 # AC_LANG_PROGRAM(Fortran)([PROLOGUE], [BODY])
253 # -----------------------------------------------
254 # FIXME: can the PROLOGUE be used?
255 m4_define([AC_LANG_PROGRAM(Fortran)],
256 [m4_ifval([$1],
257        [m4_warn([syntax], [$0: ignoring PROLOGUE: $1])])dnl
258       program main
260       end])
263 # AC_LANG_CALL(Fortran 77)(PROLOGUE, FUNCTION)
264 # --------------------------------------------
265 # FIXME: This is a guess, help!
266 m4_define([AC_LANG_CALL(Fortran 77)],
267 [AC_LANG_PROGRAM([$1],
268 [      call $2])])
271 # AC_LANG_CALL(Fortran)(PROLOGUE, FUNCTION)
272 # --------------------------------------------
273 # FIXME: This is a guess, help!
274 m4_define([AC_LANG_CALL(Fortran)],
275 [AC_LANG_PROGRAM([$1],
276 [      call $2])])
280 ## -------------------------------------------- ##
281 ## 3. Looking for Compilers and Preprocessors.  ##
282 ## -------------------------------------------- ##
285 # AC_LANG_PREPROC(Fortran 77)
286 # ---------------------------
287 # Find the Fortran 77 preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
288 AC_DEFUN([AC_LANG_PREPROC(Fortran 77)],
289 [m4_warn([syntax],
290          [$0: No preprocessor defined for ]_AC_LANG)])
292 # AC_LANG_PREPROC(Fortran)
293 # ---------------------------
294 # Find the Fortran preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
295 AC_DEFUN([AC_LANG_PREPROC(Fortran)],
296 [m4_warn([syntax],
297          [$0: No preprocessor defined for ]_AC_LANG)])
300 # AC_LANG_COMPILER(Fortran 77)
301 # ----------------------------
302 # Find the Fortran 77 compiler.  Must be AC_DEFUN'd to be
303 # AC_REQUIRE'able.
304 AC_DEFUN([AC_LANG_COMPILER(Fortran 77)],
305 [AC_REQUIRE([AC_PROG_F77])])
307 # AC_LANG_COMPILER(Fortran)
308 # ----------------------------
309 # Find the Fortran compiler.  Must be AC_DEFUN'd to be
310 # AC_REQUIRE'able.
311 AC_DEFUN([AC_LANG_COMPILER(Fortran)],
312 [AC_REQUIRE([AC_PROG_FC])])
315 # ac_cv_prog_g77
316 # --------------
317 # We used to name the cache variable this way.
318 AU_DEFUN([ac_cv_prog_g77],
319 [ac_cv_f77_compiler_gnu])
322 # _AC_FC_DIALECT_YEAR([DIALECT])
323 # ------------------------------
324 # Given a Fortran DIALECT, which is Fortran [YY]YY or simply [YY]YY,
325 # convert to a 4-digit year.  The dialect must be one of Fortran 77,
326 # 90, 95, or 2000, currently.  If DIALECT is simply Fortran or the
327 # empty string, returns the empty string.
328 AC_DEFUN([_AC_FC_DIALECT_YEAR],
329 [m4_case(m4_bpatsubsts(m4_tolower([$1]), [fortran],[], [ *],[]),
330          [77],[1977], [1977],[1977],
331          [90],[1990], [1990],[1990],
332          [95],[1995], [1995],[1995],
333          [2000],[2000],
334          [],[],
335          [m4_fatal([unknown Fortran dialect])])])
338 # _AC_PROG_FC([DIALECT], [COMPILERS...])
339 # --------------------------------------
340 # DIALECT is a Fortran dialect, given by Fortran [YY]YY or simply [YY]YY,
341 # and must be one of those supported by _AC_FC_DIALECT_YEAR
343 # If DIALECT is supplied, then we search for compilers of that dialect
344 # first, and then later dialects.  Otherwise, we search for compilers
345 # of the newest dialect first, and then earlier dialects in increasing age.
346 # This search order is necessarily imperfect because the dialect cannot
347 # always be inferred from the compiler name.
349 # Known compilers:
350 #  f77/f90/f95: generic compiler names
351 #  g77: GNU Fortran 77 compiler
352 #  gfortran: GNU Fortran 95+ compiler (released in gcc 4.0)
353 #  g95: original gcc-based f95 compiler (gfortran is a fork)
354 #  ftn: native Fortran 95 compiler on Cray X1
355 #  cf77: native F77 compiler under older Crays (prefer over fort77)
356 #  fort77: native F77 compiler under HP-UX (and some older Crays)
357 #  frt: Fujitsu F77 compiler
358 #  pgf77/pgf90/pghpf/pgf95: Portland Group F77/F90/F95 compilers
359 #  xlf/xlf90/xlf95: IBM (AIX) F77/F90/F95 compilers
360 #    Prefer xlf9x to the generic names because they do not reject file
361 #    with extension `.f'.
362 #  lf95: Lahey-Fujitsu F95 compiler
363 #  fl32: Microsoft Fortran 77 "PowerStation" compiler
364 #  af77: Apogee F77 compiler for Intergraph hardware running CLIX
365 #  epcf90: "Edinburgh Portable Compiler" F90
366 #  fort: Compaq (now HP) Fortran 90/95 compiler for Tru64 and Linux/Alpha
367 #  ifort, previously ifc: Intel Fortran 95 compiler for Linux/x86
368 #  efc: Intel Fortran 95 compiler for IA64
369 m4_define([_AC_F95_FC], [gfortran g95 xlf95 f95 fort ifort ifc efc pgf95 lf95 ftn])
370 m4_define([_AC_F90_FC], [xlf90 f90 pgf90 pghpf epcf90])
371 m4_define([_AC_F77_FC], [g77 xlf f77 frt pgf77 cf77 fort77 fl32 af77])
372 AC_DEFUN([_AC_PROG_FC],
373 [_AC_FORTRAN_ASSERT()dnl
374 AC_CHECK_TOOLS([]_AC_FC[],
375       m4_default([$2],
376         m4_case(_AC_FC_DIALECT_YEAR([$1]),
377                 [1995], [_AC_F95_FC],
378                 [1990], [_AC_F90_FC _AC_F95_FC],
379                 [1977], [_AC_F77_FC _AC_F90_FC _AC_F95_FC],
380                 [_AC_F95_FC _AC_F90_FC _AC_F77_FC])))
382 # Provide some information about the compiler.
383 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
384 set X $ac_compile
385 ac_compiler=$[2]
386 _AC_DO([$ac_compiler --version >&AS_MESSAGE_LOG_FD])
387 _AC_DO([$ac_compiler -v >&AS_MESSAGE_LOG_FD])
388 _AC_DO([$ac_compiler -V >&AS_MESSAGE_LOG_FD])
389 rm -f a.out
391 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
392 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
393 # If we don't use `.F' as extension, the preprocessor is not run on the
394 # input file.  (Note that this only needs to work for GNU compilers.)
395 ac_save_ext=$ac_ext
396 ac_ext=F
397 _AC_LANG_COMPILER_GNU
398 ac_ext=$ac_save_ext
399 _AC_PROG_FC_G
400 ])# _AC_PROG_FC
403 # AC_PROG_F77([COMPILERS...])
404 # ---------------------------
405 # COMPILERS is a space separated list of Fortran 77 compilers to search
406 # for.  See also _AC_PROG_FC.
407 AC_DEFUN([AC_PROG_F77],
408 [AC_LANG_PUSH(Fortran 77)dnl
409 AC_ARG_VAR([F77],    [Fortran 77 compiler command])dnl
410 AC_ARG_VAR([FFLAGS], [Fortran 77 compiler flags])dnl
411 _AC_ARG_VAR_LDFLAGS()dnl
412 _AC_ARG_VAR_LIBS()dnl
413 _AC_PROG_FC([Fortran 77], [$1])
414 if test $ac_compiler_gnu = yes; then
415   G77=yes
416 else
417   G77=
419 AC_LANG_POP(Fortran 77)dnl
420 ])# AC_PROG_F77
423 # AC_PROG_FC([COMPILERS...], [DIALECT])
424 # -------------------------------------
425 # COMPILERS is a space separated list of Fortran 77 compilers to search
426 # for, and [DIALECT] is an optional dialect.  See also _AC_PROG_FC.
427 AC_DEFUN([AC_PROG_FC],
428 [AC_LANG_PUSH(Fortran)dnl
429 AC_ARG_VAR([FC],    [Fortran compiler command])dnl
430 AC_ARG_VAR([FCFLAGS], [Fortran compiler flags])dnl
431 _AC_ARG_VAR_LDFLAGS()dnl
432 _AC_ARG_VAR_LIBS()dnl
433 _AC_PROG_FC([$2], [$1])
434 AC_LANG_POP(Fortran)dnl
435 ])# AC_PROG_FC
438 # _AC_PROG_FC_G
439 # -------------
440 # Check whether -g works, even if F[C]FLAGS is set, in case the package
441 # plays around with F[C]FLAGS (such as to build both debugging and normal
442 # versions of a library), tasteless as that idea is.
443 m4_define([_AC_PROG_FC_G],
444 [_AC_FORTRAN_ASSERT()dnl
445 ac_test_FFLAGS=${[]_AC_LANG_PREFIX[]FLAGS+set}
446 ac_save_FFLAGS=$[]_AC_LANG_PREFIX[]FLAGS
447 _AC_LANG_PREFIX[]FLAGS=
448 AC_CACHE_CHECK(whether $[]_AC_FC[] accepts -g, ac_cv_prog_[]_AC_LANG_ABBREV[]_g,
449 [_AC_LANG_PREFIX[]FLAGS=-g
450 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
451 [ac_cv_prog_[]_AC_LANG_ABBREV[]_g=yes],
452 [ac_cv_prog_[]_AC_LANG_ABBREV[]_g=no])
454 if test "$ac_test_FFLAGS" = set; then
455   _AC_LANG_PREFIX[]FLAGS=$ac_save_FFLAGS
456 elif test $ac_cv_prog_[]_AC_LANG_ABBREV[]_g = yes; then
457   if test "x$ac_cv_[]_AC_LANG_ABBREV[]_compiler_gnu" = xyes; then
458     _AC_LANG_PREFIX[]FLAGS="-g -O2"
459   else
460     _AC_LANG_PREFIX[]FLAGS="-g"
461   fi
462 else
463   if test "x$ac_cv_[]_AC_LANG_ABBREV[]_compiler_gnu" = xyes; then
464     _AC_LANG_PREFIX[]FLAGS="-O2"
465   else
466     _AC_LANG_PREFIX[]FLAGS=
467   fi
468 fi[]dnl
469 ])# _AC_PROG_FC_G
472 # _AC_PROG_FC_C_O
473 # ---------------
474 # Test if the Fortran compiler accepts the options `-c' and `-o'
475 # simultaneously, and define `[F77/FC]_NO_MINUS_C_MINUS_O' if it does not.
477 # The usefulness of this macro is questionable, as I can't really see
478 # why anyone would use it.  The only reason I include it is for
479 # completeness, since a similar test exists for the C compiler.
481 # FIXME: it seems like we could merge the C/C++/Fortran versions of this.
482 AC_DEFUN([_AC_PROG_FC_C_O],
483 [_AC_FORTRAN_ASSERT()dnl
484 AC_CACHE_CHECK([whether $[]_AC_FC[] understands -c and -o together],
485                [ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o],
486 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
487 # We test twice because some compilers refuse to overwrite an existing
488 # `.o' file with `-o', although they will create one.
489 ac_try='$[]_AC_FC[] $[]_AC_LANG_PREFIX[]FLAGS -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
490 rm -f conftest2.*
491 if _AC_DO_VAR(ac_try) &&
492      test -f conftest2.$ac_objext &&
493      _AC_DO_VAR(ac_try); then
494   ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o=yes
495 else
496   ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o=no
498 rm -f conftest*])
499 if test $ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o = no; then
500   AC_DEFINE([]_AC_FC[]_NO_MINUS_C_MINUS_O, 1,
501             [Define to 1 if your Fortran compiler doesn't accept
502              -c and -o together.])
504 ])# _AC_PROG_FC_C_O
507 # AC_PROG_F77_C_O
508 # ---------------
509 AC_DEFUN([AC_PROG_F77_C_O],
510 [AC_REQUIRE([AC_PROG_F77])dnl
511 AC_LANG_PUSH(Fortran 77)dnl
512 _AC_PROG_FC_C_O
513 AC_LANG_POP(Fortran 77)dnl
514 ])# AC_PROG_F77_C_O
517 # AC_PROG_FC_C_O
518 # ---------------
519 AC_DEFUN([AC_PROG_FC_C_O],
520 [AC_REQUIRE([AC_PROG_FC])dnl
521 AC_LANG_PUSH(Fortran)dnl
522 _AC_PROG_FC_C_O
523 AC_LANG_POP(Fortran)dnl
524 ])# AC_PROG_FC_C_O
528 ## ------------------------------- ##
529 ## 4. Compilers' characteristics.  ##
530 ## ------------------------------- ##
533 # _AC_PROG_FC_V_OUTPUT([FLAG = $ac_cv_prog_{f77/fc}_v])
534 # -------------------------------------------------
535 # Link a trivial Fortran program, compiling with a verbose output FLAG
536 # (whose default value, $ac_cv_prog_{f77/fc}_v, is computed by
537 # _AC_PROG_FC_V), and return the output in $ac_{f77/fc}_v_output.  This
538 # output is processed in the way expected by _AC_FC_LIBRARY_LDFLAGS,
539 # so that any link flags that are echoed by the compiler appear as
540 # space-separated items.
541 AC_DEFUN([_AC_PROG_FC_V_OUTPUT],
542 [_AC_FORTRAN_ASSERT()dnl
543 AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
545 # Compile and link our simple test program by passing a flag (argument
546 # 1 to this macro) to the Fortran compiler in order to get
547 # "verbose" output that we can then parse for the Fortran linker
548 # flags.
549 ac_save_FFLAGS=$[]_AC_LANG_PREFIX[]FLAGS
550 _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS m4_default([$1], [$ac_cv_prog_[]_AC_LANG_ABBREV[]_v])"
551 eval "set x $ac_link"
552 shift
553 _AS_ECHO_LOG([$[*]])
554 ac_[]_AC_LANG_ABBREV[]_v_output=`eval $ac_link AS_MESSAGE_LOG_FD>&1 2>&1 | grep -v 'Driving:'`
555 AS_ECHO(["$ac_[]_AC_LANG_ABBREV[]_v_output"]) >&AS_MESSAGE_LOG_FD
556 _AC_LANG_PREFIX[]FLAGS=$ac_save_FFLAGS
558 rm -f conftest*
560 # On HP/UX there is a line like: "LPATH is: /foo:/bar:/baz" where
561 # /foo, /bar, and /baz are search directories for the Fortran linker.
562 # Here, we change these into -L/foo -L/bar -L/baz (and put it first):
563 ac_[]_AC_LANG_ABBREV[]_v_output="`echo $ac_[]_AC_LANG_ABBREV[]_v_output |
564         grep 'LPATH is:' |
565         sed 's,.*LPATH is\(: *[[^ ]]*\).*,\1,;s,: */, -L/,g'` $ac_[]_AC_LANG_ABBREV[]_v_output"
567 # FIXME: we keep getting bitten by quoted arguments; a more general fix
568 #        that detects unbalanced quotes in FLIBS should be implemented
569 #        and (ugh) tested at some point.
570 case $ac_[]_AC_LANG_ABBREV[]_v_output in
571   # If we are using xlf then replace all the commas with spaces.
572   *xlfentry*)
573     ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed 's/,/ /g'` ;;
575   # With Intel ifc, ignore the quoted -mGLOB_options_string stuff (quoted
576   # $LIBS confuse us, and the libraries appear later in the output anyway).
577   *mGLOB_options_string*)
578     ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed 's/"-mGLOB[[^"]]*"/ /g'` ;;
580   # Portland Group compiler has singly- or doubly-quoted -cmdline argument
581   # Singly-quoted arguments were reported for versions 5.2-4 and 6.0-4.
582   # Doubly-quoted arguments were reported for "PGF90/x86 Linux/x86 5.0-2".
583   *-cmdline\ * | *-ignore\ * | *-def\ *)
584     ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed "\
585         s/-cmdline  *'[[^']]*'/ /g; s/-cmdline  *\"[[^\"]]*\"/ /g
586         s/-ignore  *'[[^']]*'/ /g; s/-ignore  *\"[[^\"]]*\"/ /g
587         s/-def  *'[[^']]*'/ /g; s/-def  *\"[[^\"]]*\"/ /g"` ;;
589   # If we are using Cray Fortran then delete quotes.
590   *cft90*)
591     ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed 's/"//g'` ;;
592 esac
594 ])# _AC_PROG_FC_V_OUTPUT
597 # _AC_PROG_FC_V
598 # --------------
600 # Determine the flag that causes the Fortran compiler to print
601 # information of library and object files (normally -v)
602 # Needed for _AC_FC_LIBRARY_FLAGS
603 # Some compilers don't accept -v (Lahey: -verbose, xlf: -V, Fujitsu: -###)
604 AC_DEFUN([_AC_PROG_FC_V],
605 [_AC_FORTRAN_ASSERT()dnl
606 AC_CACHE_CHECK([how to get verbose linking output from $[]_AC_FC[]],
607                 [ac_cv_prog_[]_AC_LANG_ABBREV[]_v],
608 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
609 [ac_cv_prog_[]_AC_LANG_ABBREV[]_v=
610 # Try some options frequently used verbose output
611 for ac_verb in -v -verbose --verbose -V -\#\#\#; do
612   _AC_PROG_FC_V_OUTPUT($ac_verb)
613   # look for -l* and *.a constructs in the output
614   for ac_arg in $ac_[]_AC_LANG_ABBREV[]_v_output; do
615      case $ac_arg in
616         [[\\/]]*.a | ?:[[\\/]]*.a | -[[lLRu]]*)
617           ac_cv_prog_[]_AC_LANG_ABBREV[]_v=$ac_verb
618           break 2 ;;
619      esac
620   done
621 done
622 if test -z "$ac_cv_prog_[]_AC_LANG_ABBREV[]_v"; then
623    AC_MSG_WARN([cannot determine how to obtain linking information from $[]_AC_FC[]])
624 fi],
625                   [AC_MSG_WARN([compilation failed])])
626 ])])# _AC_PROG_FC_V
629 # _AC_FC_LIBRARY_LDFLAGS
630 # ----------------------
632 # Determine the linker flags (e.g. "-L" and "-l") for the Fortran
633 # intrinsic and runtime libraries that are required to successfully
634 # link a Fortran program or shared library.  The output variable
635 # FLIBS/FCLIBS is set to these flags.
637 # This macro is intended to be used in those situations when it is
638 # necessary to mix, e.g. C++ and Fortran, source code into a single
639 # program or shared library.
641 # For example, if object files from a C++ and Fortran compiler must
642 # be linked together, then the C++ compiler/linker must be used for
643 # linking (since special C++-ish things need to happen at link time
644 # like calling global constructors, instantiating templates, enabling
645 # exception support, etc.).
647 # However, the Fortran intrinsic and runtime libraries must be
648 # linked in as well, but the C++ compiler/linker doesn't know how to
649 # add these Fortran libraries.  Hence, the macro
650 # "AC_F77_LIBRARY_LDFLAGS" was created to determine these Fortran
651 # libraries.
653 # This macro was packaged in its current form by Matthew D. Langston.
654 # However, nearly all of this macro came from the "OCTAVE_FLIBS" macro
655 # in "octave-2.0.13/aclocal.m4", and full credit should go to John
656 # W. Eaton for writing this extremely useful macro.  Thank you John.
657 AC_DEFUN([_AC_FC_LIBRARY_LDFLAGS],
658 [_AC_FORTRAN_ASSERT()dnl
659 _AC_PROG_FC_V
660 AC_CACHE_CHECK([for _AC_LANG libraries of $[]_AC_FC[]], ac_cv_[]_AC_LANG_ABBREV[]_libs,
661 [if test "x$[]_AC_LANG_PREFIX[]LIBS" != "x"; then
662   ac_cv_[]_AC_LANG_ABBREV[]_libs="$[]_AC_LANG_PREFIX[]LIBS" # Let the user override the test.
663 else
665 _AC_PROG_FC_V_OUTPUT
667 ac_cv_[]_AC_LANG_ABBREV[]_libs=
669 # Save positional arguments (if any)
670 ac_save_positional="$[@]"
672 set X $ac_[]_AC_LANG_ABBREV[]_v_output
673 while test $[@%:@] != 1; do
674   shift
675   ac_arg=$[1]
676   case $ac_arg in
677         [[\\/]]*.a | ?:[[\\/]]*.a)
678           _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
679               ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg")
680           ;;
681         -bI:*)
682           _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
683              [_AC_LINKER_OPTION([$ac_arg], ac_cv_[]_AC_LANG_ABBREV[]_libs)])
684           ;;
685           # Ignore these flags.
686         -lang* | -lcrt*.o | -lc | -lgcc* | -lSystem | -libmil | -LANG:=* | -LIST:* | -LNO:*)
687           ;;
688         -lkernel32)
689           test x"$CYGWIN" != xyes && ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg"
690           ;;
691         -[[LRuYz]])
692           # These flags, when seen by themselves, take an argument.
693           # We remove the space between option and argument and re-iterate
694           # unless we find an empty arg or a new option (starting with -)
695           case $[2] in
696              "" | -*);;
697              *)
698                 ac_arg="$ac_arg$[2]"
699                 shift; shift
700                 set X $ac_arg "$[@]"
701                 ;;
702           esac
703           ;;
704         -YP,*)
705           for ac_j in `AS_ECHO(["$ac_arg"]) | sed -e 's/-YP,/-L/;s/:/ -L/g'`; do
706             _AC_LIST_MEMBER_IF($ac_j, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
707                                [ac_arg="$ac_arg $ac_j"
708                                ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_j"])
709           done
710           ;;
711         -[[lLR]]*)
712           _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
713                              ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg")
714           ;;
715         -zallextract*| -zdefaultextract)
716           ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg"
717           ;;
718           # Ignore everything else.
719   esac
720 done
721 # restore positional arguments
722 set X $ac_save_positional; shift
724 # We only consider "LD_RUN_PATH" on Solaris systems.  If this is seen,
725 # then we insist that the "run path" must be an absolute path (i.e. it
726 # must begin with a "/").
727 case `(uname -sr) 2>/dev/null` in
728    "SunOS 5"*)
729       ac_ld_run_path=`AS_ECHO(["$ac_[]_AC_LANG_ABBREV[]_v_output"]) |
730                         sed -n 's,^.*LD_RUN_PATH *= *\(/[[^ ]]*\).*$,-R\1,p'`
731       test "x$ac_ld_run_path" != x &&
732         _AC_LINKER_OPTION([$ac_ld_run_path], ac_cv_[]_AC_LANG_ABBREV[]_libs)
733       ;;
734 esac
735 fi # test "x$[]_AC_LANG_PREFIX[]LIBS" = "x"
737 []_AC_LANG_PREFIX[]LIBS="$ac_cv_[]_AC_LANG_ABBREV[]_libs"
738 AC_SUBST([]_AC_LANG_PREFIX[]LIBS)
739 ])# _AC_FC_LIBRARY_LDFLAGS
742 # AC_F77_LIBRARY_LDFLAGS
743 # ----------------------
744 AC_DEFUN([AC_F77_LIBRARY_LDFLAGS],
745 [AC_REQUIRE([AC_PROG_F77])dnl
746 AC_LANG_PUSH(Fortran 77)dnl
747 _AC_FC_LIBRARY_LDFLAGS
748 AC_LANG_POP(Fortran 77)dnl
749 ])# AC_F77_LIBRARY_LDFLAGS
752 # AC_FC_LIBRARY_LDFLAGS
753 # ----------------------
754 AC_DEFUN([AC_FC_LIBRARY_LDFLAGS],
755 [AC_REQUIRE([AC_PROG_FC])dnl
756 AC_LANG_PUSH(Fortran)dnl
757 _AC_FC_LIBRARY_LDFLAGS
758 AC_LANG_POP(Fortran)dnl
759 ])# AC_FC_LIBRARY_LDFLAGS
762 # _AC_FC_DUMMY_MAIN([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
763 # -----------------------------------------------------------
765 # Detect name of dummy main routine required by the Fortran libraries,
766 # (if any) and define {F77,FC}_DUMMY_MAIN to this name (which should be
767 # used for a dummy declaration, if it is defined).  On some systems,
768 # linking a C program to the Fortran library does not work unless you
769 # supply a dummy function called something like MAIN__.
771 # Execute ACTION-IF-NOT-FOUND if no way of successfully linking a C
772 # program with the {F77,FC} libs is found; default to exiting with an error
773 # message.  Execute ACTION-IF-FOUND if a dummy routine name is needed
774 # and found or if it is not needed (default to defining {F77,FC}_DUMMY_MAIN
775 # when needed).
777 # What is technically happening is that the Fortran libraries provide
778 # their own main() function, which usually initializes Fortran I/O and
779 # similar stuff, and then calls MAIN__, which is the entry point of
780 # your program.  Usually, a C program will override this with its own
781 # main() routine, but the linker sometimes complain if you don't
782 # provide a dummy (never-called) MAIN__ routine anyway.
784 # Of course, programs that want to allow Fortran subroutines to do
785 # I/O, etcetera, should call their main routine MAIN__() (or whatever)
786 # instead of main().  A separate autoconf test (_AC_FC_MAIN) checks
787 # for the routine to use in this case (since the semantics of the test
788 # are slightly different).  To link to e.g. purely numerical
789 # libraries, this is normally not necessary, however, and most C/C++
790 # programs are reluctant to turn over so much control to Fortran.  =)
792 # The name variants we check for are (in order):
793 #   MAIN__ (g77, MAIN__ required on some systems; IRIX, MAIN__ optional)
794 #   MAIN_, __main (SunOS)
795 #   MAIN _MAIN __MAIN main_ main__ _main (we follow DDD and try these too)
796 AC_DEFUN([_AC_FC_DUMMY_MAIN],
797 [_AC_FORTRAN_ASSERT()dnl
798 m4_define(_AC_LANG_PROGRAM_C_[]_AC_FC[]_HOOKS,
799 [#ifdef ]_AC_FC[_DUMMY_MAIN
800 ]AC_LANG_CASE([Fortran], [#ifndef FC_DUMMY_MAIN_EQ_F77])
801 [#  ifdef __cplusplus
802      extern "C"
803 #  endif
804    int ]_AC_FC[_DUMMY_MAIN() { return 1; }
805 ]AC_LANG_CASE([Fortran], [#endif])
806 [#endif
808 AC_CACHE_CHECK([for dummy main to link with _AC_LANG libraries],
809                ac_cv_[]_AC_LANG_ABBREV[]_dummy_main,
810 [ac_[]_AC_LANG_ABBREV[]_dm_save_LIBS=$LIBS
811  LIBS="$LIBS $[]_AC_LANG_PREFIX[]LIBS"
812  ac_fortran_dm_var=[]_AC_FC[]_DUMMY_MAIN
813  AC_LANG_PUSH(C)dnl
815  # First, try linking without a dummy main:
816  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
817                 [ac_cv_fortran_dummy_main=none],
818                 [ac_cv_fortran_dummy_main=unknown])
820  if test $ac_cv_fortran_dummy_main = unknown; then
821    for ac_func in MAIN__ MAIN_ __main MAIN _MAIN __MAIN main_ main__ _main; do
822      AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@define $ac_fortran_dm_var $ac_func]])],
823                     [ac_cv_fortran_dummy_main=$ac_func; break])
824    done
825  fi
826  AC_LANG_POP(C)dnl
827  ac_cv_[]_AC_LANG_ABBREV[]_dummy_main=$ac_cv_fortran_dummy_main
828  rm -f conftest*
829  LIBS=$ac_[]_AC_LANG_ABBREV[]_dm_save_LIBS
831 []_AC_FC[]_DUMMY_MAIN=$ac_cv_[]_AC_LANG_ABBREV[]_dummy_main
832 AS_IF([test "$[]_AC_FC[]_DUMMY_MAIN" != unknown],
833       [m4_default([$1],
834 [if test $[]_AC_FC[]_DUMMY_MAIN != none; then
835   AC_DEFINE_UNQUOTED([]_AC_FC[]_DUMMY_MAIN, $[]_AC_FC[]_DUMMY_MAIN,
836                      [Define to dummy `main' function (if any) required to
837                       link to the Fortran libraries.])
838   if test "x$ac_cv_fc_dummy_main" = "x$ac_cv_f77_dummy_main"; then
839         AC_DEFINE([FC_DUMMY_MAIN_EQ_F77], 1,
840                   [Define if F77 and FC dummy `main' functions are identical.])
841   fi
842 fi])],
843       [m4_default([$2],
844             [AC_MSG_FAILURE([linking to Fortran libraries from C fails])])])
845 ])# _AC_FC_DUMMY_MAIN
848 # AC_F77_DUMMY_MAIN
849 # ----------------------
850 AC_DEFUN([AC_F77_DUMMY_MAIN],
851 [AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
852 AC_LANG_PUSH(Fortran 77)dnl
853 _AC_FC_DUMMY_MAIN($@)
854 AC_LANG_POP(Fortran 77)dnl
855 ])# AC_F77_DUMMY_MAIN
858 # AC_FC_DUMMY_MAIN
859 # ----------------------
860 AC_DEFUN([AC_FC_DUMMY_MAIN],
861 [AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
862 AC_LANG_PUSH(Fortran)dnl
863 _AC_FC_DUMMY_MAIN($@)
864 AC_LANG_POP(Fortran)dnl
865 ])# AC_FC_DUMMY_MAIN
868 # _AC_FC_MAIN
869 # -----------
870 # Define {F77,FC}_MAIN to name of alternate main() function for use with
871 # the Fortran libraries.  (Typically, the libraries may define their
872 # own main() to initialize I/O, etcetera, that then call your own
873 # routine called MAIN__ or whatever.)  See _AC_FC_DUMMY_MAIN, above.
874 # If no such alternate name is found, just define {F77,FC}_MAIN to main.
876 AC_DEFUN([_AC_FC_MAIN],
877 [_AC_FORTRAN_ASSERT()dnl
878 AC_CACHE_CHECK([for alternate main to link with _AC_LANG libraries],
879                ac_cv_[]_AC_LANG_ABBREV[]_main,
880 [ac_[]_AC_LANG_ABBREV[]_m_save_LIBS=$LIBS
881  LIBS="$LIBS $[]_AC_LANG_PREFIX[]LIBS"
882  ac_fortran_dm_var=[]_AC_FC[]_DUMMY_MAIN
883  AC_LANG_PUSH(C)dnl
884  ac_cv_fortran_main="main" # default entry point name
885  for ac_func in MAIN__ MAIN_ __main MAIN _MAIN __MAIN main_ main__ _main; do
886    AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@ifdef FC_DUMMY_MAIN_EQ_F77
887 @%:@  undef F77_DUMMY_MAIN
888 @%:@  undef FC_DUMMY_MAIN
889 @%:@else
890 @%:@  undef $ac_fortran_dm_var
891 @%:@endif
892 @%:@define main $ac_func])],
893                   [ac_cv_fortran_main=$ac_func; break])
894  done
895  AC_LANG_POP(C)dnl
896  ac_cv_[]_AC_LANG_ABBREV[]_main=$ac_cv_fortran_main
897  rm -f conftest*
898  LIBS=$ac_[]_AC_LANG_ABBREV[]_m_save_LIBS
900 AC_DEFINE_UNQUOTED([]_AC_FC[]_MAIN, $ac_cv_[]_AC_LANG_ABBREV[]_main,
901                    [Define to alternate name for `main' routine that is
902                     called from a `main' in the Fortran libraries.])
903 ])# _AC_FC_MAIN
906 # AC_F77_MAIN
907 # -----------
908 AC_DEFUN([AC_F77_MAIN],
909 [AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
910 AC_LANG_PUSH(Fortran 77)dnl
911 _AC_FC_MAIN
912 AC_LANG_POP(Fortran 77)dnl
913 ])# AC_F77_MAIN
916 # AC_FC_MAIN
917 # ----------
918 AC_DEFUN([AC_FC_MAIN],
919 [AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
920 AC_LANG_PUSH(Fortran)dnl
921 _AC_FC_MAIN
922 AC_LANG_POP(Fortran)dnl
923 ])# AC_FC_MAIN
926 # __AC_FC_NAME_MANGLING
927 # ---------------------
928 # Test for the name mangling scheme used by the Fortran compiler.
930 # Sets ac_cv_{f77,fc}_mangling. The value contains three fields, separated
931 # by commas:
933 # lower case / upper case:
934 #    case translation of the Fortran symbols
935 # underscore / no underscore:
936 #    whether the compiler appends "_" to symbol names
937 # extra underscore / no extra underscore:
938 #    whether the compiler appends an extra "_" to symbol names already
939 #    containing at least one underscore
941 AC_DEFUN([__AC_FC_NAME_MANGLING],
942 [_AC_FORTRAN_ASSERT()dnl
943 AC_CACHE_CHECK([for _AC_LANG name-mangling scheme],
944                ac_cv_[]_AC_LANG_ABBREV[]_mangling,
945 [AC_COMPILE_IFELSE(
946 [      subroutine foobar()
947       return
948       end
949       subroutine foo_bar()
950       return
951       end],
952 [mv conftest.$ac_objext cfortran_test.$ac_objext
954   ac_save_LIBS=$LIBS
955   LIBS="cfortran_test.$ac_objext $LIBS $[]_AC_LANG_PREFIX[]LIBS"
957   AC_LANG_PUSH(C)dnl
958   ac_success=no
959   for ac_foobar in foobar FOOBAR; do
960     for ac_underscore in "" "_"; do
961       ac_func="$ac_foobar$ac_underscore"
962       AC_LINK_IFELSE([AC_LANG_CALL([], [$ac_func])],
963                      [ac_success=yes; break 2])
964     done
965   done
966   AC_LANG_POP(C)dnl
968   if test "$ac_success" = "yes"; then
969      case $ac_foobar in
970         foobar)
971            ac_case=lower
972            ac_foo_bar=foo_bar
973            ;;
974         FOOBAR)
975            ac_case=upper
976            ac_foo_bar=FOO_BAR
977            ;;
978      esac
980      AC_LANG_PUSH(C)dnl
981      ac_success_extra=no
982      for ac_extra in "" "_"; do
983         ac_func="$ac_foo_bar$ac_underscore$ac_extra"
984         AC_LINK_IFELSE([AC_LANG_CALL([], [$ac_func])],
985                        [ac_success_extra=yes; break])
986      done
987      AC_LANG_POP(C)dnl
989      if test "$ac_success_extra" = "yes"; then
990         ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_case case"
991         if test -z "$ac_underscore"; then
992            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, no underscore"
993         else
994            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, underscore"
995         fi
996         if test -z "$ac_extra"; then
997            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, no extra underscore"
998         else
999            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, extra underscore"
1000         fi
1001       else
1002         ac_cv_[]_AC_LANG_ABBREV[]_mangling="unknown"
1003       fi
1004   else
1005      ac_cv_[]_AC_LANG_ABBREV[]_mangling="unknown"
1006   fi
1008   LIBS=$ac_save_LIBS
1009   rm -f cfortran_test* conftest*],
1010   [AC_MSG_FAILURE([cannot compile a simple Fortran program])])
1012 ])# __AC_FC_NAME_MANGLING
1014 # The replacement is empty.
1015 AU_DEFUN([AC_F77_NAME_MANGLING], [])
1018 # _AC_F77_NAME_MANGLING
1019 # ----------------------
1020 AC_DEFUN([_AC_F77_NAME_MANGLING],
1021 [AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
1022 AC_REQUIRE([AC_F77_DUMMY_MAIN])dnl
1023 AC_LANG_PUSH(Fortran 77)dnl
1024 __AC_FC_NAME_MANGLING
1025 AC_LANG_POP(Fortran 77)dnl
1026 ])# _AC_F77_NAME_MANGLING
1029 # _AC_FC_NAME_MANGLING
1030 # ----------------------
1031 AC_DEFUN([_AC_FC_NAME_MANGLING],
1032 [AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
1033 AC_REQUIRE([AC_FC_DUMMY_MAIN])dnl
1034 AC_LANG_PUSH(Fortran)dnl
1035 __AC_FC_NAME_MANGLING
1036 AC_LANG_POP(Fortran)dnl
1037 ])# _AC_FC_NAME_MANGLING
1040 # _AC_FC_WRAPPERS
1041 # ---------------
1042 # Defines C macros {F77,FC}_FUNC(name,NAME) and {F77,FC}_FUNC_(name,NAME) to
1043 # properly mangle the names of C identifiers, and C identifiers with
1044 # underscores, respectively, so that they match the name mangling
1045 # scheme used by the Fortran compiler.
1046 AC_DEFUN([_AC_FC_WRAPPERS],
1047 [_AC_FORTRAN_ASSERT()dnl
1048 AH_TEMPLATE(_AC_FC[_FUNC],
1049     [Define to a macro mangling the given C identifier (in lower and upper
1050      case), which must not contain underscores, for linking with Fortran.])dnl
1051 AH_TEMPLATE(_AC_FC[_FUNC_],
1052     [As ]_AC_FC[_FUNC, but for C identifiers containing underscores.])dnl
1053 case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in
1054   "lower case, no underscore, no extra underscore")
1055           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name])
1056           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name]) ;;
1057   "lower case, no underscore, extra underscore")
1058           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name])
1059           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name ## _]) ;;
1060   "lower case, underscore, no extra underscore")
1061           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name ## _])
1062           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name ## _]) ;;
1063   "lower case, underscore, extra underscore")
1064           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name ## _])
1065           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name ## __]) ;;
1066   "upper case, no underscore, no extra underscore")
1067           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME])
1068           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME]) ;;
1069   "upper case, no underscore, extra underscore")
1070           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME])
1071           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME ## _]) ;;
1072   "upper case, underscore, no extra underscore")
1073           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME ## _])
1074           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME ## _]) ;;
1075   "upper case, underscore, extra underscore")
1076           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME ## _])
1077           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME ## __]) ;;
1078   *)
1079           AC_MSG_WARN([unknown Fortran name-mangling scheme])
1080           ;;
1081 esac
1082 ])# _AC_FC_WRAPPERS
1085 # AC_F77_WRAPPERS
1086 # ---------------
1087 AC_DEFUN([AC_F77_WRAPPERS],
1088 [AC_REQUIRE([_AC_F77_NAME_MANGLING])dnl
1089 AC_LANG_PUSH(Fortran 77)dnl
1090 _AC_FC_WRAPPERS
1091 AC_LANG_POP(Fortran 77)dnl
1092 ])# AC_F77_WRAPPERS
1095 # AC_FC_WRAPPERS
1096 # --------------
1097 AC_DEFUN([AC_FC_WRAPPERS],
1098 [AC_REQUIRE([_AC_FC_NAME_MANGLING])dnl
1099 AC_LANG_PUSH(Fortran)dnl
1100 _AC_FC_WRAPPERS
1101 AC_LANG_POP(Fortran)dnl
1102 ])# AC_FC_WRAPPERS
1105 # _AC_FC_FUNC(NAME, [SHELLVAR = NAME])
1106 # ------------------------------------
1107 # For a Fortran subroutine of given NAME, define a shell variable
1108 # $SHELLVAR to the Fortran-mangled name.  If the SHELLVAR
1109 # argument is not supplied, it defaults to NAME.
1110 AC_DEFUN([_AC_FC_FUNC],
1111 [_AC_FORTRAN_ASSERT()dnl
1112 case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in
1113   upper*) ac_val="m4_toupper([$1])" ;;
1114   lower*) ac_val="m4_tolower([$1])" ;;
1115   *)      ac_val="unknown" ;;
1116 esac
1117 case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in *," underscore"*) ac_val="$ac_val"_ ;; esac
1118 m4_if(m4_index([$1],[_]),-1,[],
1119 [case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in *," extra underscore"*) ac_val="$ac_val"_ ;; esac
1121 m4_default([$2],[$1])="$ac_val"
1122 ])# _AC_FC_FUNC
1125 # AC_F77_FUNC(NAME, [SHELLVAR = NAME])
1126 # ------------------------------------
1127 AC_DEFUN([AC_F77_FUNC],
1128 [AC_REQUIRE([_AC_F77_NAME_MANGLING])dnl
1129 AC_LANG_PUSH(Fortran 77)dnl
1130 _AC_FC_FUNC([$1],[$2])
1131 AC_LANG_POP(Fortran 77)dnl
1132 ])# AC_F77_FUNC
1135 # AC_FC_FUNC(NAME, [SHELLVAR = NAME])
1136 # -----------------------------------
1137 AC_DEFUN([AC_FC_FUNC],
1138 [AC_REQUIRE([_AC_FC_NAME_MANGLING])dnl
1139 AC_LANG_PUSH(Fortran)dnl
1140 _AC_FC_FUNC([$1],[$2])
1141 AC_LANG_POP(Fortran)dnl
1142 ])# AC_FC_FUNC
1145 # AC_FC_SRCEXT(EXT, [ACTION-IF-SUCCESS], [ACTION-IF-FAILURE])
1146 # -----------------------------------------------------------
1147 # Set the source-code extension used in Fortran (FC) tests to EXT (which
1148 # defaults to f).  Also, look for any necessary additional FCFLAGS needed
1149 # to allow this extension, and store them in the output variable
1150 # FCFLAGS_<EXT> (e.g. FCFLAGS_f90 for EXT=f90).  If successful,
1151 # call ACTION-IF-SUCCESS.  If unable to compile source code with EXT,
1152 # call ACTION-IF-FAILURE, which defaults to failing with an error
1153 # message.
1155 # (The flags for the current source-code extension, if any, are stored in
1156 # $ac_fcflags_srcext and used automatically in subsequent autoconf tests.)
1158 # For ordinary extensions like f90, etcetera, the modified FCFLAGS
1159 # are currently needed for IBM's xlf* and Intel's ifc (grrr).  Unfortunately,
1160 # xlf* will only take flags to recognize one extension at a time, so if the
1161 # user wants to compile multiple extensions (.f90 and .f95, say), she
1162 # will need to use the FCFLAGS_F90 and FCFLAGS_F95 individually rather
1163 # than just adding them all to FCFLAGS, for example.
1165 # Also, for Intel's ifc compiler (which does not accept .f95 by default in
1166 # some versions), the $FCFLAGS_<EXT> variable *must* go immediately before
1167 # the source file on the command line, unlike other $FCFLAGS.  Ugh.
1168 AC_DEFUN([AC_FC_SRCEXT],
1169 [AC_LANG_PUSH(Fortran)dnl
1170 AC_CACHE_CHECK([for Fortran flag to compile .$1 files],
1171                 ac_cv_fc_srcext_$1,
1172 [ac_ext=$1
1173 ac_fcflags_srcext_save=$ac_fcflags_srcext
1174 ac_fcflags_srcext=
1175 ac_cv_fc_srcext_$1=unknown
1176 for ac_flag in none -qsuffix=f=$1 -Tf; do
1177   test "x$ac_flag" != xnone && ac_fcflags_srcext="$ac_flag"
1178   AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [ac_cv_fc_srcext_$1=$ac_flag; break])
1179 done
1180 rm -f conftest.$ac_objext conftest.$1
1181 ac_fcflags_srcext=$ac_fcflags_srcext_save
1183 if test "x$ac_cv_fc_srcext_$1" = xunknown; then
1184   m4_default([$3],[AC_MSG_ERROR([Fortran could not compile .$1 files])])
1185 else
1186   ac_fc_srcext=$1
1187   if test "x$ac_cv_fc_srcext_$1" = xnone; then
1188     ac_fcflags_srcext=""
1189     FCFLAGS_[]$1[]=""
1190   else
1191     ac_fcflags_srcext=$ac_cv_fc_srcext_$1
1192     FCFLAGS_[]$1[]=$ac_cv_fc_srcext_$1
1193   fi
1194   AC_SUBST(FCFLAGS_[]$1)
1195   $2
1197 AC_LANG_POP(Fortran)dnl
1198 ])# AC_FC_SRCEXT
1201 # AC_FC_FREEFORM([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1202 # ------------------------------------------------------------------
1203 # Look for a compiler flag to make the Fortran (FC) compiler accept
1204 # free-format source code, and adds it to FCFLAGS.  Call
1205 # ACTION-IF-SUCCESS (defaults to nothing) if successful (i.e. can
1206 # compile code using new extension) and ACTION-IF-FAILURE (defaults to
1207 # failing with an error message) if not.  (Defined via DEFUN_ONCE to
1208 # prevent flag from being added to FCFLAGS multiple times.)
1210 # The known flags are:
1211 #        -ffree-form: GNU g77
1212 #                -FR: Intel compiler (icc, ecc)
1213 #              -free: Compaq compiler (fort)
1214 #             -qfree: IBM compiler (xlf)
1215 # -Mfree, -Mfreeform: Portland Group compiler
1216 #          -freeform: SGI compiler
1217 #            -f free: Absoft Fortran
1218 # We try to test the "more popular" flags first, by some prejudiced
1219 # notion of popularity.
1220 AC_DEFUN_ONCE([AC_FC_FREEFORM],
1221 [AC_LANG_PUSH(Fortran)dnl
1222 AC_CACHE_CHECK([for Fortran flag needed to allow free-form source],
1223                 ac_cv_fc_freeform,
1224 [ac_cv_fc_freeform=unknown
1225 ac_fc_freeform_FCFLAGS_save=$FCFLAGS
1226 for ac_flag in none -ffree-form -FR -free -qfree -Mfree -Mfreeform \
1227                -freeform "-f free"
1229   test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_freeform_FCFLAGS_save $ac_flag"
1230   AC_COMPILE_IFELSE([
1231   program freeform
1232        ! FIXME: how to best confuse non-freeform compilers?
1233        print *, 'Hello ', &
1234            'world.'
1235        end],
1236                     [ac_cv_fc_freeform=$ac_flag; break])
1237 done
1238 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
1239 FCFLAGS=$ac_fc_freeform_FCFLAGS_save
1241 if test "x$ac_cv_fc_freeform" = xunknown; then
1242   m4_default([$2],
1243              [AC_MSG_ERROR([Fortran does not accept free-form source], 77)])
1244 else
1245   if test "x$ac_cv_fc_freeform" != xnone; then
1246     FCFLAGS="$FCFLAGS $ac_cv_fc_freeform"
1247   fi
1248   $1
1250 AC_LANG_POP(Fortran)dnl
1251 ])# AC_FC_FREEFORM