Fix string comparison
[WPS.git] / configure
blobd95c5b6e505de06de08622e6c455e2dc90f602ac
1 #!/bin/sh
3 arg1=$1
5 # Look for netcdf
6 if test -z "$NETCDF" ; then
7 for p in /usr/local/netcdf
8 do
9 if test -d $p ; then
10 NETCDF=$p
11 break
13 done
16 if test -z "$NETCDF" ; then
18 if [ `hostname | cut -c 1-2` = "bs" -o \
19 `hostname | cut -c 1-2` = "bv" -o \
20 `hostname` = "tempest" -o `hostname` = "lightning" ] ; then
21 echo 'Compiling on an NCAR system with weird paths to NetCDF'
22 echo 'Setting up a local NetCDF directory with symlinks'
23 if ( test -d ./netcdf_links ) ; then
24 echo 'A directory ./netcdf_links already exists. Continuing.'
25 else
26 mkdir ./netcdf_links
27 if [ -z "$OBJECT_MODE" ] ; then
28 OBJECT_MODE=32
29 export OBJECT_MODE
31 if [ $OBJECT_MODE -ne 64 -a \( `hostname | cut -c 1-2` = "bs" \) ] ; then
32 ( cd ./netcdf_links ; ln -s /usr/local/lib32/r4i4 ./lib ; \
33 ln -s /usr/local/include ./include )
34 else
35 ( cd ./netcdf_links ; ln -s /usr/local/lib64/r4i4 ./lib ; \
36 ln -s /usr/local/include ./include )
39 NETCDF=`pwd`/netcdf_links
40 export NETCDF
43 else
44 bedone=""
45 if [ -d ./netcdf_links ] ; then
46 echo '** There is an existing ./netcdf_links file. Should I use? [y]'
47 read resp
48 if [ "$resp" = "y" ] ; then
49 NETCDF=`pwd`/netcdf_links
50 bedone="yes"
51 else
52 echo 'Removing existing ./netcdf_links directory'
53 /bin/rm -fr ./netcdf_links
55 else
56 echo '** WARNING: No path to NETCDF and environment variable NETCDF not set.'
57 echo '** would you like me to try to fix? [y]'
59 netcdfipath=""
60 netcdflpath=""
61 while [ -z "$bedone" ] ; do
62 read resp
63 if [ "$resp" = "y" -o -z "$resp" ] ; then
64 if [ -d ./netcdf_links ] ; then
65 echo 'There is already a ./netcdf_links directory. Okay to use links'
66 echo 'in this directory for NetCDF include and lib dirs? [y]'
67 read resp
68 if [ "$resp" = "y" ] ; then
69 NETCDF=`pwd`/netcdf_links
70 export NETCDF
71 bedone="yes"
72 continue
75 if [ -z "$netcdfipath" ] ; then
76 echo 'Enter full path to NetCDF include directory on your system'
77 read resp
78 if [ ! -d "$resp" ] ; then
79 echo "invalid path: $resp. Try again? [y]" ; continue
81 netcdfipath=$resp
83 if [ -z "$netcdflpath" ] ; then
84 echo 'Enter full path to NetCDF library directory on your system'
85 read resp
86 if [ ! -d "$resp" ] ; then
87 echo "invalid path: $resp. Try again? [y]" ; continue
89 netcdflpath=$resp
92 if [ -n "$netcdflpath" -a -n "$netcdfipath" ] ; then
93 if [ -d ./netcdf_links ] ; then
94 echo 'Existing ./netcdf_links directory. Okay to remove. [y]'
95 read resp
96 if [ "$resp" = "y" ] ; then
97 /bin/rm -fr ./netcdf_links
100 mkdir ./netcdf_links
101 cd ./netcdf_links
102 ln -s "$netcdfipath" include
103 ln -s "$netcdflpath" lib
104 cd ..
105 echo created new ./netcdf_links directory
106 /bin/ls -lF ./netcdf_links
107 NETCDF=`pwd`/netcdf_links
108 export NETCDF
109 bedone="yes"
111 else
112 bedone="yes"
114 done
118 if [ -n "$NETCDF" ] ; then
119 echo "Will use NETCDF in dir: $NETCDF"
120 # for 3.6.2 and greater there might be a second library, libnetcdff.a . Check for this and use
121 # if available
122 NETCDFF=" "
123 if [ -f "$NETCDF/lib/libnetcdff.a" ] ; then
124 NETCDFF="-lnetcdff"
126 else
127 echo "Will configure for use without NetCDF"
130 # if the uname command exists, give it a shot and see if
131 # we can narrow the choices; otherwise, spam 'em
132 os="ARCH"
133 mach="ARCH"
134 type uname > /dev/null
135 if [ $? -eq 0 ] ; then
136 os=`uname`
137 if [ "$os" = "AIX" -o "$os" = "IRIX" -o "$os" = "IRIX64" -o "$os" = "SunOS" -o "$os" = "HP-UX" -o "$os" = "Darwin" ] ; then
138 mach="ARCH"
139 else
140 xxx=`expr "$os" : '\(.........\).*'`
141 if [ "$xxx" = "CYGWIN_NT" ] ; then
142 os=$xxx
144 if [ "$os" = "OSF1" -o "$os" = "Linux" -o "$os" = "UNICOS/mp" -o "$os" = "UNIX_System_V" -o "$os" = "CYGWIN_NT" ] ; then
145 mach=`uname -m`
146 else
147 os="ARCH"
148 mach="ARCH"
153 wrf_dir="none"
154 standard_wrf_dirs="WRF WRF-4.0.3 WRF-4.0.2 WRF-4.0.1 WRF-4.0 WRFV3"
157 # If no WRF_DIR environment variable is set, try to locate a WRF build in one
158 # of the expected directory names one directory level up; otherwise, try to use
159 # the WRF I/O library from the code in $WRF_DIR
161 if [ -z "$WRF_DIR" ]; then
162 # for d in WRF WRF-4.0.3 WRF-4.0.2 WRF-4.0.1 WRF-4.0 WRFV3; do
163 for d in ${standard_wrf_dirs}; do
164 if [ -e ../${d}/external/io_netcdf/libwrfio_nf.a ]; then
165 echo "Found what looks like a valid WRF I/O library in ../${d}"
166 wrf_dir="../${d}"
167 break
169 done
170 else
171 if [ ! -e ${WRF_DIR}/external/io_netcdf/libwrfio_nf.a ]; then
172 echo ""
173 echo "Error: The \$WRF_DIR environment variable was set, but the WRF code at"
174 echo " ${WRF_DIR} doesn't appear to have been successfully compiled"
175 echo ""
176 exit
179 echo "Using WRF I/O library in WRF build identified by \$WRF_DIR: ${WRF_DIR}"
180 wrf_dir=$WRF_DIR
183 if [ $wrf_dir = "none" ]; then
184 echo ""
185 echo "Error: No compiled WRF code found. Please check that the WRF model has been compiled"
186 echo " one directory level up (i.e., ../) in a directory named 'WRF', 'WRF-4.0.3', 'WRF-4.0.2', etc.,"
187 echo " or specify the full path to the compiled WRF model with the environment variable \$WRF_DIR ."
188 echo ""
189 exit
192 # Found perl, so proceed with configuration
193 perl arch/Config.pl -perl=$PERL -netcdf=$NETCDF -netcdff=$NETCDFF -os=$os -mach=$mach -wrfdir=$wrf_dir
196 #Checking cross-compiling capability for some particular environment
197 #on Linux and Mac box
199 if [ $os = "Linux" -o $os = "Darwin" ]; then
201 SFC=`grep '^SFC' configure.wps | awk '{print $3}'`
202 SCC=`grep '^SCC' configure.wps | awk '{print $3}'`
204 SFC="`type $SFC 2>/dev/null | awk '{print $NF}' | sed -e 's/(//g;s/)//g'`"
205 SCC="`type $SCC 2>/dev/null | awk '{print $NF}' | sed -e 's/(//g;s/)//g'`"
207 if [ -e $NETCDF/lib/libnetcdf.a -a "$SFC" != "" -a "$SCC" != "" ]; then
209 SFC_MULTI_ABI=0
210 SCC_MULTI_ABI=0
211 CROSS_COMPILING=0
213 foo=foo_$$
215 echo
216 echo Testing for NetCDF, C and Fortran compiler
217 echo
219 cat > ${foo}.c <<EOF
220 int main(int argc, char ** argv)
222 return (0);
226 cat > ${foo}.f <<EOF
227 program test_exit
228 integer :: STATUS = 0
229 call EXIT(STATUS)
230 end program test_exit
233 nct=`nm $NETCDF/lib/libnetcdf.a | grep '^0' | cut -d' ' -f 1 | head -1 | wc -c | awk '{print $1+0}'`
234 if [ "$nct" -eq "9" ]; then
235 netcdf_arch="32-bit"
236 else
237 netcdf_arch="64-bit"
240 $SFC -o ${foo} ${foo}.f > /dev/null 2>&1
241 SFC_arch="`file ${foo} | grep -o -E '[0-9]{2}-bit|i386'`"
242 rm ${foo} ${foo}.o 2> /dev/null
244 $SCC -o ${foo} ${foo}.c > /dev/null 2>&1
245 SCC_arch="`file ${foo} | grep -o -E '[0-9]{2}-bit|i386'`"
246 rm ${foo} ${foo}.o 2> /dev/null
248 if [ "$SFC_arch" = "" -o "$SCC_arch" = "" ]; then
249 echo " One of compilers testing failed!"
250 echo " Please check your compiler"
251 echo
252 rm -f ${foo} ${foo}.[cfo] 2> /dev/null
253 exit
254 else
255 cp configure.wps configure.wps.edit
258 case $netcdf_arch in
260 32-bit|i386 )
262 if [ "$SFC_arch" = "64-bit" ] ; then
263 CROSS_COMPILING=1
264 $SFC -m32 -o ${foo} ${foo}.f > /dev/null 2>&1
265 if [ $? = 0 ]; then
266 SFC_MULTI_ABI=1
267 sed '/^SFC.*=/s/$/ -m32/' configure.wps.edit > configure.wps.tmp
268 mv configure.wps.tmp configure.wps.edit
271 if [ "$SCC_arch" = "64-bit" ] ; then
272 CROSS_COMPILING=1
273 $SCC -m32 -o ${foo} ${foo}.c > /dev/null 2>&1
274 if [ $? = 0 ]; then
275 SCC_MULTI_ABI=1
276 sed '/^SCC.*=/s/$/ -m32/' configure.wps.edit > configure.wps.tmp
277 mv configure.wps.tmp configure.wps.edit
281 if [ $CROSS_COMPILING -eq 1 ] ; then
282 echo NOTE:
283 echo This installation NetCDF is 32-bit
284 if [ \( $SFC_MULTI_ABI -ne 1 -a "$SFC_arch" = "64-bit" \) \
285 -o \( $SCC_MULTI_ABI -ne 1 -a "$SCC_arch" = "64-bit" \) ] ; then
286 rm configure.wps.edit
287 echo One of compilers is 64-bit and doesn\'t support cross-compiling.
288 echo Please check your NETCDF lib and compiler
289 else
290 echo -m32 is appended to configure.wps
291 echo It will be forced to build in 32-bit.
292 echo If you don\'t want 32-bit binaries, please use 64-bit NetCDF, and re-run the configure script.
297 64-bit )
299 if [ "$SFC_arch" = "32-bit" -o "$SFC_arch" = "i386" ] ; then
300 CROSS_COMPILING=1
301 $SFC -m64 -o ${foo} ${foo}.f > /dev/null 2>&1
302 if [ $? = 0 ]; then
303 SFC_MULTI_ABI=1
304 sed '/^SFC.*=/s/$/ -m64/' configure.wps.edit > configure.wps.tmp
305 mv configure.wps.tmp configure.wps.edit
308 if [ "$SCC_arch" = "32-bit" -o "$SCC_arch" = "i386" ] ; then
309 CROSS_COMPILING=1
310 $SCC -m64 -o ${foo} ${foo}.c > /dev/null 2>&1
311 if [ $? = 0 ]; then
312 SCC_MULTI_ABI=1
313 sed '/^SCC.*=/s/$/ -m64/' configure.wps.edit > configure.wps.tmp
314 mv configure.wps.tmp configure.wps.edit
318 if [ $CROSS_COMPILING -eq 1 ] ; then
319 echo NOTE:
320 echo This installation NetCDF is 64-bit
321 if [ \( $SFC_MULTI_ABI -ne 1 -a "$SFC_arch" != "64-bit" \) \
322 -o \( $SCC_MULTI_ABI -ne 1 -a "$SCC_arch" != "64-bit" \) ]; then
323 rm configure.wps.edit
324 echo One of Compilers is 32-bit and doesn\'t support cross-compiling.
325 echo Please check your NetCDF lib and compiler
326 else
327 echo -m64 is appended to configure.wps
328 echo It will be forced to build in 64-bit.
329 echo If you don\'t want 64-bit binaries, please use 32-bit NetCDF, and re-run the configure script.
333 esac
334 rm -f ${foo} ${foo}.[cfo] 2> /dev/null
336 if [ -e configure.wps.edit ]; then
337 mv configure.wps.edit configure.wps
340 if [ $CROSS_COMPILING -eq 0 ] ; then
341 echo This installation NetCDF is $netcdf_arch
342 echo C compiler is $SCC_arch
343 echo Fortran compiler is $SFC_arch
345 echo
347 # Does our Fortran work with the given NETCDF library.
349 /bin/rm -f fort_netcdf.f fort_netcdf
350 cat > fort_netcdf.f <<EOF
351 program foo
352 include 'netcdf.inc'
353 integer ncid , status
354 status = nf_open ( 'foo.nc' , 0 , ncid )
355 print *,'status = ',status
356 end program
358 FFLAGS=`grep ^FFLAGS configure.wps | cut -d"=" -f2-`
359 cp $NETCDF/include/netcdf.inc .
360 FC=`grep ^SFC configure.wps | cut -d"=" -f2-`
361 $FC ${FFLAGS} fort_netcdf.f -o fort_netcdf -L${NETCDF}/lib $NETCDFF -lnetcdf > /dev/null 2>&1
362 if [ -f "fort_netcdf" ] ; then
363 ./fort_netcdf > /dev/null 2>&1
364 if [ $? = 0 ]; then
365 /bin/rm -f fort_netcdf.f fort_netcdf.o fort_netcdf netcdf.inc
366 else
367 echo
368 echo "Your Fortran + NETCDF did not run successfully."
369 echo
371 else
372 echo
373 echo "Your versions of Fortran and NETCDF are not consistent."
374 echo
377 cat > c_test.c <<EOF
378 #ifndef CRAY
379 # ifdef NOUNDERSCORE
380 # define C_TEST c_test
381 # else
382 # if defined ( F2CSTYLE ) || defined ( _DOUBLEUNDERSCORE )
383 # define C_TEST c_test__
384 # else
385 # define C_TEST c_test_
386 # endif
387 # endif
388 #endif
389 #include <stdio.h>
391 int C_TEST ( float *xx, int *ii )
394 printf("OK print in C function. \n" ) ;
395 printf("Values are xx = %5.2f and ii = %d \n", *xx, *ii ) ;
396 return(0) ;
399 CFLAGS=`grep ^CFLAGS configure.wps | cut -d"=" -f2-`
400 CPPFLAGS=`grep ^CPPFLAGS configure.wps | cut -d"=" -f2-`
401 CC=`grep ^SCC configure.wps | cut -d"=" -f2-`
402 ${CC} -c ${CFLAGS} ${CPPFLAGS} c_test.c
404 cat > f_test.f90 <<EOF
405 PROGRAM f_test
406 INTEGER :: ii
407 REAL :: xx
409 ii = 1
410 xx = 2
412 CALL c_test ( xx , ii )
414 END PROGRAM f_test
416 $FC ${FFLAGS} f_test.f90 -o cf_test c_test.o > /dev/null 2>&1
417 if [ -f "cf_test" ] ; then
418 ./cf_test > /dev/null 2>&1
419 if [ $? = 0 ]; then
420 /bin/rm -f cf_test c_test.c c_test.o f_test.f90 f_test.o
421 else
422 echo
423 echo "Your Fortran + C did not run successfully."
424 echo
426 else
427 echo
428 echo "Your versions of Fortran and C are not consistent."
429 echo