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