1 #***********************************************************************
2 #* GNU Lesser General Public License
4 #* This file is part of the GFDL Flexible Modeling System (FMS).
6 #* FMS is free software: you can redistribute it and/or modify it under
7 #* the terms of the GNU Lesser General Public License as published by
8 #* the Free Software Foundation, either version 3 of the License, or (at
9 #* your option) any later version.
11 #* FMS is distributed in the hope that it will be useful, but WITHOUT
12 #* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 #* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #* You should have received a copy of the GNU Lesser General Public
17 #* License along with FMS. If not, see <http://www.gnu.org/licenses/>.
18 #***********************************************************************
20 # ===========================================================================
24 # GX_FC_DEFAULT_REAL_KIND8_FLAG([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
25 # GX_FC_DEFAULT_REAL_KIND4_FLAG([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
26 # GX_FC_QUAD_PRECISION()
27 # GX_FC_CRAY_POINTER_FLAG([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
28 # GX_FC_INTERNAL_FILE_NML()
29 # GX_FC_CHECK_MOD(module-name, [only], [action-if-found], [action-if-not-found])
33 # Set of functions that check if the Fortran compiler supports certain
34 # Fortran feature, or if a specific compiler flag is needed to support
35 # the feature. Full descriptions are avalable below.
39 # Copyright (c) 2019,2020 Seth Underwood <underwoo@underwoo.io>
41 # This program is free software; you can redistribute it and/or modify it
42 # under the terms of the GNU General Public License as published by the
43 # Free Software Foundation; either version 3 of the License, or (at your
44 # option) any later version.
46 # This program is distributed in the hope that it will be useful, but
47 # WITHOUT ANY WARRANTY; without even the implied warranty of
48 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
49 # Public License for more details.
51 # You should have received a copy of the GNU General Public License along
52 # with this program. If not, see <https://www.gnu.org/licenses/>.
54 # As a special exception, the respective Autoconf Macro's copyright owner
55 # gives unlimited permission to copy, distribute and modify the configure
56 # scripts that are the output of Autoconf when processing the Macro. You
57 # need not follow the terms of the GNU General Public License when using
58 # or distributing such scripts, even though portions of the text of the
59 # Macro appear in them. The GNU General Public License (GPL) does govern
60 # all other use of the material that constitutes the Autoconf Macro.
62 # GX_FC_DEFAULT_REAL_KIND8_FLAG([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
63 # ----------------------------------------------------------------------
64 # Look for the compiler flag that sets the default REAL kind to KIND=8.
65 # Call ACTION-IF-SUCCESS (defaults to nothing) if successful (i.e. can
66 # compile with default REAL(KIND=8)) and ACTION-IF-FAILURE (defaults
67 # to failing with an error message) if not.
69 # Sets the variable FC_DEFAULT_REAL_KIND8_FLAG to hold the flag.
71 # The known flags are:
72 # -fdefault-real-8: gfortran
73 # -real-size 64: Intel compiler
74 # -real_size 64: Intel compiler
76 # -r8: Portland Group compiler
77 # -qrealsize=8: IBM compiler
78 AC_DEFUN([GX_FC_DEFAULT_REAL_KIND8_FLAG],[
79 AC_LANG_PUSH([Fortran])
80 AC_CACHE_CHECK([for Fortran flag needed to accept default REAL(KIND=8)], [gx_cv_fc_default_real_kind8_flag],[
81 gx_cv_fc_default_real_kind8_flag=unknown
82 gx_fc_default_real_kind8_flag_FCFLAGS_save=$FCFLAGS
90 test "x$ac_flag" != xnone && FCFLAGS="$gx_fc_default_real_kind8_flag_FCFLAGS_save ${ac_flag}"
91 AC_COMPILE_IFELSE([[ program test
93 subroutine test_sub(a)
94 real(kind=selected_real_kind(15,307)) :: a
95 end subroutine test_sub
100 [gx_cv_fc_default_real_kind8_flag=$ac_flag; break])
102 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
103 FCFLAGS=$gx_fc_default_real_kind8_flag_FCFLAGS_save
105 if test "x$gx_cv_fc_default_real_kind8_flag" = xunknown; then
107 [AC_MSG_ERROR([Fortran cannot set default real kind to 8])])
109 FC_DEFAULT_REAL_KIND8_FLAG=$gx_cv_fc_default_real_kind8_flag
110 if test "x$FC_DEFAULT_REAL_KIND8_FLAG" = xnone; then
111 FC_DEFAULT_REAL_KIND8_FLAG=
115 AC_LANG_POP([Fortran])
116 AC_SUBST([FC_DEFAULT_REAL_KIND8_FLAG])
119 # GX_FC_DEFAULT_REAL_KIND4_FLAG([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
120 # ----------------------------------------------------------------------
121 # Look for the compiler flag that sets the default REAL kind to KIND=4.
122 # Call ACTION-IF-SUCCESS (defaults to nothing) if successful (i.e. can
123 # compile with default REAL(KIND=4)) and ACTION-IF-FAILURE (defaults
124 # to failing with an error message) if not.
126 # Sets the variable FC_DEFAULT_REAL_KIND4_FLAG to hold the flag.
128 # The known flags are:
129 # none: gfortran (gfortran does not have an option to set the
130 # default REAL kind to KIND=4)
131 # -real-size 32: Intel compiler
132 # -real_size 32: Intel compiler
134 # -r4: Portland Group compiler
135 # -qrealsize=4: IBM compiler
136 AC_DEFUN([GX_FC_DEFAULT_REAL_KIND4_FLAG],[
137 AC_LANG_PUSH([Fortran])
138 AC_CACHE_CHECK([for Fortran flag needed to accept default REAL(KIND=4)], [gx_cv_fc_default_real_kind4_flag],[
139 gx_cv_fc_default_real_kind4_flag=unknown
140 gx_fc_default_real_kind4_flag_FCFLAGS_save=$FCFLAGS
141 for ac_flag in none \
148 test "x$ac_flag" != xnone && FCFLAGS="$gx_fc_default_real_kind4_flag_FCFLAGS_save ${ac_flag}"
149 AC_COMPILE_IFELSE([[ program test
151 subroutine test_sub(a)
152 real(kind=selected_real_kind(6, 37)) :: a
153 end subroutine test_sub
158 [gx_cv_fc_default_real_kind4_flag=$ac_flag; break])
160 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
161 FCFLAGS=$gx_fc_default_real_kind4_flag_FCFLAGS_save
163 if test "x$gx_cv_fc_default_real_kind4_flag" = xunknown; then
165 [AC_MSG_ERROR([Fortran cannot set default real kind to 4])])
167 FC_DEFAULT_REAL_KIND4_FLAG=$gx_cv_fc_real_kind4_flag
168 if test "x$FC_DEFAULT_REAL_KIND4_FLAG" = xnone; then
169 FC_DEFAULT_REAL_KIND4_FLAG=
173 AC_LANG_POP([Fortran])
174 AC_SUBST([FC_DEFAULT_REAL_KIND4_FLAG])
177 # GX_FC_QUAD_PRECISION
178 # -----------------------------------------------------------------------------
179 # Determine if the Fortran compiler and target system have support for IEEE 754,
180 # quadruple precision. If supported, sets the define HAVE_QUAD_PRECISION.
181 AC_DEFUN([GX_FC_QUAD_PRECISION],[
182 AC_LANG_PUSH([Fortran])
183 AC_CACHE_CHECK([if Fortran and target have IEEE 754 support], [gx_cv_fc_quad_precision],[
184 gx_cv_fc_quad_precision=unknown
185 AC_COMPILE_IFELSE([[ program test
186 real(KIND=selected_real_kind(33, 4931)) :: quad
188 [gx_cv_fc_quad_precision=yes],
189 [gx_cv_fc_quad_precision=no])])
190 if test "x$gx_cv_fc_quad_precision" = "xyes"; then
191 AC_DEFINE([HAVE_QUAD_PRECISION], 1,
192 [Define to 1 if your Fortran and system have IEEE 754 support])
194 AC_LANG_POP([Fortran])
197 # GX_FC_CRAY_POINTER_FLAG([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
198 # -----------------------------------------------------------------------------
199 # Look for the compiler flag that allows Fortran Cray Pointers. Cray
200 # pointers are an are part of a non-standard extension that provides a
201 # C-like pointer in Fortran. Call ACTION-IF-SUCCESS (defaults to
202 # nothing) if successful (i.e. can use Cray pointers) and
203 # ACTION-IF-FAILURE (defaults to failing with an error message) if not.
205 # Sets the variable FC_CRAY_POINTER_FLAG to hold the flag, and defines
208 # The known flags are:
209 # -fcray-pointer: gfortran
210 # none: Intel compiler (No option required for Cray Pointers)
212 # -Mcray=pointer: Portland Group compiler
213 # none: IBM compiler (No option required for Cray Pointers)
214 AC_DEFUN([GX_FC_CRAY_POINTER_FLAG],[
215 AC_LANG_PUSH([Fortran])
216 AC_CACHE_CHECK([for Fortran flag needed to accept Cray pointers], [gx_cv_fc_cray_ptr_flag],[
217 gx_cv_fc_cray_ptr_flag=unknown
218 gx_cray_ptr_flag_FCFLAGS_save=$FCFLAGS
219 for ac_flag in none \
222 test "x$ac_flag" != xnone && FCFLAGS="$gx_cray_ptr_flag_FCFLAGS_save ${ac_flag}"
223 AC_COMPILE_IFELSE([[ program test
227 [gx_cv_fc_cray_ptr_flag=$ac_flag; break])
229 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
230 FCFLAGS=$gx_cray_ptr_flag_FCFLAGS_save
232 if test "x$gx_cv_fc_cray_ptr_flag" = "xunknown"; then
234 [AC_MSG_ERROR([Fortran cannot use Cray pointers])])
236 AC_DEFINE([HAVE_CRAY_POINTER], 1,
237 [Define to 1 if your Fortran compiler supports cray pointers])
238 FC_CRAY_POINTER_FLAG=$gx_cv_fc_cray_ptr_flag
239 if test "x$FC_CRAY_POINTER_FLAG" = xnone; then
240 FC_CRAY_POINTER_FLAG=
244 AC_LANG_POP([Fortran])
245 AC_SUBST([FC_CRAY_POINTER_FLAG])
248 # GX_FC_INTERNAL_FILE_NML
249 # -----------------------------------------------------------------------------
250 # Determine if the Fortran compiler supports reading Fortran namelists from
251 # an internal file. If supported, sets the define HAVE_INTERNAL_NML.
252 AC_DEFUN([GX_FC_INTERNAL_FILE_NML],[
253 AC_LANG_PUSH([Fortran])
254 AC_CACHE_CHECK([if $[]_AC_FC[] supports reading namelists from internal files], [gx_cv_fc_internal_file_nml],[
255 gx_cv_fc_internal_file_nml=unknown
256 AC_COMPILE_IFELSE([[ program test
260 character(LEN=20) :: internal_nml ="&test_nml a=2 b=1.0/"
261 namelist /test_nml/ a, b
262 read(internal_nml,test_nml)
264 [gx_cv_fc_internal_file_nml=yes],
265 [gx_cv_fc_internal_file_nml=no])])
266 if test "x$gx_cv_fc_internal_file_nml" = "xyes"; then
267 AC_DEFINE([HAVE_INTERNAL_NML], 1,
268 [Define to 1 if your Fortran compiler supports reading namelists
269 from internal files])
271 AC_LANG_POP([Fortran])
274 # GX_FC_CHECK_MOD(module-name, [only], [action-if-found], [action-if-not-found])
275 # -----------------------------------------------------------------------------
276 # Check if a Fortran module module-name is available. Execute shell commands
277 # action-if-found, otherwise execute action-if-not-found. If only is specified
278 # then check if the Fortran module has the given symbol.
279 AC_DEFUN([GX_FC_CHECK_MOD],[
280 _AC_FORTRAN_ASSERT()dnl
281 m4_ifval([$2],[gx_fc_check_mod_only=",only:$2"],[gx_fc_check_mod_only=""])
282 AS_LITERAL_WORD_IF([$1],
283 [AS_VAR_PUSHDEF([gx_mod], [gx_cv_fc_check_mod_$1])],
284 [AS_VAR_PUSHDEF([gx_mod], AS_TR_SH([gx_cv_check_mod_$1]))])
285 dnl Autoconf does not pass CPPFLAGS to the Fortran tests. As the user may
286 dnl define the include options in CPPFLAGS instead of FFLAGS or FCFLAGS, we
287 dnl force CPPFLAGS te be part of FFLAGS/FCFLAGS
288 gx_save_[]_AC_LANG_PREFIX[]FLAGS=${[]_AC_LANG_PREFIX[]FLAGS}
289 _AC_LANG_PREFIX[]FLAGS="${[]_AC_LANG_PREFIX[]FLAGS} $CPPFLAGS"
290 AC_CACHE_CHECK([for Fortran module $1], [gx_mod],
291 [AC_COMPILE_IFELSE([[ program test
292 use $1$gx_fc_check_mod_only
294 [AS_VAR_SET([gx_mod], [yes])],
295 [AS_VAR_SET([gx_mod], [no])])])
296 _AC_LANG_PREFIX[]FLAGS="${gx_save_[]_AC_LANG_PREFIX[]FLAGS}"
297 AS_VAR_IF([gx_mod], [yes],
299 [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_MOD_$1), 1, [Define to 1 if the Fortran module $1 is found])])],
301 AS_VAR_POPDEF([gx_mod])
304 # GX_FORTRAN_CHECK_HEADERS(header, [action-if-found], [action-if-not-found])
305 # -----------------------------------------------------------------------
306 # Check if a Fortran include file is available.
307 AC_DEFUN([GX_FORTRAN_CHECK_HEADERS], [
308 _AC_FORTRAN_ASSERT()dnl
309 AS_LITERAL_WORD_IF([$1],
310 [AS_VAR_PUSHDEF([gx_header], [gx_cv_fortran_check_headers_$1])],
311 [AS_VAR_PUSHDEF([gx_header], [AS_TR_SH([gx_cv_fortran_check_headers_$1])])])
312 dnl Ensure the Fortran compiler will run the preprocessor
313 _GX_FORTRAN_PP_SRCEXT_PUSH([F])
314 dnl Autoconf does not pass CPPFLAGS to the Fortran tests. As the user may
315 dnl define the include options in CPPFLAGS instead of FFLAGS or FCFLAGS, we
316 dnl force CPPFLAGS te be part of FFLAGS/FCFLAGS
317 gx_save_[]_AC_LANG_PREFIX[]FLAGS=${[]_AC_LANG_PREFIX[]FLAGS}
318 _AC_LANG_PREFIX[]FLAGS="${[]_AC_LANG_PREFIX[]FLAGS} $CPPFLAGS"
319 AC_CACHE_CHECK([for $1 usability], [gx_header],
320 [AC_COMPILE_IFELSE(AC_LANG_PROGRAM([],
322 [AS_VAR_SET([gx_header], [yes])],
323 [AS_VAR_SET([gx_header], [no])])])
324 _AC_LANG_PREFIX[]FLAGS="${gx_save_[]_AC_LANG_PREFIX[]FLAGS}"
325 _GX_FORTRAN_PP_SRCEXT_POP([F])
326 AS_VAR_IF([gx_header], [yes],
328 [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$1), 1, [Define to 1 if the Fortran include file $1 is found])])],
330 AS_VAR_POPDEF([gx_header])
331 ])# GX_FC_CHECK_HEADERS
333 # GX_FORTRAN_SEARCH_LIBS(FUNCTION, SEARCH-LIBS, [CALL_PREFIX], [CALL_SYNTAX],
334 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
336 # ------------------------------------------------------------------------------
337 # Search for a Fortran library defining FUNCTION, if it's not already availabe.
339 # This expands AC_SEARCH_LIBS for Fortran as the AC function does not work in
340 # all cases for Fortran.
341 AC_DEFUN([GX_FORTRAN_SEARCH_LIBS], [
342 _AC_FORTRAN_ASSERT()dnl
343 AS_VAR_PUSHDEF([gx_search], [gx_cv_fortran_search_libs_$1])
344 dnl Ensure the Fortran compiler will run the preprocessor
345 _GX_FORTRAN_PP_SRCEXT_PUSH([F])
346 dnl Autoconf does not pass CPPFLAGS to the Fortran tests. As the user may
347 dnl define the include options in CPPFLAGS instead of FFLAGS or FCFLAGS, we
348 dnl force CPPFLAGS te be part of FFLAGS/FCFLAGS
349 gx_save_FLAGS="${[]_AC_LANG_PREFIX[]FLAGS}"
350 _AC_LANG_PREFIX[]FLAGS="${[]_AC_LANG_PREFIX[]FLAGS} $CPPFLAGS"
351 dnl Prepare the prefix and syntax sections so they will compile correctly
352 dnl with the Fortran compiler
353 m4_foreach(gx_line, m4_split($3, m4_newline()),
354 [m4_append([_gx_fortran_sanitized_call_prefix], m4_bmatch(gx_line, [^\w.*], [ ]gx_line, [gx_line]), m4_newline())dnl
356 gx_fortran_sanitized_call_prefix="_gx_fortran_sanitized_call_prefix"
357 gx_fortran_func_line="m4_bregexp([$4], [^.*$], [ \&])"
358 AC_CACHE_CHECK([for library containing $1], [gx_search],
359 [gx_fortran_search_libs_save_LIBS=$LIBS
360 AC_LANG_CONFTEST([AC_LANG_PROGRAM([],[[$gx_fortran_sanitized_call_prefix
361 $gx_fortran_func_line]])])
362 dnl Search for the library
363 for gx_lib in '' $2; do
364 if test -z "$gx_lib"; then
365 gx_res="none required"
368 LIBS="$gx_res $7 $gx_fortran_search_libs_save_LIBS"
370 AC_LINK_IFELSE([], [AS_VAR_SET([gx_search], [$gx_res])])
371 AS_VAR_SET_IF([gx_search], [break])
373 AS_VAR_SET_IF([gx_search], , [AS_VAR_SET([gx_search], [no])])
375 LIBS=$gx_fortran_search_libs_save_LIBS])
376 AS_VAR_COPY([gx_res], [gx_search])
377 AS_IF([test "$gx_res" != no],
378 [test "$gx_res" = "none required" || LIBS="$gx_res $LIBS"
381 _AC_LANG_PREFIX[]FLAGS="$gx_save_FLAGS"
382 _GX_FORTRAN_PP_SRCEXT_POP([F])
383 AS_VAR_POPDEF([gx_search])
384 m4_ifdef([gx_line], [m4_undefine([gx_line])])
385 m4_ifdef([_gx_fortran_sanitized_call_prefix], [m4_undefine([_gx_fortran_sanitized_call_prefix])])
386 ])# GX_FORTRAN_SEARCH_LIBS
388 # _GX_FORTRAN_PP_SRCEXT_PUSH(EXT) will ensure the Fortran test extension (stored
389 # in ac_ext) will cause the Fortran compiler to preprocess the test source file.
390 # Most Fortran compilers will preprocess the file based on the file extension,
391 # and of the known extension, F appears to work for all compilers. This
392 # function accepts the file extension (without the preceeding .), similar
393 # to the AC_FC_SRCEXT and AC_FC_PP_SRCEXT macros. If the extension is not
394 # provided, the default is 'F'.
395 # Unfortunately, this will not work for compilers that require a specific flag.
396 AC_DEFUN([_GX_FORTRAN_PP_SRCEXT_PUSH],[
397 _gx_fortran_pp_srcext_save=$ac_ext
398 AS_VAR_SET_IF([1], [ac_ext=$1], [ac_ext="F"])
399 ])# _GX_FORTRAN_PP_SRCEXT_PUSH
401 # _GX_FORTRAN_PP_SRCEXT_POP() reverses the extension change done in
402 # _GX_FORTRAN_PP_SRCEXT_PUSH. If this pop is called without a preceeding
403 # push, the default Fortran file extension (f) will be used.
404 AC_DEFUN([_GX_FORTRAN_PP_SRCEXT_POP], [
405 AS_VAR_SET_IF([_gx_fortran_pp_srcext_save], [ac_ext=${_gx_fortran_pp_srcext_save}], [ac_ext="f"])
406 unset _gx_fortran_pp_srcext_save
407 ])# _GX_FORTRAN_PP_SRCEXT_POP