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