fortran.m4 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. # This file is part of Autoconf. -*- Autoconf -*-
  2. # Fortran languages support.
  3. # Copyright (C) 2001, 2003-2011 Free Software Foundation, Inc.
  4. # This file is part of Autoconf. This program is free
  5. # software; you can redistribute it and/or modify it under the
  6. # terms of the GNU General Public License as published by the
  7. # Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # Under Section 7 of GPL version 3, you are granted additional
  16. # permissions described in the Autoconf Configure Script Exception,
  17. # version 3.0, as published by the Free Software Foundation.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # and a copy of the Autoconf Configure Script Exception along with
  21. # this program; see the files COPYINGv3 and COPYING.EXCEPTION
  22. # respectively. If not, see <http://www.gnu.org/licenses/>.
  23. # Written by David MacKenzie, with help from
  24. # Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
  25. # Roland McGrath, Noah Friedman, david d zuhn, and many others.
  26. # Table of Contents:
  27. #
  28. # Preamble
  29. #
  30. # 0. Utility macros
  31. #
  32. # 1. Language selection
  33. # and routines to produce programs in a given language.
  34. #
  35. # 2. Producing programs in a given language.
  36. #
  37. # 3. Looking for a compiler
  38. # And possibly the associated preprocessor.
  39. #
  40. # 4. Compilers' characteristics.
  41. # AC_FC_PP_SRCEXT(EXT, [ACTION-IF-SUCCESS], [ACTION-IF-FAILURE])
  42. # --------------------------------------------------------------
  43. # Like AC_FC_SRCEXT, set the source-code extension used in Fortran (FC) tests
  44. # to EXT (which defaults to f). Also, look for any necessary additional
  45. # FCFLAGS needed to allow this extension for preprocessed Fortran, and store
  46. # them in the output variable FCFLAGS_<EXT> (e.g. FCFLAGS_f90 for EXT=f90).
  47. # If successful, call ACTION-IF-SUCCESS. If unable to compile preprocessed
  48. # source code with EXT, call ACTION-IF-FAILURE, which defaults to failing with
  49. # an error message.
  50. #
  51. # Some compilers allow preprocessing with either a Fortran preprocessor or
  52. # with the C preprocessor (cpp). Prefer the Fortran preprocessor, to deal
  53. # correctly with continuation lines, `//' (not a comment), and preserve white
  54. # space (for fixed form).
  55. #
  56. # (The flags for the current source-code extension, if any, are stored in
  57. # $ac_fcflags_srcext and used automatically in subsequent autoconf tests.)
  58. #
  59. # For ordinary extensions like f90, etcetera, the modified FCFLAGS
  60. # are needed for IBM's xlf*. Also, for Intel's ifort compiler, the
  61. # $FCFLAGS_<EXT> variable *must* go immediately before the source file on the
  62. # command line, unlike other $FCFLAGS. Ugh.
  63. #
  64. # Known extensions that enable preprocessing by default, and flags to force it:
  65. # GNU: .F .F90 .F95 .F03 .F08, -cpp for most others,
  66. # -x f77-cpp-input for .f77 .F77; -x f95-cpp-input for gfortran < 4.4
  67. # SGI: .F .F90, -ftpp or -cpp for .f .f90, -E write preproc to stdout
  68. # -macro_expand enable macro expansion everywhere (with -ftpp)
  69. # -P preproc only, save in .i, no #line's
  70. # SUN: .F .F95, -fpp for others; -xpp={fpp,cpp} for preprocessor selection
  71. # -F preprocess only (save in lowercase extension)
  72. # IBM: .F .F77 .F90 .F95 .F03, -qsuffix=cpp=EXT for extension .EXT to invoke cpp
  73. # -WF,-qnofpp -WF,-qfpp=comment:linecont:nocomment:nolinecont
  74. # -WF,-qlanglvl=classic or not -qnoescape (trigraph problems)
  75. # -d no #line in output, -qnoobject for preprocessing only (output in .f)
  76. # -q{no,}ppsuborigarg substitute original macro args before expansion
  77. # HP: .F, +cpp={yes|no|default} use cpp, -cpp, +cpp_keep save in .i/.i90
  78. # PGI: -Mpreprocess
  79. # Absoft: .F .FOR .F90 .F95, -cpp for others
  80. # Cray: .F .F90 .FTN, -e Z for others; -F enable macro expansion everywhere
  81. # Intel: .F .F90, -fpp for others, but except for .f and .f90, -Tf may also be
  82. # needed right before the source file name
  83. # PathScale: .F .F90 .F95, -ftpp or -cpp for .f .f90 .f95
  84. # -macro_expand for expansion everywhere, -P for no #line in output
  85. # Lahey: .F .FOR .F90 .F95, -Cpp
  86. # NAGWare: .F .F90 .F95, .ff .ff90 .ff95 (new), -fpp for others
  87. # Compaq/Tru64: .F .F90, -cpp, -P keep .i file, -P keep .i file
  88. # f2c: .F, -cpp
  89. # g95: .F .FOR .F90 .F95 .F03, -cpp -no-cpp, -E for stdout
  90. AC_DEFUN([AC_FC_PP_SRCEXT],
  91. [AC_LANG_PUSH(Fortran)dnl
  92. AC_CACHE_CHECK([for Fortran flag to compile preprocessed .$1 files],
  93. ac_cv_fc_pp_srcext_$1,
  94. [ac_ext=$1
  95. ac_fcflags_pp_srcext_save=$ac_fcflags_srcext
  96. ac_fcflags_srcext=
  97. ac_cv_fc_pp_srcext_$1=unknown
  98. case $ac_ext in #(
  99. [[fF]]77) ac_try=f77-cpp-input;; #(
  100. *) ac_try=f95-cpp-input;;
  101. esac
  102. for ac_flag in none -ftpp -fpp -Tf "-fpp -Tf" -xpp=fpp -Mpreprocess "-e Z" \
  103. -cpp -xpp=cpp -qsuffix=cpp=$1 "-x $ac_try" +cpp -Cpp; do
  104. test "x$ac_flag" != xnone && ac_fcflags_srcext="$ac_flag"
  105. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
  106. #if 0
  107. #include <ac_nonexistent.h>
  108. choke me
  109. #endif]])],
  110. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
  111. #if 1
  112. #include <ac_nonexistent.h>
  113. choke me
  114. #endif]])],
  115. [],
  116. [ac_cv_fc_pp_srcext_$1=$ac_flag; break])])
  117. done
  118. rm -f conftest.$ac_objext conftest.$1
  119. ac_fcflags_srcext=$ac_fcflags_pp_srcext_save
  120. ])
  121. if test "x$ac_cv_fc_pp_srcext_$1" = xunknown; then
  122. m4_default([$3],
  123. [AC_MSG_ERROR([Fortran could not compile preprocessed .$1 files])])
  124. else
  125. ac_fc_srcext=$1
  126. if test "x$ac_cv_fc_pp_srcext_$1" = xnone; then
  127. ac_fcflags_srcext=""
  128. FCFLAGS_[]$1[]=""
  129. else
  130. ac_fcflags_srcext=$ac_cv_fc_pp_srcext_$1
  131. FCFLAGS_[]$1[]=$ac_cv_fc_pp_srcext_$1
  132. fi
  133. AC_SUBST(FCFLAGS_[]$1)
  134. $2
  135. fi
  136. AC_LANG_POP(Fortran)dnl
  137. ])# AC_FC_PP_SRCEXT
  138. # AC_FC_PP_DEFINE([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
  139. # -------------------------------------------------------------------
  140. # Find a flag to specify defines for preprocessed Fortran. Not all
  141. # Fortran compilers use -D. Substitute FC_DEFINE with the result and
  142. # call ACTION-IF-SUCCESS (defaults to nothing) if successful, and
  143. # ACTION-IF-FAILURE (defaults to failing with an error message) if not.
  144. #
  145. # Known flags:
  146. # IBM: -WF,-D
  147. # Lahey/Fujitsu: -Wp,-D older versions???
  148. # f2c: -D or -Wc,-D
  149. # others: -D
  150. AC_DEFUN([AC_FC_PP_DEFINE],
  151. [AC_LANG_PUSH([Fortran])dnl
  152. ac_fc_pp_define_srcext_save=$ac_fc_srcext
  153. AC_FC_PP_SRCEXT([F])
  154. AC_CACHE_CHECK([how to define symbols for preprocessed Fortran],
  155. [ac_cv_fc_pp_define],
  156. [ac_fc_pp_define_srcext_save=$ac_fc_srcext
  157. ac_cv_fc_pp_define=unknown
  158. ac_fc_pp_define_FCFLAGS_save=$FCFLAGS
  159. for ac_flag in -D -WF,-D -Wp,-D -Wc,-D
  160. do
  161. FCFLAGS="$ac_fc_pp_define_FCFLAGS_save ${ac_flag}FOOBAR ${ac_flag}ZORK=42"
  162. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
  163. #ifndef FOOBAR
  164. choke me
  165. #endif
  166. #if ZORK != 42
  167. choke me
  168. #endif]])],
  169. [ac_cv_fc_pp_define=$ac_flag])
  170. test x"$ac_cv_fc_pp_define" != xunknown && break
  171. done
  172. FCFLAGS=$ac_fc_pp_define_FCFLAGS_save
  173. ])
  174. ac_fc_srcext=$ac_fc_pp_define_srcext_save
  175. if test "x$ac_cv_fc_pp_define" = xunknown; then
  176. FC_DEFINE=
  177. m4_default([$2],
  178. [AC_MSG_ERROR([Fortran does not allow to define preprocessor symbols], 77)])
  179. else
  180. FC_DEFINE=$ac_cv_fc_pp_define
  181. $1
  182. fi
  183. AC_SUBST([FC_DEFINE])dnl
  184. AC_LANG_POP([Fortran])dnl
  185. ])
  186. # AC_FC_FREEFORM([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
  187. # ------------------------------------------------------------------
  188. # Look for a compiler flag to make the Fortran (FC) compiler accept
  189. # free-format source code, and adds it to FCFLAGS. Call
  190. # ACTION-IF-SUCCESS (defaults to nothing) if successful (i.e. can
  191. # compile code using new extension) and ACTION-IF-FAILURE (defaults to
  192. # failing with an error message) if not. (Defined via DEFUN_ONCE to
  193. # prevent flag from being added to FCFLAGS multiple times.)
  194. #
  195. # The known flags are:
  196. # -ffree-form: GNU g77, gfortran, g95
  197. # -FR, -free: Intel compiler (icc, ecc, ifort)
  198. # -free: Compaq compiler (fort), Sun compiler (f95)
  199. # -qfree: IBM compiler (xlf)
  200. # -Mfree, -Mfreeform: Portland Group compiler
  201. # -freeform: SGI compiler
  202. # -8, -f free: Absoft Fortran
  203. # +source=free: HP Fortran
  204. # (-)-nfix, -Free: Lahey/Fujitsu Fortran
  205. # -free: NAGWare
  206. # -f, -Wf,-f: f2c (but only a weak form of "free-form" and long lines)
  207. # We try to test the "more popular" flags first, by some prejudiced
  208. # notion of popularity.
  209. AC_DEFUN_ONCE([AC_FC_FREEFORM],
  210. [AC_LANG_PUSH([Fortran])dnl
  211. AC_CACHE_CHECK([for Fortran flag needed to accept free-form source],
  212. [ac_cv_fc_freeform],
  213. [ac_cv_fc_freeform=unknown
  214. ac_fc_freeform_FCFLAGS_save=$FCFLAGS
  215. for ac_flag in none -ffree-form -FR -free -qfree -Mfree -Mfreeform \
  216. -freeform "-f free" -8 +source=free -nfix --nfix -Free
  217. do
  218. test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_freeform_FCFLAGS_save $ac_flag"
  219. dnl Use @&t@ below to ensure that editors don't turn 8+ spaces into tab.
  220. AC_COMPILE_IFELSE([[
  221. program freeform
  222. ! FIXME: how to best confuse non-freeform compilers?
  223. print *, 'Hello ', &
  224. @&t@ 'world.'
  225. end]],
  226. [ac_cv_fc_freeform=$ac_flag; break])
  227. done
  228. rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
  229. FCFLAGS=$ac_fc_freeform_FCFLAGS_save
  230. ])
  231. if test "x$ac_cv_fc_freeform" = xunknown; then
  232. m4_default([$2],
  233. [AC_MSG_ERROR([Fortran does not accept free-form source], 77)])
  234. else
  235. if test "x$ac_cv_fc_freeform" != xnone; then
  236. FCFLAGS="$FCFLAGS $ac_cv_fc_freeform"
  237. fi
  238. $1
  239. fi
  240. AC_LANG_POP([Fortran])dnl
  241. ])# AC_FC_FREEFORM
  242. # AC_FC_FIXEDFORM([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
  243. # ------------------------------------------------------------------
  244. # Look for a compiler flag to make the Fortran (FC) compiler accept
  245. # fixed-format source code, and adds it to FCFLAGS. Call
  246. # ACTION-IF-SUCCESS (defaults to nothing) if successful (i.e. can
  247. # compile code using new extension) and ACTION-IF-FAILURE (defaults to
  248. # failing with an error message) if not. (Defined via DEFUN_ONCE to
  249. # prevent flag from being added to FCFLAGS multiple times.)
  250. #
  251. # The known flags are:
  252. # -ffixed-form: GNU g77, gfortran, g95
  253. # -fixed: Intel compiler (ifort), Sun compiler (f95)
  254. # -qfixed: IBM compiler (xlf*)
  255. # -Mfixed: Portland Group compiler
  256. # -fixedform: SGI compiler
  257. # -f fixed: Absoft Fortran
  258. # +source=fixed: HP Fortran
  259. # (-)-fix, -Fixed: Lahey/Fujitsu Fortran
  260. # -fixed: NAGWare
  261. # Since compilers may accept fixed form based on file name extension,
  262. # but users may want to use it with others as well, call AC_FC_SRCEXT
  263. # with the respective source extension before calling this macro.
  264. AC_DEFUN_ONCE([AC_FC_FIXEDFORM],
  265. [AC_LANG_PUSH([Fortran])dnl
  266. AC_CACHE_CHECK([for Fortran flag needed to accept fixed-form source],
  267. [ac_cv_fc_fixedform],
  268. [ac_cv_fc_fixedform=unknown
  269. ac_fc_fixedform_FCFLAGS_save=$FCFLAGS
  270. for ac_flag in none -ffixed-form -fixed -qfixed -Mfixed -fixedform "-f fixed" \
  271. +source=fixed -fix --fix -Fixed
  272. do
  273. test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_fixedform_FCFLAGS_save $ac_flag"
  274. AC_COMPILE_IFELSE([[
  275. C This comment should confuse free-form compilers.
  276. program main
  277. end]],
  278. [ac_cv_fc_fixedform=$ac_flag; break])
  279. done
  280. rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
  281. FCFLAGS=$ac_fc_fixedform_FCFLAGS_save
  282. ])
  283. if test "x$ac_cv_fc_fixedform" = xunknown; then
  284. m4_default([$2],
  285. [AC_MSG_ERROR([Fortran does not accept fixed-form source], 77)])
  286. else
  287. if test "x$ac_cv_fc_fixedform" != xnone; then
  288. FCFLAGS="$FCFLAGS $ac_cv_fc_fixedform"
  289. fi
  290. $1
  291. fi
  292. AC_LANG_POP([Fortran])dnl
  293. ])# AC_FC_FIXEDFORM
  294. # AC_FC_LINE_LENGTH([LENGTH], [ACTION-IF-SUCCESS],
  295. # [ACTION-IF-FAILURE = FAILURE])
  296. # ------------------------------------------------
  297. # Look for a compiler flag to make the Fortran (FC) compiler accept long lines
  298. # in the current (free- or fixed-format) source code, and adds it to FCFLAGS.
  299. # The optional LENGTH may be 80, 132 (default), or `unlimited' for longer
  300. # lines. Note that line lengths above 254 columns are not portable, and some
  301. # compilers (hello ifort) do not accept more than 132 columns at least for
  302. # fixed format. Call ACTION-IF-SUCCESS (defaults to nothing) if successful
  303. # (i.e. can compile code using new extension) and ACTION-IF-FAILURE (defaults
  304. # to failing with an error message) if not. (Defined via DEFUN_ONCE to
  305. # prevent flag from being added to FCFLAGS multiple times.)
  306. # You should call AC_FC_FREEFORM or AC_FC_FIXEDFORM to set the desired format
  307. # prior to using this macro.
  308. #
  309. # The known flags are:
  310. # -f{free,fixed}-line-length-N with N 72, 80, 132, or 0 or none for none.
  311. # -ffree-line-length-none: GNU gfortran
  312. # -ffree-line-length-huge: g95 (also -ffixed-line-length-N as above)
  313. # -qfixed=132 80 72: IBM compiler (xlf)
  314. # -Mextend: Cray
  315. # -132 -80 -72: Intel compiler (ifort)
  316. # Needs to come before -extend_source because ifort
  317. # accepts that as well with an optional parameter and
  318. # doesn't fail but only warns about unknown arguments.
  319. # -extend_source: SGI compiler
  320. # -W, -WNN (132, 80, 72): Absoft Fortran
  321. # +es, +extend_source: HP Fortran (254 in either form, default is 72 fixed,
  322. # 132 free)
  323. # -w, (-)-wide: Lahey/Fujitsu Fortran (255 cols in fixed form)
  324. # -e: Sun Fortran compiler (132 characters)
  325. # -132: NAGWare
  326. # -72, -f, -Wf,-f: f2c (a weak form of "free-form" and long lines).
  327. # /XLine: Open Watcom
  328. AC_DEFUN_ONCE([AC_FC_LINE_LENGTH],
  329. [AC_LANG_PUSH([Fortran])dnl
  330. m4_case(m4_default([$1], [132]),
  331. [unlimited], [ac_fc_line_len_string=unlimited
  332. ac_fc_line_len=0
  333. ac_fc_line_length_test='
  334. subroutine longer_than_132(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,'\
  335. 'arg9,arg10,arg11,arg12,arg13,arg14,arg15,arg16,arg17,arg18,arg19)'],
  336. [132], [ac_fc_line_len=132
  337. ac_fc_line_length_test='
  338. subroutine longer_than_80(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,'\
  339. 'arg10)'],
  340. [80], [ac_fc_line_len=80
  341. ac_fc_line_length_test='
  342. subroutine longer_than_72(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)'],
  343. [m4_warning([Invalid length argument `$1'])])
  344. : ${ac_fc_line_len_string=$ac_fc_line_len}
  345. AC_CACHE_CHECK(
  346. [for Fortran flag needed to accept $ac_fc_line_len_string column source lines],
  347. [ac_cv_fc_line_length],
  348. [ac_cv_fc_line_length=unknown
  349. ac_fc_line_length_FCFLAGS_save=$FCFLAGS
  350. for ac_flag in none \
  351. -ffree-line-length-none -ffixed-line-length-none \
  352. -ffree-line-length-huge \
  353. -ffree-line-length-$ac_fc_line_len \
  354. -ffixed-line-length-$ac_fc_line_len \
  355. -qfixed=$ac_fc_line_len -Mextend \
  356. -$ac_fc_line_len -extend_source \
  357. -W$ac_fc_line_len -W +extend_source +es -wide --wide -w -e \
  358. -f -Wf,-f -xline
  359. do
  360. test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_line_length_FCFLAGS_save $ac_flag"
  361. AC_COMPILE_IFELSE([[$ac_fc_line_length_test
  362. end subroutine]],
  363. [ac_cv_fc_line_length=$ac_flag; break])
  364. done
  365. rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
  366. FCFLAGS=$ac_fc_line_length_FCFLAGS_save
  367. ])
  368. if test "x$ac_cv_fc_line_length" = xunknown; then
  369. m4_default([$3],
  370. [AC_MSG_ERROR([Fortran does not accept long source lines], 77)])
  371. else
  372. if test "x$ac_cv_fc_line_length" != xnone; then
  373. FCFLAGS="$FCFLAGS $ac_cv_fc_line_length"
  374. fi
  375. $2
  376. fi
  377. AC_LANG_POP([Fortran])dnl
  378. ])# AC_FC_LINE_LENGTH
  379. # AC_FC_CHECK_BOUNDS([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
  380. # ----------------------------------------------------------------------
  381. # Look for a compiler flag to turn on array bounds checking for the
  382. # Fortran (FC) compiler, and adds it to FCFLAGS. Call
  383. # ACTION-IF-SUCCESS (defaults to nothing) if successful (i.e. can
  384. # compile code using new extension) and ACTION-IF-FAILURE (defaults to
  385. # failing with an error message) if not. (Defined via DEFUN_ONCE to
  386. # prevent flag from being added to FCFLAGS multiple times.)
  387. #
  388. # The known flags are:
  389. # -fcheck=all, -fbounds-check: gfortran
  390. # -fbounds-check: g77, g95
  391. # -CB, -check bounds: Intel compiler (icc, ecc, ifort)
  392. # -C: Sun/Oracle compiler (f95)
  393. # -C, -qcheck: IBM compiler (xlf)
  394. # -Mbounds: Portland Group compiler
  395. # -C ,-Mbounds: Cray
  396. # -C, -check_bounds: SGI compiler
  397. # -check_bounds, +check=all: HP Fortran
  398. # -C, -Rb -Rc: Absoft (-Rb: array boundaries, -Rc: array conformance)
  399. # --chk e,s -chk (e,s): Lahey
  400. # -C -C=all: NAGWare
  401. # -C, -ffortran-bounds-check: PathScale pathf90
  402. # -C: f2c
  403. # -BOunds: Open Watcom
  404. AC_DEFUN_ONCE([AC_FC_CHECK_BOUNDS],
  405. [AC_LANG_PUSH([Fortran])dnl
  406. AC_CACHE_CHECK([for Fortran flag to enable array-bounds checking],
  407. [ac_cv_fc_check_bounds],
  408. [ac_cv_fc_check_bounds=unknown
  409. ac_fc_check_bounds_FCFLAGS_save=$FCFLAGS
  410. for ac_flag in -fcheck=bounds -fbounds-check -check_bounds -Mbounds -qcheck \
  411. '-check bounds' +check=all --check '-Rb -Rc' -CB -C=all -C \
  412. -ffortran-bounds-check "--chk e,s" "-chk e -chk s" -bounds
  413. do
  414. FCFLAGS="$ac_fc_check_bounds_FCFLAGS_save $ac_flag"
  415. # We should be able to link a correct program.
  416. AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
  417. [AC_LINK_IFELSE([[
  418. subroutine sub(a)
  419. integer a(:)
  420. a(8) = 0
  421. end subroutine
  422. program main
  423. integer a(1:7)
  424. interface
  425. subroutine sub(a)
  426. integer a(:)
  427. end subroutine
  428. end interface
  429. call sub(a)
  430. end program]],
  431. [# If we can run the program, require failure at run time.
  432. # In cross-compiling mode, we rely on the compiler not accepting
  433. # unknown options.
  434. AS_IF([test "$cross_compiling" = yes],
  435. [ac_cv_fc_check_bounds=$ac_flag; break],
  436. [AS_IF([_AC_DO_TOKENS(./conftest$ac_exeext)],
  437. [],
  438. [ac_cv_fc_check_bounds=$ac_flag; break])])])])
  439. done
  440. rm -f conftest$ac_exeext conftest.err conftest.$ac_objext conftest.$ac_ext
  441. FCFLAGS=$ac_fc_check_bounds_FCFLAGS_save
  442. ])
  443. if test "x$ac_cv_fc_check_bounds" = xunknown; then
  444. m4_default([$2],
  445. [AC_MSG_ERROR([no Fortran flag for bounds checking found], 77)])
  446. else
  447. if test "x$ac_cv_fc_check_bounds" != xnone; then
  448. FCFLAGS="$FCFLAGS $ac_cv_fc_check_bounds"
  449. fi
  450. $1
  451. fi
  452. AC_LANG_POP([Fortran])dnl
  453. ])# AC_FC_CHECK_BOUNDS
  454. # _AC_FC_IMPLICIT_NONE([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
  455. # ------------------------------------------------------------------------
  456. # Look for a flag to disallow implicit declarations, and add it to FCFLAGS.
  457. # Call ACTION-IF-SUCCESS (defaults to nothing) if successful and
  458. # ACTION-IF-FAILURE (defaults to failing with an error message) if not.
  459. #
  460. # Known flags:
  461. # GNU gfortran, g95: -fimplicit-none, g77: -Wimplicit
  462. # Intel: -u, -implicitnone; might also need '-warn errors' to turn into error.
  463. # Sun/Oracle: -u
  464. # HP: +implicit_none
  465. # IBM: -u, -qundef
  466. # SGI: -u
  467. # Compaq: -u, -warn declarations
  468. # NAGWare: -u
  469. # Lahey: -in, --in, -AT
  470. # Cray: -Mdclchk -e I
  471. # PGI: -Mcdlchk
  472. # f2c: -u
  473. AC_DEFUN([_AC_FC_IMPLICIT_NONE],
  474. [_AC_FORTRAN_ASSERT()dnl
  475. AC_CACHE_CHECK([for flag to disallow _AC_LANG implicit declarations],
  476. [ac_cv_[]_AC_LANG_ABBREV[]_implicit_none],
  477. [ac_cv_[]_AC_LANG_ABBREV[]_implicit_none=unknown
  478. ac_fc_implicit_none_[]_AC_LANG_PREFIX[]FLAGS_save=$[]_AC_LANG_PREFIX[]FLAGS
  479. for ac_flag in none -fimplicit-none -u -Wimplicit -implicitnone +implicit_none \
  480. -qundef "-warn declarations" -in --in -AT "-e I" -Mdclchk \
  481. "-u -warn errors"
  482. do
  483. if test "x$ac_flag" != xnone; then
  484. _AC_LANG_PREFIX[]FLAGS="$ac_fc_implicit_none_[]_AC_LANG_PREFIX[]FLAGS_save $ac_flag"
  485. fi
  486. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])],
  487. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
  488. i = 0
  489. print *, i]])],
  490. [],
  491. [ac_cv_[]_AC_LANG_ABBREV[]_implicit_none=$ac_flag; break])])
  492. done
  493. rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
  494. _AC_LANG_PREFIX[]FLAGS=$ac_fc_implicit_none_[]_AC_LANG_PREFIX[]FLAGS_save
  495. ])
  496. if test "x$ac_cv_[]_AC_LANG_ABBREV[]_implicit_none" = xunknown; then
  497. m4_default([$3],
  498. [AC_MSG_ERROR([no Fortran flag to disallow implicit declarations found], 77)])
  499. else
  500. if test "x$ac_cv_[]_AC_LANG_ABBREV[]_implicit_none" != xnone; then
  501. _AC_LANG_PREFIX[]FLAGS="$_AC_LANG_PREFIX[]FLAGS $ac_cv_[]_AC_LANG_ABBREV[]_implicit_none"
  502. fi
  503. $2
  504. fi
  505. ])# _AC_FC_IMPLICIT_NONE
  506. # AC_F77_IMPLICIT_NONE([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
  507. # ------------------------------------------------------------------------
  508. AC_DEFUN([AC_F77_IMPLICIT_NONE],
  509. [AC_LANG_PUSH([Fortran 77])dnl
  510. _AC_FC_IMPLICIT_NONE($@)
  511. AC_LANG_POP([Fortran 77])dnl
  512. ])# AC_F77_IMPLICIT_NONE
  513. # AC_FC_IMPLICIT_NONE([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
  514. # -----------------------------------------------------------------------
  515. AC_DEFUN([AC_FC_IMPLICIT_NONE],
  516. [AC_LANG_PUSH([Fortran])dnl
  517. _AC_FC_IMPLICIT_NONE($@)
  518. AC_LANG_POP([Fortran])dnl
  519. ])# AC_FC_IMPLICIT_NONE
  520. # AC_FC_MODULE_EXTENSION
  521. # ----------------------
  522. # Find the Fortran 90 module file extension. The module extension is stored
  523. # in the variable FC_MODEXT and empty if it cannot be determined. The result
  524. # or "unknown" is cached in the cache variable ac_cv_fc_module_ext.
  525. AC_DEFUN([AC_FC_MODULE_EXTENSION],
  526. [AC_CACHE_CHECK([Fortran 90 module extension], [ac_cv_fc_module_ext],
  527. [AC_LANG_PUSH(Fortran)
  528. mkdir conftest.dir
  529. cd conftest.dir
  530. ac_cv_fc_module_ext=unknown
  531. AC_COMPILE_IFELSE([[
  532. module conftest_module
  533. contains
  534. subroutine conftest_routine
  535. write(*,'(a)') 'gotcha!'
  536. end subroutine
  537. end module]],
  538. [ac_cv_fc_module_ext=`ls | sed -n 's,conftest_module\.,,p'`
  539. if test x$ac_cv_fc_module_ext = x; then
  540. dnl Some F90 compilers use upper case characters for the module file name.
  541. ac_cv_fc_module_ext=`ls | sed -n 's,CONFTEST_MODULE\.,,p'`
  542. fi])
  543. cd ..
  544. rm -rf conftest.dir
  545. AC_LANG_POP(Fortran)
  546. ])
  547. FC_MODEXT=$ac_cv_fc_module_ext
  548. if test "$FC_MODEXT" = unknown; then
  549. FC_MODEXT=
  550. fi
  551. AC_SUBST([FC_MODEXT])dnl
  552. ])
  553. # AC_FC_MODULE_FLAG([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
  554. # ---------------------------------------------------------------------
  555. # Find a flag to include Fortran 90 modules from another directory.
  556. # If successful, run ACTION-IF-SUCCESS (defaults to nothing), otherwise
  557. # run ACTION-IF-FAILURE (defaults to failing with an error message).
  558. # The module flag is cached in the ac_cv_fc_module_flag variable.
  559. # It may contain significant trailing whitespace.
  560. #
  561. # Known flags:
  562. # gfortran: -Idir, -I dir (-M dir, -Mdir (deprecated), -Jdir for writing)
  563. # g95: -I dir (-fmod=dir for writing)
  564. # SUN: -Mdir, -M dir (-moddir=dir for writing;
  565. # -Idir for includes is also searched)
  566. # HP: -Idir, -I dir (+moddir=dir for writing)
  567. # IBM: -Idir (-qmoddir=dir for writing)
  568. # Intel: -Idir -I dir (-mod dir for writing)
  569. # Absoft: -pdir
  570. # Lahey: -Idir (-Mdir or -mod dir for writing)
  571. # Cray: -module dir, -p dir (-J dir for writing)
  572. # -e m is needed to enable writing .mod files at all
  573. # Compaq: -Idir
  574. # NAGWare: -I dir
  575. # PathScale: -I dir (but -module dir is looked at first)
  576. # Portland: -module dir (first -module also names dir for writing)
  577. # Fujitsu: -Am -Idir (-Mdir for writing is searched first, then '.', then -I)
  578. # (-Am indicates how module information is saved)
  579. AC_DEFUN([AC_FC_MODULE_FLAG],[
  580. AC_CACHE_CHECK([Fortran 90 module inclusion flag], [ac_cv_fc_module_flag],
  581. [AC_LANG_PUSH([Fortran])
  582. ac_cv_fc_module_flag=unknown
  583. mkdir conftest.dir
  584. cd conftest.dir
  585. AC_COMPILE_IFELSE([[
  586. module conftest_module
  587. contains
  588. subroutine conftest_routine
  589. write(*,'(a)') 'gotcha!'
  590. end subroutine
  591. end module]],
  592. # For Lahey -M will also write module and object files to that directory
  593. # make it read-only so that lahey fails over to -I
  594. [chmod -w .
  595. cd ..
  596. ac_fc_module_flag_FCFLAGS_save=$FCFLAGS
  597. # Flag ordering is significant for gfortran and Sun.
  598. for ac_flag in -M -I '-I ' '-M ' -p '-mod ' '-module ' '-Am -I'; do
  599. # Add the flag twice to prevent matching an output flag.
  600. FCFLAGS="$ac_fc_module_flag_FCFLAGS_save ${ac_flag}conftest.dir ${ac_flag}conftest.dir"
  601. AC_COMPILE_IFELSE([[
  602. module conftest_main
  603. use conftest_module
  604. contains
  605. subroutine conftest
  606. call conftest_routine
  607. end subroutine
  608. end module]],
  609. [ac_cv_fc_module_flag="$ac_flag"])
  610. if test "$ac_cv_fc_module_flag" != unknown; then
  611. break
  612. fi
  613. done
  614. FCFLAGS=$ac_fc_module_flag_FCFLAGS_save
  615. ])
  616. chmod +w conftest.dir
  617. rm -rf conftest.dir
  618. AC_LANG_POP([Fortran])
  619. ])
  620. if test "$ac_cv_fc_module_flag" != unknown; then
  621. FC_MODINC=$ac_cv_fc_module_flag
  622. $1
  623. else
  624. FC_MODINC=
  625. m4_default([$2],
  626. [AC_MSG_ERROR([unable to find compiler flag for module search path])])
  627. fi
  628. AC_SUBST([FC_MODINC])
  629. # Ensure trailing whitespace is preserved in a Makefile.
  630. AC_SUBST([ac_empty], [""])
  631. AC_CONFIG_COMMANDS_PRE([case $FC_MODINC in #(
  632. *\ ) FC_MODINC=$FC_MODINC'${ac_empty}' ;;
  633. esac])dnl
  634. ])
  635. # AC_FC_MODULE_OUTPUT_FLAG([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
  636. # ----------------------------------------------------------------------------
  637. # Find a flag to write Fortran 90 module information to another directory.
  638. # If successful, run ACTION-IF-SUCCESS (defaults to nothing), otherwise
  639. # run ACTION-IF-FAILURE (defaults to failing with an error message).
  640. # The module flag is cached in the ac_cv_fc_module_output_flag variable.
  641. # It may contain significant trailing whitespace.
  642. #
  643. # For known flags, see the documentation of AC_FC_MODULE_FLAG above.
  644. AC_DEFUN([AC_FC_MODULE_OUTPUT_FLAG],[
  645. AC_CACHE_CHECK([Fortran 90 module output flag], [ac_cv_fc_module_output_flag],
  646. [AC_LANG_PUSH([Fortran])
  647. mkdir conftest.dir conftest.dir/sub
  648. cd conftest.dir
  649. ac_cv_fc_module_output_flag=unknown
  650. ac_fc_module_output_flag_FCFLAGS_save=$FCFLAGS
  651. # Flag ordering is significant: put flags late which some compilers use
  652. # for the search path.
  653. for ac_flag in -J '-J ' -fmod= -moddir= +moddir= -qmoddir= '-mod ' \
  654. '-module ' -M '-Am -M' '-e m -J '; do
  655. FCFLAGS="$ac_fc_module_output_flag_FCFLAGS_save ${ac_flag}sub"
  656. AC_COMPILE_IFELSE([[
  657. module conftest_module
  658. contains
  659. subroutine conftest_routine
  660. write(*,'(a)') 'gotcha!'
  661. end subroutine
  662. end module]],
  663. [cd sub
  664. AC_COMPILE_IFELSE([[
  665. program main
  666. use conftest_module
  667. call conftest_routine
  668. end program]],
  669. [ac_cv_fc_module_output_flag="$ac_flag"])
  670. cd ..
  671. if test "$ac_cv_fc_module_output_flag" != unknown; then
  672. break
  673. fi])
  674. done
  675. FCFLAGS=$ac_fc_module_output_flag_FCFLAGS_save
  676. cd ..
  677. rm -rf conftest.dir
  678. AC_LANG_POP([Fortran])
  679. ])
  680. if test "$ac_cv_fc_module_output_flag" != unknown; then
  681. FC_MODOUT=$ac_cv_fc_module_output_flag
  682. $1
  683. else
  684. FC_MODOUT=
  685. m4_default([$2],
  686. [AC_MSG_ERROR([unable to find compiler flag to write module information to])])
  687. fi
  688. AC_SUBST([FC_MODOUT])
  689. # Ensure trailing whitespace is preserved in a Makefile.
  690. AC_SUBST([ac_empty], [""])
  691. AC_CONFIG_COMMANDS_PRE([case $FC_MODOUT in #(
  692. *\ ) FC_MODOUT=$FC_MODOUT'${ac_empty}' ;;
  693. esac])dnl
  694. ])
  695. # _AC_FC_LIBRARY_LDFLAGS
  696. # ----------------------
  697. #
  698. # Determine the linker flags (e.g. "-L" and "-l") for the Fortran
  699. # intrinsic and runtime libraries that are required to successfully
  700. # link a Fortran program or shared library. The output variable
  701. # FLIBS/FCLIBS is set to these flags.
  702. #
  703. # This macro is intended to be used in those situations when it is
  704. # necessary to mix, e.g. C++ and Fortran, source code into a single
  705. # program or shared library.
  706. #
  707. # For example, if object files from a C++ and Fortran compiler must
  708. # be linked together, then the C++ compiler/linker must be used for
  709. # linking (since special C++-ish things need to happen at link time
  710. # like calling global constructors, instantiating templates, enabling
  711. # exception support, etc.).
  712. #
  713. # However, the Fortran intrinsic and runtime libraries must be
  714. # linked in as well, but the C++ compiler/linker doesn't know how to
  715. # add these Fortran libraries. Hence, the macro
  716. # "AC_F77_LIBRARY_LDFLAGS" was created to determine these Fortran
  717. # libraries.
  718. #
  719. # This macro was packaged in its current form by Matthew D. Langston.
  720. # However, nearly all of this macro came from the "OCTAVE_FLIBS" macro
  721. # in "octave-2.0.13/aclocal.m4", and full credit should go to John
  722. # W. Eaton for writing this extremely useful macro. Thank you John.
  723. AC_DEFUN([_AC_FC_LIBRARY_LDFLAGS],
  724. [_AC_FORTRAN_ASSERT()dnl
  725. _AC_PROG_FC_V
  726. AC_CACHE_CHECK([for _AC_LANG libraries of $[]_AC_FC[]], ac_cv_[]_AC_LANG_ABBREV[]_libs,
  727. [if test "x$[]_AC_LANG_PREFIX[]LIBS" != "x"; then
  728. ac_cv_[]_AC_LANG_ABBREV[]_libs="$[]_AC_LANG_PREFIX[]LIBS" # Let the user override the test.
  729. else
  730. _AC_PROG_FC_V_OUTPUT
  731. ac_cv_[]_AC_LANG_ABBREV[]_libs=
  732. # Save positional arguments (if any)
  733. ac_save_positional="$[@]"
  734. set X $ac_[]_AC_LANG_ABBREV[]_v_output
  735. while test $[@%:@] != 1; do
  736. shift
  737. ac_arg=$[1]
  738. case $ac_arg in
  739. [[\\/]]*.a | ?:[[\\/]]*.a)
  740. _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
  741. ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg")
  742. ;;
  743. -bI:*)
  744. _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
  745. [_AC_LINKER_OPTION([$ac_arg], ac_cv_[]_AC_LANG_ABBREV[]_libs)])
  746. ;;
  747. # Ignore these flags.
  748. -lang* | -lcrt*.o | -lc | -lgcc* | -lSystem | -libmil | -little \
  749. |-LANG:=* | -LIST:* | -LNO:* | -link | -list | -lnuma )
  750. ;;
  751. -lkernel32)
  752. test x"$CYGWIN" != xyes && ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg"
  753. ;;
  754. -[[LRuYz]])
  755. # These flags, when seen by themselves, take an argument.
  756. # We remove the space between option and argument and re-iterate
  757. # unless we find an empty arg or a new option (starting with -)
  758. case $[2] in
  759. "" | -*);;
  760. *)
  761. ac_arg="$ac_arg$[2]"
  762. shift; shift
  763. set X $ac_arg "$[@]"
  764. ;;
  765. esac
  766. ;;
  767. -YP,*)
  768. for ac_j in `AS_ECHO(["$ac_arg"]) | sed -e 's/-YP,/-L/;s/:/ -L/g'`; do
  769. _AC_LIST_MEMBER_IF($ac_j, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
  770. [ac_arg="$ac_arg $ac_j"
  771. ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_j"])
  772. done
  773. ;;
  774. -[[lLR]]*)
  775. _AC_LIST_MEMBER_IF($ac_arg, $ac_cv_[]_AC_LANG_ABBREV[]_libs, ,
  776. ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg")
  777. ;;
  778. -zallextract*| -zdefaultextract)
  779. ac_cv_[]_AC_LANG_ABBREV[]_libs="$ac_cv_[]_AC_LANG_ABBREV[]_libs $ac_arg"
  780. ;;
  781. # Ignore everything else.
  782. esac
  783. done
  784. # restore positional arguments
  785. set X $ac_save_positional; shift
  786. # We only consider "LD_RUN_PATH" on Solaris systems. If this is seen,
  787. # then we insist that the "run path" must be an absolute path (i.e. it
  788. # must begin with a "/").
  789. case `(uname -sr) 2>/dev/null` in
  790. "SunOS 5"*)
  791. ac_ld_run_path=`AS_ECHO(["$ac_[]_AC_LANG_ABBREV[]_v_output"]) |
  792. sed -n 's,^.*LD_RUN_PATH *= *\(/[[^ ]]*\).*$,-R\1,p'`
  793. test "x$ac_ld_run_path" != x &&
  794. _AC_LINKER_OPTION([$ac_ld_run_path], ac_cv_[]_AC_LANG_ABBREV[]_libs)
  795. ;;
  796. esac
  797. fi # test "x$[]_AC_LANG_PREFIX[]LIBS" = "x"
  798. ])
  799. []_AC_LANG_PREFIX[]LIBS="$ac_cv_[]_AC_LANG_ABBREV[]_libs"
  800. AC_SUBST([]_AC_LANG_PREFIX[]LIBS)
  801. ])# _AC_FC_LIBRARY_LDFLAGS
  802. # AC_F77_LIBRARY_LDFLAGS
  803. # ----------------------
  804. AC_DEFUN([AC_F77_LIBRARY_LDFLAGS],
  805. [AC_REQUIRE([AC_PROG_F77])dnl
  806. AC_LANG_PUSH(Fortran 77)dnl
  807. _AC_FC_LIBRARY_LDFLAGS
  808. AC_LANG_POP(Fortran 77)dnl
  809. ])# AC_F77_LIBRARY_LDFLAGS
  810. # AC_FC_LIBRARY_LDFLAGS
  811. # ---------------------
  812. AC_DEFUN([AC_FC_LIBRARY_LDFLAGS],
  813. [AC_REQUIRE([AC_PROG_FC])dnl
  814. AC_LANG_PUSH(Fortran)dnl
  815. _AC_FC_LIBRARY_LDFLAGS
  816. AC_LANG_POP(Fortran)dnl
  817. ])# AC_FC_LIBRARY_LDFLAGS