/[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.124 - (hide annotations) (download)
Tue Jun 7 20:52:42 2005 UTC (13 years, 11 months ago) by edhill
Branch: MAIN
CVS Tags: checkpoint57k_post, checkpoint57i_post, checkpoint57j_post
Changes since 1.123: +7 -3 lines
 o add IGNORE_TIME define and -ignore_time option to genmake2 as an
   end-run around the C/Fortran linking horror in eesup/src/timers.F

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

  ViewVC Help
Powered by ViewVC 1.1.22