Allow configure script to define new FCCOMPAT flags for newer GNU compilers
[WPS.git] / configure
blob6b9f87364ddae80e65feb1d271543a8fc4cdda01
1 #!/bin/sh
4 # Check for command-line arguments
5 # At present, the only supported argument is --nowrf, which disables checks to
6 # find the path to the compiled WRF model.
8 nowrf=0
9 for arg in $@; do
10 if [ "${arg}" = "--nowrf" ]; then
11 nowrf=1
13 done
16 # Look for netcdf
17 if test -z "$NETCDF" ; then
18 for p in /usr/local/netcdf
20 if test -d $p ; then
21 NETCDF=$p
22 break
24 done
27 if test -z "$NETCDF" ; then
29 if [ `hostname | cut -c 1-2` = "bs" -o \
30 `hostname | cut -c 1-2` = "bv" -o \
31 `hostname` = "tempest" -o `hostname` = "lightning" ] ; then
32 echo 'Compiling on an NCAR system with weird paths to NetCDF'
33 echo 'Setting up a local NetCDF directory with symlinks'
34 if ( test -d ./netcdf_links ) ; then
35 echo 'A directory ./netcdf_links already exists. Continuing.'
36 else
37 mkdir ./netcdf_links
38 if [ -z "$OBJECT_MODE" ] ; then
39 OBJECT_MODE=32
40 export OBJECT_MODE
42 if [ $OBJECT_MODE -ne 64 -a \( `hostname | cut -c 1-2` = "bs" \) ] ; then
43 ( cd ./netcdf_links ; ln -s /usr/local/lib32/r4i4 ./lib ; \
44 ln -s /usr/local/include ./include )
45 else
46 ( cd ./netcdf_links ; ln -s /usr/local/lib64/r4i4 ./lib ; \
47 ln -s /usr/local/include ./include )
50 NETCDF=`pwd`/netcdf_links
51 export NETCDF
54 else
55 bedone=""
56 if [ -d ./netcdf_links ] ; then
57 echo '** There is an existing ./netcdf_links file. Should I use? [y]'
58 read resp
59 if [ "$resp" = "y" ] ; then
60 NETCDF=`pwd`/netcdf_links
61 bedone="yes"
62 else
63 echo 'Removing existing ./netcdf_links directory'
64 /bin/rm -fr ./netcdf_links
66 else
67 echo '** WARNING: No path to NETCDF and environment variable NETCDF not set.'
68 echo '** would you like me to try to fix? [y]'
70 netcdfipath=""
71 netcdflpath=""
72 while [ -z "$bedone" ] ; do
73 read resp
74 if [ "$resp" = "y" -o -z "$resp" ] ; then
75 if [ -d ./netcdf_links ] ; then
76 echo 'There is already a ./netcdf_links directory. Okay to use links'
77 echo 'in this directory for NetCDF include and lib dirs? [y]'
78 read resp
79 if [ "$resp" = "y" ] ; then
80 NETCDF=`pwd`/netcdf_links
81 export NETCDF
82 bedone="yes"
83 continue
86 if [ -z "$netcdfipath" ] ; then
87 echo 'Enter full path to NetCDF include directory on your system'
88 read resp
89 if [ ! -d "$resp" ] ; then
90 echo "invalid path: $resp. Try again? [y]" ; continue
92 netcdfipath=$resp
94 if [ -z "$netcdflpath" ] ; then
95 echo 'Enter full path to NetCDF library directory on your system'
96 read resp
97 if [ ! -d "$resp" ] ; then
98 echo "invalid path: $resp. Try again? [y]" ; continue
100 netcdflpath=$resp
103 if [ -n "$netcdflpath" -a -n "$netcdfipath" ] ; then
104 if [ -d ./netcdf_links ] ; then
105 echo 'Existing ./netcdf_links directory. Okay to remove. [y]'
106 read resp
107 if [ "$resp" = "y" ] ; then
108 /bin/rm -fr ./netcdf_links
111 mkdir ./netcdf_links
112 cd ./netcdf_links
113 ln -s "$netcdfipath" include
114 ln -s "$netcdflpath" lib
115 cd ..
116 echo created new ./netcdf_links directory
117 /bin/ls -lF ./netcdf_links
118 NETCDF=`pwd`/netcdf_links
119 export NETCDF
120 bedone="yes"
122 else
123 bedone="yes"
125 done
129 if [ -n "$NETCDF" ] ; then
130 echo "Will use NETCDF in dir: $NETCDF"
131 # for 3.6.2 and greater there might be a second library, libnetcdff.a . Check for this and use
132 # if available
133 NETCDFF=" "
134 if [ -f "$NETCDF/lib/libnetcdff.a" ] ; then
135 NETCDFF="-lnetcdff"
137 else
138 echo "Will configure for use without NetCDF"
141 # if the uname command exists, give it a shot and see if
142 # we can narrow the choices; otherwise, spam 'em
143 os="ARCH"
144 mach="ARCH"
145 type uname > /dev/null
146 if [ $? -eq 0 ] ; then
147 os=`uname`
148 if [ "$os" = "AIX" -o "$os" = "IRIX" -o "$os" = "IRIX64" -o "$os" = "SunOS" -o "$os" = "HP-UX" -o "$os" = "Darwin" ] ; then
149 mach="ARCH"
150 else
151 xxx=`expr "$os" : '\(.........\).*'`
152 if [ "$xxx" = "CYGWIN_NT" ] ; then
153 os=$xxx
155 if [ "$os" = "OSF1" -o "$os" = "Linux" -o "$os" = "UNICOS/mp" -o "$os" = "UNIX_System_V" -o "$os" = "CYGWIN_NT" ] ; then
156 mach=`uname -m`
157 else
158 os="ARCH"
159 mach="ARCH"
164 wrf_dir="none"
165 standard_wrf_dirs="WRF WRF-4.0.3 WRF-4.0.2 WRF-4.0.1 WRF-4.0 WRFV3"
167 if [ ${nowrf} -eq 0 ]; then
169 # If no WRF_DIR environment variable is set, try to locate a WRF build in one
170 # of the expected directory names one directory level up; otherwise, try to use
171 # the WRF I/O library from the code in $WRF_DIR
173 if [ -z "$WRF_DIR" ]; then
174 # for d in WRF WRF-4.0.3 WRF-4.0.2 WRF-4.0.1 WRF-4.0 WRFV3; do
175 for d in ${standard_wrf_dirs}; do
176 if [ -e ../${d}/external/io_netcdf/libwrfio_nf.a ]; then
177 echo "Found what looks like a valid WRF I/O library in ../${d}"
178 wrf_dir="../${d}"
179 break
181 done
182 else
183 if [ ! -e ${WRF_DIR}/external/io_netcdf/libwrfio_nf.a ]; then
184 echo ""
185 echo "Error: The \$WRF_DIR environment variable was set, but the WRF code at"
186 echo " ${WRF_DIR} doesn't appear to have been successfully compiled"
187 echo ""
188 exit
191 echo "Using WRF I/O library in WRF build identified by \$WRF_DIR: ${WRF_DIR}"
192 wrf_dir=$WRF_DIR
195 if [ $wrf_dir = "none" ]; then
196 echo ""
197 echo "Error: No compiled WRF code found. Please check that the WRF model has been compiled"
198 echo " one directory level up (i.e., ../) in a directory named 'WRF', 'WRF-4.0.3', 'WRF-4.0.2', etc.,"
199 echo " or specify the full path to the compiled WRF model with the environment variable \$WRF_DIR ."
200 echo ""
201 echo "Alternatively, if only WPS components that do no depend on WRF I/O libraries are needed, re-run"
202 echo "the configure script with the --nowrf option."
203 echo ""
204 exit
206 else
207 cat << EOF
208 ********************************************************************************
209 Configuring the WPS without a compiled WRF model.
210 It will not be possible to build the following WPS components, which depend on
211 the WRF I/O libraries:
212 - geogrid
213 - metgrid
214 - int2nc
215 ********************************************************************************
219 # Found perl, so proceed with configuration
220 perl arch/Config.pl -perl=$PERL -netcdf=$NETCDF -netcdff=$NETCDFF -os=$os -mach=$mach -wrfdir=$wrf_dir
223 #Checking cross-compiling capability for some particular environment
224 #on Linux and Mac box
226 if [ $os = "Linux" -o $os = "Darwin" ]; then
228 SFC=`grep '^SFC' configure.wps | awk '{print $3}'`
229 SCC=`grep '^SCC' configure.wps | awk '{print $3}'`
231 SFC="`type $SFC 2>/dev/null | awk '{print $NF}' | sed -e 's/(//g;s/)//g'`"
232 SCC="`type $SCC 2>/dev/null | awk '{print $NF}' | sed -e 's/(//g;s/)//g'`"
234 if [ -e $NETCDF/lib/libnetcdf.a -a "$SFC" != "" -a "$SCC" != "" ]; then
236 SFC_MULTI_ABI=0
237 SCC_MULTI_ABI=0
238 CROSS_COMPILING=0
240 foo=foo_$$
242 echo
243 echo Testing for NetCDF, C and Fortran compiler
244 echo
246 cat > ${foo}.c <<EOF
247 int main(int argc, char ** argv)
249 return (0);
253 cat > ${foo}.f <<EOF
254 program test_exit
255 integer :: STATUS = 0
256 call EXIT(STATUS)
257 end program test_exit
260 nct=`nm $NETCDF/lib/libnetcdf.a | grep '^0' | cut -d' ' -f 1 | head -1 | wc -c | awk '{print $1+0}'`
261 if [ "$nct" -eq "9" ]; then
262 netcdf_arch="32-bit"
263 else
264 netcdf_arch="64-bit"
267 $SFC -o ${foo} ${foo}.f > /dev/null 2>&1
268 SFC_arch="`file ${foo} | grep -o -E '[0-9]{2}-bit|i386'`"
269 rm ${foo} ${foo}.o 2> /dev/null
271 $SCC -o ${foo} ${foo}.c > /dev/null 2>&1
272 SCC_arch="`file ${foo} | grep -o -E '[0-9]{2}-bit|i386'`"
273 rm ${foo} ${foo}.o 2> /dev/null
275 if [ "$SFC_arch" = "" -o "$SCC_arch" = "" ]; then
276 echo " One of compilers testing failed!"
277 echo " Please check your compiler"
278 echo
279 rm -f ${foo} ${foo}.[cfo] 2> /dev/null
280 exit
281 else
282 cp configure.wps configure.wps.edit
285 case $netcdf_arch in
287 32-bit|i386 )
289 if [ "$SFC_arch" = "64-bit" ] ; then
290 CROSS_COMPILING=1
291 $SFC -m32 -o ${foo} ${foo}.f > /dev/null 2>&1
292 if [ $? = 0 ]; then
293 SFC_MULTI_ABI=1
294 sed '/^SFC.*=/s/$/ -m32/' configure.wps.edit > configure.wps.tmp
295 mv configure.wps.tmp configure.wps.edit
298 if [ "$SCC_arch" = "64-bit" ] ; then
299 CROSS_COMPILING=1
300 $SCC -m32 -o ${foo} ${foo}.c > /dev/null 2>&1
301 if [ $? = 0 ]; then
302 SCC_MULTI_ABI=1
303 sed '/^SCC.*=/s/$/ -m32/' configure.wps.edit > configure.wps.tmp
304 mv configure.wps.tmp configure.wps.edit
308 if [ $CROSS_COMPILING -eq 1 ] ; then
309 echo NOTE:
310 echo This installation NetCDF is 32-bit
311 if [ \( $SFC_MULTI_ABI -ne 1 -a "$SFC_arch" = "64-bit" \) \
312 -o \( $SCC_MULTI_ABI -ne 1 -a "$SCC_arch" = "64-bit" \) ] ; then
313 rm configure.wps.edit
314 echo One of compilers is 64-bit and doesn\'t support cross-compiling.
315 echo Please check your NETCDF lib and compiler
316 else
317 echo -m32 is appended to configure.wps
318 echo It will be forced to build in 32-bit.
319 echo If you don\'t want 32-bit binaries, please use 64-bit NetCDF, and re-run the configure script.
324 64-bit )
326 if [ "$SFC_arch" = "32-bit" -o "$SFC_arch" = "i386" ] ; then
327 CROSS_COMPILING=1
328 $SFC -m64 -o ${foo} ${foo}.f > /dev/null 2>&1
329 if [ $? = 0 ]; then
330 SFC_MULTI_ABI=1
331 sed '/^SFC.*=/s/$/ -m64/' configure.wps.edit > configure.wps.tmp
332 mv configure.wps.tmp configure.wps.edit
335 if [ "$SCC_arch" = "32-bit" -o "$SCC_arch" = "i386" ] ; then
336 CROSS_COMPILING=1
337 $SCC -m64 -o ${foo} ${foo}.c > /dev/null 2>&1
338 if [ $? = 0 ]; then
339 SCC_MULTI_ABI=1
340 sed '/^SCC.*=/s/$/ -m64/' configure.wps.edit > configure.wps.tmp
341 mv configure.wps.tmp configure.wps.edit
345 if [ $CROSS_COMPILING -eq 1 ] ; then
346 echo NOTE:
347 echo This installation NetCDF is 64-bit
348 if [ \( $SFC_MULTI_ABI -ne 1 -a "$SFC_arch" != "64-bit" \) \
349 -o \( $SCC_MULTI_ABI -ne 1 -a "$SCC_arch" != "64-bit" \) ]; then
350 rm configure.wps.edit
351 echo One of Compilers is 32-bit and doesn\'t support cross-compiling.
352 echo Please check your NetCDF lib and compiler
353 else
354 echo -m64 is appended to configure.wps
355 echo It will be forced to build in 64-bit.
356 echo If you don\'t want 64-bit binaries, please use 32-bit NetCDF, and re-run the configure script.
360 esac
361 rm -f ${foo} ${foo}.[cfo] 2> /dev/null
363 if [ -e configure.wps.edit ]; then
364 mv configure.wps.edit configure.wps
367 if [ $CROSS_COMPILING -eq 0 ] ; then
368 echo This installation NetCDF is $netcdf_arch
369 echo C compiler is $SCC_arch
370 echo Fortran compiler is $SFC_arch
372 echo
374 # Does our Fortran work with the given NETCDF library.
376 /bin/rm -f fort_netcdf.f fort_netcdf
377 cat > fort_netcdf.f <<EOF
378 program foo
379 include 'netcdf.inc'
380 integer ncid , status
381 status = nf_open ( 'foo.nc' , 0 , ncid )
382 print *,'status = ',status
383 end program
385 FFLAGS=`grep ^FFLAGS configure.wps | cut -d"=" -f2-`
386 cp $NETCDF/include/netcdf.inc .
387 FC=`grep ^SFC configure.wps | cut -d"=" -f2-`
388 $FC ${FFLAGS} fort_netcdf.f -o fort_netcdf -L${NETCDF}/lib $NETCDFF -lnetcdf > /dev/null 2>&1
389 if [ -f "fort_netcdf" ] ; then
390 ./fort_netcdf > /dev/null 2>&1
391 if [ $? = 0 ]; then
392 /bin/rm -f fort_netcdf.f fort_netcdf.o fort_netcdf netcdf.inc
393 else
394 echo
395 echo "Your Fortran + NETCDF did not run successfully."
396 echo
398 else
399 echo
400 echo "Your versions of Fortran and NETCDF are not consistent."
401 echo
404 cat > c_test.c <<EOF
405 #ifndef CRAY
406 # ifdef NOUNDERSCORE
407 # define C_TEST c_test
408 # else
409 # if defined ( F2CSTYLE ) || defined ( _DOUBLEUNDERSCORE )
410 # define C_TEST c_test__
411 # else
412 # define C_TEST c_test_
413 # endif
414 # endif
415 #endif
416 #include <stdio.h>
418 int C_TEST ( float *xx, int *ii )
421 printf("OK print in C function. \n" ) ;
422 printf("Values are xx = %5.2f and ii = %d \n", *xx, *ii ) ;
423 return(0) ;
426 CFLAGS=`grep ^CFLAGS configure.wps | cut -d"=" -f2-`
427 CPPFLAGS=`grep ^CPPFLAGS configure.wps | cut -d"=" -f2-`
428 CC=`grep ^SCC configure.wps | cut -d"=" -f2-`
429 ${CC} -c ${CFLAGS} ${CPPFLAGS} c_test.c
431 cat > f_test.f90 <<EOF
432 PROGRAM f_test
433 INTEGER :: ii
434 REAL :: xx
436 ii = 1
437 xx = 2
439 CALL c_test ( xx , ii )
441 END PROGRAM f_test
443 $FC ${FFLAGS} f_test.f90 -o cf_test c_test.o > /dev/null 2>&1
444 if [ -f "cf_test" ] ; then
445 ./cf_test > /dev/null 2>&1
446 if [ $? = 0 ]; then
447 /bin/rm -f cf_test c_test.c c_test.o f_test.f90 f_test.o
448 else
449 echo
450 echo "Your Fortran + C did not run successfully."
451 echo
453 else
454 echo
455 echo "Your versions of Fortran and C are not consistent."
456 echo
464 # Check for newer GNU Fortran compilers that require the use of the following:
465 # -fallow-argument-mismatch
467 cat > gnu_flag_test.F90 << EOF
468 program gnu_flag_test
469 #ifdef __GNUC__
470 #if __GNUC__ > 9
471 call exit(1) ! A GNU extension, but at this point we know this is a GNU compiler
472 #endif
473 #endif
474 end program gnu_flag_test
477 # The above test program gives exit status 1 iff we are using the GNU Fortran
478 # compiler with a major version greater than 9
480 FC=`grep ^SFC configure.wps | cut -d"=" -f2-`
481 FFLAGS=`grep ^FFLAGS configure.wps | cut -d"=" -f2-`
482 $FC ${FFLAGS} gnu_flag_test.F90 -o gnu_flag_test > /dev/null 2>&1
483 if [ -f ./gnu_flag_test ]; then
484 ./gnu_flag_test > /dev/null 2>&1
485 if [ $? -eq 1 ]; then
486 compat="-fallow-argument-mismatch"
488 rm gnu_flag_test
489 else
490 printf "*** Failed to compile the gnu_flag_test program!\n"
491 printf " This may be because the selected build option does not work correctly.\n"
493 rm gnu_flag_test.F90
495 sed "s/CONFIGURE_COMPAT_FLAGS/${compat}/" configure.wps > configure.wps.tmp
496 mv configure.wps.tmp configure.wps