/[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.68 - (hide annotations) (download)
Tue Feb 24 19:14:18 2004 UTC (20 years ago) by adcroft
Branch: MAIN
Changes since 1.67: +2 -2 lines
Missing E

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

  ViewVC Help
Powered by ViewVC 1.1.22