/[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.83 - (hide annotations) (download)
Tue Jul 6 18:06:49 2004 UTC (15 years, 2 months ago) by adcroft
Branch: MAIN
CVS Tags: checkpoint54b_post
Changes since 1.82: +2 -2 lines
Fixed .SUFFIXES order
 o order must reflect order of dependencies
 o now works with all flavors of "make" not just gmake

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

  ViewVC Help
Powered by ViewVC 1.1.22