maint: update copyright year
[autoconf.git] / lib / autoconf / fortran.m4
blobc704868cf86c47b8090e6b4b765d7571d49127f3
1 # This file is part of Autoconf.                       -*- Autoconf -*-
2 # Fortran languages support.
3 # Copyright (C) 2001, 2003-2011 Free Software Foundation, Inc.
5 # This file is part of Autoconf.  This program is free
6 # software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the
8 # Free Software Foundation, either version 3 of the License, or
9 # (at your option) 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 # Under Section 7 of GPL version 3, you are granted additional
17 # permissions described in the Autoconf Configure Script Exception,
18 # version 3.0, as published by the Free Software Foundation.
20 # You should have received a copy of the GNU General Public License
21 # and a copy of the Autoconf Configure Script Exception along with
22 # this program; see the files COPYINGv3 and COPYING.EXCEPTION
23 # respectively.  If not, see <http://www.gnu.org/licenses/>.
25 # Written by David MacKenzie, with help from
26 # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
27 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
30 # Table of Contents:
32 # Preamble
34 # 0. Utility macros
36 # 1. Language selection
37 #    and routines to produce programs in a given language.
39 # 2. Producing programs in a given language.
41 # 3. Looking for a compiler
42 #    And possibly the associated preprocessor.
44 # 4. Compilers' characteristics.
48 ## ---------- ##
49 ## Preamble.  ##
50 ## ---------- ##
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.
65 ## ------------------- ##
66 ## 0. Utility macros.  ##
67 ## ------------------- ##
70 # _AC_LIST_MEMBER_IF(ELEMENT, LIST, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
71 # ---------------------------------------------------------------------------
73 # Processing the elements of a list is tedious in shell programming,
74 # as lists tend to be implemented as space delimited strings.
76 # This macro searches LIST for ELEMENT, and executes ACTION-IF-FOUND
77 # if ELEMENT is a member of LIST, otherwise it executes
78 # ACTION-IF-NOT-FOUND.
79 AC_DEFUN([_AC_LIST_MEMBER_IF],
80 dnl Do some sanity checking of the arguments.
81 [m4_if([$1], , [m4_fatal([$0: missing argument 1])],
82       [$2], , [m4_fatal([$0: missing argument 2])])]dnl
83 [  ac_exists=false
84   for ac_i in $2; do
85     if test x"$1" = x"$ac_i"; then
86       ac_exists=true
87       break
88     fi
89   done
91   AS_IF([test x"$ac_exists" = xtrue], [$3], [$4])[]dnl
92 ])# _AC_LIST_MEMBER_IF
95 # _AC_LINKER_OPTION(LINKER-OPTIONS, SHELL-VARIABLE)
96 # -------------------------------------------------
98 # Specifying options to the compiler (whether it be the C, C++ or
99 # Fortran 77 compiler) that are meant for the linker is compiler
100 # dependent.  This macro lets you give options to the compiler that
101 # are meant for the linker in a portable, compiler-independent way.
103 # This macro take two arguments, a list of linker options that the
104 # compiler should pass to the linker (LINKER-OPTIONS) and the name of
105 # a shell variable (SHELL-VARIABLE).  The list of linker options are
106 # appended to the shell variable in a compiler-dependent way.
108 # For example, if the selected language is C, then this:
110 #   _AC_LINKER_OPTION([-R /usr/local/lib/foo], foo_LDFLAGS)
112 # will expand into this if the selected C compiler is gcc:
114 #   foo_LDFLAGS="-Xlinker -R -Xlinker /usr/local/lib/foo"
116 # otherwise, it will expand into this:
118 #   foo_LDFLAGS"-R /usr/local/lib/foo"
120 # You are encouraged to add support for compilers that this macro
121 # doesn't currently support.
122 # FIXME: Get rid of this macro.
123 AC_DEFUN([_AC_LINKER_OPTION],
124 [if test "$ac_compiler_gnu" = yes; then
125   for ac_link_opt in $1; do
126     $2="[$]$2 -Xlinker $ac_link_opt"
127   done
128 else
129   $2="[$]$2 $1"
130 fi[]dnl
131 ])# _AC_LINKER_OPTION
135 ## ------------------------ ##
136 ## 1a. Language selection.  ##
137 ## ------------------------ ##
140 # AC_LANG(Fortran 77)
141 # -------------------
142 AC_LANG_DEFINE([Fortran 77], [f77], [F], [F77], [],
143 [ac_ext=f
144 ac_compile='$F77 -c $FFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
145 ac_link='$F77 -o conftest$ac_exeext $FFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
146 ac_compiler_gnu=$ac_cv_f77_compiler_gnu
150 # AC_LANG_FORTRAN77
151 # -----------------
152 AU_DEFUN([AC_LANG_FORTRAN77], [AC_LANG(Fortran 77)])
155 # _AC_FORTRAN_ASSERT
156 # ------------------
157 # Current language must be Fortran or Fortran 77.
158 m4_defun([_AC_FORTRAN_ASSERT],
159 [m4_if(_AC_LANG, [Fortran], [],
160        [m4_if(_AC_LANG, [Fortran 77], [],
161               [m4_fatal([$0: current language is not Fortran: ] _AC_LANG)])])])
164 # _AC_FC
165 # ------
166 # Return F77 or FC, depending upon the language.
167 AC_DEFUN([_AC_FC],
168 [_AC_FORTRAN_ASSERT()dnl
169 AC_LANG_CASE([Fortran 77], [F77],
170              [Fortran],    [FC])])
174 ## ----------------------- ##
175 ## 2. Producing programs.  ##
176 ## ----------------------- ##
179 # AC_LANG_PROGRAM(Fortran 77)([PROLOGUE], [BODY])
180 # -----------------------------------------------
181 # Yes, we discard the PROLOGUE.
182 m4_define([AC_LANG_PROGRAM(Fortran 77)],
183 [m4_ifval([$1],
184        [m4_warn([syntax], [$0: ignoring PROLOGUE: $1])])dnl
185       program main
187       end])
190 # _AC_LANG_IO_PROGRAM(Fortran 77)
191 # -------------------------------
192 # Produce source that performs I/O.
193 m4_define([_AC_LANG_IO_PROGRAM(Fortran 77)],
194 [AC_LANG_PROGRAM([],
195 [dnl
196       open(unit=9,file='conftest.out')
197       close(unit=9)
198 ])])
201 # AC_LANG_CALL(Fortran 77)(PROLOGUE, FUNCTION)
202 # --------------------------------------------
203 # FIXME: This is a guess, help!
204 m4_define([AC_LANG_CALL(Fortran 77)],
205 [AC_LANG_PROGRAM([$1],
206 [      call $2])])
209 # AC_LANG_FUNC_LINK_TRY(Fortran 77)(FUNCTION)
210 # -------------------------------------------
211 m4_define([AC_LANG_FUNC_LINK_TRY(Fortran 77)],
212 [AC_LANG_PROGRAM([],
213 [      call $1])])
215 ## ------------------------ ##
216 ## 1b. Language selection.  ##
217 ## ------------------------ ##
220 # AC_LANG(Fortran)
221 # ----------------
222 AC_LANG_DEFINE([Fortran], [fc], [FC], [FC], [Fortran 77],
223 [ac_ext=${ac_fc_srcext-f}
224 ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
225 ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
226 ac_compiler_gnu=$ac_cv_fc_compiler_gnu
230 ## -------------------------------------------- ##
231 ## 3. Looking for Compilers and Preprocessors.  ##
232 ## -------------------------------------------- ##
235 # AC_LANG_PREPROC(Fortran 77)
236 # ---------------------------
237 # Find the Fortran 77 preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
238 AC_DEFUN([AC_LANG_PREPROC(Fortran 77)],
239 [m4_warn([syntax],
240          [$0: No preprocessor defined for ]_AC_LANG)])
242 # AC_LANG_PREPROC(Fortran)
243 # ------------------------
244 # Find the Fortran preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
245 AC_DEFUN([AC_LANG_PREPROC(Fortran)],
246 [m4_warn([syntax],
247          [$0: No preprocessor defined for ]_AC_LANG)])
250 # AC_LANG_COMPILER(Fortran 77)
251 # ----------------------------
252 # Find the Fortran 77 compiler.  Must be AC_DEFUN'd to be
253 # AC_REQUIRE'able.
254 AC_DEFUN([AC_LANG_COMPILER(Fortran 77)],
255 [AC_REQUIRE([AC_PROG_F77])])
257 # AC_LANG_COMPILER(Fortran)
258 # -------------------------
259 # Find the Fortran compiler.  Must be AC_DEFUN'd to be
260 # AC_REQUIRE'able.
261 AC_DEFUN([AC_LANG_COMPILER(Fortran)],
262 [AC_REQUIRE([AC_PROG_FC])])
265 # ac_cv_prog_g77
266 # --------------
267 # We used to name the cache variable this way.
268 AU_DEFUN([ac_cv_prog_g77],
269 [ac_cv_f77_compiler_gnu])
272 # _AC_FC_DIALECT_YEAR([DIALECT])
273 # ------------------------------
274 # Given a Fortran DIALECT, which is Fortran [YY]YY or simply [YY]YY,
275 # convert to a 4-digit year.  The dialect must be one of Fortran 77,
276 # 90, 95, or 2000, currently.  If DIALECT is simply Fortran or the
277 # empty string, returns the empty string.
278 AC_DEFUN([_AC_FC_DIALECT_YEAR],
279 [m4_case(m4_bpatsubsts(m4_tolower([$1]), [fortran],[], [ *],[]),
280          [77],[1977], [1977],[1977],
281          [90],[1990], [1990],[1990],
282          [95],[1995], [1995],[1995],
283          [2000],[2000],
284          [],[],
285          [m4_fatal([unknown Fortran dialect])])])
288 # _AC_PROG_FC([DIALECT], [COMPILERS...])
289 # --------------------------------------
290 # DIALECT is a Fortran dialect, given by Fortran [YY]YY or simply [YY]YY,
291 # and must be one of those supported by _AC_FC_DIALECT_YEAR
293 # If DIALECT is supplied, then we search for compilers of that dialect
294 # first, and then later dialects.  Otherwise, we search for compilers
295 # of the newest dialect first, and then earlier dialects in increasing age.
296 # This search order is necessarily imperfect because the dialect cannot
297 # always be inferred from the compiler name.
299 # Known compilers:
300 #  f77/f90/f95: generic compiler names
301 #  g77: GNU Fortran 77 compiler
302 #  gfortran: GNU Fortran 95+ compiler (released in gcc 4.0)
303 #  g95: original gcc-based f95 compiler (gfortran is a fork)
304 #  ftn: native Fortran 95 compiler on Cray X1
305 #  cf77: native F77 compiler under older Crays (prefer over fort77)
306 #  fort77: native F77 compiler under HP-UX (and some older Crays)
307 #  frt: Fujitsu F77 compiler
308 #  pgf77/pgf90/pghpf/pgf95/pgfortran: Portland Group F77/F90/F95 compilers
309 #  xlf/xlf90/xlf95: IBM (AIX) F77/F90/F95 compilers
310 #    Prefer xlf9x to the generic names because they do not reject files
311 #    with extension `.f'.
312 #  lf95: Lahey-Fujitsu F95 compiler
313 #  fl32: Microsoft Fortran 77 "PowerStation" compiler
314 #  af77: Apogee F77 compiler for Intergraph hardware running CLIX
315 #  epcf90: "Edinburgh Portable Compiler" F90
316 #  fort: Compaq (now HP) Fortran 90/95 compiler for Tru64 and Linux/Alpha
317 #  ifort, previously ifc: Intel Fortran 95 compiler for Linux/x86
318 #  efc: Intel Fortran 95 compiler for IA64
319 m4_define([_AC_F95_FC], [gfortran g95 xlf95 f95 fort ifort ifc efc pgfortran pgf95 lf95 ftn])
320 m4_define([_AC_F90_FC], [xlf90 f90 pgf90 pghpf epcf90])
321 m4_define([_AC_F77_FC], [g77 xlf f77 frt pgf77 cf77 fort77 fl32 af77])
322 AC_DEFUN([_AC_PROG_FC],
323 [_AC_FORTRAN_ASSERT()dnl
324 AC_CHECK_TOOLS([]_AC_FC[],
325       m4_default([$2],
326         m4_case(_AC_FC_DIALECT_YEAR([$1]),
327                 [1995], [_AC_F95_FC],
328                 [1990], [_AC_F90_FC _AC_F95_FC],
329                 [1977], [_AC_F77_FC _AC_F90_FC _AC_F95_FC],
330                 [_AC_F95_FC _AC_F90_FC _AC_F77_FC])))
332 # Provide some information about the compiler.
333 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
334 set X $ac_compile
335 ac_compiler=$[2]
336 for ac_option in --version -v -V -qversion; do
337   _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
338 done
339 rm -f a.out
341 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
342 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
343 # If we don't use `.F' as extension, the preprocessor is not run on the
344 # input file.  (Note that this only needs to work for GNU compilers.)
345 ac_save_ext=$ac_ext
346 ac_ext=F
347 _AC_LANG_COMPILER_GNU
348 ac_ext=$ac_save_ext
349 _AC_PROG_FC_G
350 ])# _AC_PROG_FC
353 # AC_PROG_F77([COMPILERS...])
354 # ---------------------------
355 # COMPILERS is a space separated list of Fortran 77 compilers to search
356 # for.  See also _AC_PROG_FC.
357 AC_DEFUN([AC_PROG_F77],
358 [AC_LANG_PUSH(Fortran 77)dnl
359 AC_ARG_VAR([F77],    [Fortran 77 compiler command])dnl
360 AC_ARG_VAR([FFLAGS], [Fortran 77 compiler flags])dnl
361 _AC_ARG_VAR_LDFLAGS()dnl
362 _AC_ARG_VAR_LIBS()dnl
363 _AC_PROG_FC([Fortran 77], [$1])
364 if test $ac_compiler_gnu = yes; then
365   G77=yes
366 else
367   G77=
369 AC_LANG_POP(Fortran 77)dnl
370 ])# AC_PROG_F77
373 # AC_PROG_FC([COMPILERS...], [DIALECT])
374 # -------------------------------------
375 # COMPILERS is a space separated list of Fortran 77 compilers to search
376 # for, and [DIALECT] is an optional dialect.  See also _AC_PROG_FC.
377 AC_DEFUN([AC_PROG_FC],
378 [AC_LANG_PUSH(Fortran)dnl
379 AC_ARG_VAR([FC],    [Fortran compiler command])dnl
380 AC_ARG_VAR([FCFLAGS], [Fortran compiler flags])dnl
381 _AC_ARG_VAR_LDFLAGS()dnl
382 _AC_ARG_VAR_LIBS()dnl
383 _AC_PROG_FC([$2], [$1])
384 AC_LANG_POP(Fortran)dnl
385 ])# AC_PROG_FC
388 # _AC_PROG_FC_G
389 # -------------
390 # Check whether -g works, even if F[C]FLAGS is set, in case the package
391 # plays around with F[C]FLAGS (such as to build both debugging and normal
392 # versions of a library), tasteless as that idea is.
393 m4_define([_AC_PROG_FC_G],
394 [_AC_FORTRAN_ASSERT()dnl
395 ac_test_[]_AC_LANG_PREFIX[]FLAGS=${[]_AC_LANG_PREFIX[]FLAGS+set}
396 ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
397 _AC_LANG_PREFIX[]FLAGS=
398 AC_CACHE_CHECK(whether $[]_AC_FC[] accepts -g, ac_cv_prog_[]_AC_LANG_ABBREV[]_g,
399 [_AC_LANG_PREFIX[]FLAGS=-g
400 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
401 [ac_cv_prog_[]_AC_LANG_ABBREV[]_g=yes],
402 [ac_cv_prog_[]_AC_LANG_ABBREV[]_g=no])
404 if test "$ac_test_[]_AC_LANG_PREFIX[]FLAGS" = set; then
405   _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
406 elif test $ac_cv_prog_[]_AC_LANG_ABBREV[]_g = yes; then
407   if test "x$ac_cv_[]_AC_LANG_ABBREV[]_compiler_gnu" = xyes; then
408     _AC_LANG_PREFIX[]FLAGS="-g -O2"
409   else
410     _AC_LANG_PREFIX[]FLAGS="-g"
411   fi
412 else
413   if test "x$ac_cv_[]_AC_LANG_ABBREV[]_compiler_gnu" = xyes; then
414     _AC_LANG_PREFIX[]FLAGS="-O2"
415   else
416     _AC_LANG_PREFIX[]FLAGS=
417   fi
418 fi[]dnl
419 ])# _AC_PROG_FC_G
422 # _AC_PROG_FC_C_O
423 # ---------------
424 # Test if the Fortran compiler accepts the options `-c' and `-o'
425 # simultaneously, and define `[F77/FC]_NO_MINUS_C_MINUS_O' if it does not.
427 # The usefulness of this macro is questionable, as I can't really see
428 # why anyone would use it.  The only reason I include it is for
429 # completeness, since a similar test exists for the C compiler.
431 # FIXME: it seems like we could merge the C/C++/Fortran versions of this.
432 AC_DEFUN([_AC_PROG_FC_C_O],
433 [_AC_FORTRAN_ASSERT()dnl
434 AC_CACHE_CHECK([whether $[]_AC_FC[] understands -c and -o together],
435                [ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o],
436 [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
437 # We test twice because some compilers refuse to overwrite an existing
438 # `.o' file with `-o', although they will create one.
439 ac_try='$[]_AC_FC[] $[]_AC_LANG_PREFIX[]FLAGS -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
440 rm -f conftest2.*
441 if _AC_DO_VAR(ac_try) &&
442      test -f conftest2.$ac_objext &&
443      _AC_DO_VAR(ac_try); then
444   ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o=yes
445 else
446   ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o=no
448 rm -f conftest*])
449 if test $ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o = no; then
450   AC_DEFINE([]_AC_FC[]_NO_MINUS_C_MINUS_O, 1,
451             [Define to 1 if your Fortran compiler doesn't accept
452              -c and -o together.])
454 ])# _AC_PROG_FC_C_O
457 # AC_PROG_F77_C_O
458 # ---------------
459 AC_DEFUN([AC_PROG_F77_C_O],
460 [AC_REQUIRE([AC_PROG_F77])dnl
461 AC_LANG_PUSH(Fortran 77)dnl
462 _AC_PROG_FC_C_O
463 AC_LANG_POP(Fortran 77)dnl
464 ])# AC_PROG_F77_C_O
467 # AC_PROG_FC_C_O
468 # --------------
469 AC_DEFUN([AC_PROG_FC_C_O],
470 [AC_REQUIRE([AC_PROG_FC])dnl
471 AC_LANG_PUSH(Fortran)dnl
472 _AC_PROG_FC_C_O
473 AC_LANG_POP(Fortran)dnl
474 ])# AC_PROG_FC_C_O
478 ## ------------------------------- ##
479 ## 4. Compilers' characteristics.  ##
480 ## ------------------------------- ##
483 # _AC_PROG_FC_V_OUTPUT([FLAG = $ac_cv_prog_{f77/fc}_v])
484 # -----------------------------------------------------
485 # Link a trivial Fortran program, compiling with a verbose output FLAG
486 # (whose default value, $ac_cv_prog_{f77/fc}_v, is computed by
487 # _AC_PROG_FC_V), and return the output in $ac_{f77/fc}_v_output.  This
488 # output is processed in the way expected by _AC_FC_LIBRARY_LDFLAGS,
489 # so that any link flags that are echoed by the compiler appear as
490 # space-separated items.
491 AC_DEFUN([_AC_PROG_FC_V_OUTPUT],
492 [_AC_FORTRAN_ASSERT()dnl
493 AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
495 # Compile and link our simple test program by passing a flag (argument
496 # 1 to this macro) to the Fortran compiler in order to get
497 # "verbose" output that we can then parse for the Fortran linker
498 # flags.
499 ac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
500 _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS m4_default([$1], [$ac_cv_prog_[]_AC_LANG_ABBREV[]_v])"
501 eval "set x $ac_link"
502 shift
503 _AS_ECHO_LOG([$[*]])
504 # gfortran 4.3 outputs lines setting COLLECT_GCC_OPTIONS, COMPILER_PATH,
505 # LIBRARY_PATH; skip all such settings.
506 ac_[]_AC_LANG_ABBREV[]_v_output=`eval $ac_link AS_MESSAGE_LOG_FD>&1 2>&1 |
507   sed '/^Driving:/d; /^Configured with:/d;
508       '"/^[[_$as_cr_Letters]][[_$as_cr_alnum]]*=/d"`
509 AS_ECHO(["$ac_[]_AC_LANG_ABBREV[]_v_output"]) >&AS_MESSAGE_LOG_FD
510 _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
512 rm -rf conftest*
514 # On HP/UX there is a line like: "LPATH is: /foo:/bar:/baz" where
515 # /foo, /bar, and /baz are search directories for the Fortran linker.
516 # Here, we change these into -L/foo -L/bar -L/baz (and put it first):
517 ac_[]_AC_LANG_ABBREV[]_v_output="`echo $ac_[]_AC_LANG_ABBREV[]_v_output |
518         grep 'LPATH is:' |
519         sed 's|.*LPATH is\(: *[[^ ]]*\).*|\1|;s|: */| -L/|g'` $ac_[]_AC_LANG_ABBREV[]_v_output"
521 # FIXME: we keep getting bitten by quoted arguments; a more general fix
522 #        that detects unbalanced quotes in FLIBS should be implemented
523 #        and (ugh) tested at some point.
524 case $ac_[]_AC_LANG_ABBREV[]_v_output in
525   # If we are using xlf then replace all the commas with spaces.
526   *xlfentry*)
527     ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed 's/,/ /g'` ;;
529   # With Intel ifc, ignore the quoted -mGLOB_options_string stuff (quoted
530   # $LIBS confuse us, and the libraries appear later in the output anyway).
531   *mGLOB_options_string*)
532     ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed 's/"-mGLOB[[^"]]*"/ /g'` ;;
534   # Portland Group compiler has singly- or doubly-quoted -cmdline argument
535   # Singly-quoted arguments were reported for versions 5.2-4 and 6.0-4.
536   # Doubly-quoted arguments were reported for "PGF90/x86 Linux/x86 5.0-2".
537   *-cmdline\ * | *-ignore\ * | *-def\ *)
538     ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed "\
539         s/-cmdline  *'[[^']]*'/ /g; s/-cmdline  *\"[[^\"]]*\"/ /g
540         s/-ignore  *'[[^']]*'/ /g; s/-ignore  *\"[[^\"]]*\"/ /g
541         s/-def  *'[[^']]*'/ /g; s/-def  *\"[[^\"]]*\"/ /g"` ;;
543   # If we are using Cray Fortran then delete quotes.
544   *cft90*)
545     ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed 's/"//g'` ;;
546 esac
548 ])# _AC_PROG_FC_V_OUTPUT
551 # _AC_PROG_FC_V
552 # -------------
554 # Determine the flag that causes the Fortran compiler to print
555 # information of library and object files (normally -v)
556 # Needed for _AC_FC_LIBRARY_FLAGS
557 # Some compilers don't accept -v (Lahey: -verbose, xlf: -V, Fujitsu: -###)
558 AC_DEFUN([_AC_PROG_FC_V],
559 [_AC_FORTRAN_ASSERT()dnl
560 AC_CACHE_CHECK([how to get verbose linking output from $[]_AC_FC[]],
561                 [ac_cv_prog_[]_AC_LANG_ABBREV[]_v],
562 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
563 [ac_cv_prog_[]_AC_LANG_ABBREV[]_v=
564 # Try some options frequently used verbose output
565 for ac_verb in -v -verbose --verbose -V -\#\#\#; do
566   _AC_PROG_FC_V_OUTPUT($ac_verb)
567   # look for -l* and *.a constructs in the output
568   for ac_arg in $ac_[]_AC_LANG_ABBREV[]_v_output; do
569      case $ac_arg in
570         [[\\/]]*.a | ?:[[\\/]]*.a | -[[lLRu]]*)
571           ac_cv_prog_[]_AC_LANG_ABBREV[]_v=$ac_verb
572           break 2 ;;
573      esac
574   done
575 done
576 if test -z "$ac_cv_prog_[]_AC_LANG_ABBREV[]_v"; then
577    AC_MSG_WARN([cannot determine how to obtain linking information from $[]_AC_FC[]])
578 fi],
579                   [AC_MSG_WARN([compilation failed])])
580 ])])# _AC_PROG_FC_V
583 # _AC_FC_LIBRARY_LDFLAGS
584 # ----------------------
586 # Determine the linker flags (e.g. "-L" and "-l") for the Fortran
587 # intrinsic and runtime libraries that are required to successfully
588 # link a Fortran program or shared library.  The output variable
589 # FLIBS/FCLIBS is set to these flags.
591 # This macro is intended to be used in those situations when it is
592 # necessary to mix, e.g. C++ and Fortran, source code into a single
593 # program or shared library.
595 # For example, if object files from a C++ and Fortran compiler must
596 # be linked together, then the C++ compiler/linker must be used for
597 # linking (since special C++-ish things need to happen at link time
598 # like calling global constructors, instantiating templates, enabling
599 # exception support, etc.).
601 # However, the Fortran intrinsic and runtime libraries must be
602 # linked in as well, but the C++ compiler/linker doesn't know how to
603 # add these Fortran libraries.  Hence, the macro
604 # "AC_F77_LIBRARY_LDFLAGS" was created to determine these Fortran
605 # libraries.
607 # This macro was packaged in its current form by Matthew D. Langston.
608 # However, nearly all of this macro came from the "OCTAVE_FLIBS" macro
609 # in "octave-2.0.13/aclocal.m4", and full credit should go to John
610 # W. Eaton for writing this extremely useful macro.  Thank you John.
611 AC_DEFUN([_AC_FC_LIBRARY_LDFLAGS],
612 [_AC_FORTRAN_ASSERT()dnl
613 _AC_PROG_FC_V
614 AC_CACHE_CHECK([for _AC_LANG libraries of $[]_AC_FC[]], ac_cv_[]_AC_LANG_ABBREV[]_libs,
615 [if test "x$[]_AC_LANG_PREFIX[]LIBS" != "x"; then
616   ac_cv_[]_AC_LANG_ABBREV[]_libs="$[]_AC_LANG_PREFIX[]LIBS" # Let the user override the test.
617 else
619 _AC_PROG_FC_V_OUTPUT
621 ac_cv_[]_AC_LANG_ABBREV[]_libs=
623 # Save positional arguments (if any)
624 ac_save_positional="$[@]"
626 set X $ac_[]_AC_LANG_ABBREV[]_v_output
627 while test $[@%:@] != 1; do
628   shift
629   ac_arg=$[1]
630   case $ac_arg in
631         [[\\/]]*.a | ?:[[\\/]]*.a)
632           _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
633               ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg")
634           ;;
635         -bI:*)
636           _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
637              [_AC_LINKER_OPTION([$ac_arg], ac_cv_[]_AC_LANG_ABBREV[]_libs)])
638           ;;
639           # Ignore these flags.
640         -lang* | -lcrt*.o | -lc | -lgcc* | -lSystem | -libmil | -little \
641           |-LANG:=* | -LIST:* | -LNO:* | -link)
642           ;;
643         -lkernel32)
644           test x"$CYGWIN" != xyes && ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg"
645           ;;
646         -[[LRuYz]])
647           # These flags, when seen by themselves, take an argument.
648           # We remove the space between option and argument and re-iterate
649           # unless we find an empty arg or a new option (starting with -)
650           case $[2] in
651              "" | -*);;
652              *)
653                 ac_arg="$ac_arg$[2]"
654                 shift; shift
655                 set X $ac_arg "$[@]"
656                 ;;
657           esac
658           ;;
659         -YP,*)
660           for ac_j in `AS_ECHO(["$ac_arg"]) | sed -e 's/-YP,/-L/;s/:/ -L/g'`; do
661             _AC_LIST_MEMBER_IF($ac_j, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
662                                [ac_arg="$ac_arg $ac_j"
663                                ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_j"])
664           done
665           ;;
666         -[[lLR]]*)
667           _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
668                              ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg")
669           ;;
670         -zallextract*| -zdefaultextract)
671           ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg"
672           ;;
673           # Ignore everything else.
674   esac
675 done
676 # restore positional arguments
677 set X $ac_save_positional; shift
679 # We only consider "LD_RUN_PATH" on Solaris systems.  If this is seen,
680 # then we insist that the "run path" must be an absolute path (i.e. it
681 # must begin with a "/").
682 case `(uname -sr) 2>/dev/null` in
683    "SunOS 5"*)
684       ac_ld_run_path=`AS_ECHO(["$ac_[]_AC_LANG_ABBREV[]_v_output"]) |
685                         sed -n 's,^.*LD_RUN_PATH *= *\(/[[^ ]]*\).*$,-R\1,p'`
686       test "x$ac_ld_run_path" != x &&
687         _AC_LINKER_OPTION([$ac_ld_run_path], ac_cv_[]_AC_LANG_ABBREV[]_libs)
688       ;;
689 esac
690 fi # test "x$[]_AC_LANG_PREFIX[]LIBS" = "x"
692 []_AC_LANG_PREFIX[]LIBS="$ac_cv_[]_AC_LANG_ABBREV[]_libs"
693 AC_SUBST([]_AC_LANG_PREFIX[]LIBS)
694 ])# _AC_FC_LIBRARY_LDFLAGS
697 # AC_F77_LIBRARY_LDFLAGS
698 # ----------------------
699 AC_DEFUN([AC_F77_LIBRARY_LDFLAGS],
700 [AC_REQUIRE([AC_PROG_F77])dnl
701 AC_LANG_PUSH(Fortran 77)dnl
702 _AC_FC_LIBRARY_LDFLAGS
703 AC_LANG_POP(Fortran 77)dnl
704 ])# AC_F77_LIBRARY_LDFLAGS
707 # AC_FC_LIBRARY_LDFLAGS
708 # ---------------------
709 AC_DEFUN([AC_FC_LIBRARY_LDFLAGS],
710 [AC_REQUIRE([AC_PROG_FC])dnl
711 AC_LANG_PUSH(Fortran)dnl
712 _AC_FC_LIBRARY_LDFLAGS
713 AC_LANG_POP(Fortran)dnl
714 ])# AC_FC_LIBRARY_LDFLAGS
717 # _AC_FC_DUMMY_MAIN([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
718 # -----------------------------------------------------------
720 # Detect name of dummy main routine required by the Fortran libraries,
721 # (if any) and define {F77,FC}_DUMMY_MAIN to this name (which should be
722 # used for a dummy declaration, if it is defined).  On some systems,
723 # linking a C program to the Fortran library does not work unless you
724 # supply a dummy function called something like MAIN__.
726 # Execute ACTION-IF-NOT-FOUND if no way of successfully linking a C
727 # program with the {F77,FC} libs is found; default to exiting with an error
728 # message.  Execute ACTION-IF-FOUND if a dummy routine name is needed
729 # and found or if it is not needed (default to defining {F77,FC}_DUMMY_MAIN
730 # when needed).
732 # What is technically happening is that the Fortran libraries provide
733 # their own main() function, which usually initializes Fortran I/O and
734 # similar stuff, and then calls MAIN__, which is the entry point of
735 # your program.  Usually, a C program will override this with its own
736 # main() routine, but the linker sometimes complain if you don't
737 # provide a dummy (never-called) MAIN__ routine anyway.
739 # Of course, programs that want to allow Fortran subroutines to do
740 # I/O, etcetera, should call their main routine MAIN__() (or whatever)
741 # instead of main().  A separate autoconf test (_AC_FC_MAIN) checks
742 # for the routine to use in this case (since the semantics of the test
743 # are slightly different).  To link to e.g. purely numerical
744 # libraries, this is normally not necessary, however, and most C/C++
745 # programs are reluctant to turn over so much control to Fortran.  =)
747 # The name variants we check for are (in order):
748 #   MAIN__ (g77, MAIN__ required on some systems; IRIX, MAIN__ optional)
749 #   MAIN_, __main (SunOS)
750 #   MAIN _MAIN __MAIN main_ main__ _main (we follow DDD and try these too)
751 AC_DEFUN([_AC_FC_DUMMY_MAIN],
752 [_AC_FORTRAN_ASSERT()dnl
753 m4_define(_AC_LANG_PROGRAM_C_[]_AC_FC[]_HOOKS,
754 [#ifdef ]_AC_FC[_DUMMY_MAIN
755 ]AC_LANG_CASE([Fortran], [#ifndef FC_DUMMY_MAIN_EQ_F77])
756 [#  ifdef __cplusplus
757      extern "C"
758 #  endif
759    int ]_AC_FC[_DUMMY_MAIN() { return 1; }
760 ]AC_LANG_CASE([Fortran], [#endif])
761 [#endif
763 AC_CACHE_CHECK([for dummy main to link with _AC_LANG libraries],
764                ac_cv_[]_AC_LANG_ABBREV[]_dummy_main,
765 [ac_[]_AC_LANG_ABBREV[]_dm_save_LIBS=$LIBS
766  LIBS="$LIBS $[]_AC_LANG_PREFIX[]LIBS"
767  ac_fortran_dm_var=[]_AC_FC[]_DUMMY_MAIN
768  AC_LANG_PUSH(C)dnl
770  # First, try linking without a dummy main:
771  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
772                 [ac_cv_fortran_dummy_main=none],
773                 [ac_cv_fortran_dummy_main=unknown])
775  if test $ac_cv_fortran_dummy_main = unknown; then
776    for ac_func in MAIN__ MAIN_ __main MAIN _MAIN __MAIN main_ main__ _main; do
777      AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@define $ac_fortran_dm_var $ac_func]])],
778                     [ac_cv_fortran_dummy_main=$ac_func; break])
779    done
780  fi
781  AC_LANG_POP(C)dnl
782  ac_cv_[]_AC_LANG_ABBREV[]_dummy_main=$ac_cv_fortran_dummy_main
783  rm -rf conftest*
784  LIBS=$ac_[]_AC_LANG_ABBREV[]_dm_save_LIBS
786 []_AC_FC[]_DUMMY_MAIN=$ac_cv_[]_AC_LANG_ABBREV[]_dummy_main
787 AS_IF([test "$[]_AC_FC[]_DUMMY_MAIN" != unknown],
788       [m4_default([$1],
789 [if test $[]_AC_FC[]_DUMMY_MAIN != none; then
790   AC_DEFINE_UNQUOTED([]_AC_FC[]_DUMMY_MAIN, $[]_AC_FC[]_DUMMY_MAIN,
791                      [Define to dummy `main' function (if any) required to
792                       link to the Fortran libraries.])
793   if test "x$ac_cv_fc_dummy_main" = "x$ac_cv_f77_dummy_main"; then
794         AC_DEFINE([FC_DUMMY_MAIN_EQ_F77], 1,
795                   [Define if F77 and FC dummy `main' functions are identical.])
796   fi
797 fi])],
798       [m4_default([$2],
799             [AC_MSG_FAILURE([linking to Fortran libraries from C fails])])])
800 ])# _AC_FC_DUMMY_MAIN
803 # AC_F77_DUMMY_MAIN
804 # -----------------
805 AC_DEFUN([AC_F77_DUMMY_MAIN],
806 [AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
807 AC_LANG_PUSH(Fortran 77)dnl
808 _AC_FC_DUMMY_MAIN($@)
809 AC_LANG_POP(Fortran 77)dnl
810 ])# AC_F77_DUMMY_MAIN
813 # AC_FC_DUMMY_MAIN
814 # ----------------
815 AC_DEFUN([AC_FC_DUMMY_MAIN],
816 [AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
817 AC_LANG_PUSH(Fortran)dnl
818 _AC_FC_DUMMY_MAIN($@)
819 AC_LANG_POP(Fortran)dnl
820 ])# AC_FC_DUMMY_MAIN
823 # _AC_FC_MAIN
824 # -----------
825 # Define {F77,FC}_MAIN to name of alternate main() function for use with
826 # the Fortran libraries.  (Typically, the libraries may define their
827 # own main() to initialize I/O, etcetera, that then call your own
828 # routine called MAIN__ or whatever.)  See _AC_FC_DUMMY_MAIN, above.
829 # If no such alternate name is found, just define {F77,FC}_MAIN to main.
831 AC_DEFUN([_AC_FC_MAIN],
832 [_AC_FORTRAN_ASSERT()dnl
833 AC_CACHE_CHECK([for alternate main to link with _AC_LANG libraries],
834                ac_cv_[]_AC_LANG_ABBREV[]_main,
835 [ac_[]_AC_LANG_ABBREV[]_m_save_LIBS=$LIBS
836  LIBS="$LIBS $[]_AC_LANG_PREFIX[]LIBS"
837  ac_fortran_dm_var=[]_AC_FC[]_DUMMY_MAIN
838  AC_LANG_PUSH(C)dnl
839  ac_cv_fortran_main="main" # default entry point name
840  for ac_func in MAIN__ MAIN_ __main MAIN _MAIN __MAIN main_ main__ _main; do
841    AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@ifdef FC_DUMMY_MAIN_EQ_F77
842 @%:@  undef F77_DUMMY_MAIN
843 @%:@  undef FC_DUMMY_MAIN
844 @%:@else
845 @%:@  undef $ac_fortran_dm_var
846 @%:@endif
847 @%:@define main $ac_func])],
848                   [ac_cv_fortran_main=$ac_func; break])
849  done
850  AC_LANG_POP(C)dnl
851  ac_cv_[]_AC_LANG_ABBREV[]_main=$ac_cv_fortran_main
852  rm -rf conftest*
853  LIBS=$ac_[]_AC_LANG_ABBREV[]_m_save_LIBS
855 AC_DEFINE_UNQUOTED([]_AC_FC[]_MAIN, $ac_cv_[]_AC_LANG_ABBREV[]_main,
856                    [Define to alternate name for `main' routine that is
857                     called from a `main' in the Fortran libraries.])
858 ])# _AC_FC_MAIN
861 # AC_F77_MAIN
862 # -----------
863 AC_DEFUN([AC_F77_MAIN],
864 [AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
865 AC_LANG_PUSH(Fortran 77)dnl
866 _AC_FC_MAIN
867 AC_LANG_POP(Fortran 77)dnl
868 ])# AC_F77_MAIN
871 # AC_FC_MAIN
872 # ----------
873 AC_DEFUN([AC_FC_MAIN],
874 [AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
875 AC_LANG_PUSH(Fortran)dnl
876 _AC_FC_MAIN
877 AC_LANG_POP(Fortran)dnl
878 ])# AC_FC_MAIN
881 # __AC_FC_NAME_MANGLING
882 # ---------------------
883 # Test for the name mangling scheme used by the Fortran compiler.
885 # Sets ac_cv_{f77,fc}_mangling. The value contains three fields, separated
886 # by commas:
888 # lower case / upper case:
889 #    case translation of the Fortran symbols
890 # underscore / no underscore:
891 #    whether the compiler appends "_" to symbol names
892 # extra underscore / no extra underscore:
893 #    whether the compiler appends an extra "_" to symbol names already
894 #    containing at least one underscore
896 AC_DEFUN([__AC_FC_NAME_MANGLING],
897 [_AC_FORTRAN_ASSERT()dnl
898 AC_CACHE_CHECK([for _AC_LANG name-mangling scheme],
899                ac_cv_[]_AC_LANG_ABBREV[]_mangling,
900 [AC_COMPILE_IFELSE(
901 [[      subroutine foobar()
902       return
903       end
904       subroutine foo_bar()
905       return
906       end]],
907 [mv conftest.$ac_objext cfortran_test.$ac_objext
909   ac_save_LIBS=$LIBS
910   LIBS="cfortran_test.$ac_objext $LIBS $[]_AC_LANG_PREFIX[]LIBS"
912   AC_LANG_PUSH(C)dnl
913   ac_success=no
914   for ac_foobar in foobar FOOBAR; do
915     for ac_underscore in "" "_"; do
916       ac_func="$ac_foobar$ac_underscore"
917       AC_LINK_IFELSE([AC_LANG_CALL([], [$ac_func])],
918                      [ac_success=yes; break 2])
919     done
920   done
921   AC_LANG_POP(C)dnl
923   if test "$ac_success" = "yes"; then
924      case $ac_foobar in
925         foobar)
926            ac_case=lower
927            ac_foo_bar=foo_bar
928            ;;
929         FOOBAR)
930            ac_case=upper
931            ac_foo_bar=FOO_BAR
932            ;;
933      esac
935      AC_LANG_PUSH(C)dnl
936      ac_success_extra=no
937      for ac_extra in "" "_"; do
938         ac_func="$ac_foo_bar$ac_underscore$ac_extra"
939         AC_LINK_IFELSE([AC_LANG_CALL([], [$ac_func])],
940                        [ac_success_extra=yes; break])
941      done
942      AC_LANG_POP(C)dnl
944      if test "$ac_success_extra" = "yes"; then
945         ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_case case"
946         if test -z "$ac_underscore"; then
947            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, no underscore"
948         else
949            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, underscore"
950         fi
951         if test -z "$ac_extra"; then
952            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, no extra underscore"
953         else
954            ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, extra underscore"
955         fi
956       else
957         ac_cv_[]_AC_LANG_ABBREV[]_mangling="unknown"
958       fi
959   else
960      ac_cv_[]_AC_LANG_ABBREV[]_mangling="unknown"
961   fi
963   LIBS=$ac_save_LIBS
964   rm -rf conftest*
965   rm -f cfortran_test*],
966   [AC_MSG_FAILURE([cannot compile a simple Fortran program])])
968 ])# __AC_FC_NAME_MANGLING
970 # The replacement is empty.
971 AU_DEFUN([AC_F77_NAME_MANGLING], [])
974 # _AC_F77_NAME_MANGLING
975 # ---------------------
976 AC_DEFUN([_AC_F77_NAME_MANGLING],
977 [AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
978 AC_REQUIRE([AC_F77_DUMMY_MAIN])dnl
979 AC_LANG_PUSH(Fortran 77)dnl
980 __AC_FC_NAME_MANGLING
981 AC_LANG_POP(Fortran 77)dnl
982 ])# _AC_F77_NAME_MANGLING
985 # _AC_FC_NAME_MANGLING
986 # --------------------
987 AC_DEFUN([_AC_FC_NAME_MANGLING],
988 [AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
989 AC_REQUIRE([AC_FC_DUMMY_MAIN])dnl
990 AC_LANG_PUSH(Fortran)dnl
991 __AC_FC_NAME_MANGLING
992 AC_LANG_POP(Fortran)dnl
993 ])# _AC_FC_NAME_MANGLING
996 # _AC_FC_WRAPPERS
997 # ---------------
998 # Defines C macros {F77,FC}_FUNC(name,NAME) and {F77,FC}_FUNC_(name,NAME) to
999 # properly mangle the names of C identifiers, and C identifiers with
1000 # underscores, respectively, so that they match the name mangling
1001 # scheme used by the Fortran compiler.
1002 AC_DEFUN([_AC_FC_WRAPPERS],
1003 [_AC_FORTRAN_ASSERT()dnl
1004 AH_TEMPLATE(_AC_FC[_FUNC],
1005     [Define to a macro mangling the given C identifier (in lower and upper
1006      case), which must not contain underscores, for linking with Fortran.])dnl
1007 AH_TEMPLATE(_AC_FC[_FUNC_],
1008     [As ]_AC_FC[_FUNC, but for C identifiers containing underscores.])dnl
1009 case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in
1010   "lower case, no underscore, no extra underscore")
1011           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name])
1012           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name]) ;;
1013   "lower case, no underscore, extra underscore")
1014           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name])
1015           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name [##] _]) ;;
1016   "lower case, underscore, no extra underscore")
1017           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name [##] _])
1018           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name [##] _]) ;;
1019   "lower case, underscore, extra underscore")
1020           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name [##] _])
1021           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name [##] __]) ;;
1022   "upper case, no underscore, no extra underscore")
1023           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME])
1024           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME]) ;;
1025   "upper case, no underscore, extra underscore")
1026           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME])
1027           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME [##] _]) ;;
1028   "upper case, underscore, no extra underscore")
1029           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME [##] _])
1030           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME [##] _]) ;;
1031   "upper case, underscore, extra underscore")
1032           AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME [##] _])
1033           AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME [##] __]) ;;
1034   *)
1035           AC_MSG_WARN([unknown Fortran name-mangling scheme])
1036           ;;
1037 esac
1038 ])# _AC_FC_WRAPPERS
1041 # AC_F77_WRAPPERS
1042 # ---------------
1043 AC_DEFUN([AC_F77_WRAPPERS],
1044 [AC_REQUIRE([_AC_F77_NAME_MANGLING])dnl
1045 AC_LANG_PUSH(Fortran 77)dnl
1046 _AC_FC_WRAPPERS
1047 AC_LANG_POP(Fortran 77)dnl
1048 ])# AC_F77_WRAPPERS
1051 # AC_FC_WRAPPERS
1052 # --------------
1053 AC_DEFUN([AC_FC_WRAPPERS],
1054 [AC_REQUIRE([_AC_FC_NAME_MANGLING])dnl
1055 AC_LANG_PUSH(Fortran)dnl
1056 _AC_FC_WRAPPERS
1057 AC_LANG_POP(Fortran)dnl
1058 ])# AC_FC_WRAPPERS
1061 # _AC_FC_FUNC(NAME, [SHELLVAR = NAME])
1062 # ------------------------------------
1063 # For a Fortran subroutine of given NAME, define a shell variable
1064 # $SHELLVAR to the Fortran-mangled name.  If the SHELLVAR
1065 # argument is not supplied, it defaults to NAME.
1066 AC_DEFUN([_AC_FC_FUNC],
1067 [_AC_FORTRAN_ASSERT()dnl
1068 case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in
1069   upper*) ac_val="m4_toupper([$1])" ;;
1070   lower*) ac_val="m4_tolower([$1])" ;;
1071   *)      ac_val="unknown" ;;
1072 esac
1073 case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in *," underscore"*) ac_val="$ac_val"_ ;; esac
1074 m4_if(m4_index([$1],[_]),-1,[],
1075 [case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in *," extra underscore"*) ac_val="$ac_val"_ ;; esac
1077 m4_default([$2],[$1])="$ac_val"
1078 ])# _AC_FC_FUNC
1081 # AC_F77_FUNC(NAME, [SHELLVAR = NAME])
1082 # ------------------------------------
1083 AC_DEFUN([AC_F77_FUNC],
1084 [AC_REQUIRE([_AC_F77_NAME_MANGLING])dnl
1085 AC_LANG_PUSH(Fortran 77)dnl
1086 _AC_FC_FUNC([$1],[$2])
1087 AC_LANG_POP(Fortran 77)dnl
1088 ])# AC_F77_FUNC
1091 # AC_FC_FUNC(NAME, [SHELLVAR = NAME])
1092 # -----------------------------------
1093 AC_DEFUN([AC_FC_FUNC],
1094 [AC_REQUIRE([_AC_FC_NAME_MANGLING])dnl
1095 AC_LANG_PUSH(Fortran)dnl
1096 _AC_FC_FUNC([$1],[$2])
1097 AC_LANG_POP(Fortran)dnl
1098 ])# AC_FC_FUNC
1101 # AC_FC_SRCEXT(EXT, [ACTION-IF-SUCCESS], [ACTION-IF-FAILURE])
1102 # -----------------------------------------------------------
1103 # Set the source-code extension used in Fortran (FC) tests to EXT (which
1104 # defaults to f).  Also, look for any necessary additional FCFLAGS needed
1105 # to allow this extension, and store them in the output variable
1106 # FCFLAGS_<EXT> (e.g. FCFLAGS_f90 for EXT=f90).  If successful,
1107 # call ACTION-IF-SUCCESS.  If unable to compile source code with EXT,
1108 # call ACTION-IF-FAILURE, which defaults to failing with an error
1109 # message.
1111 # (The flags for the current source-code extension, if any, are stored in
1112 # $ac_fcflags_srcext and used automatically in subsequent autoconf tests.)
1114 # For ordinary extensions like f90, etcetera, the modified FCFLAGS
1115 # are currently needed for IBM's xlf* and Intel's ifc (grrr).  Unfortunately,
1116 # xlf* will only take flags to recognize one extension at a time, so if the
1117 # user wants to compile multiple extensions (.f90 and .f95, say), she
1118 # will need to use the FCFLAGS_F90 and FCFLAGS_F95 individually rather
1119 # than just adding them all to FCFLAGS, for example.
1121 # Also, for Intel's ifc compiler (which does not accept .f95 by default in
1122 # some versions), the $FCFLAGS_<EXT> variable *must* go immediately before
1123 # the source file on the command line, unlike other $FCFLAGS.  Ugh.
1124 AC_DEFUN([AC_FC_SRCEXT],
1125 [AC_LANG_PUSH(Fortran)dnl
1126 AC_CACHE_CHECK([for Fortran flag to compile .$1 files],
1127                 ac_cv_fc_srcext_$1,
1128 [ac_ext=$1
1129 ac_fcflags_srcext_save=$ac_fcflags_srcext
1130 ac_fcflags_srcext=
1131 ac_cv_fc_srcext_$1=unknown
1132 for ac_flag in none -qsuffix=f=$1 -Tf; do
1133   test "x$ac_flag" != xnone && ac_fcflags_srcext="$ac_flag"
1134   AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [ac_cv_fc_srcext_$1=$ac_flag; break])
1135 done
1136 rm -f conftest.$ac_objext conftest.$1
1137 ac_fcflags_srcext=$ac_fcflags_srcext_save
1139 if test "x$ac_cv_fc_srcext_$1" = xunknown; then
1140   m4_default([$3],[AC_MSG_ERROR([Fortran could not compile .$1 files])])
1141 else
1142   ac_fc_srcext=$1
1143   if test "x$ac_cv_fc_srcext_$1" = xnone; then
1144     ac_fcflags_srcext=""
1145     FCFLAGS_[]$1[]=""
1146   else
1147     ac_fcflags_srcext=$ac_cv_fc_srcext_$1
1148     FCFLAGS_[]$1[]=$ac_cv_fc_srcext_$1
1149   fi
1150   AC_SUBST(FCFLAGS_[]$1)
1151   $2
1153 AC_LANG_POP(Fortran)dnl
1154 ])# AC_FC_SRCEXT
1157 # AC_FC_FREEFORM([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1158 # ------------------------------------------------------------------
1159 # Look for a compiler flag to make the Fortran (FC) compiler accept
1160 # free-format source code, and adds it to FCFLAGS.  Call
1161 # ACTION-IF-SUCCESS (defaults to nothing) if successful (i.e. can
1162 # compile code using new extension) and ACTION-IF-FAILURE (defaults to
1163 # failing with an error message) if not.  (Defined via DEFUN_ONCE to
1164 # prevent flag from being added to FCFLAGS multiple times.)
1166 # The known flags are:
1167 #        -ffree-form: GNU g77, gfortran
1168 #         -FR, -free: Intel compiler (icc, ecc, ifort)
1169 #              -free: Compaq compiler (fort), Sun compiler (f95)
1170 #             -qfree: IBM compiler (xlf)
1171 # -Mfree, -Mfreeform: Portland Group compiler
1172 #          -freeform: SGI compiler
1173 #            -f free: Absoft Fortran
1174 #       +source=free: HP Fortran
1175 #              -nfix: Lahey/Fujitsu Fortran
1176 # We try to test the "more popular" flags first, by some prejudiced
1177 # notion of popularity.
1178 AC_DEFUN_ONCE([AC_FC_FREEFORM],
1179 [AC_LANG_PUSH([Fortran])dnl
1180 AC_CACHE_CHECK([for Fortran flag needed to accept free-form source],
1181                [ac_cv_fc_freeform],
1182 [ac_cv_fc_freeform=unknown
1183 ac_fc_freeform_FCFLAGS_save=$FCFLAGS
1184 for ac_flag in none -ffree-form -FR -free -qfree -Mfree -Mfreeform \
1185                -freeform "-f free" +source=free -nfix
1187   test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_freeform_FCFLAGS_save $ac_flag"
1188 dnl Use @&t@ below to ensure that editors don't turn 8+ spaces into tab.
1189   AC_COMPILE_IFELSE([[
1190   program freeform
1191        ! FIXME: how to best confuse non-freeform compilers?
1192        print *, 'Hello ', &
1193      @&t@     'world.'
1194        end]],
1195                     [ac_cv_fc_freeform=$ac_flag; break])
1196 done
1197 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
1198 FCFLAGS=$ac_fc_freeform_FCFLAGS_save
1200 if test "x$ac_cv_fc_freeform" = xunknown; then
1201   m4_default([$2],
1202              [AC_MSG_ERROR([Fortran does not accept free-form source], 77)])
1203 else
1204   if test "x$ac_cv_fc_freeform" != xnone; then
1205     FCFLAGS="$FCFLAGS $ac_cv_fc_freeform"
1206   fi
1207   $1
1209 AC_LANG_POP([Fortran])dnl
1210 ])# AC_FC_FREEFORM
1213 # AC_FC_FIXEDFORM([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1214 # ------------------------------------------------------------------
1215 # Look for a compiler flag to make the Fortran (FC) compiler accept
1216 # fixed-format source code, and adds it to FCFLAGS.  Call
1217 # ACTION-IF-SUCCESS (defaults to nothing) if successful (i.e. can
1218 # compile code using new extension) and ACTION-IF-FAILURE (defaults to
1219 # failing with an error message) if not.  (Defined via DEFUN_ONCE to
1220 # prevent flag from being added to FCFLAGS multiple times.)
1222 # The known flags are:
1223 #       -ffixed-form: GNU g77, gfortran
1224 #             -fixed: Intel compiler (ifort), Sun compiler (f95)
1225 #            -qfixed: IBM compiler (xlf*)
1226 #            -Mfixed: Portland Group compiler
1227 #         -fixedform: SGI compiler
1228 #           -f fixed: Absoft Fortran
1229 #      +source=fixed: HP Fortran
1230 #              -fix: Lahey/Fujitsu Fortran
1231 # Since compilers may accept fixed form based on file name extension,
1232 # but users may want to use it with others as well, call AC_FC_SRCEXT
1233 # with the respective source extension before calling this macro.
1234 AC_DEFUN_ONCE([AC_FC_FIXEDFORM],
1235 [AC_LANG_PUSH([Fortran])dnl
1236 AC_CACHE_CHECK([for Fortran flag needed to accept fixed-form source],
1237                [ac_cv_fc_fixedform],
1238 [ac_cv_fc_fixedform=unknown
1239 ac_fc_fixedform_FCFLAGS_save=$FCFLAGS
1240 for ac_flag in none -ffixed-form -fixed -qfixed -Mfixed -fixedform "-f fixed" \
1241                +source=fixed -fix
1243   test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_fixedform_FCFLAGS_save $ac_flag"
1244   AC_COMPILE_IFELSE([[
1245 C     This comment should confuse free-form compilers.
1246       program main
1247       end]],
1248                     [ac_cv_fc_fixedform=$ac_flag; break])
1249 done
1250 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
1251 FCFLAGS=$ac_fc_fixedform_FCFLAGS_save
1253 if test "x$ac_cv_fc_fixedform" = xunknown; then
1254   m4_default([$2],
1255              [AC_MSG_ERROR([Fortran does not accept fixed-form source], 77)])
1256 else
1257   if test "x$ac_cv_fc_fixedform" != xnone; then
1258     FCFLAGS="$FCFLAGS $ac_cv_fc_fixedform"
1259   fi
1260   $1
1262 AC_LANG_POP([Fortran])dnl
1263 ])# AC_FC_FIXEDFORM
1266 # AC_FC_LINE_LENGTH([LENGTH], [ACTION-IF-SUCCESS],
1267 #                   [ACTION-IF-FAILURE = FAILURE])
1268 # ------------------------------------------------
1269 # Look for a compiler flag to make the Fortran (FC) compiler accept long lines
1270 # in the current (free- or fixed-format) source code, and adds it to FCFLAGS.
1271 # The optional LENGTH may be 80, 132 (default), or `unlimited' for longer
1272 # lines.  Note that line lengths above 254 columns are not portable, and some
1273 # compilers (hello ifort) do not accept more than 132 columns at least for
1274 # fixed format.  Call ACTION-IF-SUCCESS (defaults to nothing) if successful
1275 # (i.e. can compile code using new extension) and ACTION-IF-FAILURE (defaults
1276 # to failing with an error message) if not.  (Defined via DEFUN_ONCE to
1277 # prevent flag from being added to FCFLAGS multiple times.)
1278 # You should call AC_FC_FREEFORM or AC_FC_FIXEDFORM to set the desired format
1279 # prior to using this macro.
1281 # The known flags are:
1282 # -f{free,fixed}-line-length-N with N 72, 80, 132, or 0 or none for none.
1283 # -ffree-line-length-none: GNU gfortran
1284 #       -qfixed=132 80 72: IBM compiler (xlf)
1285 #                -Mextend: Cray
1286 #            -132 -80 -72: Intel compiler (ifort)
1287 #                          Needs to come before -extend_source because ifort
1288 #                          accepts that as well with an optional parameter and
1289 #                          doesn't fail but only warns about unknown arguments.
1290 #          -extend_source: SGI compiler
1291 #     -W NN (132, 80, 72): Absoft Fortran
1292 #          +extend_source: HP Fortran (254 in either form, default is 72 fixed,
1293 #                          132 free)
1294 #                   -wide: Lahey/Fujitsu Fortran (255 cols in fixed form)
1295 #                      -e: Sun Fortran compiler (132 characters)
1296 AC_DEFUN_ONCE([AC_FC_LINE_LENGTH],
1297 [AC_LANG_PUSH([Fortran])dnl
1298 m4_case(m4_default([$1], [132]),
1299   [unlimited], [ac_fc_line_len_string=unlimited
1300                        ac_fc_line_len=0
1301                        ac_fc_line_length_test='
1302       subroutine longer_than_132(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,'\
1303 'arg9,arg10,arg11,arg12,arg13,arg14,arg15,arg16,arg17,arg18,arg19)'],
1304   [132],            [ac_fc_line_len=132
1305                        ac_fc_line_length_test='
1306       subroutine longer_than_80(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,'\
1307 'arg10)'],
1308   [80],             [ac_fc_line_len=80
1309                        ac_fc_line_length_test='
1310       subroutine longer_than_72(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)'],
1311   [m4_warning([Invalid length argument `$1'])])
1312 : ${ac_fc_line_len_string=$ac_fc_line_len}
1313 AC_CACHE_CHECK(
1314 [for Fortran flag needed to accept $ac_fc_line_len_string column source lines],
1315                [ac_cv_fc_line_length],
1316 [ac_cv_fc_line_length=unknown
1317 ac_fc_line_length_FCFLAGS_save=$FCFLAGS
1318 for ac_flag in none \
1319                -ffree-line-length-none -ffixed-line-length-none \
1320                -ffree-line-length-$ac_fc_line_len \
1321                -ffixed-line-length-$ac_fc_line_len \
1322                -qfixed=$ac_fc_line_len -Mextend \
1323                -$ac_fc_line_len -extend_source \
1324                "-W $ac_fc_line_len" +extend_source -wide -e
1326   test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_line_length_FCFLAGS_save $ac_flag"
1327   AC_COMPILE_IFELSE([[$ac_fc_line_length_test
1328       end subroutine]],
1329                     [ac_cv_fc_line_length=$ac_flag; break])
1330 done
1331 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
1332 FCFLAGS=$ac_fc_line_length_FCFLAGS_save
1334 if test "x$ac_cv_fc_line_length" = xunknown; then
1335   m4_default([$3],
1336              [AC_MSG_ERROR([Fortran does not accept long source lines], 77)])
1337 else
1338   if test "x$ac_cv_fc_line_length" != xnone; then
1339     FCFLAGS="$FCFLAGS $ac_cv_fc_line_length"
1340   fi
1341   $2
1343 AC_LANG_POP([Fortran])dnl
1344 ])# AC_FC_LINE_LENGTH