/[MITgcm]/MITgcm_contrib/heimbach/OpenAD/code_heat_transport_MPI/genmake2
ViewVC logotype

Annotation of /MITgcm_contrib/heimbach/OpenAD/code_heat_transport_MPI/genmake2

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


Revision 1.4 - (hide annotations) (download)
Fri Aug 3 14:03:51 2007 UTC (19 years, 1 month ago) by utke
Branch: MAIN
Changes since 1.3: +14 -3 lines
get the relevant MPI declarations

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

  ViewVC Help
Powered by ViewVC 1.1.22