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