-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·394 lines (350 loc) · 11.2 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
#!/bin/sh
arg1=$1
# 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
# Found perl, so proceed with configuration
perl arch/Config.pl -perl=$PERL -netcdf=$NETCDF -netcdff=$NETCDFF -os=$os -mach=$mach
#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-`
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