/[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.76 - (hide annotations) (download)
Thu Apr 8 21:32:11 2004 UTC (15 years, 3 months ago) by edhill
Branch: MAIN
Changes since 1.75: +94 -42 lines
 o more changes to allow for arbitrary Fortran 77/90 file extensions on
   fundamentally broken environments (eg. cygwin, MacOS HFS+) that cannot
   distinguish between .F and .f files
   - works with arbitrary extensions on Linux
   - needs more testing on cygwin and MacOS

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

  ViewVC Help
Powered by ViewVC 1.1.22