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 \
10 dnl PAC_PROG_F77_NAME_MANGLE - Determine how the Fortran compiler mangles
14 dnl PAC_PROG_F77_NAME_MANGLE([action])
17 dnl If no action is specified, one of the following names is defined:
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
28 dnl If an action is specified, it is executed instead.
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)
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.
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
54 AC_LANG_PUSH([Fortran 77])
57 subroutine MY_name( ii )
62 PAC_RUNLOG([mv conftest.$OBJEXT f77conftest.$OBJEXT])
64 dnl FLIBS is set by AC_F77_LIBRARY_LDFLAGS
65 LIBS="f77conftest.$OBJEXT $FLIBS $LIBS"
67 for call in "" __stdcall ; do
68 for sym in my_name_ my_name__ my_name MY_NAME MY_name MY_name_ NONE ; do
70 AC_LANG_PROGRAM([extern void ${call} ${sym}(int);],[${sym}(0);])
76 test "$pac_found" = "yes" && break
80 rm -f f77conftest.$OBJEXT
82 AC_LANG_POP([Fortran 77])
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
89 for call in "" __stdcall ; do
90 for sym in my_name_ my_name__ my_name MY_NAME MY_name MY_name_ NONE ; do
92 AC_LANG_SOURCE([void ${call} ${sym}(int a) {}])
94 PAC_RUNLOG([mv conftest.$OBJEXT cconftest.$OBJEXT])
96 LIBS="cconftest.$OBJEXT $LIBS"
97 AC_LANG_PUSH([Fortran 77])
99 AC_LANG_PROGRAM([],[ call my_name(0)])
103 AC_LANG_POP([Fortran 77])
105 rm -f cconftest.$OBJEXT
106 test "$pac_found" = "yes" && break
109 test "$pac_found" = "yes" && break
113 if test "$pac_found" = "yes" ; then
116 pac_cv_prog_f77_name_mangle="lower uscore" ;;
118 pac_cv_prog_f77_name_mangle="lower 2uscore" ;;
120 pac_cv_prog_f77_name_mangle="lower" ;;
122 pac_cv_prog_f77_name_mangle="upper" ;;
124 pac_cv_prog_f77_name_mangle="mixed" ;;
126 pac_cv_prog_f77_name_mangle="mixed uscore" ;;
128 pac_cv_prog_f77_name_mangle=""
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"
139 dnl Endof ac_cache_check
140 case $pac_cv_prog_f77_name_mangle in
142 F77_STDCALL="__stdcall" ;;
146 # Get the standard call definition
147 # FIXME: This should use F77_STDCALL, not STDCALL (non-conforming name)
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])
195 dnl PAC_PROG_F77_CHECK_SIZEOF - Determine the size in bytes of a Fortran
199 dnl PAC_PROG_F77_CHECK_SIZEOF(type,[cross-size])
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').
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.
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
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])
235 call cisize( i(1), i(2) )
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
243 LIBS="pac_f77conftest.$OBJEXT $FLIBS $LIBS"
247 #if defined(HAVE_STDIO_H) || defined(STDC_HEADERS)
250 #ifdef F77_NAME_UPPER
251 #define cisize_ CISIZE
253 #elif defined(F77_NAME_LOWER) || defined(F77_NAME_MIXED)
254 #define cisize_ cisize
257 static int isize_val=0;
258 void cisize_(char *,char*);
260 void cisize_(char *i1p, char *i2p)
262 isize_val = (int)(i2p - i1p);
265 FILE *f = fopen("conftestval", "w");
268 fprintf(f,"%d\n", isize_val);
270 dnl Endof ac_lang_program
272 eval PAC_CV_NAME=`cat conftestval`
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])
279 dnl Endof ac_run_ifelse
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
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
317 dnl [AC_MSG_WARN([No value provided for size of $1 when cross-compiling])],
318 dnl [eval PAC_CV_NAME=$2])
323 #if defined(HAVE_STDIO_H) || defined(STDC_HEADERS)
326 #ifdef F77_NAME_UPPER
327 #define cisize_ CISIZE
329 #elif defined(F77_NAME_LOWER) || defined(F77_NAME_MIXED)
330 #define cisize_ cisize
333 int cisize_(char *,char*);
334 int cisize_(char *i1p, char *i2p) {
336 FILE *f = fopen("conftestval", "w");
338 isize_val = (int)(i2p - i1p);
339 fprintf(f,"%d\n", isize_val);
344 dnl Endof ac_lang_source
347 PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT])
348 # Save LIBS and prepend object file to LIBS
350 LIBS="pac_conftest.$OBJEXT $LIBS"
351 AC_LANG_PUSH([Fortran 77])
357 irc = cisize(a(1),a(2))
361 eval PAC_CV_NAME=`cat conftestval`
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])
368 AC_LANG_POP([Fortran 77])
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])
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])
387 dnl PAC_PROG_F77_EXCLAIM_COMMENTS
390 dnl PAC_PROG_F77_EXCLAIM_COMMENTS([action-if-true],[action-if-false])
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).
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])
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])
416 ifelse([$2],[],[:],[$2])
421 dnl PAC_F77_CHECK_COMPILER_OPTION - Check that a F77 compiler option is
422 dnl accepted without warning messages
425 dnl PAC_F77_CHECK_COMPILER_OPTION(optionname,action-if-ok,action-if-fail)
429 dnl If no actions are specified, a working value is added to 'FOPTIONS'
432 dnl This is now careful to check that the output is different, since
433 dnl some compilers are noisy.
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.
441 AC_DEFUN([PAC_F77_CHECK_COMPILER_OPTION],[
442 AC_MSG_CHECKING([whether Fortran 77 compiler accepts option $1])
444 AC_LANG_PUSH([Fortran 77])
445 FFLAGS_orig="$FFLAGS"
446 FFLAGS_opt="$pac_opt $FFLAGS"
449 AC_LANG_CONFTEST([AC_LANG_PROGRAM()])
450 FFLAGS="$FFLAGS_orig"
452 PAC_LINK_IFELSE_LOG([pac_test1.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])
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])
471 FFLAGS="$FFLAGS_orig"
473 PAC_COMPILE_IFELSE_LOG([pac_test3.log], [
479 PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT])
481 LIBS="pac_conftest.$OBJEXT $LIBS"
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])
492 rm -f pac_conftest.$OBJEXT
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])
507 ifelse([$3],[],[:],[$3])
509 AC_LANG_POP([Fortran 77])
513 dnl PAC_PROG_F77_LIBRARY_DIR_FLAG - Determine the flag used to indicate
514 dnl the directories to find libraries in
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'.
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])
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
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"
556 ],[pac_cv_prog_f77_library_dir_flag="$ldir";break])
558 LDFLAGS="$saved_LDFLAGS"
561 rm -f pac_f77conftest.$OBJEXT
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)
573 dnl PAC_PROG_F77_HAS_INCDIR - Check whether Fortran accepts -Idir flag
576 dnl PAC_PROG_F77_HAS_INCDIR(directory,action-if-true,action-if-false)
579 dnl Sets 'F77_INCDIR' to the flag used to choose the directory.
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.
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"
599 for idir in "-I" "-Wf,-I" ; do
600 FFLAGS="${idir} $checkdir $saved_FFLAGS"
604 include 'conftestf.h'
607 ],[pac_cv_prog_f77_has_incdir="$idir"; break])
609 FFLAGS="$saved_FFLAGS"
610 AC_LANG_POP([Fortran 77])
611 if test "$checkdir_is_given" = "yes" ; then
612 rm -f $checkdir/conftestf.h
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"
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
630 dnl PAC_PROG_F77_ALLOWS_UNUSED_EXTERNALS(action-if-true,action-if-false)
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])
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])
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],
660 dnl Fortran routine MUST be named ftest unless you include code
661 dnl to select the appropriate Fortran name.
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])
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
674 LIBS="pac_f77conftest.$OBJEXT $FLIBS $LIBS"
678 #if defined(HAVE_STDIO_H) || defined(STDC_HEADERS)
681 #ifdef F77_NAME_UPPER
683 #elif defined(F77_NAME_LOWER) || defined(F77_NAME_MIXED)
689 ifelse([$3],[],[:],[$3])
691 ifelse([$4],[],[:],[$4])
693 ifelse([$5],[],[:],[$5])
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*.
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])
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
733 LIBS="pac_f77conftest.$OBJEXT $FLIBS $saved_LIBS"
736 # Create conftest for all link tests.
739 #if defined(HAVE_STDIO_H) || defined(STDC_HEADERS)
743 #ifdef F77_NAME_UPPER
745 #elif defined(F77_NAME_LOWER) || defined(F77_NAME_MIXED)
748 extern void ftest_(void);
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])
761 if test "X$F77_IN_C_LIBS" = "X" ; then
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])
771 # remove conftest created by ac_lang_conftest
772 rm -f conftest.$ac_ext
775 rm -f pac_f77conftest.$OBJEXT
777 AC_LANG_POP([Fortran 77])
778 if test "X$F77_IN_C_LIBS" = "X" ; then
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
796 AC_LANG_PROGRAM([],[long long a;])
798 AC_DEFINE(HAVE_LONG_LONG,1,[Define if long long allowed])
802 #ifdef HAVE_LONG_LONG
803 int f(int a, long long b) { int c; c = a * ( b / 3 ) / (b-1); return c ; }
805 int f(int a, long b) { int c; c = a * b / (b-1); return c ; }
811 dnl Create a Fortran program for test
812 AC_LANG_PUSH([Fortran 77])
821 AC_LANG_POP([Fortran 77])
827 dnl Use F77 as a linker to compile a Fortran main and C subprogram.
828 if test "$pac_linkwithC" != "yes" ; then
830 AC_COMPILE_IFELSE([],[
831 PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT])
833 LIBS="pac_conftest.$OBJEXT $saved_LIBS"
834 AC_LANG_PUSH([Fortran 77])
836 AC_MSG_RESULT([Use Fortran to link programs])
839 AC_LANG_POP([Fortran 77])
841 rm -f pac_conftest.$OBJEXT
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])
852 LIBS="pac_f77conftest.$OBJEXT $FLIBS $saved_LIBS"
856 AC_MSG_RESULT([Use C with FLIBS to link programs])
858 F77_LDFLAGS="$F77_LDFLAGS $FLIBS"
862 rm -f pac_f77conftest.$OBJEXT
864 AC_LANG_POP([Fortran 77])
867 AC_LANG_PUSH([Fortran 77])
868 rm -f conftest.$ac_ext
869 AC_LANG_POP([Fortran 77])
872 rm -f conftest.$ac_ext
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])
887 # Create a simple C program for the tests.
889 AC_LANG_PROGRAM([],[int a;])
891 # Try to link a C program with all of these libraries
893 LIBS="$FLIBS $saved_LIBS"
898 AC_MSG_CHECKING([for which libraries can be used])
902 for name in $FLIBS ; do
904 -l*) pac_libs="$pac_libs $name" ;;
905 -L*) pac_ldirs="$pac_ldirs $name" ;;
906 *) pac_other="$pac_other $name" ;;
910 for name in $pac_libs ; do
911 LIBS="$saved_LIBS $pac_ldirs $pac_other $name"
913 keep_libs="$keep_libs $name"
916 AC_MSG_RESULT($keep_libs)
917 FLIBS="$pac_ldirs $pac_other $keep_libs"
920 rm -f conftest.$ac_ext
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
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 ;;
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
951 #if defined(HAVE_STDIO_H) || defined(STDC_HEADERS)
954 int $confname(int a) {
955 printf( "The answer is %d\n", a ); fflush(stdout); return 0;
959 PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT])
961 AC_LANG_PUSH([Fortran 77])
969 for extralib in "" "-lSystemStubs" ; do
970 LIBS="pac_conftest.$OBJEXT $saved_LIBS $extralib"
972 pac_cv_prog_f77_and_c_stdio_libs="$extralib"; break
975 if test "X$pac_cv_prog_f77_and_c_stdio_libs" = "X" ; then
976 pac_cv_prog_f77_and_c_stdio_libs=none
978 rm -f conftest.$ac_ext
979 AC_LANG_POP([Fortran 77])
981 rm -f pac_conftest.$OBJEXT
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"
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])
1010 AC_MSG_RESULT([yes])
1013 AC_MSG_CHECKING([for valid entries in FLIBS])
1017 for arg in $saveFLIBS ; do
1018 FLIBS="$goodFLIBS $arg"
1019 AC_LINK_IFELSE([],[goodFLIBS=$FLIBS])
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
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])
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; }
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; }
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; }
1066 AC_LANG_PUSH([Fortran 77])
1073 write(6,*) "rc=", rc
1077 AC_LANG_POP([Fortran 77])
1079 dnl Initialize flags
1083 dnl Use F77 as a linker to compile a Fortran main and C subprogram.
1084 if test "$pac_linkwithC" != "yes" ; then
1086 AC_COMPILE_IFELSE([],[
1087 PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT])
1089 LIBS="pac_conftest.$OBJEXT $saved_LIBS"
1090 AC_LANG_PUSH([Fortran 77])
1093 AC_MSG_RESULT([yes])
1095 AC_LANG_POP([Fortran 77])
1097 if test "$pac_linkwithf77" = "yes" ; then
1098 rm -f pac_conftest.$OBJEXT
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])
1110 LIBS="pac_f77conftest.$OBJEXT $FLIBS $saved_LIBS"
1114 AC_MSG_RESULT([yes])
1118 if test "$pac_linkwithC" = "yes" ; then
1119 rm -f pac_f77conftest.$OBJEXT
1122 AC_LANG_POP([Fortran 77])
1125 AC_LANG_PUSH([Fortran 77])
1126 rm -f conftest.$ac_ext
1127 AC_LANG_POP([Fortran 77])
1130 rm -f conftest.$ac_ext
1133 if test "$pac_linkwithf77" != "yes" -a "$pac_linkwithC" != "yes" ; then
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}.])
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
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}
1165 saved_FFLAGS="$FFLAGS"
1166 FFLAGS="$FFLAGS $CPPFLAGS"
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"])
1193 rm -f conftest.${ac_ext}
1197 FFLAGS="$saved_FFLAGS"
1199 AC_LANG_POP([Fortran 77])
1200 AC_MSG_RESULT([$pac_cv_f77_accepts_F])
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.
1212 dnl PAC_PROG_F77_CRAY_POINTER([action-if-true],[action-if-false])
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])
1219 AC_LANG_PROGRAM([],[
1225 saved_FFLAGS="$FFLAGS"
1226 pac_cv_prog_f77_has_pointer=no
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"
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])
1247 AC_MSG_RESULT([none])
1249 ifelse([$1],[],[:],[$1])
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])
1267 character*1 vc(1,1), vc2(1)
1271 call minitc( vc, vc2, vd )
1275 PAC_RUNLOG([mv conftest.$OBJEXT pac_f77conftest.$OBJEXT])
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"
1284 #if defined(HAVE_STDIO_H) || defined(STDC_HEADERS)
1287 #ifdef F77_NAME_UPPER
1288 #define minit_ MINIT
1289 #elif defined(F77_NAME_LOWER) || defined(F77_NAME_MIXED)
1290 #define minit_ minit
1292 extern void minit_(void);
1293 int main( int argc, char **argv )
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 )
1310 ],[pac_f_init_works_with_c=yes],[pac_f_init_works_with_c=no])
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])
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=""
1345 #if defined(HAVE_STDIO_H) || defined(STDC_HEADERS)
1348 #if defined(HAVE_STDLIB_H) || defined(STDC_HEADERS)
1351 #ifdef F77_NAME_UPPER
1352 #define ftest_ FTEST
1353 #elif defined(F77_NAME_LOWER) || defined(F77_NAME_MIXED)
1354 #define ftest_ ftest
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");
1361 fprintf( f, "%d %d\n", *itrue, *ifalse );
1366 PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT])
1368 LIBS="pac_conftest.$OBJEXT $saved_LIBS"
1369 AC_LANG_PUSH([Fortran 77])
1373 logical itrue, ifalse
1376 call ftest( itrue, ifalse )
1380 pac_cv_prog_f77_true_false_value="`cat conftestval`"
1382 AC_MSG_WARN([Failed to build/run program to determine Fortran logical values.])
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"
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.])
1391 AC_LANG_POP([Fortran 77])
1393 rm -f pac_conftest.$OBJEXT
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])
1404 AC_MSG_RESULT([could not determine])
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])