/[MITgcm]/MITgcm/verification/OpenAD/code_ad/genmake2
ViewVC logotype

Annotation of /MITgcm/verification/OpenAD/code_ad/genmake2

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.18 - (hide annotations) (download)
Fri Nov 4 17:39:22 2005 UTC (18 years, 6 months ago) by utke
Branch: MAIN
Changes since 1.17: +4 -4 lines
add the additional targets/prereq to the cb2m steps

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

  ViewVC Help
Powered by ViewVC 1.1.22