Blame confdb/aclocal_f77old.m4

Packit 0848f5
dnl/*D
Packit 0848f5
dnl PAC_PROG_F77_CMDARGS - Determine how to access the command line from
Packit 0848f5
dnl Fortran 77
Packit 0848f5
dnl
Packit 0848f5
dnl Output Effects:
Packit 0848f5
dnl  The following variables are set:
Packit 0848f5
dnl.vb
Packit 0848f5
dnl    F77_GETARG         - Statement to get an argument i into string s
Packit 0848f5
dnl    F77_IARGC          - Routine to return the number of arguments
Packit 0848f5
dnl    FXX_MODULE         - Module command when using Fortran 90 compiler
Packit 0848f5
dnl    F77_GETARGDECL     - Declaration of routine used for F77_GETARG
Packit 0848f5
dnl    F77_GETARG_FFLAGS  - Flags needed when compiling/linking
Packit 0848f5
dnl    F77_GETARG_LDFLAGS - Flags needed when linking
Packit 0848f5
dnl.ve
Packit 0848f5
dnl If 'F77_GETARG' has a value, then that value and the values for these
Packit 0848f5
dnl other symbols will be used instead.  If no approach is found, all of these
Packit 0848f5
dnl variables will have empty values.
Packit 0848f5
dnl If no other approach works and a file 'f77argdef' is in the directory, 
Packit 0848f5
dnl that file will be sourced for the values of the above four variables.
Packit 0848f5
dnl
Packit 0848f5
dnl In most cases, you should add F77_GETARG_FFLAGS to the FFLAGS variable
Packit 0848f5
dnl and F77_GETARG_LDFLAGS to the LDFLAGS variable, to ensure that tests are
Packit 0848f5
dnl performed on the compiler version that will be used.
Packit 0848f5
dnl
Packit 0848f5
dnl 'AC_SUBST' is called for all six variables.
Packit 0848f5
dnl
Packit 0848f5
dnl One complication is that on systems with multiple Fortran compilers, 
Packit 0848f5
dnl some libraries used by one Fortran compiler may have been (mis)placed
Packit 0848f5
dnl in a common location.  We have had trouble with libg2c in particular.
Packit 0848f5
dnl To work around this, we test whether iargc etc. work first.  This
Packit 0848f5
dnl will catch most systems and will speed up the tests.
Packit 0848f5
dnl
Packit 0848f5
dnl Next, the libraries are only added if they are needed to complete a 
Packit 0848f5
dnl link; they aren''t added just because they exist.
Packit 0848f5
dnl
Packit 0848f5
dnl f77argdef
Packit 0848f5
dnl D*/
Packit 0848f5
dnl
Packit 0848f5
dnl Random notes
Packit 0848f5
dnl You can export the command line arguments from C to the g77 compiler
Packit 0848f5
dnl using
Packit 0848f5
dnl    extern char **__libc_argv;
Packit 0848f5
dnl    extern int  __libc_argc;
Packit 0848f5
dnl    f_setarg( __libc_argc, __libc_argv );
Packit 0848f5
dnl
Packit 0848f5
AC_DEFUN([PAC_PROG_F77_CMDARGS],[
Packit 0848f5
found_cached="yes"
Packit 0848f5
AC_MSG_CHECKING([for routines to access the command line from Fortran 77])
Packit 0848f5
AC_CACHE_VAL(pac_cv_prog_f77_cmdarg,
Packit 0848f5
[
Packit 0848f5
    AC_MSG_RESULT([searching...])
Packit 0848f5
    found_cached="no"
Packit 0848f5
    # First, we perform a quick check.  Does iargc and getarg work?
Packit 0848f5
    fxx_module="${FXX_MODULE:-}"
Packit 0848f5
    f77_getargdecl="${F77_GETARGDECL:-external getarg}"
Packit 0848f5
    f77_getarg="${F77_GETARG:-call GETARG(i,s)}"
Packit 0848f5
    f77_iargc="${F77_IARGC:-IARGC()}"
Packit 0848f5
    #    
Packit 0848f5
    # Grumble.  The Absoft Fortran compiler computes i - i as 0 and then
Packit 0848f5
    # 1.0 / 0 at compile time, even though the code may never be executed.
Packit 0848f5
    # What we need is a way to generate an error, so the second usage of i
Packit 0848f5
    # was replaced with f77_iargc.  
Packit 0848f5
    cat > conftest.f <
Packit 0848f5
        program main
Packit 0848f5
$fxx_module
Packit 0848f5
        integer i, j
Packit 0848f5
        character*20 s
Packit 0848f5
        $f77_getargdecl
Packit 0848f5
        i = 0
Packit 0848f5
        $f77_getarg
Packit 0848f5
        i=$f77_iargc
Packit 0848f5
        if (i .gt. 1) then
Packit 0848f5
            j = i - $f77_iargc
Packit 0848f5
            j = 1.0 / j
Packit 0848f5
        endif
Packit 0848f5
        end
Packit 0848f5
EOF
Packit 0848f5
    found_answer="no"
Packit 0848f5
    if test -z "$ac_fcompilelink" ; then
Packit 0848f5
        ac_fcompilelink="${F77-f77} -o conftest $FFLAGS $flags conftest.f $LDFLAGS $LIBS 1>&AC_FD_CC"
Packit 0848f5
    fi
Packit 0848f5
    AC_MSG_CHECKING([whether ${F77-f77} $flags $libs works with GETARG and IARGC])
Packit 0848f5
    if AC_TRY_EVAL(ac_fcompilelink) && test -x conftest ; then
Packit 0848f5
	# Check that cross != yes so that this works with autoconf 2.52
Packit 0848f5
	# Check that cross_compiling != yes so that this works with 
Packit 0848f5
	# autoconf 2.6x for some (but almost certainly not all)x
Packit 0848f5
	# Question: why do we test that this runs?  It looks like we
Packit 0848f5
	# needed this for some old Fortran compilers that produced
Packit 0848f5
	# executable code that then did not run.
Packit 0848f5
	if test "$ac_cv_prog_f77_cross" != "yes" -a \
Packit 0848f5
	        "$cross_compiling" != "yes" ; then
Packit 0848f5
	    if ./conftest >/dev/null 2>&1 ; then
Packit 0848f5
		found_answer="yes"
Packit 0848f5
	        FXX_MODULE="$fxx_module"
Packit 0848f5
		F77_GETARGDECL="$f77_getargdecl"
Packit 0848f5
		F77_GETARG="$f77_getarg"
Packit 0848f5
		F77_IARGC="$f77_iargc"
Packit 0848f5
		AC_MSG_RESULT(yes)
Packit 0848f5
     	    fi
Packit 0848f5
        fi
Packit 0848f5
    fi    
Packit 0848f5
    if test $found_answer = "no" ; then
Packit 0848f5
	AC_MSG_RESULT(no)
Packit 0848f5
    # Grumph.  Here are a bunch of different approaches
Packit 0848f5
    # We have several axes the check:
Packit 0848f5
    # Library to link with (none, -lU77 (HPUX), -lg2c (LINUX f77))
Packit 0848f5
    # PEPCF90 (Intel ifc)
Packit 0848f5
    # The first line is a dummy
Packit 0848f5
    # (we experimented with using a <space>, but this caused other 
Packit 0848f5
    # problems because we need <space> in the IFS)
Packit 0848f5
    trial_LIBS="0 -lU77 -lPEPCF90"
Packit 0848f5
    if test "$NOG2C" != "1" ; then
Packit 0848f5
        trial_LIBS="$trial_LIBS -lg2c"
Packit 0848f5
    fi
Packit 0848f5
    # Discard libs that are not availble:
Packit 0848f5
    save_IFS="$IFS"
Packit 0848f5
    # Make sure that IFS includes a space, or the tests that run programs
Packit 0848f5
    # may fail
Packit 0848f5
    IFS=" ""
Packit 0848f5
"
Packit 0848f5
    save_trial_LIBS="$trial_LIBS"
Packit 0848f5
    trial_LIBS=""
Packit 0848f5
    cat > conftest.f <
Packit 0848f5
        program main
Packit 0848f5
        end
Packit 0848f5
EOF
Packit 0848f5
    ac_fcompilelink_test='${F77-f77} -o conftest $FFLAGS conftest.f $LDFLAGS $libs $LIBS 1>&AC_FD_CC'
Packit 0848f5
    for libs in $save_trial_LIBS ; do
Packit 0848f5
	if test "$libs" = "0" ; then
Packit 0848f5
	    lib_ok="yes"
Packit 0848f5
        else
Packit 0848f5
	    AC_MSG_CHECKING([whether Fortran 77 links with $libs])
Packit 0848f5
	    if AC_TRY_EVAL(ac_fcompilelink_test) && test -x conftest ; then
Packit 0848f5
		AC_MSG_RESULT([yes])
Packit 0848f5
	        lib_ok="yes"
Packit 0848f5
	    else
Packit 0848f5
		AC_MSG_RESULT([no])
Packit 0848f5
	        lib_ok="no"
Packit 0848f5
	    fi
Packit 0848f5
	fi
Packit 0848f5
	if test "$lib_ok" = "yes" ; then
Packit 0848f5
	    trial_LIBS="$trial_LIBS
Packit 0848f5
$libs"
Packit 0848f5
        fi
Packit 0848f5
    done
Packit 0848f5
Packit 0848f5
    # Options to use when compiling and linking
Packit 0848f5
    # +U77 is needed by HP Fortran to access getarg etc.
Packit 0848f5
    # The -N109 was used for getarg before we realized that GETARG
Packit 0848f5
    # was necessary with the (non standard conforming) Absoft compiler
Packit 0848f5
    # (Fortran is monocase; Absoft uses mixedcase by default)
Packit 0848f5
    # The -f is used by Absoft and is the compiler switch that folds 
Packit 0848f5
    # symbolic names to lower case.  Without this option, the compiler
Packit 0848f5
    # considers upper- and lower-case letters to be unique.
Packit 0848f5
    # The -YEXT_NAMES=LCS will cause external names to be output as lower
Packit 0848f5
    # case letter for Absoft F90 compilers (default is upper case)
Packit 0848f5
    # The first line is "<space><newline>, the space is important
Packit 0848f5
    # To make the Absoft f77 and f90 work together, we need to prefer the
Packit 0848f5
    # upper case versions of the arguments.  They also require libU77.
Packit 0848f5
    # -YCFRL=1 causes Absoft f90 to work with g77 and similar (f2c-based) 
Packit 0848f5
    # Fortran compilers
Packit 0848f5
    #
Packit 0848f5
    # Problem:  The Intel efc compiler hangs when presented with -N109 .
Packit 0848f5
    # The only real fix for this is to detect this compiler and exclude
Packit 0848f5
    # the test.  We may want to reorganize these tests so that if we
Packit 0848f5
    # can compile code without special options, we never look for them.
Packit 0848f5
    # 
Packit 0848f5
    using_intel_efc="no"
Packit 0848f5
    pac_test_msg=`$F77 -V 2>&1 | grep 'Intel(R) Fortran Itanium'`
Packit 0848f5
    if test "$pac_test_msg" != "" ; then
Packit 0848f5
	using_intel_efc="yes"
Packit 0848f5
    fi
Packit 0848f5
    if test "$using_intel_efc" = "yes" ; then
Packit 0848f5
        trial_FLAGS="000"
Packit 0848f5
    else
Packit 0848f5
        trial_FLAGS="000
Packit 0848f5
-N109
Packit 0848f5
-f
Packit 0848f5
-YEXT_NAMES=UCS
Packit 0848f5
-YEXT_NAMES=LCS
Packit 0848f5
-YCFRL=1
Packit 0848f5
+U77"
Packit 0848f5
    fi
Packit 0848f5
    # Discard options that are not available:
Packit 0848f5
    # (IFS already saved above)
Packit 0848f5
    IFS=" ""
Packit 0848f5
"
Packit 0848f5
    save_trial_FLAGS="$trial_FLAGS"
Packit 0848f5
    trial_FLAGS=""
Packit 0848f5
    for flag in $save_trial_FLAGS ; do
Packit 0848f5
	if test "$flag" = " " -o "$flag" = "000" ; then
Packit 0848f5
	    opt_ok="yes"
Packit 0848f5
        else
Packit 0848f5
            PAC_F77_CHECK_COMPILER_OPTION($flag,opt_ok=yes,opt_ok=no)
Packit 0848f5
        fi
Packit 0848f5
	if test "$opt_ok" = "yes" ; then
Packit 0848f5
	    if test "$flag" = " " -o "$flag" = "000" ; then 
Packit 0848f5
		fflag="" 
Packit 0848f5
	    else 
Packit 0848f5
		fflag="$flag" 
Packit 0848f5
	    fi
Packit 0848f5
	    # discard options that don't allow mixed-case name matching
Packit 0848f5
	    cat > conftest.f <
Packit 0848f5
        program main
Packit 0848f5
        call aB()
Packit 0848f5
        end
Packit 0848f5
        subroutine Ab()
Packit 0848f5
        end
Packit 0848f5
EOF
Packit 0848f5
	    if test -n "$fflag" ; then flagval="with $fflag" ; else flagval="" ; fi
Packit 0848f5
	    AC_MSG_CHECKING([whether Fortran 77 routine names are case-insensitive $flagval])
Packit 0848f5
	    dnl we can use double quotes here because all is already
Packit 0848f5
            dnl evaluated
Packit 0848f5
            ac_fcompilelink_test="${F77-f77} -o conftest $fflag $FFLAGS conftest.f $LDFLAGS $LIBS 1>&AC_FD_CC"
Packit 0848f5
	    if AC_TRY_EVAL(ac_fcompilelink_test) && test -x conftest ; then
Packit 0848f5
	        AC_MSG_RESULT(yes)
Packit 0848f5
	    else
Packit 0848f5
	        AC_MSG_RESULT(no)
Packit 0848f5
	        opt_ok="no"
Packit 0848f5
            fi
Packit 0848f5
        fi
Packit 0848f5
        if test "$opt_ok" = "yes" ; then
Packit 0848f5
	    trial_FLAGS="$trial_FLAGS
Packit 0848f5
$flag"
Packit 0848f5
        fi
Packit 0848f5
    done
Packit 0848f5
    IFS="$save_IFS"
Packit 0848f5
    # Name of routines.  Since these are in groups, we use a case statement
Packit 0848f5
    # and loop until the end (accomplished by reaching the end of the
Packit 0848f5
    # case statement
Packit 0848f5
    # For one version of Nag F90, the names are 
Packit 0848f5
    # call f90_unix_MP_getarg(i,s) and f90_unix_MP_iargc().
Packit 0848f5
    trial=0
Packit 0848f5
    while test -z "$pac_cv_prog_f77_cmdarg" ; do
Packit 0848f5
        case $trial in 
Packit 0848f5
	0) # User-specified values, if any
Packit 0848f5
	   if test -z "$F77_GETARG" -o -z "$F77_IARGC" ; then 
Packit 0848f5
	       trial=`expr $trial + 1`
Packit 0848f5
	       continue 
Packit 0848f5
           fi
Packit 0848f5
           MSG="Using environment values of F77_GETARG etc."
Packit 0848f5
	   ;;
Packit 0848f5
	1) # Standard practice, uppercase (some compilers are case-sensitive)
Packit 0848f5
	   FXX_MODULE=""
Packit 0848f5
	   F77_GETARGDECL="external GETARG"
Packit 0848f5
	   F77_GETARG="call GETARG(i,s)"
Packit 0848f5
	   F77_IARGC="IARGC()"
Packit 0848f5
	   MSG="GETARG and IARGC"
Packit 0848f5
	   ;;
Packit 0848f5
	2) # Standard practice, lowercase
Packit 0848f5
	   FXX_MODULE=""
Packit 0848f5
           F77_GETARGDECL="external getarg"
Packit 0848f5
	   F77_GETARG="call getarg(i,s)"
Packit 0848f5
	   F77_IARGC="iargc()"
Packit 0848f5
	   MSG="getarg and iargc"
Packit 0848f5
	   ;;
Packit 0848f5
	3) # Posix alternative
Packit 0848f5
	   FXX_MODULE=""
Packit 0848f5
	   F77_GETARGDECL="external pxfgetarg"
Packit 0848f5
	   F77_GETARG="call pxfgetarg(i,s,l,ier)"
Packit 0848f5
	   F77_IARGC="ipxfargc()"
Packit 0848f5
	   MSG="pxfgetarg and ipxfargc"
Packit 0848f5
	   ;;
Packit 0848f5
	4) # Nag f90_unix_env module
Packit 0848f5
	   FXX_MODULE="        use f90_unix_env"
Packit 0848f5
	   F77_GETARGDECL=""
Packit 0848f5
	   F77_GETARG="call getarg(i,s)"
Packit 0848f5
	   F77_IARGC="iargc()"
Packit 0848f5
	   MSG="f90_unix_env module"
Packit 0848f5
	   ;;
Packit 0848f5
        5) # Nag f90_unix module
Packit 0848f5
	   FXX_MODULE="        use f90_unix"
Packit 0848f5
	   F77_GETARGDECL=""
Packit 0848f5
	   F77_GETARG="call getarg(i,s)"
Packit 0848f5
	   F77_IARGC="iargc()"
Packit 0848f5
	   MSG="f90_unix module"
Packit 0848f5
	   ;;
Packit 0848f5
	6) # user spec in a file
Packit 0848f5
	   if test -s f77argdef ; then
Packit 0848f5
		. ./f77argdef
Packit 0848f5
	       MSG="Using definitions in the file f77argdef"
Packit 0848f5
	   else
Packit 0848f5
	        trial=`expr $trial + 1`
Packit 0848f5
		continue
Packit 0848f5
	   fi
Packit 0848f5
	   ;;
Packit 0848f5
	7) # gfortran won't find getarg if it is marked as external 
Packit 0848f5
	   FXX_MODULE=""
Packit 0848f5
	   F77_GETARGDECL="intrinsic GETARG"
Packit 0848f5
	   F77_GETARG="call GETARG(i,s)"
Packit 0848f5
	   F77_IARGC="IARGC()"
Packit 0848f5
	   MSG="intrinsic GETARG and IARGC"
Packit 0848f5
	   ;;
Packit 0848f5
        *) # exit from while loop
Packit 0848f5
	   FXX_MODULE=""
Packit 0848f5
	   F77_GETARGDECL=""
Packit 0848f5
	   F77_GETARG=""
Packit 0848f5
	   F77_IARGC=""
Packit 0848f5
           break
Packit 0848f5
	   ;;
Packit 0848f5
	esac
Packit 0848f5
	# Create the program.  Make sure that we can run it.
Packit 0848f5
	# Force a divide-by-zero if there is a problem (but only at runtime!
Packit 0848f5
        # (the Absoft compiler does divide-by-zero at compile time)
Packit 0848f5
        cat > conftest.f <
Packit 0848f5
        program main
Packit 0848f5
$FXX_MODULE
Packit 0848f5
        integer i, j
Packit 0848f5
        character*20 s
Packit 0848f5
        $F77_GETARGDECL
Packit 0848f5
        i = 0
Packit 0848f5
        $F77_GETARG
Packit 0848f5
        i=$F77_IARGC
Packit 0848f5
        if (i .gt. 1) then
Packit 0848f5
            j = i - $F77_IARGC
Packit 0848f5
            j = 1.0 / j
Packit 0848f5
        endif
Packit 0848f5
        end
Packit 0848f5
EOF
Packit 0848f5
    #
Packit 0848f5
    # Now, try to find some way to compile and link that program, looping 
Packit 0848f5
    # over the possibilities of options and libraries
Packit 0848f5
        save_IFS="$IFS"
Packit 0848f5
        IFS=" ""
Packit 0848f5
"
Packit 0848f5
        for libs in $trial_LIBS ; do
Packit 0848f5
            if test -n "$pac_cv_prog_f77_cmdarg" ; then break ; fi
Packit 0848f5
	    if test "$libs" = " " -o "$libs" = "0" ; then libs="" ; fi
Packit 0848f5
            for flags in $trial_FLAGS ; do
Packit 0848f5
	        if test "$flags" = " " -o "$flags" = "000"; then flags="" ; fi
Packit 0848f5
                AC_MSG_CHECKING([whether ${F77-f77} $flags $libs works with $MSG])
Packit 0848f5
		IFS="$save_IFS"
Packit 0848f5
		dnl We need this here because we've fiddled with IFS
Packit 0848f5
	        ac_fcompilelink_test="${F77-f77} -o conftest $FFLAGS $flags conftest.f $LDFLAGS $libs $LIBS 1>&AC_FD_CC"
Packit 0848f5
		found_answer="no"
Packit 0848f5
                if AC_TRY_EVAL(ac_fcompilelink_test) && test -x conftest ; then
Packit 0848f5
		    if test "$ac_cv_prog_f77_cross" != "yes" -a \	 
Packit 0848f5
		            "$cross_compiling" != "yes" ; then
Packit 0848f5
			if ./conftest >/dev/null 2>&1 ; then
Packit 0848f5
			    found_answer="yes"
Packit 0848f5
			fi
Packit 0848f5
		    else 
Packit 0848f5
			found_answer="yes"
Packit 0848f5
		    fi
Packit 0848f5
                fi
Packit 0848f5
	        IFS=" ""
Packit 0848f5
"
Packit 0848f5
		if test "$found_answer" = "yes" ; then
Packit 0848f5
	            AC_MSG_RESULT([yes])
Packit 0848f5
		    pac_cv_prog_f77_cmdarg="$MSG"
Packit 0848f5
		    pac_cv_prog_f77_cmdarg_fflags="$flags"
Packit 0848f5
		    pac_cv_prog_f77_cmdarg_ldflags="$libs"
Packit 0848f5
		    break
Packit 0848f5
	        else
Packit 0848f5
                    AC_MSG_RESULT([no])
Packit 0848f5
		    echo "configure: failed program was:" >&AC_FD_CC
Packit 0848f5
                    cat conftest.f >&AC_FD_CC
Packit 0848f5
	        fi
Packit 0848f5
            done
Packit 0848f5
        done
Packit 0848f5
        IFS="$save_IFS"   
Packit 0848f5
	rm -f conftest.*
Packit 0848f5
        trial=`expr $trial + 1`   
Packit 0848f5
    done
Packit 0848f5
fi
Packit 0848f5
pac_cv_F77_GETARGDECL="$F77_GETARGDECL"
Packit 0848f5
pac_cv_F77_IARGC="$F77_IARGC"
Packit 0848f5
pac_cv_F77_GETARG="$F77_GETARG"
Packit 0848f5
pac_cv_FXX_MODULE="$FXX_MODULE"
Packit 0848f5
])
Packit 0848f5
if test "$found_cached" = "yes" ; then 
Packit 0848f5
    AC_MSG_RESULT([$pac_cv_prog_f77_cmdarg])
Packit 0848f5
elif test -z "$pac_cv_F77_IARGC" ; then
Packit 0848f5
    AC_MSG_WARN([Could not find a way to access the command line from Fortran 77])
Packit 0848f5
fi
Packit 0848f5
# Set the variable values based on pac_cv_prog_xxx
Packit 0848f5
F77_GETARGDECL="$pac_cv_F77_GETARGDECL"
Packit 0848f5
F77_IARGC="$pac_cv_F77_IARGC"
Packit 0848f5
F77_GETARG="$pac_cv_F77_GETARG"
Packit 0848f5
FXX_MODULE="$pac_cv_FXX_MODULE"
Packit 0848f5
F77_GETARG_FFLAGS="$pac_cv_prog_f77_cmdarg_fflags"
Packit 0848f5
F77_GETARG_LDFLAGS="$pac_cv_prog_f77_cmdarg_ldflags"
Packit 0848f5
AC_SUBST(F77_GETARGDECL)
Packit 0848f5
AC_SUBST(F77_IARGC)
Packit 0848f5
AC_SUBST(F77_GETARG)
Packit 0848f5
AC_SUBST(FXX_MODULE)
Packit 0848f5
AC_SUBST(F77_GETARG_FFLAGS)
Packit 0848f5
AC_SUBST(F77_GETARG_LDFLAGS)
Packit 0848f5
])