/[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.236 - (hide annotations) (download)
Fri Aug 24 23:07:27 2012 UTC (7 years ago) by jmc
Branch: MAIN
Changes since 1.235: +92 -93 lines
- improve error msg when failing in 2nd test of check_for_broken_Ff
- rename FLOFILES -> FLOWFILES

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