xref: /netbsd-src/external/gpl3/autoconf/dist/lib/autoconf/fortran.m4 (revision d874e91932377fc40d53f102e48fc3ee6f4fe9de)
1*d874e919Schristos# This file is part of Autoconf.                       -*- Autoconf -*-
2*d874e919Schristos# Fortran languages support.
3*d874e919Schristos# Copyright (C) 2001, 2003-2012 Free Software Foundation, Inc.
4*d874e919Schristos
5*d874e919Schristos# This file is part of Autoconf.  This program is free
6*d874e919Schristos# software; you can redistribute it and/or modify it under the
7*d874e919Schristos# terms of the GNU General Public License as published by the
8*d874e919Schristos# Free Software Foundation, either version 3 of the License, or
9*d874e919Schristos# (at your option) any later version.
10*d874e919Schristos#
11*d874e919Schristos# This program is distributed in the hope that it will be useful,
12*d874e919Schristos# but WITHOUT ANY WARRANTY; without even the implied warranty of
13*d874e919Schristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*d874e919Schristos# GNU General Public License for more details.
15*d874e919Schristos#
16*d874e919Schristos# Under Section 7 of GPL version 3, you are granted additional
17*d874e919Schristos# permissions described in the Autoconf Configure Script Exception,
18*d874e919Schristos# version 3.0, as published by the Free Software Foundation.
19*d874e919Schristos#
20*d874e919Schristos# You should have received a copy of the GNU General Public License
21*d874e919Schristos# and a copy of the Autoconf Configure Script Exception along with
22*d874e919Schristos# this program; see the files COPYINGv3 and COPYING.EXCEPTION
23*d874e919Schristos# respectively.  If not, see <http://www.gnu.org/licenses/>.
24*d874e919Schristos
25*d874e919Schristos# Written by David MacKenzie, with help from
26*d874e919Schristos# Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
27*d874e919Schristos# Roland McGrath, Noah Friedman, david d zuhn, and many others.
28*d874e919Schristos
29*d874e919Schristos
30*d874e919Schristos# Table of Contents:
31*d874e919Schristos#
32*d874e919Schristos# Preamble
33*d874e919Schristos#
34*d874e919Schristos# 0. Utility macros
35*d874e919Schristos#
36*d874e919Schristos# 1. Language selection
37*d874e919Schristos#    and routines to produce programs in a given language.
38*d874e919Schristos#
39*d874e919Schristos# 2. Producing programs in a given language.
40*d874e919Schristos#
41*d874e919Schristos# 3. Looking for a compiler
42*d874e919Schristos#    And possibly the associated preprocessor.
43*d874e919Schristos#
44*d874e919Schristos# 4. Compilers' characteristics.
45*d874e919Schristos
46*d874e919Schristos
47*d874e919Schristos
48*d874e919Schristos## ---------- ##
49*d874e919Schristos## Preamble.  ##
50*d874e919Schristos## ---------- ##
51*d874e919Schristos
52*d874e919Schristos# Fortran vs. Fortran 77:
53*d874e919Schristos#   This file contains macros for both "Fortran 77" and "Fortran", where
54*d874e919Schristos# the former is the "classic" autoconf Fortran interface and is intended
55*d874e919Schristos# for legacy F77 codes, while the latter is intended to support newer Fortran
56*d874e919Schristos# dialects.  Fortran 77 uses environment variables F77, FFLAGS, and FLIBS,
57*d874e919Schristos# while Fortran uses FC, FCFLAGS, and FCLIBS.  For each user-callable AC_*
58*d874e919Schristos# macro, there is generally both an F77 and an FC version, where both versions
59*d874e919Schristos# share the same _AC_*_FC_* backend.  This backend macro requires that
60*d874e919Schristos# the appropriate language be AC_LANG_PUSH'ed, and uses _AC_LANG_ABBREV and
61*d874e919Schristos# _AC_LANG_PREFIX in order to name cache and environment variables, etc.
62*d874e919Schristos
63*d874e919Schristos
64*d874e919Schristos
65*d874e919Schristos## ------------------- ##
66*d874e919Schristos## 0. Utility macros.  ##
67*d874e919Schristos## ------------------- ##
68*d874e919Schristos
69*d874e919Schristos
70*d874e919Schristos# _AC_LIST_MEMBER_IF(ELEMENT, LIST, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
71*d874e919Schristos# ---------------------------------------------------------------------------
72*d874e919Schristos#
73*d874e919Schristos# Processing the elements of a list is tedious in shell programming,
74*d874e919Schristos# as lists tend to be implemented as space delimited strings.
75*d874e919Schristos#
76*d874e919Schristos# This macro searches LIST for ELEMENT, and executes ACTION-IF-FOUND
77*d874e919Schristos# if ELEMENT is a member of LIST, otherwise it executes
78*d874e919Schristos# ACTION-IF-NOT-FOUND.
79*d874e919SchristosAC_DEFUN([_AC_LIST_MEMBER_IF],
80*d874e919Schristosdnl Do some sanity checking of the arguments.
81*d874e919Schristos[m4_if([$1], , [m4_fatal([$0: missing argument 1])],
82*d874e919Schristos      [$2], , [m4_fatal([$0: missing argument 2])])]dnl
83*d874e919Schristos[  ac_exists=false
84*d874e919Schristos  for ac_i in $2; do
85*d874e919Schristos    if test x"$1" = x"$ac_i"; then
86*d874e919Schristos      ac_exists=true
87*d874e919Schristos      break
88*d874e919Schristos    fi
89*d874e919Schristos  done
90*d874e919Schristos
91*d874e919Schristos  AS_IF([test x"$ac_exists" = xtrue], [$3], [$4])[]dnl
92*d874e919Schristos])# _AC_LIST_MEMBER_IF
93*d874e919Schristos
94*d874e919Schristos
95*d874e919Schristos# _AC_LINKER_OPTION(LINKER-OPTIONS, SHELL-VARIABLE)
96*d874e919Schristos# -------------------------------------------------
97*d874e919Schristos#
98*d874e919Schristos# Specifying options to the compiler (whether it be the C, C++ or
99*d874e919Schristos# Fortran 77 compiler) that are meant for the linker is compiler
100*d874e919Schristos# dependent.  This macro lets you give options to the compiler that
101*d874e919Schristos# are meant for the linker in a portable, compiler-independent way.
102*d874e919Schristos#
103*d874e919Schristos# This macro take two arguments, a list of linker options that the
104*d874e919Schristos# compiler should pass to the linker (LINKER-OPTIONS) and the name of
105*d874e919Schristos# a shell variable (SHELL-VARIABLE).  The list of linker options are
106*d874e919Schristos# appended to the shell variable in a compiler-dependent way.
107*d874e919Schristos#
108*d874e919Schristos# For example, if the selected language is C, then this:
109*d874e919Schristos#
110*d874e919Schristos#   _AC_LINKER_OPTION([-R /usr/local/lib/foo], foo_LDFLAGS)
111*d874e919Schristos#
112*d874e919Schristos# will expand into this if the selected C compiler is gcc:
113*d874e919Schristos#
114*d874e919Schristos#   foo_LDFLAGS="-Xlinker -R -Xlinker /usr/local/lib/foo"
115*d874e919Schristos#
116*d874e919Schristos# otherwise, it will expand into this:
117*d874e919Schristos#
118*d874e919Schristos#   foo_LDFLAGS"-R /usr/local/lib/foo"
119*d874e919Schristos#
120*d874e919Schristos# You are encouraged to add support for compilers that this macro
121*d874e919Schristos# doesn't currently support.
122*d874e919Schristos# FIXME: Get rid of this macro.
123*d874e919SchristosAC_DEFUN([_AC_LINKER_OPTION],
124*d874e919Schristos[if test "$ac_compiler_gnu" = yes; then
125*d874e919Schristos  for ac_link_opt in $1; do
126*d874e919Schristos    $2="[$]$2 -Xlinker $ac_link_opt"
127*d874e919Schristos  done
128*d874e919Schristoselse
129*d874e919Schristos  $2="[$]$2 $1"
130*d874e919Schristosfi[]dnl
131*d874e919Schristos])# _AC_LINKER_OPTION
132*d874e919Schristos
133*d874e919Schristos
134*d874e919Schristos
135*d874e919Schristos## ------------------------ ##
136*d874e919Schristos## 1a. Language selection.  ##
137*d874e919Schristos## ------------------------ ##
138*d874e919Schristos
139*d874e919Schristos
140*d874e919Schristos# AC_LANG(Fortran 77)
141*d874e919Schristos# -------------------
142*d874e919SchristosAC_LANG_DEFINE([Fortran 77], [f77], [F], [F77], [],
143*d874e919Schristos[ac_ext=f
144*d874e919Schristosac_compile='$F77 -c $FFLAGS conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
145*d874e919Schristosac_link='$F77 -o conftest$ac_exeext $FFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
146*d874e919Schristosac_compiler_gnu=$ac_cv_f77_compiler_gnu
147*d874e919Schristos])
148*d874e919Schristos
149*d874e919Schristos
150*d874e919Schristos# AC_LANG_FORTRAN77
151*d874e919Schristos# -----------------
152*d874e919SchristosAU_DEFUN([AC_LANG_FORTRAN77], [AC_LANG(Fortran 77)])
153*d874e919Schristos
154*d874e919Schristos
155*d874e919Schristos# _AC_FORTRAN_ASSERT
156*d874e919Schristos# ------------------
157*d874e919Schristos# Current language must be Fortran or Fortran 77.
158*d874e919Schristosm4_defun([_AC_FORTRAN_ASSERT],
159*d874e919Schristos[m4_if(_AC_LANG, [Fortran], [],
160*d874e919Schristos       [m4_if(_AC_LANG, [Fortran 77], [],
161*d874e919Schristos	      [m4_fatal([$0: current language is not Fortran: ] _AC_LANG)])])])
162*d874e919Schristos
163*d874e919Schristos
164*d874e919Schristos# _AC_FC
165*d874e919Schristos# ------
166*d874e919Schristos# Return F77 or FC, depending upon the language.
167*d874e919SchristosAC_DEFUN([_AC_FC],
168*d874e919Schristos[_AC_FORTRAN_ASSERT()dnl
169*d874e919SchristosAC_LANG_CASE([Fortran 77], [F77],
170*d874e919Schristos	     [Fortran],    [FC])])
171*d874e919Schristos
172*d874e919Schristos
173*d874e919Schristos
174*d874e919Schristos## ----------------------- ##
175*d874e919Schristos## 2. Producing programs.  ##
176*d874e919Schristos## ----------------------- ##
177*d874e919Schristos
178*d874e919Schristos
179*d874e919Schristos# AC_LANG_PROGRAM(Fortran 77)([PROLOGUE], [BODY])
180*d874e919Schristos# -----------------------------------------------
181*d874e919Schristos# Yes, we discard the PROLOGUE.
182*d874e919Schristosm4_define([AC_LANG_PROGRAM(Fortran 77)],
183*d874e919Schristos[m4_ifval([$1],
184*d874e919Schristos       [m4_warn([syntax], [$0: ignoring PROLOGUE: $1])])dnl
185*d874e919Schristos      program main
186*d874e919Schristos$2
187*d874e919Schristos      end])
188*d874e919Schristos
189*d874e919Schristos
190*d874e919Schristos# _AC_LANG_IO_PROGRAM(Fortran 77)
191*d874e919Schristos# -------------------------------
192*d874e919Schristos# Produce source that performs I/O.
193*d874e919Schristosm4_define([_AC_LANG_IO_PROGRAM(Fortran 77)],
194*d874e919Schristos[AC_LANG_PROGRAM([],
195*d874e919Schristos[dnl
196*d874e919Schristos      open(unit=9,file='conftest.out')
197*d874e919Schristos      close(unit=9)
198*d874e919Schristos])])
199*d874e919Schristos
200*d874e919Schristos
201*d874e919Schristos# AC_LANG_CALL(Fortran 77)(PROLOGUE, FUNCTION)
202*d874e919Schristos# --------------------------------------------
203*d874e919Schristos# FIXME: This is a guess, help!
204*d874e919Schristosm4_define([AC_LANG_CALL(Fortran 77)],
205*d874e919Schristos[AC_LANG_PROGRAM([$1],
206*d874e919Schristos[      call $2])])
207*d874e919Schristos
208*d874e919Schristos
209*d874e919Schristos# AC_LANG_FUNC_LINK_TRY(Fortran 77)(FUNCTION)
210*d874e919Schristos# -------------------------------------------
211*d874e919Schristosm4_define([AC_LANG_FUNC_LINK_TRY(Fortran 77)],
212*d874e919Schristos[AC_LANG_PROGRAM([],
213*d874e919Schristos[      call $1])])
214*d874e919Schristos
215*d874e919Schristos## ------------------------ ##
216*d874e919Schristos## 1b. Language selection.  ##
217*d874e919Schristos## ------------------------ ##
218*d874e919Schristos
219*d874e919Schristos
220*d874e919Schristos# AC_LANG(Fortran)
221*d874e919Schristos# ----------------
222*d874e919SchristosAC_LANG_DEFINE([Fortran], [fc], [FC], [FC], [Fortran 77],
223*d874e919Schristos[ac_ext=${ac_fc_srcext-f}
224*d874e919Schristosac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
225*d874e919Schristosac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext conftest.$ac_ext $LIBS >&AS_MESSAGE_LOG_FD'
226*d874e919Schristosac_compiler_gnu=$ac_cv_fc_compiler_gnu
227*d874e919Schristos])
228*d874e919Schristos
229*d874e919Schristos
230*d874e919Schristos## -------------------------------------------- ##
231*d874e919Schristos## 3. Looking for Compilers and Preprocessors.  ##
232*d874e919Schristos## -------------------------------------------- ##
233*d874e919Schristos
234*d874e919Schristos
235*d874e919Schristos# AC_LANG_PREPROC(Fortran 77)
236*d874e919Schristos# ---------------------------
237*d874e919Schristos# Find the Fortran 77 preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
238*d874e919SchristosAC_DEFUN([AC_LANG_PREPROC(Fortran 77)],
239*d874e919Schristos[m4_warn([syntax],
240*d874e919Schristos	 [$0: No preprocessor defined for ]_AC_LANG)])
241*d874e919Schristos
242*d874e919Schristos# AC_LANG_PREPROC(Fortran)
243*d874e919Schristos# ------------------------
244*d874e919Schristos# Find the Fortran preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
245*d874e919SchristosAC_DEFUN([AC_LANG_PREPROC(Fortran)],
246*d874e919Schristos[m4_warn([syntax],
247*d874e919Schristos	 [$0: No preprocessor defined for ]_AC_LANG)])
248*d874e919Schristos
249*d874e919Schristos
250*d874e919Schristos# AC_LANG_COMPILER(Fortran 77)
251*d874e919Schristos# ----------------------------
252*d874e919Schristos# Find the Fortran 77 compiler.  Must be AC_DEFUN'd to be
253*d874e919Schristos# AC_REQUIRE'able.
254*d874e919SchristosAC_DEFUN([AC_LANG_COMPILER(Fortran 77)],
255*d874e919Schristos[AC_REQUIRE([AC_PROG_F77])])
256*d874e919Schristos
257*d874e919Schristos# AC_LANG_COMPILER(Fortran)
258*d874e919Schristos# -------------------------
259*d874e919Schristos# Find the Fortran compiler.  Must be AC_DEFUN'd to be
260*d874e919Schristos# AC_REQUIRE'able.
261*d874e919SchristosAC_DEFUN([AC_LANG_COMPILER(Fortran)],
262*d874e919Schristos[AC_REQUIRE([AC_PROG_FC])])
263*d874e919Schristos
264*d874e919Schristos
265*d874e919Schristos# ac_cv_prog_g77
266*d874e919Schristos# --------------
267*d874e919Schristos# We used to name the cache variable this way.
268*d874e919SchristosAU_DEFUN([ac_cv_prog_g77],
269*d874e919Schristos[ac_cv_f77_compiler_gnu])
270*d874e919Schristos
271*d874e919Schristos
272*d874e919Schristos# _AC_FC_DIALECT_YEAR([DIALECT])
273*d874e919Schristos# ------------------------------
274*d874e919Schristos# Given a Fortran DIALECT, which is Fortran [YY]YY or simply [YY]YY,
275*d874e919Schristos# convert to a 4-digit year.  The dialect must be one of Fortran 77,
276*d874e919Schristos# 90, 95, or 2000, currently.  If DIALECT is simply Fortran or the
277*d874e919Schristos# empty string, returns the empty string.
278*d874e919SchristosAC_DEFUN([_AC_FC_DIALECT_YEAR],
279*d874e919Schristos[m4_case(m4_bpatsubsts(m4_tolower([$1]), [fortran],[], [ *],[]),
280*d874e919Schristos	 [77],[1977], [1977],[1977],
281*d874e919Schristos	 [90],[1990], [1990],[1990],
282*d874e919Schristos	 [95],[1995], [1995],[1995],
283*d874e919Schristos	 [2000],[2000],
284*d874e919Schristos	 [],[],
285*d874e919Schristos	 [m4_fatal([unknown Fortran dialect])])])
286*d874e919Schristos
287*d874e919Schristos
288*d874e919Schristos# _AC_PROG_FC([DIALECT], [COMPILERS...])
289*d874e919Schristos# --------------------------------------
290*d874e919Schristos# DIALECT is a Fortran dialect, given by Fortran [YY]YY or simply [YY]YY,
291*d874e919Schristos# and must be one of those supported by _AC_FC_DIALECT_YEAR
292*d874e919Schristos#
293*d874e919Schristos# If DIALECT is supplied, then we search for compilers of that dialect
294*d874e919Schristos# first, and then later dialects.  Otherwise, we search for compilers
295*d874e919Schristos# of the newest dialect first, and then earlier dialects in increasing age.
296*d874e919Schristos# This search order is necessarily imperfect because the dialect cannot
297*d874e919Schristos# always be inferred from the compiler name.
298*d874e919Schristos#
299*d874e919Schristos# Known compilers:
300*d874e919Schristos#  f77/f90/f95: generic compiler names
301*d874e919Schristos#  g77: GNU Fortran 77 compiler
302*d874e919Schristos#  gfortran: GNU Fortran 95+ compiler (released in gcc 4.0)
303*d874e919Schristos#  g95: original gcc-based f95 compiler (gfortran is a fork)
304*d874e919Schristos#  ftn: native Fortran 95 compiler on Cray X1
305*d874e919Schristos#  cf77: native F77 compiler under older Crays (prefer over fort77)
306*d874e919Schristos#  fort77: native F77 compiler under HP-UX (and some older Crays)
307*d874e919Schristos#  frt: Fujitsu F77 compiler
308*d874e919Schristos#  pgf77/pgf90/pghpf/pgf95/pgfortran: Portland Group F77/F90/F95 compilers
309*d874e919Schristos#  xlf/xlf90/xlf95: IBM (AIX) F77/F90/F95 compilers
310*d874e919Schristos#    Prefer xlf9x to the generic names because they do not reject files
311*d874e919Schristos#    with extension `.f'.
312*d874e919Schristos#  lf95: Lahey-Fujitsu F95 compiler
313*d874e919Schristos#  fl32: Microsoft Fortran 77 "PowerStation" compiler
314*d874e919Schristos#  af77: Apogee F77 compiler for Intergraph hardware running CLIX
315*d874e919Schristos#  epcf90: "Edinburgh Portable Compiler" F90
316*d874e919Schristos#  fort: Compaq (now HP) Fortran 90/95 compiler for Tru64 and Linux/Alpha
317*d874e919Schristos#  ifort, previously ifc: Intel Fortran 95 compiler for Linux/x86
318*d874e919Schristos#  efc: Intel Fortran 95 compiler for IA64
319*d874e919Schristos#  nagfor: NAGWare Fortran 77/90/95 compiler
320*d874e919Schristosm4_define([_AC_F95_FC], [gfortran g95 xlf95 f95 fort ifort ifc efc pgfortran pgf95 lf95 ftn nagfor])
321*d874e919Schristosm4_define([_AC_F90_FC], [xlf90 f90 pgf90 pghpf epcf90])
322*d874e919Schristosm4_define([_AC_F77_FC], [g77 xlf f77 frt pgf77 cf77 fort77 fl32 af77])
323*d874e919SchristosAC_DEFUN([_AC_PROG_FC],
324*d874e919Schristos[_AC_FORTRAN_ASSERT()dnl
325*d874e919SchristosAC_CHECK_TOOLS([]_AC_FC[],
326*d874e919Schristos      m4_default([$2],
327*d874e919Schristos	m4_case(_AC_FC_DIALECT_YEAR([$1]),
328*d874e919Schristos		[1995], [_AC_F95_FC],
329*d874e919Schristos		[1990], [_AC_F90_FC _AC_F95_FC],
330*d874e919Schristos		[1977], [_AC_F77_FC _AC_F90_FC _AC_F95_FC],
331*d874e919Schristos		[_AC_F95_FC _AC_F90_FC _AC_F77_FC])))
332*d874e919Schristos
333*d874e919Schristos# Provide some information about the compiler.
334*d874e919Schristos_AS_ECHO_LOG([checking for _AC_LANG compiler version])
335*d874e919Schristosset X $ac_compile
336*d874e919Schristosac_compiler=$[2]
337*d874e919Schristosfor ac_option in --version -v -V -qversion; do
338*d874e919Schristos  _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
339*d874e919Schristosdone
340*d874e919Schristosrm -f a.out
341*d874e919Schristos
342*d874e919Schristosm4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
343*d874e919Schristosm4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
344*d874e919Schristos# If we don't use `.F' as extension, the preprocessor is not run on the
345*d874e919Schristos# input file.  (Note that this only needs to work for GNU compilers.)
346*d874e919Schristosac_save_ext=$ac_ext
347*d874e919Schristosac_ext=F
348*d874e919Schristos_AC_LANG_COMPILER_GNU
349*d874e919Schristosac_ext=$ac_save_ext
350*d874e919Schristos_AC_PROG_FC_G
351*d874e919Schristos])# _AC_PROG_FC
352*d874e919Schristos
353*d874e919Schristos
354*d874e919Schristos# AC_PROG_F77([COMPILERS...])
355*d874e919Schristos# ---------------------------
356*d874e919Schristos# COMPILERS is a space separated list of Fortran 77 compilers to search
357*d874e919Schristos# for.  See also _AC_PROG_FC.
358*d874e919SchristosAC_DEFUN([AC_PROG_F77],
359*d874e919Schristos[AC_LANG_PUSH(Fortran 77)dnl
360*d874e919SchristosAC_ARG_VAR([F77],    [Fortran 77 compiler command])dnl
361*d874e919SchristosAC_ARG_VAR([FFLAGS], [Fortran 77 compiler flags])dnl
362*d874e919Schristos_AC_ARG_VAR_LDFLAGS()dnl
363*d874e919Schristos_AC_ARG_VAR_LIBS()dnl
364*d874e919Schristos_AC_PROG_FC([Fortran 77], [$1])
365*d874e919Schristosif test $ac_compiler_gnu = yes; then
366*d874e919Schristos  G77=yes
367*d874e919Schristoselse
368*d874e919Schristos  G77=
369*d874e919Schristosfi
370*d874e919SchristosAC_LANG_POP(Fortran 77)dnl
371*d874e919Schristos])# AC_PROG_F77
372*d874e919Schristos
373*d874e919Schristos
374*d874e919Schristos# AC_PROG_FC([COMPILERS...], [DIALECT])
375*d874e919Schristos# -------------------------------------
376*d874e919Schristos# COMPILERS is a space separated list of Fortran 77 compilers to search
377*d874e919Schristos# for, and [DIALECT] is an optional dialect.  See also _AC_PROG_FC.
378*d874e919SchristosAC_DEFUN([AC_PROG_FC],
379*d874e919Schristos[AC_LANG_PUSH(Fortran)dnl
380*d874e919SchristosAC_ARG_VAR([FC],    [Fortran compiler command])dnl
381*d874e919SchristosAC_ARG_VAR([FCFLAGS], [Fortran compiler flags])dnl
382*d874e919Schristos_AC_ARG_VAR_LDFLAGS()dnl
383*d874e919Schristos_AC_ARG_VAR_LIBS()dnl
384*d874e919Schristos_AC_PROG_FC([$2], [$1])
385*d874e919Schristosif test $ac_compiler_gnu = yes; then
386*d874e919Schristos  GFC=yes
387*d874e919Schristoselse
388*d874e919Schristos  GFC=
389*d874e919Schristosfi
390*d874e919SchristosAC_LANG_POP(Fortran)dnl
391*d874e919Schristos])# AC_PROG_FC
392*d874e919Schristos
393*d874e919Schristos
394*d874e919Schristos# _AC_PROG_FC_G
395*d874e919Schristos# -------------
396*d874e919Schristos# Check whether -g works, even if F[C]FLAGS is set, in case the package
397*d874e919Schristos# plays around with F[C]FLAGS (such as to build both debugging and normal
398*d874e919Schristos# versions of a library), tasteless as that idea is.
399*d874e919Schristosm4_define([_AC_PROG_FC_G],
400*d874e919Schristos[_AC_FORTRAN_ASSERT()dnl
401*d874e919Schristosac_test_[]_AC_LANG_PREFIX[]FLAGS=${[]_AC_LANG_PREFIX[]FLAGS+set}
402*d874e919Schristosac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
403*d874e919Schristos_AC_LANG_PREFIX[]FLAGS=
404*d874e919SchristosAC_CACHE_CHECK(whether $[]_AC_FC[] accepts -g, ac_cv_prog_[]_AC_LANG_ABBREV[]_g,
405*d874e919Schristos[_AC_LANG_PREFIX[]FLAGS=-g
406*d874e919Schristos_AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
407*d874e919Schristos[ac_cv_prog_[]_AC_LANG_ABBREV[]_g=yes],
408*d874e919Schristos[ac_cv_prog_[]_AC_LANG_ABBREV[]_g=no])
409*d874e919Schristos])
410*d874e919Schristosif test "$ac_test_[]_AC_LANG_PREFIX[]FLAGS" = set; then
411*d874e919Schristos  _AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
412*d874e919Schristoselif test $ac_cv_prog_[]_AC_LANG_ABBREV[]_g = yes; then
413*d874e919Schristos  if test "x$ac_cv_[]_AC_LANG_ABBREV[]_compiler_gnu" = xyes; then
414*d874e919Schristos    _AC_LANG_PREFIX[]FLAGS="-g -O2"
415*d874e919Schristos  else
416*d874e919Schristos    _AC_LANG_PREFIX[]FLAGS="-g"
417*d874e919Schristos  fi
418*d874e919Schristoselse
419*d874e919Schristos  if test "x$ac_cv_[]_AC_LANG_ABBREV[]_compiler_gnu" = xyes; then
420*d874e919Schristos    _AC_LANG_PREFIX[]FLAGS="-O2"
421*d874e919Schristos  else
422*d874e919Schristos    _AC_LANG_PREFIX[]FLAGS=
423*d874e919Schristos  fi
424*d874e919Schristosfi[]dnl
425*d874e919Schristos])# _AC_PROG_FC_G
426*d874e919Schristos
427*d874e919Schristos
428*d874e919Schristos# _AC_PROG_FC_C_O
429*d874e919Schristos# ---------------
430*d874e919Schristos# Test if the Fortran compiler accepts the options `-c' and `-o'
431*d874e919Schristos# simultaneously, and define `[F77/FC]_NO_MINUS_C_MINUS_O' if it does not.
432*d874e919Schristos#
433*d874e919Schristos# The usefulness of this macro is questionable, as I can't really see
434*d874e919Schristos# why anyone would use it.  The only reason I include it is for
435*d874e919Schristos# completeness, since a similar test exists for the C compiler.
436*d874e919Schristos#
437*d874e919Schristos# FIXME: it seems like we could merge the C/C++/Fortran versions of this.
438*d874e919SchristosAC_DEFUN([_AC_PROG_FC_C_O],
439*d874e919Schristos[_AC_FORTRAN_ASSERT()dnl
440*d874e919SchristosAC_CACHE_CHECK([whether $[]_AC_FC[] understands -c and -o together],
441*d874e919Schristos	       [ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o],
442*d874e919Schristos[AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
443*d874e919Schristos# We test twice because some compilers refuse to overwrite an existing
444*d874e919Schristos# `.o' file with `-o', although they will create one.
445*d874e919Schristosac_try='$[]_AC_FC[] $[]_AC_LANG_PREFIX[]FLAGS -c conftest.$ac_ext -o conftest2.$ac_objext >&AS_MESSAGE_LOG_FD'
446*d874e919Schristosrm -f conftest2.*
447*d874e919Schristosif _AC_DO_VAR(ac_try) &&
448*d874e919Schristos     test -f conftest2.$ac_objext &&
449*d874e919Schristos     _AC_DO_VAR(ac_try); then
450*d874e919Schristos  ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o=yes
451*d874e919Schristoselse
452*d874e919Schristos  ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o=no
453*d874e919Schristosfi
454*d874e919Schristosrm -f conftest*])
455*d874e919Schristosif test $ac_cv_prog_[]_AC_LANG_ABBREV[]_c_o = no; then
456*d874e919Schristos  AC_DEFINE([]_AC_FC[]_NO_MINUS_C_MINUS_O, 1,
457*d874e919Schristos	    [Define to 1 if your Fortran compiler doesn't accept
458*d874e919Schristos	     -c and -o together.])
459*d874e919Schristosfi
460*d874e919Schristos])# _AC_PROG_FC_C_O
461*d874e919Schristos
462*d874e919Schristos
463*d874e919Schristos# AC_PROG_F77_C_O
464*d874e919Schristos# ---------------
465*d874e919SchristosAC_DEFUN([AC_PROG_F77_C_O],
466*d874e919Schristos[AC_REQUIRE([AC_PROG_F77])dnl
467*d874e919SchristosAC_LANG_PUSH(Fortran 77)dnl
468*d874e919Schristos_AC_PROG_FC_C_O
469*d874e919SchristosAC_LANG_POP(Fortran 77)dnl
470*d874e919Schristos])# AC_PROG_F77_C_O
471*d874e919Schristos
472*d874e919Schristos
473*d874e919Schristos# AC_PROG_FC_C_O
474*d874e919Schristos# --------------
475*d874e919SchristosAC_DEFUN([AC_PROG_FC_C_O],
476*d874e919Schristos[AC_REQUIRE([AC_PROG_FC])dnl
477*d874e919SchristosAC_LANG_PUSH(Fortran)dnl
478*d874e919Schristos_AC_PROG_FC_C_O
479*d874e919SchristosAC_LANG_POP(Fortran)dnl
480*d874e919Schristos])# AC_PROG_FC_C_O
481*d874e919Schristos
482*d874e919Schristos
483*d874e919Schristos
484*d874e919Schristos## ------------------------------- ##
485*d874e919Schristos## 4. Compilers' characteristics.  ##
486*d874e919Schristos## ------------------------------- ##
487*d874e919Schristos
488*d874e919Schristos
489*d874e919Schristos# _AC_PROG_FC_V_OUTPUT([FLAG = $ac_cv_prog_{f77/fc}_v])
490*d874e919Schristos# -----------------------------------------------------
491*d874e919Schristos# Link a trivial Fortran program, compiling with a verbose output FLAG
492*d874e919Schristos# (whose default value, $ac_cv_prog_{f77/fc}_v, is computed by
493*d874e919Schristos# _AC_PROG_FC_V), and return the output in $ac_{f77/fc}_v_output.  This
494*d874e919Schristos# output is processed in the way expected by _AC_FC_LIBRARY_LDFLAGS,
495*d874e919Schristos# so that any link flags that are echoed by the compiler appear as
496*d874e919Schristos# space-separated items.
497*d874e919SchristosAC_DEFUN([_AC_PROG_FC_V_OUTPUT],
498*d874e919Schristos[_AC_FORTRAN_ASSERT()dnl
499*d874e919SchristosAC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
500*d874e919Schristos
501*d874e919Schristos# Compile and link our simple test program by passing a flag (argument
502*d874e919Schristos# 1 to this macro) to the Fortran compiler in order to get
503*d874e919Schristos# "verbose" output that we can then parse for the Fortran linker
504*d874e919Schristos# flags.
505*d874e919Schristosac_save_[]_AC_LANG_PREFIX[]FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
506*d874e919Schristos_AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS m4_default([$1], [$ac_cv_prog_[]_AC_LANG_ABBREV[]_v])"
507*d874e919Schristoseval "set x $ac_link"
508*d874e919Schristosshift
509*d874e919Schristos_AS_ECHO_LOG([$[*]])
510*d874e919Schristos# gfortran 4.3 outputs lines setting COLLECT_GCC_OPTIONS, COMPILER_PATH,
511*d874e919Schristos# LIBRARY_PATH; skip all such settings.
512*d874e919Schristosac_[]_AC_LANG_ABBREV[]_v_output=`eval $ac_link AS_MESSAGE_LOG_FD>&1 2>&1 |
513*d874e919Schristos  sed '/^Driving:/d; /^Configured with:/d;
514*d874e919Schristos      '"/^[[_$as_cr_Letters]][[_$as_cr_alnum]]*=/d"`
515*d874e919SchristosAS_ECHO(["$ac_[]_AC_LANG_ABBREV[]_v_output"]) >&AS_MESSAGE_LOG_FD
516*d874e919Schristos_AC_LANG_PREFIX[]FLAGS=$ac_save_[]_AC_LANG_PREFIX[]FLAGS
517*d874e919Schristos
518*d874e919Schristosrm -rf conftest*
519*d874e919Schristos
520*d874e919Schristos# On HP/UX there is a line like: "LPATH is: /foo:/bar:/baz" where
521*d874e919Schristos# /foo, /bar, and /baz are search directories for the Fortran linker.
522*d874e919Schristos# Here, we change these into -L/foo -L/bar -L/baz (and put it first):
523*d874e919Schristosac_[]_AC_LANG_ABBREV[]_v_output="`echo $ac_[]_AC_LANG_ABBREV[]_v_output |
524*d874e919Schristos	grep 'LPATH is:' |
525*d874e919Schristos	sed 's|.*LPATH is\(: *[[^ ]]*\).*|\1|;s|: */| -L/|g'` $ac_[]_AC_LANG_ABBREV[]_v_output"
526*d874e919Schristos
527*d874e919Schristos# FIXME: we keep getting bitten by quoted arguments; a more general fix
528*d874e919Schristos#        that detects unbalanced quotes in FLIBS should be implemented
529*d874e919Schristos#        and (ugh) tested at some point.
530*d874e919Schristoscase $ac_[]_AC_LANG_ABBREV[]_v_output in
531*d874e919Schristos  # With xlf replace commas with spaces,
532*d874e919Schristos  # and remove "-link" and closing parenthesis.
533*d874e919Schristos  *xlfentry*)
534*d874e919Schristos    ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output |
535*d874e919Schristos      sed '
536*d874e919Schristos        s/,/ /g
537*d874e919Schristos        s/ -link / /g
538*d874e919Schristos        s/) *$//
539*d874e919Schristos      '
540*d874e919Schristos    ` ;;
541*d874e919Schristos
542*d874e919Schristos  # With Intel ifc, ignore the quoted -mGLOB_options_string stuff (quoted
543*d874e919Schristos  # $LIBS confuse us, and the libraries appear later in the output anyway).
544*d874e919Schristos  *mGLOB_options_string*)
545*d874e919Schristos    ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed 's/"-mGLOB[[^"]]*"/ /g'` ;;
546*d874e919Schristos
547*d874e919Schristos  # Portland Group compiler has singly- or doubly-quoted -cmdline argument
548*d874e919Schristos  # Singly-quoted arguments were reported for versions 5.2-4 and 6.0-4.
549*d874e919Schristos  # Doubly-quoted arguments were reported for "PGF90/x86 Linux/x86 5.0-2".
550*d874e919Schristos  *-cmdline\ * | *-ignore\ * | *-def\ *)
551*d874e919Schristos    ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed "\
552*d874e919Schristos	s/-cmdline  *'[[^']]*'/ /g; s/-cmdline  *\"[[^\"]]*\"/ /g
553*d874e919Schristos	s/-ignore  *'[[^']]*'/ /g; s/-ignore  *\"[[^\"]]*\"/ /g
554*d874e919Schristos	s/-def  *'[[^']]*'/ /g; s/-def  *\"[[^\"]]*\"/ /g"` ;;
555*d874e919Schristos
556*d874e919Schristos  # If we are using fort77 (the f2c wrapper) then filter output and delete quotes.
557*d874e919Schristos  *fort77*f2c*gcc*)
558*d874e919Schristos    ac_[]_AC_LANG_ABBREV[]_v_output=`echo "$ac_[]_AC_LANG_ABBREV[]_v_output" | sed -n '
559*d874e919Schristos        /:[[	 ]]\+Running[[	 ]]\{1,\}"gcc"/{
560*d874e919Schristos          /"-c"/d
561*d874e919Schristos          /[[.]]c"*/d
562*d874e919Schristos          s/^.*"gcc"/"gcc"/
563*d874e919Schristos          s/"//gp
564*d874e919Schristos        }'` ;;
565*d874e919Schristos
566*d874e919Schristos  # If we are using Cray Fortran then delete quotes.
567*d874e919Schristos  *cft90*)
568*d874e919Schristos    ac_[]_AC_LANG_ABBREV[]_v_output=`echo $ac_[]_AC_LANG_ABBREV[]_v_output | sed 's/"//g'` ;;
569*d874e919Schristosesac
570*d874e919Schristos
571*d874e919Schristos])# _AC_PROG_FC_V_OUTPUT
572*d874e919Schristos
573*d874e919Schristos
574*d874e919Schristos# _AC_PROG_FC_V
575*d874e919Schristos# -------------
576*d874e919Schristos#
577*d874e919Schristos# Determine the flag that causes the Fortran compiler to print
578*d874e919Schristos# information of library and object files (normally -v)
579*d874e919Schristos# Needed for _AC_FC_LIBRARY_FLAGS
580*d874e919Schristos# Some compilers don't accept -v (Lahey: (-)-verbose, xlf: -V, Fujitsu: -###)
581*d874e919SchristosAC_DEFUN([_AC_PROG_FC_V],
582*d874e919Schristos[_AC_FORTRAN_ASSERT()dnl
583*d874e919SchristosAC_CACHE_CHECK([how to get verbose linking output from $[]_AC_FC[]],
584*d874e919Schristos		[ac_cv_prog_[]_AC_LANG_ABBREV[]_v],
585*d874e919Schristos[AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
586*d874e919Schristos[ac_cv_prog_[]_AC_LANG_ABBREV[]_v=
587*d874e919Schristos# Try some options frequently used verbose output
588*d874e919Schristosfor ac_verb in -v -verbose --verbose -V -\#\#\#; do
589*d874e919Schristos  _AC_PROG_FC_V_OUTPUT($ac_verb)
590*d874e919Schristos  # look for -l* and *.a constructs in the output
591*d874e919Schristos  for ac_arg in $ac_[]_AC_LANG_ABBREV[]_v_output; do
592*d874e919Schristos     case $ac_arg in
593*d874e919Schristos	[[\\/]]*.a | ?:[[\\/]]*.a | -[[lLRu]]*)
594*d874e919Schristos	  ac_cv_prog_[]_AC_LANG_ABBREV[]_v=$ac_verb
595*d874e919Schristos	  break 2 ;;
596*d874e919Schristos     esac
597*d874e919Schristos  done
598*d874e919Schristosdone
599*d874e919Schristosif test -z "$ac_cv_prog_[]_AC_LANG_ABBREV[]_v"; then
600*d874e919Schristos   AC_MSG_WARN([cannot determine how to obtain linking information from $[]_AC_FC[]])
601*d874e919Schristosfi],
602*d874e919Schristos		  [AC_MSG_WARN([compilation failed])])
603*d874e919Schristos])])# _AC_PROG_FC_V
604*d874e919Schristos
605*d874e919Schristos
606*d874e919Schristos# _AC_FC_LIBRARY_LDFLAGS
607*d874e919Schristos# ----------------------
608*d874e919Schristos#
609*d874e919Schristos# Determine the linker flags (e.g. "-L" and "-l") for the Fortran
610*d874e919Schristos# intrinsic and runtime libraries that are required to successfully
611*d874e919Schristos# link a Fortran program or shared library.  The output variable
612*d874e919Schristos# FLIBS/FCLIBS is set to these flags.
613*d874e919Schristos#
614*d874e919Schristos# This macro is intended to be used in those situations when it is
615*d874e919Schristos# necessary to mix, e.g. C++ and Fortran, source code into a single
616*d874e919Schristos# program or shared library.
617*d874e919Schristos#
618*d874e919Schristos# For example, if object files from a C++ and Fortran compiler must
619*d874e919Schristos# be linked together, then the C++ compiler/linker must be used for
620*d874e919Schristos# linking (since special C++-ish things need to happen at link time
621*d874e919Schristos# like calling global constructors, instantiating templates, enabling
622*d874e919Schristos# exception support, etc.).
623*d874e919Schristos#
624*d874e919Schristos# However, the Fortran intrinsic and runtime libraries must be
625*d874e919Schristos# linked in as well, but the C++ compiler/linker doesn't know how to
626*d874e919Schristos# add these Fortran libraries.  Hence, the macro
627*d874e919Schristos# "AC_F77_LIBRARY_LDFLAGS" was created to determine these Fortran
628*d874e919Schristos# libraries.
629*d874e919Schristos#
630*d874e919Schristos# This macro was packaged in its current form by Matthew D. Langston.
631*d874e919Schristos# However, nearly all of this macro came from the "OCTAVE_FLIBS" macro
632*d874e919Schristos# in "octave-2.0.13/aclocal.m4", and full credit should go to John
633*d874e919Schristos# W. Eaton for writing this extremely useful macro.  Thank you John.
634*d874e919SchristosAC_DEFUN([_AC_FC_LIBRARY_LDFLAGS],
635*d874e919Schristos[AC_REQUIRE([AC_CANONICAL_HOST])dnl
636*d874e919Schristos_AC_FORTRAN_ASSERT()dnl
637*d874e919Schristos_AC_PROG_FC_V
638*d874e919SchristosAC_CACHE_CHECK([for _AC_LANG libraries of $[]_AC_FC[]], ac_cv_[]_AC_LANG_ABBREV[]_libs,
639*d874e919Schristos[if test "x$[]_AC_LANG_PREFIX[]LIBS" != "x"; then
640*d874e919Schristos  ac_cv_[]_AC_LANG_ABBREV[]_libs="$[]_AC_LANG_PREFIX[]LIBS" # Let the user override the test.
641*d874e919Schristoselse
642*d874e919Schristos
643*d874e919Schristos_AC_PROG_FC_V_OUTPUT
644*d874e919Schristos
645*d874e919Schristosac_cv_[]_AC_LANG_ABBREV[]_libs=
646*d874e919Schristos
647*d874e919Schristos# Save positional arguments (if any)
648*d874e919Schristosac_save_positional="$[@]"
649*d874e919Schristos
650*d874e919Schristosset X $ac_[]_AC_LANG_ABBREV[]_v_output
651*d874e919Schristoswhile test $[@%:@] != 1; do
652*d874e919Schristos  shift
653*d874e919Schristos  ac_arg=$[1]
654*d874e919Schristos  case $ac_arg in
655*d874e919Schristos	[[\\/]]*.a | ?:[[\\/]]*.a)
656*d874e919Schristos	  _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
657*d874e919Schristos	      ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg")
658*d874e919Schristos	  ;;
659*d874e919Schristos	-bI:*)
660*d874e919Schristos	  _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
661*d874e919Schristos	     [_AC_LINKER_OPTION([$ac_arg], ac_cv_[]_AC_LANG_ABBREV[]_libs)])
662*d874e919Schristos	  ;;
663*d874e919Schristos	  # Ignore these flags.
664*d874e919Schristos	-lang* | -lcrt*.o | -lc | -lgcc* | -lSystem | -libmil | -little \
665*d874e919Schristos	  |-LANG:=* | -LIST:* | -LNO:* | -link)
666*d874e919Schristos	  ;;
667*d874e919Schristos	-lkernel32)
668*d874e919Schristos	  case $host_os in
669*d874e919Schristos	  *cygwin*) ;;
670*d874e919Schristos	  *) ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg"
671*d874e919Schristos	    ;;
672*d874e919Schristos	  esac
673*d874e919Schristos	  ;;
674*d874e919Schristos	-[[LRuYz]])
675*d874e919Schristos	  # These flags, when seen by themselves, take an argument.
676*d874e919Schristos	  # We remove the space between option and argument and re-iterate
677*d874e919Schristos	  # unless we find an empty arg or a new option (starting with -)
678*d874e919Schristos	  case $[2] in
679*d874e919Schristos	     "" | -*);;
680*d874e919Schristos	     *)
681*d874e919Schristos		ac_arg="$ac_arg$[2]"
682*d874e919Schristos		shift; shift
683*d874e919Schristos		set X $ac_arg "$[@]"
684*d874e919Schristos		;;
685*d874e919Schristos	  esac
686*d874e919Schristos	  ;;
687*d874e919Schristos	-YP,*)
688*d874e919Schristos	  for ac_j in `AS_ECHO(["$ac_arg"]) | sed -e 's/-YP,/-L/;s/:/ -L/g'`; do
689*d874e919Schristos	    _AC_LIST_MEMBER_IF($ac_j, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
690*d874e919Schristos			       [ac_arg="$ac_arg $ac_j"
691*d874e919Schristos			       ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_j"])
692*d874e919Schristos	  done
693*d874e919Schristos	  ;;
694*d874e919Schristos	-[[lLR]]*)
695*d874e919Schristos	  _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
696*d874e919Schristos			     ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg")
697*d874e919Schristos	  ;;
698*d874e919Schristos	-zallextract*| -zdefaultextract)
699*d874e919Schristos	  ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg"
700*d874e919Schristos	  ;;
701*d874e919Schristos	  # Ignore everything else.
702*d874e919Schristos  esac
703*d874e919Schristosdone
704*d874e919Schristos# restore positional arguments
705*d874e919Schristosset X $ac_save_positional; shift
706*d874e919Schristos
707*d874e919Schristos# We only consider "LD_RUN_PATH" on Solaris systems.  If this is seen,
708*d874e919Schristos# then we insist that the "run path" must be an absolute path (i.e. it
709*d874e919Schristos# must begin with a "/").
710*d874e919Schristoscase `(uname -sr) 2>/dev/null` in
711*d874e919Schristos   "SunOS 5"*)
712*d874e919Schristos      ac_ld_run_path=`AS_ECHO(["$ac_[]_AC_LANG_ABBREV[]_v_output"]) |
713*d874e919Schristos			sed -n 's,^.*LD_RUN_PATH *= *\(/[[^ ]]*\).*$,-R\1,p'`
714*d874e919Schristos      test "x$ac_ld_run_path" != x &&
715*d874e919Schristos	_AC_LINKER_OPTION([$ac_ld_run_path], ac_cv_[]_AC_LANG_ABBREV[]_libs)
716*d874e919Schristos      ;;
717*d874e919Schristosesac
718*d874e919Schristosfi # test "x$[]_AC_LANG_PREFIX[]LIBS" = "x"
719*d874e919Schristos])
720*d874e919Schristos[]_AC_LANG_PREFIX[]LIBS="$ac_cv_[]_AC_LANG_ABBREV[]_libs"
721*d874e919SchristosAC_SUBST([]_AC_LANG_PREFIX[]LIBS)
722*d874e919Schristos])# _AC_FC_LIBRARY_LDFLAGS
723*d874e919Schristos
724*d874e919Schristos
725*d874e919Schristos# AC_F77_LIBRARY_LDFLAGS
726*d874e919Schristos# ----------------------
727*d874e919SchristosAC_DEFUN([AC_F77_LIBRARY_LDFLAGS],
728*d874e919Schristos[AC_REQUIRE([AC_PROG_F77])dnl
729*d874e919SchristosAC_LANG_PUSH(Fortran 77)dnl
730*d874e919Schristos_AC_FC_LIBRARY_LDFLAGS
731*d874e919SchristosAC_LANG_POP(Fortran 77)dnl
732*d874e919Schristos])# AC_F77_LIBRARY_LDFLAGS
733*d874e919Schristos
734*d874e919Schristos
735*d874e919Schristos# AC_FC_LIBRARY_LDFLAGS
736*d874e919Schristos# ---------------------
737*d874e919SchristosAC_DEFUN([AC_FC_LIBRARY_LDFLAGS],
738*d874e919Schristos[AC_REQUIRE([AC_PROG_FC])dnl
739*d874e919SchristosAC_LANG_PUSH(Fortran)dnl
740*d874e919Schristos_AC_FC_LIBRARY_LDFLAGS
741*d874e919SchristosAC_LANG_POP(Fortran)dnl
742*d874e919Schristos])# AC_FC_LIBRARY_LDFLAGS
743*d874e919Schristos
744*d874e919Schristos
745*d874e919Schristos# _AC_FC_DUMMY_MAIN([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
746*d874e919Schristos# -----------------------------------------------------------
747*d874e919Schristos#
748*d874e919Schristos# Detect name of dummy main routine required by the Fortran libraries,
749*d874e919Schristos# (if any) and define {F77,FC}_DUMMY_MAIN to this name (which should be
750*d874e919Schristos# used for a dummy declaration, if it is defined).  On some systems,
751*d874e919Schristos# linking a C program to the Fortran library does not work unless you
752*d874e919Schristos# supply a dummy function called something like MAIN__.
753*d874e919Schristos#
754*d874e919Schristos# Execute ACTION-IF-NOT-FOUND if no way of successfully linking a C
755*d874e919Schristos# program with the {F77,FC} libs is found; default to exiting with an error
756*d874e919Schristos# message.  Execute ACTION-IF-FOUND if a dummy routine name is needed
757*d874e919Schristos# and found or if it is not needed (default to defining {F77,FC}_DUMMY_MAIN
758*d874e919Schristos# when needed).
759*d874e919Schristos#
760*d874e919Schristos# What is technically happening is that the Fortran libraries provide
761*d874e919Schristos# their own main() function, which usually initializes Fortran I/O and
762*d874e919Schristos# similar stuff, and then calls MAIN__, which is the entry point of
763*d874e919Schristos# your program.  Usually, a C program will override this with its own
764*d874e919Schristos# main() routine, but the linker sometimes complain if you don't
765*d874e919Schristos# provide a dummy (never-called) MAIN__ routine anyway.
766*d874e919Schristos#
767*d874e919Schristos# Of course, programs that want to allow Fortran subroutines to do
768*d874e919Schristos# I/O, etcetera, should call their main routine MAIN__() (or whatever)
769*d874e919Schristos# instead of main().  A separate autoconf test (_AC_FC_MAIN) checks
770*d874e919Schristos# for the routine to use in this case (since the semantics of the test
771*d874e919Schristos# are slightly different).  To link to e.g. purely numerical
772*d874e919Schristos# libraries, this is normally not necessary, however, and most C/C++
773*d874e919Schristos# programs are reluctant to turn over so much control to Fortran.  =)
774*d874e919Schristos#
775*d874e919Schristos# The name variants we check for are (in order):
776*d874e919Schristos#   MAIN__ (g77, MAIN__ required on some systems; IRIX, MAIN__ optional)
777*d874e919Schristos#   MAIN_, __main (SunOS)
778*d874e919Schristos#   MAIN _MAIN __MAIN main_ main__ _main (we follow DDD and try these too)
779*d874e919SchristosAC_DEFUN([_AC_FC_DUMMY_MAIN],
780*d874e919Schristos[_AC_FORTRAN_ASSERT()dnl
781*d874e919Schristosm4_define(_AC_LANG_PROGRAM_C_[]_AC_FC[]_HOOKS,
782*d874e919Schristos[#ifdef ]_AC_FC[_DUMMY_MAIN
783*d874e919Schristos]AC_LANG_CASE([Fortran], [#ifndef FC_DUMMY_MAIN_EQ_F77])
784*d874e919Schristos[#  ifdef __cplusplus
785*d874e919Schristos     extern "C"
786*d874e919Schristos#  endif
787*d874e919Schristos   int ]_AC_FC[_DUMMY_MAIN() { return 1; }
788*d874e919Schristos]AC_LANG_CASE([Fortran], [#endif])
789*d874e919Schristos[#endif
790*d874e919Schristos])
791*d874e919SchristosAC_CACHE_CHECK([for dummy main to link with _AC_LANG libraries],
792*d874e919Schristos	       ac_cv_[]_AC_LANG_ABBREV[]_dummy_main,
793*d874e919Schristos[ac_[]_AC_LANG_ABBREV[]_dm_save_LIBS=$LIBS
794*d874e919Schristos LIBS="$LIBS $[]_AC_LANG_PREFIX[]LIBS"
795*d874e919Schristos ac_fortran_dm_var=[]_AC_FC[]_DUMMY_MAIN
796*d874e919Schristos AC_LANG_PUSH(C)dnl
797*d874e919Schristos
798*d874e919Schristos # First, try linking without a dummy main:
799*d874e919Schristos AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
800*d874e919Schristos		[ac_cv_fortran_dummy_main=none],
801*d874e919Schristos		[ac_cv_fortran_dummy_main=unknown])
802*d874e919Schristos
803*d874e919Schristos if test $ac_cv_fortran_dummy_main = unknown; then
804*d874e919Schristos   for ac_func in MAIN__ MAIN_ __main MAIN _MAIN __MAIN main_ main__ _main; do
805*d874e919Schristos     AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@define $ac_fortran_dm_var $ac_func]])],
806*d874e919Schristos		    [ac_cv_fortran_dummy_main=$ac_func; break])
807*d874e919Schristos   done
808*d874e919Schristos fi
809*d874e919Schristos AC_LANG_POP(C)dnl
810*d874e919Schristos ac_cv_[]_AC_LANG_ABBREV[]_dummy_main=$ac_cv_fortran_dummy_main
811*d874e919Schristos rm -rf conftest*
812*d874e919Schristos LIBS=$ac_[]_AC_LANG_ABBREV[]_dm_save_LIBS
813*d874e919Schristos])
814*d874e919Schristos[]_AC_FC[]_DUMMY_MAIN=$ac_cv_[]_AC_LANG_ABBREV[]_dummy_main
815*d874e919SchristosAS_IF([test "$[]_AC_FC[]_DUMMY_MAIN" != unknown],
816*d874e919Schristos      [m4_default([$1],
817*d874e919Schristos[if test $[]_AC_FC[]_DUMMY_MAIN != none; then
818*d874e919Schristos  AC_DEFINE_UNQUOTED([]_AC_FC[]_DUMMY_MAIN, $[]_AC_FC[]_DUMMY_MAIN,
819*d874e919Schristos		     [Define to dummy `main' function (if any) required to
820*d874e919Schristos		      link to the Fortran libraries.])
821*d874e919Schristos  if test "x$ac_cv_fc_dummy_main" = "x$ac_cv_f77_dummy_main"; then
822*d874e919Schristos	AC_DEFINE([FC_DUMMY_MAIN_EQ_F77], 1,
823*d874e919Schristos		  [Define if F77 and FC dummy `main' functions are identical.])
824*d874e919Schristos  fi
825*d874e919Schristosfi])],
826*d874e919Schristos      [m4_default([$2],
827*d874e919Schristos	    [AC_MSG_FAILURE([linking to Fortran libraries from C fails])])])
828*d874e919Schristos])# _AC_FC_DUMMY_MAIN
829*d874e919Schristos
830*d874e919Schristos
831*d874e919Schristos# AC_F77_DUMMY_MAIN
832*d874e919Schristos# -----------------
833*d874e919SchristosAC_DEFUN([AC_F77_DUMMY_MAIN],
834*d874e919Schristos[AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
835*d874e919SchristosAC_LANG_PUSH(Fortran 77)dnl
836*d874e919Schristos_AC_FC_DUMMY_MAIN($@)
837*d874e919SchristosAC_LANG_POP(Fortran 77)dnl
838*d874e919Schristos])# AC_F77_DUMMY_MAIN
839*d874e919Schristos
840*d874e919Schristos
841*d874e919Schristos# AC_FC_DUMMY_MAIN
842*d874e919Schristos# ----------------
843*d874e919SchristosAC_DEFUN([AC_FC_DUMMY_MAIN],
844*d874e919Schristos[AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
845*d874e919SchristosAC_LANG_PUSH(Fortran)dnl
846*d874e919Schristos_AC_FC_DUMMY_MAIN($@)
847*d874e919SchristosAC_LANG_POP(Fortran)dnl
848*d874e919Schristos])# AC_FC_DUMMY_MAIN
849*d874e919Schristos
850*d874e919Schristos
851*d874e919Schristos# _AC_FC_MAIN
852*d874e919Schristos# -----------
853*d874e919Schristos# Define {F77,FC}_MAIN to name of alternate main() function for use with
854*d874e919Schristos# the Fortran libraries.  (Typically, the libraries may define their
855*d874e919Schristos# own main() to initialize I/O, etcetera, that then call your own
856*d874e919Schristos# routine called MAIN__ or whatever.)  See _AC_FC_DUMMY_MAIN, above.
857*d874e919Schristos# If no such alternate name is found, just define {F77,FC}_MAIN to main.
858*d874e919Schristos#
859*d874e919SchristosAC_DEFUN([_AC_FC_MAIN],
860*d874e919Schristos[_AC_FORTRAN_ASSERT()dnl
861*d874e919SchristosAC_CACHE_CHECK([for alternate main to link with _AC_LANG libraries],
862*d874e919Schristos	       ac_cv_[]_AC_LANG_ABBREV[]_main,
863*d874e919Schristos[ac_[]_AC_LANG_ABBREV[]_m_save_LIBS=$LIBS
864*d874e919Schristos LIBS="$LIBS $[]_AC_LANG_PREFIX[]LIBS"
865*d874e919Schristos ac_fortran_dm_var=[]_AC_FC[]_DUMMY_MAIN
866*d874e919Schristos AC_LANG_PUSH(C)dnl
867*d874e919Schristos ac_cv_fortran_main="main" # default entry point name
868*d874e919Schristos for ac_func in MAIN__ MAIN_ __main MAIN _MAIN __MAIN main_ main__ _main; do
869*d874e919Schristos   AC_LINK_IFELSE([AC_LANG_PROGRAM([@%:@ifdef FC_DUMMY_MAIN_EQ_F77
870*d874e919Schristos@%:@  undef F77_DUMMY_MAIN
871*d874e919Schristos@%:@  undef FC_DUMMY_MAIN
872*d874e919Schristos@%:@else
873*d874e919Schristos@%:@  undef $ac_fortran_dm_var
874*d874e919Schristos@%:@endif
875*d874e919Schristos@%:@define main $ac_func])],
876*d874e919Schristos		  [ac_cv_fortran_main=$ac_func; break])
877*d874e919Schristos done
878*d874e919Schristos AC_LANG_POP(C)dnl
879*d874e919Schristos ac_cv_[]_AC_LANG_ABBREV[]_main=$ac_cv_fortran_main
880*d874e919Schristos rm -rf conftest*
881*d874e919Schristos LIBS=$ac_[]_AC_LANG_ABBREV[]_m_save_LIBS
882*d874e919Schristos])
883*d874e919SchristosAC_DEFINE_UNQUOTED([]_AC_FC[]_MAIN, $ac_cv_[]_AC_LANG_ABBREV[]_main,
884*d874e919Schristos		   [Define to alternate name for `main' routine that is
885*d874e919Schristos		    called from a `main' in the Fortran libraries.])
886*d874e919Schristos])# _AC_FC_MAIN
887*d874e919Schristos
888*d874e919Schristos
889*d874e919Schristos# AC_F77_MAIN
890*d874e919Schristos# -----------
891*d874e919SchristosAC_DEFUN([AC_F77_MAIN],
892*d874e919Schristos[AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
893*d874e919SchristosAC_LANG_PUSH(Fortran 77)dnl
894*d874e919Schristos_AC_FC_MAIN
895*d874e919SchristosAC_LANG_POP(Fortran 77)dnl
896*d874e919Schristos])# AC_F77_MAIN
897*d874e919Schristos
898*d874e919Schristos
899*d874e919Schristos# AC_FC_MAIN
900*d874e919Schristos# ----------
901*d874e919SchristosAC_DEFUN([AC_FC_MAIN],
902*d874e919Schristos[AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
903*d874e919SchristosAC_LANG_PUSH(Fortran)dnl
904*d874e919Schristos_AC_FC_MAIN
905*d874e919SchristosAC_LANG_POP(Fortran)dnl
906*d874e919Schristos])# AC_FC_MAIN
907*d874e919Schristos
908*d874e919Schristos
909*d874e919Schristos# __AC_FC_NAME_MANGLING
910*d874e919Schristos# ---------------------
911*d874e919Schristos# Test for the name mangling scheme used by the Fortran compiler.
912*d874e919Schristos#
913*d874e919Schristos# Sets ac_cv_{f77,fc}_mangling. The value contains three fields, separated
914*d874e919Schristos# by commas:
915*d874e919Schristos#
916*d874e919Schristos# lower case / upper case:
917*d874e919Schristos#    case translation of the Fortran symbols
918*d874e919Schristos# underscore / no underscore:
919*d874e919Schristos#    whether the compiler appends "_" to symbol names
920*d874e919Schristos# extra underscore / no extra underscore:
921*d874e919Schristos#    whether the compiler appends an extra "_" to symbol names already
922*d874e919Schristos#    containing at least one underscore
923*d874e919Schristos#
924*d874e919SchristosAC_DEFUN([__AC_FC_NAME_MANGLING],
925*d874e919Schristos[_AC_FORTRAN_ASSERT()dnl
926*d874e919SchristosAC_CACHE_CHECK([for _AC_LANG name-mangling scheme],
927*d874e919Schristos	       ac_cv_[]_AC_LANG_ABBREV[]_mangling,
928*d874e919Schristos[AC_COMPILE_IFELSE(
929*d874e919Schristos[[      subroutine foobar()
930*d874e919Schristos      return
931*d874e919Schristos      end
932*d874e919Schristos      subroutine foo_bar()
933*d874e919Schristos      return
934*d874e919Schristos      end]],
935*d874e919Schristos[mv conftest.$ac_objext cfortran_test.$ac_objext
936*d874e919Schristos
937*d874e919Schristos  ac_save_LIBS=$LIBS
938*d874e919Schristos  LIBS="cfortran_test.$ac_objext $LIBS $[]_AC_LANG_PREFIX[]LIBS"
939*d874e919Schristos
940*d874e919Schristos  AC_LANG_PUSH(C)dnl
941*d874e919Schristos  ac_success=no
942*d874e919Schristos  for ac_foobar in foobar FOOBAR; do
943*d874e919Schristos    for ac_underscore in "" "_"; do
944*d874e919Schristos      ac_func="$ac_foobar$ac_underscore"
945*d874e919Schristos      AC_LINK_IFELSE([AC_LANG_CALL([], [$ac_func])],
946*d874e919Schristos		     [ac_success=yes; break 2])
947*d874e919Schristos    done
948*d874e919Schristos  done
949*d874e919Schristos  AC_LANG_POP(C)dnl
950*d874e919Schristos
951*d874e919Schristos  if test "$ac_success" = "yes"; then
952*d874e919Schristos     case $ac_foobar in
953*d874e919Schristos	foobar)
954*d874e919Schristos	   ac_case=lower
955*d874e919Schristos	   ac_foo_bar=foo_bar
956*d874e919Schristos	   ;;
957*d874e919Schristos	FOOBAR)
958*d874e919Schristos	   ac_case=upper
959*d874e919Schristos	   ac_foo_bar=FOO_BAR
960*d874e919Schristos	   ;;
961*d874e919Schristos     esac
962*d874e919Schristos
963*d874e919Schristos     AC_LANG_PUSH(C)dnl
964*d874e919Schristos     ac_success_extra=no
965*d874e919Schristos     for ac_extra in "" "_"; do
966*d874e919Schristos	ac_func="$ac_foo_bar$ac_underscore$ac_extra"
967*d874e919Schristos	AC_LINK_IFELSE([AC_LANG_CALL([], [$ac_func])],
968*d874e919Schristos		       [ac_success_extra=yes; break])
969*d874e919Schristos     done
970*d874e919Schristos     AC_LANG_POP(C)dnl
971*d874e919Schristos
972*d874e919Schristos     if test "$ac_success_extra" = "yes"; then
973*d874e919Schristos	ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_case case"
974*d874e919Schristos	if test -z "$ac_underscore"; then
975*d874e919Schristos	   ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, no underscore"
976*d874e919Schristos	else
977*d874e919Schristos	   ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, underscore"
978*d874e919Schristos	fi
979*d874e919Schristos	if test -z "$ac_extra"; then
980*d874e919Schristos	   ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, no extra underscore"
981*d874e919Schristos	else
982*d874e919Schristos	   ac_cv_[]_AC_LANG_ABBREV[]_mangling="$ac_cv_[]_AC_LANG_ABBREV[]_mangling, extra underscore"
983*d874e919Schristos	fi
984*d874e919Schristos      else
985*d874e919Schristos	ac_cv_[]_AC_LANG_ABBREV[]_mangling="unknown"
986*d874e919Schristos      fi
987*d874e919Schristos  else
988*d874e919Schristos     ac_cv_[]_AC_LANG_ABBREV[]_mangling="unknown"
989*d874e919Schristos  fi
990*d874e919Schristos
991*d874e919Schristos  LIBS=$ac_save_LIBS
992*d874e919Schristos  rm -rf conftest*
993*d874e919Schristos  rm -f cfortran_test*],
994*d874e919Schristos  [AC_MSG_FAILURE([cannot compile a simple Fortran program])])
995*d874e919Schristos])
996*d874e919Schristos])# __AC_FC_NAME_MANGLING
997*d874e919Schristos
998*d874e919Schristos# The replacement is empty.
999*d874e919SchristosAU_DEFUN([AC_F77_NAME_MANGLING], [])
1000*d874e919Schristos
1001*d874e919Schristos
1002*d874e919Schristos# _AC_F77_NAME_MANGLING
1003*d874e919Schristos# ---------------------
1004*d874e919SchristosAC_DEFUN([_AC_F77_NAME_MANGLING],
1005*d874e919Schristos[AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])dnl
1006*d874e919SchristosAC_REQUIRE([AC_F77_DUMMY_MAIN])dnl
1007*d874e919SchristosAC_LANG_PUSH(Fortran 77)dnl
1008*d874e919Schristos__AC_FC_NAME_MANGLING
1009*d874e919SchristosAC_LANG_POP(Fortran 77)dnl
1010*d874e919Schristos])# _AC_F77_NAME_MANGLING
1011*d874e919Schristos
1012*d874e919Schristos
1013*d874e919Schristos# _AC_FC_NAME_MANGLING
1014*d874e919Schristos# --------------------
1015*d874e919SchristosAC_DEFUN([_AC_FC_NAME_MANGLING],
1016*d874e919Schristos[AC_REQUIRE([AC_FC_LIBRARY_LDFLAGS])dnl
1017*d874e919SchristosAC_REQUIRE([AC_FC_DUMMY_MAIN])dnl
1018*d874e919SchristosAC_LANG_PUSH(Fortran)dnl
1019*d874e919Schristos__AC_FC_NAME_MANGLING
1020*d874e919SchristosAC_LANG_POP(Fortran)dnl
1021*d874e919Schristos])# _AC_FC_NAME_MANGLING
1022*d874e919Schristos
1023*d874e919Schristos
1024*d874e919Schristos# _AC_FC_WRAPPERS
1025*d874e919Schristos# ---------------
1026*d874e919Schristos# Defines C macros {F77,FC}_FUNC(name,NAME) and {F77,FC}_FUNC_(name,NAME) to
1027*d874e919Schristos# properly mangle the names of C identifiers, and C identifiers with
1028*d874e919Schristos# underscores, respectively, so that they match the name mangling
1029*d874e919Schristos# scheme used by the Fortran compiler.
1030*d874e919SchristosAC_DEFUN([_AC_FC_WRAPPERS],
1031*d874e919Schristos[_AC_FORTRAN_ASSERT()dnl
1032*d874e919SchristosAH_TEMPLATE(_AC_FC[_FUNC],
1033*d874e919Schristos    [Define to a macro mangling the given C identifier (in lower and upper
1034*d874e919Schristos     case), which must not contain underscores, for linking with Fortran.])dnl
1035*d874e919SchristosAH_TEMPLATE(_AC_FC[_FUNC_],
1036*d874e919Schristos    [As ]_AC_FC[_FUNC, but for C identifiers containing underscores.])dnl
1037*d874e919Schristoscase $ac_cv_[]_AC_LANG_ABBREV[]_mangling in
1038*d874e919Schristos  "lower case, no underscore, no extra underscore")
1039*d874e919Schristos	  AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name])
1040*d874e919Schristos	  AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name]) ;;
1041*d874e919Schristos  "lower case, no underscore, extra underscore")
1042*d874e919Schristos	  AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name])
1043*d874e919Schristos	  AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name [##] _]) ;;
1044*d874e919Schristos  "lower case, underscore, no extra underscore")
1045*d874e919Schristos	  AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name [##] _])
1046*d874e919Schristos	  AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name [##] _]) ;;
1047*d874e919Schristos  "lower case, underscore, extra underscore")
1048*d874e919Schristos	  AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [name [##] _])
1049*d874e919Schristos	  AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [name [##] __]) ;;
1050*d874e919Schristos  "upper case, no underscore, no extra underscore")
1051*d874e919Schristos	  AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME])
1052*d874e919Schristos	  AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME]) ;;
1053*d874e919Schristos  "upper case, no underscore, extra underscore")
1054*d874e919Schristos	  AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME])
1055*d874e919Schristos	  AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME [##] _]) ;;
1056*d874e919Schristos  "upper case, underscore, no extra underscore")
1057*d874e919Schristos	  AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME [##] _])
1058*d874e919Schristos	  AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME [##] _]) ;;
1059*d874e919Schristos  "upper case, underscore, extra underscore")
1060*d874e919Schristos	  AC_DEFINE(_AC_FC[_FUNC(name,NAME)],  [NAME [##] _])
1061*d874e919Schristos	  AC_DEFINE(_AC_FC[_FUNC_(name,NAME)], [NAME [##] __]) ;;
1062*d874e919Schristos  *)
1063*d874e919Schristos	  AC_MSG_WARN([unknown Fortran name-mangling scheme])
1064*d874e919Schristos	  ;;
1065*d874e919Schristosesac
1066*d874e919Schristos])# _AC_FC_WRAPPERS
1067*d874e919Schristos
1068*d874e919Schristos
1069*d874e919Schristos# AC_F77_WRAPPERS
1070*d874e919Schristos# ---------------
1071*d874e919SchristosAC_DEFUN([AC_F77_WRAPPERS],
1072*d874e919Schristos[AC_REQUIRE([_AC_F77_NAME_MANGLING])dnl
1073*d874e919SchristosAC_LANG_PUSH(Fortran 77)dnl
1074*d874e919Schristos_AC_FC_WRAPPERS
1075*d874e919SchristosAC_LANG_POP(Fortran 77)dnl
1076*d874e919Schristos])# AC_F77_WRAPPERS
1077*d874e919Schristos
1078*d874e919Schristos
1079*d874e919Schristos# AC_FC_WRAPPERS
1080*d874e919Schristos# --------------
1081*d874e919SchristosAC_DEFUN([AC_FC_WRAPPERS],
1082*d874e919Schristos[AC_REQUIRE([_AC_FC_NAME_MANGLING])dnl
1083*d874e919SchristosAC_LANG_PUSH(Fortran)dnl
1084*d874e919Schristos_AC_FC_WRAPPERS
1085*d874e919SchristosAC_LANG_POP(Fortran)dnl
1086*d874e919Schristos])# AC_FC_WRAPPERS
1087*d874e919Schristos
1088*d874e919Schristos
1089*d874e919Schristos# _AC_FC_FUNC(NAME, [SHELLVAR = NAME])
1090*d874e919Schristos# ------------------------------------
1091*d874e919Schristos# For a Fortran subroutine of given NAME, define a shell variable
1092*d874e919Schristos# $SHELLVAR to the Fortran-mangled name.  If the SHELLVAR
1093*d874e919Schristos# argument is not supplied, it defaults to NAME.
1094*d874e919SchristosAC_DEFUN([_AC_FC_FUNC],
1095*d874e919Schristos[_AC_FORTRAN_ASSERT()dnl
1096*d874e919Schristoscase $ac_cv_[]_AC_LANG_ABBREV[]_mangling in
1097*d874e919Schristos  upper*) ac_val="m4_toupper([$1])" ;;
1098*d874e919Schristos  lower*) ac_val="m4_tolower([$1])" ;;
1099*d874e919Schristos  *)      ac_val="unknown" ;;
1100*d874e919Schristosesac
1101*d874e919Schristoscase $ac_cv_[]_AC_LANG_ABBREV[]_mangling in *," underscore"*) ac_val="$ac_val"_ ;; esac
1102*d874e919Schristosm4_if(m4_index([$1],[_]),-1,[],
1103*d874e919Schristos[case $ac_cv_[]_AC_LANG_ABBREV[]_mangling in *," extra underscore"*) ac_val="$ac_val"_ ;; esac
1104*d874e919Schristos])
1105*d874e919Schristosm4_default([$2],[$1])="$ac_val"
1106*d874e919Schristos])# _AC_FC_FUNC
1107*d874e919Schristos
1108*d874e919Schristos
1109*d874e919Schristos# AC_F77_FUNC(NAME, [SHELLVAR = NAME])
1110*d874e919Schristos# ------------------------------------
1111*d874e919SchristosAC_DEFUN([AC_F77_FUNC],
1112*d874e919Schristos[AC_REQUIRE([_AC_F77_NAME_MANGLING])dnl
1113*d874e919SchristosAC_LANG_PUSH(Fortran 77)dnl
1114*d874e919Schristos_AC_FC_FUNC([$1],[$2])
1115*d874e919SchristosAC_LANG_POP(Fortran 77)dnl
1116*d874e919Schristos])# AC_F77_FUNC
1117*d874e919Schristos
1118*d874e919Schristos
1119*d874e919Schristos# AC_FC_FUNC(NAME, [SHELLVAR = NAME])
1120*d874e919Schristos# -----------------------------------
1121*d874e919SchristosAC_DEFUN([AC_FC_FUNC],
1122*d874e919Schristos[AC_REQUIRE([_AC_FC_NAME_MANGLING])dnl
1123*d874e919SchristosAC_LANG_PUSH(Fortran)dnl
1124*d874e919Schristos_AC_FC_FUNC([$1],[$2])
1125*d874e919SchristosAC_LANG_POP(Fortran)dnl
1126*d874e919Schristos])# AC_FC_FUNC
1127*d874e919Schristos
1128*d874e919Schristos
1129*d874e919Schristos# AC_FC_SRCEXT(EXT, [ACTION-IF-SUCCESS], [ACTION-IF-FAILURE])
1130*d874e919Schristos# -----------------------------------------------------------
1131*d874e919Schristos# Set the source-code extension used in Fortran (FC) tests to EXT (which
1132*d874e919Schristos# defaults to f).  Also, look for any necessary additional FCFLAGS needed
1133*d874e919Schristos# to allow this extension, and store them in the output variable
1134*d874e919Schristos# FCFLAGS_<EXT> (e.g. FCFLAGS_f90 for EXT=f90).  If successful,
1135*d874e919Schristos# call ACTION-IF-SUCCESS.  If unable to compile source code with EXT,
1136*d874e919Schristos# call ACTION-IF-FAILURE, which defaults to failing with an error
1137*d874e919Schristos# message.
1138*d874e919Schristos#
1139*d874e919Schristos# (The flags for the current source-code extension, if any, are stored in
1140*d874e919Schristos# $ac_fcflags_srcext and used automatically in subsequent autoconf tests.)
1141*d874e919Schristos#
1142*d874e919Schristos# For ordinary extensions like f90, etcetera, the modified FCFLAGS
1143*d874e919Schristos# are currently needed for IBM's xlf* and Intel's ifc (grrr).  Unfortunately,
1144*d874e919Schristos# xlf* will only take flags to recognize one extension at a time, so if the
1145*d874e919Schristos# user wants to compile multiple extensions (.f90 and .f95, say), she
1146*d874e919Schristos# will need to use the FCFLAGS_F90 and FCFLAGS_F95 individually rather
1147*d874e919Schristos# than just adding them all to FCFLAGS, for example.
1148*d874e919Schristos#
1149*d874e919Schristos# Also, for Intel's ifc compiler (which does not accept .f95 by default in
1150*d874e919Schristos# some versions), the $FCFLAGS_<EXT> variable *must* go immediately before
1151*d874e919Schristos# the source file on the command line, unlike other $FCFLAGS.  Ugh.
1152*d874e919Schristos#
1153*d874e919Schristos# gfortran requires '-x f77' in order to recognize .f77 files.
1154*d874e919SchristosAC_DEFUN([AC_FC_SRCEXT],
1155*d874e919Schristos[AC_LANG_PUSH(Fortran)dnl
1156*d874e919SchristosAC_CACHE_CHECK([for Fortran flag to compile .$1 files],
1157*d874e919Schristos		ac_cv_fc_srcext_$1,
1158*d874e919Schristos[ac_ext=$1
1159*d874e919Schristosac_fcflags_srcext_save=$ac_fcflags_srcext
1160*d874e919Schristosac_fcflags_srcext=
1161*d874e919Schristosac_cv_fc_srcext_$1=unknown
1162*d874e919Schristoscase $ac_ext in #(
1163*d874e919Schristos  [[fF]]77) ac_try=f77;; #(
1164*d874e919Schristos  *) ac_try=f95;;
1165*d874e919Schristosesac
1166*d874e919Schristosfor ac_flag in none -qsuffix=f=$1 -Tf "-x $ac_try"; do
1167*d874e919Schristos  test "x$ac_flag" != xnone && ac_fcflags_srcext="$ac_flag"
1168*d874e919Schristos  AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [ac_cv_fc_srcext_$1=$ac_flag; break])
1169*d874e919Schristosdone
1170*d874e919Schristosrm -f conftest.$ac_objext conftest.$1
1171*d874e919Schristosac_fcflags_srcext=$ac_fcflags_srcext_save
1172*d874e919Schristos])
1173*d874e919Schristosif test "x$ac_cv_fc_srcext_$1" = xunknown; then
1174*d874e919Schristos  m4_default([$3],[AC_MSG_ERROR([Fortran could not compile .$1 files])])
1175*d874e919Schristoselse
1176*d874e919Schristos  ac_fc_srcext=$1
1177*d874e919Schristos  if test "x$ac_cv_fc_srcext_$1" = xnone; then
1178*d874e919Schristos    ac_fcflags_srcext=""
1179*d874e919Schristos    FCFLAGS_[]$1[]=""
1180*d874e919Schristos  else
1181*d874e919Schristos    ac_fcflags_srcext=$ac_cv_fc_srcext_$1
1182*d874e919Schristos    FCFLAGS_[]$1[]=$ac_cv_fc_srcext_$1
1183*d874e919Schristos  fi
1184*d874e919Schristos  AC_SUBST(FCFLAGS_[]$1)
1185*d874e919Schristos  $2
1186*d874e919Schristosfi
1187*d874e919SchristosAC_LANG_POP(Fortran)dnl
1188*d874e919Schristos])# AC_FC_SRCEXT
1189*d874e919Schristos
1190*d874e919Schristos
1191*d874e919Schristos# AC_FC_PP_SRCEXT(EXT, [ACTION-IF-SUCCESS], [ACTION-IF-FAILURE])
1192*d874e919Schristos# --------------------------------------------------------------
1193*d874e919Schristos# Like AC_FC_SRCEXT, set the source-code extension used in Fortran (FC) tests
1194*d874e919Schristos# to EXT (which defaults to f).  Also, look for any necessary additional
1195*d874e919Schristos# FCFLAGS needed to allow this extension for preprocessed Fortran, and store
1196*d874e919Schristos# them in the output variable FCFLAGS_<EXT> (e.g. FCFLAGS_f90 for EXT=f90).
1197*d874e919Schristos# If successful, call ACTION-IF-SUCCESS.  If unable to compile preprocessed
1198*d874e919Schristos# source code with EXT, call ACTION-IF-FAILURE, which defaults to failing with
1199*d874e919Schristos# an error message.
1200*d874e919Schristos#
1201*d874e919Schristos# Some compilers allow preprocessing with either a Fortran preprocessor or
1202*d874e919Schristos# with the C preprocessor (cpp).  Prefer the Fortran preprocessor, to deal
1203*d874e919Schristos# correctly with continuation lines, `//' (not a comment), and preserve white
1204*d874e919Schristos# space (for fixed form).
1205*d874e919Schristos#
1206*d874e919Schristos# (The flags for the current source-code extension, if any, are stored in
1207*d874e919Schristos# $ac_fcflags_srcext and used automatically in subsequent autoconf tests.)
1208*d874e919Schristos#
1209*d874e919Schristos# For ordinary extensions like f90, etcetera, the modified FCFLAGS
1210*d874e919Schristos# are needed for IBM's xlf*.  Also, for Intel's ifort compiler, the
1211*d874e919Schristos# $FCFLAGS_<EXT> variable *must* go immediately before the source file on the
1212*d874e919Schristos# command line, unlike other $FCFLAGS.  Ugh.
1213*d874e919Schristos#
1214*d874e919Schristos# Known extensions that enable preprocessing by default, and flags to force it:
1215*d874e919Schristos# GNU: .F .F90 .F95 .F03 .F08, -cpp for most others,
1216*d874e919Schristos#      -x f77-cpp-input for .f77 .F77; -x f95-cpp-input for gfortran < 4.4
1217*d874e919Schristos# SGI: .F .F90, -ftpp or -cpp for .f .f90, -E write preproc to stdout
1218*d874e919Schristos#      -macro_expand enable macro expansion everywhere (with -ftpp)
1219*d874e919Schristos#      -P preproc only, save in .i, no #line's
1220*d874e919Schristos# SUN: .F .F95, -fpp for others; -xpp={fpp,cpp} for preprocessor selection
1221*d874e919Schristos#      -F preprocess only (save in lowercase extension)
1222*d874e919Schristos# IBM: .F .F77 .F90 .F95 .F03, -qsuffix=cpp=EXT for extension .EXT to invoke cpp
1223*d874e919Schristos#      -WF,-qnofpp -WF,-qfpp=comment:linecont:nocomment:nolinecont
1224*d874e919Schristos#      -WF,-qlanglvl=classic or not -qnoescape (trigraph problems)
1225*d874e919Schristos#      -d no #line in output, -qnoobject for preprocessing only (output in .f)
1226*d874e919Schristos#      -q{no,}ppsuborigarg substitute original macro args before expansion
1227*d874e919Schristos# HP:  .F, +cpp={yes|no|default} use cpp, -cpp, +cpp_keep save in .i/.i90
1228*d874e919Schristos# PGI: -Mpreprocess
1229*d874e919Schristos# Absoft: .F .FOR .F90 .F95, -cpp for others
1230*d874e919Schristos# Cray: .F .F90 .FTN, -e Z for others; -F enable macro expansion everywhere
1231*d874e919Schristos# Intel: .F .F90, -fpp for others, but except for .f and .f90, -Tf may also be
1232*d874e919Schristos#        needed right before the source file name
1233*d874e919Schristos# PathScale: .F .F90 .F95, -ftpp or -cpp for .f .f90 .f95
1234*d874e919Schristos#         -macro_expand for expansion everywhere, -P for no #line in output
1235*d874e919Schristos# Lahey: .F .FOR .F90 .F95, -Cpp
1236*d874e919Schristos# NAGWare: .F .F90 .F95, .ff .ff90 .ff95 (new), -fpp for others
1237*d874e919Schristos# Compaq/Tru64: .F .F90, -cpp, -P keep .i file, -P keep .i file
1238*d874e919Schristos# f2c: .F, -cpp
1239*d874e919Schristos# g95: .F .FOR .F90 .F95 .F03, -cpp -no-cpp, -E for stdout
1240*d874e919SchristosAC_DEFUN([AC_FC_PP_SRCEXT],
1241*d874e919Schristos[AC_LANG_PUSH(Fortran)dnl
1242*d874e919SchristosAC_CACHE_CHECK([for Fortran flag to compile preprocessed .$1 files],
1243*d874e919Schristos		ac_cv_fc_pp_srcext_$1,
1244*d874e919Schristos[ac_ext=$1
1245*d874e919Schristosac_fcflags_pp_srcext_save=$ac_fcflags_srcext
1246*d874e919Schristosac_fcflags_srcext=
1247*d874e919Schristosac_cv_fc_pp_srcext_$1=unknown
1248*d874e919Schristoscase $ac_ext in #(
1249*d874e919Schristos  [[fF]]77) ac_try=f77-cpp-input;; #(
1250*d874e919Schristos  *) ac_try=f95-cpp-input;;
1251*d874e919Schristosesac
1252*d874e919Schristosfor ac_flag in none -ftpp -fpp -Tf "-fpp -Tf" -xpp=fpp -Mpreprocess "-e Z" \
1253*d874e919Schristos               -cpp -xpp=cpp -qsuffix=cpp=$1 "-x $ac_try" +cpp -Cpp; do
1254*d874e919Schristos  test "x$ac_flag" != xnone && ac_fcflags_srcext="$ac_flag"
1255*d874e919Schristos  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
1256*d874e919Schristos#if 0
1257*d874e919Schristos#include <ac_nonexistent.h>
1258*d874e919Schristos      choke me
1259*d874e919Schristos#endif]])],
1260*d874e919Schristos    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
1261*d874e919Schristos#if 1
1262*d874e919Schristos#include <ac_nonexistent.h>
1263*d874e919Schristos      choke me
1264*d874e919Schristos#endif]])],
1265*d874e919Schristos       [],
1266*d874e919Schristos       [ac_cv_fc_pp_srcext_$1=$ac_flag; break])])
1267*d874e919Schristosdone
1268*d874e919Schristosrm -f conftest.$ac_objext conftest.$1
1269*d874e919Schristosac_fcflags_srcext=$ac_fcflags_pp_srcext_save
1270*d874e919Schristos])
1271*d874e919Schristosif test "x$ac_cv_fc_pp_srcext_$1" = xunknown; then
1272*d874e919Schristos  m4_default([$3],
1273*d874e919Schristos             [AC_MSG_ERROR([Fortran could not compile preprocessed .$1 files])])
1274*d874e919Schristoselse
1275*d874e919Schristos  ac_fc_srcext=$1
1276*d874e919Schristos  if test "x$ac_cv_fc_pp_srcext_$1" = xnone; then
1277*d874e919Schristos    ac_fcflags_srcext=""
1278*d874e919Schristos    FCFLAGS_[]$1[]=""
1279*d874e919Schristos  else
1280*d874e919Schristos    ac_fcflags_srcext=$ac_cv_fc_pp_srcext_$1
1281*d874e919Schristos    FCFLAGS_[]$1[]=$ac_cv_fc_pp_srcext_$1
1282*d874e919Schristos  fi
1283*d874e919Schristos  AC_SUBST(FCFLAGS_[]$1)
1284*d874e919Schristos  $2
1285*d874e919Schristosfi
1286*d874e919SchristosAC_LANG_POP(Fortran)dnl
1287*d874e919Schristos])# AC_FC_PP_SRCEXT
1288*d874e919Schristos
1289*d874e919Schristos
1290*d874e919Schristos# AC_FC_PP_DEFINE([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1291*d874e919Schristos# -------------------------------------------------------------------
1292*d874e919Schristos# Find a flag to specify defines for preprocessed Fortran.  Not all
1293*d874e919Schristos# Fortran compilers use -D.  Substitute FC_DEFINE with the result and
1294*d874e919Schristos# call ACTION-IF-SUCCESS (defaults to nothing) if successful, and
1295*d874e919Schristos# ACTION-IF-FAILURE (defaults to failing with an error message) if not.
1296*d874e919Schristos#
1297*d874e919Schristos# Known flags:
1298*d874e919Schristos# IBM: -WF,-D
1299*d874e919Schristos# Lahey/Fujitsu: -Wp,-D     older versions???
1300*d874e919Schristos# f2c: -D or -Wc,-D
1301*d874e919Schristos# others: -D
1302*d874e919SchristosAC_DEFUN([AC_FC_PP_DEFINE],
1303*d874e919Schristos[AC_LANG_PUSH([Fortran])dnl
1304*d874e919Schristosac_fc_pp_define_srcext_save=$ac_fc_srcext
1305*d874e919SchristosAC_FC_PP_SRCEXT([F])
1306*d874e919SchristosAC_CACHE_CHECK([how to define symbols for preprocessed Fortran],
1307*d874e919Schristos  [ac_cv_fc_pp_define],
1308*d874e919Schristos[ac_fc_pp_define_srcext_save=$ac_fc_srcext
1309*d874e919Schristosac_cv_fc_pp_define=unknown
1310*d874e919Schristosac_fc_pp_define_FCFLAGS_save=$FCFLAGS
1311*d874e919Schristosfor ac_flag in -D -WF,-D -Wp,-D -Wc,-D
1312*d874e919Schristosdo
1313*d874e919Schristos  FCFLAGS="$ac_fc_pp_define_FCFLAGS_save ${ac_flag}FOOBAR ${ac_flag}ZORK=42"
1314*d874e919Schristos  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
1315*d874e919Schristos#ifndef FOOBAR
1316*d874e919Schristos      choke me
1317*d874e919Schristos#endif
1318*d874e919Schristos#if ZORK != 42
1319*d874e919Schristos      choke me
1320*d874e919Schristos#endif]])],
1321*d874e919Schristos    [ac_cv_fc_pp_define=$ac_flag])
1322*d874e919Schristos  test x"$ac_cv_fc_pp_define" != xunknown && break
1323*d874e919Schristosdone
1324*d874e919SchristosFCFLAGS=$ac_fc_pp_define_FCFLAGS_save
1325*d874e919Schristos])
1326*d874e919Schristosac_fc_srcext=$ac_fc_pp_define_srcext_save
1327*d874e919Schristosif test "x$ac_cv_fc_pp_define" = xunknown; then
1328*d874e919Schristos  FC_DEFINE=
1329*d874e919Schristos  m4_default([$2],
1330*d874e919Schristos	     [AC_MSG_ERROR([Fortran does not allow to define preprocessor symbols], 77)])
1331*d874e919Schristoselse
1332*d874e919Schristos  FC_DEFINE=$ac_cv_fc_pp_define
1333*d874e919Schristos  $1
1334*d874e919Schristosfi
1335*d874e919SchristosAC_SUBST([FC_DEFINE])dnl
1336*d874e919SchristosAC_LANG_POP([Fortran])dnl
1337*d874e919Schristos])
1338*d874e919Schristos
1339*d874e919Schristos
1340*d874e919Schristos# AC_FC_FREEFORM([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1341*d874e919Schristos# ------------------------------------------------------------------
1342*d874e919Schristos# Look for a compiler flag to make the Fortran (FC) compiler accept
1343*d874e919Schristos# free-format source code, and adds it to FCFLAGS.  Call
1344*d874e919Schristos# ACTION-IF-SUCCESS (defaults to nothing) if successful (i.e. can
1345*d874e919Schristos# compile code using new extension) and ACTION-IF-FAILURE (defaults to
1346*d874e919Schristos# failing with an error message) if not.  (Defined via DEFUN_ONCE to
1347*d874e919Schristos# prevent flag from being added to FCFLAGS multiple times.)
1348*d874e919Schristos#
1349*d874e919Schristos# The known flags are:
1350*d874e919Schristos#        -ffree-form: GNU g77, gfortran, g95
1351*d874e919Schristos#         -FR, -free: Intel compiler (icc, ecc, ifort)
1352*d874e919Schristos#              -free: Compaq compiler (fort), Sun compiler (f95)
1353*d874e919Schristos#             -qfree: IBM compiler (xlf)
1354*d874e919Schristos# -Mfree, -Mfreeform: Portland Group compiler
1355*d874e919Schristos#          -freeform: SGI compiler
1356*d874e919Schristos#        -8, -f free: Absoft Fortran
1357*d874e919Schristos#       +source=free: HP Fortran
1358*d874e919Schristos#    (-)-nfix, -Free: Lahey/Fujitsu Fortran
1359*d874e919Schristos#              -free: NAGWare
1360*d874e919Schristos#         -f, -Wf,-f: f2c (but only a weak form of "free-form" and long lines)
1361*d874e919Schristos# We try to test the "more popular" flags first, by some prejudiced
1362*d874e919Schristos# notion of popularity.
1363*d874e919SchristosAC_DEFUN_ONCE([AC_FC_FREEFORM],
1364*d874e919Schristos[AC_LANG_PUSH([Fortran])dnl
1365*d874e919SchristosAC_CACHE_CHECK([for Fortran flag needed to accept free-form source],
1366*d874e919Schristos	       [ac_cv_fc_freeform],
1367*d874e919Schristos[ac_cv_fc_freeform=unknown
1368*d874e919Schristosac_fc_freeform_FCFLAGS_save=$FCFLAGS
1369*d874e919Schristosfor ac_flag in none -ffree-form -FR -free -qfree -Mfree -Mfreeform \
1370*d874e919Schristos	       -freeform "-f free" -8 +source=free -nfix --nfix -Free
1371*d874e919Schristosdo
1372*d874e919Schristos  test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_freeform_FCFLAGS_save $ac_flag"
1373*d874e919Schristosdnl Use @&t@ below to ensure that editors don't turn 8+ spaces into tab.
1374*d874e919Schristos  AC_COMPILE_IFELSE([[
1375*d874e919Schristos  program freeform
1376*d874e919Schristos       ! FIXME: how to best confuse non-freeform compilers?
1377*d874e919Schristos       print *, 'Hello ', &
1378*d874e919Schristos     @&t@     'world.'
1379*d874e919Schristos       end]],
1380*d874e919Schristos		    [ac_cv_fc_freeform=$ac_flag; break])
1381*d874e919Schristosdone
1382*d874e919Schristosrm -f conftest.err conftest.$ac_objext conftest.$ac_ext
1383*d874e919SchristosFCFLAGS=$ac_fc_freeform_FCFLAGS_save
1384*d874e919Schristos])
1385*d874e919Schristosif test "x$ac_cv_fc_freeform" = xunknown; then
1386*d874e919Schristos  m4_default([$2],
1387*d874e919Schristos	     [AC_MSG_ERROR([Fortran does not accept free-form source], 77)])
1388*d874e919Schristoselse
1389*d874e919Schristos  if test "x$ac_cv_fc_freeform" != xnone; then
1390*d874e919Schristos    FCFLAGS="$FCFLAGS $ac_cv_fc_freeform"
1391*d874e919Schristos  fi
1392*d874e919Schristos  $1
1393*d874e919Schristosfi
1394*d874e919SchristosAC_LANG_POP([Fortran])dnl
1395*d874e919Schristos])# AC_FC_FREEFORM
1396*d874e919Schristos
1397*d874e919Schristos
1398*d874e919Schristos# AC_FC_FIXEDFORM([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1399*d874e919Schristos# ------------------------------------------------------------------
1400*d874e919Schristos# Look for a compiler flag to make the Fortran (FC) compiler accept
1401*d874e919Schristos# fixed-format source code, and adds it to FCFLAGS.  Call
1402*d874e919Schristos# ACTION-IF-SUCCESS (defaults to nothing) if successful (i.e. can
1403*d874e919Schristos# compile code using new extension) and ACTION-IF-FAILURE (defaults to
1404*d874e919Schristos# failing with an error message) if not.  (Defined via DEFUN_ONCE to
1405*d874e919Schristos# prevent flag from being added to FCFLAGS multiple times.)
1406*d874e919Schristos#
1407*d874e919Schristos# The known flags are:
1408*d874e919Schristos#       -ffixed-form: GNU g77, gfortran, g95
1409*d874e919Schristos#             -fixed: Intel compiler (ifort), Sun compiler (f95)
1410*d874e919Schristos#            -qfixed: IBM compiler (xlf*)
1411*d874e919Schristos#            -Mfixed: Portland Group compiler
1412*d874e919Schristos#         -fixedform: SGI compiler
1413*d874e919Schristos#           -f fixed: Absoft Fortran
1414*d874e919Schristos#      +source=fixed: HP Fortran
1415*d874e919Schristos#    (-)-fix, -Fixed: Lahey/Fujitsu Fortran
1416*d874e919Schristos#             -fixed: NAGWare
1417*d874e919Schristos# Since compilers may accept fixed form based on file name extension,
1418*d874e919Schristos# but users may want to use it with others as well, call AC_FC_SRCEXT
1419*d874e919Schristos# with the respective source extension before calling this macro.
1420*d874e919SchristosAC_DEFUN_ONCE([AC_FC_FIXEDFORM],
1421*d874e919Schristos[AC_LANG_PUSH([Fortran])dnl
1422*d874e919SchristosAC_CACHE_CHECK([for Fortran flag needed to accept fixed-form source],
1423*d874e919Schristos	       [ac_cv_fc_fixedform],
1424*d874e919Schristos[ac_cv_fc_fixedform=unknown
1425*d874e919Schristosac_fc_fixedform_FCFLAGS_save=$FCFLAGS
1426*d874e919Schristosfor ac_flag in none -ffixed-form -fixed -qfixed -Mfixed -fixedform "-f fixed" \
1427*d874e919Schristos	       +source=fixed -fix --fix -Fixed
1428*d874e919Schristosdo
1429*d874e919Schristos  test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_fixedform_FCFLAGS_save $ac_flag"
1430*d874e919Schristos  AC_COMPILE_IFELSE([[
1431*d874e919SchristosC     This comment should confuse free-form compilers.
1432*d874e919Schristos      program main
1433*d874e919Schristos      end]],
1434*d874e919Schristos		    [ac_cv_fc_fixedform=$ac_flag; break])
1435*d874e919Schristosdone
1436*d874e919Schristosrm -f conftest.err conftest.$ac_objext conftest.$ac_ext
1437*d874e919SchristosFCFLAGS=$ac_fc_fixedform_FCFLAGS_save
1438*d874e919Schristos])
1439*d874e919Schristosif test "x$ac_cv_fc_fixedform" = xunknown; then
1440*d874e919Schristos  m4_default([$2],
1441*d874e919Schristos	     [AC_MSG_ERROR([Fortran does not accept fixed-form source], 77)])
1442*d874e919Schristoselse
1443*d874e919Schristos  if test "x$ac_cv_fc_fixedform" != xnone; then
1444*d874e919Schristos    FCFLAGS="$FCFLAGS $ac_cv_fc_fixedform"
1445*d874e919Schristos  fi
1446*d874e919Schristos  $1
1447*d874e919Schristosfi
1448*d874e919SchristosAC_LANG_POP([Fortran])dnl
1449*d874e919Schristos])# AC_FC_FIXEDFORM
1450*d874e919Schristos
1451*d874e919Schristos
1452*d874e919Schristos# AC_FC_LINE_LENGTH([LENGTH], [ACTION-IF-SUCCESS],
1453*d874e919Schristos#		    [ACTION-IF-FAILURE = FAILURE])
1454*d874e919Schristos# ------------------------------------------------
1455*d874e919Schristos# Look for a compiler flag to make the Fortran (FC) compiler accept long lines
1456*d874e919Schristos# in the current (free- or fixed-format) source code, and adds it to FCFLAGS.
1457*d874e919Schristos# The optional LENGTH may be 80, 132 (default), or `unlimited' for longer
1458*d874e919Schristos# lines.  Note that line lengths above 254 columns are not portable, and some
1459*d874e919Schristos# compilers (hello ifort) do not accept more than 132 columns at least for
1460*d874e919Schristos# fixed format.  Call ACTION-IF-SUCCESS (defaults to nothing) if successful
1461*d874e919Schristos# (i.e. can compile code using new extension) and ACTION-IF-FAILURE (defaults
1462*d874e919Schristos# to failing with an error message) if not.  (Defined via DEFUN_ONCE to
1463*d874e919Schristos# prevent flag from being added to FCFLAGS multiple times.)
1464*d874e919Schristos# You should call AC_FC_FREEFORM or AC_FC_FIXEDFORM to set the desired format
1465*d874e919Schristos# prior to using this macro.
1466*d874e919Schristos#
1467*d874e919Schristos# The known flags are:
1468*d874e919Schristos# -f{free,fixed}-line-length-N with N 72, 80, 132, or 0 or none for none.
1469*d874e919Schristos# -ffree-line-length-none: GNU gfortran
1470*d874e919Schristos# -ffree-line-length-huge: g95 (also -ffixed-line-length-N as above)
1471*d874e919Schristos#       -qfixed=132 80 72: IBM compiler (xlf)
1472*d874e919Schristos#                -Mextend: Cray
1473*d874e919Schristos#            -132 -80 -72: Intel compiler (ifort)
1474*d874e919Schristos#                          Needs to come before -extend_source because ifort
1475*d874e919Schristos#                          accepts that as well with an optional parameter and
1476*d874e919Schristos#                          doesn't fail but only warns about unknown arguments.
1477*d874e919Schristos#          -extend_source: SGI compiler
1478*d874e919Schristos#  -W, -WNN (132, 80, 72): Absoft Fortran
1479*d874e919Schristos#     +es, +extend_source: HP Fortran (254 in either form, default is 72 fixed,
1480*d874e919Schristos#			   132 free)
1481*d874e919Schristos#            -w, (-)-wide: Lahey/Fujitsu Fortran (255 cols in fixed form)
1482*d874e919Schristos#                      -e: Sun Fortran compiler (132 characters)
1483*d874e919Schristos#                    -132: NAGWare
1484*d874e919Schristos#         -72, -f, -Wf,-f: f2c (a weak form of "free-form" and long lines).
1485*d874e919Schristos#                  /XLine: Open Watcom
1486*d874e919SchristosAC_DEFUN_ONCE([AC_FC_LINE_LENGTH],
1487*d874e919Schristos[AC_LANG_PUSH([Fortran])dnl
1488*d874e919Schristosm4_case(m4_default([$1], [132]),
1489*d874e919Schristos  [unlimited], [ac_fc_line_len_string=unlimited
1490*d874e919Schristos	               ac_fc_line_len=0
1491*d874e919Schristos                       ac_fc_line_length_test='
1492*d874e919Schristos      subroutine longer_than_132(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,'\
1493*d874e919Schristos'arg9,arg10,arg11,arg12,arg13,arg14,arg15,arg16,arg17,arg18,arg19)'],
1494*d874e919Schristos  [132],            [ac_fc_line_len=132
1495*d874e919Schristos		       ac_fc_line_length_test='
1496*d874e919Schristos      subroutine longer_than_80(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,'\
1497*d874e919Schristos'arg10)'],
1498*d874e919Schristos  [80],             [ac_fc_line_len=80
1499*d874e919Schristos		       ac_fc_line_length_test='
1500*d874e919Schristos      subroutine longer_than_72(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)'],
1501*d874e919Schristos  [m4_warning([Invalid length argument `$1'])])
1502*d874e919Schristos: ${ac_fc_line_len_string=$ac_fc_line_len}
1503*d874e919SchristosAC_CACHE_CHECK(
1504*d874e919Schristos[for Fortran flag needed to accept $ac_fc_line_len_string column source lines],
1505*d874e919Schristos	       [ac_cv_fc_line_length],
1506*d874e919Schristos[ac_cv_fc_line_length=unknown
1507*d874e919Schristosac_fc_line_length_FCFLAGS_save=$FCFLAGS
1508*d874e919Schristosfor ac_flag in none \
1509*d874e919Schristos	       -ffree-line-length-none -ffixed-line-length-none \
1510*d874e919Schristos	       -ffree-line-length-huge \
1511*d874e919Schristos	       -ffree-line-length-$ac_fc_line_len \
1512*d874e919Schristos	       -ffixed-line-length-$ac_fc_line_len \
1513*d874e919Schristos	       -qfixed=$ac_fc_line_len -Mextend \
1514*d874e919Schristos	       -$ac_fc_line_len -extend_source \
1515*d874e919Schristos	       -W$ac_fc_line_len -W +extend_source +es -wide --wide -w -e \
1516*d874e919Schristos               -f -Wf,-f -xline
1517*d874e919Schristosdo
1518*d874e919Schristos  test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_line_length_FCFLAGS_save $ac_flag"
1519*d874e919Schristos  AC_COMPILE_IFELSE([[$ac_fc_line_length_test
1520*d874e919Schristos      end subroutine]],
1521*d874e919Schristos		    [ac_cv_fc_line_length=$ac_flag; break])
1522*d874e919Schristosdone
1523*d874e919Schristosrm -f conftest.err conftest.$ac_objext conftest.$ac_ext
1524*d874e919SchristosFCFLAGS=$ac_fc_line_length_FCFLAGS_save
1525*d874e919Schristos])
1526*d874e919Schristosif test "x$ac_cv_fc_line_length" = xunknown; then
1527*d874e919Schristos  m4_default([$3],
1528*d874e919Schristos	     [AC_MSG_ERROR([Fortran does not accept long source lines], 77)])
1529*d874e919Schristoselse
1530*d874e919Schristos  if test "x$ac_cv_fc_line_length" != xnone; then
1531*d874e919Schristos    FCFLAGS="$FCFLAGS $ac_cv_fc_line_length"
1532*d874e919Schristos  fi
1533*d874e919Schristos  $2
1534*d874e919Schristosfi
1535*d874e919SchristosAC_LANG_POP([Fortran])dnl
1536*d874e919Schristos])# AC_FC_LINE_LENGTH
1537*d874e919Schristos
1538*d874e919Schristos
1539*d874e919Schristos# AC_FC_CHECK_BOUNDS([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1540*d874e919Schristos# ----------------------------------------------------------------------
1541*d874e919Schristos# Look for a compiler flag to turn on array bounds checking for the
1542*d874e919Schristos# Fortran (FC) compiler, and adds it to FCFLAGS.  Call
1543*d874e919Schristos# ACTION-IF-SUCCESS (defaults to nothing) if successful (i.e. can
1544*d874e919Schristos# compile code using new extension) and ACTION-IF-FAILURE (defaults to
1545*d874e919Schristos# failing with an error message) if not.  (Defined via DEFUN_ONCE to
1546*d874e919Schristos# prevent flag from being added to FCFLAGS multiple times.)
1547*d874e919Schristos#
1548*d874e919Schristos# The known flags are:
1549*d874e919Schristos# -fcheck=all, -fbounds-check: gfortran
1550*d874e919Schristos#     -fbounds-check: g77, g95
1551*d874e919Schristos# -CB, -check bounds: Intel compiler (icc, ecc, ifort)
1552*d874e919Schristos#                 -C: Sun/Oracle compiler (f95)
1553*d874e919Schristos#        -C, -qcheck: IBM compiler (xlf)
1554*d874e919Schristos#           -Mbounds: Portland Group compiler
1555*d874e919Schristos#       -C ,-Mbounds: Cray
1556*d874e919Schristos#  -C, -check_bounds: SGI compiler
1557*d874e919Schristos# -check_bounds, +check=all: HP Fortran
1558*d874e919Schristos#        -C, -Rb -Rc: Absoft (-Rb: array boundaries, -Rc: array conformance)
1559*d874e919Schristos# --chk e,s -chk (e,s): Lahey
1560*d874e919Schristos#          -C -C=all: NAGWare
1561*d874e919Schristos# -C, -ffortran-bounds-check: PathScale pathf90
1562*d874e919Schristos#                 -C: f2c
1563*d874e919Schristos#            -BOunds: Open Watcom
1564*d874e919SchristosAC_DEFUN_ONCE([AC_FC_CHECK_BOUNDS],
1565*d874e919Schristos[AC_LANG_PUSH([Fortran])dnl
1566*d874e919SchristosAC_CACHE_CHECK([for Fortran flag to enable array-bounds checking],
1567*d874e919Schristos               [ac_cv_fc_check_bounds],
1568*d874e919Schristos[ac_cv_fc_check_bounds=unknown
1569*d874e919Schristosac_fc_check_bounds_FCFLAGS_save=$FCFLAGS
1570*d874e919Schristosfor ac_flag in -fcheck=bounds -fbounds-check -check_bounds -Mbounds -qcheck \
1571*d874e919Schristos               '-check bounds' +check=all --check '-Rb -Rc' -CB -C=all -C \
1572*d874e919Schristos               -ffortran-bounds-check "--chk e,s" "-chk e -chk s" -bounds
1573*d874e919Schristosdo
1574*d874e919Schristos  FCFLAGS="$ac_fc_check_bounds_FCFLAGS_save $ac_flag"
1575*d874e919Schristos  # We should be able to link a correct program.
1576*d874e919Schristos  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
1577*d874e919Schristos    [AC_LINK_IFELSE([[
1578*d874e919Schristos      subroutine sub(a)
1579*d874e919Schristos      integer a(:)
1580*d874e919Schristos      a(8) = 0
1581*d874e919Schristos      end subroutine
1582*d874e919Schristos
1583*d874e919Schristos      program main
1584*d874e919Schristos      integer a(1:7)
1585*d874e919Schristos      interface
1586*d874e919Schristos         subroutine sub(a)
1587*d874e919Schristos         integer a(:)
1588*d874e919Schristos         end subroutine
1589*d874e919Schristos      end interface
1590*d874e919Schristos
1591*d874e919Schristos      call sub(a)
1592*d874e919Schristos      end program]],
1593*d874e919Schristos       [# If we can run the program, require failure at run time.
1594*d874e919Schristos	# In cross-compiling mode, we rely on the compiler not accepting
1595*d874e919Schristos	# unknown options.
1596*d874e919Schristos	AS_IF([test "$cross_compiling" = yes],
1597*d874e919Schristos	  [ac_cv_fc_check_bounds=$ac_flag; break],
1598*d874e919Schristos	  [AS_IF([_AC_DO_TOKENS(./conftest$ac_exeext)],
1599*d874e919Schristos	     [],
1600*d874e919Schristos	     [ac_cv_fc_check_bounds=$ac_flag; break])])])])
1601*d874e919Schristosdone
1602*d874e919Schristosrm -f conftest$ac_exeext conftest.err conftest.$ac_objext conftest.$ac_ext \
1603*d874e919Schristos  core *.core core.conftest.*
1604*d874e919SchristosFCFLAGS=$ac_fc_check_bounds_FCFLAGS_save
1605*d874e919Schristos])
1606*d874e919Schristosif test "x$ac_cv_fc_check_bounds" = xunknown; then
1607*d874e919Schristos  m4_default([$2],
1608*d874e919Schristos             [AC_MSG_ERROR([no Fortran flag for bounds checking found], 77)])
1609*d874e919Schristoselse
1610*d874e919Schristos  if test "x$ac_cv_fc_check_bounds" != xnone; then
1611*d874e919Schristos    FCFLAGS="$FCFLAGS $ac_cv_fc_check_bounds"
1612*d874e919Schristos  fi
1613*d874e919Schristos  $1
1614*d874e919Schristosfi
1615*d874e919SchristosAC_LANG_POP([Fortran])dnl
1616*d874e919Schristos])# AC_FC_CHECK_BOUNDS
1617*d874e919Schristos
1618*d874e919Schristos
1619*d874e919Schristos# _AC_FC_IMPLICIT_NONE([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1620*d874e919Schristos# ------------------------------------------------------------------------
1621*d874e919Schristos# Look for a flag to disallow implicit declarations, and add it to FCFLAGS.
1622*d874e919Schristos# Call ACTION-IF-SUCCESS (defaults to nothing) if successful and
1623*d874e919Schristos# ACTION-IF-FAILURE (defaults to failing with an error message) if not.
1624*d874e919Schristos#
1625*d874e919Schristos# Known flags:
1626*d874e919Schristos# GNU gfortran, g95: -fimplicit-none, g77: -Wimplicit
1627*d874e919Schristos# Intel: -u, -implicitnone; might also need '-warn errors' to turn into error.
1628*d874e919Schristos# Sun/Oracle: -u
1629*d874e919Schristos# HP: +implicit_none
1630*d874e919Schristos# IBM: -u, -qundef
1631*d874e919Schristos# SGI: -u
1632*d874e919Schristos# Compaq: -u, -warn declarations
1633*d874e919Schristos# NAGWare: -u
1634*d874e919Schristos# Lahey: -in, --in, -AT
1635*d874e919Schristos# Cray: -Mdclchk -e I
1636*d874e919Schristos# PGI: -Mcdlchk
1637*d874e919Schristos# f2c: -u
1638*d874e919SchristosAC_DEFUN([_AC_FC_IMPLICIT_NONE],
1639*d874e919Schristos[_AC_FORTRAN_ASSERT()dnl
1640*d874e919SchristosAC_CACHE_CHECK([for flag to disallow _AC_LANG implicit declarations],
1641*d874e919Schristos               [ac_cv_[]_AC_LANG_ABBREV[]_implicit_none],
1642*d874e919Schristos[ac_cv_[]_AC_LANG_ABBREV[]_implicit_none=unknown
1643*d874e919Schristosac_fc_implicit_none_[]_AC_LANG_PREFIX[]FLAGS_save=$[]_AC_LANG_PREFIX[]FLAGS
1644*d874e919Schristosfor ac_flag in none -fimplicit-none -u -Wimplicit -implicitnone +implicit_none \
1645*d874e919Schristos               -qundef "-warn declarations" -in --in -AT "-e I" -Mdclchk \
1646*d874e919Schristos               "-u -warn errors"
1647*d874e919Schristosdo
1648*d874e919Schristos  if test "x$ac_flag" != xnone; then
1649*d874e919Schristos    _AC_LANG_PREFIX[]FLAGS="$ac_fc_implicit_none_[]_AC_LANG_PREFIX[]FLAGS_save $ac_flag"
1650*d874e919Schristos  fi
1651*d874e919Schristos  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
1652*d874e919Schristos    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
1653*d874e919Schristos      i = 0
1654*d874e919Schristos      print *, i]])],
1655*d874e919Schristos       [],
1656*d874e919Schristos       [ac_cv_[]_AC_LANG_ABBREV[]_implicit_none=$ac_flag; break])])
1657*d874e919Schristosdone
1658*d874e919Schristosrm -f conftest.err conftest.$ac_objext conftest.$ac_ext
1659*d874e919Schristos_AC_LANG_PREFIX[]FLAGS=$ac_fc_implicit_none_[]_AC_LANG_PREFIX[]FLAGS_save
1660*d874e919Schristos])
1661*d874e919Schristosif test "x$ac_cv_[]_AC_LANG_ABBREV[]_implicit_none" = xunknown; then
1662*d874e919Schristos  m4_default([$3],
1663*d874e919Schristos    [AC_MSG_ERROR([no Fortran flag to disallow implicit declarations found], 77)])
1664*d874e919Schristoselse
1665*d874e919Schristos  if test "x$ac_cv_[]_AC_LANG_ABBREV[]_implicit_none" != xnone; then
1666*d874e919Schristos    _AC_LANG_PREFIX[]FLAGS="$_AC_LANG_PREFIX[]FLAGS $ac_cv_[]_AC_LANG_ABBREV[]_implicit_none"
1667*d874e919Schristos  fi
1668*d874e919Schristos  $2
1669*d874e919Schristosfi
1670*d874e919Schristos])# _AC_FC_IMPLICIT_NONE
1671*d874e919Schristos
1672*d874e919Schristos
1673*d874e919Schristos# AC_F77_IMPLICIT_NONE([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1674*d874e919Schristos# ------------------------------------------------------------------------
1675*d874e919SchristosAC_DEFUN([AC_F77_IMPLICIT_NONE],
1676*d874e919Schristos[AC_LANG_PUSH([Fortran 77])dnl
1677*d874e919Schristos_AC_FC_IMPLICIT_NONE($@)
1678*d874e919SchristosAC_LANG_POP([Fortran 77])dnl
1679*d874e919Schristos])# AC_F77_IMPLICIT_NONE
1680*d874e919Schristos
1681*d874e919Schristos
1682*d874e919Schristos# AC_FC_IMPLICIT_NONE([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1683*d874e919Schristos# -----------------------------------------------------------------------
1684*d874e919SchristosAC_DEFUN([AC_FC_IMPLICIT_NONE],
1685*d874e919Schristos[AC_LANG_PUSH([Fortran])dnl
1686*d874e919Schristos_AC_FC_IMPLICIT_NONE($@)
1687*d874e919SchristosAC_LANG_POP([Fortran])dnl
1688*d874e919Schristos])# AC_FC_IMPLICIT_NONE
1689*d874e919Schristos
1690*d874e919Schristos
1691*d874e919Schristos# AC_FC_MODULE_EXTENSION
1692*d874e919Schristos# ----------------------
1693*d874e919Schristos# Find the Fortran 90 module file extension.  The module extension is stored
1694*d874e919Schristos# in the variable FC_MODEXT and empty if it cannot be determined.  The result
1695*d874e919Schristos# or "unknown" is cached in the cache variable ac_cv_fc_module_ext.
1696*d874e919SchristosAC_DEFUN([AC_FC_MODULE_EXTENSION],
1697*d874e919Schristos[AC_CACHE_CHECK([Fortran 90 module extension], [ac_cv_fc_module_ext],
1698*d874e919Schristos[AC_LANG_PUSH(Fortran)
1699*d874e919Schristosmkdir conftest.dir
1700*d874e919Schristoscd conftest.dir
1701*d874e919Schristosac_cv_fc_module_ext=unknown
1702*d874e919SchristosAC_COMPILE_IFELSE([[
1703*d874e919Schristos      module conftest_module
1704*d874e919Schristos      contains
1705*d874e919Schristos      subroutine conftest_routine
1706*d874e919Schristos      write(*,'(a)') 'gotcha!'
1707*d874e919Schristos      end subroutine
1708*d874e919Schristos      end module]],
1709*d874e919Schristos  [ac_cv_fc_module_ext=`ls | sed -n 's,conftest_module\.,,p'`
1710*d874e919Schristos   if test x$ac_cv_fc_module_ext = x; then
1711*d874e919Schristosdnl Some F90 compilers use upper case characters for the module file name.
1712*d874e919Schristos     ac_cv_fc_module_ext=`ls | sed -n 's,CONFTEST_MODULE\.,,p'`
1713*d874e919Schristos   fi])
1714*d874e919Schristoscd ..
1715*d874e919Schristosrm -rf conftest.dir
1716*d874e919SchristosAC_LANG_POP(Fortran)
1717*d874e919Schristos])
1718*d874e919SchristosFC_MODEXT=$ac_cv_fc_module_ext
1719*d874e919Schristosif test "$FC_MODEXT" = unknown; then
1720*d874e919Schristos  FC_MODEXT=
1721*d874e919Schristosfi
1722*d874e919SchristosAC_SUBST([FC_MODEXT])dnl
1723*d874e919Schristos])
1724*d874e919Schristos
1725*d874e919Schristos
1726*d874e919Schristos# AC_FC_MODULE_FLAG([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1727*d874e919Schristos# ---------------------------------------------------------------------
1728*d874e919Schristos# Find a flag to include Fortran 90 modules from another directory.
1729*d874e919Schristos# If successful, run ACTION-IF-SUCCESS (defaults to nothing), otherwise
1730*d874e919Schristos# run ACTION-IF-FAILURE (defaults to failing with an error message).
1731*d874e919Schristos# The module flag is cached in the ac_cv_fc_module_flag variable.
1732*d874e919Schristos# It may contain significant trailing whitespace.
1733*d874e919Schristos#
1734*d874e919Schristos# Known flags:
1735*d874e919Schristos# gfortran: -Idir, -I dir (-M dir, -Mdir (deprecated), -Jdir for writing)
1736*d874e919Schristos# g95: -I dir (-fmod=dir for writing)
1737*d874e919Schristos# SUN: -Mdir, -M dir (-moddir=dir for writing;
1738*d874e919Schristos#                     -Idir for includes is also searched)
1739*d874e919Schristos# HP: -Idir, -I dir (+moddir=dir for writing)
1740*d874e919Schristos# IBM: -Idir (-qmoddir=dir for writing)
1741*d874e919Schristos# Intel: -Idir -I dir (-mod dir for writing)
1742*d874e919Schristos# Absoft: -pdir
1743*d874e919Schristos# Lahey: -mod dir
1744*d874e919Schristos# Cray: -module dir, -p dir (-J dir for writing)
1745*d874e919Schristos#       -e m is needed to enable writing .mod files at all
1746*d874e919Schristos# Compaq: -Idir
1747*d874e919Schristos# NAGWare: -I dir
1748*d874e919Schristos# PathScale: -I dir  (but -module dir is looked at first)
1749*d874e919Schristos# Portland: -module dir (first -module also names dir for writing)
1750*d874e919Schristos# Fujitsu: -Am -Idir (-Mdir for writing is searched first, then '.', then -I)
1751*d874e919Schristos#                    (-Am indicates how module information is saved)
1752*d874e919SchristosAC_DEFUN([AC_FC_MODULE_FLAG],[
1753*d874e919SchristosAC_CACHE_CHECK([Fortran 90 module inclusion flag], [ac_cv_fc_module_flag],
1754*d874e919Schristos[AC_LANG_PUSH([Fortran])
1755*d874e919Schristosac_cv_fc_module_flag=unknown
1756*d874e919Schristosmkdir conftest.dir
1757*d874e919Schristoscd conftest.dir
1758*d874e919SchristosAC_COMPILE_IFELSE([[
1759*d874e919Schristos      module conftest_module
1760*d874e919Schristos      contains
1761*d874e919Schristos      subroutine conftest_routine
1762*d874e919Schristos      write(*,'(a)') 'gotcha!'
1763*d874e919Schristos      end subroutine
1764*d874e919Schristos      end module]],
1765*d874e919Schristos  [cd ..
1766*d874e919Schristos   ac_fc_module_flag_FCFLAGS_save=$FCFLAGS
1767*d874e919Schristos   # Flag ordering is significant for gfortran and Sun.
1768*d874e919Schristos   for ac_flag in -M -I '-I ' '-M ' -p '-mod ' '-module ' '-Am -I'; do
1769*d874e919Schristos     # Add the flag twice to prevent matching an output flag.
1770*d874e919Schristos     FCFLAGS="$ac_fc_module_flag_FCFLAGS_save ${ac_flag}conftest.dir ${ac_flag}conftest.dir"
1771*d874e919Schristos     AC_COMPILE_IFELSE([[
1772*d874e919Schristos      program main
1773*d874e919Schristos      use conftest_module
1774*d874e919Schristos      call conftest_routine
1775*d874e919Schristos      end program]],
1776*d874e919Schristos       [ac_cv_fc_module_flag="$ac_flag"])
1777*d874e919Schristos     if test "$ac_cv_fc_module_flag" != unknown; then
1778*d874e919Schristos       break
1779*d874e919Schristos     fi
1780*d874e919Schristos   done
1781*d874e919Schristos   FCFLAGS=$ac_fc_module_flag_FCFLAGS_save
1782*d874e919Schristos])
1783*d874e919Schristosrm -rf conftest.dir
1784*d874e919SchristosAC_LANG_POP([Fortran])
1785*d874e919Schristos])
1786*d874e919Schristosif test "$ac_cv_fc_module_flag" != unknown; then
1787*d874e919Schristos  FC_MODINC=$ac_cv_fc_module_flag
1788*d874e919Schristos  $1
1789*d874e919Schristoselse
1790*d874e919Schristos  FC_MODINC=
1791*d874e919Schristos  m4_default([$2],
1792*d874e919Schristos    [AC_MSG_ERROR([unable to find compiler flag for module search path])])
1793*d874e919Schristosfi
1794*d874e919SchristosAC_SUBST([FC_MODINC])
1795*d874e919Schristos# Ensure trailing whitespace is preserved in a Makefile.
1796*d874e919SchristosAC_SUBST([ac_empty], [""])
1797*d874e919SchristosAC_CONFIG_COMMANDS_PRE([case $FC_MODINC in #(
1798*d874e919Schristos  *\ ) FC_MODINC=$FC_MODINC'${ac_empty}' ;;
1799*d874e919Schristosesac])dnl
1800*d874e919Schristos])
1801*d874e919Schristos
1802*d874e919Schristos
1803*d874e919Schristos# AC_FC_MODULE_OUTPUT_FLAG([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
1804*d874e919Schristos# ----------------------------------------------------------------------------
1805*d874e919Schristos# Find a flag to write Fortran 90 module information to another directory.
1806*d874e919Schristos# If successful, run ACTION-IF-SUCCESS (defaults to nothing), otherwise
1807*d874e919Schristos# run ACTION-IF-FAILURE (defaults to failing with an error message).
1808*d874e919Schristos# The module flag is cached in the ac_cv_fc_module_output_flag variable.
1809*d874e919Schristos# It may contain significant trailing whitespace.
1810*d874e919Schristos#
1811*d874e919Schristos# For known flags, see the documentation of AC_FC_MODULE_FLAG above.
1812*d874e919SchristosAC_DEFUN([AC_FC_MODULE_OUTPUT_FLAG],[
1813*d874e919SchristosAC_CACHE_CHECK([Fortran 90 module output flag], [ac_cv_fc_module_output_flag],
1814*d874e919Schristos[AC_LANG_PUSH([Fortran])
1815*d874e919Schristosmkdir conftest.dir conftest.dir/sub
1816*d874e919Schristoscd conftest.dir
1817*d874e919Schristosac_cv_fc_module_output_flag=unknown
1818*d874e919Schristosac_fc_module_output_flag_FCFLAGS_save=$FCFLAGS
1819*d874e919Schristos# Flag ordering is significant: put flags late which some compilers use
1820*d874e919Schristos# for the search path.
1821*d874e919Schristosfor ac_flag in -J '-J ' -fmod= -moddir= +moddir= -qmoddir= '-mod ' \
1822*d874e919Schristos	      '-module ' -M '-Am -M' '-e m -J '; do
1823*d874e919Schristos  FCFLAGS="$ac_fc_module_output_flag_FCFLAGS_save ${ac_flag}sub"
1824*d874e919Schristos  AC_COMPILE_IFELSE([[
1825*d874e919Schristos      module conftest_module
1826*d874e919Schristos      contains
1827*d874e919Schristos      subroutine conftest_routine
1828*d874e919Schristos      write(*,'(a)') 'gotcha!'
1829*d874e919Schristos      end subroutine
1830*d874e919Schristos      end module]],
1831*d874e919Schristos    [cd sub
1832*d874e919Schristos     AC_COMPILE_IFELSE([[
1833*d874e919Schristos      program main
1834*d874e919Schristos      use conftest_module
1835*d874e919Schristos      call conftest_routine
1836*d874e919Schristos      end program]],
1837*d874e919Schristos       [ac_cv_fc_module_output_flag="$ac_flag"])
1838*d874e919Schristos     cd ..
1839*d874e919Schristos     if test "$ac_cv_fc_module_output_flag" != unknown; then
1840*d874e919Schristos       break
1841*d874e919Schristos     fi])
1842*d874e919Schristosdone
1843*d874e919SchristosFCFLAGS=$ac_fc_module_output_flag_FCFLAGS_save
1844*d874e919Schristoscd ..
1845*d874e919Schristosrm -rf conftest.dir
1846*d874e919SchristosAC_LANG_POP([Fortran])
1847*d874e919Schristos])
1848*d874e919Schristosif test "$ac_cv_fc_module_output_flag" != unknown; then
1849*d874e919Schristos  FC_MODOUT=$ac_cv_fc_module_output_flag
1850*d874e919Schristos  $1
1851*d874e919Schristoselse
1852*d874e919Schristos  FC_MODOUT=
1853*d874e919Schristos  m4_default([$2],
1854*d874e919Schristos    [AC_MSG_ERROR([unable to find compiler flag to write module information to])])
1855*d874e919Schristosfi
1856*d874e919SchristosAC_SUBST([FC_MODOUT])
1857*d874e919Schristos# Ensure trailing whitespace is preserved in a Makefile.
1858*d874e919SchristosAC_SUBST([ac_empty], [""])
1859*d874e919SchristosAC_CONFIG_COMMANDS_PRE([case $FC_MODOUT in #(
1860*d874e919Schristos  *\ ) FC_MODOUT=$FC_MODOUT'${ac_empty}' ;;
1861*d874e919Schristosesac])dnl
1862*d874e919Schristos])
1863