/[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.45 - (hide annotations) (download)
Mon Nov 24 15:08:24 2003 UTC (15 years, 8 months ago) by heimbach
Branch: MAIN
Changes since 1.44: +3 -3 lines
adding 'links' to adall ftlall dependency list

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

  ViewVC Help
Powered by ViewVC 1.1.22