/[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.145 by jmc, Wed Mar 29 19:28:02 2006 UTC revision 1.281 by jmc, Thu Feb 16 23:27:08 2017 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" || exit 99      test_for_string_in_file $cpp_options "^ *# *define *\<ALLOW_$pkg\>"
185      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg" || exit 99      test_for_string_in_file $cpp_options "^ *# *undef *\<ALLOW_$pkg\>"
186      test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg" || exit 99      test_for_string_in_file $cpp_options "^ *# *define *\<DISABLE_$pkg\>"
187      test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg" || exit 99      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" || exit 99      test_for_string_in_file $cpp_options "^ *# *define *\<ALLOW_USE_MPI\>"
195      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI" || exit 99      test_for_string_in_file $cpp_options "^ *# *undef *\<ALLOW_USE_MPI\>"
     test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI" || exit 99  
     test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI" || exit 99  
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 34  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          return 1          exit 99
209      fi      fi
210      return 0      return 0
211  }  }
# Line 48  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 102  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 129  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 137  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 157  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 168  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 196  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 241  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 279  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"  
     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 346  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 f90 f95 mpif77 mpf77 mpxlf95 gfortran"      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 386  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 396  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 405  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 434  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() {
615  #     if test "x${RETVAL}" = x0 ; then  
616  #       cat >>test.f <<EOF      dBug=0
617  #       PROGRAM HELLO      rm -rf ./mpi_headers
618  #       DO 10, I=1,10      if test -d $MPIINCLUDEDIR ; then
 #       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  
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 472  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        #echo "---- content of tmp file '.pd_tmp' :" ; cat .pd_tmp ; echo "---- end of file"
701      . ./.pd_tmp      . ./.pd_tmp
702      rm -f ./.pd_tmp      rm -f ./.pd_tmp
   
     printf "PNAME = "${}  
 }  
   
   
 #  Explain usage  
 usage()  {  
 cat <<EOF  
   
 Usage: "$0" [OPTIONS]  
   where [OPTIONS] can be:  
   
     -help | --help | -h | --h  
           Print this help message and exit.  
   
     -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME  
       -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME  
           Use "NAME" as the adoptfile.  By default, the file at  
           "tools/adjoint_options/adjoint_default" will be used.  
   
     -nooptfile | --nooptfile  
       -optfile NAME | --optfile NAME | -of NAME | --of NAME  
       -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME  
           Use "NAME" as the optfile.  By default, an attempt will be  
           made to find an appropriate "standard" optfile in the  
           tools/build_options/ directory.  
   
     -pdepend NAME | --pdepend NAME  
       -pdepend=NAME | --pdepend=NAME  
           Get package dependency information from "NAME".  
   
     -pdefault NAME | --pdefault NAME  
       -pdefault=NAME | --pdefault=NAME  
           Get the default package list from "NAME".  
   
     -make NAME | -m NAME  
       --make=NAME | -m=NAME  
           Use "NAME" for the MAKE program. The default is "make" but  
           many platforms, "gmake" is the preferred choice.  
   
     -makefile NAME | -mf NAME  
       --makefile=NAME | -mf=NAME  
           Call the makefile "NAME".  The default is "Makefile".  
   
     -makedepend NAME | -md NAME  
       --makedepend=NAME | -md=NAME  
           Use "NAME" for the MAKEDEPEND program.  
   
     -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME  
       -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME  
           Specify the location of the MITgcm ROOTDIR as "NAME".  
           By default, genamke will try to find the location by  
           looking in parent directories (up to the 5th parent).  
   
     -mods NAME | --mods NAME | -mo NAME | --mo NAME  
       -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME  
           Here, "NAME" specifies a list of directories that are  
           used for additional source code.  Files found in the  
           "mods list" are given preference over files of the same  
           name found elsewhere.  
   
     -disable NAME | --disable NAME  
       -disable=NAME | --disable=NAME  
           Here "NAME" specifies a list of packages that we don't  
           want to use.  If this violates package dependencies,  
           genamke will exit with an error message.  
   
     -enable NAME | --enable NAME  
       -enable=NAME | --enable=NAME  
           Here "NAME" specifies a list of packages that we wish  
           to specifically enable.  If this violates package  
           dependencies, genamke will exit with an error message.  
   
     -standarddirs NAME | --standarddirs NAME  
       -standarddirs=NAME | --standarddirs=NAME  
           Here, "NAME" specifies a list of directories to be  
           used as the "standard" code.  
   
     -fortran NAME | --fortran NAME | -fc NAME | --fc NAME  
       -fc=NAME | --fc=NAME  
           Use "NAME" as the fortran compiler.  By default, genmake  
           will search for a working compiler by trying a list of  
           "usual suspects" such as g77, f77, etc.  
   
     -cc NAME | --cc NAME | -cc=NAME | --cc=NAME  
           Use "NAME" as the C compiler.  By default, genmake  
           will search for a working compiler by trying a list of  
           "usual suspects" such as gcc, c89, cc, etc.  
   
     -[no]ieee | --[no]ieee  
           Do or don't use IEEE numerics.  Note that this option  
           *only* works if it is supported by the OPTFILE that  
           is being used.  
   
     -ignoretime | -ignore_time | --ignoretime | --ignore_time  
           Ignore all the "wall clock" routines entirely.  This will  
           not in any way hurt the model results -- it simply means  
           that the code that checks how long the model spends in  
           various routines will give junk values.  
   
     -ts | --ts  
           Produce timing information per timestep  
     -papis | --papis  
           Produce summary MFlop/s with PAPI per timestep  
     -foolad | --foolad  
           Fool the AD code generator  
     -papi | --papi  
           Performance analysis with PAPI  
     -hpmt | --hpmt  
           Performance analysis with the HPM Toolkit  
   
     -gsl | --gsl  
           Use GSL to control floating point rounding and precision  
   
     -mpi | --mpi  
           Include MPI header files and link to MPI libraries  
     -mpi=PATH | --mpi=PATH  
           Include MPI header files and link to MPI libraries using MPI_ROOT  
           set to PATH. i.e. Include files from \$PATH/include, link to libraries  
           from \$PATH/lib and use binaries from \$PATH/bin.  
   
     -es | --es | -embed-source | --embed-source  
           Embed a tarball containing the full source code  
           (including the Makefile, etc.) used to build the  
           executable [off by default]  
   
     -bash NAME  
           Explicitly specify the Bourne or BASH shell to use  
   
   While it is most often a single word, the "NAME" variables specified  
   above can in many cases be a space-delimited string such as:  
   
     --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'  
     -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'  
     -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'  
   
   which, depending upon your shell, may need to be single-quoted.  
   
   For more detailed genmake documentation, please see:  
   
     http://mitgcm.org/devel_HOWTO/  
   
 EOF  
   
     exit 1  
703  }  }
704    
705  #  Build a CPP macro to automate calling C routines from FORTRAN  #  Build a CPP macro to automate calling C routines from FORTRAN
# Line 628  get_fortran_c_namemangling()  { Line 707  get_fortran_c_namemangling()  {
707    
708      #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""      #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
709      if test ! "x$FC_NAMEMANGLE" = x ; then      if test ! "x$FC_NAMEMANGLE" = x ; then
710          return 0          return 0
711      fi      fi
712        echo " running: get_fortran_c_namemangling()" >> $LOGFILE
713    
714      default_nm="#define FC_NAMEMANGLE(X) X ## _"      default_nm="#define FC_NAMEMANGLE(X) X ## _"
715        
716      cat > genmake_test.c <<EOF      cat > genmake_test.c <<EOF
717  void tcall( char * string ) { tsub( string ); }  void tcall( char * string ) { tsub( string ); }
718  EOF  EOF
719      $MAKE genmake_test.o >> genmake_warnings 2>&1      COMM="$CC $CFLAGS -c genmake_test.c"
720        echo ' '$COMM >> $LOGFILE
721        $COMM >> $LOGFILE 2>&1
722      RETVAL=$?      RETVAL=$?
723      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
724          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
725          cat <<EOF>> genmake_errors          cat <<EOF>> $LOGFILE
726    
727  WARNING: C test compile fails   WARNING: C test compile fails
728  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
729  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here   WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
730  EOF  EOF
731          return 1          return 1
732      fi      fi
# Line 652  EOF Line 734  EOF
734      RETVAL=$?      RETVAL=$?
735      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
736          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
737          cat <<EOF>> genmake_warnings          cat <<EOF>> $LOGFILE
738    
739  WARNING: The "nm" command failed.   WARNING: The "nm" command failed.
740  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
741  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here   WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
742  EOF  EOF
743          return 1          return 1
744      fi      fi
# Line 666  EOF Line 748  EOF
748        call tsub( string )        call tsub( string )
749        end        end
750  EOF  EOF
751      $FC $FFLAGS -c genmake_tcomp.$FS >> genmake_warnings 2>&1      COMM="$FC $FFLAGS -c genmake_tcomp.$FS"
752        echo ' '$COMM >> $LOGFILE
753        $COMM >> $LOGFILE 2>&1
754      RETVAL=$?      RETVAL=$?
755      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
756          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
757          cat <<EOF>> genmake_warnings          cat <<EOF>> $LOGFILE
758    
759  WARNING: FORTRAN test compile fails -- please see "genmake_errors"   WARNING: FORTRAN test compile fails -- please see '$LOGFILE'
760  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
761  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.   WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
762  EOF  EOF
763          return 1          return 1
764      fi      fi
# Line 682  EOF Line 766  EOF
766      RETVAL=$?      RETVAL=$?
767      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
768          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
769          cat <<EOF>> genmake_warnings          cat <<EOF>> $LOGFILE
770    
771  WARNING: The "nm" command failed.   WARNING: The "nm" command failed.
772  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
773  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.   WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
774  EOF  EOF
775          return 1          return 1
776      fi      fi
# Line 712  EOF Line 796  EOF
796    
797      #  cleanup the testing files      #  cleanup the testing files
798      rm -f genmake_tcomp.* genmake_test.*      rm -f genmake_tcomp.* genmake_test.*
 }  
799    
800        echo " --> set FC_NAMEMANGLE='$FC_NAMEMANGLE'" >> $LOGFILE
801    }
802    
803  check_HAVE_CLOC()  {  check_HAVE_CLOC()  {
804        echo >> $LOGFILE
805        echo "running: check_HAVE_CLOC()" >> $LOGFILE
806      get_fortran_c_namemangling      get_fortran_c_namemangling
807      cat <<EOF > genmake_tc_1.c      cat <<EOF > genmake_tc_1.c
808  $FC_NAMEMANGLE  $FC_NAMEMANGLE
# Line 732  void FC_NAMEMANGLE(cloc) ( double *curti Line 819  void FC_NAMEMANGLE(cloc) ( double *curti
819   *curtim = *curtim/1.E6;   *curtim = *curtim/1.E6;
820  }  }
821  EOF  EOF
822      make genmake_tc_1.o >> genmake_warnings 2>&1      COMM="$CC $CFLAGS -c genmake_tc_1.c"
823        echo $COMM >> $LOGFILE
824        $COMM >> $LOGFILE 2>&1
825      RET_C=$?      RET_C=$?
826      cat <<EOF > genmake_tc_2.$FS      cat <<EOF > genmake_tc_2.$FS
827        program hello        program hello
# Line 742  EOF Line 831  EOF
831        print *," HELLO WORLD", wtime        print *," HELLO WORLD", wtime
832        end        end
833  EOF  EOF
834      $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_warnings 2>&1      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
835        echo $COMM >> $LOGFILE
836        $COMM >> $LOGFILE 2>&1
837      RET_F=$?      RET_F=$?
838      test -x ./genmake_tc  &&  ./genmake_tc >> genmake_warnings 2>&1      test -x ./genmake_tc  &&  ./genmake_tc >> $LOGFILE 2>&1
839      RETVAL=$?      RETVAL=$?
840      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
841          HAVE_CLOC=t          HAVE_CLOC=t
         DEFINES="$DEFINES -DHAVE_CLOC"  
842      fi      fi
843      rm -f genmake_tc*      rm -f genmake_tc*
844        echo " --> set HAVE_CLOC='$HAVE_CLOC'" >> $LOGFILE
845  }  }
846    
   
847  check_HAVE_SIGREG()  {  check_HAVE_SIGREG()  {
848        if test ! "x$HAVE_SIGREG" = x ; then
849            return
850        fi
851        echo >> $LOGFILE
852        echo "running: check_HAVE_SIGREG()" >> $LOGFILE
853      get_fortran_c_namemangling      get_fortran_c_namemangling
854      cat <<EOF > genmake_tc_1.c      cat <<EOF > genmake_tc_1.c
855  $FC_NAMEMANGLE  $FC_NAMEMANGLE
# Line 786  void FC_NAMEMANGLE(sigreg) (int * aip) Line 881  void FC_NAMEMANGLE(sigreg) (int * aip)
881      return;      return;
882  }  }
883  EOF  EOF
884      make genmake_tc_1.o >> genmake_warnings 2>&1      COMM="$CC $CFLAGS -c genmake_tc_1.c"
885        echo $COMM >> $LOGFILE
886        $COMM >> $LOGFILE 2>&1
887      RET_C=$?      RET_C=$?
888      cat <<EOF > genmake_tc_2.$FS      cat <<EOF > genmake_tc_2.$FS
889        program hello        program hello
# Line 796  EOF Line 893  EOF
893        call sigreg(anint)        call sigreg(anint)
894        end        end
895  EOF  EOF
896      echo >> genmake_warnings      cat genmake_tc_2.$FS >> $LOGFILE
     echo "running: check_HAVE_SIGREG()" >> genmake_warnings  
     cat genmake_tc_2.$FS >> genmake_warnings  
897      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
898      echo $COMM >> genmake_warnings      echo $COMM >> $LOGFILE
899      $COMM >> genmake_warnings 2>&1      $COMM >> $LOGFILE 2>&1
900      RETVAL=$?      RETVAL=$?
901      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
902          HAVE_SIGREG=t          HAVE_SIGREG=t
         DEFINES="$DEFINES -DHAVE_SIGREG"  
903      fi      fi
904      rm -f genmake_tc*      rm -f genmake_tc*
905        echo " --> set HAVE_SIGREG='$HAVE_SIGREG'" >> $LOGFILE
906  }  }
907    
   
908  check_HAVE_SETRLSTK()  {  check_HAVE_SETRLSTK()  {
909        if test ! "x$HAVE_SETRLSTK" = x ; then
910            return
911        fi
912        echo >> $LOGFILE
913        echo "running: check_HAVE_SETRLSTK()" >> $LOGFILE
914      get_fortran_c_namemangling      get_fortran_c_namemangling
915      cat <<EOF > genmake_tc_1.c      cat <<EOF > genmake_tc_1.c
916  $FC_NAMEMANGLE  $FC_NAMEMANGLE
# Line 827  void FC_NAMEMANGLE(setrlstk) () Line 926  void FC_NAMEMANGLE(setrlstk) ()
926      return;      return;
927  }  }
928  EOF  EOF
929      make genmake_tc_1.o >> genmake_warnings 2>&1      COMM="$CC $CFLAGS -c genmake_tc_1.c"
930        echo $COMM >> $LOGFILE
931        $COMM >> $LOGFILE 2>&1
932      RET_C=$?      RET_C=$?
933      cat <<EOF > genmake_tc_2.$FS      cat <<EOF > genmake_tc_2.$FS
934        program hello        program hello
# Line 835  EOF Line 936  EOF
936        call setrlstk()        call setrlstk()
937        end        end
938  EOF  EOF
939      echo >> genmake_warnings      cat genmake_tc_2.$FS >> $LOGFILE
     echo "running: check_HAVE_SETRLSTK()" >> genmake_warnings  
     cat genmake_tc_2.$FS >> genmake_warnings  
940      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
941      echo $COMM >> genmake_warnings      echo $COMM >> $LOGFILE
942      $COMM >> genmake_warnings 2>&1      $COMM >> $LOGFILE 2>&1
943      RETVAL=$?      RETVAL=$?
944      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
945          HAVE_SETRLSTK=t          HAVE_SETRLSTK=t
         DEFINES="$DEFINES -DHAVE_SETRLSTK"  
946      fi      fi
947      rm -f genmake_tc*      rm -f genmake_tc*
948        echo " --> set HAVE_SETRLSTK='$HAVE_SETRLSTK'" >> $LOGFILE
949  }  }
950    
   
951  check_HAVE_STAT()  {  check_HAVE_STAT()  {
952        echo >> $LOGFILE
953        echo "running: check_HAVE_STAT()" >> $LOGFILE
954      get_fortran_c_namemangling      get_fortran_c_namemangling
955      cat <<EOF > genmake_tc_1.c      cat <<EOF > genmake_tc_1.c
956  $FC_NAMEMANGLE  $FC_NAMEMANGLE
# Line 871  void FC_NAMEMANGLE(tfsize) ( int *nbyte Line 971  void FC_NAMEMANGLE(tfsize) ( int *nbyte
971          *nbyte = -1;          *nbyte = -1;
972  }  }
973  EOF  EOF
974      make genmake_tc_1.o >> genmake_tc.log 2>&1      COMM="$CC $CFLAGS -c genmake_tc_1.c"
975        echo $COMM >> $LOGFILE
976        $COMM >> genmake_tc.log 2>&1
977      RET_C=$?      RET_C=$?
978      cat <<EOF > genmake_tc_2.$FS      cat <<EOF > genmake_tc_2.$FS
979        program hello        program hello
# Line 880  EOF Line 982  EOF
982        print *," HELLO WORLD", nbyte        print *," HELLO WORLD", nbyte
983        end        end
984  EOF  EOF
985      echo >> genmake_warnings      cat genmake_tc_2.$FS >> $LOGFILE
     echo "running: check_HAVE_STAT()" >> genmake_warnings  
     cat genmake_tc_2.$FS >> genmake_warnings  
986      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
987      echo $COMM >> genmake_warnings      echo $COMM >> $LOGFILE
988      $COMM >> genmake_tc.log 2>&1      $COMM >> genmake_tc.log 2>&1
989      RETVAL=$?      RETVAL=$?
990      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
991          HAVE_STAT=t          HAVE_STAT=t
         DEFINES="$DEFINES -DHAVE_STAT"  
992      fi      fi
993      rm -f genmake_tc*      rm -f genmake_tc*
994        echo " --> set HAVE_STAT='$HAVE_STAT'" >> $LOGFILE
995  }  }
996    
   
997  check_netcdf_libs()  {  check_netcdf_libs()  {
998      if test ! "x$SKIP_NETCDF_CHECK" = x ; then      if test ! "x$SKIP_NETCDF_CHECK" = x ; then
999          return          return
1000      fi      fi
1001      echo >> genmake_warnings      echo >> $LOGFILE
1002      echo "running: check_netcdf_libs()" >> genmake_warnings      echo "running: check_netcdf_libs()" >> $LOGFILE
1003      cat <<EOF > genmake_tnc.F      cat <<EOF > genmake_tnc.F
1004        program fgennc        program fgennc
1005  #include "netcdf.inc"  #include "netcdf.inc"
1006  EOF  EOF
1007      if test ! "x$MPI" = x ; then     #if test ! "x$MPI" = x ; then
1008          echo '#include "mpif.h"' >> genmake_tnc.F     #    echo '#include "mpif.h"' >> genmake_tnc.F
1009      fi     #fi
1010      cat <<EOF >> genmake_tnc.F      cat <<EOF >> genmake_tnc.F
1011        integer iret, ncid, xid        integer iret, ncid, xid
1012        iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)        iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
# Line 918  EOF Line 1017  EOF
1017        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
1018        end        end
1019  EOF  EOF
1020      echo "===  genmake_tnc.F  ===" > genmake_tnc.log      echo "===  genmake_tnc.F  >>>" > genmake_tnc.log
1021      cat genmake_tnc.F >> genmake_tnc.log      cat genmake_tnc.F >> genmake_tnc.log
1022      echo "===  genmake_tnc.F  ===" >> genmake_tnc.log      echo "<<<  genmake_tnc.F  ===" >> genmake_tnc.log
1023      RET_CPP=f      RET_CPP=f
1024      COMM="$CPP $DEFINES $INCLUDES genmake_tnc.F"      COMM="cat genmake_tnc.F | $CPP $DEFINES $INCLUDES"
1025      echo "$COMM" >> genmake_tnc.log      echo "$COMM" >> genmake_tnc.log
1026      $COMM > genmake_tnc.$FS 2>/dev/null  &&  RET_CPP=t      eval $COMM > genmake_tnc.$FS 2>/dev/null  &&  RET_CPP=t
1027      if test "x$RET_CPP" = xf ; then      if test "x$RET_CPP" = xf ; then
1028          echo "  WARNING: CPP failed to pre-process the netcdf test." \          echo "  WARNING: CPP failed to pre-process the netcdf test." \
1029              >> genmake_tnc.log              >> genmake_tnc.log
# Line 932  EOF Line 1031  EOF
1031              >> genmake_tnc.log              >> genmake_tnc.log
1032      fi      fi
1033      echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.$FS  \ " >> genmake_tnc.log      echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.$FS  \ " >> genmake_tnc.log
1034      echo "  &&  $LINK -o genmake_tnc.o $LIBS" >> genmake_tnc.log      echo "  &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc.o $LIBS" >> genmake_tnc.log
1035      $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \      $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
1036          &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1          &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
1037      RET_COMPILE=$?      RET_COMPILE=$?
1038      cat genmake_tnc.log >> genmake_warnings      cat genmake_tnc.log >> $LOGFILE
1039    
1040      #EH3  Remove test program execution for machines that either disallow      #EH3  Remove test program execution for machines that either disallow
1041      #EH3  execution or cannot support it (eg. cross-compilers)      #EH3  execution or cannot support it (eg. cross-compilers)
# Line 947  EOF Line 1046  EOF
1046    
1047      if test "x$RET_COMPILE" = x0 ; then      if test "x$RET_COMPILE" = x0 ; then
1048          HAVE_NETCDF=t          HAVE_NETCDF=t
1049            echo "check_netcdf: successful" >> $LOGFILE
1050      else      else
1051          # try again with "-lnetcdf" added to the libs          # try again with "-lnetcdf" added to the libs
1052          echo "try again with added '-lnetcdf'" > genmake_tnc.log          echo "==> try again with added '-lnetcdf'" > genmake_tnc.log
1053          echo "$CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS \ " >> genmake_tnc.log          echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log
1054          echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log          echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
1055          echo " &&  $LINK -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
1056          $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null  \          cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null  \
1057              &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \              &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
1058              &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1              &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
1059          RET_COMPILE=$?          RET_COMPILE=$?
1060          cat genmake_tnc.log >> genmake_warnings          echo >> $LOGFILE
1061            cat genmake_tnc.log >> $LOGFILE
1062          if test "x$RET_COMPILE" = x0 ; then          if test "x$RET_COMPILE" = x0 ; then
1063              LIBS="$LIBS -lnetcdf"              LIBS="$LIBS -lnetcdf"
1064              HAVE_NETCDF=t              HAVE_NETCDF=t
1065                echo "check_netcdf: successful" >> $LOGFILE
1066            else
1067            # try again with "-lnetcdff" added to the libs
1068                echo "==> try again with added '-lnetcdff -lnetcdf'" > genmake_tnc.log
1069                echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log
1070                echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
1071                echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
1072                cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null  \
1073                    &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
1074                    &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdff -lnetcdf >> genmake_tnc.log 2>&1
1075                RET_COMPILE=$?
1076                echo >> $LOGFILE
1077                cat genmake_tnc.log >> $LOGFILE
1078                if test "x$RET_COMPILE" = x0 ; then
1079                    LIBS="$LIBS -lnetcdff -lnetcdf"
1080                    HAVE_NETCDF=t
1081                    echo "check_netcdf: successful" >> $LOGFILE
1082                fi
1083          fi          fi
1084      fi      fi
1085      rm -f genmake_tnc*      rm -f genmake_tnc*
1086        echo " --> set HAVE_NETCDF='$HAVE_NETCDF'" >> $LOGFILE
1087  }  }
1088    
1089    check_lapack_libs()  {
1090        if test "x$CHECK_FOR_LAPACK" = xf ; then return ; fi
1091        echo >> $LOGFILE
1092        echo "running: check_lapack_libs()" >> $LOGFILE
1093        cat <<EOF > genmake_tla.F
1094          program fgenla
1095          integer info
1096          integer ipiv( 2 )
1097          double precision ab( 4, 2 ), b( 2 )
1098          data ab / 0., 0., 1., 2., 0., 2., 1., 0. /
1099          data b / 1., 1. /
1100          call dgbsv( 2, 1, 1, 1, ab, 4, ipiv, b, 2, info )
1101          IF (info .NE. 0) write(*,*) 'Error:', info
1102          write(*,*) b
1103          end
1104    EOF
1105        echo "===  genmake_tla.F  >>>" > genmake_tla.log
1106        cat genmake_tla.F >> genmake_tla.log
1107        echo "<<<  genmake_tla.F  ===" >> genmake_tla.log
1108        RET_CPP=f
1109        COMM="cat genmake_tla.F | $CPP $DEFINES $INCLUDES"
1110        echo "$COMM" >> genmake_tla.log
1111        eval $COMM > genmake_tla.$FS 2>/dev/null  &&  RET_CPP=t
1112        if test "x$RET_CPP" = xf ; then
1113            echo "  WARNING: CPP failed to pre-process the lapack test." \
1114                >> genmake_tla.log
1115            echo "    Please check that \$INCLUDES is properly set." \
1116                >> genmake_tla.log
1117        fi
1118        echo "$FC $FFLAGS $FOPTIM -c genmake_tla.$FS  \ " >> genmake_tla.log
1119        echo "  &&  $LINK $FFLAGS $FOPTIM -o genmake_tla.o $LIBS" >> genmake_tla.log
1120        $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
1121            &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS >> genmake_tla.log 2>&1
1122        RET_COMPILE=$?
1123        cat genmake_tla.log >> $LOGFILE
1124    
1125        # test program execution not always possible (see check_netcdf_libs)
1126        #
1127        #test -x ./genmake_tla  &&  ./genmake_tla >> genmake_tla.log 2>&1
1128        #RETVAL=$?
1129        #if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
1130    
1131        if test "x$RET_COMPILE" = x0 ; then
1132            HAVE_LAPACK=t
1133            echo "check_lapack: successful" >> $LOGFILE
1134        else
1135            # try again with "-llapack" added to the libs
1136            echo "==> try again with added '-llapack'" > genmake_tla.log
1137            echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1138            echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1139            echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack" >> genmake_tla.log
1140            cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null  \
1141                &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
1142                &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack >> genmake_tla.log 2>&1
1143            RET_COMPILE=$?
1144            echo >> $LOGFILE
1145            cat genmake_tla.log >> $LOGFILE
1146            if test "x$RET_COMPILE" = x0 ; then
1147                LIBS="$LIBS -llapack"
1148                HAVE_LAPACK=t
1149                echo "check_lapack: successful" >> $LOGFILE
1150            else
1151            # try again with "-lf77blas -lcblas" added to the libs
1152                echo "==> try again with added '-llapack -lf77blas -lcblas'" > genmake_tla.log
1153                echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1154                echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1155                echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas" >> genmake_tla.log
1156                cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null  \
1157                    &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
1158                    &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas >> genmake_tla.log 2>&1
1159                RET_COMPILE=$?
1160                echo >> $LOGFILE
1161                cat genmake_tla.log >> $LOGFILE
1162                if test "x$RET_COMPILE" = x0 ; then
1163                    LIBS="$LIBS -llapack -lf77blas -lcblas"
1164                    HAVE_LAPACK=t
1165                    echo "check_lapack: successful" >> $LOGFILE
1166                else
1167                # try again with "-latlas" added to the libs
1168                    echo "==> try again with added '-llapack -lf77blas -lcblas -latlas'" > genmake_tla.log
1169                    echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1170                    echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1171                    echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas -latlas" >> genmake_tla.log
1172                    cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null  \
1173                        &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
1174                        &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas -latlas >> genmake_tla.log 2>&1
1175                    RET_COMPILE=$?
1176                    echo >> $LOGFILE
1177                    cat genmake_tla.log >> $LOGFILE
1178                    if test "x$RET_COMPILE" = x0 ; then
1179                        LIBS="$LIBS -llapack -lf77blas -lcblas -latlas"
1180                        HAVE_LAPACK=t
1181                        echo "check_lapack: successful" >> $LOGFILE
1182                    fi
1183                fi
1184            fi
1185        fi
1186        rm -f genmake_tla*
1187        echo " --> set HAVE_LAPACK='$HAVE_LAPACK'" >> $LOGFILE
1188    }
1189    
1190    check_HAVE_FLUSH()  {
1191        if test ! "x$SKIP_CHECK_FLUSH" = x ; then
1192            return
1193        fi
1194        echo >> $LOGFILE
1195        echo "running: check_HAVE_FLUSH()" >> $LOGFILE
1196        cat <<EOF > genmake_tflsh.$FS
1197          program fgenflsh
1198          integer iounit
1199          character*9 fname
1200          iounit = 26
1201          fname = 'tmp.tflsh'
1202          open(iounit,FILE=fname,STATUS='unknown')
1203          write(iounit,*) 'genmake_tflsh: hello'
1204          call flush(iounit)
1205          close(iounit)
1206          end
1207    EOF
1208        echo "===  genmake_tflsh.$FS  >>>" > genmake_tflsh.log
1209        cat genmake_tflsh.$FS >> genmake_tflsh.log
1210        echo "<<<  genmake_tflsh.$FS  ===" >> genmake_tflsh.log
1211    
1212        echo "$FC $FFLAGS $FOPTIM -c genmake_tflsh.$FS  \ " >> genmake_tflsh.log
1213        echo "  &&  $LINK $FFLAGS $FOPTIM -o genmake_tflsh.o $LIBS" >> genmake_tflsh.log
1214        $FC $FFLAGS $FOPTIM -c genmake_tflsh.$FS >> genmake_tflsh.log 2>&1  \
1215            &&  $LINK $FFLAGS $FOPTIM -o genmake_tflsh genmake_tflsh.o $LIBS >> genmake_tflsh.log 2>&1
1216        RET_COMPILE=$?
1217    
1218        if test "x$RET_COMPILE" = x0 ; then
1219            HAVE_FLUSH=t
1220            #cat genmake_tflsh.log >> $LOGFILE
1221            echo "  check_HAVE_FLUSH: successful" >> $LOGFILE
1222        else
1223            HAVE_FLUSH=f
1224            cat genmake_tflsh.log >> $LOGFILE
1225        fi
1226        rm -f genmake_tflsh*
1227        echo " --> set HAVE_FLUSH='$HAVE_FLUSH'" >> $LOGFILE
1228    }
1229    
1230  ###############################################################################  ###############################################################################
1231  #   Sequential part of script starts here  #   Sequential part of script starts here
# Line 989  ENABLE= Line 1248  ENABLE=
1248  DISABLE=  DISABLE=
1249  # MAKEFILE=  # MAKEFILE=
1250  # MAKEDEPEND=  # MAKEDEPEND=
1251  PDEPEND=  PKG_DEPEND=
1252  DUMPSTATE=t  PKG_GROUPS=
1253  PDEFAULT=  DUMPSTATE=f
1254  OPTFILE=  OPTFILE=
1255  INCLUDES="-I. $INCLUDES"  INCLUDES="-I. $INCLUDES"
1256  FFLAGS=  FFLAGS=
1257  FOPTIM=  FOPTIM=
1258    FEXTRAFLAGS=
1259    USE_EXTENDED_SRC=
1260    EXTENDED_SRC_FLAG=
1261    GET_FC_VERSION=
1262  CFLAGS=  CFLAGS=
1263  KFLAGS1=  KFLAGS1=
1264  KFLAGS2=  KFLAGS2=
# Line 1006  NOOPTFILES= Line 1269  NOOPTFILES=
1269  NOOPTFLAGS=  NOOPTFLAGS=
1270  MPI=  MPI=
1271  MPIPATH=  MPIPATH=
1272    OMP=
1273    OMPFLAG=
1274    USE_R4=
1275  TS=  TS=
1276  PAPIS=  PAPIS=
1277    PCLS=
1278  FOOLAD=  FOOLAD=
1279  PAPI=  PAPI=
1280    PCL=
1281  HPMT=  HPMT=
1282  GSL=  GSL=
1283    DEVEL=
1284  HAVE_TEST_L=  HAVE_TEST_L=
1285    
1286    # set this to "t" to enable lapack test
1287    CHECK_FOR_LAPACK=f
1288    
1289  # DEFINES checked by test compilation or command-line  # DEFINES checked by test compilation or command-line
1290  HAVE_SYSTEM=  HAVE_SYSTEM=
1291  HAVE_FDATE=  HAVE_FDATE=
1292  FC_NAMEMANGLE=  FC_NAMEMANGLE=
1293  HAVE_CLOC=  HAVE_CLOC=
1294  HAVE_SETRLSTK=  # HAVE_SETRLSTK=
1295  HAVE_STAT=  HAVE_STAT=
1296  HAVE_NETCDF=  HAVE_NETCDF=
1297  HAVE_ETIME=  HAVE_ETIME=
1298  IGNORE_TIME=  IGNORE_TIME=
1299    HAVE_LAPACK=
1300    HAVE_FLUSH=
1301    
1302  MODS=  MODS=
1303  TOOLSDIR=  TOOLSDIR=
# Line 1031  SOURCEDIRS= Line 1305  SOURCEDIRS=
1305  INCLUDEDIRS=  INCLUDEDIRS=
1306  STANDARDDIRS="USE_THE_DEFAULT"  STANDARDDIRS="USE_THE_DEFAULT"
1307    
1308    #- local config file
1309    gm_local="genmake_local"
1310    
1311  G2ARGS=  G2ARGS=
1312  BASH=  BASH=
1313  PWD=`pwd`  PWD=`pwd`
# Line 1046  MACHINE=`uname -a` Line 1323  MACHINE=`uname -a`
1323  EXECUTABLE=  EXECUTABLE=
1324  EXEHOOK=  EXEHOOK=
1325  EXEDIR=  EXEDIR=
 PACKAGES_CONF=  
1326  IEEE=  IEEE=
1327  if test "x$MITGCM_IEEE" != x ; then  if test "x$MITGCM_IEEE" != x ; then
1328      IEEE=$MITGCM_IEEE      IEEE=$MITGCM_IEEE
# Line 1055  FS= Line 1331  FS=
1331  FS90=  FS90=
1332    
1333  AUTODIFF_PKG_USED=f  AUTODIFF_PKG_USED=f
1334    OPENAD=
1335  AD_OPTFILE=  AD_OPTFILE=
1336    CAT_SRC_FOR_TAF=1
1337  TAF=  TAF=
1338  AD_TAF_FLAGS=  AD_TAF_FLAGS=
1339  FTL_TAF_FLAGS=  FTL_TAF_FLAGS=
# Line 1067  FTL_TAF_FLAGS= Line 1345  FTL_TAF_FLAGS=
1345  SVD_TAMC_FLAGS=  SVD_TAMC_FLAGS=
1346  TAMC_EXTRA=  TAMC_EXTRA=
1347    
1348    DIVA=
1349    MPIINCLUDEDIR=
1350    MPI_HEADER_FILES=
1351    LOCAL_MPI_HEADERS=
1352    
1353  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
1354  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"  gm_s1="ROOTDIR STANDARDDIRS MODS PKG_DEPEND PKG_GROUPS DISABLE ENABLE"
1355  gm_s2="FC CPP IEEE TS PAPIS PAPI HPMT GSL MPI JAM DUMPSTATE STANDARDDIRS"  gm_s2="PLATFORM OPTFILE MAKE MAKEFILE MAKEDEPEND FC CC MPI OMP USE_R4"
1356    gm_s3="FEXTRAFLAGS IEEE DEVEL GSL TS PAPIS PCLS PAPI PCL HPMT DUMPSTATE"
1357    
1358  #  The following state is not directly set by command-line switches  #  The following state is not directly set by command-line switches
1359  gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "  gm_s4="LN S64 LINK PACKAGES INCLUDES FFLAGS FOPTIM"
1360  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"  gm_s5="CFLAGS LIBS KPP KFLAGS1 KFLAGS2 KPPFILES NOOPTFILES NOOPTFLAGS"
1361  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE"  gm_s6="PWD TOOLSDIR SOURCEDIRS INCLUDEDIRS EXEDIR EXECUTABLE EXEHOOK"
1362  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"  gm_s7="TMP THISHOST THISUSER THISDATE THISVER MACHINE FC_NAMEMANGLE"
1363  gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME"  gm_s8="HAVE_NETCDF HAVE_SYSTEM HAVE_FDATE HAVE_ETIME HAVE_LAPACK HAVE_FLUSH"
1364    
1365  #  The following are all related to adjoint/tangent-linear stuff  #  The following are all related to adjoint/tangent-linear stuff
1366  gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"  gm_s10="AUTODIFF_PKG_USED AD_OPTFILE OPENAD TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
1367  gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"  gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
1368  gm_s12="TAF_EXTRA TAMC_EXTRA"  gm_s12="TAF_EXTRA TAMC_EXTRA DIVA MPIINCLUDEDIR MPI_HEADER_FILES"
1369    
1370  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7 $gm_s8"
1371  gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"  gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
1372    
1373  cat <<EOF  cat <<EOF
1374    
1375  GENMAKE :  GENMAKE :
1376    
1377  A program for GENerating MAKEfiles for the MITgcm project.  For a  A program for GENerating MAKEfiles for the MITgcm project.
1378  quick list of options, use "genmake -h" or for more detail see:     For a quick list of options, use "genmake2 -h"
1379    or for more detail see the Developer's HOWTO manual at:
1380    http://mitgcm.org/devel_HOWTO/     http://mitgcm.org/public/docs.html
1381    
1382  EOF  EOF
1383    
1384    LOGFILE="genmake.log"
1385    #- clean-up previous genmake logfiles:
1386    rm -f genmake_state genmake_*optfile $LOGFILE
1387    
1388  echo "===  Processing options files and arguments  ==="  echo "===  Processing options files and arguments  ==="
 gm_local="genmake_local"  
 for i in . $MODS ; do  
     if test -r $i/$gm_local ; then  
         . $i/$gm_local  
         break  
     fi  
 done  
 printf "  getting local config information:  "  
 if test -f $gm_local ; then  
     echo "using $gm_local"  
     . $gm_local  
     # echo "DISABLE=$DISABLE"  
     # echo "ENABLE=$ENABLE"  
 else  
     echo "none found"  
 fi  
1389    
1390  #echo "$0::$1:$2:$3:$4:$5:$6:$7:"  #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
 #OPTIONS=  
 #n=0  
 #for i ; do  
 #   echo "$i  $n"  
 #   setvar="OPTIONS[$n]='$i'"  
 #   #  echo "  $setvar"  
 #   eval "$setvar"  
 #   n=$(( $n + 1 ))  
 #done  
1391  #parse_options  #parse_options
1392  ac_prev=  ac_prev=
1393  for ac_option in "$@" ; do  for ac_option in "$@" ; do
# Line 1138  for ac_option in "$@" ; do Line 1400  for ac_option in "$@" ; do
1400          ac_prev=          ac_prev=
1401          continue          continue
1402      fi      fi
1403        
1404      ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`      ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
1405        
1406      case $ac_option in      case $ac_option in
1407            
1408          -help | --help | -h | --h)          -help | --help | -h | --h)
1409              usage ;;              usage ;;
1410            
         -nooptfile | --nooptfile)  
             OPTFILE="NONE" ;;  
1411          -optfile | --optfile | -of | --of)          -optfile | --optfile | -of | --of)
1412              ac_prev=OPTFILE ;;              ac_prev=OPTFILE ;;
1413          -optfile=* | --optfile=* | -of=* | --of=*)          -optfile=* | --optfile=* | -of=* | --of=*)
1414              OPTFILE=$ac_optarg ;;              OPTFILE=$ac_optarg ;;
1415            
1416            -oad | --oad)
1417                OPENAD="true" ; ALWAYS_USE_F90=1 ;;
1418            -nocat4ad | -dog4ad | -ncad | -dad)
1419                CAT_SRC_FOR_TAF=0 ;;
1420          -adoptfile | --adoptfile | -adof | --adof)          -adoptfile | --adoptfile | -adof | --adof)
1421              ac_prev=AD_OPTFILE ;;              ac_prev=AD_OPTFILE ;;
1422          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
1423              AD_OPTFILE=$ac_optarg ;;              AD_OPTFILE=$ac_optarg ;;
1424            
1425          -pdepend | --pdepend)          -pdepend | --pdepend)
1426              ac_prev=PDEPEND ;;              ac_prev=PKG_DEPEND ;;
1427          -pdepend=* | --pdepend=*)          -pdepend=* | --pdepend=*)
1428              PDEPEND=$ac_optarg ;;              PKG_DEPEND=$ac_optarg ;;
1429            
1430          -pdefault | --pdefault)          -pgroups | --pgroups)
1431              ac_prev=PDEFAULT ;;              ac_prev=PKG_GROUPS ;;
1432          -pdefault=* | --pdefault=*)          -pgroups=* | --pgroups=*)
1433              PDEFAULT=$ac_optarg ;;              PKG_GROUPS=$ac_optarg ;;
1434            
1435          -make | --make | -m | --m)          -make | --make | -m | --m)
1436              ac_prev=MAKE ;;              ac_prev=MAKE ;;
1437          -make=* | --make=* | -m=* | --m=*)          -make=* | --make=* | -m=* | --m=*)
1438              MAKE=$ac_optarg ;;              MAKE=$ac_optarg ;;
1439            
1440          -bash | --bash)          -bash | --bash)
1441              ac_prev=BASH ;;              ac_prev=BASH ;;
1442          -bash=* | --bash=*)          -bash=* | --bash=*)
1443              BASH=$ac_optarg ;;              BASH=$ac_optarg ;;
1444            
1445          -makedepend | --makedepend | -md | --md)          -makedepend | --makedepend | -md | --md)
1446              ac_prev=MAKEDEPEND ;;              ac_prev=MAKEDEPEND ;;
1447          -makedepend=* | --makedepend=* | -md=* | --md=*)          -makedepend=* | --makedepend=* | -md=* | --md=*)
1448              MAKEDEPEND=$ac_optarg ;;              MAKEDEPEND=$ac_optarg ;;
1449            
1450          -makefile | --makefile | -ma | --ma)          -makefile | --makefile | -mf | --mf)
1451              ac_prev=MAKEFILE ;;              ac_prev=MAKEFILE ;;
1452          -makefile=* | --makefile=* | -ma=* | --ma=*)          -makefile=* | --makefile=* | -mf=* | --mf=*)
1453              MAKEFILE=$ac_optarg ;;              MAKEFILE=$ac_optarg ;;
1454            
1455          -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)          -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
1456              echo "ERROR: The platform option has been removed.  Please specify"              echo "ERROR: The platform option has been removed.  Please specify"
1457              echo "  the build options using the \"optfile\" mechanism."              echo "  the build options using the \"optfile\" mechanism."
1458              echo              echo
1459              usage              usage
1460              ;;              ;;
1461            
1462          -rootdir | --rootdir | -rd | --rd)          -rootdir | --rootdir | -rd | --rd)
1463              ac_prev=ROOTDIR ;;              ac_prev=ROOTDIR ;;
1464          -rootdir=* | --rootdir=* | -rd=* | --rd=*)          -rootdir=* | --rootdir=* | -rd=* | --rd=*)
1465              ROOTDIR=$ac_optarg ;;              ROOTDIR=$ac_optarg ;;
1466            
1467          -mods | --mods | -mo | --mo)          -mods | --mods | -mo | --mo)
1468              ac_prev=MODS ;;              ac_prev=MODS ;;
1469          -mods=* | --mods=* | -mo=* | --mo=*)          -mods=* | --mods=* | -mo=* | --mo=*)
1470              MODS=$ac_optarg ;;              MODS=$ac_optarg ;;
1471            
1472          -disable | --disable)          -disable | --disable)
1473              ac_prev=DISABLE ;;              ac_prev=DISABLE ;;
1474          -disable=* | --disable=*)          -disable=* | --disable=*)
1475              DISABLE=$ac_optarg ;;              DISABLE=$ac_optarg ;;
1476            
1477          -enable | --enable)          -enable | --enable)
1478              ac_prev=ENABLE ;;              ac_prev=ENABLE ;;
1479          -enable=* | --enable=*)          -enable=* | --enable=*)
1480              ENABLE=$ac_optarg ;;              ENABLE=$ac_optarg ;;
1481            
1482          -standarddirs | --standarddirs)          -standarddirs | --standarddirs)
1483              ac_prev=STANDARDDIRS ;;              ac_prev=STANDARDDIRS ;;
1484          -standarddirs=* | --standarddirs=*)          -standarddirs=* | --standarddirs=*)
# Line 1224  for ac_option in "$@" ; do Line 1488  for ac_option in "$@" ; do
1488  #               ac_prev=cpp ;;  #               ac_prev=cpp ;;
1489  #           -cpp=* | --cpp=*)  #           -cpp=* | --cpp=*)
1490  #               CPP=$ac_optarg ;;  #               CPP=$ac_optarg ;;
1491            
1492          -cc | --cc)          -cc | --cc)
1493              ac_prev=CC ;;              ac_prev=CC ;;
1494          -cc=* | --cc=*)          -cc=* | --cc=*)
1495              CC=$ac_optarg ;;              CC=$ac_optarg ;;
1496            
1497          -fortran | --fortran | -fc | --fc)          -fortran | --fortran | -fc | --fc)
1498              ac_prev=FC ;;              ac_prev=FC ;;
1499          -fc=* | --fc=*)          -fc=* | --fc=*)
1500              FC=$ac_optarg ;;              FC=$ac_optarg ;;
1501            
1502          -fs | --fs)          -fs | --fs)
1503              ac_prev=FS ;;              ac_prev=FS ;;
1504          -fs=* | --fs=*)          -fs=* | --fs=*)
1505              FS=$ac_optarg ;;              FS=$ac_optarg ;;
1506            
1507          -fs90 | --fs90)          -fs90 | --fs90)
1508              ac_prev=FS90 ;;              ac_prev=FS90 ;;
1509          -fs90=* | --fs90=*)          -fs90=* | --fs90=*)
1510              FS90=$ac_optarg ;;              FS90=$ac_optarg ;;
1511            
1512            -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4 )
1513                USE_R4=true ;;
1514    
1515          -ieee | --ieee)          -ieee | --ieee)
1516              IEEE=true ;;              IEEE=true ;;
1517          -noieee | --noieee)          -noieee | --noieee)
1518              IEEE= ;;              echo "Warning: ignore option '$ac_option' (default is already without '-ieee')" ;;
1519            -devel | --devel)
1520                IEEE=true ; DEVEL=true ;;
1521            -gsl | --gsl)
1522                GSL=true ;;
1523    
1524          -ts | --ts)          -ts | --ts)
1525              TS=true ;;              TS=true ;;
1526          -papis | --papis)          -papis | --papis)
1527              PAPIS=true ;;              PAPIS=true ;;
1528            -pcls | --pcls)
1529                PCLS=true ;;
1530          -foolad | --foolad)          -foolad | --foolad)
1531              FOOLAD=true ;;              FOOLAD=true ;;
1532          -papi | --papi)          -papi | --papi)
1533              PAPI=true ;;              PAPI=true ;;
1534            -pcl | --pcl)
1535                PCL=true ;;
1536          -hpmt | --hpmt)          -hpmt | --hpmt)
1537              HPMT=true ;;              HPMT=true ;;
1538    
         -gsl | --gsl)  
             GSL=true ;;  
   
1539          -mpi | --mpi)          -mpi | --mpi)
1540              MPI=true ;;              MPI=true ;;
1541          -mpi=* | --mpi=*)          -mpi=* | --mpi=*)
1542              MPIPATH=$ac_optarg              MPIPATH=$ac_optarg
1543              MPI=true ;;              MPI=true ;;
1544            
1545  #       -jam | --jam)          -omp | --omp)
1546  #           JAM=1 ;;              OMP=true ;;
1547  #       -nojam | --nojam)          -omp=* | --omp=*)
1548  #           JAM=0 ;;              OMPFLAG=$ac_optarg
1549                        OMP=true ;;
1550    
1551          -ds | --ds)          -ds | --ds)
1552              DUMPSTATE=t ;;              DUMPSTATE=t ;;
1553            
1554            -extra_flag | --extra_flag)
1555                ac_prev=FEXTRAFLAGS ;;
1556            -extra_flag=* | --extra_flag=*)
1557                FEXTRAFLAGS=$ac_optarg ;;
1558    
1559          -taf_extra | --taf_extra)          -taf_extra | --taf_extra)
1560              ac_prev=TAF_EXTRA ;;              ac_prev=TAF_EXTRA ;;
1561          -taf_extra=* | --taf_extra=*)          -taf_extra=* | --taf_extra=*)
# Line 1287  for ac_option in "$@" ; do Line 1565  for ac_option in "$@" ; do
1565              ac_prev=TAMC_EXTRA ;;              ac_prev=TAMC_EXTRA ;;
1566          -tamc_extra=* | --tamc_extra=*)          -tamc_extra=* | --tamc_extra=*)
1567              TAMC_EXTRA=$ac_optarg ;;              TAMC_EXTRA=$ac_optarg ;;
1568            
1569          -ignoretime | -ignore_time | --ignoretime | --ignore_time)          -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1570              IGNORE_TIME="-DIGNORE_TIME" ;;              IGNORE_TIME="-DIGNORE_TIME" ;;
1571    
# Line 1298  for ac_option in "$@" ; do Line 1576  for ac_option in "$@" ; do
1576              echo "Error: unrecognized option: "$ac_option              echo "Error: unrecognized option: "$ac_option
1577              usage              usage
1578              ;;              ;;
1579            
1580          *)          *)
1581              echo "Error: unrecognized argument: "$ac_option              echo "Error: unrecognized argument: "$ac_option
1582              usage              usage
1583              ;;              ;;
1584            
1585      esac      esac
1586        
1587  done  done
1588    
1589    #TMP=./genmk_$$
1590    #- try to put temporary files in system-local /tmp dir
1591    TMP=/tmp/genmk_${USER}_$$
1592    touch $TMP ; retVal=$?
1593    if [ $retVal -eq 0 ] ; then
1594      if test ! -r $TMP ; then TMP=./genmk_$$ ; fi
1595    else
1596      TMP=./genmk_$$
1597    fi
1598    rm -f $TMP
1599    #echo "  temp files: $TMP.*"
1600    
1601    printf "  getting local config information:  "
1602    if test -f $gm_local ; then
1603        echo "using $gm_local"
1604        . $gm_local
1605    else
1606        echo "none found"
1607    fi
1608    
1609  if test -f ./.genmakerc ; then  if test -f ./.genmakerc ; then
1610      echo      echo
1611      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
1612      echo "  file.  This file format is no longer supported.  Please see:"      echo "  file.  This file format is no longer supported.  For directions on"
1613      echo      echo "  how to setup and use the new \"genmake2\" script, please see:"
1614      echo "    http://mitgcm.org/devel_HOWTO/"      echo "    http://mitgcm.org/public/devel_HOWTO/"
1615        echo "  and send an email to MITgcm-support@mitgcm.org if you need help."
1616        echo "WARNING: ignore \"./.genmakerc\" and continue."
1617      echo      echo
     echo "  for directions on how to setup and use the new \"genmake2\" input"  
     echo "  files and send an email to MITgcm-support@mitgcm.org if you want help."  
     echo  
1618  fi  fi
1619    
1620  #  Find the MITgcm ${ROOTDIR}  #  Find the MITgcm ${ROOTDIR}
1621  if test "x${ROOTDIR}" = x ; then  if test "x${ROOTDIR}" = x ; then
1622      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1623      if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then      if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesupp -a -d ../pkg ; then
1624          ROOTDIR=".."          ROOTDIR=".."
1625      else      else
1626          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1627              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
1628                  ROOTDIR=$d                  ROOTDIR=$d
1629                  printf "Warning:  ROOTDIR was not specified but there appears to be"                  printf "Warning: ROOTDIR was not specified ;"
1630                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."                  echo " try using a local copy of MITgcm found at \"$ROOTDIR\""
1631                  break                  break
1632              fi              fi
1633          done          done
# Line 1349  if test ! -d ${ROOTDIR} ; then Line 1645  if test ! -d ${ROOTDIR} ; then
1645  fi  fi
1646    
1647  #  Find the MITgcm ${THISVER}  #  Find the MITgcm ${THISVER}
1648  if test -f "${ROOTDIR}/doc/tag-index" ; then  version_file="${ROOTDIR}/doc/tag-index"
1649      THISVER=`grep '^checkpoint' ${ROOTDIR}/doc/tag-index | head -1`  if test -f $version_file ; then
1650        THISVER=`$AWK '/^checkpoint/{print $1; exit}' $version_file`
1651    #-  remove ./BUILD_INFO.h file if older than version_file
1652        if test -f ./BUILD_INFO.h -a ./BUILD_INFO.h -ot $version_file ; then
1653            echo "  remove ./BUILD_INFO.h (older than ${version_file})"
1654            rm -f ./BUILD_INFO.h
1655        fi
1656  fi  fi
1657    
1658  if test "x$MAKEFILE" = x ; then  if test "x$MAKEFILE" = x ; then
1659      MAKEFILE="Makefile"      MAKEFILE="Makefile"
1660  fi  fi
1661    
1662  echo "  getting OPTFILE information:  "  echo "  getting OPTFILE information:"
1663  if test "x${OPTFILE}" = x ; then  if test "x${OPTFILE}" = x ; then
1664      if test "x$MITGCM_OF" = x ; then      if test "x$MITGCM_OF" = x ; then
1665          echo "Warning: no OPTFILE specified so we'll look for possible settings"          echo "Warning: no OPTFILE specified so we'll look for possible settings"
1666          printf "\n===  Searching for possible settings for OPTFILE  ===\n"          printf "\n===  Searching for possible settings for OPTFILE  ===\n"
1667          find_possible_configs          find_possible_optfile
1668      else      else
1669          OPTFILE=$MITGCM_OF          OPTFILE=$MITGCM_OF
1670      fi      fi
# Line 1377  if test "x$OPTFILE" != xNONE ; then Line 1679  if test "x$OPTFILE" != xNONE ; then
1679              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1680              exit 1              exit 1
1681          fi          fi
1682          if test "x$DUMPSTATE" != xf ; then          if test "x$DUMPSTATE" = xt ; then
1683              cp -f $OPTFILE "genmake_optfile"              cp -f $OPTFILE "genmake_optfile"
1684          fi          fi
1685      else      else
# Line 1386  if test "x$OPTFILE" != xNONE ; then Line 1688  if test "x$OPTFILE" != xNONE ; then
1688      fi      fi
1689  fi  fi
1690    
1691  echo "  getting AD_OPTFILE information:  "  echo "  getting AD_OPTFILE information:"
1692  if test "x${AD_OPTFILE}" = x ; then  if test "x${AD_OPTFILE}" = x ; then
1693      if test "x$MITGCM_AD_OF" = x ; then      if test "x$MITGCM_AD_OF" != x ; then
1694            AD_OPTFILE=$MITGCM_AD_OF
1695        elif test "x$OPENAD" = x ; then
1696          AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default          AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
1697      else      else
1698          AD_OPTFILE=$MITGCM_AD_OF          AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_oad
1699      fi      fi
1700  fi  fi
1701  if test "x${AD_OPTFILE}" != xNONE ; then  if test "x${AD_OPTFILE}" != xNONE ; then
# Line 1404  if test "x${AD_OPTFILE}" != xNONE ; then Line 1708  if test "x${AD_OPTFILE}" != xNONE ; then
1708              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1709              exit 1              exit 1
1710          fi          fi
1711          if test "x$DUMPSTATE" != xf ; then          if test "x$DUMPSTATE" = xt ; then
1712              cp -f $AD_OPTFILE "genmake_ad_optfile"              cp -f $AD_OPTFILE "genmake_ad_optfile"
1713          fi          fi
1714      else      else
# Line 1414  if test "x${AD_OPTFILE}" != xNONE ; then Line 1718  if test "x${AD_OPTFILE}" != xNONE ; then
1718  fi  fi
1719    
1720  #====================================================================  #====================================================================
1721    # Initialize INCLUDEDIRSMK from and optfile INCLUDEDIRS
1722    if test "x${INCLUDEDIRS}" != "x" ; then
1723     INCLUDEDIRSMK=${INCLUDEDIRS}
1724    fi
1725    
1726    #====================================================================
1727  #  Set default values if not set by the optfile  #  Set default values if not set by the optfile
1728  #  #
1729  #  Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined.  If not,  #  Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
# Line 1432  Error: no Fortran compiler: please speci Line 1742  Error: no Fortran compiler: please speci
1742  EOF  EOF
1743      exit 1      exit 1
1744  fi  fi
1745    if test "x$GET_FC_VERSION" != x ; then
1746      echo "Get compiler version using: $FC $GET_FC_VERSION" >> $LOGFILE
1747      ff=`echo $FC | sed 's/ .*//'` ; xx=`echo $ff | sed 's/^./& /' | sed 's/ .*//'`
1748      if test $xx != '/' ; then which $ff >> $LOGFILE ; fi
1749      $FC $GET_FC_VERSION > genmake_fc_vers1 2> genmake_fc_vers2
1750      if test -s genmake_fc_vers1 ; then
1751        cat genmake_fc_vers1 >> $LOGFILE
1752      else
1753        cat genmake_fc_vers2 >> $LOGFILE
1754      fi
1755      echo "<-- compiler version ----" >> $LOGFILE
1756      rm -f genmake_fc_vers1 genmake_fc_vers2
1757    fi
1758    
1759  if test "x$CC" = x ; then  if test "x$CC" = x ; then
1760      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  
1761  fi  fi
1762    
1763  if test "x$LINK" = x ; then  if test "x$LINK" = x ; then
1764      LINK=$FC      LINK=$FC
1765  fi  fi
# Line 1449  if test "x$MAKE" = x ; then Line 1767  if test "x$MAKE" = x ; then
1767      MAKE="make"      MAKE="make"
1768  fi  fi
1769  if test "x$CPP" = x ; then  if test "x$CPP" = x ; then
1770      CPP=cpp      CPP="cpp -traditional -P"
1771  fi  fi
1772  #EH3 === UGLY ===  #EH3 === UGLY ===
1773  #  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 1476  EOF Line 1794  EOF
1794  else  else
1795      rm -f test_cpp      rm -f test_cpp
1796  fi  fi
1797    
1798  look_for_makedepend  look_for_makedepend
1799    
1800    #  Check that soft-link command is set and usable
1801  if test "x$LN" = x ; then  if test "x$LN" = x ; then
1802      LN="ln -s"      LN="ln -s"
1803  fi  fi
# Line 1486  RETVAL=$? Line 1807  RETVAL=$?
1807  if test "x$RETVAL" != x0 ; then  if test "x$RETVAL" != x0 ; then
1808      cat <<EOF 1>&2      cat <<EOF 1>&2
1809    
1810  Error: The command "ln -s" failed -- please specify a working soft-link  Error: The command "$LN" failed -- please specify a working soft-link
1811    command in the optfile.    command in the optfile.
1812    
1813  EOF  EOF
# Line 1504  check_for_broken_Ff Line 1825  check_for_broken_Ff
1825    
1826  if test ! "x$MPI" = x ; then  if test ! "x$MPI" = x ; then
1827        echo "  Turning on MPI cpp macros"        echo "  Turning on MPI cpp macros"
1828        DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"        DEFINES="$DEFINES -DALLOW_USE_MPI"
1829    #- To compile code older than checkpoint63s (2012/09/05), un-comment the following line:
1830    #     DEFINES="$DEFINES -DALWAYS_USE_MPI"
1831    fi
1832    if test ! "x$OMP" = x ; then
1833          echo "  Add OMPFLAG and turn on OpenMP cpp macros"
1834          FFLAGS="$FFLAGS $OMPFLAG"
1835          F90FLAGS="$F90FLAGS $OMPFLAG"
1836          DEFINES="$DEFINES -DUSE_OMP_THREADING"
1837    fi
1838    
1839    if test ! "x$USE_R4" = x ; then
1840          echo "  Turning on LET_RS_BE_REAL4 cpp flag"
1841          DEFINES="$DEFINES -DLET_RS_BE_REAL4"
1842  fi  fi
1843    
1844  if test ! "x$TS" = x ; then  if test ! "x$TS" = x ; then
1845        echo "  Turning on timing per timestep"        echo "  Turning on timing per timestep"
1846        if test ! "x$FOOLAD" = x ; then        if test ! "x$FOOLAD" = x ; then
1847              DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP"              DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP"
1848        else        else
1849              DEFINES="$DEFINES -DTIME_PER_TIMESTEP"              DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1850        fi        fi
1851          PACKAGES="$PACKAGES showflops"
1852  fi  fi
1853  if test ! "x$PAPIS" = x ; then  if test ! "x$PAPIS" = x ; then
1854        echo "  Turning on PAPI flop summary per timestep"        echo "  Turning on PAPI flop summary per timestep"
# Line 1525  if test ! "x$PAPIS" = x ; then Line 1860  if test ! "x$PAPIS" = x ; then
1860        fi        fi
1861        INCLUDES="$INCLUDES $PAPIINC"        INCLUDES="$INCLUDES $PAPIINC"
1862        LIBS="$LIBS $PAPILIB"        LIBS="$LIBS $PAPILIB"
1863          PACKAGES="$PACKAGES showflops"
1864    fi
1865    if test ! "x$PCLS" = x ; then
1866          echo "  Turning on PCL counter summary per timestep"
1867          echo "  Please make sure PCLINC, PCLLIB are defined"
1868          if test ! "x$FOOLAD" = x ; then
1869                DEFINES="$DEFINES -DUSE_PCL_FLOPS_SFP"
1870          else
1871                DEFINES="$DEFINES -DUSE_PCL_FLOPS"
1872          fi
1873          INCLUDES="$INCLUDES $PCLINC"
1874          LIBS="$LIBS $PCLLIB"
1875          PACKAGES="$PACKAGES showflops"
1876  fi  fi
1877  if test ! "x$PAPI" = x ; then  if test ! "x$PAPI" = x ; then
1878        if test ! "x$PAPIS" = x ; then        if test ! "x$PAPIS" = x ; then
# Line 1532  if test ! "x$PAPI" = x ; then Line 1880  if test ! "x$PAPI" = x ; then
1880            echo "  Sticking with PAPI flop summary per timestep!"            echo "  Sticking with PAPI flop summary per timestep!"
1881        else        else
1882            echo "  Turning on performance analysis with PAPI"            echo "  Turning on performance analysis with PAPI"
1883            echo "  Please make sure PAPIINC, PAPILIB are defined"            echo "  Please make sure PAPIINC, PAPILIB are defined"
1884            DEFINES="$DEFINES -DUSE_PAPI"            DEFINES="$DEFINES -DUSE_PAPI"
1885            INCLUDES="$INCLUDES $PAPIINC"            INCLUDES="$INCLUDES $PAPIINC"
1886            LIBS="$LIBS $PAPILIB"            LIBS="$LIBS $PAPILIB"
1887        fi        fi
1888  fi  fi
1889    if test ! "x$PCL" = x ; then
1890          if test ! "x$PCLS" = x ; then
1891              echo "  PCL performance analysis and flop summary per timestep cannot co-exist!"
1892              echo "  Sticking with PCL flop summary per timestep!"
1893          else
1894              echo "  Turning on performance analysis with PCL"
1895              echo "  Please make sure PCLINC, PCLLIB are defined"
1896              DEFINES="$DEFINES -DUSE_PCL"
1897              INCLUDES="$INCLUDES $PCLINC"
1898              LIBS="$LIBS $PCLLIB"
1899          fi
1900    fi
1901  if test ! "x$HPMT" = x ; then  if test ! "x$HPMT" = x ; then
1902        if test ! "x$PAPI" = x ; then        if test ! "x$PAPI" = x ; then
1903            echo "  PAPI and the HPM Toolkit cannot co-exist!"            echo "  PAPI and the HPM Toolkit cannot co-exist!"
1904            echo "  Sticking with PAPI!"            echo "  Sticking with PAPI!"
1905        else        else
1906            if test ! "x$PCL" = x ; then
1907              echo "  PCL and the HPM Toolkit cannot co-exist!"
1908              echo "  Sticking with PCL!"
1909            else
1910            echo "  Turning on performance analysis with the HPM Toolkit"            echo "  Turning on performance analysis with the HPM Toolkit"
1911            echo "  Please make sure HPMTINC, HPMTLIB are defined"            echo "  Please make sure HPMTINC, HPMTLIB are defined"
1912            DEFINES="$DEFINES -DUSE_LIBHPM"            DEFINES="$DEFINES -DUSE_LIBHPM"
1913            INCLUDES="$INCLUDES $HPMTINC"            INCLUDES="$INCLUDES $HPMTINC"
1914            LIBS="$LIBS $HPMTLIB"            LIBS="$LIBS $HPMTLIB"
1915            fi
1916        fi        fi
1917  fi  fi
1918  if test ! "x$GSL" = x ; then  if test ! "x$GSL" = x ; then
# Line 1557  if test ! "x$GSL" = x ; then Line 1922  if test ! "x$GSL" = x ; then
1922        INCLUDES="$INCLUDES $GSLINC"        INCLUDES="$INCLUDES $GSLINC"
1923        LIBS="$LIBS $GSLLIB"        LIBS="$LIBS $GSLLIB"
1924  fi  fi
1925    #- if USE_EXTENDED_SRC is set, add EXTENDED_SRC_FLAG to FFLAGS :
1926    if test ! "x$USE_EXTENDED_SRC" = x ; then
1927          FFLAGS="$FFLAGS $EXTENDED_SRC_FLAG"
1928          F90FIXEDFORMAT="$F90FIXEDFORMAT $EXTENDED_SRC_FLAG"
1929    fi
1930    
1931  printf "\n===  Checking system libraries  ===\n"  printf "\n===  Checking system libraries  ===\n"
1932  printf "  Do we have the system() command using $FC...  "  printf "  Do we have the system() command using $FC...  "
# Line 1598  else Line 1968  else
1968  fi  fi
1969  rm -f genmake_tcomp*  rm -f genmake_tcomp*
1970    
1971  printf "  Do we have the etime() command using $FC...  "  printf "  Do we have the etime() command using $FC... "
1972  cat > genmake_tcomp.$FS <<EOF  cat > genmake_tcomp_1.$FS <<EOF
1973        program hello        program hello
1974        REAL*4 ACTUAL, TARRAY(2)        REAL*4 actual, tarray(2)
1975        EXTERNAL ETIME        EXTERNAL ETIME
1976        REAL*4 ETIME        REAL*4 ETIME
1977        actual = etime( tarray )        actual = ETIME( tarray )
1978        print *, tarray        print *, tarray
1979        end        end
1980  EOF  EOF
1981  $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
1982  RETVAL=$?  RETVAL=$?
1983  if test "x$RETVAL" = x0 ; then  if test "x$RETVAL" = x0 ; then
1984      HAVE_ETIME=t      HAVE_ETIME='Fct'
1985      DEFINES="$DEFINES -DHAVE_ETIME"      DEFINES="$DEFINES -DHAVE_ETIME_FCT"
1986      echo "yes"      echo " yes (${HAVE_ETIME})"
1987  else  else
1988      cat > genmake_tcomp_2.$FS <<EOF
1989          program hello
1990          REAL*4 actual, tarray(2)
1991          actual = -999.
1992          call ETIME( tarray, actual )
1993          if ( actual.ge.0. ) then
1994            print *, 0, tarray, actual
1995          else
1996            print *, 1, tarray, actual
1997          endif
1998          end
1999    EOF
2000      $FC $FFLAGS -o genmake_tcomp_2 genmake_tcomp_2.$FS >> genmake_tcomp.log 2>&1
2001      RETVAL=$?
2002      if test "x$RETVAL" = x0 ; then
2003        echo -n 'c,'
2004        ./genmake_tcomp_2 > genmake_tcomp_2.out 2>&1
2005        RETVAL=$?
2006      fi
2007      if test "x$RETVAL" = x0 ; then
2008        echo -n 'r:'
2009        RETVAL=`cat genmake_tcomp_2.out | $AWK '{print $1}'`
2010      fi
2011      if test "x$RETVAL" = x0 ; then
2012        HAVE_ETIME='SbR'
2013        DEFINES="$DEFINES -DHAVE_ETIME_SBR"
2014        echo " yes (${HAVE_ETIME})"
2015      else
2016      HAVE_ETIME=      HAVE_ETIME=
2017      echo "no"      echo " no"
2018      fi
2019  fi  fi
2020    #mkdir chk_etime ; cp -p -f genmake_tcomp* chk_etime
2021  rm -f genmake_tcomp*  rm -f genmake_tcomp*
2022    
2023  printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "  printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
2024  check_HAVE_CLOC  check_HAVE_CLOC
2025  if test "x$HAVE_CLOC" != x ; then  if test "x$HAVE_CLOC" != x ; then
2026        DEFINES="$DEFINES -DHAVE_CLOC"
2027      echo "yes"      echo "yes"
2028  else  else
2029      echo "no"      echo "no"
# Line 1636  rm -f genmake_t* Line 2037  rm -f genmake_t*
2037    
2038  printf "  Can we unlimit the stack size using $FC...  "  printf "  Can we unlimit the stack size using $FC...  "
2039  check_HAVE_SETRLSTK  check_HAVE_SETRLSTK
2040  if test "x$HAVE_SETRLSTK" != x ; then  if test "x$HAVE_SETRLSTK" = xt ; then
2041        DEFINES="$DEFINES -DHAVE_SETRLSTK"
2042      echo "yes"      echo "yes"
2043  else  else
2044      echo "no"      echo "no"
# Line 1645  rm -f genmake_t* Line 2047  rm -f genmake_t*
2047    
2048  printf "  Can we register a signal handler using $FC...  "  printf "  Can we register a signal handler using $FC...  "
2049  check_HAVE_SIGREG  check_HAVE_SIGREG
2050  if test "x$HAVE_SIGREG" != x ; then  if test "x$HAVE_SIGREG" = xt ; then
2051        DEFINES="$DEFINES -DHAVE_SIGREG"
2052      echo "yes"      echo "yes"
2053  else  else
2054      echo "no"      echo "no"
# Line 1655  rm -f genmake_t* Line 2058  rm -f genmake_t*
2058  printf "  Can we use stat() through C calls...  "  printf "  Can we use stat() through C calls...  "
2059  check_HAVE_STAT  check_HAVE_STAT
2060  if test "x$HAVE_STAT" != x ; then  if test "x$HAVE_STAT" != x ; then
2061        DEFINES="$DEFINES -DHAVE_STAT"
2062      echo "yes"      echo "yes"
2063  else  else
2064      echo "no"      echo "no"
# Line 1664  rm -f genmake_t* Line 2068  rm -f genmake_t*
2068  printf "  Can we create NetCDF-enabled binaries...  "  printf "  Can we create NetCDF-enabled binaries...  "
2069  check_netcdf_libs  check_netcdf_libs
2070  if test "x$HAVE_NETCDF" != x ; then  if test "x$HAVE_NETCDF" != x ; then
2071        DEFINES="$DEFINES -DHAVE_NETCDF"
2072        echo "yes"
2073    else
2074        echo "no"
2075    fi
2076    
2077    printf "  Can we create LAPACK-enabled binaries...  "
2078    check_lapack_libs
2079    if test "x$HAVE_LAPACK" != x ; then
2080        DEFINES="$DEFINES -DHAVE_LAPACK"
2081        echo "yes"
2082    else
2083        echo "no"
2084    fi
2085    
2086    printf "  Can we call FLUSH intrinsic subroutine...  "
2087    check_HAVE_FLUSH
2088    if test "x$HAVE_FLUSH" = xt ; then
2089        DEFINES="$DEFINES -DHAVE_FLUSH"
2090      echo "yes"      echo "yes"
2091  else  else
2092      echo "no"      echo "no"
2093  fi  fi
 DEFINES="$DEFINES $IGNORE_TIME"  
2094    
2095    DEFINES="$DEFINES $IGNORE_TIME"
2096  if test "x$EMBED_SRC" = xt ; then  if test "x$EMBED_SRC" = xt ; then
2097      build_embed_encode      build_embed_encode
2098  fi  fi
2099  if test "x$EMBED_SRC" = xt ; then  if test "x$EMBED_SRC" = xt ; then
2100      ENABLE="$ENABLE embed_files"      ENABLE="$ENABLE embed_files"
2101    #   DEFINES="$DEFINES -DHAVE_EMBED_SRC"
2102  fi  fi
2103    
   
2104  printf "\n===  Setting defaults  ===\n"  printf "\n===  Setting defaults  ===\n"
2105  printf "  Adding MODS directories:  "  printf "  Adding MODS directories: "
2106  for d in $MODS ; do  for d in $MODS ; do
2107      if test ! -d $d ; then      if test ! -d $d ; then
2108          echo          echo
2109          echo "Error: MODS directory \"$d\" not found!"          echo "Error: MODS directory \"$d\" not found!"
2110          exit 1          exit 1
2111      else      else
2112          printf " $d"          printf "$d "
2113          SOURCEDIRS="$SOURCEDIRS $d"          SOURCEDIRS="$SOURCEDIRS $d"
2114          INCLUDEDIRS="$INCLUDEDIRS $d"          INCLUDEDIRS="$INCLUDEDIRS $d"
2115            SOURCEDIRSMK="$SOURCEDIRSMK $d"
2116            INCLUDEDIRSMK="$INCLUDEDIRSMK $d"
2117      fi      fi
2118  done  done
2119  echo  echo
2120    
2121  if test "x${PLATFORM}" = x ; then  #if test "x${PLATFORM}" = x ; then
2122      PLATFORM=$p_PLATFORM  #    PLATFORM=$p_PLATFORM
2123  fi  #fi
2124    
2125  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
2126      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
# Line 1712  fi Line 2137  fi
2137    
2138  if test "x${TOOLSDIR}" = x ; then  if test "x${TOOLSDIR}" = x ; then
2139      TOOLSDIR="$ROOTDIR/tools"      TOOLSDIR="$ROOTDIR/tools"
2140        TOOLSDIRMK='$(ROOTDIR)'"/tools"
2141    else
2142        TOOLSDIRMK=${TOOLSDIR}
2143  fi  fi
2144  if test ! -d ${TOOLSDIR} ; then  if test ! -d ${TOOLSDIR} ; then
2145      echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
# Line 1735  ERROR: neither of the two default script Line 2163  ERROR: neither of the two default script
2163      ${TOOLSDIR}/set64bitConst.sh      ${TOOLSDIR}/set64bitConst.sh
2164      ${TOOLSDIR}/set64bitConst.csh      ${TOOLSDIR}/set64bitConst.csh
2165    
2166    are working so please check paths or specify (with \$S64) a    are working so please check paths or specify (with \$S64) a
2167    working version of this script.    working version of this script.
2168    
2169  EOF  EOF
# Line 1747  THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSD Line 2175  THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSD
2175    
2176  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
2177    
2178    #  Set Standard Code Directories:
2179    if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
2180        STANDARDDIRS="eesupp model"
2181    fi
2182    #  if model in Standard-Code-Dir, add eesupp (needed to compile model)
2183    echo " $STANDARDDIRS " | grep ' model ' > /dev/null 2>&1
2184    ckM=$?
2185    echo " $STANDARDDIRS " | grep ' eesupp ' > /dev/null 2>&1
2186    ckE=$?
2187    if test $ckM = 0 -a $ckE = 1 ; then
2188        STANDARDDIRS="$STANDARDDIRS eesupp"
2189    fi
2190    
2191  #  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
2192  #  generated from some template source files. We'll make them first so  #  generated from some template source files. We'll make them first so
2193  #  they appear as regular source code  #  they appear as regular source code
2194  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
2195      echo "  Making source files in eesupp from templates"      echo "  Making source files in eesupp from templates"
2196      ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1      ( cd $ROOTDIR"/eesupp/src/" && $MAKE clean_old && $MAKE \
2197        ) > make_eesupp.errors 2>&1
2198      RETVAL=$?      RETVAL=$?
2199      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
2200          rm -f make_eesupp.errors          rm -f make_eesupp.errors
# Line 1763  if test -r $ROOTDIR"/eesupp/src/Makefile Line 2205  if test -r $ROOTDIR"/eesupp/src/Makefile
2205      fi      fi
2206  fi  fi
2207    
2208  #same for exch2  #same for pkg/exch2 and pkg/regrid
2209  if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then  for pdir in exch2 regrid ; do
2210      echo "  Making source files in exch2 from  templates"      if test -r $ROOTDIR"/pkg/${pdir}/Makefile" ; then
2211      ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1          echo "  Making source files in pkg/${pdir} from templates"
2212      RETVAL=$?          ( cd $ROOTDIR"/pkg/"${pdir} && $MAKE clean_old && $MAKE \
2213      if test "x${RETVAL}" = x0 ; then          ) > make_${pdir}.errors 2>&1
2214          rm -f make_exch2.errors          RETVAL=$?
2215      else          if test "x${RETVAL}" = x0 ; then
2216          echo "Error: problem encountered while building source files in exch2:"              rm -f make_${pdir}.errors
2217          cat make_exch2.errors 1>&2          else
2218          exit 1              echo "Error: problem encountered while building source files in pkg/${pdir}:"
2219                cat make_${pdir}.errors 1>&2
2220                exit 1
2221            fi
2222      fi      fi
2223  fi  done
2224    
2225  printf "\n===  Determining package settings  ===\n"  printf "\n===  Determining package settings  ===\n"
2226  if  test "x${PDEPEND}" = x ; then  if  test "x${PKG_DEPEND}" = x ; then
2227      tmp=$ROOTDIR"/pkg/pkg_depend"      tmp=$ROOTDIR"/pkg/pkg_depend"
2228      if test -r $tmp ; then      if test -r $tmp ; then PKG_DEPEND=$tmp ; fi
2229          PDEPEND=$tmp  fi
2230      else  if  test "x${PKG_DEPEND}" = x ; then
2231          echo "Warning:  No package dependency information was specified."          echo "Warning:  No package dependency information was specified."
2232          echo "  Please check that ROOTDIR/pkg/pkg_depend exists."          echo "  Please check that ROOTDIR/pkg/pkg_depend exists."
     fi  
2233  else  else
2234      if test ! -r ${PDEPEND} ; then      if test ! -r ${PKG_DEPEND} ; then
2235          echo "Error:  can't read package dependency info from PDEPEND=\"$PDEPEND\""          echo "Error:  can't read package dependency info from PKG_DEPEND=\"$PKG_DEPEND\""
2236          exit 1          exit 1
2237      fi      fi
2238        echo "  getting package dependency info from  $PKG_DEPEND"
2239    #  Strip the comments and then convert the dependency file into arrays: PNAME, DNAME
2240        get_pdepend_list $PKG_DEPEND
2241  fi  fi
2242  echo "  getting package dependency info from  $PDEPEND"  
2243  #  Strip the comments and then convert the dependency file into  # A default package groups file "$ROOTDIR/pkg/pkg_groups" is provided
2244  #  two arrays: PNAME, DNAME  #  to define the "default_pkg_list" and package groups (for convenience, one
2245  cat $PDEPEND | sed -e 's/#.*$//g' \  #  can specify a group of packages using names like "ocean" and "atmosphere").
2246      | $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
2247      > ./.pd_tmp      tmp=$ROOTDIR"/pkg/pkg_groups"
2248  RETVAL=$?      if test -r $tmp ; then PKG_GROUPS=$tmp ; fi
2249  if test ! "x${RETVAL}" = x0 ; then  fi
2250      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""  if test "x${PKG_GROUPS}" = x ; then
2251      exit 1          echo "Warning:  No package groups information was specified."
2252            echo "  Please check that ROOTDIR/pkg/pkg_groups exists."
2253    else
2254        if test ! -r ${PKG_GROUPS} ; then
2255            echo "Error:  can't read package groups info from PKG_GROUPS=\"$PKG_GROUPS\""
2256            exit 1
2257        fi
2258        echo "  getting package groups info from      $PKG_GROUPS"
2259  fi  fi
 . ./.pd_tmp  
 rm -f ./.pd_tmp  
2260    
2261  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"  #  Search for packages to compile.
2262  #  file should eventually be added so that, for convenience, one can  echo "  checking list of packages to compile:"
2263  #  specify groups of packages using names like "ocean" and "atmosphere".  PKG_LIST=
2264  echo "  checking default package list:  "  if test "x${PKG_LIST}" = x ; then
 if test "x${PDEFAULT}" = x ; then  
2265      for i in "." $MODS ; do      for i in "." $MODS ; do
2266          if test -r $i"/packages.conf" ; then          if test -r $i"/packages.conf" ; then
2267                  PDEFAULT=$i"/packages.conf"                  PKG_LIST=$i"/packages.conf"
2268                  break                  break
2269          fi          fi
2270      done      done
2271  fi  fi
2272  if test "x${PDEFAULT}" = x ; then  if test "x${PKG_LIST}" = x ; then
2273      PDEFAULT="$ROOTDIR/pkg/pkg_default"      pkg_list='default_pkg_list'
2274  fi      if test "x${PKG_GROUPS}" = x ; then
2275  if test "x${PDEFAULT}" = xNONE ; then          echo "Error:  need package groups info to expand pkg_list=\"$pkg_list\""
2276      echo "    default packages file disabled"          exit 1
2277        fi
2278  else  else
2279      if test ! -r $PDEFAULT ; then      if test ! -r $PKG_LIST ; then
2280          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""          echo "Error:  can't read package list from PKG_LIST=\"$PKG_LIST\""
2281            exit 1
2282      else      else
2283          echo "    using PDEFAULT=\"$PDEFAULT\""          echo "    using PKG_LIST=\"$PKG_LIST\""
2284          #  Strip the comments and add all the names          #  Strip the comments and add all the names
2285          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}'`
2286          RETVAL=$?          RETVAL=$?
2287          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
2288              printf "Error: can't parse default package list "              printf "Error: can't parse package list "
2289              echo "-- please check PDEFAULT=\"$PDEFAULT\""              echo "-- please check PKG_LIST=\"$PKG_LIST\""
2290              exit 1              exit 1
2291          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"  
2292      fi      fi
2293  fi  fi
2294    for i in $pkg_list ; do
2295        PACKAGES="$PACKAGES $i"
2296    done
2297    echo     "    before group expansion packages are:$PACKAGES"
2298    if test "x${PKG_GROUPS}" != x ; then
2299        RET=1
2300        while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
2301        echo "    after group expansion packages are: $PACKAGES"
2302    fi
2303    
2304  echo "  applying DISABLE settings"  echo "  applying DISABLE settings"
2305    echo "" > $TMP.pack
2306  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2307      echo $i >> ./.tmp_pack      echo $i >> $TMP.pack
2308  done  done
2309  for i in `grep  "-" ./.tmp_pack` ; do  for i in `grep  "-" $TMP.pack` ; do
2310      j=`echo $i | sed 's/[-]//'`      j=`echo $i | sed 's/[-]//'`
2311      DISABLE="$DISABLE $j"      DISABLE="$DISABLE $j"
2312  done  done
# Line 1868  for p in $PACKAGES ; do Line 2324  for p in $PACKAGES ; do
2324  done  done
2325  PACKAGES="$pack"  PACKAGES="$pack"
2326  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
2327  echo "" > ./.tmp_pack  echo "" > $TMP.pack
2328  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
2329  # Test if each explicitly referenced package exists  # Test if each explicitly referenced package exists
2330  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2331      j=`echo $i | sed 's/[-+]//'`      j=`echo $i | sed 's/[-+]//'`
2332      if test ! -d "$ROOTDIR/pkg/$j" ; then      if test ! -d "$ROOTDIR/pkg/$j" ; then
2333          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""          echo "Error: dir '$ROOTDIR/pkg/$i' missing for package '$i'"
2334          exit 1          exit 1
2335      fi      fi
2336      echo $i >> ./.tmp_pack      echo $i >> $TMP.pack
2337  done  done
2338  PACKAGES=  PACKAGES=
2339  for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do  for i in `grep -v "-" $TMP.pack | sort | uniq` ; do
2340      PACKAGES="$PACKAGES $i"      PACKAGES="$PACKAGES $i"
2341  done  done
2342  rm -f ./.tmp_pack  rm -f $TMP.pack
2343  echo "    packages are:  $PACKAGES"  echo "    packages are: $PACKAGES"
2344    
2345  #  Check availability of NetCDF and then either build the MNC template  #  Check for package MNC: if NetCDF is available, then build the MNC
2346  #  files or delete mnc from the list of available packages.  #  template files ; otherwise, delete mnc from the list of packages.
2347  echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1  echo " $PACKAGES " | grep ' mnc ' > /dev/null 2>&1
2348  RETVAL=$?  mnc_in=$?
2349  if test "x$RETVAL" = x0 ; then  if test "x$HAVE_NETCDF" != xt ; then
2350      if test "x$HAVE_NETCDF" != xt ; then      if test "x$mnc_in" = x0 ; then
2351          cat <<EOF          cat <<EOF
   
2352  *********************************************************************  *********************************************************************
2353  WARNING: the "mnc" package was enabled but tests failed to compile  WARNING: the "mnc" package was enabled but tests failed to compile
2354    NetCDF applications.  Please check that:    NetCDF applications.  Please check that:
2355    
2356    1) NetCDF is correctly installed for this compiler and    1) NetCDF is correctly installed for this compiler and
2357    2) the LIBS variable (within the "optfile") specifies the correct    2) the LIBS variable (within the "optfile") specifies the correct
2358         NetCDF library to link against.         NetCDF library to link against.
2359    
2360    Due to this failure, the "mnc" package is now DISABLED.    Due to this failure, the "mnc" package is now DISABLED.
2361  *********************************************************************  *********************************************************************
   
2362  EOF  EOF
2363          PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`          PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
2364          DISABLE="$DISABLE mnc"          DISABLE="$DISABLE mnc"
2365      else      else
2366          ( 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
2367          RETVAL=$?          DISABLE="$DISABLE mnc"
2368          if test "x${RETVAL}" = x0 ; then      fi
2369              rm -f make_mnc.errors  else
2370          else      # we have NetCDF, we try to build MNC template files
2371              echo "Error: problem encountered while building source files in pkg/mnc:"      ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
2372              cat make_mnc.errors 1>&2      RETVAL=$?
2373        if test "x${RETVAL}" = x0 ; then
2374            rm -f make_mnc.errors
2375        else
2376            echo "Error: problem encountered while building source files in pkg/mnc:"
2377            cat make_mnc.errors 1>&2
2378            if test "x$mnc_in" = x0 ; then
2379              exit 1              exit 1
2380            else
2381                DISABLE="$DISABLE mnc"
2382          fi          fi
2383      fi      fi
2384  fi  fi
2385    
2386  echo "  applying package dependency rules"  #  Check for package PROFILES: if NetCDF is not available,
2387  ck=  #  then delete profiles from the list of available packages.
2388  while test "x$ck" != xtt ; do  if test "x$HAVE_NETCDF" != xt ; then
2389        echo " $PACKAGES " | grep ' profiles ' > /dev/null 2>&1
2390        RETVAL=$?
2391        if test "x$RETVAL" = x0 ; then
2392            cat <<EOF
2393    *********************************************************************
2394    WARNING: the "profiles" package was enabled but tests failed to
2395      compile NetCDF applications.  Please check that:
2396    
2397      1) NetCDF is correctly installed for this compiler and
2398      2) the LIBS variable (within the "optfile") specifies the correct
2399           NetCDF library to link against.
2400    
2401      Due to this failure, the "profiles" package is now DISABLED.
2402    *********************************************************************
2403    EOF
2404            PACKAGES=`echo $PACKAGES | sed -e 's/profiles//g'`
2405            DISABLE="$DISABLE profiles"
2406        else
2407        #  this prevent to add profiles (due to pdepend rules) if not available
2408            DISABLE="$DISABLE profiles"
2409        fi
2410    fi
2411    
2412    #  Make sure the openad package is enabled if using OpenAD
2413    if test "x$OPENAD" != x ; then
2414        echo " $PACKAGES " | grep ' openad ' > /dev/null 2>&1
2415        RETVAL=$?
2416        if test "x$RETVAL" != x0 ; then
2417            cat <<EOF
2418    
2419    *********************************************************************
2420    ERROR: when generating an adjoint with OpenAD, the openad package
2421      must be enabled.  Please add it to packages.conf.
2422    *********************************************************************
2423    
2424    EOF
2425            exit 1
2426        fi
2427    fi
2428    
2429    if  test "x${PKG_DEPEND}" != x ; then
2430      echo "  applying package dependency rules"
2431      ck=
2432      while test "x$ck" != xtt ; do
2433      i=0      i=0
2434      # rtot=${#PNAME[@]}      # rtot=${#PNAME[@]}
2435      rtot=$nname      rtot=$nname
2436      while test $i -lt $rtot ; do      while test $i -le $rtot ; do
2437    
2438          #  Is $pname in the current $PACKAGES list?          #  Is $pname in the current $PACKAGES list?
2439          #  pname=${PNAME[$i]}          #  pname=${PNAME[$i]}
# Line 1939  while test "x$ck" != xtt ; do Line 2445  while test "x$ck" != xtt ; do
2445                  pin="t"                  pin="t"
2446              fi              fi
2447          done          done
2448            #  or in the current $STANDARDDIRS list?
2449            for p in $STANDARDDIRS ; do
2450                if test "x$p" = "x$pname" ; then pin="t" ; fi
2451            done
2452    
2453          #  Is the DNAME entry a (+) or (-) rule ?          #  Is the DNAME entry a (=), (+) or (-) rule ?
2454          tmp="dname=\"\$DNAME_$i\""          tmp="dname=\"\$DNAME_$i\""
2455          eval $tmp          eval $tmp
2456          plus="-"          plus="a"
2457          echo $dname | grep '^+' > /dev/null 2>&1          echo $dname | grep '^+' > /dev/null 2>&1
2458          RETVAL=$?          RETVAL=$?
2459          if test "x$RETVAL" = x0 ; then          if test "x$RETVAL" = x0 ; then plus="+" ; fi
2460              plus="+"          echo $dname | grep '^-' > /dev/null 2>&1
2461          fi          RETVAL=$?
2462            if test "x$RETVAL" = x0 ; then plus="-" ; fi
2463    
2464          #  Is $dname in the current $PACKAGES list?          #  Is $dname in the current $PACKAGES list?
2465          dname=`echo $dname | sed -e 's/^[+-]//'`          dname=`echo $dname | sed -e 's/^[=+-]//'`
2466          din="f"          din="f"
2467          for p in $PACKAGES ; do          for p in $PACKAGES ; do
2468              if test "x$p" = "x$dname" ; then              if test "x$p" = "x$dname" ; then
# Line 1960  while test "x$ck" != xtt ; do Line 2471  while test "x$ck" != xtt ; do
2471          done          done
2472    
2473          #  Do we need to add $dname according to the dependency rules?          #  Do we need to add $dname according to the dependency rules?
2474          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
2475                #echo "   " $pname ": need to add :" $dname
2476              in_dis="f"              in_dis="f"
2477              for dis in $DISABLE ; do              for dis in $DISABLE ; do
2478                  if test "x$dis" = "x$dname" ; then                  if test "x$dis" = "x$dname" ; then
# Line 1968  while test "x$ck" != xtt ; do Line 2480  while test "x$ck" != xtt ; do
2480                  fi                  fi
2481              done              done
2482              if test "x$in_dis" = xt ; then              if test "x$in_dis" = xt ; then
2483                  echo "Error: can't satisfy package dependencies:"                  if test "x$plus" = "x+" ; then
2484                  echo "  \"$dname\" is required by the dependency rules"                      echo "Error: can't satisfy package dependencies:"
2485                  echo "  but is disallowed by the DISABLE settings"                      echo "  \"$dname\" is required with pkg \"$pname\" (dependency rules)"
2486                  exit 1                      echo "  but is disallowed by the DISABLE settings"
2487                        exit 1
2488                    elif test "x$ck" = xt ; then
2489                    #- (=) is a weaker dependency rule: warning but no stop
2490                        echo    "Warning: pkg \"$dname\" is set DISABLE (from: \"$PKG_LIST\")"
2491                        echo -n "     but is recommended with pkg \"$pname\" (dependency rules)"
2492                        echo " <- ignores recommendation"
2493                    fi
2494              else              else
2495                  PACKAGES="$PACKAGES $dname"                  PACKAGES="$PACKAGES $dname"
2496                  ck=                  ck=
# Line 1981  while test "x$ck" != xtt ; do Line 2500  while test "x$ck" != xtt ; do
2500          #  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?
2501          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
2502              echo "Error: can't satisfy package dependencies:"              echo "Error: can't satisfy package dependencies:"
2503              echo "  \"$pname\" was requested but is disallowed by"              echo "  \"$dname\" was requested but is disallowed by"
2504              echo "  the dependency rules for \"$dname\""              echo "  the dependency rules for \"$pname\""
2505              exit 1              exit 1
2506          fi          fi
2507          i=`echo "$i + 1" | bc -l`          i=`expr $i + 1`
2508          #i=$(( $i + 1 ))          #i=`echo "$i + 1" | bc -l`
2509      done      done
2510      ck=$ck"t"      ck=$ck"t"
2511  done    done
2512  echo "    packages are:  $PACKAGES"    echo "    packages are: $PACKAGES"
2513    fi
2514  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2515      adr="$ROOTDIR/pkg/$i"      adr="$ROOTDIR/pkg/$i"
2516        adrmk='$(ROOTDIR)'"/pkg/$i"
2517      if test -d $adr ; then      if test -d $adr ; then
2518          SOURCEDIRS="$SOURCEDIRS $adr"          SOURCEDIRS="$SOURCEDIRS $adr"
2519          INCLUDEDIRS="$INCLUDEDIRS $adr"          INCLUDEDIRS="$INCLUDEDIRS $adr"
2520            SOURCEDIRSMK="$SOURCEDIRSMK $adrmk"
2521            INCLUDEDIRSMK="$INCLUDEDIRSMK $adrmk"
2522          if test "x$i" = xautodiff ; then          if test "x$i" = xautodiff ; then
2523              AUTODIFF_PKG_USED=t              AUTODIFF_PKG_USED=t
2524          fi          fi
# Line 2007  done Line 2530  done
2530    
2531  # Create a list of #define and #undef to enable/disable packages  # Create a list of #define and #undef to enable/disable packages
2532  PACKAGES_DOT_H=PACKAGES_CONFIG.h  PACKAGES_DOT_H=PACKAGES_CONFIG.h
2533  #  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
2534  #  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
2535  #  file would eventually be split up so that all package-related #define  #  file would eventually be split up so that all package-related #define
2536  #  statements could be separated and handled only by genmake.  #  statements could be separated and handled only by genmake.
2537  names=`ls -1 "$ROOTDIR/pkg"`  names=`ls -1 "$ROOTDIR/pkg"`
# Line 2025  for n in $names ; do Line 2548  for n in $names ; do
2548          done          done
2549          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
2550              undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`              undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2551              DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"              DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
2552          fi          fi
2553      fi      fi
2554  done  done
# Line 2036  for i in $PACKAGES ; do Line 2559  for i in $PACKAGES ; do
2559  #eh3 DEFINES="$DEFINES -D$def"  #eh3 DEFINES="$DEFINES -D$def"
2560    
2561  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
2562      case $i in      case $i in
2563          aim_v23)          aim_v23)
2564              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
2565              echo "Warning: ALLOW_AIM is set to enable aim_v23."              echo "Warning: ALLOW_AIM is set to enable aim_v23."
2566              ;;              ;;
2567      esac      esac
# Line 2046  for i in $PACKAGES ; do Line 2569  for i in $PACKAGES ; do
2569    
2570  done  done
2571    
2572  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS='$STANDARDDIRS'"
2573  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
 if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then  
     STANDARDDIRS="eesupp model"  
 fi  
2574  if test "x$STANDARDDIRS" != x ; then  if test "x$STANDARDDIRS" != x ; then
2575      for d in $STANDARDDIRS ; do      for d in $STANDARDDIRS ; do
2576          adr="$ROOTDIR/$d/src"          adr="$ROOTDIR/$d/src"
2577            adrmk='$(ROOTDIR)/'"$d/src"
2578          if test ! -d $adr ; then          if test ! -d $adr ; then
2579              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
2580              echo "  is correct and that you correctly specified the STANDARDDIRS option"              echo "  is correct and that you correctly specified the STANDARDDIRS option"
2581              exit 1              exit 1
2582          else          else
2583              SOURCEDIRS="$SOURCEDIRS $adr"              SOURCEDIRS="$SOURCEDIRS $adr"
2584                SOURCEDIRSMK="$SOURCEDIRSMK $adrmk"
2585          fi          fi
2586          adr="$ROOTDIR/$d/inc"          adr="$ROOTDIR/$d/inc"
2587            adrmk='$(ROOTDIR)/'"$d/inc"
2588          if test ! -d $adr ; then          if test ! -d $adr ; then
2589              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
2590              echo "  is correct and that you correctly specified the STANDARDDIRS option"              echo "  is correct and that you correctly specified the STANDARDDIRS option"
2591              exit 1              exit 1
2592          else          else
2593              INCLUDEDIRS="$INCLUDEDIRS $adr"              INCLUDEDIRS="$INCLUDEDIRS $adr"
2594                INCLUDEDIRSMK="$INCLUDEDIRSMK $adrmk"
2595          fi          fi
2596      done      done
2597  fi  fi
# Line 2083  for i in $spaths ; do Line 2607  for i in $spaths ; do
2607      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
2608          echo "    found CPP_OPTIONS=\"$try\""          echo "    found CPP_OPTIONS=\"$try\""
2609          CPP_OPTIONS="$try"          CPP_OPTIONS="$try"
2610          # 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
2611          for n in $names ; do          for n in $names ; do
2612              test_for_package_in_cpp_options $CPP_OPTIONS $n              test_for_package_in_cpp_options $CPP_OPTIONS $n
2613          done          done
2614      fi      fi
2615      try="$i/CPP_EEOPTIONS.h"      try="$i/CPP_EEOPTIONS.h"
2616      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
2617          echo "    found CPP_EEOPTIONS=\"$try\""          echo "    found CPP_EEOPTIONS=\"$try\""
2618          # 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
2619  #**** not yet enabled ****  #**** not yet enabled ****
2620  #        test_for_mpi_in_cpp_eeoptions $try  #        test_for_mpi_in_cpp_eeoptions $try
2621  #**** not yet enabled ****  #**** not yet enabled ****
# Line 2105  fi Line 2629  fi
2629    
2630  #  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
2631  #  compiler.  #  compiler.
2632  if test -f ./ad_files ; then  if test -f $TMP.adSrcFiles ; then
2633      rm -f ./ad_files      rm -f $TMP.adSrcFiles
2634  fi  fi
2635  echo "  Creating the list of files for the adjoint compiler."  echo "  Creating the list of files for the adjoint compiler."
2636    touch $TMP.adSrcFiles
2637  for i in $SOURCEDIRS ; do  for i in $SOURCEDIRS ; do
2638      list_files=`( cd $i && ls -1 *.list 2>/dev/null )`      list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
2639      for j in $list_files ; do      for j in $list_files ; do
2640          cat $i/$j >> ad_files          cat $i/$j >> $TMP.adSrcFiles
2641      done      done
2642  done  done
2643  if test ! "x"$FS = "x.f" ; then  if test ! "x"$FS = "x.f" ; then
2644      cat ad_files | sed -e "s/\.f/.$FS/g" > ad_files_f      cat $TMP.adSrcFiles | sed -e "s/\.f/.$FS/g" > $TMP.adSrcFiles_f
2645      mv -f ad_files_f ad_files      mv -f $TMP.adSrcFiles_f $TMP.adSrcFiles
2646  fi  fi
2647    
2648  echo  echo
# Line 2129  for i in $INCLUDEDIRS ; do Line 2654  for i in $INCLUDEDIRS ; do
2654      fi      fi
2655  done  done
2656    
2657  if test ! "x$DIVA" = x ; then  if test ! "x$DIVA" = x -a ! "x$MPI" = x ; then
2658      echo "  Creating the pseudo-MPI include directory"      if test ! "x$MPIINCLUDEDIR" = x ; then
2659      INCLUDES="-I./mpi_headers $INCLUDES"          #  Do a local copy of MPI headers files (in local dir ./mpi_headers/) after
2660      rm -rf ./mpi_headers          #   checking for additional included headers (in case of chain of included
2661      mkdir -p ./mpi_headers          #   header); also set LOCAL_MPI_HEADERS (if not already set)
2662            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  
2663      fi      fi
2664  fi  fi
2665    
2666  echo "  Determining the list of source and include files"  echo "  Determining the list of source and include files"
2667  rm -rf .links.tmp  rm -rf $TMP.links
2668  mkdir .links.tmp  mkdir $TMP.links
2669  touch .links.tmp/foo  touch $TMP.links/foo
2670  if test ! -r ".links.tmp/foo" ; then  if test ! -r "$TMP.links/foo" ; then
2671      echo      echo
2672      echo "ERROR : something is wrong with your directory permissions or"      echo "ERROR : something is wrong with your directory permissions or"
2673      echo "   your user file-creation mask (\"umask\") since creating a"      echo "   your user file-creation mask (\"umask\") since creating a"
# Line 2174  if test ! -r ".links.tmp/foo" ; then Line 2683  if test ! -r ".links.tmp/foo" ; then
2683      echo      echo
2684      exit 1      exit 1
2685  fi  fi
2686  rm -f .links.tmp/foo  rm -f $TMP.links/foo
2687  echo "# This section creates symbolic links" > srclinks.tmp  
2688  echo "" >> srclinks.tmp  if test "x$OPENAD" != x ; then
2689  printf 'SRCFILES = '    > srclist.inc      OAD_DONT_COMPILE="/dev/null"
2690  printf 'CSRCFILES = '   > csrclist.inc      OAD_DONT_TRANSFORM="/dev/null"
2691  printf 'F90SRCFILES = ' > f90srclist.inc      OAD_KEEP_ORIGINAL="/dev/null"
2692  printf 'HEADERFILES = ' > hlist.inc      OAD_CB2M_FILES="/dev/null"
2693  printf 'AD_FLOW_FILES = ' > ad_flow_files.inc      OADTOOLS="$TOOLSDIR/OAD_support"
2694        OADTOOLSMK='$(TOOLSDIR)/OAD_support'
2695        echo "  looking for dontCompile file:  "
2696        for i in "." $MODS $OADTOOLS ; do
2697            if test -r $i"/dontCompile" ; then
2698                OAD_DONT_COMPILE=$i"/dontCompile"
2699                echo "     found $OAD_DONT_COMPILE"
2700                break
2701            fi
2702        done
2703        echo "  looking for dontTransform file:  "
2704        for i in "." $MODS $OADTOOLS ; do
2705            if test -r $i"/dontTransform" ; then
2706                OAD_DONT_TRANSFORM=$i"/dontTransform"
2707                echo "     found $OAD_DONT_TRANSFORM"
2708                break
2709            fi
2710        done
2711        echo "  looking for keepOriginal file:  "
2712        for i in "." $MODS $OADTOOLS ; do
2713            if test -r $i"/keepOriginal" ; then
2714                OAD_KEEP_ORIGINAL=$i"/keepOriginal"
2715                echo "     found $OAD_KEEP_ORIGINAL"
2716                break
2717            fi
2718        done
2719        echo "  looking for cb2mFiles:  "
2720        for i in "." $MODS $OADTOOLS ; do
2721            if test -r $i"/cb2mFiles" ; then
2722                OAD_CB2M_FILES=$i"/cb2mFiles"
2723                echo "     found $OAD_CB2M_FILES"
2724                break
2725            fi
2726        done
2727        echo "   OpenAD exceptions:  "
2728    fi
2729    
2730    echo "# This section creates symbolic links" > $TMP.srclinks
2731    echo "" >> $TMP.srclinks
2732    printf 'F77_SRC_FILES = ' > $TMP.F77srclist
2733    printf 'NON_AD_F77_SRC_FILES = ' > $TMP.nonADF77srclist
2734    printf 'C_SRC_FILES = '   > $TMP.csrclist
2735    printf 'F90_SRC_FILES = ' > $TMP.F90srclist
2736    printf 'H_SRC_FILES = '   > $TMP.hsrclist
2737    printf 'AD_FLOW_FILES = ' > $TMP.ad_flow_files
2738  alldirs="$SOURCEDIRS $INCLUDEDIRS ."  alldirs="$SOURCEDIRS $INCLUDEDIRS ."
2739    alldirsmk=(${SOURCEDIRSMK} ${INCLUDEDIRSMK} ".")
2740    nd=0
2741  for d in $alldirs ; do  for d in $alldirs ; do
2742        dmk=${alldirsmk[${nd}]}
2743        nd=$((${nd}+1))
2744      deplist=      deplist=
2745      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
2746      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
2747        if test "x$OPENAD" != x ; then
2748            sfiles=`( echo $sfiles | grep -v _cb2m\. )`
2749        fi
2750      for sf in $sfiles ; do      for sf in $sfiles ; do
2751          if test ! -r ".links.tmp/$sf" ; then          if test ! -r "$TMP.links/$sf" ; then
2752              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
2753                  ignore_f=f                  ignore_f=f
2754                  case $d/$sf in                  case $d/$sf in
2755                    ./$PACKAGES_DOT_H)                    ./$PACKAGES_DOT_H)
2756                          ignore_f=t                          ignore_f=t
2757                          ;;                          ;;
2758                    ./AD_CONFIG.h)                    ./AD_CONFIG.h)
2759                          ignore_f=t                          ignore_f=t
2760                          ;;                          ;;
2761                    ./FC_NAMEMANGLE.h)                    ./FC_NAMEMANGLE.h)
2762                          ignore_f=t                          ignore_f=t
2763                          ;;                          ;;
2764                    ./BUILD_INFO.h)                    ./BUILD_INFO.h)
2765                          ignore_f=t                          ignore_f=t
2766                          ;;                          ;;
2767                    ./EMBEDDED_FILES.h)                    ./EMBEDDED_FILES.h)
2768                          ignore_f=t                          ignore_f=t
2769                          ;;                          ;;
2770                    *)                    *)
2771                          #  For the local directory *ONLY*,                          #  For the local directory *ONLY*,
2772                          #  ignore all soft-links                          #  ignore all soft-links
2773                          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
2774                              ignore_f=t                              ignore_f=t
2775                          else                          else
2776                              touch .links.tmp/$sf                              touch $TMP.links/$sf
2777                              deplist="$deplist $sf"                              deplist="$deplist $sf"
2778                          fi                          fi
2779                          ;;                          ;;
2780                  esac                  esac
2781                  if test "x$ignore_f" = xf ; then                  if test "x$ignore_f" = xf ; then
2782                      extn=`echo $sf | $AWK -F. '{print $NF}'`                      extn=`echo $sf | $AWK -F. '{print $NF}'`
2783                      case $extn in                      case $extn in
2784                          F)                        F)
2785                              echo    " \\"  >> srclist.inc                          echo    " \\"  >> $TMP.F77srclist
2786                              printf " $sf" >> srclist.inc                          printf " $sf" >> $TMP.F77srclist
2787                              ;;                          if test "x$OPENAD" = x ; then
2788                          F90)                              basename=${sf%%.F}
2789                              echo    " \\"  >> f90srclist.inc                              isAD=`egrep ^$basename.f'[  ]*' $TMP.adSrcFiles`
2790                              printf " $sf" >> f90srclist.inc                              if test -z "$isAD" ; then
2791                              ;;                                  echo    " \\"  >> $TMP.nonADF77srclist
2792                          c)                                  printf " $sf" >> $TMP.nonADF77srclist
2793                              echo    " \\"  >> csrclist.inc                              fi
2794                              printf " $sf" >> csrclist.inc                          else #- OpenAD case:
2795                              ;;                              basename=${sf%%.F}
2796                          h)                              isAD=`egrep ^$basename.f'[  ]*' $TMP.adSrcFiles`
2797                              echo    " \\"  >> hlist.inc                              if test -z "$isAD" ; then
2798                              printf " $sf" >> hlist.inc                                  toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE}`
2799                              ;;                                  if test -z "$toBeIgnored" ; then
2800                          flow)                                      echo    " \\"  >> $TMP.nonADF77srclist
2801                              echo    " \\"  >> ad_flow_files.inc                                      printf " $sf" >> $TMP.nonADF77srclist
2802                              printf " $sf" >> ad_flow_files.inc                                  else
2803                              ;;                                      echo "    not to be compiled   :  $sf"
2804                      esac                                  fi
2805                  fi                              else # file is initially listed as an AD file we want to exclude it
2806                                     # or we want to retain the untransformed version
2807                                    notToBeTransformed=`egrep ^$basename'[      ]*' ${OAD_DONT_TRANSFORM}`
2808                                    untransformedVersionToBeKept=`egrep ^$basename'[      ]*' ${OAD_KEEP_ORIGINAL}`
2809                                    if test -n "$notToBeTransformed"; then
2810                                        echo "    not to be transformed:  $sf"
2811                                    fi
2812                                    if test -n "$untransformedVersionToBeKept" ; then
2813                                        echo "    original to be kept  :  $sf"
2814                                    fi
2815                                    if test -n "$notToBeTransformed" -o -n "$untransformedVersionToBeKept" ; then
2816                                        echo    " \\"  >> $TMP.nonADF77srclist
2817                                        printf " $sf" >> $TMP.nonADF77srclist
2818                                    fi
2819                                fi
2820                            fi
2821                            ;;
2822                        F90)
2823                            echo    " \\"  >> $TMP.F90srclist
2824                            printf " $sf" >> $TMP.F90srclist
2825                            ;;
2826                        c)
2827                            echo    " \\"  >> $TMP.csrclist
2828                            printf " $sf" >> $TMP.csrclist
2829                            ;;
2830                        h)
2831                            echo    " \\"  >> $TMP.hsrclist
2832                            printf " $sf" >> $TMP.hsrclist
2833                            ;;
2834                        flow)
2835                            echo    " \\"  >> $TMP.ad_flow_files
2836                            printf " $sf" >> $TMP.ad_flow_files
2837                            ;;
2838                       esac
2839                    fi
2840              fi              fi
2841          fi          fi
2842      done      done
2843      if test "x$deplist" != x ; then      if test "x$deplist" != x ; then
2844          echo "" >> srclinks.tmp        if test "$d" != "." ; then
2845          echo "#  These files are linked from $d" >> srclinks.tmp          echo "" >> $TMP.srclinks
2846          echo "$deplist :" >> srclinks.tmp          echo "#  These files are linked from $dmk ( aka $d )" >> $TMP.srclinks
2847          printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp          echo "$deplist :" >> $TMP.srclinks
2848    # We need to make sure that the link isn't already there.
2849    # This may happen when make thinks that a header file has to be "remade"
2850    # because a module it depends on has changed.  In this case we do nothing.
2851            printf "\tif [ ! -L \$@ ]; then \$(LN) %s/\$@ \$@; fi\n" $dmk >> $TMP.srclinks
2852          fi
2853      fi      fi
2854  done  done
2855  rm -rf .links.tmp  rm -rf $TMP.links
2856  echo "" >> srclist.inc  echo "" >> $TMP.F77srclist
2857  echo "" >> csrclist.inc  echo "" >> $TMP.nonADF77srclist
2858  echo "" >> f90srclist.inc  echo "" >> $TMP.csrclist
2859  echo "" >> hlist.inc  echo "" >> $TMP.F90srclist
2860  echo "" >> ad_flow_files.inc  echo "" >> $TMP.hsrclist
2861    echo "" >> $TMP.ad_flow_files
2862    
2863    CMDLINE=$0
2864    for xx in "$@" ; do nw=`echo $xx | wc -w`
2865        if test $nw = '1' ; then CMDLINE="$CMDLINE $xx"
2866                            else CMDLINE="$CMDLINE '$xx'" ; fi
2867    done
2868    
2869  if test -f $MAKEFILE ; then  if test -f $MAKEFILE ; then
2870      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.old"
2871  fi  fi
2872  echo "  Writing makefile: $MAKEFILE"  echo "  Writing makefile: $MAKEFILE"
2873  echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE  echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
# Line 2269  echo "#    $MACHINE" >> $MAKEFILE Line 2875  echo "#    $MACHINE" >> $MAKEFILE
2875  echo "# This makefile was generated automatically on" >> $MAKEFILE  echo "# This makefile was generated automatically on" >> $MAKEFILE
2876  echo "#    $THISDATE" >> $MAKEFILE  echo "#    $THISDATE" >> $MAKEFILE
2877  echo "# by the command:" >> $MAKEFILE  echo "# by the command:" >> $MAKEFILE
2878  echo "#    $0 $G2ARGS" >> $MAKEFILE  echo "#    $CMDLINE"  >> $MAKEFILE
2879  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
2880  echo "#    ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE  echo "#    ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
2881    
# Line 2280  EXE_SVD=$EXECUTABLE"_svd" Line 2886  EXE_SVD=$EXECUTABLE"_svd"
2886  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2887  #  #
2888  # OPTFILE="$OPTFILE"  # OPTFILE="$OPTFILE"
2889  #  #
2890  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
2891  # SOURCEDIRS   : Directories containing the source (.F) files  # SOURCEDIRS   : Directories containing the source (.F) files
2892  # INCLUDEDIRS  : Directories containing the header-source (.h) files  # INCLUDEDIRS  : Directories containing the header-source (.h) files
# Line 2291  cat >>$MAKEFILE <<EOF Line 2897  cat >>$MAKEFILE <<EOF
2897  # INCLUDES     : Directories searched for header files  # INCLUDES     : Directories searched for header files
2898  # DEFINES      : Macro definitions for CPP  # DEFINES      : Macro definitions for CPP
2899  # MAKEDEPEND   : Dependency generator  # MAKEDEPEND   : Dependency generator
 # KPP          : Special preprocessor command (specific to platform)  
 # KFLAGS       : Flags for KPP  
2900  # FC           : Fortran compiler command  # FC           : Fortran compiler command
2901  # FFLAGS       : Configuration/debugging options for FC  # FFLAGS       : Configuration/debugging options for FC
2902  # FOPTIM       : Optimization options for FC  # FOPTIM       : Optimization options for FC
# Line 2300  cat >>$MAKEFILE <<EOF Line 2904  cat >>$MAKEFILE <<EOF
2904  # LIBS         : Library flags /or/ additional optimization/debugging flags  # LIBS         : Library flags /or/ additional optimization/debugging flags
2905    
2906  ROOTDIR     = ${ROOTDIR}  ROOTDIR     = ${ROOTDIR}
2907  BUILDDIR    = ${BUILDDIR}    BUILDDIR    = ${BUILDDIR}
2908  SOURCEDIRS  = ${SOURCEDIRS}  SOURCEDIRS  = ${SOURCEDIRSMK}
2909  INCLUDEDIRS = ${INCLUDEDIRS}  INCLUDEDIRS = ${INCLUDEDIRSMK}
2910  EXEDIR      = ${EXEDIR}  EXEDIR      = ${EXEDIR}
2911  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}
2912  TOOLSDIR    = ${TOOLSDIR}  TOOLSDIR    = ${TOOLSDIRMK}
2913    OADTOOLS    = ${OADTOOLSMK}
2914    
2915  #eh3  new defines for the adjoint work  #eh3  new defines for the adjoint work
2916  AUTODIFF    = ${ROOTDIR}/pkg/autodiff  AUTODIFF    = \$(ROOTDIR)/pkg/autodiff
2917  EXE_AD      = ${EXE_AD}  EXE_AD      = ${EXE_AD}
2918  EXE_FTL     = ${EXE_FTL}  EXE_FTL     = ${EXE_FTL}
2919  EXE_SVD     = ${EXE_SVD}  EXE_SVD     = ${EXE_SVD}
# Line 2326  else Line 2931  else
2931      echo "EMBEDDED_FILES = " >>$MAKEFILE      echo "EMBEDDED_FILES = " >>$MAKEFILE
2932  fi  fi
2933    
2934  #  Note: figure out some way to add Hyades JAM libraries here  # extract default cpp search path so we can pass it to makedepend
2935    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}'`
2936    
2937  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2938  # Unix ln (link)  # Unix ln (link)
2939  LN = ${LN}  LN = ${LN}
 # C preprocessor  
 CPP = cat \$< | ${S64} | ${CPP}  
2940  # Dependency generator  # Dependency generator
2941  MAKEDEPEND = ${MAKEDEPEND}  MAKEDEPEND = ${MAKEDEPEND}
2942  # Special preprocessor (KAP on DECs, FPP on Crays)  # Special preprocessor (KAP on DECs, FPP on Crays)
# Line 2349  LINK = ${LINK} ${LDADD} Line 2954  LINK = ${LINK} ${LDADD}
2954  DEFINES = ${DEFINES}  DEFINES = ${DEFINES}
2955  # Includes for CPP  # Includes for CPP
2956  INCLUDES = ${INCLUDES}  INCLUDES = ${INCLUDES}
2957    # default CPP includes for makedepend
2958    CPPINCLUDES = ${CPPINCLUDES}
2959  # Flags for KPP  # Flags for KPP
2960  KFLAGS1 = ${KFLAGS1}  KFLAGS1 = ${KFLAGS1}
2961  KFLAGS2 = ${KFLAGS2}  KFLAGS2 = ${KFLAGS2}
2962  # Optim./debug for FC  # Optim./debug for FC
2963  FFLAGS = ${FFLAGS}  FFLAGS = ${FFLAGS}
2964  FOPTIM = ${FOPTIM}  FOPTIM = ${FOPTIM} ${FEXTRAFLAGS}
2965  # Optim./debug for FC  # Optim./debug for FC
2966  F90FLAGS = ${F90FLAGS}  F90FLAGS = ${F90FLAGS}
2967  F90OPTIM = ${F90OPTIM}  F90OPTIM = ${F90OPTIM}
2968    F90FIXEDFORMAT = ${F90FIXEDFORMAT}
2969  # Flags for CC  # Flags for CC
2970  CFLAGS = ${CFLAGS}  CFLAGS = ${CFLAGS}
2971  # Files that should not be optimized  # Files that should not be optimized
# Line 2365  NOOPTFILES = ${NOOPTFILES} Line 2973  NOOPTFILES = ${NOOPTFILES}
2973  NOOPTFLAGS = ${NOOPTFLAGS}  NOOPTFLAGS = ${NOOPTFLAGS}
2974  # Flags and libraries needed for linking  # Flags and libraries needed for linking
2975  LIBS = ${LIBS}  LIBS = ${LIBS}
2976  # Name of the Mekfile  # Name of the makefile
2977  MAKEFILE=${MAKEFILE}  MAKEFILE = ${MAKEFILE}
2978    # Name of the make program
2979    MAKE = ${MAKE}
2980    
2981  EOF  EOF
2982    
2983  cat srclist.inc       >> $MAKEFILE  cat $TMP.F77srclist      >> $MAKEFILE
2984  cat csrclist.inc      >> $MAKEFILE  cat $TMP.nonADF77srclist >> $MAKEFILE
2985  cat f90srclist.inc    >> $MAKEFILE  cat $TMP.csrclist        >> $MAKEFILE
2986  cat hlist.inc         >> $MAKEFILE  cat $TMP.F90srclist      >> $MAKEFILE
2987  cat ad_flow_files.inc >> $MAKEFILE  cat $TMP.hsrclist        >> $MAKEFILE
2988    cat $TMP.ad_flow_files   >> $MAKEFILE
2989    
2990    rm -f $TMP.F77srclist $TMP.nonADF77srclist $TMP.csrclist $TMP.F90srclist $TMP.hsrclist $TMP.ad_flow_files
2991    
2992  echo >> $MAKEFILE  echo >> $MAKEFILE
2993  echo 'F77FILES =  $(SRCFILES:.F=.'$FS')'      >> $MAKEFILE  
2994  echo 'F90FILES =  $(F90SRCFILES:.F90=.'$FS90')' >> $MAKEFILE  # add definitions for preprocessed sources
2995  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE  # and note that not all systems allow case sensitive extensions
2996    # hence the $FS and $FS90 here.
2997    # for fixed format f90 files we use ff90 or FF90 resp
2998    # but these are not expected to be the original source files
2999    
3000    echo 'F77_PP_SRC_FILES = $(F77_SRC_FILES:.F=.'$FS')'      >> $MAKEFILE
3001    echo 'F90_PP_SRC_FILES = $(F90_SRC_FILES:.F90=.'$FS90')' >> $MAKEFILE
3002    echo 'OBJFILES= $(F77_SRC_FILES:.F=.o) $(C_SRC_FILES:.c=.o) $(F90_SRC_FILES:.F90=.o)' >> $MAKEFILE
3003    echo 'FLOWFILES =  $(AD_FLOW_FILES:.flow=.flowdir)' >> $MAKEFILE
3004  echo >> $MAKEFILE  echo >> $MAKEFILE
3005  echo '.SUFFIXES:' >> $MAKEFILE  echo '.SUFFIXES:' >> $MAKEFILE
3006  echo '.SUFFIXES: .o .'$FS' .p .F .c .'$FS90' .F90' >> $MAKEFILE  echo '.SUFFIXES: .o .'$FS' .p .F .c .f'$FS90' .'$FS90' .FF90 .F90 .flowdir .flow' >> $MAKEFILE
 rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc  
 rm -f ad_flow_files.inc  
3007    
3008  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
3009    
3010  all: \$(EXECUTABLE)  all: fwd_exe_target
3011  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(OBJFILES) \$(EMBEDDED_FILES)  fwd_exe_target:
3012            @echo Update AD_CONFIG.h and make \$(EXECUTABLE)
3013            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Forward version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3014            @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3015            @-rm -f ad_config.template
3016            \$(MAKE) -f \$(MAKEFILE) \$(EXECUTABLE)
3017    
3018    \$(EXECUTABLE): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(OBJFILES) \$(EMBEDDED_FILES)
3019          @echo Creating \$@ ...          @echo Creating \$@ ...
3020          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
3021    
3022  depend:  depend:
3023          @make links          @\$(MAKE) -f \$(MAKEFILE) links
3024          \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(CPPINCLUDES) \$(F77_SRC_FILES)
3025          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
3026          -rm -f makedepend.out          -rm -f makedepend.out
3027    
3028  lib: libmitgcmuv.a  lib: libmitgcmuv.a
3029    
3030  libmitgcmuv.a: \$(OBJFILES)  libmitgcmuv.a: \$(SPECIAL_FILES) \$(OBJFILES)
3031          ar rcv libmitgcmuv.a \$(OBJFILES)          ar rcv libmitgcmuv.a \$(OBJFILES)
3032            ar d   libmitgcmuv.a main.o
3033    
3034  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES)  obj: \$(OBJFILES)
3035    
3036  small_f: \$(F77FILES) \$(F90FILES)  links: \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(SPECIAL_FILES)
3037    
3038  output.txt: \$(EXECUTABLE)  small_f: \$(F77_PP_SRC_FILES) \$(F90_PP_SRC_FILES)
         @printf 'running ... '  
         @\$(EXECUTABLE) > \$@  
3039    
3040    # remove most of the files that "make" generates
3041  clean:  clean:
3042          -rm -rf *.o *.$FS *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template          -rm -rf *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
3043            -rm -rf *.o
3044            -rm -rf *.$FS *.flowdir
3045            -rm -rf *.f$FS90 \$(AD_CLEAN) ad_input*
3046    
3047    # remove most of the files that "make" and "make depend" generate
3048  Clean:  Clean:
3049          @make clean          @\$(MAKE) -f \$(MAKEFILE) clean
3050          @make cleanlinks          @\$(MAKE) -f \$(MAKEFILE) cleanlinks
3051          -rm -f \$(SPECIAL_FILES)          -rm -f \$(SPECIAL_FILES) f90mkdepend.log $MAKEFILE.old
3052          -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak          -rm -f taf_command taf_output taf_ad.log taf_ad_flow.log taf_ftl.log
3053    
3054    # remove also the executable, files that "genmake2" generates (except Makefile)
3055    #         and output from a run (plus log files from testreport)
3056  CLEAN:  CLEAN:
3057          @make Clean          @\$(MAKE) -f \$(MAKEFILE) Clean
3058            -rm -f \$(EXECUTABLE) \$(EXE_AD) \$(EXE_FTL) *.bak
3059            -rm -f $LOGFILE genmake_state genmake_*optfile
3060            -rm -f SIZE.h.mpi genmake.tr_log make.tr_log
3061            -rm -rf mpi_headers mnc_test_*
3062          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
3063          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
3064          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
3065          -rm -f \$(EXECUTABLE) *.txt STD* *diagnostics.log datetime          -rm -f *.txt STDOUT.* STDERR.* *diagnostics.log *.[0-9][0-9][0-9][0-9].log
3066          -rm -rf mnc_test_*          -rm -f datetime costfinal divided.ctrl snapshot* output_adm.txt.diva_*
3067            -rm -f *_MIT_CE_000.opt0000 costfunction*0000
3068            -rm -f oad_cp.[0-9][0-9][0-9].?????
3069    
 #eh3 Makefile: makefile  
3070  makefile:  makefile:
3071          $THIS_SCRIPT $G2ARGS          $THIS_SCRIPT $G2ARGS
3072  cleanlinks:  cleanlinks:
3073          -find . -type l -exec rm {} \;          -find . -type l -exec rm {} \;
3074    
3075  # Special targets (SPECIAL_FILES) which are create by make  # Special targets (SPECIAL_FILES) which are created by make
3076  ${PACKAGES_DOT_H}:  ${PACKAGES_DOT_H}:
3077          @echo Creating \$@ ...          @echo Creating \$@ ...
3078          @$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) > \$@
3079  AD_CONFIG.h:  AD_CONFIG.h:
3080          @echo Creating \$@ ...          @echo Creating \$@ ...
3081          @$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 > \$@
3082  FC_NAMEMANGLE.h:  FC_NAMEMANGLE.h:
3083          @echo Creating \$@ ...          @echo Creating \$@ ...
3084          echo "$FC_NAMEMANGLE" > \$@          echo "$FC_NAMEMANGLE" > \$@
# Line 2456  if test "x$EMBED_SRC" = xt ; then Line 3097  if test "x$EMBED_SRC" = xt ; then
3097    
3098  decode_files.o : EMBEDDED_FILES.h  decode_files.o : EMBEDDED_FILES.h
3099    
3100  ##  \$(F77FILES)  ##  \$(F77_PP_SRC_FILES)
3101  all_fF.tar.gz : \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(F77FILES) Makefile  all_fF.tar.gz : \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile
3102          @echo Creating \$@ ...          @echo Creating \$@ ...
3103          -tar -hcf all_fF.tar \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(F77FILES) 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
3104          -rm -f all_fF.tar.gz          -rm -f all_fF.tar.gz
3105          -gzip all_fF.tar          -gzip all_fF.tar
3106    
# Line 2477  cat >>$MAKEFILE <<EOF Line 3118  cat >>$MAKEFILE <<EOF
3118  ## This nullifies any default implicit rules concerning these two file types:  ## This nullifies any default implicit rules concerning these two file types:
3119  ## %.o : %.F  ## %.o : %.F
3120    
3121    # C preprocessing and replacing the _d in constants:
3122    CPPCMD = cat \$< | ${CPP} \$(DEFINES) \$(INCLUDES) | ${S64}
3123    
3124  .F.$FS:  .F.$FS:
3125          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPPCMD)  > \$@
3126  .$FS.o:  .$FS.o:
3127          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
3128    .F.o:
3129            \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
3130  .F90.$FS90:  .F90.$FS90:
3131          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPPCMD)  > \$@
3132    .FF90.f$FS90:
3133            \$(CPPCMD)  > \$@
3134  .$FS90.o:  .$FS90.o:
3135          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
3136    .f$FS90.o:
3137            cp \$< \$(basename  \$<).f90
3138            \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$(F90FIXEDFORMAT) \$(basename  \$<).f90
3139  .c.o:  .c.o:
3140          \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$<          \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$<
3141    .flow.flowdir:
3142            \$(CPPCMD) > \$@
3143    
3144  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
3145  .F.p:  .F.p:
3146          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPPCMD) > \$@
3147  .p.$FS:  .p.$FS:
3148          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
3149    
3150    EOF
3151    
3152  #=========================================  #=========================================
3153  #===  Automatic Differentiation Rules  ===  #===  Automatic Differentiation Rules  ===
3154    #===  for TAMC/TAF  ======================
3155    
3156    if test "x$OPENAD" = x ; then
3157    
3158    cat >>$MAKEFILE <<EOF
3159    
3160  TAMC           = ${TAMC}  TAMC           = ${TAMC}
3161  TAF            = ${TAF}  TAF            = ${TAF}
3162    
3163  TAF_EXTRA      = ${TAF_EXTRA}  TAF_EXTRA      = ${TAF_EXTRA}
3164  TAMC_EXTRA     = ${TAMC_EXTRA}  TAMC_EXTRA     = ${TAMC_EXTRA}
3165    LOCAL_MPI_HEADERS    = ${LOCAL_MPI_HEADERS}
3166    
3167  EOF  EOF
3168    
# Line 2510  ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF Line 3171  ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF
3171  ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"  ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
3172  for i in $ad_vars ; do  for i in $ad_vars ; do
3173      name=$i      name=$i
3174      t1="t2=\$"`echo $i`      t1="t2=\$"`echo "$i"`
3175      eval $t1      eval $t1
3176      printf "%-20s = " $name >> $MAKEFILE      printf "%-20s = " $name >> $MAKEFILE
3177      echo $t2 >> $MAKEFILE      echo "$t2" | sed -e 's| \+| |g' >> $MAKEFILE
3178  done  done
3179    
3180  echo "  Add the source list for AD code generation"  echo "  Add the source list for AD code generation"
3181  echo >> $MAKEFILE  echo >> $MAKEFILE
3182  printf "AD_FILES = " >> $MAKEFILE  printf "AD_FILES = " >> $MAKEFILE
3183  AD_FILES=`cat ad_files`  AD_FILES=`cat $TMP.adSrcFiles`
3184  for i in $AD_FILES ; do  for i in $AD_FILES ; do
3185      echo    " \\" >> $MAKEFILE      echo    " \\" >> $MAKEFILE
3186      printf " $i" >> $MAKEFILE      printf " $i" >> $MAKEFILE
3187  done  done
3188  echo >> $MAKEFILE  echo >> $MAKEFILE
3189  rm -f ad_files  rm -f $TMP.adSrcFiles
3190    
3191    if test $CAT_SRC_FOR_TAF = 0 ; then
3192    cat >>$MAKEFILE <<EOF
3193    
3194    # ... Utilities ...
3195    remove_comments:
3196            sed -i.bak -f \$(TOOLSDIR)/remove_comments_sed \$(AD_FILES)
3197            @-rm -f \$(AD_FILES:.$FS=.$FS.bak)
3198    adj_sed:
3199            sed -i.bak -f \$(TOOLSDIR)/adjoint_sed \$(AD_FILES:.$FS=_ad.$FS)
3200            @-rm -f \$(AD_FILES:.$FS=_ad.$FS.bak)
3201    ftl_sed:
3202            sed -i.bak -f \$(TOOLSDIR)/adjoint_sed \$(AD_FILES:.$FS=_tl.$FS)
3203            @-rm -f \$(AD_FILES:.$FS=_tl.$FS.bak)
3204    adobjfiles: \$(AD_FILES:.$FS=_ad.o)
3205    ftlobjfiles: \$(AD_FILES:.$FS=_tl.o)
3206    EOF
3207    fi
3208    
3209  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
3210    
3211  # ... AD ...  # ... AD ...
3212  adall: ad_taf  adall: ad_exe_target
3213  adtaf: ad_taf_output.$FS  adtaf: ad_taf_output.$FS
3214  adtamc: ad_tamc_output.$FS  adtamc: ad_tamc_output.$FS
3215    
3216  ad_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)  ad_exe_target:
3217          @$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)
3218            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3219            @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3220            @-rm -f ad_config.template
3221            \$(MAKE) -f \$(MAKEFILE) \$(EXE_AD)
3222    
3223    ad_input_code.$FS: \$(AD_FILES) \$(AD_FLOW_FILES)
3224            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3225          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
3226          -rm -f ad_config.template          @-rm -f ad_config.template
3227          @make \$(F77FILES)          @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3228          @make \$(AD_FLOW_FILES)          @\$(MAKE) -f \$(MAKEFILE) \$(FLOWFILES)
3229          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.$FS          cat \$(FLOWFILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ad_input_code.$FS
3230    
3231  ad_taf_output.$FS: ad_input_code.$FS  adtafonly:
3232          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
3233            ls -l ad_input_code_ad.$FS
3234          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
3235    
3236  adtafonly:  EOF
3237    
3238    if test $CAT_SRC_FOR_TAF = 1 ; then
3239    cat >>$MAKEFILE <<EOF
3240    # ... send 1 file to TAF ...
3241    ad_taf_output.$FS: ad_input_code.$FS
3242            @-rm -f ad_input_code_ad.$FS ; echo ''
3243          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
3244            ls -l ad_input_code_ad.$FS
3245          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
3246    
3247  ad_taf: 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)
3248          \$(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)
3249    
3250  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  
3251    
3252  ad_tamc: ad_tamc_output.o \$(OBJFILES)  EOF
3253          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)  
3254    else
3255    cat >>$MAKEFILE <<EOF
3256    # ... send multiple files to TAF ...
3257    ad_taf_output.$FS: \$(AD_FLOW_FILES) \$(AD_FILES)
3258            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3259            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3260            @-rm -f ad_config.template
3261            @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3262            @\$(MAKE) -f \$(MAKEFILE) \$(FLOWFILES)
3263            @-rm -f \$(AD_FILES:.$FS=_ad.$FS) \$(AD_FILES:.$FS=_ad.o); echo ''
3264            \$(MAKE) -f \$(MAKEFILE) remove_comments
3265            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) \$(FLOWFILES) \$(AD_FILES)
3266            \$(MAKE) -f \$(MAKEFILE) adj_sed
3267            cat \$(AD_FILES:.$FS=_ad.$FS) > ad_taf_output.$FS
3268    
3269    \$(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)
3270            \$(MAKE) -f \$(MAKEFILE) adobjfiles
3271            \$(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)
3272    
3273    adobj: ad_taf_output.$FS \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o)
3274            \$(MAKE) -f \$(MAKEFILE) adobjfiles
3275    
3276    EOF
3277    fi
3278    
3279    cat >>$MAKEFILE <<EOF
3280  adonlyfwd:  adonlyfwd:
3281          patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff          patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
3282    
3283  adtrick:  adtrick:
3284          patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff          patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
3285    
3286    ad_tamc_output.$FS: ad_input_code.$FS
3287            \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
3288            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS
3289    
3290    ad_tamc: ad_tamc_output.o \$(OBJFILES)
3291            \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
3292    
3293  # ... FTL ...  # ... FTL ...
3294  ftlall: ftl_taf  ftlall: ftl_exe_target
3295  ftltaf: ftl_taf_output.$FS  ftltaf: ftl_taf_output.$FS
3296  ftltamc: ftl_tamc_output.$FS  ftltamc: ftl_tamc_output.$FS
3297    
3298  ftl_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)  ftl_exe_target:
3299          @$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)
3300          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
3301          -rm -f ftl_config.template          @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3302          @make \$(F77FILES)          @-rm -f ad_config.template
3303          @make \$(AD_FLOW_FILES)          \$(MAKE) -f \$(MAKEFILE) \$(EXE_FTL)
         cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.$FS  
3304    
3305  ftl_taf_output.$FS: ftl_input_code.$FS  ftl_input_code.$FS: \$(AD_FILES)
3306          \$(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
3307          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS          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            cat \$(AD_FLOW_FILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ftl_input_code.$FS
3312    
3313  ftltafonly:  ftltafonly:
3314          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
3315          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS          ls -l ftl_input_code_tl.$FS
3316            cat ftl_input_code_tl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
3317    
3318    EOF
3319    
3320    if test $CAT_SRC_FOR_TAF = 1 ; then
3321    cat >>$MAKEFILE <<EOF
3322    # ... send 1 file to TAF ...
3323    ftl_taf_output.$FS: ftl_input_code.$FS
3324            @-rm -f ftl_input_code_tl.$FS ; echo ''
3325            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
3326            ls -l ftl_input_code_tl.$FS
3327            cat ftl_input_code_tl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
3328    
3329    \$(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)
3330            \$(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)
3331    
3332    EOF
3333    
3334    else
3335    cat >>$MAKEFILE <<EOF
3336    # ... send multiple files to TAF ...
3337    ftl_taf_output.$FS: \$(AD_FLOW_FILES) \$(AD_FILES)
3338            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
3339            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3340            @-rm -f ad_config.template
3341            @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3342            @\$(MAKE) -f \$(MAKEFILE) \$(AD_FLOW_FILES)
3343            @-rm -f \$(AD_FILES:.$FS=_tl.$FS) \$(AD_FILES:.$FS=_tl.o); echo ''
3344            \$(MAKE) -f \$(MAKEFILE) remove_comments
3345            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) \$(AD_FLOW_FILES) \$(AD_FILES)
3346            \$(MAKE) -f \$(MAKEFILE) ftl_sed
3347            cat \$(AD_FILES:.$FS=_tl.$FS) > ftl_taf_output.$FS
3348    
3349    \$(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)
3350            \$(MAKE) -f \$(MAKEFILE) ftlobjfiles
3351            \$(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)
3352    
3353  ftl_taf: ftl_taf_output.o \$(OBJFILES)  EOF
3354          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)  fi
3355    
3356    cat >>$MAKEFILE <<EOF
3357  ftl_tamc_output.$FS: ftl_input_code.$FS  ftl_tamc_output.$FS: ftl_input_code.$FS
3358          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
3359          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
3360    
3361  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
3362          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
   
3363    
3364  # ... SVD ...  # ... SVD ...
3365  svdtaf: ad_taf_output.$FS ftl_taf_output.$FS  svdtaf: ad_taf_output.$FS ftl_taf_output.$FS
# Line 2618  svd_touch: Line 3381  svd_touch:
3381          touch ad_taf_output.$FS ftl_taf_output.$FS          touch ad_taf_output.$FS ftl_taf_output.$FS
3382          \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS          \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS
3383          \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS          \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS
3384          @$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
3385          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
3386          -rm -f ftl_config.template          @-rm -f ad_config.template
3387    
3388  #=========================================  EOF
3389    
3390    fi
3391    
3392    #===  for OpenAD  ========================
3393    
3394    if test "x$OPENAD" != x ; then
3395    
3396    # ============ begin OpenAD specific section ==============
3397    
3398    cat >>$MAKEFILE <<EOF
3399    # ... OpenAD ...
3400    
3401    # all the source files linked from the various locations:
3402    ALL_LINKED_FILES= \
3403    \$(F77_SRC_FILES) \
3404    \$(C_SRC_FILES) \
3405    \$(H_SRC_FILES) \
3406    \$(F90_SRC_FILES) \
3407    \$(SPECIAL_FILES)
3408    
3409    ifndef OPENADROOT
3410      \$(error "Error:  environment variable OPENADROOT not defined!")
3411    endif
3412    
3413    ifndef XAIFSCHEMAROOT
3414      \$(error "Error:  environment variable XAIFSCHEMAROOT not defined!")
3415    endif
3416    
3417    ifndef XAIFBOOSTERROOT
3418      \$(error "Error:  environment variable XAIFBOOSTERROOT not defined!")
3419    endif
3420    
3421    EOF
3422    
3423    echo "  Add the source list for common block to module conversion "
3424    echo >> $MAKEFILE
3425    printf "CB2M_F90_SRC_NAMES = " >> $MAKEFILE
3426    for i in `cat ${OAD_CB2M_FILES}` ; do
3427      echo    " \\" >> $MAKEFILE
3428      printf " $i" >> $MAKEFILE
3429    done
3430    echo >> $MAKEFILE
3431    
3432    echo "  Add the source list for AD code generation"
3433    echo >> $MAKEFILE
3434    printf "AD_FILES = " >> $MAKEFILE
3435    for i in `cat ${OAD_CB2M_FILES}` ; do
3436      echo    " \\" >> $MAKEFILE
3437      printf " ${i}_mod.f$FS90" >> $MAKEFILE
3438    done
3439    AD_FILES=`cat $TMP.adSrcFiles`
3440    for i in $AD_FILES ; do
3441      basename=${i%%.f}
3442      toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE} ${OAD_DONT_TRANSFORM}`
3443      if test -z "$toBeIgnored" ; then
3444        echo    " \\" >> $MAKEFILE
3445        printf " $i" >> $MAKEFILE
3446      fi
3447    done
3448    echo >> $MAKEFILE
3449    rm -f $TMP.adSrcFiles
3450    
3451    cat >>$MAKEFILE <<EOF
3452    
3453    adAll: ad_exe_target
3454    .PHONY: adAll
3455    
3456    ad_exe_target:
3457            @echo Update AD_CONFIG.h and make \$(EXE_AD)
3458            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3459            @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3460            @-rm -f ad_config.template
3461            \$(MAKE) -f \$(MAKEFILE) \$(EXE_AD)
3462    
3463    CB2M_F90_PP_SRC_FILES=\$(addsuffix _mod.f$FS90, \$(CB2M_F90_SRC_NAMES))
3464    
3465    .PRECIOUS: \$(CB2M_F90_PP_SRC_FILES) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90)
3466    
3467    .PHONY: adDepend
3468    adDepend: \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) \$(addsuffix _mod.FF90, \$(CB2M_F90_SRC_NAMES)) \$(F77_SRC_FILES:.F=_cb2m.FF90)
3469            \$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)
3470            \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
3471            -rm -f makedepend.out
3472    
3473    OPENAD_SUPPORT_F90_SRC_FILES = \
3474    w2f__types.F90 \
3475    OAD_active.F90 \
3476    OAD_cp.F90 \
3477    OAD_rev.F90 \
3478    OAD_tape.F90 \
3479    OAD_regular_cp.F90 \
3480    revolve.F90
3481    
3482    OPENAD_SUPPORT_C_SRC_FILES = \
3483    iaddr.c \
3484    timeRatio.c
3485    
3486    f95_test_mods.f90: \$(OPENAD_SUPPORT_F90_SRC_FILES:F90=$FS90)
3487            cat \$^ > \$@
3488    
3489    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
3490            cat \$^ > \$@
3491    
3492    f95_test.out: f95_test_mods.f90 f95_test.f90
3493            f95 -fixed -w=unused -maxcontin=132 -c f95_test_mods.f90 > \$@ 2>&1
3494            f95 -fixed -w=unused -maxcontin=132 -c -fixed f95_test.f90 >> \$@ 2>&1
3495    
3496    CB2M_AD_FILES=\$(AD_FILES:.f=_cb2m.f$FS90)
3497    
3498    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)
3499    
3500    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)
3501    
3502    \$(EXE_AD): \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) postProcess.tag \$(AD_OBJ_FILES_S2)
3503            \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(AD_OBJ_FILES_S2) \$(LIBS)
3504    
3505    # create sources files modules from header files containing common blocks
3506    %_mod.FF90 : %.h \$(OADTOOLS)/cb2mGetModules.csh \$(OADTOOLS)/cb2mGetModules.awk
3507            \$(OADTOOLS)/cb2mGetModules.csh $< \$(OADTOOLS)/cb2mGetModules.awk
3508    
3509    # create new header files with USE statements for the new modules made above
3510    %_mod.h : %.h \$(OADTOOLS)/cb2mGetHeaders.csh \$(OADTOOLS)/cb2mGetHeaders.awk
3511            \$(OADTOOLS)/cb2mGetHeaders.csh $< \$(OADTOOLS)/cb2mGetHeaders.awk \$(CB2M_F90_SRC_NAMES)
3512    
3513    # change the include directives of everybody to refer to  the new header files with the USE statements
3514    %_cb2m.FF90 : %.F \$(OADTOOLS)/cb2mUseModules.bash
3515            \$(OADTOOLS)/cb2mUseModules.bash $< ${MPI}
3516    
3517    # makefile debug rule
3518    small_f: \$(CB2M_F90_PP_SRC_FILES)
3519    .PHONY: small_f
3520    
3521    ad_input_code.f$FS90:  \$(CB2M_AD_FILES)
3522            cat \$^ > \$@
3523    
3524    # canonicalizer
3525    ad_input_code_sf.pre.f90 : \$(CB2M_AD_FILES)
3526            \${OPENADFORTTK_BASE}/tools/SourceProcessing/preProcess.py --timing --r8 -H -S  -o \$@ \$^
3527    
3528    # replace stop statements (to avoid the implied unstructured control flow)  with print statements
3529    ad_input_code_sf.pre.s2p.f90 : ad_input_code_sf.pre.f90
3530            cat \$< | sed -f \$(OADTOOLS)/stop2print.sed > ad_input_code_sf.pre.s2p.f90
3531    
3532    # F -> WHIRL
3533    ad_input_code_sf.pre.s2p.B: ad_input_code_sf.pre.s2p.f90
3534            \${OPEN64ROOT}/crayf90/sgi/mfef90 -r8 -z -F ad_input_code_sf.pre.s2p.f90
3535    
3536    # WHIRL -> XAIF
3537    ad_input_code_sf.pre.s2p.xaif : ad_input_code_sf.pre.s2p.B
3538            \${OPENADFORTTK}/bin/whirl2xaif -s -n --debug 1 -o \$@ \$<
3539    
3540    # XAIF -> XAIF'
3541    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
3542            \${XAIFBOOSTERROOT}/xaifBooster/algorithms/BasicBlockPreaccumulationReverse/driver/oadDriver -f -t forward_step -i \$< -c \${XAIFSCHEMAROOT}/schema/examples/inlinable_intrinsics.xaif -o \$@ -I -r
3543    
3544    # XAIF' -> WHIRL'
3545    ad_input_code_sf.pre.s2p.xb.x2w.B : ad_input_code_sf.pre.s2p.xb.xaif
3546            \${OPENADFORTTK}/bin/xaif2whirl --debug 1 ad_input_code_sf.pre.s2p.B \$<
3547    
3548    # WHIRL' -> F'
3549    ad_input_code_sf.pre.s2p.xb.x2w.w2f.f$FS90: ad_input_code_sf.pre.s2p.xb.x2w.B
3550            \${OPEN64ROOT}/whirl2f/whirl2f -FLIST:ftn_file=\$@ -openad \$<
3551    
3552    # insert template directives
3553    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
3554            \$(OADTOOLS)/insertTemplateDir.bash \$< \$@
3555    
3556    PPEXTRAS=\$(notdir \$(wildcard \$(OADTOOLS)/ad_template.*.F)) ad_inline.F
3557    # postprocess F'
3558    postProcess.tag: ad_input_code_sf.pre.s2p.xb.x2w.w2f.td.f$FS90 \$(PPEXTRAS:.F=.f) | w2f__types.f90
3559            \${OPENADFORTTK_BASE}/tools/SourceProcessing/postProcess.py --progress --timing --infoUnitFile w2f__types.f90 --outputFormat=fixed --separateOutput --pathSuffix "" --filenameSuffix "_oad" -m r -i ad_inline.f \$<
3560            # the target is a placeholder to trigger a single execution of the rule
3561            touch \$@
3562    # put this so make knows about the postprocessing output
3563    OAD_intrinsics_oad.f \$(CB2M_AD_FILES:.f$FS90=_oad.f): postProcess.tag
3564    
3565    # link the XAIF schema files
3566    %.xsd:
3567            \$(LN) \${XAIFSCHEMAROOT}/schema/\$@ .
3568    
3569    # link the support files:
3570    \$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES) \$(PPEXTRAS):
3571            \$(LN) \$(OADTOOLS)/\$@ .
3572    
3573    AD_CLEAN += *_mod.h *_mod.F90 *.FF90 *.mod-whirl temp.sed oad_cp.* postProcess.tag
3574    
3575    # ============ end OpenAD specific section ==============
3576    
3577  EOF  EOF
3578    
3579    fi
3580    
3581    #=========================================
3582    
3583  if test "x$EXEHOOK" != x ; then  if test "x$EXEHOOK" != x ; then
3584      printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE      printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
3585  fi  fi
# Line 2652  for i in $NOOPTFILES ; do Line 3606  for i in $NOOPTFILES ; do
3606  done  done
3607    
3608  echo "  Add rules for links"  echo "  Add rules for links"
3609  cat srclinks.tmp >> $MAKEFILE  cat $TMP.srclinks >> $MAKEFILE
3610  rm -f srclinks.tmp  rm -f $TMP.srclinks
3611    
3612  echo "  Adding makedepend marker"  echo "  Adding makedepend marker"
3613  printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE  printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
# Line 2661  printf "\n\n# DO NOT DELETE\n" >> $MAKEF Line 3615  printf "\n\n# DO NOT DELETE\n" >> $MAKEF
3615  printf "\n===  Done  ===\n"  printf "\n===  Done  ===\n"
3616    
3617  # Create special header files  # Create special header files
3618  $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"
3619  if test ! -f $PACKAGES_DOT_H ; then  if test ! -f $PACKAGES_DOT_H ; then
3620      mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H      mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
3621  else  else
# Line 2675  else Line 3629  else
3629      fi      fi
3630  fi  fi
3631  if test ! -f AD_CONFIG.h ; then  if test ! -f AD_CONFIG.h ; then
3632      $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
3633  fi  fi
3634    
   
3635  #  Write the "state" for future records  #  Write the "state" for future records
3636  if test "x$DUMPSTATE" != xf ; then  if test "x$DUMPSTATE" = xt ; then
3637      printf "" > genmake_state      printf "" > genmake_state
3638      for i in $gm_state ; do      for i in $gm_state ; do
3639          t1="t2=\$$i"          t1="t2=\$$i"
3640          eval $t1          eval $t1
3641          echo "$i='$t2'" >> genmake_state          echo "$i='$t2'" | sed -e 's/  */ /g' >> genmake_state
3642      done      done
3643  fi  fi

Legend:
Removed from v.1.145  
changed lines
  Added in v.1.281

  ViewVC Help
Powered by ViewVC 1.1.22