/[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.84 - (hide annotations) (download)
Mon Jul 12 15:49:08 2004 UTC (19 years, 8 months ago) by edhill
Branch: MAIN
Changes since 1.83: +37 -33 lines
 o do a better job of finding makedepend even when an optfile is specified

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

  ViewVC Help
Powered by ViewVC 1.1.22