"Fossies" - the Fresh Open Source Software Archive

Member "openmpi-4.1.2/ompi/mca/io/romio321/romio/confdb/aclocal_f77.m4" (24 Nov 2021, 46711 Bytes) of package /linux/misc/openmpi-4.1.2.tar.bz2:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 dnl PAC_F77_SEARCH_LIST - expands to a whitespace separated list of fortran 77
    2 dnl compilers for use with AC_PROG_F77 that is more suitable for HPC software
    3 dnl packages
    4 AC_DEFUN([PAC_F77_SEARCH_LIST],[ifort pgf77 af77 xlf frt cf77 fort77 fl32 fort ifc efc ftn gfortran f77 g77])
    5 dnl PAC_PROG_F77 - reprioritize the F77 compiler search order
    6 dnl NOTE: this macro suffers from a basically intractable "expanded before it
    7 dnl was required" problem when libtool is also used
    8 AC_DEFUN([PAC_PROG_F77],[
    9 PAC_PUSH_FLAG([FFLAGS])
   10 AC_PROG_F77([PAC_F77_SEARCH_LIST])
   11 PAC_POP_FLAG([FFLAGS])
   12 ])
   13 dnl
   14 dnl/*D
   15 dnl PAC_PROG_F77_NAME_MANGLE - Determine how the Fortran compiler mangles
   16 dnl names 
   17 dnl
   18 dnl Synopsis:
   19 dnl PAC_PROG_F77_NAME_MANGLE([action])
   20 dnl
   21 dnl Output Effect:
   22 dnl If no action is specified, one of the following names is defined:
   23 dnl.vb
   24 dnl If fortran names are mapped:
   25 dnl   lower -> lower                  F77_NAME_LOWER
   26 dnl   lower -> lower_                 F77_NAME_LOWER_USCORE
   27 dnl   lower -> UPPER                  F77_NAME_UPPER
   28 dnl   lower_lower -> lower__          F77_NAME_LOWER_2USCORE
   29 dnl   mixed -> mixed                  F77_NAME_MIXED
   30 dnl   mixed -> mixed_                 F77_NAME_MIXED_USCORE
   31 dnl   mixed -> UPPER@STACK_SIZE       F77_NAME_UPPER_STDCALL
   32 dnl.ve
   33 dnl If an action is specified, it is executed instead.
   34 dnl 
   35 dnl Notes:
   36 dnl We assume that if lower -> lower (any underscore), upper -> upper with the
   37 dnl same underscore behavior.  Previous versions did this by 
   38 dnl compiling a Fortran program and running strings -a over it.  Depending on 
   39 dnl strings is a bad idea, so instead we try compiling and linking with a 
   40 dnl C program, since that is why we are doing this anyway.  A similar approach
   41 dnl is used by FFTW, though without some of the cases we check (specifically, 
   42 dnl mixed name mangling).  STD_CALL not only specifies a particular name
   43 dnl mangling convention (adding the size of the calling stack into the function
   44 dnl name, but also the stack management convention (callee cleans the stack,
   45 dnl and arguments are pushed onto the stack from right to left)
   46 dnl
   47 dnl One additional problem is that some Fortran implementations include 
   48 dnl references to the runtime (like pgf90_compiled for the pgf90 compiler
   49 dnl used as the "Fortran 77" compiler).  This is not yet solved.
   50 dnl
   51 dnl D*/
   52 dnl
   53 AC_DEFUN([PAC_PROG_F77_NAME_MANGLE],[
   54 AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])
   55 AC_CACHE_CHECK([for Fortran 77 name mangling],
   56 pac_cv_prog_f77_name_mangle,[
   57 # Initialize pac_found to indicate if name mangling scheme has been found
   58 pac_found=no
   59 AC_LANG_PUSH([Fortran 77])
   60 AC_COMPILE_IFELSE([
   61     AC_LANG_SOURCE([
   62         subroutine MY_name( ii )
   63         return
   64         end
   65     ])
   66 ],[
   67     PAC_RUNLOG([mv conftest.$OBJEXT f77conftest.$OBJEXT])
   68     saved_LIBS="$LIBS"
   69     dnl  FLIBS is set by AC_F77_LIBRARY_LDFLAGS
   70     LIBS="f77conftest.$OBJEXT $FLIBS $LIBS"
   71     AC_LANG_PUSH([C])
   72     for call in "" __stdcall ; do
   73         for sym in my_name_ my_name__ my_name MY_NAME MY_name MY_name_ NONE ; do
   74             AC_LINK_IFELSE([
   75                 AC_LANG_PROGRAM([extern void ${call} ${sym}(int);],[${sym}(0);])
   76             ],[
   77                 pac_found=yes
   78                 break
   79             ])
   80         done
   81         test "$pac_found" = "yes" && break
   82     done
   83     AC_LANG_POP([C])
   84     LIBS="$saved_LIBS"
   85     rm -f f77conftest.$OBJEXT
   86 ])
   87 AC_LANG_POP([Fortran 77])
   88 dnl
   89 # If we got to here and pac_cv_prog_f77_name_mangle is still NOT definable,
   90 # it may be that the programs have to be linked with the Fortran compiler,
   91 # not the C compiler.  Try reversing the language used for the test
   92 if test  "$pac_found" != "yes" ; then
   93     AC_LANG_PUSH([C])
   94     for call in "" __stdcall ; do
   95         for sym in my_name_ my_name__ my_name MY_NAME MY_name MY_name_ NONE ; do
   96             AC_COMPILE_IFELSE([
   97                 AC_LANG_SOURCE([void ${call} ${sym}(int a) {}])
   98             ],[
   99                 PAC_RUNLOG([mv conftest.$OBJEXT cconftest.$OBJEXT])
  100                 saved_LIBS="$LIBS"
  101                 LIBS="cconftest.$OBJEXT $LIBS"
  102                 AC_LANG_PUSH([Fortran 77])
  103                 AC_LINK_IFELSE([
  104                     AC_LANG_PROGRAM([],[      call my_name(0)])
  105                 ],[
  106                     pac_found=yes
  107                 ]) 
  108                 AC_LANG_POP([Fortran 77])
  109                 LIBS="$saved_LIBS"
  110                 rm -f cconftest.$OBJEXT
  111                 test "$pac_found" = "yes" && break
  112             ])
  113         done
  114         test "$pac_found" = "yes" && break
  115     done
  116     AC_LANG_POP([C])
  117 fi
  118 if test "$pac_found" = "yes" ; then
  119     case ${sym} in
  120         my_name_)
  121             pac_cv_prog_f77_name_mangle="lower uscore" ;;
  122         my_name__)
  123             pac_cv_prog_f77_name_mangle="lower 2uscore" ;;
  124         my_name)
  125             pac_cv_prog_f77_name_mangle="lower" ;;
  126         MY_NAME)
  127             pac_cv_prog_f77_name_mangle="upper" ;;
  128         MY_name)
  129             pac_cv_prog_f77_name_mangle="mixed" ;;
  130         MY_name_)
  131             pac_cv_prog_f77_name_mangle="mixed uscore" ;;
  132         *)
  133             pac_cv_prog_f77_name_mangle=""
  134             pac_found=no;
  135             ;;
  136     esac
  137     if test "X$pac_cv_prog_f77_name_mangle" != "X" ; then
  138         if test "$call" = "__stdcall" ; then
  139             pac_cv_prog_f77_name_mangle="$pac_cv_prog_f77_name_mangle stdcall"
  140         fi
  141     fi
  142 fi
  143 ])
  144 dnl Endof ac_cache_check
  145 case $pac_cv_prog_f77_name_mangle in
  146     *stdcall)
  147         F77_STDCALL="__stdcall" ;;
  148     *)
  149         F77_STDCALL="" ;;
  150 esac
  151 # Get the standard call definition
  152 # FIXME: This should use F77_STDCALL, not STDCALL (non-conforming name)
  153 F77_STDCALL="$call"
  154 AC_DEFINE_UNQUOTED(STDCALL,[$F77_STDCALL],[Define calling convention])
  155 
  156 # new_name="`echo $name | tr ' ' '_' | tr [a-z] [A-Z]`"
  157 # We could have done the character conversion with 'tr'
  158 # which may not be portable, e.g. solaris's /usr/ucb/bin/tr.
  159 # So use a conservative approach.
  160 
  161 # Replace blank with underscore
  162 name_scheme="`echo $pac_cv_prog_f77_name_mangle | sed 's% %_%g'`"
  163 # Turn lowercase into uppercase.
  164 name_scheme="`echo $name_scheme | sed -e 'y%abcdefghijklmnopqrstuvwxyz%ABCDEFGHIJKLMNOPQRSTUVWXYZ%'`"
  165 F77_NAME_MANGLE="F77_NAME_${name_scheme}"
  166 AC_DEFINE_UNQUOTED([$F77_NAME_MANGLE]) 
  167 AC_SUBST(F77_NAME_MANGLE)
  168 if test "X$pac_cv_prog_f77_name_mangle" = "X" ; then
  169     AC_MSG_WARN([Unknown Fortran naming scheme])
  170 fi
  171 dnl
  172 dnl Define the macros that is needed by AC_DEFINE_UNQUOTED([$F77_NAME_MANGLE])
  173 AH_TEMPLATE([F77_NAME_LOWER],
  174     [Fortran names are lowercase with no trailing underscore])
  175 AH_TEMPLATE([F77_NAME_LOWER_USCORE],
  176     [Fortran names are lowercase with one trailing underscore])
  177 AH_TEMPLATE([F77_NAME_LOWER_2USCORE],
  178     [Fortran names are lowercase with two trailing underscores])
  179 AH_TEMPLATE([F77_NAME_MIXED],
  180     [Fortran names preserve the original case])
  181 AH_TEMPLATE([F77_NAME_MIXED_USCORE],
  182     [Fortran names preserve the original case with one trailing underscore])
  183 AH_TEMPLATE([F77_NAME_UPPER],
  184     [Fortran names are uppercase])
  185 AH_TEMPLATE([F77_NAME_LOWER_STDCALL],
  186     [Fortran names are lowercase with no trailing underscore in stdcall])
  187 AH_TEMPLATE([F77_NAME_LOWER_USCORE_STDCALL],
  188     [Fortran names are lowercase with one trailing underscore in stdcall])
  189 AH_TEMPLATE([F77_NAME_LOWER_2USCORE_STDCALL],
  190     [Fortran names are lowercase with two trailing underscores in stdcall])
  191 AH_TEMPLATE([F77_NAME_MIXED_STDCALL],
  192     [Fortran names preserve the original case in stdcall])
  193 AH_TEMPLATE([F77_NAME_MIXED_USCORE_STDCALL],
  194     [Fortran names preserve the original case with one trailing underscore in stdcall])
  195 AH_TEMPLATE([F77_NAME_UPPER_STDCALL],
  196     [Fortran names are uppercase in stdcall])
  197 ])
  198 dnl
  199 dnl/*D
  200 dnl PAC_PROG_F77_CHECK_SIZEOF - Determine the size in bytes of a Fortran
  201 dnl type
  202 dnl
  203 dnl Synopsis:
  204 dnl PAC_PROG_F77_CHECK_SIZEOF(type,[cross-size])
  205 dnl
  206 dnl Output Effect:
  207 dnl Sets SIZEOF_F77_uctype to the size if bytes of type.
  208 dnl If type is unknown, the size is set to 0.
  209 dnl If cross-compiling, the value cross-size is used (it may be a variable)
  210 dnl For example 'PAC_PROG_F77_CHECK_SIZEOF(real)' defines
  211 dnl 'SIZEOF_F77_REAL' to 4 on most systems.  The variable 
  212 dnl 'pac_cv_sizeof_f77_<type>' (e.g., 'pac_cv_sizeof_f77_real') is also set to
  213 dnl the size of the type. 
  214 dnl If the corresponding variable is already set, that value is used.
  215 dnl If the name has an '*' in it (e.g., 'integer*4'), the defined name 
  216 dnl replaces that with an underscore (e.g., 'SIZEOF_F77_INTEGER_4').
  217 dnl
  218 dnl Notes:
  219 dnl If the 'cross-size' argument is not given, 'autoconf' will issue an error
  220 dnl message.  You can use '0' to specify undetermined.
  221 dnl
  222 dnl D*/
  223 AC_DEFUN([PAC_PROG_F77_CHECK_SIZEOF],[
  224 AC_REQUIRE([AC_HEADER_STDC])
  225 AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])
  226 changequote(<<, >>)dnl
  227 dnl The name to #define.
  228 dnl dnl If the arg value contains a variable, we need to update that
  229 define(<<PAC_TYPE_NAME>>, translit(sizeof_f77_$1, [a-z *], [A-Z__]))dnl
  230 dnl The cache variable name.
  231 define(<<PAC_CV_NAME>>, translit(pac_cv_f77_sizeof_$1, [ *], [__]))dnl
  232 changequote([, ])dnl
  233 AC_CACHE_CHECK([for size of Fortran type $1],PAC_CV_NAME,[
  234 AC_REQUIRE([PAC_PROG_F77_NAME_MANGLE])
  235 AC_LANG_PUSH([Fortran 77])
  236 AC_COMPILE_IFELSE([
  237     AC_LANG_SOURCE([
  238         subroutine isize()
  239         $1 i(2)
  240         call cisize( i(1), i(2) )
  241         end
  242     ])
  243 ],[
  244     # pac_f77compile_ok=yes
  245     PAC_RUNLOG([mv conftest.$OBJEXT pac_f77conftest.$OBJEXT])
  246     # Save original LIBS, prepend previously generated object file to LIBS
  247     saved_LIBS="$LIBS"
  248     LIBS="pac_f77conftest.$OBJEXT $FLIBS $LIBS"
  249     AC_LANG_PUSH([C])
  250     AC_RUN_IFELSE([
  251         AC_LANG_PROGRAM([
  252 #if defined(HAVE_STDIO_H) || defined(STDC_HEADERS)
  253 #include <stdio.h>
  254 #endif
  255 #ifdef F77_NAME_UPPER
  256 #define cisize_ CISIZE
  257 #define isize_ ISIZE
  258 #elif defined(F77_NAME_LOWER) || defined(F77_NAME_MIXED)
  259 #define cisize_ cisize
  260 #define isize_ isize
  261 #endif
  262 static int isize_val=0;
  263 void cisize_(char *,char*);
  264 void isize_(void);
  265 void cisize_(char *i1p, char *i2p)
  266 { 
  267    isize_val = (int)(i2p - i1p);
  268 }
  269         ],[
  270     FILE *f = fopen("conftestval", "w");
  271     if (!f) return 1;
  272     isize_();
  273     fprintf(f,"%d\n", isize_val);
  274         ])
  275         dnl Endof ac_lang_program
  276     ],[
  277         eval PAC_CV_NAME=`cat conftestval`
  278     ],[
  279         eval PAC_CV_NAME=0
  280     ],[
  281         # Use -9999 as value to emit a warning message after the cache_check.
  282         ifelse([$2],[],[eval PAC_CV_NAME=-9999],[eval PAC_CV_NAME=$2])
  283     ])
  284     dnl Endof ac_run_ifelse
  285     AC_LANG_POP([C])
  286     LIBS="$saved_LIBS"
  287     # remove previously generated object file.
  288     rm -f pac_f77conftest.$OBJEXT
  289 ],[
  290     # pac_f77compile_ok=no
  291     ifelse([$2],,eval PAC_CV_NAME=0,eval PAC_CV_NAME=$2)
  292 ])  Endof ac_compile_ifelse
  293 AC_LANG_POP([Fortran 77])
  294 ])
  295 dnl Endof ac_cache_check
  296 if test "$PAC_CV_NAME" = "-9999" ; then
  297      AC_MSG_WARN([No value provided for size of $1 when cross-compiling])
  298 fi
  299 AC_DEFINE_UNQUOTED(PAC_TYPE_NAME,$PAC_CV_NAME,[Define size of PAC_TYPE_NAME])
  300 undefine([PAC_TYPE_NAME])
  301 undefine([PAC_CV_NAME])
  302 ])
  303 dnl
  304 dnl This version uses a Fortran program to link programs.
  305 dnl This is necessary because some compilers provide shared libraries
  306 dnl that are not within the default linker paths (e.g., our installation
  307 dnl of the Portland Group compilers)
  308 dnl
  309 AC_DEFUN([PAC_PROG_F77_CHECK_SIZEOF_EXT],[
  310 changequote(<<,>>)dnl
  311 dnl The name to #define.
  312 dnl If the arg value contains a variable, we need to update that
  313 define(<<PAC_TYPE_NAME>>, translit(sizeof_f77_$1, [a-z *], [A-Z__]))dnl
  314 dnl The cache variable name.
  315 define(<<PAC_CV_NAME>>, translit(pac_cv_f77_sizeof_$1, [ *], [__]))dnl
  316 changequote([,])dnl
  317 AC_CACHE_CHECK([for size of Fortran type $1],PAC_CV_NAME,[
  318 AC_REQUIRE([AC_HEADER_STDC])
  319 AC_REQUIRE([PAC_PROG_F77_NAME_MANGLE])
  320 dnl if test "$cross_compiling" = yes ; then
  321 dnl     ifelse([$2],[],
  322 dnl         [AC_MSG_WARN([No value provided for size of $1 when cross-compiling])],
  323 dnl         [eval PAC_CV_NAME=$2])
  324 dnl fi
  325 AC_LANG_PUSH([C])
  326 AC_COMPILE_IFELSE([
  327     AC_LANG_SOURCE([
  328 #if defined(HAVE_STDIO_H) || defined(STDC_HEADERS)
  329 #include <stdio.h>
  330 #endif
  331 #ifdef F77_NAME_UPPER
  332 #define cisize_ CISIZE
  333 #define isize_ ISIZE
  334 #elif defined(F77_NAME_LOWER) || defined(F77_NAME_MIXED)
  335 #define cisize_ cisize
  336 #define isize_ isize
  337 #endif
  338 int cisize_(char *,char*);
  339 int cisize_(char *i1p, char *i2p) {
  340     int isize_val=0;
  341     FILE *f = fopen("conftestval", "w");
  342     if (!f) return 1;
  343     isize_val = (int)(i2p - i1p);
  344     fprintf(f,"%d\n", isize_val);
  345     fclose(f);
  346     return 0;
  347 }
  348     ])
  349     dnl Endof ac_lang_source
  350 ],[
  351     # pac_compile_ok=yes
  352     PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT])
  353     # Save LIBS and prepend object file to LIBS
  354     saved_LIBS="$LIBS"
  355     LIBS="pac_conftest.$OBJEXT $LIBS"
  356     AC_LANG_PUSH([Fortran 77])
  357     AC_RUN_IFELSE([
  358         AC_LANG_SOURCE([
  359             program main
  360             $1 a(2)
  361             integer irc, cisize
  362             irc = cisize(a(1),a(2))
  363             end
  364         ])
  365     ],[
  366         eval PAC_CV_NAME=`cat conftestval`
  367     ],[
  368         eval PAC_CV_NAME=0
  369     ],[
  370         # Use -9999 as value to emit a warning message after the cache_check.
  371         ifelse([$2],[],[eval PAC_CV_NAME=-9999],[eval PAC_CV_NAME=$2])
  372     ])
  373     AC_LANG_POP([Fortran 77])
  374     LIBS="$saved_LIBS"
  375     # remove previously generated object file.
  376     rm -f pac_conftest.$OBJEXT
  377 ],[
  378     AC_MSG_WARN([Unable to compile the C routine for finding the size of a $1])
  379 ])
  380 AC_LANG_POP([C])
  381 ])
  382 dnl Endof ac_cache_check
  383 if test "$PAC_CV_NAME" = "-9999" ; then
  384      AC_MSG_WARN([No value provided for size of $1 when cross-compiling])
  385 fi
  386 AC_DEFINE_UNQUOTED(PAC_TYPE_NAME,$PAC_CV_NAME,[Define size of PAC_TYPE_NAME])
  387 undefine([PAC_TYPE_NAME])
  388 undefine([PAC_CV_NAME])
  389 ])
  390 dnl
  391 dnl/*D
  392 dnl PAC_PROG_F77_EXCLAIM_COMMENTS
  393 dnl
  394 dnl Synopsis:
  395 dnl PAC_PROG_F77_EXCLAIM_COMMENTS([action-if-true],[action-if-false])
  396 dnl
  397 dnl Notes:
  398 dnl Check whether '!' may be used to begin comments in Fortran.
  399 dnl
  400 dnl This macro requires a version of autoconf `after` 2.13; the 'acgeneral.m4'
  401 dnl file contains an error in the handling of Fortran programs in 
  402 dnl 'AC_TRY_COMPILE' (fixed in our local version).
  403 dnl
  404 dnl D*/
  405 AC_DEFUN([PAC_PROG_F77_EXCLAIM_COMMENTS],[
  406 AC_CACHE_CHECK([whether Fortran 77 accepts ! for comments],
  407 pac_cv_prog_f77_exclaim_comments,[
  408 AC_LANG_PUSH([Fortran 77])
  409 AC_COMPILE_IFELSE([
  410      AC_LANG_PROGRAM([],[!        This is a comment])
  411 ],[
  412     pac_cv_prog_f77_exclaim_comments="yes"
  413 ],[
  414     pac_cv_prog_f77_exclaim_comments="no"
  415 ])
  416 AC_LANG_POP([Fortran 77])
  417 ])
  418 if test "$pac_cv_prog_f77_exclaim_comments" = "yes" ; then
  419     ifelse([$1],[],[:],[$1])
  420 else
  421     ifelse([$2],[],[:],[$2])
  422 fi
  423 ])dnl
  424 dnl
  425 dnl/*D
  426 dnl PAC_F77_CHECK_COMPILER_OPTION - Check that a F77 compiler option is
  427 dnl accepted without warning messages
  428 dnl
  429 dnl Synopsis:
  430 dnl PAC_F77_CHECK_COMPILER_OPTION(optionname,action-if-ok,action-if-fail)
  431 dnl
  432 dnl Output Effects:
  433 dnl
  434 dnl If no actions are specified, a working value is added to 'FOPTIONS'
  435 dnl
  436 dnl Notes:
  437 dnl This is now careful to check that the output is different, since 
  438 dnl some compilers are noisy.
  439 dnl 
  440 dnl We are extra careful to prototype the functions in case compiler options
  441 dnl that complain about poor code are in effect.
  442 dnl
  443 dnl Because this is a long script, we have ensured that you can pass a 
  444 dnl variable containing the option name as the first argument.
  445 dnl D*/
  446 AC_DEFUN([PAC_F77_CHECK_COMPILER_OPTION],[
  447 AC_MSG_CHECKING([whether Fortran 77 compiler accepts option $1])
  448 pac_opt="$1"
  449 AC_LANG_PUSH([Fortran 77])
  450 FFLAGS_orig="$FFLAGS"
  451 FFLAGS_opt="$pac_opt $FFLAGS"
  452 pac_result="unknown"
  453 
  454 AC_LANG_CONFTEST([AC_LANG_PROGRAM()])
  455 FFLAGS="$FFLAGS_orig"
  456 rm -f pac_test1.log
  457 PAC_LINK_IFELSE_LOG([pac_test1.log], [], [
  458     FFLAGS="$FFLAGS_opt"
  459     rm -f pac_test2.log
  460     PAC_LINK_IFELSE_LOG([pac_test2.log], [], [
  461         PAC_RUNLOG_IFELSE([diff -b pac_test1.log pac_test2.log],
  462                           [pac_result=yes], [pac_result=no])
  463     ],[
  464         pac_result=no
  465     ])
  466 ], [
  467     pac_result=no
  468 ])
  469 AC_MSG_RESULT([$pac_result])
  470 dnl Delete the conftest created by AC_LANG_CONFTEST.
  471 rm -f conftest.$ac_ext
  472 #
  473 if test "$pac_result" = "yes" ; then
  474     AC_MSG_CHECKING([whether routines compiled with $pac_opt can be linked with ones compiled without $pac_opt])
  475     pac_result=unknown
  476     FFLAGS="$FFLAGS_orig"
  477     rm -f pac_test3.log
  478     PAC_COMPILE_IFELSE_LOG([pac_test3.log], [
  479         AC_LANG_SOURCE([
  480             subroutine try()
  481             end
  482         ])
  483     ],[
  484         PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT])
  485         saved_LIBS="$LIBS"
  486         LIBS="pac_conftest.$OBJEXT $LIBS"
  487 
  488         FFLAGS="$FFLAGS_opt"
  489         rm -f pac_test4.log
  490         PAC_LINK_IFELSE_LOG([pac_test4.log], [AC_LANG_PROGRAM()], [
  491             PAC_RUNLOG_IFELSE([diff -b pac_test2.log pac_test4.log],
  492                               [pac_result=yes], [pac_result=no])
  493         ],[
  494             pac_result=no
  495         ])
  496         LIBS="$saved_LIBS"
  497         rm -f pac_conftest.$OBJEXT
  498     ],[
  499         pac_result=no
  500     ])
  501     AC_MSG_RESULT([$pac_result])
  502     rm -f pac_test3.log pac_test4.log
  503 fi
  504 rm -f pac_test1.log pac_test2.log
  505 
  506 dnl Restore FFLAGS before 2nd/3rd argument commands are executed,
  507 dnl as 2nd/3rd argument command could be modifying FFLAGS.
  508 FFLAGS="$FFLAGS_orig"
  509 if test "$pac_result" = "yes" ; then
  510      ifelse([$2],[],[FOPTIONS="$FOPTIONS $1"],[$2])
  511 else
  512      ifelse([$3],[],[:],[$3])
  513 fi
  514 AC_LANG_POP([Fortran 77])
  515 ])
  516 dnl
  517 dnl/*D
  518 dnl PAC_PROG_F77_LIBRARY_DIR_FLAG - Determine the flag used to indicate
  519 dnl the directories to find libraries in
  520 dnl
  521 dnl Notes:
  522 dnl Many compilers accept '-Ldir' just like most C compilers.  
  523 dnl Unfortunately, some (such as some HPUX Fortran compilers) do not, 
  524 dnl and require instead either '-Wl,-L,dir' or something else.  This
  525 dnl command attempts to determine what is accepted.  The flag is 
  526 dnl placed into 'F77_LIBDIR_LEADER'.
  527 dnl
  528 dnl D*/
  529 dnl
  530 dnl An earlier version of this only tried the arguments without using
  531 dnl a library.  This failed when the HP compiler complained about the
  532 dnl arguments, but produced an executable anyway.
  533 AC_DEFUN([PAC_PROG_F77_LIBRARY_DIR_FLAG],[
  534 AC_CACHE_CHECK([for Fortran 77 flag for library directories],
  535 pac_cv_prog_f77_library_dir_flag,[
  536 AC_LANG_PUSH([Fortran 77])
  537 AC_COMPILE_IFELSE([
  538     AC_LANG_SOURCE([
  539         subroutine f1conf
  540         end
  541     ])
  542 ],[
  543     # pac_f77compile_ok=yes
  544     PAC_RUNLOG([mv conftest.$OBJEXT pac_f77conftest.$OBJEXT])
  545     PAC_RUNLOG([test -d conftestdir || mkdir conftestdir])
  546     PAC_RUNLOG([${AR-ar} ${AR_FLAGS-cr} conftestdir/libf77conftest.a pac_f77conftest.$OBJEXT])
  547     PAC_RUNLOG([${RANLIB-ranlib} conftestdir/libf77conftest.a])
  548     # Save original LIBS, prepend previously generated object file to LIBS
  549     saved_LIBS="$LIBS"
  550     LIBS="-lf77conftest $LIBS"
  551     saved_LDFLAGS="$LDFLAGS"
  552     pac_cv_prog_f77_library_dir_flag="none"
  553     for ldir in "-L" "-Wl,-L," ; do
  554         LDFLAGS="${ldir}conftestdir $saved_LDFLAGS"
  555         AC_LINK_IFELSE([
  556             AC_LANG_SOURCE([
  557                 program main
  558                 call f1conf
  559                 end
  560             ])
  561         ],[pac_cv_prog_f77_library_dir_flag="$ldir";break])
  562     done
  563     LDFLAGS="$saved_LDFLAGS"
  564     LIBS="$saved_LIBS"
  565     rm -rf conftestdir
  566     rm -f pac_f77conftest.$OBJEXT
  567 ],[])
  568 AC_LANG_POP([Fortran 77])
  569 ])
  570 dnl Endof ac_cache_check
  571 if test "X$pac_cv_prog_f77_library_dir_flag" != "Xnone" ; then
  572     F77_LIBDIR_LEADER="$pac_cv_prog_f77_library_dir_flag"
  573     AC_SUBST(F77_LIBDIR_LEADER)
  574 fi
  575 ])
  576 dnl
  577 dnl/*D 
  578 dnl PAC_PROG_F77_HAS_INCDIR - Check whether Fortran accepts -Idir flag
  579 dnl
  580 dnl Syntax:
  581 dnl   PAC_PROG_F77_HAS_INCDIR(directory,action-if-true,action-if-false)
  582 dnl
  583 dnl Output Effect:
  584 dnl  Sets 'F77_INCDIR' to the flag used to choose the directory.  
  585 dnl
  586 dnl Notes:
  587 dnl This refers to the handling of the common Fortran include extension,
  588 dnl not to the use of '#include' with the C preprocessor.
  589 dnl If directory does not exist, it will be created.  In that case, the 
  590 dnl directory should be a direct descendant of the current directory.
  591 dnl
  592 dnl D*/
  593 AC_DEFUN([PAC_PROG_F77_HAS_INCDIR],[
  594 ifelse([$1],[],[checkdir=f77tmpdir],[checkdir=$1;checkdir_is_given=yes])
  595 AC_CACHE_CHECK([for include directory flag for Fortran],
  596 pac_cv_prog_f77_has_incdir,[
  597 test -d $checkdir || mkdir $checkdir
  598 dnl PAC_RUNLOG([echo '       call sub()' > $checkdir/conftestf.h])
  599 echo '       call sub()' > $checkdir/conftestf.h
  600 AC_LANG_PUSH([Fortran 77])
  601 saved_FFLAGS="$FFLAGS"
  602 pac_cv_prog_f77_has_incdir="none"
  603 # SGI wants -Wf,-I
  604 for idir in "-I" "-Wf,-I" ; do
  605     FFLAGS="${idir} $checkdir $saved_FFLAGS"
  606     AC_COMPILE_IFELSE([
  607         AC_LANG_SOURCE([
  608             program main
  609             include 'conftestf.h'
  610             end
  611         ])
  612     ],[pac_cv_prog_f77_has_incdir="$idir"; break])
  613 done
  614 FFLAGS="$saved_FFLAGS"
  615 AC_LANG_POP([Fortran 77])
  616 if test "$checkdir_is_given" = "yes" ; then
  617     rm -f $checkdir/conftestf.h
  618 else
  619     rm -rf $checkdir
  620 fi
  621 ])
  622 dnl Endof ac_cache_check
  623 if test "X$pac_cv_prog_f77_has_incdir" != "Xnone" ; then
  624     F77_INCDIR="$pac_cv_prog_f77_has_incdir"
  625     AC_SUBST(F77_INCDIR)
  626 fi
  627 ])
  628 dnl
  629 dnl/*D
  630 dnl PAC_PROG_F77_ALLOWS_UNUSED_EXTERNALS - Check whether the Fortran compiler
  631 dnl allows unused and undefined functions to be listed in an external 
  632 dnl statement
  633 dnl
  634 dnl Syntax:
  635 dnl   PAC_PROG_F77_ALLOWS_UNUSED_EXTERNALS(action-if-true,action-if-false)
  636 dnl
  637 dnl D*/
  638 AC_DEFUN([PAC_PROG_F77_ALLOWS_UNUSED_EXTERNALS],[
  639 AC_CACHE_CHECK([whether Fortran allows unused externals],
  640 pac_cv_prog_f77_allows_unused_externals,[
  641 AC_LANG_PUSH([Fortran 77])
  642 AC_LINK_IFELSE([
  643     AC_LANG_SOURCE([
  644         program main
  645         external bar
  646         end
  647     ])
  648 ],[
  649     pac_cv_prog_f77_allows_unused_externals="yes"
  650 ],[
  651     pac_cv_prog_f77_allows_unused_externals="no"
  652 ])
  653 AC_LANG_POP([Fortran 77])
  654 ])
  655 dnl Endof ac_cache_check
  656 if test "X$pac_cv_prog_f77_allows_unused_externals" = "Xyes" ; then
  657    ifelse([$1],[],[:],[$1])
  658 else
  659    ifelse([$2],[],[:],[$2])
  660 fi
  661 ])
  662 dnl PAC_PROG_F77_RUN_PROC_FROM_C( c main program, fortran routine, 
  663 dnl                               [action-if-works], [action-if-fails], 
  664 dnl                               [cross-action] )
  665 dnl Fortran routine MUST be named ftest unless you include code
  666 dnl to select the appropriate Fortran name.
  667 dnl 
  668 AC_DEFUN([PAC_PROG_F77_RUN_PROC_FROM_C],[
  669 AC_REQUIRE([AC_HEADER_STDC])
  670 AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])
  671 AC_LANG_PUSH([Fortran 77])
  672 AC_COMPILE_IFELSE([
  673     AC_LANG_SOURCE([$2])
  674 ],[
  675     # pac_f77compile_ok=yes
  676     PAC_RUNLOG([mv conftest.$OBJEXT pac_f77conftest.$OBJEXT])
  677     # Save original LIBS, prepend previously generated object file to LIBS
  678     saved_LIBS="$LIBS"
  679     LIBS="pac_f77conftest.$OBJEXT $FLIBS $LIBS"
  680     AC_LANG_PUSH([C])
  681     AC_RUN_IFELSE([
  682         AC_LANG_SOURCE([
  683 #if defined(HAVE_STDIO_H) || defined(STDC_HEADERS)
  684 #include <stdio.h>
  685 #endif
  686 #ifdef F77_NAME_UPPER
  687 #define ftest_ FTEST
  688 #elif defined(F77_NAME_LOWER) || defined(F77_NAME_MIXED)
  689 #define ftest_ ftest
  690 #endif
  691 $1
  692         ])
  693     ],[
  694         ifelse([$3],[],[:],[$3])
  695     ],[
  696         ifelse([$4],[],[:],[$4])
  697     ],[
  698         ifelse([$5],[],[:],[$5])
  699     ])
  700     AC_LANG_POP([C])
  701     LIBS="$saved_LIBS"
  702     rm -f pac_f77conftest.$OBJEXT
  703 ],[
  704 ])
  705 AC_LANG_POP([Fortran 77])
  706 ])
  707 dnl PAC_PROG_F77_IN_C_LIBS
  708 dnl
  709 dnl Find the essential libraries that are needed to use the C linker to 
  710 dnl create a program that includes a trival Fortran code.  
  711 dnl
  712 dnl For example, all pgf90 compiled objects include a reference to the
  713 dnl symbol pgf90_compiled, found in libpgf90 .
  714 dnl
  715 dnl There is an additional problem.  To *run* programs, we may need 
  716 dnl additional arguments; e.g., if shared libraries are used.  Even
  717 dnl with autoconf 2.52, the autoconf macro to find the library arguments
  718 dnl doesn't handle this, either by detecting the use of -rpath or
  719 dnl by trying to *run* a trivial program.  It only checks for *linking*.
  720 dnl 
  721 dnl
  722 AC_DEFUN([PAC_PROG_F77_IN_C_LIBS],[
  723 AC_REQUIRE([AC_HEADER_STDC])
  724 AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])
  725 AC_MSG_CHECKING([for which Fortran libraries are needed to link C with Fortran])
  726 F77_IN_C_LIBS="invalid"
  727 AC_LANG_PUSH([Fortran 77])
  728 AC_COMPILE_IFELSE([
  729     AC_LANG_SOURCE([
  730         subroutine ftest
  731         end
  732     ])
  733 ],[
  734     # pac_f77compile_ok=yes
  735     PAC_RUNLOG([mv conftest.$OBJEXT pac_f77conftest.$OBJEXT])
  736     # Save original LIBS, prepend previously generated object file to LIBS
  737     saved_LIBS="$LIBS"
  738     LIBS="pac_f77conftest.$OBJEXT $FLIBS $saved_LIBS"
  739     AC_LANG_PUSH([C])
  740 
  741     # Create conftest for all link tests.
  742     AC_LANG_CONFTEST([
  743         AC_LANG_PROGRAM([
  744 #if defined(HAVE_STDIO_H) || defined(STDC_HEADERS)
  745 #include <stdio.h>
  746 #endif
  747         ],[
  748 #ifdef F77_NAME_UPPER
  749 #define ftest_ FTEST
  750 #elif defined(F77_NAME_LOWER) || defined(F77_NAME_MIXED)
  751 #define ftest_ ftest
  752 #endif
  753 extern void ftest_(void);
  754 ftest_();
  755         ])
  756     ])
  757 
  758     F77_IN_C_LIBS=""
  759     AC_LINK_IFELSE([],[:],[
  760         flibdirs=`echo $FLIBS | tr ' ' '\012' | grep '\-L' | tr '\012' ' '`
  761         fliblibs=`echo $FLIBS | tr ' ' '\012' | grep -v '\-L' | tr '\012' ' '`
  762         for flibs in $fliblibs ; do
  763             LIBS="pac_f77conftest.$OBJEXT $flibdirs $flibs $saved_LIBS"
  764             AC_LINK_IFELSE([],[F77_IN_C_LIBS="$flibdirs $flibs"; break])
  765         done
  766         if test "X$F77_IN_C_LIBS" = "X" ; then
  767             flibscat=""
  768             for flibs in $fliblibs ; do
  769                 flibscat="$flibscat $flibs"
  770                 LIBS="pac_f77conftest.$OBJEXT $flibdirs $flibscat $saved_LIBS"
  771                 AC_LINK_IFELSE([],[F77_IN_C_LIBS="$flibdirs $flibscat";break])
  772             done
  773         fi
  774     ])
  775 
  776     # remove conftest created by ac_lang_conftest
  777     rm -f conftest.$ac_ext
  778     AC_LANG_POP([C])
  779     LIBS="$saved_LIBS"
  780     rm -f pac_f77conftest.$OBJEXT
  781 ])
  782 AC_LANG_POP([Fortran 77])
  783 if test "X$F77_IN_C_LIBS" = "X" ; then
  784     AC_MSG_RESULT(none)
  785 else
  786     AC_MSG_RESULT($F77_IN_C_LIBS)
  787 fi
  788 ])
  789 dnl
  790 dnl Test to see if we should use C or Fortran to link programs whose
  791 dnl main program is in Fortran.  We may find that neither work because 
  792 dnl we need special libraries in each case.
  793 dnl
  794 AC_DEFUN([PAC_PROG_F77_LINKER_WITH_C],[
  795 AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])
  796 AC_MSG_CHECKING([for linker for Fortran main program])
  797 dnl Create a C program that uses multiplication and division
  798 dnl in case that requires special libraries
  799 AC_LANG_PUSH([C])
  800 AC_COMPILE_IFELSE([
  801     AC_LANG_PROGRAM([],[long long a;])
  802 ],[
  803     AC_DEFINE(HAVE_LONG_LONG,1,[Define if long long allowed])
  804 ])
  805 AC_LANG_CONFTEST([
  806     AC_LANG_SOURCE([
  807 #ifdef HAVE_LONG_LONG
  808 int f(int a, long long b) { int c; c = a * ( b / 3 ) / (b-1); return c ; }
  809 #else
  810 int f(int a, long b) { int c; c = a * b / (b-1); return c ; }
  811 #endif
  812     ])
  813 ])
  814 AC_LANG_POP([C])
  815 
  816 dnl Create a Fortran program for test
  817 AC_LANG_PUSH([Fortran 77])
  818 AC_LANG_CONFTEST([
  819     AC_LANG_SOURCE([
  820         program main
  821         double precision d
  822         print *, "hi"
  823         end
  824     ])
  825 ])
  826 AC_LANG_POP([Fortran 77])
  827 
  828 dnl Initialize flags
  829 pac_linkwithf77=no
  830 pac_linkwithC=no
  831 
  832 dnl Use F77 as a linker to compile a Fortran main and C subprogram.
  833 if test "$pac_linkwithC" != "yes" ; then
  834     AC_LANG_PUSH([C])
  835     AC_COMPILE_IFELSE([],[
  836         PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT])
  837         saved_LIBS="$LIBS"
  838         LIBS="pac_conftest.$OBJEXT $saved_LIBS"
  839         AC_LANG_PUSH([Fortran 77])
  840         AC_LINK_IFELSE([],[
  841             AC_MSG_RESULT([Use Fortran to link programs])
  842             pac_linkwithf77=yes
  843         ])
  844         AC_LANG_POP([Fortran 77])
  845         LIBS="$saved_LIBS"
  846         rm -f pac_conftest.$OBJEXT
  847     ])
  848     AC_LANG_POP([C])
  849 fi
  850 
  851 dnl Use C as a linker and FLIBS to compile a Fortran main and C subprogram.
  852 if test "$pac_linkwithf77" != "yes" ; then
  853     AC_LANG_PUSH([Fortran 77])
  854     AC_COMPILE_IFELSE([],[
  855         PAC_RUNLOG([mv conftest.$OBJEXT pac_f77conftest.$OBJEXT])
  856         saved_LIBS="$LIBS"
  857         LIBS="pac_f77conftest.$OBJEXT $FLIBS $saved_LIBS"
  858         AC_LANG_PUSH([C])
  859         AC_LINK_IFELSE([],[
  860             pac_linkwithC=yes
  861             AC_MSG_RESULT([Use C with FLIBS to link programs])
  862             F77LINKER="$CC"
  863             F77_LDFLAGS="$F77_LDFLAGS $FLIBS"
  864         ])
  865         AC_LANG_POP([C])
  866         LIBS="$saved_LIBS"
  867         rm -f pac_f77conftest.$OBJEXT
  868     ])
  869     AC_LANG_POP([Fortran 77])
  870 fi
  871 
  872 AC_LANG_PUSH([Fortran 77])
  873 rm -f conftest.$ac_ext
  874 AC_LANG_POP([Fortran 77])
  875 
  876 AC_LANG_PUSH([C])
  877 rm -f conftest.$ac_ext
  878 AC_LANG_POP([C])
  879 
  880 if test "$pac_linkwithf77" != "yes" -a "$pac_linkwithC" != "yes" ; then
  881     AC_MSG_ERROR([Could not determine a way to link a Fortran test program!])
  882 fi
  883 ])
  884 dnl
  885 dnl Check to see if a C program can be linked when using the libraries
  886 dnl needed by C programs
  887 dnl
  888 AC_DEFUN([PAC_PROG_F77_CHECK_FLIBS],[
  889 AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])
  890 AC_MSG_CHECKING([whether $CC links with FLIBS found by autoconf])
  891 AC_LANG_PUSH([C])
  892 # Create a simple C program for the tests.
  893 AC_LANG_CONFTEST([
  894     AC_LANG_PROGRAM([],[int a;])
  895 ])
  896 # Try to link a C program with all of these libraries
  897 saved_LIBS="$LIBS"
  898 LIBS="$FLIBS $saved_LIBS"
  899 AC_LINK_IFELSE([],[
  900     AC_MSG_RESULT([yes])
  901 ],[
  902     AC_MSG_RESULT([no])
  903     AC_MSG_CHECKING([for which libraries can be used])
  904     pac_ldirs=""
  905     pac_libs=""
  906     pac_other=""
  907     for name in $FLIBS ; do
  908         case $name in 
  909         -l*) pac_libs="$pac_libs $name"   ;;
  910         -L*) pac_ldirs="$pac_ldirs $name" ;;
  911           *) pac_other="$pac_other $name" ;;
  912         esac
  913     done
  914     keep_libs=""
  915     for name in $pac_libs ; do
  916         LIBS="$saved_LIBS $pac_ldirs $pac_other $name"
  917         AC_LINK_IFELSE([],[
  918             keep_libs="$keep_libs $name"
  919         ])
  920     done
  921     AC_MSG_RESULT($keep_libs)
  922     FLIBS="$pac_ldirs $pac_other $keep_libs"
  923 ])
  924 LIBS="$saved_LIBS"
  925 rm -f conftest.$ac_ext
  926 AC_LANG_PUSH([C])
  927 ])
  928 dnl
  929 dnl Test for extra libraries needed when linking C routines that use
  930 dnl stdio with Fortran.  This test was created for OSX, which 
  931 dnl sometimes requires -lSystemStubs.  If another library is needed,
  932 dnl add it to F77_OTHER_LIBS
  933 dnl
  934 AC_DEFUN([PAC_PROG_F77_AND_C_STDIO_LIBS],[
  935 AC_REQUIRE([AC_HEADER_STDC])
  936 AC_REQUIRE([PAC_PROG_F77_NAME_MANGLE])
  937 # To simply the code in the cache_check macro, chose the routine name
  938 # first, in case we need it
  939 confname=conf1_
  940 case "$pac_cv_prog_f77_name_mangle" in
  941     "lower underscore")       confname=conf1_ ;;
  942     "upper stdcall")          confname=CONF1  ;;
  943     "upper")                  confname=CONF1  ;;
  944     "lower doubleunderscore") confname=conf1_ ;;
  945     "lower")                  confname=conf1  ;;
  946     "mixed underscore")       confname=conf1_ ;;
  947     "mixed")                  confname=conf1  ;;
  948 esac
  949 
  950 AC_CACHE_CHECK([for libraries to link Fortran main with C stdio routines],
  951 pac_cv_prog_f77_and_c_stdio_libs,[
  952 pac_cv_prog_f77_and_c_stdio_libs=unknown
  953 AC_LANG_PUSH([C])
  954 AC_COMPILE_IFELSE([
  955     AC_LANG_SOURCE([
  956 #if defined(HAVE_STDIO_H) || defined(STDC_HEADERS)
  957 #include <stdio.h>
  958 #endif
  959 int $confname(int a) {
  960     printf( "The answer is %d\n", a ); fflush(stdout); return 0;
  961 }
  962     ])
  963 ],[
  964     PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT])
  965     saved_LIBS="$LIBS"
  966     AC_LANG_PUSH([Fortran 77])
  967     AC_LANG_CONFTEST([
  968         AC_LANG_SOURCE([
  969             program main
  970             call conf1(0)
  971             end
  972         ])
  973     ])
  974     for extralib in "" "-lSystemStubs" ; do
  975         LIBS="pac_conftest.$OBJEXT $saved_LIBS $extralib"
  976         AC_LINK_IFELSE([],[
  977             pac_cv_prog_f77_and_c_stdio_libs="$extralib"; break
  978         ])
  979     done
  980     if test "X$pac_cv_prog_f77_and_c_stdio_libs" = "X" ; then
  981         pac_cv_prog_f77_and_c_stdio_libs=none
  982     fi
  983     rm -f conftest.$ac_ext
  984     AC_LANG_POP([Fortran 77])
  985     LIBS="$saved_LIBS"
  986     rm -f pac_conftest.$OBJEXT
  987 ])
  988 AC_LANG_POP([C])
  989 ])
  990 dnl Endof ac_cache_check
  991 if test "$pac_cv_prog_f77_and_c_stdio_libs" != "none" \
  992      -a "$pac_cv_prog_f77_and_c_stdio_libs" != "unknown" ; then
  993     F77_OTHER_LIBS="$F77_OTHER_LIBS $pac_cv_prog_f77_and_c_stdio_libs"
  994 fi    
  995 ])
  996 dnl
  997 dnl Check that the FLIBS determined by AC_F77_LIBRARY_LDFLAGS is valid.
  998 dnl That macro (at least as of autoconf 2.59) attempted to parse the output
  999 dnl of the compiler when asked to be verbose; in the case of the Fujitsu
 1000 dnl frt Fortran compiler, it included files that frt looked for and then
 1001 dnl discarded because they did not exist.
 1002 dnl
 1003 AC_DEFUN([PAC_PROG_F77_FLIBS_VALID],[
 1004 AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])
 1005 AC_MSG_CHECKING([whether $F77 accepts the FLIBS found by autoconf])
 1006 pac_cv_f77_flibs_valid=unknown
 1007 AC_LANG_PUSH([Fortran 77])
 1008 AC_LANG_CONFTEST([
 1009     AC_LANG_SOURCE([
 1010         program main
 1011         end
 1012     ])
 1013 ])
 1014 AC_LINK_IFELSE([],[
 1015     AC_MSG_RESULT([yes])
 1016 ],[
 1017     AC_MSG_RESULT([no])
 1018     AC_MSG_CHECKING([for valid entries in FLIBS])
 1019     goodFLIBS=""
 1020     saveFLIBS=$FLIBS
 1021     FLIBS=""
 1022     for arg in $saveFLIBS ; do
 1023         FLIBS="$goodFLIBS $arg"
 1024         AC_LINK_IFELSE([],[goodFLIBS=$FLIBS])
 1025     done
 1026     FLIBS=$goodFLIBS
 1027     AC_MSG_RESULT($FLIBS)
 1028 ])
 1029 rm -f conftest.$ac_ext
 1030 AC_LANG_POP([Fortran 77])
 1031 ])
 1032 dnl
 1033 dnl Check if the Fortran 77 and C objects are compatible in linking.
 1034 dnl e.g. On some intel x86_64 Mac, Fortran compiler's default binary format
 1035 dnl is different from C, so either -m64 or -m32 is needed in either CFLAGS
 1036 dnl or FFLAGS.
 1037 dnl
 1038 AC_DEFUN([PAC_PROG_F77_OBJ_LINKS_WITH_C],[
 1039 AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])
 1040 AC_MSG_CHECKING([whether Fortran 77 and C objects are compatible])
 1041 AC_LANG_PUSH([C])
 1042 AC_LANG_CONFTEST([
 1043     AC_LANG_SOURCE([
 1044 /* lower */
 1045 void c_subpgm( int *rc );
 1046 void c_subpgm( int *rc ) { *rc = 1; }
 1047 
 1048 /* lower underscore */
 1049 void c_subpgm_( int *rc );
 1050 void c_subpgm_( int *rc ) { *rc = 2; }
 1051 
 1052 /* upper */
 1053 void C_SUBPGM( int *rc );
 1054 void C_SUBPGM( int *rc ) { *rc = 3; }
 1055 
 1056 /* lower doubleunderscore */
 1057 void c_subpgm__( int *rc );
 1058 void c_subpgm__( int *rc ) { *rc = 4; }
 1059 
 1060 /* mixed */
 1061 void C_subpgm( int *rc );
 1062 void C_subpgm( int *rc ) { *rc = 5; }
 1063 
 1064 /* mixed underscore */
 1065 void C_subpgm_( int *rc );
 1066 void C_subpgm_( int *rc ) { *rc = 6; }
 1067     ])
 1068 ])
 1069 AC_LANG_POP([C])
 1070 
 1071 AC_LANG_PUSH([Fortran 77])
 1072 AC_LANG_CONFTEST([
 1073     AC_LANG_SOURCE([
 1074         program test
 1075         integer rc
 1076         rc = -1
 1077         call c_subpgm( rc )
 1078         write(6,*) "rc=", rc
 1079         end
 1080     ])
 1081 ])
 1082 AC_LANG_POP([Fortran 77])
 1083 
 1084 dnl Initialize flags
 1085 pac_linkwithf77=no
 1086 pac_linkwithC=no
 1087 
 1088 dnl Use F77 as a linker to compile a Fortran main and C subprogram.
 1089 if test "$pac_linkwithC" != "yes" ; then
 1090     AC_LANG_PUSH([C])
 1091     AC_COMPILE_IFELSE([],[
 1092         PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT])
 1093         saved_LIBS="$LIBS"
 1094         LIBS="pac_conftest.$OBJEXT $saved_LIBS"
 1095         AC_LANG_PUSH([Fortran 77])
 1096         AC_LINK_IFELSE([],[
 1097             pac_linkwithf77=yes
 1098             AC_MSG_RESULT([yes])
 1099         ])
 1100         AC_LANG_POP([Fortran 77])
 1101         LIBS="$saved_LIBS"
 1102         if test "$pac_linkwithf77" = "yes" ; then
 1103             rm -f pac_conftest.$OBJEXT
 1104         fi
 1105     ])
 1106     AC_LANG_POP([C])
 1107 fi
 1108 
 1109 dnl Use C as a linker and FLIBS to compile a Fortran main and C subprogram.
 1110 if test "$pac_linkwithf77" != "yes" ; then
 1111     AC_LANG_PUSH([Fortran 77])
 1112     AC_COMPILE_IFELSE([],[
 1113         PAC_RUNLOG([mv conftest.$OBJEXT pac_f77conftest.$OBJEXT])
 1114         saved_LIBS="$LIBS"
 1115         LIBS="pac_f77conftest.$OBJEXT $FLIBS $saved_LIBS"
 1116         AC_LANG_PUSH([C])
 1117         AC_LINK_IFELSE([],[
 1118             pac_linkwithC=yes
 1119             AC_MSG_RESULT([yes])
 1120         ])
 1121         AC_LANG_POP([C])
 1122         LIBS="$saved_LIBS"
 1123         if test "$pac_linkwithC" = "yes" ; then
 1124             rm -f pac_f77conftest.$OBJEXT
 1125         fi
 1126     ])
 1127     AC_LANG_POP([Fortran 77])
 1128 fi
 1129 
 1130 AC_LANG_PUSH([Fortran 77])
 1131 rm -f conftest.$ac_ext
 1132 AC_LANG_POP([Fortran 77])
 1133 
 1134 AC_LANG_PUSH([C])
 1135 rm -f conftest.$ac_ext
 1136 AC_LANG_POP([C])
 1137 
 1138 if test "$pac_linkwithf77" != "yes" -a "$pac_linkwithC" != "yes" ; then
 1139     AC_MSG_RESULT(no)
 1140     AC_CHECK_PROG(FILE, file, file, [])
 1141     if test "X$FILE" != "X" ; then
 1142         fobjtype="`${FILE} pac_f77conftest.$OBJEXT | sed -e \"s|pac_f77conftest\.$OBJEXT||g\"`"
 1143         cobjtype="`${FILE} pac_conftest.$OBJEXT | sed -e \"s|pac_conftest\.$OBJEXT||g\"`"
 1144         if test "$fobjtype" != "$cobjtype" ; then
 1145             AC_MSG_ERROR([****  Incompatible Fortran and C Object File Types!  ****
 1146 F77 Object File Type produced by \"${F77} ${FFLAGS}\" is : ${fobjtype}.
 1147  C  Object File Type produced by \"${CC} ${CFLAGS}\" is : ${cobjtype}.])
 1148         fi
 1149     fi
 1150 fi
 1151 ])
 1152 dnl
 1153 dnl /*D
 1154 dnl PAC_F77_WORKS_WITH_CPP
 1155 dnl
 1156 dnl Checks if Fortran 77 compiler works with C preprocessor
 1157 dnl
 1158 dnl Most systems allow the Fortran compiler to process .F and .F90 files
 1159 dnl using the C preprocessor.  However, some systems either do not
 1160 dnl allow this or have serious bugs (OSF Fortran compilers have a bug
 1161 dnl that generates an error message from cpp).  The following test
 1162 dnl checks to see if .F works, and if not, whether "cpp -P -C" can be used
 1163 dnl D*/
 1164 AC_DEFUN([PAC_F77_WORKS_WITH_CPP],[
 1165 AC_REQUIRE([AC_PROG_CPP])
 1166 AC_MSG_CHECKING([whether Fortran 77 compiler processes .F files with C preprocessor])
 1167 AC_LANG_PUSH([Fortran 77])
 1168 saved_f77_ext=${ac_ext}
 1169 ac_ext="F"
 1170 saved_FFLAGS="$FFLAGS"
 1171 FFLAGS="$FFLAGS $CPPFLAGS"
 1172 AC_LANG_CONFTEST([
 1173     AC_LANG_SOURCE([
 1174         program main
 1175 #define ASIZE 10
 1176         integer a(ASIZE)
 1177         end
 1178     ])
 1179 ])
 1180 AC_COMPILE_IFELSE([],[
 1181     pac_cv_f77_accepts_F=yes
 1182     ifelse([$1],[],[],[$1=""])
 1183 ],[
 1184     pac_cv_f77_accepts_F=no
 1185     ifelse([$1],[],[:],[$1="false"])
 1186 ])
 1187 # Restore Fortran 77's ac_ext but not FFLAGS
 1188 ac_ext="$saved_f77_ext"
 1189 
 1190 if test "$pac_cv_f77_accepts_F" != "yes" ; then
 1191     pac_cpp_f77="$ac_cpp -C -P conftest.F > conftest.$ac_ext"
 1192     PAC_RUNLOG_IFELSE([$pac_cpp_f77],[
 1193         if test -s conftest.${ac_ext} ; then
 1194             AC_COMPILE_IFELSE([],[
 1195                 pac_cv_f77_accepts_F="no, use cpp"
 1196                 ifelse([$1],[],[],[$1="$CPP -C -P"])
 1197             ],[])
 1198             rm -f conftest.${ac_ext}
 1199         fi
 1200     ],[])
 1201 fi
 1202 FFLAGS="$saved_FFLAGS"
 1203 rm -f conftest.F
 1204 AC_LANG_POP([Fortran 77])
 1205 AC_MSG_RESULT([$pac_cv_f77_accepts_F])
 1206 ])
 1207 dnl
 1208 dnl /*D 
 1209 dnl PAC_PROG_F77_CRAY_POINTER - Check if Fortran 77 supports Cray-style pointer.
 1210 dnl                             If so, set pac_cv_prog_f77_has_pointer to yes
 1211 dnl                             and find out if any extra compiler flag is
 1212 dnl                             needed and set it as CRAYPTR_FFLAGS.
 1213 dnl                             i.e. CRAYPTR_FFLAGS is meaningful only if
 1214 dnl                             pac_cv_prog_f77_has_pointer = yes.
 1215 dnl
 1216 dnl Synopsis:
 1217 dnl   PAC_PROG_F77_CRAY_POINTER([action-if-true],[action-if-false])
 1218 dnl D*/
 1219 AC_DEFUN([PAC_PROG_F77_CRAY_POINTER],[
 1220 AC_CACHE_CHECK([whether Fortran 77 supports Cray-style pointer],
 1221 pac_cv_prog_f77_has_pointer,[
 1222 AC_LANG_PUSH([Fortran 77])
 1223 AC_LANG_CONFTEST([
 1224     AC_LANG_PROGRAM([],[
 1225         integer M
 1226         pointer (MPTR,M)
 1227         data MPTR/0/
 1228     ])
 1229 ])
 1230 saved_FFLAGS="$FFLAGS"
 1231 pac_cv_prog_f77_has_pointer=no
 1232 CRAYPTR_FFLAGS=""
 1233 for ptrflag in '' '-fcray-pointer' ; do
 1234     FFLAGS="$saved_FFLAGS $ptrflag"
 1235     AC_COMPILE_IFELSE([], [
 1236         pac_cv_prog_f77_has_pointer=yes
 1237         CRAYPTR_FFLAGS="$ptrflag"
 1238         break
 1239     ])
 1240 done
 1241 dnl Restore FFLAGS first, since user may not want to modify FFLAGS
 1242 FFLAGS="$saved_FFLAGS"
 1243 dnl remove conftest after ac_lang_conftest
 1244 rm -f conftest.$ac_ext
 1245 AC_LANG_POP([Fortran 77])
 1246 ])
 1247 if test "$pac_cv_prog_f77_has_pointer" = "yes" ; then
 1248     AC_MSG_CHECKING([for Fortran 77 compiler flag for Cray-style pointer])
 1249     if test "X$CRAYPTR_FFLAGS" != "X" ; then
 1250         AC_MSG_RESULT([$CRAYPTR_FFLAGS])
 1251     else
 1252         AC_MSG_RESULT([none])
 1253     fi
 1254     ifelse([$1],[],[:],[$1])
 1255 else
 1256     ifelse([$2],[],[:],[$2])
 1257 fi
 1258 ])
 1259 dnl
 1260 dnl
 1261 dnl PAC_F77_INIT_WORKS_WITH_C
 1262 dnl
 1263 AC_DEFUN([PAC_F77_INIT_WORKS_WITH_C],[
 1264 AC_REQUIRE([AC_HEADER_STDC])
 1265 AC_MSG_CHECKING([whether Fortran init will work with C])
 1266 pac_f_init_works_with_c=unknown
 1267 AC_LANG_PUSH([Fortran 77])
 1268 AC_COMPILE_IFELSE([
 1269     AC_LANG_SOURCE([
 1270         subroutine minit()
 1271         common /m1/ vc, vc2
 1272         character*1 vc(1,1), vc2(1)
 1273         common /m2/ vd
 1274         integer vd
 1275         save /m1/, /m2/
 1276         call minitc( vc, vc2, vd )
 1277         end
 1278     ])
 1279 ],[
 1280     PAC_RUNLOG([mv conftest.$OBJEXT pac_f77conftest.$OBJEXT])
 1281     saved_LIBS="$LIBS"
 1282     # This test checks if Fortran init can be done in pure C environment,
 1283     # i.e. no FLIBS in linking, so don't put FLIBS in LIBS below
 1284     dnl LIBS="pac_f77conftest.$OBJEXT $FLIBS $LIBS"
 1285     LIBS="pac_f77conftest.$OBJEXT $LIBS"
 1286     AC_LANG_PUSH([C])
 1287     AC_LINK_IFELSE([
 1288         AC_LANG_SOURCE([
 1289 #if defined(HAVE_STDIO_H) || defined(STDC_HEADERS)
 1290 #include <stdio.h>
 1291 #endif
 1292 #ifdef F77_NAME_UPPER
 1293 #define minit_ MINIT
 1294 #elif defined(F77_NAME_LOWER) || defined(F77_NAME_MIXED)
 1295 #define minit_ minit
 1296 #endif
 1297 extern void minit_(void);
 1298 int main( int argc, char **argv )
 1299 {
 1300     minit_();
 1301     return 0;
 1302 }
 1303 char *v1 = 0;
 1304 char *vc2 = 0;
 1305 int  v2 = 0;
 1306 void minitc_( char *dv1, int d, char *dv2, int d2, int dv3 );
 1307 void minitc_( char *dv1, int d, char *dv2, int d2, int dv3 )
 1308 {
 1309 v1 = dv1;
 1310 v2 = dv3;
 1311 vc2 = dv2;
 1312 *vc2 = ' ';
 1313 }
 1314         ])
 1315     ],[pac_f_init_works_with_c=yes],[pac_f_init_works_with_c=no])
 1316     AC_LANG_POP([C])
 1317     LIBS="$saved_LIBS"
 1318     rm -f pac_f77conftest.$OBJEXT
 1319 ])
 1320 AC_LANG_POP([Fortran 77])
 1321 AC_MSG_RESULT([$pac_f_init_works_with_c])
 1322 ])
 1323 dnl
 1324 dnl PAC_F77_LOGICALS_IN_C(MPI_FINT)
 1325 dnl
 1326 dnl where MPI_FINT is the C type for Fortran integer.
 1327 dnl
 1328 dnl Use a Fortran main program.  This simplifies some steps, 
 1329 dnl since getting all of the Fortran libraries (including shared 
 1330 dnl libraries that are not in the default library search path) can 
 1331 dnl be tricky.  Specifically, The PROG_F77_RUN_PROC_FROM_C failed with 
 1332 dnl some installations of the Portland group compiler.
 1333 dnl
 1334 dnl We'd also like to check other values for .TRUE. and .FALSE. to see
 1335 dnl if the compiler allows (or uses) more than one value (some DEC compilers,
 1336 dnl for example, used the high (sign) bit to indicate true and false; the 
 1337 dnl rest of the bits were ignored.  For now, we'll assume that there are 
 1338 dnl unique true and false values.
 1339 dnl
 1340 AC_DEFUN([PAC_F77_LOGICALS_IN_C],[
 1341 AC_REQUIRE([AC_HEADER_STDC])
 1342 AC_REQUIRE([PAC_PROG_F77_NAME_MANGLE])
 1343 pac_mpi_fint="$1"
 1344 AC_MSG_CHECKING([for values of Fortran logicals])
 1345 AC_CACHE_VAL(pac_cv_prog_f77_true_false_value,[
 1346 pac_cv_prog_f77_true_false_value=""
 1347 AC_LANG_PUSH([C])
 1348 AC_COMPILE_IFELSE([
 1349     AC_LANG_SOURCE([
 1350 #if defined(HAVE_STDIO_H) || defined(STDC_HEADERS)
 1351 #include <stdio.h>
 1352 #endif
 1353 #if defined(HAVE_STDLIB_H) || defined(STDC_HEADERS)
 1354 #include <stdlib.h>
 1355 #endif
 1356 #ifdef F77_NAME_UPPER
 1357 #define ftest_ FTEST
 1358 #elif defined(F77_NAME_LOWER) || defined(F77_NAME_MIXED)
 1359 #define ftest_ ftest
 1360 #endif
 1361 void ftest_( $pac_mpi_fint *, $pac_mpi_fint *);
 1362 void ftest_( $pac_mpi_fint *itrue, $pac_mpi_fint *ifalse )
 1363 {
 1364   FILE *f = fopen("conftestval","w");
 1365   if (!f) exit(1);
 1366   fprintf( f, "%d %d\n", *itrue, *ifalse );
 1367   fclose(f);
 1368 }
 1369     ])
 1370 ],[
 1371     PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT])
 1372     saved_LIBS="$LIBS"
 1373     LIBS="pac_conftest.$OBJEXT $saved_LIBS"
 1374     AC_LANG_PUSH([Fortran 77])
 1375     AC_RUN_IFELSE([
 1376         AC_LANG_SOURCE([
 1377             program main
 1378             logical itrue, ifalse
 1379             itrue = .TRUE.
 1380             ifalse = .FALSE.
 1381             call ftest( itrue, ifalse )
 1382             end
 1383         ])
 1384     ],[
 1385         pac_cv_prog_f77_true_false_value="`cat conftestval`"
 1386     ],[
 1387         AC_MSG_WARN([Failed to build/run program to determine Fortran logical values.])
 1388     ],[
 1389         # Cross-Compiling.  Allow the user to set the values
 1390         if test -n "$CROSS_F77_TRUE_VALUE" -a -n "$CROSS_F77_FALSE_VALUE" ; then
 1391             pac_cv_prog_f77_true_false_value="$CROSS_F77_TRUE_VALUE $CROSS_F77_FALSE_VALUE"
 1392         else
 1393             AC_MSG_WARN([Either CROSS_F77_TRUE_VALUE="$CROSS_F77_TRUE_VALUE" or CROSS_F77_FALSE_VALUE="$CROSS_F77_FALSE_VALUE" is not set.])
 1394         fi
 1395     ])
 1396     AC_LANG_POP([Fortran 77])
 1397     LIBS="$saved_LIBS"
 1398     rm -f pac_conftest.$OBJEXT
 1399 ])
 1400 AC_LANG_POP([C])
 1401 ])
 1402 dnl Endof ac_cache_val
 1403 if test "X$pac_cv_prog_f77_true_false_value" != "X" ; then
 1404     true_val="`echo $pac_cv_prog_f77_true_false_value | sed -e 's/ .*//g'`"
 1405     false_val="`echo $pac_cv_prog_f77_true_false_value | sed -e 's/.*  *//g'`"
 1406     if test -n "$true_val" -a -n "$false_val" ; then
 1407         AC_MSG_RESULT([True is $true_val and False is $false_val])
 1408     else
 1409         AC_MSG_RESULT([could not determine])
 1410     fi
 1411 fi
 1412 if test -n "$true_val" -a -n "$false_val" ; then
 1413     AC_DEFINE(F77_TRUE_VALUE_SET,1,[Define if we know the value of Fortran true and false])
 1414     AC_DEFINE_UNQUOTED(F77_TRUE_VALUE,$true_val,[The value of true in Fortran])
 1415     AC_DEFINE_UNQUOTED(F77_FALSE_VALUE,$false_val,[The value of false in Fortran])
 1416 fi
 1417 ])
 1418 dnl/*D
 1419 dnl PAC_PROG_F77_MISMATCHED_ARGS([option],[AllOnly]) - Determine whether the 
 1420 dnl Fortran compiler allows routines to be called with different 
 1421 dnl argument types.  If not, attempts to determine a command-line argument 
 1422 dnl that permits such use 
 1423 dnl (The Fortran standard prohibits this usage)
 1424 dnl
 1425 dnl option is set to the compiler option to use.
 1426 dnl if AllOnly is yes (literal, not variable with value), then only consider 
 1427 dnl options that turn off checking
 1428 dnl for all routines
 1429 dnl
 1430 dnl The NAG Fortran compiler, nagfor, is known to enforce this part of the
 1431 dnl Fortran standard.
 1432 dnl D*/
 1433 AC_DEFUN([PAC_PROG_F77_MISMATCHED_ARGS],[
 1434 AC_MSG_CHECKING([whether $F77 allows mismatched arguments])
 1435 if test "X$pac_cv_prog_f77_mismatched_args" = X ; then
 1436     pac_cv_prog_f77_mismatched_args_parm=""
 1437     pac_cv_prog_f77_mismatched_args=no
 1438     AC_LANG_PUSH([Fortran 77])
 1439     AC_COMPILE_IFELSE([
 1440        AC_LANG_SOURCE([
 1441         program main
 1442         integer a
 1443         real b
 1444         character c
 1445         call foo1(a)
 1446         call foo1(b)
 1447         call foo1(c)
 1448         end
 1449 ])],[pac_cv_prog_f77_mismatched_args=yes])
 1450     if test "$pac_cv_prog_f77_mismatched_args" != "yes" ; then
 1451         # try again with -wmismatch=foo1
 1452         save_FFLAGS="$FFLAGS"
 1453 	# The best solution is to turn off errors on particular routines
 1454 	# if that isn't possible (e.g., too many of them), then
 1455 	# just try arguments that turn off all checking
 1456 	for flags in ifelse($2,yes,,"-wmismatch=foo1") "-mismatch" ; do
 1457             testok=no
 1458             FFLAGS="$FFLAGS $flags"
 1459             AC_COMPILE_IFELSE([
 1460             AC_LANG_SOURCE([
 1461         program main
 1462         integer a
 1463         real b
 1464         character c
 1465         call foo1(a)
 1466         call foo1(b)
 1467         call foo1(c)
 1468         end
 1469 ])],[testok=yes])
 1470             FFLAGS="$save_FFLAGS"
 1471             if test "$testok" = yes ; then break ; fi
 1472         done
 1473         if test "$testok" = yes ; then 
 1474 	    pac_cv_prog_f77_mismatched_args_parm="$flags"
 1475             pac_cv_prog_f77_mismatched_args="yes, with $pac_cv_prog_f77_mismatched_args_parm"
 1476         fi
 1477     fi
 1478     AC_LANG_POP([Fortran 77])
 1479 fi
 1480 AC_MSG_RESULT($pac_cv_prog_f77_mismatched_args)
 1481 if test "$pac_cv_prog_f77_mismatched_args" = no ; then
 1482     AC_MSG_ERROR([The Fortran compiler $F77 will not compile files that call 
 1483 the same routine with arguments of different types.])
 1484 fi
 1485 
 1486 ifelse($1,,,[$1=$pac_cv_prog_f77_mismatched_args_parm])
 1487 ])