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

Legend:
Removed from v.1.178  
changed lines
  Added in v.1.278

  ViewVC Help
Powered by ViewVC 1.1.22