/[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.146 - (hide annotations) (download)
Fri Apr 7 02:53:55 2006 UTC (17 years, 11 months ago) by edhill
Branch: MAIN
CVS Tags: checkpoint58d_post
Changes since 1.145: +18 -10 lines
fix annoying overly-general check reported by PH using method suggested
  by JMC

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

  ViewVC Help
Powered by ViewVC 1.1.22