/[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.141 - (hide annotations) (download)
Wed Jan 11 06:02:31 2006 UTC (18 years, 2 months ago) by edhill
Branch: MAIN
CVS Tags: checkpoint58
Changes since 1.140: +92 -5 lines
o add "--embed-source" option to genmake2 which, when the supporting
  tools can be compiled (as determined by genmake2) will turn on the
  embed_files package which then embeds the entire MITgcm source code
  (*.[fFhc] + Makefile) used for the build within the executable
  - requested by CNH but off by default
  - adds a paltry <9MB to the mitgcmuv executable in most cases
  - only writes the output when useEMBEDSRC in eedata is true

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

  ViewVC Help
Powered by ViewVC 1.1.22