1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
|
dnl/*D
dnl PAC_PROG_F77_CMDARGS - Determine how to access the command line from
dnl Fortran 77
dnl
dnl Output Effects:
dnl The following variables are set:
dnl.vb
dnl F77_GETARG - Statement to get an argument i into string s
dnl F77_IARGC - Routine to return the number of arguments
dnl FXX_MODULE - Module command when using Fortran 90 compiler
dnl F77_GETARGDECL - Declaration of routine used for F77_GETARG
dnl F77_GETARG_FFLAGS - Flags needed when compiling/linking
dnl F77_GETARG_LDFLAGS - Flags needed when linking
dnl.ve
dnl If 'F77_GETARG' has a value, then that value and the values for these
dnl other symbols will be used instead. If no approach is found, all of these
dnl variables will have empty values.
dnl If no other approach works and a file 'f77argdef' is in the directory,
dnl that file will be sourced for the values of the above four variables.
dnl
dnl In most cases, you should add F77_GETARG_FFLAGS to the FFLAGS variable
dnl and F77_GETARG_LDFLAGS to the LDFLAGS variable, to ensure that tests are
dnl performed on the compiler version that will be used.
dnl
dnl 'AC_SUBST' is called for all six variables.
dnl
dnl One complication is that on systems with multiple Fortran compilers,
dnl some libraries used by one Fortran compiler may have been (mis)placed
dnl in a common location. We have had trouble with libg2c in particular.
dnl To work around this, we test whether iargc etc. work first. This
dnl will catch most systems and will speed up the tests.
dnl
dnl Next, the libraries are only added if they are needed to complete a
dnl link; they aren''t added just because they exist.
dnl
dnl f77argdef
dnl D*/
dnl
dnl Random notes
dnl You can export the command line arguments from C to the g77 compiler
dnl using
dnl extern char **__libc_argv;
dnl extern int __libc_argc;
dnl f_setarg( __libc_argc, __libc_argv );
dnl
AC_DEFUN([PAC_PROG_F77_CMDARGS],[
found_cached="yes"
AC_MSG_CHECKING([for routines to access the command line from Fortran 77])
AC_CACHE_VAL(pac_cv_prog_f77_cmdarg,
[
AC_MSG_RESULT([searching...])
found_cached="no"
# First, we perform a quick check. Does iargc and getarg work?
fxx_module="${FXX_MODULE:-}"
f77_getargdecl="${F77_GETARGDECL:-external getarg}"
f77_getarg="${F77_GETARG:-call GETARG(i,s)}"
f77_iargc="${F77_IARGC:-IARGC()}"
#
# Grumble. The Absoft Fortran compiler computes i - i as 0 and then
# 1.0 / 0 at compile time, even though the code may never be executed.
# What we need is a way to generate an error, so the second usage of i
# was replaced with f77_iargc.
cat > conftest.f <<EOF
program main
$fxx_module
integer i, j
character*20 s
$f77_getargdecl
i = 0
$f77_getarg
i=$f77_iargc
if (i .gt. 1) then
j = i - $f77_iargc
j = 1.0 / j
endif
end
EOF
found_answer="no"
if test -z "$ac_fcompilelink" ; then
ac_fcompilelink="${F77-f77} -o conftest $FFLAGS $flags conftest.f $LDFLAGS $LIBS 1>&AS_MESSAGE_LOG_FD"
fi
AC_MSG_CHECKING([whether ${F77-f77} $flags $libs works with GETARG and IARGC])
if AC_TRY_EVAL(ac_fcompilelink) && test -x conftest ; then
# Check that cross != yes so that this works with autoconf 2.52
# Check that cross_compiling != yes so that this works with
# autoconf 2.6x for some (but almost certainly not all)x
# Question: why do we test that this runs? It looks like we
# needed this for some old Fortran compilers that produced
# executable code that then did not run.
if test "$ac_cv_prog_f77_cross" != "yes" -a \
"$cross_compiling" != "yes" ; then
if ./conftest >/dev/null 2>&1 ; then
found_answer="yes"
FXX_MODULE="$fxx_module"
F77_GETARGDECL="$f77_getargdecl"
F77_GETARG="$f77_getarg"
F77_IARGC="$f77_iargc"
AC_MSG_RESULT(yes)
fi
fi
fi
if test $found_answer = "no" ; then
AC_MSG_RESULT(no)
# Grumph. Here are a bunch of different approaches
# We have several axes the check:
# Library to link with (none, -lU77 (HPUX), -lg2c (LINUX f77))
# PEPCF90 (Intel ifc)
# The first line is a dummy
# (we experimented with using a <space>, but this caused other
# problems because we need <space> in the IFS)
trial_LIBS="0 -lU77 -lPEPCF90"
if test "$NOG2C" != "1" ; then
trial_LIBS="$trial_LIBS -lg2c"
fi
# Discard libs that are not available:
save_IFS="$IFS"
# Make sure that IFS includes a space, or the tests that run programs
# may fail
IFS=" ""
"
save_trial_LIBS="$trial_LIBS"
trial_LIBS=""
cat > conftest.f <<EOF
program main
end
EOF
ac_fcompilelink_test='${F77-f77} -o conftest $FFLAGS conftest.f $LDFLAGS $libs $LIBS 1>&AS_MESSAGE_LOG_FD'
for libs in $save_trial_LIBS ; do
if test "$libs" = "0" ; then
lib_ok="yes"
else
AC_MSG_CHECKING([whether Fortran 77 links with $libs])
if AC_TRY_EVAL(ac_fcompilelink_test) && test -x conftest ; then
AC_MSG_RESULT([yes])
lib_ok="yes"
else
AC_MSG_RESULT([no])
lib_ok="no"
fi
fi
if test "$lib_ok" = "yes" ; then
trial_LIBS="$trial_LIBS
$libs"
fi
done
# Options to use when compiling and linking
# +U77 is needed by HP Fortran to access getarg etc.
# The -N109 was used for getarg before we realized that GETARG
# was necessary with the (non standard conforming) Absoft compiler
# (Fortran is monocase; Absoft uses mixedcase by default)
# The -f is used by Absoft and is the compiler switch that folds
# symbolic names to lower case. Without this option, the compiler
# considers upper- and lower-case letters to be unique.
# The -YEXT_NAMES=LCS will cause external names to be output as lower
# case letter for Absoft F90 compilers (default is upper case)
# The first line is "<space><newline>, the space is important
# To make the Absoft f77 and f90 work together, we need to prefer the
# upper case versions of the arguments. They also require libU77.
# -YCFRL=1 causes Absoft f90 to work with g77 and similar (f2c-based)
# Fortran compilers
#
# Problem: The Intel efc compiler hangs when presented with -N109 .
# The only real fix for this is to detect this compiler and exclude
# the test. We may want to reorganize these tests so that if we
# can compile code without special options, we never look for them.
#
using_intel_efc="no"
pac_test_msg=`$F77 -V 2>&1 | grep 'Intel(R) Fortran Itanium'`
if test "$pac_test_msg" != "" ; then
using_intel_efc="yes"
fi
if test "$using_intel_efc" = "yes" ; then
trial_FLAGS="000"
else
trial_FLAGS="000
-N109
-f
-YEXT_NAMES=UCS
-YEXT_NAMES=LCS
-YCFRL=1
+U77"
fi
# Discard options that are not available:
# (IFS already saved above)
IFS=" ""
"
save_trial_FLAGS="$trial_FLAGS"
trial_FLAGS=""
for flag in $save_trial_FLAGS ; do
if test "$flag" = " " -o "$flag" = "000" ; then
opt_ok="yes"
else
PAC_F77_CHECK_COMPILER_OPTION($flag,opt_ok=yes,opt_ok=no)
fi
if test "$opt_ok" = "yes" ; then
if test "$flag" = " " -o "$flag" = "000" ; then
fflag=""
else
fflag="$flag"
fi
# discard options that don't allow mixed-case name matching
cat > conftest.f <<EOF
program main
call aB()
end
subroutine Ab()
end
EOF
if test -n "$fflag" ; then flagval="with $fflag" ; else flagval="" ; fi
AC_MSG_CHECKING([whether Fortran 77 routine names are case-insensitive $flagval])
dnl we can use double quotes here because all is already
dnl evaluated
ac_fcompilelink_test="${F77-f77} -o conftest $fflag $FFLAGS conftest.f $LDFLAGS $LIBS 1>&AS_MESSAGE_LOG_FD"
if AC_TRY_EVAL(ac_fcompilelink_test) && test -x conftest ; then
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
opt_ok="no"
fi
fi
if test "$opt_ok" = "yes" ; then
trial_FLAGS="$trial_FLAGS
$flag"
fi
done
IFS="$save_IFS"
# Name of routines. Since these are in groups, we use a case statement
# and loop until the end (accomplished by reaching the end of the
# case statement
# For one version of Nag F90, the names are
# call f90_unix_MP_getarg(i,s) and f90_unix_MP_iargc().
trial=0
while test -z "$pac_cv_prog_f77_cmdarg" ; do
case $trial in
0) # User-specified values, if any
if test -z "$F77_GETARG" -o -z "$F77_IARGC" ; then
trial=`expr $trial + 1`
continue
fi
MSG="Using environment values of F77_GETARG etc."
;;
1) # Standard practice, uppercase (some compilers are case-sensitive)
FXX_MODULE=""
F77_GETARGDECL="external GETARG"
F77_GETARG="call GETARG(i,s)"
F77_IARGC="IARGC()"
MSG="GETARG and IARGC"
;;
2) # Standard practice, lowercase
FXX_MODULE=""
F77_GETARGDECL="external getarg"
F77_GETARG="call getarg(i,s)"
F77_IARGC="iargc()"
MSG="getarg and iargc"
;;
3) # Posix alternative
FXX_MODULE=""
F77_GETARGDECL="external pxfgetarg"
F77_GETARG="call pxfgetarg(i,s,l,ier)"
F77_IARGC="ipxfargc()"
MSG="pxfgetarg and ipxfargc"
;;
4) # Nag f90_unix_env module
FXX_MODULE=" use f90_unix_env"
F77_GETARGDECL=""
F77_GETARG="call getarg(i,s)"
F77_IARGC="iargc()"
MSG="f90_unix_env module"
;;
5) # Nag f90_unix module
FXX_MODULE=" use f90_unix"
F77_GETARGDECL=""
F77_GETARG="call getarg(i,s)"
F77_IARGC="iargc()"
MSG="f90_unix module"
;;
6) # user spec in a file
if test -s f77argdef ; then
. ./f77argdef
MSG="Using definitions in the file f77argdef"
else
trial=`expr $trial + 1`
continue
fi
;;
7) # gfortran won't find getarg if it is marked as external
FXX_MODULE=""
F77_GETARGDECL="intrinsic GETARG"
F77_GETARG="call GETARG(i,s)"
F77_IARGC="IARGC()"
MSG="intrinsic GETARG and IARGC"
;;
*) # exit from while loop
FXX_MODULE=""
F77_GETARGDECL=""
F77_GETARG=""
F77_IARGC=""
break
;;
esac
# Create the program. Make sure that we can run it.
# Force a divide-by-zero if there is a problem (but only at runtime!
# (the Absoft compiler does divide-by-zero at compile time)
cat > conftest.f <<EOF
program main
$FXX_MODULE
integer i, j
character*20 s
$F77_GETARGDECL
i = 0
$F77_GETARG
i=$F77_IARGC
if (i .gt. 1) then
j = i - $F77_IARGC
j = 1.0 / j
endif
end
EOF
#
# Now, try to find some way to compile and link that program, looping
# over the possibilities of options and libraries
save_IFS="$IFS"
IFS=" ""
"
for libs in $trial_LIBS ; do
if test -n "$pac_cv_prog_f77_cmdarg" ; then break ; fi
if test "$libs" = " " -o "$libs" = "0" ; then libs="" ; fi
for flags in $trial_FLAGS ; do
if test "$flags" = " " -o "$flags" = "000"; then flags="" ; fi
AC_MSG_CHECKING([whether ${F77-f77} $flags $libs works with $MSG])
IFS="$save_IFS"
dnl We need this here because we've fiddled with IFS
ac_fcompilelink_test="${F77-f77} -o conftest $FFLAGS $flags conftest.f $LDFLAGS $libs $LIBS 1>&AS_MESSAGE_LOG_FD"
found_answer="no"
if AC_TRY_EVAL(ac_fcompilelink_test) && test -x conftest ; then
if test "$ac_cv_prog_f77_cross" != "yes" -a \
"$cross_compiling" != "yes" ; then
if ./conftest >/dev/null 2>&1 ; then
found_answer="yes"
fi
else
found_answer="yes"
fi
fi
IFS=" ""
"
if test "$found_answer" = "yes" ; then
AC_MSG_RESULT([yes])
pac_cv_prog_f77_cmdarg="$MSG"
pac_cv_prog_f77_cmdarg_fflags="$flags"
pac_cv_prog_f77_cmdarg_ldflags="$libs"
break
else
AC_MSG_RESULT([no])
echo "configure: failed program was:" >&AS_MESSAGE_LOG_FD
cat conftest.f >&AS_MESSAGE_LOG_FD
fi
done
done
IFS="$save_IFS"
rm -f conftest.*
trial=`expr $trial + 1`
done
fi
pac_cv_F77_GETARGDECL="$F77_GETARGDECL"
pac_cv_F77_IARGC="$F77_IARGC"
pac_cv_F77_GETARG="$F77_GETARG"
pac_cv_FXX_MODULE="$FXX_MODULE"
])
if test "$found_cached" = "yes" ; then
AC_MSG_RESULT([$pac_cv_prog_f77_cmdarg])
elif test -z "$pac_cv_F77_IARGC" ; then
AC_MSG_WARN([Could not find a way to access the command line from Fortran 77])
fi
# Set the variable values based on pac_cv_prog_xxx
F77_GETARGDECL="$pac_cv_F77_GETARGDECL"
F77_IARGC="$pac_cv_F77_IARGC"
F77_GETARG="$pac_cv_F77_GETARG"
FXX_MODULE="$pac_cv_FXX_MODULE"
F77_GETARG_FFLAGS="$pac_cv_prog_f77_cmdarg_fflags"
F77_GETARG_LDFLAGS="$pac_cv_prog_f77_cmdarg_ldflags"
AC_SUBST(F77_GETARGDECL)
AC_SUBST(F77_IARGC)
AC_SUBST(F77_GETARG)
AC_SUBST(FXX_MODULE)
AC_SUBST(F77_GETARG_FFLAGS)
AC_SUBST(F77_GETARG_LDFLAGS)
])
|