-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ksh
executable file
·355 lines (293 loc) · 8.02 KB
/
build.ksh
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
#!/bin/ksh
known_hosts()
{
set -A kh vayu cher burn shin jigg raij
}
## jiggle
host_jigg()
{
export NCDIR='/usr/local/lib'
export NCMOD='/usr/local/include'
export FC=gfortran
export CFLAGS='-O2 -x f95-cpp-input -ffree-form -ffree-line-length-0'
export LD='-lnetcdf -lnetcdff'
export LDFLAGS='-L/usr/local/lib -O2'
build_build
cd ../
build_status
}
## shine-cl.nexus.csiro.au
host_shin()
{
export NCDIR='/usr/local/intel/lib'
export NCMOD='/usr/local/intel/include'
export FC=ifort
export CFLAGS='-O2 -fp-model precise -ftz -fpe0'
export LD='-lnetcdf'
export LDFLAGS='-L/usr/local/intel/lib -O2'
build_build
cd ../
build_status
}
## burnet.hpsc.csiro.au
host_burn()
{
export NCDIR=$NETCDF_ROOT'/lib/'
export NCMOD=$NETCDF_ROOT'/include/'
export FC=$F90
export CFLAGS='-O2 -fp-model precise'
export LDFLAGS='-L'$NCDIR' -O2'
export LD='-lnetcdf -lnetcdff'
build_build
cd ../
build_status
}
## cherax.hpsc.csiro.au
host_cher()
{
export NCDIR=$NETCDF_ROOT'/lib/'
export NCMOD=$NETCDF_ROOT'/include/'
export FC=$F90
export CFLAGS='-O2 -fp-model precise'
export LDFLAGS='-L'$NCDIR' -O2'
export LD='-lnetcdf -lnetcdff'
build_build
cd ../
build_status
}
## vayu.nci.org.au
host_vayu()
{
export NCDIR=$NETCDF_ROOT'/lib/Intel'
export NCMOD=$NETCDF_ROOT'/include/Intel'
export FC=$F90
export CFLAGS='-O2 -fp-model precise'
if [[ $1 = 'debug' ]]; then
export CFLAGS='-O0 -traceback -g -fp-model precise -ftz -fpe0'
fi
export LDFLAGS='-L'$NCDIR' -O2'
export LD='-lnetcdf'
build_build
cd ../
build_status
}
## raijin.nci.org.au
host_raij()
{
module load netcdf
export NCDIR=$NETCDF_ROOT'/lib/Intel'
export NCMOD=$NETCDF_ROOT'/include/Intel'
export FC=$F90
export CFLAGS='-O2 -fp-model precise'
if [[ $1 = 'debug' ]]; then
export CFLAGS='-O0 -traceback -g -fp-model precise -ftz -fpe0'
fi
export LDFLAGS='-L'$NCDIR' -O2'
export LD='-lnetcdf -lnetcdff'
build_build
cd ../
build_status
}
## unknown machine, user entering options stdout
host_read()
{
print "\n\tWhat is the ROOT path of your NetCDF library" \
"and .mod file. "
print "\tRemember these have to be created by the same " \
"Fortran compiler you"
print "\twant to use to build CABLE. e.g./usr/local/intel"
read NCDF_ROOT
print "\n\tWhat is the path, relative to the above ROOT, of " \
"your NetCDF library."
print "\n\tPress enter for default [lib]."
read NCDF_DIR
if [[ $NCDF_DIR == '' ]]; then
export NCDIR=$NCDF_ROOT/'lib'
else
export NCDIR=$NCDF_ROOT/$NCDF_DIR
fi
print "\n\tWhat is the path, relative to the above ROOT, of " \
"your NetCDF .mod file."
print "\n\tPress enter for default [include]."
read NCDF_MOD
if [[ $NCDF_MOD == '' ]]; then
export NCMOD=$NCDF_ROOT/'include'
else
export NCMOD=$NCDF_ROOT/$NCDF_MOD
fi
print "\n\tWhat is the Fortran compiler you wish to use."
print "\te.g. ifort, gfortran"
print "\n\tPress enter for default [ifort]."
read FCRESPONSE
if [[ $FCRESPONSE == '' ]]; then
export FC='ifort'
else
export FC=$FCRESPONSE
fi
print "\n\tWhat are the approriate compiler options"
print "\te.g.(ifort) -O2 -fp-model precise "
print "\n\tPress enter for default [-O2 -fp-model precise]."
read CFLAGRESPONSE
if [[ $CFLAGRESPONSE == '' ]]; then
export CFLAGS='-O2 -fp-model precise'
else
export CFLAGS=$CFLAGRESPONSE
fi
iflags='-L'$NCDIR' -O2'
export LDFLAGS=$iflags
print "\n\tWhat are the approriate libraries to link"
print "\te.g.(most systems) -lnetcdf "
print "\n\tPress enter for default [-lnetcdf]."
read LDRESPONSE
if [[ $LDRESPONSE == '' ]]; then
export LD='-lnetcdf'
else
export LD=$LDRESPONSE
fi
}
host_write()
{
print '#!/bin/ksh' > junk
print '' >> junk
print 'known_hosts()' >> junk
print '{' >> junk
print ' set -A kh' ${kh[*]} $HOST_MACH >> junk
print '}' >> junk
print '' >> junk
print '' >> junk
print '## '$HOST_COMM >> junk
print 'host_'$HOST_MACH'()' >> junk
print '{' >> junk
print ' export NCDIR='"'"$NCDIR"'" >> junk
print ' export NCMOD='"'"$NCMOD"'" >> junk
print ' export FC='$FC >> junk
print ' export CFLAGS='"'"$CFLAGS"'" >> junk
print ' export LD='"'"$LD"'" >> junk
print ' export LDFLAGS='"'"$LDFLAGS"'" >> junk
print ' build_build' >> junk
print ' cd ../' >> junk
print ' build_status' >> junk
print '}' >> junk
print '' >> junk
print '' >> junk
}
clean_build()
{
print '\ncleaning up\n'
rm -fr .tmp
print '\n\tPress Enter too continue buiding, Control-C to abort now.\n'
read dummy
}
not_recognized()
{
print "\n\n\tThis is not a recognized host for which we " \
"know the location of the"
print "\tnetcdf distribution and correct compiler switches."
print "\n\tPlease enter these details as prompted, and the " \
"script will be "
print "\tupdated accordingly. "
print "\n\tIf this is a common machine for CABLE users, " \
"please email"
print "\n\t\t cable_help@nf.nci.org.au "
print "\n\talong with your new build.ksh so that we can " \
"update the script "
print "\tfor all users. "
print "\n\tTo enter compile options for this build press " \
"enter, otherwise "
print "\tControl-C to abort script."
host_read
print "\n\tPlease supply a comment include the new build " \
"script."
print "\n\tGenerally the host URL e.g. raijin.nci.org.au "
read HOST_COMM
build_build
}
do_i_no_u()
{
integer kmax=${#kh[*]}
integer k=0
typeset -f subr
while [[ $k -lt $kmax ]]; do
if [[ $HOST_MACH = ${kh[$k]} ]];then
print 'Host recognized as' $HOST_MACH
subr=host_${kh[$k]}
$subr $1
fi
(( k = k + 1 ))
done
}
build_status()
{
if [[ -f .tmp/cable ]]; then
mv .tmp/cable .
print '\nBUILD OK\n'
else
print '\nOooops. Something went wrong\n'
print '\nKnown build issues:\n'
print '\nSome systems require additional library. \n'
print '\nEdit Makefile_offline; add -lnetcdff to LD = ...\n'
fi
exit
}
i_do_now()
{
cd ../
host_write
tail -n +7 build.ksh > build.ksh.tmp
cat junk build.ksh.tmp > build.ksh.new
mv build.ksh.new build.ksh
chmod u+x build.ksh
rm -f build.ksh.tmp build.ksh.new junk
build_status
}
build_build()
{
# write file for consumption by Fortran code
# get SVN revision number
#echo ""
#echo ""
##alias svn='/opt/subversion/bin/svn'
##echo `which svn`
#echo ""
#echo ""
CABLE_REV=`svn info | grep Revis |cut -c 11-18`
if [[ $CABLE_REV="" ]]; then
echo "this is not an svn checkout"
CABLE_REV=0
echo "setting CABLE revision number to " $CABLE_REV
fi
print $CABLE_REV > ~/.cable_rev
# get SVN status
CABLE_STAT=`svn status`
print $CABLE_STAT >> ~/.cable_rev
if [[ ! -d .tmp ]]; then
mkdir .tmp
fi
if [[ -f cable ]]; then
print '\ncable executable exists. copying to dated backup file\n'
mv cable cable.`date +%d.%m.%y`
fi
CORE="../core/biogeophys"
DRV="."
CASA="../core/biogeochem"
/bin/cp -p $CORE/*90 ./.tmp
/bin/cp -p $DRV/*90 ./.tmp
/bin/cp -p $CASA/*90 ./.tmp
print "\n\n\tPlease note: CASA-CNP files are included in build only for "
print "\ttechnical reasons. Implementation is not officially available with"
print "\tthe release of CABLE 2.0\n"
/bin/cp -p Makefile_offline ./.tmp
cd .tmp/
make -f Makefile_offline
}
###########################################
## build.ksh - MAIN SCRIPT STARTS HERE ##
###########################################
if [[ $1 = 'clean' ]]; then
clean_build
fi
known_hosts
HOST_MACH=`uname -n | cut -c 1-4`
do_i_no_u $1
not_recognized
i_do_now