/[MITgcm]/MITgcm/tools/genmake2
ViewVC logotype

Annotation of /MITgcm/tools/genmake2

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.272 - (hide annotations) (download)
Fri Jul 3 21:33:55 2015 UTC (4 years, 2 months ago) by heimbach
Branch: MAIN
CVS Tags: checkpoint65n
Changes since 1.271: +7 -1 lines
Merge and update from Krishna Narayanan's contrib area:
o genmake2 flag -diva (but only for OpenAD)
o required modifs for OAD_support

1 edhill 1.86 #! /usr/bin/env bash
2 edhill 1.1 #
3 heimbach 1.272 # $Header: /u/gcmpack/MITgcm_contrib/snarayan/divided_adjoint/tools/genmake2,v 1.1 2015/05/19 21:32:23 snarayan Exp $
4 jmc 1.233 # $Name: $
5 edhill 1.1 #
6     # Makefile generator for MITgcm UV codes
7     # created by cnh 03/98
8     # adapted by aja 06/98
9     # modified by aja 01/00
10     # rewritten in bash by eh3 08/03
11    
12 jmc 1.214 # Explain usage
13     usage() {
14     cat <<EOF
15    
16     Usage: "$0" [OPTIONS]
17     where [OPTIONS] can be:
18    
19     -help | --help | -h | --h
20 jmc 1.237 Print this help message and exit.
21 jmc 1.214
22 jmc 1.264 -oad | --oad
23     Generate a Makefile for an OpenAD built
24    
25 jmc 1.269 -nocat4ad | -dog4ad | -ncad | -dad
26     do not concatenate (cat) source code sent to TAF
27     resulting in compilation of multiple files
28    
29 jmc 1.214 -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME
30     -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME
31 jmc 1.237 Use "NAME" as the adoptfile. By default, the file at
32 jmc 1.264 "tools/adjoint_options/adjoint_oad" (for OpenAD built) or
33 jmc 1.237 "tools/adjoint_options/adjoint_default" will be used.
34 jmc 1.214
35     -nooptfile | --nooptfile
36     -optfile NAME | --optfile NAME | -of NAME | --of NAME
37     -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
38 jmc 1.237 Use "NAME" as the optfile. By default, an attempt will be
39     made to find an appropriate "standard" optfile in the
40     tools/build_options/ directory.
41 jmc 1.214
42     -pdepend NAME | --pdepend NAME
43     -pdepend=NAME | --pdepend=NAME
44 jmc 1.237 Get package dependency information from "NAME".
45 jmc 1.214
46     -pgroups NAME | --pgroups NAME
47     -pgroups=NAME | --pgroups=NAME
48 jmc 1.237 Get the package groups information from "NAME".
49 jmc 1.214
50     -bash NAME
51 jmc 1.237 Explicitly specify the Bourne or BASH shell to use
52 jmc 1.214
53     -make NAME | -m NAME
54     --make=NAME | -m=NAME
55 jmc 1.237 Use "NAME" for the MAKE program. The default is "make" but
56     many platforms, "gmake" is the preferred choice.
57 jmc 1.214
58     -makefile NAME | -mf NAME
59     --makefile=NAME | -mf=NAME
60 jmc 1.237 Call the makefile "NAME". The default is "Makefile".
61 jmc 1.214
62     -makedepend NAME | -md NAME
63     --makedepend=NAME | -md=NAME
64 jmc 1.237 Use "NAME" for the MAKEDEPEND program.
65 jmc 1.214
66     -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
67     -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
68 jmc 1.237 Specify the location of the MITgcm ROOTDIR as "NAME".
69     By default, genamke will try to find the location by
70     looking in parent directories (up to the 5th parent).
71 jmc 1.214
72     -mods NAME | --mods NAME | -mo NAME | --mo NAME
73     -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
74 jmc 1.237 Here, "NAME" specifies a list of directories that are
75     used for additional source code. Files found in the
76     "mods list" are given preference over files of the same
77     name found elsewhere.
78 jmc 1.214
79     -disable NAME | --disable NAME
80     -disable=NAME | --disable=NAME
81 jmc 1.237 Here "NAME" specifies a list of packages that we don't
82     want to use. If this violates package dependencies,
83     genamke will exit with an error message.
84 jmc 1.214
85     -enable NAME | --enable NAME
86     -enable=NAME | --enable=NAME
87 jmc 1.237 Here "NAME" specifies a list of packages that we wish
88     to specifically enable. If this violates package
89     dependencies, genamke will exit with an error message.
90 jmc 1.214
91     -standarddirs NAME | --standarddirs NAME
92     -standarddirs=NAME | --standarddirs=NAME
93 jmc 1.237 Here, "NAME" specifies a list of directories to be
94     used as the "standard" code.
95 jmc 1.214
96     -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
97     -fc=NAME | --fc=NAME
98 jmc 1.237 Use "NAME" as the fortran compiler. By default, genmake
99     will search for a working compiler by trying a list of
100     "usual suspects" such as g77, f77, etc.
101 jmc 1.214
102     -cc NAME | --cc NAME | -cc=NAME | --cc=NAME
103 jmc 1.237 Use "NAME" as the C compiler. By default, genmake
104     will search for a working compiler by trying a list of
105     "usual suspects" such as gcc, c89, cc, etc.
106 jmc 1.214
107     -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4
108 jmc 1.237 Use "real*4" type for _RS variable (#undef REAL4_IS_SLOW)
109     *only* works if CPP_EEOPTIONS.h allows this.
110 jmc 1.214
111     -ignoretime | -ignore_time | --ignoretime | --ignore_time
112 jmc 1.237 Ignore all the "wall clock" routines entirely. This will
113     not in any way hurt the model results -- it simply means
114     that the code that checks how long the model spends in
115     various routines will give junk values.
116 jmc 1.214
117     -ts | --ts
118 jmc 1.237 Produce timing information per timestep
119 jmc 1.214 -papis | --papis
120 jmc 1.237 Produce summary MFlop/s (and IPC) with PAPI per timestep
121 jmc 1.214 -pcls | --pcls
122 jmc 1.237 Produce summary MFlop/s etc. with PCL per timestep
123 jmc 1.214 -foolad | --foolad
124 jmc 1.237 Fool the AD code generator
125 jmc 1.214 -papi | --papi
126 jmc 1.237 Performance analysis with PAPI
127 jmc 1.214 -pcl | --pcl
128 jmc 1.237 Performance analysis with PCL
129 jmc 1.214 -hpmt | --hpmt
130 jmc 1.237 Performance analysis with the HPM Toolkit
131 jmc 1.214
132 jmc 1.220 -ieee | --ieee
133 jmc 1.237 use IEEE numerics. Note that this option *only* works
134     if it is supported by the OPTFILE that is being used.
135 jmc 1.220 -devel | --devel
136 jmc 1.237 Add additional warning and debugging flags for development
137     (if supported by the OPTFILE); also switch to IEEE numerics.
138 jmc 1.214 -gsl | --gsl
139 jmc 1.237 Use GSL to control floating point rounding and precision
140 jmc 1.214
141     -mpi | --mpi
142 jmc 1.237 Include MPI header files and link to MPI libraries
143 jmc 1.214 -mpi=PATH | --mpi=PATH
144 jmc 1.237 Include MPI header files and link to MPI libraries using MPI_ROOT
145     set to PATH. i.e. Include files from \$PATH/include, link to libraries
146     from \$PATH/lib and use binaries from \$PATH/bin.
147 jmc 1.214
148     -omp | --omp
149 jmc 1.237 Activate OpenMP code + use Compiler option OMPFLAG
150 jmc 1.214 -omp=OMPFLAG | --omp=OMPFLAG
151 jmc 1.237 Activate OpenMP code + use Compiler option OMPFLAG
152 jmc 1.214
153     -es | --es | -embed-source | --embed-source
154 jmc 1.237 Embed a tarball containing the full source code
155     (including the Makefile, etc.) used to build the
156     executable [off by default]
157 jmc 1.214
158     -ds | --ds
159 jmc 1.237 Report genmake internal variables status (DUMPSTATE)
160     to file "genmake_state" (for debug purpose)
161 jmc 1.214
162     While it is most often a single word, the "NAME" variables specified
163     above can in many cases be a space-delimited string such as:
164    
165     --enable pkg1 --enable 'pkg1 pkg2' --enable 'pkg1 pkg2 pkg3'
166     -mods=dir1 -mods='dir1' -mods='dir1 dir2 dir3'
167     -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
168    
169     which, depending upon your shell, may need to be single-quoted.
170    
171     For more detailed genmake documentation, please see:
172    
173     http://mitgcm.org/public/devel_HOWTO/
174    
175     EOF
176    
177     exit 1
178     }
179    
180 edhill 1.12 # Search for particular CPP #cmds associated with packages
181     # usage: test_for_package_in_cpp_options CPP_file package_name
182     test_for_package_in_cpp_options() {
183     cpp_options=$1
184     pkg=$2
185 jmc 1.239 test_for_string_in_file $cpp_options "^ *# *define *\<ALLOW_$pkg\>"
186     test_for_string_in_file $cpp_options "^ *# *undef *\<ALLOW_$pkg\>"
187     test_for_string_in_file $cpp_options "^ *# *define *\<DISABLE_$pkg\>"
188     test_for_string_in_file $cpp_options "^ *# *undef *\<DISABLE_$pkg\>"
189 adcroft 1.52 }
190    
191     # Search for particular CPP #cmds associated with MPI
192     # usage: test_for_mpi_in_cpp_eeoptions CPP_file
193     test_for_mpi_in_cpp_eeoptions() {
194     cpp_options=$1
195 jmc 1.239 test_for_string_in_file $cpp_options "^ *# *define *\<ALLOW_USE_MPI\>"
196     test_for_string_in_file $cpp_options "^ *# *undef *\<ALLOW_USE_MPI\>"
197 adcroft 1.52 }
198    
199     # Search for particular string in a file. Return 1 if detected, 0 if not
200     # usage: test_for_string_in_file file string
201     test_for_string_in_file() {
202     file=$1
203     strng=$2
204 jmc 1.239 grep "$strng" $file > /dev/null 2>&1
205 edhill 1.12 RETVAL=$?
206     if test "x${RETVAL}" = x0 ; then
207 edhill 1.71 printf "Error: In $file there is an illegal line: "
208 jmc 1.237 grep -i "$strng" $file
209 edhill 1.146 exit 99
210 edhill 1.12 fi
211 adcroft 1.52 return 0
212 edhill 1.12 }
213    
214     # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to
215     # the package list.
216     expand_pkg_groups() {
217     new_packages=
218     if test -r $PKG_GROUPS ; then
219 jmc 1.260 cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > $TMP.p1
220     cat $TMP.p1 | $AWK '(NF>2 && $2==":"){ print $0 }' > $TMP.p2
221 edhill 1.12 matched=0
222     for i in $PACKAGES ; do
223 jmc 1.260 line=`grep "^ *$i" $TMP.p2`
224 edhill 1.12 RETVAL=$?
225     if test "x$RETVAL" = x0 ; then
226     matched=1
227 edhill 1.15 replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`
228 jmc 1.208 echo " replacing \"$i\" with:$replace"
229 edhill 1.12 new_packages="$new_packages $replace"
230     else
231     new_packages="$new_packages $i"
232     fi
233     done
234     PACKAGES=$new_packages
235 jmc 1.260 rm -f $TMP.p[1,2]
236 adcroft 1.74 return $matched
237 edhill 1.12 else
238     echo "Warning: can't read package groups definition file: $PKG_GROUPS"
239     fi
240     }
241 edhill 1.1
242 edhill 1.75 # Check for broken environments (eg. cygwin, MacOSX w/HFS+) that
243     # cannot distinguish [*.F/*.F90] from [*.f/*.f90] files.
244     check_for_broken_Ff() {
245 edhill 1.76 # Do we have defaults for $FS and/or $FS90 ?
246     tfs=f
247     tfs9=f90
248     if test "x$FS" != x ; then
249     tfs="$FS"
250     fi
251     if test "x$FS90" != x ; then
252     tfs9="$FS90"
253     fi
254    
255 edhill 1.75 # First check the ability to create a *.F/.f pair.
256 edhill 1.76 cat <<EOF >> genmake_hello.F
257 edhill 1.75 program hello
258     write(*,*) 'hi'
259     stop
260     end
261     EOF
262 edhill 1.76 cp genmake_hello.F "genmake_hello."$tfs > /dev/null 2>&1
263 edhill 1.75 RETVAL=$?
264     if test "x$RETVAL" != x0 ; then
265 edhill 1.76 if test "x$FS" = x ; then
266 edhill 1.77 FS='for'
267     FS90='fr9'
268 edhill 1.76 check_for_broken_Ff
269     else
270     cat <<EOF 2>&1
271 jmc 1.206 ERROR: Your file system cannot distinguish between *.F and *.f files
272     (fails the "cp" test) and this program cannot find a suitable
273     replacement extension. Please try a different build environment or
274 edhill 1.76 contact the <MITgcm-support@mitgcm.org> list for help.
275    
276     EOF
277     exit -1
278     fi
279 edhill 1.75 return
280     fi
281 edhill 1.76 rm -f genmake_hello.*
282 edhill 1.75
283 edhill 1.76 # Check the ability of ${MAKE} and ${LN} to use the current set
284     # of extensions.
285     cat <<EOF >> genmake_hello.F
286     program hello
287     write(*,*) 'hi'
288     stop
289     end
290     EOF
291 edhill 1.119 test -f $MAKEFILE && mv -f $MAKEFILE $MAKEFILE".tst"
292     cat <<EOF >> $MAKEFILE
293 edhill 1.75 .SUFFIXES:
294 edhill 1.101 .SUFFIXES: .$tfs .F
295     .F.$tfs:
296     $LN \$< \$@
297 edhill 1.75 EOF
298 jmc 1.228 $MAKE -f $MAKEFILE "genmake_hello."$tfs > /dev/null 2>&1
299 edhill 1.75 RETVAL=$?
300 edhill 1.88 if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then
301 edhill 1.76 if test "x$FS" = x ; then
302 edhill 1.77 FS='for'
303     FS90='fr9'
304 edhill 1.76 check_for_broken_Ff
305     else
306 jmc 1.236 echo "ERROR: test: '$MAKE -f $MAKEFILE genmake_hello.$tfs' Failed"
307     echo " see simple makefile: '$MAKEFILE' (left here)"
308     echo " Please check (1) your '$MAKE' command, (2) your '$LN' command"
309     echo " and (3) the allowed sufix '.F' and '.$tfs' in makefile"
310     echo " or contact the <MITgcm-support@mitgcm.org> list for help."
311     echo ""
312 edhill 1.76 exit -1
313     return
314     fi
315 edhill 1.75 fi
316 edhill 1.119 rm -f genmake_hello.* $MAKEFILE
317     test -f $MAKEFILE".tst" && mv -f $MAKEFILE".tst" $MAKEFILE
318 edhill 1.75
319 edhill 1.76 # If we make it here, use the extensions
320     FS=$tfs
321     FS90=$tfs9
322     return
323 edhill 1.75 }
324    
325 edhill 1.84 look_for_makedepend() {
326 adcroft 1.33
327 edhill 1.69 # The "original" makedepend is part of the Imake system that is
328     # most often distributed with XFree86 or with an XFree86 source
329     # package. As a result, many machines (eg. generic Linux) do not
330     # have a system-default "makedepend" available. For those
331     # systems, we have two fall-back options:
332     #
333     # 1) a makedepend implementation shipped with the cyrus-imapd
334     # package: ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
335 jmc 1.250 # 2) a local tools/xmakedepend shell script
336 edhill 1.69 #
337     # So the choices are, in order:
338     # 1) use the user-specified program
339 jmc 1.250 # 2) use the local xmakedepend script (get all dependencies, but slower)
340     # 3) use a system-wide default
341     # 4) locally build and use the cyrus makedepend
342     # (faster, but can miss some dependencies)
343 edhill 1.69 #
344 jmc 1.218 echo >> $LOGFILE
345     echo "running: look_for_makedepend()" >> $LOGFILE
346     if test "x${MAKEDEPEND}" != x ; then
347     echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1
348     RETVAL=$?
349     if test x"$RETVAL" = x0 ; then
350     build_cyrus_makedepend
351     RETVAL=$?
352     if test "x$RETVAL" != x0 ; then
353 jmc 1.250 echo "WARNING: unable to build cyrus-makedepend. Try other 'makedepend'"
354 jmc 1.218 MAKEDEPEND=
355     fi
356     else
357 jmc 1.221 echo "${MAKEDEPEND}" | grep 'tools.xmakedepend' > /dev/null 2>&1
358     RETVAL=$?
359     if test "x$RETVAL" = x0 ; then
360     MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
361     fi
362 jmc 1.218 echo " --> MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
363     fi
364     fi
365 adcroft 1.33 if test "x${MAKEDEPEND}" = x ; then
366 edhill 1.119 test -f $MAKEFILE && mv -f $MAKEFILE $MAKEFILE".tst"
367     # echo 'MAKEFILE="'$MAKEFILE'"'
368     cat <<EOF >> $MAKEFILE
369     # THIS IS A TEST MAKEFILE GENERATED BY "genmake2"
370     #
371 jmc 1.206 # Some "makedepend" implementations will die if they cannot
372     # find a Makefile -- so this file is here to gives them an
373 edhill 1.119 # empty one to find and parse.
374     EOF
375 edhill 1.85 cat <<EOF >> genmake_tc.f
376 edhill 1.77 program test
377     write(*,*) 'test'
378     stop
379     end
380     EOF
381 jmc 1.250 $ROOTDIR/tools/xmakedepend -f $MAKEFILE genmake_tc.f > /dev/null 2>&1
382 mlosch 1.120 RV1=$?
383 jmc 1.250 which makedepend > /dev/null 2>&1
384     RV2=$?
385     if test "x${RV2}" = x0 ; then
386     makedepend -f $MAKEFILE genmake_tc.f > /dev/null 2>&1
387     RV3=$? ; loc_msg='not working.'
388     else RV3=$RV2 ; loc_msg='not found.'
389     fi
390 edhill 1.119 test -f $MAKEFILE && rm -f $MAKEFILE
391     test -f $MAKEFILE".tst" && mv -f $MAKEFILE".tst" $MAKEFILE
392 jmc 1.250 echo " check makedepend (local: $RV1, system: $RV2, $RV3)"
393     if test "x${RV1}" = x0 ; then
394     MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
395     echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
396     elif test "x${RV3}" = x0 ; then
397     echo " local tools/xmakedepend not working. Use system-default makedepend"
398 edhill 1.85 MAKEDEPEND=makedepend
399 jmc 1.218 echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
400 edhill 1.85 else
401 jmc 1.250 echo " local tools/xmakedepend not working; system-default makedepend $loc_msg"
402     echo -n " Try to build cyrus-makedepend ..."
403 edhill 1.85 # Try to build the cyrus implementation
404 edhill 1.90 build_cyrus_makedepend
405 edhill 1.85 RETVAL=$?
406 jmc 1.250 if test "x$RETVAL" = x0 ; then
407     echo " Works"
408     else
409     echo " Fails" ; echo "" >> $LOGFILE
410     echo "ERROR: no working makedepend found ; look_for_makedepend FAILED" | tee -a $LOGFILE
411     echo ""
412     exit -1
413     return
414 edhill 1.85 fi
415 edhill 1.90 fi
416 edhill 1.1 fi
417 edhill 1.84 }
418    
419 edhill 1.90 build_cyrus_makedepend() {
420 jmc 1.218 echo >> $LOGFILE
421     echo "running: build_cyrus_makedepend()" >> $LOGFILE
422 edhill 1.90 rm -f ./genmake_cy_md
423     (
424     cd $ROOTDIR/tools/cyrus-imapd-makedepend \
425     && ./configure > /dev/null 2>&1 \
426 jmc 1.238 && $MAKE > /dev/null 2>&1
427 edhill 1.90 if test -x ./makedepend.exe ; then
428     $LN ./makedepend.exe ./makedepend
429     fi
430     ./makedepend ifparser.c > /dev/null 2>&1 \
431     && echo "true"
432     ) > ./genmake_cy_md
433     grep true ./genmake_cy_md > /dev/null 2>&1
434     RETVAL=$?
435     rm -f ./genmake_cy_md
436     if test "x$RETVAL" = x0 ; then
437     MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
438 jmc 1.218 echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
439 edhill 1.90 return 0
440     else
441 jmc 1.218 echo "WARNING: fail to build cyrus-imapd-makedepend" >> $LOGFILE
442 edhill 1.90 return 1
443     fi
444     }
445    
446 edhill 1.141 build_embed_encode()
447     {
448     printf " building the embed-encode utility... "
449     if test ! -e "$ROOTDIR/tools/embed_encode/encode_files" ; then
450 jmc 1.237 if test ! -d "$ROOTDIR/tools/embed_encode" ; then
451     echo
452     echo " Error: can't locate \"$ROOTDIR/tools/embed_encode\""
453     echo
454     EMBED_SRC=f
455 edhill 1.141 return 1
456 jmc 1.237 fi
457 edhill 1.141 clist="cc gcc c89 $CC"
458 jmc 1.206 for ic in $clist ; do
459 edhill 1.141 comm="$ic -o encode_files encode_files.c"
460     ( cd $ROOTDIR/tools/embed_encode && $comm ) > /dev/null 2>&1
461     RETVAL=$?
462     if test "x$RETVAL" = x0 ; then
463     echo "OK"
464     return 0
465     fi
466     done
467     echo
468     echo " Error: unable to build $ROOTDIR/embed_encode/encode_files"
469     echo " so it has been disabled"
470     echo
471     EMBED_SRC=f
472     return 1
473     fi
474     echo "OK"
475     }
476    
477 jmc 1.212 # look for possible C compilers
478     look_for_C_compilers() {
479 jmc 1.213 echo >> $LOGFILE
480     echo "running: look_for_C_compilers()" >> $LOGFILE
481     rm -f ./genmake_hello.c ./genmake_hello
482     cat >> genmake_hello.c << EOF
483 edhill 1.91 #include <stdio.h>
484     int main(int argc, char **argv) {
485     printf("Hello!\n");
486     return 0;
487     }
488     EOF
489 jmc 1.213 tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc icc"
490     p_CC=
491     for c in $tmp ; do
492     COMM="$c $CFLAGS -o genmake_hello genmake_hello.c"
493     echo $COMM >> $LOGFILE
494     $COMM >> $LOGFILE 2>&1
495 edhill 1.91 RETVAL=$?
496     if test "x${RETVAL}" = x0 ; then
497 jmc 1.213 echo " $c test successful" >> $LOGFILE
498 edhill 1.91 p_CC="$p_CC $c"
499     fi
500     done
501     rm -f ./genmake_hello.c ./genmake_hello
502     if test "x${p_CC}" = x ; then
503     cat 1>&2 <<EOF
504    
505     Error: No C compilers were found in your path. Please specify one using:
506    
507     1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
508     2) the CC or MITGCM_CC environment variables.
509    
510     EOF
511     exit 1
512     else
513 jmc 1.213 echo " The possible C compilers found in your path are: $p_CC" | tee -a $LOGFILE
514 edhill 1.91 if test "x$CC" = x ; then
515     CC=`echo $p_CC | $AWK '{print $1}'`
516     echo " Setting C compiler to: "$CC
517     fi
518     fi
519 jmc 1.213 echo " --> set CC='$CC'" >> $LOGFILE
520 jmc 1.212 }
521    
522     # Guess possible config options for this host
523     find_possible_optfile() {
524    
525 jmc 1.214 echo >> $LOGFILE
526     echo "running: find_possible_optfile()" >> $LOGFILE
527 jmc 1.212 tmp1=`uname`"_"`uname -m`
528     tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
529     tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
530     tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
531     tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
532     tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
533     PLATFORM=$tmp3
534     echo $PLATFORM | grep cygwin > /dev/null 2>&1 && PLATFORM=cygwin_ia32
535     OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
536 jmc 1.214 echo " The platform appears to be: $PLATFORM" | tee -a $LOGFILE
537 edhill 1.91
538     #================================================================
539     # look for possible FORTRAN compilers
540 jmc 1.214 echo " look for possible FORTRAN compilers" >> $LOGFILE
541     tmp="$MITGCM_FC $FC efc gfortran g77 f77 pgf77 pgf95 ifc ifort f90 f95 mpif77 mpf77 mpxlf95 g95"
542 edhill 1.1 p_FC=
543 jmc 1.214 rm -f ./genmake_hello.f
544     cat >> genmake_hello.f <<EOF
545 edhill 1.11 program hello
546     do i=1,3
547     print *, 'hello world : ', i
548     enddo
549     end
550     EOF
551 jmc 1.214 for f in $tmp ; do
552     COMM="$f -o genmake_hello genmake_hello.f"
553     echo $COMM >> $LOGFILE
554     $COMM >> $LOGFILE 2>&1
555 edhill 1.1 RETVAL=$?
556     if test "x${RETVAL}" = x0 ; then
557 jmc 1.214 echo " $f test successful" >> $LOGFILE
558     p_FC="$p_FC $f"
559 edhill 1.1 fi
560     done
561 jmc 1.214 rm -f ./genmake_hello.f ./genmake_hello
562 edhill 1.1 if test "x${p_FC}" = x ; then
563 edhill 1.11 cat 1>&2 <<EOF
564    
565     Error: No Fortran compilers were found in your path. Please specify one using:
566    
567     1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
568     2) a command-line option (eg. "-fc NAME"), or
569 edhill 1.91 3) the FC or MITGCM_FC environment variables.
570 edhill 1.11
571     EOF
572     exit 1
573 edhill 1.1 else
574 jmc 1.214 echo " The possible FORTRAN compilers found in your path are: $p_FC" | tee -a $LOGFILE
575 edhill 1.136 fi
576    
577     # Use the first of the compilers found in the current PATH
578     # that has a correctly-named optfile
579     if test "x$OPTFILE" = x -a "x$FC" = x ; then
580     for i in $p_FC ; do
581     OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
582     if test -r $OPTFILE ; then
583 jmc 1.214 echo " Setting OPTFILE to: "$OPTFILE | tee -a $LOGFILE
584 edhill 1.136 break
585     fi
586     done
587 edhill 1.1 fi
588    
589 adcroft 1.67 if test "x$OPTFILE" = x ; then
590     OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
591     if test ! -r $OPTFILE ; then
592 jmc 1.236 echo " I looked for the file "$OPTFILE" but did not find it"
593     fi
594 adcroft 1.67 fi
595 jmc 1.212
596 edhill 1.11 if test "x$OPTFILE" = x ; then
597     cat 1>&2 <<EOF
598    
599     Error: No options file was found in: $ROOTDIR/tools/build_options/
600     that matches this platform ("$PLATFORM") and the compilers found in
601     your path. Please specify an "optfile" using:
602    
603     1) the command line (eg. "-optfile=path/to/OPTFILE"), or
604     2) the MITGCM_OF environment variable.
605    
606     If you need help, please contact the developers at <MITgcm-support@mitgcm.org>.
607    
608 edhill 1.1 EOF
609 edhill 1.11 exit 1
610 edhill 1.1 fi
611     }
612    
613 jmc 1.251 # Do a local copy of MPI headers files (in local dir ./mpi_headers/) after
614     # checking for additional included headers (in case of chain of included header)
615     mpi_headers_do_local_copy() {
616    
617     dBug=0
618 jmc 1.253 rm -rf ./mpi_headers
619     if test -d $MPIINCLUDEDIR ; then
620    
621     #----- check for additional headers (chain of included headers)
622     echo -n ' Check MPI headers ... '
623     listIni=$MPI_HEADER_FILES
624     echo $listIni | grep "\<mpif.h\>" > /dev/null 2>&1
625     outp=$?
626     #- always check mpif.h (the only mpi-header included in standard MITgcm code)
627     if test $outp != 0 ; then listIni="mpif.h $listIni" ; fi
628     if test $dBug = 1 ; then echo "listIni='$listIni'" ; fi
629    
630     doCheck=1 ; list2copy='' ; list2check=$listIni
631     while test $doCheck = 1 ; do
632     newList=''
633     for i in $list2check ; do
634     if test -f $MPIINCLUDEDIR/$i ; then
635     newInc=`grep '^ *include ' $MPIINCLUDEDIR/$i | \
636 jmc 1.251 sed -e 's/^ *include //' -e 's/\!.*$//' -e "s/'//g" -e 's/\"//g'`
637 jmc 1.253 if test $dBug = 1 ; then echo -n "checking $i : newInc='$newInc'" ; fi
638     for j in $newInc ; do
639     echo $listIni $list2copy $newList | grep "\<$j\>" > /dev/null 2>&1
640     outp=$?
641     if test $outp != 0 ; then
642     if test $dBug = 1 ; then echo -n " ; adding $j" ; fi
643     newList="$newList $j"
644     fi
645     done
646     if test $dBug = 1 ; then echo "" ; fi
647     fi
648     done
649     if test "x$newList" = x ; then doCheck=0
650     else list2check=$newList ; list2copy="$list2copy $newList"
651     fi
652 jmc 1.251 done
653 jmc 1.253 list2copy="$MPI_HEADER_FILES $list2copy"
654     if test $dBug = 1 ; then echo "list2copy='$list2copy'" ; fi
655    
656     #----- create local mpi_headers dir if we have files to copy
657     mkListInc=`echo $list2copy | wc -w`
658     if test $mkListInc != 0 ; then
659     echo 'create local "./mpi_headers" dir'
660     mkdir -p ./mpi_headers
661     INCLUDES="-I./mpi_headers $INCLUDES"
662     mkListInc=1
663     fi
664     if test "x$LOCAL_MPI_HEADERS" != x ; then mkListInc=0 ; fi
665    
666     #----- make local copy and update LOCAL_MPI_HEADERS (if not already set)
667     for i in $list2copy ; do
668     if test -f $MPIINCLUDEDIR/$i ; then
669 jmc 1.251 cp -p $MPIINCLUDEDIR/$i ./mpi_headers
670     if test $i = 'mpif.h' ; then
671     perl -i -pe 's/MPI_DISPLACEMENT_CURRENT=-1_8/MPI_DISPLACEMENT_CURRENT=-1/g' mpi_headers/mpif.h
672     fi
673 jmc 1.253 if test $mkListInc = 2 ; then
674 jmc 1.251 LOCAL_MPI_HEADERS="$LOCAL_MPI_HEADERS ./mpi_headers/$i"
675     fi
676 jmc 1.253 if test $mkListInc = 1 ; then
677     LOCAL_MPI_HEADERS="./mpi_headers/$i" ; mkListInc=2
678 jmc 1.251 fi
679 jmc 1.253 fi
680     done
681     else
682     echo "WARNING: MPIINCLUDEDIR='$MPIINCLUDEDIR' is not a directory"
683     echo "WARNING: => skip checking for MPI headers (no ./mpi_headers dir)"
684     # exit -1
685     fi
686 jmc 1.251 }
687    
688 edhill 1.1 # Parse the package dependency information
689     get_pdepend_list() {
690    
691     # strip the comments and then convert the dependency file into
692     # two arrays: PNAME, DNAME
693     cat $1 | sed -e 's/#.*$//g' \
694 jmc 1.205 | $AWK 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \
695 edhill 1.1 > ./.pd_tmp
696 jmc 1.205 RETVAL=$?
697     if test ! "x${RETVAL}" = x0 ; then
698 jmc 1.208 echo "Error: unable to parse package dependencies -- please check PKG_DEPEND=\"$1\""
699 jmc 1.205 exit 1
700     fi
701 edhill 1.34 . ./.pd_tmp
702 edhill 1.1 rm -f ./.pd_tmp
703     }
704    
705 edhill 1.31 # Build a CPP macro to automate calling C routines from FORTRAN
706     get_fortran_c_namemangling() {
707 edhill 1.89
708     #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
709     if test ! "x$FC_NAMEMANGLE" = x ; then
710 jmc 1.236 return 0
711 edhill 1.89 fi
712 jmc 1.212 echo " running: get_fortran_c_namemangling()" >> $LOGFILE
713 edhill 1.89
714 edhill 1.31 default_nm="#define FC_NAMEMANGLE(X) X ## _"
715 jmc 1.206
716 edhill 1.31 cat > genmake_test.c <<EOF
717     void tcall( char * string ) { tsub( string ); }
718     EOF
719 jmc 1.212 COMM="$CC $CFLAGS -c genmake_test.c"
720     echo ' '$COMM >> $LOGFILE
721     $COMM >> $LOGFILE 2>&1
722 edhill 1.31 RETVAL=$?
723     if test "x$RETVAL" != x0 ; then
724     FC_NAMEMANGLE=$default_nm
725 jmc 1.211 cat <<EOF>> $LOGFILE
726 edhill 1.39
727 jmc 1.212 WARNING: C test compile fails
728     WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
729     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
730 edhill 1.39 EOF
731 edhill 1.31 return 1
732     fi
733 edhill 1.91 c_tcall=`nm genmake_test.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
734 edhill 1.31 RETVAL=$?
735     if test "x$RETVAL" != x0 ; then
736     FC_NAMEMANGLE=$default_nm
737 jmc 1.211 cat <<EOF>> $LOGFILE
738 edhill 1.39
739 jmc 1.212 WARNING: The "nm" command failed.
740     WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
741     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
742 edhill 1.39 EOF
743 edhill 1.31 return 1
744     fi
745 edhill 1.118 cat > genmake_tcomp.$FS <<EOF
746 edhill 1.31 subroutine tcall( string )
747     character*(*) string
748     call tsub( string )
749     end
750     EOF
751 jmc 1.212 COMM="$FC $FFLAGS -c genmake_tcomp.$FS"
752     echo ' '$COMM >> $LOGFILE
753     $COMM >> $LOGFILE 2>&1
754 edhill 1.31 RETVAL=$?
755     if test "x$RETVAL" != x0 ; then
756     FC_NAMEMANGLE=$default_nm
757 jmc 1.211 cat <<EOF>> $LOGFILE
758 edhill 1.39
759 jmc 1.212 WARNING: FORTRAN test compile fails -- please see '$LOGFILE'
760     WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
761     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
762 edhill 1.39 EOF
763 edhill 1.31 return 1
764     fi
765 edhill 1.91 f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
766 edhill 1.31 RETVAL=$?
767     if test "x$RETVAL" != x0 ; then
768     FC_NAMEMANGLE=$default_nm
769 jmc 1.211 cat <<EOF>> $LOGFILE
770 edhill 1.39
771 jmc 1.212 WARNING: The "nm" command failed.
772     WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
773     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
774 edhill 1.39 EOF
775 edhill 1.31 return 1
776     fi
777    
778     c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
779     f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
780     c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
781     f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
782    
783     nmangle="X"
784     if test "x$c_a" != "x$f_a" ; then
785     comm="echo x$f_a | sed -e 's|x$c_a||'"
786     a=`eval $comm`
787     nmangle="$a ## $nmangle"
788     fi
789     if test "x$c_b" != "x$f_b" ; then
790     comm="echo x$f_b | sed -e 's|x$c_b||'"
791     b=`eval $comm`
792     nmangle="$nmangle ## $b"
793     fi
794    
795     FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) $nmangle"
796 edhill 1.32
797     # cleanup the testing files
798     rm -f genmake_tcomp.* genmake_test.*
799 jmc 1.212
800     echo " --> set FC_NAMEMANGLE='$FC_NAMEMANGLE'" >> $LOGFILE
801 edhill 1.31 }
802 edhill 1.1
803 edhill 1.39 check_HAVE_CLOC() {
804 jmc 1.211 echo >> $LOGFILE
805     echo "running: check_HAVE_CLOC()" >> $LOGFILE
806 edhill 1.39 get_fortran_c_namemangling
807     cat <<EOF > genmake_tc_1.c
808     $FC_NAMEMANGLE
809     #include <stdio.h>
810     #include <stdlib.h>
811     #include <unistd.h>
812     #include <assert.h>
813     #include <sys/time.h>
814     void FC_NAMEMANGLE(cloc) ( double *curtim )
815     {
816     struct timeval tv1;
817     gettimeofday(&tv1 , (void *)NULL );
818     *curtim = (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
819     *curtim = *curtim/1.E6;
820     }
821     EOF
822 mlosch 1.168 COMM="$CC $CFLAGS -c genmake_tc_1.c"
823 jmc 1.211 echo $COMM >> $LOGFILE
824     $COMM >> $LOGFILE 2>&1
825 edhill 1.39 RET_C=$?
826 edhill 1.118 cat <<EOF > genmake_tc_2.$FS
827 edhill 1.39 program hello
828 edhill 1.129 REAL*8 wtime
829 edhill 1.39 external cloc
830     call cloc(wtime)
831     print *," HELLO WORLD", wtime
832 edhill 1.128 end
833 edhill 1.39 EOF
834 mlosch 1.163 COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
835 jmc 1.211 echo $COMM >> $LOGFILE
836     $COMM >> $LOGFILE 2>&1
837 edhill 1.39 RET_F=$?
838 jmc 1.211 test -x ./genmake_tc && ./genmake_tc >> $LOGFILE 2>&1
839 edhill 1.39 RETVAL=$?
840     if test "x$RETVAL" = x0 ; then
841     HAVE_CLOC=t
842     fi
843     rm -f genmake_tc*
844 jmc 1.212 echo " --> set HAVE_CLOC='$HAVE_CLOC'" >> $LOGFILE
845 edhill 1.39 }
846    
847 edhill 1.137 check_HAVE_SIGREG() {
848 edhill 1.150 if test ! "x$HAVE_SIGREG" = x ; then
849     return
850     fi
851 jmc 1.211 echo >> $LOGFILE
852     echo "running: check_HAVE_SIGREG()" >> $LOGFILE
853 edhill 1.137 get_fortran_c_namemangling
854     cat <<EOF > genmake_tc_1.c
855     $FC_NAMEMANGLE
856     #include <stdlib.h>
857     #include <stdio.h>
858     #include <signal.h>
859     #include <errno.h>
860     #include <ucontext.h>
861    
862     int * ip;
863    
864     static void killhandler(
865     unsigned int sn, siginfo_t si, struct ucontext *sc )
866     {
867     *ip = *ip + 1;
868     return;
869     }
870    
871     void FC_NAMEMANGLE(sigreg) (int * aip)
872     {
873 edhill 1.138 struct sigaction s;
874 edhill 1.137 ip = aip;
875     s.sa_flags = SA_SIGINFO;
876     s.sa_sigaction = (void *)killhandler;
877     if(sigaction (SIGTERM,&s,(struct sigaction *)NULL)) {
878     printf("Sigaction returned error = %d\n", errno);
879     exit(0);
880     }
881     return;
882     }
883     EOF
884 mlosch 1.168 COMM="$CC $CFLAGS -c genmake_tc_1.c"
885 jmc 1.211 echo $COMM >> $LOGFILE
886     $COMM >> $LOGFILE 2>&1
887 edhill 1.137 RET_C=$?
888     cat <<EOF > genmake_tc_2.$FS
889     program hello
890     integer anint
891     common /iv/ anint
892     external sigreg
893     call sigreg(anint)
894     end
895     EOF
896 jmc 1.211 cat genmake_tc_2.$FS >> $LOGFILE
897 edhill 1.137 COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
898 jmc 1.211 echo $COMM >> $LOGFILE
899     $COMM >> $LOGFILE 2>&1
900 edhill 1.137 RETVAL=$?
901     if test "x$RETVAL" = x0 ; then
902     HAVE_SIGREG=t
903     fi
904     rm -f genmake_tc*
905 jmc 1.212 echo " --> set HAVE_SIGREG='$HAVE_SIGREG'" >> $LOGFILE
906 edhill 1.137 }
907    
908 edhill 1.130 check_HAVE_SETRLSTK() {
909 edhill 1.151 if test ! "x$HAVE_SETRLSTK" = x ; then
910     return
911     fi
912 jmc 1.211 echo >> $LOGFILE
913     echo "running: check_HAVE_SETRLSTK()" >> $LOGFILE
914 edhill 1.130 get_fortran_c_namemangling
915     cat <<EOF > genmake_tc_1.c
916     $FC_NAMEMANGLE
917     #include <sys/time.h>
918     #include <sys/resource.h>
919     #include <unistd.h>
920     void FC_NAMEMANGLE(setrlstk) ()
921     {
922     struct rlimit rls;
923     rls.rlim_cur = RLIM_INFINITY;
924     rls.rlim_max = RLIM_INFINITY;
925     setrlimit(RLIMIT_STACK, &rls);
926     return;
927     }
928     EOF
929 mlosch 1.168 COMM="$CC $CFLAGS -c genmake_tc_1.c"
930 jmc 1.211 echo $COMM >> $LOGFILE
931     $COMM >> $LOGFILE 2>&1
932 edhill 1.130 RET_C=$?
933     cat <<EOF > genmake_tc_2.$FS
934     program hello
935     external setrlstk
936     call setrlstk()
937     end
938     EOF
939 jmc 1.211 cat genmake_tc_2.$FS >> $LOGFILE
940 edhill 1.135 COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
941 jmc 1.211 echo $COMM >> $LOGFILE
942     $COMM >> $LOGFILE 2>&1
943 edhill 1.130 RETVAL=$?
944     if test "x$RETVAL" = x0 ; then
945     HAVE_SETRLSTK=t
946     fi
947     rm -f genmake_tc*
948 jmc 1.212 echo " --> set HAVE_SETRLSTK='$HAVE_SETRLSTK'" >> $LOGFILE
949 edhill 1.130 }
950    
951 edhill 1.108 check_HAVE_STAT() {
952 jmc 1.211 echo >> $LOGFILE
953     echo "running: check_HAVE_STAT()" >> $LOGFILE
954 edhill 1.108 get_fortran_c_namemangling
955     cat <<EOF > genmake_tc_1.c
956     $FC_NAMEMANGLE
957     #include <stdio.h>
958     #include <stdlib.h>
959     #include <unistd.h>
960     #include <sys/stat.h>
961     #include <sys/types.h>
962     void FC_NAMEMANGLE(tfsize) ( int *nbyte )
963     {
964     char name[512];
965     struct stat astat;
966    
967     name[0] = 'a'; name[1] = '\0';
968     if (! stat(name, &astat))
969     *nbyte = (int)(astat.st_size);
970     else
971     *nbyte = -1;
972     }
973     EOF
974 mlosch 1.168 COMM="$CC $CFLAGS -c genmake_tc_1.c"
975 jmc 1.211 echo $COMM >> $LOGFILE
976 mlosch 1.168 $COMM >> genmake_tc.log 2>&1
977 edhill 1.108 RET_C=$?
978 edhill 1.118 cat <<EOF > genmake_tc_2.$FS
979 edhill 1.108 program hello
980     integer nbyte
981     call tfsize(nbyte)
982     print *," HELLO WORLD", nbyte
983 edhill 1.128 end
984 edhill 1.108 EOF
985 jmc 1.211 cat genmake_tc_2.$FS >> $LOGFILE
986 edhill 1.135 COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
987 jmc 1.211 echo $COMM >> $LOGFILE
988 edhill 1.135 $COMM >> genmake_tc.log 2>&1
989 edhill 1.108 RETVAL=$?
990     if test "x$RETVAL" = x0 ; then
991     HAVE_STAT=t
992     fi
993     rm -f genmake_tc*
994 jmc 1.212 echo " --> set HAVE_STAT='$HAVE_STAT'" >> $LOGFILE
995 edhill 1.108 }
996    
997 edhill 1.60 check_netcdf_libs() {
998 edhill 1.113 if test ! "x$SKIP_NETCDF_CHECK" = x ; then
999     return
1000     fi
1001 jmc 1.211 echo >> $LOGFILE
1002     echo "running: check_netcdf_libs()" >> $LOGFILE
1003 edhill 1.117 cat <<EOF > genmake_tnc.F
1004 edhill 1.60 program fgennc
1005     #include "netcdf.inc"
1006 edhill 1.113 EOF
1007 jmc 1.245 #if test ! "x$MPI" = x ; then
1008     # echo '#include "mpif.h"' >> genmake_tnc.F
1009     #fi
1010 edhill 1.117 cat <<EOF >> genmake_tnc.F
1011 edhill 1.60 integer iret, ncid, xid
1012     iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
1013     IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
1014     iret = nf_def_dim(ncid, 'X', 11, xid)
1015     IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
1016     iret = nf_close(ncid)
1017     IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
1018     end
1019     EOF
1020 jmc 1.210 echo "=== genmake_tnc.F >>>" > genmake_tnc.log
1021 edhill 1.135 cat genmake_tnc.F >> genmake_tnc.log
1022 jmc 1.210 echo "<<< genmake_tnc.F ===" >> genmake_tnc.log
1023 edhill 1.111 RET_CPP=f
1024 edhill 1.149 COMM="cat genmake_tnc.F | $CPP $DEFINES $INCLUDES"
1025 edhill 1.135 echo "$COMM" >> genmake_tnc.log
1026 dfer 1.155 eval $COMM > genmake_tnc.$FS 2>/dev/null && RET_CPP=t
1027 edhill 1.111 if test "x$RET_CPP" = xf ; then
1028     echo " WARNING: CPP failed to pre-process the netcdf test." \
1029 edhill 1.133 >> genmake_tnc.log
1030 edhill 1.111 echo " Please check that \$INCLUDES is properly set." \
1031 edhill 1.133 >> genmake_tnc.log
1032 edhill 1.111 fi
1033 edhill 1.135 echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
1034 edhill 1.153 echo " && $LINK $FFLAGS $FOPTIM -o genmake_tnc.o $LIBS" >> genmake_tnc.log
1035 edhill 1.117 $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \
1036 edhill 1.153 && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
1037 edhill 1.60 RET_COMPILE=$?
1038 jmc 1.211 cat genmake_tnc.log >> $LOGFILE
1039 edhill 1.99
1040     #EH3 Remove test program execution for machines that either disallow
1041     #EH3 execution or cannot support it (eg. cross-compilers)
1042     #EH3
1043     #EH3 test -x ./genmake_tnc && ./genmake_tnc >> genmake_tnc.log 2>&1
1044     #EH3 RETVAL=$?
1045     #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
1046    
1047     if test "x$RET_COMPILE" = x0 ; then
1048 edhill 1.60 HAVE_NETCDF=t
1049 jmc 1.211 echo "check_netcdf: successful" >> $LOGFILE
1050 edhill 1.60 else
1051 edhill 1.66 # try again with "-lnetcdf" added to the libs
1052 jmc 1.210 echo "==> try again with added '-lnetcdf'" > genmake_tnc.log
1053 edhill 1.149 echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log
1054 edhill 1.133 echo " && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
1055 edhill 1.153 echo " && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
1056 edhill 1.149 cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null \
1057 edhill 1.117 && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \
1058 edhill 1.153 && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
1059 edhill 1.66 RET_COMPILE=$?
1060 jmc 1.211 echo >> $LOGFILE
1061     cat genmake_tnc.log >> $LOGFILE
1062 edhill 1.99 if test "x$RET_COMPILE" = x0 ; then
1063 edhill 1.66 LIBS="$LIBS -lnetcdf"
1064     HAVE_NETCDF=t
1065 jmc 1.211 echo "check_netcdf: successful" >> $LOGFILE
1066 ce107 1.160 else
1067     # try again with "-lnetcdff" added to the libs
1068 jmc 1.210 echo "==> try again with added '-lnetcdff -lnetcdf'" > genmake_tnc.log
1069 ce107 1.160 echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log
1070     echo " && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
1071     echo " && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
1072     cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null \
1073     && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \
1074     && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdff -lnetcdf >> genmake_tnc.log 2>&1
1075     RET_COMPILE=$?
1076 jmc 1.211 echo >> $LOGFILE
1077     cat genmake_tnc.log >> $LOGFILE
1078 ce107 1.160 if test "x$RET_COMPILE" = x0 ; then
1079     LIBS="$LIBS -lnetcdff -lnetcdf"
1080     HAVE_NETCDF=t
1081 jmc 1.211 echo "check_netcdf: successful" >> $LOGFILE
1082 ce107 1.160 fi
1083 edhill 1.66 fi
1084 edhill 1.60 fi
1085     rm -f genmake_tnc*
1086 jmc 1.212 echo " --> set HAVE_NETCDF='$HAVE_NETCDF'" >> $LOGFILE
1087 edhill 1.60 }
1088    
1089 jahn 1.232 check_lapack_libs() {
1090 jmc 1.266 if test "x$CHECK_FOR_LAPACK" = xf ; then return ; fi
1091 jahn 1.232 echo >> $LOGFILE
1092     echo "running: check_lapack_libs()" >> $LOGFILE
1093     cat <<EOF > genmake_tla.F
1094     program fgenla
1095 jmc 1.236 integer info
1096 jahn 1.232 integer ipiv( 2 )
1097     double precision ab( 4, 2 ), b( 2 )
1098     data ab / 0., 0., 1., 2., 0., 2., 1., 0. /
1099     data b / 1., 1. /
1100     call dgbsv( 2, 1, 1, 1, ab, 4, ipiv, b, 2, info )
1101     IF (info .NE. 0) write(*,*) 'Error:', info
1102     write(*,*) b
1103     end
1104     EOF
1105     echo "=== genmake_tla.F >>>" > genmake_tla.log
1106     cat genmake_tla.F >> genmake_tla.log
1107     echo "<<< genmake_tla.F ===" >> genmake_tla.log
1108     RET_CPP=f
1109     COMM="cat genmake_tla.F | $CPP $DEFINES $INCLUDES"
1110     echo "$COMM" >> genmake_tla.log
1111     eval $COMM > genmake_tla.$FS 2>/dev/null && RET_CPP=t
1112     if test "x$RET_CPP" = xf ; then
1113     echo " WARNING: CPP failed to pre-process the lapack test." \
1114     >> genmake_tla.log
1115     echo " Please check that \$INCLUDES is properly set." \
1116     >> genmake_tla.log
1117     fi
1118     echo "$FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1119     echo " && $LINK $FFLAGS $FOPTIM -o genmake_tla.o $LIBS" >> genmake_tla.log
1120     $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1 \
1121     && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS >> genmake_tla.log 2>&1
1122     RET_COMPILE=$?
1123     cat genmake_tla.log >> $LOGFILE
1124    
1125     # test program execution not always possible (see check_netcdf_libs)
1126     #
1127     #test -x ./genmake_tla && ./genmake_tla >> genmake_tla.log 2>&1
1128     #RETVAL=$?
1129     #if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
1130    
1131     if test "x$RET_COMPILE" = x0 ; then
1132     HAVE_LAPACK=t
1133     echo "check_lapack: successful" >> $LOGFILE
1134     else
1135     # try again with "-llapack" added to the libs
1136     echo "==> try again with added '-llapack'" > genmake_tla.log
1137     echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1138     echo " && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1139     echo " && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack" >> genmake_tla.log
1140     cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null \
1141     && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1 \
1142     && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack >> genmake_tla.log 2>&1
1143     RET_COMPILE=$?
1144     echo >> $LOGFILE
1145     cat genmake_tla.log >> $LOGFILE
1146     if test "x$RET_COMPILE" = x0 ; then
1147     LIBS="$LIBS -llapack"
1148     HAVE_LAPACK=t
1149     echo "check_lapack: successful" >> $LOGFILE
1150     else
1151     # try again with "-lf77blas -lcblas" added to the libs
1152     echo "==> try again with added '-llapack -lf77blas -lcblas'" > genmake_tla.log
1153     echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1154     echo " && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1155     echo " && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas" >> genmake_tla.log
1156     cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null \
1157     && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1 \
1158     && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas >> genmake_tla.log 2>&1
1159     RET_COMPILE=$?
1160     echo >> $LOGFILE
1161     cat genmake_tla.log >> $LOGFILE
1162     if test "x$RET_COMPILE" = x0 ; then
1163     LIBS="$LIBS -llapack -lf77blas -lcblas"
1164     HAVE_LAPACK=t
1165     echo "check_lapack: successful" >> $LOGFILE
1166 jmc 1.236 else
1167     # try again with "-latlas" added to the libs
1168     echo "==> try again with added '-llapack -lf77blas -lcblas -latlas'" > genmake_tla.log
1169     echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1170     echo " && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1171     echo " && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas -latlas" >> genmake_tla.log
1172     cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null \
1173     && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1 \
1174     && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas -latlas >> genmake_tla.log 2>&1
1175     RET_COMPILE=$?
1176     echo >> $LOGFILE
1177     cat genmake_tla.log >> $LOGFILE
1178     if test "x$RET_COMPILE" = x0 ; then
1179     LIBS="$LIBS -llapack -lf77blas -lcblas -latlas"
1180     HAVE_LAPACK=t
1181     echo "check_lapack: successful" >> $LOGFILE
1182     fi
1183 jahn 1.232 fi
1184     fi
1185     fi
1186     rm -f genmake_tla*
1187     echo " --> set HAVE_LAPACK='$HAVE_LAPACK'" >> $LOGFILE
1188     }
1189    
1190 jmc 1.244 check_HAVE_FLUSH() {
1191     if test ! "x$SKIP_CHECK_FLUSH" = x ; then
1192     return
1193     fi
1194     echo >> $LOGFILE
1195     echo "running: check_HAVE_FLUSH()" >> $LOGFILE
1196     cat <<EOF > genmake_tflsh.$FS
1197     program fgenflsh
1198     integer iounit
1199     character*9 fname
1200     iounit = 26
1201     fname = 'tmp.tflsh'
1202     open(iounit,FILE=fname,STATUS='unknown')
1203     write(iounit,*) 'genmake_tflsh: hello'
1204     call flush(iounit)
1205     close(iounit)
1206     end
1207     EOF
1208     echo "=== genmake_tflsh.$FS >>>" > genmake_tflsh.log
1209     cat genmake_tflsh.$FS >> genmake_tflsh.log
1210     echo "<<< genmake_tflsh.$FS ===" >> genmake_tflsh.log
1211    
1212     echo "$FC $FFLAGS $FOPTIM -c genmake_tflsh.$FS \ " >> genmake_tflsh.log
1213     echo " && $LINK $FFLAGS $FOPTIM -o genmake_tflsh.o $LIBS" >> genmake_tflsh.log
1214     $FC $FFLAGS $FOPTIM -c genmake_tflsh.$FS >> genmake_tflsh.log 2>&1 \
1215     && $LINK $FFLAGS $FOPTIM -o genmake_tflsh genmake_tflsh.o $LIBS >> genmake_tflsh.log 2>&1
1216     RET_COMPILE=$?
1217    
1218     if test "x$RET_COMPILE" = x0 ; then
1219     HAVE_FLUSH=t
1220     #cat genmake_tflsh.log >> $LOGFILE
1221     echo " check_HAVE_FLUSH: successful" >> $LOGFILE
1222     else
1223     HAVE_FLUSH=f
1224     cat genmake_tflsh.log >> $LOGFILE
1225     fi
1226     rm -f genmake_tflsh*
1227     echo " --> set HAVE_FLUSH='$HAVE_FLUSH'" >> $LOGFILE
1228     }
1229 edhill 1.60
1230 adcroft 1.67 ###############################################################################
1231     # Sequential part of script starts here
1232     ###############################################################################
1233    
1234 edhill 1.1 # Set defaults here
1235 edhill 1.5 COMMANDL="$0 $@"
1236    
1237 edhill 1.1 PLATFORM=
1238     LN=
1239     S64=
1240     KPP=
1241 edhill 1.114 #FC=
1242 edhill 1.93 #CC=gcc
1243 edhill 1.114 #CPP=
1244 edhill 1.1 LINK=
1245 edhill 1.31 DEFINES=
1246 edhill 1.1 PACKAGES=
1247     ENABLE=
1248     DISABLE=
1249 edhill 1.119 # MAKEFILE=
1250     # MAKEDEPEND=
1251 jmc 1.208 PKG_DEPEND=
1252     PKG_GROUPS=
1253 jmc 1.211 DUMPSTATE=f
1254 edhill 1.1 OPTFILE=
1255 edhill 1.111 INCLUDES="-I. $INCLUDES"
1256 edhill 1.1 FFLAGS=
1257     FOPTIM=
1258 mlosch 1.165 FEXTRAFLAGS=
1259 jmc 1.181 USE_EXTENDED_SRC=
1260     EXTENDED_SRC_FLAG=
1261 jmc 1.216 GET_FC_VERSION=
1262 edhill 1.1 CFLAGS=
1263     KFLAGS1=
1264     KFLAGS2=
1265 edhill 1.70 #LDADD=
1266 edhill 1.1 LIBS=
1267     KPPFILES=
1268     NOOPTFILES=
1269     NOOPTFLAGS=
1270 adcroft 1.67 MPI=
1271     MPIPATH=
1272 jmc 1.187 OMP=
1273     OMPFLAG=
1274 jmc 1.203 USE_R4=
1275 ce107 1.126 TS=
1276 ce107 1.139 PAPIS=
1277 ce107 1.147 PCLS=
1278 ce107 1.139 FOOLAD=
1279     PAPI=
1280 ce107 1.147 PCL=
1281 ce107 1.139 HPMT=
1282     GSL=
1283 ce107 1.160 DEVEL=
1284 edhill 1.131 HAVE_TEST_L=
1285 edhill 1.1
1286 jmc 1.266 # set this to "t" to enable lapack test
1287     CHECK_FOR_LAPACK=f
1288 jahn 1.246
1289 edhill 1.124 # DEFINES checked by test compilation or command-line
1290 edhill 1.29 HAVE_SYSTEM=
1291     HAVE_FDATE=
1292     FC_NAMEMANGLE=
1293 edhill 1.39 HAVE_CLOC=
1294 edhill 1.151 # HAVE_SETRLSTK=
1295 edhill 1.108 HAVE_STAT=
1296 edhill 1.60 HAVE_NETCDF=
1297 cnh 1.81 HAVE_ETIME=
1298 edhill 1.124 IGNORE_TIME=
1299 jahn 1.232 HAVE_LAPACK=
1300 jmc 1.244 HAVE_FLUSH=
1301 edhill 1.29
1302 edhill 1.1 MODS=
1303     TOOLSDIR=
1304     SOURCEDIRS=
1305     INCLUDEDIRS=
1306 edhill 1.57 STANDARDDIRS="USE_THE_DEFAULT"
1307 edhill 1.1
1308 jmc 1.237 #- local config file
1309     gm_local="genmake_local"
1310    
1311 edhill 1.73 G2ARGS=
1312 edhill 1.71 BASH=
1313 edhill 1.1 PWD=`pwd`
1314 edhill 1.114 test "x$MAKE" = x && MAKE=make
1315     test "x$AWK" = x && AWK=awk
1316 edhill 1.141 EMBED_SRC=
1317 edhill 1.97 THISHOST=`hostname`
1318 edhill 1.1 THISCWD=`pwd`
1319     THISDATE=`date`
1320 edhill 1.97 THISUSER=`echo $USER`
1321     THISVER=
1322 edhill 1.1 MACHINE=`uname -a`
1323 edhill 1.7 EXECUTABLE=
1324     EXEHOOK=
1325     EXEDIR=
1326 edhill 1.12 IEEE=
1327     if test "x$MITGCM_IEEE" != x ; then
1328     IEEE=$MITGCM_IEEE
1329     fi
1330 edhill 1.76 FS=
1331     FS90=
1332 edhill 1.1
1333 edhill 1.14 AUTODIFF_PKG_USED=f
1334 jmc 1.264 OPENAD=
1335 heimbach 1.272 OPENAD_DIVA=
1336 edhill 1.14 AD_OPTFILE=
1337 jmc 1.269 CAT_SRC_FOR_TAF=1
1338 edhill 1.17 TAF=
1339     AD_TAF_FLAGS=
1340     FTL_TAF_FLAGS=
1341     SVD_TAF_FLAGS=
1342     TAF_EXTRA=
1343     TAMC=
1344     AD_TAMC_FLAGS=
1345     FTL_TAF_FLAGS=
1346     SVD_TAMC_FLAGS=
1347     TAMC_EXTRA=
1348    
1349 jmc 1.251 DIVA=
1350     MPIINCLUDEDIR=
1351     MPI_HEADER_FILES=
1352     LOCAL_MPI_HEADERS=
1353    
1354 edhill 1.5 # The following state can be set directly by command-line switches
1355 jmc 1.238 gm_s1="ROOTDIR STANDARDDIRS MODS PKG_DEPEND PKG_GROUPS DISABLE ENABLE"
1356     gm_s2="PLATFORM OPTFILE MAKE MAKEFILE MAKEDEPEND FC CC MPI OMP USE_R4"
1357     gm_s3="FEXTRAFLAGS IEEE DEVEL GSL TS PAPIS PCLS PAPI PCL HPMT DUMPSTATE"
1358 edhill 1.5
1359     # The following state is not directly set by command-line switches
1360 jmc 1.238 gm_s4="LN S64 LINK PACKAGES INCLUDES FFLAGS FOPTIM"
1361 jmc 1.222 gm_s5="CFLAGS LIBS KPP KFLAGS1 KFLAGS2 KPPFILES NOOPTFILES NOOPTFLAGS"
1362 jmc 1.244 gm_s6="PWD TOOLSDIR SOURCEDIRS INCLUDEDIRS EXEDIR EXECUTABLE EXEHOOK"
1363 jmc 1.260 gm_s7="TMP THISHOST THISUSER THISDATE THISVER MACHINE FC_NAMEMANGLE"
1364 jmc 1.244 gm_s8="HAVE_NETCDF HAVE_SYSTEM HAVE_FDATE HAVE_ETIME HAVE_LAPACK HAVE_FLUSH"
1365 edhill 1.5
1366 edhill 1.14 # The following are all related to adjoint/tangent-linear stuff
1367 jmc 1.264 gm_s10="AUTODIFF_PKG_USED AD_OPTFILE OPENAD TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
1368 edhill 1.29 gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
1369 jmc 1.251 gm_s12="TAF_EXTRA TAMC_EXTRA DIVA MPIINCLUDEDIR MPI_HEADER_FILES"
1370 edhill 1.14
1371 jmc 1.222 gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7 $gm_s8"
1372 edhill 1.29 gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
1373 edhill 1.5
1374 edhill 1.41 cat <<EOF
1375    
1376     GENMAKE :
1377    
1378 jmc 1.211 A program for GENerating MAKEfiles for the MITgcm project.
1379     For a quick list of options, use "genmake2 -h"
1380     or for more detail see the Developer's HOWTO manual at:
1381     http://mitgcm.org/public/docs.html
1382 edhill 1.41
1383     EOF
1384 edhill 1.5
1385 jmc 1.211 LOGFILE="genmake.log"
1386 jmc 1.210 #- clean-up previous genmake logfiles:
1387 jmc 1.211 rm -f genmake_state genmake_*optfile $LOGFILE
1388 jmc 1.209
1389 edhill 1.2 echo "=== Processing options files and arguments ==="
1390 edhill 1.1
1391 edhill 1.103 #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
1392 edhill 1.2 #parse_options
1393     ac_prev=
1394 edhill 1.102 for ac_option in "$@" ; do
1395 edhill 1.2
1396 edhill 1.73 G2ARGS="$G2ARGS \"$ac_option\""
1397    
1398 edhill 1.2 # If the previous option needs an argument, assign it.
1399     if test -n "$ac_prev"; then
1400     eval "$ac_prev=\$ac_option"
1401     ac_prev=
1402     continue
1403     fi
1404 jmc 1.206
1405 edhill 1.2 ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
1406 jmc 1.206
1407 edhill 1.2 case $ac_option in
1408 jmc 1.236
1409 edhill 1.2 -help | --help | -h | --h)
1410     usage ;;
1411 jmc 1.236
1412 edhill 1.2 -nooptfile | --nooptfile)
1413     OPTFILE="NONE" ;;
1414     -optfile | --optfile | -of | --of)
1415 edhill 1.4 ac_prev=OPTFILE ;;
1416 edhill 1.2 -optfile=* | --optfile=* | -of=* | --of=*)
1417     OPTFILE=$ac_optarg ;;
1418 jmc 1.236
1419 jmc 1.264 -oad | --oad)
1420 jmc 1.268 OPENAD="true" ; ALWAYS_USE_F90=1 ;;
1421 jmc 1.269 -nocat4ad | -dog4ad | -ncad | -dad)
1422     CAT_SRC_FOR_TAF=0 ;;
1423 edhill 1.50 -adoptfile | --adoptfile | -adof | --adof)
1424 edhill 1.14 ac_prev=AD_OPTFILE ;;
1425     -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
1426     AD_OPTFILE=$ac_optarg ;;
1427 jmc 1.236
1428 heimbach 1.272 -diva | --diva)
1429     OPENAD_DIVA="ALLOW_OPENAD_DIVA=" ;;
1430    
1431 edhill 1.2 -pdepend | --pdepend)
1432 jmc 1.208 ac_prev=PKG_DEPEND ;;
1433 edhill 1.2 -pdepend=* | --pdepend=*)
1434 jmc 1.208 PKG_DEPEND=$ac_optarg ;;
1435 jmc 1.236
1436 jmc 1.208 -pgroups | --pgroups)
1437     ac_prev=PKG_GROUPS ;;
1438     -pgroups=* | --pgroups=*)
1439     PKG_GROUPS=$ac_optarg ;;
1440 jmc 1.236
1441 edhill 1.6 -make | --make | -m | --m)
1442     ac_prev=MAKE ;;
1443     -make=* | --make=* | -m=* | --m=*)
1444     MAKE=$ac_optarg ;;
1445 jmc 1.236
1446 edhill 1.71 -bash | --bash)
1447     ac_prev=BASH ;;
1448     -bash=* | --bash=*)
1449     BASH=$ac_optarg ;;
1450 jmc 1.236
1451 edhill 1.69 -makedepend | --makedepend | -md | --md)
1452     ac_prev=MAKEDEPEND ;;
1453     -makedepend=* | --makedepend=* | -md=* | --md=*)
1454     MAKEDEPEND=$ac_optarg ;;
1455 jmc 1.236
1456 jmc 1.237 -makefile | --makefile | -mf | --mf)
1457 edhill 1.4 ac_prev=MAKEFILE ;;
1458 jmc 1.237 -makefile=* | --makefile=* | -mf=* | --mf=*)
1459 edhill 1.2 MAKEFILE=$ac_optarg ;;
1460 jmc 1.236
1461 edhill 1.41 -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
1462     echo "ERROR: The platform option has been removed. Please specify"
1463     echo " the build options using the \"optfile\" mechanism."
1464     echo
1465     usage
1466     ;;
1467 jmc 1.236
1468 edhill 1.2 -rootdir | --rootdir | -rd | --rd)
1469 edhill 1.4 ac_prev=ROOTDIR ;;
1470 edhill 1.2 -rootdir=* | --rootdir=* | -rd=* | --rd=*)
1471     ROOTDIR=$ac_optarg ;;
1472 jmc 1.236
1473 edhill 1.2 -mods | --mods | -mo | --mo)
1474 edhill 1.4 ac_prev=MODS ;;
1475 edhill 1.2 -mods=* | --mods=* | -mo=* | --mo=*)
1476     MODS=$ac_optarg ;;
1477 jmc 1.236
1478 edhill 1.2 -disable | --disable)
1479 edhill 1.4 ac_prev=DISABLE ;;
1480 edhill 1.2 -disable=* | --disable=*)
1481     DISABLE=$ac_optarg ;;
1482 jmc 1.236
1483 edhill 1.2 -enable | --enable)
1484 edhill 1.4 ac_prev=ENABLE ;;
1485 edhill 1.2 -enable=* | --enable=*)
1486     ENABLE=$ac_optarg ;;
1487 jmc 1.236
1488 edhill 1.12 -standarddirs | --standarddirs)
1489     ac_prev=STANDARDDIRS ;;
1490     -standarddirs=* | --standarddirs=*)
1491     STANDARDDIRS=$ac_optarg ;;
1492    
1493 edhill 1.2 # -cpp | --cpp)
1494     # ac_prev=cpp ;;
1495     # -cpp=* | --cpp=*)
1496     # CPP=$ac_optarg ;;
1497 jmc 1.236
1498 edhill 1.91 -cc | --cc)
1499     ac_prev=CC ;;
1500     -cc=* | --cc=*)
1501     CC=$ac_optarg ;;
1502 jmc 1.236
1503 edhill 1.2 -fortran | --fortran | -fc | --fc)
1504 edhill 1.4 ac_prev=FC ;;
1505 edhill 1.2 -fc=* | --fc=*)
1506     FC=$ac_optarg ;;
1507 jmc 1.236
1508 edhill 1.76 -fs | --fs)
1509     ac_prev=FS ;;
1510     -fs=* | --fs=*)
1511     FS=$ac_optarg ;;
1512 jmc 1.236
1513 edhill 1.76 -fs90 | --fs90)
1514     ac_prev=FS90 ;;
1515     -fs90=* | --fs90=*)
1516     FS90=$ac_optarg ;;
1517 jmc 1.236
1518 jmc 1.220 -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4 )
1519     USE_R4=true ;;
1520    
1521 edhill 1.2 -ieee | --ieee)
1522 edhill 1.12 IEEE=true ;;
1523 edhill 1.2 -noieee | --noieee)
1524 jmc 1.220 echo "Warning: ignore option '$ac_option' (default is already without '-ieee')" ;;
1525 jmc 1.237 -devel | --devel)
1526 jmc 1.220 IEEE=true ; DEVEL=true ;;
1527 jmc 1.237 -gsl | --gsl)
1528 jmc 1.220 GSL=true ;;
1529 jmc 1.203
1530 ce107 1.126 -ts | --ts)
1531     TS=true ;;
1532 ce107 1.139 -papis | --papis)
1533     PAPIS=true ;;
1534 ce107 1.147 -pcls | --pcls)
1535     PCLS=true ;;
1536 ce107 1.139 -foolad | --foolad)
1537     FOOLAD=true ;;
1538     -papi | --papi)
1539     PAPI=true ;;
1540 ce107 1.147 -pcl | --pcl)
1541     PCL=true ;;
1542 ce107 1.139 -hpmt | --hpmt)
1543     HPMT=true ;;
1544    
1545 adcroft 1.67 -mpi | --mpi)
1546     MPI=true ;;
1547     -mpi=* | --mpi=*)
1548     MPIPATH=$ac_optarg
1549     MPI=true ;;
1550 jmc 1.236
1551     -omp | --omp)
1552     OMP=true ;;
1553 jmc 1.187 -omp=* | --omp=*)
1554     OMPFLAG=$ac_optarg
1555     OMP=true ;;
1556 jmc 1.236
1557 edhill 1.5 -ds | --ds)
1558     DUMPSTATE=t ;;
1559 jmc 1.236
1560 jmc 1.222 -extra_flag | --extra_flag)
1561     ac_prev=FEXTRAFLAGS ;;
1562     -extra_flag=* | --extra_flag=*)
1563     FEXTRAFLAGS=$ac_optarg ;;
1564 jmc 1.236
1565 edhill 1.17 -taf_extra | --taf_extra)
1566     ac_prev=TAF_EXTRA ;;
1567     -taf_extra=* | --taf_extra=*)
1568     TAF_EXTRA=$ac_optarg ;;
1569    
1570     -tamc_extra | --tamc_extra)
1571     ac_prev=TAMC_EXTRA ;;
1572     -tamc_extra=* | --tamc_extra=*)
1573     TAMC_EXTRA=$ac_optarg ;;
1574 jmc 1.236
1575 edhill 1.124 -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1576     IGNORE_TIME="-DIGNORE_TIME" ;;
1577 edhill 1.17
1578 edhill 1.141 -es | --es | -embed-source | --embed-source)
1579     EMBED_SRC=t ;;
1580    
1581 edhill 1.2 -*)
1582     echo "Error: unrecognized option: "$ac_option
1583     usage
1584     ;;
1585 jmc 1.236
1586 edhill 1.2 *)
1587     echo "Error: unrecognized argument: "$ac_option
1588     usage
1589     ;;
1590 jmc 1.236
1591 edhill 1.2 esac
1592 jmc 1.206
1593 edhill 1.1 done
1594    
1595 jmc 1.262 #TMP=./genmk_$$
1596 jmc 1.260 #- try to put temporary files in system-local /tmp dir
1597 jmc 1.270 TMP=/tmp/genmk_${USER}_$$
1598 jmc 1.262 touch $TMP ; retVal=$?
1599     if [ $retVal -eq 0 ] ; then
1600     if test ! -r $TMP ; then TMP=./genmk_$$ ; fi
1601     else
1602     TMP=./genmk_$$
1603     fi
1604     rm -f $TMP
1605     #echo " temp files: $TMP.*"
1606 jmc 1.260
1607 jmc 1.237 printf " getting local config information: "
1608     if test -f $gm_local ; then
1609     echo "using $gm_local"
1610     . $gm_local
1611     else
1612     echo "none found"
1613     fi
1614    
1615 edhill 1.12 if test -f ./.genmakerc ; then
1616     echo
1617     echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
1618 jmc 1.161 echo " file. This file format is no longer supported. For directions on"
1619     echo " how to setup and use the new \"genmake2\" script, please see:"
1620 jmc 1.220 echo " http://mitgcm.org/public/devel_HOWTO/"
1621 jmc 1.161 echo " and send an email to MITgcm-support@mitgcm.org if you need help."
1622     echo "WARNING: ignore \"./.genmakerc\" and continue."
1623 jmc 1.206 echo
1624 edhill 1.12 fi
1625    
1626 edhill 1.97 # Find the MITgcm ${ROOTDIR}
1627 edhill 1.11 if test "x${ROOTDIR}" = x ; then
1628 edhill 1.112 tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1629 edhill 1.154 if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesupp -a -d ../pkg ; then
1630 edhill 1.11 ROOTDIR=".."
1631     else
1632     for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1633     if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
1634     ROOTDIR=$d
1635 jmc 1.218 printf "Warning: ROOTDIR was not specified ;"
1636     echo " try using a local copy of MITgcm found at \"$ROOTDIR\""
1637 edhill 1.11 break
1638     fi
1639     done
1640     fi
1641     fi
1642     if test "x${ROOTDIR}" = x ; then
1643     echo "Error: Cannot determine ROOTDIR for MITgcm code."
1644     echo " Please specify a ROOTDIR using either an options "
1645     echo " file or a command-line option."
1646     exit 1
1647     fi
1648     if test ! -d ${ROOTDIR} ; then
1649     echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
1650     exit 1
1651     fi
1652    
1653 edhill 1.97 # Find the MITgcm ${THISVER}
1654 jmc 1.179 version_file="${ROOTDIR}/doc/tag-index"
1655     if test -f $version_file ; then
1656 jmc 1.200 THISVER=`$AWK '/^checkpoint/{print $1; exit}' $version_file`
1657 jmc 1.179 #- remove ./BUILD_INFO.h file if older than version_file
1658     if test -f ./BUILD_INFO.h -a ./BUILD_INFO.h -ot $version_file ; then
1659     echo " remove ./BUILD_INFO.h (older than ${version_file})"
1660     rm -f ./BUILD_INFO.h
1661     fi
1662 edhill 1.97 fi
1663    
1664 edhill 1.119 if test "x$MAKEFILE" = x ; then
1665     MAKEFILE="Makefile"
1666     fi
1667    
1668 jmc 1.222 echo " getting OPTFILE information:"
1669 edhill 1.1 if test "x${OPTFILE}" = x ; then
1670 edhill 1.11 if test "x$MITGCM_OF" = x ; then
1671     echo "Warning: no OPTFILE specified so we'll look for possible settings"
1672     printf "\n=== Searching for possible settings for OPTFILE ===\n"
1673 jmc 1.212 find_possible_optfile
1674 edhill 1.1 else
1675 edhill 1.11 OPTFILE=$MITGCM_OF
1676     fi
1677     fi
1678     if test "x$OPTFILE" != xNONE ; then
1679     if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
1680     echo " using OPTFILE=\"$OPTFILE\""
1681 edhill 1.34 . "$OPTFILE"
1682 edhill 1.11 RETVAL=$?
1683     if test "x$RETVAL" != x0 ; then
1684 edhill 1.71 printf "Error: failed to source OPTFILE \"$OPTFILE\""
1685 edhill 1.11 echo "--please check that variable syntax is bash-compatible"
1686 edhill 1.1 exit 1
1687     fi
1688 jmc 1.211 if test "x$DUMPSTATE" = xt ; then
1689 edhill 1.12 cp -f $OPTFILE "genmake_optfile"
1690 edhill 1.11 fi
1691     else
1692     echo "Error: can't read OPTFILE=\"$OPTFILE\""
1693     exit 1
1694 edhill 1.1 fi
1695     fi
1696 edhill 1.8
1697 jmc 1.222 echo " getting AD_OPTFILE information:"
1698 edhill 1.14 if test "x${AD_OPTFILE}" = x ; then
1699 jmc 1.264 if test "x$MITGCM_AD_OF" != x ; then
1700     AD_OPTFILE=$MITGCM_AD_OF
1701     elif test "x$OPENAD" = x ; then
1702 edhill 1.14 AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
1703     else
1704 jmc 1.264 AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_oad
1705 edhill 1.14 fi
1706     fi
1707     if test "x${AD_OPTFILE}" != xNONE ; then
1708     if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
1709     echo " using AD_OPTFILE=\"$AD_OPTFILE\""
1710 edhill 1.34 . "$AD_OPTFILE"
1711 edhill 1.14 RETVAL=$?
1712     if test "x$RETVAL" != x0 ; then
1713 edhill 1.71 printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
1714 edhill 1.14 echo "--please check that variable syntax is bash-compatible"
1715     exit 1
1716     fi
1717 jmc 1.211 if test "x$DUMPSTATE" = xt ; then
1718 edhill 1.14 cp -f $AD_OPTFILE "genmake_ad_optfile"
1719     fi
1720     else
1721     echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
1722     exit 1
1723     fi
1724     fi
1725    
1726 edhill 1.119 #====================================================================
1727     # Set default values if not set by the optfile
1728     #
1729 edhill 1.91 # Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined. If not,
1730 edhill 1.39 # either set defaults or complain and abort!
1731 edhill 1.71 if test ! "x$BASH" = x ; then
1732     # add a trailing space so that it works within the Makefile syntax (see below)
1733     BASH="$BASH "
1734     fi
1735 edhill 1.8 if test "x$FC" = x ; then
1736     cat <<EOF 1>&2
1737    
1738     Error: no Fortran compiler: please specify using one of the following:
1739     1) within the options file ("FC=...") as specified by "-of=OPTFILE"
1740     2) the "-fc=XXX" command-line option
1741 edhill 1.12 3) the "./genmake_local" file
1742 edhill 1.8 EOF
1743     exit 1
1744     fi
1745 jmc 1.216 if test "x$GET_FC_VERSION" != x ; then
1746     echo "Get compiler version using: $FC $GET_FC_VERSION" >> $LOGFILE
1747 jmc 1.225 ff=`echo $FC | sed 's/ .*//'` ; xx=`echo $ff | sed 's/^./& /' | sed 's/ .*//'`
1748     if test $xx != '/' ; then which $ff >> $LOGFILE ; fi
1749 jmc 1.224 $FC $GET_FC_VERSION > genmake_fc_vers1 2> genmake_fc_vers2
1750     if test -s genmake_fc_vers1 ; then
1751     cat genmake_fc_vers1 >> $LOGFILE
1752     else
1753     cat genmake_fc_vers2 >> $LOGFILE
1754     fi
1755 jmc 1.217 echo "<-- compiler version ----" >> $LOGFILE
1756 jmc 1.224 rm -f genmake_fc_vers1 genmake_fc_vers2
1757 jmc 1.216 fi
1758 jmc 1.212
1759 edhill 1.91 if test "x$CC" = x ; then
1760 jmc 1.212 look_for_C_compilers
1761 edhill 1.91 fi
1762 jmc 1.212
1763 edhill 1.8 if test "x$LINK" = x ; then
1764     LINK=$FC
1765     fi
1766 edhill 1.39 if test "x$MAKE" = x ; then
1767     MAKE="make"
1768     fi
1769 edhill 1.63 if test "x$CPP" = x ; then
1770 jmc 1.212 CPP="cpp -traditional -P"
1771 edhill 1.63 fi
1772     #EH3 === UGLY ===
1773 edhill 1.76 # The following is an ugly little hack to check for $CPP in /lib/ and
1774     # it should eventually be replaced with a more general function that
1775 edhill 1.63 # searches a combo of the user's path and a list of "usual suspects"
1776     # to find the correct location for binaries such as $CPP.
1777     for i in " " "/lib/" ; do
1778     echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1779     done
1780     #EH3 === UGLY ===
1781 edhill 1.13 echo "#define A a" | $CPP > test_cpp 2>&1
1782 edhill 1.11 RETVAL=$?
1783     if test "x$RETVAL" != x0 ; then
1784 edhill 1.8 cat <<EOF 1>&2
1785    
1786 edhill 1.11 Error: C pre-processor "$CPP" failed the test case: please specify using:
1787    
1788 edhill 1.8 1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
1789 edhill 1.12 2) the "./genmake_local" file
1790 edhill 1.30 3) with the CPP environment variable
1791 edhill 1.11
1792 edhill 1.8 EOF
1793     exit 1
1794 edhill 1.11 else
1795     rm -f test_cpp
1796 edhill 1.8 fi
1797 jmc 1.212
1798 edhill 1.84 look_for_makedepend
1799 jmc 1.212
1800     # Check that soft-link command is set and usable
1801 edhill 1.35 if test "x$LN" = x ; then
1802     LN="ln -s"
1803     fi
1804     echo "test" > genmake_test_ln
1805     $LN genmake_test_ln genmake_tlink
1806     RETVAL=$?
1807     if test "x$RETVAL" != x0 ; then
1808     cat <<EOF 1>&2
1809 edhill 1.29
1810 jmc 1.212 Error: The command "$LN" failed -- please specify a working soft-link
1811 edhill 1.35 command in the optfile.
1812    
1813     EOF
1814     exit 1
1815     fi
1816 edhill 1.131 test -L genmake_tlink > /dev/null 2>&1
1817     RETVAL=$?
1818     if test "x$RETVAL" = x0 ; then
1819     HAVE_TEST_L=t
1820     fi
1821 edhill 1.35 rm -f genmake_test_ln genmake_tlink
1822 edhill 1.77
1823     # Check for broken *.F/*.f handling and fix if possible
1824     check_for_broken_Ff
1825 edhill 1.29
1826 adcroft 1.67 if test ! "x$MPI" = x ; then
1827     echo " Turning on MPI cpp macros"
1828 jmc 1.239 DEFINES="$DEFINES -DALLOW_USE_MPI"
1829 jmc 1.248 #- To compile code older than checkpoint63s (2012/09/05), un-comment the following line:
1830     # DEFINES="$DEFINES -DALWAYS_USE_MPI"
1831 adcroft 1.67 fi
1832 jmc 1.187 if test ! "x$OMP" = x ; then
1833     echo " Add OMPFLAG and turn on OpenMP cpp macros"
1834     FFLAGS="$FFLAGS $OMPFLAG"
1835     F90FLAGS="$F90FLAGS $OMPFLAG"
1836     DEFINES="$DEFINES -DUSE_OMP_THREADING"
1837     fi
1838 edhill 1.39
1839 jmc 1.203 if test ! "x$USE_R4" = x ; then
1840     echo " Turning on LET_RS_BE_REAL4 cpp flag"
1841     DEFINES="$DEFINES -DLET_RS_BE_REAL4"
1842     fi
1843    
1844 ce107 1.126 if test ! "x$TS" = x ; then
1845     echo " Turning on timing per timestep"
1846 ce107 1.139 if test ! "x$FOOLAD" = x ; then
1847 jmc 1.236 DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP"
1848 ce107 1.139 else
1849     DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1850     fi
1851 ce107 1.164 PACKAGES="$PACKAGES showflops"
1852 ce107 1.139 fi
1853     if test ! "x$PAPIS" = x ; then
1854     echo " Turning on PAPI flop summary per timestep"
1855     echo " Please make sure PAPIINC, PAPILIB are defined"
1856     if test ! "x$FOOLAD" = x ; then
1857     DEFINES="$DEFINES -DUSE_PAPI_FLOPS_SFP"
1858     else
1859     DEFINES="$DEFINES -DUSE_PAPI_FLOPS"
1860     fi
1861     INCLUDES="$INCLUDES $PAPIINC"
1862     LIBS="$LIBS $PAPILIB"
1863 ce107 1.164 PACKAGES="$PACKAGES showflops"
1864 ce107 1.139 fi
1865 ce107 1.147 if test ! "x$PCLS" = x ; then
1866     echo " Turning on PCL counter summary per timestep"
1867     echo " Please make sure PCLINC, PCLLIB are defined"
1868     if test ! "x$FOOLAD" = x ; then
1869     DEFINES="$DEFINES -DUSE_PCL_FLOPS_SFP"
1870     else
1871     DEFINES="$DEFINES -DUSE_PCL_FLOPS"
1872     fi
1873     INCLUDES="$INCLUDES $PCLINC"
1874     LIBS="$LIBS $PCLLIB"
1875 ce107 1.164 PACKAGES="$PACKAGES showflops"
1876 ce107 1.147 fi
1877 ce107 1.139 if test ! "x$PAPI" = x ; then
1878     if test ! "x$PAPIS" = x ; then
1879     echo " PAPI performance analysis and flop summary per timestep cannot co-exist!"
1880     echo " Sticking with PAPI flop summary per timestep!"
1881     else
1882     echo " Turning on performance analysis with PAPI"
1883 jmc 1.236 echo " Please make sure PAPIINC, PAPILIB are defined"
1884 ce107 1.139 DEFINES="$DEFINES -DUSE_PAPI"
1885     INCLUDES="$INCLUDES $PAPIINC"
1886     LIBS="$LIBS $PAPILIB"
1887     fi
1888     fi
1889 ce107 1.147 if test ! "x$PCL" = x ; then
1890     if test ! "x$PCLS" = x ; then
1891     echo " PCL performance analysis and flop summary per timestep cannot co-exist!"
1892     echo " Sticking with PCL flop summary per timestep!"
1893     else
1894     echo " Turning on performance analysis with PCL"
1895 jmc 1.236 echo " Please make sure PCLINC, PCLLIB are defined"
1896 ce107 1.147 DEFINES="$DEFINES -DUSE_PCL"
1897     INCLUDES="$INCLUDES $PCLINC"
1898     LIBS="$LIBS $PCLLIB"
1899     fi
1900     fi
1901 ce107 1.139 if test ! "x$HPMT" = x ; then
1902     if test ! "x$PAPI" = x ; then
1903     echo " PAPI and the HPM Toolkit cannot co-exist!"
1904     echo " Sticking with PAPI!"
1905 jmc 1.237 else
1906     if test ! "x$PCL" = x ; then
1907 ce107 1.147 echo " PCL and the HPM Toolkit cannot co-exist!"
1908     echo " Sticking with PCL!"
1909 jmc 1.237 else
1910 ce107 1.139 echo " Turning on performance analysis with the HPM Toolkit"
1911 jmc 1.236 echo " Please make sure HPMTINC, HPMTLIB are defined"
1912 ce107 1.139 DEFINES="$DEFINES -DUSE_LIBHPM"
1913 jmc 1.236 INCLUDES="$INCLUDES $HPMTINC"
1914 ce107 1.139 LIBS="$LIBS $HPMTLIB"
1915 jmc 1.237 fi
1916 ce107 1.148 fi
1917 ce107 1.139 fi
1918     if test ! "x$GSL" = x ; then
1919     echo " Turning on use of GSL to control floating point calculations"
1920     echo " Please make sure GSLINC, GSLLIB are defined"
1921     DEFINES="$DEFINES -DUSE_GSL_IEEE"
1922     INCLUDES="$INCLUDES $GSLINC"
1923     LIBS="$LIBS $GSLLIB"
1924 ce107 1.126 fi
1925 jmc 1.181 #- if USE_EXTENDED_SRC is set, add EXTENDED_SRC_FLAG to FFLAGS :
1926     if test ! "x$USE_EXTENDED_SRC" = x ; then
1927     FFLAGS="$FFLAGS $EXTENDED_SRC_FLAG"
1928     F90FIXEDFORMAT="$F90FIXEDFORMAT $EXTENDED_SRC_FLAG"
1929     fi
1930 ce107 1.126
1931 edhill 1.29 printf "\n=== Checking system libraries ===\n"
1932 edhill 1.71 printf " Do we have the system() command using $FC... "
1933 edhill 1.118 cat > genmake_tcomp.$FS <<EOF
1934 edhill 1.29 program hello
1935     call system('echo hi')
1936     end
1937     EOF
1938 edhill 1.134 $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1939 edhill 1.29 RETVAL=$?
1940     if test "x$RETVAL" = x0 ; then
1941     HAVE_SYSTEM=t
1942     DEFINES="$DEFINES -DHAVE_SYSTEM"
1943     echo "yes"
1944     else
1945     HAVE_SYSTEM=
1946     echo "no"
1947     fi
1948     rm -f genmake_tcomp*
1949    
1950 edhill 1.71 printf " Do we have the fdate() command using $FC... "
1951 edhill 1.118 cat > genmake_tcomp.$FS <<EOF
1952 edhill 1.29 program hello
1953 edhill 1.129 CHARACTER*(128) string
1954 edhill 1.29 string = ' '
1955     call fdate( string )
1956     print *, string
1957     end
1958     EOF
1959 edhill 1.134 $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1960 edhill 1.29 RETVAL=$?
1961     if test "x$RETVAL" = x0 ; then
1962     HAVE_FDATE=t
1963     DEFINES="$DEFINES -DHAVE_FDATE"
1964     echo "yes"
1965     else
1966     HAVE_FDATE=
1967     echo "no"
1968     fi
1969     rm -f genmake_tcomp*
1970    
1971 cnh 1.81 printf " Do we have the etime() command using $FC... "
1972 edhill 1.118 cat > genmake_tcomp.$FS <<EOF
1973 cnh 1.81 program hello
1974 cnh 1.82 REAL*4 ACTUAL, TARRAY(2)
1975     EXTERNAL ETIME
1976     REAL*4 ETIME
1977     actual = etime( tarray )
1978 cnh 1.81 print *, tarray
1979     end
1980     EOF
1981 edhill 1.134 $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1982 cnh 1.81 RETVAL=$?
1983     if test "x$RETVAL" = x0 ; then
1984     HAVE_ETIME=t
1985     DEFINES="$DEFINES -DHAVE_ETIME"
1986     echo "yes"
1987     else
1988     HAVE_ETIME=
1989     echo "no"
1990     fi
1991     rm -f genmake_tcomp*
1992    
1993 edhill 1.71 printf " Can we call simple C routines (here, \"cloc()\") using $FC... "
1994 edhill 1.39 check_HAVE_CLOC
1995     if test "x$HAVE_CLOC" != x ; then
1996 jmc 1.230 DEFINES="$DEFINES -DHAVE_CLOC"
1997 edhill 1.39 echo "yes"
1998     else
1999     echo "no"
2000 edhill 1.141 if test "x$EMBED_SRC" = xt ; then
2001     echo " WARNING: you requested file embedding but it has"
2002     echo " been disabled since C code cannot be called"
2003     EMBED_SRC=
2004     fi
2005 edhill 1.29 fi
2006 edhill 1.39 rm -f genmake_t*
2007 edhill 1.29
2008 edhill 1.130 printf " Can we unlimit the stack size using $FC... "
2009     check_HAVE_SETRLSTK
2010 edhill 1.151 if test "x$HAVE_SETRLSTK" = xt ; then
2011 jmc 1.230 DEFINES="$DEFINES -DHAVE_SETRLSTK"
2012 edhill 1.130 echo "yes"
2013     else
2014     echo "no"
2015     fi
2016     rm -f genmake_t*
2017    
2018 edhill 1.137 printf " Can we register a signal handler using $FC... "
2019     check_HAVE_SIGREG
2020 edhill 1.150 if test "x$HAVE_SIGREG" = xt ; then
2021 jmc 1.230 DEFINES="$DEFINES -DHAVE_SIGREG"
2022 edhill 1.137 echo "yes"
2023     else
2024     echo "no"
2025     fi
2026     rm -f genmake_t*
2027    
2028 edhill 1.108 printf " Can we use stat() through C calls... "
2029     check_HAVE_STAT
2030     if test "x$HAVE_STAT" != x ; then
2031 jmc 1.230 DEFINES="$DEFINES -DHAVE_STAT"
2032 edhill 1.108 echo "yes"
2033     else
2034     echo "no"
2035     fi
2036     rm -f genmake_t*
2037    
2038 edhill 1.71 printf " Can we create NetCDF-enabled binaries... "
2039 edhill 1.60 check_netcdf_libs
2040     if test "x$HAVE_NETCDF" != x ; then
2041 jmc 1.230 DEFINES="$DEFINES -DHAVE_NETCDF"
2042 edhill 1.60 echo "yes"
2043     else
2044     echo "no"
2045     fi
2046 jahn 1.232
2047     printf " Can we create LAPACK-enabled binaries... "
2048     check_lapack_libs
2049     if test "x$HAVE_LAPACK" != x ; then
2050     DEFINES="$DEFINES -DHAVE_LAPACK"
2051     echo "yes"
2052     else
2053     echo "no"
2054     fi
2055 jmc 1.244
2056     printf " Can we call FLUSH intrinsic subroutine... "
2057     check_HAVE_FLUSH
2058     if test "x$HAVE_FLUSH" = xt ; then
2059     DEFINES="$DEFINES -DHAVE_FLUSH"
2060     echo "yes"
2061     else
2062     echo "no"
2063     fi
2064    
2065 edhill 1.124 DEFINES="$DEFINES $IGNORE_TIME"
2066 edhill 1.141 if test "x$EMBED_SRC" = xt ; then
2067     build_embed_encode
2068     fi
2069     if test "x$EMBED_SRC" = xt ; then
2070     ENABLE="$ENABLE embed_files"
2071 jmc 1.230 # DEFINES="$DEFINES -DHAVE_EMBED_SRC"
2072 edhill 1.141 fi
2073    
2074 edhill 1.2 printf "\n=== Setting defaults ===\n"
2075 jmc 1.185 printf " Adding MODS directories: "
2076 edhill 1.1 for d in $MODS ; do
2077     if test ! -d $d ; then
2078 edhill 1.2 echo
2079     echo "Error: MODS directory \"$d\" not found!"
2080 edhill 1.1 exit 1
2081     else
2082 jmc 1.185 printf "$d "
2083 edhill 1.1 SOURCEDIRS="$SOURCEDIRS $d"
2084     INCLUDEDIRS="$INCLUDEDIRS $d"
2085     fi
2086     done
2087     echo
2088    
2089 jmc 1.212 #if test "x${PLATFORM}" = x ; then
2090     # PLATFORM=$p_PLATFORM
2091     #fi
2092 edhill 1.1
2093     if test "x${EXEDIR}" = x ; then
2094 edhill 1.112 tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
2095 edhill 1.87 if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
2096 edhill 1.1 EXEDIR=../exe
2097     else
2098     EXEDIR=.
2099     fi
2100     fi
2101     if test ! -d ${EXEDIR} ; then
2102     echo "Error: the specified EXEDIR (\"$EXEDIR\") does not exist!"
2103     exit 1
2104     fi
2105    
2106     if test "x${TOOLSDIR}" = x ; then
2107     TOOLSDIR="$ROOTDIR/tools"
2108     fi
2109     if test ! -d ${TOOLSDIR} ; then
2110 cnh 1.65 echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
2111 edhill 1.1 exit 1
2112     fi
2113 edhill 1.11 if test "x$S64" = x ; then
2114 edhill 1.104 echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1
2115     RETVAL=$?
2116     if test "x${RETVAL}" = x0 ; then
2117     S64='$(TOOLSDIR)/set64bitConst.sh'
2118     else
2119     echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1
2120     RETVAL=$?
2121     if test "x${RETVAL}" = x0 ; then
2122     S64='$(TOOLSDIR)/set64bitConst.csh'
2123     else
2124     cat <<EOF
2125    
2126     ERROR: neither of the two default scripts:
2127    
2128     ${TOOLSDIR}/set64bitConst.sh
2129     ${TOOLSDIR}/set64bitConst.csh
2130    
2131 jmc 1.206 are working so please check paths or specify (with \$S64) a
2132 edhill 1.104 working version of this script.
2133    
2134     EOF
2135     exit 1
2136     fi
2137     fi
2138 edhill 1.11 fi
2139 adcroft 1.44 THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
2140 edhill 1.1
2141     EXECUTABLE=${EXECUTABLE:-mitgcmuv}
2142    
2143 jmc 1.205 # Set Standard Code Directories:
2144     if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
2145     STANDARDDIRS="eesupp model"
2146     fi
2147     # if model in Standard-Code-Dir, add eesupp (needed to compile model)
2148     echo " $STANDARDDIRS " | grep ' model ' > /dev/null 2>&1
2149     ckM=$?
2150     echo " $STANDARDDIRS " | grep ' eesupp ' > /dev/null 2>&1
2151     ckE=$?
2152 jmc 1.206 if test $ckM = 0 -a $ckE = 1 ; then
2153 jmc 1.205 STANDARDDIRS="$STANDARDDIRS eesupp"
2154     fi
2155    
2156 edhill 1.1 # We have a special set of source files in eesupp/src which are
2157     # generated from some template source files. We'll make them first so
2158     # they appear as regular source code
2159     if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
2160     echo " Making source files in eesupp from templates"
2161 jmc 1.207 ( cd $ROOTDIR"/eesupp/src/" && $MAKE clean_old && $MAKE \
2162     ) > make_eesupp.errors 2>&1
2163 edhill 1.1 RETVAL=$?
2164 edhill 1.2 if test "x${RETVAL}" = x0 ; then
2165 edhill 1.1 rm -f make_eesupp.errors
2166     else
2167     echo "Error: problem encountered while building source files in eesupp:"
2168 edhill 1.62 cat make_eesupp.errors 1>&2
2169 edhill 1.1 exit 1
2170 afe 1.58 fi
2171     fi
2172    
2173 edhill 1.154 #same for pkg/exch2 and pkg/regrid
2174     for pdir in exch2 regrid ; do
2175     if test -r $ROOTDIR"/pkg/${pdir}/Makefile" ; then
2176     echo " Making source files in pkg/${pdir} from templates"
2177 jmc 1.207 ( cd $ROOTDIR"/pkg/"${pdir} && $MAKE clean_old && $MAKE \
2178     ) > make_${pdir}.errors 2>&1
2179 edhill 1.154 RETVAL=$?
2180     if test "x${RETVAL}" = x0 ; then
2181     rm -f make_${pdir}.errors
2182     else
2183     echo "Error: problem encountered while building source files in pkg/${pdir}:"
2184     cat make_${pdir}.errors 1>&2
2185     exit 1
2186     fi
2187 edhill 1.1 fi
2188 edhill 1.154 done
2189 edhill 1.1
2190 edhill 1.2 printf "\n=== Determining package settings ===\n"
2191 jmc 1.208 if test "x${PKG_DEPEND}" = x ; then
2192 edhill 1.1 tmp=$ROOTDIR"/pkg/pkg_depend"
2193 jmc 1.208 if test -r $tmp ; then PKG_DEPEND=$tmp ; fi
2194     fi
2195     if test "x${PKG_DEPEND}" = x ; then
2196 edhill 1.1 echo "Warning: No package dependency information was specified."
2197     echo " Please check that ROOTDIR/pkg/pkg_depend exists."
2198 jmc 1.208 else
2199     if test ! -r ${PKG_DEPEND} ; then
2200     echo "Error: can't read package dependency info from PKG_DEPEND=\"$PKG_DEPEND\""
2201     exit 1
2202 edhill 1.1 fi
2203 jmc 1.208 echo " getting package dependency info from $PKG_DEPEND"
2204     # Strip the comments and then convert the dependency file into arrays: PNAME, DNAME
2205     get_pdepend_list $PKG_DEPEND
2206     fi
2207    
2208     # A default package groups file "$ROOTDIR/pkg/pkg_groups" is provided
2209     # to define the "default_pkg_list" and package groups (for convenience, one
2210     # can specify a group of packages using names like "ocean" and "atmosphere").
2211     if test "x${PKG_GROUPS}" = x ; then
2212     tmp=$ROOTDIR"/pkg/pkg_groups"
2213     if test -r $tmp ; then PKG_GROUPS=$tmp ; fi
2214     fi
2215     if test "x${PKG_GROUPS}" = x ; then
2216     echo "Warning: No package groups information was specified."
2217     echo " Please check that ROOTDIR/pkg/pkg_groups exists."
2218 edhill 1.1 else
2219 jmc 1.208 if test ! -r ${PKG_GROUPS} ; then
2220     echo "Error: can't read package groups info from PKG_GROUPS=\"$PKG_GROUPS\""
2221 edhill 1.1 exit 1
2222     fi
2223 jmc 1.208 echo " getting package groups info from $PKG_GROUPS"
2224 edhill 1.1 fi
2225 jmc 1.208
2226     # Search for packages to compile.
2227     echo " checking list of packages to compile:"
2228     PKG_LIST=
2229     if test "x${PKG_LIST}" = x ; then
2230 edhill 1.12 for i in "." $MODS ; do
2231     if test -r $i"/packages.conf" ; then
2232 jmc 1.208 PKG_LIST=$i"/packages.conf"
2233 edhill 1.12 break
2234     fi
2235     done
2236     fi
2237 jmc 1.208 if test "x${PKG_LIST}" = x ; then
2238     pkg_list='default_pkg_list'
2239     if test "x${PKG_GROUPS}" = x ; then
2240     echo "Error: need package groups info to expand pkg_list=\"$pkg_list\""
2241     exit 1
2242     fi
2243 edhill 1.1 else
2244 jmc 1.208 if test ! -r $PKG_LIST ; then
2245     echo "Error: can't read package list from PKG_LIST=\"$PKG_LIST\""
2246     exit 1
2247 edhill 1.1 else
2248 jmc 1.208 echo " using PKG_LIST=\"$PKG_LIST\""
2249 jmc 1.237 # Strip the comments and add all the names
2250 jmc 1.208 pkg_list=`cat $PKG_LIST | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
2251 edhill 1.1 RETVAL=$?
2252     if test "x${RETVAL}" != x0 ; then
2253 jmc 1.208 printf "Error: can't parse package list "
2254     echo "-- please check PKG_LIST=\"$PKG_LIST\""
2255 edhill 1.1 exit 1
2256     fi
2257     fi
2258     fi
2259 jmc 1.208 for i in $pkg_list ; do
2260     PACKAGES="$PACKAGES $i"
2261     done
2262     echo " before group expansion packages are:$PACKAGES"
2263     if test "x${PKG_GROUPS}" != x ; then
2264     RET=1
2265     while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
2266     echo " after group expansion packages are: $PACKAGES"
2267     fi
2268 edhill 1.1
2269     echo " applying DISABLE settings"
2270 jmc 1.260 echo "" > $TMP.pack
2271 adcroft 1.74 for i in $PACKAGES ; do
2272 jmc 1.260 echo $i >> $TMP.pack
2273 adcroft 1.74 done
2274 jmc 1.260 for i in `grep "-" $TMP.pack` ; do
2275 adcroft 1.74 j=`echo $i | sed 's/[-]//'`
2276     DISABLE="$DISABLE $j"
2277     done
2278 edhill 1.1 pack=
2279     for p in $PACKAGES ; do
2280     addit="t"
2281     for d in $DISABLE ; do
2282     if test "x$p" = "x$d" ; then
2283     addit="f"
2284     fi
2285     done
2286     if test "x$addit" = xt ; then
2287     pack="$pack $p"
2288     fi
2289     done
2290     PACKAGES="$pack"
2291     echo " applying ENABLE settings"
2292 jmc 1.260 echo "" > $TMP.pack
2293 edhill 1.1 PACKAGES="$PACKAGES $ENABLE"
2294 adcroft 1.74 # Test if each explicitly referenced package exists
2295 edhill 1.1 for i in $PACKAGES ; do
2296 adcroft 1.74 j=`echo $i | sed 's/[-+]//'`
2297     if test ! -d "$ROOTDIR/pkg/$j" ; then
2298 jmc 1.208 echo "Error: dir '$ROOTDIR/pkg/$i' missing for package '$i'"
2299 jmc 1.236 exit 1
2300 edhill 1.1 fi
2301 jmc 1.260 echo $i >> $TMP.pack
2302 edhill 1.1 done
2303     PACKAGES=
2304 jmc 1.260 for i in `grep -v "-" $TMP.pack | sort | uniq` ; do
2305 edhill 1.1 PACKAGES="$PACKAGES $i"
2306     done
2307 jmc 1.260 rm -f $TMP.pack
2308 jmc 1.205 echo " packages are: $PACKAGES"
2309 edhill 1.1
2310 jmc 1.206 # Check for package MNC: if NetCDF is available, then build the MNC
2311 jmc 1.161 # template files ; otherwise, delete mnc from the list of packages.
2312 jmc 1.205 echo " $PACKAGES " | grep ' mnc ' > /dev/null 2>&1
2313 jmc 1.206 mnc_in=$?
2314     if test "x$HAVE_NETCDF" != xt ; then
2315     if test "x$mnc_in" = x0 ; then
2316 edhill 1.100 cat <<EOF
2317     *********************************************************************
2318     WARNING: the "mnc" package was enabled but tests failed to compile
2319     NetCDF applications. Please check that:
2320    
2321     1) NetCDF is correctly installed for this compiler and
2322 jmc 1.206 2) the LIBS variable (within the "optfile") specifies the correct
2323 edhill 1.100 NetCDF library to link against.
2324    
2325     Due to this failure, the "mnc" package is now DISABLED.
2326     *********************************************************************
2327     EOF
2328     PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
2329     DISABLE="$DISABLE mnc"
2330     else
2331 jmc 1.206 # this prevent to add mnc (due to pdepend rules) if not available
2332     DISABLE="$DISABLE mnc"
2333     fi
2334     else
2335     # we have NetCDF, we try to build MNC template files
2336     ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
2337     RETVAL=$?
2338     if test "x${RETVAL}" = x0 ; then
2339     rm -f make_mnc.errors
2340     else
2341     echo "Error: problem encountered while building source files in pkg/mnc:"
2342     cat make_mnc.errors 1>&2
2343     if test "x$mnc_in" = x0 ; then
2344 jmc 1.237 exit 1
2345 edhill 1.100 else
2346 jmc 1.206 DISABLE="$DISABLE mnc"
2347 edhill 1.100 fi
2348     fi
2349     fi
2350    
2351 jmc 1.161 # Check for package PROFILES: if NetCDF is not available,
2352     # then delete profiles from the list of available packages.
2353 jmc 1.206 if test "x$HAVE_NETCDF" != xt ; then
2354     echo " $PACKAGES " | grep ' profiles ' > /dev/null 2>&1
2355     RETVAL=$?
2356     if test "x$RETVAL" = x0 ; then
2357 jmc 1.161 cat <<EOF
2358     *********************************************************************
2359     WARNING: the "profiles" package was enabled but tests failed to
2360     compile NetCDF applications. Please check that:
2361    
2362     1) NetCDF is correctly installed for this compiler and
2363 jmc 1.206 2) the LIBS variable (within the "optfile") specifies the correct
2364 jmc 1.161 NetCDF library to link against.
2365    
2366     Due to this failure, the "profiles" package is now DISABLED.
2367     *********************************************************************
2368     EOF
2369     PACKAGES=`echo $PACKAGES | sed -e 's/profiles//g'`
2370     DISABLE="$DISABLE profiles"
2371 jmc 1.206 else
2372     # this prevent to add profiles (due to pdepend rules) if not available
2373     DISABLE="$DISABLE profiles"
2374 jmc 1.161 fi
2375     fi
2376    
2377 jahn 1.261 # Make sure the openad package is enabled if using OpenAD
2378     if test "x$OPENAD" != x ; then
2379     echo " $PACKAGES " | grep ' openad ' > /dev/null 2>&1
2380     RETVAL=$?
2381     if test "x$RETVAL" != x0 ; then
2382     cat <<EOF
2383    
2384     *********************************************************************
2385     ERROR: when generating an adjoint with OpenAD, the openad package
2386     must be enabled. Please add it to packages.conf.
2387     *********************************************************************
2388    
2389     EOF
2390     exit 1
2391     fi
2392     fi
2393    
2394 jmc 1.208 if test "x${PKG_DEPEND}" != x ; then
2395     echo " applying package dependency rules"
2396     ck=
2397     while test "x$ck" != xtt ; do
2398 edhill 1.1 i=0
2399 edhill 1.2 # rtot=${#PNAME[@]}
2400     rtot=$nname
2401 jmc 1.162 while test $i -le $rtot ; do
2402 edhill 1.1
2403     # Is $pname in the current $PACKAGES list?
2404 edhill 1.2 # pname=${PNAME[$i]}
2405     tmp="pname=\"\$PNAME_$i\""
2406     eval $tmp
2407 edhill 1.1 pin="f"
2408     for p in $PACKAGES ; do
2409     if test "x$p" = "x$pname" ; then
2410     pin="t"
2411     fi
2412     done
2413 jmc 1.205 # or in the current $STANDARDDIRS list?
2414     for p in $STANDARDDIRS ; do
2415     if test "x$p" = "x$pname" ; then pin="t" ; fi
2416     done
2417 edhill 1.1
2418     # Is the DNAME entry a (+) or (-) rule ?
2419 edhill 1.2 tmp="dname=\"\$DNAME_$i\""
2420     eval $tmp
2421 edhill 1.1 plus="-"
2422 edhill 1.2 echo $dname | grep '^+' > /dev/null 2>&1
2423 edhill 1.1 RETVAL=$?
2424     if test "x$RETVAL" = x0 ; then
2425     plus="+"
2426     fi
2427    
2428     # Is $dname in the current $PACKAGES list?
2429 edhill 1.2 dname=`echo $dname | sed -e 's/^[+-]//'`
2430 edhill 1.1 din="f"
2431     for p in $PACKAGES ; do
2432     if test "x$p" = "x$dname" ; then
2433     din="t"
2434     fi
2435     done
2436    
2437     # Do we need to add $dname according to the dependency rules?
2438     if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then
2439 jmc 1.236 #echo " " $pname ": need to add :" $dname
2440 edhill 1.1 in_dis="f"
2441     for dis in $DISABLE ; do
2442     if test "x$dis" = "x$dname" ; then
2443     in_dis="t"
2444     fi
2445     done
2446     if test "x$in_dis" = xt ; then
2447     echo "Error: can't satisfy package dependencies:"
2448     echo " \"$dname\" is required by the dependency rules"
2449     echo " but is disallowed by the DISABLE settings"
2450     exit 1
2451     else
2452     PACKAGES="$PACKAGES $dname"
2453     ck=
2454     fi
2455     fi
2456    
2457     # Do we need to get rid of $dname according to the dependency rules?
2458     if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then
2459     echo "Error: can't satisfy package dependencies:"
2460 jmc 1.206 echo " \"$pname\" was requested but is disallowed by"
2461 edhill 1.1 echo " the dependency rules for \"$dname\""
2462     exit 1
2463     fi
2464 jmc 1.236 i=`echo "$i + 1" | bc -l`
2465 edhill 1.87 #i=$(( $i + 1 ))
2466 edhill 1.1 done
2467     ck=$ck"t"
2468 jmc 1.208 done
2469     echo " packages are: $PACKAGES"
2470     fi
2471 edhill 1.1 for i in $PACKAGES ; do
2472     adr="$ROOTDIR/pkg/$i"
2473     if test -d $adr ; then
2474     SOURCEDIRS="$SOURCEDIRS $adr"
2475     INCLUDEDIRS="$INCLUDEDIRS $adr"
2476 edhill 1.14 if test "x$i" = xautodiff ; then
2477     AUTODIFF_PKG_USED=t
2478     fi
2479 edhill 1.1 else
2480     echo "Error: the directory \"$adr\" for package $i doesn't exist"
2481     exit 1
2482     fi
2483     done
2484    
2485 edhill 1.12 # Create a list of #define and #undef to enable/disable packages
2486     PACKAGES_DOT_H=PACKAGES_CONFIG.h
2487 jmc 1.206 # The following UGLY HACK sets multiple "#undef"s and it needs to go
2488     # away. On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
2489 edhill 1.1 # file would eventually be split up so that all package-related #define
2490     # statements could be separated and handled only by genmake.
2491     names=`ls -1 "$ROOTDIR/pkg"`
2492     all_pack=
2493 adcroft 1.44 DISABLED_PACKAGES=
2494 edhill 1.1 for n in $names ; do
2495     if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
2496     has_pack="f"
2497     for pack in $PACKAGES ; do
2498     if test "x$pack" = "x$n" ; then
2499     has_pack="t"
2500     break
2501     fi
2502     done
2503     if test "x$has_pack" = xf ; then
2504 edhill 1.116 undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2505 jmc 1.236 DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
2506 edhill 1.1 fi
2507     fi
2508     done
2509 adcroft 1.44 ENABLED_PACKAGES=
2510 edhill 1.1 for i in $PACKAGES ; do
2511 edhill 1.116 def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2512 adcroft 1.44 ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
2513 edhill 1.12 #eh3 DEFINES="$DEFINES -D$def"
2514 edhill 1.1
2515     #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
2516 jmc 1.206 case $i in
2517 edhill 1.1 aim_v23)
2518 jmc 1.236 ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
2519 jmc 1.55 echo "Warning: ALLOW_AIM is set to enable aim_v23."
2520 edhill 1.1 ;;
2521     esac
2522     #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
2523    
2524     done
2525    
2526 jmc 1.205 echo " Adding STANDARDDIRS='$STANDARDDIRS'"
2527 edhill 1.1 BUILDDIR=${BUILDDIR:-.}
2528 edhill 1.57 if test "x$STANDARDDIRS" != x ; then
2529     for d in $STANDARDDIRS ; do
2530     adr="$ROOTDIR/$d/src"
2531     if test ! -d $adr ; then
2532     echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
2533     echo " is correct and that you correctly specified the STANDARDDIRS option"
2534     exit 1
2535     else
2536     SOURCEDIRS="$SOURCEDIRS $adr"
2537     fi
2538     adr="$ROOTDIR/$d/inc"
2539     if test ! -d $adr ; then
2540     echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
2541     echo " is correct and that you correctly specified the STANDARDDIRS option"
2542     exit 1
2543     else
2544     INCLUDEDIRS="$INCLUDEDIRS $adr"
2545     fi
2546     done
2547     fi
2548 edhill 1.1
2549 adcroft 1.52 echo " Searching for *OPTIONS.h files in order to warn about the presence"
2550     echo " of \"#define \"-type statements that are no longer allowed:"
2551 edhill 1.12 CPP_OPTIONS=
2552 adcroft 1.52 CPP_EEOPTIONS=
2553 edhill 1.12 spaths=". $INCLUDEDIRS"
2554 adcroft 1.52 names=`ls -1 "$ROOTDIR/pkg"`
2555 edhill 1.12 for i in $spaths ; do
2556     try="$i/CPP_OPTIONS.h"
2557 edhill 1.54 if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
2558 edhill 1.12 echo " found CPP_OPTIONS=\"$try\""
2559     CPP_OPTIONS="$try"
2560 jmc 1.236 # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
2561     for n in $names ; do
2562     test_for_package_in_cpp_options $CPP_OPTIONS $n
2563     done
2564 adcroft 1.52 fi
2565     try="$i/CPP_EEOPTIONS.h"
2566 edhill 1.54 if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
2567 adcroft 1.52 echo " found CPP_EEOPTIONS=\"$try\""
2568 jmc 1.236 # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
2569 adcroft 1.52 #**** not yet enabled ****
2570     # test_for_mpi_in_cpp_eeoptions $try
2571     #**** not yet enabled ****
2572     CPP_EEOPTIONS="$try"
2573 edhill 1.12 fi
2574     done
2575     if test "x$CPP_OPTIONS" = x ; then
2576     echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
2577     exit 1
2578     fi
2579 edhill 1.1
2580 edhill 1.14 # Here, we build the list of files to be "run through" the adjoint
2581     # compiler.
2582 jmc 1.260 if test -f $TMP.adSrcFiles ; then
2583     rm -f $TMP.adSrcFiles
2584 edhill 1.14 fi
2585     echo " Creating the list of files for the adjoint compiler."
2586 jmc 1.260 touch $TMP.adSrcFiles
2587 edhill 1.14 for i in $SOURCEDIRS ; do
2588     list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
2589     for j in $list_files ; do
2590 jmc 1.260 cat $i/$j >> $TMP.adSrcFiles
2591 edhill 1.14 done
2592     done
2593 edhill 1.121 if test ! "x"$FS = "x.f" ; then
2594 jmc 1.260 cat $TMP.adSrcFiles | sed -e "s/\.f/.$FS/g" > $TMP.adSrcFiles_f
2595     mv -f $TMP.adSrcFiles_f $TMP.adSrcFiles
2596 edhill 1.121 fi
2597 edhill 1.14
2598 edhill 1.2 echo
2599     echo "=== Creating the Makefile ==="
2600 edhill 1.1 echo " setting INCLUDES"
2601     for i in $INCLUDEDIRS ; do
2602 edhill 1.87 if test ! -d $i ; then
2603 edhill 1.1 echo "Warning: can't find INCLUDEDIRS=\"$i\""
2604     fi
2605     done
2606    
2607 jmc 1.256 if test ! "x$DIVA" = x -a ! "x$MPI" = x ; then
2608 jmc 1.253 if test ! "x$MPIINCLUDEDIR" = x ; then
2609 jmc 1.251 # Do a local copy of MPI headers files (in local dir ./mpi_headers/) after
2610     # checking for additional included headers (in case of chain of included
2611     # header); also set LOCAL_MPI_HEADERS (if not already set)
2612     mpi_headers_do_local_copy
2613 ce107 1.139 fi
2614     fi
2615    
2616 edhill 1.1 echo " Determining the list of source and include files"
2617 jmc 1.260 rm -rf $TMP.links
2618     mkdir $TMP.links
2619     touch $TMP.links/foo
2620     if test ! -r "$TMP.links/foo" ; then
2621 edhill 1.142 echo
2622     echo "ERROR : something is wrong with your directory permissions or"
2623     echo " your user file-creation mask (\"umask\") since creating a"
2624     echo " sub-dir, touch-ing a file within it, and then reading it is"
2625     echo " not working. Please try setting your umask to something"
2626     echo " sane such as:"
2627     echo
2628     echo " umask 0002"
2629     echo
2630     echo " and please verify that you have the proper permissions for"
2631     echo " creating sub-directories and then reading files created"
2632     echo " within them."
2633     echo
2634     exit 1
2635     fi
2636 jmc 1.260 rm -f $TMP.links/foo
2637 jmc 1.176
2638 jmc 1.206 if test "x$OPENAD" != x ; then
2639 jmc 1.176 OAD_DONT_COMPILE="/dev/null"
2640     OAD_DONT_TRANSFORM="/dev/null"
2641     OAD_KEEP_ORIGINAL="/dev/null"
2642     OAD_CB2M_FILES="/dev/null"
2643 heimbach 1.242 OADTOOLS="$TOOLSDIR/OAD_support"
2644 jmc 1.176 echo " looking for dontCompile file: "
2645 heimbach 1.267 for i in "." $MODS $OADTOOLS ; do
2646 jmc 1.176 if test -r $i"/dontCompile" ; then
2647     OAD_DONT_COMPILE=$i"/dontCompile"
2648     echo " found $OAD_DONT_COMPILE"
2649     break
2650     fi
2651     done
2652     echo " looking for dontTransform file: "
2653 heimbach 1.267 for i in "." $MODS $OADTOOLS ; do
2654 jmc 1.176 if test -r $i"/dontTransform" ; then
2655     OAD_DONT_TRANSFORM=$i"/dontTransform"
2656     echo " found $OAD_DONT_TRANSFORM"
2657     break
2658     fi
2659     done
2660     echo " looking for keepOriginal file: "
2661 heimbach 1.267 for i in "." $MODS $OADTOOLS ; do
2662 jmc 1.176 if test -r $i"/keepOriginal" ; then
2663     OAD_KEEP_ORIGINAL=$i"/keepOriginal"
2664     echo " found $OAD_KEEP_ORIGINAL"
2665     break
2666     fi
2667     done
2668     echo " looking for cb2mFiles: "
2669 heimbach 1.267 for i in "." $MODS $OADTOOLS ; do
2670 jmc 1.176 if test -r $i"/cb2mFiles" ; then
2671     OAD_CB2M_FILES=$i"/cb2mFiles"
2672     echo " found $OAD_CB2M_FILES"
2673     break
2674     fi
2675     done
2676     echo " OpenAD exceptions: "
2677     fi
2678    
2679 jmc 1.260 echo "# This section creates symbolic links" > $TMP.srclinks
2680     echo "" >> $TMP.srclinks
2681     printf 'F77_SRC_FILES = ' > $TMP.F77srclist
2682     printf 'NON_AD_F77_SRC_FILES = ' > $TMP.nonADF77srclist
2683     printf 'C_SRC_FILES = ' > $TMP.csrclist
2684     printf 'F90_SRC_FILES = ' > $TMP.F90srclist
2685     printf 'H_SRC_FILES = ' > $TMP.hsrclist
2686     printf 'AD_FLOW_FILES = ' > $TMP.ad_flow_files
2687 adcroft 1.9 alldirs="$SOURCEDIRS $INCLUDEDIRS ."
2688 edhill 1.1 for d in $alldirs ; do
2689     deplist=
2690 edhill 1.14 sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
2691 cnh 1.3 sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
2692 jmc 1.206 if test "x$OPENAD" != x ; then
2693 jmc 1.176 sfiles=`( echo $sfiles | grep -v _cb2m\. )`
2694     fi
2695 edhill 1.1 for sf in $sfiles ; do
2696 jmc 1.260 if test ! -r "$TMP.links/$sf" ; then
2697 edhill 1.1 if test -f "$d/$sf" ; then
2698 edhill 1.131 ignore_f=f
2699 jmc 1.236 case $d/$sf in
2700     ./$PACKAGES_DOT_H)
2701 edhill 1.141 ignore_f=t
2702 adcroft 1.44 ;;
2703 jmc 1.236 ./AD_CONFIG.h)
2704 edhill 1.141 ignore_f=t
2705 adcroft 1.44 ;;
2706 jmc 1.236 ./FC_NAMEMANGLE.h)
2707 edhill 1.141 ignore_f=t
2708 adcroft 1.44 ;;
2709 jmc 1.236 ./BUILD_INFO.h)
2710 edhill 1.141 ignore_f=t
2711     ;;
2712 jmc 1.236 ./EMBEDDED_FILES.h)
2713 edhill 1.141 ignore_f=t
2714 edhill 1.98 ;;
2715 jmc 1.236 *)
2716 edhill 1.131 # For the local directory *ONLY*,
2717     # ignore all soft-links
2718     if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then
2719     ignore_f=t
2720     else
2721 jmc 1.260 touch $TMP.links/$sf
2722 edhill 1.131 deplist="$deplist $sf"
2723     fi
2724 adcroft 1.44 ;;
2725 jmc 1.236 esac
2726 edhill 1.131 if test "x$ignore_f" = xf ; then
2727     extn=`echo $sf | $AWK -F. '{print $NF}'`
2728     case $extn in
2729 jmc 1.176 F)
2730 jmc 1.260 echo " \\" >> $TMP.F77srclist
2731     printf " $sf" >> $TMP.F77srclist
2732 jmc 1.256 if test "x$OPENAD" = x ; then
2733     basename=${sf%%.F}
2734 jmc 1.260 isAD=`egrep ^$basename.f'[ ]*' $TMP.adSrcFiles`
2735 jmc 1.256 if test -z "$isAD" ; then
2736 jmc 1.260 echo " \\" >> $TMP.nonADF77srclist
2737     printf " $sf" >> $TMP.nonADF77srclist
2738 jmc 1.256 fi
2739     else #- OpenAD case:
2740 jmc 1.176 basename=${sf%%.F}
2741 jmc 1.260 isAD=`egrep ^$basename.f'[ ]*' $TMP.adSrcFiles`
2742 jmc 1.206 if test -z "$isAD" ; then
2743 jmc 1.176 toBeIgnored=`egrep ^$basename'[ ]*' ${OAD_DONT_COMPILE}`
2744 jmc 1.206 if test -z "$toBeIgnored" ; then
2745 jmc 1.260 echo " \\" >> $TMP.nonADF77srclist
2746     printf " $sf" >> $TMP.nonADF77srclist
2747 jmc 1.206 else
2748 jmc 1.176 echo " not to be compiled : $sf"
2749     fi
2750 jmc 1.206 else # file is initially listed as an AD file we want to exclude it
2751 jmc 1.176 # or we want to retain the untransformed version
2752     notToBeTransformed=`egrep ^$basename'[ ]*' ${OAD_DONT_TRANSFORM}`
2753     untransformedVersionToBeKept=`egrep ^$basename'[ ]*' ${OAD_KEEP_ORIGINAL}`
2754 jmc 1.206 if test -n "$notToBeTransformed"; then
2755 jmc 1.176 echo " not to be transformed: $sf"
2756     fi
2757     if test -n "$untransformedVersionToBeKept" ; then
2758     echo " original to be kept : $sf"
2759 jmc 1.206 fi
2760 jmc 1.176 if test -n "$notToBeTransformed" -o -n "$untransformedVersionToBeKept" ; then
2761 jmc 1.260 echo " \\" >> $TMP.nonADF77srclist
2762     printf " $sf" >> $TMP.nonADF77srclist
2763 jmc 1.176 fi
2764     fi
2765     fi
2766     ;;
2767     F90)
2768 jmc 1.260 echo " \\" >> $TMP.F90srclist
2769     printf " $sf" >> $TMP.F90srclist
2770 jmc 1.176 ;;
2771     c)
2772 jmc 1.260 echo " \\" >> $TMP.csrclist
2773     printf " $sf" >> $TMP.csrclist
2774 jmc 1.176 ;;
2775     h)
2776 jmc 1.260 echo " \\" >> $TMP.hsrclist
2777     printf " $sf" >> $TMP.hsrclist
2778 jmc 1.176 ;;
2779 jmc 1.236 flow)
2780 jmc 1.260 echo " \\" >> $TMP.ad_flow_files
2781     printf " $sf" >> $TMP.ad_flow_files
2782 jmc 1.176 ;;
2783     esac
2784     fi
2785 edhill 1.1 fi
2786     fi
2787     done
2788     if test "x$deplist" != x ; then
2789 jmc 1.176 if test "$d" != "." ; then
2790 jmc 1.260 echo "" >> $TMP.srclinks
2791     echo "# These files are linked from $d" >> $TMP.srclinks
2792     echo "$deplist :" >> $TMP.srclinks
2793 jahn 1.170 # We need to make sure that the link isn't already there.
2794     # This may happen when make thinks that a header file has to be "remade"
2795     # because a module it depends on has changed. In this case we do nothing.
2796 jmc 1.260 printf "\tif [ ! -L \$@ ]; then \$(LN) %s/\$@ \$@; fi\n" $d >> $TMP.srclinks
2797 jmc 1.176 fi
2798 edhill 1.1 fi
2799     done
2800 jmc 1.260 rm -rf $TMP.links
2801     echo "" >> $TMP.F77srclist
2802     echo "" >> $TMP.nonADF77srclist
2803     echo "" >> $TMP.csrclist
2804     echo "" >> $TMP.F90srclist
2805     echo "" >> $TMP.hsrclist
2806     echo "" >> $TMP.ad_flow_files
2807 edhill 1.1
2808 jmc 1.192 CMDLINE=$0