/[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.181 by jmc, Fri Jan 2 20:32:21 2009 UTC revision 1.274 by jmc, Fri Nov 20 01:22:36 2015 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        -oad | --oad
23              Generate a Makefile for an OpenAD built
24    
25        -nocat4ad | -dog4ad | -ncad | -dad
26              do not concatenate (cat) source code sent to TAF
27              resulting in compilation of multiple files
28    
29        -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME
30          -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME
31              Use "NAME" as the adoptfile.  By default, the file at
32              "tools/adjoint_options/adjoint_oad" (for OpenAD built) or
33              "tools/adjoint_options/adjoint_default" will be used.
34    
35        -nooptfile | --nooptfile
36          -optfile NAME | --optfile NAME | -of NAME | --of NAME
37          -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
38              Use "NAME" as the optfile.  By default, an attempt will be
39              made to find an appropriate "standard" optfile in the
40              tools/build_options/ directory.
41    
42        -pdepend NAME | --pdepend NAME
43          -pdepend=NAME | --pdepend=NAME
44              Get package dependency information from "NAME".
45    
46        -pgroups NAME | --pgroups NAME
47          -pgroups=NAME | --pgroups=NAME
48              Get the package groups information from "NAME".
49    
50        -bash NAME
51              Explicitly specify the Bourne or BASH shell to use
52    
53        -make NAME | -m NAME
54          --make=NAME | -m=NAME
55              Use "NAME" for the MAKE program. The default is "make" but
56              many platforms, "gmake" is the preferred choice.
57    
58        -makefile NAME | -mf NAME
59          --makefile=NAME | -mf=NAME
60              Call the makefile "NAME".  The default is "Makefile".
61    
62        -makedepend NAME | -md NAME
63          --makedepend=NAME | -md=NAME
64              Use "NAME" for the MAKEDEPEND program.
65    
66        -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
67          -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
68              Specify the location of the MITgcm ROOTDIR as "NAME".
69              By default, genamke will try to find the location by
70              looking in parent directories (up to the 5th parent).
71    
72        -mods NAME | --mods NAME | -mo NAME | --mo NAME
73          -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
74              Here, "NAME" specifies a list of directories that are
75              used for additional source code.  Files found in the
76              "mods list" are given preference over files of the same
77              name found elsewhere.
78    
79        -disable NAME | --disable NAME
80          -disable=NAME | --disable=NAME
81              Here "NAME" specifies a list of packages that we don't
82              want to use.  If this violates package dependencies,
83              genamke will exit with an error message.
84    
85        -enable NAME | --enable NAME
86          -enable=NAME | --enable=NAME
87              Here "NAME" specifies a list of packages that we wish
88              to specifically enable.  If this violates package
89              dependencies, genamke will exit with an error message.
90    
91        -standarddirs NAME | --standarddirs NAME
92          -standarddirs=NAME | --standarddirs=NAME
93              Here, "NAME" specifies a list of directories to be
94              used as the "standard" code.
95    
96        -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
97          -fc=NAME | --fc=NAME
98              Use "NAME" as the fortran compiler.  By default, genmake
99              will search for a working compiler by trying a list of
100              "usual suspects" such as g77, f77, etc.
101    
102        -cc NAME | --cc NAME | -cc=NAME | --cc=NAME
103              Use "NAME" as the C compiler.  By default, genmake
104              will search for a working compiler by trying a list of
105              "usual suspects" such as gcc, c89, cc, etc.
106    
107        -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4
108              Use "real*4" type for _RS variable (#undef REAL4_IS_SLOW)
109              *only* works if CPP_EEOPTIONS.h allows this.
110    
111        -ignoretime | -ignore_time | --ignoretime | --ignore_time
112              Ignore all the "wall clock" routines entirely.  This will
113              not in any way hurt the model results -- it simply means
114              that the code that checks how long the model spends in
115              various routines will give junk values.
116    
117        -ts | --ts
118              Produce timing information per timestep
119        -papis | --papis
120              Produce summary MFlop/s (and IPC) with PAPI per timestep
121        -pcls | --pcls
122              Produce summary MFlop/s etc. with PCL per timestep
123        -foolad | --foolad
124              Fool the AD code generator
125        -papi | --papi
126              Performance analysis with PAPI
127        -pcl | --pcl
128              Performance analysis with PCL
129        -hpmt | --hpmt
130              Performance analysis with the HPM Toolkit
131    
132        -ieee | --ieee
133              use IEEE numerics.  Note that this option *only* works
134              if it is supported by the OPTFILE that is being used.
135        -devel | --devel
136              Add additional warning and debugging flags for development
137              (if supported by the OPTFILE); also switch to IEEE numerics.
138        -gsl | --gsl
139              Use GSL to control floating point rounding and precision
140    
141        -mpi | --mpi
142              Include MPI header files and link to MPI libraries
143        -mpi=PATH | --mpi=PATH
144              Include MPI header files and link to MPI libraries using MPI_ROOT
145              set to PATH. i.e. Include files from \$PATH/include, link to libraries
146              from \$PATH/lib and use binaries from \$PATH/bin.
147    
148        -omp | --omp
149              Activate OpenMP code + use Compiler option OMPFLAG
150        -omp=OMPFLAG | --omp=OMPFLAG
151              Activate OpenMP code + use Compiler option OMPFLAG
152    
153        -es | --es | -embed-source | --embed-source
154              Embed a tarball containing the full source code
155              (including the Makefile, etc.) used to build the
156              executable [off by default]
157    
158        -ds | --ds
159              Report genmake internal variables status (DUMPSTATE)
160              to file "genmake_state" (for debug purpose)
161    
162      While it is most often a single word, the "NAME" variables specified
163      above can in many cases be a space-delimited string such as:
164    
165        --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'
166        -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'
167        -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
168    
169      which, depending upon your shell, may need to be single-quoted.
170    
171      For more detailed genmake documentation, please see:
172    
173        http://mitgcm.org/public/devel_HOWTO/
174    
175    EOF
176    
177        exit 1
178    }
179    
180  # Search for particular CPP #cmds associated with packages  # Search for particular CPP #cmds associated with packages
181  # usage: test_for_package_in_cpp_options CPP_file package_name  # usage: test_for_package_in_cpp_options CPP_file package_name
182  test_for_package_in_cpp_options() {  test_for_package_in_cpp_options() {
183      cpp_options=$1      cpp_options=$1
184      pkg=$2      pkg=$2
185      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg[ ]"      test_for_string_in_file $cpp_options "^ *# *define *\<ALLOW_$pkg\>"
186      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg[ ]"      test_for_string_in_file $cpp_options "^ *# *undef *\<ALLOW_$pkg\>"
187      test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg[ ]"      test_for_string_in_file $cpp_options "^ *# *define *\<DISABLE_$pkg\>"
188      test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg[ ]"      test_for_string_in_file $cpp_options "^ *# *undef *\<DISABLE_$pkg\>"
     test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg$"  
     test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg$"  
     test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg$"  
     test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg$"  
189  }  }
190    
191  # Search for particular CPP #cmds associated with MPI  # Search for particular CPP #cmds associated with MPI
192  # usage: test_for_mpi_in_cpp_eeoptions CPP_file  # usage: test_for_mpi_in_cpp_eeoptions CPP_file
193  test_for_mpi_in_cpp_eeoptions() {  test_for_mpi_in_cpp_eeoptions() {
194      cpp_options=$1      cpp_options=$1
195      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI[ ]"      test_for_string_in_file $cpp_options "^ *# *define *\<ALLOW_USE_MPI\>"
196      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI[ ]"      test_for_string_in_file $cpp_options "^ *# *undef *\<ALLOW_USE_MPI\>"
     test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI[ ]"  
     test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI[ ]"  
     test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI$"  
     test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI$"  
     test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI$"  
     test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI$"  
197  }  }
198    
199  # 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 42  test_for_mpi_in_cpp_eeoptions() { Line 201  test_for_mpi_in_cpp_eeoptions() {
201  test_for_string_in_file() {  test_for_string_in_file() {
202      file=$1      file=$1
203      strng=$2      strng=$2
204      grep -i "$strng" $file > /dev/null 2>&1      grep "$strng" $file > /dev/null 2>&1
205      RETVAL=$?      RETVAL=$?
206      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
207          printf "Error: In $file there is an illegal line: "          printf "Error: In $file there is an illegal line: "
208          grep -i "$strng" $file          grep -i "$strng" $file
209          exit 99          exit 99
210      fi      fi
211      return 0      return 0
# Line 56  test_for_string_in_file() { Line 215  test_for_string_in_file() {
215  # the package list.  # the package list.
216  expand_pkg_groups() {  expand_pkg_groups() {
217      new_packages=      new_packages=
     PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups"  
218      if test -r $PKG_GROUPS ; then      if test -r $PKG_GROUPS ; then
219          cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp          cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > $TMP.p1
220          cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp          cat $TMP.p1 | $AWK '(NF>2 && $2==":"){ print $0 }' > $TMP.p2
221          matched=0          matched=0
222          for i in $PACKAGES ; do          for i in $PACKAGES ; do
223              line=`grep "^ *$i" ./p2.tmp`              line=`grep "^ *$i" $TMP.p2`
224              RETVAL=$?              RETVAL=$?
225              if test "x$RETVAL" = x0 ; then              if test "x$RETVAL" = x0 ; then
226                  matched=1                  matched=1
227                  replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`                  replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`
228                  echo "    replacing \"$i\" with: $replace"                  echo "    replacing \"$i\" with:$replace"
229                  new_packages="$new_packages $replace"                  new_packages="$new_packages $replace"
230              else              else
231                  new_packages="$new_packages $i"                  new_packages="$new_packages $i"
232              fi              fi
233          done          done
234          PACKAGES=$new_packages          PACKAGES=$new_packages
235          rm -f ./p[1,2].tmp          rm -f $TMP.p[1,2]
236          return $matched          return $matched
237      else      else
238          echo "Warning: can't read package groups definition file: $PKG_GROUPS"          echo "Warning: can't read package groups definition file: $PKG_GROUPS"
# Line 110  EOF Line 268  EOF
268              check_for_broken_Ff              check_for_broken_Ff
269          else          else
270              cat <<EOF 2>&1              cat <<EOF 2>&1
271  ERROR: Your file system cannot distinguish between *.F and *.f files  ERROR: Your file system cannot distinguish between *.F and *.f files
272    (fails the "cp" test) and this program cannot find a suitable    (fails the "cp" test) and this program cannot find a suitable
273    replacement extension.  Please try a different build environment or    replacement extension.  Please try a different build environment or
274    contact the <MITgcm-support@mitgcm.org> list for help.    contact the <MITgcm-support@mitgcm.org> list for help.
275    
276  EOF  EOF
# Line 137  EOF Line 295  EOF
295  .F.$tfs:  .F.$tfs:
296          $LN \$< \$@          $LN \$< \$@
297  EOF  EOF
298      $MAKE "genmake_hello."$tfs > /dev/null 2>&1      $MAKE -f $MAKEFILE "genmake_hello."$tfs > /dev/null 2>&1
299      RETVAL=$?      RETVAL=$?
300      if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then      if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then
301          if test "x$FS" = x ; then          if test "x$FS" = x ; then
# Line 145  EOF Line 303  EOF
303              FS90='fr9'              FS90='fr9'
304              check_for_broken_Ff              check_for_broken_Ff
305          else          else
306              cat <<EOF 2>&1              echo "ERROR: test: '$MAKE -f $MAKEFILE genmake_hello.$tfs' Failed"
307  ERROR: Your file system cannot distinguish between *.F and *.f files              echo "       see simple makefile: '$MAKEFILE' (left here)"
308    (fails the "make/ln" test) and this program cannot find a suitable              echo "  Please check (1) your '$MAKE' command, (2) your '$LN' command"
309    replacement extension.  Please try a different build environment or              echo "           and (3) the allowed sufix '.F' and '.$tfs' in makefile"
310    contact the <MITgcm-support@mitgcm.org> list for help.              echo "  or contact the <MITgcm-support@mitgcm.org> list for help."
311                echo ""
 EOF  
312              exit -1              exit -1
313              return              return
314          fi          fi
# Line 165  EOF Line 322  EOF
322      return      return
323  }  }
324    
   
325  look_for_makedepend()  {  look_for_makedepend()  {
326    
327      #  The "original" makedepend is part of the Imake system that is      #  The "original" makedepend is part of the Imake system that is
# Line 176  look_for_makedepend()  { Line 332  look_for_makedepend()  {
332      #      #
333      #    1) a makedepend implementation shipped with the cyrus-imapd      #    1) a makedepend implementation shipped with the cyrus-imapd
334      #       package:  ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/      #       package:  ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
335      #      #    2) a local tools/xmakedepend shell script
     #    2) a known-buggy xmakedpend shell script  
336      #      #
337      #  So the choices are, in order:      #  So the choices are, in order:
     #  
338      #    1) use the user-specified program      #    1) use the user-specified program
339      #    2) use a system-wide default      #    2) use the local xmakedepend script (get all dependencies, but slower)
340      #    3) locally build and use the cyrus implementation      #    3) use a system-wide default
341      #    4) fall back to the buggy local xmakedpend script      #    4) locally build and use the cyrus makedepend
342        #             (faster, but can miss some dependencies)
343      #      #
344        echo >> $LOGFILE
345        echo "running: look_for_makedepend()" >> $LOGFILE
346        if test "x${MAKEDEPEND}" != x ; then
347            echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1
348            RETVAL=$?
349            if test x"$RETVAL" = x0 ; then
350                build_cyrus_makedepend
351                RETVAL=$?
352                if test "x$RETVAL" != x0 ; then
353                    echo "WARNING: unable to build cyrus-makedepend. Try other 'makedepend'"
354                    MAKEDEPEND=
355                fi
356            else
357                echo "${MAKEDEPEND}" | grep 'tools.xmakedepend' > /dev/null 2>&1
358                RETVAL=$?
359                if test "x$RETVAL" = x0 ; then
360                    MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
361                fi
362                echo " -->     MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
363            fi
364        fi
365      if test "x${MAKEDEPEND}" = x ; then      if test "x${MAKEDEPEND}" = x ; then
         which makedepend > /dev/null 2>&1  
         RV0=$?  
366          test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"          test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
367          #  echo 'MAKEFILE="'$MAKEFILE'"'          #  echo 'MAKEFILE="'$MAKEFILE'"'
368          cat <<EOF >> $MAKEFILE          cat <<EOF >> $MAKEFILE
369  #   THIS IS A TEST MAKEFILE GENERATED BY "genmake2"  #   THIS IS A TEST MAKEFILE GENERATED BY "genmake2"
370  #  #
371  #   Some "makedepend" implementations will die if they cannot  #   Some "makedepend" implementations will die if they cannot
372  #   find a Makefile -- so this file is here to gives them an  #   find a Makefile -- so this file is here to gives them an
373  #   empty one to find and parse.  #   empty one to find and parse.
374  EOF  EOF
375          cat <<EOF >> genmake_tc.f          cat <<EOF >> genmake_tc.f
# Line 204  EOF Line 378  EOF
378        stop        stop
379        end        end
380  EOF  EOF
381          makedepend genmake_tc.f > /dev/null 2>&1          $ROOTDIR/tools/xmakedepend -f $MAKEFILE genmake_tc.f > /dev/null 2>&1
382          RV1=$?          RV1=$?
383            which makedepend > /dev/null 2>&1
384            RV2=$?
385            if test "x${RV2}" = x0 ; then
386                makedepend -f $MAKEFILE genmake_tc.f > /dev/null 2>&1
387                RV3=$? ; loc_msg='not working.'
388            else RV3=$RV2 ; loc_msg='not found.'
389            fi
390          test -f $MAKEFILE  &&  rm -f $MAKEFILE          test -f $MAKEFILE  &&  rm -f $MAKEFILE
391          test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE          test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
392          if test "x${RV0}${RV1}" = x00 ; then          echo "  check makedepend (local: $RV1, system: $RV2, $RV3)"
393            if test "x${RV1}" = x0 ; then
394                MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
395                echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
396            elif test "x${RV3}" = x0 ; then
397                echo "    local tools/xmakedepend not working. Use system-default makedepend"
398              MAKEDEPEND=makedepend              MAKEDEPEND=makedepend
399                echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
400          else          else
401              echo "    a system-default makedepend was not found."              echo "    local tools/xmakedepend not working; system-default makedepend $loc_msg"
402                            echo -n "    Try to build cyrus-makedepend ..."
403              #  Try to build the cyrus implementation              #  Try to build the cyrus implementation
404              build_cyrus_makedepend              build_cyrus_makedepend
405              RETVAL=$?              RETVAL=$?
406              if test "x$RETVAL" != x0 ; then              if test "x$RETVAL" = x0 ; then
407                  MAKEDEPEND='$(TOOLSDIR)/xmakedepend'                  echo "  Works"
408                else
409                    echo "  Fails" ; echo "" >> $LOGFILE
410                    echo "ERROR: no working makedepend found ; look_for_makedepend FAILED" | tee -a $LOGFILE
411                    echo ""
412                    exit -1
413                    return
414              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  
415          fi          fi
416      fi      fi
417  }  }
418    
   
419  build_cyrus_makedepend()  {  build_cyrus_makedepend()  {
420        echo >> $LOGFILE
421        echo "running: build_cyrus_makedepend()" >> $LOGFILE
422      rm -f ./genmake_cy_md      rm -f ./genmake_cy_md
423      (      (
424          cd $ROOTDIR/tools/cyrus-imapd-makedepend  \          cd $ROOTDIR/tools/cyrus-imapd-makedepend  \
425              &&  ./configure > /dev/null 2>&1  \              &&  ./configure > /dev/null 2>&1  \
426              &&  make > /dev/null 2>&1              &&  $MAKE > /dev/null 2>&1
427          if test -x ./makedepend.exe ; then          if test -x ./makedepend.exe ; then
428              $LN ./makedepend.exe ./makedepend              $LN ./makedepend.exe ./makedepend
429          fi          fi
# Line 249  build_cyrus_makedepend()  { Line 435  build_cyrus_makedepend()  {
435      rm -f ./genmake_cy_md      rm -f ./genmake_cy_md
436      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
437          MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'          MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
438            echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
439          return 0          return 0
440      else      else
441          echo "WARNING: unable to build cyrus-imapd-makedepend"          echo "WARNING: fail to build cyrus-imapd-makedepend" >> $LOGFILE
442          return 1          return 1
443      fi      fi
444  }  }
445    
   
446  build_embed_encode()  build_embed_encode()
447  {  {
448      printf "  building the embed-encode utility...  "      printf "  building the embed-encode utility...  "
449      if test ! -e "$ROOTDIR/tools/embed_encode/encode_files" ; then      if test ! -e "$ROOTDIR/tools/embed_encode/encode_files" ; then
450          if test ! -d "$ROOTDIR/tools/embed_encode" ; then          if test ! -d "$ROOTDIR/tools/embed_encode" ; then
451              echo              echo
452              echo "    Error: can't locate \"$ROOTDIR/tools/embed_encode\""              echo "    Error: can't locate \"$ROOTDIR/tools/embed_encode\""
453              echo              echo
454              EMBED_SRC=f              EMBED_SRC=f
455              return 1              return 1
456          fi          fi
457          clist="cc gcc c89 $CC"          clist="cc gcc c89 $CC"
458          for ic in $clist ; do          for ic in $clist ; do
459              comm="$ic -o encode_files encode_files.c"              comm="$ic -o encode_files encode_files.c"
460              ( cd $ROOTDIR/tools/embed_encode && $comm ) > /dev/null 2>&1              ( cd $ROOTDIR/tools/embed_encode && $comm ) > /dev/null 2>&1
461              RETVAL=$?              RETVAL=$?
462              if test "x$RETVAL" = x0 ; then              if test "x$RETVAL" = x0 ; then
463                  echo "OK"                  echo "OK"
                 DEFINES="$DEFINES -DHAVE_EMBED_SRC"  
464                  return 0                  return 0
465              fi              fi
466          done          done
# Line 287  build_embed_encode() Line 472  build_embed_encode()
472          return 1          return 1
473      fi      fi
474      echo "OK"      echo "OK"
     DEFINES="$DEFINES -DHAVE_EMBED_SRC"  
475  }  }
476    
477    #  look for possible C compilers
478  # Guess possible config options for this host  look_for_C_compilers() {
479  find_possible_configs()  {      echo >> $LOGFILE
480        echo "running: look_for_C_compilers()" >> $LOGFILE
481      tmp1=`uname`"_"`uname -m`      rm -f ./genmake_hello.c  ./genmake_hello
482      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`      cat >> genmake_hello.c << EOF
     tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`  
     tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`  
     tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`  
     tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`  
     PLATFORM=$tmp3  
     echo $PLATFORM | grep cygwin > /dev/null 2>&1  &&  PLATFORM=cygwin_ia32  
     OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`  
     echo "  The platform appears to be:  $PLATFORM"  
       
     echo "test" > test  
     ln -s ./test link  
     RETVAL=$?  
     if test "x${RETVAL}" = x0 ; then  
         LN="ln -s"  
     else  
         echo "Error: \"ln -s\" does not appear to work on this system!"  
         echo "  For help, please contact <MITgcm-support@mitgcm.org>."  
         exit 1  
     fi  
     rm -f test link  
   
     if test "x$CPP" = x ; then  
         CPP="cpp -traditional -P"  
     fi  
   
     look_for_makedepend  
   
     #================================================================  
     #  look for possible C compilers  
     tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc icc"  
     p_CC=  
     for c in $tmp ; do  
         rm -f ./genmake_hello.c  ./genmake_hello  
         cat >> genmake_hello.c << EOF  
483  #include <stdio.h>  #include <stdio.h>
484  int main(int argc, char **argv) {  int main(int argc, char **argv) {
485    printf("Hello!\n");    printf("Hello!\n");
486    return 0;    return 0;
487  }  }
488  EOF  EOF
489          $c -o genmake_hello genmake_hello.c > /dev/null 2>&1      tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc icc"
490        p_CC=
491        for c in $tmp ; do
492            COMM="$c $CFLAGS -o genmake_hello genmake_hello.c"
493            echo $COMM >> $LOGFILE
494            $COMM >> $LOGFILE 2>&1
495          RETVAL=$?          RETVAL=$?
496          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
497                echo " $c test successful" >> $LOGFILE
498              p_CC="$p_CC $c"              p_CC="$p_CC $c"
499          fi          fi
500      done      done
# Line 354  Error: No C compilers were found in your Line 510  Error: No C compilers were found in your
510  EOF  EOF
511          exit 1          exit 1
512      else      else
513          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  
514          if test "x$CC" = x ; then          if test "x$CC" = x ; then
515              CC=`echo $p_CC | $AWK '{print $1}'`              CC=`echo $p_CC | $AWK '{print $1}'`
516              echo "  Setting C compiler to: "$CC              echo "  Setting C compiler to: "$CC
517          fi          fi
518      fi      fi
519        echo " --> set CC='$CC'" >> $LOGFILE
520    }
521    
522    # Guess possible config options for this host
523    find_possible_optfile()  {
524    
525        echo >> $LOGFILE
526        echo "running: find_possible_optfile()" >> $LOGFILE
527        tmp1=`uname`"_"`uname -m`
528        tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
529        tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
530        tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
531        tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
532        tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
533        PLATFORM=$tmp3
534        echo $PLATFORM | grep cygwin > /dev/null 2>&1  &&  PLATFORM=cygwin_ia32
535        OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
536        echo "  The platform appears to be:  $PLATFORM" | tee -a $LOGFILE
537    
538      #================================================================      #================================================================
539      #  look for possible FORTRAN compilers      #  look for possible FORTRAN compilers
540      tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc ifort f90 f95 mpif77 mpf77 mpxlf95 gfortran g95"      echo "  look for possible FORTRAN compilers" >> $LOGFILE
541        tmp="$MITGCM_FC $FC efc gfortran g77 f77 pgf77 pgf95 ifc ifort f90 f95 mpif77 mpf77 mpxlf95 g95"
542      p_FC=      p_FC=
543      for c in $tmp ; do      rm -f ./genmake_hello.f
544          rm -f ./hello.f ./hello      cat >> genmake_hello.f <<EOF
         cat >> hello.f <<EOF  
545        program hello        program hello
546        do i=1,3        do i=1,3
547          print *, 'hello world : ', i          print *, 'hello world : ', i
548        enddo        enddo
549        end        end
550  EOF  EOF
551          $c -o hello hello.f > /dev/null 2>&1      for f in $tmp ; do
552            COMM="$f -o genmake_hello genmake_hello.f"
553            echo $COMM >> $LOGFILE
554            $COMM >> $LOGFILE 2>&1
555          RETVAL=$?          RETVAL=$?
556          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
557              p_FC="$p_FC $c"              echo " $f test successful" >> $LOGFILE
558                p_FC="$p_FC $f"
559          fi          fi
560      done      done
561      rm -f ./hello.f ./hello      rm -f ./genmake_hello.f ./genmake_hello
562      if test "x${p_FC}" = x ; then      if test "x${p_FC}" = x ; then
563          cat 1>&2 <<EOF          cat 1>&2 <<EOF
564    
# Line 394  Error: No Fortran compilers were found i Line 571  Error: No Fortran compilers were found i
571  EOF  EOF
572          exit 1          exit 1
573      else      else
574          echo "  The possible FORTRAN compilers found in your path are:"          echo "  The possible FORTRAN compilers found in your path are: $p_FC" | tee -a $LOGFILE
         echo "   "$p_FC  
575      fi      fi
576    
577      #  Use the first of the compilers found in the current PATH      #  Use the first of the compilers found in the current PATH
# Line 404  EOF Line 580  EOF
580          for i in $p_FC ; do          for i in $p_FC ; do
581              OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i              OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
582              if test -r $OPTFILE ; then              if test -r $OPTFILE ; then
583                  echo "  Setting OPTFILE to: "$OPTFILE                  echo "  Setting OPTFILE to: "$OPTFILE | tee -a $LOGFILE
584                  break                  break
585              fi              fi
586          done          done
# Line 413  EOF Line 589  EOF
589      if test "x$OPTFILE" = x ; then      if test "x$OPTFILE" = x ; then
590          OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC          OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
591          if test ! -r $OPTFILE ; then          if test ! -r $OPTFILE ; then
592               echo "  I looked for the file "$OPTFILE" but did not find it"               echo "  I looked for the file "$OPTFILE" but did not find it"
593          fi          fi
594      fi      fi
595  #    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  
596      if test "x$OPTFILE" = x ; then      if test "x$OPTFILE" = x ; then
597          cat 1>&2 <<EOF          cat 1>&2 <<EOF
598    
# Line 442  Error: No options file was found in:  $R Line 608  Error: No options file was found in:  $R
608  EOF  EOF
609          exit 1          exit 1
610      fi      fi
611        }
612  #     # look for possible MPI libraries  
613  #     mpi_libs=  #  Do a local copy of MPI headers files (in local dir ./mpi_headers/) after
614  #     mpi_fort=`which mpif77 2>/dev/null`  #  checking for additional included headers (in case of chain of included header)
615  #     RETVAL=$?  mpi_headers_do_local_copy() {
616  #     if test "x${RETVAL}" = x0 ; then  
617  #       cat >>test.f <<EOF      dBug=0
618  #       PROGRAM HELLO      rm -rf ./mpi_headers
619  #       DO 10, I=1,10      if test -d $MPIINCLUDEDIR ; then
620  #       PRINT *,'Hello World'  
621  #    10 CONTINUE          #----- check for additional headers (chain of included headers)
622  #       STOP          echo -n '  Check MPI headers ... '
623  #       END          listIni=$MPI_HEADER_FILES
624  # EOF          echo $listIni | grep "\<mpif.h\>" > /dev/null 2>&1
625  #       eval "$mpi_fort -showme test.f > out"          outp=$?
626  #       RETVAL=$?          #- always check mpif.h (the only mpi-header included in standard MITgcm code)
627  #       if test "x${RETVAL}" = x0 ; then          if test $outp != 0 ; then listIni="mpif.h $listIni" ; fi
628  #           a=`cat out`          if test $dBug = 1 ; then echo "listIni='$listIni'" ; fi
629  #           for i in $a ; do  
630  #               case $i in          doCheck=1 ; list2copy='' ; list2check=$listIni
631  #                   -*)          while test $doCheck = 1 ; do
632  #                       mpi_libs="$mpi_libs $i" ;;            newList=''
633  #               esac            for i in $list2check ; do
634  #           done              if test -f $MPIINCLUDEDIR/$i ; then
635  #           echo "The MPI libs appear to be:"                newInc=`grep '^ *include ' $MPIINCLUDEDIR/$i | \
636  #           echo "  "$mpi_libs                  sed -e 's/^ *include //' -e 's/\!.*$//' -e "s/'//g"  -e 's/\"//g'`
637  #       fi                if test $dBug = 1 ; then echo -n "checking $i : newInc='$newInc'" ; fi
638  #       rm -f test.f out                for j in $newInc ; do
639  #     fi                  echo $listIni $list2copy $newList | grep "\<$j\>" > /dev/null 2>&1
640                    outp=$?
641                    if test $outp != 0 ; then
642                      if test $dBug = 1 ; then echo -n " ; adding $j" ; fi
643                      newList="$newList $j"
644                    fi
645                  done
646                  if test $dBug = 1 ; then echo "" ; fi
647                fi
648              done
649              if test "x$newList" = x ; then doCheck=0
650              else list2check=$newList ; list2copy="$list2copy $newList"
651              fi
652            done
653            list2copy="$MPI_HEADER_FILES $list2copy"
654            if test $dBug = 1 ; then echo "list2copy='$list2copy'" ; fi
655    
656            #----- create local mpi_headers dir if we have files to copy
657            mkListInc=`echo $list2copy | wc -w`
658            if test $mkListInc != 0 ; then
659              echo 'create local "./mpi_headers" dir'
660              mkdir -p ./mpi_headers
661              INCLUDES="-I./mpi_headers $INCLUDES"
662              mkListInc=1
663            fi
664            if test "x$LOCAL_MPI_HEADERS" != x ; then mkListInc=0 ; fi
665    
666            #----- make local copy and update LOCAL_MPI_HEADERS (if not already set)
667            for i in $list2copy ; do
668              if test -f $MPIINCLUDEDIR/$i ; then
669                cp -p $MPIINCLUDEDIR/$i ./mpi_headers
670                if test $i = 'mpif.h' ; then
671                    perl -i -pe 's/MPI_DISPLACEMENT_CURRENT=-1_8/MPI_DISPLACEMENT_CURRENT=-1/g' mpi_headers/mpif.h
672                fi
673                if test $mkListInc = 2 ; then
674                    LOCAL_MPI_HEADERS="$LOCAL_MPI_HEADERS ./mpi_headers/$i"
675                fi
676                if test $mkListInc = 1 ; then
677                    LOCAL_MPI_HEADERS="./mpi_headers/$i" ; mkListInc=2
678                fi
679              fi
680            done
681        else
682            echo "WARNING: MPIINCLUDEDIR='$MPIINCLUDEDIR' is not a directory"
683            echo "WARNING: => skip checking for MPI headers (no ./mpi_headers dir)"
684    #       exit -1
685        fi
686  }  }
687    
688  #  Parse the package dependency information  #  Parse the package dependency information
# Line 480  get_pdepend_list()  { Line 691  get_pdepend_list()  {
691      #  strip the comments and then convert the dependency file into      #  strip the comments and then convert the dependency file into
692      #  two arrays: PNAME, DNAME      #  two arrays: PNAME, DNAME
693      cat $1 | sed -e 's/#.*$//g' \      cat $1 | sed -e 's/#.*$//g' \
694          | $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}' \
695          > ./.pd_tmp          > ./.pd_tmp
696        RETVAL=$?
697        if test ! "x${RETVAL}" = x0 ; then
698          echo "Error: unable to parse package dependencies -- please check PKG_DEPEND=\"$1\""
699          exit 1
700        fi
701      . ./.pd_tmp      . ./.pd_tmp
702      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.  
   
     -ignoretime | -ignore_time | --ignoretime | --ignore_time  
           Ignore all the "wall clock" routines entirely.  This will  
           not in any way hurt the model results -- it simply means  
           that the code that checks how long the model spends in  
           various routines will give junk values.  
   
     -ts | --ts  
           Produce timing information per timestep  
     -papis | --papis  
           Produce summary MFlop/s (and IPC) with PAPI per timestep  
     -pcls | --pcls  
           Produce summary MFlop/s etc. with PCL per timestep  
     -foolad | --foolad  
           Fool the AD code generator  
     -papi | --papi  
           Performance analysis with PAPI  
     -pcl | --pcl  
           Performance analysis with PCL  
     -hpmt | --hpmt  
           Performance analysis with the HPM Toolkit  
   
     -gsl | --gsl  
           Use GSL to control floating point rounding and precision  
     -devel | --devel  
           Add additional warning and debugging flags for development  
   
     -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.  
   
     -es | --es | -embed-source | --embed-source  
           Embed a tarball containing the full source code  
           (including the Makefile, etc.) used to build the  
           executable [off by default]  
   
     -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  
703  }  }
704    
705  #  Build a CPP macro to automate calling C routines from FORTRAN  #  Build a CPP macro to automate calling C routines from FORTRAN
# Line 642  get_fortran_c_namemangling()  { Line 707  get_fortran_c_namemangling()  {
707    
708      #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""      #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
709      if test ! "x$FC_NAMEMANGLE" = x ; then      if test ! "x$FC_NAMEMANGLE" = x ; then
710          return 0          return 0
711      fi      fi
712        echo " running: get_fortran_c_namemangling()" >> $LOGFILE
713    
714      default_nm="#define FC_NAMEMANGLE(X) X ## _"      default_nm="#define FC_NAMEMANGLE(X) X ## _"
715        
716      cat > genmake_test.c <<EOF      cat > genmake_test.c <<EOF
717  void tcall( char * string ) { tsub( string ); }  void tcall( char * string ) { tsub( string ); }
718  EOF  EOF
719      $MAKE genmake_test.o >> genmake_warnings 2>&1      COMM="$CC $CFLAGS -c genmake_test.c"
720        echo ' '$COMM >> $LOGFILE
721        $COMM >> $LOGFILE 2>&1
722      RETVAL=$?      RETVAL=$?
723      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
724          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
725          cat <<EOF>> genmake_errors          cat <<EOF>> $LOGFILE
726    
727  WARNING: C test compile fails   WARNING: C test compile fails
728  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
729  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here   WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
730  EOF  EOF
731          return 1          return 1
732      fi      fi
# Line 666  EOF Line 734  EOF
734      RETVAL=$?      RETVAL=$?
735      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
736          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
737          cat <<EOF>> genmake_warnings          cat <<EOF>> $LOGFILE
738    
739  WARNING: The "nm" command failed.   WARNING: The "nm" command failed.
740  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
741  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here   WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
742  EOF  EOF
743          return 1          return 1
744      fi      fi
# Line 680  EOF Line 748  EOF
748        call tsub( string )        call tsub( string )
749        end        end
750  EOF  EOF
751      $FC $FFLAGS -c genmake_tcomp.$FS >> genmake_warnings 2>&1      COMM="$FC $FFLAGS -c genmake_tcomp.$FS"
752        echo ' '$COMM >> $LOGFILE
753        $COMM >> $LOGFILE 2>&1
754      RETVAL=$?      RETVAL=$?
755      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
756          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
757          cat <<EOF>> genmake_warnings          cat <<EOF>> $LOGFILE
758    
759  WARNING: FORTRAN test compile fails -- please see "genmake_errors"   WARNING: FORTRAN test compile fails -- please see '$LOGFILE'
760  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
761  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.   WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
762  EOF  EOF
763          return 1          return 1
764      fi      fi
# Line 696  EOF Line 766  EOF
766      RETVAL=$?      RETVAL=$?
767      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
768          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
769          cat <<EOF>> genmake_warnings          cat <<EOF>> $LOGFILE
770    
771  WARNING: The "nm" command failed.   WARNING: The "nm" command failed.
772  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
773  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.   WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
774  EOF  EOF
775          return 1          return 1
776      fi      fi
# Line 726  EOF Line 796  EOF
796    
797      #  cleanup the testing files      #  cleanup the testing files
798      rm -f genmake_tcomp.* genmake_test.*      rm -f genmake_tcomp.* genmake_test.*
 }  
799    
800        echo " --> set FC_NAMEMANGLE='$FC_NAMEMANGLE'" >> $LOGFILE
801    }
802    
803  check_HAVE_CLOC()  {  check_HAVE_CLOC()  {
804        echo >> $LOGFILE
805        echo "running: check_HAVE_CLOC()" >> $LOGFILE
806      get_fortran_c_namemangling      get_fortran_c_namemangling
807      cat <<EOF > genmake_tc_1.c      cat <<EOF > genmake_tc_1.c
808  $FC_NAMEMANGLE  $FC_NAMEMANGLE
# Line 747  void FC_NAMEMANGLE(cloc) ( double *curti Line 820  void FC_NAMEMANGLE(cloc) ( double *curti
820  }  }
821  EOF  EOF
822      COMM="$CC $CFLAGS -c genmake_tc_1.c"      COMM="$CC $CFLAGS -c genmake_tc_1.c"
823      echo $COMM >> genmake_warnings      echo $COMM >> $LOGFILE
824      $COMM >> genmake_warnings 2>&1      $COMM >> $LOGFILE 2>&1
825      RET_C=$?      RET_C=$?
826      cat <<EOF > genmake_tc_2.$FS      cat <<EOF > genmake_tc_2.$FS
827        program hello        program hello
# Line 759  EOF Line 832  EOF
832        end        end
833  EOF  EOF
834      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
835      echo $COMM >> genmake_warnings      echo $COMM >> $LOGFILE
836      $COMM >> genmake_warnings 2>&1      $COMM >> $LOGFILE 2>&1
837      RET_F=$?      RET_F=$?
838      test -x ./genmake_tc  &&  ./genmake_tc >> genmake_warnings 2>&1      test -x ./genmake_tc  &&  ./genmake_tc >> $LOGFILE 2>&1
839      RETVAL=$?      RETVAL=$?
840      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
841          HAVE_CLOC=t          HAVE_CLOC=t
         DEFINES="$DEFINES -DHAVE_CLOC"  
842      fi      fi
843      rm -f genmake_tc*      rm -f genmake_tc*
844        echo " --> set HAVE_CLOC='$HAVE_CLOC'" >> $LOGFILE
845  }  }
846    
   
847  check_HAVE_SIGREG()  {  check_HAVE_SIGREG()  {
848      if test ! "x$HAVE_SIGREG" = x ; then      if test ! "x$HAVE_SIGREG" = x ; then
849          return          return
850      fi      fi
851        echo >> $LOGFILE
852        echo "running: check_HAVE_SIGREG()" >> $LOGFILE
853      get_fortran_c_namemangling      get_fortran_c_namemangling
854      cat <<EOF > genmake_tc_1.c      cat <<EOF > genmake_tc_1.c
855  $FC_NAMEMANGLE  $FC_NAMEMANGLE
# Line 808  void FC_NAMEMANGLE(sigreg) (int * aip) Line 882  void FC_NAMEMANGLE(sigreg) (int * aip)
882  }  }
883  EOF  EOF
884      COMM="$CC $CFLAGS -c genmake_tc_1.c"      COMM="$CC $CFLAGS -c genmake_tc_1.c"
885      echo $COMM >> genmake_warnings      echo $COMM >> $LOGFILE
886      $COMM >> genmake_warnings 2>&1      $COMM >> $LOGFILE 2>&1
887      RET_C=$?      RET_C=$?
888      cat <<EOF > genmake_tc_2.$FS      cat <<EOF > genmake_tc_2.$FS
889        program hello        program hello
# Line 819  EOF Line 893  EOF
893        call sigreg(anint)        call sigreg(anint)
894        end        end
895  EOF  EOF
896      echo >> genmake_warnings      cat genmake_tc_2.$FS >> $LOGFILE
     echo "running: check_HAVE_SIGREG()" >> genmake_warnings  
     cat genmake_tc_2.$FS >> genmake_warnings  
897      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
898      echo $COMM >> genmake_warnings      echo $COMM >> $LOGFILE
899      $COMM >> genmake_warnings 2>&1      $COMM >> $LOGFILE 2>&1
900      RETVAL=$?      RETVAL=$?
901      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
902          HAVE_SIGREG=t          HAVE_SIGREG=t
         DEFINES="$DEFINES -DHAVE_SIGREG"  
903      fi      fi
904      rm -f genmake_tc*      rm -f genmake_tc*
905        echo " --> set HAVE_SIGREG='$HAVE_SIGREG'" >> $LOGFILE
906  }  }
907    
   
908  check_HAVE_SETRLSTK()  {  check_HAVE_SETRLSTK()  {
     if test "x$HAVE_SETRLSTK" = xt ; then  
         DEFINES="$DEFINES -DHAVE_SETRLSTK"  
         return  
     fi    
909      if test ! "x$HAVE_SETRLSTK" = x ; then      if test ! "x$HAVE_SETRLSTK" = x ; then
910          return          return
911      fi      fi
912        echo >> $LOGFILE
913        echo "running: check_HAVE_SETRLSTK()" >> $LOGFILE
914      get_fortran_c_namemangling      get_fortran_c_namemangling
915      cat <<EOF > genmake_tc_1.c      cat <<EOF > genmake_tc_1.c
916  $FC_NAMEMANGLE  $FC_NAMEMANGLE
# Line 858  void FC_NAMEMANGLE(setrlstk) () Line 927  void FC_NAMEMANGLE(setrlstk) ()
927  }  }
928  EOF  EOF
929      COMM="$CC $CFLAGS -c genmake_tc_1.c"      COMM="$CC $CFLAGS -c genmake_tc_1.c"
930      echo $COMM >> genmake_warnings      echo $COMM >> $LOGFILE
931      $COMM >> genmake_warnings 2>&1      $COMM >> $LOGFILE 2>&1
932      RET_C=$?      RET_C=$?
933      cat <<EOF > genmake_tc_2.$FS      cat <<EOF > genmake_tc_2.$FS
934        program hello        program hello
# Line 867  EOF Line 936  EOF
936        call setrlstk()        call setrlstk()
937        end        end
938  EOF  EOF
939      echo >> genmake_warnings      cat genmake_tc_2.$FS >> $LOGFILE
     echo "running: check_HAVE_SETRLSTK()" >> genmake_warnings  
     cat genmake_tc_2.$FS >> genmake_warnings  
940      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
941      echo $COMM >> genmake_warnings      echo $COMM >> $LOGFILE
942      $COMM >> genmake_warnings 2>&1      $COMM >> $LOGFILE 2>&1
943      RETVAL=$?      RETVAL=$?
944      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
945          HAVE_SETRLSTK=t          HAVE_SETRLSTK=t
         DEFINES="$DEFINES -DHAVE_SETRLSTK"  
946      fi      fi
947      rm -f genmake_tc*      rm -f genmake_tc*
948        echo " --> set HAVE_SETRLSTK='$HAVE_SETRLSTK'" >> $LOGFILE
949  }  }
950    
   
951  check_HAVE_STAT()  {  check_HAVE_STAT()  {
952        echo >> $LOGFILE
953        echo "running: check_HAVE_STAT()" >> $LOGFILE
954      get_fortran_c_namemangling      get_fortran_c_namemangling
955      cat <<EOF > genmake_tc_1.c      cat <<EOF > genmake_tc_1.c
956  $FC_NAMEMANGLE  $FC_NAMEMANGLE
# Line 904  void FC_NAMEMANGLE(tfsize) ( int *nbyte Line 972  void FC_NAMEMANGLE(tfsize) ( int *nbyte
972  }  }
973  EOF  EOF
974      COMM="$CC $CFLAGS -c genmake_tc_1.c"      COMM="$CC $CFLAGS -c genmake_tc_1.c"
975      echo $COMM >> genmake_warnings      echo $COMM >> $LOGFILE
976      $COMM >> genmake_tc.log 2>&1      $COMM >> genmake_tc.log 2>&1
977      RET_C=$?      RET_C=$?
978      cat <<EOF > genmake_tc_2.$FS      cat <<EOF > genmake_tc_2.$FS
# Line 914  EOF Line 982  EOF
982        print *," HELLO WORLD", nbyte        print *," HELLO WORLD", nbyte
983        end        end
984  EOF  EOF
985      echo >> genmake_warnings      cat genmake_tc_2.$FS >> $LOGFILE
     echo "running: check_HAVE_STAT()" >> genmake_warnings  
     cat genmake_tc_2.$FS >> genmake_warnings  
986      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
987      echo $COMM >> genmake_warnings      echo $COMM >> $LOGFILE
988      $COMM >> genmake_tc.log 2>&1      $COMM >> genmake_tc.log 2>&1
989      RETVAL=$?      RETVAL=$?
990      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
991          HAVE_STAT=t          HAVE_STAT=t
         DEFINES="$DEFINES -DHAVE_STAT"  
992      fi      fi
993      rm -f genmake_tc*      rm -f genmake_tc*
994        echo " --> set HAVE_STAT='$HAVE_STAT'" >> $LOGFILE
995  }  }
996    
   
997  check_netcdf_libs()  {  check_netcdf_libs()  {
998      if test ! "x$SKIP_NETCDF_CHECK" = x ; then      if test ! "x$SKIP_NETCDF_CHECK" = x ; then
999          return          return
1000      fi      fi
1001      echo >> genmake_warnings      echo >> $LOGFILE
1002      echo "running: check_netcdf_libs()" >> genmake_warnings      echo "running: check_netcdf_libs()" >> $LOGFILE
1003      cat <<EOF > genmake_tnc.F      cat <<EOF > genmake_tnc.F
1004        program fgennc        program fgennc
1005  #include "netcdf.inc"  #include "netcdf.inc"
1006  EOF  EOF
1007      if test ! "x$MPI" = x ; then     #if test ! "x$MPI" = x ; then
1008          echo '#include "mpif.h"' >> genmake_tnc.F     #    echo '#include "mpif.h"' >> genmake_tnc.F
1009      fi     #fi
1010      cat <<EOF >> genmake_tnc.F      cat <<EOF >> genmake_tnc.F
1011        integer iret, ncid, xid        integer iret, ncid, xid
1012        iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)        iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
# Line 952  EOF Line 1017  EOF
1017        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
1018        end        end
1019  EOF  EOF
1020      echo "===  genmake_tnc.F  ===" > genmake_tnc.log      echo "===  genmake_tnc.F  >>>" > genmake_tnc.log
1021      cat genmake_tnc.F >> genmake_tnc.log      cat genmake_tnc.F >> genmake_tnc.log
1022      echo "===  genmake_tnc.F  ===" >> genmake_tnc.log      echo "<<<  genmake_tnc.F  ===" >> genmake_tnc.log
1023      RET_CPP=f      RET_CPP=f
1024      COMM="cat genmake_tnc.F | $CPP $DEFINES $INCLUDES"      COMM="cat genmake_tnc.F | $CPP $DEFINES $INCLUDES"
1025      echo "$COMM" >> genmake_tnc.log      echo "$COMM" >> genmake_tnc.log
# Line 970  EOF Line 1035  EOF
1035      $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \      $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
1036          &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1          &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
1037      RET_COMPILE=$?      RET_COMPILE=$?
1038      cat genmake_tnc.log >> genmake_warnings      cat genmake_tnc.log >> $LOGFILE
1039    
1040      #EH3  Remove test program execution for machines that either disallow      #EH3  Remove test program execution for machines that either disallow
1041      #EH3  execution or cannot support it (eg. cross-compilers)      #EH3  execution or cannot support it (eg. cross-compilers)
# Line 981  EOF Line 1046  EOF
1046    
1047      if test "x$RET_COMPILE" = x0 ; then      if test "x$RET_COMPILE" = x0 ; then
1048          HAVE_NETCDF=t          HAVE_NETCDF=t
1049            echo "check_netcdf: successful" >> $LOGFILE
1050      else      else
1051          # try again with "-lnetcdf" added to the libs          # try again with "-lnetcdf" added to the libs
1052          echo "try again with added '-lnetcdf'" > genmake_tnc.log          echo "==> try again with added '-lnetcdf'" > genmake_tnc.log
1053          echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log          echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log
1054          echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log          echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
1055          echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log          echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
# Line 991  EOF Line 1057  EOF
1057              &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \              &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
1058              &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1              &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
1059          RET_COMPILE=$?          RET_COMPILE=$?
1060          cat genmake_tnc.log >> genmake_warnings          echo >> $LOGFILE
1061            cat genmake_tnc.log >> $LOGFILE
1062          if test "x$RET_COMPILE" = x0 ; then          if test "x$RET_COMPILE" = x0 ; then
1063              LIBS="$LIBS -lnetcdf"              LIBS="$LIBS -lnetcdf"
1064              HAVE_NETCDF=t              HAVE_NETCDF=t
1065                echo "check_netcdf: successful" >> $LOGFILE
1066          else          else
1067          # try again with "-lnetcdff" added to the libs          # try again with "-lnetcdff" added to the libs
1068              echo "try again with added '-lnetcdff -lnetcdf'" > genmake_tnc.log              echo "==> try again with added '-lnetcdff -lnetcdf'" > genmake_tnc.log
1069              echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log              echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log
1070              echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log              echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
1071              echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log              echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
# Line 1005  EOF Line 1073  EOF
1073                  &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \                  &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
1074                  &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdff -lnetcdf >> genmake_tnc.log 2>&1                  &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdff -lnetcdf >> genmake_tnc.log 2>&1
1075              RET_COMPILE=$?              RET_COMPILE=$?
1076              cat genmake_tnc.log >> genmake_warnings              echo >> $LOGFILE
1077                cat genmake_tnc.log >> $LOGFILE
1078              if test "x$RET_COMPILE" = x0 ; then              if test "x$RET_COMPILE" = x0 ; then
1079                  LIBS="$LIBS -lnetcdff -lnetcdf"                  LIBS="$LIBS -lnetcdff -lnetcdf"
1080                  HAVE_NETCDF=t                  HAVE_NETCDF=t
1081                    echo "check_netcdf: successful" >> $LOGFILE
1082                fi
1083            fi
1084        fi
1085        rm -f genmake_tnc*
1086        echo " --> set HAVE_NETCDF='$HAVE_NETCDF'" >> $LOGFILE
1087    }
1088    
1089    check_lapack_libs()  {
1090        if test "x$CHECK_FOR_LAPACK" = xf ; then return ; fi
1091        echo >> $LOGFILE
1092        echo "running: check_lapack_libs()" >> $LOGFILE
1093        cat <<EOF > genmake_tla.F
1094          program fgenla
1095          integer info
1096          integer ipiv( 2 )
1097          double precision ab( 4, 2 ), b( 2 )
1098          data ab / 0., 0., 1., 2., 0., 2., 1., 0. /
1099          data b / 1., 1. /
1100          call dgbsv( 2, 1, 1, 1, ab, 4, ipiv, b, 2, info )
1101          IF (info .NE. 0) write(*,*) 'Error:', info
1102          write(*,*) b
1103          end
1104    EOF
1105        echo "===  genmake_tla.F  >>>" > genmake_tla.log
1106        cat genmake_tla.F >> genmake_tla.log
1107        echo "<<<  genmake_tla.F  ===" >> genmake_tla.log
1108        RET_CPP=f
1109        COMM="cat genmake_tla.F | $CPP $DEFINES $INCLUDES"
1110        echo "$COMM" >> genmake_tla.log
1111        eval $COMM > genmake_tla.$FS 2>/dev/null  &&  RET_CPP=t
1112        if test "x$RET_CPP" = xf ; then
1113            echo "  WARNING: CPP failed to pre-process the lapack test." \
1114                >> genmake_tla.log
1115            echo "    Please check that \$INCLUDES is properly set." \
1116                >> genmake_tla.log
1117        fi
1118        echo "$FC $FFLAGS $FOPTIM -c genmake_tla.$FS  \ " >> genmake_tla.log
1119        echo "  &&  $LINK $FFLAGS $FOPTIM -o genmake_tla.o $LIBS" >> genmake_tla.log
1120        $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
1121            &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS >> genmake_tla.log 2>&1
1122        RET_COMPILE=$?
1123        cat genmake_tla.log >> $LOGFILE
1124    
1125        # test program execution not always possible (see check_netcdf_libs)
1126        #
1127        #test -x ./genmake_tla  &&  ./genmake_tla >> genmake_tla.log 2>&1
1128        #RETVAL=$?
1129        #if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
1130    
1131        if test "x$RET_COMPILE" = x0 ; then
1132            HAVE_LAPACK=t
1133            echo "check_lapack: successful" >> $LOGFILE
1134        else
1135            # try again with "-llapack" added to the libs
1136            echo "==> try again with added '-llapack'" > genmake_tla.log
1137            echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1138            echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1139            echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack" >> genmake_tla.log
1140            cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null  \
1141                &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
1142                &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack >> genmake_tla.log 2>&1
1143            RET_COMPILE=$?
1144            echo >> $LOGFILE
1145            cat genmake_tla.log >> $LOGFILE
1146            if test "x$RET_COMPILE" = x0 ; then
1147                LIBS="$LIBS -llapack"
1148                HAVE_LAPACK=t
1149                echo "check_lapack: successful" >> $LOGFILE
1150            else
1151            # try again with "-lf77blas -lcblas" added to the libs
1152                echo "==> try again with added '-llapack -lf77blas -lcblas'" > genmake_tla.log
1153                echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1154                echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1155                echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas" >> genmake_tla.log
1156                cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null  \
1157                    &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
1158                    &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas >> genmake_tla.log 2>&1
1159                RET_COMPILE=$?
1160                echo >> $LOGFILE
1161                cat genmake_tla.log >> $LOGFILE
1162                if test "x$RET_COMPILE" = x0 ; then
1163                    LIBS="$LIBS -llapack -lf77blas -lcblas"
1164                    HAVE_LAPACK=t
1165                    echo "check_lapack: successful" >> $LOGFILE
1166                else
1167                # try again with "-latlas" added to the libs
1168                    echo "==> try again with added '-llapack -lf77blas -lcblas -latlas'" > genmake_tla.log
1169                    echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1170                    echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1171                    echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas -latlas" >> genmake_tla.log
1172                    cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null  \
1173                        &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
1174                        &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas -latlas >> genmake_tla.log 2>&1
1175                    RET_COMPILE=$?
1176                    echo >> $LOGFILE
1177                    cat genmake_tla.log >> $LOGFILE
1178                    if test "x$RET_COMPILE" = x0 ; then
1179                        LIBS="$LIBS -llapack -lf77blas -lcblas -latlas"
1180                        HAVE_LAPACK=t
1181                        echo "check_lapack: successful" >> $LOGFILE
1182                    fi
1183              fi              fi
1184          fi          fi
1185      fi      fi
1186      rm -f genmake_tnc*      rm -f genmake_tla*
1187        echo " --> set HAVE_LAPACK='$HAVE_LAPACK'" >> $LOGFILE
1188    }
1189    
1190    check_HAVE_FLUSH()  {
1191        if test ! "x$SKIP_CHECK_FLUSH" = x ; then
1192            return
1193        fi
1194        echo >> $LOGFILE
1195        echo "running: check_HAVE_FLUSH()" >> $LOGFILE
1196        cat <<EOF > genmake_tflsh.$FS
1197          program fgenflsh
1198          integer iounit
1199          character*9 fname
1200          iounit = 26
1201          fname = 'tmp.tflsh'
1202          open(iounit,FILE=fname,STATUS='unknown')
1203          write(iounit,*) 'genmake_tflsh: hello'
1204          call flush(iounit)
1205          close(iounit)
1206          end
1207    EOF
1208        echo "===  genmake_tflsh.$FS  >>>" > genmake_tflsh.log
1209        cat genmake_tflsh.$FS >> genmake_tflsh.log
1210        echo "<<<  genmake_tflsh.$FS  ===" >> genmake_tflsh.log
1211    
1212        echo "$FC $FFLAGS $FOPTIM -c genmake_tflsh.$FS  \ " >> genmake_tflsh.log
1213        echo "  &&  $LINK $FFLAGS $FOPTIM -o genmake_tflsh.o $LIBS" >> genmake_tflsh.log
1214        $FC $FFLAGS $FOPTIM -c genmake_tflsh.$FS >> genmake_tflsh.log 2>&1  \
1215            &&  $LINK $FFLAGS $FOPTIM -o genmake_tflsh genmake_tflsh.o $LIBS >> genmake_tflsh.log 2>&1
1216        RET_COMPILE=$?
1217    
1218        if test "x$RET_COMPILE" = x0 ; then
1219            HAVE_FLUSH=t
1220            #cat genmake_tflsh.log >> $LOGFILE
1221            echo "  check_HAVE_FLUSH: successful" >> $LOGFILE
1222        else
1223            HAVE_FLUSH=f
1224            cat genmake_tflsh.log >> $LOGFILE
1225        fi
1226        rm -f genmake_tflsh*
1227        echo " --> set HAVE_FLUSH='$HAVE_FLUSH'" >> $LOGFILE
1228  }  }
1229    
   
   
1230  ###############################################################################  ###############################################################################
1231  #   Sequential part of script starts here  #   Sequential part of script starts here
1232  ###############################################################################  ###############################################################################
# Line 1038  ENABLE= Line 1248  ENABLE=
1248  DISABLE=  DISABLE=
1249  # MAKEFILE=  # MAKEFILE=
1250  # MAKEDEPEND=  # MAKEDEPEND=
1251  PDEPEND=  PKG_DEPEND=
1252  DUMPSTATE=t  PKG_GROUPS=
1253  PDEFAULT=  DUMPSTATE=f
1254  OPTFILE=  OPTFILE=
1255  INCLUDES="-I. $INCLUDES"  INCLUDES="-I. $INCLUDES"
1256  FFLAGS=  FFLAGS=
# Line 1048  FOPTIM= Line 1258  FOPTIM=
1258  FEXTRAFLAGS=  FEXTRAFLAGS=
1259  USE_EXTENDED_SRC=  USE_EXTENDED_SRC=
1260  EXTENDED_SRC_FLAG=  EXTENDED_SRC_FLAG=
1261    GET_FC_VERSION=
1262  CFLAGS=  CFLAGS=
1263  KFLAGS1=  KFLAGS1=
1264  KFLAGS2=  KFLAGS2=
# Line 1058  NOOPTFILES= Line 1269  NOOPTFILES=
1269  NOOPTFLAGS=  NOOPTFLAGS=
1270  MPI=  MPI=
1271  MPIPATH=  MPIPATH=
1272    OMP=
1273    OMPFLAG=
1274    USE_R4=
1275  TS=  TS=
1276  PAPIS=  PAPIS=
1277  PCLS=  PCLS=
# Line 1069  GSL= Line 1283  GSL=
1283  DEVEL=  DEVEL=
1284  HAVE_TEST_L=  HAVE_TEST_L=
1285    
1286    # set this to "t" to enable lapack test
1287    CHECK_FOR_LAPACK=f
1288    
1289  # DEFINES checked by test compilation or command-line  # DEFINES checked by test compilation or command-line
1290  HAVE_SYSTEM=  HAVE_SYSTEM=
1291  HAVE_FDATE=  HAVE_FDATE=
# Line 1079  HAVE_STAT= Line 1296  HAVE_STAT=
1296  HAVE_NETCDF=  HAVE_NETCDF=
1297  HAVE_ETIME=  HAVE_ETIME=
1298  IGNORE_TIME=  IGNORE_TIME=
1299    HAVE_LAPACK=
1300    HAVE_FLUSH=
1301    
1302  MODS=  MODS=
1303  TOOLSDIR=  TOOLSDIR=
# Line 1086  SOURCEDIRS= Line 1305  SOURCEDIRS=
1305  INCLUDEDIRS=  INCLUDEDIRS=
1306  STANDARDDIRS="USE_THE_DEFAULT"  STANDARDDIRS="USE_THE_DEFAULT"
1307    
1308    #- local config file
1309    gm_local="genmake_local"
1310    
1311  G2ARGS=  G2ARGS=
1312  BASH=  BASH=
1313  PWD=`pwd`  PWD=`pwd`
# Line 1101  MACHINE=`uname -a` Line 1323  MACHINE=`uname -a`
1323  EXECUTABLE=  EXECUTABLE=
1324  EXEHOOK=  EXEHOOK=
1325  EXEDIR=  EXEDIR=
 PACKAGES_CONF=  
1326  IEEE=  IEEE=
1327  if test "x$MITGCM_IEEE" != x ; then  if test "x$MITGCM_IEEE" != x ; then
1328      IEEE=$MITGCM_IEEE      IEEE=$MITGCM_IEEE
# Line 1110  FS= Line 1331  FS=
1331  FS90=  FS90=
1332    
1333  AUTODIFF_PKG_USED=f  AUTODIFF_PKG_USED=f
1334    OPENAD=
1335  AD_OPTFILE=  AD_OPTFILE=
1336    CAT_SRC_FOR_TAF=1
1337  TAF=  TAF=
1338  AD_TAF_FLAGS=  AD_TAF_FLAGS=
1339  FTL_TAF_FLAGS=  FTL_TAF_FLAGS=
# Line 1122  FTL_TAF_FLAGS= Line 1345  FTL_TAF_FLAGS=
1345  SVD_TAMC_FLAGS=  SVD_TAMC_FLAGS=
1346  TAMC_EXTRA=  TAMC_EXTRA=
1347    
1348    DIVA=
1349    MPIINCLUDEDIR=
1350    MPI_HEADER_FILES=
1351    LOCAL_MPI_HEADERS=
1352    
1353  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
1354  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"  gm_s1="ROOTDIR STANDARDDIRS MODS PKG_DEPEND PKG_GROUPS DISABLE ENABLE"
1355  gm_s2="FC CPP IEEE TS PAPIS PCLS PAPI PCL HPMT GSL DEVEL MPI JAM DUMPSTATE STANDARDDIRS"  gm_s2="PLATFORM OPTFILE MAKE MAKEFILE MAKEDEPEND FC CC MPI OMP USE_R4"
1356    gm_s3="FEXTRAFLAGS IEEE DEVEL GSL TS PAPIS PCLS PAPI PCL HPMT DUMPSTATE"
1357    
1358  #  The following state is not directly set by command-line switches  #  The following state is not directly set by command-line switches
1359  gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM FEXTRAFLAGS"  gm_s4="LN S64 LINK PACKAGES INCLUDES FFLAGS FOPTIM"
1360  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"  gm_s5="CFLAGS LIBS KPP KFLAGS1 KFLAGS2 KPPFILES NOOPTFILES NOOPTFLAGS"
1361  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE"  gm_s6="PWD TOOLSDIR SOURCEDIRS INCLUDEDIRS EXEDIR EXECUTABLE EXEHOOK"
1362  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"  gm_s7="TMP THISHOST THISUSER THISDATE THISVER MACHINE FC_NAMEMANGLE"
1363  gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME"  gm_s8="HAVE_NETCDF HAVE_SYSTEM HAVE_FDATE HAVE_ETIME HAVE_LAPACK HAVE_FLUSH"
1364    
1365  #  The following are all related to adjoint/tangent-linear stuff  #  The following are all related to adjoint/tangent-linear stuff
1366  gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"  gm_s10="AUTODIFF_PKG_USED AD_OPTFILE OPENAD TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
1367  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"
1368  gm_s12="TAF_EXTRA TAMC_EXTRA"  gm_s12="TAF_EXTRA TAMC_EXTRA DIVA MPIINCLUDEDIR MPI_HEADER_FILES"
1369    
1370  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"
1371  gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"  gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
1372    
1373  cat <<EOF  cat <<EOF
1374    
1375  GENMAKE :  GENMAKE :
1376    
1377  A program for GENerating MAKEfiles for the MITgcm project.  For a  A program for GENerating MAKEfiles for the MITgcm project.
1378  quick list of options, use "genmake -h" or for more detail see:     For a quick list of options, use "genmake2 -h"
1379    or for more detail see the Developer's HOWTO manual at:
1380    http://mitgcm.org/devel_HOWTO/     http://mitgcm.org/public/docs.html
1381    
1382  EOF  EOF
1383    
1384    LOGFILE="genmake.log"
1385    #- clean-up previous genmake logfiles:
1386    rm -f genmake_state genmake_*optfile $LOGFILE
1387    
1388  echo "===  Processing options files and arguments  ==="  echo "===  Processing options files and arguments  ==="
 gm_local="genmake_local"  
 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  
1389    
1390  #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  
1391  #parse_options  #parse_options
1392  ac_prev=  ac_prev=
1393  for ac_option in "$@" ; do  for ac_option in "$@" ; do
# Line 1187  for ac_option in "$@" ; do Line 1400  for ac_option in "$@" ; do
1400          ac_prev=          ac_prev=
1401          continue          continue
1402      fi      fi
1403        
1404      ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`      ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
1405        
1406      case $ac_option in      case $ac_option in
1407            
1408          -help | --help | -h | --h)          -help | --help | -h | --h)
1409              usage ;;              usage ;;
1410            
1411          -nooptfile | --nooptfile)          -nooptfile | --nooptfile)
1412              OPTFILE="NONE" ;;              OPTFILE="NONE" ;;
1413          -optfile | --optfile | -of | --of)          -optfile | --optfile | -of | --of)
1414              ac_prev=OPTFILE ;;              ac_prev=OPTFILE ;;
1415          -optfile=* | --optfile=* | -of=* | --of=*)          -optfile=* | --optfile=* | -of=* | --of=*)
1416              OPTFILE=$ac_optarg ;;              OPTFILE=$ac_optarg ;;
1417            
1418            -oad | --oad)
1419                OPENAD="true" ; ALWAYS_USE_F90=1 ;;
1420            -nocat4ad | -dog4ad | -ncad | -dad)
1421                CAT_SRC_FOR_TAF=0 ;;
1422          -adoptfile | --adoptfile | -adof | --adof)          -adoptfile | --adoptfile | -adof | --adof)
1423              ac_prev=AD_OPTFILE ;;              ac_prev=AD_OPTFILE ;;
1424          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
1425              AD_OPTFILE=$ac_optarg ;;              AD_OPTFILE=$ac_optarg ;;
1426            
1427          -pdepend | --pdepend)          -pdepend | --pdepend)
1428              ac_prev=PDEPEND ;;              ac_prev=PKG_DEPEND ;;
1429          -pdepend=* | --pdepend=*)          -pdepend=* | --pdepend=*)
1430              PDEPEND=$ac_optarg ;;              PKG_DEPEND=$ac_optarg ;;
1431            
1432          -pdefault | --pdefault)          -pgroups | --pgroups)
1433              ac_prev=PDEFAULT ;;              ac_prev=PKG_GROUPS ;;
1434          -pdefault=* | --pdefault=*)          -pgroups=* | --pgroups=*)
1435              PDEFAULT=$ac_optarg ;;              PKG_GROUPS=$ac_optarg ;;
1436            
1437          -make | --make | -m | --m)          -make | --make | -m | --m)
1438              ac_prev=MAKE ;;              ac_prev=MAKE ;;
1439          -make=* | --make=* | -m=* | --m=*)          -make=* | --make=* | -m=* | --m=*)
1440              MAKE=$ac_optarg ;;              MAKE=$ac_optarg ;;
1441            
1442          -bash | --bash)          -bash | --bash)
1443              ac_prev=BASH ;;              ac_prev=BASH ;;
1444          -bash=* | --bash=*)          -bash=* | --bash=*)
1445              BASH=$ac_optarg ;;              BASH=$ac_optarg ;;
1446            
1447          -makedepend | --makedepend | -md | --md)          -makedepend | --makedepend | -md | --md)
1448              ac_prev=MAKEDEPEND ;;              ac_prev=MAKEDEPEND ;;
1449          -makedepend=* | --makedepend=* | -md=* | --md=*)          -makedepend=* | --makedepend=* | -md=* | --md=*)
1450              MAKEDEPEND=$ac_optarg ;;              MAKEDEPEND=$ac_optarg ;;
1451            
1452          -makefile | --makefile | -ma | --ma)          -makefile | --makefile | -mf | --mf)
1453              ac_prev=MAKEFILE ;;              ac_prev=MAKEFILE ;;
1454          -makefile=* | --makefile=* | -ma=* | --ma=*)          -makefile=* | --makefile=* | -mf=* | --mf=*)
1455              MAKEFILE=$ac_optarg ;;              MAKEFILE=$ac_optarg ;;
1456            
1457          -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)          -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
1458              echo "ERROR: The platform option has been removed.  Please specify"              echo "ERROR: The platform option has been removed.  Please specify"
1459              echo "  the build options using the \"optfile\" mechanism."              echo "  the build options using the \"optfile\" mechanism."
1460              echo              echo
1461              usage              usage
1462              ;;              ;;
1463            
1464          -rootdir | --rootdir | -rd | --rd)          -rootdir | --rootdir | -rd | --rd)
1465              ac_prev=ROOTDIR ;;              ac_prev=ROOTDIR ;;
1466          -rootdir=* | --rootdir=* | -rd=* | --rd=*)          -rootdir=* | --rootdir=* | -rd=* | --rd=*)
1467              ROOTDIR=$ac_optarg ;;              ROOTDIR=$ac_optarg ;;
1468            
1469          -mods | --mods | -mo | --mo)          -mods | --mods | -mo | --mo)
1470              ac_prev=MODS ;;              ac_prev=MODS ;;
1471          -mods=* | --mods=* | -mo=* | --mo=*)          -mods=* | --mods=* | -mo=* | --mo=*)
1472              MODS=$ac_optarg ;;              MODS=$ac_optarg ;;
1473            
1474          -disable | --disable)          -disable | --disable)
1475              ac_prev=DISABLE ;;              ac_prev=DISABLE ;;
1476          -disable=* | --disable=*)          -disable=* | --disable=*)
1477              DISABLE=$ac_optarg ;;              DISABLE=$ac_optarg ;;
1478            
1479          -enable | --enable)          -enable | --enable)
1480              ac_prev=ENABLE ;;              ac_prev=ENABLE ;;
1481          -enable=* | --enable=*)          -enable=* | --enable=*)
1482              ENABLE=$ac_optarg ;;              ENABLE=$ac_optarg ;;
1483            
1484          -standarddirs | --standarddirs)          -standarddirs | --standarddirs)
1485              ac_prev=STANDARDDIRS ;;              ac_prev=STANDARDDIRS ;;
1486          -standarddirs=* | --standarddirs=*)          -standarddirs=* | --standarddirs=*)
# Line 1273  for ac_option in "$@" ; do Line 1490  for ac_option in "$@" ; do
1490  #               ac_prev=cpp ;;  #               ac_prev=cpp ;;
1491  #           -cpp=* | --cpp=*)  #           -cpp=* | --cpp=*)
1492  #               CPP=$ac_optarg ;;  #               CPP=$ac_optarg ;;
1493            
1494          -cc | --cc)          -cc | --cc)
1495              ac_prev=CC ;;              ac_prev=CC ;;
1496          -cc=* | --cc=*)          -cc=* | --cc=*)
1497              CC=$ac_optarg ;;              CC=$ac_optarg ;;
1498            
1499          -fortran | --fortran | -fc | --fc)          -fortran | --fortran | -fc | --fc)
1500              ac_prev=FC ;;              ac_prev=FC ;;
1501          -fc=* | --fc=*)          -fc=* | --fc=*)
1502              FC=$ac_optarg ;;              FC=$ac_optarg ;;
1503            
1504          -fs | --fs)          -fs | --fs)
1505              ac_prev=FS ;;              ac_prev=FS ;;
1506          -fs=* | --fs=*)          -fs=* | --fs=*)
1507              FS=$ac_optarg ;;              FS=$ac_optarg ;;
1508            
1509          -fs90 | --fs90)          -fs90 | --fs90)
1510              ac_prev=FS90 ;;              ac_prev=FS90 ;;
1511          -fs90=* | --fs90=*)          -fs90=* | --fs90=*)
1512              FS90=$ac_optarg ;;              FS90=$ac_optarg ;;
1513            
1514            -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4 )
1515                USE_R4=true ;;
1516    
1517          -ieee | --ieee)          -ieee | --ieee)
1518              IEEE=true ;;              IEEE=true ;;
1519          -noieee | --noieee)          -noieee | --noieee)
1520              IEEE= ;;              echo "Warning: ignore option '$ac_option' (default is already without '-ieee')" ;;
1521            -devel | --devel)
1522                IEEE=true ; DEVEL=true ;;
1523            -gsl | --gsl)
1524                GSL=true ;;
1525    
1526          -ts | --ts)          -ts | --ts)
1527              TS=true ;;              TS=true ;;
# Line 1314  for ac_option in "$@" ; do Line 1538  for ac_option in "$@" ; do
1538          -hpmt | --hpmt)          -hpmt | --hpmt)
1539              HPMT=true ;;              HPMT=true ;;
1540    
         -gsl | --gsl)  
             GSL=true ;;  
   
         -devel | --devel)  
             DEVEL=true ;;  
   
1541          -mpi | --mpi)          -mpi | --mpi)
1542              MPI=true ;;              MPI=true ;;
1543          -mpi=* | --mpi=*)          -mpi=* | --mpi=*)
1544              MPIPATH=$ac_optarg              MPIPATH=$ac_optarg
1545              MPI=true ;;              MPI=true ;;
1546            
1547  #       -jam | --jam)          -omp | --omp)
1548  #           JAM=1 ;;              OMP=true ;;
1549  #       -nojam | --nojam)          -omp=* | --omp=*)
1550  #           JAM=0 ;;              OMPFLAG=$ac_optarg
1551                        OMP=true ;;
1552    
1553          -ds | --ds)          -ds | --ds)
1554              DUMPSTATE=t ;;              DUMPSTATE=t ;;
1555            
1556            -extra_flag | --extra_flag)
1557                ac_prev=FEXTRAFLAGS ;;
1558            -extra_flag=* | --extra_flag=*)
1559                FEXTRAFLAGS=$ac_optarg ;;
1560    
1561          -taf_extra | --taf_extra)          -taf_extra | --taf_extra)
1562              ac_prev=TAF_EXTRA ;;              ac_prev=TAF_EXTRA ;;
1563          -taf_extra=* | --taf_extra=*)          -taf_extra=* | --taf_extra=*)
# Line 1343  for ac_option in "$@" ; do Line 1567  for ac_option in "$@" ; do
1567              ac_prev=TAMC_EXTRA ;;              ac_prev=TAMC_EXTRA ;;
1568          -tamc_extra=* | --tamc_extra=*)          -tamc_extra=* | --tamc_extra=*)
1569              TAMC_EXTRA=$ac_optarg ;;              TAMC_EXTRA=$ac_optarg ;;
1570            
1571          -ignoretime | -ignore_time | --ignoretime | --ignore_time)          -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1572              IGNORE_TIME="-DIGNORE_TIME" ;;              IGNORE_TIME="-DIGNORE_TIME" ;;
1573    
# Line 1354  for ac_option in "$@" ; do Line 1578  for ac_option in "$@" ; do
1578              echo "Error: unrecognized option: "$ac_option              echo "Error: unrecognized option: "$ac_option
1579              usage              usage
1580              ;;              ;;
1581            
1582          *)          *)
1583              echo "Error: unrecognized argument: "$ac_option              echo "Error: unrecognized argument: "$ac_option
1584              usage              usage
1585              ;;              ;;
1586            
1587      esac      esac
1588        
1589  done  done
1590    
1591    #TMP=./genmk_$$
1592    #- try to put temporary files in system-local /tmp dir
1593    TMP=/tmp/genmk_${USER}_$$
1594    touch $TMP ; retVal=$?
1595    if [ $retVal -eq 0 ] ; then
1596      if test ! -r $TMP ; then TMP=./genmk_$$ ; fi
1597    else
1598      TMP=./genmk_$$
1599    fi
1600    rm -f $TMP
1601    #echo "  temp files: $TMP.*"
1602    
1603    printf "  getting local config information:  "
1604    if test -f $gm_local ; then
1605        echo "using $gm_local"
1606        . $gm_local
1607    else
1608        echo "none found"
1609    fi
1610    
1611  if test -f ./.genmakerc ; then  if test -f ./.genmakerc ; then
1612      echo      echo
1613      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
1614      echo "  file.  This file format is no longer supported.  For directions on"      echo "  file.  This file format is no longer supported.  For directions on"
1615      echo "  how to setup and use the new \"genmake2\" script, please see:"      echo "  how to setup and use the new \"genmake2\" script, please see:"
1616      echo "    http://mitgcm.org/devel_HOWTO/"      echo "    http://mitgcm.org/public/devel_HOWTO/"
1617      echo "  and send an email to MITgcm-support@mitgcm.org if you need help."      echo "  and send an email to MITgcm-support@mitgcm.org if you need help."
1618      echo "WARNING: ignore \"./.genmakerc\" and continue."      echo "WARNING: ignore \"./.genmakerc\" and continue."
1619      echo      echo
1620  fi  fi
1621    
1622  #  Find the MITgcm ${ROOTDIR}  #  Find the MITgcm ${ROOTDIR}
# Line 1385  if test "x${ROOTDIR}" = x ; then Line 1628  if test "x${ROOTDIR}" = x ; then
1628          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1629              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
1630                  ROOTDIR=$d                  ROOTDIR=$d
1631                  printf "Warning:  ROOTDIR was not specified but there appears to be"                  printf "Warning: ROOTDIR was not specified ;"
1632                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."                  echo " try using a local copy of MITgcm found at \"$ROOTDIR\""
1633                  break                  break
1634              fi              fi
1635          done          done
# Line 1406  fi Line 1649  fi
1649  #  Find the MITgcm ${THISVER}  #  Find the MITgcm ${THISVER}
1650  version_file="${ROOTDIR}/doc/tag-index"  version_file="${ROOTDIR}/doc/tag-index"
1651  if test -f $version_file ; then  if test -f $version_file ; then
1652      THISVER=`grep '^checkpoint' $version_file | head -1`      THISVER=`$AWK '/^checkpoint/{print $1; exit}' $version_file`
1653  #-  remove ./BUILD_INFO.h file if older than version_file  #-  remove ./BUILD_INFO.h file if older than version_file
1654      if test -f ./BUILD_INFO.h -a ./BUILD_INFO.h -ot $version_file ; then      if test -f ./BUILD_INFO.h -a ./BUILD_INFO.h -ot $version_file ; then
1655          echo "  remove ./BUILD_INFO.h (older than ${version_file})"          echo "  remove ./BUILD_INFO.h (older than ${version_file})"
# Line 1418  if test "x$MAKEFILE" = x ; then Line 1661  if test "x$MAKEFILE" = x ; then
1661      MAKEFILE="Makefile"      MAKEFILE="Makefile"
1662  fi  fi
1663    
1664  echo "  getting OPTFILE information:  "  echo "  getting OPTFILE information:"
1665  if test "x${OPTFILE}" = x ; then  if test "x${OPTFILE}" = x ; then
1666      if test "x$MITGCM_OF" = x ; then      if test "x$MITGCM_OF" = x ; then
1667          echo "Warning: no OPTFILE specified so we'll look for possible settings"          echo "Warning: no OPTFILE specified so we'll look for possible settings"
1668          printf "\n===  Searching for possible settings for OPTFILE  ===\n"          printf "\n===  Searching for possible settings for OPTFILE  ===\n"
1669          find_possible_configs          find_possible_optfile
1670      else      else
1671          OPTFILE=$MITGCM_OF          OPTFILE=$MITGCM_OF
1672      fi      fi
# Line 1438  if test "x$OPTFILE" != xNONE ; then Line 1681  if test "x$OPTFILE" != xNONE ; then
1681              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1682              exit 1              exit 1
1683          fi          fi
1684          if test "x$DUMPSTATE" != xf ; then          if test "x$DUMPSTATE" = xt ; then
1685              cp -f $OPTFILE "genmake_optfile"              cp -f $OPTFILE "genmake_optfile"
1686          fi          fi
1687      else      else
# Line 1447  if test "x$OPTFILE" != xNONE ; then Line 1690  if test "x$OPTFILE" != xNONE ; then
1690      fi      fi
1691  fi  fi
1692    
1693  echo "  getting AD_OPTFILE information:  "  echo "  getting AD_OPTFILE information:"
1694  if test "x${AD_OPTFILE}" = x ; then  if test "x${AD_OPTFILE}" = x ; then
1695      if test "x$MITGCM_AD_OF" = x ; then      if test "x$MITGCM_AD_OF" != x ; then
1696            AD_OPTFILE=$MITGCM_AD_OF
1697        elif test "x$OPENAD" = x ; then
1698          AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default          AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
1699      else      else
1700          AD_OPTFILE=$MITGCM_AD_OF          AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_oad
1701      fi      fi
1702  fi  fi
1703  if test "x${AD_OPTFILE}" != xNONE ; then  if test "x${AD_OPTFILE}" != xNONE ; then
# Line 1465  if test "x${AD_OPTFILE}" != xNONE ; then Line 1710  if test "x${AD_OPTFILE}" != xNONE ; then
1710              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1711              exit 1              exit 1
1712          fi          fi
1713          if test "x$DUMPSTATE" != xf ; then          if test "x$DUMPSTATE" = xt ; then
1714              cp -f $AD_OPTFILE "genmake_ad_optfile"              cp -f $AD_OPTFILE "genmake_ad_optfile"
1715          fi          fi
1716      else      else
# Line 1493  Error: no Fortran compiler: please speci Line 1738  Error: no Fortran compiler: please speci
1738  EOF  EOF
1739      exit 1      exit 1
1740  fi  fi
1741    if test "x$GET_FC_VERSION" != x ; then
1742      echo "Get compiler version using: $FC $GET_FC_VERSION" >> $LOGFILE
1743      ff=`echo $FC | sed 's/ .*//'` ; xx=`echo $ff | sed 's/^./& /' | sed 's/ .*//'`
1744      if test $xx != '/' ; then which $ff >> $LOGFILE ; fi
1745      $FC $GET_FC_VERSION > genmake_fc_vers1 2> genmake_fc_vers2
1746      if test -s genmake_fc_vers1 ; then
1747        cat genmake_fc_vers1 >> $LOGFILE
1748      else
1749        cat genmake_fc_vers2 >> $LOGFILE
1750      fi
1751      echo "<-- compiler version ----" >> $LOGFILE
1752      rm -f genmake_fc_vers1 genmake_fc_vers2
1753    fi
1754    
1755  if test "x$CC" = x ; then  if test "x$CC" = x ; then
1756      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  
1757  fi  fi
1758    
1759  if test "x$LINK" = x ; then  if test "x$LINK" = x ; then
1760      LINK=$FC      LINK=$FC
1761  fi  fi
# Line 1510  if test "x$MAKE" = x ; then Line 1763  if test "x$MAKE" = x ; then
1763      MAKE="make"      MAKE="make"
1764  fi  fi
1765  if test "x$CPP" = x ; then  if test "x$CPP" = x ; then
1766      CPP=cpp      CPP="cpp -traditional -P"
1767  fi  fi
1768  #EH3 === UGLY ===  #EH3 === UGLY ===
1769  #  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 1537  EOF Line 1790  EOF
1790  else  else
1791      rm -f test_cpp      rm -f test_cpp
1792  fi  fi
1793    
1794  look_for_makedepend  look_for_makedepend
1795    
1796    #  Check that soft-link command is set and usable
1797  if test "x$LN" = x ; then  if test "x$LN" = x ; then
1798      LN="ln -s"      LN="ln -s"
1799  fi  fi
# Line 1547  RETVAL=$? Line 1803  RETVAL=$?
1803  if test "x$RETVAL" != x0 ; then  if test "x$RETVAL" != x0 ; then
1804      cat <<EOF 1>&2      cat <<EOF 1>&2
1805    
1806  Error: The command "ln -s" failed -- please specify a working soft-link  Error: The command "$LN" failed -- please specify a working soft-link
1807    command in the optfile.    command in the optfile.
1808    
1809  EOF  EOF
# Line 1565  check_for_broken_Ff Line 1821  check_for_broken_Ff
1821    
1822  if test ! "x$MPI" = x ; then  if test ! "x$MPI" = x ; then
1823        echo "  Turning on MPI cpp macros"        echo "  Turning on MPI cpp macros"
1824        DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"        DEFINES="$DEFINES -DALLOW_USE_MPI"
1825    #- To compile code older than checkpoint63s (2012/09/05), un-comment the following line:
1826    #     DEFINES="$DEFINES -DALWAYS_USE_MPI"
1827    fi
1828    if test ! "x$OMP" = x ; then
1829          echo "  Add OMPFLAG and turn on OpenMP cpp macros"
1830          FFLAGS="$FFLAGS $OMPFLAG"
1831          F90FLAGS="$F90FLAGS $OMPFLAG"
1832          DEFINES="$DEFINES -DUSE_OMP_THREADING"
1833    fi
1834    
1835    if test ! "x$USE_R4" = x ; then
1836          echo "  Turning on LET_RS_BE_REAL4 cpp flag"
1837          DEFINES="$DEFINES -DLET_RS_BE_REAL4"
1838  fi  fi
1839    
1840  if test ! "x$TS" = x ; then  if test ! "x$TS" = x ; then
1841        echo "  Turning on timing per timestep"        echo "  Turning on timing per timestep"
1842        if test ! "x$FOOLAD" = x ; then        if test ! "x$FOOLAD" = x ; then
1843              DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP"              DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP"
1844        else        else
1845              DEFINES="$DEFINES -DTIME_PER_TIMESTEP"              DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1846        fi        fi
# Line 1607  if test ! "x$PAPI" = x ; then Line 1876  if test ! "x$PAPI" = x ; then
1876            echo "  Sticking with PAPI flop summary per timestep!"            echo "  Sticking with PAPI flop summary per timestep!"
1877        else        else
1878            echo "  Turning on performance analysis with PAPI"            echo "  Turning on performance analysis with PAPI"
1879            echo "  Please make sure PAPIINC, PAPILIB are defined"            echo "  Please make sure PAPIINC, PAPILIB are defined"
1880            DEFINES="$DEFINES -DUSE_PAPI"            DEFINES="$DEFINES -DUSE_PAPI"
1881            INCLUDES="$INCLUDES $PAPIINC"            INCLUDES="$INCLUDES $PAPIINC"
1882            LIBS="$LIBS $PAPILIB"            LIBS="$LIBS $PAPILIB"
# Line 1619  if test ! "x$PCL" = x ; then Line 1888  if test ! "x$PCL" = x ; then
1888            echo "  Sticking with PCL flop summary per timestep!"            echo "  Sticking with PCL flop summary per timestep!"
1889        else        else
1890            echo "  Turning on performance analysis with PCL"            echo "  Turning on performance analysis with PCL"
1891            echo "  Please make sure PCLINC, PCLLIB are defined"            echo "  Please make sure PCLINC, PCLLIB are defined"
1892            DEFINES="$DEFINES -DUSE_PCL"            DEFINES="$DEFINES -DUSE_PCL"
1893            INCLUDES="$INCLUDES $PCLINC"            INCLUDES="$INCLUDES $PCLINC"
1894            LIBS="$LIBS $PCLLIB"            LIBS="$LIBS $PCLLIB"
# Line 1629  if test ! "x$HPMT" = x ; then Line 1898  if test ! "x$HPMT" = x ; then
1898        if test ! "x$PAPI" = x ; then        if test ! "x$PAPI" = x ; then
1899            echo "  PAPI and the HPM Toolkit cannot co-exist!"            echo "  PAPI and the HPM Toolkit cannot co-exist!"
1900            echo "  Sticking with PAPI!"            echo "  Sticking with PAPI!"
1901        else if test ! "x$PCL" = x ; then        else
1902            if test ! "x$PCL" = x ; then
1903            echo "  PCL and the HPM Toolkit cannot co-exist!"            echo "  PCL and the HPM Toolkit cannot co-exist!"
1904            echo "  Sticking with PCL!"            echo "  Sticking with PCL!"
1905        else          else
1906            echo "  Turning on performance analysis with the HPM Toolkit"            echo "  Turning on performance analysis with the HPM Toolkit"
1907            echo "  Please make sure HPMTINC, HPMTLIB are defined"            echo "  Please make sure HPMTINC, HPMTLIB are defined"
1908            DEFINES="$DEFINES -DUSE_LIBHPM"            DEFINES="$DEFINES -DUSE_LIBHPM"
1909            INCLUDES="$INCLUDES $HPMTINC"            INCLUDES="$INCLUDES $HPMTINC"
1910            LIBS="$LIBS $HPMTLIB"            LIBS="$LIBS $HPMTLIB"
1911        fi          fi
1912        fi        fi
1913  fi  fi
1914  if test ! "x$GSL" = x ; then  if test ! "x$GSL" = x ; then
# Line 1698  printf "  Do we have the etime() command Line 1968  printf "  Do we have the etime() command
1968  cat > genmake_tcomp.$FS <<EOF  cat > genmake_tcomp.$FS <<EOF
1969        program hello        program hello
1970        REAL*4 ACTUAL, TARRAY(2)        REAL*4 ACTUAL, TARRAY(2)
1971        EXTERNAL ETIME        call etime( tarray, actual )
       REAL*4 ETIME  
       actual = etime( tarray )  
1972        print *, tarray        print *, tarray
1973        end        end
1974  EOF  EOF
# Line 1719  rm -f genmake_tcomp* Line 1987  rm -f genmake_tcomp*
1987  printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "  printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
1988  check_HAVE_CLOC  check_HAVE_CLOC
1989  if test "x$HAVE_CLOC" != x ; then  if test "x$HAVE_CLOC" != x ; then
1990        DEFINES="$DEFINES -DHAVE_CLOC"
1991      echo "yes"      echo "yes"
1992  else  else
1993      echo "no"      echo "no"
# Line 1733  rm -f genmake_t* Line 2002  rm -f genmake_t*
2002  printf "  Can we unlimit the stack size using $FC...  "  printf "  Can we unlimit the stack size using $FC...  "
2003  check_HAVE_SETRLSTK  check_HAVE_SETRLSTK
2004  if test "x$HAVE_SETRLSTK" = xt ; then  if test "x$HAVE_SETRLSTK" = xt ; then
2005        DEFINES="$DEFINES -DHAVE_SETRLSTK"
2006      echo "yes"      echo "yes"
2007  else  else
2008      echo "no"      echo "no"
# Line 1742  rm -f genmake_t* Line 2012  rm -f genmake_t*
2012  printf "  Can we register a signal handler using $FC...  "  printf "  Can we register a signal handler using $FC...  "
2013  check_HAVE_SIGREG  check_HAVE_SIGREG
2014  if test "x$HAVE_SIGREG" = xt ; then  if test "x$HAVE_SIGREG" = xt ; then
2015        DEFINES="$DEFINES -DHAVE_SIGREG"
2016      echo "yes"      echo "yes"
2017  else  else
2018      echo "no"      echo "no"
# Line 1751  rm -f genmake_t* Line 2022  rm -f genmake_t*
2022  printf "  Can we use stat() through C calls...  "  printf "  Can we use stat() through C calls...  "
2023  check_HAVE_STAT  check_HAVE_STAT
2024  if test "x$HAVE_STAT" != x ; then  if test "x$HAVE_STAT" != x ; then
2025        DEFINES="$DEFINES -DHAVE_STAT"
2026      echo "yes"      echo "yes"
2027  else  else
2028      echo "no"      echo "no"
# Line 1760  rm -f genmake_t* Line 2032  rm -f genmake_t*
2032  printf "  Can we create NetCDF-enabled binaries...  "  printf "  Can we create NetCDF-enabled binaries...  "
2033  check_netcdf_libs  check_netcdf_libs
2034  if test "x$HAVE_NETCDF" != x ; then  if test "x$HAVE_NETCDF" != x ; then
2035        DEFINES="$DEFINES -DHAVE_NETCDF"
2036        echo "yes"
2037    else
2038        echo "no"
2039    fi
2040    
2041    printf "  Can we create LAPACK-enabled binaries...  "
2042    check_lapack_libs
2043    if test "x$HAVE_LAPACK" != x ; then
2044        DEFINES="$DEFINES -DHAVE_LAPACK"
2045        echo "yes"
2046    else
2047        echo "no"
2048    fi
2049    
2050    printf "  Can we call FLUSH intrinsic subroutine...  "
2051    check_HAVE_FLUSH
2052    if test "x$HAVE_FLUSH" = xt ; then
2053        DEFINES="$DEFINES -DHAVE_FLUSH"
2054      echo "yes"      echo "yes"
2055  else  else
2056      echo "no"      echo "no"
2057  fi  fi
 DEFINES="$DEFINES $IGNORE_TIME"  
2058    
2059    DEFINES="$DEFINES $IGNORE_TIME"
2060  if test "x$EMBED_SRC" = xt ; then  if test "x$EMBED_SRC" = xt ; then
2061      build_embed_encode      build_embed_encode
2062  fi  fi
2063  if test "x$EMBED_SRC" = xt ; then  if test "x$EMBED_SRC" = xt ; then
2064      ENABLE="$ENABLE embed_files"      ENABLE="$ENABLE embed_files"
2065    #   DEFINES="$DEFINES -DHAVE_EMBED_SRC"
2066  fi  fi
2067    
   
2068  printf "\n===  Setting defaults  ===\n"  printf "\n===  Setting defaults  ===\n"
2069  printf "  Adding MODS directories:  "  printf "  Adding MODS directories: "
2070  for d in $MODS ; do  for d in $MODS ; do
2071      if test ! -d $d ; then      if test ! -d $d ; then
2072          echo          echo
2073          echo "Error: MODS directory \"$d\" not found!"          echo "Error: MODS directory \"$d\" not found!"
2074          exit 1          exit 1
2075      else      else
2076          printf " $d"          printf "$d "
2077          SOURCEDIRS="$SOURCEDIRS $d"          SOURCEDIRS="$SOURCEDIRS $d"
2078          INCLUDEDIRS="$INCLUDEDIRS $d"          INCLUDEDIRS="$INCLUDEDIRS $d"
2079      fi      fi
2080  done  done
2081  echo  echo
2082    
2083  if test "x${PLATFORM}" = x ; then  #if test "x${PLATFORM}" = x ; then
2084      PLATFORM=$p_PLATFORM  #    PLATFORM=$p_PLATFORM
2085  fi  #fi
2086    
2087  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
2088      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
# Line 1831  ERROR: neither of the two default script Line 2122  ERROR: neither of the two default script
2122      ${TOOLSDIR}/set64bitConst.sh      ${TOOLSDIR}/set64bitConst.sh
2123      ${TOOLSDIR}/set64bitConst.csh      ${TOOLSDIR}/set64bitConst.csh
2124    
2125    are working so please check paths or specify (with \$S64) a    are working so please check paths or specify (with \$S64) a
2126    working version of this script.    working version of this script.
2127    
2128  EOF  EOF
# Line 1843  THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSD Line 2134  THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSD
2134    
2135  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
2136    
2137    #  Set Standard Code Directories:
2138    if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
2139        STANDARDDIRS="eesupp model"
2140    fi
2141    #  if model in Standard-Code-Dir, add eesupp (needed to compile model)
2142    echo " $STANDARDDIRS " | grep ' model ' > /dev/null 2>&1
2143    ckM=$?
2144    echo " $STANDARDDIRS " | grep ' eesupp ' > /dev/null 2>&1
2145    ckE=$?
2146    if test $ckM = 0 -a $ckE = 1 ; then
2147        STANDARDDIRS="$STANDARDDIRS eesupp"
2148    fi
2149    
2150  #  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
2151  #  generated from some template source files. We'll make them first so  #  generated from some template source files. We'll make them first so
2152  #  they appear as regular source code  #  they appear as regular source code
2153  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
2154      echo "  Making source files in eesupp from templates"      echo "  Making source files in eesupp from templates"
2155      ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1      ( cd $ROOTDIR"/eesupp/src/" && $MAKE clean_old && $MAKE \
2156        ) > make_eesupp.errors 2>&1
2157      RETVAL=$?      RETVAL=$?
2158      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
2159          rm -f make_eesupp.errors          rm -f make_eesupp.errors
# Line 1863  fi Line 2168  fi
2168  for pdir in exch2 regrid ; do  for pdir in exch2 regrid ; do
2169      if test -r $ROOTDIR"/pkg/${pdir}/Makefile" ; then      if test -r $ROOTDIR"/pkg/${pdir}/Makefile" ; then
2170          echo "  Making source files in pkg/${pdir} from templates"          echo "  Making source files in pkg/${pdir} from templates"
2171          ( cd $ROOTDIR"/pkg/"${pdir} && $MAKE ) > make_${pdir}.errors 2>&1          ( cd $ROOTDIR"/pkg/"${pdir} && $MAKE clean_old && $MAKE \
2172            ) > make_${pdir}.errors 2>&1
2173          RETVAL=$?          RETVAL=$?
2174          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
2175              rm -f make_${pdir}.errors              rm -f make_${pdir}.errors
# Line 1876  for pdir in exch2 regrid ; do Line 2182  for pdir in exch2 regrid ; do
2182  done  done
2183    
2184  printf "\n===  Determining package settings  ===\n"  printf "\n===  Determining package settings  ===\n"
2185  if  test "x${PDEPEND}" = x ; then  if  test "x${PKG_DEPEND}" = x ; then
2186      tmp=$ROOTDIR"/pkg/pkg_depend"      tmp=$ROOTDIR"/pkg/pkg_depend"
2187      if test -r $tmp ; then      if test -r $tmp ; then PKG_DEPEND=$tmp ; fi
2188          PDEPEND=$tmp  fi
2189      else  if  test "x${PKG_DEPEND}" = x ; then
2190          echo "Warning:  No package dependency information was specified."          echo "Warning:  No package dependency information was specified."
2191          echo "  Please check that ROOTDIR/pkg/pkg_depend exists."          echo "  Please check that ROOTDIR/pkg/pkg_depend exists."
     fi  
2192  else  else
2193      if test ! -r ${PDEPEND} ; then      if test ! -r ${PKG_DEPEND} ; then
2194          echo "Error:  can't read package dependency info from PDEPEND=\"$PDEPEND\""          echo "Error:  can't read package dependency info from PKG_DEPEND=\"$PKG_DEPEND\""
2195          exit 1          exit 1
2196      fi      fi
2197        echo "  getting package dependency info from  $PKG_DEPEND"
2198    #  Strip the comments and then convert the dependency file into arrays: PNAME, DNAME
2199        get_pdepend_list $PKG_DEPEND
2200  fi  fi
2201  echo "  getting package dependency info from  $PDEPEND"  
2202  #  Strip the comments and then convert the dependency file into  # A default package groups file "$ROOTDIR/pkg/pkg_groups" is provided
2203  #  two arrays: PNAME, DNAME  #  to define the "default_pkg_list" and package groups (for convenience, one
2204  cat $PDEPEND | sed -e 's/#.*$//g' \  #  can specify a group of packages using names like "ocean" and "atmosphere").
2205      | $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
2206      > ./.pd_tmp      tmp=$ROOTDIR"/pkg/pkg_groups"
2207  RETVAL=$?      if test -r $tmp ; then PKG_GROUPS=$tmp ; fi
2208  if test ! "x${RETVAL}" = x0 ; then  fi
2209      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""  if test "x${PKG_GROUPS}" = x ; then
2210      exit 1          echo "Warning:  No package groups information was specified."
2211            echo "  Please check that ROOTDIR/pkg/pkg_groups exists."
2212    else
2213        if test ! -r ${PKG_GROUPS} ; then
2214            echo "Error:  can't read package groups info from PKG_GROUPS=\"$PKG_GROUPS\""
2215            exit 1
2216        fi
2217        echo "  getting package groups info from      $PKG_GROUPS"
2218  fi  fi
 . ./.pd_tmp  
 rm -f ./.pd_tmp  
2219    
2220  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"  #  Search for packages to compile.
2221  #  file should eventually be added so that, for convenience, one can  echo "  checking list of packages to compile:"
2222  #  specify groups of packages using names like "ocean" and "atmosphere".  PKG_LIST=
2223  echo "  checking default package list:  "  if test "x${PKG_LIST}" = x ; then
 if test "x${PDEFAULT}" = x ; then  
2224      for i in "." $MODS ; do      for i in "." $MODS ; do
2225          if test -r $i"/packages.conf" ; then          if test -r $i"/packages.conf" ; then
2226                  PDEFAULT=$i"/packages.conf"                  PKG_LIST=$i"/packages.conf"
2227                  break                  break
2228          fi          fi
2229      done      done
2230  fi  fi
2231  if test "x${PDEFAULT}" = x ; then  if test "x${PKG_LIST}" = x ; then
2232      PDEFAULT="$ROOTDIR/pkg/pkg_default"      pkg_list='default_pkg_list'
2233  fi      if test "x${PKG_GROUPS}" = x ; then
2234  if test "x${PDEFAULT}" = xNONE ; then          echo "Error:  need package groups info to expand pkg_list=\"$pkg_list\""
2235      echo "    default packages file disabled"          exit 1
2236        fi
2237  else  else
2238      if test ! -r $PDEFAULT ; then      if test ! -r $PKG_LIST ; then
2239          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""          echo "Error:  can't read package list from PKG_LIST=\"$PKG_LIST\""
2240            exit 1
2241      else      else
2242          echo "    using PDEFAULT=\"$PDEFAULT\""          echo "    using PKG_LIST=\"$PKG_LIST\""
2243          #  Strip the comments and add all the names          #  Strip the comments and add all the names
2244          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}'`
2245          RETVAL=$?          RETVAL=$?
2246          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
2247              printf "Error: can't parse default package list "              printf "Error: can't parse package list "
2248              echo "-- please check PDEFAULT=\"$PDEFAULT\""              echo "-- please check PKG_LIST=\"$PKG_LIST\""
2249              exit 1              exit 1
2250          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"  
2251      fi      fi
2252  fi  fi
2253    for i in $pkg_list ; do
2254        PACKAGES="$PACKAGES $i"
2255    done
2256    echo     "    before group expansion packages are:$PACKAGES"
2257    if test "x${PKG_GROUPS}" != x ; then
2258        RET=1
2259        while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
2260        echo "    after group expansion packages are: $PACKAGES"
2261    fi
2262    
2263  echo "  applying DISABLE settings"  echo "  applying DISABLE settings"
2264    echo "" > $TMP.pack
2265  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2266      echo $i >> ./.tmp_pack      echo $i >> $TMP.pack
2267  done  done
2268  for i in `grep  "-" ./.tmp_pack` ; do  for i in `grep  "-" $TMP.pack` ; do
2269      j=`echo $i | sed 's/[-]//'`      j=`echo $i | sed 's/[-]//'`
2270      DISABLE="$DISABLE $j"      DISABLE="$DISABLE $j"
2271  done  done
# Line 1966  for p in $PACKAGES ; do Line 2283  for p in $PACKAGES ; do
2283  done  done
2284  PACKAGES="$pack"  PACKAGES="$pack"
2285  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
2286  echo "" > ./.tmp_pack  echo "" > $TMP.pack
2287  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
2288  # Test if each explicitly referenced package exists  # Test if each explicitly referenced package exists
2289  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2290      j=`echo $i | sed 's/[-+]//'`      j=`echo $i | sed 's/[-+]//'`
2291      if test ! -d "$ROOTDIR/pkg/$j" ; then      if test ! -d "$ROOTDIR/pkg/$j" ; then
2292          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""          echo "Error: dir '$ROOTDIR/pkg/$i' missing for package '$i'"
2293          exit 1          exit 1
2294      fi      fi
2295      echo $i >> ./.tmp_pack      echo $i >> $TMP.pack
2296  done  done
2297  PACKAGES=  PACKAGES=
2298  for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do  for i in `grep -v "-" $TMP.pack | sort | uniq` ; do
2299      PACKAGES="$PACKAGES $i"      PACKAGES="$PACKAGES $i"
2300  done  done
2301  rm -f ./.tmp_pack  rm -f $TMP.pack
2302  echo "    packages are:  $PACKAGES"  echo "    packages are: $PACKAGES"
2303    
2304  #  Check for package MNC: if NetCDF is available, then build the MNC  #  Check for package MNC: if NetCDF is available, then build the MNC
2305  #  template files ; otherwise, delete mnc from the list of packages.  #  template files ; otherwise, delete mnc from the list of packages.
2306  echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1  echo " $PACKAGES " | grep ' mnc ' > /dev/null 2>&1
2307  RETVAL=$?  mnc_in=$?
2308  if test "x$RETVAL" = x0 ; then  if test "x$HAVE_NETCDF" != xt ; then
2309      if test "x$HAVE_NETCDF" != xt ; then      if test "x$mnc_in" = x0 ; then
2310          cat <<EOF          cat <<EOF
   
2311  *********************************************************************  *********************************************************************
2312  WARNING: the "mnc" package was enabled but tests failed to compile  WARNING: the "mnc" package was enabled but tests failed to compile
2313    NetCDF applications.  Please check that:    NetCDF applications.  Please check that:
2314    
2315    1) NetCDF is correctly installed for this compiler and    1) NetCDF is correctly installed for this compiler and
2316    2) the LIBS variable (within the "optfile") specifies the correct    2) the LIBS variable (within the "optfile") specifies the correct
2317         NetCDF library to link against.         NetCDF library to link against.
2318    
2319    Due to this failure, the "mnc" package is now DISABLED.    Due to this failure, the "mnc" package is now DISABLED.
2320  *********************************************************************  *********************************************************************
   
2321  EOF  EOF
2322          PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`          PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
2323          DISABLE="$DISABLE mnc"          DISABLE="$DISABLE mnc"
2324      else      else
2325          ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1      #  this prevent to add mnc (due to pdepend rules) if not available
2326          RETVAL=$?          DISABLE="$DISABLE mnc"
2327          if test "x${RETVAL}" = x0 ; then      fi
2328              rm -f make_mnc.errors  else
2329          else      # we have NetCDF, we try to build MNC template files
2330              echo "Error: problem encountered while building source files in pkg/mnc:"      ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
2331              cat make_mnc.errors 1>&2      RETVAL=$?
2332        if test "x${RETVAL}" = x0 ; then
2333            rm -f make_mnc.errors
2334        else
2335            echo "Error: problem encountered while building source files in pkg/mnc:"
2336            cat make_mnc.errors 1>&2
2337            if test "x$mnc_in" = x0 ; then
2338              exit 1              exit 1
2339            else
2340                DISABLE="$DISABLE mnc"
2341          fi          fi
2342      fi      fi
2343  fi  fi
2344    
2345  #  Check for package PROFILES: if NetCDF is not available,  #  Check for package PROFILES: if NetCDF is not available,
2346  #  then delete profiles from the list of available packages.  #  then delete profiles from the list of available packages.
2347  echo $PACKAGES | grep ' profiles ' > /dev/null 2>&1  if test "x$HAVE_NETCDF" != xt ; then
2348  RETVAL=$?      echo " $PACKAGES " | grep ' profiles ' > /dev/null 2>&1
2349  if test "x$RETVAL" = x0 ; then      RETVAL=$?
2350      if test "x$HAVE_NETCDF" != xt ; then      if test "x$RETVAL" = x0 ; then
2351          cat <<EOF          cat <<EOF
   
2352  *********************************************************************  *********************************************************************
2353  WARNING: the "profiles" package was enabled but tests failed to  WARNING: the "profiles" package was enabled but tests failed to
2354    compile NetCDF applications.  Please check that:    compile NetCDF applications.  Please check that:
2355    
2356    1) NetCDF is correctly installed for this compiler and    1) NetCDF is correctly installed for this compiler and
2357    2) the LIBS variable (within the "optfile") specifies the correct    2) the LIBS variable (within the "optfile") specifies the correct
2358         NetCDF library to link against.         NetCDF library to link against.
2359    
2360    Due to this failure, the "profiles" package is now DISABLED.    Due to this failure, the "profiles" package is now DISABLED.
2361  *********************************************************************  *********************************************************************
   
2362  EOF  EOF
2363          PACKAGES=`echo $PACKAGES | sed -e 's/profiles//g'`          PACKAGES=`echo $PACKAGES | sed -e 's/profiles//g'`
2364          DISABLE="$DISABLE profiles"          DISABLE="$DISABLE profiles"
2365        else
2366        #  this prevent to add profiles (due to pdepend rules) if not available
2367            DISABLE="$DISABLE profiles"
2368        fi
2369    fi
2370    
2371    #  Make sure the openad package is enabled if using OpenAD
2372    if test "x$OPENAD" != x ; then
2373        echo " $PACKAGES " | grep ' openad ' > /dev/null 2>&1
2374        RETVAL=$?
2375        if test "x$RETVAL" != x0 ; then
2376            cat <<EOF
2377    
2378    *********************************************************************
2379    ERROR: when generating an adjoint with OpenAD, the openad package
2380      must be enabled.  Please add it to packages.conf.
2381    *********************************************************************
2382    
2383    EOF
2384            exit 1
2385      fi      fi
2386  fi  fi
2387    
2388  echo "  applying package dependency rules"  if  test "x${PKG_DEPEND}" != x ; then
2389  ck=    echo "  applying package dependency rules"
2390  while test "x$ck" != xtt ; do    ck=
2391      while test "x$ck" != xtt ; do
2392      i=0      i=0
2393      # rtot=${#PNAME[@]}      # rtot=${#PNAME[@]}
2394      rtot=$nname      rtot=$nname
# Line 2062  while test "x$ck" != xtt ; do Line 2404  while test "x$ck" != xtt ; do
2404                  pin="t"                  pin="t"
2405              fi              fi
2406          done          done
2407            #  or in the current $STANDARDDIRS list?
2408            for p in $STANDARDDIRS ; do
2409                if test "x$p" = "x$pname" ; then pin="t" ; fi
2410            done
2411    
2412          #  Is the DNAME entry a (+) or (-) rule ?          #  Is the DNAME entry a (+) or (-) rule ?
2413          tmp="dname=\"\$DNAME_$i\""          tmp="dname=\"\$DNAME_$i\""
# Line 2084  while test "x$ck" != xtt ; do Line 2430  while test "x$ck" != xtt ; do
2430    
2431          #  Do we need to add $dname according to the dependency rules?          #  Do we need to add $dname according to the dependency rules?
2432          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
2433              #echo "   " $pname ": need to add :" $dname              #echo "   " $pname ": need to add :" $dname
2434              in_dis="f"              in_dis="f"
2435              for dis in $DISABLE ; do              for dis in $DISABLE ; do
2436                  if test "x$dis" = "x$dname" ; then                  if test "x$dis" = "x$dname" ; then
# Line 2105  while test "x$ck" != xtt ; do Line 2451  while test "x$ck" != xtt ; do
2451          #  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?
2452          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
2453              echo "Error: can't satisfy package dependencies:"              echo "Error: can't satisfy package dependencies:"
2454              echo "  \"$pname\" was requested but is disallowed by"              echo "  \"$pname\" was requested but is disallowed by"
2455              echo "  the dependency rules for \"$dname\""              echo "  the dependency rules for \"$dname\""
2456              exit 1              exit 1
2457          fi          fi
2458          i=`echo "$i + 1" | bc -l`          i=`echo "$i + 1" | bc -l`
2459          #i=$(( $i + 1 ))          #i=$(( $i + 1 ))
2460      done      done
2461      ck=$ck"t"      ck=$ck"t"
2462  done    done
2463  echo "    packages are:  $PACKAGES"    echo "    packages are: $PACKAGES"
2464    fi
2465  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2466      adr="$ROOTDIR/pkg/$i"      adr="$ROOTDIR/pkg/$i"
2467      if test -d $adr ; then      if test -d $adr ; then
# Line 2131  done Line 2478  done
2478    
2479  # Create a list of #define and #undef to enable/disable packages  # Create a list of #define and #undef to enable/disable packages
2480  PACKAGES_DOT_H=PACKAGES_CONFIG.h  PACKAGES_DOT_H=PACKAGES_CONFIG.h
2481  #  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
2482  #  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
2483  #  file would eventually be split up so that all package-related #define  #  file would eventually be split up so that all package-related #define
2484  #  statements could be separated and handled only by genmake.  #  statements could be separated and handled only by genmake.
2485  names=`ls -1 "$ROOTDIR/pkg"`  names=`ls -1 "$ROOTDIR/pkg"`
# Line 2149  for n in $names ; do Line 2496  for n in $names ; do
2496          done          done
2497          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
2498              undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`              undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2499              DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"              DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
2500          fi          fi
2501      fi      fi
2502  done  done
# Line 2160  for i in $PACKAGES ; do Line 2507  for i in $PACKAGES ; do
2507  #eh3 DEFINES="$DEFINES -D$def"  #eh3 DEFINES="$DEFINES -D$def"
2508    
2509  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
2510      case $i in      case $i in
2511          aim_v23)          aim_v23)
2512              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
2513              echo "Warning: ALLOW_AIM is set to enable aim_v23."              echo "Warning: ALLOW_AIM is set to enable aim_v23."
2514              ;;              ;;
2515      esac      esac
# Line 2170  for i in $PACKAGES ; do Line 2517  for i in $PACKAGES ; do
2517    
2518  done  done
2519    
2520  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS='$STANDARDDIRS'"
2521  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
 if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then  
     STANDARDDIRS="eesupp model"  
 fi  
2522  if test "x$STANDARDDIRS" != x ; then  if test "x$STANDARDDIRS" != x ; then
2523      for d in $STANDARDDIRS ; do      for d in $STANDARDDIRS ; do
2524          adr="$ROOTDIR/$d/src"          adr="$ROOTDIR/$d/src"
# Line 2207  for i in $spaths ; do Line 2551  for i in $spaths ; do
2551      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
2552          echo "    found CPP_OPTIONS=\"$try\""          echo "    found CPP_OPTIONS=\"$try\""
2553          CPP_OPTIONS="$try"          CPP_OPTIONS="$try"
2554          # 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
2555          for n in $names ; do          for n in $names ; do
2556              test_for_package_in_cpp_options $CPP_OPTIONS $n              test_for_package_in_cpp_options $CPP_OPTIONS $n
2557          done          done
2558      fi      fi
2559      try="$i/CPP_EEOPTIONS.h"      try="$i/CPP_EEOPTIONS.h"
2560      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
2561          echo "    found CPP_EEOPTIONS=\"$try\""          echo "    found CPP_EEOPTIONS=\"$try\""
2562          # 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
2563  #**** not yet enabled ****  #**** not yet enabled ****
2564  #        test_for_mpi_in_cpp_eeoptions $try  #        test_for_mpi_in_cpp_eeoptions $try
2565  #**** not yet enabled ****  #**** not yet enabled ****
# Line 2229  fi Line 2573  fi
2573    
2574  #  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
2575  #  compiler.  #  compiler.
2576  if test -f ./adSrcFiles.tmp ; then  if test -f $TMP.adSrcFiles ; then
2577      rm -f ./adSrcFiles.tmp      rm -f $TMP.adSrcFiles
2578  fi  fi
2579  echo "  Creating the list of files for the adjoint compiler."  echo "  Creating the list of files for the adjoint compiler."
2580    touch $TMP.adSrcFiles
2581  for i in $SOURCEDIRS ; do  for i in $SOURCEDIRS ; do
2582      list_files=`( cd $i && ls -1 *.list 2>/dev/null )`      list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
2583      for j in $list_files ; do      for j in $list_files ; do
2584          cat $i/$j >> adSrcFiles.tmp          cat $i/$j >> $TMP.adSrcFiles
2585      done      done
2586  done  done
2587  if test ! "x"$FS = "x.f" ; then  if test ! "x"$FS = "x.f" ; then
2588      cat adSrcFiles.tmp | sed -e "s/\.f/.$FS/g" > adSrcFiles.tmp_f      cat $TMP.adSrcFiles | sed -e "s/\.f/.$FS/g" > $TMP.adSrcFiles_f
2589      mv -f adSrcFiles.tmp_f adSrcFiles.tmp      mv -f $TMP.adSrcFiles_f $TMP.adSrcFiles
2590  fi  fi
2591    
2592  echo  echo
# Line 2253  for i in $INCLUDEDIRS ; do Line 2598  for i in $INCLUDEDIRS ; do
2598      fi      fi
2599  done  done
2600    
2601  if test ! "x$DIVA" = x ; then  if test ! "x$DIVA" = x -a ! "x$MPI" = x ; then
2602      echo "  Creating the pseudo-MPI include directory"      if test ! "x$MPIINCLUDEDIR" = x ; then
2603      INCLUDES="-I./mpi_headers $INCLUDES"          #  Do a local copy of MPI headers files (in local dir ./mpi_headers/) after
2604      rm -rf ./mpi_headers          #   checking for additional included headers (in case of chain of included
2605      mkdir -p ./mpi_headers          #   header); also set LOCAL_MPI_HEADERS (if not already set)
2606            mpi_headers_do_local_copy
     if test "x$MPIINCLUDEDIR" = x ; then  
         if test "x$MPIHOME" = x ; then  
             MPIHOME='/usr'  
         fi  
         MPIINCLUDEDIR='$MPIHOME/include'  
     fi  
       
     if test -r $MPIINCLUDEDIR/mpif.h ; then  
         for i in $MPI_HEADER_FILES; do  
             cp -p $MPIINCLUDEDIR/$i ./mpi_headers  
         done  
   
         perl -i -pe 's/MPI_DISPLACEMENT_CURRENT=-1_8/MPI_DISPLACEMENT_CURRENT=-1/g' mpi_headers/mpif.h  
     else  
         echo " We cannot create a copy of mpif.h!"  
 #       exit -1  
2607      fi      fi
2608  fi  fi
2609    
2610  echo "  Determining the list of source and include files"  echo "  Determining the list of source and include files"
2611  rm -rf .links.tmp  rm -rf $TMP.links
2612  mkdir .links.tmp  mkdir $TMP.links
2613  touch .links.tmp/foo  touch $TMP.links/foo
2614  if test ! -r ".links.tmp/foo" ; then  if test ! -r "$TMP.links/foo" ; then
2615      echo      echo
2616      echo "ERROR : something is wrong with your directory permissions or"      echo "ERROR : something is wrong with your directory permissions or"
2617      echo "   your user file-creation mask (\"umask\") since creating a"      echo "   your user file-creation mask (\"umask\") since creating a"
# Line 2298  if test ! -r ".links.tmp/foo" ; then Line 2627  if test ! -r ".links.tmp/foo" ; then
2627      echo      echo
2628      exit 1      exit 1
2629  fi  fi
2630  rm -f .links.tmp/foo  rm -f $TMP.links/foo
2631    
2632  if test "x$OPENAD" != x ; then  if test "x$OPENAD" != x ; then
2633      OAD_DONT_COMPILE="/dev/null"      OAD_DONT_COMPILE="/dev/null"
2634      OAD_DONT_TRANSFORM="/dev/null"      OAD_DONT_TRANSFORM="/dev/null"
2635      OAD_KEEP_ORIGINAL="/dev/null"      OAD_KEEP_ORIGINAL="/dev/null"
2636      OAD_CB2M_FILES="/dev/null"      OAD_CB2M_FILES="/dev/null"
2637        OADTOOLS="$TOOLSDIR/OAD_support"
2638      echo "  looking for dontCompile file:  "      echo "  looking for dontCompile file:  "
2639      for i in "." $MODS ; do      for i in "." $MODS $OADTOOLS ; do
2640          if test -r $i"/dontCompile" ; then          if test -r $i"/dontCompile" ; then
2641              OAD_DONT_COMPILE=$i"/dontCompile"              OAD_DONT_COMPILE=$i"/dontCompile"
2642              echo "     found $OAD_DONT_COMPILE"              echo "     found $OAD_DONT_COMPILE"
# Line 2314  if test "x$OPENAD" != x ; then Line 2644  if test "x$OPENAD" != x ; then
2644          fi          fi
2645      done      done
2646      echo "  looking for dontTransform file:  "      echo "  looking for dontTransform file:  "
2647      for i in "." $MODS ; do      for i in "." $MODS $OADTOOLS ; do
2648          if test -r $i"/dontTransform" ; then          if test -r $i"/dontTransform" ; then
2649              OAD_DONT_TRANSFORM=$i"/dontTransform"              OAD_DONT_TRANSFORM=$i"/dontTransform"
2650              echo "     found $OAD_DONT_TRANSFORM"              echo "     found $OAD_DONT_TRANSFORM"
# Line 2322  if test "x$OPENAD" != x ; then Line 2652  if test "x$OPENAD" != x ; then
2652          fi          fi
2653      done      done
2654      echo "  looking for keepOriginal file:  "      echo "  looking for keepOriginal file:  "
2655      for i in "." $MODS ; do      for i in "." $MODS $OADTOOLS ; do
2656          if test -r $i"/keepOriginal" ; then          if test -r $i"/keepOriginal" ; then
2657              OAD_KEEP_ORIGINAL=$i"/keepOriginal"              OAD_KEEP_ORIGINAL=$i"/keepOriginal"
2658              echo "     found $OAD_KEEP_ORIGINAL"              echo "     found $OAD_KEEP_ORIGINAL"
# Line 2330  if test "x$OPENAD" != x ; then Line 2660  if test "x$OPENAD" != x ; then
2660          fi          fi
2661      done      done
2662      echo "  looking for cb2mFiles:  "      echo "  looking for cb2mFiles:  "
2663      for i in "." $MODS ; do      for i in "." $MODS $OADTOOLS ; do
2664          if test -r $i"/cb2mFiles" ; then          if test -r $i"/cb2mFiles" ; then
2665              OAD_CB2M_FILES=$i"/cb2mFiles"              OAD_CB2M_FILES=$i"/cb2mFiles"
2666              echo "     found $OAD_CB2M_FILES"              echo "     found $OAD_CB2M_FILES"
# Line 2340  if test "x$OPENAD" != x ; then Line 2670  if test "x$OPENAD" != x ; then
2670      echo "   OpenAD exceptions:  "      echo "   OpenAD exceptions:  "
2671  fi  fi
2672    
2673  echo "# This section creates symbolic links" > srclinks.tmp  echo "# This section creates symbolic links" > $TMP.srclinks
2674  echo "" >> srclinks.tmp  echo "" >> $TMP.srclinks
2675  printf 'F77_SRC_FILES = ' > F77srclist.tmp  printf 'F77_SRC_FILES = ' > $TMP.F77srclist
2676  printf 'NON_AD_F77_SRC_FILES = ' > nonADF77srclist.tmp  printf 'NON_AD_F77_SRC_FILES = ' > $TMP.nonADF77srclist
2677  printf 'C_SRC_FILES = '   > csrclist.tmp  printf 'C_SRC_FILES = '   > $TMP.csrclist
2678  printf 'F90_SRC_FILES = ' > F90srclist.tmp  printf 'F90_SRC_FILES = ' > $TMP.F90srclist
2679  printf 'H_SRC_FILES = '   > hsrclist.tmp  printf 'H_SRC_FILES = '   > $TMP.hsrclist
2680  printf 'AD_FLOW_FILES = ' > ad_flow_files.tmp  printf 'AD_FLOW_FILES = ' > $TMP.ad_flow_files
2681  alldirs="$SOURCEDIRS $INCLUDEDIRS ."  alldirs="$SOURCEDIRS $INCLUDEDIRS ."
2682  for d in $alldirs ; do  for d in $alldirs ; do
2683      deplist=      deplist=
2684      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
2685      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
2686      if test "x$OPENAD" != x ; then      if test "x$OPENAD" != x ; then
2687          sfiles=`( echo $sfiles | grep -v _cb2m\. )`          sfiles=`( echo $sfiles | grep -v _cb2m\. )`
2688      fi      fi
2689      for sf in $sfiles ; do      for sf in $sfiles ; do
2690          if test ! -r ".links.tmp/$sf" ; then          if test ! -r "$TMP.links/$sf" ; then
2691              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
2692                  ignore_f=f                  ignore_f=f
2693                  case $d/$sf in                  case $d/$sf in
2694                    ./$PACKAGES_DOT_H)                    ./$PACKAGES_DOT_H)
2695                          ignore_f=t                          ignore_f=t
2696                          ;;                          ;;
2697                    ./AD_CONFIG.h)                    ./AD_CONFIG.h)
2698                          ignore_f=t                          ignore_f=t
2699                          ;;                          ;;
2700                    ./FC_NAMEMANGLE.h)                    ./FC_NAMEMANGLE.h)
2701                          ignore_f=t                          ignore_f=t
2702                          ;;                          ;;
2703                    ./BUILD_INFO.h)                    ./BUILD_INFO.h)
2704                          ignore_f=t                          ignore_f=t
2705                          ;;                          ;;
2706                    ./EMBEDDED_FILES.h)                    ./EMBEDDED_FILES.h)
2707                          ignore_f=t                          ignore_f=t
2708                          ;;                          ;;
2709                    *)                    *)
2710                          #  For the local directory *ONLY*,                          #  For the local directory *ONLY*,
2711                          #  ignore all soft-links                          #  ignore all soft-links
2712                          if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then                          if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then
2713                              ignore_f=t                              ignore_f=t
2714                          else                          else
2715                              touch .links.tmp/$sf                              touch $TMP.links/$sf
2716                              deplist="$deplist $sf"                              deplist="$deplist $sf"
2717                          fi                          fi
2718                          ;;                          ;;
2719                  esac                  esac
2720                  if test "x$ignore_f" = xf ; then                  if test "x$ignore_f" = xf ; then
2721                      extn=`echo $sf | $AWK -F. '{print $NF}'`                      extn=`echo $sf | $AWK -F. '{print $NF}'`
2722                      case $extn in                      case $extn in
2723                        F)                        F)
2724                          echo    " \\"  >> F77srclist.tmp                          echo    " \\"  >> $TMP.F77srclist
2725                          printf " $sf" >> F77srclist.tmp                          printf " $sf" >> $TMP.F77srclist
2726                          if test "x$OPENAD" != x ; then                          if test "x$OPENAD" = x ; then
2727                                basename=${sf%%.F}
2728                                isAD=`egrep ^$basename.f'[  ]*' $TMP.adSrcFiles`
2729                                if test -z "$isAD" ; then
2730                                    echo    " \\"  >> $TMP.nonADF77srclist
2731                                    printf " $sf" >> $TMP.nonADF77srclist
2732                                fi
2733                            else #- OpenAD case:
2734                              basename=${sf%%.F}                              basename=${sf%%.F}
2735                              isAD=`egrep ^$basename.f'[  ]*' adSrcFiles.tmp`                              isAD=`egrep ^$basename.f'[  ]*' $TMP.adSrcFiles`
2736                              if test -z "$isAD" ; then                              if test -z "$isAD" ; then
2737                                  toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE}`                                  toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE}`
2738                                  if test -z "$toBeIgnored" ; then                                  if test -z "$toBeIgnored" ; then
2739                                      echo    " \\"  >> nonADF77srclist.tmp                                      echo    " \\"  >> $TMP.nonADF77srclist
2740                                      printf " $sf" >> nonADF77srclist.tmp                                      printf " $sf" >> $TMP.nonADF77srclist
2741                                  else                                  else
2742                                      echo "    not to be compiled   :  $sf"                                      echo "    not to be compiled   :  $sf"
2743                                  fi                                  fi
2744                              else # file is initially listed as an AD file we want to exclude it                              else # file is initially listed as an AD file we want to exclude it
2745                                   # or we want to retain the untransformed version                                   # or we want to retain the untransformed version
2746                                  notToBeTransformed=`egrep ^$basename'[      ]*' ${OAD_DONT_TRANSFORM}`                                  notToBeTransformed=`egrep ^$basename'[      ]*' ${OAD_DONT_TRANSFORM}`
2747                                  untransformedVersionToBeKept=`egrep ^$basename'[      ]*' ${OAD_KEEP_ORIGINAL}`                                  untransformedVersionToBeKept=`egrep ^$basename'[      ]*' ${OAD_KEEP_ORIGINAL}`
2748                                  if test -n "$notToBeTransformed"; then                                  if test -n "$notToBeTransformed"; then
2749                                      echo "    not to be transformed:  $sf"                                      echo "    not to be transformed:  $sf"
2750                                  fi                                  fi
2751                                  if test -n "$untransformedVersionToBeKept" ; then                                  if test -n "$untransformedVersionToBeKept" ; then
2752                                      echo "    original to be kept  :  $sf"                                      echo "    original to be kept  :  $sf"
2753                                  fi                                      fi
2754                                  if test -n "$notToBeTransformed" -o -n "$untransformedVersionToBeKept" ; then                                  if test -n "$notToBeTransformed" -o -n "$untransformedVersionToBeKept" ; then
2755                                      echo    " \\"  >> nonADF77srclist.tmp                                      echo    " \\"  >> $TMP.nonADF77srclist
2756                                      printf " $sf" >> nonADF77srclist.tmp                                      printf " $sf" >> $TMP.nonADF77srclist
2757                                  fi                                  fi
2758                              fi                              fi
2759                          fi                          fi
2760                          ;;                          ;;
2761                      F90)                      F90)
2762                          echo    " \\"  >> F90srclist.tmp                          echo    " \\"  >> $TMP.F90srclist
2763                          printf " $sf" >> F90srclist.tmp                          printf " $sf" >> $TMP.F90srclist
2764                          ;;                          ;;
2765                      c)                      c)
2766                          echo    " \\"  >> csrclist.tmp                          echo    " \\"  >> $TMP.csrclist
2767                          printf " $sf" >> csrclist.tmp                          printf " $sf" >> $TMP.csrclist
2768                          ;;                          ;;
2769                      h)                      h)
2770                          echo    " \\"  >> hsrclist.tmp                          echo    " \\"  >> $TMP.hsrclist
2771                          printf " $sf" >> hsrclist.tmp                          printf " $sf" >> $TMP.hsrclist
2772                          ;;                          ;;
2773                      flow)                      flow)
2774                          echo    " \\"  >> ad_flow_files.tmp                          echo    " \\"  >> $TMP.ad_flow_files
2775                          printf " $sf" >> ad_flow_files.tmp                          printf " $sf" >> $TMP.ad_flow_files
2776                          ;;                          ;;
2777                     esac                     esac
2778                  fi                  fi
# Line 2444  for d in $alldirs ; do Line 2781  for d in $alldirs ; do
2781      done      done
2782      if test "x$deplist" != x ; then      if test "x$deplist" != x ; then
2783        if test "$d" != "." ; then        if test "$d" != "." ; then
2784          echo "" >> srclinks.tmp          echo "" >> $TMP.srclinks
2785          echo "#  These files are linked from $d" >> srclinks.tmp          echo "#  These files are linked from $d" >> $TMP.srclinks
2786          echo "$deplist :" >> srclinks.tmp          echo "$deplist :" >> $TMP.srclinks
2787  # We need to make sure that the link isn't already there.  # We need to make sure that the link isn't already there.
2788  # This may happen when make thinks that a header file has to be "remade"  # This may happen when make thinks that a header file has to be "remade"
2789  # because a module it depends on has changed.  In this case we do nothing.  # because a module it depends on has changed.  In this case we do nothing.
2790          printf "\tif [ ! -L \$@ ]; then \$(LN) %s/\$@ \$@; fi\n" $d >> srclinks.tmp          printf "\tif [ ! -L \$@ ]; then \$(LN) %s/\$@ \$@; fi\n" $d >> $TMP.srclinks
2791        fi        fi
2792      fi      fi
2793  done  done
2794  rm -rf .links.tmp  rm -rf $TMP.links
2795  echo "" >> F77srclist.tmp  echo "" >> $TMP.F77srclist
2796  echo "" >> nonADF77srclist.tmp  echo "" >> $TMP.nonADF77srclist
2797  echo "" >> csrclist.tmp  echo "" >> $TMP.csrclist
2798  echo "" >> F90srclist.tmp  echo "" >> $TMP.F90srclist
2799  echo "" >> hsrclist.tmp  echo "" >> $TMP.hsrclist
2800  echo "" >> ad_flow_files.tmp  echo "" >> $TMP.ad_flow_files
2801    
2802    CMDLINE=$0
2803    for xx in "$@" ; do nw=`echo $xx | wc -w`
2804        if test $nw = '1' ; then CMDLINE="$CMDLINE $xx"
2805                            else CMDLINE="$CMDLINE '$xx'" ; fi
2806    done
2807    
2808  if test -f $MAKEFILE ; then  if test -f $MAKEFILE ; then
2809      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.old"
2810  fi  fi
2811  echo "  Writing makefile: $MAKEFILE"  echo "  Writing makefile: $MAKEFILE"
2812  echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE  echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
# Line 2471  echo "#    $MACHINE" >> $MAKEFILE Line 2814  echo "#    $MACHINE" >> $MAKEFILE
2814  echo "# This makefile was generated automatically on" >> $MAKEFILE  echo "# This makefile was generated automatically on" >> $MAKEFILE
2815  echo "#    $THISDATE" >> $MAKEFILE  echo "#    $THISDATE" >> $MAKEFILE
2816  echo "# by the command:" >> $MAKEFILE  echo "# by the command:" >> $MAKEFILE
2817  echo "#    $0 $G2ARGS" >> $MAKEFILE  echo "#    $CMDLINE"  >> $MAKEFILE
2818  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
2819  echo "#    ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE  echo "#    ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
2820    
# Line 2482  EXE_SVD=$EXECUTABLE"_svd" Line 2825  EXE_SVD=$EXECUTABLE"_svd"
2825  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2826  #  #
2827  # OPTFILE="$OPTFILE"  # OPTFILE="$OPTFILE"
2828  #  #
2829  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
2830  # SOURCEDIRS   : Directories containing the source (.F) files  # SOURCEDIRS   : Directories containing the source (.F) files
2831  # INCLUDEDIRS  : Directories containing the header-source (.h) files  # INCLUDEDIRS  : Directories containing the header-source (.h) files
# Line 2493  cat >>$MAKEFILE <<EOF Line 2836  cat >>$MAKEFILE <<EOF
2836  # INCLUDES     : Directories searched for header files  # INCLUDES     : Directories searched for header files
2837  # DEFINES      : Macro definitions for CPP  # DEFINES      : Macro definitions for CPP
2838  # MAKEDEPEND   : Dependency generator  # MAKEDEPEND   : Dependency generator
 # KPP          : Special preprocessor command (specific to platform)  
 # KFLAGS       : Flags for KPP  
2839  # FC           : Fortran compiler command  # FC           : Fortran compiler command
2840  # FFLAGS       : Configuration/debugging options for FC  # FFLAGS       : Configuration/debugging options for FC
2841  # FOPTIM       : Optimization options for FC  # FOPTIM       : Optimization options for FC
# Line 2502  cat >>$MAKEFILE <<EOF Line 2843  cat >>$MAKEFILE <<EOF
2843  # LIBS         : Library flags /or/ additional optimization/debugging flags  # LIBS         : Library flags /or/ additional optimization/debugging flags
2844    
2845  ROOTDIR     = ${ROOTDIR}  ROOTDIR     = ${ROOTDIR}
2846  BUILDDIR    = ${BUILDDIR}    BUILDDIR    = ${BUILDDIR}
2847  SOURCEDIRS  = ${SOURCEDIRS}  SOURCEDIRS  = ${SOURCEDIRS}
2848  INCLUDEDIRS = ${INCLUDEDIRS}  INCLUDEDIRS = ${INCLUDEDIRS}
2849  EXEDIR      = ${EXEDIR}  EXEDIR      = ${EXEDIR}
2850  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}
2851  TOOLSDIR    = ${TOOLSDIR}  TOOLSDIR    = ${TOOLSDIR}
2852    OADTOOLS    = ${OADTOOLS}
2853    
2854  #eh3  new defines for the adjoint work  #eh3  new defines for the adjoint work
2855  AUTODIFF    = ${ROOTDIR}/pkg/autodiff  AUTODIFF    = ${ROOTDIR}/pkg/autodiff
# Line 2528  else Line 2870  else
2870      echo "EMBEDDED_FILES = " >>$MAKEFILE      echo "EMBEDDED_FILES = " >>$MAKEFILE
2871  fi  fi
2872    
2873  #  Note: figure out some way to add Hyades JAM libraries here  # extract default cpp search path so we can pass it to makedepend
2874    CPPINCLUDES=`cat /dev/null | $CPP -v 2>&1 | awk '/^End of search/{f=0}!/^\#/{if(f){printf " -I%s", $1;}}/^\#include "..." search start/{f=1}'`
2875    
2876  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2877  # Unix ln (link)  # Unix ln (link)
2878  LN = ${LN}  LN = ${LN}
 # C preprocessor  
 CPP = cat \$< | ${S64} | ${CPP}  
2879  # Dependency generator  # Dependency generator
2880  MAKEDEPEND = ${MAKEDEPEND}  MAKEDEPEND = ${MAKEDEPEND}
2881  # Special preprocessor (KAP on DECs, FPP on Crays)  # Special preprocessor (KAP on DECs, FPP on Crays)
# Line 2551  LINK = ${LINK} ${LDADD} Line 2893  LINK = ${LINK} ${LDADD}
2893  DEFINES = ${DEFINES}  DEFINES = ${DEFINES}
2894  # Includes for CPP  # Includes for CPP
2895  INCLUDES = ${INCLUDES}  INCLUDES = ${INCLUDES}
2896    # default CPP includes for makedepend
2897    CPPINCLUDES = ${CPPINCLUDES}
2898  # Flags for KPP  # Flags for KPP
2899  KFLAGS1 = ${KFLAGS1}  KFLAGS1 = ${KFLAGS1}
2900  KFLAGS2 = ${KFLAGS2}  KFLAGS2 = ${KFLAGS2}
2901  # Optim./debug for FC  # Optim./debug for FC
2902  FFLAGS = ${FFLAGS} ${FEXTRAFLAGS}  FFLAGS = ${FFLAGS}
2903  FOPTIM = ${FOPTIM}  FOPTIM = ${FOPTIM} ${FEXTRAFLAGS}
2904  # Optim./debug for FC  # Optim./debug for FC
2905  F90FLAGS = ${F90FLAGS}  F90FLAGS = ${F90FLAGS}
2906  F90OPTIM = ${F90OPTIM}  F90OPTIM = ${F90OPTIM}
# Line 2568  NOOPTFILES = ${NOOPTFILES} Line 2912  NOOPTFILES = ${NOOPTFILES}
2912  NOOPTFLAGS = ${NOOPTFLAGS}  NOOPTFLAGS = ${NOOPTFLAGS}
2913  # Flags and libraries needed for linking  # Flags and libraries needed for linking
2914  LIBS = ${LIBS}  LIBS = ${LIBS}
2915  # Name of the Mekfile  # Name of the makefile
2916  MAKEFILE=${MAKEFILE}  MAKEFILE = ${MAKEFILE}
2917    # Name of the make program
2918    MAKE = ${MAKE}
2919    
2920  EOF  EOF
2921    
2922  cat F77srclist.tmp      >> $MAKEFILE  cat $TMP.F77srclist      >> $MAKEFILE
2923  cat nonADF77srclist.tmp >> $MAKEFILE  cat $TMP.nonADF77srclist >> $MAKEFILE
2924  cat csrclist.tmp        >> $MAKEFILE  cat $TMP.csrclist        >> $MAKEFILE
2925  cat F90srclist.tmp      >> $MAKEFILE  cat $TMP.F90srclist      >> $MAKEFILE
2926  cat hsrclist.tmp        >> $MAKEFILE  cat $TMP.hsrclist        >> $MAKEFILE
2927  cat ad_flow_files.tmp   >> $MAKEFILE  cat $TMP.ad_flow_files   >> $MAKEFILE
2928    
2929  rm -f F77srclist.tmp nonADF77srclist.tmp csrclist.tmp F90srclist.tmp hsrclist.tmp ad_flow_files.tmp  rm -f $TMP.F77srclist $TMP.nonADF77srclist $TMP.csrclist $TMP.F90srclist $TMP.hsrclist $TMP.ad_flow_files
2930    
2931  echo >> $MAKEFILE  echo >> $MAKEFILE
2932    
2933  # add definitions for preprocessed sources  # add definitions for preprocessed sources
2934  # and note that not all systems allow case sensitive extensions  # and note that not all systems allow case sensitive extensions
2935  # hence the $FS and $FS90 here.  # hence the $FS and $FS90 here.
2936  # for fixed format f90 files we use ff90 or FF90 resp  # for fixed format f90 files we use ff90 or FF90 resp
2937  # but these are not expected to be the original source files  # but these are not expected to be the original source files
2938    
2939  echo 'F77_PP_SRC_FILES = $(F77_SRC_FILES:.F=.'$FS')'      >> $MAKEFILE  echo 'F77_PP_SRC_FILES = $(F77_SRC_FILES:.F=.'$FS')'      >> $MAKEFILE
2940  echo 'F90_PP_SRC_FILES = $(F90_SRC_FILES:.F90=.'$FS90')' >> $MAKEFILE  echo 'F90_PP_SRC_FILES = $(F90_SRC_FILES:.F90=.'$FS90')' >> $MAKEFILE
2941  echo 'OBJFILES= $(F77_SRC_FILES:.F=.o) $(C_SRC_FILES:.c=.o) $(F90_SRC_FILES:.F90=.o)' >> $MAKEFILE  echo 'OBJFILES= $(F77_SRC_FILES:.F=.o) $(C_SRC_FILES:.c=.o) $(F90_SRC_FILES:.F90=.o)' >> $MAKEFILE
2942  echo 'FLOFILES =  $(AD_FLOW_FILES:.flow=.flowdir)' >> $MAKEFILE  echo 'FLOWFILES =  $(AD_FLOW_FILES:.flow=.flowdir)' >> $MAKEFILE
2943  echo >> $MAKEFILE  echo >> $MAKEFILE
2944  echo '.SUFFIXES:' >> $MAKEFILE  echo '.SUFFIXES:' >> $MAKEFILE
2945  echo '.SUFFIXES: .o .'$FS' .p .F .c .f'$FS90' .'$FS90' .FF90 .F90 .flowdir .flow' >> $MAKEFILE  echo '.SUFFIXES: .o .'$FS' .p .F .c .f'$FS90' .'$FS90' .FF90 .F90 .flowdir .flow' >> $MAKEFILE
2946    
2947  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2948    
2949  all: \$(EXECUTABLE)  all: fwd_exe_target
2950    fwd_exe_target:
2951            @echo Update AD_CONFIG.h and make \$(EXECUTABLE)
2952            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Forward version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
2953            @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
2954            @-rm -f ad_config.template
2955            \$(MAKE) -f \$(MAKEFILE) \$(EXECUTABLE)
2956    
2957  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(OBJFILES) \$(EMBEDDED_FILES)  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(OBJFILES) \$(EMBEDDED_FILES)
2958          @echo Creating \$@ ...          @echo Creating \$@ ...
2959          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
2960    
2961  depend:  depend:
2962          @make links          @\$(MAKE) -f \$(MAKEFILE) links
2963          \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)          \$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(CPPINCLUDES) \$(F77_SRC_FILES)
2964          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2965          -rm -f makedepend.out          -rm -f makedepend.out
2966    
# Line 2616  libmitgcmuv.a: \$(OBJFILES) Line 2970  libmitgcmuv.a: \$(OBJFILES)
2970          ar rcv libmitgcmuv.a \$(OBJFILES)          ar rcv libmitgcmuv.a \$(OBJFILES)
2971          ar d   libmitgcmuv.a main.o          ar d   libmitgcmuv.a main.o
2972    
2973    obj: \$(OBJFILES)
2974    
2975  links: \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(SPECIAL_FILES)  links: \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(SPECIAL_FILES)
2976    
2977  small_f: \$(F77_PP_SRC_FILES) \$(F90_PP_SRC_FILES)  small_f: \$(F77_PP_SRC_FILES) \$(F90_PP_SRC_FILES)
2978    
2979  output.txt: \$(EXECUTABLE)  # remove most of the files that "make" generates
         @printf 'running ... '  
         @\$(EXECUTABLE) > \$@  
   
2980  clean:  clean:
2981          -rm -rf *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template          -rm -rf *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
2982          -rm -rf *.o          -rm -rf *.o
2983          -rm -rf *.$FS *.flowdir          -rm -rf *.$FS *.flowdir
2984          -rm -rf *.f$FS90 *_mod.h *_mod.F90 *.FF90 *.mod-whirl ad_input*          -rm -rf *.f$FS90 \$(AD_CLEAN) ad_input*
2985          -rm -rf temp.sed  
2986    # remove most of the files that "make" and "make depend" generate
2987  Clean:  Clean:
2988          @make clean          @\$(MAKE) -f \$(MAKEFILE) clean
2989          @make cleanlinks          @\$(MAKE) -f \$(MAKEFILE) cleanlinks
2990          -rm -f \$(SPECIAL_FILES)          -rm -f \$(SPECIAL_FILES) f90mkdepend.log $MAKEFILE.old
2991          -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log f90mkdepend.log *.bak          -rm -f taf_command taf_output taf_ad.log taf_ad_flow.log taf_ftl.log
2992          -rm -f taf_command taf_output taf_ad.log taf_ad_flow.log  
2993    # remove also the executable, files that "genmake2" generates (except Makefile)
2994    #         and output from a run (plus log files from testreport)
2995  CLEAN:  CLEAN:
2996          @make Clean          @\$(MAKE) -f \$(MAKEFILE) Clean
2997            -rm -f \$(EXECUTABLE) \$(EXE_AD) \$(EXE_FTL) *.bak
2998            -rm -f $LOGFILE genmake_state genmake_*optfile
2999            -rm -f SIZE.h.mpi genmake.tr_log make.tr_log
3000            -rm -rf mpi_headers mnc_test_*
3001          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
3002          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
3003          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
3004          -rm -f \$(EXECUTABLE) \$(EXE_AD) *.txt STD* *diagnostics.log datetime          -rm -f *.txt STDOUT.* STDERR.* *diagnostics.log *.[0-9][0-9][0-9][0-9].log
3005            -rm -f datetime costfinal divided.ctrl snapshot* output_adm.txt.diva_*
3006          -rm -f *_MIT_CE_000.opt0000 costfunction*0000          -rm -f *_MIT_CE_000.opt0000 costfunction*0000
3007          -rm -rf mnc_test_*          -rm -f oad_cp.[0-9][0-9][0-9].?????
3008    
 #eh3 Makefile: makefile  
3009  makefile:  makefile:
3010          $THIS_SCRIPT $G2ARGS          $THIS_SCRIPT $G2ARGS
3011  cleanlinks:  cleanlinks:
# Line 2654  cleanlinks: Line 3014  cleanlinks:
3014  # Special targets (SPECIAL_FILES) which are created by make  # Special targets (SPECIAL_FILES) which are created by make
3015  ${PACKAGES_DOT_H}:  ${PACKAGES_DOT_H}:
3016          @echo Creating \$@ ...          @echo Creating \$@ ...
3017          @$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) > \$@
3018  AD_CONFIG.h:  AD_CONFIG.h:
3019          @echo Creating \$@ ...          @echo Creating \$@ ...
3020          @$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 > \$@
3021  FC_NAMEMANGLE.h:  FC_NAMEMANGLE.h:
3022          @echo Creating \$@ ...          @echo Creating \$@ ...
3023          echo "$FC_NAMEMANGLE" > \$@          echo "$FC_NAMEMANGLE" > \$@
# Line 2676  if test "x$EMBED_SRC" = xt ; then Line 3036  if test "x$EMBED_SRC" = xt ; then
3036    
3037  decode_files.o : EMBEDDED_FILES.h  decode_files.o : EMBEDDED_FILES.h
3038    
3039  ##  \$(F77_PP_SRC_FILES)  ##  \$(F77_PP_SRC_FILES)
3040  all_fF.tar.gz : \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile  all_fF.tar.gz : \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile
3041          @echo Creating \$@ ...          @echo Creating \$@ ...
3042          -tar -hcf all_fF.tar \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile          -tar -hcf all_fF.tar \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile
# Line 2697  cat >>$MAKEFILE <<EOF Line 3057  cat >>$MAKEFILE <<EOF
3057  ## This nullifies any default implicit rules concerning these two file types:  ## This nullifies any default implicit rules concerning these two file types:
3058  ## %.o : %.F  ## %.o : %.F
3059    
3060    # C preprocessing and replacing the _d in constants:
3061    CPPCMD = cat \$< | ${CPP} \$(DEFINES) \$(INCLUDES) | ${S64}
3062    
3063  .F.$FS:  .F.$FS:
3064          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPPCMD)  > \$@
3065  .$FS.o:  .$FS.o:
3066          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
3067    .F.o:
3068            \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
3069  .F90.$FS90:  .F90.$FS90:
3070          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPPCMD)  > \$@
3071  .FF90.f$FS90:  .FF90.f$FS90:
3072          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPPCMD)  > \$@
3073  .$FS90.o:  .$FS90.o:
3074          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
3075  .f$FS90.o:  .f$FS90.o:
# Line 2713  cat >>$MAKEFILE <<EOF Line 3078  cat >>$MAKEFILE <<EOF
3078  .c.o:  .c.o:
3079          \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$<          \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$<
3080  .flow.flowdir:  .flow.flowdir:
3081          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPPCMD) > \$@
3082    
3083  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
3084  .F.p:  .F.p:
3085          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPPCMD) > \$@
3086  .p.$FS:  .p.$FS:
3087          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
3088    
# Line 2727  EOF Line 3092  EOF
3092  #===  Automatic Differentiation Rules  ===  #===  Automatic Differentiation Rules  ===
3093  #===  for TAMC/TAF  ======================  #===  for TAMC/TAF  ======================
3094    
3095  if test "x$OPENAD" == x ; then  if test "x$OPENAD" = x ; then
3096    
3097  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
3098    
# Line 2736  TAF            = ${TAF} Line 3101  TAF            = ${TAF}
3101    
3102  TAF_EXTRA      = ${TAF_EXTRA}  TAF_EXTRA      = ${TAF_EXTRA}
3103  TAMC_EXTRA     = ${TAMC_EXTRA}  TAMC_EXTRA     = ${TAMC_EXTRA}
3104    LOCAL_MPI_HEADERS    = ${LOCAL_MPI_HEADERS}
3105    
3106  EOF  EOF
3107    
# Line 2753  done Line 3119  done
3119  echo "  Add the source list for AD code generation"  echo "  Add the source list for AD code generation"
3120  echo >> $MAKEFILE  echo >> $MAKEFILE
3121  printf "AD_FILES = " >> $MAKEFILE  printf "AD_FILES = " >> $MAKEFILE
3122  AD_FILES=`cat adSrcFiles.tmp`  AD_FILES=`cat $TMP.adSrcFiles`
3123  for i in $AD_FILES ; do  for i in $AD_FILES ; do
3124      echo    " \\" >> $MAKEFILE      echo    " \\" >> $MAKEFILE
3125      printf " $i" >> $MAKEFILE      printf " $i" >> $MAKEFILE
3126  done  done
3127  echo >> $MAKEFILE  echo >> $MAKEFILE
3128  rm -f adSrcFiles.tmp  rm -f $TMP.adSrcFiles
3129    
3130    if test $CAT_SRC_FOR_TAF = 0 ; then
3131    cat >>$MAKEFILE <<EOF
3132    
3133    # ... Utilities ...
3134    remove_comments:
3135            sed -i.bak -f \$(TOOLSDIR)/remove_comments_sed \$(AD_FILES)
3136            @-rm -f \$(AD_FILES:.$FS=.$FS.bak)
3137    adj_sed:
3138            sed -i.bak -f \$(TOOLSDIR)/adjoint_sed \$(AD_FILES:.$FS=_ad.$FS)
3139            @-rm -f \$(AD_FILES:.$FS=_ad.$FS.bak)
3140    ftl_sed:
3141            sed -i.bak -f \$(TOOLSDIR)/adjoint_sed \$(AD_FILES:.$FS=_tl.$FS)
3142            @-rm -f \$(AD_FILES:.$FS=_tl.$FS.bak)
3143    adobjfiles: \$(AD_FILES:.$FS=_ad.o)
3144    ftlobjfiles: \$(AD_FILES:.$FS=_tl.o)
3145    EOF
3146    fi
3147    
3148  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
3149    
3150  # ... AD ...  # ... AD ...
3151  adall: \$(EXE_AD)  adall: ad_exe_target
3152  adtaf: ad_taf_output.$FS  adtaf: ad_taf_output.$FS
3153  adtamc: ad_tamc_output.$FS  adtamc: ad_tamc_output.$FS
3154    
3155  ad_input_code.$FS: \$(AD_FILES) \$(H_SRC_FILES)  ad_exe_target:
3156          @$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          @echo Update AD_CONFIG.h and make \$(EXE_AD)
3157            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3158            @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3159            @-rm -f ad_config.template
3160            \$(MAKE) -f \$(MAKEFILE) \$(EXE_AD)
3161    
3162    ad_input_code.$FS: \$(AD_FILES) \$(AD_FLOW_FILES)
3163            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3164          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
3165          -rm -f ad_config.template          @-rm -f ad_config.template
3166          @make \$(F77_PP_SRC_FILES)          @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3167          @make \$(FLOFILES)          @\$(MAKE) -f \$(MAKEFILE) \$(FLOWFILES)
3168          cat \$(FLOFILES) \$(AD_FILES) > ad_input_code.$FS          cat \$(FLOWFILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ad_input_code.$FS
3169    
3170  ad_taf_output.$FS: ad_input_code.$FS  adtafonly:
3171          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
3172          ls -l ad_input_code_ad.$FS          ls -l ad_input_code_ad.$FS
3173          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
3174    
3175  adtafonly:  EOF
3176    
3177    if test $CAT_SRC_FOR_TAF = 1 ; then
3178    cat >>$MAKEFILE <<EOF
3179    # ... send 1 file to TAF ...
3180    ad_taf_output.$FS: ad_input_code.$FS
3181            @-rm -f ad_input_code_ad.$FS ; echo ''
3182          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
3183          ls -l ad_input_code_ad.$FS          ls -l ad_input_code_ad.$FS
3184          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
3185    
3186  \${EXE_AD}: ad_taf_output.o \$(OBJFILES)  \$(EXE_AD): \$(SPECIAL_FILES) \$(H_SRC_FILES) ad_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(EMBEDDED_FILES)
3187          \$(LINK) -o \${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)          \$(LINK) -o \${EXE_AD} \$(FFLAGS) \$(FOPTIM) ad_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(LIBS)
3188    
3189  ad_tamc_output.$FS: ad_input_code.$FS  adobj: ad_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o)
         \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS  
         cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS  
3190    
3191  ad_tamc: ad_tamc_output.o \$(OBJFILES)  EOF
3192          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)  
3193    else
3194    cat >>$MAKEFILE <<EOF
3195    # ... send multiple files to TAF ...
3196    ad_taf_output.$FS: \$(AD_FLOW_FILES) \$(AD_FILES)
3197            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3198            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3199            @-rm -f ad_config.template
3200            @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3201            @\$(MAKE) -f \$(MAKEFILE) \$(FLOWFILES)
3202            @-rm -f \$(AD_FILES:.$FS=_ad.$FS) \$(AD_FILES:.$FS=_ad.o); echo ''
3203            \$(MAKE) -f \$(MAKEFILE) remove_comments
3204            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) \$(FLOWFILES) \$(AD_FILES)
3205            \$(MAKE) -f \$(MAKEFILE) adj_sed
3206            cat \$(AD_FILES:.$FS=_ad.$FS) > ad_taf_output.$FS
3207    
3208    \$(EXE_AD): \$(SPECIAL_FILES) \$(H_SRC_FILES) ad_taf_output.$FS \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(EMBEDDED_FILES)
3209            \$(MAKE) -f \$(MAKEFILE) adobjfiles
3210            \$(LINK) -o \${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(AD_FILES:.$FS=_ad.o) \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(LIBS)
3211    
3212    adobj: ad_taf_output.$FS \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o)
3213            \$(MAKE) -f \$(MAKEFILE) adobjfiles
3214    
3215    EOF
3216    fi
3217    
3218    cat >>$MAKEFILE <<EOF
3219  adonlyfwd:  adonlyfwd:
3220          patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff          patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
3221    
3222  adtrick:  adtrick:
3223          patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff          patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
3224    
3225    ad_tamc_output.$FS: ad_input_code.$FS
3226            \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
3227            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS
3228    
3229    ad_tamc: ad_tamc_output.o \$(OBJFILES)
3230            \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
3231    
3232  # ... FTL ...  # ... FTL ...
3233  ftlall: ftl_taf  ftlall: ftl_exe_target
3234  ftltaf: ftl_taf_output.$FS  ftltaf: ftl_taf_output.$FS
3235  ftltamc: ftl_tamc_output.$FS  ftltamc: ftl_tamc_output.$FS
3236    
3237  ftl_input_code.$FS: \$(AD_FILES) \$(H_SRC_FILES)  ftl_exe_target:
3238          @$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          @echo Update AD_CONFIG.h and make \$(EXE_FTL)
3239          cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h          @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
3240          -rm -f ftl_config.template          @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3241          @make \$(F77_PP_SRC_FILES)          @-rm -f ad_config.template
3242          @make \$(AD_FLOW_FILES)          \$(MAKE) -f \$(MAKEFILE) \$(EXE_FTL)
         cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.$FS  
3243    
3244  ftl_taf_output.$FS: ftl_input_code.$FS  ftl_input_code.$FS: \$(AD_FILES)
3245          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS          @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
3246          ls -l ftl_input_code_ftl.$FS          cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3247          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS          @-rm -f ad_config.template
3248            @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3249            @\$(MAKE) -f \$(MAKEFILE) \$(AD_FLOW_FILES)
3250            cat \$(AD_FLOW_FILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ftl_input_code.$FS
3251    
3252  ftltafonly:  ftltafonly:
3253          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
3254          ls -l ftl_input_code_ftl.$FS          ls -l ftl_input_code_tl.$FS
3255          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS          cat ftl_input_code_tl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
3256    
3257    EOF
3258    
3259    if test $CAT_SRC_FOR_TAF = 1 ; then
3260    cat >>$MAKEFILE <<EOF
3261    # ... send 1 file to TAF ...
3262    ftl_taf_output.$FS: ftl_input_code.$FS
3263            @-rm -f ftl_input_code_tl.$FS ; echo ''
3264            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
3265            ls -l ftl_input_code_tl.$FS
3266            cat ftl_input_code_tl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
3267    
3268    \$(EXE_FTL): \$(SPECIAL_FILES) \$(H_SRC_FILES) ftl_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(EMBEDDED_FILES)
3269            \$(LINK) -o \${EXE_FTL} \$(FFLAGS) \$(FOPTIM) ftl_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(LIBS)
3270    
3271    EOF
3272    
3273    else
3274    cat >>$MAKEFILE <<EOF
3275    # ... send multiple files to TAF ...
3276    ftl_taf_output.$FS: \$(AD_FLOW_FILES) \$(AD_FILES)
3277            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
3278            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3279            @-rm -f ad_config.template
3280            @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3281            @\$(MAKE) -f \$(MAKEFILE) \$(AD_FLOW_FILES)
3282            @-rm -f \$(AD_FILES:.$FS=_tl.$FS) \$(AD_FILES:.$FS=_tl.o); echo ''
3283            \$(MAKE) -f \$(MAKEFILE) remove_comments
3284            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) \$(AD_FLOW_FILES) \$(AD_FILES)
3285            \$(MAKE) -f \$(MAKEFILE) ftl_sed
3286            cat \$(AD_FILES:.$FS=_tl.$FS) > ftl_taf_output.$FS
3287    
3288    \$(EXE_FTL): \$(SPECIAL_FILES) \$(H_SRC_FILES) ftl_taf_output.$FS \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(EMBEDDED_FILES)
3289            \$(MAKE) -f \$(MAKEFILE) ftlobjfiles
3290            \$(LINK) -o \${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(AD_FILES:.$FS=_tl.o) \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(LIBS)
3291    
3292  ftl_taf: ftl_taf_output.o \$(OBJFILES)  EOF
3293          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)  fi
3294    
3295    cat >>$MAKEFILE <<EOF
3296  ftl_tamc_output.$FS: ftl_input_code.$FS  ftl_tamc_output.$FS: ftl_input_code.$FS
3297          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
3298          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS
3299    
3300  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
3301          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
   
3302    
3303  # ... SVD ...  # ... SVD ...
3304  svdtaf: ad_taf_output.$FS ftl_taf_output.$FS  svdtaf: ad_taf_output.$FS ftl_taf_output.$FS
# Line 2856  svd_touch: Line 3320  svd_touch:
3320          touch ad_taf_output.$FS ftl_taf_output.$FS          touch ad_taf_output.$FS ftl_taf_output.$FS
3321          \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS          \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS
3322          \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS          \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS
3323          @$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
3324          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
3325          -rm -f ftl_config.template          @-rm -f ad_config.template
3326    
3327  EOF  EOF
3328    
3329  fi  fi
3330    
3331  #===  for OpenAD  ========================  #===  for OpenAD  ========================
3332    
3333  if test "x$OPENAD" != x ; then  if test "x$OPENAD" != x ; then
3334    
3335  # ============ begin OpenAD specific section ==============  # ============ begin OpenAD specific section ==============
3336    
3337  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
3338    # ... OpenAD ...
3339    
3340  # all the source files linked from the various locations:  # all the source files linked from the various locations:
3341  ALL_LINKED_FILES= \  ALL_LINKED_FILES= \
3342  \$(F77_SRC_FILES) \  \$(F77_SRC_FILES) \
3343  \$(C_SRC_FILES) \  \$(C_SRC_FILES) \
# Line 2910  for i in `cat ${OAD_CB2M_FILES}` ; do Line 3375  for i in `cat ${OAD_CB2M_FILES}` ; do
3375    echo    " \\" >> $MAKEFILE    echo    " \\" >> $MAKEFILE
3376    printf " ${i}_mod.f$FS90" >> $MAKEFILE    printf " ${i}_mod.f$FS90" >> $MAKEFILE
3377  done  done
3378  AD_FILES=`cat adSrcFiles.tmp`  AD_FILES=`cat $TMP.adSrcFiles`
3379  for i in $AD_FILES ; do  for i in $AD_FILES ; do
3380    basename=${i%%.f}    basename=${i%%.f}
3381    toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE} ${OAD_DONT_TRANSFORM}`    toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE} ${OAD_DONT_TRANSFORM}`
# Line 2920  for i in $AD_FILES ; do Line 3385  for i in $AD_FILES ; do
3385    fi    fi
3386  done  done
3387  echo >> $MAKEFILE  echo >> $MAKEFILE
3388  rm -f adSrcFiles.tmp  rm -f $TMP.adSrcFiles
3389    
3390  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
3391    
3392  adAll: \$(EXE_AD)  adAll: ad_exe_target
3393  .PHONY: adAll  .PHONY: adAll
3394    
3395    ad_exe_target:
3396            @echo Update AD_CONFIG.h and make \$(EXE_AD)
3397            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3398            @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3399            @-rm -f ad_config.template
3400            \$(MAKE) -f \$(MAKEFILE) \$(EXE_AD)
3401    
3402  CB2M_F90_PP_SRC_FILES=\$(addsuffix _mod.f$FS90, \$(CB2M_F90_SRC_NAMES))  CB2M_F90_PP_SRC_FILES=\$(addsuffix _mod.f$FS90, \$(CB2M_F90_SRC_NAMES))
3403    
3404  .PRECIOUS: \$(CB2M_F90_PP_SRC_FILES) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90)  .PRECIOUS: \$(CB2M_F90_PP_SRC_FILES) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90)
3405    
3406  .PHONY: adDepend  .PHONY: adDepend
3407  adDepend: \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) \$(addsuffix _mod.FF90, \$(CB2M_F90_SRC_NAMES)) \$(F77_SRC_FILES:.F=_cb2m.FF90)  adDepend: \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) \$(addsuffix _mod.FF90, \$(CB2M_F90_SRC_NAMES)) \$(F77_SRC_FILES:.F=_cb2m.FF90)
3408          \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)          \$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)
3409          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
3410          -rm -f makedepend.out          -rm -f makedepend.out
3411    
# Line 2942  w2f__types.F90 \ Line 3414  w2f__types.F90 \
3414  OAD_active.F90 \  OAD_active.F90 \
3415  OAD_cp.F90 \  OAD_cp.F90 \
3416  OAD_rev.F90 \  OAD_rev.F90 \
3417  OAD_tape.F90          OAD_tape.F90 \
3418    OAD_regular_cp.F90 \
3419    revolve.F90
3420    
3421  OPENAD_SUPPORT_C_SRC_FILES = \  OPENAD_SUPPORT_C_SRC_FILES = \
3422  iaddr.c \  iaddr.c \
# Line 2951  timeRatio.c Line 3425  timeRatio.c
3425  f95_test_mods.f90: \$(OPENAD_SUPPORT_F90_SRC_FILES:F90=$FS90)  f95_test_mods.f90: \$(OPENAD_SUPPORT_F90_SRC_FILES:F90=$FS90)
3426          cat \$^ > \$@          cat \$^ > \$@
3427    
3428  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  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
3429          cat \$^ > \$@          cat \$^ > \$@
3430    
3431  f95_test.out: f95_test_mods.f90 f95_test.f90  f95_test.out: f95_test_mods.f90 f95_test.f90
3432          f95 -fixed -w=unused -maxcontin=132 -c f95_test_mods.f90 > \$@ 2>&1          f95 -fixed -w=unused -maxcontin=132 -c f95_test_mods.f90 > \$@ 2>&1
3433          f95 -fixed -w=unused -maxcontin=132 -c -fixed f95_test.f90 >> \$@ 2>&1          f95 -fixed -w=unused -maxcontin=132 -c -fixed f95_test.f90 >> \$@ 2>&1
3434    
3435  AD_OBJ_FILES=\$(OPENAD_SUPPORT_F90_SRC_FILES:.F90=.o) \$(OPENAD_SUPPORT_C_SRC_FILES:.c=.o) all_mods.xb.x2w.w2f.pp.o  ad_input_code.w2f.pre.xb.x2w.w2f.td.pp.o \$(NON_AD_F77_SRC_FILES:.F=_cb2m.o) \$(C_SRC_FILES:.c=.o) \$(F90_SRC_FILES:.F90=.o)  CB2M_AD_FILES=\$(AD_FILES:.f=_cb2m.f$FS90)
3436    
3437  \$(EXE_AD): \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) \$(AD_OBJ_FILES)  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)
         @echo Creating \$@ ...  
         \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(AD_OBJ_FILES) \$(LIBS)  
3438    
3439  # makefile debug rule  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)
3440  openad: ad_input_code.w2f.pre.xb.x2w.w2f.td.pp.f$FS90  
3441  .PHONY: openad  \$(EXE_AD): \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) postProcess.tag \$(AD_OBJ_FILES_S2)
3442            \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(AD_OBJ_FILES_S2) \$(LIBS)
3443    
3444  # create the module files  # create sources files modules from header files containing common blocks
3445  %_mod.FF90 : %.h ../OAD_support/cb2mGetModules.csh ../OAD_support/cb2mGetModules.awk  %_mod.FF90 : %.h \${OADTOOLS}/cb2mGetModules.csh \${OADTOOLS}/cb2mGetModules.awk
3446          ../OAD_support/cb2mGetModules.csh $< ../OAD_support/cb2mGetModules.awk          \${OADTOOLS}/cb2mGetModules.csh $< \${OADTOOLS}/cb2mGetModules.awk
3447    
3448  # create the header files  # create new header files with USE statements for the new modules made above
3449  %_mod.h : %.h ../OAD_support/cb2mGetHeaders.csh ../OAD_support/cb2mGetHeaders.awk  %_mod.h : %.h \${OADTOOLS}/cb2mGetHeaders.csh \${OADTOOLS}/cb2mGetHeaders.awk
3450          ../OAD_support/cb2mGetHeaders.csh $< ../OAD_support/cb2mGetHeaders.awk \$(CB2M_F90_SRC_NAMES)          \${OADTOOLS}/cb2mGetHeaders.csh $< \${OADTOOLS}/cb2mGetHeaders.awk \$(CB2M_F90_SRC_NAMES)
3451    
3452  # change everybody else to use the new module files:  # change the include directives of everybody to refer to  the new header files with the USE statements
3453  %_cb2m.FF90 : %.F ../OAD_support/cb2mUseModules.bash  %_cb2m.FF90 : %.F \${OADTOOLS}/cb2mUseModules.bash
3454          ../OAD_support/cb2mUseModules.bash $< ${MPI}          \${OADTOOLS}/cb2mUseModules.bash $< ${MPI}
3455    
3456  # makefile debug rule  # makefile debug rule
3457  small_f: \$(CB2M_F90_PP_SRC_FILES)  small_f: \$(CB2M_F90_PP_SRC_FILES)
3458  .PHONY: small_f  .PHONY: small_f
3459    
3460  ad_output.txt: \$(EXE_AD)  ad_input_code.f$FS90:  \$(CB2M_AD_FILES)
         @printf 'linking data files ... '  
         \$(LN) -f ../input_ad/data* ../input_ad/eedata .  
         \$(LN) -f ../../global_ocean.90x40x15/input/*.bin .  
         @printf 'running ... '  
         @./\$(EXE_AD) > \$@  
   
 CB2M_AD_FILES=\$(AD_FILES:.f=_cb2m.f$FS90)  
 ad_input_code.f$FS90: ../OAD_support/maxMinDefs.f \$(CB2M_AD_FILES)  
3461          cat \$^ > \$@          cat \$^ > \$@
3462    
 # strip all comments and blanks to reduce  
 # the file size in order to reduce perl's memory requirements  
 ad_input_code_sf.f$FS90 : ad_input_code.f$FS90  
         cat \$^ | sed -f ../OAD_support/strip.sed | sed -f ../OAD_support/stop2print.sed > \$@  
   
 # mfef90 preprocessing  
 # expand statement functions  
 # expose mfef90 specific substring handling  
 # add the w2f__types module  
 ad_input_code_sf.w2f.f$FS90: ad_input_code_sf.f$FS90 mfef90 whirl2f whirl2f_be w2f__types.f90  
         ./mfef90 -r8 -z -F -N132 \$<  
         mv \$<.B \$(basename \$<).B  
         ./whirl2f -openad \$(basename \$<).B  
         cat w2f__types.f90 \$(basename \$<).w2f.f > \$@  
   
3463  # canonicalizer  # canonicalizer
3464  ad_input_code_sf.w2f.pre.f$FS90: ad_input_code_sf.w2f.f$FS90 preProcess.py  ad_input_code_sf.pre.f90 : \$(CB2M_AD_FILES)
3465          ./preProcess.py --mode=reverse \$< -o \$@          \${OPENADFORTTK_BASE}/tools/SourceProcessing/preProcess.py --timing --r8 -H -S  -o \$@ \$^
3466    
3467    # replace stop statements (to avoid the implied unstructured control flow)  with print statements
3468    ad_input_code_sf.pre.s2p.f90 : ad_input_code_sf.pre.f90
3469            cat \$< | sed -f \${OADTOOLS}/stop2print.sed > ad_input_code_sf.pre.s2p.f90
3470    
3471  # F -> WHIRL  # F -> WHIRL
3472  # note that the canonicalized version cuts off at col 72  ad_input_code_sf.pre.s2p.B: ad_input_code_sf.pre.s2p.f90
3473  # doing this also for string constants which is ok as long          \${OPEN64ROOT}/crayf90/sgi/mfef90 -r8 -z -F ad_input_code_sf.pre.s2p.f90
 # as we are in fixed mode and cut of exactly there.  
 # Otherwise mfef90 patches in spaces to fill up to 72 (or 132)  
 # characters respectively.  
 ad_input_code_sf.w2f.pre.B: ad_input_code_sf.w2f.pre.f$FS90 mfef90  
         ./mfef90 -r8 -z -F \$<  
         mv \$<.B \$@  
3474    
3475  # WHIRL -> XAIF  # WHIRL -> XAIF
3476  ad_input_code_sf.w2f.pre.xaif : ad_input_code_sf.w2f.pre.B whirl2xaif  ad_input_code_sf.pre.s2p.xaif : ad_input_code_sf.pre.s2p.B
3477          ./whirl2xaif -s -n --debug 1 -o \$@ \$<          \${OPENADFORTTK}/bin/whirl2xaif -s -n --debug 1 -o \$@ \$<
3478    
3479  # XAIF -> XAIF'  # XAIF -> XAIF'
3480  ad_input_code_sf.w2f.pre.xb.xaif : ad_input_code_sf.w2f.pre.xaif xaif.xsd xaif_base.xsd xaif_inlinable_intrinsics.xsd xaif_derivative_propagator.xsd xaif_output.xsd openad_adm  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
3481          ./openad_adm -f -t forward_step -i \$< -c \${XAIFSCHEMAROOT}/schema/examples/inlinable_intrinsics.xaif -o \$@ -I -r          \${XAIFBOOSTERROOT}/xaifBooster/algorithms/BasicBlockPreaccumulationReverse/driver/oadDriver -f -t forward_step -i \$< -c \${XAIFSCHEMAROOT}/schema/examples/inlinable_intrinsics.xaif -o \$@ -I -r
3482    
3483  # XAIF' -> WHIRL'  # XAIF' -> WHIRL'
3484  ad_input_code_sf.w2f.pre.xb.x2w.B : ad_input_code_sf.w2f.pre.xb.xaif xaif2whirl  ad_input_code_sf.pre.s2p.xb.x2w.B : ad_input_code_sf.pre.s2p.xb.xaif
3485          ./xaif2whirl --debug 1 --structured ad_input_code_sf.w2f.pre.B \$<          \${OPENADFORTTK}/bin/xaif2whirl --debug 1 ad_input_code_sf.pre.s2p.B \$<
3486    
3487  # WHIRL' -> F'  # WHIRL' -> F'
3488  ad_input_code_sf.w2f.pre.xb.x2w.w2f.f$FS90: ad_input_code_sf.w2f.pre.xb.x2w.B whirl2f whirl2f_be  ad_input_code_sf.pre.s2p.xb.x2w.w2f.f$FS90: ad_input_code_sf.pre.s2p.xb.x2w.B
3489          ./whirl2f -FLIST:ftn_file=\$@ -openad \$<          \${OPEN64ROOT}/whirl2f/whirl2f -FLIST:ftn_file=\$@ -openad \$<
3490    
3491  # insert template directives  # insert template directives
3492  ad_input_code_sf.w2f.pre.xb.x2w.w2f.td.f$FS90: ad_input_code_sf.w2f.pre.xb.x2w.w2f.f$FS90 ../OAD_support/insertTemplateDir.bash  ad_input_code_sf.pre.s2p.xb.x2w.w2f.td.f$FS90: ad_input_code_sf.pre.s2p.xb.x2w.w2f.f$FS90 \${OADTOOLS}/insertTemplateDir.bash
3493          ../OAD_support/insertTemplateDir.bash \$< \$@          \${OADTOOLS}/insertTemplateDir.bash \$< \$@
3494    
3495    PPEXTRAS=\$(notdir \$(wildcard \${OADTOOLS}/ad_template.*.F)) ad_inline.F
3496  # postprocess F'  # postprocess F'
3497  ad_input_code_sf.w2f.pre.xb.x2w.w2f.td.pp.f$FS90: ad_input_code_sf.w2f.pre.xb.x2w.w2f.td.f$FS90 multi-pp.pl ../OAD_support/ad_inline.f \$(wildcard ../OAD_support/ad_template.*.f)  postProcess.tag: ad_input_code_sf.pre.s2p.xb.x2w.w2f.td.f$FS90 \$(PPEXTRAS:.F=.f) | w2f__types.f90
3498          perl multi-pp.pl -inline=../OAD_support/ad_inline.f \$<          \${OPENADFORTTK_BASE}/tools/SourceProcessing/postProcess.py --progress --timing --infoUnitFile w2f__types.f90 --outputFormat=fixed --separateOutput --pathSuffix "" --filenameSuffix "_oad" -m r -i ad_inline.f \$<
3499          # the postprocessor still gets the name wrong          # the target is a placeholder to trigger a single execution of the rule
3500          cat \$<.pp | sed 's/RETURN//' > \$@          touch \$@
3501    # put this so make knows about the postprocessing output
3502  # extract all transformed modules  OAD_intrinsics_oad.f \$(CB2M_AD_FILES:.f$FS90=_oad.f): postProcess.tag
 all_mods.xb.x2w.w2f.pp.f$FS90: ad_input_code_sf.w2f.pre.xb.x2w.w2f.td.pp.f$FS90  
         cat \$< | sed -n '/MODULE /,/END MODULE/p' > \$@  
   
 # remove the transformed globals module from the  
 # transformed ad_input_code file  
 # and remove for now the duplicate variables  
 # and fix 2 data statements  
 ad_input_code.w2f.pre.xb.x2w.w2f.td.pp.f$FS90: ad_input_code_sf.w2f.pre.xb.x2w.w2f.td.pp.f$FS90  
         cat \$< | sed '/MODULE /,/END MODULE/d' | sed '/^      INTEGER(w2f__i4) DOLOOP_UB/d' > \$@  
3503    
3504  # setup some links  # link the XAIF schema files
3505  %.xsd:  %.xsd:
3506          \$(LN) \${XAIFSCHEMAROOT}/schema/\$@ .          \$(LN) \${XAIFSCHEMAROOT}/schema/\$@ .
3507    
 mfef90:  
         \$(LN) \${OPEN64ROOT}/crayf90/sgi/mfef90 .  
   
3508  # link the support files:  # link the support files:
3509  \$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES):  \$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES) \$(PPEXTRAS):
3510          \$(LN) ../OAD_support/\$@ .          \$(LN) \${OADTOOLS}/\$@ .
   
 whirl2xaif xaif2whirl:  
         \$(LN) \${OPENADFORTTK}/bin/\$@ .  
3511    
3512  %.pl:  AD_CLEAN += *_mod.h *_mod.F90 *.FF90 *.mod-whirl temp.sed oad_cp.* postProcess.tag
         \$(LN) \${OPENADFORTTK}/bin/\$@ .  
   
 preProcess.py:  
         \$(LN) \${OPENADFORTTK_BASE}/tools/SourceProcessing/\$@ .  
   
 whirl2f whirl2f_be:  
         \$(LN) \${OPEN64ROOT}/whirl2f/\$@ .  
   
 openad_adm:  
         \$(LN) \${XAIFBOOSTERROOT}/xaifBooster/algorithms/BasicBlockPreaccumulationReverse/test/t \$@  
3513    
3514  # ============ end OpenAD specific section ==============  # ============ end OpenAD specific section ==============
3515    
# Line 3121  for i in $NOOPTFILES ; do Line 3545  for i in $NOOPTFILES ; do
3545  done  done
3546    
3547  echo "  Add rules for links"  echo "  Add rules for links"
3548  cat srclinks.tmp >> $MAKEFILE  cat $TMP.srclinks >> $MAKEFILE
3549  rm -f srclinks.tmp  rm -f $TMP.srclinks
3550    
3551  echo "  Adding makedepend marker"  echo "  Adding makedepend marker"
3552  printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE  printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
# Line 3130  printf "\n\n# DO NOT DELETE\n" >> $MAKEF Line 3554  printf "\n\n# DO NOT DELETE\n" >> $MAKEF
3554  printf "\n===  Done  ===\n"  printf "\n===  Done  ===\n"
3555    
3556  # Create special header files  # Create special header files
3557  $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"
3558  if test ! -f $PACKAGES_DOT_H ; then  if test ! -f $PACKAGES_DOT_H ; then
3559      mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H      mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
3560  else  else
# Line 3144  else Line 3568  else
3568      fi      fi
3569  fi  fi
3570  if test ! -f AD_CONFIG.h ; then  if test ! -f AD_CONFIG.h ; then
3571      $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
3572  fi  fi
3573    
   
3574  #  Write the "state" for future records  #  Write the "state" for future records
3575  if test "x$DUMPSTATE" != xf ; then  if test "x$DUMPSTATE" = xt ; then
3576      printf "" > genmake_state      printf "" > genmake_state
3577      for i in $gm_state ; do      for i in $gm_state ; do
3578          t1="t2=\$$i"          t1="t2=\$$i"
3579          eval $t1          eval $t1
3580          echo "$i='$t2'" >> genmake_state          echo "$i='$t2'" | sed -e 's/  */ /g' >> genmake_state
3581      done      done
3582  fi  fi

Legend:
Removed from v.1.181  
changed lines
  Added in v.1.274

  ViewVC Help
Powered by ViewVC 1.1.22