/[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.28 - (hide annotations) (download)
Tue Nov 4 19:51:54 2003 UTC (15 years, 8 months ago) by edhill
Branch: MAIN
CVS Tags: checkpoint52, ecco_c52_e35, checkpoint51t_post, checkpoint51u_post, checkpoint51s_post
Changes since 1.27: +1 -14 lines
 o cleanup: convert DISABLE_MOM_FLUXFORM & DISABLE_MOM_VECINV to the
   newer ALLOW_${pkg} form
   - the only remaining package-based "special case" within genmake2
     is the one for AIM vs. AIM_V23

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

  ViewVC Help
Powered by ViewVC 1.1.22