forked from wrf-model/WPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·545 lines (486 loc) · 16.5 KB
/
configure
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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
#!/bin/sh
print_help()
{
echo 'Usage: configure [options]'
echo ''
echo 'where options may be any of the following:'
echo ''
echo ' --nowrf Disables checks to find the path to the compiled WRF model.'
echo ' This enables some WPS programs to be compiled without'
echo ' requiring WRF to have been compiled, but it will preclude'
echo ' the compilation of WPS programs that depend on the WRF I/O'
echo ' API (geogrid, metgrid, and int2nc).'
echo ''
echo ' --build-grib2-libs Compiles zlib, libpng, and JasPer libraries from source in'
echo ' the external/ directory, and installs the libraries in'
echo ' grib2/.'
echo ''
echo ' -h/--help Print this help message and quit.'
}
#
# Check for command-line arguments
# At present, the only supported arguments are:
# --nowrf : disables checks to find the path to the compiled WRF model
# --build-grib2-libs : compiles zlib, libpng, and JasPer libraries from
# source in the external/ directory and installs
# the libraries in grib2/
#
nowrf=0
build_grib2=0
for arg in $@; do
if [ "${arg}" = "--nowrf" ]; then
nowrf=1
elif [ "${arg}" = "--build-grib2-libs" ]; then
build_grib2=1
elif [ "${arg}" = "--help" ] || [ "${arg}" = "-h" ]; then
print_help
exit
else
printf "Unrecognized option %s\n" ${arg}
fi
done
# Look for netcdf
if test -z "$NETCDF" ; then
for p in /usr/local/netcdf
do
if test -d $p ; then
NETCDF=$p
break
fi
done
fi
if test -z "$NETCDF" ; then
if [ `hostname | cut -c 1-2` = "bs" -o \
`hostname | cut -c 1-2` = "bv" -o \
`hostname` = "tempest" -o `hostname` = "lightning" ] ; then
echo 'Compiling on an NCAR system with weird paths to NetCDF'
echo 'Setting up a local NetCDF directory with symlinks'
if ( test -d ./netcdf_links ) ; then
echo 'A directory ./netcdf_links already exists. Continuing.'
else
mkdir ./netcdf_links
if [ -z "$OBJECT_MODE" ] ; then
OBJECT_MODE=32
export OBJECT_MODE
fi
if [ $OBJECT_MODE -ne 64 -a \( `hostname | cut -c 1-2` = "bs" \) ] ; then
( cd ./netcdf_links ; ln -s /usr/local/lib32/r4i4 ./lib ; \
ln -s /usr/local/include ./include )
else
( cd ./netcdf_links ; ln -s /usr/local/lib64/r4i4 ./lib ; \
ln -s /usr/local/include ./include )
fi
fi
NETCDF=`pwd`/netcdf_links
export NETCDF
else
bedone=""
if [ -d ./netcdf_links ] ; then
echo '** There is an existing ./netcdf_links file. Should I use? [y]'
read resp
if [ "$resp" = "y" ] ; then
NETCDF=`pwd`/netcdf_links
bedone="yes"
else
echo 'Removing existing ./netcdf_links directory'
/bin/rm -fr ./netcdf_links
fi
else
echo '** WARNING: No path to NETCDF and environment variable NETCDF not set.'
echo '** would you like me to try to fix? [y]'
fi
netcdfipath=""
netcdflpath=""
while [ -z "$bedone" ] ; do
read resp
if [ "$resp" = "y" -o -z "$resp" ] ; then
if [ -d ./netcdf_links ] ; then
echo 'There is already a ./netcdf_links directory. Okay to use links'
echo 'in this directory for NetCDF include and lib dirs? [y]'
read resp
if [ "$resp" = "y" ] ; then
NETCDF=`pwd`/netcdf_links
export NETCDF
bedone="yes"
continue
fi
fi
if [ -z "$netcdfipath" ] ; then
echo 'Enter full path to NetCDF include directory on your system'
read resp
if [ ! -d "$resp" ] ; then
echo "invalid path: $resp. Try again? [y]" ; continue
fi
netcdfipath=$resp
fi
if [ -z "$netcdflpath" ] ; then
echo 'Enter full path to NetCDF library directory on your system'
read resp
if [ ! -d "$resp" ] ; then
echo "invalid path: $resp. Try again? [y]" ; continue
fi
netcdflpath=$resp
fi
if [ -n "$netcdflpath" -a -n "$netcdfipath" ] ; then
if [ -d ./netcdf_links ] ; then
echo 'Existing ./netcdf_links directory. Okay to remove. [y]'
read resp
if [ "$resp" = "y" ] ; then
/bin/rm -fr ./netcdf_links
fi
fi
mkdir ./netcdf_links
cd ./netcdf_links
ln -s "$netcdfipath" include
ln -s "$netcdflpath" lib
cd ..
echo created new ./netcdf_links directory
/bin/ls -lF ./netcdf_links
NETCDF=`pwd`/netcdf_links
export NETCDF
bedone="yes"
fi
else
bedone="yes"
fi
done
fi
fi
if [ -n "$NETCDF" ] ; then
echo "Will use NETCDF in dir: $NETCDF"
# for 3.6.2 and greater there might be a second library, libnetcdff.a . Check for this and use
# if available
NETCDFF=" "
if [ -f "$NETCDF/lib/libnetcdff.a" ] ; then
NETCDFF="-lnetcdff"
fi
else
echo "Will configure for use without NetCDF"
fi
# if the uname command exists, give it a shot and see if
# we can narrow the choices; otherwise, spam 'em
os="ARCH"
mach="ARCH"
type uname > /dev/null
if [ $? -eq 0 ] ; then
os=`uname`
if [ "$os" = "AIX" -o "$os" = "IRIX" -o "$os" = "IRIX64" -o "$os" = "SunOS" -o "$os" = "HP-UX" -o "$os" = "Darwin" ] ; then
mach="ARCH"
else
xxx=`expr "$os" : '\(.........\).*'`
if [ "$xxx" = "CYGWIN_NT" ] ; then
os=$xxx
fi
if [ "$os" = "OSF1" -o "$os" = "Linux" -o "$os" = "UNICOS/mp" -o "$os" = "UNIX_System_V" -o "$os" = "CYGWIN_NT" ] ; then
mach=`uname -m`
else
os="ARCH"
mach="ARCH"
fi
fi
fi
wrf_dir="none"
standard_wrf_dirs="WRF WRF-4.0.3 WRF-4.0.2 WRF-4.0.1 WRF-4.0 WRFV3"
if [ ${nowrf} -eq 0 ]; then
#
# If no WRF_DIR environment variable is set, try to locate a WRF build in one
# of the expected directory names one directory level up; otherwise, try to use
# the WRF I/O library from the code in $WRF_DIR
#
if [ -z "$WRF_DIR" ]; then
# for d in WRF WRF-4.0.3 WRF-4.0.2 WRF-4.0.1 WRF-4.0 WRFV3; do
for d in ${standard_wrf_dirs}; do
if [ -e ../${d}/external/io_netcdf/libwrfio_nf.a ]; then
echo "Found what looks like a valid WRF I/O library in ../${d}"
wrf_dir="../${d}"
break
fi
done
else
if [ ! -e ${WRF_DIR}/external/io_netcdf/libwrfio_nf.a ]; then
echo ""
echo "Error: The \$WRF_DIR environment variable was set, but the WRF code at"
echo " ${WRF_DIR} doesn't appear to have been successfully compiled"
echo ""
exit
fi
echo "Using WRF I/O library in WRF build identified by \$WRF_DIR: ${WRF_DIR}"
wrf_dir=$WRF_DIR
fi
if [ $wrf_dir = "none" ]; then
echo ""
echo "Error: No compiled WRF code found. Please check that the WRF model has been compiled"
echo " one directory level up (i.e., ../) in a directory named 'WRF', 'WRF-4.0.3', 'WRF-4.0.2', etc.,"
echo " or specify the full path to the compiled WRF model with the environment variable \$WRF_DIR ."
echo ""
echo "Alternatively, if only WPS components that do no depend on WRF I/O libraries are needed, re-run"
echo "the configure script with the --nowrf option."
echo ""
exit
fi
else
cat << EOF
********************************************************************************
Configuring the WPS without a compiled WRF model.
It will not be possible to build the following WPS components, which depend on
the WRF I/O libraries:
- geogrid
- metgrid
- int2nc
********************************************************************************
EOF
fi
grib2dir=""
if [ ${build_grib2} -eq 1 ]; then
grib2dir="${PWD}/grib2"
cat << EOF
********************************************************************************
The zlib, libpng, and JasPer libraries will be compiled from source and
installed in ${grib2dir} .
The environment variables JASPERLIB and JASPERINC will be ignored.
********************************************************************************
EOF
fi
# Found perl, so proceed with configuration
perl arch/Config.pl -perl=$PERL -netcdf=$NETCDF -netcdff=$NETCDFF -os=$os -mach=$mach -wrfdir=$wrf_dir -grib2dir=$grib2dir
#Checking cross-compiling capability for some particular environment
#on Linux and Mac box
if [ $os = "Linux" -o $os = "Darwin" ]; then
SFC=`grep '^SFC' configure.wps | awk '{print $3}'`
SCC=`grep '^SCC' configure.wps | awk '{print $3}'`
SFC="`type $SFC 2>/dev/null | awk '{print $NF}' | sed -e 's/(//g;s/)//g'`"
SCC="`type $SCC 2>/dev/null | awk '{print $NF}' | sed -e 's/(//g;s/)//g'`"
if [ -e $NETCDF/lib/libnetcdf.a -a "$SFC" != "" -a "$SCC" != "" ]; then
SFC_MULTI_ABI=0
SCC_MULTI_ABI=0
CROSS_COMPILING=0
foo=foo_$$
echo
echo Testing for NetCDF, C and Fortran compiler
echo
cat > ${foo}.c <<EOF
int main(int argc, char ** argv)
{
return (0);
}
EOF
cat > ${foo}.f <<EOF
program test_exit
integer :: STATUS = 0
call EXIT(STATUS)
end program test_exit
EOF
nct=`nm $NETCDF/lib/libnetcdf.a | grep '^0' | cut -d' ' -f 1 | head -1 | wc -c | awk '{print $1+0}'`
if [ "$nct" -eq "9" ]; then
netcdf_arch="32-bit"
else
netcdf_arch="64-bit"
fi
$SFC -o ${foo} ${foo}.f > /dev/null 2>&1
SFC_arch="`file ${foo} | grep -o -E '[0-9]{2}-bit|i386'`"
rm ${foo} ${foo}.o 2> /dev/null
$SCC -o ${foo} ${foo}.c > /dev/null 2>&1
SCC_arch="`file ${foo} | grep -o -E '[0-9]{2}-bit|i386'`"
rm ${foo} ${foo}.o 2> /dev/null
if [ "$SFC_arch" = "" -o "$SCC_arch" = "" ]; then
echo " One of compilers testing failed!"
echo " Please check your compiler"
echo
rm -f ${foo} ${foo}.[cfo] 2> /dev/null
exit
else
cp configure.wps configure.wps.edit
fi
case $netcdf_arch in
32-bit|i386 )
if [ "$SFC_arch" = "64-bit" ] ; then
CROSS_COMPILING=1
$SFC -m32 -o ${foo} ${foo}.f > /dev/null 2>&1
if [ $? = 0 ]; then
SFC_MULTI_ABI=1
sed '/^SFC.*=/s/$/ -m32/' configure.wps.edit > configure.wps.tmp
mv configure.wps.tmp configure.wps.edit
fi
fi
if [ "$SCC_arch" = "64-bit" ] ; then
CROSS_COMPILING=1
$SCC -m32 -o ${foo} ${foo}.c > /dev/null 2>&1
if [ $? = 0 ]; then
SCC_MULTI_ABI=1
sed '/^SCC.*=/s/$/ -m32/' configure.wps.edit > configure.wps.tmp
mv configure.wps.tmp configure.wps.edit
fi
fi
if [ $CROSS_COMPILING -eq 1 ] ; then
echo NOTE:
echo This installation NetCDF is 32-bit
if [ \( $SFC_MULTI_ABI -ne 1 -a "$SFC_arch" = "64-bit" \) \
-o \( $SCC_MULTI_ABI -ne 1 -a "$SCC_arch" = "64-bit" \) ] ; then
rm configure.wps.edit
echo One of compilers is 64-bit and doesn\'t support cross-compiling.
echo Please check your NETCDF lib and compiler
else
echo -m32 is appended to configure.wps
echo It will be forced to build in 32-bit.
echo If you don\'t want 32-bit binaries, please use 64-bit NetCDF, and re-run the configure script.
fi
fi
;;
64-bit )
if [ "$SFC_arch" = "32-bit" -o "$SFC_arch" = "i386" ] ; then
CROSS_COMPILING=1
$SFC -m64 -o ${foo} ${foo}.f > /dev/null 2>&1
if [ $? = 0 ]; then
SFC_MULTI_ABI=1
sed '/^SFC.*=/s/$/ -m64/' configure.wps.edit > configure.wps.tmp
mv configure.wps.tmp configure.wps.edit
fi
fi
if [ "$SCC_arch" = "32-bit" -o "$SCC_arch" = "i386" ] ; then
CROSS_COMPILING=1
$SCC -m64 -o ${foo} ${foo}.c > /dev/null 2>&1
if [ $? = 0 ]; then
SCC_MULTI_ABI=1
sed '/^SCC.*=/s/$/ -m64/' configure.wps.edit > configure.wps.tmp
mv configure.wps.tmp configure.wps.edit
fi
fi
if [ $CROSS_COMPILING -eq 1 ] ; then
echo NOTE:
echo This installation NetCDF is 64-bit
if [ \( $SFC_MULTI_ABI -ne 1 -a "$SFC_arch" != "64-bit" \) \
-o \( $SCC_MULTI_ABI -ne 1 -a "$SCC_arch" != "64-bit" \) ]; then
rm configure.wps.edit
echo One of Compilers is 32-bit and doesn\'t support cross-compiling.
echo Please check your NetCDF lib and compiler
else
echo -m64 is appended to configure.wps
echo It will be forced to build in 64-bit.
echo If you don\'t want 64-bit binaries, please use 32-bit NetCDF, and re-run the configure script.
fi
fi
;;
esac
rm -f ${foo} ${foo}.[cfo] 2> /dev/null
if [ -e configure.wps.edit ]; then
mv configure.wps.edit configure.wps
fi
if [ $CROSS_COMPILING -eq 0 ] ; then
echo This installation NetCDF is $netcdf_arch
echo C compiler is $SCC_arch
echo Fortran compiler is $SFC_arch
fi
echo
# Does our Fortran work with the given NETCDF library.
/bin/rm -f fort_netcdf.f fort_netcdf
cat > fort_netcdf.f <<EOF
program foo
include 'netcdf.inc'
integer ncid , status
status = nf_open ( 'foo.nc' , 0 , ncid )
print *,'status = ',status
end program
EOF
FFLAGS=`grep ^FFLAGS configure.wps | cut -d"=" -f2-`
FORMAT_FREE=`grep ^FORMAT_FREE configure.wps | cut -d"=" -f2-`
FFLAGS=`printf "%s" "${FFLAGS}" | sed -e "s/\\$(FORMAT_FREE)/${FORMAT_FREE}/g"`
cp $NETCDF/include/netcdf.inc .
FC=`grep ^SFC configure.wps | cut -d"=" -f2-`
$FC ${FFLAGS} fort_netcdf.f -o fort_netcdf -L${NETCDF}/lib $NETCDFF -lnetcdf > /dev/null 2>&1
if [ -f "fort_netcdf" ] ; then
./fort_netcdf > /dev/null 2>&1
if [ $? = 0 ]; then
/bin/rm -f fort_netcdf.f fort_netcdf.o fort_netcdf netcdf.inc
else
echo
echo "Your Fortran + NETCDF did not run successfully."
echo
fi
else
echo
echo "Your versions of Fortran and NETCDF are not consistent."
echo
fi
cat > c_test.c <<EOF
#ifndef CRAY
# ifdef NOUNDERSCORE
# define C_TEST c_test
# else
# if defined ( F2CSTYLE ) || defined ( _DOUBLEUNDERSCORE )
# define C_TEST c_test__
# else
# define C_TEST c_test_
# endif
# endif
#endif
#include <stdio.h>
int C_TEST ( float *xx, int *ii )
{
printf("OK print in C function. \n" ) ;
printf("Values are xx = %5.2f and ii = %d \n", *xx, *ii ) ;
return(0) ;
}
EOF
CFLAGS=`grep ^CFLAGS configure.wps | cut -d"=" -f2-`
CPPFLAGS=`grep ^CPPFLAGS configure.wps | cut -d"=" -f2-`
CC=`grep ^SCC configure.wps | cut -d"=" -f2-`
${CC} -c ${CFLAGS} ${CPPFLAGS} c_test.c
cat > f_test.f90 <<EOF
PROGRAM f_test
INTEGER :: ii
REAL :: xx
ii = 1
xx = 2
CALL c_test ( xx , ii )
END PROGRAM f_test
EOF
$FC ${FFLAGS} f_test.f90 -o cf_test c_test.o > /dev/null 2>&1
if [ -f "cf_test" ] ; then
./cf_test > /dev/null 2>&1
if [ $? = 0 ]; then
/bin/rm -f cf_test c_test.c c_test.o f_test.f90 f_test.o
else
echo
echo "Your Fortran + C did not run successfully."
echo
fi
else
echo
echo "Your versions of Fortran and C are not consistent."
echo
fi
fi
fi
#
# Check for newer GNU Fortran compilers that require the use of the following:
# -fallow-argument-mismatch
#
cat > gnu_flag_test.F90 << EOF
program gnu_flag_test
#ifdef __GNUC__
#if __GNUC__ > 9
call exit(1) ! A GNU extension, but at this point we know this is a GNU compiler
#endif
#endif
end program gnu_flag_test
EOF
# The above test program gives exit status 1 iff we are using the GNU Fortran
# compiler with a major version greater than 9
FC=`grep ^SFC configure.wps | cut -d"=" -f2-`
FFLAGS=`grep ^FFLAGS configure.wps | cut -d"=" -f2-`
FORMAT_FREE=`grep ^FORMAT_FREE configure.wps | cut -d"=" -f2-`
FFLAGS=`printf "%s" "${FFLAGS}" | sed -e "s/\\$(FORMAT_FREE)/${FORMAT_FREE}/g"`
$FC ${FFLAGS} gnu_flag_test.F90 -o gnu_flag_test > /dev/null 2>&1
if [ -f ./gnu_flag_test ]; then
./gnu_flag_test > /dev/null 2>&1
if [ $? -eq 1 ]; then
compat="-fallow-argument-mismatch"
fi
rm gnu_flag_test
else
printf "*** Failed to compile the gnu_flag_test program!\n"
printf " This may be because the selected build option does not work correctly.\n"
fi
rm gnu_flag_test.F90
sed "s/CONFIGURE_COMPAT_FLAGS/${compat}/" configure.wps > configure.wps.tmp
mv configure.wps.tmp configure.wps