/[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.109 by heimbach, Fri Oct 22 11:46:02 2004 UTC revision 1.238 by jmc, Tue Aug 28 21:11:22 2012 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        -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4
100              Use "real*4" type for _RS variable (#undef REAL4_IS_SLOW)
101              *only* works if CPP_EEOPTIONS.h allows this.
102    
103        -ignoretime | -ignore_time | --ignoretime | --ignore_time
104              Ignore all the "wall clock" routines entirely.  This will
105              not in any way hurt the model results -- it simply means
106              that the code that checks how long the model spends in
107              various routines will give junk values.
108    
109        -ts | --ts
110              Produce timing information per timestep
111        -papis | --papis
112              Produce summary MFlop/s (and IPC) with PAPI per timestep
113        -pcls | --pcls
114              Produce summary MFlop/s etc. with PCL per timestep
115        -foolad | --foolad
116              Fool the AD code generator
117        -papi | --papi
118              Performance analysis with PAPI
119        -pcl | --pcl
120              Performance analysis with PCL
121        -hpmt | --hpmt
122              Performance analysis with the HPM Toolkit
123    
124        -ieee | --ieee
125              use IEEE numerics.  Note that this option *only* works
126              if it is supported by the OPTFILE that is being used.
127        -devel | --devel
128              Add additional warning and debugging flags for development
129              (if supported by the OPTFILE); also switch to IEEE numerics.
130        -gsl | --gsl
131              Use GSL to control floating point rounding and precision
132    
133        -mpi | --mpi
134              Include MPI header files and link to MPI libraries
135        -mpi=PATH | --mpi=PATH
136              Include MPI header files and link to MPI libraries using MPI_ROOT
137              set to PATH. i.e. Include files from \$PATH/include, link to libraries
138              from \$PATH/lib and use binaries from \$PATH/bin.
139    
140        -omp | --omp
141              Activate OpenMP code + use Compiler option OMPFLAG
142        -omp=OMPFLAG | --omp=OMPFLAG
143              Activate OpenMP code + use Compiler option OMPFLAG
144    
145        -es | --es | -embed-source | --embed-source
146              Embed a tarball containing the full source code
147              (including the Makefile, etc.) used to build the
148              executable [off by default]
149    
150        -ds | --ds
151              Report genmake internal variables status (DUMPSTATE)
152              to file "genmake_state" (for debug purpose)
153    
154      While it is most often a single word, the "NAME" variables specified
155      above can in many cases be a space-delimited string such as:
156    
157        --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'
158        -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'
159        -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
160    
161      which, depending upon your shell, may need to be single-quoted.
162    
163      For more detailed genmake documentation, please see:
164    
165        http://mitgcm.org/public/devel_HOWTO/
166    
167    EOF
168    
169        exit 1
170    }
171    
172  # Search for particular CPP #cmds associated with packages  # Search for particular CPP #cmds associated with packages
173  # usage: test_for_package_in_cpp_options CPP_file package_name  # usage: test_for_package_in_cpp_options CPP_file package_name
174  test_for_package_in_cpp_options() {  test_for_package_in_cpp_options() {
175      cpp_options=$1      cpp_options=$1
176      pkg=$2      pkg=$2
177      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg[ ]"
178      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg[ ]"
179      test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg[ ]"
180      test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg[ ]"
181        test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg$"
182        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg$"
183        test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg$"
184        test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg$"
185  }  }
186    
187  # Search for particular CPP #cmds associated with MPI  # Search for particular CPP #cmds associated with MPI
188  # usage: test_for_mpi_in_cpp_eeoptions CPP_file  # usage: test_for_mpi_in_cpp_eeoptions CPP_file
189  test_for_mpi_in_cpp_eeoptions() {  test_for_mpi_in_cpp_eeoptions() {
190      cpp_options=$1      cpp_options=$1
191      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI[ ]"
192      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI[ ]"
193      test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI[ ]"
194      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI[ ]"
195        test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI$"
196        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI$"
197        test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI$"
198        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI$"
199  }  }
200    
201  # 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 38  test_for_string_in_file() { Line 207  test_for_string_in_file() {
207      RETVAL=$?      RETVAL=$?
208      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
209          printf "Error: In $file there is an illegal line: "          printf "Error: In $file there is an illegal line: "
210          grep -i "$strng" $file          grep -i "$strng" $file
211          return 1          exit 99
212      fi      fi
213      return 0      return 0
214  }  }
# Line 48  test_for_string_in_file() { Line 217  test_for_string_in_file() {
217  # the package list.  # the package list.
218  expand_pkg_groups() {  expand_pkg_groups() {
219      new_packages=      new_packages=
     PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups"  
220      if test -r $PKG_GROUPS ; then      if test -r $PKG_GROUPS ; then
221          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
222          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 227  expand_pkg_groups() {
227              if test "x$RETVAL" = x0 ; then              if test "x$RETVAL" = x0 ; then
228                  matched=1                  matched=1
229                  replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`                  replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`
230                  echo "    replacing \"$i\" with: $replace"                  echo "    replacing \"$i\" with:$replace"
231                  new_packages="$new_packages $replace"                  new_packages="$new_packages $replace"
232              else              else
233                  new_packages="$new_packages $i"                  new_packages="$new_packages $i"
# Line 102  EOF Line 270  EOF
270              check_for_broken_Ff              check_for_broken_Ff
271          else          else
272              cat <<EOF 2>&1              cat <<EOF 2>&1
273  ERROR: Your file system cannot distinguish between *.F and *.f files  ERROR: Your file system cannot distinguish between *.F and *.f files
274    (fails the "cp" test) and this program cannot find a suitable    (fails the "cp" test) and this program cannot find a suitable
275    replacement extension.  Please try a different build environment or    replacement extension.  Please try a different build environment or
276    contact the <MITgcm-support@mitgcm.org> list for help.    contact the <MITgcm-support@mitgcm.org> list for help.
277    
278  EOF  EOF
# Line 122  EOF Line 290  EOF
290        stop        stop
291        end        end
292  EOF  EOF
293      test -f Makefile  &&  mv -f Makefile Makefile.bak      test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
294      cat <<EOF >> Makefile      cat <<EOF >> $MAKEFILE
295  .SUFFIXES:  .SUFFIXES:
296  .SUFFIXES: .$tfs .F  .SUFFIXES: .$tfs .F
297  .F.$tfs:  .F.$tfs:
298          $LN \$< \$@          $LN \$< \$@
299  EOF  EOF
300      $MAKE "genmake_hello."$tfs > /dev/null 2>&1      $MAKE -f $MAKEFILE "genmake_hello."$tfs > /dev/null 2>&1
301      RETVAL=$?      RETVAL=$?
302      if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then      if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then
303          if test "x$FS" = x ; then          if test "x$FS" = x ; then
# Line 137  EOF Line 305  EOF
305              FS90='fr9'              FS90='fr9'
306              check_for_broken_Ff              check_for_broken_Ff
307          else          else
308              cat <<EOF 2>&1              echo "ERROR: test: '$MAKE -f $MAKEFILE genmake_hello.$tfs' Failed"
309  ERROR: Your file system cannot distinguish between *.F and *.f files              echo "       see simple makefile: '$MAKEFILE' (left here)"
310    (fails the "make/ln" test) and this program cannot find a suitable              echo "  Please check (1) your '$MAKE' command, (2) your '$LN' command"
311    replacement extension.  Please try a different build environment or              echo "           and (3) the allowed sufix '.F' and '.$tfs' in makefile"
312    contact the <MITgcm-support@mitgcm.org> list for help.              echo "  or contact the <MITgcm-support@mitgcm.org> list for help."
313                echo ""
 EOF  
314              exit -1              exit -1
315              return              return
316          fi          fi
317      fi      fi
318      rm -f genmake_hello.* Makefile      rm -f genmake_hello.* $MAKEFILE
319      test -f Makefile  &&  mv -f Makefile.bak Makefile      test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
320    
321      #  If we make it here, use the extensions      #  If we make it here, use the extensions
322      FS=$tfs      FS=$tfs
# Line 157  EOF Line 324  EOF
324      return      return
325  }  }
326    
   
327  look_for_makedepend()  {  look_for_makedepend()  {
328    
329      #  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 344  look_for_makedepend()  {
344      #    3) locally build and use the cyrus implementation      #    3) locally build and use the cyrus implementation
345      #    4) fall back to the buggy local xmakedpend script      #    4) fall back to the buggy local xmakedpend script
346      #      #
347        echo >> $LOGFILE
348        echo "running: look_for_makedepend()" >> $LOGFILE
349        if test "x${MAKEDEPEND}" != x ; then
350            echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1
351            RETVAL=$?
352            if test x"$RETVAL" = x0 ; then
353                build_cyrus_makedepend
354                RETVAL=$?
355                if test "x$RETVAL" != x0 ; then
356                    echo "WARNING: unable to build cyrus-makedepend. Try 'makedepend'"
357                    MAKEDEPEND=
358                fi
359            else
360                echo "${MAKEDEPEND}" | grep 'tools.xmakedepend' > /dev/null 2>&1
361                RETVAL=$?
362                if test "x$RETVAL" = x0 ; then
363                    MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
364                fi
365                echo " -->     MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
366            fi
367        fi
368      if test "x${MAKEDEPEND}" = x ; then      if test "x${MAKEDEPEND}" = x ; then
369          which makedepend > /dev/null 2>&1          which makedepend > /dev/null 2>&1
370          RV0=$?          RV0=$?
371            test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
372            #  echo 'MAKEFILE="'$MAKEFILE'"'
373            cat <<EOF >> $MAKEFILE
374    #   THIS IS A TEST MAKEFILE GENERATED BY "genmake2"
375    #
376    #   Some "makedepend" implementations will die if they cannot
377    #   find a Makefile -- so this file is here to gives them an
378    #   empty one to find and parse.
379    EOF
380          cat <<EOF >> genmake_tc.f          cat <<EOF >> genmake_tc.f
381        program test        program test
382        write(*,*) 'test'        write(*,*) 'test'
383        stop        stop
384        end        end
385  EOF  EOF
386          makedepend genmake_tc.f > /dev/null 2>&1          makedepend -f $MAKEFILE genmake_tc.f > /dev/null 2>&1
387          RV1=$?          RV1=$?
388            test -f $MAKEFILE  &&  rm -f $MAKEFILE
389            test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
390          if test "x${RV0}${RV1}" = x00 ; then          if test "x${RV0}${RV1}" = x00 ; then
391              MAKEDEPEND=makedepend              MAKEDEPEND=makedepend
392                echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
393          else          else
394              echo "    a system-default makedepend was not found."              echo "    system-default makedepend not found. Try to build cyrus-makedepend"
               
395              #  Try to build the cyrus implementation              #  Try to build the cyrus implementation
396              build_cyrus_makedepend              build_cyrus_makedepend
397              RETVAL=$?              RETVAL=$?
398              if test "x$RETVAL" != x0 ; then              if test "x$RETVAL" != x0 ; then
399                    echo "WARNING: unable to build cyrus-makedepend. Use local xmakedepend"
400                  MAKEDEPEND='$(TOOLSDIR)/xmakedepend'                  MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
401                    echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
402              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  
403          fi          fi
404      fi      fi
405  }  }
406    
   
407  build_cyrus_makedepend()  {  build_cyrus_makedepend()  {
408        echo >> $LOGFILE
409        echo "running: build_cyrus_makedepend()" >> $LOGFILE
410      rm -f ./genmake_cy_md      rm -f ./genmake_cy_md
411      (      (
412          cd $ROOTDIR/tools/cyrus-imapd-makedepend  \          cd $ROOTDIR/tools/cyrus-imapd-makedepend  \
413              &&  ./configure > /dev/null 2>&1  \              &&  ./configure > /dev/null 2>&1  \
414              &&  make > /dev/null 2>&1              &&  $MAKE > /dev/null 2>&1
415          if test -x ./makedepend.exe ; then          if test -x ./makedepend.exe ; then
416              $LN ./makedepend.exe ./makedepend              $LN ./makedepend.exe ./makedepend
417          fi          fi
# Line 230  build_cyrus_makedepend()  { Line 423  build_cyrus_makedepend()  {
423      rm -f ./genmake_cy_md      rm -f ./genmake_cy_md
424      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
425          MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'          MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
426            echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
427          return 0          return 0
428      else      else
429          echo "WARNING: unable to build cyrus-imapd-makedepend"          echo "WARNING: fail to build cyrus-imapd-makedepend" >> $LOGFILE
430          return 1          return 1
431      fi      fi
432  }  }
433    
434  # Guess possible config options for this host  build_embed_encode()
435  find_possible_configs()  {  {
436        printf "  building the embed-encode utility...  "
437      tmp1=`uname`"_"`uname -m`      if test ! -e "$ROOTDIR/tools/embed_encode/encode_files" ; then
438      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`          if test ! -d "$ROOTDIR/tools/embed_encode" ; then
439      tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`              echo
440      tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`              echo "    Error: can't locate \"$ROOTDIR/tools/embed_encode\""
441      tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`              echo
442      tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`              EMBED_SRC=f
443      PLATFORM=$tmp3              return 1
444      echo $PLATFORM | grep cygwin > /dev/null 2>&1  &&  PLATFORM=cygwin_ia32          fi
445      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`          clist="cc gcc c89 $CC"
446      echo "  The platform appears to be:  $PLATFORM"          for ic in $clist ; do
447                    comm="$ic -o encode_files encode_files.c"
448      echo "test" > test              ( cd $ROOTDIR/tools/embed_encode && $comm ) > /dev/null 2>&1
449      ln -s ./test link              RETVAL=$?
450      RETVAL=$?              if test "x$RETVAL" = x0 ; then
451      if test "x${RETVAL}" = x0 ; then                  echo "OK"
452          LN="ln -s"                  return 0
453      else              fi
454          echo "Error: \"ln -s\" does not appear to work on this system!"          done
455          echo "  For help, please contact <MITgcm-support@mitgcm.org>."          echo
456          exit 1          echo "    Error: unable to build $ROOTDIR/embed_encode/encode_files"
457      fi          echo "      so it has been disabled"
458      rm -f test link          echo
459            EMBED_SRC=f
460      if test "x$CPP" = x ; then          return 1
         CPP="cpp -traditional -P"  
461      fi      fi
462        echo "OK"
463    }
464    
465      look_for_makedepend  #  look for possible C compilers
466    look_for_C_compilers() {
467      #================================================================      echo >> $LOGFILE
468      #  look for possible C compilers      echo "running: look_for_C_compilers()" >> $LOGFILE
469      tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc"      rm -f ./genmake_hello.c  ./genmake_hello
470      p_CC=      cat >> genmake_hello.c << EOF
     for c in $tmp ; do  
         rm -f ./genmake_hello.c  ./genmake_hello  
         cat >> genmake_hello.c << EOF  
471  #include <stdio.h>  #include <stdio.h>
472  int main(int argc, char **argv) {  int main(int argc, char **argv) {
473    printf("Hello!\n");    printf("Hello!\n");
474    return 0;    return 0;
475  }  }
476  EOF  EOF
477          $c -o genmake_hello genmake_hello.c > /dev/null 2>&1      tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc icc"
478        p_CC=
479        for c in $tmp ; do
480            COMM="$c $CFLAGS -o genmake_hello genmake_hello.c"
481            echo $COMM >> $LOGFILE
482            $COMM >> $LOGFILE 2>&1
483          RETVAL=$?          RETVAL=$?
484          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
485                echo " $c test successful" >> $LOGFILE
486              p_CC="$p_CC $c"              p_CC="$p_CC $c"
487          fi          fi
488      done      done
# Line 300  Error: No C compilers were found in your Line 498  Error: No C compilers were found in your
498  EOF  EOF
499          exit 1          exit 1
500      else      else
501          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  
502          if test "x$CC" = x ; then          if test "x$CC" = x ; then
503              CC=`echo $p_CC | $AWK '{print $1}'`              CC=`echo $p_CC | $AWK '{print $1}'`
504              echo "  Setting C compiler to: "$CC              echo "  Setting C compiler to: "$CC
505          fi          fi
506      fi      fi
507        echo " --> set CC='$CC'" >> $LOGFILE
508    }
509    
510    # Guess possible config options for this host
511    find_possible_optfile()  {
512    
513        echo >> $LOGFILE
514        echo "running: find_possible_optfile()" >> $LOGFILE
515        tmp1=`uname`"_"`uname -m`
516        tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
517        tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
518        tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
519        tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
520        tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
521        PLATFORM=$tmp3
522        echo $PLATFORM | grep cygwin > /dev/null 2>&1  &&  PLATFORM=cygwin_ia32
523        OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
524        echo "  The platform appears to be:  $PLATFORM" | tee -a $LOGFILE
525    
526      #================================================================      #================================================================
527      #  look for possible FORTRAN compilers      #  look for possible FORTRAN compilers
528      tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"      echo "  look for possible FORTRAN compilers" >> $LOGFILE
529        tmp="$MITGCM_FC $FC efc gfortran g77 f77 pgf77 pgf95 ifc ifort f90 f95 mpif77 mpf77 mpxlf95 g95"
530      p_FC=      p_FC=
531      for c in $tmp ; do      rm -f ./genmake_hello.f
532          rm -f ./hello.f ./hello      cat >> genmake_hello.f <<EOF
         cat >> hello.f <<EOF  
533        program hello        program hello
534        do i=1,3        do i=1,3
535          print *, 'hello world : ', i          print *, 'hello world : ', i
536        enddo        enddo
537        end        end
538  EOF  EOF
539          $c -o hello hello.f > /dev/null 2>&1      for f in $tmp ; do
540            COMM="$f -o genmake_hello genmake_hello.f"
541            echo $COMM >> $LOGFILE
542            $COMM >> $LOGFILE 2>&1
543          RETVAL=$?          RETVAL=$?
544          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
545              p_FC="$p_FC $c"              echo " $f test successful" >> $LOGFILE
546                p_FC="$p_FC $f"
547          fi          fi
548      done      done
549      rm -f ./hello.f ./hello      rm -f ./genmake_hello.f ./genmake_hello
550      if test "x${p_FC}" = x ; then      if test "x${p_FC}" = x ; then
551          cat 1>&2 <<EOF          cat 1>&2 <<EOF
552    
# Line 340  Error: No Fortran compilers were found i Line 559  Error: No Fortran compilers were found i
559  EOF  EOF
560          exit 1          exit 1
561      else      else
562          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
563          echo "   "$p_FC      fi
564          if test "x$FC" = x ; then  
565              FC=`echo $p_FC | $AWK '{print $1}'`      #  Use the first of the compilers found in the current PATH
566              echo "  Setting FORTRAN compiler to: "$FC      #  that has a correctly-named optfile
567          fi      if test "x$OPTFILE" = x  -a  "x$FC" = x ; then
568            for i in $p_FC ; do
569                OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
570                if test -r $OPTFILE ; then
571                    echo "  Setting OPTFILE to: "$OPTFILE | tee -a $LOGFILE
572                    break
573                fi
574            done
575      fi      fi
576    
577      if test "x$OPTFILE" = x ; then      if test "x$OPTFILE" = x ; then
578          OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC          OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
579          if test ! -r $OPTFILE ; then          if test ! -r $OPTFILE ; then
580               echo "  I looked for the file "$OPTFILE" but did not find it"               echo "  I looked for the file "$OPTFILE" but did not find it"
581          fi          fi
582      fi      fi
583  #    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  
584      if test "x$OPTFILE" = x ; then      if test "x$OPTFILE" = x ; then
585          cat 1>&2 <<EOF          cat 1>&2 <<EOF
586    
# Line 380  Error: No options file was found in:  $R Line 596  Error: No options file was found in:  $R
596  EOF  EOF
597          exit 1          exit 1
598      fi      fi
       
 #     # look for possible MPI libraries  
 #     mpi_libs=  
 #     mpi_fort=`which mpif77 2>/dev/null`  
 #     RETVAL=$?  
 #     if test "x${RETVAL}" = x0 ; then  
 #       cat >>test.f <<EOF  
 #       PROGRAM HELLO  
 #       DO 10, I=1,10  
 #       PRINT *,'Hello World'  
 #    10 CONTINUE  
 #       STOP  
 #       END  
 # EOF  
 #       eval "$mpi_fort -showme test.f > out"  
 #       RETVAL=$?  
 #       if test "x${RETVAL}" = x0 ; then  
 #           a=`cat out`  
 #           for i in $a ; do  
 #               case $i in  
 #                   -*)  
 #                       mpi_libs="$mpi_libs $i" ;;  
 #               esac  
 #           done  
 #           echo "The MPI libs appear to be:"  
 #           echo "  "$mpi_libs  
 #       fi  
 #       rm -f test.f out  
 #     fi  
   
599  }  }
600    
601  #  Parse the package dependency information  #  Parse the package dependency information
# Line 418  get_pdepend_list()  { Line 604  get_pdepend_list()  {
604      #  strip the comments and then convert the dependency file into      #  strip the comments and then convert the dependency file into
605      #  two arrays: PNAME, DNAME      #  two arrays: PNAME, DNAME
606      cat $1 | sed -e 's/#.*$//g' \      cat $1 | sed -e 's/#.*$//g' \
607          | $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}' \
608          > ./.pd_tmp          > ./.pd_tmp
609        RETVAL=$?
610        if test ! "x${RETVAL}" = x0 ; then
611          echo "Error: unable to parse package dependencies -- please check PKG_DEPEND=\"$1\""
612          exit 1
613        fi
614      . ./.pd_tmp      . ./.pd_tmp
615      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.  
   
     -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  
616  }  }
617    
618  #  Build a CPP macro to automate calling C routines from FORTRAN  #  Build a CPP macro to automate calling C routines from FORTRAN
# Line 549  get_fortran_c_namemangling()  { Line 620  get_fortran_c_namemangling()  {
620    
621      #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""      #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
622      if test ! "x$FC_NAMEMANGLE" = x ; then      if test ! "x$FC_NAMEMANGLE" = x ; then
623          return 0          return 0
624      fi      fi
625        echo " running: get_fortran_c_namemangling()" >> $LOGFILE
626    
627      default_nm="#define FC_NAMEMANGLE(X) X ## _"      default_nm="#define FC_NAMEMANGLE(X) X ## _"
628        
629      cat > genmake_test.c <<EOF      cat > genmake_test.c <<EOF
630  void tcall( char * string ) { tsub( string ); }  void tcall( char * string ) { tsub( string ); }
631  EOF  EOF
632      $MAKE genmake_test.o >> genmake_warnings 2>&1      COMM="$CC $CFLAGS -c genmake_test.c"
633        echo ' '$COMM >> $LOGFILE
634        $COMM >> $LOGFILE 2>&1
635      RETVAL=$?      RETVAL=$?
636      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
637          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
638          cat <<EOF>> genmake_errors          cat <<EOF>> $LOGFILE
639    
640  WARNING: C test compile fails   WARNING: C test compile fails
641  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
642  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here   WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
643  EOF  EOF
644          return 1          return 1
645      fi      fi
# Line 573  EOF Line 647  EOF
647      RETVAL=$?      RETVAL=$?
648      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
649          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
650          cat <<EOF>> genmake_warnings          cat <<EOF>> $LOGFILE
651    
652  WARNING: The "nm" command failed.   WARNING: The "nm" command failed.
653  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
654  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here   WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
655  EOF  EOF
656          return 1          return 1
657      fi      fi
658      cat > genmake_tcomp.f <<EOF      cat > genmake_tcomp.$FS <<EOF
659        subroutine tcall( string )        subroutine tcall( string )
660        character*(*) string        character*(*) string
661        call tsub( string )        call tsub( string )
662        end        end
663  EOF  EOF
664      $FC $FFLAGS $DEFINES -c genmake_tcomp.f >> genmake_warnings 2>&1      COMM="$FC $FFLAGS -c genmake_tcomp.$FS"
665        echo ' '$COMM >> $LOGFILE
666        $COMM >> $LOGFILE 2>&1
667      RETVAL=$?      RETVAL=$?
668      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
669          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
670          cat <<EOF>> genmake_warnings          cat <<EOF>> $LOGFILE
671    
672  WARNING: FORTRAN test compile fails -- please see "genmake_errors"   WARNING: FORTRAN test compile fails -- please see '$LOGFILE'
673  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
674  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.   WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
675  EOF  EOF
676          return 1          return 1
677      fi      fi
# Line 603  EOF Line 679  EOF
679      RETVAL=$?      RETVAL=$?
680      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
681          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
682          cat <<EOF>> genmake_warnings          cat <<EOF>> $LOGFILE
683    
684  WARNING: The "nm" command failed.   WARNING: The "nm" command failed.
685  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
686  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.   WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
687  EOF  EOF
688          return 1          return 1
689      fi      fi
# Line 633  EOF Line 709  EOF
709    
710      #  cleanup the testing files      #  cleanup the testing files
711      rm -f genmake_tcomp.* genmake_test.*      rm -f genmake_tcomp.* genmake_test.*
 }  
712    
713        echo " --> set FC_NAMEMANGLE='$FC_NAMEMANGLE'" >> $LOGFILE
714    }
715    
716  check_HAVE_CLOC()  {  check_HAVE_CLOC()  {
717        echo >> $LOGFILE
718        echo "running: check_HAVE_CLOC()" >> $LOGFILE
719      get_fortran_c_namemangling      get_fortran_c_namemangling
720      cat <<EOF > genmake_tc_1.c      cat <<EOF > genmake_tc_1.c
721  $FC_NAMEMANGLE  $FC_NAMEMANGLE
# Line 653  void FC_NAMEMANGLE(cloc) ( double *curti Line 732  void FC_NAMEMANGLE(cloc) ( double *curti
732   *curtim = *curtim/1.E6;   *curtim = *curtim/1.E6;
733  }  }
734  EOF  EOF
735      make genmake_tc_1.o >> genmake_tc.log 2>&1      COMM="$CC $CFLAGS -c genmake_tc_1.c"
736        echo $COMM >> $LOGFILE
737        $COMM >> $LOGFILE 2>&1
738      RET_C=$?      RET_C=$?
739      cat <<EOF > genmake_tc_2.f      cat <<EOF > genmake_tc_2.$FS
740        program hello        program hello
741        Real*8 wtime        REAL*8 wtime
742        external cloc        external cloc
743        call cloc(wtime)        call cloc(wtime)
744        print *," HELLO WORLD", wtime        print *," HELLO WORLD", wtime
745        end program hello        end
746  EOF  EOF
747      $FC $FFLAGS -o genmake_tc genmake_tc_2.f genmake_tc_1.o >> genmake_tc.log 2>&1      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
748        echo $COMM >> $LOGFILE
749        $COMM >> $LOGFILE 2>&1
750      RET_F=$?      RET_F=$?
751      test -x ./genmake_tc  &&  ./genmake_tc >> genmake_tc.log 2>&1      test -x ./genmake_tc  &&  ./genmake_tc >> $LOGFILE 2>&1
752      RETVAL=$?      RETVAL=$?
753      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
754          HAVE_CLOC=t          HAVE_CLOC=t
         DEFINES="$DEFINES -DHAVE_CLOC"  
755      fi      fi
756      rm -f genmake_tc*      rm -f genmake_tc*
757        echo " --> set HAVE_CLOC='$HAVE_CLOC'" >> $LOGFILE
758  }  }
759    
760    check_HAVE_SIGREG()  {
761        if test ! "x$HAVE_SIGREG" = x ; then
762            return
763        fi
764        echo >> $LOGFILE
765        echo "running: check_HAVE_SIGREG()" >> $LOGFILE
766        get_fortran_c_namemangling
767        cat <<EOF > genmake_tc_1.c
768    $FC_NAMEMANGLE
769    #include <stdlib.h>
770    #include <stdio.h>
771    #include <signal.h>
772    #include <errno.h>
773    #include <ucontext.h>
774    
775    int * ip;
776    
777    static void killhandler(
778        unsigned int sn, siginfo_t  si, struct ucontext *sc )
779    {
780        *ip = *ip + 1;
781        return;
782    }
783    
784    void FC_NAMEMANGLE(sigreg) (int * aip)
785    {
786        struct sigaction s;
787        ip = aip;
788        s.sa_flags = SA_SIGINFO;
789        s.sa_sigaction = (void *)killhandler;
790        if(sigaction (SIGTERM,&s,(struct sigaction *)NULL)) {
791            printf("Sigaction returned error = %d\n", errno);
792            exit(0);
793        }
794        return;
795    }
796    EOF
797        COMM="$CC $CFLAGS -c genmake_tc_1.c"
798        echo $COMM >> $LOGFILE
799        $COMM >> $LOGFILE 2>&1
800        RET_C=$?
801        cat <<EOF > genmake_tc_2.$FS
802          program hello
803          integer anint
804          common /iv/ anint
805          external sigreg
806          call sigreg(anint)
807          end
808    EOF
809        cat genmake_tc_2.$FS >> $LOGFILE
810        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
811        echo $COMM >> $LOGFILE
812        $COMM >> $LOGFILE 2>&1
813        RETVAL=$?
814        if test "x$RETVAL" = x0 ; then
815            HAVE_SIGREG=t
816        fi
817        rm -f genmake_tc*
818        echo " --> set HAVE_SIGREG='$HAVE_SIGREG'" >> $LOGFILE
819    }
820    
821    check_HAVE_SETRLSTK()  {
822        if test ! "x$HAVE_SETRLSTK" = x ; then
823            return
824        fi
825        echo >> $LOGFILE
826        echo "running: check_HAVE_SETRLSTK()" >> $LOGFILE
827        get_fortran_c_namemangling
828        cat <<EOF > genmake_tc_1.c
829    $FC_NAMEMANGLE
830    #include <sys/time.h>
831    #include <sys/resource.h>
832    #include <unistd.h>
833    void FC_NAMEMANGLE(setrlstk) ()
834    {
835        struct rlimit rls;
836        rls.rlim_cur = RLIM_INFINITY;
837        rls.rlim_max = RLIM_INFINITY;
838        setrlimit(RLIMIT_STACK, &rls);
839        return;
840    }
841    EOF
842        COMM="$CC $CFLAGS -c genmake_tc_1.c"
843        echo $COMM >> $LOGFILE
844        $COMM >> $LOGFILE 2>&1
845        RET_C=$?
846        cat <<EOF > genmake_tc_2.$FS
847          program hello
848          external setrlstk
849          call setrlstk()
850          end
851    EOF
852        cat genmake_tc_2.$FS >> $LOGFILE
853        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
854        echo $COMM >> $LOGFILE
855        $COMM >> $LOGFILE 2>&1
856        RETVAL=$?
857        if test "x$RETVAL" = x0 ; then
858            HAVE_SETRLSTK=t
859        fi
860        rm -f genmake_tc*
861        echo " --> set HAVE_SETRLSTK='$HAVE_SETRLSTK'" >> $LOGFILE
862    }
863    
864  check_HAVE_STAT()  {  check_HAVE_STAT()  {
865        echo >> $LOGFILE
866        echo "running: check_HAVE_STAT()" >> $LOGFILE
867      get_fortran_c_namemangling      get_fortran_c_namemangling
868      cat <<EOF > genmake_tc_1.c      cat <<EOF > genmake_tc_1.c
869  $FC_NAMEMANGLE  $FC_NAMEMANGLE
# Line 696  void FC_NAMEMANGLE(tfsize) ( int *nbyte Line 884  void FC_NAMEMANGLE(tfsize) ( int *nbyte
884          *nbyte = -1;          *nbyte = -1;
885  }  }
886  EOF  EOF
887      make genmake_tc_1.o >> genmake_tc.log 2>&1      COMM="$CC $CFLAGS -c genmake_tc_1.c"
888        echo $COMM >> $LOGFILE
889        $COMM >> genmake_tc.log 2>&1
890      RET_C=$?      RET_C=$?
891      cat <<EOF > genmake_tc_2.f      cat <<EOF > genmake_tc_2.$FS
892        program hello        program hello
893        integer nbyte        integer nbyte
894        call tfsize(nbyte)        call tfsize(nbyte)
895        print *," HELLO WORLD", nbyte        print *," HELLO WORLD", nbyte
896        end program hello        end
897  EOF  EOF
898      $FC $FFLAGS -o genmake_tc genmake_tc_2.f genmake_tc_1.o >> genmake_tc.log 2>&1      cat genmake_tc_2.$FS >> $LOGFILE
899      RET_F=$?      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
900      test -x ./genmake_tc  &&  ./genmake_tc >> genmake_tc.log 2>&1      echo $COMM >> $LOGFILE
901        $COMM >> genmake_tc.log 2>&1
902      RETVAL=$?      RETVAL=$?
903      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
904          HAVE_STAT=t          HAVE_STAT=t
         DEFINES="$DEFINES -DHAVE_STAT"  
905      fi      fi
906      rm -f genmake_tc*      rm -f genmake_tc*
907        echo " --> set HAVE_STAT='$HAVE_STAT'" >> $LOGFILE
908  }  }
909    
   
910  check_netcdf_libs()  {  check_netcdf_libs()  {
911      echo "" > genmake_tnc.log      if test ! "x$SKIP_NETCDF_CHECK" = x ; then
912      cat <<EOF > genmake_tnc.for          return
913        fi
914        echo >> $LOGFILE
915        echo "running: check_netcdf_libs()" >> $LOGFILE
916        cat <<EOF > genmake_tnc.F
917        program fgennc        program fgennc
918  #include "netcdf.inc"  #include "netcdf.inc"
919    EOF
920        if test ! "x$MPI" = x ; then
921            echo '#include "mpif.h"' >> genmake_tnc.F
922        fi
923        cat <<EOF >> genmake_tnc.F
924        integer iret, ncid, xid        integer iret, ncid, xid
925        iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)        iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
926        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
# Line 731  check_netcdf_libs()  { Line 930  check_netcdf_libs()  {
930        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
931        end        end
932  EOF  EOF
933      #echo "$CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f"      echo "===  genmake_tnc.F  >>>" > genmake_tnc.log
934      #echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.f"      cat genmake_tnc.F >> genmake_tnc.log
935      #echo "$LINK -o genmake_tnc.o $LIBS"      echo "<<<  genmake_tnc.F  ===" >> genmake_tnc.log
936      $CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f 2>/dev/null  \      RET_CPP=f
937          &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.f >> genmake_tnc.log 2>&1  \      COMM="cat genmake_tnc.F | $CPP $DEFINES $INCLUDES"
938          &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1      echo "$COMM" >> genmake_tnc.log
939        eval $COMM > genmake_tnc.$FS 2>/dev/null  &&  RET_CPP=t
940        if test "x$RET_CPP" = xf ; then
941            echo "  WARNING: CPP failed to pre-process the netcdf test." \
942                >> genmake_tnc.log
943            echo "    Please check that \$INCLUDES is properly set." \
944                >> genmake_tnc.log
945        fi
946        echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.$FS  \ " >> genmake_tnc.log
947        echo "  &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc.o $LIBS" >> genmake_tnc.log
948        $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
949            &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
950      RET_COMPILE=$?      RET_COMPILE=$?
951        cat genmake_tnc.log >> $LOGFILE
952    
953      #EH3  Remove test program execution for machines that either disallow      #EH3  Remove test program execution for machines that either disallow
954      #EH3  execution or cannot support it (eg. cross-compilers)      #EH3  execution or cannot support it (eg. cross-compilers)
# Line 748  EOF Line 959  EOF
959    
960      if test "x$RET_COMPILE" = x0 ; then      if test "x$RET_COMPILE" = x0 ; then
961          HAVE_NETCDF=t          HAVE_NETCDF=t
962            echo "check_netcdf: successful" >> $LOGFILE
963      else      else
964          # try again with "-lnetcdf" added to the libs          # try again with "-lnetcdf" added to the libs
965          $CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f 2>/dev/null  \          echo "==> try again with added '-lnetcdf'" > genmake_tnc.log
966              &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.f >> genmake_tnc.log 2>&1  \          echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log
967              &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1          echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
968            echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
969            cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null  \
970                &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
971                &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
972          RET_COMPILE=$?          RET_COMPILE=$?
973            echo >> $LOGFILE
974            cat genmake_tnc.log >> $LOGFILE
975          if test "x$RET_COMPILE" = x0 ; then          if test "x$RET_COMPILE" = x0 ; then
976              LIBS="$LIBS -lnetcdf"              LIBS="$LIBS -lnetcdf"
977              HAVE_NETCDF=t              HAVE_NETCDF=t
978                echo "check_netcdf: successful" >> $LOGFILE
979          else          else
980              cat genmake_tnc.log >> genmake_warnings          # try again with "-lnetcdff" added to the libs
981                echo "==> try again with added '-lnetcdff -lnetcdf'" > genmake_tnc.log
982                echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log
983                echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
984                echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
985                cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null  \
986                    &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
987                    &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdff -lnetcdf >> genmake_tnc.log 2>&1
988                RET_COMPILE=$?
989                echo >> $LOGFILE
990                cat genmake_tnc.log >> $LOGFILE
991                if test "x$RET_COMPILE" = x0 ; then
992                    LIBS="$LIBS -lnetcdff -lnetcdf"
993                    HAVE_NETCDF=t
994                    echo "check_netcdf: successful" >> $LOGFILE
995                fi
996          fi          fi
997      fi      fi
998      rm -f genmake_tnc*      rm -f genmake_tnc*
999        echo " --> set HAVE_NETCDF='$HAVE_NETCDF'" >> $LOGFILE
1000  }  }
1001    
1002    check_lapack_libs()  {
1003        if test ! "x$SKIP_LAPACK_CHECK" = x ; then
1004            return
1005        fi
1006        echo >> $LOGFILE
1007        echo "running: check_lapack_libs()" >> $LOGFILE
1008        cat <<EOF > genmake_tla.F
1009          program fgenla
1010          integer info
1011          integer ipiv( 2 )
1012          double precision ab( 4, 2 ), b( 2 )
1013          data ab / 0., 0., 1., 2., 0., 2., 1., 0. /
1014          data b / 1., 1. /
1015          call dgbsv( 2, 1, 1, 1, ab, 4, ipiv, b, 2, info )
1016          IF (info .NE. 0) write(*,*) 'Error:', info
1017          write(*,*) b
1018          end
1019    EOF
1020        echo "===  genmake_tla.F  >>>" > genmake_tla.log
1021        cat genmake_tla.F >> genmake_tla.log
1022        echo "<<<  genmake_tla.F  ===" >> genmake_tla.log
1023        RET_CPP=f
1024        COMM="cat genmake_tla.F | $CPP $DEFINES $INCLUDES"
1025        echo "$COMM" >> genmake_tla.log
1026        eval $COMM > genmake_tla.$FS 2>/dev/null  &&  RET_CPP=t
1027        if test "x$RET_CPP" = xf ; then
1028            echo "  WARNING: CPP failed to pre-process the lapack test." \
1029                >> genmake_tla.log
1030            echo "    Please check that \$INCLUDES is properly set." \
1031                >> genmake_tla.log
1032        fi
1033        echo "$FC $FFLAGS $FOPTIM -c genmake_tla.$FS  \ " >> genmake_tla.log
1034        echo "  &&  $LINK $FFLAGS $FOPTIM -o genmake_tla.o $LIBS" >> genmake_tla.log
1035        $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
1036            &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS >> genmake_tla.log 2>&1
1037        RET_COMPILE=$?
1038        cat genmake_tla.log >> $LOGFILE
1039    
1040        # test program execution not always possible (see check_netcdf_libs)
1041        #
1042        #test -x ./genmake_tla  &&  ./genmake_tla >> genmake_tla.log 2>&1
1043        #RETVAL=$?
1044        #if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
1045    
1046        if test "x$RET_COMPILE" = x0 ; then
1047            HAVE_LAPACK=t
1048            echo "check_lapack: successful" >> $LOGFILE
1049        else
1050            # try again with "-llapack" added to the libs
1051            echo "==> try again with added '-llapack'" > genmake_tla.log
1052            echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1053            echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1054            echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack" >> genmake_tla.log
1055            cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null  \
1056                &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
1057                &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack >> genmake_tla.log 2>&1
1058            RET_COMPILE=$?
1059            echo >> $LOGFILE
1060            cat genmake_tla.log >> $LOGFILE
1061            if test "x$RET_COMPILE" = x0 ; then
1062                LIBS="$LIBS -llapack"
1063                HAVE_LAPACK=t
1064                echo "check_lapack: successful" >> $LOGFILE
1065            else
1066            # try again with "-lf77blas -lcblas" added to the libs
1067                echo "==> try again with added '-llapack -lf77blas -lcblas'" > genmake_tla.log
1068                echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1069                echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1070                echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas" >> genmake_tla.log
1071                cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null  \
1072                    &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
1073                    &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas >> genmake_tla.log 2>&1
1074                RET_COMPILE=$?
1075                echo >> $LOGFILE
1076                cat genmake_tla.log >> $LOGFILE
1077                if test "x$RET_COMPILE" = x0 ; then
1078                    LIBS="$LIBS -llapack -lf77blas -lcblas"
1079                    HAVE_LAPACK=t
1080                    echo "check_lapack: successful" >> $LOGFILE
1081                else
1082                # try again with "-latlas" added to the libs
1083                    echo "==> try again with added '-llapack -lf77blas -lcblas -latlas'" > genmake_tla.log
1084                    echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1085                    echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1086                    echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas -latlas" >> genmake_tla.log
1087                    cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null  \
1088                        &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
1089                        &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas -latlas >> genmake_tla.log 2>&1
1090                    RET_COMPILE=$?
1091                    echo >> $LOGFILE
1092                    cat genmake_tla.log >> $LOGFILE
1093                    if test "x$RET_COMPILE" = x0 ; then
1094                        LIBS="$LIBS -llapack -lf77blas -lcblas -latlas"
1095                        HAVE_LAPACK=t
1096                        echo "check_lapack: successful" >> $LOGFILE
1097                    fi
1098                fi
1099            fi
1100        fi
1101        rm -f genmake_tla*
1102        echo " --> set HAVE_LAPACK='$HAVE_LAPACK'" >> $LOGFILE
1103    }
1104    
1105    
1106  ###############################################################################  ###############################################################################
# Line 777  PLATFORM= Line 1114  PLATFORM=
1114  LN=  LN=
1115  S64=  S64=
1116  KPP=  KPP=
1117  FC=  #FC=
1118  #CC=gcc  #CC=gcc
1119  CPP=  #CPP=
1120  LINK=  LINK=
1121  DEFINES=  DEFINES=
1122  PACKAGES=  PACKAGES=
1123  ENABLE=  ENABLE=
1124  DISABLE=  DISABLE=
1125  MAKEFILE=  # MAKEFILE=
1126  #MAKEDEPEND=  # MAKEDEPEND=
1127  PDEPEND=  PKG_DEPEND=
1128  DUMPSTATE=t  PKG_GROUPS=
1129  PDEFAULT=  DUMPSTATE=f
1130  OPTFILE=  OPTFILE=
1131  INCLUDES="-I."  INCLUDES="-I. $INCLUDES"
1132  FFLAGS=  FFLAGS=
1133  FOPTIM=  FOPTIM=
1134    FEXTRAFLAGS=
1135    USE_EXTENDED_SRC=
1136    EXTENDED_SRC_FLAG=
1137    GET_FC_VERSION=
1138  CFLAGS=  CFLAGS=
1139  KFLAGS1=  KFLAGS1=
1140  KFLAGS2=  KFLAGS2=
# Line 804  NOOPTFILES= Line 1145  NOOPTFILES=
1145  NOOPTFLAGS=  NOOPTFLAGS=
1146  MPI=  MPI=
1147  MPIPATH=  MPIPATH=
1148    OMP=
1149    OMPFLAG=
1150    USE_R4=
1151    TS=
1152    PAPIS=
1153    PCLS=
1154    FOOLAD=
1155    PAPI=
1156    PCL=
1157    HPMT=
1158    GSL=
1159    DEVEL=
1160    HAVE_TEST_L=
1161    
1162  # DEFINES checked by test compilation  # DEFINES checked by test compilation or command-line
1163  HAVE_SYSTEM=  HAVE_SYSTEM=
1164  HAVE_FDATE=  HAVE_FDATE=
1165  FC_NAMEMANGLE=  FC_NAMEMANGLE=
1166  HAVE_CLOC=  HAVE_CLOC=
1167    # HAVE_SETRLSTK=
1168  HAVE_STAT=  HAVE_STAT=
1169  HAVE_NETCDF=  HAVE_NETCDF=
1170  HAVE_ETIME=  HAVE_ETIME=
1171    IGNORE_TIME=
1172    HAVE_LAPACK=
1173    
1174  MODS=  MODS=
1175  TOOLSDIR=  TOOLSDIR=
# Line 820  SOURCEDIRS= Line 1177  SOURCEDIRS=
1177  INCLUDEDIRS=  INCLUDEDIRS=
1178  STANDARDDIRS="USE_THE_DEFAULT"  STANDARDDIRS="USE_THE_DEFAULT"
1179    
1180    #- local config file
1181    gm_local="genmake_local"
1182    
1183  G2ARGS=  G2ARGS=
1184  BASH=  BASH=
1185  PWD=`pwd`  PWD=`pwd`
1186  MAKE=make  test "x$MAKE" = x  &&  MAKE=make
1187  AWK=awk  test "x$AWK" = x   &&  AWK=awk
1188    EMBED_SRC=
1189  THISHOST=`hostname`  THISHOST=`hostname`
1190  THISCWD=`pwd`  THISCWD=`pwd`
1191  THISDATE=`date`  THISDATE=`date`
# Line 834  MACHINE=`uname -a` Line 1195  MACHINE=`uname -a`
1195  EXECUTABLE=  EXECUTABLE=
1196  EXEHOOK=  EXEHOOK=
1197  EXEDIR=  EXEDIR=
 PACKAGES_CONF=  
1198  IEEE=  IEEE=
1199  if test "x$MITGCM_IEEE" != x ; then  if test "x$MITGCM_IEEE" != x ; then
1200      IEEE=$MITGCM_IEEE      IEEE=$MITGCM_IEEE
# Line 855  FTL_TAF_FLAGS= Line 1215  FTL_TAF_FLAGS=
1215  SVD_TAMC_FLAGS=  SVD_TAMC_FLAGS=
1216  TAMC_EXTRA=  TAMC_EXTRA=
1217    
   
1218  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
1219  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"  gm_s1="ROOTDIR STANDARDDIRS MODS PKG_DEPEND PKG_GROUPS DISABLE ENABLE"
1220  gm_s2="FC CPP IEEE MPI JAM DUMPSTATE STANDARDDIRS"  gm_s2="PLATFORM OPTFILE MAKE MAKEFILE MAKEDEPEND FC CC MPI OMP USE_R4"
1221    gm_s3="FEXTRAFLAGS IEEE DEVEL GSL TS PAPIS PCLS PAPI PCL HPMT DUMPSTATE"
1222    
1223  #  The following state is not directly set by command-line switches  #  The following state is not directly set by command-line switches
1224  gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "  gm_s4="LN S64 LINK PACKAGES INCLUDES FFLAGS FOPTIM"
1225  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"  gm_s5="CFLAGS LIBS KPP KFLAGS1 KFLAGS2 KPPFILES NOOPTFILES NOOPTFLAGS"
1226  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE"  gm_s6="TOOLSDIR SOURCEDIRS INCLUDEDIRS EXEDIR EXECUTABLE EXEHOOK"
1227  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"  gm_s7="PWD THISHOST THISUSER THISDATE THISVER MACHINE"
1228  gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME"  gm_s8="FC_NAMEMANGLE HAVE_NETCDF HAVE_SYSTEM HAVE_FDATE HAVE_ETIME HAVE_LAPACK"
1229    
1230  #  The following are all related to adjoint/tangent-linear stuff  #  The following are all related to adjoint/tangent-linear stuff
1231  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"
1232  gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"  gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
1233  gm_s12="TAF_EXTRA TAMC_EXTRA"  gm_s12="TAF_EXTRA TAMC_EXTRA"
1234    
1235  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7 $gm_s8"
1236  gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"  gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
1237    
1238  cat <<EOF  cat <<EOF
1239    
1240  GENMAKE :  GENMAKE :
1241    
1242  A program for GENerating MAKEfiles for the MITgcm project.  For a  A program for GENerating MAKEfiles for the MITgcm project.
1243  quick list of options, use "genmake -h" or for more detail see:     For a quick list of options, use "genmake2 -h"
1244    or for more detail see the Developer's HOWTO manual at:
1245    http://mitgcm.org/devel_HOWTO/     http://mitgcm.org/public/docs.html
1246    
1247  EOF  EOF
1248    
1249    LOGFILE="genmake.log"
1250    #- clean-up previous genmake logfiles:
1251    rm -f genmake_state genmake_*optfile $LOGFILE
1252    
1253  echo "===  Processing options files and arguments  ==="  echo "===  Processing options files and arguments  ==="
 gm_local="genmake_local"  
 for i in . $MODS ; do  
     if test -r $i/$gm_local ; then  
         . $i/$gm_local  
         break  
     fi  
 done  
 printf "  getting local config information:  "  
 if test -f $gm_local ; then  
     echo "using $gm_local"  
     . $gm_local  
     # echo "DISABLE=$DISABLE"  
     # echo "ENABLE=$ENABLE"  
 else  
     echo "none found"  
 fi  
1254    
1255  #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  
1256  #parse_options  #parse_options
1257  ac_prev=  ac_prev=
1258  for ac_option in "$@" ; do  for ac_option in "$@" ; do
# Line 926  for ac_option in "$@" ; do Line 1265  for ac_option in "$@" ; do
1265          ac_prev=          ac_prev=
1266          continue          continue
1267      fi      fi
1268        
1269      ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`      ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
1270        
1271      case $ac_option in      case $ac_option in
1272            
1273          -help | --help | -h | --h)          -help | --help | -h | --h)
1274              usage ;;              usage ;;
1275            
1276          -nooptfile | --nooptfile)          -nooptfile | --nooptfile)
1277              OPTFILE="NONE" ;;              OPTFILE="NONE" ;;
1278          -optfile | --optfile | -of | --of)          -optfile | --optfile | -of | --of)
1279              ac_prev=OPTFILE ;;              ac_prev=OPTFILE ;;
1280          -optfile=* | --optfile=* | -of=* | --of=*)          -optfile=* | --optfile=* | -of=* | --of=*)
1281              OPTFILE=$ac_optarg ;;              OPTFILE=$ac_optarg ;;
1282            
1283          -adoptfile | --adoptfile | -adof | --adof)          -adoptfile | --adoptfile | -adof | --adof)
1284              ac_prev=AD_OPTFILE ;;              ac_prev=AD_OPTFILE ;;
1285          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
1286              AD_OPTFILE=$ac_optarg ;;              AD_OPTFILE=$ac_optarg ;;
1287            
1288          -pdepend | --pdepend)          -pdepend | --pdepend)
1289              ac_prev=PDEPEND ;;              ac_prev=PKG_DEPEND ;;
1290          -pdepend=* | --pdepend=*)          -pdepend=* | --pdepend=*)
1291              PDEPEND=$ac_optarg ;;              PKG_DEPEND=$ac_optarg ;;
1292            
1293          -pdefault | --pdefault)          -pgroups | --pgroups)
1294              ac_prev=PDEFAULT ;;              ac_prev=PKG_GROUPS ;;
1295          -pdefault=* | --pdefault=*)          -pgroups=* | --pgroups=*)
1296              PDEFAULT=$ac_optarg ;;              PKG_GROUPS=$ac_optarg ;;
1297            
1298          -make | --make | -m | --m)          -make | --make | -m | --m)
1299              ac_prev=MAKE ;;              ac_prev=MAKE ;;
1300          -make=* | --make=* | -m=* | --m=*)          -make=* | --make=* | -m=* | --m=*)
1301              MAKE=$ac_optarg ;;              MAKE=$ac_optarg ;;
1302            
1303          -bash | --bash)          -bash | --bash)
1304              ac_prev=BASH ;;              ac_prev=BASH ;;
1305          -bash=* | --bash=*)          -bash=* | --bash=*)
1306              BASH=$ac_optarg ;;              BASH=$ac_optarg ;;
1307            
1308          -makedepend | --makedepend | -md | --md)          -makedepend | --makedepend | -md | --md)
1309              ac_prev=MAKEDEPEND ;;              ac_prev=MAKEDEPEND ;;
1310          -makedepend=* | --makedepend=* | -md=* | --md=*)          -makedepend=* | --makedepend=* | -md=* | --md=*)
1311              MAKEDEPEND=$ac_optarg ;;              MAKEDEPEND=$ac_optarg ;;
1312            
1313          -makefile | --makefile | -ma | --ma)          -makefile | --makefile | -mf | --mf)
1314              ac_prev=MAKEFILE ;;              ac_prev=MAKEFILE ;;
1315          -makefile=* | --makefile=* | -ma=* | --ma=*)          -makefile=* | --makefile=* | -mf=* | --mf=*)
1316              MAKEFILE=$ac_optarg ;;              MAKEFILE=$ac_optarg ;;
1317            
1318          -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)          -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
1319              echo "ERROR: The platform option has been removed.  Please specify"              echo "ERROR: The platform option has been removed.  Please specify"
1320              echo "  the build options using the \"optfile\" mechanism."              echo "  the build options using the \"optfile\" mechanism."
1321              echo              echo
1322              usage              usage
1323              ;;              ;;
1324            
1325          -rootdir | --rootdir | -rd | --rd)          -rootdir | --rootdir | -rd | --rd)
1326              ac_prev=ROOTDIR ;;              ac_prev=ROOTDIR ;;
1327          -rootdir=* | --rootdir=* | -rd=* | --rd=*)          -rootdir=* | --rootdir=* | -rd=* | --rd=*)
1328              ROOTDIR=$ac_optarg ;;              ROOTDIR=$ac_optarg ;;
1329            
1330          -mods | --mods | -mo | --mo)          -mods | --mods | -mo | --mo)
1331              ac_prev=MODS ;;              ac_prev=MODS ;;
1332          -mods=* | --mods=* | -mo=* | --mo=*)          -mods=* | --mods=* | -mo=* | --mo=*)
1333              MODS=$ac_optarg ;;              MODS=$ac_optarg ;;
1334            
1335          -disable | --disable)          -disable | --disable)
1336              ac_prev=DISABLE ;;              ac_prev=DISABLE ;;
1337          -disable=* | --disable=*)          -disable=* | --disable=*)
1338              DISABLE=$ac_optarg ;;              DISABLE=$ac_optarg ;;
1339            
1340          -enable | --enable)          -enable | --enable)
1341              ac_prev=ENABLE ;;              ac_prev=ENABLE ;;
1342          -enable=* | --enable=*)          -enable=* | --enable=*)
1343              ENABLE=$ac_optarg ;;              ENABLE=$ac_optarg ;;
1344            
1345          -standarddirs | --standarddirs)          -standarddirs | --standarddirs)
1346              ac_prev=STANDARDDIRS ;;              ac_prev=STANDARDDIRS ;;
1347          -standarddirs=* | --standarddirs=*)          -standarddirs=* | --standarddirs=*)
# Line 1012  for ac_option in "$@" ; do Line 1351  for ac_option in "$@" ; do
1351  #               ac_prev=cpp ;;  #               ac_prev=cpp ;;
1352  #           -cpp=* | --cpp=*)  #           -cpp=* | --cpp=*)
1353  #               CPP=$ac_optarg ;;  #               CPP=$ac_optarg ;;
1354            
1355          -cc | --cc)          -cc | --cc)
1356              ac_prev=CC ;;              ac_prev=CC ;;
1357          -cc=* | --cc=*)          -cc=* | --cc=*)
1358              CC=$ac_optarg ;;              CC=$ac_optarg ;;
1359            
1360          -fortran | --fortran | -fc | --fc)          -fortran | --fortran | -fc | --fc)
1361              ac_prev=FC ;;              ac_prev=FC ;;
1362          -fc=* | --fc=*)          -fc=* | --fc=*)
1363              FC=$ac_optarg ;;              FC=$ac_optarg ;;
1364            
1365          -fs | --fs)          -fs | --fs)
1366              ac_prev=FS ;;              ac_prev=FS ;;
1367          -fs=* | --fs=*)          -fs=* | --fs=*)
1368              FS=$ac_optarg ;;              FS=$ac_optarg ;;
1369            
1370          -fs90 | --fs90)          -fs90 | --fs90)
1371              ac_prev=FS90 ;;              ac_prev=FS90 ;;
1372          -fs90=* | --fs90=*)          -fs90=* | --fs90=*)
1373              FS90=$ac_optarg ;;              FS90=$ac_optarg ;;
1374            
1375            -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4 )
1376                USE_R4=true ;;
1377    
1378          -ieee | --ieee)          -ieee | --ieee)
1379              IEEE=true ;;              IEEE=true ;;
1380          -noieee | --noieee)          -noieee | --noieee)
1381              IEEE= ;;              echo "Warning: ignore option '$ac_option' (default is already without '-ieee')" ;;
1382            -devel | --devel)
1383                IEEE=true ; DEVEL=true ;;
1384            -gsl | --gsl)
1385                GSL=true ;;
1386    
1387            -ts | --ts)
1388                TS=true ;;
1389            -papis | --papis)
1390                PAPIS=true ;;
1391            -pcls | --pcls)
1392                PCLS=true ;;
1393            -foolad | --foolad)
1394                FOOLAD=true ;;
1395            -papi | --papi)
1396                PAPI=true ;;
1397            -pcl | --pcl)
1398                PCL=true ;;
1399            -hpmt | --hpmt)
1400                HPMT=true ;;
1401    
1402          -mpi | --mpi)          -mpi | --mpi)
1403              MPI=true ;;              MPI=true ;;
1404          -mpi=* | --mpi=*)          -mpi=* | --mpi=*)
1405              MPIPATH=$ac_optarg              MPIPATH=$ac_optarg
1406              MPI=true ;;              MPI=true ;;
1407            
1408  #       -jam | --jam)          -omp | --omp)
1409  #           JAM=1 ;;              OMP=true ;;
1410  #       -nojam | --nojam)          -omp=* | --omp=*)
1411  #           JAM=0 ;;              OMPFLAG=$ac_optarg
1412                        OMP=true ;;
1413    
1414          -ds | --ds)          -ds | --ds)
1415              DUMPSTATE=t ;;              DUMPSTATE=t ;;
1416            
1417            -extra_flag | --extra_flag)
1418                ac_prev=FEXTRAFLAGS ;;
1419            -extra_flag=* | --extra_flag=*)
1420                FEXTRAFLAGS=$ac_optarg ;;
1421    
1422          -taf_extra | --taf_extra)          -taf_extra | --taf_extra)
1423              ac_prev=TAF_EXTRA ;;              ac_prev=TAF_EXTRA ;;
1424          -taf_extra=* | --taf_extra=*)          -taf_extra=* | --taf_extra=*)
# Line 1062  for ac_option in "$@" ; do Line 1429  for ac_option in "$@" ; do
1429          -tamc_extra=* | --tamc_extra=*)          -tamc_extra=* | --tamc_extra=*)
1430              TAMC_EXTRA=$ac_optarg ;;              TAMC_EXTRA=$ac_optarg ;;
1431    
1432            -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1433                IGNORE_TIME="-DIGNORE_TIME" ;;
1434    
1435            -es | --es | -embed-source | --embed-source)
1436                EMBED_SRC=t ;;
1437    
1438          -*)          -*)
1439              echo "Error: unrecognized option: "$ac_option              echo "Error: unrecognized option: "$ac_option
1440              usage              usage
1441              ;;              ;;
1442            
1443          *)          *)
1444              echo "Error: unrecognized argument: "$ac_option              echo "Error: unrecognized argument: "$ac_option
1445              usage              usage
1446              ;;              ;;
1447            
1448      esac      esac
1449        
1450  done  done
1451    
1452    printf "  getting local config information:  "
1453    if test -f $gm_local ; then
1454        echo "using $gm_local"
1455        . $gm_local
1456    else
1457        echo "none found"
1458    fi
1459    
1460  if test -f ./.genmakerc ; then  if test -f ./.genmakerc ; then
1461      echo      echo
1462      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
1463      echo "  file.  This file format is no longer supported.  Please see:"      echo "  file.  This file format is no longer supported.  For directions on"
1464      echo      echo "  how to setup and use the new \"genmake2\" script, please see:"
1465      echo "    http://mitgcm.org/devel_HOWTO/"      echo "    http://mitgcm.org/public/devel_HOWTO/"
1466        echo "  and send an email to MITgcm-support@mitgcm.org if you need help."
1467        echo "WARNING: ignore \"./.genmakerc\" and continue."
1468      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  
1469  fi  fi
1470    
1471  #  Find the MITgcm ${ROOTDIR}  #  Find the MITgcm ${ROOTDIR}
1472  if test "x${ROOTDIR}" = x ; then  if test "x${ROOTDIR}" = x ; then
1473      tmp=`echo $PWD | sed -e 's/\// /g' | awk '{print $NR}'`      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1474      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
1475          ROOTDIR=".."          ROOTDIR=".."
1476      else      else
1477          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1478              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
1479                  ROOTDIR=$d                  ROOTDIR=$d
1480                  printf "Warning:  ROOTDIR was not specified but there appears to be"                  printf "Warning: ROOTDIR was not specified ;"
1481                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."                  echo " try using a local copy of MITgcm found at \"$ROOTDIR\""
1482                  break                  break
1483              fi              fi
1484          done          done
# Line 1115  if test ! -d ${ROOTDIR} ; then Line 1495  if test ! -d ${ROOTDIR} ; then
1495      exit 1      exit 1
1496  fi  fi
1497    
1498  #  Find the MITgcm ${THISVER}  #  Find the MITgcm ${THISVER}
1499  if test -f "${ROOTDIR}/doc/tag-index" ; then  version_file="${ROOTDIR}/doc/tag-index"
1500      THISVER=`grep checkpoint ${ROOTDIR}/doc/tag-index | head -1`  if test -f $version_file ; then
1501        THISVER=`$AWK '/^checkpoint/{print $1; exit}' $version_file`
1502    #-  remove ./BUILD_INFO.h file if older than version_file
1503        if test -f ./BUILD_INFO.h -a ./BUILD_INFO.h -ot $version_file ; then
1504            echo "  remove ./BUILD_INFO.h (older than ${version_file})"
1505            rm -f ./BUILD_INFO.h
1506        fi
1507    fi
1508    
1509    if test "x$MAKEFILE" = x ; then
1510        MAKEFILE="Makefile"
1511  fi  fi
1512    
1513  echo "  getting OPTFILE information:  "  echo "  getting OPTFILE information:"
1514  if test "x${OPTFILE}" = x ; then  if test "x${OPTFILE}" = x ; then
1515      if test "x$MITGCM_OF" = x ; then      if test "x$MITGCM_OF" = x ; then
1516          echo "Warning: no OPTFILE specified so we'll look for possible settings"          echo "Warning: no OPTFILE specified so we'll look for possible settings"
1517          printf "\n===  Searching for possible settings for OPTFILE  ===\n"          printf "\n===  Searching for possible settings for OPTFILE  ===\n"
1518          find_possible_configs          find_possible_optfile
1519      else      else
1520          OPTFILE=$MITGCM_OF          OPTFILE=$MITGCM_OF
1521      fi      fi
# Line 1140  if test "x$OPTFILE" != xNONE ; then Line 1530  if test "x$OPTFILE" != xNONE ; then
1530              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1531              exit 1              exit 1
1532          fi          fi
1533          if test "x$DUMPSTATE" != xf ; then          if test "x$DUMPSTATE" = xt ; then
1534              cp -f $OPTFILE "genmake_optfile"              cp -f $OPTFILE "genmake_optfile"
1535          fi          fi
1536      else      else
# Line 1149  if test "x$OPTFILE" != xNONE ; then Line 1539  if test "x$OPTFILE" != xNONE ; then
1539      fi      fi
1540  fi  fi
1541    
1542  #  Check for broken systems that cannot correctly distinguish *.F and *.f files  echo "  getting AD_OPTFILE information:"
 # check_for_broken_Ff  
   
 echo "  getting AD_OPTFILE information:  "  
1543  if test "x${AD_OPTFILE}" = x ; then  if test "x${AD_OPTFILE}" = x ; then
1544      if test "x$MITGCM_AD_OF" = x ; then      if test "x$MITGCM_AD_OF" = x ; then
1545          AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default          AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
# Line 1170  if test "x${AD_OPTFILE}" != xNONE ; then Line 1557  if test "x${AD_OPTFILE}" != xNONE ; then
1557              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1558              exit 1              exit 1
1559          fi          fi
1560          if test "x$DUMPSTATE" != xf ; then          if test "x$DUMPSTATE" = xt ; then
1561              cp -f $AD_OPTFILE "genmake_ad_optfile"              cp -f $AD_OPTFILE "genmake_ad_optfile"
1562          fi          fi
1563      else      else
# Line 1179  if test "x${AD_OPTFILE}" != xNONE ; then Line 1566  if test "x${AD_OPTFILE}" != xNONE ; then
1566      fi      fi
1567  fi  fi
1568    
1569    #====================================================================
1570    #  Set default values if not set by the optfile
1571    #
1572  #  Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined.  If not,  #  Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
1573  #  either set defaults or complain and abort!  #  either set defaults or complain and abort!
1574  if test ! "x$BASH" = x ; then  if test ! "x$BASH" = x ; then
# Line 1195  Error: no Fortran compiler: please speci Line 1585  Error: no Fortran compiler: please speci
1585  EOF  EOF
1586      exit 1      exit 1
1587  fi  fi
1588    if test "x$GET_FC_VERSION" != x ; then
1589      echo "Get compiler version using: $FC $GET_FC_VERSION" >> $LOGFILE
1590      ff=`echo $FC | sed 's/ .*//'` ; xx=`echo $ff | sed 's/^./& /' | sed 's/ .*//'`
1591      if test $xx != '/' ; then which $ff >> $LOGFILE ; fi
1592      $FC $GET_FC_VERSION > genmake_fc_vers1 2> genmake_fc_vers2
1593      if test -s genmake_fc_vers1 ; then
1594        cat genmake_fc_vers1 >> $LOGFILE
1595      else
1596        cat genmake_fc_vers2 >> $LOGFILE
1597      fi
1598      echo "<-- compiler version ----" >> $LOGFILE
1599      rm -f genmake_fc_vers1 genmake_fc_vers2
1600    fi
1601    
1602  if test "x$CC" = x ; then  if test "x$CC" = x ; then
1603      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  
1604  fi  fi
1605    
1606  if test "x$LINK" = x ; then  if test "x$LINK" = x ; then
1607      LINK=$FC      LINK=$FC
1608  fi  fi
# Line 1212  if test "x$MAKE" = x ; then Line 1610  if test "x$MAKE" = x ; then
1610      MAKE="make"      MAKE="make"
1611  fi  fi
1612  if test "x$CPP" = x ; then  if test "x$CPP" = x ; then
1613      CPP=cpp      CPP="cpp -traditional -P"
1614  fi  fi
1615  #EH3 === UGLY ===  #EH3 === UGLY ===
1616  #  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 1239  EOF Line 1637  EOF
1637  else  else
1638      rm -f test_cpp      rm -f test_cpp
1639  fi  fi
1640    
1641  look_for_makedepend  look_for_makedepend
1642    
1643    #  Check that soft-link command is set and usable
1644  if test "x$LN" = x ; then  if test "x$LN" = x ; then
1645      LN="ln -s"      LN="ln -s"
1646  fi  fi
# Line 1249  RETVAL=$? Line 1650  RETVAL=$?
1650  if test "x$RETVAL" != x0 ; then  if test "x$RETVAL" != x0 ; then
1651      cat <<EOF 1>&2      cat <<EOF 1>&2
1652    
1653  Error: The command "ln -s" failed -- please specify a working soft-link  Error: The command "$LN" failed -- please specify a working soft-link
1654    command in the optfile.    command in the optfile.
1655    
1656  EOF  EOF
1657      exit 1      exit 1
1658  fi  fi
1659    test -L genmake_tlink > /dev/null 2>&1
1660    RETVAL=$?
1661    if test "x$RETVAL" = x0 ; then
1662        HAVE_TEST_L=t
1663    fi
1664  rm -f genmake_test_ln genmake_tlink  rm -f genmake_test_ln genmake_tlink
1665    
1666  #  Check for broken *.F/*.f handling and fix if possible  #  Check for broken *.F/*.f handling and fix if possible
# Line 1264  if test ! "x$MPI" = x ; then Line 1670  if test ! "x$MPI" = x ; then
1670        echo "  Turning on MPI cpp macros"        echo "  Turning on MPI cpp macros"
1671        DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"        DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
1672  fi  fi
1673    if test ! "x$OMP" = x ; then
1674          echo "  Add OMPFLAG and turn on OpenMP cpp macros"
1675          FFLAGS="$FFLAGS $OMPFLAG"
1676          F90FLAGS="$F90FLAGS $OMPFLAG"
1677          DEFINES="$DEFINES -DUSE_OMP_THREADING"
1678    fi
1679    
1680    if test ! "x$USE_R4" = x ; then
1681          echo "  Turning on LET_RS_BE_REAL4 cpp flag"
1682          DEFINES="$DEFINES -DLET_RS_BE_REAL4"
1683    fi
1684    
1685    if test ! "x$TS" = x ; then
1686          echo "  Turning on timing per timestep"
1687          if test ! "x$FOOLAD" = x ; then
1688                DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP"
1689          else
1690                DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1691          fi
1692          PACKAGES="$PACKAGES showflops"
1693    fi
1694    if test ! "x$PAPIS" = x ; then
1695          echo "  Turning on PAPI flop summary per timestep"
1696          echo "  Please make sure PAPIINC, PAPILIB are defined"
1697          if test ! "x$FOOLAD" = x ; then
1698                DEFINES="$DEFINES -DUSE_PAPI_FLOPS_SFP"
1699          else
1700                DEFINES="$DEFINES -DUSE_PAPI_FLOPS"
1701          fi
1702          INCLUDES="$INCLUDES $PAPIINC"
1703          LIBS="$LIBS $PAPILIB"
1704          PACKAGES="$PACKAGES showflops"
1705    fi
1706    if test ! "x$PCLS" = x ; then
1707          echo "  Turning on PCL counter summary per timestep"
1708          echo "  Please make sure PCLINC, PCLLIB are defined"
1709          if test ! "x$FOOLAD" = x ; then
1710                DEFINES="$DEFINES -DUSE_PCL_FLOPS_SFP"
1711          else
1712                DEFINES="$DEFINES -DUSE_PCL_FLOPS"
1713          fi
1714          INCLUDES="$INCLUDES $PCLINC"
1715          LIBS="$LIBS $PCLLIB"
1716          PACKAGES="$PACKAGES showflops"
1717    fi
1718    if test ! "x$PAPI" = x ; then
1719          if test ! "x$PAPIS" = x ; then
1720              echo "  PAPI performance analysis and flop summary per timestep cannot co-exist!"
1721              echo "  Sticking with PAPI flop summary per timestep!"
1722          else
1723              echo "  Turning on performance analysis with PAPI"
1724              echo "  Please make sure PAPIINC, PAPILIB are defined"
1725              DEFINES="$DEFINES -DUSE_PAPI"
1726              INCLUDES="$INCLUDES $PAPIINC"
1727              LIBS="$LIBS $PAPILIB"
1728          fi
1729    fi
1730    if test ! "x$PCL" = x ; then
1731          if test ! "x$PCLS" = x ; then
1732              echo "  PCL performance analysis and flop summary per timestep cannot co-exist!"
1733              echo "  Sticking with PCL flop summary per timestep!"
1734          else
1735              echo "  Turning on performance analysis with PCL"
1736              echo "  Please make sure PCLINC, PCLLIB are defined"
1737              DEFINES="$DEFINES -DUSE_PCL"
1738              INCLUDES="$INCLUDES $PCLINC"
1739              LIBS="$LIBS $PCLLIB"
1740          fi
1741    fi
1742    if test ! "x$HPMT" = x ; then
1743          if test ! "x$PAPI" = x ; then
1744              echo "  PAPI and the HPM Toolkit cannot co-exist!"
1745              echo "  Sticking with PAPI!"
1746          else
1747            if test ! "x$PCL" = x ; then
1748              echo "  PCL and the HPM Toolkit cannot co-exist!"
1749              echo "  Sticking with PCL!"
1750            else
1751              echo "  Turning on performance analysis with the HPM Toolkit"
1752              echo "  Please make sure HPMTINC, HPMTLIB are defined"
1753              DEFINES="$DEFINES -DUSE_LIBHPM"
1754              INCLUDES="$INCLUDES $HPMTINC"
1755              LIBS="$LIBS $HPMTLIB"
1756            fi
1757          fi
1758    fi
1759    if test ! "x$GSL" = x ; then
1760          echo "  Turning on use of GSL to control floating point calculations"
1761          echo "  Please make sure GSLINC, GSLLIB are defined"
1762          DEFINES="$DEFINES -DUSE_GSL_IEEE"
1763          INCLUDES="$INCLUDES $GSLINC"
1764          LIBS="$LIBS $GSLLIB"
1765    fi
1766    #- if USE_EXTENDED_SRC is set, add EXTENDED_SRC_FLAG to FFLAGS :
1767    if test ! "x$USE_EXTENDED_SRC" = x ; then
1768          FFLAGS="$FFLAGS $EXTENDED_SRC_FLAG"
1769          F90FIXEDFORMAT="$F90FIXEDFORMAT $EXTENDED_SRC_FLAG"
1770    fi
1771    
1772  printf "\n===  Checking system libraries  ===\n"  printf "\n===  Checking system libraries  ===\n"
1773  printf "  Do we have the system() command using $FC...  "  printf "  Do we have the system() command using $FC...  "
1774  cat > genmake_tcomp.f <<EOF  cat > genmake_tcomp.$FS <<EOF
1775        program hello        program hello
1776        call system('echo hi')        call system('echo hi')
1777        end        end
1778  EOF  EOF
1779  $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1  $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1780  RETVAL=$?  RETVAL=$?
1781  if test "x$RETVAL" = x0 ; then  if test "x$RETVAL" = x0 ; then
1782      HAVE_SYSTEM=t      HAVE_SYSTEM=t
# Line 1285  fi Line 1789  fi
1789  rm -f genmake_tcomp*  rm -f genmake_tcomp*
1790    
1791  printf "  Do we have the fdate() command using $FC...  "  printf "  Do we have the fdate() command using $FC...  "
1792  cat > genmake_tcomp.f <<EOF  cat > genmake_tcomp.$FS <<EOF
1793        program hello        program hello
1794        CHARACTER(128) string        CHARACTER*(128) string
1795        string = ' '        string = ' '
1796        call fdate( string )        call fdate( string )
1797        print *, string        print *, string
1798        end        end
1799  EOF  EOF
1800  $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1  $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1801  RETVAL=$?  RETVAL=$?
1802  if test "x$RETVAL" = x0 ; then  if test "x$RETVAL" = x0 ; then
1803      HAVE_FDATE=t      HAVE_FDATE=t
# Line 1306  fi Line 1810  fi
1810  rm -f genmake_tcomp*  rm -f genmake_tcomp*
1811    
1812  printf "  Do we have the etime() command using $FC...  "  printf "  Do we have the etime() command using $FC...  "
1813  cat > genmake_tcomp.f <<EOF  cat > genmake_tcomp.$FS <<EOF
1814        program hello        program hello
1815        REAL*4 ACTUAL, TARRAY(2)        REAL*4 ACTUAL, TARRAY(2)
1816        EXTERNAL ETIME        EXTERNAL ETIME
# Line 1315  cat > genmake_tcomp.f <<EOF Line 1819  cat > genmake_tcomp.f <<EOF
1819        print *, tarray        print *, tarray
1820        end        end
1821  EOF  EOF
1822  $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1  $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1823  RETVAL=$?  RETVAL=$?
1824  if test "x$RETVAL" = x0 ; then  if test "x$RETVAL" = x0 ; then
1825      HAVE_ETIME=t      HAVE_ETIME=t
# Line 1330  rm -f genmake_tcomp* Line 1834  rm -f genmake_tcomp*
1834  printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "  printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
1835  check_HAVE_CLOC  check_HAVE_CLOC
1836  if test "x$HAVE_CLOC" != x ; then  if test "x$HAVE_CLOC" != x ; then
1837        DEFINES="$DEFINES -DHAVE_CLOC"
1838        echo "yes"
1839    else
1840        echo "no"
1841        if test "x$EMBED_SRC" = xt ; then
1842            echo "    WARNING: you requested file embedding but it has"
1843            echo "      been disabled since C code cannot be called"
1844            EMBED_SRC=
1845        fi
1846    fi
1847    rm -f genmake_t*
1848    
1849    printf "  Can we unlimit the stack size using $FC...  "
1850    check_HAVE_SETRLSTK
1851    if test "x$HAVE_SETRLSTK" = xt ; then
1852        DEFINES="$DEFINES -DHAVE_SETRLSTK"
1853        echo "yes"
1854    else
1855        echo "no"
1856    fi
1857    rm -f genmake_t*
1858    
1859    printf "  Can we register a signal handler using $FC...  "
1860    check_HAVE_SIGREG
1861    if test "x$HAVE_SIGREG" = xt ; then
1862        DEFINES="$DEFINES -DHAVE_SIGREG"
1863      echo "yes"      echo "yes"
1864  else  else
1865      echo "no"      echo "no"
# Line 1339  rm -f genmake_t* Line 1869  rm -f genmake_t*
1869  printf "  Can we use stat() through C calls...  "  printf "  Can we use stat() through C calls...  "
1870  check_HAVE_STAT  check_HAVE_STAT
1871  if test "x$HAVE_STAT" != x ; then  if test "x$HAVE_STAT" != x ; then
1872        DEFINES="$DEFINES -DHAVE_STAT"
1873      echo "yes"      echo "yes"
1874  else  else
1875      echo "no"      echo "no"
# Line 1348  rm -f genmake_t* Line 1879  rm -f genmake_t*
1879  printf "  Can we create NetCDF-enabled binaries...  "  printf "  Can we create NetCDF-enabled binaries...  "
1880  check_netcdf_libs  check_netcdf_libs
1881  if test "x$HAVE_NETCDF" != x ; then  if test "x$HAVE_NETCDF" != x ; then
1882        DEFINES="$DEFINES -DHAVE_NETCDF"
1883        echo "yes"
1884    else
1885        echo "no"
1886    fi
1887    
1888    printf "  Can we create LAPACK-enabled binaries...  "
1889    check_lapack_libs
1890    if test "x$HAVE_LAPACK" != x ; then
1891        DEFINES="$DEFINES -DHAVE_LAPACK"
1892      echo "yes"      echo "yes"
1893  else  else
1894      echo "no"      echo "no"
1895  fi  fi
1896    DEFINES="$DEFINES $IGNORE_TIME"
1897    
1898    if test "x$EMBED_SRC" = xt ; then
1899        build_embed_encode
1900    fi
1901    if test "x$EMBED_SRC" = xt ; then
1902        ENABLE="$ENABLE embed_files"
1903    #   DEFINES="$DEFINES -DHAVE_EMBED_SRC"
1904    fi
1905    
1906  printf "\n===  Setting defaults  ===\n"  printf "\n===  Setting defaults  ===\n"
1907  printf "  Adding MODS directories:  "  printf "  Adding MODS directories: "
1908  for d in $MODS ; do  for d in $MODS ; do
1909      if test ! -d $d ; then      if test ! -d $d ; then
1910          echo          echo
1911          echo "Error: MODS directory \"$d\" not found!"          echo "Error: MODS directory \"$d\" not found!"
1912          exit 1          exit 1
1913      else      else
1914          printf " $d"          printf "$d "
1915          SOURCEDIRS="$SOURCEDIRS $d"          SOURCEDIRS="$SOURCEDIRS $d"
1916          INCLUDEDIRS="$INCLUDEDIRS $d"          INCLUDEDIRS="$INCLUDEDIRS $d"
1917      fi      fi
1918  done  done
1919  echo  echo
1920    
1921  if test "x$MAKEFILE" = x ; then  #if test "x${PLATFORM}" = x ; then
1922      MAKEFILE="Makefile"  #    PLATFORM=$p_PLATFORM
1923  fi  #fi
 if test "x${PLATFORM}" = x ; then  
     PLATFORM=$p_PLATFORM  
 fi  
1924    
1925  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
1926      tmp=`echo $PWD | sed -e 's/\// /g' | awk '{print $NR}'`      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1927      if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then      if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
1928          EXEDIR=../exe          EXEDIR=../exe
1929      else      else
# Line 1414  ERROR: neither of the two default script Line 1960  ERROR: neither of the two default script
1960      ${TOOLSDIR}/set64bitConst.sh      ${TOOLSDIR}/set64bitConst.sh
1961      ${TOOLSDIR}/set64bitConst.csh      ${TOOLSDIR}/set64bitConst.csh
1962    
1963    are working so please check paths or specify (with \$S64) a    are working so please check paths or specify (with \$S64) a
1964    working version of this script.    working version of this script.
1965    
1966  EOF  EOF
# Line 1426  THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSD Line 1972  THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSD
1972    
1973  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1974    
1975    #  Set Standard Code Directories:
1976    if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
1977        STANDARDDIRS="eesupp model"
1978    fi
1979    #  if model in Standard-Code-Dir, add eesupp (needed to compile model)
1980    echo " $STANDARDDIRS " | grep ' model ' > /dev/null 2>&1
1981    ckM=$?
1982    echo " $STANDARDDIRS " | grep ' eesupp ' > /dev/null 2>&1
1983    ckE=$?
1984    if test $ckM = 0 -a $ckE = 1 ; then
1985        STANDARDDIRS="$STANDARDDIRS eesupp"
1986    fi
1987    
1988  #  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
1989  #  generated from some template source files. We'll make them first so  #  generated from some template source files. We'll make them first so
1990  #  they appear as regular source code  #  they appear as regular source code
1991  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
1992      echo "  Making source files in eesupp from templates"      echo "  Making source files in eesupp from templates"
1993      ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1      ( cd $ROOTDIR"/eesupp/src/" && $MAKE clean_old && $MAKE \
1994        ) > make_eesupp.errors 2>&1
1995      RETVAL=$?      RETVAL=$?
1996      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
1997          rm -f make_eesupp.errors          rm -f make_eesupp.errors
# Line 1442  if test -r $ROOTDIR"/eesupp/src/Makefile Line 2002  if test -r $ROOTDIR"/eesupp/src/Makefile
2002      fi      fi
2003  fi  fi
2004    
2005  #same for exch2  #same for pkg/exch2 and pkg/regrid
2006  if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then  for pdir in exch2 regrid ; do
2007      echo "  Making source files in exch2 from  templates"      if test -r $ROOTDIR"/pkg/${pdir}/Makefile" ; then
2008      ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1          echo "  Making source files in pkg/${pdir} from templates"
2009      RETVAL=$?          ( cd $ROOTDIR"/pkg/"${pdir} && $MAKE clean_old && $MAKE \
2010      if test "x${RETVAL}" = x0 ; then          ) > make_${pdir}.errors 2>&1
2011          rm -f make_exch2.errors          RETVAL=$?
2012      else          if test "x${RETVAL}" = x0 ; then
2013          echo "Error: problem encountered while building source files in exch2:"              rm -f make_${pdir}.errors
2014          cat make_exch2.errors 1>&2          else
2015          exit 1              echo "Error: problem encountered while building source files in pkg/${pdir}:"
2016                cat make_${pdir}.errors 1>&2
2017                exit 1
2018            fi
2019      fi      fi
2020  fi  done
2021    
2022  printf "\n===  Determining package settings  ===\n"  printf "\n===  Determining package settings  ===\n"
2023  if  test "x${PDEPEND}" = x ; then  if  test "x${PKG_DEPEND}" = x ; then
2024      tmp=$ROOTDIR"/pkg/pkg_depend"      tmp=$ROOTDIR"/pkg/pkg_depend"
2025      if test -r $tmp ; then      if test -r $tmp ; then PKG_DEPEND=$tmp ; fi
2026          PDEPEND=$tmp  fi
2027      else  if  test "x${PKG_DEPEND}" = x ; then
2028          echo "Warning:  No package dependency information was specified."          echo "Warning:  No package dependency information was specified."
2029          echo "  Please check that ROOTDIR/pkg/pkg_depend exists."          echo "  Please check that ROOTDIR/pkg/pkg_depend exists."
     fi  
2030  else  else
2031      if test ! -r ${PDEPEND} ; then      if test ! -r ${PKG_DEPEND} ; then
2032          echo "Error:  can't read package dependency info from PDEPEND=\"$PDEPEND\""          echo "Error:  can't read package dependency info from PKG_DEPEND=\"$PKG_DEPEND\""
2033          exit 1          exit 1
2034      fi      fi
2035        echo "  getting package dependency info from  $PKG_DEPEND"
2036    #  Strip the comments and then convert the dependency file into arrays: PNAME, DNAME
2037        get_pdepend_list $PKG_DEPEND
2038  fi  fi
2039  echo "  getting package dependency info from  $PDEPEND"  
2040  #  Strip the comments and then convert the dependency file into  # A default package groups file "$ROOTDIR/pkg/pkg_groups" is provided
2041  #  two arrays: PNAME, DNAME  #  to define the "default_pkg_list" and package groups (for convenience, one
2042  cat $PDEPEND | sed -e 's/#.*$//g' \  #  can specify a group of packages using names like "ocean" and "atmosphere").
2043      | $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
2044      > ./.pd_tmp      tmp=$ROOTDIR"/pkg/pkg_groups"
2045  RETVAL=$?      if test -r $tmp ; then PKG_GROUPS=$tmp ; fi
2046  if test ! "x${RETVAL}" = x0 ; then  fi
2047      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""  if test "x${PKG_GROUPS}" = x ; then
2048      exit 1          echo "Warning:  No package groups information was specified."
2049            echo "  Please check that ROOTDIR/pkg/pkg_groups exists."
2050    else
2051        if test ! -r ${PKG_GROUPS} ; then
2052            echo "Error:  can't read package groups info from PKG_GROUPS=\"$PKG_GROUPS\""
2053            exit 1
2054        fi
2055        echo "  getting package groups info from      $PKG_GROUPS"
2056  fi  fi
 . ./.pd_tmp  
 rm -f ./.pd_tmp  
2057    
2058  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"  #  Search for packages to compile.
2059  #  file should eventually be added so that, for convenience, one can  echo "  checking list of packages to compile:"
2060  #  specify groups of packages using names like "ocean" and "atmosphere".  PKG_LIST=
2061  echo "  checking default package list:  "  if test "x${PKG_LIST}" = x ; then
 if test "x${PDEFAULT}" = x ; then  
2062      for i in "." $MODS ; do      for i in "." $MODS ; do
2063          if test -r $i"/packages.conf" ; then          if test -r $i"/packages.conf" ; then
2064                  PDEFAULT=$i"/packages.conf"                  PKG_LIST=$i"/packages.conf"
2065                  break                  break
2066          fi          fi
2067      done      done
2068  fi  fi
2069  if test "x${PDEFAULT}" = x ; then  if test "x${PKG_LIST}" = x ; then
2070      PDEFAULT="$ROOTDIR/pkg/pkg_default"      pkg_list='default_pkg_list'
2071  fi      if test "x${PKG_GROUPS}" = x ; then
2072  if test "x${PDEFAULT}" = xNONE ; then          echo "Error:  need package groups info to expand pkg_list=\"$pkg_list\""
2073      echo "    default packages file disabled"          exit 1
2074        fi
2075  else  else
2076      if test ! -r $PDEFAULT ; then      if test ! -r $PKG_LIST ; then
2077          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""          echo "Error:  can't read package list from PKG_LIST=\"$PKG_LIST\""
2078            exit 1
2079      else      else
2080          echo "    using PDEFAULT=\"$PDEFAULT\""          echo "    using PKG_LIST=\"$PKG_LIST\""
2081          #  Strip the comments and add all the names          #  Strip the comments and add all the names
2082          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}'`
2083          RETVAL=$?          RETVAL=$?
2084          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
2085              printf "Error: can't parse default package list "              printf "Error: can't parse package list "
2086              echo "-- please check PDEFAULT=\"$PDEFAULT\""              echo "-- please check PKG_LIST=\"$PKG_LIST\""
2087              exit 1              exit 1
2088          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"  
2089      fi      fi
2090  fi  fi
2091    for i in $pkg_list ; do
2092        PACKAGES="$PACKAGES $i"
2093    done
2094    echo     "    before group expansion packages are:$PACKAGES"
2095    if test "x${PKG_GROUPS}" != x ; then
2096        RET=1
2097        while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
2098        echo "    after group expansion packages are: $PACKAGES"
2099    fi
2100    
2101  echo "  applying DISABLE settings"  echo "  applying DISABLE settings"
2102    echo "" > ./.tmp_pack
2103  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2104      echo $i >> ./.tmp_pack      echo $i >> ./.tmp_pack
2105  done  done
# Line 1553  PACKAGES="$PACKAGES $ENABLE" Line 2127  PACKAGES="$PACKAGES $ENABLE"
2127  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2128      j=`echo $i | sed 's/[-+]//'`      j=`echo $i | sed 's/[-+]//'`
2129      if test ! -d "$ROOTDIR/pkg/$j" ; then      if test ! -d "$ROOTDIR/pkg/$j" ; then
2130          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""          echo "Error: dir '$ROOTDIR/pkg/$i' missing for package '$i'"
2131          exit 1          exit 1
2132      fi      fi
2133      echo $i >> ./.tmp_pack      echo $i >> ./.tmp_pack
2134  done  done
# Line 1563  for i in `grep -v "-" ./.tmp_pack | sort Line 2137  for i in `grep -v "-" ./.tmp_pack | sort
2137      PACKAGES="$PACKAGES $i"      PACKAGES="$PACKAGES $i"
2138  done  done
2139  rm -f ./.tmp_pack  rm -f ./.tmp_pack
2140  echo "    packages are:  $PACKAGES"  echo "    packages are: $PACKAGES"
2141    
2142  #  Check availability of NetCDF and then either build the MNC template  #  Check for package MNC: if NetCDF is available, then build the MNC
2143  #  files or delete mnc from the list of available packages.  #  template files ; otherwise, delete mnc from the list of packages.
2144  echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1  echo " $PACKAGES " | grep ' mnc ' > /dev/null 2>&1
2145  RETVAL=$?  mnc_in=$?
2146  if test "x$RETVAL" = x0 ; then  if test "x$HAVE_NETCDF" != xt ; then
2147      if test "x$HAVE_NETCDF" != xt ; then      if test "x$mnc_in" = x0 ; then
2148          cat <<EOF          cat <<EOF
   
2149  *********************************************************************  *********************************************************************
2150  WARNING: the "mnc" package was enabled but tests failed to compile  WARNING: the "mnc" package was enabled but tests failed to compile
2151    NetCDF applications.  Please check that:    NetCDF applications.  Please check that:
2152    
2153    1) NetCDF is correctly installed for this compiler and    1) NetCDF is correctly installed for this compiler and
2154    2) the LIBS variable (within the "optfile") specifies the correct    2) the LIBS variable (within the "optfile") specifies the correct
2155         NetCDF library to link against.         NetCDF library to link against.
2156    
2157    Due to this failure, the "mnc" package is now DISABLED.    Due to this failure, the "mnc" package is now DISABLED.
2158  *********************************************************************  *********************************************************************
   
2159  EOF  EOF
2160          PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`          PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
2161          DISABLE="$DISABLE mnc"          DISABLE="$DISABLE mnc"
2162      else      else
2163          ( cd $ROOTDIR"/pkg/mnc" && $MAKE templates ) > make_mnc.errors 2>&1      #  this prevent to add mnc (due to pdepend rules) if not available
2164          RETVAL=$?          DISABLE="$DISABLE mnc"
2165          if test "x${RETVAL}" = x0 ; then      fi
2166              rm -f make_mnc.errors  else
2167          else      # we have NetCDF, we try to build MNC template files
2168              echo "Error: problem encountered while building source files in pkg/mnc:"      ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
2169              cat make_mnc.errors 1>&2      RETVAL=$?
2170        if test "x${RETVAL}" = x0 ; then
2171            rm -f make_mnc.errors
2172        else
2173            echo "Error: problem encountered while building source files in pkg/mnc:"
2174            cat make_mnc.errors 1>&2
2175            if test "x$mnc_in" = x0 ; then
2176              exit 1              exit 1
2177            else
2178                DISABLE="$DISABLE mnc"
2179          fi          fi
2180      fi      fi
2181  fi  fi
2182    
2183  echo "  applying package dependency rules"  #  Check for package PROFILES: if NetCDF is not available,
2184  ck=  #  then delete profiles from the list of available packages.
2185  while test "x$ck" != xtt ; do  if test "x$HAVE_NETCDF" != xt ; then
2186        echo " $PACKAGES " | grep ' profiles ' > /dev/null 2>&1
2187        RETVAL=$?
2188        if test "x$RETVAL" = x0 ; then
2189            cat <<EOF
2190    *********************************************************************
2191    WARNING: the "profiles" package was enabled but tests failed to
2192      compile NetCDF applications.  Please check that:
2193    
2194      1) NetCDF is correctly installed for this compiler and
2195      2) the LIBS variable (within the "optfile") specifies the correct
2196           NetCDF library to link against.
2197    
2198      Due to this failure, the "profiles" package is now DISABLED.
2199    *********************************************************************
2200    EOF
2201            PACKAGES=`echo $PACKAGES | sed -e 's/profiles//g'`
2202            DISABLE="$DISABLE profiles"
2203        else
2204        #  this prevent to add profiles (due to pdepend rules) if not available
2205            DISABLE="$DISABLE profiles"
2206        fi
2207    fi
2208    
2209    #  Check for package RADTRANS: if LAPACK is not available,
2210    #  then issue a warning that the direct radtrans solver is not available.
2211    if test "x$HAVE_LAPACK" != xt ; then
2212        echo " $PACKAGES " | grep ' radtrans ' > /dev/null 2>&1
2213        RETVAL=$?
2214        if test "x$RETVAL" = x0 ; then
2215            cat <<EOF
2216    *********************************************************************
2217    WARNING: the "radtrans" package was enabled but tests failed to
2218      compile LAPACK applications.  This means that the direct radtrans
2219      solver is not available and compilation will fail if it is enabled.
2220      If you want to use the direct solver, please check that:
2221    
2222      1) LAPACK is correctly installed for this compiler and
2223      2) the LIBS variable (within the "optfile") specifies the correct
2224         LAPACK library to link against.
2225    *********************************************************************
2226    EOF
2227        fi
2228    fi
2229    
2230    if  test "x${PKG_DEPEND}" != x ; then
2231      echo "  applying package dependency rules"
2232      ck=
2233      while test "x$ck" != xtt ; do
2234      i=0      i=0
2235      # rtot=${#PNAME[@]}      # rtot=${#PNAME[@]}
2236      rtot=$nname      rtot=$nname
2237      while test $i -lt $rtot ; do      while test $i -le $rtot ; do
2238    
2239          #  Is $pname in the current $PACKAGES list?          #  Is $pname in the current $PACKAGES list?
2240          #  pname=${PNAME[$i]}          #  pname=${PNAME[$i]}
# Line 1618  while test "x$ck" != xtt ; do Line 2246  while test "x$ck" != xtt ; do
2246                  pin="t"                  pin="t"
2247              fi              fi
2248          done          done
2249            #  or in the current $STANDARDDIRS list?
2250            for p in $STANDARDDIRS ; do
2251                if test "x$p" = "x$pname" ; then pin="t" ; fi
2252            done
2253    
2254          #  Is the DNAME entry a (+) or (-) rule ?          #  Is the DNAME entry a (+) or (-) rule ?
2255          tmp="dname=\"\$DNAME_$i\""          tmp="dname=\"\$DNAME_$i\""
# Line 1640  while test "x$ck" != xtt ; do Line 2272  while test "x$ck" != xtt ; do
2272    
2273          #  Do we need to add $dname according to the dependency rules?          #  Do we need to add $dname according to the dependency rules?
2274          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
2275                #echo "   " $pname ": need to add :" $dname
2276              in_dis="f"              in_dis="f"
2277              for dis in $DISABLE ; do              for dis in $DISABLE ; do
2278                  if test "x$dis" = "x$dname" ; then                  if test "x$dis" = "x$dname" ; then
# Line 1660  while test "x$ck" != xtt ; do Line 2293  while test "x$ck" != xtt ; do
2293          #  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?
2294          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
2295              echo "Error: can't satisfy package dependencies:"              echo "Error: can't satisfy package dependencies:"
2296              echo "  \"$pname\" was requested but is disallowed by"              echo "  \"$pname\" was requested but is disallowed by"
2297              echo "  the dependency rules for \"$dname\""              echo "  the dependency rules for \"$dname\""
2298              exit 1              exit 1
2299          fi          fi
2300          i=`echo "$i + 1" | bc -l`          i=`echo "$i + 1" | bc -l`
2301          #i=$(( $i + 1 ))          #i=$(( $i + 1 ))
2302      done      done
2303      ck=$ck"t"      ck=$ck"t"
2304  done    done
2305  echo "    packages are:  $PACKAGES"    echo "    packages are: $PACKAGES"
2306    fi
2307  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2308      adr="$ROOTDIR/pkg/$i"      adr="$ROOTDIR/pkg/$i"
2309      if test -d $adr ; then      if test -d $adr ; then
# Line 1686  done Line 2320  done
2320    
2321  # Create a list of #define and #undef to enable/disable packages  # Create a list of #define and #undef to enable/disable packages
2322  PACKAGES_DOT_H=PACKAGES_CONFIG.h  PACKAGES_DOT_H=PACKAGES_CONFIG.h
2323  #  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
2324  #  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
2325  #  file would eventually be split up so that all package-related #define  #  file would eventually be split up so that all package-related #define
2326  #  statements could be separated and handled only by genmake.  #  statements could be separated and handled only by genmake.
2327  names=`ls -1 "$ROOTDIR/pkg"`  names=`ls -1 "$ROOTDIR/pkg"`
# Line 1703  for n in $names ; do Line 2337  for n in $names ; do
2337              fi              fi
2338          done          done
2339          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
2340              undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2341              DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"              DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
2342          fi          fi
2343      fi      fi
2344  done  done
2345  ENABLED_PACKAGES=  ENABLED_PACKAGES=
2346  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2347      def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`      def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2348      ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"      ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
2349  #eh3 DEFINES="$DEFINES -D$def"  #eh3 DEFINES="$DEFINES -D$def"
2350    
2351  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
2352      case $i in      case $i in
2353          aim_v23)          aim_v23)
2354              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
2355              echo "Warning: ALLOW_AIM is set to enable aim_v23."              echo "Warning: ALLOW_AIM is set to enable aim_v23."
2356              ;;              ;;
2357      esac      esac
# Line 1725  for i in $PACKAGES ; do Line 2359  for i in $PACKAGES ; do
2359    
2360  done  done
2361    
2362  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS='$STANDARDDIRS'"
2363  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
 if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then  
     STANDARDDIRS="eesupp model"  
 fi  
2364  if test "x$STANDARDDIRS" != x ; then  if test "x$STANDARDDIRS" != x ; then
2365      for d in $STANDARDDIRS ; do      for d in $STANDARDDIRS ; do
2366          adr="$ROOTDIR/$d/src"          adr="$ROOTDIR/$d/src"
# Line 1762  for i in $spaths ; do Line 2393  for i in $spaths ; do
2393      if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then      if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
2394          echo "    found CPP_OPTIONS=\"$try\""          echo "    found CPP_OPTIONS=\"$try\""
2395          CPP_OPTIONS="$try"          CPP_OPTIONS="$try"
2396          # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h          # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
2397          for n in $names ; do          for n in $names ; do
2398              test_for_package_in_cpp_options $CPP_OPTIONS $n              test_for_package_in_cpp_options $CPP_OPTIONS $n
2399          done          done
2400      fi      fi
2401      try="$i/CPP_EEOPTIONS.h"      try="$i/CPP_EEOPTIONS.h"
2402      if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then      if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
2403          echo "    found CPP_EEOPTIONS=\"$try\""          echo "    found CPP_EEOPTIONS=\"$try\""
2404          # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h          # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
2405  #**** not yet enabled ****  #**** not yet enabled ****
2406  #        test_for_mpi_in_cpp_eeoptions $try  #        test_for_mpi_in_cpp_eeoptions $try
2407  #**** not yet enabled ****  #**** not yet enabled ****
# Line 1784  fi Line 2415  fi
2415    
2416  #  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
2417  #  compiler.  #  compiler.
2418  if test -f ./ad_files ; then  if test -f ./adSrcFiles.tmp ; then
2419      rm -f ./ad_files      rm -f ./adSrcFiles.tmp
2420  fi  fi
2421  echo "  Creating the list of files for the adjoint compiler."  echo "  Creating the list of files for the adjoint compiler."
2422    touch adSrcFiles.tmp
2423  for i in $SOURCEDIRS ; do  for i in $SOURCEDIRS ; do
2424      list_files=`( cd $i && ls -1 *.list 2>/dev/null )`      list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
2425      for j in $list_files ; do      for j in $list_files ; do
2426          cat $i/$j >> ad_files          cat $i/$j >> adSrcFiles.tmp
2427      done      done
2428  done  done
2429    if test ! "x"$FS = "x.f" ; then
2430        cat adSrcFiles.tmp | sed -e "s/\.f/.$FS/g" > adSrcFiles.tmp_f
2431        mv -f adSrcFiles.tmp_f adSrcFiles.tmp
2432    fi
2433    
2434  echo  echo
2435  echo "===  Creating the Makefile  ==="  echo "===  Creating the Makefile  ==="
# Line 1805  for i in $INCLUDEDIRS ; do Line 2440  for i in $INCLUDEDIRS ; do
2440      fi      fi
2441  done  done
2442    
2443    if test ! "x$DIVA" = x ; then
2444        echo "  Creating the pseudo-MPI include directory"
2445        INCLUDES="-I./mpi_headers $INCLUDES"
2446        rm -rf ./mpi_headers
2447        mkdir -p ./mpi_headers
2448    
2449        if test "x$MPIINCLUDEDIR" = x ; then
2450            if test "x$MPIHOME" = x ; then
2451                MPIHOME='/usr'
2452            fi
2453            MPIINCLUDEDIR='$MPIHOME/include'
2454        fi
2455    
2456        if test -r $MPIINCLUDEDIR/mpif.h ; then
2457            for i in $MPI_HEADER_FILES; do
2458                cp -p $MPIINCLUDEDIR/$i ./mpi_headers
2459            done
2460    
2461            perl -i -pe 's/MPI_DISPLACEMENT_CURRENT=-1_8/MPI_DISPLACEMENT_CURRENT=-1/g' mpi_headers/mpif.h
2462        else
2463            echo " We cannot create a copy of mpif.h!"
2464    #       exit -1
2465        fi
2466    fi
2467    
2468  echo "  Determining the list of source and include files"  echo "  Determining the list of source and include files"
2469  rm -rf .links.tmp  rm -rf .links.tmp
2470  mkdir .links.tmp  mkdir .links.tmp
2471    touch .links.tmp/foo
2472    if test ! -r ".links.tmp/foo" ; then
2473        echo
2474        echo "ERROR : something is wrong with your directory permissions or"
2475        echo "   your user file-creation mask (\"umask\") since creating a"
2476        echo "   sub-dir, touch-ing a file within it, and then reading it is"
2477        echo "   not working.  Please try setting your umask to something"
2478        echo "   sane such as:"
2479        echo
2480        echo "      umask 0002"
2481        echo
2482        echo "   and please verify that you have the proper permissions for"
2483        echo "   creating sub-directories and then reading files created"
2484        echo "   within them."
2485        echo
2486        exit 1
2487    fi
2488    rm -f .links.tmp/foo
2489    
2490    if test "x$OPENAD" != x ; then
2491        OAD_DONT_COMPILE="/dev/null"
2492        OAD_DONT_TRANSFORM="/dev/null"
2493        OAD_KEEP_ORIGINAL="/dev/null"
2494        OAD_CB2M_FILES="/dev/null"
2495        echo "  looking for dontCompile file:  "
2496        for i in "." $MODS ; do
2497            if test -r $i"/dontCompile" ; then
2498                OAD_DONT_COMPILE=$i"/dontCompile"
2499                echo "     found $OAD_DONT_COMPILE"
2500                break
2501            fi
2502        done
2503        echo "  looking for dontTransform file:  "
2504        for i in "." $MODS ; do
2505            if test -r $i"/dontTransform" ; then
2506                OAD_DONT_TRANSFORM=$i"/dontTransform"
2507                echo "     found $OAD_DONT_TRANSFORM"
2508                break
2509            fi
2510        done
2511        echo "  looking for keepOriginal file:  "
2512        for i in "." $MODS ; do
2513            if test -r $i"/keepOriginal" ; then
2514                OAD_KEEP_ORIGINAL=$i"/keepOriginal"
2515                echo "     found $OAD_KEEP_ORIGINAL"
2516                break
2517            fi
2518        done
2519        echo "  looking for cb2mFiles:  "
2520        for i in "." $MODS ; do
2521            if test -r $i"/cb2mFiles" ; then
2522                OAD_CB2M_FILES=$i"/cb2mFiles"
2523                echo "     found $OAD_CB2M_FILES"
2524                break
2525            fi
2526        done
2527        echo "   OpenAD exceptions:  "
2528    fi
2529    
2530  echo "# This section creates symbolic links" > srclinks.tmp  echo "# This section creates symbolic links" > srclinks.tmp
2531  echo "" >> srclinks.tmp  echo "" >> srclinks.tmp
2532  printf 'SRCFILES = '    > srclist.inc  printf 'F77_SRC_FILES = ' > F77srclist.tmp
2533  printf 'CSRCFILES = '   > csrclist.inc  printf 'NON_AD_F77_SRC_FILES = ' > nonADF77srclist.tmp
2534  printf 'F90SRCFILES = ' > f90srclist.inc  printf 'C_SRC_FILES = '   > csrclist.tmp
2535  printf 'HEADERFILES = ' > hlist.inc  printf 'F90_SRC_FILES = ' > F90srclist.tmp
2536  printf 'AD_FLOW_FILES = ' > ad_flow_files.inc  printf 'H_SRC_FILES = '   > hsrclist.tmp
2537    printf 'AD_FLOW_FILES = ' > ad_flow_files.tmp
2538  alldirs="$SOURCEDIRS $INCLUDEDIRS ."  alldirs="$SOURCEDIRS $INCLUDEDIRS ."
2539  for d in $alldirs ; do  for d in $alldirs ; do
2540      deplist=      deplist=
2541      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
2542      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
2543        if test "x$OPENAD" != x ; then
2544            sfiles=`( echo $sfiles | grep -v _cb2m\. )`
2545        fi
2546      for sf in $sfiles ; do      for sf in $sfiles ; do
2547          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
2548              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
2549                  case $d/$sf in                  ignore_f=f
2550                    ./$PACKAGES_DOT_H)                  case $d/$sf in
2551                      ./$PACKAGES_DOT_H)
2552                            ignore_f=t
2553                            ;;
2554                      ./AD_CONFIG.h)
2555                            ignore_f=t
2556                          ;;                          ;;
2557                    ./AD_CONFIG.h)                    ./FC_NAMEMANGLE.h)
2558                            ignore_f=t
2559                          ;;                          ;;
2560                    ./FC_NAMEMANGLE.h)                    ./BUILD_INFO.h)
2561                            ignore_f=t
2562                          ;;                          ;;
2563                    ./BUILD_INFO.h)                    ./EMBEDDED_FILES.h)
2564                            ignore_f=t
2565                          ;;                          ;;
2566                    *)                    *)
2567                          touch .links.tmp/$sf                          #  For the local directory *ONLY*,
2568                          deplist="$deplist $sf"                          #  ignore all soft-links
2569                            if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then
2570                                ignore_f=t
2571                            else
2572                                touch .links.tmp/$sf
2573                                deplist="$deplist $sf"
2574                            fi
2575                          ;;                          ;;
2576                  esac                  esac
2577                  extn=`echo $sf | $AWK -F '.' '{print $NF}'`                  if test "x$ignore_f" = xf ; then
2578                  case $extn in                      extn=`echo $sf | $AWK -F. '{print $NF}'`
2579                      F)                      case $extn in
2580                          echo    " \\"  >> srclist.inc                        F)
2581                          printf " $sf" >> srclist.inc                          echo    " \\"  >> F77srclist.tmp
2582                            printf " $sf" >> F77srclist.tmp
2583                            if test "x$OPENAD" != x ; then
2584                                basename=${sf%%.F}
2585                                isAD=`egrep ^$basename.f'[  ]*' adSrcFiles.tmp`
2586                                if test -z "$isAD" ; then
2587                                    toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE}`
2588                                    if test -z "$toBeIgnored" ; then
2589                                        echo    " \\"  >> nonADF77srclist.tmp
2590                                        printf " $sf" >> nonADF77srclist.tmp
2591                                    else
2592                                        echo "    not to be compiled   :  $sf"
2593                                    fi
2594                                else # file is initially listed as an AD file we want to exclude it
2595                                     # or we want to retain the untransformed version
2596                                    notToBeTransformed=`egrep ^$basename'[      ]*' ${OAD_DONT_TRANSFORM}`
2597                                    untransformedVersionToBeKept=`egrep ^$basename'[      ]*' ${OAD_KEEP_ORIGINAL}`
2598                                    if test -n "$notToBeTransformed"; then
2599                                        echo "    not to be transformed:  $sf"
2600                                    fi
2601                                    if test -n "$untransformedVersionToBeKept" ; then
2602                                        echo "    original to be kept  :  $sf"
2603                                    fi
2604                                    if test -n "$notToBeTransformed" -o -n "$untransformedVersionToBeKept" ; then
2605                                        echo    " \\"  >> nonADF77srclist.tmp
2606                                        printf " $sf" >> nonADF77srclist.tmp
2607                                    fi
2608                                fi
2609                            fi
2610                          ;;                          ;;
2611                      F90)                      F90)
2612                          echo    " \\"  >> f90srclist.inc                          echo    " \\"  >> F90srclist.tmp
2613                          printf " $sf" >> f90srclist.inc                          printf " $sf" >> F90srclist.tmp
2614                          ;;                          ;;
2615                      c)                      c)
2616                          echo    " \\"  >> csrclist.inc                          echo    " \\"  >> csrclist.tmp
2617                          printf " $sf" >> csrclist.inc                          printf " $sf" >> csrclist.tmp
2618                          ;;                          ;;
2619                      h)                      h)
2620                          echo    " \\"  >> hlist.inc                          echo    " \\"  >> hsrclist.tmp
2621                          printf " $sf" >> hlist.inc                          printf " $sf" >> hsrclist.tmp
2622                          ;;                          ;;
2623                      flow)                      flow)
2624                          echo    " \\"  >> ad_flow_files.inc                          echo    " \\"  >> ad_flow_files.tmp
2625                          printf " $sf" >> ad_flow_files.inc                          printf " $sf" >> ad_flow_files.tmp
2626                          ;;                          ;;
2627                  esac                     esac
2628                    fi
2629              fi              fi
2630          fi          fi
2631      done      done
2632      if test "x$deplist" != x ; then      if test "x$deplist" != x ; then
2633          if test "$d" != "." ; then
2634          echo "" >> srclinks.tmp          echo "" >> srclinks.tmp
2635          echo "#  These files are linked from $d" >> srclinks.tmp          echo "#  These files are linked from $d" >> srclinks.tmp
2636          echo "$deplist :" >> srclinks.tmp          echo "$deplist :" >> srclinks.tmp
2637          printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp  # We need to make sure that the link isn't already there.
2638    # This may happen when make thinks that a header file has to be "remade"
2639    # because a module it depends on has changed.  In this case we do nothing.
2640            printf "\tif [ ! -L \$@ ]; then \$(LN) %s/\$@ \$@; fi\n" $d >> srclinks.tmp
2641          fi
2642      fi      fi
2643  done  done
2644  rm -rf .links.tmp  rm -rf .links.tmp
2645  echo "" >> srclist.inc  echo "" >> F77srclist.tmp
2646  echo "" >> csrclist.inc  echo "" >> nonADF77srclist.tmp
2647  echo "" >> f90srclist.inc  echo "" >> csrclist.tmp
2648  echo "" >> hlist.inc  echo "" >> F90srclist.tmp
2649  echo "" >> ad_flow_files.inc  echo "" >> hsrclist.tmp
2650    echo "" >> ad_flow_files.tmp
2651    
2652    CMDLINE=$0
2653    for xx in "$@" ; do nw=`echo $xx | wc -w`
2654        if test $nw = '1' ; then CMDLINE="$CMDLINE $xx"
2655                            else CMDLINE="$CMDLINE '$xx'" ; fi
2656    done
2657    
2658  if test -f $MAKEFILE ; then  if test -f $MAKEFILE ; then
2659      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.old"
2660  fi  fi
2661  echo "  Writing makefile: $MAKEFILE"  echo "  Writing makefile: $MAKEFILE"
2662  echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE  echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
# Line 1886  echo "#    $MACHINE" >> $MAKEFILE Line 2664  echo "#    $MACHINE" >> $MAKEFILE
2664  echo "# This makefile was generated automatically on" >> $MAKEFILE  echo "# This makefile was generated automatically on" >> $MAKEFILE
2665  echo "#    $THISDATE" >> $MAKEFILE  echo "#    $THISDATE" >> $MAKEFILE
2666  echo "# by the command:" >> $MAKEFILE  echo "# by the command:" >> $MAKEFILE
2667  echo "#    $0 $G2ARGS" >> $MAKEFILE  echo "#    $CMDLINE"  >> $MAKEFILE
2668  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
2669  echo "#    ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE  echo "#    ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
2670    
# Line 1897  EXE_SVD=$EXECUTABLE"_svd" Line 2675  EXE_SVD=$EXECUTABLE"_svd"
2675  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2676  #  #
2677  # OPTFILE="$OPTFILE"  # OPTFILE="$OPTFILE"
2678  #  #
2679  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
2680  # SOURCEDIRS   : Directories containing the source (.F) files  # SOURCEDIRS   : Directories containing the source (.F) files
2681  # INCLUDEDIRS  : Directories containing the header-source (.h) files  # INCLUDEDIRS  : Directories containing the header-source (.h) files
# Line 1908  cat >>$MAKEFILE <<EOF Line 2686  cat >>$MAKEFILE <<EOF
2686  # INCLUDES     : Directories searched for header files  # INCLUDES     : Directories searched for header files
2687  # DEFINES      : Macro definitions for CPP  # DEFINES      : Macro definitions for CPP
2688  # MAKEDEPEND   : Dependency generator  # MAKEDEPEND   : Dependency generator
 # KPP          : Special preprocessor command (specific to platform)  
 # KFLAGS       : Flags for KPP  
2689  # FC           : Fortran compiler command  # FC           : Fortran compiler command
2690  # FFLAGS       : Configuration/debugging options for FC  # FFLAGS       : Configuration/debugging options for FC
2691  # FOPTIM       : Optimization options for FC  # FOPTIM       : Optimization options for FC
# Line 1917  cat >>$MAKEFILE <<EOF Line 2693  cat >>$MAKEFILE <<EOF
2693  # LIBS         : Library flags /or/ additional optimization/debugging flags  # LIBS         : Library flags /or/ additional optimization/debugging flags
2694    
2695  ROOTDIR     = ${ROOTDIR}  ROOTDIR     = ${ROOTDIR}
2696  BUILDDIR    = ${BUILDDIR}    BUILDDIR    = ${BUILDDIR}
2697  SOURCEDIRS  = ${SOURCEDIRS}  SOURCEDIRS  = ${SOURCEDIRS}
2698  INCLUDEDIRS = ${INCLUDEDIRS}  INCLUDEDIRS = ${INCLUDEDIRS}
2699  EXEDIR      = ${EXEDIR}  EXEDIR      = ${EXEDIR}
# Line 1935  DISABLED_PACKAGES = ${DISABLED_PACKAGES} Line 2711  DISABLED_PACKAGES = ${DISABLED_PACKAGES}
2711    
2712  # These files are created by Makefile  # These files are created by Makefile
2713  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
   
2714  EOF  EOF
2715    
2716  #  Note: figure out some way to add Hyades JAM libraries here  if test "x$EMBED_SRC" = xt ; then
2717        echo "EMBEDDED_FILES = EMBEDDED_FILES.h" >>$MAKEFILE
2718    else
2719        echo "EMBEDDED_FILES = " >>$MAKEFILE
2720    fi
2721    
2722  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2723  # Unix ln (link)  # Unix ln (link)
2724  LN = ${LN}  LN = ${LN}
# Line 1966  INCLUDES = ${INCLUDES} Line 2745  INCLUDES = ${INCLUDES}
2745  KFLAGS1 = ${KFLAGS1}  KFLAGS1 = ${KFLAGS1}
2746  KFLAGS2 = ${KFLAGS2}  KFLAGS2 = ${KFLAGS2}
2747  # Optim./debug for FC  # Optim./debug for FC
2748  FFLAGS = ${FFLAGS}  FFLAGS = ${FFLAGS} ${FEXTRAFLAGS}
2749  FOPTIM = ${FOPTIM}  FOPTIM = ${FOPTIM}
2750  # Optim./debug for FC  # Optim./debug for FC
2751  F90FLAGS = ${F90FLAGS}  F90FLAGS = ${F90FLAGS}
2752  F90OPTIM = ${F90OPTIM}  F90OPTIM = ${F90OPTIM}
2753    F90FIXEDFORMAT = ${F90FIXEDFORMAT}
2754  # Flags for CC  # Flags for CC
2755  CFLAGS = ${CFLAGS}  CFLAGS = ${CFLAGS}
2756  # Files that should not be optimized  # Files that should not be optimized
# Line 1978  NOOPTFILES = ${NOOPTFILES} Line 2758  NOOPTFILES = ${NOOPTFILES}
2758  NOOPTFLAGS = ${NOOPTFLAGS}  NOOPTFLAGS = ${NOOPTFLAGS}
2759  # Flags and libraries needed for linking  # Flags and libraries needed for linking
2760  LIBS = ${LIBS}  LIBS = ${LIBS}
2761  # Name of the Mekfile  # Name of the makefile
2762  MAKEFILE=${MAKEFILE}  MAKEFILE = ${MAKEFILE}
2763    # Name of the make program
2764    MAKE = ${MAKE}
2765    
2766  EOF  EOF
2767    
2768  cat srclist.inc       >> $MAKEFILE  cat F77srclist.tmp      >> $MAKEFILE
2769  cat csrclist.inc      >> $MAKEFILE  cat nonADF77srclist.tmp >> $MAKEFILE
2770  cat f90srclist.inc    >> $MAKEFILE  cat csrclist.tmp        >> $MAKEFILE
2771  cat hlist.inc         >> $MAKEFILE  cat F90srclist.tmp      >> $MAKEFILE
2772  cat ad_flow_files.inc >> $MAKEFILE  cat hsrclist.tmp        >> $MAKEFILE
2773    cat ad_flow_files.tmp   >> $MAKEFILE
2774    
2775    rm -f F77srclist.tmp nonADF77srclist.tmp csrclist.tmp F90srclist.tmp hsrclist.tmp ad_flow_files.tmp
2776    
2777  echo >> $MAKEFILE  echo >> $MAKEFILE
2778  echo 'F77FILES =  $(SRCFILES:.F=.'$FS')'      >> $MAKEFILE  
2779  echo 'F90FILES =  $(F90SRCFILES:.F=.'$FS90')' >> $MAKEFILE  # add definitions for preprocessed sources
2780  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE  # and note that not all systems allow case sensitive extensions
2781    # hence the $FS and $FS90 here.
2782    # for fixed format f90 files we use ff90 or FF90 resp
2783    # but these are not expected to be the original source files
2784    
2785    echo 'F77_PP_SRC_FILES = $(F77_SRC_FILES:.F=.'$FS')'      >> $MAKEFILE
2786    echo 'F90_PP_SRC_FILES = $(F90_SRC_FILES:.F90=.'$FS90')' >> $MAKEFILE
2787    echo 'OBJFILES= $(F77_SRC_FILES:.F=.o) $(C_SRC_FILES:.c=.o) $(F90_SRC_FILES:.F90=.o)' >> $MAKEFILE
2788    echo 'FLOWFILES =  $(AD_FLOW_FILES:.flow=.flowdir)' >> $MAKEFILE
2789  echo >> $MAKEFILE  echo >> $MAKEFILE
2790  echo '.SUFFIXES:' >> $MAKEFILE  echo '.SUFFIXES:' >> $MAKEFILE
2791  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  
2792    
2793  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2794    
2795  all: \$(EXECUTABLE)  all: fwd_exe_target
2796  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(OBJFILES)  fwd_exe_target:
2797            @echo Update AD_CONFIG.h and make \$(EXECUTABLE)
2798            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Forward version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
2799            @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
2800            @-rm -f ad_config.template
2801            \$(MAKE) -f \$(MAKEFILE) \$(EXECUTABLE)
2802    
2803    \$(EXECUTABLE): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(OBJFILES) \$(EMBEDDED_FILES)
2804          @echo Creating \$@ ...          @echo Creating \$@ ...
2805          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
2806    
2807  depend:  depend:
2808          @make links          @\$(MAKE) -f \$(MAKEFILE) links
2809          \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)
2810          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2811          -rm -f makedepend.out          -rm -f makedepend.out
2812    
2813  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES)  lib: libmitgcmuv.a
2814    
2815    libmitgcmuv.a: \$(OBJFILES)
2816            ar rcv libmitgcmuv.a \$(OBJFILES)
2817            ar d   libmitgcmuv.a main.o
2818    
2819  small_f: \$(F77FILES) \$(F90FILES)  obj: \$(OBJFILES)
2820    
2821    links: \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(SPECIAL_FILES)
2822    
2823    small_f: \$(F77_PP_SRC_FILES) \$(F90_PP_SRC_FILES)
2824    
2825  output.txt: \$(EXECUTABLE)  output.txt: \$(EXECUTABLE)
2826          @printf 'running ... '          @printf 'running ... '
2827          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
2828    
2829    # remove most of the files that "make" generates
2830  clean:  clean:
2831          -rm -rf *.o *.$FS *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template          -rm -rf *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
2832            -rm -rf *.o
2833            -rm -rf *.$FS *.flowdir
2834            -rm -rf *.f$FS90 \$(AD_CLEAN) ad_input*
2835    
2836    # remove most of the files that "make" and "make depend" generate
2837  Clean:  Clean:
2838          @make clean          @\$(MAKE) -f \$(MAKEFILE) clean
2839          @make cleanlinks          @\$(MAKE) -f \$(MAKEFILE) cleanlinks
2840          -rm -f \$(SPECIAL_FILES)          -rm -f \$(SPECIAL_FILES) f90mkdepend.log $MAKEFILE.old
2841          -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 taf_ftl.log
2842            -rm -f genmake_warnings genmake_errors make.log
2843    
2844    # remove also the executable, files that "genmake2" generates (except Makefile)
2845    #         and output from a run (plus log files from testreport)
2846  CLEAN:  CLEAN:
2847          @make Clean          @\$(MAKE) -f \$(MAKEFILE) Clean
2848            -rm -f \$(EXECUTABLE) \$(EXE_AD) \$(EXE_FTL) *.bak
2849            -rm -f $LOGFILE genmake_state genmake_*optfile
2850            -rm -f SIZE.h.mpi genmake.tr_log make.tr_log
2851          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
2852          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
2853          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
2854          -rm -f \$(EXECUTABLE) output.txt STD*          -rm -f *.txt STD* *diagnostics.log datetime
2855            -rm -f *_MIT_CE_000.opt0000 costfunction*0000
2856            -rm -rf mnc_test_*
2857    
 #eh3 Makefile: makefile  
2858  makefile:  makefile:
2859          $THIS_SCRIPT $G2ARGS          $THIS_SCRIPT $G2ARGS
2860  cleanlinks:  cleanlinks:
2861          -find . -type l -exec rm {} \;          -find . -type l -exec rm {} \;
2862    
2863  # Special targets (SPECIAL_FILES) which are create by make  # Special targets (SPECIAL_FILES) which are created by make
2864  ${PACKAGES_DOT_H}:  ${PACKAGES_DOT_H}:
2865          @echo Creating \$@ ...          @echo Creating \$@ ...
2866          @$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 -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@
2867  AD_CONFIG.h:  AD_CONFIG.h:
2868          @echo Creating \$@ ...          @echo Creating \$@ ...
2869          @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > \$@          @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Default version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > \$@
2870  FC_NAMEMANGLE.h:  FC_NAMEMANGLE.h:
2871          @echo Creating \$@ ...          @echo Creating \$@ ...
2872          echo "$FC_NAMEMANGLE" > \$@          echo "$FC_NAMEMANGLE" > \$@
# Line 2058  test ! "x$THISUSER" = x && echo "      -echo Line 2880  test ! "x$THISUSER" = x && echo "      -echo
2880  test ! "x$THISDATE" = x && echo "       -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE  test ! "x$THISDATE" = x && echo "       -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
2881  test ! "x$THISHOST" = x && echo "       -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE  test ! "x$THISHOST" = x && echo "       -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
2882    
2883    if test "x$EMBED_SRC" = xt ; then
2884        cat >>$MAKEFILE <<EOF
2885    
2886    decode_files.o : EMBEDDED_FILES.h
2887    
2888    ##  \$(F77_PP_SRC_FILES)
2889    all_fF.tar.gz : \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile
2890            @echo Creating \$@ ...
2891            -tar -hcf all_fF.tar \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile
2892            -rm -f all_fF.tar.gz
2893            -gzip all_fF.tar
2894    
2895    EMBEDDED_FILES.h : all_fF.tar.gz
2896            @echo Creating \$@ ...
2897            -\${ROOTDIR}/tools/embed_encode/encode_files EMBEDDED_FILES.h all_fF.tar.gz
2898    
2899    EOF
2900    fi
2901    
2902  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2903    
2904  # The normal chain of rules is (  .F - .$FS - .o  )  # The normal chain of rules is (  .F - .$FS - .o  )
# Line 2069  cat >>$MAKEFILE <<EOF Line 2910  cat >>$MAKEFILE <<EOF
2910          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2911  .$FS.o:  .$FS.o:
2912          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2913    .F.o:
2914            \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2915  .F90.$FS90:  .F90.$FS90:
2916          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2917    .FF90.f$FS90:
2918            \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2919  .$FS90.o:  .$FS90.o:
2920          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
2921    .f$FS90.o:
2922            cp \$< \$(basename  \$<).f90
2923            \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$(F90FIXEDFORMAT) \$(basename  \$<).f90
2924  .c.o:  .c.o:
2925          \$(CC) \$(CFLAGS) -c \$<          \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$<
2926    .flow.flowdir:
2927            \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2928    
2929  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
2930  .F.p:  .F.p:
# Line 2082  cat >>$MAKEFILE <<EOF Line 2932  cat >>$MAKEFILE <<EOF
2932  .p.$FS:  .p.$FS:
2933          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
2934    
2935    EOF
2936    
2937  #=========================================  #=========================================
2938  #===  Automatic Differentiation Rules  ===  #===  Automatic Differentiation Rules  ===
2939    #===  for TAMC/TAF  ======================
2940    
2941    if test "x$OPENAD" = x ; then
2942    
2943    cat >>$MAKEFILE <<EOF
2944    
2945  TAMC           = ${TAMC}  TAMC           = ${TAMC}
2946  TAF            = ${TAF}  TAF            = ${TAF}
# Line 2098  ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF Line 2955  ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF
2955  ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"  ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
2956  for i in $ad_vars ; do  for i in $ad_vars ; do
2957      name=$i      name=$i
2958      t1="t2=\$"`echo $i`      t1="t2=\$"`echo "$i"`
2959      eval $t1      eval $t1
2960      printf "%-20s = " $name >> $MAKEFILE      printf "%-20s = " $name >> $MAKEFILE
2961      echo $t2 >> $MAKEFILE      echo "$t2" | sed -e 's| \+| |g' >> $MAKEFILE
2962  done  done
2963    
2964  echo "  Add the source list for AD code generation"  echo "  Add the source list for AD code generation"
2965  echo >> $MAKEFILE  echo >> $MAKEFILE
2966  printf "AD_FILES = " >> $MAKEFILE  printf "AD_FILES = " >> $MAKEFILE
2967  AD_FILES=`cat ad_files`  AD_FILES=`cat adSrcFiles.tmp`
2968  for i in $AD_FILES ; do  for i in $AD_FILES ; do
2969      echo    " \\" >> $MAKEFILE      echo    " \\" >> $MAKEFILE
2970      printf " $i" >> $MAKEFILE      printf " $i" >> $MAKEFILE
2971  done  done
2972  echo >> $MAKEFILE  echo >> $MAKEFILE
2973  rm -f ad_files  rm -f adSrcFiles.tmp
2974    
2975  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2976    
2977  # ... AD ...  # ... AD ...
2978  adall: ad_taf  adall: ad_exe_target
2979  adtaf: ad_taf_output.f  adtaf: ad_taf_output.$FS
2980  adtamc: ad_tamc_output.f  adtamc: ad_tamc_output.$FS
2981    
2982    ad_exe_target:
2983            @echo Update AD_CONFIG.h and make \$(EXE_AD)
2984            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
2985            @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
2986            @-rm -f ad_config.template
2987            \$(MAKE) -f \$(MAKEFILE) \$(EXE_AD)
2988    
2989  ad_input_code.f: \$(AD_FILES) \$(HEADERFILES)  ad_input_code.$FS: \$(AD_FILES) \$(H_SRC_FILES) \$(AD_FLOW_FILES)
2990          @$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 "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
2991          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
2992          -rm -f ad_config.template          @-rm -f ad_config.template
2993          @make \$(F77FILES)          @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
2994          @make \$(AD_FLOW_FILES)          @\$(MAKE) -f \$(MAKEFILE) \$(FLOWFILES)
2995          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f          cat \$(FLOWFILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ad_input_code.$FS
2996    
2997  ad_taf_output.f: ad_input_code.f  ad_taf_output.$FS: ad_input_code.$FS
2998          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2999          cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f          ls -l ad_input_code_ad.$FS
3000            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
3001    
3002  adtafonly:  adtafonly:
3003          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
3004          cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f          ls -l ad_input_code_ad.$FS
3005            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
3006  ad_taf: ad_taf_output.o \$(OBJFILES)  
3007          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)  \${EXE_AD}: ad_taf_output.o \$(OBJFILES)
3008            \$(LINK) -o \${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
3009  ad_tamc_output.f: ad_input_code.f  
3010          \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f  ad_tamc_output.$FS: ad_input_code.$FS
3011          cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.f          \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
3012            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS
3013    
3014  ad_tamc: ad_tamc_output.o \$(OBJFILES)  ad_tamc: ad_tamc_output.o \$(OBJFILES)
3015          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
3016    
3017  adonlyfwd:  adonlyfwd:
3018          patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff          patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
3019    
3020  adtrick:  adtrick:
3021          patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff          patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
3022    
3023  # ... FTL ...  adobj: ad_taf_output.o \$(OBJFILES)
 ftlall: ftl_taf  
 ftltaf: ftl_taf_output.f  
 ftltamc: ftl_tamc_output.f  
   
 ftl_input_code.f: \$(AD_FILES) \$(HEADERFILES)  
         @$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  
         cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h  
         -rm -f ftl_config.template  
         @make \$(F77FILES)  
         @make \$(AD_FLOW_FILES)  
         cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f  
   
 ftl_taf_output.f: ftl_input_code.f  
         \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f  
         cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f  
3024    
3025  ftltafonly:  # ... FTL ...
3026          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f  ftlall: ftl_exe_target
3027          cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f  ftltaf: ftl_taf_output.$FS
3028    ftltamc: ftl_tamc_output.$FS
3029    
3030    ftl_exe_target:
3031            @echo Update AD_CONFIG.h and make \$(EXE_FTL)
3032            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
3033            @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3034            @-rm -f ad_config.template
3035            \$(MAKE) -f \$(MAKEFILE) \$(EXE_FTL)
3036    
3037  ftl_taf: ftl_taf_output.o \$(OBJFILES)  ftl_input_code.$FS: \$(AD_FILES) \$(H_SRC_FILES)
3038          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)          @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
3039            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3040            @-rm -f ad_config.template
3041            @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3042            @\$(MAKE) -f \$(MAKEFILE) \$(AD_FLOW_FILES)
3043            cat \$(AD_FLOW_FILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ftl_input_code.$FS
3044    
3045    ftl_taf_output.$FS: ftl_input_code.$FS
3046            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
3047            ls -l ftl_input_code_ftl.$FS
3048            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
3049    
3050  ftl_tamc_output.f: ftl_input_code.f  ftltafonly:
3051          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
3052          cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.f          ls -l ftl_input_code_ftl.$FS
3053            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
3054    
3055    \${EXE_FTL}: ftl_taf_output.o \$(OBJFILES)
3056            \$(LINK) -o \${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
3057    
3058    ftl_tamc_output.$FS: ftl_input_code.$FS
3059            \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
3060            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS
3061    
3062  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
3063          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
   
3064    
3065  # ... SVD ...  # ... SVD ...
3066  svdtaf: ad_taf_output.f ftl_taf_output.f  svdtaf: ad_taf_output.$FS ftl_taf_output.$FS
3067          @echo "--->>> Only ran TAF to generate SVD code!    <<<---"          @echo "--->>> Only ran TAF to generate SVD code!    <<<---"
3068          @echo "--->>> Do make svdall afterwards to compile. <<<---"          @echo "--->>> Do make svdall afterwards to compile. <<<---"
3069  svdall: svd_touch svd_taf  svdall: svd_touch svd_taf
# Line 2203  svd_touch: Line 3079  svd_touch:
3079          @echo "--->>> Only COMPILE svd code! <<<---"          @echo "--->>> Only COMPILE svd code! <<<---"
3080          @echo "--->>> Assumes you previously <<<---"          @echo "--->>> Assumes you previously <<<---"
3081          @echo "--->>> did make svdtaf        <<<---"          @echo "--->>> did make svdtaf        <<<---"
3082          touch ad_taf_output.f ftl_taf_output.f          touch ad_taf_output.$FS ftl_taf_output.$FS
3083          \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.f          \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS
3084          \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.f          \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS
3085          @$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 "SVD version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
3086          cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h          cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3087          -rm -f ftl_config.template          @-rm -f ad_config.template
3088    
3089  #=========================================  EOF
3090    
3091    fi
3092    
3093    #===  for OpenAD  ========================
3094    
3095    if test "x$OPENAD" != x ; then
3096    
3097    # ============ begin OpenAD specific section ==============
3098    
3099    cat >>$MAKEFILE <<EOF
3100    
3101    # all the source files linked from the various locations:
3102    ALL_LINKED_FILES= \
3103    \$(F77_SRC_FILES) \
3104    \$(C_SRC_FILES) \
3105    \$(H_SRC_FILES) \
3106    \$(F90_SRC_FILES) \
3107    \$(SPECIAL_FILES)
3108    
3109    ifndef OPENADROOT
3110      \$(error "Error:  environment variable OPENADROOT not defined!")
3111    endif
3112    
3113    ifndef XAIFSCHEMAROOT
3114      \$(error "Error:  environment variable XAIFSCHEMAROOT not defined!")
3115    endif
3116    
3117    ifndef XAIFBOOSTERROOT
3118      \$(error "Error:  environment variable XAIFBOOSTERROOT not defined!")
3119    endif
3120    
3121    EOF
3122    
3123    echo "  Add the source list for common block to module conversion "
3124    echo >> $MAKEFILE
3125    printf "CB2M_F90_SRC_NAMES = " >> $MAKEFILE
3126    for i in `cat ${OAD_CB2M_FILES}` ; do
3127      echo    " \\" >> $MAKEFILE
3128      printf " $i" >> $MAKEFILE
3129    done
3130    echo >> $MAKEFILE
3131    
3132    echo "  Add the source list for AD code generation"
3133    echo >> $MAKEFILE
3134    printf "AD_FILES = " >> $MAKEFILE
3135    for i in `cat ${OAD_CB2M_FILES}` ; do
3136      echo    " \\" >> $MAKEFILE
3137      printf " ${i}_mod.f$FS90" >> $MAKEFILE
3138    done
3139    AD_FILES=`cat adSrcFiles.tmp`
3140    for i in $AD_FILES ; do
3141      basename=${i%%.f}
3142      toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE} ${OAD_DONT_TRANSFORM}`
3143      if test -z "$toBeIgnored" ; then
3144        echo    " \\" >> $MAKEFILE
3145        printf " $i" >> $MAKEFILE
3146      fi
3147    done
3148    echo >> $MAKEFILE
3149    rm -f adSrcFiles.tmp
3150    
3151    cat >>$MAKEFILE <<EOF
3152    
3153    adAll: \$(EXE_AD)
3154    .PHONY: adAll
3155    
3156    CB2M_F90_PP_SRC_FILES=\$(addsuffix _mod.f$FS90, \$(CB2M_F90_SRC_NAMES))
3157    
3158    .PRECIOUS: \$(CB2M_F90_PP_SRC_FILES) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90)
3159    
3160    .PHONY: adDepend
3161    adDepend: \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) \$(addsuffix _mod.FF90, \$(CB2M_F90_SRC_NAMES)) \$(F77_SRC_FILES:.F=_cb2m.FF90)
3162            \$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)
3163            \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
3164            -rm -f makedepend.out
3165    
3166    OPENAD_SUPPORT_F90_SRC_FILES = \
3167    w2f__types.F90 \
3168    OAD_active.F90 \
3169    OAD_cp.F90 \
3170    OAD_rev.F90 \
3171    OAD_tape.F90
3172    
3173    OPENAD_SUPPORT_C_SRC_FILES = \
3174    iaddr.c \
3175    timeRatio.c
3176    
3177    f95_test_mods.f90: \$(OPENAD_SUPPORT_F90_SRC_FILES:F90=$FS90)
3178            cat \$^ > \$@
3179    
3180    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
3181            cat \$^ > \$@
3182    
3183    f95_test.out: f95_test_mods.f90 f95_test.f90
3184            f95 -fixed -w=unused -maxcontin=132 -c f95_test_mods.f90 > \$@ 2>&1
3185            f95 -fixed -w=unused -maxcontin=132 -c -fixed f95_test.f90 >> \$@ 2>&1
3186    
3187    CB2M_AD_FILES=\$(AD_FILES:.f=_cb2m.f$FS90)
3188    
3189    AD_OBJ_FILES_S1=\$(OPENAD_SUPPORT_F90_SRC_FILES:.F90=.o) \$(OPENAD_SUPPORT_C_SRC_FILES:.c=.o)  OAD_intrinsics_oad.o \$(CB2M_AD_FILES:.f$FS90=_oad.o)
3190    
3191    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)
3192    
3193    \$(EXE_AD): \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) postProcess.tag \$(AD_OBJ_FILES_S2)
3194            \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(AD_OBJ_FILES_S2) \$(LIBS)
3195    
3196    # create sources files modules from header files containing common blocks
3197    %_mod.FF90 : %.h ../OAD_support/cb2mGetModules.csh ../OAD_support/cb2mGetModules.awk
3198            ../OAD_support/cb2mGetModules.csh $< ../OAD_support/cb2mGetModules.awk
3199    
3200    # create new header files with USE statements for the new modules made above
3201    %_mod.h : %.h ../OAD_support/cb2mGetHeaders.csh ../OAD_support/cb2mGetHeaders.awk
3202            ../OAD_support/cb2mGetHeaders.csh $< ../OAD_support/cb2mGetHeaders.awk \$(CB2M_F90_SRC_NAMES)
3203    
3204    # change the include directives of everybody to refer to  the new header files with the USE statements
3205    %_cb2m.FF90 : %.F ../OAD_support/cb2mUseModules.bash
3206            ../OAD_support/cb2mUseModules.bash $< ${MPI}
3207    
3208    # makefile debug rule
3209    small_f: \$(CB2M_F90_PP_SRC_FILES)
3210    .PHONY: small_f
3211    
3212    ad_output.txt: \$(EXE_AD)
3213            @printf 'linking data files ... '
3214            \$(LN) -f ../input_ad/data* ../input_ad/eedata .
3215            \$(LN) -f ../../global_ocean.90x40x15/input/*.bin .
3216            @printf 'running ... '
3217            @./\$(EXE_AD) > \$@
3218    
3219    ad_input_code.f$FS90:  \$(CB2M_AD_FILES)
3220            cat \$^ > \$@
3221    
3222    # canonicalizer
3223    ad_input_code_sf.pre.f90 : \$(CB2M_AD_FILES)
3224            \${OPENADFORTTK_BASE}/tools/SourceProcessing/preProcess.py --timing --r8 -H -S  -o \$@ \$^
3225    
3226    # replace stop statements (to avoid the implied unstructured control flow)  with print statements
3227    ad_input_code_sf.pre.s2p.f90 : ad_input_code_sf.pre.f90
3228            cat \$< | sed -f ../OAD_support/stop2print.sed > ad_input_code_sf.pre.s2p.f90
3229    
3230    # F -> WHIRL
3231    ad_input_code_sf.pre.s2p.B: ad_input_code_sf.pre.s2p.f90
3232            \${OPEN64ROOT}/crayf90/sgi/mfef90 -r8 -z -F ad_input_code_sf.pre.s2p.f90
3233    
3234    # WHIRL -> XAIF
3235    ad_input_code_sf.pre.s2p.xaif : ad_input_code_sf.pre.s2p.B
3236            \${OPENADFORTTK}/bin/whirl2xaif -s -n --debug 1 -o \$@ \$<
3237    
3238    # XAIF -> XAIF'
3239    ad_input_code_sf.pre.s2p.xb.xaif : ad_input_code_sf.pre.s2p.xaif xaif.xsd xaif_base.xsd xaif_inlinable_intrinsics.xsd xaif_derivative_propagator.xsd xaif_output.xsd
3240            \${XAIFBOOSTERROOT}/xaifBooster/algorithms/BasicBlockPreaccumulationReverse/driver/oadDriver -f -t forward_step -i \$< -c \${XAIFSCHEMAROOT}/schema/examples/inlinable_intrinsics.xaif -o \$@ -I -r
3241    
3242    # XAIF' -> WHIRL'
3243    ad_input_code_sf.pre.s2p.xb.x2w.B : ad_input_code_sf.pre.s2p.xb.xaif
3244            \${OPENADFORTTK}/bin/xaif2whirl --debug 1 ad_input_code_sf.pre.s2p.B \$<
3245    
3246    # WHIRL' -> F'
3247    ad_input_code_sf.pre.s2p.xb.x2w.w2f.f$FS90: ad_input_code_sf.pre.s2p.xb.x2w.B
3248            \${OPEN64ROOT}/whirl2f/whirl2f -FLIST:ftn_file=\$@ -openad \$<
3249    
3250    # insert template directives
3251    ad_input_code_sf.pre.s2p.xb.x2w.w2f.td.f$FS90: ad_input_code_sf.pre.s2p.xb.x2w.w2f.f$FS90 ../OAD_support/insertTemplateDir.bash
3252            ../OAD_support/insertTemplateDir.bash \$< \$@
3253    
3254    PPEXTRAS=\$(wildcard ../OAD_support/ad_template.*.F) ../OAD_support/ad_inline.F
3255    # postprocess F'
3256    postProcess.tag: ad_input_code_sf.pre.s2p.xb.x2w.w2f.td.f$FS90 \$(PPEXTRAS:.F=.f) | w2f__types.f90
3257            \${OPENADFORTTK_BASE}/tools/SourceProcessing/postProcess.py --progress --timing --infoUnitFile w2f__types.f90 --outputFormat=fixed --separateOutput --pathSuffix "" --filenameSuffix "_oad" -m r -i ../OAD_support/ad_inline.f \$<
3258            # the target is a placeholder to trigger a single execution of the rule
3259            touch \$@
3260    # put this so make knows about the postprocessing output
3261    OAD_intrinsics_oad.f \$(CB2M_AD_FILES:.f$FS90=_oad.f): postProcess.tag
3262    
3263    # link the XAIF schema files
3264    %.xsd:
3265            \$(LN) \${XAIFSCHEMAROOT}/schema/\$@ .
3266    
3267    # link the support files:
3268    \$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES):
3269            \$(LN) ../OAD_support/\$@ .
3270    
3271    AD_CLEAN += *_mod.h *_mod.F90 *.FF90 *.mod-whirl temp.sed oad_cp.* postProcess.tag \$(PPEXTRAS:.F=.f)
3272    
3273    # ============ end OpenAD specific section ==============
3274    
3275  EOF  EOF
3276    
3277    fi
3278    
3279    #=========================================
3280    
3281  if test "x$EXEHOOK" != x ; then  if test "x$EXEHOOK" != x ; then
3282      printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE      printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
3283  fi  fi
# Line 2249  printf "\n\n# DO NOT DELETE\n" >> $MAKEF Line 3313  printf "\n\n# DO NOT DELETE\n" >> $MAKEF
3313  printf "\n===  Done  ===\n"  printf "\n===  Done  ===\n"
3314    
3315  # Create special header files  # Create special header files
3316  $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 -bPACKAGES_CONFIG_H "Disabled packages:" $DISABLED_PACKAGES " " "Enabled packages:" $ENABLED_PACKAGES > $PACKAGES_DOT_H".tmp"
3317  if test ! -f $PACKAGES_DOT_H ; then  if test ! -f $PACKAGES_DOT_H ; then
3318      mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H      mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
3319  else  else
# Line 2263  else Line 3327  else
3327      fi      fi
3328  fi  fi
3329  if test ! -f AD_CONFIG.h ; then  if test ! -f AD_CONFIG.h ; then
3330      $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 "Default version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > AD_CONFIG.h
3331  fi  fi
3332    
   
3333  #  Write the "state" for future records  #  Write the "state" for future records
3334  if test "x$DUMPSTATE" != xf ; then  if test "x$DUMPSTATE" = xt ; then
3335      printf "" > genmake_state      printf "" > genmake_state
3336      for i in $gm_state ; do      for i in $gm_state ; do
3337          t1="t2=\$$i"          t1="t2=\$$i"
3338          eval $t1          eval $t1
3339          echo "$i='$t2'" >> genmake_state          echo "$i='$t2'" | sed -e 's/  */ /g' >> genmake_state
3340      done      done
3341  fi  fi

Legend:
Removed from v.1.109  
changed lines
  Added in v.1.238

  ViewVC Help
Powered by ViewVC 1.1.22