/[MITgcm]/MITgcm/tools/genmake2
ViewVC logotype

Diff of /MITgcm/tools/genmake2

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

revision 1.138 by edhill, Sun Dec 4 13:57:08 2005 UTC revision 1.219 by jmc, Sat Jan 15 19:16:32 2011 UTC
# Line 1  Line 1 
1  #! /usr/bin/env bash  #! /usr/bin/env bash
2  #  #
3  # $Header$  # $Header$
4    # $Name$
5  #  #
6  # Makefile generator for MITgcm UV codes  # Makefile generator for MITgcm UV codes
7  #   created  by cnh 03/98  #   created  by cnh 03/98
# Line 8  Line 9 
9  #   modified by aja 01/00  #   modified by aja 01/00
10  #   rewritten in bash by eh3 08/03  #   rewritten in bash by eh3 08/03
11    
12    #  Explain usage
13    usage()  {
14    cat <<EOF
15    
16    Usage: "$0" [OPTIONS]
17      where [OPTIONS] can be:
18    
19        -help | --help | -h | --h
20              Print this help message and exit.
21    
22        -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME
23          -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME
24              Use "NAME" as the adoptfile.  By default, the file at
25              "tools/adjoint_options/adjoint_default" will be used.
26    
27        -nooptfile | --nooptfile
28          -optfile NAME | --optfile NAME | -of NAME | --of NAME
29          -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
30              Use "NAME" as the optfile.  By default, an attempt will be
31              made to find an appropriate "standard" optfile in the
32              tools/build_options/ directory.
33    
34        -pdepend NAME | --pdepend NAME
35          -pdepend=NAME | --pdepend=NAME
36              Get package dependency information from "NAME".
37    
38        -pgroups NAME | --pgroups NAME
39          -pgroups=NAME | --pgroups=NAME
40              Get the package groups information from "NAME".
41    
42        -bash NAME
43              Explicitly specify the Bourne or BASH shell to use
44    
45        -make NAME | -m NAME
46          --make=NAME | -m=NAME
47              Use "NAME" for the MAKE program. The default is "make" but
48              many platforms, "gmake" is the preferred choice.
49    
50        -makefile NAME | -mf NAME
51          --makefile=NAME | -mf=NAME
52              Call the makefile "NAME".  The default is "Makefile".
53    
54        -makedepend NAME | -md NAME
55          --makedepend=NAME | -md=NAME
56              Use "NAME" for the MAKEDEPEND program.
57    
58        -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
59          -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
60              Specify the location of the MITgcm ROOTDIR as "NAME".
61              By default, genamke will try to find the location by
62              looking in parent directories (up to the 5th parent).
63    
64        -mods NAME | --mods NAME | -mo NAME | --mo NAME
65          -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
66              Here, "NAME" specifies a list of directories that are
67              used for additional source code.  Files found in the
68              "mods list" are given preference over files of the same
69              name found elsewhere.
70    
71        -disable NAME | --disable NAME
72          -disable=NAME | --disable=NAME
73              Here "NAME" specifies a list of packages that we don't
74              want to use.  If this violates package dependencies,
75              genamke will exit with an error message.
76    
77        -enable NAME | --enable NAME
78          -enable=NAME | --enable=NAME
79              Here "NAME" specifies a list of packages that we wish
80              to specifically enable.  If this violates package
81              dependencies, genamke will exit with an error message.
82    
83        -standarddirs NAME | --standarddirs NAME
84          -standarddirs=NAME | --standarddirs=NAME
85              Here, "NAME" specifies a list of directories to be
86              used as the "standard" code.
87    
88        -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
89          -fc=NAME | --fc=NAME
90              Use "NAME" as the fortran compiler.  By default, genmake
91              will search for a working compiler by trying a list of
92              "usual suspects" such as g77, f77, etc.
93    
94        -cc NAME | --cc NAME | -cc=NAME | --cc=NAME
95              Use "NAME" as the C compiler.  By default, genmake
96              will search for a working compiler by trying a list of
97              "usual suspects" such as gcc, c89, cc, etc.
98    
99        -[no]ieee | --[no]ieee
100              Do or don't use IEEE numerics.  Note that this option
101              *only* works if it is supported by the OPTFILE that
102              is being used.
103    
104        -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4
105              Use "real*4" type for _RS variable (#undef REAL4_IS_SLOW)
106              *only* works if CPP_EEOPTIONS.h allows this.
107    
108        -ignoretime | -ignore_time | --ignoretime | --ignore_time
109              Ignore all the "wall clock" routines entirely.  This will
110              not in any way hurt the model results -- it simply means
111              that the code that checks how long the model spends in
112              various routines will give junk values.
113    
114        -ts | --ts
115              Produce timing information per timestep
116        -papis | --papis
117              Produce summary MFlop/s (and IPC) with PAPI per timestep
118        -pcls | --pcls
119              Produce summary MFlop/s etc. with PCL per timestep
120        -foolad | --foolad
121              Fool the AD code generator
122        -papi | --papi
123              Performance analysis with PAPI
124        -pcl | --pcl
125              Performance analysis with PCL
126        -hpmt | --hpmt
127              Performance analysis with the HPM Toolkit
128    
129        -gsl | --gsl
130              Use GSL to control floating point rounding and precision
131        -devel | --devel
132              Add additional warning and debugging flags for development
133    
134        -mpi | --mpi
135              Include MPI header files and link to MPI libraries
136        -mpi=PATH | --mpi=PATH
137              Include MPI header files and link to MPI libraries using MPI_ROOT
138              set to PATH. i.e. Include files from \$PATH/include, link to libraries
139              from \$PATH/lib and use binaries from \$PATH/bin.
140    
141        -omp | --omp
142              Activate OpenMP code + use Compiler option OMPFLAG
143        -omp=OMPFLAG | --omp=OMPFLAG
144              Activate OpenMP code + use Compiler option OMPFLAG
145    
146        -es | --es | -embed-source | --embed-source
147              Embed a tarball containing the full source code
148              (including the Makefile, etc.) used to build the
149              executable [off by default]
150    
151        -ds | --ds
152              Report genmake internal variables status (DUMPSTATE)
153              to file "genmake_state" (for debug purpose)
154    
155      While it is most often a single word, the "NAME" variables specified
156      above can in many cases be a space-delimited string such as:
157    
158        --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'
159        -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'
160        -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
161    
162      which, depending upon your shell, may need to be single-quoted.
163    
164      For more detailed genmake documentation, please see:
165    
166        http://mitgcm.org/public/devel_HOWTO/
167    
168    EOF
169    
170        exit 1
171    }
172    
173  # Search for particular CPP #cmds associated with packages  # Search for particular CPP #cmds associated with packages
174  # usage: test_for_package_in_cpp_options CPP_file package_name  # usage: test_for_package_in_cpp_options CPP_file package_name
175  test_for_package_in_cpp_options() {  test_for_package_in_cpp_options() {
176      cpp_options=$1      cpp_options=$1
177      pkg=$2      pkg=$2
178      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg[ ]"
179      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg[ ]"
180      test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg[ ]"
181      test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg[ ]"
182        test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg$"
183        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg$"
184        test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg$"
185        test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg$"
186  }  }
187    
188  # Search for particular CPP #cmds associated with MPI  # Search for particular CPP #cmds associated with MPI
189  # usage: test_for_mpi_in_cpp_eeoptions CPP_file  # usage: test_for_mpi_in_cpp_eeoptions CPP_file
190  test_for_mpi_in_cpp_eeoptions() {  test_for_mpi_in_cpp_eeoptions() {
191      cpp_options=$1      cpp_options=$1
192      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI[ ]"
193      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI[ ]"
194      test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI[ ]"
195      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI[ ]"
196        test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI$"
197        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI$"
198        test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI$"
199        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI$"
200  }  }
201    
202  # Search for particular string in a file. Return 1 if detected, 0 if not  # Search for particular string in a file. Return 1 if detected, 0 if not
# Line 39  test_for_string_in_file() { Line 209  test_for_string_in_file() {
209      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
210          printf "Error: In $file there is an illegal line: "          printf "Error: In $file there is an illegal line: "
211          grep -i "$strng" $file          grep -i "$strng" $file
212          return 1          exit 99
213      fi      fi
214      return 0      return 0
215  }  }
# Line 48  test_for_string_in_file() { Line 218  test_for_string_in_file() {
218  # the package list.  # the package list.
219  expand_pkg_groups() {  expand_pkg_groups() {
220      new_packages=      new_packages=
     PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups"  
221      if test -r $PKG_GROUPS ; then      if test -r $PKG_GROUPS ; then
222          cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp          cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp
223          cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp          cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp
# Line 59  expand_pkg_groups() { Line 228  expand_pkg_groups() {
228              if test "x$RETVAL" = x0 ; then              if test "x$RETVAL" = x0 ; then
229                  matched=1                  matched=1
230                  replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`                  replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`
231                  echo "    replacing \"$i\" with: $replace"                  echo "    replacing \"$i\" with:$replace"
232                  new_packages="$new_packages $replace"                  new_packages="$new_packages $replace"
233              else              else
234                  new_packages="$new_packages $i"                  new_packages="$new_packages $i"
# Line 102  EOF Line 271  EOF
271              check_for_broken_Ff              check_for_broken_Ff
272          else          else
273              cat <<EOF 2>&1              cat <<EOF 2>&1
274  ERROR: Your file system cannot distinguish between *.F and *.f files  ERROR: Your file system cannot distinguish between *.F and *.f files
275    (fails the "cp" test) and this program cannot find a suitable    (fails the "cp" test) and this program cannot find a suitable
276    replacement extension.  Please try a different build environment or    replacement extension.  Please try a different build environment or
277    contact the <MITgcm-support@mitgcm.org> list for help.    contact the <MITgcm-support@mitgcm.org> list for help.
278    
279  EOF  EOF
# Line 138  EOF Line 307  EOF
307              check_for_broken_Ff              check_for_broken_Ff
308          else          else
309              cat <<EOF 2>&1              cat <<EOF 2>&1
310  ERROR: Your file system cannot distinguish between *.F and *.f files  ERROR: Your file system cannot distinguish between *.F and *.f files
311    (fails the "make/ln" test) and this program cannot find a suitable    (fails the "make/ln" test) and this program cannot find a suitable
312    replacement extension.  Please try a different build environment or    replacement extension.  Please try a different build environment or
313    contact the <MITgcm-support@mitgcm.org> list for help.    contact the <MITgcm-support@mitgcm.org> list for help.
314    
315  EOF  EOF
# Line 157  EOF Line 326  EOF
326      return      return
327  }  }
328    
   
329  look_for_makedepend()  {  look_for_makedepend()  {
330    
331      #  The "original" makedepend is part of the Imake system that is      #  The "original" makedepend is part of the Imake system that is
# Line 178  look_for_makedepend()  { Line 346  look_for_makedepend()  {
346      #    3) locally build and use the cyrus implementation      #    3) locally build and use the cyrus implementation
347      #    4) fall back to the buggy local xmakedpend script      #    4) fall back to the buggy local xmakedpend script
348      #      #
349        echo >> $LOGFILE
350        echo "running: look_for_makedepend()" >> $LOGFILE
351        if test "x${MAKEDEPEND}" != x ; then
352            echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1
353            RETVAL=$?
354            if test x"$RETVAL" = x0 ; then
355                build_cyrus_makedepend
356                RETVAL=$?
357                if test "x$RETVAL" != x0 ; then
358                    echo "WARNING: unable to build cyrus-makedepend. Try 'makedepend'"
359                    MAKEDEPEND=
360                fi
361            else
362                echo " -->     MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
363            fi
364        fi
365      if test "x${MAKEDEPEND}" = x ; then      if test "x${MAKEDEPEND}" = x ; then
366          which makedepend > /dev/null 2>&1          which makedepend > /dev/null 2>&1
367          RV0=$?          RV0=$?
# Line 186  look_for_makedepend()  { Line 370  look_for_makedepend()  {
370          cat <<EOF >> $MAKEFILE          cat <<EOF >> $MAKEFILE
371  #   THIS IS A TEST MAKEFILE GENERATED BY "genmake2"  #   THIS IS A TEST MAKEFILE GENERATED BY "genmake2"
372  #  #
373  #   Some "makedepend" implementations will die if they cannot  #   Some "makedepend" implementations will die if they cannot
374  #   find a Makefile -- so this file is here to gives them an  #   find a Makefile -- so this file is here to gives them an
375  #   empty one to find and parse.  #   empty one to find and parse.
376  EOF  EOF
377          cat <<EOF >> genmake_tc.f          cat <<EOF >> genmake_tc.f
# Line 202  EOF Line 386  EOF
386          test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE          test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
387          if test "x${RV0}${RV1}" = x00 ; then          if test "x${RV0}${RV1}" = x00 ; then
388              MAKEDEPEND=makedepend              MAKEDEPEND=makedepend
389                echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
390          else          else
391              echo "    a system-default makedepend was not found."              echo "    system-default makedepend not found. Try to build cyrus-makedepend"
               
392              #  Try to build the cyrus implementation              #  Try to build the cyrus implementation
393              build_cyrus_makedepend              build_cyrus_makedepend
394              RETVAL=$?              RETVAL=$?
395              if test "x$RETVAL" != x0 ; then              if test "x$RETVAL" != x0 ; then
396                    echo "WARNING: unable to build cyrus-makedepend. Use local xmakedepend"
397                  MAKEDEPEND='$(TOOLSDIR)/xmakedepend'                  MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
398                    echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
399              fi              fi
             rm -f ./genmake_cy_md  
         fi  
     else  
         #  echo "MAKEDEPEND=${MAKEDEPEND}"  
         echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1  
         RETVAL=$?  
         if test x"$RETVAL" = x0 ; then  
             build_cyrus_makedepend  
400          fi          fi
401      fi      fi
402  }  }
403    
   
404  build_cyrus_makedepend()  {  build_cyrus_makedepend()  {
405        echo >> $LOGFILE
406        echo "running: build_cyrus_makedepend()" >> $LOGFILE
407      rm -f ./genmake_cy_md      rm -f ./genmake_cy_md
408      (      (
409          cd $ROOTDIR/tools/cyrus-imapd-makedepend  \          cd $ROOTDIR/tools/cyrus-imapd-makedepend  \
# Line 241  build_cyrus_makedepend()  { Line 420  build_cyrus_makedepend()  {
420      rm -f ./genmake_cy_md      rm -f ./genmake_cy_md
421      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
422          MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'          MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
423            echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
424          return 0          return 0
425      else      else
426          echo "WARNING: unable to build cyrus-imapd-makedepend"          echo "WARNING: fail to build cyrus-imapd-makedepend" >> $LOGFILE
427          return 1          return 1
428      fi      fi
429  }  }
430    
431  # Guess possible config options for this host  build_embed_encode()
432  find_possible_configs()  {  {
433        printf "  building the embed-encode utility...  "
434      tmp1=`uname`"_"`uname -m`      if test ! -e "$ROOTDIR/tools/embed_encode/encode_files" ; then
435      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`          if test ! -d "$ROOTDIR/tools/embed_encode" ; then
436      tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`              echo
437      tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`              echo "    Error: can't locate \"$ROOTDIR/tools/embed_encode\""
438      tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`              echo
439      tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`              EMBED_SRC=f
440      PLATFORM=$tmp3              return 1
441      echo $PLATFORM | grep cygwin > /dev/null 2>&1  &&  PLATFORM=cygwin_ia32          fi
442      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`          clist="cc gcc c89 $CC"
443      echo "  The platform appears to be:  $PLATFORM"          for ic in $clist ; do
444                    comm="$ic -o encode_files encode_files.c"
445      echo "test" > test              ( cd $ROOTDIR/tools/embed_encode && $comm ) > /dev/null 2>&1
446      ln -s ./test link              RETVAL=$?
447      RETVAL=$?              if test "x$RETVAL" = x0 ; then
448      if test "x${RETVAL}" = x0 ; then                  echo "OK"
449          LN="ln -s"                  DEFINES="$DEFINES -DHAVE_EMBED_SRC"
450      else                  return 0
451          echo "Error: \"ln -s\" does not appear to work on this system!"              fi
452          echo "  For help, please contact <MITgcm-support@mitgcm.org>."          done
453          exit 1          echo
454      fi          echo "    Error: unable to build $ROOTDIR/embed_encode/encode_files"
455      rm -f test link          echo "      so it has been disabled"
456            echo
457      if test "x$CPP" = x ; then          EMBED_SRC=f
458          CPP="cpp -traditional -P"          return 1
459      fi      fi
460        echo "OK"
461        DEFINES="$DEFINES -DHAVE_EMBED_SRC"
462    }
463    
464      look_for_makedepend  #  look for possible C compilers
465    look_for_C_compilers() {
466      #================================================================      echo >> $LOGFILE
467      #  look for possible C compilers      echo "running: look_for_C_compilers()" >> $LOGFILE
468      tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc"      rm -f ./genmake_hello.c  ./genmake_hello
469      p_CC=      cat >> genmake_hello.c << EOF
     for c in $tmp ; do  
         rm -f ./genmake_hello.c  ./genmake_hello  
         cat >> genmake_hello.c << EOF  
470  #include <stdio.h>  #include <stdio.h>
471  int main(int argc, char **argv) {  int main(int argc, char **argv) {
472    printf("Hello!\n");    printf("Hello!\n");
473    return 0;    return 0;
474  }  }
475  EOF  EOF
476          $c -o genmake_hello genmake_hello.c > /dev/null 2>&1      tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc icc"
477        p_CC=
478        for c in $tmp ; do
479            COMM="$c $CFLAGS -o genmake_hello genmake_hello.c"
480            echo $COMM >> $LOGFILE
481            $COMM >> $LOGFILE 2>&1
482          RETVAL=$?          RETVAL=$?
483          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
484                echo " $c test successful" >> $LOGFILE
485              p_CC="$p_CC $c"              p_CC="$p_CC $c"
486          fi          fi
487      done      done
# Line 311  Error: No C compilers were found in your Line 497  Error: No C compilers were found in your
497  EOF  EOF
498          exit 1          exit 1
499      else      else
500          echo "  The possible C compilers found in your path are:"          echo "  The possible C compilers found in your path are: $p_CC" | tee -a $LOGFILE
         echo "   "$p_CC  
501          if test "x$CC" = x ; then          if test "x$CC" = x ; then
502              CC=`echo $p_CC | $AWK '{print $1}'`              CC=`echo $p_CC | $AWK '{print $1}'`
503              echo "  Setting C compiler to: "$CC              echo "  Setting C compiler to: "$CC
504          fi          fi
505      fi      fi
506        echo " --> set CC='$CC'" >> $LOGFILE
507    }
508    
509    # Guess possible config options for this host
510    find_possible_optfile()  {
511    
512        echo >> $LOGFILE
513        echo "running: find_possible_optfile()" >> $LOGFILE
514        tmp1=`uname`"_"`uname -m`
515        tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
516        tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
517        tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
518        tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
519        tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
520        PLATFORM=$tmp3
521        echo $PLATFORM | grep cygwin > /dev/null 2>&1  &&  PLATFORM=cygwin_ia32
522        OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
523        echo "  The platform appears to be:  $PLATFORM" | tee -a $LOGFILE
524    
525      #================================================================      #================================================================
526      #  look for possible FORTRAN compilers      #  look for possible FORTRAN compilers
527      tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 gfortran"      echo "  look for possible FORTRAN compilers" >> $LOGFILE
528        tmp="$MITGCM_FC $FC efc gfortran g77 f77 pgf77 pgf95 ifc ifort f90 f95 mpif77 mpf77 mpxlf95 g95"
529      p_FC=      p_FC=
530      for c in $tmp ; do      rm -f ./genmake_hello.f
531          rm -f ./hello.f ./hello      cat >> genmake_hello.f <<EOF
         cat >> hello.f <<EOF  
532        program hello        program hello
533        do i=1,3        do i=1,3
534          print *, 'hello world : ', i          print *, 'hello world : ', i
535        enddo        enddo
536        end        end
537  EOF  EOF
538          $c -o hello hello.f > /dev/null 2>&1      for f in $tmp ; do
539            COMM="$f -o genmake_hello genmake_hello.f"
540            echo $COMM >> $LOGFILE
541            $COMM >> $LOGFILE 2>&1
542          RETVAL=$?          RETVAL=$?
543          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
544              p_FC="$p_FC $c"              echo " $f test successful" >> $LOGFILE
545                p_FC="$p_FC $f"
546          fi          fi
547      done      done
548      rm -f ./hello.f ./hello      rm -f ./genmake_hello.f ./genmake_hello
549      if test "x${p_FC}" = x ; then      if test "x${p_FC}" = x ; then
550          cat 1>&2 <<EOF          cat 1>&2 <<EOF
551    
# Line 351  Error: No Fortran compilers were found i Line 558  Error: No Fortran compilers were found i
558  EOF  EOF
559          exit 1          exit 1
560      else      else
561          echo "  The possible FORTRAN compilers found in your path are:"          echo "  The possible FORTRAN compilers found in your path are: $p_FC" | tee -a $LOGFILE
         echo "   "$p_FC  
562      fi      fi
563    
564      #  Use the first of the compilers found in the current PATH      #  Use the first of the compilers found in the current PATH
# Line 361  EOF Line 567  EOF
567          for i in $p_FC ; do          for i in $p_FC ; do
568              OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i              OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
569              if test -r $OPTFILE ; then              if test -r $OPTFILE ; then
570                  echo "  Setting OPTFILE to: "$OPTFILE                  echo "  Setting OPTFILE to: "$OPTFILE | tee -a $LOGFILE
571                  break                  break
572              fi              fi
573          done          done
# Line 373  EOF Line 579  EOF
579               echo "  I looked for the file "$OPTFILE" but did not find it"               echo "  I looked for the file "$OPTFILE" but did not find it"
580          fi          fi
581      fi      fi
582  #    echo "  The options file:  $p_OF"  
 #    echo "    appears to match so we'll use it."  
 #   for i in $p_FC ; do  
 #p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i  
 #if test -r $p_OF ; then  
 #    OPTFILE=$p_OF  
 #    echo "  The options file:  $p_OF"  
 #    echo "    appears to match so we'll use it."  
 #    break  
 #fi  
 #   done  
583      if test "x$OPTFILE" = x ; then      if test "x$OPTFILE" = x ; then
584          cat 1>&2 <<EOF          cat 1>&2 <<EOF
585    
# Line 399  Error: No options file was found in:  $R Line 595  Error: No options file was found in:  $R
595  EOF  EOF
596          exit 1          exit 1
597      fi      fi
598        
599  #     # look for possible MPI libraries  #     # look for possible MPI libraries
600  #     mpi_libs=  #     mpi_libs=
601  #     mpi_fort=`which mpif77 2>/dev/null`  #     mpi_fort=`which mpif77 2>/dev/null`
# Line 418  EOF Line 614  EOF
614  #       if test "x${RETVAL}" = x0 ; then  #       if test "x${RETVAL}" = x0 ; then
615  #           a=`cat out`  #           a=`cat out`
616  #           for i in $a ; do  #           for i in $a ; do
617  #               case $i in  #               case $i in
618  #                   -*)  #                   -*)
619  #                       mpi_libs="$mpi_libs $i" ;;  #                       mpi_libs="$mpi_libs $i" ;;
620  #               esac  #               esac
# Line 428  EOF Line 624  EOF
624  #       fi  #       fi
625  #       rm -f test.f out  #       rm -f test.f out
626  #     fi  #     fi
   
627  }  }
628    
629  #  Parse the package dependency information  #  Parse the package dependency information
# Line 437  get_pdepend_list()  { Line 632  get_pdepend_list()  {
632      #  strip the comments and then convert the dependency file into      #  strip the comments and then convert the dependency file into
633      #  two arrays: PNAME, DNAME      #  two arrays: PNAME, DNAME
634      cat $1 | sed -e 's/#.*$//g' \      cat $1 | sed -e 's/#.*$//g' \
635          | $AWK 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \          | $AWK 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \
636          > ./.pd_tmp          > ./.pd_tmp
637        RETVAL=$?
638        if test ! "x${RETVAL}" = x0 ; then
639          echo "Error: unable to parse package dependencies -- please check PKG_DEPEND=\"$1\""
640          exit 1
641        fi
642      . ./.pd_tmp      . ./.pd_tmp
643      rm -f ./.pd_tmp      rm -f ./.pd_tmp
   
     printf "PNAME = "${}  
 }  
   
   
 #  Explain usage  
 usage()  {  
 cat <<EOF  
   
 Usage: "$0" [OPTIONS]  
   where [OPTIONS] can be:  
   
     -help | --help | -h | --h  
           Print this help message and exit.  
   
     -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME  
       -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME  
           Use "NAME" as the adoptfile.  By default, the file at  
           "tools/adjoint_options/adjoint_default" will be used.  
   
     -nooptfile | --nooptfile  
       -optfile NAME | --optfile NAME | -of NAME | --of NAME  
       -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME  
           Use "NAME" as the optfile.  By default, an attempt will be  
           made to find an appropriate "standard" optfile in the  
           tools/build_options/ directory.  
   
     -pdepend NAME | --pdepend NAME  
       -pdepend=NAME | --pdepend=NAME  
           Get package dependency information from "NAME".  
   
     -pdefault NAME | --pdefault NAME  
       -pdefault=NAME | --pdefault=NAME  
           Get the default package list from "NAME".  
   
     -make NAME | -m NAME  
       --make=NAME | -m=NAME  
           Use "NAME" for the MAKE program. The default is "make" but  
           many platforms, "gmake" is the preferred choice.  
   
     -makefile NAME | -mf NAME  
       --makefile=NAME | -mf=NAME  
           Call the makefile "NAME".  The default is "Makefile".  
   
     -makedepend NAME | -md NAME  
       --makedepend=NAME | -md=NAME  
           Use "NAME" for the MAKEDEPEND program.  
   
     -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME  
       -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME  
           Specify the location of the MITgcm ROOTDIR as "NAME".  
           By default, genamke will try to find the location by  
           looking in parent directories (up to the 5th parent).  
   
     -mods NAME | --mods NAME | -mo NAME | --mo NAME  
       -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME  
           Here, "NAME" specifies a list of directories that are  
           used for additional source code.  Files found in the  
           "mods list" are given preference over files of the same  
           name found elsewhere.  
   
     -disable NAME | --disable NAME  
       -disable=NAME | --disable=NAME  
           Here "NAME" specifies a list of packages that we don't  
           want to use.  If this violates package dependencies,  
           genamke will exit with an error message.  
   
     -enable NAME | --enable NAME  
       -enable=NAME | --enable=NAME  
           Here "NAME" specifies a list of packages that we wish  
           to specifically enable.  If this violates package  
           dependencies, genamke will exit with an error message.  
   
     -standarddirs NAME | --standarddirs NAME  
       -standarddirs=NAME | --standarddirs=NAME  
           Here, "NAME" specifies a list of directories to be  
           used as the "standard" code.  
   
     -fortran NAME | --fortran NAME | -fc NAME | --fc NAME  
       -fc=NAME | --fc=NAME  
           Use "NAME" as the fortran compiler.  By default, genmake  
           will search for a working compiler by trying a list of  
           "usual suspects" such as g77, f77, etc.  
   
     -cc NAME | --cc NAME | -cc=NAME | --cc=NAME  
           Use "NAME" as the C compiler.  By default, genmake  
           will search for a working compiler by trying a list of  
           "usual suspects" such as gcc, c89, cc, etc.  
   
     -[no]ieee | --[no]ieee  
           Do or don't use IEEE numerics.  Note that this option  
           *only* works if it is supported by the OPTFILE that  
           is being used.  
   
     -ts | --ts  
           Produce timing information per timestep  
   
     -mpi | --mpi  
           Include MPI header files and link to MPI libraries  
     -mpi=PATH | --mpi=PATH  
           Include MPI header files and link to MPI libraries using MPI_ROOT  
           set to PATH. i.e. Include files from \$PATH/include, link to libraries  
           from \$PATH/lib and use binaries from \$PATH/bin.  
   
     -bash NAME  
           Explicitly specify the Bourne or BASH shell to use  
   
   While it is most often a single word, the "NAME" variables specified  
   above can in many cases be a space-delimited string such as:  
   
     --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'  
     -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'  
     -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'  
   
   which, depending upon your shell, may need to be single-quoted.  
   
   For more detailed genmake documentation, please see:  
   
     http://mitgcm.org/devel_HOWTO/  
   
 EOF  
   
     exit 1  
644  }  }
645    
646  #  Build a CPP macro to automate calling C routines from FORTRAN  #  Build a CPP macro to automate calling C routines from FORTRAN
# Line 573  get_fortran_c_namemangling()  { Line 650  get_fortran_c_namemangling()  {
650      if test ! "x$FC_NAMEMANGLE" = x ; then      if test ! "x$FC_NAMEMANGLE" = x ; then
651          return 0          return 0
652      fi      fi
653        echo " running: get_fortran_c_namemangling()" >> $LOGFILE
654    
655      default_nm="#define FC_NAMEMANGLE(X) X ## _"      default_nm="#define FC_NAMEMANGLE(X) X ## _"
656        
657      cat > genmake_test.c <<EOF      cat > genmake_test.c <<EOF
658  void tcall( char * string ) { tsub( string ); }  void tcall( char * string ) { tsub( string ); }
659  EOF  EOF
660      $MAKE genmake_test.o >> genmake_warnings 2>&1      COMM="$CC $CFLAGS -c genmake_test.c"
661        echo ' '$COMM >> $LOGFILE
662        $COMM >> $LOGFILE 2>&1
663      RETVAL=$?      RETVAL=$?
664      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
665          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
666          cat <<EOF>> genmake_errors          cat <<EOF>> $LOGFILE
667    
668  WARNING: C test compile fails   WARNING: C test compile fails
669  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
670  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here   WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
671  EOF  EOF
672          return 1          return 1
673      fi      fi
# Line 595  EOF Line 675  EOF
675      RETVAL=$?      RETVAL=$?
676      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
677          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
678          cat <<EOF>> genmake_warnings          cat <<EOF>> $LOGFILE
679    
680  WARNING: The "nm" command failed.   WARNING: The "nm" command failed.
681  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
682  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here   WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
683  EOF  EOF
684          return 1          return 1
685      fi      fi
# Line 609  EOF Line 689  EOF
689        call tsub( string )        call tsub( string )
690        end        end
691  EOF  EOF
692      $FC $FFLAGS -c genmake_tcomp.$FS >> genmake_warnings 2>&1      COMM="$FC $FFLAGS -c genmake_tcomp.$FS"
693        echo ' '$COMM >> $LOGFILE
694        $COMM >> $LOGFILE 2>&1
695      RETVAL=$?      RETVAL=$?
696      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
697          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
698          cat <<EOF>> genmake_warnings          cat <<EOF>> $LOGFILE
699    
700  WARNING: FORTRAN test compile fails -- please see "genmake_errors"   WARNING: FORTRAN test compile fails -- please see '$LOGFILE'
701  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
702  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.   WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
703  EOF  EOF
704          return 1          return 1
705      fi      fi
# Line 625  EOF Line 707  EOF
707      RETVAL=$?      RETVAL=$?
708      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
709          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
710          cat <<EOF>> genmake_warnings          cat <<EOF>> $LOGFILE
711    
712  WARNING: The "nm" command failed.   WARNING: The "nm" command failed.
713  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
714  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.   WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
715  EOF  EOF
716          return 1          return 1
717      fi      fi
# Line 655  EOF Line 737  EOF
737    
738      #  cleanup the testing files      #  cleanup the testing files
739      rm -f genmake_tcomp.* genmake_test.*      rm -f genmake_tcomp.* genmake_test.*
 }  
740    
741        echo " --> set FC_NAMEMANGLE='$FC_NAMEMANGLE'" >> $LOGFILE
742    }
743    
744  check_HAVE_CLOC()  {  check_HAVE_CLOC()  {
745        echo >> $LOGFILE
746        echo "running: check_HAVE_CLOC()" >> $LOGFILE
747      get_fortran_c_namemangling      get_fortran_c_namemangling
748      cat <<EOF > genmake_tc_1.c      cat <<EOF > genmake_tc_1.c
749  $FC_NAMEMANGLE  $FC_NAMEMANGLE
# Line 675  void FC_NAMEMANGLE(cloc) ( double *curti Line 760  void FC_NAMEMANGLE(cloc) ( double *curti
760   *curtim = *curtim/1.E6;   *curtim = *curtim/1.E6;
761  }  }
762  EOF  EOF
763      make genmake_tc_1.o >> genmake_warnings 2>&1      COMM="$CC $CFLAGS -c genmake_tc_1.c"
764        echo $COMM >> $LOGFILE
765        $COMM >> $LOGFILE 2>&1
766      RET_C=$?      RET_C=$?
767      cat <<EOF > genmake_tc_2.$FS      cat <<EOF > genmake_tc_2.$FS
768        program hello        program hello
# Line 685  EOF Line 772  EOF
772        print *," HELLO WORLD", wtime        print *," HELLO WORLD", wtime
773        end        end
774  EOF  EOF
775      $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_warnings 2>&1      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
776        echo $COMM >> $LOGFILE
777        $COMM >> $LOGFILE 2>&1
778      RET_F=$?      RET_F=$?
779      test -x ./genmake_tc  &&  ./genmake_tc >> genmake_warnings 2>&1      test -x ./genmake_tc  &&  ./genmake_tc >> $LOGFILE 2>&1
780      RETVAL=$?      RETVAL=$?
781      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
782          HAVE_CLOC=t          HAVE_CLOC=t
783          DEFINES="$DEFINES -DHAVE_CLOC"          DEFINES="$DEFINES -DHAVE_CLOC"
784      fi      fi
785      rm -f genmake_tc*      rm -f genmake_tc*
786        echo " --> set HAVE_CLOC='$HAVE_CLOC'" >> $LOGFILE
787  }  }
788    
   
789  check_HAVE_SIGREG()  {  check_HAVE_SIGREG()  {
790        if test ! "x$HAVE_SIGREG" = x ; then
791            return
792        fi
793        echo >> $LOGFILE
794        echo "running: check_HAVE_SIGREG()" >> $LOGFILE
795      get_fortran_c_namemangling      get_fortran_c_namemangling
796      cat <<EOF > genmake_tc_1.c      cat <<EOF > genmake_tc_1.c
797  $FC_NAMEMANGLE  $FC_NAMEMANGLE
# Line 729  void FC_NAMEMANGLE(sigreg) (int * aip) Line 823  void FC_NAMEMANGLE(sigreg) (int * aip)
823      return;      return;
824  }  }
825  EOF  EOF
826      make genmake_tc_1.o >> genmake_warnings 2>&1      COMM="$CC $CFLAGS -c genmake_tc_1.c"
827        echo $COMM >> $LOGFILE
828        $COMM >> $LOGFILE 2>&1
829      RET_C=$?      RET_C=$?
830      cat <<EOF > genmake_tc_2.$FS      cat <<EOF > genmake_tc_2.$FS
831        program hello        program hello
# Line 739  EOF Line 835  EOF
835        call sigreg(anint)        call sigreg(anint)
836        end        end
837  EOF  EOF
838      echo >> genmake_warnings      cat genmake_tc_2.$FS >> $LOGFILE
     echo "running: check_HAVE_SIGREG()" >> genmake_warnings  
     cat genmake_tc_2.$FS >> genmake_warnings  
839      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
840      echo $COMM >> genmake_warnings      echo $COMM >> $LOGFILE
841      $COMM >> genmake_warnings 2>&1      $COMM >> $LOGFILE 2>&1
842      RETVAL=$?      RETVAL=$?
843      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
844          HAVE_SIGREG=t          HAVE_SIGREG=t
845          DEFINES="$DEFINES -DHAVE_SIGREG"          DEFINES="$DEFINES -DHAVE_SIGREG"
846      fi      fi
847      rm -f genmake_tc*      rm -f genmake_tc*
848        echo " --> set HAVE_SIGREG='$HAVE_SIGREG'" >> $LOGFILE
849  }  }
850    
   
851  check_HAVE_SETRLSTK()  {  check_HAVE_SETRLSTK()  {
852        if test "x$HAVE_SETRLSTK" = xt ; then
853            DEFINES="$DEFINES -DHAVE_SETRLSTK"
854            return
855        fi  
856        if test ! "x$HAVE_SETRLSTK" = x ; then
857            return
858        fi
859        echo >> $LOGFILE
860        echo "running: check_HAVE_SETRLSTK()" >> $LOGFILE
861      get_fortran_c_namemangling      get_fortran_c_namemangling
862      cat <<EOF > genmake_tc_1.c      cat <<EOF > genmake_tc_1.c
863  $FC_NAMEMANGLE  $FC_NAMEMANGLE
# Line 770  void FC_NAMEMANGLE(setrlstk) () Line 873  void FC_NAMEMANGLE(setrlstk) ()
873      return;      return;
874  }  }
875  EOF  EOF
876      make genmake_tc_1.o >> genmake_warnings 2>&1      COMM="$CC $CFLAGS -c genmake_tc_1.c"
877        echo $COMM >> $LOGFILE
878        $COMM >> $LOGFILE 2>&1
879      RET_C=$?      RET_C=$?
880      cat <<EOF > genmake_tc_2.$FS      cat <<EOF > genmake_tc_2.$FS
881        program hello        program hello
# Line 778  EOF Line 883  EOF
883        call setrlstk()        call setrlstk()
884        end        end
885  EOF  EOF
886      echo >> genmake_warnings      cat genmake_tc_2.$FS >> $LOGFILE
     echo "running: check_HAVE_SETRLSTK()" >> genmake_warnings  
     cat genmake_tc_2.$FS >> genmake_warnings  
887      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
888      echo $COMM >> genmake_warnings      echo $COMM >> $LOGFILE
889      $COMM >> genmake_warnings 2>&1      $COMM >> $LOGFILE 2>&1
890      RETVAL=$?      RETVAL=$?
891      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
892          HAVE_SETRLSTK=t          HAVE_SETRLSTK=t
893          DEFINES="$DEFINES -DHAVE_SETRLSTK"          DEFINES="$DEFINES -DHAVE_SETRLSTK"
894      fi      fi
895      rm -f genmake_tc*      rm -f genmake_tc*
896        echo " --> set HAVE_SETRLSTK='$HAVE_SETRLSTK'" >> $LOGFILE
897  }  }
898    
   
899  check_HAVE_STAT()  {  check_HAVE_STAT()  {
900        echo >> $LOGFILE
901        echo "running: check_HAVE_STAT()" >> $LOGFILE
902      get_fortran_c_namemangling      get_fortran_c_namemangling
903      cat <<EOF > genmake_tc_1.c      cat <<EOF > genmake_tc_1.c
904  $FC_NAMEMANGLE  $FC_NAMEMANGLE
# Line 814  void FC_NAMEMANGLE(tfsize) ( int *nbyte Line 919  void FC_NAMEMANGLE(tfsize) ( int *nbyte
919          *nbyte = -1;          *nbyte = -1;
920  }  }
921  EOF  EOF
922      make genmake_tc_1.o >> genmake_tc.log 2>&1      COMM="$CC $CFLAGS -c genmake_tc_1.c"
923        echo $COMM >> $LOGFILE
924        $COMM >> genmake_tc.log 2>&1
925      RET_C=$?      RET_C=$?
926      cat <<EOF > genmake_tc_2.$FS      cat <<EOF > genmake_tc_2.$FS
927        program hello        program hello
# Line 823  EOF Line 930  EOF
930        print *," HELLO WORLD", nbyte        print *," HELLO WORLD", nbyte
931        end        end
932  EOF  EOF
933      echo >> genmake_warnings      cat genmake_tc_2.$FS >> $LOGFILE
     echo "running: check_HAVE_STAT()" >> genmake_warnings  
     cat genmake_tc_2.$FS >> genmake_warnings  
934      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
935      echo $COMM >> genmake_warnings      echo $COMM >> $LOGFILE
936      $COMM >> genmake_tc.log 2>&1      $COMM >> genmake_tc.log 2>&1
937      RETVAL=$?      RETVAL=$?
938      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
# Line 835  EOF Line 940  EOF
940          DEFINES="$DEFINES -DHAVE_STAT"          DEFINES="$DEFINES -DHAVE_STAT"
941      fi      fi
942      rm -f genmake_tc*      rm -f genmake_tc*
943        echo " --> set HAVE_STAT='$HAVE_STAT'" >> $LOGFILE
944  }  }
945    
   
946  check_netcdf_libs()  {  check_netcdf_libs()  {
947      if test ! "x$SKIP_NETCDF_CHECK" = x ; then      if test ! "x$SKIP_NETCDF_CHECK" = x ; then
948          return          return
949      fi      fi
950      echo >> genmake_warnings      echo >> $LOGFILE
951      echo "running: check_netcdf_libs()" >> genmake_warnings      echo "running: check_netcdf_libs()" >> $LOGFILE
952      cat <<EOF > genmake_tnc.F      cat <<EOF > genmake_tnc.F
953        program fgennc        program fgennc
954  #include "netcdf.inc"  #include "netcdf.inc"
# Line 861  EOF Line 966  EOF
966        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
967        end        end
968  EOF  EOF
969      echo "===  genmake_tnc.F  ===" > genmake_tnc.log      echo "===  genmake_tnc.F  >>>" > genmake_tnc.log
970      cat genmake_tnc.F >> genmake_tnc.log      cat genmake_tnc.F >> genmake_tnc.log
971      echo "===  genmake_tnc.F  ===" >> genmake_tnc.log      echo "<<<  genmake_tnc.F  ===" >> genmake_tnc.log
972      RET_CPP=f      RET_CPP=f
973      COMM="$CPP $DEFINES $INCLUDES genmake_tnc.F"      COMM="cat genmake_tnc.F | $CPP $DEFINES $INCLUDES"
974      echo "$COMM" >> genmake_tnc.log      echo "$COMM" >> genmake_tnc.log
975      $COMM > genmake_tnc.$FS 2>/dev/null  &&  RET_CPP=t      eval $COMM > genmake_tnc.$FS 2>/dev/null  &&  RET_CPP=t
976      if test "x$RET_CPP" = xf ; then      if test "x$RET_CPP" = xf ; then
977          echo "  WARNING: CPP failed to pre-process the netcdf test." \          echo "  WARNING: CPP failed to pre-process the netcdf test." \
978              >> genmake_tnc.log              >> genmake_tnc.log
# Line 875  EOF Line 980  EOF
980              >> genmake_tnc.log              >> genmake_tnc.log
981      fi      fi
982      echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.$FS  \ " >> genmake_tnc.log      echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.$FS  \ " >> genmake_tnc.log
983      echo "  &&  $LINK -o genmake_tnc.o $LIBS" >> genmake_tnc.log      echo "  &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc.o $LIBS" >> genmake_tnc.log
984      $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \      $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
985          &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1          &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
986      RET_COMPILE=$?      RET_COMPILE=$?
987      cat genmake_tnc.log >> genmake_warnings      cat genmake_tnc.log >> $LOGFILE
988    
989      #EH3  Remove test program execution for machines that either disallow      #EH3  Remove test program execution for machines that either disallow
990      #EH3  execution or cannot support it (eg. cross-compilers)      #EH3  execution or cannot support it (eg. cross-compilers)
# Line 890  EOF Line 995  EOF
995    
996      if test "x$RET_COMPILE" = x0 ; then      if test "x$RET_COMPILE" = x0 ; then
997          HAVE_NETCDF=t          HAVE_NETCDF=t
998            echo "check_netcdf: successful" >> $LOGFILE
999      else      else
1000          # try again with "-lnetcdf" added to the libs          # try again with "-lnetcdf" added to the libs
1001          echo "try again with added '-lnetcdf'" > genmake_tnc.log          echo "==> try again with added '-lnetcdf'" > genmake_tnc.log
1002          echo "$CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS \ " >> genmake_tnc.log          echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log
1003          echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log          echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
1004          echo " &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log          echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
1005          $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null  \          cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null  \
1006              &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \              &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
1007              &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1              &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
1008          RET_COMPILE=$?          RET_COMPILE=$?
1009          cat genmake_tnc.log >> genmake_warnings          echo >> $LOGFILE
1010            cat genmake_tnc.log >> $LOGFILE
1011          if test "x$RET_COMPILE" = x0 ; then          if test "x$RET_COMPILE" = x0 ; then
1012              LIBS="$LIBS -lnetcdf"              LIBS="$LIBS -lnetcdf"
1013              HAVE_NETCDF=t              HAVE_NETCDF=t
1014                echo "check_netcdf: successful" >> $LOGFILE
1015            else
1016            # try again with "-lnetcdff" added to the libs
1017                echo "==> try again with added '-lnetcdff -lnetcdf'" > genmake_tnc.log
1018                echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log
1019                echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
1020                echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
1021                cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null  \
1022                    &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
1023                    &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdff -lnetcdf >> genmake_tnc.log 2>&1
1024                RET_COMPILE=$?
1025                echo >> $LOGFILE
1026                cat genmake_tnc.log >> $LOGFILE
1027                if test "x$RET_COMPILE" = x0 ; then
1028                    LIBS="$LIBS -lnetcdff -lnetcdf"
1029                    HAVE_NETCDF=t
1030                    echo "check_netcdf: successful" >> $LOGFILE
1031                fi
1032          fi          fi
1033      fi      fi
1034      rm -f genmake_tnc*      rm -f genmake_tnc*
1035        echo " --> set HAVE_NETCDF='$HAVE_NETCDF'" >> $LOGFILE
1036  }  }
1037    
1038    
   
1039  ###############################################################################  ###############################################################################
1040  #   Sequential part of script starts here  #   Sequential part of script starts here
1041  ###############################################################################  ###############################################################################
# Line 932  ENABLE= Line 1057  ENABLE=
1057  DISABLE=  DISABLE=
1058  # MAKEFILE=  # MAKEFILE=
1059  # MAKEDEPEND=  # MAKEDEPEND=
1060  PDEPEND=  PKG_DEPEND=
1061  DUMPSTATE=t  PKG_GROUPS=
1062  PDEFAULT=  DUMPSTATE=f
1063  OPTFILE=  OPTFILE=
1064  INCLUDES="-I. $INCLUDES"  INCLUDES="-I. $INCLUDES"
1065  FFLAGS=  FFLAGS=
1066  FOPTIM=  FOPTIM=
1067    FEXTRAFLAGS=
1068    USE_EXTENDED_SRC=
1069    EXTENDED_SRC_FLAG=
1070    GET_FC_VERSION=
1071  CFLAGS=  CFLAGS=
1072  KFLAGS1=  KFLAGS1=
1073  KFLAGS2=  KFLAGS2=
# Line 949  NOOPTFILES= Line 1078  NOOPTFILES=
1078  NOOPTFLAGS=  NOOPTFLAGS=
1079  MPI=  MPI=
1080  MPIPATH=  MPIPATH=
1081    OMP=
1082    OMPFLAG=
1083    USE_R4=
1084  TS=  TS=
1085    PAPIS=
1086    PCLS=
1087    FOOLAD=
1088    PAPI=
1089    PCL=
1090    HPMT=
1091    GSL=
1092    DEVEL=
1093  HAVE_TEST_L=  HAVE_TEST_L=
1094    
1095  # DEFINES checked by test compilation or command-line  # DEFINES checked by test compilation or command-line
# Line 957  HAVE_SYSTEM= Line 1097  HAVE_SYSTEM=
1097  HAVE_FDATE=  HAVE_FDATE=
1098  FC_NAMEMANGLE=  FC_NAMEMANGLE=
1099  HAVE_CLOC=  HAVE_CLOC=
1100  HAVE_SETRLSTK=  # HAVE_SETRLSTK=
1101  HAVE_STAT=  HAVE_STAT=
1102  HAVE_NETCDF=  HAVE_NETCDF=
1103  HAVE_ETIME=  HAVE_ETIME=
# Line 974  BASH= Line 1114  BASH=
1114  PWD=`pwd`  PWD=`pwd`
1115  test "x$MAKE" = x  &&  MAKE=make  test "x$MAKE" = x  &&  MAKE=make
1116  test "x$AWK" = x   &&  AWK=awk  test "x$AWK" = x   &&  AWK=awk
1117    EMBED_SRC=
1118  THISHOST=`hostname`  THISHOST=`hostname`
1119  THISCWD=`pwd`  THISCWD=`pwd`
1120  THISDATE=`date`  THISDATE=`date`
# Line 1004  FTL_TAF_FLAGS= Line 1145  FTL_TAF_FLAGS=
1145  SVD_TAMC_FLAGS=  SVD_TAMC_FLAGS=
1146  TAMC_EXTRA=  TAMC_EXTRA=
1147    
   
1148  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
1149  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"  gm_s1="OPTFILE PKG_DEPEND PKG_GROUPS MAKEFILE MAKEDEPEND PLATFORM ROOTDIR MODS DISABLE ENABLE"
1150  gm_s2="FC CPP IEEE TS MPI JAM DUMPSTATE STANDARDDIRS"  gm_s2="FC CC IEEE USE_R4 TS PAPIS PCLS PAPI PCL HPMT GSL DEVEL MPI OMP DUMPSTATE STANDARDDIRS"
1151    
1152  #  The following state is not directly set by command-line switches  #  The following state is not directly set by command-line switches
1153  gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "  gm_s3="LN S64 LINK MAKE PACKAGES INCLUDES FFLAGS FOPTIM FEXTRAFLAGS"
1154  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"  gm_s4="CFLAGS LIBS KPP KFLAGS1 KFLAGS2 KPPFILES NOOPTFILES NOOPTFLAGS"
1155  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE"  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD THISHOST THISUSER THISDATE THISVER MACHINE"
1156  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
1157  gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME"  gm_s7="FC_NAMEMANGLE HAVE_NETCDF HAVE_SYSTEM HAVE_FDATE HAVE_ETIME"
1158    
1159  #  The following are all related to adjoint/tangent-linear stuff  #  The following are all related to adjoint/tangent-linear stuff
1160  gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"  gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
# Line 1028  cat <<EOF Line 1168  cat <<EOF
1168    
1169  GENMAKE :  GENMAKE :
1170    
1171  A program for GENerating MAKEfiles for the MITgcm project.  For a  A program for GENerating MAKEfiles for the MITgcm project.
1172  quick list of options, use "genmake -h" or for more detail see:     For a quick list of options, use "genmake2 -h"
1173    or for more detail see the Developer's HOWTO manual at:
1174    http://mitgcm.org/devel_HOWTO/     http://mitgcm.org/public/docs.html
1175    
1176  EOF  EOF
1177    
1178    LOGFILE="genmake.log"
1179    #- clean-up previous genmake logfiles:
1180    rm -f genmake_state genmake_*optfile $LOGFILE
1181    
1182  echo "===  Processing options files and arguments  ==="  echo "===  Processing options files and arguments  ==="
1183  gm_local="genmake_local"  gm_local="genmake_local"
 for i in . $MODS ; do  
     if test -r $i/$gm_local ; then  
         . $i/$gm_local  
         break  
     fi  
 done  
1184  printf "  getting local config information:  "  printf "  getting local config information:  "
1185  if test -f $gm_local ; then  if test -f $gm_local ; then
1186      echo "using $gm_local"      echo "using $gm_local"
# Line 1054  else Line 1192  else
1192  fi  fi
1193    
1194  #echo "$0::$1:$2:$3:$4:$5:$6:$7:"  #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
 #OPTIONS=  
 #n=0  
 #for i ; do  
 #   echo "$i  $n"  
 #   setvar="OPTIONS[$n]='$i'"  
 #   #  echo "  $setvar"  
 #   eval "$setvar"  
 #   n=$(( $n + 1 ))  
 #done  
1195  #parse_options  #parse_options
1196  ac_prev=  ac_prev=
1197  for ac_option in "$@" ; do  for ac_option in "$@" ; do
# Line 1075  for ac_option in "$@" ; do Line 1204  for ac_option in "$@" ; do
1204          ac_prev=          ac_prev=
1205          continue          continue
1206      fi      fi
1207        
1208      ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`      ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
1209        
1210      case $ac_option in      case $ac_option in
1211                    
1212          -help | --help | -h | --h)          -help | --help | -h | --h)
# Line 1096  for ac_option in "$@" ; do Line 1225  for ac_option in "$@" ; do
1225              AD_OPTFILE=$ac_optarg ;;              AD_OPTFILE=$ac_optarg ;;
1226                    
1227          -pdepend | --pdepend)          -pdepend | --pdepend)
1228              ac_prev=PDEPEND ;;              ac_prev=PKG_DEPEND ;;
1229          -pdepend=* | --pdepend=*)          -pdepend=* | --pdepend=*)
1230              PDEPEND=$ac_optarg ;;              PKG_DEPEND=$ac_optarg ;;
1231                    
1232          -pdefault | --pdefault)          -pgroups | --pgroups)
1233              ac_prev=PDEFAULT ;;              ac_prev=PKG_GROUPS ;;
1234          -pdefault=* | --pdefault=*)          -pgroups=* | --pgroups=*)
1235              PDEFAULT=$ac_optarg ;;              PKG_GROUPS=$ac_optarg ;;
1236                    
1237          -make | --make | -m | --m)          -make | --make | -m | --m)
1238              ac_prev=MAKE ;;              ac_prev=MAKE ;;
# Line 1187  for ac_option in "$@" ; do Line 1316  for ac_option in "$@" ; do
1316          -noieee | --noieee)          -noieee | --noieee)
1317              IEEE= ;;              IEEE= ;;
1318    
1319            -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4 )
1320                USE_R4=true ;;
1321    
1322          -ts | --ts)          -ts | --ts)
1323              TS=true ;;              TS=true ;;
1324            -papis | --papis)
1325                PAPIS=true ;;
1326            -pcls | --pcls)
1327                PCLS=true ;;
1328            -foolad | --foolad)
1329                FOOLAD=true ;;
1330            -papi | --papi)
1331                PAPI=true ;;
1332            -pcl | --pcl)
1333                PCL=true ;;
1334            -hpmt | --hpmt)
1335                HPMT=true ;;
1336    
1337            -gsl | --gsl)
1338                GSL=true ;;
1339    
1340            -devel | --devel)
1341                DEVEL=true ;;
1342    
1343          -mpi | --mpi)          -mpi | --mpi)
1344              MPI=true ;;              MPI=true ;;
# Line 1196  for ac_option in "$@" ; do Line 1346  for ac_option in "$@" ; do
1346              MPIPATH=$ac_optarg              MPIPATH=$ac_optarg
1347              MPI=true ;;              MPI=true ;;
1348                    
1349  #       -jam | --jam)          -omp | --omp)
1350  #           JAM=1 ;;              OMP=true ;;
1351  #       -nojam | --nojam)          -omp=* | --omp=*)
1352  #           JAM=0 ;;              OMPFLAG=$ac_optarg
1353                OMP=true ;;
1354                    
1355          -ds | --ds)          -ds | --ds)
1356              DUMPSTATE=t ;;              DUMPSTATE=t ;;
# Line 1217  for ac_option in "$@" ; do Line 1368  for ac_option in "$@" ; do
1368          -ignoretime | -ignore_time | --ignoretime | --ignore_time)          -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1369              IGNORE_TIME="-DIGNORE_TIME" ;;              IGNORE_TIME="-DIGNORE_TIME" ;;
1370    
1371            -es | --es | -embed-source | --embed-source)
1372                EMBED_SRC=t ;;
1373    
1374          -*)          -*)
1375              echo "Error: unrecognized option: "$ac_option              echo "Error: unrecognized option: "$ac_option
1376              usage              usage
# Line 1228  for ac_option in "$@" ; do Line 1382  for ac_option in "$@" ; do
1382              ;;              ;;
1383                    
1384      esac      esac
       
 done  
1385    
1386    done
1387    
1388  if test -f ./.genmakerc ; then  if test -f ./.genmakerc ; then
1389      echo      echo
1390      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
1391      echo "  file.  This file format is no longer supported.  Please see:"      echo "  file.  This file format is no longer supported.  For directions on"
1392      echo      echo "  how to setup and use the new \"genmake2\" script, please see:"
1393      echo "    http://mitgcm.org/devel_HOWTO/"      echo "    http://mitgcm.org/devel_HOWTO/"
1394        echo "  and send an email to MITgcm-support@mitgcm.org if you need help."
1395        echo "WARNING: ignore \"./.genmakerc\" and continue."
1396      echo      echo
     echo "  for directions on how to setup and use the new \"genmake2\" input"  
     echo "  files and send an email to MITgcm-support@mitgcm.org if you want help."  
     echo  
1397  fi  fi
1398    
1399  #  Find the MITgcm ${ROOTDIR}  #  Find the MITgcm ${ROOTDIR}
1400  if test "x${ROOTDIR}" = x ; then  if test "x${ROOTDIR}" = x ; then
1401      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1402      if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then      if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesupp -a -d ../pkg ; then
1403          ROOTDIR=".."          ROOTDIR=".."
1404      else      else
1405          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1406              if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then              if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
1407                  ROOTDIR=$d                  ROOTDIR=$d
1408                  printf "Warning:  ROOTDIR was not specified but there appears to be"                  printf "Warning: ROOTDIR was not specified ;"
1409                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."                  echo " try using a local copy of MITgcm found at \"$ROOTDIR\""
1410                  break                  break
1411              fi              fi
1412          done          done
# Line 1272  if test ! -d ${ROOTDIR} ; then Line 1424  if test ! -d ${ROOTDIR} ; then
1424  fi  fi
1425    
1426  #  Find the MITgcm ${THISVER}  #  Find the MITgcm ${THISVER}
1427  if test -f "${ROOTDIR}/doc/tag-index" ; then  version_file="${ROOTDIR}/doc/tag-index"
1428      THISVER=`grep '^checkpoint' ${ROOTDIR}/doc/tag-index | head -1`  if test -f $version_file ; then
1429        THISVER=`$AWK '/^checkpoint/{print $1; exit}' $version_file`
1430    #-  remove ./BUILD_INFO.h file if older than version_file
1431        if test -f ./BUILD_INFO.h -a ./BUILD_INFO.h -ot $version_file ; then
1432            echo "  remove ./BUILD_INFO.h (older than ${version_file})"
1433            rm -f ./BUILD_INFO.h
1434        fi
1435  fi  fi
1436    
1437  if test "x$MAKEFILE" = x ; then  if test "x$MAKEFILE" = x ; then
# Line 1285  if test "x${OPTFILE}" = x ; then Line 1443  if test "x${OPTFILE}" = x ; then
1443      if test "x$MITGCM_OF" = x ; then      if test "x$MITGCM_OF" = x ; then
1444          echo "Warning: no OPTFILE specified so we'll look for possible settings"          echo "Warning: no OPTFILE specified so we'll look for possible settings"
1445          printf "\n===  Searching for possible settings for OPTFILE  ===\n"          printf "\n===  Searching for possible settings for OPTFILE  ===\n"
1446          find_possible_configs          find_possible_optfile
1447      else      else
1448          OPTFILE=$MITGCM_OF          OPTFILE=$MITGCM_OF
1449      fi      fi
# Line 1300  if test "x$OPTFILE" != xNONE ; then Line 1458  if test "x$OPTFILE" != xNONE ; then
1458              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1459              exit 1              exit 1
1460          fi          fi
1461          if test "x$DUMPSTATE" != xf ; then          if test "x$DUMPSTATE" = xt ; then
1462              cp -f $OPTFILE "genmake_optfile"              cp -f $OPTFILE "genmake_optfile"
1463          fi          fi
1464      else      else
# Line 1327  if test "x${AD_OPTFILE}" != xNONE ; then Line 1485  if test "x${AD_OPTFILE}" != xNONE ; then
1485              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1486              exit 1              exit 1
1487          fi          fi
1488          if test "x$DUMPSTATE" != xf ; then          if test "x$DUMPSTATE" = xt ; then
1489              cp -f $AD_OPTFILE "genmake_ad_optfile"              cp -f $AD_OPTFILE "genmake_ad_optfile"
1490          fi          fi
1491      else      else
# Line 1355  Error: no Fortran compiler: please speci Line 1513  Error: no Fortran compiler: please speci
1513  EOF  EOF
1514      exit 1      exit 1
1515  fi  fi
1516    if test "x$GET_FC_VERSION" != x ; then
1517      echo "Get compiler version using: $FC $GET_FC_VERSION" >> $LOGFILE
1518      $FC $GET_FC_VERSION >> $LOGFILE 2>&1
1519      echo "<-- compiler version ----" >> $LOGFILE
1520    fi
1521    
1522  if test "x$CC" = x ; then  if test "x$CC" = x ; then
1523      CC=cc      look_for_C_compilers
 #     cat <<EOF 1>&2  
 # Error: no C compiler: please specify using one of the following:  
 #   1) within the options file ("CC=...") as specified by "-of=OPTFILE"  
 #   2) the "-cc=XXX" command-line option  
 #   3) the "./genmake_local" file  
 # EOF  
 #     exit 1  
1524  fi  fi
1525    
1526  if test "x$LINK" = x ; then  if test "x$LINK" = x ; then
1527      LINK=$FC      LINK=$FC
1528  fi  fi
# Line 1372  if test "x$MAKE" = x ; then Line 1530  if test "x$MAKE" = x ; then
1530      MAKE="make"      MAKE="make"
1531  fi  fi
1532  if test "x$CPP" = x ; then  if test "x$CPP" = x ; then
1533      CPP=cpp      CPP="cpp -traditional -P"
1534  fi  fi
1535  #EH3 === UGLY ===  #EH3 === UGLY ===
1536  #  The following is an ugly little hack to check for $CPP in /lib/ and  #  The following is an ugly little hack to check for $CPP in /lib/ and
# Line 1399  EOF Line 1557  EOF
1557  else  else
1558      rm -f test_cpp      rm -f test_cpp
1559  fi  fi
1560    
1561  look_for_makedepend  look_for_makedepend
1562    
1563    #  Check that soft-link command is set and usable
1564  if test "x$LN" = x ; then  if test "x$LN" = x ; then
1565      LN="ln -s"      LN="ln -s"
1566  fi  fi
# Line 1409  RETVAL=$? Line 1570  RETVAL=$?
1570  if test "x$RETVAL" != x0 ; then  if test "x$RETVAL" != x0 ; then
1571      cat <<EOF 1>&2      cat <<EOF 1>&2
1572    
1573  Error: The command "ln -s" failed -- please specify a working soft-link  Error: The command "$LN" failed -- please specify a working soft-link
1574    command in the optfile.    command in the optfile.
1575    
1576  EOF  EOF
# Line 1429  if test ! "x$MPI" = x ; then Line 1590  if test ! "x$MPI" = x ; then
1590        echo "  Turning on MPI cpp macros"        echo "  Turning on MPI cpp macros"
1591        DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"        DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
1592  fi  fi
1593    if test ! "x$OMP" = x ; then
1594          echo "  Add OMPFLAG and turn on OpenMP cpp macros"
1595          FFLAGS="$FFLAGS $OMPFLAG"
1596          F90FLAGS="$F90FLAGS $OMPFLAG"
1597          DEFINES="$DEFINES -DUSE_OMP_THREADING"
1598    fi
1599    
1600    if test ! "x$USE_R4" = x ; then
1601          echo "  Turning on LET_RS_BE_REAL4 cpp flag"
1602          DEFINES="$DEFINES -DLET_RS_BE_REAL4"
1603    fi
1604    
1605  if test ! "x$TS" = x ; then  if test ! "x$TS" = x ; then
1606        echo "  Turning on timing per timestep"        echo "  Turning on timing per timestep"
1607        DEFINES="$DEFINES -DTIME_PER_TIMESTEP"        if test ! "x$FOOLAD" = x ; then
1608                DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP"
1609          else
1610                DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1611          fi
1612          PACKAGES="$PACKAGES showflops"
1613    fi
1614    if test ! "x$PAPIS" = x ; then
1615          echo "  Turning on PAPI flop summary per timestep"
1616          echo "  Please make sure PAPIINC, PAPILIB are defined"
1617          if test ! "x$FOOLAD" = x ; then
1618                DEFINES="$DEFINES -DUSE_PAPI_FLOPS_SFP"
1619          else
1620                DEFINES="$DEFINES -DUSE_PAPI_FLOPS"
1621          fi
1622          INCLUDES="$INCLUDES $PAPIINC"
1623          LIBS="$LIBS $PAPILIB"
1624          PACKAGES="$PACKAGES showflops"
1625    fi
1626    if test ! "x$PCLS" = x ; then
1627          echo "  Turning on PCL counter summary per timestep"
1628          echo "  Please make sure PCLINC, PCLLIB are defined"
1629          if test ! "x$FOOLAD" = x ; then
1630                DEFINES="$DEFINES -DUSE_PCL_FLOPS_SFP"
1631          else
1632                DEFINES="$DEFINES -DUSE_PCL_FLOPS"
1633          fi
1634          INCLUDES="$INCLUDES $PCLINC"
1635          LIBS="$LIBS $PCLLIB"
1636          PACKAGES="$PACKAGES showflops"
1637    fi
1638    if test ! "x$PAPI" = x ; then
1639          if test ! "x$PAPIS" = x ; then
1640              echo "  PAPI performance analysis and flop summary per timestep cannot co-exist!"
1641              echo "  Sticking with PAPI flop summary per timestep!"
1642          else
1643              echo "  Turning on performance analysis with PAPI"
1644              echo "  Please make sure PAPIINC, PAPILIB are defined"
1645              DEFINES="$DEFINES -DUSE_PAPI"
1646              INCLUDES="$INCLUDES $PAPIINC"
1647              LIBS="$LIBS $PAPILIB"
1648          fi
1649    fi
1650    if test ! "x$PCL" = x ; then
1651          if test ! "x$PCLS" = x ; then
1652              echo "  PCL performance analysis and flop summary per timestep cannot co-exist!"
1653              echo "  Sticking with PCL flop summary per timestep!"
1654          else
1655              echo "  Turning on performance analysis with PCL"
1656              echo "  Please make sure PCLINC, PCLLIB are defined"
1657              DEFINES="$DEFINES -DUSE_PCL"
1658              INCLUDES="$INCLUDES $PCLINC"
1659              LIBS="$LIBS $PCLLIB"
1660          fi
1661    fi
1662    if test ! "x$HPMT" = x ; then
1663          if test ! "x$PAPI" = x ; then
1664              echo "  PAPI and the HPM Toolkit cannot co-exist!"
1665              echo "  Sticking with PAPI!"
1666          else if test ! "x$PCL" = x ; then
1667              echo "  PCL and the HPM Toolkit cannot co-exist!"
1668              echo "  Sticking with PCL!"
1669          else
1670              echo "  Turning on performance analysis with the HPM Toolkit"
1671              echo "  Please make sure HPMTINC, HPMTLIB are defined"
1672              DEFINES="$DEFINES -DUSE_LIBHPM"
1673              INCLUDES="$INCLUDES $HPMTINC"
1674              LIBS="$LIBS $HPMTLIB"
1675          fi
1676          fi
1677    fi
1678    if test ! "x$GSL" = x ; then
1679          echo "  Turning on use of GSL to control floating point calculations"
1680          echo "  Please make sure GSLINC, GSLLIB are defined"
1681          DEFINES="$DEFINES -DUSE_GSL_IEEE"
1682          INCLUDES="$INCLUDES $GSLINC"
1683          LIBS="$LIBS $GSLLIB"
1684    fi
1685    #- if USE_EXTENDED_SRC is set, add EXTENDED_SRC_FLAG to FFLAGS :
1686    if test ! "x$USE_EXTENDED_SRC" = x ; then
1687          FFLAGS="$FFLAGS $EXTENDED_SRC_FLAG"
1688          F90FIXEDFORMAT="$F90FIXEDFORMAT $EXTENDED_SRC_FLAG"
1689  fi  fi
1690    
1691  printf "\n===  Checking system libraries  ===\n"  printf "\n===  Checking system libraries  ===\n"
# Line 1503  if test "x$HAVE_CLOC" != x ; then Line 1756  if test "x$HAVE_CLOC" != x ; then
1756      echo "yes"      echo "yes"
1757  else  else
1758      echo "no"      echo "no"
1759        if test "x$EMBED_SRC" = xt ; then
1760            echo "    WARNING: you requested file embedding but it has"
1761            echo "      been disabled since C code cannot be called"
1762            EMBED_SRC=
1763        fi
1764  fi  fi
1765  rm -f genmake_t*  rm -f genmake_t*
1766    
1767  printf "  Can we unlimit the stack size using $FC...  "  printf "  Can we unlimit the stack size using $FC...  "
1768  check_HAVE_SETRLSTK  check_HAVE_SETRLSTK
1769  if test "x$HAVE_SETRLSTK" != x ; then  if test "x$HAVE_SETRLSTK" = xt ; then
1770      echo "yes"      echo "yes"
1771  else  else
1772      echo "no"      echo "no"
# Line 1517  rm -f genmake_t* Line 1775  rm -f genmake_t*
1775    
1776  printf "  Can we register a signal handler using $FC...  "  printf "  Can we register a signal handler using $FC...  "
1777  check_HAVE_SIGREG  check_HAVE_SIGREG
1778  if test "x$HAVE_SIGREG" != x ; then  if test "x$HAVE_SIGREG" = xt ; then
1779      echo "yes"      echo "yes"
1780  else  else
1781      echo "no"      echo "no"
# Line 1542  else Line 1800  else
1800  fi  fi
1801  DEFINES="$DEFINES $IGNORE_TIME"  DEFINES="$DEFINES $IGNORE_TIME"
1802    
1803    if test "x$EMBED_SRC" = xt ; then
1804        build_embed_encode
1805    fi
1806    if test "x$EMBED_SRC" = xt ; then
1807        ENABLE="$ENABLE embed_files"
1808    fi
1809    
1810  printf "\n===  Setting defaults  ===\n"  printf "\n===  Setting defaults  ===\n"
1811  printf "  Adding MODS directories:  "  printf "  Adding MODS directories: "
1812  for d in $MODS ; do  for d in $MODS ; do
1813      if test ! -d $d ; then      if test ! -d $d ; then
1814          echo          echo
1815          echo "Error: MODS directory \"$d\" not found!"          echo "Error: MODS directory \"$d\" not found!"
1816          exit 1          exit 1
1817      else      else
1818          printf " $d"          printf "$d "
1819          SOURCEDIRS="$SOURCEDIRS $d"          SOURCEDIRS="$SOURCEDIRS $d"
1820          INCLUDEDIRS="$INCLUDEDIRS $d"          INCLUDEDIRS="$INCLUDEDIRS $d"
1821      fi      fi
1822  done  done
1823  echo  echo
1824    
1825  if test "x${PLATFORM}" = x ; then  #if test "x${PLATFORM}" = x ; then
1826      PLATFORM=$p_PLATFORM  #    PLATFORM=$p_PLATFORM
1827  fi  #fi
1828    
1829  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
1830      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
# Line 1599  ERROR: neither of the two default script Line 1864  ERROR: neither of the two default script
1864      ${TOOLSDIR}/set64bitConst.sh      ${TOOLSDIR}/set64bitConst.sh
1865      ${TOOLSDIR}/set64bitConst.csh      ${TOOLSDIR}/set64bitConst.csh
1866    
1867    are working so please check paths or specify (with \$S64) a    are working so please check paths or specify (with \$S64) a
1868    working version of this script.    working version of this script.
1869    
1870  EOF  EOF
# Line 1611  THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSD Line 1876  THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSD
1876    
1877  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1878    
1879    #  Set Standard Code Directories:
1880    if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
1881        STANDARDDIRS="eesupp model"
1882    fi
1883    #  if model in Standard-Code-Dir, add eesupp (needed to compile model)
1884    echo " $STANDARDDIRS " | grep ' model ' > /dev/null 2>&1
1885    ckM=$?
1886    echo " $STANDARDDIRS " | grep ' eesupp ' > /dev/null 2>&1
1887    ckE=$?
1888    if test $ckM = 0 -a $ckE = 1 ; then
1889        STANDARDDIRS="$STANDARDDIRS eesupp"
1890    fi
1891    
1892  #  We have a special set of source files in eesupp/src which are  #  We have a special set of source files in eesupp/src which are
1893  #  generated from some template source files. We'll make them first so  #  generated from some template source files. We'll make them first so
1894  #  they appear as regular source code  #  they appear as regular source code
1895  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
1896      echo "  Making source files in eesupp from templates"      echo "  Making source files in eesupp from templates"
1897      ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1      ( cd $ROOTDIR"/eesupp/src/" && $MAKE clean_old && $MAKE \
1898        ) > make_eesupp.errors 2>&1
1899      RETVAL=$?      RETVAL=$?
1900      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
1901          rm -f make_eesupp.errors          rm -f make_eesupp.errors
# Line 1627  if test -r $ROOTDIR"/eesupp/src/Makefile Line 1906  if test -r $ROOTDIR"/eesupp/src/Makefile
1906      fi      fi
1907  fi  fi
1908    
1909  #same for exch2  #same for pkg/exch2 and pkg/regrid
1910  if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then  for pdir in exch2 regrid ; do
1911      echo "  Making source files in exch2 from  templates"      if test -r $ROOTDIR"/pkg/${pdir}/Makefile" ; then
1912      ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1          echo "  Making source files in pkg/${pdir} from templates"
1913      RETVAL=$?          ( cd $ROOTDIR"/pkg/"${pdir} && $MAKE clean_old && $MAKE \
1914      if test "x${RETVAL}" = x0 ; then          ) > make_${pdir}.errors 2>&1
1915          rm -f make_exch2.errors          RETVAL=$?
1916      else          if test "x${RETVAL}" = x0 ; then
1917          echo "Error: problem encountered while building source files in exch2:"              rm -f make_${pdir}.errors
1918          cat make_exch2.errors 1>&2          else
1919          exit 1              echo "Error: problem encountered while building source files in pkg/${pdir}:"
1920                cat make_${pdir}.errors 1>&2
1921                exit 1
1922            fi
1923      fi      fi
1924  fi  done
1925    
1926  printf "\n===  Determining package settings  ===\n"  printf "\n===  Determining package settings  ===\n"
1927  if  test "x${PDEPEND}" = x ; then  if  test "x${PKG_DEPEND}" = x ; then
1928      tmp=$ROOTDIR"/pkg/pkg_depend"      tmp=$ROOTDIR"/pkg/pkg_depend"
1929      if test -r $tmp ; then      if test -r $tmp ; then PKG_DEPEND=$tmp ; fi
1930          PDEPEND=$tmp  fi
1931      else  if  test "x${PKG_DEPEND}" = x ; then
1932          echo "Warning:  No package dependency information was specified."          echo "Warning:  No package dependency information was specified."
1933          echo "  Please check that ROOTDIR/pkg/pkg_depend exists."          echo "  Please check that ROOTDIR/pkg/pkg_depend exists."
     fi  
1934  else  else
1935      if test ! -r ${PDEPEND} ; then      if test ! -r ${PKG_DEPEND} ; then
1936          echo "Error:  can't read package dependency info from PDEPEND=\"$PDEPEND\""          echo "Error:  can't read package dependency info from PKG_DEPEND=\"$PKG_DEPEND\""
1937          exit 1          exit 1
1938      fi      fi
1939        echo "  getting package dependency info from  $PKG_DEPEND"
1940    #  Strip the comments and then convert the dependency file into arrays: PNAME, DNAME
1941        get_pdepend_list $PKG_DEPEND
1942  fi  fi
1943  echo "  getting package dependency info from  $PDEPEND"  
1944  #  Strip the comments and then convert the dependency file into  # A default package groups file "$ROOTDIR/pkg/pkg_groups" is provided
1945  #  two arrays: PNAME, DNAME  #  to define the "default_pkg_list" and package groups (for convenience, one
1946  cat $PDEPEND | sed -e 's/#.*$//g' \  #  can specify a group of packages using names like "ocean" and "atmosphere").
1947      | $AWK 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \  if test "x${PKG_GROUPS}" = x ; then
1948      > ./.pd_tmp      tmp=$ROOTDIR"/pkg/pkg_groups"
1949  RETVAL=$?      if test -r $tmp ; then PKG_GROUPS=$tmp ; fi
1950  if test ! "x${RETVAL}" = x0 ; then  fi
1951      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""  if test "x${PKG_GROUPS}" = x ; then
1952      exit 1          echo "Warning:  No package groups information was specified."
1953            echo "  Please check that ROOTDIR/pkg/pkg_groups exists."
1954    else
1955        if test ! -r ${PKG_GROUPS} ; then
1956            echo "Error:  can't read package groups info from PKG_GROUPS=\"$PKG_GROUPS\""
1957            exit 1
1958        fi
1959        echo "  getting package groups info from      $PKG_GROUPS"
1960  fi  fi
 . ./.pd_tmp  
 rm -f ./.pd_tmp  
1961    
1962  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"  #  Search for packages to compile.
1963  #  file should eventually be added so that, for convenience, one can  echo "  checking list of packages to compile:"
1964  #  specify groups of packages using names like "ocean" and "atmosphere".  PKG_LIST=
1965  echo "  checking default package list:  "  if test "x${PKG_LIST}" = x ; then
 if test "x${PDEFAULT}" = x ; then  
1966      for i in "." $MODS ; do      for i in "." $MODS ; do
1967          if test -r $i"/packages.conf" ; then          if test -r $i"/packages.conf" ; then
1968                  PDEFAULT=$i"/packages.conf"                  PKG_LIST=$i"/packages.conf"
1969                  break                  break
1970          fi          fi
1971      done      done
1972  fi  fi
1973  if test "x${PDEFAULT}" = x ; then  if test "x${PKG_LIST}" = x ; then
1974      PDEFAULT="$ROOTDIR/pkg/pkg_default"      pkg_list='default_pkg_list'
1975  fi      if test "x${PKG_GROUPS}" = x ; then
1976  if test "x${PDEFAULT}" = xNONE ; then          echo "Error:  need package groups info to expand pkg_list=\"$pkg_list\""
1977      echo "    default packages file disabled"          exit 1
1978        fi
1979  else  else
1980      if test ! -r $PDEFAULT ; then      if test ! -r $PKG_LIST ; then
1981          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""          echo "Error:  can't read package list from PKG_LIST=\"$PKG_LIST\""
1982            exit 1
1983      else      else
1984          echo "    using PDEFAULT=\"$PDEFAULT\""          echo "    using PKG_LIST=\"$PKG_LIST\""
1985          #  Strip the comments and add all the names          #  Strip the comments and add all the names
1986          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`          pkg_list=`cat $PKG_LIST | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
1987          RETVAL=$?          RETVAL=$?
1988          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
1989              printf "Error: can't parse default package list "              printf "Error: can't parse package list "
1990              echo "-- please check PDEFAULT=\"$PDEFAULT\""              echo "-- please check PKG_LIST=\"$PKG_LIST\""
1991              exit 1              exit 1
1992          fi          fi
         for i in $def ; do  
             PACKAGES="$PACKAGES $i"  
         done  
         echo "    before group expansion packages are: $PACKAGES"  
         RET=1  
         while test $RET = 1 ; do expand_pkg_groups; RET=$?; done  
         echo "    after group expansion packages are:  $PACKAGES"  
1993      fi      fi
1994  fi  fi
1995    for i in $pkg_list ; do
1996        PACKAGES="$PACKAGES $i"
1997    done
1998    echo     "    before group expansion packages are:$PACKAGES"
1999    if test "x${PKG_GROUPS}" != x ; then
2000        RET=1
2001        while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
2002        echo "    after group expansion packages are: $PACKAGES"
2003    fi
2004    
2005  echo "  applying DISABLE settings"  echo "  applying DISABLE settings"
2006    echo "" > ./.tmp_pack
2007  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2008      echo $i >> ./.tmp_pack      echo $i >> ./.tmp_pack
2009  done  done
# Line 1738  PACKAGES="$PACKAGES $ENABLE" Line 2031  PACKAGES="$PACKAGES $ENABLE"
2031  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2032      j=`echo $i | sed 's/[-+]//'`      j=`echo $i | sed 's/[-+]//'`
2033      if test ! -d "$ROOTDIR/pkg/$j" ; then      if test ! -d "$ROOTDIR/pkg/$j" ; then
2034          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""          echo "Error: dir '$ROOTDIR/pkg/$i' missing for package '$i'"
2035          exit 1          exit 1
2036      fi      fi
2037      echo $i >> ./.tmp_pack      echo $i >> ./.tmp_pack
# Line 1748  for i in `grep -v "-" ./.tmp_pack | sort Line 2041  for i in `grep -v "-" ./.tmp_pack | sort
2041      PACKAGES="$PACKAGES $i"      PACKAGES="$PACKAGES $i"
2042  done  done
2043  rm -f ./.tmp_pack  rm -f ./.tmp_pack
2044  echo "    packages are:  $PACKAGES"  echo "    packages are: $PACKAGES"
2045    
2046  #  Check availability of NetCDF and then either build the MNC template  #  Check for package MNC: if NetCDF is available, then build the MNC
2047  #  files or delete mnc from the list of available packages.  #  template files ; otherwise, delete mnc from the list of packages.
2048  echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1  echo " $PACKAGES " | grep ' mnc ' > /dev/null 2>&1
2049  RETVAL=$?  mnc_in=$?
2050  if test "x$RETVAL" = x0 ; then  if test "x$HAVE_NETCDF" != xt ; then
2051      if test "x$HAVE_NETCDF" != xt ; then      if test "x$mnc_in" = x0 ; then
2052          cat <<EOF          cat <<EOF
   
2053  *********************************************************************  *********************************************************************
2054  WARNING: the "mnc" package was enabled but tests failed to compile  WARNING: the "mnc" package was enabled but tests failed to compile
2055    NetCDF applications.  Please check that:    NetCDF applications.  Please check that:
2056    
2057    1) NetCDF is correctly installed for this compiler and    1) NetCDF is correctly installed for this compiler and
2058    2) the LIBS variable (within the "optfile") specifies the correct    2) the LIBS variable (within the "optfile") specifies the correct
2059         NetCDF library to link against.         NetCDF library to link against.
2060    
2061    Due to this failure, the "mnc" package is now DISABLED.    Due to this failure, the "mnc" package is now DISABLED.
2062  *********************************************************************  *********************************************************************
   
2063  EOF  EOF
2064          PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`          PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
2065          DISABLE="$DISABLE mnc"          DISABLE="$DISABLE mnc"
2066      else      else
2067          ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1      #  this prevent to add mnc (due to pdepend rules) if not available
2068          RETVAL=$?          DISABLE="$DISABLE mnc"
2069          if test "x${RETVAL}" = x0 ; then      fi
2070              rm -f make_mnc.errors  else
2071        # we have NetCDF, we try to build MNC template files
2072        ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
2073        RETVAL=$?
2074        if test "x${RETVAL}" = x0 ; then
2075            rm -f make_mnc.errors
2076        else
2077            echo "Error: problem encountered while building source files in pkg/mnc:"
2078            cat make_mnc.errors 1>&2
2079            if test "x$mnc_in" = x0 ; then
2080                exit 1
2081          else          else
2082              echo "Error: problem encountered while building source files in pkg/mnc:"              DISABLE="$DISABLE mnc"
             cat make_mnc.errors 1>&2  
             exit 1  
2083          fi          fi
2084      fi      fi
2085  fi  fi
2086    
2087  echo "  applying package dependency rules"  #  Check for package PROFILES: if NetCDF is not available,
2088  ck=  #  then delete profiles from the list of available packages.
2089  while test "x$ck" != xtt ; do  if test "x$HAVE_NETCDF" != xt ; then
2090        echo " $PACKAGES " | grep ' profiles ' > /dev/null 2>&1
2091        RETVAL=$?
2092        if test "x$RETVAL" = x0 ; then
2093            cat <<EOF
2094    *********************************************************************
2095    WARNING: the "profiles" package was enabled but tests failed to
2096      compile NetCDF applications.  Please check that:
2097    
2098      1) NetCDF is correctly installed for this compiler and
2099      2) the LIBS variable (within the "optfile") specifies the correct
2100           NetCDF library to link against.
2101    
2102      Due to this failure, the "profiles" package is now DISABLED.
2103    *********************************************************************
2104    EOF
2105            PACKAGES=`echo $PACKAGES | sed -e 's/profiles//g'`
2106            DISABLE="$DISABLE profiles"
2107        else
2108        #  this prevent to add profiles (due to pdepend rules) if not available
2109            DISABLE="$DISABLE profiles"
2110        fi
2111    fi
2112    
2113    if  test "x${PKG_DEPEND}" != x ; then
2114      echo "  applying package dependency rules"
2115      ck=
2116      while test "x$ck" != xtt ; do
2117      i=0      i=0
2118      # rtot=${#PNAME[@]}      # rtot=${#PNAME[@]}
2119      rtot=$nname      rtot=$nname
2120      while test $i -lt $rtot ; do      while test $i -le $rtot ; do
2121    
2122          #  Is $pname in the current $PACKAGES list?          #  Is $pname in the current $PACKAGES list?
2123          #  pname=${PNAME[$i]}          #  pname=${PNAME[$i]}
# Line 1803  while test "x$ck" != xtt ; do Line 2129  while test "x$ck" != xtt ; do
2129                  pin="t"                  pin="t"
2130              fi              fi
2131          done          done
2132            #  or in the current $STANDARDDIRS list?
2133            for p in $STANDARDDIRS ; do
2134                if test "x$p" = "x$pname" ; then pin="t" ; fi
2135            done
2136    
2137          #  Is the DNAME entry a (+) or (-) rule ?          #  Is the DNAME entry a (+) or (-) rule ?
2138          tmp="dname=\"\$DNAME_$i\""          tmp="dname=\"\$DNAME_$i\""
# Line 1825  while test "x$ck" != xtt ; do Line 2155  while test "x$ck" != xtt ; do
2155    
2156          #  Do we need to add $dname according to the dependency rules?          #  Do we need to add $dname according to the dependency rules?
2157          if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then          if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then
2158                #echo "   " $pname ": need to add :" $dname
2159              in_dis="f"              in_dis="f"
2160              for dis in $DISABLE ; do              for dis in $DISABLE ; do
2161                  if test "x$dis" = "x$dname" ; then                  if test "x$dis" = "x$dname" ; then
# Line 1845  while test "x$ck" != xtt ; do Line 2176  while test "x$ck" != xtt ; do
2176          #  Do we need to get rid of $dname according to the dependency rules?          #  Do we need to get rid of $dname according to the dependency rules?
2177          if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then          if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then
2178              echo "Error: can't satisfy package dependencies:"              echo "Error: can't satisfy package dependencies:"
2179              echo "  \"$pname\" was requested but is disallowed by"              echo "  \"$pname\" was requested but is disallowed by"
2180              echo "  the dependency rules for \"$dname\""              echo "  the dependency rules for \"$dname\""
2181              exit 1              exit 1
2182          fi          fi
# Line 1853  while test "x$ck" != xtt ; do Line 2184  while test "x$ck" != xtt ; do
2184          #i=$(( $i + 1 ))          #i=$(( $i + 1 ))
2185      done      done
2186      ck=$ck"t"      ck=$ck"t"
2187  done    done
2188  echo "    packages are:  $PACKAGES"    echo "    packages are: $PACKAGES"
2189    fi
2190  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2191      adr="$ROOTDIR/pkg/$i"      adr="$ROOTDIR/pkg/$i"
2192      if test -d $adr ; then      if test -d $adr ; then
# Line 1871  done Line 2203  done
2203    
2204  # Create a list of #define and #undef to enable/disable packages  # Create a list of #define and #undef to enable/disable packages
2205  PACKAGES_DOT_H=PACKAGES_CONFIG.h  PACKAGES_DOT_H=PACKAGES_CONFIG.h
2206  #  The following UGLY HACK sets multiple "#undef"s and it needs to go  #  The following UGLY HACK sets multiple "#undef"s and it needs to go
2207  #  away.  On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h  #  away.  On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
2208  #  file would eventually be split up so that all package-related #define  #  file would eventually be split up so that all package-related #define
2209  #  statements could be separated and handled only by genmake.  #  statements could be separated and handled only by genmake.
2210  names=`ls -1 "$ROOTDIR/pkg"`  names=`ls -1 "$ROOTDIR/pkg"`
# Line 1900  for i in $PACKAGES ; do Line 2232  for i in $PACKAGES ; do
2232  #eh3 DEFINES="$DEFINES -D$def"  #eh3 DEFINES="$DEFINES -D$def"
2233    
2234  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
2235      case $i in      case $i in
2236          aim_v23)          aim_v23)
2237              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
2238              echo "Warning: ALLOW_AIM is set to enable aim_v23."              echo "Warning: ALLOW_AIM is set to enable aim_v23."
# Line 1910  for i in $PACKAGES ; do Line 2242  for i in $PACKAGES ; do
2242    
2243  done  done
2244    
2245  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS='$STANDARDDIRS'"
2246  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
 if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then  
     STANDARDDIRS="eesupp model"  
 fi  
2247  if test "x$STANDARDDIRS" != x ; then  if test "x$STANDARDDIRS" != x ; then
2248      for d in $STANDARDDIRS ; do      for d in $STANDARDDIRS ; do
2249          adr="$ROOTDIR/$d/src"          adr="$ROOTDIR/$d/src"
# Line 1969  fi Line 2298  fi
2298    
2299  #  Here, we build the list of files to be "run through" the adjoint  #  Here, we build the list of files to be "run through" the adjoint
2300  #  compiler.  #  compiler.
2301  if test -f ./ad_files ; then  if test -f ./adSrcFiles.tmp ; then
2302      rm -f ./ad_files      rm -f ./adSrcFiles.tmp
2303  fi  fi
2304  echo "  Creating the list of files for the adjoint compiler."  echo "  Creating the list of files for the adjoint compiler."
2305    touch adSrcFiles.tmp
2306  for i in $SOURCEDIRS ; do  for i in $SOURCEDIRS ; do
2307      list_files=`( cd $i && ls -1 *.list 2>/dev/null )`      list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
2308      for j in $list_files ; do      for j in $list_files ; do
2309          cat $i/$j >> ad_files          cat $i/$j >> adSrcFiles.tmp
2310      done      done
2311  done  done
2312  if test ! "x"$FS = "x.f" ; then  if test ! "x"$FS = "x.f" ; then
2313      cat ad_files | sed -e "s/\.f/.$FS/g" > ad_files_f      cat adSrcFiles.tmp | sed -e "s/\.f/.$FS/g" > adSrcFiles.tmp_f
2314      mv -f ad_files_f ad_files      mv -f adSrcFiles.tmp_f adSrcFiles.tmp
2315  fi  fi
2316    
2317  echo  echo
# Line 1993  for i in $INCLUDEDIRS ; do Line 2323  for i in $INCLUDEDIRS ; do
2323      fi      fi
2324  done  done
2325    
2326    if test ! "x$DIVA" = x ; then
2327        echo "  Creating the pseudo-MPI include directory"
2328        INCLUDES="-I./mpi_headers $INCLUDES"
2329        rm -rf ./mpi_headers
2330        mkdir -p ./mpi_headers
2331    
2332        if test "x$MPIINCLUDEDIR" = x ; then
2333            if test "x$MPIHOME" = x ; then
2334                MPIHOME='/usr'
2335            fi
2336            MPIINCLUDEDIR='$MPIHOME/include'
2337        fi
2338    
2339        if test -r $MPIINCLUDEDIR/mpif.h ; then
2340            for i in $MPI_HEADER_FILES; do
2341                cp -p $MPIINCLUDEDIR/$i ./mpi_headers
2342            done
2343    
2344            perl -i -pe 's/MPI_DISPLACEMENT_CURRENT=-1_8/MPI_DISPLACEMENT_CURRENT=-1/g' mpi_headers/mpif.h
2345        else
2346            echo " We cannot create a copy of mpif.h!"
2347    #       exit -1
2348        fi
2349    fi
2350    
2351  echo "  Determining the list of source and include files"  echo "  Determining the list of source and include files"
2352  rm -rf .links.tmp  rm -rf .links.tmp
2353  mkdir .links.tmp  mkdir .links.tmp
2354    touch .links.tmp/foo
2355    if test ! -r ".links.tmp/foo" ; then
2356        echo
2357        echo "ERROR : something is wrong with your directory permissions or"
2358        echo "   your user file-creation mask (\"umask\") since creating a"
2359        echo "   sub-dir, touch-ing a file within it, and then reading it is"
2360        echo "   not working.  Please try setting your umask to something"
2361        echo "   sane such as:"
2362        echo
2363        echo "      umask 0002"
2364        echo
2365        echo "   and please verify that you have the proper permissions for"
2366        echo "   creating sub-directories and then reading files created"
2367        echo "   within them."
2368        echo
2369        exit 1
2370    fi
2371    rm -f .links.tmp/foo
2372    
2373    if test "x$OPENAD" != x ; then
2374        OAD_DONT_COMPILE="/dev/null"
2375        OAD_DONT_TRANSFORM="/dev/null"
2376        OAD_KEEP_ORIGINAL="/dev/null"
2377        OAD_CB2M_FILES="/dev/null"
2378        echo "  looking for dontCompile file:  "
2379        for i in "." $MODS ; do
2380            if test -r $i"/dontCompile" ; then
2381                OAD_DONT_COMPILE=$i"/dontCompile"
2382                echo "     found $OAD_DONT_COMPILE"
2383                break
2384            fi
2385        done
2386        echo "  looking for dontTransform file:  "
2387        for i in "." $MODS ; do
2388            if test -r $i"/dontTransform" ; then
2389                OAD_DONT_TRANSFORM=$i"/dontTransform"
2390                echo "     found $OAD_DONT_TRANSFORM"
2391                break
2392            fi
2393        done
2394        echo "  looking for keepOriginal file:  "
2395        for i in "." $MODS ; do
2396            if test -r $i"/keepOriginal" ; then
2397                OAD_KEEP_ORIGINAL=$i"/keepOriginal"
2398                echo "     found $OAD_KEEP_ORIGINAL"
2399                break
2400            fi
2401        done
2402        echo "  looking for cb2mFiles:  "
2403        for i in "." $MODS ; do
2404            if test -r $i"/cb2mFiles" ; then
2405                OAD_CB2M_FILES=$i"/cb2mFiles"
2406                echo "     found $OAD_CB2M_FILES"
2407                break
2408            fi
2409        done
2410        echo "   OpenAD exceptions:  "
2411    fi
2412    
2413  echo "# This section creates symbolic links" > srclinks.tmp  echo "# This section creates symbolic links" > srclinks.tmp
2414  echo "" >> srclinks.tmp  echo "" >> srclinks.tmp
2415  printf 'SRCFILES = '    > srclist.inc  printf 'F77_SRC_FILES = ' > F77srclist.tmp
2416  printf 'CSRCFILES = '   > csrclist.inc  printf 'NON_AD_F77_SRC_FILES = ' > nonADF77srclist.tmp
2417  printf 'F90SRCFILES = ' > f90srclist.inc  printf 'C_SRC_FILES = '   > csrclist.tmp
2418  printf 'HEADERFILES = ' > hlist.inc  printf 'F90_SRC_FILES = ' > F90srclist.tmp
2419  printf 'AD_FLOW_FILES = ' > ad_flow_files.inc  printf 'H_SRC_FILES = '   > hsrclist.tmp
2420    printf 'AD_FLOW_FILES = ' > ad_flow_files.tmp
2421  alldirs="$SOURCEDIRS $INCLUDEDIRS ."  alldirs="$SOURCEDIRS $INCLUDEDIRS ."
2422  for d in $alldirs ; do  for d in $alldirs ; do
2423      deplist=      deplist=
2424      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
2425      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
2426        if test "x$OPENAD" != x ; then
2427            sfiles=`( echo $sfiles | grep -v _cb2m\. )`
2428        fi
2429      for sf in $sfiles ; do      for sf in $sfiles ; do
2430          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
2431              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
2432                  ignore_f=f                  ignore_f=f
2433                  case $d/$sf in                  case $d/$sf in
2434                    ./$PACKAGES_DOT_H)                    ./$PACKAGES_DOT_H)
2435                            ignore_f=t
2436                          ;;                          ;;
2437                    ./AD_CONFIG.h)                    ./AD_CONFIG.h)
2438                            ignore_f=t
2439                          ;;                          ;;
2440                    ./FC_NAMEMANGLE.h)                    ./FC_NAMEMANGLE.h)
2441                            ignore_f=t
2442                          ;;                          ;;
2443                    ./BUILD_INFO.h)                    ./BUILD_INFO.h)
2444                            ignore_f=t
2445                            ;;
2446                      ./EMBEDDED_FILES.h)
2447                            ignore_f=t
2448                          ;;                          ;;
2449                    *)                    *)
2450                          #  For the local directory *ONLY*,                          #  For the local directory *ONLY*,
# Line 2035  for d in $alldirs ; do Line 2460  for d in $alldirs ; do
2460                  if test "x$ignore_f" = xf ; then                  if test "x$ignore_f" = xf ; then
2461                      extn=`echo $sf | $AWK -F. '{print $NF}'`                      extn=`echo $sf | $AWK -F. '{print $NF}'`
2462                      case $extn in                      case $extn in
2463                          F)                        F)
2464                              echo    " \\"  >> srclist.inc                          echo    " \\"  >> F77srclist.tmp
2465                              printf " $sf" >> srclist.inc                          printf " $sf" >> F77srclist.tmp
2466                              ;;                          if test "x$OPENAD" != x ; then
2467                          F90)                              basename=${sf%%.F}
2468                              echo    " \\"  >> f90srclist.inc                              isAD=`egrep ^$basename.f'[  ]*' adSrcFiles.tmp`
2469                              printf " $sf" >> f90srclist.inc                              if test -z "$isAD" ; then
2470                              ;;                                  toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE}`
2471                          c)                                  if test -z "$toBeIgnored" ; then
2472                              echo    " \\"  >> csrclist.inc                                      echo    " \\"  >> nonADF77srclist.tmp
2473                              printf " $sf" >> csrclist.inc                                      printf " $sf" >> nonADF77srclist.tmp
2474                              ;;                                  else
2475                          h)                                      echo "    not to be compiled   :  $sf"
2476                              echo    " \\"  >> hlist.inc                                  fi
2477                              printf " $sf" >> hlist.inc                              else # file is initially listed as an AD file we want to exclude it
2478                              ;;                                   # or we want to retain the untransformed version
2479                          flow)                                  notToBeTransformed=`egrep ^$basename'[      ]*' ${OAD_DONT_TRANSFORM}`
2480                              echo    " \\"  >> ad_flow_files.inc                                  untransformedVersionToBeKept=`egrep ^$basename'[      ]*' ${OAD_KEEP_ORIGINAL}`
2481                              printf " $sf" >> ad_flow_files.inc                                  if test -n "$notToBeTransformed"; then
2482                              ;;                                      echo "    not to be transformed:  $sf"
2483                      esac                                  fi
2484                  fi                                  if test -n "$untransformedVersionToBeKept" ; then
2485                                        echo "    original to be kept  :  $sf"
2486                                    fi
2487                                    if test -n "$notToBeTransformed" -o -n "$untransformedVersionToBeKept" ; then
2488                                        echo    " \\"  >> nonADF77srclist.tmp
2489                                        printf " $sf" >> nonADF77srclist.tmp
2490                                    fi
2491                                fi
2492                            fi
2493                            ;;
2494                        F90)
2495                            echo    " \\"  >> F90srclist.tmp
2496                            printf " $sf" >> F90srclist.tmp
2497                            ;;
2498                        c)
2499                            echo    " \\"  >> csrclist.tmp
2500                            printf " $sf" >> csrclist.tmp
2501                            ;;
2502                        h)
2503                            echo    " \\"  >> hsrclist.tmp
2504                            printf " $sf" >> hsrclist.tmp
2505                            ;;
2506                        flow)
2507                            echo    " \\"  >> ad_flow_files.tmp
2508                            printf " $sf" >> ad_flow_files.tmp
2509                            ;;
2510                       esac
2511                    fi
2512              fi              fi
2513          fi          fi
2514      done      done
2515      if test "x$deplist" != x ; then      if test "x$deplist" != x ; then
2516          echo "" >> srclinks.tmp        if test "$d" != "." ; then
2517            echo "" >> srclinks.tmp
2518          echo "#  These files are linked from $d" >> srclinks.tmp          echo "#  These files are linked from $d" >> srclinks.tmp
2519          echo "$deplist :" >> srclinks.tmp          echo "$deplist :" >> srclinks.tmp
2520          printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp  # We need to make sure that the link isn't already there.
2521    # This may happen when make thinks that a header file has to be "remade"
2522    # because a module it depends on has changed.  In this case we do nothing.
2523            printf "\tif [ ! -L \$@ ]; then \$(LN) %s/\$@ \$@; fi\n" $d >> srclinks.tmp
2524          fi
2525      fi      fi
2526  done  done
2527  rm -rf .links.tmp  rm -rf .links.tmp
2528  echo "" >> srclist.inc  echo "" >> F77srclist.tmp
2529  echo "" >> csrclist.inc  echo "" >> nonADF77srclist.tmp
2530  echo "" >> f90srclist.inc  echo "" >> csrclist.tmp
2531  echo "" >> hlist.inc  echo "" >> F90srclist.tmp
2532  echo "" >> ad_flow_files.inc  echo "" >> hsrclist.tmp
2533    echo "" >> ad_flow_files.tmp
2534    
2535    CMDLINE=$0
2536    for xx in "$@" ; do nw=`echo $xx | wc -w`
2537        if test $nw = '1' ; then CMDLINE="$CMDLINE $xx"
2538                            else CMDLINE="$CMDLINE '$xx'" ; fi
2539    done
2540    
2541  if test -f $MAKEFILE ; then  if test -f $MAKEFILE ; then
2542      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.old"
2543  fi  fi
2544  echo "  Writing makefile: $MAKEFILE"  echo "  Writing makefile: $MAKEFILE"
2545  echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE  echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
# Line 2083  echo "#    $MACHINE" >> $MAKEFILE Line 2547  echo "#    $MACHINE" >> $MAKEFILE
2547  echo "# This makefile was generated automatically on" >> $MAKEFILE  echo "# This makefile was generated automatically on" >> $MAKEFILE
2548  echo "#    $THISDATE" >> $MAKEFILE  echo "#    $THISDATE" >> $MAKEFILE
2549  echo "# by the command:" >> $MAKEFILE  echo "# by the command:" >> $MAKEFILE
2550  echo "#    $0 $G2ARGS" >> $MAKEFILE  echo "#    $CMDLINE"  >> $MAKEFILE
2551  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
2552  echo "#    ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE  echo "#    ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
2553    
# Line 2094  EXE_SVD=$EXECUTABLE"_svd" Line 2558  EXE_SVD=$EXECUTABLE"_svd"
2558  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2559  #  #
2560  # OPTFILE="$OPTFILE"  # OPTFILE="$OPTFILE"
2561  #  #
2562  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
2563  # SOURCEDIRS   : Directories containing the source (.F) files  # SOURCEDIRS   : Directories containing the source (.F) files
2564  # INCLUDEDIRS  : Directories containing the header-source (.h) files  # INCLUDEDIRS  : Directories containing the header-source (.h) files
# Line 2114  cat >>$MAKEFILE <<EOF Line 2578  cat >>$MAKEFILE <<EOF
2578  # LIBS         : Library flags /or/ additional optimization/debugging flags  # LIBS         : Library flags /or/ additional optimization/debugging flags
2579    
2580  ROOTDIR     = ${ROOTDIR}  ROOTDIR     = ${ROOTDIR}
2581  BUILDDIR    = ${BUILDDIR}    BUILDDIR    = ${BUILDDIR}
2582  SOURCEDIRS  = ${SOURCEDIRS}  SOURCEDIRS  = ${SOURCEDIRS}
2583  INCLUDEDIRS = ${INCLUDEDIRS}  INCLUDEDIRS = ${INCLUDEDIRS}
2584  EXEDIR      = ${EXEDIR}  EXEDIR      = ${EXEDIR}
# Line 2132  DISABLED_PACKAGES = ${DISABLED_PACKAGES} Line 2596  DISABLED_PACKAGES = ${DISABLED_PACKAGES}
2596    
2597  # These files are created by Makefile  # These files are created by Makefile
2598  SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h  SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h
   
2599  EOF  EOF
2600    
2601  #  Note: figure out some way to add Hyades JAM libraries here  if test "x$EMBED_SRC" = xt ; then
2602        echo "EMBEDDED_FILES = EMBEDDED_FILES.h" >>$MAKEFILE
2603    else
2604        echo "EMBEDDED_FILES = " >>$MAKEFILE
2605    fi
2606    
2607  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2608  # Unix ln (link)  # Unix ln (link)
2609  LN = ${LN}  LN = ${LN}
# Line 2163  INCLUDES = ${INCLUDES} Line 2630  INCLUDES = ${INCLUDES}
2630  KFLAGS1 = ${KFLAGS1}  KFLAGS1 = ${KFLAGS1}
2631  KFLAGS2 = ${KFLAGS2}  KFLAGS2 = ${KFLAGS2}
2632  # Optim./debug for FC  # Optim./debug for FC
2633  FFLAGS = ${FFLAGS}  FFLAGS = ${FFLAGS} ${FEXTRAFLAGS}
2634  FOPTIM = ${FOPTIM}  FOPTIM = ${FOPTIM}
2635  # Optim./debug for FC  # Optim./debug for FC
2636  F90FLAGS = ${F90FLAGS}  F90FLAGS = ${F90FLAGS}
2637  F90OPTIM = ${F90OPTIM}  F90OPTIM = ${F90OPTIM}
2638    F90FIXEDFORMAT = ${F90FIXEDFORMAT}
2639  # Flags for CC  # Flags for CC
2640  CFLAGS = ${CFLAGS}  CFLAGS = ${CFLAGS}
2641  # Files that should not be optimized  # Files that should not be optimized
# Line 2180  MAKEFILE=${MAKEFILE} Line 2648  MAKEFILE=${MAKEFILE}
2648    
2649  EOF  EOF
2650    
2651  cat srclist.inc       >> $MAKEFILE  cat F77srclist.tmp      >> $MAKEFILE
2652  cat csrclist.inc      >> $MAKEFILE  cat nonADF77srclist.tmp >> $MAKEFILE
2653  cat f90srclist.inc    >> $MAKEFILE  cat csrclist.tmp        >> $MAKEFILE
2654  cat hlist.inc         >> $MAKEFILE  cat F90srclist.tmp      >> $MAKEFILE
2655  cat ad_flow_files.inc >> $MAKEFILE  cat hsrclist.tmp        >> $MAKEFILE
2656    cat ad_flow_files.tmp   >> $MAKEFILE
2657    
2658    rm -f F77srclist.tmp nonADF77srclist.tmp csrclist.tmp F90srclist.tmp hsrclist.tmp ad_flow_files.tmp
2659    
2660  echo >> $MAKEFILE  echo >> $MAKEFILE
2661  echo 'F77FILES =  $(SRCFILES:.F=.'$FS')'      >> $MAKEFILE  
2662  echo 'F90FILES =  $(F90SRCFILES:.F90=.'$FS90')' >> $MAKEFILE  # add definitions for preprocessed sources
2663  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE  # and note that not all systems allow case sensitive extensions
2664    # hence the $FS and $FS90 here.
2665    # for fixed format f90 files we use ff90 or FF90 resp
2666    # but these are not expected to be the original source files
2667    
2668    echo 'F77_PP_SRC_FILES = $(F77_SRC_FILES:.F=.'$FS')'      >> $MAKEFILE
2669    echo 'F90_PP_SRC_FILES = $(F90_SRC_FILES:.F90=.'$FS90')' >> $MAKEFILE
2670    echo 'OBJFILES= $(F77_SRC_FILES:.F=.o) $(C_SRC_FILES:.c=.o) $(F90_SRC_FILES:.F90=.o)' >> $MAKEFILE
2671    echo 'FLOFILES =  $(AD_FLOW_FILES:.flow=.flowdir)' >> $MAKEFILE
2672  echo >> $MAKEFILE  echo >> $MAKEFILE
2673  echo '.SUFFIXES:' >> $MAKEFILE  echo '.SUFFIXES:' >> $MAKEFILE
2674  echo '.SUFFIXES: .o .'$FS' .p .F .c .'$FS90' .F90' >> $MAKEFILE  echo '.SUFFIXES: .o .'$FS' .p .F .c .f'$FS90' .'$FS90' .FF90 .F90 .flowdir .flow' >> $MAKEFILE
 rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc  
 rm -f ad_flow_files.inc  
2675    
2676  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2677    
2678  all: \$(EXECUTABLE)  all: \$(EXECUTABLE)
2679  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(OBJFILES)  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(OBJFILES) \$(EMBEDDED_FILES)
2680          @echo Creating \$@ ...          @echo Creating \$@ ...
2681          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
2682  depend:  depend:
2683          @make links          @make links
2684          \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)
2685          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2686          -rm -f makedepend.out          -rm -f makedepend.out
2687    
# Line 2211  lib: libmitgcmuv.a Line 2689  lib: libmitgcmuv.a
2689    
2690  libmitgcmuv.a: \$(OBJFILES)  libmitgcmuv.a: \$(OBJFILES)
2691          ar rcv libmitgcmuv.a \$(OBJFILES)          ar rcv libmitgcmuv.a \$(OBJFILES)
2692            ar d   libmitgcmuv.a main.o
2693    
2694  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES)  links: \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(SPECIAL_FILES)
2695    
2696  small_f: \$(F77FILES) \$(F90FILES)  small_f: \$(F77_PP_SRC_FILES) \$(F90_PP_SRC_FILES)
2697    
2698  output.txt: \$(EXECUTABLE)  output.txt: \$(EXECUTABLE)
2699          @printf 'running ... '          @printf 'running ... '
2700          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
2701    
2702    # remove most of the files that "make" generates
2703  clean:  clean:
2704          -rm -rf *.o *.$FS *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template          -rm -rf *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
2705            -rm -rf *.o
2706            -rm -rf *.$FS *.flowdir
2707            -rm -rf *.f$FS90 \$(AD_CLEAN) ad_input*
2708    
2709    # remove most of the files that "make" and "make depend" generate
2710  Clean:  Clean:
2711          @make clean          @make clean
2712          @make cleanlinks          @make cleanlinks
2713          -rm -f \$(SPECIAL_FILES)          -rm -f \$(SPECIAL_FILES) f90mkdepend.log $MAKEFILE.old
2714          -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak          -rm -f taf_command taf_output taf_ad.log taf_ad_flow.log
2715            -rm -f genmake_warnings genmake_errors make.log
2716    
2717    # remove also the executable, files that "genmake2" generates (except Makefile)
2718    #         and output from a run (plus log files from testreport)
2719  CLEAN:  CLEAN:
2720          @make Clean          @make Clean
2721            -rm -f \$(EXECUTABLE) \$(EXE_AD) *.bak
2722            -rm -f $LOGFILE genmake_state genmake_*optfile
2723            -rm -f SIZE.h.mpi genmake.tr_log make.tr_log
2724          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
2725          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
2726          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
2727          -rm -f \$(EXECUTABLE) output.txt STD*          -rm -f *.txt STD* *diagnostics.log datetime
2728            -rm -f *_MIT_CE_000.opt0000 costfunction*0000
2729            -rm -rf mnc_test_*
2730    
 #eh3 Makefile: makefile  
2731  makefile:  makefile:
2732          $THIS_SCRIPT $G2ARGS          $THIS_SCRIPT $G2ARGS
2733  cleanlinks:  cleanlinks:
2734          -find . -type l -exec rm {} \;          -find . -type l -exec rm {} \;
2735    
2736  # Special targets (SPECIAL_FILES) which are create by make  # Special targets (SPECIAL_FILES) which are created by make
2737  ${PACKAGES_DOT_H}:  ${PACKAGES_DOT_H}:
2738          @echo Creating \$@ ...          @echo Creating \$@ ...
2739          @$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) > \$@          @$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) > \$@
# Line 2260  test ! "x$THISUSER" = x && echo "      -echo Line 2753  test ! "x$THISUSER" = x && echo "      -echo
2753  test ! "x$THISDATE" = x && echo "       -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE  test ! "x$THISDATE" = x && echo "       -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
2754  test ! "x$THISHOST" = x && echo "       -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE  test ! "x$THISHOST" = x && echo "       -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
2755    
2756    if test "x$EMBED_SRC" = xt ; then
2757        cat >>$MAKEFILE <<EOF
2758    
2759    decode_files.o : EMBEDDED_FILES.h
2760    
2761    ##  \$(F77_PP_SRC_FILES)
2762    all_fF.tar.gz : \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile
2763            @echo Creating \$@ ...
2764            -tar -hcf all_fF.tar \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile
2765            -rm -f all_fF.tar.gz
2766            -gzip all_fF.tar
2767    
2768    EMBEDDED_FILES.h : all_fF.tar.gz
2769            @echo Creating \$@ ...
2770            -\${ROOTDIR}/tools/embed_encode/encode_files EMBEDDED_FILES.h all_fF.tar.gz
2771    
2772    EOF
2773    fi
2774    
2775  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2776    
2777  # The normal chain of rules is (  .F - .$FS - .o  )  # The normal chain of rules is (  .F - .$FS - .o  )
# Line 2271  cat >>$MAKEFILE <<EOF Line 2783  cat >>$MAKEFILE <<EOF
2783          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2784  .$FS.o:  .$FS.o:
2785          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2786    .F.o:
2787            \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2788  .F90.$FS90:  .F90.$FS90:
2789          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2790    .FF90.f$FS90:
2791            \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2792  .$FS90.o:  .$FS90.o:
2793          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
2794    .f$FS90.o:
2795            cp \$< \$(basename  \$<).f90
2796            \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$(F90FIXEDFORMAT) \$(basename  \$<).f90
2797  .c.o:  .c.o:
2798          \$(CC) \$(CFLAGS) -c \$<          \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$<
2799    .flow.flowdir:
2800            \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2801    
2802  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
2803  .F.p:  .F.p:
# Line 2284  cat >>$MAKEFILE <<EOF Line 2805  cat >>$MAKEFILE <<EOF
2805  .p.$FS:  .p.$FS:
2806          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
2807    
2808    EOF
2809    
2810  #=========================================  #=========================================
2811  #===  Automatic Differentiation Rules  ===  #===  Automatic Differentiation Rules  ===
2812    #===  for TAMC/TAF  ======================
2813    
2814    if test "x$OPENAD" = x ; then
2815    
2816    cat >>$MAKEFILE <<EOF
2817    
2818  TAMC           = ${TAMC}  TAMC           = ${TAMC}
2819  TAF            = ${TAF}  TAF            = ${TAF}
# Line 2300  ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF Line 2828  ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF
2828  ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"  ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
2829  for i in $ad_vars ; do  for i in $ad_vars ; do
2830      name=$i      name=$i
2831      t1="t2=\$"`echo $i`      t1="t2=\$"`echo "$i"`
2832      eval $t1      eval $t1
2833      printf "%-20s = " $name >> $MAKEFILE      printf "%-20s = " $name >> $MAKEFILE
2834      echo $t2 >> $MAKEFILE      echo "$t2" | sed -e 's| \+| |g' >> $MAKEFILE
2835  done  done
2836    
2837  echo "  Add the source list for AD code generation"  echo "  Add the source list for AD code generation"
2838  echo >> $MAKEFILE  echo >> $MAKEFILE
2839  printf "AD_FILES = " >> $MAKEFILE  printf "AD_FILES = " >> $MAKEFILE
2840  AD_FILES=`cat ad_files`  AD_FILES=`cat adSrcFiles.tmp`
2841  for i in $AD_FILES ; do  for i in $AD_FILES ; do
2842      echo    " \\" >> $MAKEFILE      echo    " \\" >> $MAKEFILE
2843      printf " $i" >> $MAKEFILE      printf " $i" >> $MAKEFILE
2844  done  done
2845  echo >> $MAKEFILE  echo >> $MAKEFILE
2846  rm -f ad_files  rm -f adSrcFiles.tmp
2847    
2848  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2849    
2850  # ... AD ...  # ... AD ...
2851  adall: ad_taf  adall: \$(EXE_AD)
2852  adtaf: ad_taf_output.$FS  adtaf: ad_taf_output.$FS
2853  adtamc: ad_tamc_output.$FS  adtamc: ad_tamc_output.$FS
2854    
2855  ad_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)  ad_input_code.$FS: \$(AD_FILES) \$(H_SRC_FILES) \$(AD_FLOW_FILES)
2856          @$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          @$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
2857          cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h          cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
2858          -rm -f ad_config.template          -rm -f ad_config.template
2859          @make \$(F77FILES)          @make \$(F77_PP_SRC_FILES)
2860          @make \$(AD_FLOW_FILES)          @make \$(FLOFILES)
2861          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.$FS          cat \$(FLOFILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ad_input_code.$FS
2862    
2863  ad_taf_output.$FS: ad_input_code.$FS  ad_taf_output.$FS: ad_input_code.$FS
2864          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2865            ls -l ad_input_code_ad.$FS
2866          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
2867    
2868  adtafonly:  adtafonly:
2869          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2870            ls -l ad_input_code_ad.$FS
2871          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
2872    
2873  ad_taf: ad_taf_output.o \$(OBJFILES)  \${EXE_AD}: ad_taf_output.o \$(OBJFILES)
2874          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)          \$(LINK) -o \${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
2875    
2876  ad_tamc_output.$FS: ad_input_code.$FS  ad_tamc_output.$FS: ad_input_code.$FS
2877          \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS          \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
2878          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS
2879    
2880  ad_tamc: ad_tamc_output.o \$(OBJFILES)  ad_tamc: ad_tamc_output.o \$(OBJFILES)
2881          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
2882    
2883  adonlyfwd:  adonlyfwd:
2884          patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff          patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
2885    
2886  adtrick:  adtrick:
2887          patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff          patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
2888    
# Line 2361  ftlall: ftl_taf Line 2891  ftlall: ftl_taf
2891  ftltaf: ftl_taf_output.$FS  ftltaf: ftl_taf_output.$FS
2892  ftltamc: ftl_tamc_output.$FS  ftltamc: ftl_tamc_output.$FS
2893    
2894  ftl_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)  ftl_input_code.$FS: \$(AD_FILES) \$(H_SRC_FILES)
2895          @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > ftl_config.template          @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > ftl_config.template
2896          cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h          cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
2897          -rm -f ftl_config.template          -rm -f ftl_config.template
2898          @make \$(F77FILES)          @make \$(F77_PP_SRC_FILES)
2899          @make \$(AD_FLOW_FILES)          @make \$(AD_FLOW_FILES)
2900          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.$FS          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.$FS
2901    
2902  ftl_taf_output.$FS: ftl_input_code.$FS  ftl_taf_output.$FS: ftl_input_code.$FS
2903          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2904            ls -l ftl_input_code_ftl.$FS
2905          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2906    
2907  ftltafonly:  ftltafonly:
2908          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2909            ls -l ftl_input_code_ftl.$FS
2910          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2911    
2912  ftl_taf: ftl_taf_output.o \$(OBJFILES)  ftl_taf: ftl_taf_output.o \$(OBJFILES)
2913          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
2914    
2915  ftl_tamc_output.$FS: ftl_input_code.$FS  ftl_tamc_output.$FS: ftl_input_code.$FS
2916          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
2917          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS
2918    
2919  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
2920          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
   
2921    
2922  # ... SVD ...  # ... SVD ...
2923  svdtaf: ad_taf_output.$FS ftl_taf_output.$FS  svdtaf: ad_taf_output.$FS ftl_taf_output.$FS
# Line 2412  svd_touch: Line 2943  svd_touch:
2943          cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h          cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
2944          -rm -f ftl_config.template          -rm -f ftl_config.template
2945    
2946  #=========================================  EOF
2947    
2948    fi
2949    
2950    #===  for OpenAD  ========================
2951    
2952    if test "x$OPENAD" != x ; then
2953    
2954    # ============ begin OpenAD specific section ==============
2955    
2956    cat >>$MAKEFILE <<EOF
2957    
2958    # all the source files linked from the various locations:
2959    ALL_LINKED_FILES= \
2960    \$(F77_SRC_FILES) \
2961    \$(C_SRC_FILES) \
2962    \$(H_SRC_FILES) \
2963    \$(F90_SRC_FILES) \
2964    \$(SPECIAL_FILES)
2965    
2966    ifndef OPENADROOT
2967      \$(error "Error:  environment variable OPENADROOT not defined!")
2968    endif
2969    
2970    ifndef XAIFSCHEMAROOT
2971      \$(error "Error:  environment variable XAIFSCHEMAROOT not defined!")
2972    endif
2973    
2974    ifndef XAIFBOOSTERROOT
2975      \$(error "Error:  environment variable XAIFBOOSTERROOT not defined!")
2976    endif
2977    
2978  EOF  EOF
2979    
2980    echo "  Add the source list for common block to module conversion "
2981    echo >> $MAKEFILE
2982    printf "CB2M_F90_SRC_NAMES = " >> $MAKEFILE
2983    for i in `cat ${OAD_CB2M_FILES}` ; do
2984      echo    " \\" >> $MAKEFILE
2985      printf " $i" >> $MAKEFILE
2986    done
2987    echo >> $MAKEFILE
2988    
2989    echo "  Add the source list for AD code generation"
2990    echo >> $MAKEFILE
2991    printf "AD_FILES = " >> $MAKEFILE
2992    for i in `cat ${OAD_CB2M_FILES}` ; do
2993      echo    " \\" >> $MAKEFILE
2994      printf " ${i}_mod.f$FS90" >> $MAKEFILE
2995    done
2996    AD_FILES=`cat adSrcFiles.tmp`
2997    for i in $AD_FILES ; do
2998      basename=${i%%.f}
2999      toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE} ${OAD_DONT_TRANSFORM}`
3000      if test -z "$toBeIgnored" ; then
3001        echo    " \\" >> $MAKEFILE
3002        printf " $i" >> $MAKEFILE
3003      fi
3004    done
3005    echo >> $MAKEFILE
3006    rm -f adSrcFiles.tmp
3007    
3008    cat >>$MAKEFILE <<EOF
3009    
3010    adAll: \$(EXE_AD)
3011    .PHONY: adAll
3012    
3013    CB2M_F90_PP_SRC_FILES=\$(addsuffix _mod.f$FS90, \$(CB2M_F90_SRC_NAMES))
3014    
3015    .PRECIOUS: \$(CB2M_F90_PP_SRC_FILES) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90)
3016    
3017    .PHONY: adDepend
3018    adDepend: \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) \$(addsuffix _mod.FF90, \$(CB2M_F90_SRC_NAMES)) \$(F77_SRC_FILES:.F=_cb2m.FF90)
3019            \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)
3020            \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
3021            -rm -f makedepend.out
3022    
3023    OPENAD_SUPPORT_F90_SRC_FILES = \
3024    w2f__types.F90 \
3025    OAD_active.F90 \
3026    OAD_cp.F90 \
3027    OAD_rev.F90 \
3028    OAD_tape.F90
3029    
3030    OPENAD_SUPPORT_C_SRC_FILES = \
3031    iaddr.c \
3032    timeRatio.c
3033    
3034    f95_test_mods.f90: \$(OPENAD_SUPPORT_F90_SRC_FILES:F90=$FS90)
3035            cat \$^ > \$@
3036    
3037    f95_test.f90: all_mods.xb.x2w.w2f.pp.f$FS90 \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90) ad_input_code.w2f.pre.xb.x2w.w2f.td.pp.f$FS90
3038            cat \$^ > \$@
3039    
3040    f95_test.out: f95_test_mods.f90 f95_test.f90
3041            f95 -fixed -w=unused -maxcontin=132 -c f95_test_mods.f90 > \$@ 2>&1
3042            f95 -fixed -w=unused -maxcontin=132 -c -fixed f95_test.f90 >> \$@ 2>&1
3043    
3044    # the file included below is created by the
3045    # postProcessor and its inclusion sets the
3046    # variable POSTPROCESSEDFILES
3047    # used below. Because the file is made during
3048    # make it won't be read until the second (recursive)
3049    # invocation in the rule below
3050    -include postProcess.make
3051    
3052    AD_OBJ_FILES_S1=\$(OPENAD_SUPPORT_F90_SRC_FILES:.F90=.o) \$(OPENAD_SUPPORT_C_SRC_FILES:.c=.o) \$(POSTPROCESSEDFILES:.f$FS90=.o)
3053    
3054    AD_OBJ_FILES_S2=\$(AD_OBJ_FILES_S1) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.o) \$(C_SRC_FILES:.c=.o) \$(F90_SRC_FILES:.F90=.o)
3055    
3056    postProcess.comp: \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) postProcess.tag \$(AD_OBJ_FILES_S1)
3057    ifeq (\$(MAKELEVEL),0)
3058            \$(MAKE) adAll
3059    else
3060            touch \$@
3061    endif
3062    
3063    \$(EXE_AD): \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) postProcess.comp \$(AD_OBJ_FILES_S2)
3064    ifeq (\$(MAKELEVEL),1)
3065            \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(AD_OBJ_FILES_S2) \$(LIBS)
3066    else
3067            touch \$@
3068    endif
3069    
3070    # makefile debug rule
3071    openad: ad_input_code.w2f.pre.xb.x2w.w2f.td.pp.f$FS90
3072    .PHONY: openad
3073    
3074    # create the module files
3075    %_mod.FF90 : %.h ../OAD_support/cb2mGetModules.csh ../OAD_support/cb2mGetModules.awk
3076            ../OAD_support/cb2mGetModules.csh $< ../OAD_support/cb2mGetModules.awk
3077    
3078    # create the header files
3079    %_mod.h : %.h ../OAD_support/cb2mGetHeaders.csh ../OAD_support/cb2mGetHeaders.awk
3080            ../OAD_support/cb2mGetHeaders.csh $< ../OAD_support/cb2mGetHeaders.awk \$(CB2M_F90_SRC_NAMES)
3081    
3082    # change everybody else to use the new module files:
3083    %_cb2m.FF90 : %.F ../OAD_support/cb2mUseModules.bash
3084            ../OAD_support/cb2mUseModules.bash $< ${MPI}
3085    
3086    # makefile debug rule
3087    small_f: \$(CB2M_F90_PP_SRC_FILES)
3088    .PHONY: small_f
3089    
3090    ad_output.txt: \$(EXE_AD)
3091            @printf 'linking data files ... '
3092            \$(LN) -f ../input_ad/data* ../input_ad/eedata .
3093            \$(LN) -f ../../global_ocean.90x40x15/input/*.bin .
3094            @printf 'running ... '
3095            @./\$(EXE_AD) > \$@
3096    
3097    CB2M_AD_FILES=\$(AD_FILES:.f=_cb2m.f$FS90)
3098    ad_input_code.f$FS90:  \$(CB2M_AD_FILES)
3099            cat \$^ > \$@
3100    
3101    # strip all comments and blanks to reduce
3102    # the file size in order to reduce perl's memory requirements
3103    ad_input_code_sf.f$FS90 : ad_input_code.f$FS90
3104            cat \$^ | sed -f ../OAD_support/strip.sed | sed -f ../OAD_support/stop2print.sed > \$@
3105    
3106    # mfef90 preprocessing
3107    # expand statement functions
3108    # expose mfef90 specific substring handling
3109    # add the w2f__types module
3110    ad_input_code_sf.w2f.f$FS90: ad_input_code_sf.f$FS90 mfef90 whirl2f whirl2f_be w2f__types.f90
3111            ./mfef90 -r8 -z -F -N132 \$<
3112            mv \$<.B \$(basename \$<).B
3113            ./whirl2f -openad \$(basename \$<).B
3114            cat w2f__types.f90 \$(basename \$<).w2f.f > \$@
3115    
3116    # canonicalizer
3117    ad_input_code_sf.w2f.pre.f$FS90: ad_input_code_sf.w2f.f$FS90 preProcess.py
3118            ./preProcess.py --timing --r8 -H -S \$< -o \$@
3119    
3120    # F -> WHIRL
3121    # note that the canonicalized version cuts off at col 72
3122    # doing this also for string constants which is ok as long
3123    # as we are in fixed mode and cut of exactly there.
3124    # Otherwise mfef90 patches in spaces to fill up to 72 (or 132)
3125    # characters respectively.
3126    ad_input_code_sf.w2f.pre.B: ad_input_code_sf.w2f.pre.f$FS90 mfef90
3127            ./mfef90 -r8 -z -F \$<
3128            mv \$<.B \$@
3129    
3130    # WHIRL -> XAIF
3131    ad_input_code_sf.w2f.pre.xaif : ad_input_code_sf.w2f.pre.B whirl2xaif
3132            ./whirl2xaif -s -n --debug 1 -o \$@ \$<
3133    
3134    # XAIF -> XAIF'
3135    ad_input_code_sf.w2f.pre.xb.xaif : ad_input_code_sf.w2f.pre.xaif xaif.xsd xaif_base.xsd xaif_inlinable_intrinsics.xsd xaif_derivative_propagator.xsd xaif_output.xsd oadDriver
3136            ./oadDriver -f -t forward_step -i \$< -c \${XAIFSCHEMAROOT}/schema/examples/inlinable_intrinsics.xaif -o \$@ -I -r
3137    
3138    # XAIF' -> WHIRL'
3139    ad_input_code_sf.w2f.pre.xb.x2w.B : ad_input_code_sf.w2f.pre.xb.xaif xaif2whirl
3140            ./xaif2whirl --debug 1 ad_input_code_sf.w2f.pre.B \$<
3141    
3142    # WHIRL' -> F'
3143    ad_input_code_sf.w2f.pre.xb.x2w.w2f.f$FS90: ad_input_code_sf.w2f.pre.xb.x2w.B whirl2f whirl2f_be
3144            ./whirl2f -FLIST:ftn_file=\$@ -openad \$<
3145    
3146    # insert template directives
3147    ad_input_code_sf.w2f.pre.xb.x2w.w2f.td.f$FS90: ad_input_code_sf.w2f.pre.xb.x2w.w2f.f$FS90 ../OAD_support/insertTemplateDir.bash
3148            ../OAD_support/insertTemplateDir.bash \$< \$@
3149    
3150    PPEXTRAS=\$(wildcard ../OAD_support/ad_template.*.F) ../OAD_support/ad_inline.F
3151    # postprocess F'
3152    postProcess.tag: ad_input_code_sf.w2f.pre.xb.x2w.w2f.td.f$FS90 postProcess.py \$(PPEXTRAS:.F=.f)
3153            # the target is a placeholder to signal execution of the rule
3154            touch \$@
3155            # this step also creates the file postProcess.make but we cannot
3156            # name it as the target or else make will try to remake it for
3157            # the include directive above for any rule, e.g. make clean
3158            ./postProcess.py --progress --timing --outputFormat=fixed -m r -i ../OAD_support/ad_inline.f --width 4 \$<
3159    
3160    # setup some links
3161    %.xsd:
3162            \$(LN) \${XAIFSCHEMAROOT}/schema/\$@ .
3163    
3164    mfef90:
3165            \$(LN) \${OPEN64ROOT}/crayf90/sgi/mfef90 .
3166    
3167    # link the support files:
3168    \$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES):
3169            \$(LN) ../OAD_support/\$@ .
3170    
3171    whirl2xaif xaif2whirl:
3172            \$(LN) \${OPENADFORTTK}/bin/\$@ .
3173    
3174    preProcess.py postProcess.py:
3175            \$(LN) \${OPENADFORTTK_BASE}/tools/SourceProcessing/\$@ .
3176    
3177    whirl2f whirl2f_be:
3178            \$(LN) \${OPEN64ROOT}/whirl2f/\$@ .
3179    
3180    oadDriver:
3181            \$(LN) \${XAIFBOOSTERROOT}/xaifBooster/algorithms/BasicBlockPreaccumulationReverse/driver/oadDriver \$@
3182    
3183    AD_CLEAN += *_mod.h *_mod.F90 *.FF90 *.mod-whirl temp.sed oad_cp.* postProcess.make postProcess.tag postProcess.comp \$(PPEXTRAS:.F=.f)
3184    
3185    # ============ end OpenAD specific section ==============
3186    
3187    EOF
3188    
3189    fi
3190    
3191    #=========================================
3192    
3193  if test "x$EXEHOOK" != x ; then  if test "x$EXEHOOK" != x ; then
3194      printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE      printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
3195  fi  fi
# Line 2451  printf "\n\n# DO NOT DELETE\n" >> $MAKEF Line 3225  printf "\n\n# DO NOT DELETE\n" >> $MAKEF
3225  printf "\n===  Done  ===\n"  printf "\n===  Done  ===\n"
3226    
3227  # Create special header files  # Create special header files
3228  $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"  $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"
3229  if test ! -f $PACKAGES_DOT_H ; then  if test ! -f $PACKAGES_DOT_H ; then
3230      mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H      mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
3231  else  else
# Line 2468  if test ! -f AD_CONFIG.h ; then Line 3242  if test ! -f AD_CONFIG.h ; then
3242      $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      $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
3243  fi  fi
3244    
   
3245  #  Write the "state" for future records  #  Write the "state" for future records
3246  if test "x$DUMPSTATE" != xf ; then  if test "x$DUMPSTATE" = xt ; then
3247      printf "" > genmake_state      printf "" > genmake_state
3248      for i in $gm_state ; do      for i in $gm_state ; do
3249          t1="t2=\$$i"          t1="t2=\$$i"

Legend:
Removed from v.1.138  
changed lines
  Added in v.1.219

  ViewVC Help
Powered by ViewVC 1.1.22