/[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.134 - (hide annotations) (download)
Wed Nov 9 04:31:30 2005 UTC (18 years, 4 months ago) by edhill
Branch: MAIN
Changes since 1.133: +5 -5 lines
 o removed buggy $DEFINES which had been, in error, used as command-line
   options for some of the Fortran compiler tests -- this should fix
   some problems pointed out by Jeff Polton

1 edhill 1.86 #! /usr/bin/env bash
2 edhill 1.1 #
3 edhill 1.134 # $Header: /u/gcmpack/MITgcm/tools/genmake2,v 1.133 2005/10/15 00:35:36 edhill Exp $
4 edhill 1.1 #
5     # Makefile generator for MITgcm UV codes
6     # created by cnh 03/98
7     # adapted by aja 06/98
8     # modified by aja 01/00
9     # rewritten in bash by eh3 08/03
10    
11 edhill 1.12 # Search for particular CPP #cmds associated with packages
12     # usage: test_for_package_in_cpp_options CPP_file package_name
13     test_for_package_in_cpp_options() {
14     cpp_options=$1
15     pkg=$2
16 adcroft 1.52 test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg" || exit 99
17     test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg" || exit 99
18     test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg" || exit 99
19     test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg" || exit 99
20     }
21    
22     # Search for particular CPP #cmds associated with MPI
23     # usage: test_for_mpi_in_cpp_eeoptions CPP_file
24     test_for_mpi_in_cpp_eeoptions() {
25     cpp_options=$1
26     test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI" || exit 99
27     test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI" || exit 99
28     test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI" || exit 99
29     test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI" || exit 99
30     }
31    
32     # Search for particular string in a file. Return 1 if detected, 0 if not
33     # usage: test_for_string_in_file file string
34     test_for_string_in_file() {
35     file=$1
36     strng=$2
37     grep -i "$strng" $file > /dev/null 2>&1
38 edhill 1.12 RETVAL=$?
39     if test "x${RETVAL}" = x0 ; then
40 edhill 1.71 printf "Error: In $file there is an illegal line: "
41 adcroft 1.52 grep -i "$strng" $file
42     return 1
43 edhill 1.12 fi
44 adcroft 1.52 return 0
45 edhill 1.12 }
46    
47     # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to
48     # the package list.
49     expand_pkg_groups() {
50     new_packages=
51     PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups"
52     if test -r $PKG_GROUPS ; then
53     cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp
54 edhill 1.15 cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp
55 edhill 1.12 matched=0
56     for i in $PACKAGES ; do
57     line=`grep "^ *$i" ./p2.tmp`
58     RETVAL=$?
59     if test "x$RETVAL" = x0 ; then
60     matched=1
61 edhill 1.15 replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`
62 edhill 1.12 echo " replacing \"$i\" with: $replace"
63     new_packages="$new_packages $replace"
64     else
65     new_packages="$new_packages $i"
66     fi
67     done
68     PACKAGES=$new_packages
69     rm -f ./p[1,2].tmp
70 adcroft 1.74 return $matched
71 edhill 1.12 else
72     echo "Warning: can't read package groups definition file: $PKG_GROUPS"
73     fi
74     }
75 edhill 1.1
76 edhill 1.75 # Check for broken environments (eg. cygwin, MacOSX w/HFS+) that
77     # cannot distinguish [*.F/*.F90] from [*.f/*.f90] files.
78     check_for_broken_Ff() {
79 edhill 1.76 # Do we have defaults for $FS and/or $FS90 ?
80     tfs=f
81     tfs9=f90
82     if test "x$FS" != x ; then
83     tfs="$FS"
84     fi
85     if test "x$FS90" != x ; then
86     tfs9="$FS90"
87     fi
88    
89 edhill 1.75 # First check the ability to create a *.F/.f pair.
90 edhill 1.76 cat <<EOF >> genmake_hello.F
91 edhill 1.75 program hello
92     write(*,*) 'hi'
93     stop
94     end
95     EOF
96 edhill 1.76 cp genmake_hello.F "genmake_hello."$tfs > /dev/null 2>&1
97 edhill 1.75 RETVAL=$?
98     if test "x$RETVAL" != x0 ; then
99 edhill 1.76 if test "x$FS" = x ; then
100 edhill 1.77 FS='for'
101     FS90='fr9'
102 edhill 1.76 check_for_broken_Ff
103     else
104     cat <<EOF 2>&1
105     ERROR: Your file system cannot distinguish between *.F and *.f files
106     (fails the "cp" test) and this program cannot find a suitable
107     replacement extension. Please try a different build environment or
108     contact the <MITgcm-support@mitgcm.org> list for help.
109    
110     EOF
111     exit -1
112     fi
113 edhill 1.75 return
114     fi
115 edhill 1.76 rm -f genmake_hello.*
116 edhill 1.75
117 edhill 1.76 # Check the ability of ${MAKE} and ${LN} to use the current set
118     # of extensions.
119     cat <<EOF >> genmake_hello.F
120     program hello
121     write(*,*) 'hi'
122     stop
123     end
124     EOF
125 edhill 1.119 test -f $MAKEFILE && mv -f $MAKEFILE $MAKEFILE".tst"
126     cat <<EOF >> $MAKEFILE
127 edhill 1.75 .SUFFIXES:
128 edhill 1.101 .SUFFIXES: .$tfs .F
129     .F.$tfs:
130     $LN \$< \$@
131 edhill 1.75 EOF
132 edhill 1.76 $MAKE "genmake_hello."$tfs > /dev/null 2>&1
133 edhill 1.75 RETVAL=$?
134 edhill 1.88 if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then
135 edhill 1.76 if test "x$FS" = x ; then
136 edhill 1.77 FS='for'
137     FS90='fr9'
138 edhill 1.76 check_for_broken_Ff
139     else
140     cat <<EOF 2>&1
141     ERROR: Your file system cannot distinguish between *.F and *.f files
142     (fails the "make/ln" test) and this program cannot find a suitable
143     replacement extension. Please try a different build environment or
144     contact the <MITgcm-support@mitgcm.org> list for help.
145    
146     EOF
147     exit -1
148     return
149     fi
150 edhill 1.75 fi
151 edhill 1.119 rm -f genmake_hello.* $MAKEFILE
152     test -f $MAKEFILE".tst" && mv -f $MAKEFILE".tst" $MAKEFILE
153 edhill 1.75
154 edhill 1.76 # If we make it here, use the extensions
155     FS=$tfs
156     FS90=$tfs9
157     return
158 edhill 1.75 }
159    
160    
161 edhill 1.84 look_for_makedepend() {
162 adcroft 1.33
163 edhill 1.69 # The "original" makedepend is part of the Imake system that is
164     # most often distributed with XFree86 or with an XFree86 source
165     # package. As a result, many machines (eg. generic Linux) do not
166     # have a system-default "makedepend" available. For those
167     # systems, we have two fall-back options:
168     #
169     # 1) a makedepend implementation shipped with the cyrus-imapd
170     # package: ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
171     #
172     # 2) a known-buggy xmakedpend shell script
173     #
174     # So the choices are, in order:
175     #
176     # 1) use the user-specified program
177     # 2) use a system-wide default
178     # 3) locally build and use the cyrus implementation
179     # 4) fall back to the buggy local xmakedpend script
180     #
181 adcroft 1.33 if test "x${MAKEDEPEND}" = x ; then
182 edhill 1.85 which makedepend > /dev/null 2>&1
183     RV0=$?
184 edhill 1.119 test -f $MAKEFILE && mv -f $MAKEFILE $MAKEFILE".tst"
185     # echo 'MAKEFILE="'$MAKEFILE'"'
186     cat <<EOF >> $MAKEFILE
187     # THIS IS A TEST MAKEFILE GENERATED BY "genmake2"
188     #
189     # Some "makedepend" implementations will die if they cannot
190     # find a Makefile -- so this file is here to gives them an
191     # empty one to find and parse.
192     EOF
193 edhill 1.85 cat <<EOF >> genmake_tc.f
194 edhill 1.77 program test
195     write(*,*) 'test'
196     stop
197     end
198     EOF
199 edhill 1.85 makedepend genmake_tc.f > /dev/null 2>&1
200 mlosch 1.120 RV1=$?
201 edhill 1.119 test -f $MAKEFILE && rm -f $MAKEFILE
202     test -f $MAKEFILE".tst" && mv -f $MAKEFILE".tst" $MAKEFILE
203 edhill 1.85 if test "x${RV0}${RV1}" = x00 ; then
204     MAKEDEPEND=makedepend
205     else
206     echo " a system-default makedepend was not found."
207    
208     # Try to build the cyrus implementation
209 edhill 1.90 build_cyrus_makedepend
210 edhill 1.85 RETVAL=$?
211 edhill 1.90 if test "x$RETVAL" != x0 ; then
212 edhill 1.85 MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
213     fi
214     rm -f ./genmake_cy_md
215     fi
216 edhill 1.90 else
217     # echo "MAKEDEPEND=${MAKEDEPEND}"
218     echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1
219     RETVAL=$?
220     if test x"$RETVAL" = x0 ; then
221     build_cyrus_makedepend
222     fi
223 edhill 1.1 fi
224 edhill 1.84 }
225    
226    
227 edhill 1.90 build_cyrus_makedepend() {
228     rm -f ./genmake_cy_md
229     (
230     cd $ROOTDIR/tools/cyrus-imapd-makedepend \
231     && ./configure > /dev/null 2>&1 \
232     && make > /dev/null 2>&1
233     if test -x ./makedepend.exe ; then
234     $LN ./makedepend.exe ./makedepend
235     fi
236     ./makedepend ifparser.c > /dev/null 2>&1 \
237     && echo "true"
238     ) > ./genmake_cy_md
239     grep true ./genmake_cy_md > /dev/null 2>&1
240     RETVAL=$?
241     rm -f ./genmake_cy_md
242     if test "x$RETVAL" = x0 ; then
243     MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
244     return 0
245     else
246     echo "WARNING: unable to build cyrus-imapd-makedepend"
247     return 1
248     fi
249     }
250    
251 edhill 1.84 # Guess possible config options for this host
252     find_possible_configs() {
253    
254     tmp1=`uname`"_"`uname -m`
255     tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
256     tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
257     tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
258     tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
259     tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
260     PLATFORM=$tmp3
261     echo $PLATFORM | grep cygwin > /dev/null 2>&1 && PLATFORM=cygwin_ia32
262     OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
263     echo " The platform appears to be: $PLATFORM"
264    
265     echo "test" > test
266     ln -s ./test link
267     RETVAL=$?
268     if test "x${RETVAL}" = x0 ; then
269     LN="ln -s"
270     else
271     echo "Error: \"ln -s\" does not appear to work on this system!"
272     echo " For help, please contact <MITgcm-support@mitgcm.org>."
273     exit 1
274     fi
275     rm -f test link
276    
277     if test "x$CPP" = x ; then
278     CPP="cpp -traditional -P"
279     fi
280    
281     look_for_makedepend
282 edhill 1.1
283 edhill 1.91 #================================================================
284     # look for possible C compilers
285     tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc"
286     p_CC=
287     for c in $tmp ; do
288     rm -f ./genmake_hello.c ./genmake_hello
289     cat >> genmake_hello.c << EOF
290     #include <stdio.h>
291     int main(int argc, char **argv) {
292     printf("Hello!\n");
293     return 0;
294     }
295     EOF
296     $c -o genmake_hello genmake_hello.c > /dev/null 2>&1
297     RETVAL=$?
298     if test "x${RETVAL}" = x0 ; then
299     p_CC="$p_CC $c"
300     fi
301     done
302     rm -f ./genmake_hello.c ./genmake_hello
303     if test "x${p_CC}" = x ; then
304     cat 1>&2 <<EOF
305    
306     Error: No C compilers were found in your path. Please specify one using:
307    
308     1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
309     2) the CC or MITGCM_CC environment variables.
310    
311     EOF
312     exit 1
313     else
314     echo " The possible C compilers found in your path are:"
315     echo " "$p_CC
316     if test "x$CC" = x ; then
317     CC=`echo $p_CC | $AWK '{print $1}'`
318     echo " Setting C compiler to: "$CC
319     fi
320     fi
321    
322     #================================================================
323     # look for possible FORTRAN compilers
324 edhill 1.123 tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 gfortran"
325 edhill 1.1 p_FC=
326 edhill 1.11 for c in $tmp ; do
327     rm -f ./hello.f ./hello
328     cat >> hello.f <<EOF
329     program hello
330     do i=1,3
331     print *, 'hello world : ', i
332     enddo
333     end
334     EOF
335     $c -o hello hello.f > /dev/null 2>&1
336 edhill 1.1 RETVAL=$?
337     if test "x${RETVAL}" = x0 ; then
338     p_FC="$p_FC $c"
339     fi
340     done
341 edhill 1.21 rm -f ./hello.f ./hello
342 edhill 1.1 if test "x${p_FC}" = x ; then
343 edhill 1.11 cat 1>&2 <<EOF
344    
345     Error: No Fortran compilers were found in your path. Please specify one using:
346    
347     1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
348     2) a command-line option (eg. "-fc NAME"), or
349 edhill 1.91 3) the FC or MITGCM_FC environment variables.
350 edhill 1.11
351     EOF
352     exit 1
353 edhill 1.1 else
354 edhill 1.11 echo " The possible FORTRAN compilers found in your path are:"
355     echo " "$p_FC
356     if test "x$FC" = x ; then
357 edhill 1.15 FC=`echo $p_FC | $AWK '{print $1}'`
358 adcroft 1.67 echo " Setting FORTRAN compiler to: "$FC
359 edhill 1.11 fi
360 edhill 1.1 fi
361    
362 adcroft 1.67 if test "x$OPTFILE" = x ; then
363     OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
364     if test ! -r $OPTFILE ; then
365     echo " I looked for the file "$OPTFILE" but did not find it"
366     fi
367     fi
368     # echo " The options file: $p_OF"
369     # echo " appears to match so we'll use it."
370     # for i in $p_FC ; do
371     #p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
372     #if test -r $p_OF ; then
373     # OPTFILE=$p_OF
374     # echo " The options file: $p_OF"
375     # echo " appears to match so we'll use it."
376     # break
377     #fi
378     # done
379 edhill 1.11 if test "x$OPTFILE" = x ; then
380     cat 1>&2 <<EOF
381    
382     Error: No options file was found in: $ROOTDIR/tools/build_options/
383     that matches this platform ("$PLATFORM") and the compilers found in
384     your path. Please specify an "optfile" using:
385    
386     1) the command line (eg. "-optfile=path/to/OPTFILE"), or
387     2) the MITGCM_OF environment variable.
388    
389     If you need help, please contact the developers at <MITgcm-support@mitgcm.org>.
390    
391 edhill 1.1 EOF
392 edhill 1.11 exit 1
393 edhill 1.1 fi
394 edhill 1.11
395     # # look for possible MPI libraries
396     # mpi_libs=
397     # mpi_fort=`which mpif77 2>/dev/null`
398     # RETVAL=$?
399     # if test "x${RETVAL}" = x0 ; then
400     # cat >>test.f <<EOF
401     # PROGRAM HELLO
402     # DO 10, I=1,10
403     # PRINT *,'Hello World'
404     # 10 CONTINUE
405     # STOP
406     # END
407     # EOF
408     # eval "$mpi_fort -showme test.f > out"
409     # RETVAL=$?
410     # if test "x${RETVAL}" = x0 ; then
411     # a=`cat out`
412     # for i in $a ; do
413     # case $i in
414     # -*)
415     # mpi_libs="$mpi_libs $i" ;;
416     # esac
417     # done
418     # echo "The MPI libs appear to be:"
419     # echo " "$mpi_libs
420     # fi
421     # rm -f test.f out
422     # fi
423 edhill 1.1
424     }
425    
426     # Parse the package dependency information
427     get_pdepend_list() {
428    
429     # strip the comments and then convert the dependency file into
430     # two arrays: PNAME, DNAME
431     cat $1 | sed -e 's/#.*$//g' \
432 edhill 1.15 | $AWK 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \
433 edhill 1.1 > ./.pd_tmp
434 edhill 1.34 . ./.pd_tmp
435 edhill 1.1 rm -f ./.pd_tmp
436    
437 edhill 1.71 printf "PNAME = "${}
438 edhill 1.1 }
439    
440    
441     # Explain usage
442     usage() {
443 edhill 1.41 cat <<EOF
444    
445     Usage: "$0" [OPTIONS]
446     where [OPTIONS] can be:
447    
448     -help | --help | -h | --h
449     Print this help message and exit.
450 edhill 1.79
451     -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME
452     -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME
453     Use "NAME" as the adoptfile. By default, the file at
454     "tools/adjoint_options/adjoint_default" will be used.
455 edhill 1.41
456     -nooptfile | --nooptfile
457     -optfile NAME | --optfile NAME | -of NAME | --of NAME
458     -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
459     Use "NAME" as the optfile. By default, an attempt will be
460     made to find an appropriate "standard" optfile in the
461     tools/build_options/ directory.
462    
463     -pdepend NAME | --pdepend NAME
464     -pdepend=NAME | --pdepend=NAME
465     Get package dependency information from "NAME".
466    
467     -pdefault NAME | --pdefault NAME
468     -pdefault=NAME | --pdefault=NAME
469     Get the default package list from "NAME".
470    
471     -make NAME | -m NAME
472     --make=NAME | -m=NAME
473     Use "NAME" for the MAKE program. The default is "make" but
474     many platforms, "gmake" is the preferred choice.
475    
476     -makefile NAME | -mf NAME
477     --makefile=NAME | -mf=NAME
478     Call the makefile "NAME". The default is "Makefile".
479    
480 edhill 1.69 -makedepend NAME | -md NAME
481     --makedepend=NAME | -md=NAME
482     Use "NAME" for the MAKEDEPEND program.
483    
484 edhill 1.41 -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
485     -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
486     Specify the location of the MITgcm ROOTDIR as "NAME".
487     By default, genamke will try to find the location by
488     looking in parent directories (up to the 5th parent).
489    
490     -mods NAME | --mods NAME | -mo NAME | --mo NAME
491     -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
492     Here, "NAME" specifies a list of directories that are
493     used for additional source code. Files found in the
494     "mods list" are given preference over files of the same
495     name found elsewhere.
496    
497     -disable NAME | --disable NAME
498     -disable=NAME | --disable=NAME
499     Here "NAME" specifies a list of packages that we don't
500     want to use. If this violates package dependencies,
501     genamke will exit with an error message.
502    
503     -enable NAME | --enable NAME
504     -enable=NAME | --enable=NAME
505     Here "NAME" specifies a list of packages that we wish
506     to specifically enable. If this violates package
507     dependencies, genamke will exit with an error message.
508    
509     -standarddirs NAME | --standarddirs NAME
510     -standarddirs=NAME | --standarddirs=NAME
511     Here, "NAME" specifies a list of directories to be
512     used as the "standard" code.
513    
514     -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
515     -fc=NAME | --fc=NAME
516     Use "NAME" as the fortran compiler. By default, genmake
517     will search for a working compiler by trying a list of
518     "usual suspects" such as g77, f77, etc.
519    
520 edhill 1.91 -cc NAME | --cc NAME | -cc=NAME | --cc=NAME
521     Use "NAME" as the C compiler. By default, genmake
522     will search for a working compiler by trying a list of
523     "usual suspects" such as gcc, c89, cc, etc.
524    
525 edhill 1.41 -[no]ieee | --[no]ieee
526     Do or don't use IEEE numerics. Note that this option
527     *only* works if it is supported by the OPTFILE that
528     is being used.
529    
530 ce107 1.126 -ts | --ts
531     Produce timing information per timestep
532    
533 adcroft 1.67 -mpi | --mpi
534     Include MPI header files and link to MPI libraries
535     -mpi=PATH | --mpi=PATH
536     Include MPI header files and link to MPI libraries using MPI_ROOT
537 edhill 1.95 set to PATH. i.e. Include files from \$PATH/include, link to libraries
538     from \$PATH/lib and use binaries from \$PATH/bin.
539 adcroft 1.67
540 edhill 1.71 -bash NAME
541     Explicitly specify the Bourne or BASH shell to use
542    
543 edhill 1.41 While it is most often a single word, the "NAME" variables specified
544     above can in many cases be a space-delimited string such as:
545    
546     --enable pkg1 --enable 'pkg1 pkg2' --enable 'pkg1 pkg2 pkg3'
547     -mods=dir1 -mods='dir1' -mods='dir1 dir2 dir3'
548     -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
549    
550     which, depending upon your shell, may need to be single-quoted.
551    
552     For more detailed genmake documentation, please see:
553    
554     http://mitgcm.org/devel_HOWTO/
555    
556     EOF
557    
558 edhill 1.1 exit 1
559     }
560    
561 edhill 1.31 # Build a CPP macro to automate calling C routines from FORTRAN
562     get_fortran_c_namemangling() {
563 edhill 1.89
564     #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
565     if test ! "x$FC_NAMEMANGLE" = x ; then
566     return 0
567     fi
568    
569 edhill 1.31 default_nm="#define FC_NAMEMANGLE(X) X ## _"
570    
571     cat > genmake_test.c <<EOF
572     void tcall( char * string ) { tsub( string ); }
573     EOF
574 edhill 1.39 $MAKE genmake_test.o >> genmake_warnings 2>&1
575 edhill 1.31 RETVAL=$?
576     if test "x$RETVAL" != x0 ; then
577     FC_NAMEMANGLE=$default_nm
578 edhill 1.39 cat <<EOF>> genmake_errors
579    
580     WARNING: C test compile fails
581     WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
582     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
583     EOF
584 edhill 1.31 return 1
585     fi
586 edhill 1.91 c_tcall=`nm genmake_test.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
587 edhill 1.31 RETVAL=$?
588     if test "x$RETVAL" != x0 ; then
589     FC_NAMEMANGLE=$default_nm
590 edhill 1.39 cat <<EOF>> genmake_warnings
591    
592     WARNING: The "nm" command failed.
593     WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
594     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
595     EOF
596 edhill 1.31 return 1
597     fi
598 edhill 1.118 cat > genmake_tcomp.$FS <<EOF
599 edhill 1.31 subroutine tcall( string )
600     character*(*) string
601     call tsub( string )
602     end
603     EOF
604 edhill 1.134 $FC $FFLAGS -c genmake_tcomp.$FS >> genmake_warnings 2>&1
605 edhill 1.31 RETVAL=$?
606     if test "x$RETVAL" != x0 ; then
607     FC_NAMEMANGLE=$default_nm
608 edhill 1.39 cat <<EOF>> genmake_warnings
609    
610     WARNING: FORTRAN test compile fails -- please see "genmake_errors"
611     WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
612     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
613     EOF
614 edhill 1.31 return 1
615     fi
616 edhill 1.91 f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
617 edhill 1.31 RETVAL=$?
618     if test "x$RETVAL" != x0 ; then
619     FC_NAMEMANGLE=$default_nm
620 edhill 1.39 cat <<EOF>> genmake_warnings
621    
622     WARNING: The "nm" command failed.
623     WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
624     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
625     EOF
626 edhill 1.31 return 1
627     fi
628    
629     c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
630     f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
631     c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
632     f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
633    
634     nmangle="X"
635     if test "x$c_a" != "x$f_a" ; then
636     comm="echo x$f_a | sed -e 's|x$c_a||'"
637     a=`eval $comm`
638     nmangle="$a ## $nmangle"
639     fi
640     if test "x$c_b" != "x$f_b" ; then
641     comm="echo x$f_b | sed -e 's|x$c_b||'"
642     b=`eval $comm`
643     nmangle="$nmangle ## $b"
644     fi
645    
646     FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) $nmangle"
647 edhill 1.32
648     # cleanup the testing files
649     rm -f genmake_tcomp.* genmake_test.*
650 edhill 1.31 }
651 edhill 1.1
652 edhill 1.39
653     check_HAVE_CLOC() {
654     get_fortran_c_namemangling
655     cat <<EOF > genmake_tc_1.c
656     $FC_NAMEMANGLE
657     #include <stdio.h>
658     #include <stdlib.h>
659     #include <unistd.h>
660     #include <assert.h>
661     #include <sys/time.h>
662     void FC_NAMEMANGLE(cloc) ( double *curtim )
663     {
664     struct timeval tv1;
665     gettimeofday(&tv1 , (void *)NULL );
666     *curtim = (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
667     *curtim = *curtim/1.E6;
668     }
669     EOF
670 edhill 1.118 make genmake_tc_1.o >> genmake_warnings 2>&1
671 edhill 1.39 RET_C=$?
672 edhill 1.118 cat <<EOF > genmake_tc_2.$FS
673 edhill 1.39 program hello
674 edhill 1.129 REAL*8 wtime
675 edhill 1.39 external cloc
676     call cloc(wtime)
677     print *," HELLO WORLD", wtime
678 edhill 1.128 end
679 edhill 1.39 EOF
680 edhill 1.118 $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_warnings 2>&1
681 edhill 1.39 RET_F=$?
682 edhill 1.118 test -x ./genmake_tc && ./genmake_tc >> genmake_warnings 2>&1
683 edhill 1.39 RETVAL=$?
684     if test "x$RETVAL" = x0 ; then
685     HAVE_CLOC=t
686     DEFINES="$DEFINES -DHAVE_CLOC"
687     fi
688     rm -f genmake_tc*
689     }
690    
691    
692 edhill 1.130 check_HAVE_SETRLSTK() {
693     get_fortran_c_namemangling
694     cat <<EOF > genmake_tc_1.c
695     $FC_NAMEMANGLE
696     #include <sys/time.h>
697     #include <sys/resource.h>
698     #include <unistd.h>
699     void FC_NAMEMANGLE(setrlstk) ()
700     {
701     struct rlimit rls;
702     rls.rlim_cur = RLIM_INFINITY;
703     rls.rlim_max = RLIM_INFINITY;
704     setrlimit(RLIMIT_STACK, &rls);
705     return;
706     }
707     EOF
708     make genmake_tc_1.o >> genmake_warnings 2>&1
709     RET_C=$?
710     cat <<EOF > genmake_tc_2.$FS
711     program hello
712     external setrlstk
713     call setrlstk()
714     end
715     EOF
716     $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_warnings 2>&1
717     RET_F=$?
718     test -x ./genmake_tc && ./genmake_tc >> genmake_warnings 2>&1
719     RETVAL=$?
720     if test "x$RETVAL" = x0 ; then
721     HAVE_SETRLSTK=t
722     DEFINES="$DEFINES -DHAVE_SETRLSTK"
723     fi
724     rm -f genmake_tc*
725     }
726    
727    
728 edhill 1.108 check_HAVE_STAT() {
729     get_fortran_c_namemangling
730     cat <<EOF > genmake_tc_1.c
731     $FC_NAMEMANGLE
732     #include <stdio.h>
733     #include <stdlib.h>
734     #include <unistd.h>
735     #include <sys/stat.h>
736     #include <sys/types.h>
737     void FC_NAMEMANGLE(tfsize) ( int *nbyte )
738     {
739     char name[512];
740     struct stat astat;
741    
742     name[0] = 'a'; name[1] = '\0';
743     if (! stat(name, &astat))
744     *nbyte = (int)(astat.st_size);
745     else
746     *nbyte = -1;
747     }
748     EOF
749     make genmake_tc_1.o >> genmake_tc.log 2>&1
750     RET_C=$?
751 edhill 1.118 cat <<EOF > genmake_tc_2.$FS
752 edhill 1.108 program hello
753     integer nbyte
754     call tfsize(nbyte)
755     print *," HELLO WORLD", nbyte
756 edhill 1.128 end
757 edhill 1.108 EOF
758 edhill 1.118 $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_tc.log 2>&1
759 edhill 1.108 RET_F=$?
760     test -x ./genmake_tc && ./genmake_tc >> genmake_tc.log 2>&1
761     RETVAL=$?
762     if test "x$RETVAL" = x0 ; then
763     HAVE_STAT=t
764     DEFINES="$DEFINES -DHAVE_STAT"
765     fi
766     rm -f genmake_tc*
767     }
768    
769    
770 edhill 1.60 check_netcdf_libs() {
771 edhill 1.113 if test ! "x$SKIP_NETCDF_CHECK" = x ; then
772     return
773     fi
774 edhill 1.91 echo "" > genmake_tnc.log
775 edhill 1.117 cat <<EOF > genmake_tnc.F
776 edhill 1.60 program fgennc
777     #include "netcdf.inc"
778 edhill 1.113 EOF
779     if test ! "x$MPI" = x ; then
780 edhill 1.117 echo '#include "mpif.h"' >> genmake_tnc.F
781 edhill 1.113 fi
782 edhill 1.117 cat <<EOF >> genmake_tnc.F
783 edhill 1.60 integer iret, ncid, xid
784     iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
785     IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
786     iret = nf_def_dim(ncid, 'X', 11, xid)
787     IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
788     iret = nf_close(ncid)
789     IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
790     end
791     EOF
792 edhill 1.111 echo "Executing:" > genmake_tnc.log
793 edhill 1.117 echo " $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS" \
794 edhill 1.133 >> genmake_tnc.log
795 edhill 1.111 RET_CPP=f
796 edhill 1.117 $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null \
797 edhill 1.111 && RET_CPP=t
798     if test "x$RET_CPP" = xf ; then
799     echo " WARNING: CPP failed to pre-process the netcdf test." \
800 edhill 1.133 >> genmake_tnc.log
801 edhill 1.111 echo " Please check that \$INCLUDES is properly set." \
802 edhill 1.133 >> genmake_tnc.log
803 edhill 1.111 fi
804     echo "Executing:" > genmake_tnc.log
805 edhill 1.133 echo " $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS" >> genmake_tnc.log
806     echo " $LINK -o genmake_tnc.o $LIBS" >> genmake_tnc.log
807 edhill 1.117 $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \
808 edhill 1.96 && $LINK -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
809 edhill 1.60 RET_COMPILE=$?
810 edhill 1.99
811     #EH3 Remove test program execution for machines that either disallow
812     #EH3 execution or cannot support it (eg. cross-compilers)
813     #EH3
814     #EH3 test -x ./genmake_tnc && ./genmake_tnc >> genmake_tnc.log 2>&1
815     #EH3 RETVAL=$?
816     #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
817    
818     if test "x$RET_COMPILE" = x0 ; then
819 edhill 1.60 HAVE_NETCDF=t
820     else
821 edhill 1.66 # try again with "-lnetcdf" added to the libs
822 edhill 1.133 echo "$CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS \ " >> genmake_tnc.log
823     echo " && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
824     echo " && $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
825 edhill 1.117 $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null \
826     && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \
827 edhill 1.99 && $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
828 edhill 1.66 RET_COMPILE=$?
829 edhill 1.99 if test "x$RET_COMPILE" = x0 ; then
830 edhill 1.66 LIBS="$LIBS -lnetcdf"
831     HAVE_NETCDF=t
832     else
833 edhill 1.133 echo "=== genmake_tnc.F ===" >> genmake_warnings
834     cat genmake_tnc.F >> genmake_warnings
835     echo "=== genmake_tnc.F ===" >> genmake_warnings
836 edhill 1.66 cat genmake_tnc.log >> genmake_warnings
837     fi
838 edhill 1.60 fi
839     rm -f genmake_tnc*
840     }
841    
842    
843 adcroft 1.67
844     ###############################################################################
845     # Sequential part of script starts here
846     ###############################################################################
847    
848 edhill 1.1 # Set defaults here
849 edhill 1.5 COMMANDL="$0 $@"
850    
851 edhill 1.1 PLATFORM=
852     LN=
853     S64=
854     KPP=
855 edhill 1.114 #FC=
856 edhill 1.93 #CC=gcc
857 edhill 1.114 #CPP=
858 edhill 1.1 LINK=
859 edhill 1.31 DEFINES=
860 edhill 1.1 PACKAGES=
861     ENABLE=
862     DISABLE=
863 edhill 1.119 # MAKEFILE=
864     # MAKEDEPEND=
865 edhill 1.1 PDEPEND=
866 edhill 1.11 DUMPSTATE=t
867 edhill 1.1 PDEFAULT=
868     OPTFILE=
869 edhill 1.111 INCLUDES="-I. $INCLUDES"
870 edhill 1.1 FFLAGS=
871     FOPTIM=
872     CFLAGS=
873     KFLAGS1=
874     KFLAGS2=
875 edhill 1.70 #LDADD=
876 edhill 1.1 LIBS=
877     KPPFILES=
878     NOOPTFILES=
879     NOOPTFLAGS=
880 adcroft 1.67 MPI=
881     MPIPATH=
882 ce107 1.126 TS=
883 edhill 1.131 HAVE_TEST_L=
884 edhill 1.1
885 edhill 1.124 # DEFINES checked by test compilation or command-line
886 edhill 1.29 HAVE_SYSTEM=
887     HAVE_FDATE=
888     FC_NAMEMANGLE=
889 edhill 1.39 HAVE_CLOC=
890 edhill 1.130 HAVE_SETRLSTK=
891 edhill 1.108 HAVE_STAT=
892 edhill 1.60 HAVE_NETCDF=
893 cnh 1.81 HAVE_ETIME=
894 edhill 1.124 IGNORE_TIME=
895 edhill 1.29
896 edhill 1.1 MODS=
897     TOOLSDIR=
898     SOURCEDIRS=
899     INCLUDEDIRS=
900 edhill 1.57 STANDARDDIRS="USE_THE_DEFAULT"
901 edhill 1.1
902 edhill 1.73 G2ARGS=
903 edhill 1.71 BASH=
904 edhill 1.1 PWD=`pwd`
905 edhill 1.114 test "x$MAKE" = x && MAKE=make
906     test "x$AWK" = x && AWK=awk
907 edhill 1.97 THISHOST=`hostname`
908 edhill 1.1 THISCWD=`pwd`
909     THISDATE=`date`
910 edhill 1.97 THISUSER=`echo $USER`
911     THISVER=
912 edhill 1.1 MACHINE=`uname -a`
913 edhill 1.7 EXECUTABLE=
914     EXEHOOK=
915     EXEDIR=
916 edhill 1.12 PACKAGES_CONF=
917     IEEE=
918     if test "x$MITGCM_IEEE" != x ; then
919     IEEE=$MITGCM_IEEE
920     fi
921 edhill 1.76 FS=
922     FS90=
923 edhill 1.1
924 edhill 1.14 AUTODIFF_PKG_USED=f
925     AD_OPTFILE=
926 edhill 1.17 TAF=
927     AD_TAF_FLAGS=
928     FTL_TAF_FLAGS=
929     SVD_TAF_FLAGS=
930     TAF_EXTRA=
931     TAMC=
932     AD_TAMC_FLAGS=
933     FTL_TAF_FLAGS=
934     SVD_TAMC_FLAGS=
935     TAMC_EXTRA=
936    
937 edhill 1.14
938 edhill 1.5 # The following state can be set directly by command-line switches
939 edhill 1.41 gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"
940 ce107 1.126 gm_s2="FC CPP IEEE TS MPI JAM DUMPSTATE STANDARDDIRS"
941 edhill 1.5
942     # The following state is not directly set by command-line switches
943     gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
944     gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
945 edhill 1.97 gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE"
946 edhill 1.12 gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
947 cnh 1.81 gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME"
948 edhill 1.5
949 edhill 1.14 # The following are all related to adjoint/tangent-linear stuff
950 edhill 1.29 gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
951     gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
952     gm_s12="TAF_EXTRA TAMC_EXTRA"
953 edhill 1.14
954 edhill 1.29 gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"
955     gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
956 edhill 1.5
957 edhill 1.41 cat <<EOF
958    
959     GENMAKE :
960    
961     A program for GENerating MAKEfiles for the MITgcm project. For a
962     quick list of options, use "genmake -h" or for more detail see:
963    
964     http://mitgcm.org/devel_HOWTO/
965    
966     EOF
967 edhill 1.5
968 edhill 1.2 echo "=== Processing options files and arguments ==="
969 edhill 1.12 gm_local="genmake_local"
970     for i in . $MODS ; do
971     if test -r $i/$gm_local ; then
972 edhill 1.34 . $i/$gm_local
973 edhill 1.12 break
974     fi
975     done
976 edhill 1.71 printf " getting local config information: "
977 edhill 1.88 if test -f $gm_local ; then
978 edhill 1.1 echo "using $gm_local"
979 edhill 1.34 . $gm_local
980 edhill 1.2 # echo "DISABLE=$DISABLE"
981     # echo "ENABLE=$ENABLE"
982 edhill 1.1 else
983     echo "none found"
984     fi
985    
986 edhill 1.103 #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
987 edhill 1.2 #OPTIONS=
988     #n=0
989     #for i ; do
990     # echo "$i $n"
991     # setvar="OPTIONS[$n]='$i'"
992     # # echo " $setvar"
993     # eval "$setvar"
994     # n=$(( $n + 1 ))
995     #done
996     #parse_options
997     ac_prev=
998 edhill 1.102 for ac_option in "$@" ; do
999 edhill 1.2
1000 edhill 1.73 G2ARGS="$G2ARGS \"$ac_option\""
1001    
1002 edhill 1.2 # If the previous option needs an argument, assign it.
1003     if test -n "$ac_prev"; then
1004     eval "$ac_prev=\$ac_option"
1005     ac_prev=
1006     continue
1007     fi
1008    
1009     ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
1010    
1011     case $ac_option in
1012    
1013     -help | --help | -h | --h)
1014     usage ;;
1015    
1016     -nooptfile | --nooptfile)
1017     OPTFILE="NONE" ;;
1018     -optfile | --optfile | -of | --of)
1019 edhill 1.4 ac_prev=OPTFILE ;;
1020 edhill 1.2 -optfile=* | --optfile=* | -of=* | --of=*)
1021     OPTFILE=$ac_optarg ;;
1022    
1023 edhill 1.50 -adoptfile | --adoptfile | -adof | --adof)
1024 edhill 1.14 ac_prev=AD_OPTFILE ;;
1025     -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
1026     AD_OPTFILE=$ac_optarg ;;
1027    
1028 edhill 1.2 -pdepend | --pdepend)
1029 edhill 1.4 ac_prev=PDEPEND ;;
1030 edhill 1.2 -pdepend=* | --pdepend=*)
1031     PDEPEND=$ac_optarg ;;
1032    
1033     -pdefault | --pdefault)
1034 edhill 1.4 ac_prev=PDEFAULT ;;
1035 edhill 1.2 -pdefault=* | --pdefault=*)
1036     PDEFAULT=$ac_optarg ;;
1037    
1038 edhill 1.6 -make | --make | -m | --m)
1039     ac_prev=MAKE ;;
1040     -make=* | --make=* | -m=* | --m=*)
1041     MAKE=$ac_optarg ;;
1042 edhill 1.69
1043 edhill 1.71 -bash | --bash)
1044     ac_prev=BASH ;;
1045     -bash=* | --bash=*)
1046     BASH=$ac_optarg ;;
1047    
1048 edhill 1.69 -makedepend | --makedepend | -md | --md)
1049     ac_prev=MAKEDEPEND ;;
1050     -makedepend=* | --makedepend=* | -md=* | --md=*)
1051     MAKEDEPEND=$ac_optarg ;;
1052 edhill 1.6
1053     -makefile | --makefile | -ma | --ma)
1054 edhill 1.4 ac_prev=MAKEFILE ;;
1055 edhill 1.6 -makefile=* | --makefile=* | -ma=* | --ma=*)
1056 edhill 1.2 MAKEFILE=$ac_optarg ;;
1057    
1058 edhill 1.41 -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
1059     echo "ERROR: The platform option has been removed. Please specify"
1060     echo " the build options using the \"optfile\" mechanism."
1061     echo
1062     usage
1063     ;;
1064 edhill 1.2
1065     -rootdir | --rootdir | -rd | --rd)
1066 edhill 1.4 ac_prev=ROOTDIR ;;
1067 edhill 1.2 -rootdir=* | --rootdir=* | -rd=* | --rd=*)
1068     ROOTDIR=$ac_optarg ;;
1069    
1070     -mods | --mods | -mo | --mo)
1071 edhill 1.4 ac_prev=MODS ;;
1072 edhill 1.2 -mods=* | --mods=* | -mo=* | --mo=*)
1073     MODS=$ac_optarg ;;
1074    
1075     -disable | --disable)
1076 edhill 1.4 ac_prev=DISABLE ;;
1077 edhill 1.2 -disable=* | --disable=*)
1078     DISABLE=$ac_optarg ;;
1079    
1080     -enable | --enable)
1081 edhill 1.4 ac_prev=ENABLE ;;
1082 edhill 1.2 -enable=* | --enable=*)
1083     ENABLE=$ac_optarg ;;
1084    
1085 edhill 1.12 -standarddirs | --standarddirs)
1086     ac_prev=STANDARDDIRS ;;
1087     -standarddirs=* | --standarddirs=*)
1088     STANDARDDIRS=$ac_optarg ;;
1089    
1090 edhill 1.2 # -cpp | --cpp)
1091     # ac_prev=cpp ;;
1092     # -cpp=* | --cpp=*)
1093     # CPP=$ac_optarg ;;
1094 edhill 1.91
1095     -cc | --cc)
1096     ac_prev=CC ;;
1097     -cc=* | --cc=*)
1098     CC=$ac_optarg ;;
1099    
1100 edhill 1.2 -fortran | --fortran | -fc | --fc)
1101 edhill 1.4 ac_prev=FC ;;
1102 edhill 1.2 -fc=* | --fc=*)
1103     FC=$ac_optarg ;;
1104    
1105 edhill 1.76 -fs | --fs)
1106     ac_prev=FS ;;
1107     -fs=* | --fs=*)
1108     FS=$ac_optarg ;;
1109    
1110     -fs90 | --fs90)
1111     ac_prev=FS90 ;;
1112     -fs90=* | --fs90=*)
1113     FS90=$ac_optarg ;;
1114    
1115 edhill 1.2 -ieee | --ieee)
1116 edhill 1.12 IEEE=true ;;
1117 edhill 1.2 -noieee | --noieee)
1118 edhill 1.12 IEEE= ;;
1119 adcroft 1.67
1120 ce107 1.126 -ts | --ts)
1121     TS=true ;;
1122    
1123 adcroft 1.67 -mpi | --mpi)
1124     MPI=true ;;
1125     -mpi=* | --mpi=*)
1126     MPIPATH=$ac_optarg
1127     MPI=true ;;
1128 edhill 1.2
1129 edhill 1.41 # -jam | --jam)
1130     # JAM=1 ;;
1131     # -nojam | --nojam)
1132     # JAM=0 ;;
1133 edhill 1.2
1134 edhill 1.5 -ds | --ds)
1135     DUMPSTATE=t ;;
1136    
1137 edhill 1.17 -taf_extra | --taf_extra)
1138     ac_prev=TAF_EXTRA ;;
1139     -taf_extra=* | --taf_extra=*)
1140     TAF_EXTRA=$ac_optarg ;;
1141    
1142     -tamc_extra | --tamc_extra)
1143     ac_prev=TAMC_EXTRA ;;
1144     -tamc_extra=* | --tamc_extra=*)
1145     TAMC_EXTRA=$ac_optarg ;;
1146 edhill 1.124
1147     -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1148     IGNORE_TIME="-DIGNORE_TIME" ;;
1149 edhill 1.17
1150 edhill 1.2 -*)
1151     echo "Error: unrecognized option: "$ac_option
1152     usage
1153     ;;
1154    
1155     *)
1156     echo "Error: unrecognized argument: "$ac_option
1157     usage
1158     ;;
1159    
1160     esac
1161    
1162 edhill 1.1 done
1163    
1164 edhill 1.119
1165 edhill 1.12 if test -f ./.genmakerc ; then
1166     echo
1167     echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
1168     echo " file. This file format is no longer supported. Please see:"
1169     echo
1170     echo " http://mitgcm.org/devel_HOWTO/"
1171     echo
1172     echo " for directions on how to setup and use the new \"genmake2\" input"
1173     echo " files and send an email to MITgcm-support@mitgcm.org if you want help."
1174     echo
1175     fi
1176    
1177 edhill 1.97 # Find the MITgcm ${ROOTDIR}
1178 edhill 1.11 if test "x${ROOTDIR}" = x ; then
1179 edhill 1.112 tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1180 edhill 1.87 if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
1181 edhill 1.11 ROOTDIR=".."
1182     else
1183     for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1184     if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
1185     ROOTDIR=$d
1186 edhill 1.71 printf "Warning: ROOTDIR was not specified but there appears to be"
1187 edhill 1.11 echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
1188     break
1189     fi
1190     done
1191     fi
1192     fi
1193     if test "x${ROOTDIR}" = x ; then
1194     echo "Error: Cannot determine ROOTDIR for MITgcm code."
1195     echo " Please specify a ROOTDIR using either an options "
1196     echo " file or a command-line option."
1197     exit 1
1198     fi
1199     if test ! -d ${ROOTDIR} ; then
1200     echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
1201     exit 1
1202     fi
1203    
1204 edhill 1.97 # Find the MITgcm ${THISVER}
1205     if test -f "${ROOTDIR}/doc/tag-index" ; then
1206 edhill 1.125 THISVER=`grep '^checkpoint' ${ROOTDIR}/doc/tag-index | head -1`
1207 edhill 1.97 fi
1208    
1209 edhill 1.119 if test "x$MAKEFILE" = x ; then
1210     MAKEFILE="Makefile"
1211     fi
1212    
1213 edhill 1.1 echo " getting OPTFILE information: "
1214     if test "x${OPTFILE}" = x ; then
1215 edhill 1.11 if test "x$MITGCM_OF" = x ; then
1216     echo "Warning: no OPTFILE specified so we'll look for possible settings"
1217     printf "\n=== Searching for possible settings for OPTFILE ===\n"
1218     find_possible_configs
1219 edhill 1.1 else
1220 edhill 1.11 OPTFILE=$MITGCM_OF
1221     fi
1222     fi
1223     if test "x$OPTFILE" != xNONE ; then
1224     if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
1225     echo " using OPTFILE=\"$OPTFILE\""
1226 edhill 1.34 . "$OPTFILE"
1227 edhill 1.11 RETVAL=$?
1228     if test "x$RETVAL" != x0 ; then
1229 edhill 1.71 printf "Error: failed to source OPTFILE \"$OPTFILE\""
1230 edhill 1.11 echo "--please check that variable syntax is bash-compatible"
1231 edhill 1.1 exit 1
1232     fi
1233 edhill 1.11 if test "x$DUMPSTATE" != xf ; then
1234 edhill 1.12 cp -f $OPTFILE "genmake_optfile"
1235 edhill 1.11 fi
1236     else
1237     echo "Error: can't read OPTFILE=\"$OPTFILE\""
1238     exit 1
1239 edhill 1.1 fi
1240     fi
1241 edhill 1.8
1242 edhill 1.14 echo " getting AD_OPTFILE information: "
1243     if test "x${AD_OPTFILE}" = x ; then
1244     if test "x$MITGCM_AD_OF" = x ; then
1245     AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
1246     else
1247     AD_OPTFILE=$MITGCM_AD_OF
1248     fi
1249     fi
1250     if test "x${AD_OPTFILE}" != xNONE ; then
1251     if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
1252     echo " using AD_OPTFILE=\"$AD_OPTFILE\""
1253 edhill 1.34 . "$AD_OPTFILE"
1254 edhill 1.14 RETVAL=$?
1255     if test "x$RETVAL" != x0 ; then
1256 edhill 1.71 printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
1257 edhill 1.14 echo "--please check that variable syntax is bash-compatible"
1258     exit 1
1259     fi
1260     if test "x$DUMPSTATE" != xf ; then
1261     cp -f $AD_OPTFILE "genmake_ad_optfile"
1262     fi
1263     else
1264     echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
1265     exit 1
1266     fi
1267     fi
1268    
1269 edhill 1.119 #====================================================================
1270     # Set default values if not set by the optfile
1271     #
1272 edhill 1.91 # Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined. If not,
1273 edhill 1.39 # either set defaults or complain and abort!
1274 edhill 1.71 if test ! "x$BASH" = x ; then
1275     # add a trailing space so that it works within the Makefile syntax (see below)
1276     BASH="$BASH "
1277     fi
1278 edhill 1.8 if test "x$FC" = x ; then
1279     cat <<EOF 1>&2
1280    
1281     Error: no Fortran compiler: please specify using one of the following:
1282     1) within the options file ("FC=...") as specified by "-of=OPTFILE"
1283     2) the "-fc=XXX" command-line option
1284 edhill 1.12 3) the "./genmake_local" file
1285 edhill 1.8 EOF
1286     exit 1
1287     fi
1288 edhill 1.91 if test "x$CC" = x ; then
1289 edhill 1.93 CC=cc
1290     # cat <<EOF 1>&2
1291     # Error: no C compiler: please specify using one of the following:
1292     # 1) within the options file ("CC=...") as specified by "-of=OPTFILE"
1293     # 2) the "-cc=XXX" command-line option
1294     # 3) the "./genmake_local" file
1295     # EOF
1296     # exit 1
1297 edhill 1.91 fi
1298 edhill 1.8 if test "x$LINK" = x ; then
1299     LINK=$FC
1300     fi
1301 edhill 1.39 if test "x$MAKE" = x ; then
1302     MAKE="make"
1303     fi
1304 edhill 1.63 if test "x$CPP" = x ; then
1305     CPP=cpp
1306     fi
1307     #EH3 === UGLY ===
1308 edhill 1.76 # The following is an ugly little hack to check for $CPP in /lib/ and
1309     # it should eventually be replaced with a more general function that
1310 edhill 1.63 # searches a combo of the user's path and a list of "usual suspects"
1311     # to find the correct location for binaries such as $CPP.
1312     for i in " " "/lib/" ; do
1313     echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1314     done
1315     #EH3 === UGLY ===
1316 edhill 1.13 echo "#define A a" | $CPP > test_cpp 2>&1
1317 edhill 1.11 RETVAL=$?
1318     if test "x$RETVAL" != x0 ; then
1319 edhill 1.8 cat <<EOF 1>&2
1320    
1321 edhill 1.11 Error: C pre-processor "$CPP" failed the test case: please specify using:
1322    
1323 edhill 1.8 1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
1324 edhill 1.12 2) the "./genmake_local" file
1325 edhill 1.30 3) with the CPP environment variable
1326 edhill 1.11
1327 edhill 1.8 EOF
1328     exit 1
1329 edhill 1.11 else
1330     rm -f test_cpp
1331 edhill 1.8 fi
1332 edhill 1.84 look_for_makedepend
1333 edhill 1.35 if test "x$LN" = x ; then
1334     LN="ln -s"
1335     fi
1336     echo "test" > genmake_test_ln
1337     $LN genmake_test_ln genmake_tlink
1338     RETVAL=$?
1339     if test "x$RETVAL" != x0 ; then
1340     cat <<EOF 1>&2
1341 edhill 1.29
1342 edhill 1.35 Error: The command "ln -s" failed -- please specify a working soft-link
1343     command in the optfile.
1344    
1345     EOF
1346     exit 1
1347     fi
1348 edhill 1.131 test -L genmake_tlink > /dev/null 2>&1
1349     RETVAL=$?
1350     if test "x$RETVAL" = x0 ; then
1351     HAVE_TEST_L=t
1352     fi
1353 edhill 1.35 rm -f genmake_test_ln genmake_tlink
1354 edhill 1.77
1355     # Check for broken *.F/*.f handling and fix if possible
1356     check_for_broken_Ff
1357 edhill 1.29
1358 adcroft 1.67 if test ! "x$MPI" = x ; then
1359     echo " Turning on MPI cpp macros"
1360 adcroft 1.68 DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
1361 adcroft 1.67 fi
1362 edhill 1.39
1363 ce107 1.126 if test ! "x$TS" = x ; then
1364     echo " Turning on timing per timestep"
1365     DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1366     fi
1367    
1368 edhill 1.29 printf "\n=== Checking system libraries ===\n"
1369 edhill 1.71 printf " Do we have the system() command using $FC... "
1370 edhill 1.118 cat > genmake_tcomp.$FS <<EOF
1371 edhill 1.29 program hello
1372     call system('echo hi')
1373     end
1374     EOF
1375 edhill 1.134 $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1376 edhill 1.29 RETVAL=$?
1377     if test "x$RETVAL" = x0 ; then
1378     HAVE_SYSTEM=t
1379     DEFINES="$DEFINES -DHAVE_SYSTEM"
1380     echo "yes"
1381     else
1382     HAVE_SYSTEM=
1383     echo "no"
1384     fi
1385     rm -f genmake_tcomp*
1386    
1387 edhill 1.71 printf " Do we have the fdate() command using $FC... "
1388 edhill 1.118 cat > genmake_tcomp.$FS <<EOF
1389 edhill 1.29 program hello
1390 edhill 1.129 CHARACTER*(128) string
1391 edhill 1.29 string = ' '
1392     call fdate( string )
1393     print *, string
1394     end
1395     EOF
1396 edhill 1.134 $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1397 edhill 1.29 RETVAL=$?
1398     if test "x$RETVAL" = x0 ; then
1399     HAVE_FDATE=t
1400     DEFINES="$DEFINES -DHAVE_FDATE"
1401     echo "yes"
1402     else
1403     HAVE_FDATE=
1404     echo "no"
1405     fi
1406     rm -f genmake_tcomp*
1407    
1408 cnh 1.81 printf " Do we have the etime() command using $FC... "
1409 edhill 1.118 cat > genmake_tcomp.$FS <<EOF
1410 cnh 1.81 program hello
1411 cnh 1.82 REAL*4 ACTUAL, TARRAY(2)
1412     EXTERNAL ETIME
1413     REAL*4 ETIME
1414     actual = etime( tarray )
1415 cnh 1.81 print *, tarray
1416     end
1417     EOF
1418 edhill 1.134 $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1419 cnh 1.81 RETVAL=$?
1420     if test "x$RETVAL" = x0 ; then
1421     HAVE_ETIME=t
1422     DEFINES="$DEFINES -DHAVE_ETIME"
1423     echo "yes"
1424     else
1425     HAVE_ETIME=
1426     echo "no"
1427     fi
1428     rm -f genmake_tcomp*
1429    
1430 edhill 1.71 printf " Can we call simple C routines (here, \"cloc()\") using $FC... "
1431 edhill 1.39 check_HAVE_CLOC
1432     if test "x$HAVE_CLOC" != x ; then
1433     echo "yes"
1434     else
1435     echo "no"
1436 edhill 1.29 fi
1437 edhill 1.39 rm -f genmake_t*
1438 edhill 1.29
1439 edhill 1.130 printf " Can we unlimit the stack size using $FC... "
1440     check_HAVE_SETRLSTK
1441     if test "x$HAVE_SETRLSTK" != x ; then
1442     echo "yes"
1443     else
1444     echo "no"
1445     fi
1446     rm -f genmake_t*
1447    
1448 edhill 1.108 printf " Can we use stat() through C calls... "
1449     check_HAVE_STAT
1450     if test "x$HAVE_STAT" != x ; then
1451     echo "yes"
1452     else
1453     echo "no"
1454     fi
1455     rm -f genmake_t*
1456    
1457 edhill 1.71 printf " Can we create NetCDF-enabled binaries... "
1458 edhill 1.60 check_netcdf_libs
1459     if test "x$HAVE_NETCDF" != x ; then
1460     echo "yes"
1461     else
1462     echo "no"
1463     fi
1464 edhill 1.124 DEFINES="$DEFINES $IGNORE_TIME"
1465 edhill 1.8
1466 edhill 1.2 printf "\n=== Setting defaults ===\n"
1467 edhill 1.71 printf " Adding MODS directories: "
1468 edhill 1.1 for d in $MODS ; do
1469     if test ! -d $d ; then
1470 edhill 1.2 echo
1471     echo "Error: MODS directory \"$d\" not found!"
1472 edhill 1.1 exit 1
1473     else
1474 edhill 1.71 printf " $d"
1475 edhill 1.1 SOURCEDIRS="$SOURCEDIRS $d"
1476     INCLUDEDIRS="$INCLUDEDIRS $d"
1477     fi
1478     done
1479     echo
1480    
1481     if test "x${PLATFORM}" = x ; then
1482     PLATFORM=$p_PLATFORM
1483     fi
1484    
1485     if test "x${EXEDIR}" = x ; then
1486 edhill 1.112 tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1487 edhill 1.87 if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
1488 edhill 1.1 EXEDIR=../exe
1489     else
1490     EXEDIR=.
1491     fi
1492     fi
1493     if test ! -d ${EXEDIR} ; then
1494     echo "Error: the specified EXEDIR (\"$EXEDIR\") does not exist!"
1495     exit 1
1496     fi
1497    
1498     if test "x${TOOLSDIR}" = x ; then
1499     TOOLSDIR="$ROOTDIR/tools"
1500     fi
1501     if test ! -d ${TOOLSDIR} ; then
1502 cnh 1.65 echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
1503 edhill 1.1 exit 1
1504     fi
1505 edhill 1.11 if test "x$S64" = x ; then
1506 edhill 1.104 echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1
1507     RETVAL=$?
1508     if test "x${RETVAL}" = x0 ; then
1509     S64='$(TOOLSDIR)/set64bitConst.sh'
1510     else
1511     echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1
1512     RETVAL=$?
1513     if test "x${RETVAL}" = x0 ; then
1514     S64='$(TOOLSDIR)/set64bitConst.csh'
1515     else
1516     cat <<EOF
1517    
1518     ERROR: neither of the two default scripts:
1519    
1520     ${TOOLSDIR}/set64bitConst.sh
1521     ${TOOLSDIR}/set64bitConst.csh
1522    
1523     are working so please check paths or specify (with \$S64) a
1524     working version of this script.
1525    
1526     EOF
1527     exit 1
1528     fi
1529     fi
1530 edhill 1.11 fi
1531 adcroft 1.44 THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
1532 edhill 1.1
1533     EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1534    
1535     # We have a special set of source files in eesupp/src which are
1536     # generated from some template source files. We'll make them first so
1537     # they appear as regular source code
1538     if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
1539     echo " Making source files in eesupp from templates"
1540 edhill 1.36 ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1
1541 edhill 1.1 RETVAL=$?
1542 edhill 1.2 if test "x${RETVAL}" = x0 ; then
1543 edhill 1.1 rm -f make_eesupp.errors
1544     else
1545     echo "Error: problem encountered while building source files in eesupp:"
1546 edhill 1.62 cat make_eesupp.errors 1>&2
1547 edhill 1.1 exit 1
1548 afe 1.58 fi
1549     fi
1550    
1551     #same for exch2
1552     if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then
1553     echo " Making source files in exch2 from templates"
1554     ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1
1555     RETVAL=$?
1556     if test "x${RETVAL}" = x0 ; then
1557     rm -f make_exch2.errors
1558     else
1559 edhill 1.59 echo "Error: problem encountered while building source files in exch2:"
1560 edhill 1.62 cat make_exch2.errors 1>&2
1561 afe 1.58 exit 1
1562 edhill 1.1 fi
1563     fi
1564    
1565 edhill 1.2 printf "\n=== Determining package settings ===\n"
1566 edhill 1.1 if test "x${PDEPEND}" = x ; then
1567     tmp=$ROOTDIR"/pkg/pkg_depend"
1568     if test -r $tmp ; then
1569     PDEPEND=$tmp
1570     else
1571     echo "Warning: No package dependency information was specified."
1572     echo " Please check that ROOTDIR/pkg/pkg_depend exists."
1573     fi
1574     else
1575     if test ! -r ${PDEPEND} ; then
1576     echo "Error: can't read package dependency info from PDEPEND=\"$PDEPEND\""
1577     exit 1
1578     fi
1579     fi
1580     echo " getting package dependency info from $PDEPEND"
1581     # Strip the comments and then convert the dependency file into
1582     # two arrays: PNAME, DNAME
1583     cat $PDEPEND | sed -e 's/#.*$//g' \
1584 edhill 1.15 | $AWK 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \
1585 edhill 1.1 > ./.pd_tmp
1586     RETVAL=$?
1587     if test ! "x${RETVAL}" = x0 ; then
1588     echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
1589     exit 1
1590     fi
1591 edhill 1.34 . ./.pd_tmp
1592 edhill 1.1 rm -f ./.pd_tmp
1593    
1594 edhill 1.12 # Search for default packages. Note that a "$ROOTDIR/pkg/pkg_groups"
1595     # file should eventually be added so that, for convenience, one can
1596     # specify groups of packages using names like "ocean" and "atmosphere".
1597 edhill 1.41 echo " checking default package list: "
1598 edhill 1.1 if test "x${PDEFAULT}" = x ; then
1599 edhill 1.12 for i in "." $MODS ; do
1600     if test -r $i"/packages.conf" ; then
1601     PDEFAULT=$i"/packages.conf"
1602     break
1603     fi
1604     done
1605     fi
1606     if test "x${PDEFAULT}" = x ; then
1607 edhill 1.1 PDEFAULT="$ROOTDIR/pkg/pkg_default"
1608     fi
1609     if test "x${PDEFAULT}" = xNONE ; then
1610 edhill 1.41 echo " default packages file disabled"
1611 edhill 1.1 else
1612     if test ! -r $PDEFAULT ; then
1613     echo "Warning: can't read default packages from PDEFAULT=\"$PDEFAULT\""
1614     else
1615 edhill 1.41 echo " using PDEFAULT=\"$PDEFAULT\""
1616 edhill 1.1 # Strip the comments and add all the names
1617 edhill 1.15 def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
1618 edhill 1.1 RETVAL=$?
1619     if test "x${RETVAL}" != x0 ; then
1620 edhill 1.71 printf "Error: can't parse default package list "
1621 edhill 1.1 echo "-- please check PDEFAULT=\"$PDEFAULT\""
1622     exit 1
1623     fi
1624     for i in $def ; do
1625     PACKAGES="$PACKAGES $i"
1626     done
1627 edhill 1.12 echo " before group expansion packages are: $PACKAGES"
1628 edhill 1.87 RET=1
1629     while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
1630 edhill 1.12 echo " after group expansion packages are: $PACKAGES"
1631 edhill 1.1 fi
1632     fi
1633    
1634     echo " applying DISABLE settings"
1635 adcroft 1.74 for i in $PACKAGES ; do
1636     echo $i >> ./.tmp_pack
1637     done
1638     for i in `grep "-" ./.tmp_pack` ; do
1639     j=`echo $i | sed 's/[-]//'`
1640     DISABLE="$DISABLE $j"
1641     done
1642 edhill 1.1 pack=
1643     for p in $PACKAGES ; do
1644     addit="t"
1645     for d in $DISABLE ; do
1646     if test "x$p" = "x$d" ; then
1647     addit="f"
1648     fi
1649     done
1650     if test "x$addit" = xt ; then
1651     pack="$pack $p"
1652     fi
1653     done
1654     PACKAGES="$pack"
1655     echo " applying ENABLE settings"
1656 edhill 1.12 echo "" > ./.tmp_pack
1657 edhill 1.1 PACKAGES="$PACKAGES $ENABLE"
1658 adcroft 1.74 # Test if each explicitly referenced package exists
1659 edhill 1.1 for i in $PACKAGES ; do
1660 adcroft 1.74 j=`echo $i | sed 's/[-+]//'`
1661     if test ! -d "$ROOTDIR/pkg/$j" ; then
1662 edhill 1.1 echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
1663 adcroft 1.74 exit 1
1664 edhill 1.1 fi
1665     echo $i >> ./.tmp_pack
1666     done
1667     PACKAGES=
1668 adcroft 1.74 for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do
1669 edhill 1.1 PACKAGES="$PACKAGES $i"
1670     done
1671 adcroft 1.74 rm -f ./.tmp_pack
1672 edhill 1.1 echo " packages are: $PACKAGES"
1673    
1674 edhill 1.100 # Check availability of NetCDF and then either build the MNC template
1675     # files or delete mnc from the list of available packages.
1676     echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1
1677     RETVAL=$?
1678     if test "x$RETVAL" = x0 ; then
1679     if test "x$HAVE_NETCDF" != xt ; then
1680     cat <<EOF
1681    
1682     *********************************************************************
1683     WARNING: the "mnc" package was enabled but tests failed to compile
1684     NetCDF applications. Please check that:
1685    
1686     1) NetCDF is correctly installed for this compiler and
1687     2) the LIBS variable (within the "optfile") specifies the correct
1688     NetCDF library to link against.
1689    
1690     Due to this failure, the "mnc" package is now DISABLED.
1691     *********************************************************************
1692    
1693     EOF
1694     PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
1695     DISABLE="$DISABLE mnc"
1696     else
1697 edhill 1.110 ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
1698 edhill 1.100 RETVAL=$?
1699     if test "x${RETVAL}" = x0 ; then
1700     rm -f make_mnc.errors
1701     else
1702     echo "Error: problem encountered while building source files in pkg/mnc:"
1703     cat make_mnc.errors 1>&2
1704     exit 1
1705     fi
1706     fi
1707     fi
1708    
1709 edhill 1.1 echo " applying package dependency rules"
1710     ck=
1711     while test "x$ck" != xtt ; do
1712     i=0
1713 edhill 1.2 # rtot=${#PNAME[@]}
1714     rtot=$nname
1715 edhill 1.1 while test $i -lt $rtot ; do
1716    
1717     # Is $pname in the current $PACKAGES list?
1718 edhill 1.2 # pname=${PNAME[$i]}
1719     tmp="pname=\"\$PNAME_$i\""
1720     eval $tmp
1721 edhill 1.1 pin="f"
1722     for p in $PACKAGES ; do
1723     if test "x$p" = "x$pname" ; then
1724     pin="t"
1725     fi
1726     done
1727    
1728     # Is the DNAME entry a (+) or (-) rule ?
1729 edhill 1.2 tmp="dname=\"\$DNAME_$i\""
1730     eval $tmp
1731 edhill 1.1 plus="-"
1732 edhill 1.2 echo $dname | grep '^+' > /dev/null 2>&1
1733 edhill 1.1 RETVAL=$?
1734     if test "x$RETVAL" = x0 ; then
1735     plus="+"
1736     fi
1737    
1738     # Is $dname in the current $PACKAGES list?
1739 edhill 1.2 dname=`echo $dname | sed -e 's/^[+-]//'`
1740 edhill 1.1 din="f"
1741     for p in $PACKAGES ; do
1742     if test "x$p" = "x$dname" ; then
1743     din="t"
1744     fi
1745     done
1746    
1747     # Do we need to add $dname according to the dependency rules?
1748     if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then
1749     in_dis="f"
1750     for dis in $DISABLE ; do
1751     if test "x$dis" = "x$dname" ; then
1752     in_dis="t"
1753     fi
1754     done
1755     if test "x$in_dis" = xt ; then
1756     echo "Error: can't satisfy package dependencies:"
1757     echo " \"$dname\" is required by the dependency rules"
1758     echo " but is disallowed by the DISABLE settings"
1759     exit 1
1760     else
1761     PACKAGES="$PACKAGES $dname"
1762     ck=
1763     fi
1764     fi
1765    
1766     # Do we need to get rid of $dname according to the dependency rules?
1767     if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then
1768     echo "Error: can't satisfy package dependencies:"
1769     echo " \"$pname\" was requested but is disallowed by"
1770     echo " the dependency rules for \"$dname\""
1771     exit 1
1772     fi
1773 edhill 1.87 i=`echo "$i + 1" | bc -l`
1774     #i=$(( $i + 1 ))
1775 edhill 1.1 done
1776     ck=$ck"t"
1777     done
1778     echo " packages are: $PACKAGES"
1779     for i in $PACKAGES ; do
1780     adr="$ROOTDIR/pkg/$i"
1781     if test -d $adr ; then
1782     SOURCEDIRS="$SOURCEDIRS $adr"
1783     INCLUDEDIRS="$INCLUDEDIRS $adr"
1784 edhill 1.14 if test "x$i" = xautodiff ; then
1785     AUTODIFF_PKG_USED=t
1786     fi
1787 edhill 1.1 else
1788     echo "Error: the directory \"$adr\" for package $i doesn't exist"
1789     exit 1
1790     fi
1791     done
1792    
1793 edhill 1.12 # Create a list of #define and #undef to enable/disable packages
1794     PACKAGES_DOT_H=PACKAGES_CONFIG.h
1795 edhill 1.1 # The following UGLY HACK sets multiple "#undef"s and it needs to go
1796     # away. On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
1797     # file would eventually be split up so that all package-related #define
1798     # statements could be separated and handled only by genmake.
1799     names=`ls -1 "$ROOTDIR/pkg"`
1800     all_pack=
1801 adcroft 1.44 DISABLED_PACKAGES=
1802 edhill 1.1 for n in $names ; do
1803     if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
1804     has_pack="f"
1805     for pack in $PACKAGES ; do
1806     if test "x$pack" = "x$n" ; then
1807     has_pack="t"
1808     break
1809     fi
1810     done
1811     if test "x$has_pack" = xf ; then
1812 edhill 1.116 undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1813 adcroft 1.44 DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
1814 edhill 1.1 fi
1815     fi
1816     done
1817 adcroft 1.44 ENABLED_PACKAGES=
1818 edhill 1.1 for i in $PACKAGES ; do
1819 edhill 1.116 def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1820 adcroft 1.44 ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
1821 edhill 1.12 #eh3 DEFINES="$DEFINES -D$def"
1822 edhill 1.1
1823     #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
1824     case $i in
1825     aim_v23)
1826 adcroft 1.46 ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
1827 jmc 1.55 echo "Warning: ALLOW_AIM is set to enable aim_v23."
1828 edhill 1.1 ;;
1829     esac
1830     #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
1831    
1832     done
1833    
1834     echo " Adding STANDARDDIRS"
1835     BUILDDIR=${BUILDDIR:-.}
1836 edhill 1.57 if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
1837 edhill 1.12 STANDARDDIRS="eesupp model"
1838     fi
1839 edhill 1.57 if test "x$STANDARDDIRS" != x ; then
1840     for d in $STANDARDDIRS ; do
1841     adr="$ROOTDIR/$d/src"
1842     if test ! -d $adr ; then
1843     echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1844     echo " is correct and that you correctly specified the STANDARDDIRS option"
1845     exit 1
1846     else
1847     SOURCEDIRS="$SOURCEDIRS $adr"
1848     fi
1849     adr="$ROOTDIR/$d/inc"
1850     if test ! -d $adr ; then
1851     echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1852     echo " is correct and that you correctly specified the STANDARDDIRS option"
1853     exit 1
1854     else
1855     INCLUDEDIRS="$INCLUDEDIRS $adr"
1856     fi
1857     done
1858     fi
1859 edhill 1.1
1860 adcroft 1.52 echo " Searching for *OPTIONS.h files in order to warn about the presence"
1861     echo " of \"#define \"-type statements that are no longer allowed:"
1862 edhill 1.12 CPP_OPTIONS=
1863 adcroft 1.52 CPP_EEOPTIONS=
1864 edhill 1.12 spaths=". $INCLUDEDIRS"
1865 adcroft 1.52 names=`ls -1 "$ROOTDIR/pkg"`
1866 edhill 1.12 for i in $spaths ; do
1867     try="$i/CPP_OPTIONS.h"
1868 edhill 1.54 if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
1869 edhill 1.12 echo " found CPP_OPTIONS=\"$try\""
1870     CPP_OPTIONS="$try"
1871 adcroft 1.52 # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
1872     for n in $names ; do
1873     test_for_package_in_cpp_options $CPP_OPTIONS $n
1874     done
1875     fi
1876     try="$i/CPP_EEOPTIONS.h"
1877 edhill 1.54 if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
1878 adcroft 1.52 echo " found CPP_EEOPTIONS=\"$try\""
1879     # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
1880     #**** not yet enabled ****
1881     # test_for_mpi_in_cpp_eeoptions $try
1882     #**** not yet enabled ****
1883     CPP_EEOPTIONS="$try"
1884 edhill 1.12 fi
1885     done
1886     if test "x$CPP_OPTIONS" = x ; then
1887     echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
1888     exit 1
1889     fi
1890 edhill 1.1
1891 edhill 1.14 # Here, we build the list of files to be "run through" the adjoint
1892     # compiler.
1893     if test -f ./ad_files ; then
1894     rm -f ./ad_files
1895     fi
1896     echo " Creating the list of files for the adjoint compiler."
1897     for i in $SOURCEDIRS ; do
1898     list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
1899     for j in $list_files ; do
1900     cat $i/$j >> ad_files
1901     done
1902     done
1903 edhill 1.121 if test ! "x"$FS = "x.f" ; then
1904 edhill 1.122 cat ad_files | sed -e "s/\.f/.$FS/g" > ad_files_f
1905 edhill 1.121 mv -f ad_files_f ad_files
1906     fi
1907 edhill 1.14
1908 edhill 1.2 echo
1909     echo "=== Creating the Makefile ==="
1910 edhill 1.1 echo " setting INCLUDES"
1911     for i in $INCLUDEDIRS ; do
1912 edhill 1.87 if test ! -d $i ; then
1913 edhill 1.1 echo "Warning: can't find INCLUDEDIRS=\"$i\""
1914     fi
1915     done
1916    
1917     echo " Determining the list of source and include files"
1918     rm -rf .links.tmp
1919     mkdir .links.tmp
1920     echo "# This section creates symbolic links" > srclinks.tmp
1921     echo "" >> srclinks.tmp
1922 edhill 1.71 printf 'SRCFILES = ' > srclist.inc
1923     printf 'CSRCFILES = ' > csrclist.inc
1924     printf 'F90SRCFILES = ' > f90srclist.inc
1925     printf 'HEADERFILES = ' > hlist.inc
1926     printf 'AD_FLOW_FILES = ' > ad_flow_files.inc
1927 adcroft 1.9 alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1928 edhill 1.1 for d in $alldirs ; do
1929     deplist=
1930 edhill 1.14 sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
1931 cnh 1.3 sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
1932 edhill 1.1 for sf in $sfiles ; do
1933     if test ! -r ".links.tmp/$sf" ; then
1934     if test -f "$d/$sf" ; then
1935 edhill 1.131 ignore_f=f
1936 adcroft 1.44 case $d/$sf in
1937     ./$PACKAGES_DOT_H)
1938     ;;
1939     ./AD_CONFIG.h)
1940     ;;
1941     ./FC_NAMEMANGLE.h)
1942     ;;
1943 edhill 1.98 ./BUILD_INFO.h)
1944     ;;
1945 adcroft 1.44 *)
1946 edhill 1.131 # For the local directory *ONLY*,
1947     # ignore all soft-links
1948     if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then
1949     ignore_f=t
1950     else
1951     touch .links.tmp/$sf
1952     deplist="$deplist $sf"
1953     fi
1954 adcroft 1.44 ;;
1955     esac
1956 edhill 1.131 if test "x$ignore_f" = xf ; then
1957     extn=`echo $sf | $AWK -F. '{print $NF}'`
1958     case $extn in
1959     F)
1960     echo " \\" >> srclist.inc
1961     printf " $sf" >> srclist.inc
1962     ;;
1963     F90)
1964     echo " \\" >> f90srclist.inc
1965     printf " $sf" >> f90srclist.inc
1966     ;;
1967     c)
1968     echo " \\" >> csrclist.inc
1969     printf " $sf" >> csrclist.inc
1970     ;;
1971     h)
1972     echo " \\" >> hlist.inc
1973     printf " $sf" >> hlist.inc
1974     ;;
1975     flow)
1976     echo " \\" >> ad_flow_files.inc
1977     printf " $sf" >> ad_flow_files.inc
1978     ;;
1979     esac
1980     fi
1981 edhill 1.1 fi
1982     fi
1983     done
1984     if test "x$deplist" != x ; then
1985 edhill 1.2 echo "" >> srclinks.tmp
1986     echo "# These files are linked from $d" >> srclinks.tmp
1987 edhill 1.1 echo "$deplist :" >> srclinks.tmp
1988 edhill 1.2 printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp
1989 edhill 1.1 fi
1990     done
1991     rm -rf .links.tmp
1992     echo "" >> srclist.inc
1993     echo "" >> csrclist.inc
1994 cnh 1.3 echo "" >> f90srclist.inc
1995 edhill 1.1 echo "" >> hlist.inc
1996 edhill 1.14 echo "" >> ad_flow_files.inc
1997 edhill 1.1
1998 edhill 1.88 if test -f $MAKEFILE ; then
1999 edhill 1.1 mv -f $MAKEFILE "$MAKEFILE.bak"
2000     fi
2001     echo " Writing makefile: $MAKEFILE"
2002     echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
2003     echo "# $MACHINE" >> $MAKEFILE
2004     echo "# This makefile was generated automatically on" >> $MAKEFILE
2005     echo "# $THISDATE" >> $MAKEFILE
2006     echo "# by the command:" >> $MAKEFILE
2007 edhill 1.73 echo "# $0 $G2ARGS" >> $MAKEFILE
2008 edhill 1.1 echo "# executed by:" >> $MAKEFILE
2009 edhill 1.97 echo "# ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
2010 edhill 1.21
2011     EXE_AD=$EXECUTABLE"_ad"
2012     EXE_FTL=$EXECUTABLE"_ftl"
2013     EXE_SVD=$EXECUTABLE"_svd"
2014    
2015 edhill 1.1 cat >>$MAKEFILE <<EOF
2016 edhill 1.53 #
2017     # OPTFILE="$OPTFILE"
2018 edhill 1.1 #
2019     # BUILDDIR : Directory where object files are written
2020     # SOURCEDIRS : Directories containing the source (.F) files
2021     # INCLUDEDIRS : Directories containing the header-source (.h) files
2022     # EXEDIR : Directory where executable that is generated is written
2023     # EXECUTABLE : Full path of executable binary
2024     #
2025     # CPP : C-preprocessor command
2026     # INCLUDES : Directories searched for header files
2027     # DEFINES : Macro definitions for CPP
2028     # MAKEDEPEND : Dependency generator
2029     # KPP : Special preprocessor command (specific to platform)
2030     # KFLAGS : Flags for KPP
2031     # FC : Fortran compiler command
2032     # FFLAGS : Configuration/debugging options for FC
2033     # FOPTIM : Optimization options for FC
2034     # LINK : Command for link editor program
2035     # LIBS : Library flags /or/ additional optimization/debugging flags
2036    
2037     ROOTDIR = ${ROOTDIR}
2038     BUILDDIR = ${BUILDDIR}
2039     SOURCEDIRS = ${SOURCEDIRS}
2040     INCLUDEDIRS = ${INCLUDEDIRS}
2041     EXEDIR = ${EXEDIR}
2042     EXECUTABLE = \$(EXEDIR)/${EXECUTABLE}
2043     TOOLSDIR = ${TOOLSDIR}
2044    
2045 edhill 1.14 #eh3 new defines for the adjoint work
2046     AUTODIFF = ${ROOTDIR}/pkg/autodiff
2047 edhill 1.21 EXE_AD = ${EXE_AD}
2048     EXE_FTL = ${EXE_FTL}
2049     EXE_SVD = ${EXE_SVD}
2050 edhill 1.14
2051 adcroft 1.44 ENABLED_PACKAGES = ${ENABLED_PACKAGES}
2052     DISABLED_PACKAGES = ${DISABLED_PACKAGES}
2053    
2054 adcroft 1.52 # These files are created by Makefile
2055 edhill 1.97 SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h
2056 adcroft 1.52
2057 edhill 1.1 EOF
2058    
2059     # Note: figure out some way to add Hyades JAM libraries here
2060    
2061     cat >>$MAKEFILE <<EOF
2062     # Unix ln (link)
2063     LN = ${LN}
2064     # C preprocessor
2065     CPP = cat \$< | ${S64} | ${CPP}
2066     # Dependency generator
2067     MAKEDEPEND = ${MAKEDEPEND}
2068     # Special preprocessor (KAP on DECs, FPP on Crays)
2069     KPP = ${KPP}
2070     # Fortran compiler
2071 edhill 1.94 FC = ${FC}
2072 cnh 1.3 # Fortran compiler
2073     F90C = ${F90C}
2074 edhill 1.92 # C compiler
2075     CC = ${CC}
2076 edhill 1.1 # Link editor
2077 edhill 1.70 LINK = ${LINK} ${LDADD}
2078 edhill 1.1
2079     # Defines for CPP
2080     DEFINES = ${DEFINES}
2081     # Includes for CPP
2082     INCLUDES = ${INCLUDES}
2083     # Flags for KPP
2084     KFLAGS1 = ${KFLAGS1}
2085     KFLAGS2 = ${KFLAGS2}
2086     # Optim./debug for FC
2087     FFLAGS = ${FFLAGS}
2088     FOPTIM = ${FOPTIM}
2089 cnh 1.3 # Optim./debug for FC
2090     F90FLAGS = ${F90FLAGS}
2091     F90OPTIM = ${F90OPTIM}
2092 edhill 1.1 # Flags for CC
2093     CFLAGS = ${CFLAGS}
2094     # Files that should not be optimized
2095     NOOPTFILES = ${NOOPTFILES}
2096     NOOPTFLAGS = ${NOOPTFLAGS}
2097     # Flags and libraries needed for linking
2098 edhill 1.107 LIBS = ${LIBS}
2099 cnh 1.3 # Name of the Mekfile
2100     MAKEFILE=${MAKEFILE}
2101 edhill 1.1
2102     EOF
2103    
2104 edhill 1.14 cat srclist.inc >> $MAKEFILE
2105     cat csrclist.inc >> $MAKEFILE
2106     cat f90srclist.inc >> $MAKEFILE
2107     cat hlist.inc >> $MAKEFILE
2108     cat ad_flow_files.inc >> $MAKEFILE
2109 edhill 1.75 echo >> $MAKEFILE
2110 edhill 1.76 echo 'F77FILES = $(SRCFILES:.F=.'$FS')' >> $MAKEFILE
2111 heimbach 1.127 echo 'F90FILES = $(F90SRCFILES:.F90=.'$FS90')' >> $MAKEFILE
2112 edhill 1.76 echo 'OBJFILES = $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
2113 edhill 1.75 echo >> $MAKEFILE
2114     echo '.SUFFIXES:' >> $MAKEFILE
2115 adcroft 1.83 echo '.SUFFIXES: .o .'$FS' .p .F .c .'$FS90' .F90' >> $MAKEFILE
2116 cnh 1.3 rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc
2117 edhill 1.14 rm -f ad_flow_files.inc
2118 edhill 1.1
2119     cat >>$MAKEFILE <<EOF
2120    
2121     all: \$(EXECUTABLE)
2122 adcroft 1.52 \$(EXECUTABLE): \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(OBJFILES)
2123 adcroft 1.44 @echo Creating \$@ ...
2124 edhill 1.1 \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
2125     depend:
2126     @make links
2127 edhill 1.76 \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
2128 adcroft 1.44 \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2129 edhill 1.72 -rm -f makedepend.out
2130 edhill 1.1
2131 cnh 1.132 lib: libmitgcmuv.a
2132    
2133     libmitgcmuv.a: \$(OBJFILES)
2134     ar rcv libmitgcmuv.a \$(OBJFILES)
2135    
2136 adcroft 1.52 links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES)
2137 edhill 1.1
2138 cnh 1.3 small_f: \$(F77FILES) \$(F90FILES)
2139 edhill 1.1
2140     output.txt: \$(EXECUTABLE)
2141     @printf 'running ... '
2142     @\$(EXECUTABLE) > \$@
2143    
2144     clean:
2145 edhill 1.76 -rm -rf *.o *.$FS *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
2146 edhill 1.1 Clean:
2147     @make clean
2148     @make cleanlinks
2149 adcroft 1.52 -rm -f \$(SPECIAL_FILES)
2150 adcroft 1.51 -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak
2151 edhill 1.1 CLEAN:
2152     @make Clean
2153     -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
2154     -find \$(EXEDIR) -name "*.data" -exec rm {} \;
2155     -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
2156 adcroft 1.78 -rm -f \$(EXECUTABLE) output.txt STD*
2157 edhill 1.1
2158 edhill 1.18 #eh3 Makefile: makefile
2159 edhill 1.1 makefile:
2160 edhill 1.73 $THIS_SCRIPT $G2ARGS
2161 edhill 1.1 cleanlinks:
2162     -find . -type l -exec rm {} \;
2163    
2164 edhill 1.97 # Special targets (SPECIAL_FILES) which are create by make
2165 adcroft 1.44 ${PACKAGES_DOT_H}:
2166     @echo Creating \$@ ...
2167 edhill 1.71 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@
2168 adcroft 1.44 AD_CONFIG.h:
2169     @echo Creating \$@ ...
2170 edhill 1.71 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > \$@
2171 adcroft 1.52 FC_NAMEMANGLE.h:
2172     @echo Creating \$@ ...
2173     echo "$FC_NAMEMANGLE" > \$@
2174 adcroft 1.44
2175 edhill 1.97 BUILD_INFO.h:
2176     @echo Creating \$@ ...
2177     EOF
2178    
2179     test ! "x$THISVER" = x && echo " -echo \"#define THISVER '$THISVER'\" > \$@" >> $MAKEFILE
2180     test ! "x$THISUSER" = x && echo " -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE
2181     test ! "x$THISDATE" = x && echo " -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
2182     test ! "x$THISHOST" = x && echo " -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
2183    
2184     cat >>$MAKEFILE <<EOF
2185    
2186 edhill 1.76 # The normal chain of rules is ( .F - .$FS - .o )
2187    
2188 edhill 1.101 ## This nullifies any default implicit rules concerning these two file types:
2189     ## %.o : %.F
2190 edhill 1.76
2191     .F.$FS:
2192 edhill 1.1 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2193 edhill 1.76 .$FS.o:
2194 edhill 1.1 \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2195 edhill 1.76 .F90.$FS90:
2196 cnh 1.3 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2197 edhill 1.76 .$FS90.o:
2198 cnh 1.3 \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
2199 edhill 1.1 .c.o:
2200     \$(CC) \$(CFLAGS) -c \$<
2201    
2202 edhill 1.76 # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
2203     .F.p:
2204 edhill 1.1 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2205 edhill 1.76 .p.$FS:
2206 edhill 1.1 \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
2207 edhill 1.14
2208     #=========================================
2209     #=== Automatic Differentiation Rules ===
2210    
2211     TAMC = ${TAMC}
2212     TAF = ${TAF}
2213    
2214 edhill 1.17 TAF_EXTRA = ${TAF_EXTRA}
2215     TAMC_EXTRA = ${TAMC_EXTRA}
2216    
2217 edhill 1.14 EOF
2218    
2219     ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
2220     ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF_FLAGS"
2221     ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
2222     for i in $ad_vars ; do
2223     name=$i
2224     t1="t2=\$"`echo $i`
2225     eval $t1
2226     printf "%-20s = " $name >> $MAKEFILE
2227     echo $t2 >> $MAKEFILE
2228     done
2229    
2230     echo " Add the source list for AD code generation"
2231     echo >> $MAKEFILE
2232 edhill 1.71 printf "AD_FILES = " >> $MAKEFILE
2233 edhill 1.14 AD_FILES=`cat ad_files`
2234     for i in $AD_FILES ; do
2235     echo " \\" >> $MAKEFILE
2236 edhill 1.71 printf " $i" >> $MAKEFILE
2237 edhill 1.14 done
2238     echo >> $MAKEFILE
2239 edhill 1.21 rm -f ad_files
2240 edhill 1.14
2241     cat >>$MAKEFILE <<EOF
2242    
2243 edhill 1.16 # ... AD ...
2244 edhill 1.23 adall: ad_taf
2245 edhill 1.121 adtaf: ad_taf_output.$FS
2246     adtamc: ad_tamc_output.$FS
2247 edhill 1.21
2248 edhill 1.121 ad_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)
2249 edhill 1.71 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > ad_config.template
2250 edhill 1.23 cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
2251 adcroft 1.44 -rm -f ad_config.template
2252 edhill 1.22 @make \$(F77FILES)
2253     @make \$(AD_FLOW_FILES)
2254 edhill 1.121 cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.$FS
2255 edhill 1.22
2256 edhill 1.121 ad_taf_output.$FS: ad_input_code.$FS
2257     \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2258     cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
2259 heimbach 1.37
2260     adtafonly:
2261 edhill 1.121 \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2262     cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
2263 edhill 1.14
2264     ad_taf: ad_taf_output.o \$(OBJFILES)
2265 edhill 1.21 \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
2266 edhill 1.14
2267 edhill 1.121 ad_tamc_output.$FS: ad_input_code.$FS
2268     \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
2269     cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS
2270 edhill 1.14
2271     ad_tamc: ad_tamc_output.o \$(OBJFILES)
2272 edhill 1.21 \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
2273 edhill 1.14
2274 heimbach 1.105 adonlyfwd:
2275 edhill 1.106 patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
2276 heimbach 1.105
2277     adtrick:
2278 edhill 1.106 patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
2279 edhill 1.14
2280 edhill 1.19 # ... FTL ...
2281 edhill 1.23 ftlall: ftl_taf
2282 edhill 1.121 ftltaf: ftl_taf_output.$FS
2283     ftltamc: ftl_tamc_output.$FS
2284 edhill 1.21
2285 edhill 1.121 ftl_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)
2286 edhill 1.71 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > ftl_config.template
2287 edhill 1.23 cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
2288 adcroft 1.44 -rm -f ftl_config.template
2289 edhill 1.23 @make \$(F77FILES)
2290 edhill 1.22 @make \$(AD_FLOW_FILES)
2291 edhill 1.121 cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.$FS
2292 edhill 1.22
2293 edhill 1.121 ftl_taf_output.$FS: ftl_input_code.$FS
2294     \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2295     cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2296 edhill 1.14
2297 heimbach 1.40 ftltafonly:
2298 edhill 1.121 \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2299     cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2300 heimbach 1.40
2301 edhill 1.19 ftl_taf: ftl_taf_output.o \$(OBJFILES)
2302 edhill 1.21 \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
2303 edhill 1.14
2304 edhill 1.121 ftl_tamc_output.$FS: ftl_input_code.$FS
2305     \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
2306     cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS
2307 edhill 1.16
2308 edhill 1.19 ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
2309 edhill 1.21 \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
2310 edhill 1.16
2311    
2312     # ... SVD ...
2313 edhill 1.121 svdtaf: ad_taf_output.$FS ftl_taf_output.$FS
2314 heimbach 1.109 @echo "--->>> Only ran TAF to generate SVD code! <<<---"
2315     @echo "--->>> Do make svdall afterwards to compile. <<<---"
2316     svdall: svd_touch svd_taf
2317 edhill 1.16
2318 heimbach 1.109 svd_taf: \$(OBJFILES)
2319 heimbach 1.40 \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
2320 edhill 1.14
2321 heimbach 1.109 @echo "--->>> Only COMPILE svd code! <<<---"
2322     @echo "--->>> Assumes you previously <<<---"
2323     @echo "--->>> did make svdtaf <<<---"
2324    
2325     svd_touch:
2326     @echo "--->>> Only COMPILE svd code! <<<---"
2327     @echo "--->>> Assumes you previously <<<---"
2328     @echo "--->>> did make svdtaf <<<---"
2329 edhill 1.121 touch ad_taf_output.$FS ftl_taf_output.$FS
2330     \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS
2331     \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS
2332 heimbach 1.109 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > ftl_config.template
2333     cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
2334     -rm -f ftl_config.template
2335 edhill 1.14
2336     #=========================================
2337 edhill 1.1
2338     EOF
2339 edhill 1.7
2340     if test "x$EXEHOOK" != x ; then
2341     printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
2342     fi
2343 edhill 1.1
2344     echo " Making list of \"exceptions\" that need \".p\" files"
2345     for i in $KPPFILES ; do
2346     base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
2347     RETVAL=$?
2348     if test "x$RETVAL" != x0 ; then
2349     echo "Error: unable to add file \"$i\" to the exceptions list"
2350     fi
2351 edhill 1.76 echo "$base.$FS: $base.p" >> $MAKEFILE
2352 edhill 1.1 done
2353    
2354     echo " Making list of NOOPTFILES"
2355     for i in $NOOPTFILES ; do
2356     base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
2357     RETVAL=$?
2358     if test "x$RETVAL" != x0 ; then
2359     echo "Error: unable to add file \"$i\" to the exceptions list"
2360     fi
2361 edhill 1.76 echo "$base.o: $base.$FS" >> $MAKEFILE
2362 edhill 1.2 printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
2363 edhill 1.1 done
2364    
2365     echo " Add rules for links"
2366     cat srclinks.tmp >> $MAKEFILE
2367     rm -f srclinks.tmp
2368    
2369     echo " Adding makedepend marker"
2370 edhill 1.2 printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
2371 edhill 1.1
2372 edhill 1.2 printf "\n=== Done ===\n"
2373 adcroft 1.47
2374     # Create special header files
2375 edhill 1.71 $BASH $TOOLSDIR/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" $DISABLED_PACKAGES " " "Enabled packages:" $ENABLED_PACKAGES > $PACKAGES_DOT_H".tmp"
2376 adcroft 1.47 if test ! -f $PACKAGES_DOT_H ; then
2377     mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2378     else
2379 edhill 1.61 cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
2380 adcroft 1.47 RETVAL=$?
2381     if test "x$RETVAL" = x0 ; then
2382     rm -f $PACKAGES_DOT_H".tmp"
2383     else
2384     mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
2385     mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2386     fi
2387     fi
2388     if test ! -f AD_CONFIG.h ; then
2389 edhill 1.71 $BASH $TOOLSDIR/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > AD_CONFIG.h
2390 adcroft 1.47 fi
2391 edhill 1.5
2392    
2393     # Write the "state" for future records
2394     if test "x$DUMPSTATE" != xf ; then
2395 edhill 1.71 printf "" > genmake_state
2396 edhill 1.5 for i in $gm_state ; do
2397     t1="t2=\$$i"
2398     eval $t1
2399 edhill 1.12 echo "$i='$t2'" >> genmake_state
2400 edhill 1.5 done
2401     fi

  ViewVC Help
Powered by ViewVC 1.1.22