/[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.88 - (hide annotations) (download)
Tue Jul 20 19:43:45 2004 UTC (15 years, 4 months ago) by edhill
Branch: MAIN
Changes since 1.87: +6 -6 lines
 o convert "test -e" to "test -f" which seems to be more portable
   - the "sh" shell on NEC SX-6 machines dies without it!

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

  ViewVC Help
Powered by ViewVC 1.1.22