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