forked from ICTP/RegCM
-
Notifications
You must be signed in to change notification settings - Fork 1
/
acinclude.m4
443 lines (389 loc) · 12.7 KB
/
acinclude.m4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
dnl
dnl autoconf macro for detecting NetCDF
dnl
AC_DEFUN([AX_PROG_NC_CONFIG], [
AC_REQUIRE([AC_PROG_EGREP])
AC_CACHE_CHECK([if nc-config program is present],[ax_cv_prog_nc_config],[
AS_IF([nc-config --version 2>/dev/null | egrep -q '^netCDF '],
[ax_cv_prog_nc_config=yes], [ax_cv_prog_nc_config=no])
])
AS_IF([test "$ax_cv_prog_nc_config" = "yes"], [[$1]], [[$2]])
])
AC_DEFUN([AX_PROG_NF_CONFIG], [
AC_REQUIRE([AC_PROG_EGREP])
AC_CACHE_CHECK([if nf-config program is present],[ax_cv_prog_nf_config],[
AS_IF([nf-config --version 2>/dev/null | egrep -q '.*'],
[ax_cv_prog_nf_config=yes], [ax_cv_prog_nf_config=no])
])
AS_IF([test "$ax_cv_prog_nf_config" = "yes"], [[$1]], [[$2]])
])
AC_DEFUN([RR_PATH_NETCDF],[
AC_CHECKING([for NetCDF])
save_CPPFLAGS="$CPPFLAGS"
save_LDFLAGS="$LDFLAGS"
CPPFLAGS="$CPPFLAGS $NC_INCLUDES"
AMDEPFLAGS="$AMDEPFLAGS $NC_INCLUDES"
LIBS="$LIBS $NC_LIBS"
LDFLAGS="$LDFLAGS $NC_LDFLAGS"
AC_SUBST([AMDEPFLAGS])
netcdf=no
AC_LANG_PUSH([C])
AC_CHECKING([for netcdf.h])
AC_CHECK_HEADER([netcdf.h],
[netcdf=yes], [netcdf=no])
if test "x$netcdf" = xno; then
AC_MSG_ERROR([NetCDF include not found])
fi
AC_CHECKING([for libnetcdf.a])
AC_CHECK_LIB([netcdf], [nc_close],
[netcdf=yes], [netcdf=no])
if test "x$netcdf" = xno; then
AC_CHECKING([if we need to link jpeg library for HDF4])
LDFLAGS="$LDFLAGS $NC_LDFLAGS"
LIBS="$LIBS -ljpeg"
AC_CHECK_LIB([netcdf], [nc_enddef],
[netcdf=yes], [netcdf=no])
if test "x$netcdf" = xno; then
AC_CHECKING([if we need to link hdf5 library])
NC_LDFLAGS="$NC_LDFLAGS -L$HDF5_PREFIX/lib"
LDFLAGS="$LDFLAGS $NC_LDFLAGS"
LIBS="$LIBS -lhdf5 -lhdf5_hl"
AC_CHECK_LIB([netcdf], [nc_sync],
[netcdf=yes], [netcdf=no])
if test "x$netcdf" = xno; then
AC_CHECKING([if we need to link szlib library])
NC_LDFLAGS="$NC_LDFLAGS -L$SZIP_PREFIX/lib"
LDFLAGS="$LDFLAGS $NC_LDFLAGS"
LIBS="$LIBS -lsz"
AC_CHECK_LIB([netcdf], [nc_inq_libvers],
[netcdf=yes], [netcdf=no])
fi
fi
if test "x$netcdf" = xno; then
AC_MSG_ERROR([NetCDF library not found])
fi
fi
# Put them back to how they used to be and set the AM versions
# The AM versions must be substituted explicitly
CPPFLAGS="$save_CPPFLAGS"
LDFLAGS="$save_LDFLAGS"
AM_CPPFLAGS="$NC_INCLUDES $AM_CPPFLAGS"
AM_LDFLAGS="$NC_LDFLAGS $AM_LDFLAGS"
AC_SUBST([AM_CPPFLAGS])
AC_SUBST([AM_LDFLAGS])
AC_LANG_POP([C])
# Netcdf Fortran interface can be placed in a separate libnetcdff
#
LDFLAGS="$LDFLAGS $NC_LDFLAGS"
AC_CHECKING([for libnetcdff.a])
AC_CHECK_LIB([netcdf], [nf_close],
[netcdf=yes], [netcdf=no])
if test "x$netcdf" = xno; then
LIBS="-lnetcdff $LIBS"
AC_CHECKING([for libnetcdff.a])
AC_CHECK_LIB([netcdff], [nf_close],
[netcdf=yes], [netcdf=no])
if test "x$netcdf" = xno; then
AC_MSG_ERROR([NetCDF library not found])
fi
fi
LDFLAGS="$save_LDFLAGS"
])
dnl
dnl autoconf macro for detecting NetCDF module file
dnl
AC_DEFUN([RR_PATH_NETCDF_F90],[
AC_CHECKING([for NetCDF module file])
save_FCFLAGS="$FCFLAGS"
if test -z "$NC_INCLUDES"; then
for flag in "-I" "-M" "-p"; do
FCFLAGS="$flag$NC_PREFIX/include $save_FCFLAGS"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[ ]],
[[ use netcdf]])],
[netcdf=yes; NC_FCFLAGS=$flag],
[netcdf=no])
if test "x$netcdf" = xyes; then
break
fi
done
if test "x$netcdf" = xno; then
AC_MSG_ERROR([NetCDF module not found])
fi
FCFLAGS="$save_FCFLAGS"
AM_CPPFLAGS="$NC_FCFLAGS$NC_PREFIX/include $AM_CPPFLAGS"
else
FCFLAGS="$NC_INCLUDES $save_FCFLAGS"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[ ]],
[[ use netcdf]])],
[netcdf=yes],
[netcdf=no])
if test "x$netcdf" = xno; then
AC_MSG_ERROR([NetCDF module not found])
fi
FCFLAGS="$save_FCFLAGS"
AM_CPPFLAGS="$NC_INCLUDES $AM_CPPFLAGS"
fi
AC_SUBST([AM_CPPFLAGS])
])
AC_DEFUN([RR_CDF5],[
AC_CHECKING([for NetCDF CDF5])
save_FCFLAGS="$FCFLAGS"
if test -z "$NC_INCLUDES"; then
for flag in "-I" "-M" "-p"; do
FCFLAGS="$flag$NC_PREFIX/include $save_FCFLAGS"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[ ]],
[[
use netcdf
implicit none
integer :: imode
imode = nf90_cdf5]])],
[cdf5=yes],
[cdf5=no])
if test "x$cdf5" = xyes; then
AM_CPPFLAGS="-DNETCDF_CDF5 $AM_CPPFLAGS"
break
fi
done
FCFLAGS="$save_FCFLAGS"
else
FCFLAGS="$NC_INCLUDES $save_FCFLAGS"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[ ]],
[[
use netcdf
implicit none
integer :: imode
imode = nf90_cdf5]])],
[cdf5=yes],
[cdf5=no])
if test "x$cdf5" = xyes; then
AM_CPPFLAGS="-DNETCDF_CDF5 $AM_CPPFLAGS"
fi
FCFLAGS="$save_FCFLAGS"
fi
AC_SUBST([AM_CPPFLAGS])
])
dnl @synopsis ACX_MPI([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
dnl
dnl @summary figure out how to compile/link code with MPI
dnl
dnl This macro tries to find out how to compile programs that use MPI
dnl (Message Passing Interface), a standard API for parallel process
dnl communication (see http://www-unix.mcs.anl.gov/mpi/)
dnl
dnl On success, it sets the MPICC, MPICXX, or MPIF77 output variable to
dnl the name of the MPI compiler, depending upon the current language.
dnl (This may just be $CC/$CXX/$F77, but is more often something like
dnl mpicc/mpiCC/mpif77.) It also sets MPILIBS to any libraries that are
dnl needed for linking MPI (e.g. -lmpi, if a special
dnl MPICC/MPICXX/MPIF77 was not found).
dnl
dnl If you want to compile everything with MPI, you should set:
dnl
dnl CC="$MPICC" #OR# CXX="$MPICXX" #OR# F77="$MPIF77"
dnl LIBS="$MPILIBS $LIBS"
dnl
dnl NOTE: The above assumes that you will use $CC (or whatever) for
dnl linking as well as for compiling. (This is the default for automake
dnl and most Makefiles.)
dnl
dnl The user can force a particular library/compiler by setting the
dnl MPICC/MPICXX/MPIF77 and/or MPILIBS environment variables.
dnl
dnl ACTION-IF-FOUND is a list of shell commands to run if an MPI
dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
dnl default action will define HAVE_MPI.
dnl
dnl @category InstalledPackages
dnl @author Steven G. Johnson <[email protected]>
dnl @author Julian Cummings <[email protected]>
dnl @version 2006-10-13
dnl @license GPLWithACException
AC_DEFUN([ACX_MPI], [
AC_PREREQ(2.50) dnl for AC_LANG_CASE
AC_LANG_CASE([C], [
AC_REQUIRE([AC_PROG_CC])
AC_ARG_VAR(MPICC,[MPI C compiler command])
AC_CHECK_PROGS(MPICC, mpicc hcc mpxlc_r mpxlc mpcc cmpicc, $CC)
acx_mpi_save_CC="$CC"
CC="$MPICC"
AC_SUBST(MPICC)
],
[C++], [
AC_REQUIRE([AC_PROG_CXX])
AC_ARG_VAR(MPICXX,[MPI C++ compiler command])
AC_CHECK_PROGS(MPICXX, mpic++ mpicxx mpiCC hcp mpxlC_r mpxlC mpCC cmpic++, $CXX)
acx_mpi_save_CXX="$CXX"
CXX="$MPICXX"
AC_SUBST(MPICXX)
],
[Fortran 77], [
AC_REQUIRE([AC_PROG_F77])
AC_ARG_VAR(MPIF77,[MPI Fortran 77 compiler command])
AC_CHECK_PROGS(MPIF77, mpif77 hf77 mpxlf mpf77 mpif90 mpf90 mpixlf90 mpixlf95 mpixlf_r cmpifc cmpif90c, $F77)
acx_mpi_save_F77="$F77"
F77="$MPIF77"
AC_SUBST(MPIF77)
],
[Fortran], [
AC_REQUIRE([AC_PROG_FC])
AC_ARG_VAR(MPIFC,[MPI Fortran compiler command])
AC_CHECK_PROGS(MPIFC, mpifort mpiifort mpixfl2003 mpixlf2008 mpf90 cmpifc cmpif90c hf90 mpif90, $FC)
acx_mpi_save_FC="$FC"
FC="$MPIFC"
AC_SUBST(MPIFC)
])
if test x = x"$MPILIBS"; then
AC_LANG_CASE([C], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])],
[C++], [AC_CHECK_FUNC(MPI_Init, [MPILIBS=" "])],
[Fortran 77], [AC_MSG_CHECKING([for MPI_Init])
AC_LINK_IFELSE([AC_LANG_PROGRAM([],[ call MPI_Init])],[MPILIBS=" "
AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])],
[Fortran], [AC_MSG_CHECKING([for MPI_Init])
AC_LINK_IFELSE([AC_LANG_PROGRAM([],[ call MPI_Init])],[MPILIBS=" "
AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])])
fi
AC_LANG_CASE([Fortran 77], [
if test x = x"$MPILIBS"; then
AC_CHECK_LIB(fmpi, MPI_Init, [MPILIBS="-lfmpi"])
fi
if test x = x"$MPILIBS"; then
AC_CHECK_LIB(fmpich, MPI_Init, [MPILIBS="-lfmpich"])
fi
],
[Fortran], [
if test x = x"$MPILIBS"; then
AC_CHECK_LIB(fmpi, MPI_Init, [MPILIBS="-lfmpi"])
fi
if test x = x"$MPILIBS"; then
AC_CHECK_LIB(mpichf90, MPI_Init, [MPILIBS="-lmpichf90"])
fi
])
if test x = x"$MPILIBS"; then
AC_CHECK_LIB(mpi, MPI_Init, [MPILIBS="-lmpi"])
fi
if test x = x"$MPILIBS"; then
AC_CHECK_LIB(mpich, MPI_Init, [MPILIBS="-lmpich"])
fi
dnl We have to use AC_TRY_COMPILE and not AC_CHECK_HEADER because the
dnl latter uses $CPP, not $CC (which may be mpicc).
AC_LANG_CASE([C], [if test x != x"$MPILIBS"; then
AC_MSG_CHECKING([for mpi.h])
AC_TRY_COMPILE([#include <mpi.h>],[],[AC_MSG_RESULT(yes)], [MPILIBS=""
AC_MSG_RESULT(no)])
fi],
[C++], [if test x != x"$MPILIBS"; then
AC_MSG_CHECKING([for mpi.h])
AC_TRY_COMPILE([#include <mpi.h>],[],[AC_MSG_RESULT(yes)], [MPILIBS=""
AC_MSG_RESULT(no)])
fi],
[Fortran 77], [if test x != x"$MPILIBS"; then
AC_MSG_CHECKING([for mpif.h])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[ include 'mpif.h'])],[AC_MSG_RESULT(yes)], [MPILIBS=""
AC_MSG_RESULT(no)])
fi],
[Fortran], [if test x != x"$MPILIBS"; then
AC_MSG_CHECKING([for mpif.h])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[ include 'mpif.h'])],[AC_MSG_RESULT(yes)], [MPILIBS=""
AC_MSG_RESULT(no)])
fi])
AC_LANG_CASE([C], [CC="$acx_mpi_save_CC"],
[C++], [CXX="$acx_mpi_save_CXX"],
[Fortran 77], [F77="$acx_mpi_save_F77"],
[Fortran], [FC="$acx_mpi_save_FC"])
AC_SUBST(MPILIBS)
# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
if test x = x"$MPILIBS"; then
$2
:
else
ifelse([$1],,[AC_DEFINE(HAVE_MPI,1,[Define if you have the MPI library.])],[$1])
:
fi
])dnl ACX_MPI
dnl
dnl autoconf macro for detecting pNetCDF
dnl
AC_DEFUN([AX_PROG_PNETCDF_CONFIG], [
AC_REQUIRE([AC_PROG_EGREP])
AC_CACHE_CHECK([if pnetcdf-config program is present],[ax_cv_prog_pnetcdf_config],[
AS_IF([pnetcdf-config --version 2>/dev/null | egrep -q '^PnetCDF '],
[ax_cv_prog_pnetcdf_config=yes], [ax_cv_prog_pnetcdf_config=no])
])
AS_IF([test "$ax_cv_prog_pnetcdf_config" = "yes"], [[$1]], [[$2]])
])
AC_DEFUN([RR_PATH_PNETCDF],[
AC_CHECKING([for Parallel NetCDF])
save_CPPFLAGS="$CPPFLAGS"
save_FCFLAGS="$FCFLAGS"
save_LDFLAGS="$LDFLAGS"
CPPFLAGS="$CPPFLAGS $NC_INCLUDES"
FCFLAGS="$CPPFLAGS $NC_INCLUDES"
AMDEPFLAGS="$AMDEPFLAGS $NC_INCLUDES"
LIBS="$LIBS $NC_LIBS"
LDFLAGS="$LDFLAGS $NC_LDFLAGS"
AC_SUBST([AMDEPFLAGS])
pnetcdf=no
AC_LANG_PUSH([C])
AC_CHECKING([for pnetcdf.h])
AC_CHECK_HEADER([pnetcdf.h],
[pnetcdf=yes], [pnetcdf=no])
if test "x$pnetcdf" = xno; then
AC_MSG_ERROR([Parallel NetCDF include not found])
fi
AC_CHECKING([for libpnetcdf.a])
AC_CHECK_LIB([pnetcdf], [ncmpi_close],
[pnetcdf=yes], [pnetcdf=no])
if test "x$pnetcdf" = xno; then
AC_MSG_ERROR([Parallel NetCDF library not found])
fi
AC_LANG_POP([C])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[ ]],
[[
use pnetcdf
implicit none
integer :: imode
imode = nf90_cdf5]])],
[cdf5=yes],
[cdf5=no])
if test "x$cdf5" = xyes; then
AM_CPPFLAGS="-DNETCDF_CDF5 $AM_CPPFLAGS"
fi
# Put them back to how they used to be and set the AM versions
# The AM versions must be substituted explicitly
CPPFLAGS="$save_CPPFLAGS"
FCFLAGS="$save_FCFLAGS"
LDFLAGS="$save_LDFLAGS"
AM_CPPFLAGS="$NC_INCLUDES $AM_CPPFLAGS"
AM_LDFLAGS="$NC_LDFLAGS $AM_LDFLAGS"
AC_SUBST([AM_CPPFLAGS])
AC_SUBST([AM_LDFLAGS])
])
AC_DEFUN([RCM_FC_CHECK_IEEE_ARITHMETIC],[
# Init
fc_has_ieee_arithmetic="no"
AC_MSG_CHECKING([whether the Fortran compiler supports IEEE_ARITHMETIC])
# Try to compile a piece of code that uses the module.
AC_LANG_PUSH([Fortran])
AC_LINK_IFELSE([AC_LANG_PROGRAM([],
[[
use, intrinsic :: ieee_arithmetic
real :: val
if (ieee_is_nan(val)) then ! NaN
write(*,*)"Hello NAN"
end if
]])], [fc_has_ieee_arithmetic="yes"])
AC_LANG_POP([Fortran])
if test "${fc_has_ieee_arithmetic}" = "yes"; then
AC_DEFINE([HAVE_FC_IEEE_ARITHMETIC],1,
[Define to 1 if your Fortran compiler supports IEEE_ARITHMETIC module.])
FCFLAGS="-DF2008 $FCFLAGS"
AC_SUBST(FCFLAGS)
fi
AC_MSG_RESULT([${fc_has_ieee_arithmetic}])
]) # RCM_FC_CHECK_IEEE_ARITHMETIC