2 dnl PAC_PROG_F77_CMDARGS - Determine how to access the command line from
6 dnl The following variables are set:
8 dnl F77_GETARG - Statement to get an argument i into string s
9 dnl F77_IARGC - Routine to return the number of arguments
10 dnl FXX_MODULE - Module command when using Fortran 90 compiler
11 dnl F77_GETARGDECL - Declaration of routine used for F77_GETARG
12 dnl F77_GETARG_FFLAGS - Flags needed when compiling/linking
13 dnl F77_GETARG_LDFLAGS - Flags needed when linking
15 dnl If 'F77_GETARG' has a value, then that value and the values for these
16 dnl other symbols will be used instead. If no approach is found, all of these
17 dnl variables will have empty values.
18 dnl If no other approach works and a file 'f77argdef' is in the directory,
19 dnl that file will be sourced for the values of the above four variables.
21 dnl In most cases, you should add F77_GETARG_FFLAGS to the FFLAGS variable
22 dnl and F77_GETARG_LDFLAGS to the LDFLAGS variable, to ensure that tests are
23 dnl performed on the compiler version that will be used.
25 dnl 'AC_SUBST' is called for all six variables.
27 dnl One complication is that on systems with multiple Fortran compilers,
28 dnl some libraries used by one Fortran compiler may have been (mis)placed
29 dnl in a common location. We have had trouble with libg2c in particular.
30 dnl To work around this, we test whether iargc etc. work first. This
31 dnl will catch most systems and will speed up the tests.
33 dnl Next, the libraries are only added if they are needed to complete a
34 dnl link; they aren''t added just because they exist.
40 dnl You can export the command line arguments from C to the g77 compiler
42 dnl extern char **__libc_argv;
43 dnl extern int __libc_argc;
44 dnl f_setarg( __libc_argc, __libc_argv );
46 AC_DEFUN([PAC_PROG_F77_CMDARGS],[
48 AC_MSG_CHECKING([for routines to access the command line from Fortran 77])
49 AC_CACHE_VAL(pac_cv_prog_f77_cmdarg,
51 AC_MSG_RESULT([searching...])
53 # First, we perform a quick check. Does iargc and getarg work?
54 fxx_module="${FXX_MODULE:-}"
55 f77_getargdecl="${F77_GETARGDECL:-external getarg}"
56 f77_getarg="${F77_GETARG:-call GETARG(i,s)}"
57 f77_iargc="${F77_IARGC:-IARGC()}"
59 # Grumble. The Absoft Fortran compiler computes i - i as 0 and then
60 # 1.0 / 0 at compile time, even though the code may never be executed.
61 # What we need is a way to generate an error, so the second usage of i
62 # was replaced with f77_iargc.
63 cat > conftest.f <<EOF
79 if test -z "$ac_fcompilelink" ; then
80 ac_fcompilelink="${F77-f77} -o conftest $FFLAGS $flags conftest.f $LDFLAGS $LIBS 1>&AC_FD_CC"
82 AC_MSG_CHECKING([whether ${F77-f77} $flags $libs works with GETARG and IARGC])
83 if AC_TRY_EVAL(ac_fcompilelink) && test -x conftest ; then
84 # Check that cross != yes so that this works with autoconf 2.52
85 # Check that cross_compiling != yes so that this works with
86 # autoconf 2.6x for some (but almost certainly not all)x
87 # Question: why do we test that this runs? It looks like we
88 # needed this for some old Fortran compilers that produced
89 # executable code that then did not run.
90 if test "$ac_cv_prog_f77_cross" != "yes" -a \
91 "$cross_compiling" != "yes" ; then
92 if ./conftest >/dev/null 2>&1 ; then
94 FXX_MODULE="$fxx_module"
95 F77_GETARGDECL="$f77_getargdecl"
96 F77_GETARG="$f77_getarg"
97 F77_IARGC="$f77_iargc"
102 if test $found_answer = "no" ; then
104 # Grumph. Here are a bunch of different approaches
105 # We have several axes the check:
106 # Library to link with (none, -lU77 (HPUX), -lg2c (LINUX f77))
107 # PEPCF90 (Intel ifc)
108 # The first line is a dummy
109 # (we experimented with using a <space>, but this caused other
110 # problems because we need <space> in the IFS)
111 trial_LIBS="0 -lU77 -lPEPCF90"
112 if test "$NOG2C" != "1" ; then
113 trial_LIBS="$trial_LIBS -lg2c"
115 # Discard libs that are not availble:
117 # Make sure that IFS includes a space, or the tests that run programs
121 save_trial_LIBS="$trial_LIBS"
123 cat > conftest.f <<EOF
127 ac_fcompilelink_test='${F77-f77} -o conftest $FFLAGS conftest.f $LDFLAGS $libs $LIBS 1>&AC_FD_CC'
128 for libs in $save_trial_LIBS ; do
129 if test "$libs" = "0" ; then
132 AC_MSG_CHECKING([whether Fortran 77 links with $libs])
133 if AC_TRY_EVAL(ac_fcompilelink_test) && test -x conftest ; then
141 if test "$lib_ok" = "yes" ; then
142 trial_LIBS="$trial_LIBS
147 # Options to use when compiling and linking
148 # +U77 is needed by HP Fortran to access getarg etc.
149 # The -N109 was used for getarg before we realized that GETARG
150 # was necessary with the (non standard conforming) Absoft compiler
151 # (Fortran is monocase; Absoft uses mixedcase by default)
152 # The -f is used by Absoft and is the compiler switch that folds
153 # symbolic names to lower case. Without this option, the compiler
154 # considers upper- and lower-case letters to be unique.
155 # The -YEXT_NAMES=LCS will cause external names to be output as lower
156 # case letter for Absoft F90 compilers (default is upper case)
157 # The first line is "<space><newline>, the space is important
158 # To make the Absoft f77 and f90 work together, we need to prefer the
159 # upper case versions of the arguments. They also require libU77.
160 # -YCFRL=1 causes Absoft f90 to work with g77 and similar (f2c-based)
163 # Problem: The Intel efc compiler hangs when presented with -N109 .
164 # The only real fix for this is to detect this compiler and exclude
165 # the test. We may want to reorganize these tests so that if we
166 # can compile code without special options, we never look for them.
169 pac_test_msg=`$F77 -V 2>&1 | grep 'Intel(R) Fortran Itanium'`
170 if test "$pac_test_msg" != "" ; then
171 using_intel_efc="yes"
173 if test "$using_intel_efc" = "yes" ; then
184 # Discard options that are not available:
185 # (IFS already saved above)
188 save_trial_FLAGS="$trial_FLAGS"
190 for flag in $save_trial_FLAGS ; do
191 if test "$flag" = " " -o "$flag" = "000" ; then
194 PAC_F77_CHECK_COMPILER_OPTION($flag,opt_ok=yes,opt_ok=no)
196 if test "$opt_ok" = "yes" ; then
197 if test "$flag" = " " -o "$flag" = "000" ; then
202 # discard options that don't allow mixed-case name matching
203 cat > conftest.f <<EOF
210 if test -n "$fflag" ; then flagval="with $fflag" ; else flagval="" ; fi
211 AC_MSG_CHECKING([whether Fortran 77 routine names are case-insensitive $flagval])
212 dnl we can use double quotes here because all is already
214 ac_fcompilelink_test="${F77-f77} -o conftest $fflag $FFLAGS conftest.f $LDFLAGS $LIBS 1>&AC_FD_CC"
215 if AC_TRY_EVAL(ac_fcompilelink_test) && test -x conftest ; then
222 if test "$opt_ok" = "yes" ; then
223 trial_FLAGS="$trial_FLAGS
228 # Name of routines. Since these are in groups, we use a case statement
229 # and loop until the end (accomplished by reaching the end of the
231 # For one version of Nag F90, the names are
232 # call f90_unix_MP_getarg(i,s) and f90_unix_MP_iargc().
234 while test -z "$pac_cv_prog_f77_cmdarg" ; do
236 0) # User-specified values, if any
237 if test -z "$F77_GETARG" -o -z "$F77_IARGC" ; then
238 trial=`expr $trial + 1`
241 MSG="Using environment values of F77_GETARG etc."
243 1) # Standard practice, uppercase (some compilers are case-sensitive)
245 F77_GETARGDECL="external GETARG"
246 F77_GETARG="call GETARG(i,s)"
248 MSG="GETARG and IARGC"
250 2) # Standard practice, lowercase
252 F77_GETARGDECL="external getarg"
253 F77_GETARG="call getarg(i,s)"
255 MSG="getarg and iargc"
257 3) # Posix alternative
259 F77_GETARGDECL="external pxfgetarg"
260 F77_GETARG="call pxfgetarg(i,s,l,ier)"
261 F77_IARGC="ipxfargc()"
262 MSG="pxfgetarg and ipxfargc"
264 4) # Nag f90_unix_env module
265 FXX_MODULE=" use f90_unix_env"
267 F77_GETARG="call getarg(i,s)"
269 MSG="f90_unix_env module"
271 5) # Nag f90_unix module
272 FXX_MODULE=" use f90_unix"
274 F77_GETARG="call getarg(i,s)"
276 MSG="f90_unix module"
278 6) # user spec in a file
279 if test -s f77argdef ; then
281 MSG="Using definitions in the file f77argdef"
283 trial=`expr $trial + 1`
287 7) # gfortran won't find getarg if it is marked as external
289 F77_GETARGDECL="intrinsic GETARG"
290 F77_GETARG="call GETARG(i,s)"
292 MSG="intrinsic GETARG and IARGC"
294 *) # exit from while loop
302 # Create the program. Make sure that we can run it.
303 # Force a divide-by-zero if there is a problem (but only at runtime!
304 # (the Absoft compiler does divide-by-zero at compile time)
305 cat > conftest.f <<EOF
321 # Now, try to find some way to compile and link that program, looping
322 # over the possibilities of options and libraries
326 for libs in $trial_LIBS ; do
327 if test -n "$pac_cv_prog_f77_cmdarg" ; then break ; fi
328 if test "$libs" = " " -o "$libs" = "0" ; then libs="" ; fi
329 for flags in $trial_FLAGS ; do
330 if test "$flags" = " " -o "$flags" = "000"; then flags="" ; fi
331 AC_MSG_CHECKING([whether ${F77-f77} $flags $libs works with $MSG])
333 dnl We need this here because we've fiddled with IFS
334 ac_fcompilelink_test="${F77-f77} -o conftest $FFLAGS $flags conftest.f $LDFLAGS $libs $LIBS 1>&AC_FD_CC"
336 if AC_TRY_EVAL(ac_fcompilelink_test) && test -x conftest ; then
337 if test "$ac_cv_prog_f77_cross" != "yes" -a \
338 "$cross_compiling" != "yes" ; then
339 if ./conftest >/dev/null 2>&1 ; then
348 if test "$found_answer" = "yes" ; then
350 pac_cv_prog_f77_cmdarg="$MSG"
351 pac_cv_prog_f77_cmdarg_fflags="$flags"
352 pac_cv_prog_f77_cmdarg_ldflags="$libs"
356 echo "configure: failed program was:" >&AC_FD_CC
357 cat conftest.f >&AC_FD_CC
363 trial=`expr $trial + 1`
366 pac_cv_F77_GETARGDECL="$F77_GETARGDECL"
367 pac_cv_F77_IARGC="$F77_IARGC"
368 pac_cv_F77_GETARG="$F77_GETARG"
369 pac_cv_FXX_MODULE="$FXX_MODULE"
371 if test "$found_cached" = "yes" ; then
372 AC_MSG_RESULT([$pac_cv_prog_f77_cmdarg])
373 elif test -z "$pac_cv_F77_IARGC" ; then
374 AC_MSG_WARN([Could not find a way to access the command line from Fortran 77])
376 # Set the variable values based on pac_cv_prog_xxx
377 F77_GETARGDECL="$pac_cv_F77_GETARGDECL"
378 F77_IARGC="$pac_cv_F77_IARGC"
379 F77_GETARG="$pac_cv_F77_GETARG"
380 FXX_MODULE="$pac_cv_FXX_MODULE"
381 F77_GETARG_FFLAGS="$pac_cv_prog_f77_cmdarg_fflags"
382 F77_GETARG_LDFLAGS="$pac_cv_prog_f77_cmdarg_ldflags"
383 AC_SUBST(F77_GETARGDECL)
387 AC_SUBST(F77_GETARG_FFLAGS)
388 AC_SUBST(F77_GETARG_LDFLAGS)