/[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.74 - (hide annotations) (download)
Wed Mar 24 17:12:51 2004 UTC (19 years, 11 months ago) by adcroft
Branch: MAIN
Changes since 1.73: +16 -7 lines
o expand_pkg_groups now returns a state indicating whether it did an
  expansion or not
o expand_pkg_groups is called repeatedly until all expansions are complete
o implemented -pkg in packages.conf (thought we were already doing this but
  it didn't seem to be there)

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

  ViewVC Help
Powered by ViewVC 1.1.22