1dnl PAC_FC_SEARCH_LIST - expands to a whitespace separated list of modern 2dnl fortran compilers for use with AC_PROG_FC that is more suitable for HPC 3dnl software packages 4AC_DEFUN([PAC_FC_SEARCH_LIST], 5 [ifort pgf90 pathf90 pathf95 xlf90 xlf95 xlf2003 gfortran f90 epcf90 f95 fort lf95 g95 ifc efc gfc]) 6dnl /*D 7dnl PAC_PROG_FC([COMPILERS]) 8dnl 9dnl COMPILERS is a space separated list of Fortran 77 compilers to search 10dnl for. Fortran 95 isn't strictly backwards-compatible with Fortran 77, 11dnl but `f95' is worth trying. 12dnl 13dnl Compilers are ordered by 14dnl 1. F77, F90, F95 15dnl 2. Good/tested native compilers, bad/untested native compilers 16dnl 3. Wrappers around f2c go last. 17dnl 18dnl `fort77' is a wrapper around `f2c'. 19dnl It is believed that under HP-UX `fort77' is the name of the native 20dnl compiler. On some Cray systems, fort77 is a native compiler. 21dnl frt is the Fujitsu F77 compiler. 22dnl pgf77 and pgf90 are the Portland Group F77 and F90 compilers. 23dnl xlf/xlf90/xlf95/xlf2003 are IBM (AIX) F77/F90/F95/F2003 compilers. 24dnl lf95 is the Lahey-Fujitsu compiler. 25dnl fl32 is the Microsoft Fortran "PowerStation" compiler. 26dnl af77 is the Apogee F77 compiler for Intergraph hardware running CLIX. 27dnl epcf90 is the "Edinburgh Portable Compiler" F90. 28dnl fort is the Compaq Fortran 90 (now 95) compiler for Tru64 and Linux/Alpha. 29dnl pathf90 is the Pathscale Fortran 90 compiler 30dnl ifort is another name for the Intel f90 compiler 31dnl efc - An older Intel compiler (?) 32dnl ifc - An older Intel compiler 33dnl fc - A compiler on some unknown system. This has been removed because 34dnl it may also be the name of a command for something other than 35dnl the Fortran compiler (e.g., fc=file system check!) 36dnl gfortran - The GNU Fortran compiler (not the same as g95) 37dnl gfc - An alias for gfortran recommended in cygwin installations 38dnl D*/ 39dnl NOTE: this macro suffers from a basically intractable "expanded before it 40dnl was required" problem when libtool is also used 41AC_DEFUN([PAC_PROG_FC],[ 42PAC_PUSH_FLAG([FCFLAGS]) 43AC_PROG_FC([m4_default([$1],[PAC_FC_SEARCH_LIST])]) 44PAC_POP_FLAG([FCFLAGS]) 45]) 46dnl 47dnl PAC_FC_EXT checks for the default Fortran 90 program extension, f90 then f. 48dnl This could be replaced by AC_FC_SRCEXT but since AC_FC_SRCEXT 49dnl adds FCFLAGS_ext, which is used to modify FCFLAGS or Makefile.in. 50dnl So will do this later. 51dnl 52AC_DEFUN([PAC_FC_EXT],[ 53AC_MSG_CHECKING([for extension for Fortran 90 programs]) 54ac_fc_srcext="f90" 55AC_LANG_PUSH(Fortran) 56AC_COMPILE_IFELSE([ 57 AC_LANG_PROGRAM() 58],[ 59 AC_MSG_RESULT([f90]) 60],[ 61 ac_fc_srcext="f" 62 AC_COMPILE_IFELSE([ 63 AC_LANG_PROGRAM() 64 ],[ 65 AC_MSG_RESULT([f]) 66 ],[ 67 AC_MSG_RESULT([unknown!]) 68 ]) 69]) 70AC_LANG_POP(Fortran) 71]) 72dnl 73dnl Internal routine for testing F90 74dnl PAC_PROG_FC_WORKS() 75dnl 76AC_DEFUN([PAC_PROG_FC_WORKS],[ 77AC_REQUIRE([PAC_FC_EXT]) 78AC_LANG_PUSH(Fortran) 79AC_MSG_CHECKING([whether the Fortran 90 compiler ($FC $FCFLAGS $LDFLAGS) works]) 80AC_LINK_IFELSE([ 81 AC_LANG_SOURCE([ 82 program conftest 83 integer, dimension(10) :: n 84 end 85 ]) 86],[ 87 pac_cv_prog_fc_works="yes" 88 AC_MSG_RESULT([$pac_cv_prog_fc_works]) 89 AC_MSG_CHECKING([whether the Fortran 90 compiler ($FC $FCFLAGS $LDFLAGS) is a cross-compiler]) 90 AC_RUN_IFELSE([], 91 [pac_cv_prog_fc_cross="no"], 92 [pac_cv_prog_fc_cross="yes"], 93 [pac_cv_prog_fc_cross="$cross_compiling"] 94 ) 95 AC_MSG_RESULT($pac_cv_prog_fc_cross) 96],[ 97 pac_cv_prog_fc_works="no" 98 AC_MSG_WARN([installation or configuration problem: Fortran 90 compiler cannot create executables.]) 99]) 100# The intel compiler sometimes generates these work.pc and .pcl files 101rm -f work.pc work.pcl 102AC_LANG_POP(Fortran) 103dnl cross_compiling no longer maintained by autoconf as part of the 104dnl AC_LANG changes. If we set it here, a later AC_LANG may not 105dnl restore it (in the case where one compiler claims to be a cross compiler 106dnl and another does not) 107dnl cross_compiling=$pac_cv_prog_f90_cross 108]) 109dnl/*D 110dnl PAC_PROG_FC_INT_KIND - Determine kind parameter for an integer with 111dnl the specified number of bytes. 112dnl 113dnl Synopsis: 114dnl PAC_PROG_FC_INT_KIND(variable-to-set,number-of-bytes,[cross-size]) 115dnl 116dnl D*/ 117AC_DEFUN([PAC_PROG_FC_INT_KIND],[ 118# Set the default 119$1=-1 120if test "$pac_cv_prog_fc_cross" = "yes" ; then 121 AS_IF([test -z "$3"],[AC_MSG_ERROR(['$3' is empty])]) 122 $1="$3" 123else 124 AC_LANG_PUSH(Fortran) 125 AC_MSG_CHECKING([for Fortran 90 integer kind for $2-byte integers]) 126 # Convert bytes to digits 127 case $2 in 128 1) sellen=2 ;; 129 2) sellen=4 ;; 130 4) sellen=8 ;; 131 8) sellen=16 ;; 132 16) sellen=30 ;; 133 *) sellen=8 ;; 134 esac 135 # Check for cached value 136 eval testval=\$"pac_cv_prog_fc_int_kind_$sellen" 137 if test -n "$testval" ; then 138 AC_MSG_RESULT([$testval (cached)]) 139 $1=$testval 140 else 141 KINDVAL="unavailable" 142 eval "pac_cv_prog_fc_int_kind_$sellen"=-1 143 AC_RUN_IFELSE([ 144 AC_LANG_SOURCE([ 145 program main 146 integer ii 147 ii = selected_int_kind($sellen) 148 open(8, file="conftest1.out", form="formatted") 149 write (8,*) ii 150 close(8) 151 stop 152 end 153 ]) 154 ],[pac_run_ok=yes],[pac_run_ok=no]) 155 if test "$pac_run_ok" = "yes" ; then 156 if test -s conftest1.out ; then 157 # Because of write, there may be a leading blank. 158 KINDVAL=`cat conftest1.out | sed 's/ //g'` 159 eval "pac_cv_prog_fc_int_kind_$sellen"=$KINDVAL 160 $1=$KINDVAL 161 fi 162 fi 163 AC_MSG_RESULT([$KINDVAL]) 164 fi # not cached 165 AC_LANG_POP(Fortran) 166fi # is not cross compiling 167])dnl 168dnl 169dnl ------------------------------------------------------------------------ 170dnl Special characteristics that have no autoconf counterpart but that 171dnl we need as part of the Fortran 90 support. To distinquish these, they 172dnl have a [PAC] prefix. 173dnl 174dnl 175dnl PAC_FC_MODULE_EXT(action if found,action if not found) 176dnl 177AC_DEFUN([PAC_FC_MODULE_EXT], 178[AC_CACHE_CHECK([for Fortran 90 module extension], 179pac_cv_fc_module_ext,[ 180pac_cv_fc_module_case="unknown" 181AC_LANG_PUSH(Fortran) 182AC_COMPILE_IFELSE([ 183 AC_LANG_SOURCE([ 184 module conftest 185 integer n 186 parameter (n=1) 187 end module conftest 188 ]) 189],[ 190 dnl Look for module name 191 dnl First, try to find known names. This avoids confusion caused by 192 dnl additional files (like <name>.stb created by some versions of pgf90) 193 dnl Early versions of the Intel compiler used "d" as the module extension; 194 dnl we include that just to finish the test as early as possible. 195 for name in conftest CONFTEST ; do 196 for ext in mod MOD d ; do 197 if test -s $name.$ext ; then 198 if test $name = conftest ; then 199 pac_cv_fc_module_case=lower 200 else 201 pac_cv_fc_module_case=upper 202 fi 203 pac_cv_fc_module_ext=$ext 204 pac_MOD=$ext 205 break 206 fi 207 done 208 if test -n "$pac_cv_fc_module_ext" ; then break ; fi 209 done 210 if test -z "$pac_MOD" ; then 211 pac_MOD=`ls conftest.* 2>&1 | grep -v conftest.${ac_fc_srcext} | grep -v conftest.o` 212 pac_MOD=`echo $pac_MOD | sed -e 's/conftest\.//g'` 213 pac_cv_fc_module_case="lower" 214 if test "X$pac_MOD" = "X" ; then 215 pac_MOD=`ls CONFTEST* 2>&1 | grep -v CONFTEST.f | grep -v CONFTEST.o` 216 pac_MOD=`echo $pac_MOD | sed -e 's/CONFTEST\.//g'` 217 if test -n "$pac_MOD" -a -s "CONFTEST.$pac_MOD" ; then 218 testname="CONFTEST" 219 pac_cv_fc_module_case="upper" 220 else 221 # Clear because we must have gotten an error message 222 pac_MOD="" 223 fi 224 fi 225 if test -z "$pac_MOD" ; then 226 pac_cv_fc_module_ext="unknown" 227 else 228 pac_cv_fc_module_ext=$pac_MOD 229 fi 230 fi 231],[ 232 pac_cv_fc_module_ext="unknown" 233]) 234AC_LANG_POP(Fortran) 235]) 236dnl 237dnl 238dnl 239AC_SUBST(FCMODEXT) 240if test "$pac_cv_fc_module_ext" = "unknown" ; then 241 ifelse($2,,:,[$2]) 242else 243 ifelse($1,,FCMODEXT=$pac_MOD,[$1]) 244fi 245]) 246dnl 247dnl 248dnl PAC_FC_MODULE_INCFLAG 249AC_DEFUN([PAC_FC_MODULE_INCFLAG],[ 250AC_REQUIRE([PAC_FC_MODULE_EXT]) 251AC_CACHE_CHECK([for Fortran 90 module include flag], 252pac_cv_fc_module_incflag,[ 253AC_LANG_PUSH(Fortran) 254AC_LANG_CONFTEST([ 255 AC_LANG_SOURCE([ 256 module conf 257 integer n 258 parameter (n=1) 259 end module conf 260 ]) 261]) 262pac_madedir="no" 263if test ! -d conf ; then mkdir conftestdir ; pac_madedir="yes"; fi 264if test "$pac_cv_fc_module_case" = "upper" ; then 265 pac_module="CONF.$pac_cv_fc_module_ext" 266else 267 pac_module="conf.$pac_cv_fc_module_ext" 268fi 269AC_COMPILE_IFELSE([],[ 270 if test -s "$pac_module" ; then 271 mv $pac_module conftestdir 272 # Remove any temporary files, and hide the work.pc file 273 # (if the compiler generates them) 274 if test -f work.pc ; then 275 mv -f work.pc conftest.pc 276 fi 277 rm -f work.pcl 278 else 279 AC_MSG_WARN([Unable to build a simple Fortran 90 module]) 280 # echo "configure: failed program was:" >&AS_MESSAGE_LOG_FD 281 # cat conftest.$ac_ext >&AS_MESSAGE_LOG_FD 282 _AC_MSG_LOG_CONFTEST 283 fi 284],[]) 285# Remove the conftest* after AC_LANG_CONFTEST 286rm -rf conftest.dSYM 287rm -f conftest.$ac_ext 288 289dnl Create the conftest here so the test isn't created everytime inside loop. 290AC_LANG_CONFTEST([AC_LANG_PROGRAM([],[use conf])]) 291 292# Save the original FCFLAGS 293saved_FCFLAGS="$FCFLAGS" 294pac_cv_fc_module_incflag="" 295for inchdr in '-I' '-M' '-p' ; do 296 FCFLAGS="$saved_FCFLAGS ${inchdr}conftestdir" 297 AC_COMPILE_IFELSE([],[pac_cv_fc_module_incflag="$inchdr" ; break]) 298done 299if test "X$pac_cv_fc_module_incflag" = "X" ; then 300 if test -s conftest.pc ; then 301 mv conftest.pc conftestdir/mpimod.pc 302 echo "mpimod.pc" > conftestdir/mpimod.pcl 303 echo "`pwd`/conftestdir/mpimod.pc" >> conftestdir/mpimod.pcl 304 inchdr='-cl,' 305 FCFLAGS="$save_FCFLAGS ${inchdr}conftestdir" 306 AC_COMPILE_IFELSE([], [pac_fcompile_ok=yes], [pac_fcompile_ok=no]) 307 if test "$pac_fcompile_ok" = "yes" ; then 308 pac_cv_fc_module_incflag="$inchdr" 309 # Not quite right; see the comments that follow 310 AC_MSG_RESULT([-cl,filename where filename contains a list of files and directories]) 311 FC_WORK_FILES_ARG="-cl,mpimod.pcl" 312 FCMODINCSPEC="-cl,<dir>/<file>mod.pcl" 313 else 314 # The version of the Intel compiler that I have refuses to let 315 # you put the "work catalog" list anywhere but the current directory. 316 pac_cv_fc_module_incflag="Unavailable!" 317 fi 318 else 319 # Early versions of the Intel ifc compiler required a *file* 320 # containing the names of files that contained the names of the 321 # 322 # -cl,filename.pcl 323 # filename.pcl contains 324 # fullpathname.pc 325 # The "fullpathname.pc" is generated, I believe, when a module is 326 # compiled. 327 # Intel compilers use a wierd system: -cl,filename.pcl . If no file is 328 # specified, work.pcl and work.pc are created. However, if you specify 329 # a file, it must contain a the name of a file ending in .pc . Ugh! 330 pac_cv_fc_module_incflag="unknown" 331 fi 332fi 333# Restore the original FCFLAGS 334FCFLAGS="$saved_FCFLAGS" 335if test "$pac_madedir" = "yes" ; then rm -rf conftestdir ; fi 336# Remove the conftest* after AC_LANG_CONFTEST 337# This is needed for Mac OSX 10.5 338rm -rf conftest.dSYM 339rm -f conftest* 340AC_LANG_POP(Fortran) 341]) 342AC_SUBST(FC_WORK_FILES_ARG) 343AC_SUBST(FCMODINCFLAG) 344FCMODINCFLAG=$pac_cv_fc_module_incflag 345]) 346dnl 347dnl 348dnl 349AC_DEFUN([PAC_FC_MODULE],[ 350PAC_FC_MODULE_EXT 351PAC_FC_MODULE_INCFLAG 352PAC_FC_MODULE_OUTFLAG 353]) 354dnl 355dnl PAC_FC_MODULE_OUTFLAG 356AC_DEFUN([PAC_FC_MODULE_OUTFLAG],[ 357AC_REQUIRE([PAC_FC_MODULE_EXT]) 358AC_CACHE_CHECK([for Fortran 90 module output directory flag], 359 [pac_cv_fc_module_outflag], 360[ 361AC_LANG_PUSH([Fortran]) 362AC_LANG_CONFTEST([ 363 AC_LANG_SOURCE([ 364 module conf 365 integer n 366 parameter (n=1) 367 end module conf 368 ]) 369]) 370pac_madedir="no" 371if test ! -d conf ; then mkdir conftestdir ; pac_madedir="yes"; fi 372if test "$pac_cv_fc_module_case" = "upper" ; then 373 pac_module="CONF.$pac_cv_fc_module_ext" 374else 375 pac_module="conf.$pac_cv_fc_module_ext" 376fi 377 378# check base case that the compiler can create modules and that they endup in 379# the current directory 380AC_COMPILE_IFELSE([],[ 381 if test -s "$pac_module" ; then 382 rm -f "$pac_module" 383 # Remove any temporary files, and hide the work.pc file 384 # (if the compiler generates them) 385 if test -f work.pc ; then 386 mv -f work.pc conftest.pc 387 fi 388 rm -f work.pcl 389 else 390 AC_MSG_WARN([Unable to build a simple Fortran 90 module]) 391 # echo "configure: failed program was:" >&AS_MESSAGE_LOG_FD 392 # cat conftest.$ac_ext >&AS_MESSAGE_LOG_FD 393 _AC_MSG_LOG_CONFTEST 394 fi 395],[]) 396 397# known flags for reasonably recent versions of various f90 compilers: 398# gfortran -J${dir} 399# xlf -qmoddir=${dir} 400# pgf90 -module ${dir} 401# ifort -module ${dir} 402# nagfor -mdir ${dir} 403# ftn -J ${dir} ## the Cray fortran compiler 404# f95 -YMOD_OUT_DIR=${dir} ## the Absoft fortran compiler 405# lf95 -Am -mod ${dir} ## the Lahey/Fujitsu fortran compiler 406# f90 -moddir=${dir} ## the Sun f90 compiler 407# 408# If there are any compilers still out there that are totally brain-dead and 409# don't support an output directory flag, we can write a wrapper script to tell 410# users to use. Alternatively they can use an older version of MPICH2. 411 412pac_cv_fc_module_outflag= 413for mod_flag in '-J' '-J ' '-qmoddir=' '-module ' '-YMOD_OUT_DIR=' '-mdir ' '-moddir=' ; do 414 rm -f conftestdir/NONEXISTENT conftestdir/* 415 PAC_PUSH_FLAG([FCFLAGS]) 416 FCFLAGS="$FCFLAGS ${mod_flag}conftestdir" 417 AC_COMPILE_IFELSE([],[pac_build_success=yes],[pac_build_success=no]) 418 AS_IF([test "X$pac_build_success" = Xyes], 419 [AS_IF([test -s "conftestdir/${pac_module}"], 420 [pac_cv_fc_module_outflag="$mod_flag"])]) 421 PAC_POP_FLAG([FCFLAGS]) 422 AS_IF([test "X$pac_cv_fc_module_outflag" = X],[:],[break]) 423done 424 425# Remove the conftest* after AC_LANG_CONFTEST 426rm -rf conftest.dSYM 427rm -f conftest.$ac_ext 428 429if test "$pac_madedir" = "yes" ; then rm -rf conftestdir ; fi 430AS_UNSET([pac_madedir]) 431# Remove the conftest* after AC_LANG_CONFTEST 432# This is needed for Mac OSX 10.5 433rm -rf conftest.dSYM 434rm -f conftest* 435AC_LANG_POP(Fortran) 436])dnl end AC_CACHE_CHECK 437 438AC_SUBST([FCMODOUTFLAG],[$pac_cv_fc_module_outflag]) 439])dnl end AC_DEFUN([PAC_FC_MODULE_OUTFLAG]) 440dnl 441dnl PAC_FC_AND_F77_COMPATIBLE([action-if-true],[action-if-false]) 442dnl 443dnl Determine whether object files compiled with Fortran 77 can be 444dnl linked to Fortran 90 main programs. 445dnl 446dnl The test uses a name that includes an underscore unless the 3rd 447dnl argument provides another routine name. 448dnl 449AC_DEFUN([PAC_FC_AND_F77_COMPATIBLE],[ 450AC_REQUIRE([PAC_PROG_FC_WORKS]) 451AC_CACHE_CHECK([whether Fortran 90 compiler works with Fortran 77 compiler], 452pac_cv_fc_and_f77,[ 453pacTestRoutine=foo_abc 454ifelse([$3],,,[eval pacTestRoutine=$3]) 455pac_cv_fc_and_f77="unknown" 456# compile the f77 program and link with the f90 program 457# The reverse may not work because the Fortran 90 environment may 458# expect to be in control (and to provide library files unknown to any other 459# environment, even Fortran 77!) 460AC_LANG_PUSH(Fortran 77) 461AC_COMPILE_IFELSE([ 462 AC_LANG_SOURCE([ 463 subroutine ${pacTestRoutine}(b) 464 integer b 465 b = b + 1 466 end 467 ]) 468],[ 469 # pac_f77compile_ok=yes 470 PAC_RUNLOG([mv conftest.$OBJEXT pac_f77conftest.$OBJEXT]) 471 # Save original LIBS, prepend previously generated object file to LIBS 472 saved_LIBS="$LIBS" 473 LIBS="pac_f77conftest.$OBJEXT $LIBS" 474 AC_LANG_PUSH(Fortran) 475 AC_LINK_IFELSE([ 476 AC_LANG_SOURCE([ 477 program main 478 integer a 479 a = 1 480 call ${pacTestRoutine}(a) 481 end 482 ]) 483 ],[pac_cv_fc_and_f77=yes],[pac_cv_fc_and_f77=no]) 484 # Some versions of the Intel compiler produce these two files 485 rm -f work.pc work.pcl 486 # Restore LIBS 487 LIBS="$saved_LIBS" 488 AC_LANG_POP(Fortran) 489 # remove previously generated object file. 490 rm -f pac_f77conftest.$OBJEXT 491], [ 492 # pac_f77compile_ok=no 493 pac_cv_fc_and_f77=no 494]) 495AC_LANG_POP(Fortran 77) 496# Perform the requested action based on whether the test succeeded 497if test "$pac_cv_fc_and_f77" = yes ; then 498 ifelse($1,,:,[$1]) 499else 500 ifelse($2,,:,[$2]) 501 AC_MSG_WARN([See config.log for the failed test program and its output.]) 502fi 503]) 504dnl 505]) 506dnl 507dnl 508dnl /*D 509dnl PAC_PROG_FC_CRAY_POINTER - Check if Fortran supports Cray-style pointer. 510dnl If so, set pac_cv_prog_fc_has_pointer to yes 511dnl and find out if any extra compiler flag is 512dnl needed and set it as CRAYPTR_FCFLAGS. 513dnl i.e. CRAYPTR_FCFLAGS is meaningful only if 514dnl pac_cv_prog_fc_has_pointer = yes. 515dnl 516dnl Synopsis: 517dnl PAC_PROG_FC_CRAY_POINTER([action-if-true],[action-if-false]) 518dnl D*/ 519AC_DEFUN([PAC_PROG_FC_CRAY_POINTER],[ 520AC_CACHE_CHECK([whether Fortran 90 supports Cray-style pointer], 521pac_cv_prog_fc_has_pointer,[ 522AC_LANG_PUSH([Fortran]) 523AC_LANG_CONFTEST([ 524 AC_LANG_PROGRAM([],[ 525 integer M 526 pointer (MPTR,M) 527 data MPTR/0/ 528 ]) 529]) 530saved_FCFLAGS="$FCFLAGS" 531pac_cv_prog_fc_has_pointer=no 532CRAYPTR_FCFLAGS="" 533for ptrflag in '' '-fcray-pointer' ; do 534 FCFLAGS="$saved_FCFLAGS $ptrflag" 535 AC_COMPILE_IFELSE([],[ 536 pac_cv_prog_fc_has_pointer=yes 537 CRAYPTR_FCFLAGS="$ptrflag" 538 break 539 ]) 540done 541dnl Restore FCFLAGS first, since user may not want to modify FCFLAGS 542FCFLAGS="$saved_FCFLAGS" 543dnl remove conftest after ac_lang_conftest 544rm -f conftest.$ac_ext 545AC_LANG_POP([Fortran]) 546]) 547if test "$pac_cv_prog_fc_has_pointer" = "yes" ; then 548 AC_MSG_CHECKING([for Fortran 90 compiler flag for Cray-style pointer]) 549 if test "X$CRAYPTR_FCFLAGS" != "X" ; then 550 AC_MSG_RESULT([$CRAYPTR_FCFLAGS]) 551 else 552 AC_MSG_RESULT([none]) 553 fi 554 ifelse([$1],[],[:],[$1]) 555else 556 ifelse([$2],[],[:],[$2]) 557fi 558]) 559dnl 560dnl 561dnl 562AC_DEFUN([PAC_PROG_FC_AND_C_STDIO_LIBS],[ 563AC_REQUIRE([AC_HEADER_STDC]) 564# To simply the code in the cache_check macro, chose the routine name 565# first, in case we need it 566confname=conf1_ 567case "$pac_cv_prog_f77_name_mangle" in 568 "lower underscore") confname=conf1_ ;; 569 "upper stdcall") confname=CONF1 ;; 570 upper) confname=CONF1 ;; 571 "lower doubleunderscore") confname=conf1_ ;; 572 lower) confname=conf1 ;; 573 "mixed underscore") confname=conf1_ ;; 574 mixed) confname=conf1 ;; 575esac 576 577AC_CACHE_CHECK([what libraries are needed to link Fortran90 programs with C routines that use stdio],pac_cv_prog_fc_and_c_stdio_libs,[ 578pac_cv_prog_fc_and_c_stdio_libs=unknown 579 580AC_LANG_PUSH(C) 581AC_COMPILE_IFELSE([ 582 AC_LANG_SOURCE([ 583#if defined(HAVE_STDIO_H) || defined(STDC_HEADERS) 584#include <stdio.h> 585#endif 586int $confname( int a ) 587{ printf( "The answer is %d\n", a ); fflush(stdout); return 0; } 588 ]) 589],[ 590 pac_compile_ok=yes 591 PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT]) 592 # Save LIBS and prepend object file to LIBS 593 saved_LIBS="$LIBS" 594 LIBS="pac_conftest.$OBJEXT $LIBS" 595 AC_LANG_PUSH(Fortran) 596 AC_LINK_IFELSE([ 597 AC_LANG_PROGRAM([],[call conf1(0)]) 598 ],[ 599 pac_cv_prog_fc_and_c_stdio_libs=none 600 ],[ 601 # Try again with -lSystemStubs 602 LIBS="$LIBS -lSystemStubs" 603 AC_LINK_IFELSE([],[ 604 pac_cv_prog_fc_and_c_stdio_libs="-lSystemStubs" 605 ],[]) 606 ]) 607 LIBS="$saved_LIBS" 608 AC_LANG_POP(Fortran) 609 rm -f pac_conftest.$OBJEXT 610]) 611AC_LANG_POP(C) 612dnl 613if test "$pac_cv_prog_fc_and_c_stdio_libs" != none -a \ 614 "$pac_cv_prog_fc_and_c_stdio_libs" != unknown ; then 615 FC_OTHER_LIBS="$FC_OTHER_LIBS $pac_cv_prog_fc_and_c_stdio_libs" 616fi 617]) 618dnl 619]) 620dnl 621dnl/*D 622dnl PAC_FC_CHECK_COMPILER_OPTION - Check that a FC compiler option is 623dnl accepted without warning messages 624dnl 625dnl Synopsis: 626dnl PAC_FC_CHECK_COMPILER_OPTION(optionname,action-if-ok,action-if-fail) 627dnl 628dnl Output Effects: 629dnl 630dnl If no actions are specified, a working value is added to 'FCOPTIONS' 631dnl 632dnl Notes: 633dnl This is now careful to check that the output is different, since 634dnl some compilers are noisy. 635dnl 636dnl We are extra careful to prototype the functions in case compiler options 637dnl that complain about poor code are in effect. 638dnl 639dnl Because this is a long script, we have ensured that you can pass a 640dnl variable containing the option name as the first argument. 641dnl D*/ 642AC_DEFUN([PAC_FC_CHECK_COMPILER_OPTION],[ 643AC_MSG_CHECKING([whether Fortran 90 compiler accepts option $1]) 644pac_opt="$1" 645AC_LANG_PUSH(Fortran) 646FCFLAGS_orig="$FCFLAGS" 647FCFLAGS_opt="$pac_opt $FCFLAGS" 648pac_result="unknown" 649 650AC_LANG_CONFTEST([AC_LANG_PROGRAM()]) 651FCFLAGS="$FCFLAGS_orig" 652rm -f pac_test1.log 653PAC_LINK_IFELSE_LOG([pac_test1.log], [], [ 654 FCFLAGS="$FCFLAGS_opt" 655 rm -f pac_test2.log 656 PAC_LINK_IFELSE_LOG([pac_test2.log], [], [ 657 PAC_RUNLOG_IFELSE([diff -b pac_test1.log pac_test2.log], 658 [pac_result=yes], [pac_result=no]) 659 ],[ 660 pac_result=no 661 ]) 662], [ 663 pac_result=no 664]) 665AC_MSG_RESULT([$pac_result]) 666dnl Delete the conftest created by AC_LANG_CONFTEST. 667rm -f conftest.$ac_ext 668# 669if test "$pac_result" = "yes" ; then 670 AC_MSG_CHECKING([whether routines compiled with $pac_opt can be linked with ones compiled without $pac_opt]) 671 pac_result=unknown 672 FCFLAGS="$FCFLAGS_orig" 673 rm -f pac_test3.log 674 PAC_COMPILE_IFELSE_LOG([pac_test3.log], [ 675 AC_LANG_SOURCE([ 676 subroutine try() 677 end 678 ]) 679 ],[ 680 PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT]) 681 saved_LIBS="$LIBS" 682 LIBS="pac_conftest.$OBJEXT $LIBS" 683 684 FCFLAGS="$FCFLAGS_opt" 685 rm -f pac_test4.log 686 PAC_LINK_IFELSE_LOG([pac_test4.log], [AC_LANG_PROGRAM()], [ 687 PAC_RUNLOG_IFELSE([diff -b pac_test2.log pac_test4.log], 688 [pac_result=yes], [pac_result=no]) 689 ],[ 690 pac_result=no 691 ]) 692 LIBS="$saved_LIBS" 693 rm -f pac_conftest.$OBJEXT 694 ],[ 695 pac_result=no 696 ]) 697 AC_MSG_RESULT([$pac_result]) 698 rm -f pac_test3.log pac_test4.log 699fi 700rm -f pac_test1.log pac_test2.log 701 702dnl Restore FCFLAGS before 2nd/3rd argument commands are executed, 703dnl as 2nd/3rd argument command could be modifying FCFLAGS. 704FCFLAGS="$FCFLAGS_orig" 705if test "$pac_result" = "yes" ; then 706 ifelse([$2],[],[FCOPTIONS="$FCOPTIONS $1"],[$2]) 707else 708 ifelse([$3],[],[:],[$3]) 709fi 710AC_LANG_POP(Fortran) 711]) 712dnl /*D 713dnl PAC_FC_WORKS_WITH_CPP 714dnl 715dnl Checks if Fortran 90 compiler works with C preprocessor 716dnl 717dnl Most systems allow the Fortran compiler to process .F and .F90 files 718dnl using the C preprocessor. However, some systems either do not 719dnl allow this or have serious bugs (OSF Fortran compilers have a bug 720dnl that generates an error message from cpp). The following test 721dnl checks to see if .F works, and if not, whether "cpp -P -C" can be used 722dnl D*/ 723AC_DEFUN([PAC_FC_WORKS_WITH_CPP],[ 724AC_REQUIRE([AC_PROG_CPP]) 725AC_MSG_CHECKING([whether Fortran 90 compiler processes .F90 files with C preprocessor]) 726AC_LANG_PUSH([Fortran]) 727saved_fc_ext=${ac_ext} 728ac_ext="F90" 729saved_FCFLAGS="$FCFLAGS" 730FCFLAGS="$FCFLAGS $CPPFLAGS" 731AC_LANG_CONFTEST([ 732 AC_LANG_SOURCE([ 733 program main 734#define ASIZE 10 735 integer a(ASIZE) 736 end 737 ]) 738]) 739AC_COMPILE_IFELSE([],[ 740 pac_cv_fc_accepts_F90=yes 741 ifelse([$1],[],[],[$1=""]) 742],[ 743 pac_cv_fc_accepts_F90=no 744 ifelse([$1],[],[:],[$1="false"]) 745]) 746# Restore Fortran's ac_ext but not FCFLAGS 747ac_ext="$saved_fc_ext" 748 749if test "$pac_cv_fc_accepts_F90" != "yes" ; then 750 pac_cpp_fc="$ac_cpp -C -P conftest.F90 > conftest.$ac_ext" 751 PAC_RUNLOG_IFELSE([$pac_cpp_fc],[ 752 if test -s conftest.${ac_ext} ; then 753 AC_COMPILE_IFELSE([],[ 754 pac_cv_fc_accepts_F90="no, use cpp" 755 ifelse([$1],[],[],[$1="$CPP -C -P"]) 756 ],[]) 757 rm -f conftest.${ac_ext} 758 fi 759 ],[]) 760fi 761FCFLAGS="$saved_FCFLAGS" 762rm -f conftest.F90 763AC_LANG_POP([Fortran]) 764AC_MSG_RESULT([$pac_cv_fc_accepts_F90]) 765]) 766dnl 767dnl PAC_FC_VENDOR: 768dnl Try to get a version string for the F90 compiler. We may 769dnl need this to find likely command-line arguments for accessing 770dnl shared libraries 771dnl 772AC_DEFUN([PAC_FC_VENDOR],[ 773AC_MSG_CHECKING([for Fortran 90 compiler vendor]) 774# This is complicated by some compilers (such as the Intel 8.1 ifort) 775# that return a non-zero status even when they accept the -V option 776# (a zero status is returned only if there is a file). 777pac_cv_fc_vendor="unknown" 778for arg in --version -V -v ; do 779 rm -f conftest.txt 780 PAC_RUNLOG([$FC $arg </dev/null >conftest.txt 2>&1]) 781 # Ignore the return code, because some compilers set the 782 # return code to zero on invalid arguments and some to 783 # non-zero on success (with no files to compile) 784 if test -f conftest.txt ; then 785 if grep 'Portland Group' conftest.txt >/dev/null 2>&1 ; then 786 pac_cv_fc_vendor=pgi 787 elif grep 'Sun Workshop' conftest.txt >/dev/null 2>&1 ; then 788 pac_cv_fc_vendor=sun 789 elif grep 'Sun Fortran 9' conftest.txt >/dev/null 2>&1 ; then 790 pac_cv_fc_vendor=sun 791 elif grep 'Absoft' conftest.txt >/dev/null 2>&1 ; then 792 pac_cv_fc_vendor=absoft 793 elif grep 'G95' conftest.txt >/dev/null 2>&1 ; then 794 pac_cv_fc_vendor=gnu 795 elif grep 'GNU Fortran' conftest.txt >/dev/null 2>&1 ; then 796 # This is gfortran 797 pac_cv_fc_vendor=gnu 798 elif grep Intel conftest.txt >/dev/null 2>&1 ; then 799 pac_cv_fc_vendor=intel 800 fi 801 fi 802 if test "$pac_cv_fc_vendor" != "unknown" ; then break ; fi 803done 804if test "$pac_cv_fc_vendor" = "unknown" ; then 805 # Try to use the compiler name 806 if test "$FC" = "ifort" -o "$FC" = "ifc" ; then 807 pac_cv_fc_vendor=intel 808 elif test "$FC" = "pgf90" ; then 809 pac_cv_fc_vendor=pgi 810 elif test "$FC" = "xlf90" -o "$FC" = "xlf90_r" ; then 811 pac_cv_fc_vendor=ibm 812 elif test "$FC" = "xlf95" -o "$FC" = "xlf95_r" ; then 813 pac_cv_fc_vendor=ibm 814 fi 815fi 816AC_MSG_RESULT([$pac_cv_fc_vendor]) 817rm -f conftest.txt 818# End of checking for F90 compiler vendor 819]) 820dnl 821dnl PAC_F77_IS_FC([ACTION_IF_TRUE],[ACTION_IF_FALSE]) 822dnl Check if F77 is a Fortran 90 compiler. 823dnl 824AC_DEFUN([PAC_F77_IS_FC],[ 825AC_MSG_CHECKING([whether $F77 is a Fortran 90 compiler]) 826AC_LANG_PUSH([Fortran 77]) 827saved_ac_ext=$ac_ext 828ac_ext="f90" 829AC_LINK_IFELSE([ 830 AC_LANG_SOURCE([ 831 program main 832 integer, dimension(10) :: n 833 integer k 834 print *, range(k) 835 end 836 ]) 837],[ 838 pac_cv_prog_f77_is_fc=yes 839 ifelse([$1],[],[],[$1]) 840],[ 841 pac_cv_prog_f77_is_fc=no 842 ifelse([$2],[],[],[$2]) 843]) 844AC_MSG_RESULT([$pac_cv_prog_f77_is_fc]) 845AC_LANG_POP([Fortran 77]) 846]) 847dnl 848dnl PAC_FC_FLOAT_MODEL(float_type, [variable-set-if-successful-test]) 849dnl variable-set-if-successful-test is optional variable. 850dnl 851dnl This is a runtime test. 852dnl 853AC_DEFUN([PAC_FC_FLOAT_MODEL],[ 854type="$1" 855AC_MSG_CHECKING([for precision and range of $type]) 856AC_LANG_PUSH([Fortran]) 857rm -f pac_fconftest.out 858AC_RUN_IFELSE([ 859 AC_LANG_SOURCE([ 860 program main 861 $type aa 862 open(8, file="pac_fconftest.out", form="formatted") 863 write(8,*) precision(aa), ",", range(aa) 864 close(8) 865 end 866 ]) 867],[ 868 if test -s pac_fconftest.out ; then 869 pac_fc_num_model="`sed -e 's/ */ /g' pac_fconftest.out`" 870 AC_MSG_RESULT([$pac_fc_num_model]) 871 ifelse([$2],[],[],[$2=$pac_fc_num_model]) 872 else 873 AC_MSG_RESULT([Error]) 874 AC_MSG_WARN([No output from test program!]) 875 fi 876 rm -f pac_fconftest.out 877],[ 878 AC_MSG_RESULT([Error]) 879 AC_MSG_WARN([Failed to run program to determine the precision and range of $type]) 880]) 881AC_LANG_POP([Fortran]) 882]) 883dnl 884dnl PAC_FC_SIMPLE_NUMBER_MODEL(message, Fortran-type, Fortran-write, 885dnl [variable-set-if-successful-test], 886dnl [cross-value]) 887dnl 888dnl message : message of what test-fc-code is checking 889dnl Fortran-type : Fortran90 type's data model to be examined. 890dnl Fortran-write : Fortran90 type's write statement used with write(N,*). 891dnl variable-set-if-successful-test : 892dnl The optional variable to be set if the codelet: 893dnl "Fortran-type" + "write(N,*) Fortran-write" 894dnl is successful in returning the simple data model. 895dnl cross-value : value to be used for above variable when 896dnl cross_compiling=yes 897dnl 898dnl This is a runtime test. 899dnl 900AC_DEFUN([PAC_FC_SIMPLE_NUMBER_MODEL],[ 901pac_msg="$1" 902AC_MSG_CHECKING([for $pac_msg]) 903AC_LANG_PUSH([Fortran]) 904rm -f pac_fconftest.out 905AC_RUN_IFELSE([ 906 AC_LANG_SOURCE([ 907 program main 908 $2 909 open(8, file="pac_fconftest.out", form="formatted") 910 write(8,*) $3 911 close(8) 912 end 913 ]) 914],[ 915 if test -s pac_fconftest.out ; then 916 pac_fc_num_model="`sed -e 's/ */ /g' pac_fconftest.out`" 917 AC_MSG_RESULT([$pac_fc_num_model]) 918 ifelse([$4],[],[],[$4=$pac_fc_num_model]) 919 else 920 AC_MSG_RESULT([Error]) 921 AC_MSG_WARN([No output from test program!]) 922 fi 923 rm -f pac_fconftest.out 924],[ 925 AC_MSG_RESULT([Error]) 926 AC_MSG_WARN([Failed to run program to determine $pac_msg]) 927],[ 928 AC_MSG_RESULT([$5]) 929 ifelse([$4],[],[],[$4=$5]) 930]) 931AC_LANG_POP([Fortran]) 932]) 933dnl 934dnl PAC_FC_AVAIL_INTEGER_MODELS([INTEGER-MODELS-FLAG],[CROSS-VARIABLE]) 935dnl 936dnl INTEGER-MODELS-FLAG : an optional variable to be set if provided. 937dnl If it isn't provided, PAC_FC_ALL_INTEGER_MODELS 938dnl will be set. 939dnl CROSS-VALUE : value will be used to set INTEGER-MODELS-FLAG 940dnl or PAC_FC_ALL_INTEGER_MODELS if cross_compiling=yes. 941dnl 942dnl This is a runtime test. 943dnl 944AC_DEFUN([PAC_FC_AVAIL_INTEGER_MODELS],[ 945AC_MSG_CHECKING([for available integer kinds]) 946AC_LANG_PUSH([Fortran]) 947rm -f pac_fconftest.out 948AC_RUN_IFELSE([ 949 AC_LANG_SOURCE([ 950 program main 951 integer r, lastkind 952 lastkind=selected_int_kind(1) 953 open(8, file="pac_fconftest.out", form="formatted") 954 do r=2,30 955 k = selected_int_kind(r) 956 if (k .ne. lastkind) then 957 write(8,*) r-1, ",", lastkind 958 lastkind = k 959 endif 960 if (k .le. 0) then 961 exit 962 endif 963 enddo 964 if (k.ne.lastkind) then 965 write(8,*) 31, ",", k 966 endif 967 close(8) 968 end 969 ]) 970],[ 971 if test -s pac_fconftest.out ; then 972 pac_flag="`sed -e 's/ */ /g' pac_fconftest.out | tr '\012' ','`" 973 AC_MSG_RESULT([$pac_flag]) 974 pac_validKinds="`sed -e 's/ */ /g' pac_fconftest.out | tr '\012' ':'`" 975 ifelse([$1],[],[PAC_FC_ALL_INTEGER_MODELS=$pac_flag],[$1=$pac_flag]) 976 else 977 AC_MSG_RESULT([Error]) 978 AC_MSG_WARN([No output from test program!]) 979 fi 980 rm -f pac_fconftest.out 981],[ 982 AC_MSG_RESULT([Error]) 983 AC_MSG_WARN([Failed to run program to determine available integer models]) 984],[ 985 dnl Even when cross_compiling=yes, 986 dnl pac_validKinds needs to be set for PAC_FC_INTEGER_MODEL_MAP() 987 pac_validKinds="`echo \"$2\" | tr ',' ':'`" 988 AC_MSG_RESULT([$2]) 989 ifelse([$1],[],[PAC_FC_ALL_INTEGER_MODELS=$2],[$1=$2]) 990]) 991AC_LANG_POP([Fortran]) 992]) 993dnl 994dnl PAC_FC_INTEGER_MODEL_MAP([INTEGER-MODEL-MAP-FLAG],[CROSS-VALUE])) 995dnl 996dnl INTEGER-MODEL-MAP-FLAG : an optional variable to be set if provided. 997dnl If it isn't provided, PAC_FC_INTEGER_MODEL_MAP 998dnl will be set. 999dnl CROSS-VALUE : value will be used to set INTEGER-MODEL-MAP-FLAG 1000dnl or PAC_FC_INTEGER_MODEL_MAP if cross_compiling=yes. 1001dnl 1002dnl This test requires $pac_validKinds set by PAC_FC_ALL_INTEGER_MODELS(). 1003dnl 1004dnl This is a runtime test. 1005dnl 1006dnl Compile the C subroutine as pac_conftest.o and Link it with a Fortran main. 1007AC_DEFUN([PAC_FC_INTEGER_MODEL_MAP],[ 1008AC_REQUIRE([PAC_FC_AVAIL_INTEGER_MODELS]) 1009AC_MSG_CHECKING([for available integer ranges]) 1010AC_LANG_PUSH([C]) 1011AC_COMPILE_IFELSE([ 1012 AC_LANG_SOURCE([ 1013#ifdef F77_NAME_UPPER 1014#define cisize_ CISIZE 1015#define isize_ ISIZE 1016#elif defined(F77_NAME_LOWER) || defined(F77_NAME_MIXED) 1017#define cisize_ cisize 1018#define isize_ isize 1019#endif 1020int cisize_(char *,char*); 1021int cisize_(char *i1p, char *i2p) 1022{ 1023 int isize_val=0; 1024 isize_val = (int)(i2p - i1p); 1025 return isize_val; 1026} 1027 ]) 1028],[ 1029 PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT]) 1030 pac_ccompile_ok=yes 1031],[ 1032 pac_ccompile_ok=no 1033]) 1034AC_LANG_POP([C]) 1035dnl 1036if test "$pac_ccompile_ok" = "yes" ; then 1037 saved_LIBS="$LIBS" 1038 LIBS="pac_conftest.$OBJEXT $LIBS" 1039 saved_IFS=$IFS 1040 IFS=: 1041 AC_LANG_PUSH([Fortran]) 1042 pac_flag="" 1043 for rangekind in $pac_validKinds ; do 1044 kind="`echo $rangekind | sed -e 's/.*,//'`" 1045 range="`echo $rangekind | sed -e 's/,.*//'`" 1046 AC_LANG_CONFTEST([ 1047 AC_LANG_SOURCE([ 1048 program main 1049 integer (kind=$kind) a(2) 1050 integer cisize 1051 open(8, file="pac_fconftest.out", form="formatted") 1052 write(8,*) $range, ",", $kind, ",", cisize( a(1), a(2) ) 1053 close(8) 1054 end 1055 ]) 1056 ]) 1057 IFS=$saved_IFS 1058 rm -f pac_fconftest.out 1059 AC_RUN_IFELSE([],[ 1060 if test -s pac_fconftest.out ; then 1061 sizes="`sed -e 's/ */ /g' pac_fconftest.out`" 1062 pac_flag="$pac_flag { $sizes }," 1063 else 1064 AC_MSG_WARN([No output from test program!]) 1065 fi 1066 rm -f pac_fconftest.out 1067 ],[ 1068 AC_MSG_WARN([Fortran program fails to build or run!]) 1069 ],[ 1070 pac_flag="$2" 1071 ]) 1072 IFS=: 1073 done 1074 IFS=$saved_IFS 1075 AC_MSG_RESULT([$pac_flag]) 1076 ifelse([$1],[],[PAC_FC_INTEGER_MODEL_MAP=$pac_flag],[$1=$pac_flag]) 1077 AC_LANG_POP([Fortran]) 1078 LIBS="$saved_LIBS" 1079 rm -f pac_conftest.$OBJEXT 1080fi 1081]) 1082