/[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.75 - (hide annotations) (download)
Wed Apr 7 20:28:09 2004 UTC (15 years, 5 months ago) by edhill
Branch: MAIN
Changes since 1.74: +65 -16 lines
 o first step towards fixing the *.F/*.f problem that exists within cygwin
   and MacOSX environments

1 edhill 1.49 #! /usr/bin/env bash
2 edhill 1.1 #
3 edhill 1.75 # $Header: /u/gcmpack/MITgcm/tools/genmake2,v 1.74 2004/03/24 17:12:51 adcroft 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     # First check the ability to create a *.F/.f pair.
80     cat <<EOF >> ./hello.F
81     program hello
82     write(*,*) 'hi'
83     stop
84     end
85     EOF
86     cp ./hello.F ./hello.f
87     RETVAL=$?
88     if test "x$RETVAL" != x0 ; then
89     FEXT='fp'
90     F90EXT='fp90'
91     return
92     fi
93     rm -f ./hello.f
94    
95     # Then check the ability of ${MAKE} to use the two.
96     test -e Makefile && mv -f Makefile Makefile.bak
97     cat <<EOF >> Makefile
98     .SUFFIXES:
99     hello.f: hello.F
100     cp -f hello.F hello.f
101     EOF
102     ( $MAKE hello.f ) > /dev/null 2>&1
103     RETVAL=$?
104     if test "x$RETVAL" != x0 -o ! -f ./hello.f ; then
105     FEXT='fp'
106     F90EXT='fp90'
107     return
108     fi
109     rm -f ./hello.f ./hello.F Makefile
110     test -e Makefile && mv -f Makefile.bak Makefile
111    
112     # Both tests passed, so use the default.
113     FEXT='F'
114     F90EXT='F90'
115     }
116    
117    
118 edhill 1.1 # Guess possible config options for this host
119     find_possible_configs() {
120    
121 edhill 1.11 tmp1=`uname`"_"`uname -m`
122     tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
123 edhill 1.25 tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
124 edhill 1.56 tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
125     tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
126 edhill 1.72 tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
127     PLATFORM=$tmp3
128 edhill 1.11 OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
129     echo " The platform appears to be: $PLATFORM"
130    
131 edhill 1.1 echo "test" > test
132     ln -s ./test link
133     RETVAL=$?
134     if test "x${RETVAL}" = x0 ; then
135 edhill 1.11 LN="ln -s"
136     else
137     echo "Error: \"ln -s\" does not appear to work on this system!"
138     echo " For help, please contact <MITgcm-support@mitgcm.org>."
139     exit 1
140 edhill 1.1 fi
141     rm -f test link
142    
143 edhill 1.11 if test "x$CPP" = x ; then
144     CPP="cpp -traditional -P"
145 adcroft 1.33 fi
146    
147 edhill 1.69 # The "original" makedepend is part of the Imake system that is
148     # most often distributed with XFree86 or with an XFree86 source
149     # package. As a result, many machines (eg. generic Linux) do not
150     # have a system-default "makedepend" available. For those
151     # systems, we have two fall-back options:
152     #
153     # 1) a makedepend implementation shipped with the cyrus-imapd
154     # package: ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
155     #
156     # 2) a known-buggy xmakedpend shell script
157     #
158     # So the choices are, in order:
159     #
160     # 1) use the user-specified program
161     # 2) use a system-wide default
162     # 3) locally build and use the cyrus implementation
163     # 4) fall back to the buggy local xmakedpend script
164     #
165 adcroft 1.33 if test "x${MAKEDEPEND}" = x ; then
166 edhill 1.72 which makedepend > /dev/null 2>&1
167 adcroft 1.33 RETVAL=$?
168 edhill 1.69 if test ! "x${RETVAL}" = x0 ; then
169     echo " a system-default makedepend was not found."
170    
171     # Try to build the cyrus impl
172     rm -f ./genmake_cy_md
173     (
174     cd $ROOTDIR/tools/cyrus-imapd-makedepend \
175     && ./configure > /dev/null 2>&1 \
176     && make > /dev/null 2>&1 \
177     && ./makedepend ifparser.c > /dev/null 2>&1 \
178     && echo "true"
179     ) > ./genmake_cy_md
180     grep true ./genmake_cy_md > /dev/null 2>&1
181     RETVAL=$?
182     if test "x$RETVAL" = x0 ; then
183     MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
184     else
185     MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
186     fi
187     rm -f ./genmake_cy_md
188 adcroft 1.33 fi
189 edhill 1.1 fi
190    
191     # look for possible fortran compilers
192 cnh 1.24 tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"
193 edhill 1.1 p_FC=
194 edhill 1.11 for c in $tmp ; do
195     rm -f ./hello.f ./hello
196     cat >> hello.f <<EOF
197     program hello
198     do i=1,3
199     print *, 'hello world : ', i
200     enddo
201     end
202     EOF
203     $c -o hello hello.f > /dev/null 2>&1
204 edhill 1.1 RETVAL=$?
205     if test "x${RETVAL}" = x0 ; then
206     p_FC="$p_FC $c"
207     fi
208     done
209 edhill 1.21 rm -f ./hello.f ./hello
210 edhill 1.1 if test "x${p_FC}" = x ; then
211 edhill 1.11 cat 1>&2 <<EOF
212    
213     Error: No Fortran compilers were found in your path. Please specify one using:
214    
215     1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
216     2) a command-line option (eg. "-fc NAME"), or
217     3) the MITGCM_FC environment variable.
218    
219     EOF
220     exit 1
221 edhill 1.1 else
222 edhill 1.11 echo " The possible FORTRAN compilers found in your path are:"
223     echo " "$p_FC
224     if test "x$FC" = x ; then
225 edhill 1.15 FC=`echo $p_FC | $AWK '{print $1}'`
226 adcroft 1.67 echo " Setting FORTRAN compiler to: "$FC
227 edhill 1.11 fi
228 edhill 1.1 fi
229    
230 adcroft 1.67 if test "x$OPTFILE" = x ; then
231     OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
232     if test ! -r $OPTFILE ; then
233     echo " I looked for the file "$OPTFILE" but did not find it"
234     fi
235     fi
236     # echo " The options file: $p_OF"
237     # echo " appears to match so we'll use it."
238     # for i in $p_FC ; do
239     #p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
240     #if test -r $p_OF ; then
241     # OPTFILE=$p_OF
242     # echo " The options file: $p_OF"
243     # echo " appears to match so we'll use it."
244     # break
245     #fi
246     # done
247 edhill 1.11 if test "x$OPTFILE" = x ; then
248     cat 1>&2 <<EOF
249    
250     Error: No options file was found in: $ROOTDIR/tools/build_options/
251     that matches this platform ("$PLATFORM") and the compilers found in
252     your path. Please specify an "optfile" using:
253    
254     1) the command line (eg. "-optfile=path/to/OPTFILE"), or
255     2) the MITGCM_OF environment variable.
256    
257     If you need help, please contact the developers at <MITgcm-support@mitgcm.org>.
258    
259 edhill 1.1 EOF
260 edhill 1.11 exit 1
261 edhill 1.1 fi
262 edhill 1.11
263     # # look for possible MPI libraries
264     # mpi_libs=
265     # mpi_fort=`which mpif77 2>/dev/null`
266     # RETVAL=$?
267     # if test "x${RETVAL}" = x0 ; then
268     # cat >>test.f <<EOF
269     # PROGRAM HELLO
270     # DO 10, I=1,10
271     # PRINT *,'Hello World'
272     # 10 CONTINUE
273     # STOP
274     # END
275     # EOF
276     # eval "$mpi_fort -showme test.f > out"
277     # RETVAL=$?
278     # if test "x${RETVAL}" = x0 ; then
279     # a=`cat out`
280     # for i in $a ; do
281     # case $i in
282     # -*)
283     # mpi_libs="$mpi_libs $i" ;;
284     # esac
285     # done
286     # echo "The MPI libs appear to be:"
287     # echo " "$mpi_libs
288     # fi
289     # rm -f test.f out
290     # fi
291 edhill 1.1
292     }
293    
294     # Parse the package dependency information
295     get_pdepend_list() {
296    
297     # strip the comments and then convert the dependency file into
298     # two arrays: PNAME, DNAME
299     cat $1 | sed -e 's/#.*$//g' \
300 edhill 1.15 | $AWK 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \
301 edhill 1.1 > ./.pd_tmp
302 edhill 1.34 . ./.pd_tmp
303 edhill 1.1 rm -f ./.pd_tmp
304    
305 edhill 1.71 printf "PNAME = "${}
306 edhill 1.1 }
307    
308    
309     # Explain usage
310     usage() {
311 edhill 1.41 cat <<EOF
312    
313     Usage: "$0" [OPTIONS]
314     where [OPTIONS] can be:
315    
316     -help | --help | -h | --h
317     Print this help message and exit.
318    
319     -nooptfile | --nooptfile
320     -optfile NAME | --optfile NAME | -of NAME | --of NAME
321     -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
322     Use "NAME" as the optfile. By default, an attempt will be
323     made to find an appropriate "standard" optfile in the
324     tools/build_options/ directory.
325    
326     -pdepend NAME | --pdepend NAME
327     -pdepend=NAME | --pdepend=NAME
328     Get package dependency information from "NAME".
329    
330     -pdefault NAME | --pdefault NAME
331     -pdefault=NAME | --pdefault=NAME
332     Get the default package list from "NAME".
333    
334     -make NAME | -m NAME
335     --make=NAME | -m=NAME
336     Use "NAME" for the MAKE program. The default is "make" but
337     many platforms, "gmake" is the preferred choice.
338    
339     -makefile NAME | -mf NAME
340     --makefile=NAME | -mf=NAME
341     Call the makefile "NAME". The default is "Makefile".
342    
343 edhill 1.69 -makedepend NAME | -md NAME
344     --makedepend=NAME | -md=NAME
345     Use "NAME" for the MAKEDEPEND program.
346    
347 edhill 1.41 -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
348     -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
349     Specify the location of the MITgcm ROOTDIR as "NAME".
350     By default, genamke will try to find the location by
351     looking in parent directories (up to the 5th parent).
352    
353     -mods NAME | --mods NAME | -mo NAME | --mo NAME
354     -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
355     Here, "NAME" specifies a list of directories that are
356     used for additional source code. Files found in the
357     "mods list" are given preference over files of the same
358     name found elsewhere.
359    
360     -disable NAME | --disable NAME
361     -disable=NAME | --disable=NAME
362     Here "NAME" specifies a list of packages that we don't
363     want to use. If this violates package dependencies,
364     genamke will exit with an error message.
365    
366     -enable NAME | --enable NAME
367     -enable=NAME | --enable=NAME
368     Here "NAME" specifies a list of packages that we wish
369     to specifically enable. If this violates package
370     dependencies, genamke will exit with an error message.
371    
372     -standarddirs NAME | --standarddirs NAME
373     -standarddirs=NAME | --standarddirs=NAME
374     Here, "NAME" specifies a list of directories to be
375     used as the "standard" code.
376    
377     -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
378     -fc=NAME | --fc=NAME
379     Use "NAME" as the fortran compiler. By default, genmake
380     will search for a working compiler by trying a list of
381     "usual suspects" such as g77, f77, etc.
382    
383     -[no]ieee | --[no]ieee
384     Do or don't use IEEE numerics. Note that this option
385     *only* works if it is supported by the OPTFILE that
386     is being used.
387    
388 adcroft 1.67 -mpi | --mpi
389     Include MPI header files and link to MPI libraries
390     -mpi=PATH | --mpi=PATH
391     Include MPI header files and link to MPI libraries using MPI_ROOT
392     set to PATH. i.e. Include files from $PATH/include, link to libraries
393     from $PATH/lib and use binaries from $PATH/bin.
394    
395 edhill 1.71 -bash NAME
396     Explicitly specify the Bourne or BASH shell to use
397    
398 edhill 1.41 While it is most often a single word, the "NAME" variables specified
399     above can in many cases be a space-delimited string such as:
400    
401     --enable pkg1 --enable 'pkg1 pkg2' --enable 'pkg1 pkg2 pkg3'
402     -mods=dir1 -mods='dir1' -mods='dir1 dir2 dir3'
403     -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
404    
405     which, depending upon your shell, may need to be single-quoted.
406    
407     For more detailed genmake documentation, please see:
408    
409     http://mitgcm.org/devel_HOWTO/
410    
411     EOF
412    
413 edhill 1.1 exit 1
414     }
415    
416 edhill 1.31 # Build a CPP macro to automate calling C routines from FORTRAN
417     get_fortran_c_namemangling() {
418     default_nm="#define FC_NAMEMANGLE(X) X ## _"
419    
420     cat > genmake_test.c <<EOF
421     void tcall( char * string ) { tsub( string ); }
422     EOF
423 edhill 1.39 $MAKE genmake_test.o >> genmake_warnings 2>&1
424 edhill 1.31 RETVAL=$?
425     if test "x$RETVAL" != x0 ; then
426     FC_NAMEMANGLE=$default_nm
427 edhill 1.39 cat <<EOF>> genmake_errors
428    
429     WARNING: C test compile fails
430     WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
431     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
432     EOF
433 edhill 1.31 return 1
434     fi
435 edhill 1.43 c_tcall=`nm genmake_test.o | grep 'T ' | grep tcall | cut -d ' ' -f 3`
436 edhill 1.31 RETVAL=$?
437     if test "x$RETVAL" != x0 ; then
438     FC_NAMEMANGLE=$default_nm
439 edhill 1.39 cat <<EOF>> genmake_warnings
440    
441     WARNING: The "nm" command failed.
442     WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
443     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
444     EOF
445 edhill 1.31 return 1
446     fi
447     cat > genmake_tcomp.f <<EOF
448     subroutine tcall( string )
449     character*(*) string
450     call tsub( string )
451     end
452     EOF
453 edhill 1.39 $FC $FFLAGS $DEFINES -c genmake_tcomp.f >> genmake_warnings 2>&1
454 edhill 1.31 RETVAL=$?
455     if test "x$RETVAL" != x0 ; then
456     FC_NAMEMANGLE=$default_nm
457 edhill 1.39 cat <<EOF>> genmake_warnings
458    
459     WARNING: FORTRAN test compile fails -- please see "genmake_errors"
460     WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
461     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
462     EOF
463 edhill 1.31 return 1
464     fi
465 edhill 1.43 f_tcall=`nm genmake_tcomp.o | grep 'T ' | grep tcall | cut -d ' ' -f 3`
466 edhill 1.31 RETVAL=$?
467     if test "x$RETVAL" != x0 ; then
468     FC_NAMEMANGLE=$default_nm
469 edhill 1.39 cat <<EOF>> genmake_warnings
470    
471     WARNING: The "nm" command failed.
472     WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
473     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
474     EOF
475 edhill 1.31 return 1
476     fi
477    
478     c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
479     f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
480     c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
481     f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
482    
483     nmangle="X"
484     if test "x$c_a" != "x$f_a" ; then
485     comm="echo x$f_a | sed -e 's|x$c_a||'"
486     a=`eval $comm`
487     nmangle="$a ## $nmangle"
488     fi
489     if test "x$c_b" != "x$f_b" ; then
490     comm="echo x$f_b | sed -e 's|x$c_b||'"
491     b=`eval $comm`
492     nmangle="$nmangle ## $b"
493     fi
494    
495     FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) $nmangle"
496 edhill 1.32
497     # cleanup the testing files
498     rm -f genmake_tcomp.* genmake_test.*
499 edhill 1.31 }
500 edhill 1.1
501 edhill 1.39
502     check_HAVE_CLOC() {
503     get_fortran_c_namemangling
504     cat <<EOF > genmake_tc_1.c
505     $FC_NAMEMANGLE
506     #include <stdio.h>
507     #include <stdlib.h>
508     #include <unistd.h>
509     #include <assert.h>
510     #include <sys/time.h>
511     void FC_NAMEMANGLE(cloc) ( double *curtim )
512     {
513     struct timeval tv1;
514     gettimeofday(&tv1 , (void *)NULL );
515     *curtim = (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
516     *curtim = *curtim/1.E6;
517     }
518     EOF
519     make genmake_tc_1.o >> genmake_tc.log 2>&1
520     RET_C=$?
521     cat <<EOF > genmake_tc_2.f
522     program hello
523     Real*8 wtime
524     external cloc
525     call cloc(wtime)
526     print *," HELLO WORLD", wtime
527     end program hello
528     EOF
529     $FC $FFLAGS -o genmake_tc genmake_tc_2.f genmake_tc_1.o >> genmake_tc.log 2>&1
530     RET_F=$?
531     test -x ./genmake_tc && ./genmake_tc >> genmake_tc.log 2>&1
532     RETVAL=$?
533     if test "x$RETVAL" = x0 ; then
534     HAVE_CLOC=t
535     DEFINES="$DEFINES -DHAVE_CLOC"
536     fi
537     rm -f genmake_tc*
538     }
539    
540    
541 edhill 1.60 check_netcdf_libs() {
542 edhill 1.75 cat <<EOF > genmake_tnc.for
543 edhill 1.60 program fgennc
544     #include "netcdf.inc"
545     integer iret, ncid, xid
546     iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
547     IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
548     iret = nf_def_dim(ncid, 'X', 11, xid)
549     IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
550     iret = nf_close(ncid)
551     IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
552     end
553     EOF
554 edhill 1.75 $CPP genmake_tnc.for > genmake_tnc.f \
555 edhill 1.60 && $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f $LIBS >> genmake_tnc.log 2>&1
556     RET_COMPILE=$?
557     test -x ./genmake_tnc && ./genmake_tnc >> genmake_tnc.log 2>&1
558     RETVAL=$?
559     if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
560     HAVE_NETCDF=t
561     else
562 edhill 1.66 # try again with "-lnetcdf" added to the libs
563 edhill 1.75 $CPP genmake_tnc.for > genmake_tnc.f \
564 edhill 1.66 && $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f \
565     $LIBS -lnetcdf >> genmake_tnc_2.log 2>&1
566     RET_COMPILE=$?
567     test -x ./genmake_tnc && ./genmake_tnc >> genmake_tnc.log 2>&1
568     RETVAL=$?
569     if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
570     LIBS="$LIBS -lnetcdf"
571     HAVE_NETCDF=t
572     else
573     cat genmake_tnc.log >> genmake_warnings
574     fi
575 edhill 1.60 fi
576     rm -f genmake_tnc*
577     }
578    
579    
580 adcroft 1.67
581     ###############################################################################
582     # Sequential part of script starts here
583     ###############################################################################
584    
585 edhill 1.1 # Set defaults here
586 edhill 1.5 COMMANDL="$0 $@"
587    
588 edhill 1.1 PLATFORM=
589     LN=
590     S64=
591     KPP=
592     FC=
593 edhill 1.60 CPP=
594 edhill 1.1 LINK=
595 edhill 1.31 DEFINES=
596 edhill 1.1 PACKAGES=
597     ENABLE=
598     DISABLE=
599     MAKEFILE=
600     MAKEDEPEND=
601     PDEPEND=
602 edhill 1.11 DUMPSTATE=t
603 edhill 1.1 PDEFAULT=
604     OPTFILE=
605 edhill 1.2 INCLUDES="-I."
606 edhill 1.1 FFLAGS=
607     FOPTIM=
608     CFLAGS=
609     KFLAGS1=
610     KFLAGS2=
611 edhill 1.70 #LDADD=
612 edhill 1.1 LIBS=
613     KPPFILES=
614     NOOPTFILES=
615     NOOPTFLAGS=
616 adcroft 1.67 MPI=
617     MPIPATH=
618 edhill 1.1
619 edhill 1.29 # DEFINES checked by test compilation
620     HAVE_SYSTEM=
621     HAVE_FDATE=
622     FC_NAMEMANGLE=
623 edhill 1.39 HAVE_CLOC=
624 edhill 1.60 HAVE_NETCDF=
625 edhill 1.29
626 edhill 1.1 MODS=
627     TOOLSDIR=
628     SOURCEDIRS=
629     INCLUDEDIRS=
630 edhill 1.57 STANDARDDIRS="USE_THE_DEFAULT"
631 edhill 1.1
632 edhill 1.73 G2ARGS=
633 edhill 1.71 BASH=
634 edhill 1.1 PWD=`pwd`
635     MAKE=make
636 edhill 1.15 AWK=awk
637 edhill 1.1 THISHOSTNAME=`hostname`
638     THISCWD=`pwd`
639     THISDATE=`date`
640     MACHINE=`uname -a`
641 edhill 1.7 EXECUTABLE=
642     EXEHOOK=
643     EXEDIR=
644 edhill 1.12 PACKAGES_CONF=
645     IEEE=
646     if test "x$MITGCM_IEEE" != x ; then
647     IEEE=$MITGCM_IEEE
648     fi
649 edhill 1.75 FEXT=
650     F90EXT=
651 edhill 1.1
652 edhill 1.14 AUTODIFF_PKG_USED=f
653     AD_OPTFILE=
654 edhill 1.17 TAF=
655     AD_TAF_FLAGS=
656     FTL_TAF_FLAGS=
657     SVD_TAF_FLAGS=
658     TAF_EXTRA=
659     TAMC=
660     AD_TAMC_FLAGS=
661     FTL_TAF_FLAGS=
662     SVD_TAMC_FLAGS=
663     TAMC_EXTRA=
664    
665 edhill 1.14
666 edhill 1.5 # The following state can be set directly by command-line switches
667 edhill 1.41 gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"
668 edhill 1.60 gm_s2="FC CPP IEEE MPI JAM DUMPSTATE STANDARDDIRS"
669 edhill 1.5
670     # The following state is not directly set by command-line switches
671     gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
672     gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
673     gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"
674 edhill 1.12 gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
675 edhill 1.29 gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE"
676 edhill 1.5
677 edhill 1.14 # The following are all related to adjoint/tangent-linear stuff
678 edhill 1.29 gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
679     gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
680     gm_s12="TAF_EXTRA TAMC_EXTRA"
681 edhill 1.14
682 edhill 1.29 gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"
683     gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
684 edhill 1.5
685 edhill 1.41 cat <<EOF
686    
687     GENMAKE :
688    
689     A program for GENerating MAKEfiles for the MITgcm project. For a
690     quick list of options, use "genmake -h" or for more detail see:
691    
692     http://mitgcm.org/devel_HOWTO/
693    
694     EOF
695 edhill 1.5
696 edhill 1.2 echo "=== Processing options files and arguments ==="
697 edhill 1.12 gm_local="genmake_local"
698     for i in . $MODS ; do
699     if test -r $i/$gm_local ; then
700 edhill 1.34 . $i/$gm_local
701 edhill 1.12 break
702     fi
703     done
704 edhill 1.71 printf " getting local config information: "
705 edhill 1.1 if test -e $gm_local ; then
706     echo "using $gm_local"
707 edhill 1.34 . $gm_local
708 edhill 1.2 # echo "DISABLE=$DISABLE"
709     # echo "ENABLE=$ENABLE"
710 edhill 1.1 else
711     echo "none found"
712     fi
713    
714     # echo "$0::$1:$2:$3:$4:$5:$6:$7:"
715 edhill 1.2 #OPTIONS=
716     #n=0
717     #for i ; do
718     # echo "$i $n"
719     # setvar="OPTIONS[$n]='$i'"
720     # # echo " $setvar"
721     # eval "$setvar"
722     # n=$(( $n + 1 ))
723     #done
724     #parse_options
725     ac_prev=
726     for ac_option ; do
727    
728 edhill 1.73 G2ARGS="$G2ARGS \"$ac_option\""
729    
730 edhill 1.2 # If the previous option needs an argument, assign it.
731     if test -n "$ac_prev"; then
732     eval "$ac_prev=\$ac_option"
733     ac_prev=
734     continue
735     fi
736    
737     ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
738    
739     case $ac_option in
740    
741     -help | --help | -h | --h)
742     usage ;;
743    
744     -nooptfile | --nooptfile)
745     OPTFILE="NONE" ;;
746     -optfile | --optfile | -of | --of)
747 edhill 1.4 ac_prev=OPTFILE ;;
748 edhill 1.2 -optfile=* | --optfile=* | -of=* | --of=*)
749     OPTFILE=$ac_optarg ;;
750    
751 edhill 1.50 -adoptfile | --adoptfile | -adof | --adof)
752 edhill 1.14 ac_prev=AD_OPTFILE ;;
753     -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
754     AD_OPTFILE=$ac_optarg ;;
755    
756 edhill 1.2 -pdepend | --pdepend)
757 edhill 1.4 ac_prev=PDEPEND ;;
758 edhill 1.2 -pdepend=* | --pdepend=*)
759     PDEPEND=$ac_optarg ;;
760    
761     -pdefault | --pdefault)
762 edhill 1.4 ac_prev=PDEFAULT ;;
763 edhill 1.2 -pdefault=* | --pdefault=*)
764     PDEFAULT=$ac_optarg ;;
765    
766 edhill 1.6 -make | --make | -m | --m)
767     ac_prev=MAKE ;;
768     -make=* | --make=* | -m=* | --m=*)
769     MAKE=$ac_optarg ;;
770 edhill 1.69
771 edhill 1.71 -bash | --bash)
772     ac_prev=BASH ;;
773     -bash=* | --bash=*)
774     BASH=$ac_optarg ;;
775    
776 edhill 1.69 -makedepend | --makedepend | -md | --md)
777     ac_prev=MAKEDEPEND ;;
778     -makedepend=* | --makedepend=* | -md=* | --md=*)
779     MAKEDEPEND=$ac_optarg ;;
780 edhill 1.6
781     -makefile | --makefile | -ma | --ma)
782 edhill 1.4 ac_prev=MAKEFILE ;;
783 edhill 1.6 -makefile=* | --makefile=* | -ma=* | --ma=*)
784 edhill 1.2 MAKEFILE=$ac_optarg ;;
785    
786 edhill 1.41 -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
787     echo "ERROR: The platform option has been removed. Please specify"
788     echo " the build options using the \"optfile\" mechanism."
789     echo
790     usage
791     ;;
792 edhill 1.2
793     -rootdir | --rootdir | -rd | --rd)
794 edhill 1.4 ac_prev=ROOTDIR ;;
795 edhill 1.2 -rootdir=* | --rootdir=* | -rd=* | --rd=*)
796     ROOTDIR=$ac_optarg ;;
797    
798     -mods | --mods | -mo | --mo)
799 edhill 1.4 ac_prev=MODS ;;
800 edhill 1.2 -mods=* | --mods=* | -mo=* | --mo=*)
801     MODS=$ac_optarg ;;
802    
803     -disable | --disable)
804 edhill 1.4 ac_prev=DISABLE ;;
805 edhill 1.2 -disable=* | --disable=*)
806     DISABLE=$ac_optarg ;;
807    
808     -enable | --enable)
809 edhill 1.4 ac_prev=ENABLE ;;
810 edhill 1.2 -enable=* | --enable=*)
811     ENABLE=$ac_optarg ;;
812    
813 edhill 1.12 -standarddirs | --standarddirs)
814     ac_prev=STANDARDDIRS ;;
815     -standarddirs=* | --standarddirs=*)
816     STANDARDDIRS=$ac_optarg ;;
817    
818 edhill 1.2 # -cpp | --cpp)
819     # ac_prev=cpp ;;
820     # -cpp=* | --cpp=*)
821     # CPP=$ac_optarg ;;
822    
823     -fortran | --fortran | -fc | --fc)
824 edhill 1.4 ac_prev=FC ;;
825 edhill 1.2 -fc=* | --fc=*)
826     FC=$ac_optarg ;;
827    
828     -ieee | --ieee)
829 edhill 1.12 IEEE=true ;;
830 edhill 1.2 -noieee | --noieee)
831 edhill 1.12 IEEE= ;;
832 adcroft 1.67
833     -mpi | --mpi)
834     MPI=true ;;
835     -mpi=* | --mpi=*)
836     MPIPATH=$ac_optarg
837     MPI=true ;;
838 edhill 1.2
839 edhill 1.41 # -jam | --jam)
840     # JAM=1 ;;
841     # -nojam | --nojam)
842     # JAM=0 ;;
843 edhill 1.2
844 edhill 1.5 -ds | --ds)
845     DUMPSTATE=t ;;
846    
847 edhill 1.17 -taf_extra | --taf_extra)
848     ac_prev=TAF_EXTRA ;;
849     -taf_extra=* | --taf_extra=*)
850     TAF_EXTRA=$ac_optarg ;;
851    
852     -tamc_extra | --tamc_extra)
853     ac_prev=TAMC_EXTRA ;;
854     -tamc_extra=* | --tamc_extra=*)
855     TAMC_EXTRA=$ac_optarg ;;
856    
857 edhill 1.2 -*)
858     echo "Error: unrecognized option: "$ac_option
859     usage
860     ;;
861    
862     *)
863     echo "Error: unrecognized argument: "$ac_option
864     usage
865     ;;
866    
867     esac
868    
869 edhill 1.1 done
870    
871 edhill 1.12 if test -f ./.genmakerc ; then
872     echo
873     echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
874     echo " file. This file format is no longer supported. Please see:"
875     echo
876     echo " http://mitgcm.org/devel_HOWTO/"
877     echo
878     echo " for directions on how to setup and use the new \"genmake2\" input"
879     echo " files and send an email to MITgcm-support@mitgcm.org if you want help."
880     echo
881     fi
882    
883 edhill 1.11 if test "x${ROOTDIR}" = x ; then
884     if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
885     ROOTDIR=".."
886     else
887     for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
888     if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
889     ROOTDIR=$d
890 edhill 1.71 printf "Warning: ROOTDIR was not specified but there appears to be"
891 edhill 1.11 echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
892     break
893     fi
894     done
895     fi
896     fi
897     if test "x${ROOTDIR}" = x ; then
898     echo "Error: Cannot determine ROOTDIR for MITgcm code."
899     echo " Please specify a ROOTDIR using either an options "
900     echo " file or a command-line option."
901     exit 1
902     fi
903     if test ! -d ${ROOTDIR} ; then
904     echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
905     exit 1
906     fi
907    
908 edhill 1.1 echo " getting OPTFILE information: "
909     if test "x${OPTFILE}" = x ; then
910 edhill 1.11 if test "x$MITGCM_OF" = x ; then
911     echo "Warning: no OPTFILE specified so we'll look for possible settings"
912     printf "\n=== Searching for possible settings for OPTFILE ===\n"
913     find_possible_configs
914 edhill 1.1 else
915 edhill 1.11 OPTFILE=$MITGCM_OF
916     fi
917     fi
918     if test "x$OPTFILE" != xNONE ; then
919     if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
920     echo " using OPTFILE=\"$OPTFILE\""
921 edhill 1.34 . "$OPTFILE"
922 edhill 1.11 RETVAL=$?
923     if test "x$RETVAL" != x0 ; then
924 edhill 1.71 printf "Error: failed to source OPTFILE \"$OPTFILE\""
925 edhill 1.11 echo "--please check that variable syntax is bash-compatible"
926 edhill 1.1 exit 1
927     fi
928 edhill 1.11 if test "x$DUMPSTATE" != xf ; then
929 edhill 1.12 cp -f $OPTFILE "genmake_optfile"
930 edhill 1.11 fi
931     else
932     echo "Error: can't read OPTFILE=\"$OPTFILE\""
933     exit 1
934 edhill 1.1 fi
935     fi
936 edhill 1.8
937 edhill 1.75 # Check for broken systems that cannot correctly distinguish *.F and *.f files
938     if test "x$FEXT" = x -a "x$F90EXT" = x ; then
939     check_for_broken_Ff
940     fi
941    
942 edhill 1.14 echo " getting AD_OPTFILE information: "
943     if test "x${AD_OPTFILE}" = x ; then
944     if test "x$MITGCM_AD_OF" = x ; then
945     AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
946     else
947     AD_OPTFILE=$MITGCM_AD_OF
948     fi
949     fi
950     if test "x${AD_OPTFILE}" != xNONE ; then
951     if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
952     echo " using AD_OPTFILE=\"$AD_OPTFILE\""
953 edhill 1.34 . "$AD_OPTFILE"
954 edhill 1.14 RETVAL=$?
955     if test "x$RETVAL" != x0 ; then
956 edhill 1.71 printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
957 edhill 1.14 echo "--please check that variable syntax is bash-compatible"
958     exit 1
959     fi
960     if test "x$DUMPSTATE" != xf ; then
961     cp -f $AD_OPTFILE "genmake_ad_optfile"
962     fi
963     else
964     echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
965     exit 1
966     fi
967     fi
968    
969 edhill 1.39 # Check that FC, LINK, CPP, S64, LN, and MAKE are defined. If not,
970     # either set defaults or complain and abort!
971 edhill 1.71 if test ! "x$BASH" = x ; then
972     # add a trailing space so that it works within the Makefile syntax (see below)
973     BASH="$BASH "
974     fi
975 edhill 1.8 if test "x$FC" = x ; then
976     cat <<EOF 1>&2
977    
978     Error: no Fortran compiler: please specify using one of the following:
979     1) within the options file ("FC=...") as specified by "-of=OPTFILE"
980     2) the "-fc=XXX" command-line option
981 edhill 1.12 3) the "./genmake_local" file
982 edhill 1.8 EOF
983     exit 1
984     fi
985     if test "x$LINK" = x ; then
986     LINK=$FC
987     fi
988 edhill 1.39 if test "x$MAKE" = x ; then
989     MAKE="make"
990     fi
991 edhill 1.63 if test "x$CPP" = x ; then
992     CPP=cpp
993     fi
994     #EH3 === UGLY ===
995     # The following an ugly little hack to check for $CPP in /lib/ and it
996     # should eventually be replaced with a more general function that
997     # searches a combo of the user's path and a list of "usual suspects"
998     # to find the correct location for binaries such as $CPP.
999     for i in " " "/lib/" ; do
1000     echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1001     done
1002     #EH3 === UGLY ===
1003 edhill 1.13 echo "#define A a" | $CPP > test_cpp 2>&1
1004 edhill 1.11 RETVAL=$?
1005     if test "x$RETVAL" != x0 ; then
1006 edhill 1.8 cat <<EOF 1>&2
1007    
1008 edhill 1.11 Error: C pre-processor "$CPP" failed the test case: please specify using:
1009    
1010 edhill 1.8 1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
1011 edhill 1.12 2) the "./genmake_local" file
1012 edhill 1.30 3) with the CPP environment variable
1013 edhill 1.11
1014 edhill 1.8 EOF
1015     exit 1
1016 edhill 1.11 else
1017     rm -f test_cpp
1018 edhill 1.8 fi
1019 edhill 1.11 if test "x$MAKEDEPEND" = x ; then
1020     MAKEDEPEND=makedepend
1021 edhill 1.8 fi
1022 edhill 1.35 if test "x$LN" = x ; then
1023     LN="ln -s"
1024     fi
1025     echo "test" > genmake_test_ln
1026     $LN genmake_test_ln genmake_tlink
1027     RETVAL=$?
1028     if test "x$RETVAL" != x0 ; then
1029     cat <<EOF 1>&2
1030 edhill 1.29
1031 edhill 1.35 Error: The command "ln -s" failed -- please specify a working soft-link
1032     command in the optfile.
1033    
1034     EOF
1035     exit 1
1036     fi
1037     rm -f genmake_test_ln genmake_tlink
1038 edhill 1.29
1039 adcroft 1.67 if test ! "x$MPI" = x ; then
1040     echo " Turning on MPI cpp macros"
1041 adcroft 1.68 DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
1042 adcroft 1.67 fi
1043 edhill 1.39
1044 edhill 1.29 printf "\n=== Checking system libraries ===\n"
1045 edhill 1.71 printf " Do we have the system() command using $FC... "
1046 edhill 1.29 cat > genmake_tcomp.f <<EOF
1047     program hello
1048     call system('echo hi')
1049     end
1050     EOF
1051     $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1
1052     RETVAL=$?
1053     if test "x$RETVAL" = x0 ; then
1054     HAVE_SYSTEM=t
1055     DEFINES="$DEFINES -DHAVE_SYSTEM"
1056     echo "yes"
1057     else
1058     HAVE_SYSTEM=
1059     echo "no"
1060     fi
1061     rm -f genmake_tcomp*
1062    
1063 edhill 1.71 printf " Do we have the fdate() command using $FC... "
1064 edhill 1.29 cat > genmake_tcomp.f <<EOF
1065     program hello
1066     CHARACTER(128) string
1067     string = ' '
1068     call fdate( string )
1069     print *, string
1070     end
1071     EOF
1072     $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1
1073     RETVAL=$?
1074     if test "x$RETVAL" = x0 ; then
1075     HAVE_FDATE=t
1076     DEFINES="$DEFINES -DHAVE_FDATE"
1077     echo "yes"
1078     else
1079     HAVE_FDATE=
1080     echo "no"
1081     fi
1082     rm -f genmake_tcomp*
1083    
1084 edhill 1.71 printf " Can we call simple C routines (here, \"cloc()\") using $FC... "
1085 edhill 1.39 check_HAVE_CLOC
1086     if test "x$HAVE_CLOC" != x ; then
1087     echo "yes"
1088     else
1089     echo "no"
1090 edhill 1.29 fi
1091 edhill 1.39 rm -f genmake_t*
1092 edhill 1.29
1093 edhill 1.71 printf " Can we create NetCDF-enabled binaries... "
1094 edhill 1.60 check_netcdf_libs
1095     if test "x$HAVE_NETCDF" != x ; then
1096     echo "yes"
1097     else
1098     echo "no"
1099     fi
1100    
1101 edhill 1.8
1102 edhill 1.2 printf "\n=== Setting defaults ===\n"
1103 edhill 1.71 printf " Adding MODS directories: "
1104 edhill 1.1 for d in $MODS ; do
1105     if test ! -d $d ; then
1106 edhill 1.2 echo
1107     echo "Error: MODS directory \"$d\" not found!"
1108 edhill 1.1 exit 1
1109     else
1110 edhill 1.71 printf " $d"
1111 edhill 1.1 SOURCEDIRS="$SOURCEDIRS $d"
1112     INCLUDEDIRS="$INCLUDEDIRS $d"
1113     fi
1114     done
1115     echo
1116    
1117     if test "x$MAKEFILE" = x ; then
1118     MAKEFILE="Makefile"
1119     fi
1120     if test "x${PLATFORM}" = x ; then
1121     PLATFORM=$p_PLATFORM
1122     fi
1123    
1124     if test "x${EXEDIR}" = x ; then
1125     if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then
1126     EXEDIR=../exe
1127     else
1128     EXEDIR=.
1129     fi
1130     fi
1131     if test ! -d ${EXEDIR} ; then
1132     echo "Error: the specified EXEDIR (\"$EXEDIR\") does not exist!"
1133     exit 1
1134     fi
1135    
1136     if test "x${TOOLSDIR}" = x ; then
1137     TOOLSDIR="$ROOTDIR/tools"
1138     fi
1139     if test ! -d ${TOOLSDIR} ; then
1140 cnh 1.65 echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
1141 edhill 1.1 exit 1
1142     fi
1143 edhill 1.11 if test "x$S64" = x ; then
1144     S64='$(TOOLSDIR)/set64bitConst.sh'
1145     fi
1146 adcroft 1.44 THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
1147 edhill 1.1
1148     EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1149    
1150     # We have a special set of source files in eesupp/src which are
1151     # generated from some template source files. We'll make them first so
1152     # they appear as regular source code
1153     if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
1154     echo " Making source files in eesupp from templates"
1155 edhill 1.36 ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1
1156 edhill 1.1 RETVAL=$?
1157 edhill 1.2 if test "x${RETVAL}" = x0 ; then
1158 edhill 1.1 rm -f make_eesupp.errors
1159     else
1160     echo "Error: problem encountered while building source files in eesupp:"
1161 edhill 1.62 cat make_eesupp.errors 1>&2
1162 edhill 1.1 exit 1
1163 afe 1.58 fi
1164     fi
1165    
1166     #same for exch2
1167     if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then
1168     echo " Making source files in exch2 from templates"
1169     ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1
1170     RETVAL=$?
1171     if test "x${RETVAL}" = x0 ; then
1172     rm -f make_exch2.errors
1173     else
1174 edhill 1.59 echo "Error: problem encountered while building source files in exch2:"
1175 edhill 1.62 cat make_exch2.errors 1>&2
1176 afe 1.58 exit 1
1177 edhill 1.1 fi
1178     fi
1179    
1180 edhill 1.2 printf "\n=== Determining package settings ===\n"
1181 edhill 1.1 if test "x${PDEPEND}" = x ; then
1182     tmp=$ROOTDIR"/pkg/pkg_depend"
1183     if test -r $tmp ; then
1184     PDEPEND=$tmp
1185     else
1186     echo "Warning: No package dependency information was specified."
1187     echo " Please check that ROOTDIR/pkg/pkg_depend exists."
1188     fi
1189     else
1190     if test ! -r ${PDEPEND} ; then
1191     echo "Error: can't read package dependency info from PDEPEND=\"$PDEPEND\""
1192     exit 1
1193     fi
1194     fi
1195     echo " getting package dependency info from $PDEPEND"
1196     # Strip the comments and then convert the dependency file into
1197     # two arrays: PNAME, DNAME
1198     cat $PDEPEND | sed -e 's/#.*$//g' \
1199 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}' \
1200 edhill 1.1 > ./.pd_tmp
1201     RETVAL=$?
1202     if test ! "x${RETVAL}" = x0 ; then
1203     echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
1204     exit 1
1205     fi
1206 edhill 1.34 . ./.pd_tmp
1207 edhill 1.1 rm -f ./.pd_tmp
1208    
1209 edhill 1.12 # Search for default packages. Note that a "$ROOTDIR/pkg/pkg_groups"
1210     # file should eventually be added so that, for convenience, one can
1211     # specify groups of packages using names like "ocean" and "atmosphere".
1212 edhill 1.41 echo " checking default package list: "
1213 edhill 1.1 if test "x${PDEFAULT}" = x ; then
1214 edhill 1.12 for i in "." $MODS ; do
1215     if test -r $i"/packages.conf" ; then
1216     PDEFAULT=$i"/packages.conf"
1217     break
1218     fi
1219     done
1220     fi
1221     if test "x${PDEFAULT}" = x ; then
1222 edhill 1.1 PDEFAULT="$ROOTDIR/pkg/pkg_default"
1223     fi
1224     if test "x${PDEFAULT}" = xNONE ; then
1225 edhill 1.41 echo " default packages file disabled"
1226 edhill 1.1 else
1227     if test ! -r $PDEFAULT ; then
1228     echo "Warning: can't read default packages from PDEFAULT=\"$PDEFAULT\""
1229     else
1230 edhill 1.41 echo " using PDEFAULT=\"$PDEFAULT\""
1231 edhill 1.1 # Strip the comments and add all the names
1232 edhill 1.15 def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
1233 edhill 1.1 RETVAL=$?
1234     if test "x${RETVAL}" != x0 ; then
1235 edhill 1.71 printf "Error: can't parse default package list "
1236 edhill 1.1 echo "-- please check PDEFAULT=\"$PDEFAULT\""
1237     exit 1
1238     fi
1239     for i in $def ; do
1240     PACKAGES="$PACKAGES $i"
1241     done
1242 edhill 1.12 echo " before group expansion packages are: $PACKAGES"
1243 adcroft 1.74 while ! expand_pkg_groups; do echo > /dev/null; done
1244 edhill 1.12 echo " after group expansion packages are: $PACKAGES"
1245 edhill 1.1 fi
1246     fi
1247    
1248     echo " applying DISABLE settings"
1249 adcroft 1.74 for i in $PACKAGES ; do
1250     echo $i >> ./.tmp_pack
1251     done
1252     for i in `grep "-" ./.tmp_pack` ; do
1253     j=`echo $i | sed 's/[-]//'`
1254     DISABLE="$DISABLE $j"
1255     done
1256 edhill 1.1 pack=
1257     for p in $PACKAGES ; do
1258     addit="t"
1259     for d in $DISABLE ; do
1260     if test "x$p" = "x$d" ; then
1261     addit="f"
1262     fi
1263     done
1264     if test "x$addit" = xt ; then
1265     pack="$pack $p"
1266     fi
1267     done
1268     PACKAGES="$pack"
1269     echo " applying ENABLE settings"
1270 edhill 1.12 echo "" > ./.tmp_pack
1271 edhill 1.1 PACKAGES="$PACKAGES $ENABLE"
1272 adcroft 1.74 # Test if each explicitly referenced package exists
1273 edhill 1.1 for i in $PACKAGES ; do
1274 adcroft 1.74 j=`echo $i | sed 's/[-+]//'`
1275     if test ! -d "$ROOTDIR/pkg/$j" ; then
1276 edhill 1.1 echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
1277 adcroft 1.74 exit 1
1278 edhill 1.1 fi
1279     echo $i >> ./.tmp_pack
1280     done
1281     PACKAGES=
1282 adcroft 1.74 for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do
1283 edhill 1.1 PACKAGES="$PACKAGES $i"
1284     done
1285 adcroft 1.74 rm -f ./.tmp_pack
1286 edhill 1.1 echo " packages are: $PACKAGES"
1287    
1288     echo " applying package dependency rules"
1289     ck=
1290     while test "x$ck" != xtt ; do
1291     i=0
1292 edhill 1.2 # rtot=${#PNAME[@]}
1293     rtot=$nname
1294 edhill 1.1 while test $i -lt $rtot ; do
1295    
1296     # Is $pname in the current $PACKAGES list?
1297 edhill 1.2 # pname=${PNAME[$i]}
1298     tmp="pname=\"\$PNAME_$i\""
1299     eval $tmp
1300 edhill 1.1 pin="f"
1301     for p in $PACKAGES ; do
1302     if test "x$p" = "x$pname" ; then
1303     pin="t"
1304     fi
1305     done
1306    
1307     # Is the DNAME entry a (+) or (-) rule ?
1308 edhill 1.2 tmp="dname=\"\$DNAME_$i\""
1309     eval $tmp
1310 edhill 1.1 plus="-"
1311 edhill 1.2 echo $dname | grep '^+' > /dev/null 2>&1
1312 edhill 1.1 RETVAL=$?
1313     if test "x$RETVAL" = x0 ; then
1314     plus="+"
1315     fi
1316    
1317     # Is $dname in the current $PACKAGES list?
1318 edhill 1.2 dname=`echo $dname | sed -e 's/^[+-]//'`
1319 edhill 1.1 din="f"
1320     for p in $PACKAGES ; do
1321     if test "x$p" = "x$dname" ; then
1322     din="t"
1323     fi
1324     done
1325    
1326     # Do we need to add $dname according to the dependency rules?
1327     if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then
1328     in_dis="f"
1329     for dis in $DISABLE ; do
1330     if test "x$dis" = "x$dname" ; then
1331     in_dis="t"
1332     fi
1333     done
1334     if test "x$in_dis" = xt ; then
1335     echo "Error: can't satisfy package dependencies:"
1336     echo " \"$dname\" is required by the dependency rules"
1337     echo " but is disallowed by the DISABLE settings"
1338     exit 1
1339     else
1340     PACKAGES="$PACKAGES $dname"
1341     ck=
1342     fi
1343     fi
1344    
1345     # Do we need to get rid of $dname according to the dependency rules?
1346     if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then
1347     echo "Error: can't satisfy package dependencies:"
1348     echo " \"$pname\" was requested but is disallowed by"
1349     echo " the dependency rules for \"$dname\""
1350     exit 1
1351     fi
1352     i=$(( $i + 1 ))
1353     done
1354     ck=$ck"t"
1355     done
1356     echo " packages are: $PACKAGES"
1357     for i in $PACKAGES ; do
1358     adr="$ROOTDIR/pkg/$i"
1359     if test -d $adr ; then
1360     SOURCEDIRS="$SOURCEDIRS $adr"
1361     INCLUDEDIRS="$INCLUDEDIRS $adr"
1362 edhill 1.14 if test "x$i" = xautodiff ; then
1363     AUTODIFF_PKG_USED=t
1364     fi
1365 edhill 1.1 else
1366     echo "Error: the directory \"$adr\" for package $i doesn't exist"
1367     exit 1
1368     fi
1369     done
1370    
1371 edhill 1.62 # Build MNC templates and check for ability to build and use NetCDF
1372 edhill 1.60 echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1
1373     RETVAL=$?
1374 edhill 1.62 if test "x$RETVAL" = x0 ; then
1375     ( cd $ROOTDIR"/pkg/mnc" && $MAKE templates ) > make_mnc.errors 2>&1
1376     RETVAL=$?
1377     if test "x${RETVAL}" = x0 ; then
1378     rm -f make_mnc.errors
1379     else
1380     echo "Error: problem encountered while building source files in pkg/mnc:"
1381     cat make_mnc.errors 1>&2
1382     exit 1
1383     fi
1384 edhill 1.64 if test "x$HAVE_NETCDF" != xt ; then
1385 edhill 1.62 cat <<EOF
1386 edhill 1.60
1387     WARNING: the "mnc" package has been enabled but tests failed to
1388     compile and/or execute NetCDF applications. Please check that:
1389    
1390     1) NetCDF is installed for your compiler and
1391     2) the LIBS variable (within the 'optfile") specifies the correct
1392     NetCDF library to link against.
1393    
1394     EOF
1395 edhill 1.62 fi
1396 edhill 1.60 fi
1397 edhill 1.1
1398 edhill 1.12 # Create a list of #define and #undef to enable/disable packages
1399     PACKAGES_DOT_H=PACKAGES_CONFIG.h
1400 edhill 1.1 # The following UGLY HACK sets multiple "#undef"s and it needs to go
1401     # away. On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
1402     # file would eventually be split up so that all package-related #define
1403     # statements could be separated and handled only by genmake.
1404     names=`ls -1 "$ROOTDIR/pkg"`
1405     all_pack=
1406 adcroft 1.44 DISABLED_PACKAGES=
1407 edhill 1.1 for n in $names ; do
1408     if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
1409     has_pack="f"
1410     for pack in $PACKAGES ; do
1411     if test "x$pack" = "x$n" ; then
1412     has_pack="t"
1413     break
1414     fi
1415     done
1416     if test "x$has_pack" = xf ; then
1417 edhill 1.15 undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`
1418 adcroft 1.44 DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
1419 edhill 1.1 fi
1420     fi
1421     done
1422 adcroft 1.44 ENABLED_PACKAGES=
1423 edhill 1.1 for i in $PACKAGES ; do
1424 edhill 1.15 def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`
1425 adcroft 1.44 ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
1426 edhill 1.12 #eh3 DEFINES="$DEFINES -D$def"
1427 edhill 1.1
1428     #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
1429     case $i in
1430     aim_v23)
1431 adcroft 1.46 ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
1432 jmc 1.55 echo "Warning: ALLOW_AIM is set to enable aim_v23."
1433 edhill 1.1 ;;
1434     esac
1435     #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
1436    
1437     done
1438    
1439     echo " Adding STANDARDDIRS"
1440     BUILDDIR=${BUILDDIR:-.}
1441 edhill 1.57 if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
1442 edhill 1.12 STANDARDDIRS="eesupp model"
1443     fi
1444 edhill 1.57 if test "x$STANDARDDIRS" != x ; then
1445     for d in $STANDARDDIRS ; do
1446     adr="$ROOTDIR/$d/src"
1447     if test ! -d $adr ; then
1448     echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1449     echo " is correct and that you correctly specified the STANDARDDIRS option"
1450     exit 1
1451     else
1452     SOURCEDIRS="$SOURCEDIRS $adr"
1453     fi
1454     adr="$ROOTDIR/$d/inc"
1455     if test ! -d $adr ; then
1456     echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1457     echo " is correct and that you correctly specified the STANDARDDIRS option"
1458     exit 1
1459     else
1460     INCLUDEDIRS="$INCLUDEDIRS $adr"
1461     fi
1462     done
1463     fi
1464 edhill 1.1
1465 adcroft 1.52 echo " Searching for *OPTIONS.h files in order to warn about the presence"
1466     echo " of \"#define \"-type statements that are no longer allowed:"
1467 edhill 1.12 CPP_OPTIONS=
1468 adcroft 1.52 CPP_EEOPTIONS=
1469 edhill 1.12 spaths=". $INCLUDEDIRS"
1470 adcroft 1.52 names=`ls -1 "$ROOTDIR/pkg"`
1471 edhill 1.12 for i in $spaths ; do
1472     try="$i/CPP_OPTIONS.h"
1473 edhill 1.54 if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
1474 edhill 1.12 echo " found CPP_OPTIONS=\"$try\""
1475     CPP_OPTIONS="$try"
1476 adcroft 1.52 # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
1477     for n in $names ; do
1478     test_for_package_in_cpp_options $CPP_OPTIONS $n
1479     done
1480     fi
1481     try="$i/CPP_EEOPTIONS.h"
1482 edhill 1.54 if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
1483 adcroft 1.52 echo " found CPP_EEOPTIONS=\"$try\""
1484     # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
1485     #**** not yet enabled ****
1486     # test_for_mpi_in_cpp_eeoptions $try
1487     #**** not yet enabled ****
1488     CPP_EEOPTIONS="$try"
1489 edhill 1.12 fi
1490     done
1491     if test "x$CPP_OPTIONS" = x ; then
1492     echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
1493     exit 1
1494     fi
1495 edhill 1.1
1496 edhill 1.14 # Here, we build the list of files to be "run through" the adjoint
1497     # compiler.
1498     if test -f ./ad_files ; then
1499     rm -f ./ad_files
1500     fi
1501     echo " Creating the list of files for the adjoint compiler."
1502     for i in $SOURCEDIRS ; do
1503     list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
1504     for j in $list_files ; do
1505     cat $i/$j >> ad_files
1506     done
1507     done
1508 edhill 1.60
1509 edhill 1.14
1510 edhill 1.2 echo
1511     echo "=== Creating the Makefile ==="
1512 edhill 1.1 echo " setting INCLUDES"
1513     for i in $INCLUDEDIRS ; do
1514 edhill 1.12 if ! test -d $i ; then
1515     # INCLUDES="$INCLUDES -I$i"
1516     # else
1517 edhill 1.1 echo "Warning: can't find INCLUDEDIRS=\"$i\""
1518     fi
1519     done
1520    
1521     echo " Determining the list of source and include files"
1522     rm -rf .links.tmp
1523     mkdir .links.tmp
1524     echo "# This section creates symbolic links" > srclinks.tmp
1525     echo "" >> srclinks.tmp
1526 edhill 1.71 printf 'SRCFILES = ' > srclist.inc
1527     printf 'CSRCFILES = ' > csrclist.inc
1528     printf 'F90SRCFILES = ' > f90srclist.inc
1529     printf 'HEADERFILES = ' > hlist.inc
1530     printf 'AD_FLOW_FILES = ' > ad_flow_files.inc
1531 adcroft 1.9 alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1532 edhill 1.1 for d in $alldirs ; do
1533     deplist=
1534 edhill 1.14 sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
1535 cnh 1.3 sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
1536 edhill 1.1 for sf in $sfiles ; do
1537     if test ! -r ".links.tmp/$sf" ; then
1538     if test -f "$d/$sf" ; then
1539 adcroft 1.44 case $d/$sf in
1540     ./$PACKAGES_DOT_H)
1541     ;;
1542     ./AD_CONFIG.h)
1543     ;;
1544     ./FC_NAMEMANGLE.h)
1545     ;;
1546     *)
1547     touch .links.tmp/$sf
1548     deplist="$deplist $sf"
1549     ;;
1550     esac
1551 edhill 1.15 extn=`echo $sf | $AWK -F '.' '{print $NF}'`
1552 edhill 1.1 case $extn in
1553     F)
1554     echo " \\" >> srclist.inc
1555 edhill 1.71 printf " $sf" >> srclist.inc
1556 edhill 1.1 ;;
1557 cnh 1.3 F90)
1558     echo " \\" >> f90srclist.inc
1559 edhill 1.71 printf " $sf" >> f90srclist.inc
1560 cnh 1.3 ;;
1561 edhill 1.1 c)
1562     echo " \\" >> csrclist.inc
1563 edhill 1.71 printf " $sf" >> csrclist.inc
1564 edhill 1.1 ;;
1565     h)
1566     echo " \\" >> hlist.inc
1567 edhill 1.71 printf " $sf" >> hlist.inc
1568 edhill 1.1 ;;
1569 edhill 1.14 flow)
1570     echo " \\" >> ad_flow_files.inc
1571 edhill 1.71 printf " $sf" >> ad_flow_files.inc
1572 edhill 1.14 ;;
1573 edhill 1.1 esac
1574     fi
1575     fi
1576     done
1577     if test "x$deplist" != x ; then
1578 edhill 1.2 echo "" >> srclinks.tmp
1579     echo "# These files are linked from $d" >> srclinks.tmp
1580 edhill 1.1 echo "$deplist :" >> srclinks.tmp
1581 edhill 1.2 printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp
1582 edhill 1.1 fi
1583     done
1584     rm -rf .links.tmp
1585     echo "" >> srclist.inc
1586     echo "" >> csrclist.inc
1587 cnh 1.3 echo "" >> f90srclist.inc
1588 edhill 1.1 echo "" >> hlist.inc
1589 edhill 1.14 echo "" >> ad_flow_files.inc
1590 edhill 1.1
1591     if test -e $MAKEFILE ; then
1592     mv -f $MAKEFILE "$MAKEFILE.bak"
1593     fi
1594     echo " Writing makefile: $MAKEFILE"
1595     echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
1596     echo "# $MACHINE" >> $MAKEFILE
1597     echo "# This makefile was generated automatically on" >> $MAKEFILE
1598     echo "# $THISDATE" >> $MAKEFILE
1599     echo "# by the command:" >> $MAKEFILE
1600 edhill 1.73 echo "# $0 $G2ARGS" >> $MAKEFILE
1601 edhill 1.1 echo "# executed by:" >> $MAKEFILE
1602     echo "# $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE
1603 edhill 1.21
1604     EXE_AD=$EXECUTABLE"_ad"
1605     EXE_FTL=$EXECUTABLE"_ftl"
1606     EXE_SVD=$EXECUTABLE"_svd"
1607    
1608 edhill 1.1 cat >>$MAKEFILE <<EOF
1609 edhill 1.53 #
1610     # OPTFILE="$OPTFILE"
1611 edhill 1.1 #
1612     # BUILDDIR : Directory where object files are written
1613     # SOURCEDIRS : Directories containing the source (.F) files
1614     # INCLUDEDIRS : Directories containing the header-source (.h) files
1615     # EXEDIR : Directory where executable that is generated is written
1616     # EXECUTABLE : Full path of executable binary
1617     #
1618     # CPP : C-preprocessor command
1619     # INCLUDES : Directories searched for header files
1620     # DEFINES : Macro definitions for CPP
1621     # MAKEDEPEND : Dependency generator
1622     # KPP : Special preprocessor command (specific to platform)
1623     # KFLAGS : Flags for KPP
1624     # FC : Fortran compiler command
1625     # FFLAGS : Configuration/debugging options for FC
1626     # FOPTIM : Optimization options for FC
1627     # LINK : Command for link editor program
1628     # LIBS : Library flags /or/ additional optimization/debugging flags
1629    
1630     ROOTDIR = ${ROOTDIR}
1631     BUILDDIR = ${BUILDDIR}
1632     SOURCEDIRS = ${SOURCEDIRS}
1633     INCLUDEDIRS = ${INCLUDEDIRS}
1634     EXEDIR = ${EXEDIR}
1635     EXECUTABLE = \$(EXEDIR)/${EXECUTABLE}
1636     TOOLSDIR = ${TOOLSDIR}
1637    
1638 edhill 1.14 #eh3 new defines for the adjoint work
1639     AUTODIFF = ${ROOTDIR}/pkg/autodiff
1640 edhill 1.21 EXE_AD = ${EXE_AD}
1641     EXE_FTL = ${EXE_FTL}
1642     EXE_SVD = ${EXE_SVD}
1643 edhill 1.14
1644 adcroft 1.44 ENABLED_PACKAGES = ${ENABLED_PACKAGES}
1645     DISABLED_PACKAGES = ${DISABLED_PACKAGES}
1646    
1647 adcroft 1.52 # These files are created by Makefile
1648     SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h
1649    
1650 edhill 1.1 EOF
1651    
1652     # Note: figure out some way to add Hyades JAM libraries here
1653    
1654     cat >>$MAKEFILE <<EOF
1655     # Unix ln (link)
1656     LN = ${LN}
1657     # C preprocessor
1658     CPP = cat \$< | ${S64} | ${CPP}
1659     # Dependency generator
1660     MAKEDEPEND = ${MAKEDEPEND}
1661     # Special preprocessor (KAP on DECs, FPP on Crays)
1662     KPP = ${KPP}
1663     # Fortran compiler
1664     FC = ${FC}
1665 cnh 1.3 # Fortran compiler
1666     F90C = ${F90C}
1667 edhill 1.1 # Link editor
1668 edhill 1.70 LINK = ${LINK} ${LDADD}
1669 edhill 1.1
1670     # Defines for CPP
1671     DEFINES = ${DEFINES}
1672     # Includes for CPP
1673     INCLUDES = ${INCLUDES}
1674     # Flags for KPP
1675     KFLAGS1 = ${KFLAGS1}
1676     KFLAGS2 = ${KFLAGS2}
1677     # Optim./debug for FC
1678     FFLAGS = ${FFLAGS}
1679     FOPTIM = ${FOPTIM}
1680 cnh 1.3 # Optim./debug for FC
1681     F90FLAGS = ${F90FLAGS}
1682     F90OPTIM = ${F90OPTIM}
1683 edhill 1.1 # Flags for CC
1684     CFLAGS = ${CFLAGS}
1685     # Files that should not be optimized
1686     NOOPTFILES = ${NOOPTFILES}
1687     NOOPTFLAGS = ${NOOPTFLAGS}
1688     # Flags and libraries needed for linking
1689     LIBS = ${LIBS} \$(XLIBS)
1690 cnh 1.3 # Name of the Mekfile
1691     MAKEFILE=${MAKEFILE}
1692 edhill 1.1
1693     EOF
1694    
1695 edhill 1.14 cat srclist.inc >> $MAKEFILE
1696     cat csrclist.inc >> $MAKEFILE
1697     cat f90srclist.inc >> $MAKEFILE
1698     cat hlist.inc >> $MAKEFILE
1699     cat ad_flow_files.inc >> $MAKEFILE
1700 edhill 1.75 echo >> $MAKEFILE
1701     echo 'F77FILES = $(SRCFILES:.'$FEXT'=.f)' >> $MAKEFILE
1702     echo 'F90FILES = $(F90SRCFILES:.'$F90EXT'=.f90)' >> $MAKEFILE
1703     echo 'OBJFILES = $(SRCFILES:.'$FEXT'=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.'$F90EXT'=.o)' >> $MAKEFILE
1704     echo >> $MAKEFILE
1705     echo '.SUFFIXES:' >> $MAKEFILE
1706     echo '.SUFFIXES: .o .f .p .'$FEXT' .c .'$F90EXT' .f90' >> $MAKEFILE
1707 edhill 1.1
1708 cnh 1.3 rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc
1709 edhill 1.14 rm -f ad_flow_files.inc
1710 edhill 1.1
1711     cat >>$MAKEFILE <<EOF
1712    
1713     all: \$(EXECUTABLE)
1714 adcroft 1.52 \$(EXECUTABLE): \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(OBJFILES)
1715 adcroft 1.44 @echo Creating \$@ ...
1716 edhill 1.1 \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
1717     depend:
1718     @make links
1719     \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
1720 adcroft 1.44 \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
1721 edhill 1.72 -rm -f makedepend.out
1722 edhill 1.1
1723 adcroft 1.52 links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES)
1724 edhill 1.1
1725 cnh 1.3 small_f: \$(F77FILES) \$(F90FILES)
1726 edhill 1.1
1727     output.txt: \$(EXECUTABLE)
1728     @printf 'running ... '
1729     @\$(EXECUTABLE) > \$@
1730    
1731     clean:
1732 adcroft 1.44 -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl} *.template
1733 edhill 1.1 Clean:
1734     @make clean
1735     @make cleanlinks
1736 adcroft 1.52 -rm -f \$(SPECIAL_FILES)
1737 adcroft 1.51 -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak
1738 edhill 1.1 CLEAN:
1739     @make Clean
1740     -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
1741     -find \$(EXEDIR) -name "*.data" -exec rm {} \;
1742     -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
1743 edhill 1.12 -rm -f \$(EXECUTABLE) output.txt
1744 edhill 1.1
1745 edhill 1.18 #eh3 Makefile: makefile
1746 edhill 1.1 makefile:
1747 edhill 1.73 $THIS_SCRIPT $G2ARGS
1748 edhill 1.1 cleanlinks:
1749     -find . -type l -exec rm {} \;
1750    
1751 adcroft 1.52 # Special targets ($SPECIAL_FILES) which are create by make
1752 adcroft 1.44 ${PACKAGES_DOT_H}:
1753     @echo Creating \$@ ...
1754 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) > \$@
1755 adcroft 1.44 AD_CONFIG.h:
1756     @echo Creating \$@ ...
1757 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 > \$@
1758 adcroft 1.52 FC_NAMEMANGLE.h:
1759     @echo Creating \$@ ...
1760     echo "$FC_NAMEMANGLE" > \$@
1761 adcroft 1.44
1762 edhill 1.75 # The normal chain of rules is ( .$FEXT - .f - .o )
1763     .$FEXT.f:
1764 edhill 1.1 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1765     .f.o:
1766     \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
1767 edhill 1.75 .$F90EXT.f90:
1768 cnh 1.3 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1769     .f90.o:
1770     \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
1771 edhill 1.1 .c.o:
1772     \$(CC) \$(CFLAGS) -c \$<
1773    
1774 edhill 1.75 # Special exceptions that use the ( .$FEXT - .p - .f - .o ) rule-chain
1775     .$FEXT.p:
1776 edhill 1.1 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1777     .p.f:
1778     \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
1779 edhill 1.14
1780     #=========================================
1781     #=== Automatic Differentiation Rules ===
1782    
1783     TAMC = ${TAMC}
1784     TAF = ${TAF}
1785    
1786 edhill 1.17 TAF_EXTRA = ${TAF_EXTRA}
1787     TAMC_EXTRA = ${TAMC_EXTRA}
1788    
1789 edhill 1.14 EOF
1790    
1791     ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
1792     ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF_FLAGS"
1793     ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
1794     for i in $ad_vars ; do
1795     name=$i
1796     t1="t2=\$"`echo $i`
1797     eval $t1
1798     printf "%-20s = " $name >> $MAKEFILE
1799     echo $t2 >> $MAKEFILE
1800     done
1801    
1802     echo " Add the source list for AD code generation"
1803     echo >> $MAKEFILE
1804 edhill 1.71 printf "AD_FILES = " >> $MAKEFILE
1805 edhill 1.14 AD_FILES=`cat ad_files`
1806     for i in $AD_FILES ; do
1807     echo " \\" >> $MAKEFILE
1808 edhill 1.71 printf " $i" >> $MAKEFILE
1809 edhill 1.14 done
1810     echo >> $MAKEFILE
1811 edhill 1.21 rm -f ad_files
1812 edhill 1.14
1813     cat >>$MAKEFILE <<EOF
1814    
1815 edhill 1.16 # ... AD ...
1816 edhill 1.23 adall: ad_taf
1817     adtaf: ad_taf_output.f
1818     adtamc: ad_tamc_output.f
1819 edhill 1.21
1820 heimbach 1.48 ad_input_code.f: \$(AD_FILES) \$(HEADERFILES)
1821 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
1822 edhill 1.23 cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
1823 adcroft 1.44 -rm -f ad_config.template
1824 edhill 1.22 @make \$(F77FILES)
1825     @make \$(AD_FLOW_FILES)
1826     cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f
1827    
1828 edhill 1.14 ad_taf_output.f: ad_input_code.f
1829 heimbach 1.37 \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1830 adcroft 1.44 cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f
1831 heimbach 1.37
1832     adtafonly:
1833 edhill 1.17 \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1834 adcroft 1.44 cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f
1835 edhill 1.14
1836     ad_taf: ad_taf_output.o \$(OBJFILES)
1837 edhill 1.21 \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
1838 edhill 1.14
1839     ad_tamc_output.f: ad_input_code.f
1840 edhill 1.17 \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f
1841 adcroft 1.44 cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.f
1842 edhill 1.14
1843     ad_tamc: ad_tamc_output.o \$(OBJFILES)
1844 edhill 1.21 \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
1845 edhill 1.14
1846    
1847 edhill 1.19 # ... FTL ...
1848 edhill 1.23 ftlall: ftl_taf
1849     ftltaf: ftl_taf_output.f
1850     ftltamc: ftl_tamc_output.f
1851 edhill 1.21
1852 heimbach 1.48 ftl_input_code.f: \$(AD_FILES) \$(HEADERFILES)
1853 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
1854 edhill 1.23 cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
1855 adcroft 1.44 -rm -f ftl_config.template
1856 edhill 1.23 @make \$(F77FILES)
1857 edhill 1.22 @make \$(AD_FLOW_FILES)
1858     cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f
1859    
1860     ftl_taf_output.f: ftl_input_code.f
1861     \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f
1862 adcroft 1.44 cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f
1863 edhill 1.14
1864 heimbach 1.40 ftltafonly:
1865     \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f
1866 adcroft 1.44 cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f
1867 heimbach 1.40
1868 edhill 1.19 ftl_taf: ftl_taf_output.o \$(OBJFILES)
1869 edhill 1.21 \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
1870 edhill 1.14
1871 edhill 1.22 ftl_tamc_output.f: ftl_input_code.f
1872     \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f
1873 adcroft 1.44 cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.f
1874 edhill 1.16
1875 edhill 1.19 ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
1876 edhill 1.21 \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
1877 edhill 1.16
1878    
1879     # ... SVD ...
1880 heimbach 1.40 svdtaf: ad_taf_output.f ftl_taf_output.f
1881     svdall: svd_taf
1882 edhill 1.16
1883 heimbach 1.40 svd_taf: ad_taf_output.o ftl_taf_output.o \$(OBJFILES)
1884     \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
1885 edhill 1.14
1886    
1887     #=========================================
1888 edhill 1.1
1889     EOF
1890 edhill 1.7
1891     if test "x$EXEHOOK" != x ; then
1892     printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
1893     fi
1894 edhill 1.1
1895     echo " Making list of \"exceptions\" that need \".p\" files"
1896     for i in $KPPFILES ; do
1897     base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
1898     RETVAL=$?
1899     if test "x$RETVAL" != x0 ; then
1900     echo "Error: unable to add file \"$i\" to the exceptions list"
1901     fi
1902     echo "$base.f: $base.p" >> $MAKEFILE
1903     done
1904    
1905     echo " Making list of NOOPTFILES"
1906     for i in $NOOPTFILES ; do
1907     base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
1908     RETVAL=$?
1909     if test "x$RETVAL" != x0 ; then
1910     echo "Error: unable to add file \"$i\" to the exceptions list"
1911     fi
1912     echo "$base.o: $base.f" >> $MAKEFILE
1913 edhill 1.2 printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
1914 edhill 1.1 done
1915    
1916     echo " Add rules for links"
1917     cat srclinks.tmp >> $MAKEFILE
1918     rm -f srclinks.tmp
1919    
1920     echo " Adding makedepend marker"
1921 edhill 1.2 printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
1922 edhill 1.1
1923 edhill 1.2 printf "\n=== Done ===\n"
1924 adcroft 1.47
1925     # Create special header files
1926 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"
1927 adcroft 1.47 if test ! -f $PACKAGES_DOT_H ; then
1928     mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
1929     else
1930 edhill 1.61 cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
1931 adcroft 1.47 RETVAL=$?
1932     if test "x$RETVAL" = x0 ; then
1933     rm -f $PACKAGES_DOT_H".tmp"
1934     else
1935     mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
1936     mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
1937     fi
1938     fi
1939     if test ! -f AD_CONFIG.h ; then
1940 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
1941 adcroft 1.47 fi
1942 edhill 1.5
1943    
1944     # Write the "state" for future records
1945     if test "x$DUMPSTATE" != xf ; then
1946 edhill 1.71 printf "" > genmake_state
1947 edhill 1.5 for i in $gm_state ; do
1948     t1="t2=\$$i"
1949     eval $t1
1950 edhill 1.12 echo "$i='$t2'" >> genmake_state
1951 edhill 1.5 done
1952     fi

  ViewVC Help
Powered by ViewVC 1.1.22