/[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.20 - (hide annotations) (download)
Wed Oct 22 15:27:07 2003 UTC (20 years, 5 months ago) by heimbach
Branch: MAIN
Changes since 1.19: +3 -3 lines
Correcting '_ftl' for TAF forward mode output.

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

  ViewVC Help
Powered by ViewVC 1.1.22