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 </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 , but this caused other # problems because we need in the IFS) trial_LIBS="0 -lU77 -lPEPCF90" if test "$NOG2C" != "1" ; then trial_LIBS="$trial_LIBS -lg2c" fi # Discard libs that are not availble: 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 <, 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 < conftest.f </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:" >&AC_FD_CC cat conftest.f >&AC_FD_CC 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) ])