Merge branch 'improve_rotang_calculation' into develop (PR #211)
[WPS.git] / configure
blob701b24a5c79e0c585e39a50601f6ffad224e80b8
1 #!/bin/sh
4 # Check for command-line arguments
5 # At present, the only supported arguments are:
6 # --nowrf : disables checks to find the path to the compiled WRF model
7 # --build-grib2-libs : compiles zlib, libpng, and JasPer libraries from
8 # source in the external/ directory and installs
9 # the libraries in grib2/
11 nowrf=0
12 build_grib2=0
13 for arg in $@; do
14 if [ "${arg}" = "--nowrf" ]; then
15 nowrf=1
16 elif [ "${arg}" = "--build-grib2-libs" ]; then
17 build_grib2=1
18 else
19 printf "Unrecognized option %s\n" ${arg}
21 done
24 # Look for netcdf
25 if test -z "$NETCDF" ; then
26 for p in /usr/local/netcdf
28 if test -d $p ; then
29 NETCDF=$p
30 break
32 done
35 if test -z "$NETCDF" ; then
37 if [ `hostname | cut -c 1-2` = "bs" -o \
38 `hostname | cut -c 1-2` = "bv" -o \
39 `hostname` = "tempest" -o `hostname` = "lightning" ] ; then
40 echo 'Compiling on an NCAR system with weird paths to NetCDF'
41 echo 'Setting up a local NetCDF directory with symlinks'
42 if ( test -d ./netcdf_links ) ; then
43 echo 'A directory ./netcdf_links already exists. Continuing.'
44 else
45 mkdir ./netcdf_links
46 if [ -z "$OBJECT_MODE" ] ; then
47 OBJECT_MODE=32
48 export OBJECT_MODE
50 if [ $OBJECT_MODE -ne 64 -a \( `hostname | cut -c 1-2` = "bs" \) ] ; then
51 ( cd ./netcdf_links ; ln -s /usr/local/lib32/r4i4 ./lib ; \
52 ln -s /usr/local/include ./include )
53 else
54 ( cd ./netcdf_links ; ln -s /usr/local/lib64/r4i4 ./lib ; \
55 ln -s /usr/local/include ./include )
58 NETCDF=`pwd`/netcdf_links
59 export NETCDF
62 else
63 bedone=""
64 if [ -d ./netcdf_links ] ; then
65 echo '** There is an existing ./netcdf_links file. Should I use? [y]'
66 read resp
67 if [ "$resp" = "y" ] ; then
68 NETCDF=`pwd`/netcdf_links
69 bedone="yes"
70 else
71 echo 'Removing existing ./netcdf_links directory'
72 /bin/rm -fr ./netcdf_links
74 else
75 echo '** WARNING: No path to NETCDF and environment variable NETCDF not set.'
76 echo '** would you like me to try to fix? [y]'
78 netcdfipath=""
79 netcdflpath=""
80 while [ -z "$bedone" ] ; do
81 read resp
82 if [ "$resp" = "y" -o -z "$resp" ] ; then
83 if [ -d ./netcdf_links ] ; then
84 echo 'There is already a ./netcdf_links directory. Okay to use links'
85 echo 'in this directory for NetCDF include and lib dirs? [y]'
86 read resp
87 if [ "$resp" = "y" ] ; then
88 NETCDF=`pwd`/netcdf_links
89 export NETCDF
90 bedone="yes"
91 continue
94 if [ -z "$netcdfipath" ] ; then
95 echo 'Enter full path to NetCDF include directory on your system'
96 read resp
97 if [ ! -d "$resp" ] ; then
98 echo "invalid path: $resp. Try again? [y]" ; continue
100 netcdfipath=$resp
102 if [ -z "$netcdflpath" ] ; then
103 echo 'Enter full path to NetCDF library directory on your system'
104 read resp
105 if [ ! -d "$resp" ] ; then
106 echo "invalid path: $resp. Try again? [y]" ; continue
108 netcdflpath=$resp
111 if [ -n "$netcdflpath" -a -n "$netcdfipath" ] ; then
112 if [ -d ./netcdf_links ] ; then
113 echo 'Existing ./netcdf_links directory. Okay to remove. [y]'
114 read resp
115 if [ "$resp" = "y" ] ; then
116 /bin/rm -fr ./netcdf_links
119 mkdir ./netcdf_links
120 cd ./netcdf_links
121 ln -s "$netcdfipath" include
122 ln -s "$netcdflpath" lib
123 cd ..
124 echo created new ./netcdf_links directory
125 /bin/ls -lF ./netcdf_links
126 NETCDF=`pwd`/netcdf_links
127 export NETCDF
128 bedone="yes"
130 else
131 bedone="yes"
133 done
137 if [ -n "$NETCDF" ] ; then
138 echo "Will use NETCDF in dir: $NETCDF"
139 # for 3.6.2 and greater there might be a second library, libnetcdff.a . Check for this and use
140 # if available
141 NETCDFF=" "
142 if [ -f "$NETCDF/lib/libnetcdff.a" ] ; then
143 NETCDFF="-lnetcdff"
145 else
146 echo "Will configure for use without NetCDF"
149 # if the uname command exists, give it a shot and see if
150 # we can narrow the choices; otherwise, spam 'em
151 os="ARCH"
152 mach="ARCH"
153 type uname > /dev/null
154 if [ $? -eq 0 ] ; then
155 os=`uname`
156 if [ "$os" = "AIX" -o "$os" = "IRIX" -o "$os" = "IRIX64" -o "$os" = "SunOS" -o "$os" = "HP-UX" -o "$os" = "Darwin" ] ; then
157 mach="ARCH"
158 else
159 xxx=`expr "$os" : '\(.........\).*'`
160 if [ "$xxx" = "CYGWIN_NT" ] ; then
161 os=$xxx
163 if [ "$os" = "OSF1" -o "$os" = "Linux" -o "$os" = "UNICOS/mp" -o "$os" = "UNIX_System_V" -o "$os" = "CYGWIN_NT" ] ; then
164 mach=`uname -m`
165 else
166 os="ARCH"
167 mach="ARCH"
172 wrf_dir="none"
173 standard_wrf_dirs="WRF WRF-4.0.3 WRF-4.0.2 WRF-4.0.1 WRF-4.0 WRFV3"
175 if [ ${nowrf} -eq 0 ]; then
177 # If no WRF_DIR environment variable is set, try to locate a WRF build in one
178 # of the expected directory names one directory level up; otherwise, try to use
179 # the WRF I/O library from the code in $WRF_DIR
181 if [ -z "$WRF_DIR" ]; then
182 # for d in WRF WRF-4.0.3 WRF-4.0.2 WRF-4.0.1 WRF-4.0 WRFV3; do
183 for d in ${standard_wrf_dirs}; do
184 if [ -e ../${d}/external/io_netcdf/libwrfio_nf.a ]; then
185 echo "Found what looks like a valid WRF I/O library in ../${d}"
186 wrf_dir="../${d}"
187 break
189 done
190 else
191 if [ ! -e ${WRF_DIR}/external/io_netcdf/libwrfio_nf.a ]; then
192 echo ""
193 echo "Error: The \$WRF_DIR environment variable was set, but the WRF code at"
194 echo " ${WRF_DIR} doesn't appear to have been successfully compiled"
195 echo ""
196 exit
199 echo "Using WRF I/O library in WRF build identified by \$WRF_DIR: ${WRF_DIR}"
200 wrf_dir=$WRF_DIR
203 if [ $wrf_dir = "none" ]; then
204 echo ""
205 echo "Error: No compiled WRF code found. Please check that the WRF model has been compiled"
206 echo " one directory level up (i.e., ../) in a directory named 'WRF', 'WRF-4.0.3', 'WRF-4.0.2', etc.,"
207 echo " or specify the full path to the compiled WRF model with the environment variable \$WRF_DIR ."
208 echo ""
209 echo "Alternatively, if only WPS components that do no depend on WRF I/O libraries are needed, re-run"
210 echo "the configure script with the --nowrf option."
211 echo ""
212 exit
214 else
215 cat << EOF
216 ********************************************************************************
217 Configuring the WPS without a compiled WRF model.
218 It will not be possible to build the following WPS components, which depend on
219 the WRF I/O libraries:
220 - geogrid
221 - metgrid
222 - int2nc
223 ********************************************************************************
227 grib2dir=""
228 if [ ${build_grib2} -eq 1 ]; then
229 grib2dir="${PWD}/grib2"
231 cat << EOF
232 ********************************************************************************
233 The zlib, libpng, and JasPer libraries will be compiled from source and
234 installed in ${grib2dir} .
236 The environment variables JASPERLIB and JASPERINC will be ignored.
237 ********************************************************************************
241 # Found perl, so proceed with configuration
242 perl arch/Config.pl -perl=$PERL -netcdf=$NETCDF -netcdff=$NETCDFF -os=$os -mach=$mach -wrfdir=$wrf_dir -grib2dir=$grib2dir
245 #Checking cross-compiling capability for some particular environment
246 #on Linux and Mac box
248 if [ $os = "Linux" -o $os = "Darwin" ]; then
250 SFC=`grep '^SFC' configure.wps | awk '{print $3}'`
251 SCC=`grep '^SCC' configure.wps | awk '{print $3}'`
253 SFC="`type $SFC 2>/dev/null | awk '{print $NF}' | sed -e 's/(//g;s/)//g'`"
254 SCC="`type $SCC 2>/dev/null | awk '{print $NF}' | sed -e 's/(//g;s/)//g'`"
256 if [ -e $NETCDF/lib/libnetcdf.a -a "$SFC" != "" -a "$SCC" != "" ]; then
258 SFC_MULTI_ABI=0
259 SCC_MULTI_ABI=0
260 CROSS_COMPILING=0
262 foo=foo_$$
264 echo
265 echo Testing for NetCDF, C and Fortran compiler
266 echo
268 cat > ${foo}.c <<EOF
269 int main(int argc, char ** argv)
271 return (0);
275 cat > ${foo}.f <<EOF
276 program test_exit
277 integer :: STATUS = 0
278 call EXIT(STATUS)
279 end program test_exit
282 nct=`nm $NETCDF/lib/libnetcdf.a | grep '^0' | cut -d' ' -f 1 | head -1 | wc -c | awk '{print $1+0}'`
283 if [ "$nct" -eq "9" ]; then
284 netcdf_arch="32-bit"
285 else
286 netcdf_arch="64-bit"
289 $SFC -o ${foo} ${foo}.f > /dev/null 2>&1
290 SFC_arch="`file ${foo} | grep -o -E '[0-9]{2}-bit|i386'`"
291 rm ${foo} ${foo}.o 2> /dev/null
293 $SCC -o ${foo} ${foo}.c > /dev/null 2>&1
294 SCC_arch="`file ${foo} | grep -o -E '[0-9]{2}-bit|i386'`"
295 rm ${foo} ${foo}.o 2> /dev/null
297 if [ "$SFC_arch" = "" -o "$SCC_arch" = "" ]; then
298 echo " One of compilers testing failed!"
299 echo " Please check your compiler"
300 echo
301 rm -f ${foo} ${foo}.[cfo] 2> /dev/null
302 exit
303 else
304 cp configure.wps configure.wps.edit
307 case $netcdf_arch in
309 32-bit|i386 )
311 if [ "$SFC_arch" = "64-bit" ] ; then
312 CROSS_COMPILING=1
313 $SFC -m32 -o ${foo} ${foo}.f > /dev/null 2>&1
314 if [ $? = 0 ]; then
315 SFC_MULTI_ABI=1
316 sed '/^SFC.*=/s/$/ -m32/' configure.wps.edit > configure.wps.tmp
317 mv configure.wps.tmp configure.wps.edit
320 if [ "$SCC_arch" = "64-bit" ] ; then
321 CROSS_COMPILING=1
322 $SCC -m32 -o ${foo} ${foo}.c > /dev/null 2>&1
323 if [ $? = 0 ]; then
324 SCC_MULTI_ABI=1
325 sed '/^SCC.*=/s/$/ -m32/' configure.wps.edit > configure.wps.tmp
326 mv configure.wps.tmp configure.wps.edit
330 if [ $CROSS_COMPILING -eq 1 ] ; then
331 echo NOTE:
332 echo This installation NetCDF is 32-bit
333 if [ \( $SFC_MULTI_ABI -ne 1 -a "$SFC_arch" = "64-bit" \) \
334 -o \( $SCC_MULTI_ABI -ne 1 -a "$SCC_arch" = "64-bit" \) ] ; then
335 rm configure.wps.edit
336 echo One of compilers is 64-bit and doesn\'t support cross-compiling.
337 echo Please check your NETCDF lib and compiler
338 else
339 echo -m32 is appended to configure.wps
340 echo It will be forced to build in 32-bit.
341 echo If you don\'t want 32-bit binaries, please use 64-bit NetCDF, and re-run the configure script.
346 64-bit )
348 if [ "$SFC_arch" = "32-bit" -o "$SFC_arch" = "i386" ] ; then
349 CROSS_COMPILING=1
350 $SFC -m64 -o ${foo} ${foo}.f > /dev/null 2>&1
351 if [ $? = 0 ]; then
352 SFC_MULTI_ABI=1
353 sed '/^SFC.*=/s/$/ -m64/' configure.wps.edit > configure.wps.tmp
354 mv configure.wps.tmp configure.wps.edit
357 if [ "$SCC_arch" = "32-bit" -o "$SCC_arch" = "i386" ] ; then
358 CROSS_COMPILING=1
359 $SCC -m64 -o ${foo} ${foo}.c > /dev/null 2>&1
360 if [ $? = 0 ]; then
361 SCC_MULTI_ABI=1
362 sed '/^SCC.*=/s/$/ -m64/' configure.wps.edit > configure.wps.tmp
363 mv configure.wps.tmp configure.wps.edit
367 if [ $CROSS_COMPILING -eq 1 ] ; then
368 echo NOTE:
369 echo This installation NetCDF is 64-bit
370 if [ \( $SFC_MULTI_ABI -ne 1 -a "$SFC_arch" != "64-bit" \) \
371 -o \( $SCC_MULTI_ABI -ne 1 -a "$SCC_arch" != "64-bit" \) ]; then
372 rm configure.wps.edit
373 echo One of Compilers is 32-bit and doesn\'t support cross-compiling.
374 echo Please check your NetCDF lib and compiler
375 else
376 echo -m64 is appended to configure.wps
377 echo It will be forced to build in 64-bit.
378 echo If you don\'t want 64-bit binaries, please use 32-bit NetCDF, and re-run the configure script.
382 esac
383 rm -f ${foo} ${foo}.[cfo] 2> /dev/null
385 if [ -e configure.wps.edit ]; then
386 mv configure.wps.edit configure.wps
389 if [ $CROSS_COMPILING -eq 0 ] ; then
390 echo This installation NetCDF is $netcdf_arch
391 echo C compiler is $SCC_arch
392 echo Fortran compiler is $SFC_arch
394 echo
396 # Does our Fortran work with the given NETCDF library.
398 /bin/rm -f fort_netcdf.f fort_netcdf
399 cat > fort_netcdf.f <<EOF
400 program foo
401 include 'netcdf.inc'
402 integer ncid , status
403 status = nf_open ( 'foo.nc' , 0 , ncid )
404 print *,'status = ',status
405 end program
407 FFLAGS=`grep ^FFLAGS configure.wps | cut -d"=" -f2-`
408 cp $NETCDF/include/netcdf.inc .
409 FC=`grep ^SFC configure.wps | cut -d"=" -f2-`
410 $FC ${FFLAGS} fort_netcdf.f -o fort_netcdf -L${NETCDF}/lib $NETCDFF -lnetcdf > /dev/null 2>&1
411 if [ -f "fort_netcdf" ] ; then
412 ./fort_netcdf > /dev/null 2>&1
413 if [ $? = 0 ]; then
414 /bin/rm -f fort_netcdf.f fort_netcdf.o fort_netcdf netcdf.inc
415 else
416 echo
417 echo "Your Fortran + NETCDF did not run successfully."
418 echo
420 else
421 echo
422 echo "Your versions of Fortran and NETCDF are not consistent."
423 echo
426 cat > c_test.c <<EOF
427 #ifndef CRAY
428 # ifdef NOUNDERSCORE
429 # define C_TEST c_test
430 # else
431 # if defined ( F2CSTYLE ) || defined ( _DOUBLEUNDERSCORE )
432 # define C_TEST c_test__
433 # else
434 # define C_TEST c_test_
435 # endif
436 # endif
437 #endif
438 #include <stdio.h>
440 int C_TEST ( float *xx, int *ii )
443 printf("OK print in C function. \n" ) ;
444 printf("Values are xx = %5.2f and ii = %d \n", *xx, *ii ) ;
445 return(0) ;
448 CFLAGS=`grep ^CFLAGS configure.wps | cut -d"=" -f2-`
449 CPPFLAGS=`grep ^CPPFLAGS configure.wps | cut -d"=" -f2-`
450 CC=`grep ^SCC configure.wps | cut -d"=" -f2-`
451 ${CC} -c ${CFLAGS} ${CPPFLAGS} c_test.c
453 cat > f_test.f90 <<EOF
454 PROGRAM f_test
455 INTEGER :: ii
456 REAL :: xx
458 ii = 1
459 xx = 2
461 CALL c_test ( xx , ii )
463 END PROGRAM f_test
465 $FC ${FFLAGS} f_test.f90 -o cf_test c_test.o > /dev/null 2>&1
466 if [ -f "cf_test" ] ; then
467 ./cf_test > /dev/null 2>&1
468 if [ $? = 0 ]; then
469 /bin/rm -f cf_test c_test.c c_test.o f_test.f90 f_test.o
470 else
471 echo
472 echo "Your Fortran + C did not run successfully."
473 echo
475 else
476 echo
477 echo "Your versions of Fortran and C are not consistent."
478 echo
486 # Check for newer GNU Fortran compilers that require the use of the following:
487 # -fallow-argument-mismatch
489 cat > gnu_flag_test.F90 << EOF
490 program gnu_flag_test
491 #ifdef __GNUC__
492 #if __GNUC__ > 9
493 call exit(1) ! A GNU extension, but at this point we know this is a GNU compiler
494 #endif
495 #endif
496 end program gnu_flag_test
499 # The above test program gives exit status 1 iff we are using the GNU Fortran
500 # compiler with a major version greater than 9
502 FC=`grep ^SFC configure.wps | cut -d"=" -f2-`
503 FFLAGS=`grep ^FFLAGS configure.wps | cut -d"=" -f2-`
504 $FC ${FFLAGS} gnu_flag_test.F90 -o gnu_flag_test > /dev/null 2>&1
505 if [ -f ./gnu_flag_test ]; then
506 ./gnu_flag_test > /dev/null 2>&1
507 if [ $? -eq 1 ]; then
508 compat="-fallow-argument-mismatch"
510 rm gnu_flag_test
511 else
512 printf "*** Failed to compile the gnu_flag_test program!\n"
513 printf " This may be because the selected build option does not work correctly.\n"
515 rm gnu_flag_test.F90
517 sed "s/CONFIGURE_COMPAT_FLAGS/${compat}/" configure.wps > configure.wps.tmp
518 mv configure.wps.tmp configure.wps