/[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.23 - (hide annotations) (download)
Fri Oct 24 05:52:05 2003 UTC (20 years, 5 months ago) by edhill
Branch: MAIN
CVS Tags: checkpoint51o_pre, checkpoint51o_post
Changes since 1.22: +23 -24 lines
 o check-in of all PH's changes: continued efforts to get the adjoint
   working with genmake2

1 edhill 1.1 #!/bin/bash
2     #
3 edhill 1.23 # $Header: /u/u3/gcmpack/MITgcm/tools/genmake2,v 1.22 2003/10/23 04:41:41 edhill Exp $
4 edhill 1.1 #
5     # Makefile generator for MITgcm UV codes
6     # created by cnh 03/98
7     # adapted by aja 06/98
8     # modified by aja 01/00
9     # rewritten in bash by eh3 08/03
10    
11 edhill 1.12 # Search for particular CPP #cmds associated with packages
12     # usage: test_for_package_in_cpp_options CPP_file package_name
13     test_for_package_in_cpp_options() {
14     cpp_options=$1
15     pkg=$2
16     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.12 PLATFORM=`echo $tmp2 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
76 edhill 1.11 OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
77     echo " The platform appears to be: $PLATFORM"
78     # if test "x$OFLIST" = x ; then
79     # echo " No pre-defined options files were found matching this platform"
80     # echo " but examples for other platforms can be found in:"
81     # echo " $ROOTDIR/tools/build_options"
82     # else
83     # echo " Options files (located in $ROOTDIR/tools/build_options) that"
84     # echo " may work with this machine are:"
85     # for i in $OFLIST ; do
86     # echo " $i"
87     # done
88     # fi
89    
90 edhill 1.1 echo "test" > test
91     ln -s ./test link
92     RETVAL=$?
93     if test "x${RETVAL}" = x0 ; then
94 edhill 1.11 LN="ln -s"
95     else
96     echo "Error: \"ln -s\" does not appear to work on this system!"
97     echo " For help, please contact <MITgcm-support@mitgcm.org>."
98     exit 1
99 edhill 1.1 fi
100     rm -f test link
101    
102 edhill 1.11 if test "x$CPP" = x ; then
103     CPP="cpp -traditional -P"
104 edhill 1.1 fi
105    
106     # look for possible fortran compilers
107 edhill 1.11 tmp="$MITGCM_FC $FC 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     source ./.pd_tmp
209     rm -f ./.pd_tmp
210    
211     echo -n "PNAME = "${}
212     }
213    
214    
215     # Explain usage
216     usage() {
217 edhill 1.2 echo
218 edhill 1.1 echo "Usage: "$0" [OPTIONS]"
219 edhill 1.2 echo " where [OPTIONS] can be:"
220     echo
221 edhill 1.1 echo " -help | --help | -h | --h"
222     echo " -nooptfile | --nooptfile"
223     echo " -optfile NAME | --optfile NAME | -of NAME | --of NAME"
224     echo " -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME"
225     echo " -pdepend NAME | --pdepend NAME"
226     echo " -pdepend=NAME | --pdepend=NAME"
227     echo " -pdefault NAME | --pdefault NAME"
228     echo " -pdefault=NAME | --pdefault=NAME"
229 edhill 1.6 echo " -make NAME | -m NAME"
230     echo " --make=NAME | -m=NAME"
231     echo " -makefile NAME | -mf NAME"
232     echo " --makefile=NAME | -mf=NAME"
233 edhill 1.1 echo " -platform NAME | --platform NAME | -pl NAME | --pl NAME"
234     echo " -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"
235     echo " -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"
236     echo " -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME"
237     echo " -mods NAME | --mods NAME | -mo NAME | --mo NAME"
238     echo " -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME"
239     echo " -disable NAME | --disable NAME"
240     echo " -disable=NAME | --disable=NAME"
241     echo " -enable NAME | --enable NAME"
242     echo " -enable=NAME | --enable=NAME"
243 edhill 1.12 echo " -standarddirs NAME | --standarddirs NAME"
244     echo " -standarddirs=NAME | --standarddirs=NAME"
245 edhill 1.1 echo " -noopt NAME | --noopt NAME"
246     echo " -noopt=NAME | --noopt=NAME"
247     # echo " -cpp NAME | --cpp NAME"
248     # echo " -cpp=NAME | --cpp=NAME"
249     echo " -fortran NAME | --fortran NAME | -fc NAME | --fc NAME"
250     echo " -fc=NAME | --fc=NAME"
251     echo " -[no]ieee | --[no]ieee"
252     echo " -[no]mpi | --[no]mpi"
253 edhill 1.2 echo " -[no]jam | --[no]jam"
254     echo
255     echo " and NAME is a string such as:"
256     echo
257 edhill 1.1 echo " --enable pkg1 --enable 'pkg1 pkg2' --enable 'pkg1 pkg2 pkg3'"
258     echo " -mods=dir1 -mods='dir1' -mods='dir1 dir2 dir3'"
259 edhill 1.2 echo " -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"
260     echo
261 edhill 1.1 echo " which, depending upon your shell, may need to be single-quoted"
262     echo " if it contains spaces, dashes, or other special characters."
263     exit 1
264     }
265    
266     #eh3 # This is the generic configuration.
267     #eh3 set LN = ( 'ln -s' )
268     #eh3 set CPP = ( '/lib/cpp -P' )
269     #eh3 set S64 = ( '$(TOOLSDIR)/set64bitConst.sh' )
270     #eh3 set KPP = ( )
271     #eh3 set FC = ( 'f77' )
272     #eh3 set LINK = $FC
273     #eh3 set MAKEDEPEND = ( 'makedepend' )
274     #eh3 set INCLUDES = ( -I. )
275     #eh3 set FFLAGS = ( )
276     #eh3 set FOPTIM = ( )
277     #eh3 set CFLAGS = ( )
278     #eh3 set KFLAGS1 = ( )
279     #eh3 set KFLAGS2 = ( )
280     #eh3 set LIBS = ( )
281     #eh3 set KPPFILES = ( )
282     #eh3 if (! $?NOOPTFILES ) set NOOPTFILES = ( )
283     #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = ( )
284    
285     # Set defaults here
286 edhill 1.5 COMMANDL="$0 $@"
287    
288 edhill 1.1 PLATFORM=
289     LN=
290     S64=
291     KPP=
292     FC=
293     LINK=
294 edhill 1.11 DEFINES="-DWORDLENGTH=4"
295 edhill 1.1 PACKAGES=
296     ENABLE=
297     DISABLE=
298     MAKEFILE=
299     MAKEDEPEND=
300     PDEPEND=
301 edhill 1.11 DUMPSTATE=t
302 edhill 1.1 PDEFAULT=
303     OPTFILE=
304 edhill 1.2 INCLUDES="-I."
305 edhill 1.1 FFLAGS=
306     FOPTIM=
307     CFLAGS=
308     KFLAGS1=
309     KFLAGS2=
310     LIBS=
311     KPPFILES=
312     NOOPTFILES=
313     NOOPTFLAGS=
314    
315     MODS=
316     TOOLSDIR=
317     SOURCEDIRS=
318     INCLUDEDIRS=
319 edhill 1.12 STANDARDDIRS=
320 edhill 1.1
321     PWD=`pwd`
322     MAKE=make
323 edhill 1.15 AWK=awk
324 edhill 1.1 THISHOSTNAME=`hostname`
325     THISCWD=`pwd`
326     THISDATE=`date`
327     MACHINE=`uname -a`
328 edhill 1.7 EXECUTABLE=
329     EXEHOOK=
330     EXEDIR=
331 edhill 1.12 PACKAGES_CONF=
332     IEEE=
333     if test "x$MITGCM_IEEE" != x ; then
334     IEEE=$MITGCM_IEEE
335     fi
336 edhill 1.1
337 edhill 1.14 AUTODIFF_PKG_USED=f
338     AD_OPTFILE=
339 edhill 1.17 TAF=
340     AD_TAF_FLAGS=
341     FTL_TAF_FLAGS=
342     SVD_TAF_FLAGS=
343     TAF_EXTRA=
344     TAMC=
345     AD_TAMC_FLAGS=
346     FTL_TAF_FLAGS=
347     SVD_TAMC_FLAGS=
348     TAMC_EXTRA=
349    
350 edhill 1.14
351 edhill 1.5 # The following state can be set directly by command-line switches
352     gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"
353 edhill 1.12 gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS"
354 edhill 1.5
355     # The following state is not directly set by command-line switches
356     gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
357     gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
358     gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"
359 edhill 1.12 gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
360 edhill 1.5
361 edhill 1.14 # The following are all related to adjoint/tangent-linear stuff
362 edhill 1.17 gm_s7="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
363 edhill 1.14 gm_s8="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
364 edhill 1.17 gm_s9="TAF_EXTRA TAMC_EXTRA"
365 edhill 1.14
366 edhill 1.17 gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7 $gm_s8 $gm_s9"
367 edhill 1.5
368    
369 edhill 1.2 echo
370     echo "=== Processing options files and arguments ==="
371 edhill 1.12 gm_local="genmake_local"
372     for i in . $MODS ; do
373     if test -r $i/$gm_local ; then
374     source $i/$gm_local
375     break
376     fi
377     done
378 edhill 1.1 echo -n " getting local config information: "
379     if test -e $gm_local ; then
380     echo "using $gm_local"
381     source $gm_local
382 edhill 1.2 # echo "DISABLE=$DISABLE"
383     # echo "ENABLE=$ENABLE"
384 edhill 1.1 else
385     echo "none found"
386     fi
387    
388     # echo "$0::$1:$2:$3:$4:$5:$6:$7:"
389 edhill 1.2 #OPTIONS=
390     #n=0
391     #for i ; do
392     # echo "$i $n"
393     # setvar="OPTIONS[$n]='$i'"
394     # # echo " $setvar"
395     # eval "$setvar"
396     # n=$(( $n + 1 ))
397     #done
398     #parse_options
399     ac_prev=
400     for ac_option ; do
401    
402     # If the previous option needs an argument, assign it.
403     if test -n "$ac_prev"; then
404     eval "$ac_prev=\$ac_option"
405     ac_prev=
406     continue
407     fi
408    
409     ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
410    
411     case $ac_option in
412    
413     -help | --help | -h | --h)
414     usage ;;
415    
416     -nooptfile | --nooptfile)
417     OPTFILE="NONE" ;;
418     -optfile | --optfile | -of | --of)
419 edhill 1.4 ac_prev=OPTFILE ;;
420 edhill 1.2 -optfile=* | --optfile=* | -of=* | --of=*)
421     OPTFILE=$ac_optarg ;;
422    
423 edhill 1.14 -adoptfile | --adoptfile | -ad | --ad)
424     ac_prev=AD_OPTFILE ;;
425     -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
426     AD_OPTFILE=$ac_optarg ;;
427    
428 edhill 1.2 -pdepend | --pdepend)
429 edhill 1.4 ac_prev=PDEPEND ;;
430 edhill 1.2 -pdepend=* | --pdepend=*)
431     PDEPEND=$ac_optarg ;;
432    
433     -pdefault | --pdefault)
434 edhill 1.4 ac_prev=PDEFAULT ;;
435 edhill 1.2 -pdefault=* | --pdefault=*)
436     PDEFAULT=$ac_optarg ;;
437    
438 edhill 1.6 -make | --make | -m | --m)
439     ac_prev=MAKE ;;
440     -make=* | --make=* | -m=* | --m=*)
441     MAKE=$ac_optarg ;;
442    
443     -makefile | --makefile | -ma | --ma)
444 edhill 1.4 ac_prev=MAKEFILE ;;
445 edhill 1.6 -makefile=* | --makefile=* | -ma=* | --ma=*)
446 edhill 1.2 MAKEFILE=$ac_optarg ;;
447    
448     -platform | --platform | -pl | --pl)
449 edhill 1.4 ac_prev=PLATFORM ;;
450 edhill 1.2 -platform=* | --platform=* | -pl=* | --pl=*)
451     PLATFORM=$ac_optarg ;;
452    
453     -rootdir | --rootdir | -rd | --rd)
454 edhill 1.4 ac_prev=ROOTDIR ;;
455 edhill 1.2 -rootdir=* | --rootdir=* | -rd=* | --rd=*)
456     ROOTDIR=$ac_optarg ;;
457    
458     -mods | --mods | -mo | --mo)
459 edhill 1.4 ac_prev=MODS ;;
460 edhill 1.2 -mods=* | --mods=* | -mo=* | --mo=*)
461     MODS=$ac_optarg ;;
462    
463     -disable | --disable)
464 edhill 1.4 ac_prev=DISABLE ;;
465 edhill 1.2 -disable=* | --disable=*)
466     DISABLE=$ac_optarg ;;
467    
468     -enable | --enable)
469 edhill 1.4 ac_prev=ENABLE ;;
470 edhill 1.2 -enable=* | --enable=*)
471     ENABLE=$ac_optarg ;;
472    
473 edhill 1.12 -standarddirs | --standarddirs)
474     ac_prev=STANDARDDIRS ;;
475     -standarddirs=* | --standarddirs=*)
476     STANDARDDIRS=$ac_optarg ;;
477    
478 edhill 1.2 -noopt | --noopt)
479 edhill 1.4 ac_prev=NOOPT ;;
480 edhill 1.2 -noopt=* | --noopt=*)
481     NOOPT=$ac_optarg ;;
482    
483     # -cpp | --cpp)
484     # ac_prev=cpp ;;
485     # -cpp=* | --cpp=*)
486     # CPP=$ac_optarg ;;
487    
488     -fortran | --fortran | -fc | --fc)
489 edhill 1.4 ac_prev=FC ;;
490 edhill 1.2 -fc=* | --fc=*)
491     FC=$ac_optarg ;;
492    
493     -ieee | --ieee)
494 edhill 1.12 IEEE=true ;;
495 edhill 1.2 -noieee | --noieee)
496 edhill 1.12 IEEE= ;;
497 edhill 1.2
498     -mpi | --mpi)
499 edhill 1.12 MPI=true ;;
500 edhill 1.2 -nompi | --nompi)
501 edhill 1.12 MPI= ;;
502 edhill 1.2
503     -jam | --jam)
504     JAM=1 ;;
505     -nojam | --nojam)
506     JAM=0 ;;
507    
508 edhill 1.5 -ds | --ds)
509     DUMPSTATE=t ;;
510    
511 edhill 1.17 -taf_extra | --taf_extra)
512     ac_prev=TAF_EXTRA ;;
513     -taf_extra=* | --taf_extra=*)
514     TAF_EXTRA=$ac_optarg ;;
515    
516     -tamc_extra | --tamc_extra)
517     ac_prev=TAMC_EXTRA ;;
518     -tamc_extra=* | --tamc_extra=*)
519     TAMC_EXTRA=$ac_optarg ;;
520    
521 edhill 1.2 -*)
522     echo "Error: unrecognized option: "$ac_option
523     usage
524     ;;
525    
526     *)
527     echo "Error: unrecognized argument: "$ac_option
528     usage
529     ;;
530    
531     esac
532    
533 edhill 1.1 done
534    
535 edhill 1.12 if test -f ./.genmakerc ; then
536     echo
537     echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
538     echo " file. This file format is no longer supported. Please see:"
539     echo
540     echo " http://mitgcm.org/devel_HOWTO/"
541     echo
542     echo " for directions on how to setup and use the new \"genmake2\" input"
543     echo " files and send an email to MITgcm-support@mitgcm.org if you want help."
544     echo
545     fi
546    
547 edhill 1.11 if test "x${ROOTDIR}" = x ; then
548     if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
549     ROOTDIR=".."
550     else
551     for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
552     if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
553     ROOTDIR=$d
554     echo -n "Warning: ROOTDIR was not specified but there appears to be"
555     echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
556     break
557     fi
558     done
559     fi
560     fi
561     if test "x${ROOTDIR}" = x ; then
562     echo "Error: Cannot determine ROOTDIR for MITgcm code."
563     echo " Please specify a ROOTDIR using either an options "
564     echo " file or a command-line option."
565     exit 1
566     fi
567     if test ! -d ${ROOTDIR} ; then
568     echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
569     exit 1
570     fi
571    
572 edhill 1.1 echo " getting OPTFILE information: "
573     if test "x${OPTFILE}" = x ; then
574 edhill 1.11 if test "x$MITGCM_OF" = x ; then
575     echo "Warning: no OPTFILE specified so we'll look for possible settings"
576     printf "\n=== Searching for possible settings for OPTFILE ===\n"
577     find_possible_configs
578 edhill 1.1 else
579 edhill 1.11 OPTFILE=$MITGCM_OF
580     fi
581     fi
582     if test "x$OPTFILE" != xNONE ; then
583     if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
584     echo " using OPTFILE=\"$OPTFILE\""
585     source "$OPTFILE"
586     RETVAL=$?
587     if test "x$RETVAL" != x0 ; then
588     echo -n "Error: failed to source OPTFILE \"$OPTFILE\""
589     echo "--please check that variable syntax is bash-compatible"
590 edhill 1.1 exit 1
591     fi
592 edhill 1.11 if test "x$DUMPSTATE" != xf ; then
593 edhill 1.12 cp -f $OPTFILE "genmake_optfile"
594 edhill 1.11 fi
595     else
596     echo "Error: can't read OPTFILE=\"$OPTFILE\""
597     exit 1
598 edhill 1.1 fi
599     fi
600 edhill 1.8
601 edhill 1.14 echo " getting AD_OPTFILE information: "
602     if test "x${AD_OPTFILE}" = x ; then
603     if test "x$MITGCM_AD_OF" = x ; then
604     AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
605     else
606     AD_OPTFILE=$MITGCM_AD_OF
607     fi
608     fi
609     if test "x${AD_OPTFILE}" != xNONE ; then
610     if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
611     echo " using AD_OPTFILE=\"$AD_OPTFILE\""
612     source "$AD_OPTFILE"
613     RETVAL=$?
614     if test "x$RETVAL" != x0 ; then
615     echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
616     echo "--please check that variable syntax is bash-compatible"
617     exit 1
618     fi
619     if test "x$DUMPSTATE" != xf ; then
620     cp -f $AD_OPTFILE "genmake_ad_optfile"
621     fi
622     else
623     echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
624     exit 1
625     fi
626     fi
627    
628 edhill 1.8 # Check that FC, LINK, CPP, and S64 are defined. If not, complain
629     # and abort!
630     if test "x$FC" = x ; then
631     cat <<EOF 1>&2
632    
633     Error: no Fortran compiler: please specify using one of the following:
634     1) within the options file ("FC=...") as specified by "-of=OPTFILE"
635     2) the "-fc=XXX" command-line option
636 edhill 1.12 3) the "./genmake_local" file
637 edhill 1.8 EOF
638     exit 1
639     fi
640     if test "x$LINK" = x ; then
641     LINK=$FC
642     fi
643     if test "x$CPP" = x ; then
644 edhill 1.11 CPP="cpp"
645     fi
646 edhill 1.13 echo "#define A a" | $CPP > test_cpp 2>&1
647 edhill 1.11 RETVAL=$?
648     if test "x$RETVAL" != x0 ; then
649 edhill 1.8 cat <<EOF 1>&2
650    
651 edhill 1.11 Error: C pre-processor "$CPP" failed the test case: please specify using:
652    
653 edhill 1.8 1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
654 edhill 1.12 2) the "./genmake_local" file
655 edhill 1.11
656 edhill 1.8 EOF
657     exit 1
658 edhill 1.11 else
659     rm -f test_cpp
660 edhill 1.8 fi
661 edhill 1.11 if test "x$MAKEDEPEND" = x ; then
662     MAKEDEPEND=makedepend
663 edhill 1.8 fi
664    
665 edhill 1.2 printf "\n=== Setting defaults ===\n"
666 edhill 1.1 echo -n " Adding MODS directories: "
667     for d in $MODS ; do
668     if test ! -d $d ; then
669 edhill 1.2 echo
670     echo "Error: MODS directory \"$d\" not found!"
671 edhill 1.1 exit 1
672     else
673     echo -n " $d"
674     SOURCEDIRS="$SOURCEDIRS $d"
675     INCLUDEDIRS="$INCLUDEDIRS $d"
676     fi
677     done
678     echo
679    
680     if test "x$MAKEFILE" = x ; then
681     MAKEFILE="Makefile"
682     fi
683     if test "x${PLATFORM}" = x ; then
684     PLATFORM=$p_PLATFORM
685     fi
686    
687     if test "x${EXEDIR}" = x ; then
688     if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then
689     EXEDIR=../exe
690     else
691     EXEDIR=.
692     fi
693     fi
694     if test ! -d ${EXEDIR} ; then
695     echo "Error: the specified EXEDIR (\"$EXEDIR\") does not exist!"
696     exit 1
697     fi
698    
699     if test "x${TOOLSDIR}" = x ; then
700     TOOLSDIR="$ROOTDIR/tools"
701     fi
702     if test ! -d ${TOOLSDIR} ; then
703     echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"
704     exit 1
705     fi
706 edhill 1.11 if test "x$S64" = x ; then
707     S64='$(TOOLSDIR)/set64bitConst.sh'
708     fi
709 edhill 1.1
710     EXECUTABLE=${EXECUTABLE:-mitgcmuv}
711    
712     # We have a special set of source files in eesupp/src which are
713     # generated from some template source files. We'll make them first so
714     # they appear as regular source code
715     if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
716     echo " Making source files in eesupp from templates"
717     $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1
718     RETVAL=$?
719 edhill 1.2 if test "x${RETVAL}" = x0 ; then
720 edhill 1.1 rm -f make_eesupp.errors
721     else
722     echo "Error: problem encountered while building source files in eesupp:"
723     cat make_eesupp.errors
724     exit 1
725     fi
726     fi
727    
728 edhill 1.2 printf "\n=== Determining package settings ===\n"
729 edhill 1.1 if test "x${PDEPEND}" = x ; then
730     tmp=$ROOTDIR"/pkg/pkg_depend"
731     if test -r $tmp ; then
732     PDEPEND=$tmp
733     else
734     echo "Warning: No package dependency information was specified."
735     echo " Please check that ROOTDIR/pkg/pkg_depend exists."
736     fi
737     else
738     if test ! -r ${PDEPEND} ; then
739     echo "Error: can't read package dependency info from PDEPEND=\"$PDEPEND\""
740     exit 1
741     fi
742     fi
743     echo " getting package dependency info from $PDEPEND"
744     # Strip the comments and then convert the dependency file into
745     # two arrays: PNAME, DNAME
746     cat $PDEPEND | sed -e 's/#.*$//g' \
747 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}' \
748 edhill 1.1 > ./.pd_tmp
749     RETVAL=$?
750     if test ! "x${RETVAL}" = x0 ; then
751     echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
752     exit 1
753     fi
754     source ./.pd_tmp
755     rm -f ./.pd_tmp
756    
757 edhill 1.12 # Search for default packages. Note that a "$ROOTDIR/pkg/pkg_groups"
758     # file should eventually be added so that, for convenience, one can
759     # specify groups of packages using names like "ocean" and "atmosphere".
760 edhill 1.1 echo -n " checking default package list: "
761     if test "x${PDEFAULT}" = x ; then
762 edhill 1.12 for i in "." $MODS ; do
763     if test -r $i"/packages.conf" ; then
764     PDEFAULT=$i"/packages.conf"
765     break
766     fi
767     done
768     fi
769     if test "x${PDEFAULT}" = x ; then
770 edhill 1.1 PDEFAULT="$ROOTDIR/pkg/pkg_default"
771     fi
772     if test "x${PDEFAULT}" = xNONE ; then
773     echo "default packages file disabled"
774     else
775     if test ! -r $PDEFAULT ; then
776     echo ""
777     echo "Warning: can't read default packages from PDEFAULT=\"$PDEFAULT\""
778     else
779     echo " using PDEFAULT=\"$PDEFAULT\""
780     # Strip the comments and add all the names
781 edhill 1.15 def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
782 edhill 1.1 RETVAL=$?
783     if test "x${RETVAL}" != x0 ; then
784     echo -n "Error: can't parse default package list "
785     echo "-- please check PDEFAULT=\"$PDEFAULT\""
786     exit 1
787     fi
788     for i in $def ; do
789     PACKAGES="$PACKAGES $i"
790     done
791 edhill 1.12 echo " before group expansion packages are: $PACKAGES"
792     expand_pkg_groups
793     echo " after group expansion packages are: $PACKAGES"
794 edhill 1.1 fi
795     fi
796    
797     echo " applying DISABLE settings"
798     pack=
799     for p in $PACKAGES ; do
800     addit="t"
801     for d in $DISABLE ; do
802     if test "x$p" = "x$d" ; then
803     addit="f"
804     fi
805     done
806     if test "x$addit" = xt ; then
807     pack="$pack $p"
808     fi
809     done
810     PACKAGES="$pack"
811     echo " applying ENABLE settings"
812 edhill 1.12 echo "" > ./.tmp_pack
813 edhill 1.1 PACKAGES="$PACKAGES $ENABLE"
814     for i in $PACKAGES ; do
815     if test ! -d "$ROOTDIR/pkg/$i" ; then
816     echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
817     exit 1
818     fi
819     echo $i >> ./.tmp_pack
820     done
821     pack=`cat ./.tmp_pack | sort | uniq`
822     rm -f ./.tmp_pack
823     PACKAGES=
824     for i in $pack ; do
825     PACKAGES="$PACKAGES $i"
826     done
827     echo " packages are: $PACKAGES"
828    
829     echo " applying package dependency rules"
830     ck=
831     while test "x$ck" != xtt ; do
832     i=0
833 edhill 1.2 # rtot=${#PNAME[@]}
834     rtot=$nname
835 edhill 1.1 while test $i -lt $rtot ; do
836    
837     # Is $pname in the current $PACKAGES list?
838 edhill 1.2 # pname=${PNAME[$i]}
839     tmp="pname=\"\$PNAME_$i\""
840     eval $tmp
841 edhill 1.1 pin="f"
842     for p in $PACKAGES ; do
843     if test "x$p" = "x$pname" ; then
844     pin="t"
845     fi
846     done
847    
848     # Is the DNAME entry a (+) or (-) rule ?
849 edhill 1.2 tmp="dname=\"\$DNAME_$i\""
850     eval $tmp
851 edhill 1.1 plus="-"
852 edhill 1.2 echo $dname | grep '^+' > /dev/null 2>&1
853 edhill 1.1 RETVAL=$?
854     if test "x$RETVAL" = x0 ; then
855     plus="+"
856     fi
857    
858     # Is $dname in the current $PACKAGES list?
859 edhill 1.2 dname=`echo $dname | sed -e 's/^[+-]//'`
860 edhill 1.1 din="f"
861     for p in $PACKAGES ; do
862     if test "x$p" = "x$dname" ; then
863     din="t"
864     fi
865     done
866    
867     # Do we need to add $dname according to the dependency rules?
868     if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then
869     in_dis="f"
870     for dis in $DISABLE ; do
871     if test "x$dis" = "x$dname" ; then
872     in_dis="t"
873     fi
874     done
875     if test "x$in_dis" = xt ; then
876     echo "Error: can't satisfy package dependencies:"
877     echo " \"$dname\" is required by the dependency rules"
878     echo " but is disallowed by the DISABLE settings"
879     exit 1
880     else
881     PACKAGES="$PACKAGES $dname"
882     ck=
883     fi
884     fi
885    
886     # Do we need to get rid of $dname according to the dependency rules?
887     if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then
888     echo "Error: can't satisfy package dependencies:"
889     echo " \"$pname\" was requested but is disallowed by"
890     echo " the dependency rules for \"$dname\""
891     exit 1
892     fi
893     i=$(( $i + 1 ))
894     done
895     ck=$ck"t"
896     done
897     echo " packages are: $PACKAGES"
898     for i in $PACKAGES ; do
899     adr="$ROOTDIR/pkg/$i"
900     if test -d $adr ; then
901     SOURCEDIRS="$SOURCEDIRS $adr"
902     INCLUDEDIRS="$INCLUDEDIRS $adr"
903 edhill 1.14 if test "x$i" = xautodiff ; then
904     AUTODIFF_PKG_USED=t
905     fi
906 edhill 1.1 else
907     echo "Error: the directory \"$adr\" for package $i doesn't exist"
908     exit 1
909     fi
910     done
911    
912     # This is compatible with the old genmake. The "DISABLE_*" flags
913     # need to be replaced by the "ALLOW_*" flags set below.
914     #
915     # echo -n " Setting package-specific CPP flags: "
916     # pkrm=( mom_fluxform mom_vecinv generic_advdiff )
917     # pkrmdef=( -DDISABLE_MOM_FLUXFORM -DDISABLE_MOM_VECINV -DDISABLE_GENERIC_ADVDIFF -DDISABLE_DEBUGMODE )
918     # echo -n " "
919     # i=0
920     # while test $i -lt "${#pkrm[@]}" ; do
921     # echo "$PACKAGES" | grep "${pk[$i]}" > /dev/null 2>&1
922     # RETVAL=$?
923     # if test "x$RETVAL" = x1 ; then
924     # DEFINES="$DEFINES ${pkdef[$i]}"
925     # echo -n " ${pkdef[$i]}"
926     # fi
927     # i=$(( $i + 1 ))
928     # done
929     # echo
930    
931 edhill 1.12 # Create a list of #define and #undef to enable/disable packages
932     PACKAGES_DOT_H=PACKAGES_CONFIG.h
933     cat <<EOF >$PACKAGES_DOT_H".tmp"
934 edhill 1.1 C=== GENMAKE v2 ===
935 edhill 1.11 C The following defines have been set by GENMAKE, so please do not
936     C edit anything below these comments. In general, you should
937 edhill 1.1 C add or remove packages by re-running genmake with different
938     C "-enable" and/or "-disable" options.
939    
940 edhill 1.12 #ifndef PACKAGES_H
941     #define PACKAGES_H
942    
943 edhill 1.1 C Packages disabled by genmake:
944     EOF
945     # The following UGLY HACK sets multiple "#undef"s and it needs to go
946     # away. On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
947     # file would eventually be split up so that all package-related #define
948     # statements could be separated and handled only by genmake.
949     names=`ls -1 "$ROOTDIR/pkg"`
950     all_pack=
951     for n in $names ; do
952     if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
953     has_pack="f"
954     for pack in $PACKAGES ; do
955     if test "x$pack" = "x$n" ; then
956     has_pack="t"
957     break
958     fi
959     done
960     if test "x$has_pack" = xf ; then
961 edhill 1.15 undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`
962 edhill 1.12 echo "#undef $undef" >> $PACKAGES_DOT_H".tmp"
963     # DEFINES="$DEFINES -U$undef"
964 edhill 1.1
965     #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
966     case $n in
967     mom_fluxform)
968     DEFINES="$DEFINES -DDISABLE_MOM_FLUXFORM"
969     ;;
970     mom_vecinv)
971     DEFINES="$DEFINES -DDISABLE_MOM_VECINV"
972     ;;
973     debug)
974     DEFINES="$DEFINES -DDISABLE_DEBUGMODE"
975     ;;
976     esac
977     #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
978    
979     fi
980     fi
981     done
982 edhill 1.12 cat <<EOF >>$PACKAGES_DOT_H".tmp"
983 edhill 1.1
984     C Packages enabled by genmake:
985     EOF
986     for i in $PACKAGES ; do
987 edhill 1.15 def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`
988 edhill 1.12 echo "#define $def" >> $PACKAGES_DOT_H".tmp"
989     #eh3 DEFINES="$DEFINES -D$def"
990 edhill 1.1
991     #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
992     case $i in
993     aim_v23)
994 edhill 1.12 echo "#define ALLOW_AIM" >> $PACKAGES_DOT_H".tmp"
995     DEFINES="$DEFINES -DALLOW_AIM"
996     echo "Warning: ALLOW_AIM is set to enable aim_v23. This is REALLY ugly Jean-Michel :-)"
997 edhill 1.1 ;;
998     esac
999     #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
1000    
1001     done
1002 edhill 1.12 cat <<EOF >>$PACKAGES_DOT_H".tmp"
1003    
1004     #endif /* PACKAGES_H */
1005     EOF
1006    
1007     if test ! -f $PACKAGES_DOT_H ; then
1008     mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
1009     else
1010     cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
1011     RETVAL=$?
1012     if test "x$RETVAL" = x0 ; then
1013     rm -f $PACKAGES_DOT_H".tmp"
1014     else
1015     mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
1016     mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
1017     fi
1018     fi
1019 edhill 1.1
1020     echo " Adding STANDARDDIRS"
1021     BUILDDIR=${BUILDDIR:-.}
1022 edhill 1.12 if test "x$STANDARDDIRS" = x ; then
1023     STANDARDDIRS="eesupp model"
1024     fi
1025 edhill 1.1 for d in $STANDARDDIRS ; do
1026     adr="$ROOTDIR/$d/src"
1027     if test ! -d $adr ; then
1028     echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1029     echo " is correct and that you correctly specified the STANDARDDIRS option"
1030     exit 1
1031     else
1032     SOURCEDIRS="$SOURCEDIRS $adr"
1033     fi
1034     adr="$ROOTDIR/$d/inc"
1035     if test ! -d $adr ; then
1036     echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1037     echo " is correct and that you correctly specified the STANDARDDIRS option"
1038     exit 1
1039     else
1040     INCLUDEDIRS="$INCLUDEDIRS $adr"
1041     fi
1042     done
1043    
1044 edhill 1.22 echo " Searching for CPP_OPTIONS.h in order to warn about the presence"
1045     echo " of \"#define ALLOW_PKGNAME\"-type statements:"
1046 edhill 1.12 CPP_OPTIONS=
1047     spaths=". $INCLUDEDIRS"
1048     for i in $spaths ; do
1049     try="$i/CPP_OPTIONS.h"
1050     # echo -n " trying $try : "
1051     if test -f $try -a -r $try ; then
1052     echo " found CPP_OPTIONS=\"$try\""
1053     CPP_OPTIONS="$try"
1054     break
1055     fi
1056     done
1057     if test "x$CPP_OPTIONS" = x ; then
1058     echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
1059     exit 1
1060     fi
1061     # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
1062     names=`ls -1 "$ROOTDIR/pkg"`
1063     for n in $names ; do
1064     test_for_package_in_cpp_options $CPP_OPTIONS $n
1065     done
1066    
1067 edhill 1.1
1068 edhill 1.14 # Here, we build the list of files to be "run through" the adjoint
1069     # compiler.
1070     if test -f ./ad_files ; then
1071     rm -f ./ad_files
1072     fi
1073     echo " Creating the list of files for the adjoint compiler."
1074     for i in $SOURCEDIRS ; do
1075     list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
1076     for j in $list_files ; do
1077     cat $i/$j >> ad_files
1078     done
1079     done
1080    
1081     cat <<EOF > adjoint_sed
1082     s/call adopen(/call adopen ( mythid,\\
1083     \& /g
1084     s/call adclose(/call adclose( mythid,\\
1085     \& /g
1086     s/call adread(/call adread ( mythid,\\
1087     \& /g
1088     s/call adwrite(/call adwrite( mythid,\\
1089     \& /g
1090    
1091     EOF
1092    
1093 edhill 1.2 echo
1094     echo "=== Creating the Makefile ==="
1095 edhill 1.1 echo " setting INCLUDES"
1096     for i in $INCLUDEDIRS ; do
1097 edhill 1.12 if ! test -d $i ; then
1098     # INCLUDES="$INCLUDES -I$i"
1099     # else
1100 edhill 1.1 echo "Warning: can't find INCLUDEDIRS=\"$i\""
1101     fi
1102     done
1103    
1104     echo " Determining the list of source and include files"
1105     rm -rf .links.tmp
1106     mkdir .links.tmp
1107     echo "# This section creates symbolic links" > srclinks.tmp
1108     echo "" >> srclinks.tmp
1109 cnh 1.3 echo -n 'SRCFILES = ' > srclist.inc
1110     echo -n 'CSRCFILES = ' > csrclist.inc
1111     echo -n 'F90SRCFILES = ' > f90srclist.inc
1112 edhill 1.1 echo -n 'HEADERFILES = ' > hlist.inc
1113 edhill 1.14 echo -n 'AD_FLOW_FILES = ' > ad_flow_files.inc
1114 adcroft 1.9 alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1115 edhill 1.1 for d in $alldirs ; do
1116     deplist=
1117 edhill 1.14 sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
1118 cnh 1.3 sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
1119 edhill 1.1 for sf in $sfiles ; do
1120     if test ! -r ".links.tmp/$sf" ; then
1121     if test -f "$d/$sf" ; then
1122 edhill 1.15 extn=`echo $sf | $AWK -F '.' '{print $NF}'`
1123 edhill 1.1 touch .links.tmp/$sf
1124     deplist="$deplist $sf"
1125     case $extn in
1126     F)
1127     echo " \\" >> srclist.inc
1128     echo -n " $sf" >> srclist.inc
1129     ;;
1130 cnh 1.3 F90)
1131     echo " \\" >> f90srclist.inc
1132     echo -n " $sf" >> f90srclist.inc
1133     ;;
1134 edhill 1.1 c)
1135     echo " \\" >> csrclist.inc
1136     echo -n " $sf" >> csrclist.inc
1137     ;;
1138     h)
1139     echo " \\" >> hlist.inc
1140     echo -n " $sf" >> hlist.inc
1141     ;;
1142 edhill 1.14 flow)
1143     echo " \\" >> ad_flow_files.inc
1144     echo -n " $sf" >> ad_flow_files.inc
1145     ;;
1146 edhill 1.1 esac
1147     fi
1148     fi
1149     done
1150     if test "x$deplist" != x ; then
1151 edhill 1.2 echo "" >> srclinks.tmp
1152     echo "# These files are linked from $d" >> srclinks.tmp
1153 edhill 1.1 echo "$deplist :" >> srclinks.tmp
1154 edhill 1.2 printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp
1155 edhill 1.1 fi
1156     done
1157     rm -rf .links.tmp
1158     echo "" >> srclist.inc
1159     echo "" >> csrclist.inc
1160 cnh 1.3 echo "" >> f90srclist.inc
1161 edhill 1.1 echo "" >> hlist.inc
1162 edhill 1.14 echo "" >> ad_flow_files.inc
1163 edhill 1.1
1164     if test -e $MAKEFILE ; then
1165     mv -f $MAKEFILE "$MAKEFILE.bak"
1166     fi
1167     echo " Writing makefile: $MAKEFILE"
1168     echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
1169     echo "# $MACHINE" >> $MAKEFILE
1170     echo "# This makefile was generated automatically on" >> $MAKEFILE
1171     echo "# $THISDATE" >> $MAKEFILE
1172     echo "# by the command:" >> $MAKEFILE
1173     echo "# $0 $@" >> $MAKEFILE
1174     echo "# executed by:" >> $MAKEFILE
1175     echo "# $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE
1176 edhill 1.21
1177     EXE_AD=$EXECUTABLE"_ad"
1178     EXE_FTL=$EXECUTABLE"_ftl"
1179     EXE_SVD=$EXECUTABLE"_svd"
1180    
1181 edhill 1.1 cat >>$MAKEFILE <<EOF
1182     #
1183     # BUILDDIR : Directory where object files are written
1184     # SOURCEDIRS : Directories containing the source (.F) files
1185     # INCLUDEDIRS : Directories containing the header-source (.h) files
1186     # EXEDIR : Directory where executable that is generated is written
1187     # EXECUTABLE : Full path of executable binary
1188     #
1189     # CPP : C-preprocessor command
1190     # INCLUDES : Directories searched for header files
1191     # DEFINES : Macro definitions for CPP
1192     # MAKEDEPEND : Dependency generator
1193     # KPP : Special preprocessor command (specific to platform)
1194     # KFLAGS : Flags for KPP
1195     # FC : Fortran compiler command
1196     # FFLAGS : Configuration/debugging options for FC
1197     # FOPTIM : Optimization options for FC
1198     # LINK : Command for link editor program
1199     # LIBS : Library flags /or/ additional optimization/debugging flags
1200    
1201     ROOTDIR = ${ROOTDIR}
1202     BUILDDIR = ${BUILDDIR}
1203     SOURCEDIRS = ${SOURCEDIRS}
1204     INCLUDEDIRS = ${INCLUDEDIRS}
1205     EXEDIR = ${EXEDIR}
1206     EXECUTABLE = \$(EXEDIR)/${EXECUTABLE}
1207     TOOLSDIR = ${TOOLSDIR}
1208    
1209 edhill 1.14 #eh3 new defines for the adjoint work
1210     AUTODIFF = ${ROOTDIR}/pkg/autodiff
1211 edhill 1.21 EXE_AD = ${EXE_AD}
1212     EXE_FTL = ${EXE_FTL}
1213     EXE_SVD = ${EXE_SVD}
1214 edhill 1.14
1215 edhill 1.1 EOF
1216    
1217     # Note: figure out some way to add Hyades JAM libraries here
1218    
1219     cat >>$MAKEFILE <<EOF
1220     # Unix ln (link)
1221     LN = ${LN}
1222     # C preprocessor
1223     CPP = cat \$< | ${S64} | ${CPP}
1224     # Dependency generator
1225     MAKEDEPEND = ${MAKEDEPEND}
1226     # Special preprocessor (KAP on DECs, FPP on Crays)
1227     KPP = ${KPP}
1228     # Fortran compiler
1229     FC = ${FC}
1230 cnh 1.3 # Fortran compiler
1231     F90C = ${F90C}
1232 edhill 1.1 # Link editor
1233     LINK = ${LINK}
1234    
1235     # Defines for CPP
1236     DEFINES = ${DEFINES}
1237     # Includes for CPP
1238     INCLUDES = ${INCLUDES}
1239     # Flags for KPP
1240     KFLAGS1 = ${KFLAGS1}
1241     KFLAGS2 = ${KFLAGS2}
1242     # Optim./debug for FC
1243     FFLAGS = ${FFLAGS}
1244     FOPTIM = ${FOPTIM}
1245 cnh 1.3 # Optim./debug for FC
1246     F90FLAGS = ${F90FLAGS}
1247     F90OPTIM = ${F90OPTIM}
1248 edhill 1.1 # Flags for CC
1249     CFLAGS = ${CFLAGS}
1250     # Files that should not be optimized
1251     NOOPTFILES = ${NOOPTFILES}
1252     NOOPTFLAGS = ${NOOPTFLAGS}
1253     # Flags and libraries needed for linking
1254     LIBS = ${LIBS} \$(XLIBS)
1255 cnh 1.3 # Name of the Mekfile
1256     MAKEFILE=${MAKEFILE}
1257 edhill 1.1
1258     EOF
1259    
1260 edhill 1.14 cat srclist.inc >> $MAKEFILE
1261     cat csrclist.inc >> $MAKEFILE
1262     cat f90srclist.inc >> $MAKEFILE
1263     cat hlist.inc >> $MAKEFILE
1264     cat ad_flow_files.inc >> $MAKEFILE
1265     echo >> $MAKEFILE
1266 cnh 1.3 echo 'F77FILES = $(SRCFILES:.F=.f)' >> $MAKEFILE
1267     echo 'F90FILES = $(F90SRCFILES:.F90=.f90)' >> $MAKEFILE
1268     echo 'OBJFILES = $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
1269 edhill 1.1
1270 cnh 1.3 rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc
1271 edhill 1.14 rm -f ad_flow_files.inc
1272 edhill 1.1
1273     cat >>$MAKEFILE <<EOF
1274    
1275     .SUFFIXES:
1276 cnh 1.3 .SUFFIXES: .o .f .p .F .c .F90 .f90
1277 edhill 1.1
1278     all: \$(EXECUTABLE)
1279     \$(EXECUTABLE): \$(OBJFILES)
1280     \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
1281     depend:
1282     @make links
1283     \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
1284 edhill 1.7 ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE)
1285 edhill 1.1
1286 cnh 1.3 links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)
1287 edhill 1.1
1288 cnh 1.3 small_f: \$(F77FILES) \$(F90FILES)
1289 edhill 1.1
1290     output.txt: \$(EXECUTABLE)
1291     @printf 'running ... '
1292     @\$(EXECUTABLE) > \$@
1293    
1294     clean:
1295 edhill 1.22 -cat AD_CONFIG.template > AD_CONFIG.h
1296 cnh 1.3 -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}
1297 edhill 1.1 Clean:
1298     @make clean
1299     @make cleanlinks
1300 edhill 1.22 -rm -f Makefile.bak genmake_state genmake_*optfile make.log
1301 edhill 1.1 CLEAN:
1302     @make Clean
1303     -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
1304     -find \$(EXEDIR) -name "*.data" -exec rm {} \;
1305     -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
1306 edhill 1.12 -rm -f \$(EXECUTABLE) output.txt
1307 edhill 1.1
1308 edhill 1.18 #eh3 Makefile: makefile
1309 edhill 1.1 makefile:
1310     ${0} $@
1311     cleanlinks:
1312     -find . -type l -exec rm {} \;
1313    
1314     # The normal chain of rules is ( .F - .f - .o )
1315     .F.f:
1316     \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1317     .f.o:
1318     \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
1319 cnh 1.3 .F90.f90:
1320     \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1321     .f90.o:
1322     \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
1323 edhill 1.1 .c.o:
1324     \$(CC) \$(CFLAGS) -c \$<
1325    
1326     # Special exceptions that use the ( .F - .p - .f - .o ) rule-chain
1327     .F.p:
1328     \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1329     .p.f:
1330     \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
1331 edhill 1.14
1332     #=========================================
1333     #=== Automatic Differentiation Rules ===
1334    
1335     TAMC = ${TAMC}
1336     TAF = ${TAF}
1337    
1338 edhill 1.17 TAF_EXTRA = ${TAF_EXTRA}
1339     TAMC_EXTRA = ${TAMC_EXTRA}
1340    
1341 edhill 1.14 EOF
1342    
1343     ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
1344     ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF_FLAGS"
1345     ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
1346     for i in $ad_vars ; do
1347     name=$i
1348     t1="t2=\$"`echo $i`
1349     eval $t1
1350     printf "%-20s = " $name >> $MAKEFILE
1351     echo $t2 >> $MAKEFILE
1352     done
1353    
1354     echo " Add the source list for AD code generation"
1355     echo >> $MAKEFILE
1356     echo -n "AD_FILES = " >> $MAKEFILE
1357     AD_FILES=`cat ad_files`
1358     for i in $AD_FILES ; do
1359     echo " \\" >> $MAKEFILE
1360     echo -n " $i" >> $MAKEFILE
1361     done
1362     echo >> $MAKEFILE
1363 edhill 1.21 rm -f ad_files
1364 edhill 1.14
1365     cat >>$MAKEFILE <<EOF
1366    
1367 edhill 1.16 # ... AD ...
1368 edhill 1.23 adall: ad_taf
1369     adtaf: ad_taf_output.f
1370     adtamc: ad_tamc_output.f
1371 edhill 1.21
1372 edhill 1.23 ad_input_code.f: \$(SRCFILES) \$(HEADERFILES)
1373     cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
1374 edhill 1.22 @make \$(F77FILES)
1375     @make \$(AD_FLOW_FILES)
1376     cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f
1377    
1378 edhill 1.14 ad_taf_output.f: ad_input_code.f
1379 edhill 1.17 \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1380 edhill 1.14 cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f
1381    
1382     ad_taf: ad_taf_output.o \$(OBJFILES)
1383 edhill 1.21 \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
1384 edhill 1.14
1385     ad_tamc_output.f: ad_input_code.f
1386 edhill 1.17 \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f
1387 edhill 1.16 cat ad_input_code_ad.f | sed -f adjoint_sed > ad_tamc_output.f
1388 edhill 1.14
1389     ad_tamc: ad_tamc_output.o \$(OBJFILES)
1390 edhill 1.21 \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
1391 edhill 1.14
1392    
1393 edhill 1.19 # ... FTL ...
1394 edhill 1.23 ftlall: ftl_taf
1395     ftltaf: ftl_taf_output.f
1396     ftltamc: ftl_tamc_output.f
1397 edhill 1.21
1398 edhill 1.22 ftl_input_code.f: \$(SRCFILES)
1399 edhill 1.23 cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
1400     @make \$(F77FILES)
1401 edhill 1.22 @make \$(AD_FLOW_FILES)
1402     cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f
1403    
1404     ftl_taf_output.f: ftl_input_code.f
1405     \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f
1406     cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_taf_output.f
1407 edhill 1.14
1408 edhill 1.19 ftl_taf: ftl_taf_output.o \$(OBJFILES)
1409 edhill 1.21 \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
1410 edhill 1.14
1411 edhill 1.22 ftl_tamc_output.f: ftl_input_code.f
1412     \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f
1413     cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_tamc_output.f
1414 edhill 1.16
1415 edhill 1.19 ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
1416 edhill 1.21 \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
1417 edhill 1.16
1418    
1419     # ... SVD ...
1420 edhill 1.21 svd: svd_taf
1421     svd_taf_f: svd_taf_output.f
1422    
1423 edhill 1.22 svd_input_code.f: \$(SRCFILES)
1424 edhill 1.23 cmp svd_config.template AD_CONFIG.h || cat svd_config.template > AD_CONFIG.h
1425     @make \$(F77FILES)
1426 edhill 1.22 @make \$(AD_FLOW_FILES)
1427     cat \$(AD_FLOW_FILES) \$(AD_FILES) > svd_input_code.f
1428    
1429     svd_taf_output.f: svd_input_code.f
1430     \$(TAF) \$(SVD_TAF_FLAGS) \$(TAF_EXTRA) svd_input_code.f
1431     cat svd_input_code_ad.f | sed -f adjoint_sed > svd_taf_output.f
1432 edhill 1.16
1433     svd_taf: svd_taf_output.o \$(OBJFILES)
1434 edhill 1.21 \$(LINK) -o ${EXE_SVD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) svd_taf_output.o \$(LIBS)
1435 edhill 1.14
1436    
1437     #=========================================
1438 edhill 1.1
1439     EOF
1440 edhill 1.7
1441     if test "x$EXEHOOK" != x ; then
1442     printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
1443     fi
1444 edhill 1.1
1445     echo " Making list of \"exceptions\" that need \".p\" files"
1446     for i in $KPPFILES ; do
1447     base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
1448     RETVAL=$?
1449     if test "x$RETVAL" != x0 ; then
1450     echo "Error: unable to add file \"$i\" to the exceptions list"
1451     fi
1452     echo "$base.f: $base.p" >> $MAKEFILE
1453     done
1454    
1455     echo " Making list of NOOPTFILES"
1456     for i in $NOOPTFILES ; do
1457     base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
1458     RETVAL=$?
1459     if test "x$RETVAL" != x0 ; then
1460     echo "Error: unable to add file \"$i\" to the exceptions list"
1461     fi
1462     echo "$base.o: $base.f" >> $MAKEFILE
1463 edhill 1.2 printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
1464 edhill 1.1 done
1465    
1466     echo " Add rules for links"
1467     cat srclinks.tmp >> $MAKEFILE
1468     rm -f srclinks.tmp
1469    
1470     echo " Adding makedepend marker"
1471 edhill 1.2 printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
1472 edhill 1.1
1473 edhill 1.2 printf "\n=== Done ===\n"
1474 edhill 1.22
1475     # Write the "template" files for the adjoint builds
1476 edhill 1.23 cat >AD_CONFIG.template <<EOF
1477 edhill 1.22 C WARNING: This file is automatically generated by genmake2 and
1478     C used by the Makefile rules. Please DO NOT EDIT this file
1479 edhill 1.23 C unless you are CERTAIN that you know what you are doing.
1480 edhill 1.22
1481     #undef ALLOW_ADJOINT_RUN
1482     #undef ALLOW_TANGENTLINEAR_RUN
1483     #undef ALLOW_ECCO_OPTIMIZATION
1484     EOF
1485 edhill 1.23 cat >ad_config.template <<EOF
1486 edhill 1.22 C WARNING: This file is automatically generated by genmake2 and
1487     C used by the Makefile rules. Please DO NOT EDIT this file
1488 edhill 1.23 C unless you are CERTAIN that you know what you are doing.
1489 edhill 1.22
1490 edhill 1.23 #define ALLOW_ADJOINT_RUN
1491 edhill 1.22 #undef ALLOW_TANGENTLINEAR_RUN
1492     #undef ALLOW_ECCO_OPTIMIZATION
1493     EOF
1494 edhill 1.23 cat >ftl_config.template <<EOF
1495 edhill 1.22 C WARNING: This file is automatically generated by genmake2 and
1496     C used by the Makefile rules. Please DO NOT EDIT this file
1497 edhill 1.23 C unless you are CERTAIN that you know what you are doing.
1498 edhill 1.22
1499     #undef ALLOW_ADJOINT_RUN
1500 edhill 1.23 #define ALLOW_TANGENTLINEAR_RUN
1501 edhill 1.22 #undef ALLOW_ECCO_OPTIMIZATION
1502     EOF
1503 edhill 1.23 cat >svd_config.template <<EOF
1504 edhill 1.22 C WARNING: This file is automatically generated by genmake2 and
1505     C used by the Makefile rules. Please DO NOT EDIT this file
1506 edhill 1.23 C unless you are CERTAIN that you know what you are doing.
1507 edhill 1.22
1508     #undef ALLOW_ADJOINT_RUN
1509     #undef ALLOW_TANGENTLINEAR_RUN
1510     #undef ALLOW_ECCO_OPTIMIZATION
1511     EOF
1512     cp AD_CONFIG.template AD_CONFIG.h
1513 edhill 1.5
1514    
1515     # Write the "state" for future records
1516     if test "x$DUMPSTATE" != xf ; then
1517 edhill 1.12 echo -n "" > genmake_state
1518 edhill 1.5 for i in $gm_state ; do
1519     t1="t2=\$$i"
1520     eval $t1
1521 edhill 1.12 echo "$i='$t2'" >> genmake_state
1522 edhill 1.5 done
1523     fi

  ViewVC Help
Powered by ViewVC 1.1.22