/[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.14 by edhill, Tue Oct 21 15:29:20 2003 UTC revision 1.139 by ce107, Thu Dec 22 01:22:27 2005 UTC
# Line 1  Line 1 
1  #!/bin/bash  #! /usr/bin/env bash
2  #  #
3  # $Header$  # $Header$
4  #  #
# Line 13  Line 13 
13  test_for_package_in_cpp_options() {  test_for_package_in_cpp_options() {
14      cpp_options=$1      cpp_options=$1
15      pkg=$2      pkg=$2
16      grep -i "#define.*ALLOW_$pkg" $cpp_options > /dev/null 2>&1      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg" || exit 99
17      RETVAL=$?      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg" || exit 99
18      if test "x${RETVAL}" = x0 ; then      test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg" || exit 99
19          echo "Error: In $cpp_options there is an illegal line: #define ALLOW_$pkg"      test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg" || exit 99
20          exit 99  }
21      fi  
22      grep -i "#undef.*ALLOW_$pkg" $cpp_options > /dev/null 2>&1  # Search for particular CPP #cmds associated with MPI
23      RETVAL=$?  # usage: test_for_mpi_in_cpp_eeoptions CPP_file
24      if test "x${RETVAL}" = x0 ; then  test_for_mpi_in_cpp_eeoptions() {
25          echo "Error: In $cpp_options there is an illegal line: #undef ALLOW_$pkg"      cpp_options=$1
26          exit 99      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI" || exit 99
27      fi      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI" || exit 99
28      grep -i "#define.*DISABLE_$pkg" $cpp_options > /dev/null 2>&1      test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI" || exit 99
29        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI" || exit 99
30    }
31    
32    # Search for particular string in a file. Return 1 if detected, 0 if not
33    # usage: test_for_string_in_file file string
34    test_for_string_in_file() {
35        file=$1
36        strng=$2
37        grep -i "$strng" $file > /dev/null 2>&1
38      RETVAL=$?      RETVAL=$?
39      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
40          echo "Error: In $cpp_options there is an illegal line: #define DISABLE_$pkg"          printf "Error: In $file there is an illegal line: "
41          exit 99          grep -i "$strng" $file
42            return 1
43      fi      fi
44      grep -i "#undef.*DISABLE_$pkg" $cpp_options > /dev/null 2>&1      return 0
     RETVAL=$?  
     if test "x${RETVAL}" = x0 ; then  
         echo "Error: In $cpp_options there is an illegal line: #undef DISABLE_$pkg"  
         exit 99  
    fi  
45  }  }
46    
47  # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to  # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to
# Line 46  expand_pkg_groups() { Line 51  expand_pkg_groups() {
51      PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups"      PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups"
52      if test -r $PKG_GROUPS ; then      if test -r $PKG_GROUPS ; then
53          cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp          cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp
54          cat ./p1.tmp | awk '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp          cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp
55          matched=0          matched=0
56          for i in $PACKAGES ; do          for i in $PACKAGES ; do
57              line=`grep "^ *$i" ./p2.tmp`              line=`grep "^ *$i" ./p2.tmp`
58              RETVAL=$?              RETVAL=$?
59              if test "x$RETVAL" = x0 ; then              if test "x$RETVAL" = x0 ; then
60                  matched=1                  matched=1
61                  replace=`echo $line | awk '{ $1=""; $2=""; print $0 }'`                  replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`
62                  echo "    replacing \"$i\" with: $replace"                  echo "    replacing \"$i\" with: $replace"
63                  new_packages="$new_packages $replace"                  new_packages="$new_packages $replace"
64              else              else
# Line 62  expand_pkg_groups() { Line 67  expand_pkg_groups() {
67          done          done
68          PACKAGES=$new_packages          PACKAGES=$new_packages
69          rm -f ./p[1,2].tmp          rm -f ./p[1,2].tmp
70            return $matched
71      else      else
72          echo "Warning: can't read package groups definition file: $PKG_GROUPS"          echo "Warning: can't read package groups definition file: $PKG_GROUPS"
73      fi      fi
74  }  }
75    
76    #  Check for broken environments (eg. cygwin, MacOSX w/HFS+) that
77    #  cannot distinguish [*.F/*.F90] from [*.f/*.f90] files.
78    check_for_broken_Ff()  {
79        #  Do we have defaults for $FS and/or $FS90 ?
80        tfs=f
81        tfs9=f90
82        if test "x$FS" != x ; then
83            tfs="$FS"
84        fi
85        if test "x$FS90" != x ; then
86            tfs9="$FS90"
87        fi
88    
89        #  First check the ability to create a *.F/.f pair.
90        cat <<EOF >> genmake_hello.F
91          program hello
92          write(*,*) 'hi'
93          stop
94          end
95    EOF
96        cp genmake_hello.F "genmake_hello."$tfs > /dev/null 2>&1
97        RETVAL=$?
98        if test "x$RETVAL" != x0 ; then
99            if test "x$FS" = x ; then
100                FS='for'
101                FS90='fr9'
102                check_for_broken_Ff
103            else
104                cat <<EOF 2>&1
105    ERROR: Your file system cannot distinguish between *.F and *.f files
106      (fails the "cp" test) and this program cannot find a suitable
107      replacement extension.  Please try a different build environment or
108      contact the <MITgcm-support@mitgcm.org> list for help.
109    
110    EOF
111                exit -1
112            fi
113            return
114        fi
115        rm -f genmake_hello.*
116    
117        #  Check the ability of ${MAKE} and ${LN} to use the current set
118        #  of extensions.
119        cat <<EOF >> genmake_hello.F
120          program hello
121          write(*,*) 'hi'
122          stop
123          end
124    EOF
125        test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
126        cat <<EOF >> $MAKEFILE
127    .SUFFIXES:
128    .SUFFIXES: .$tfs .F
129    .F.$tfs:
130            $LN \$< \$@
131    EOF
132        $MAKE "genmake_hello."$tfs > /dev/null 2>&1
133        RETVAL=$?
134        if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then
135            if test "x$FS" = x ; then
136                FS='for'
137                FS90='fr9'
138                check_for_broken_Ff
139            else
140                cat <<EOF 2>&1
141    ERROR: Your file system cannot distinguish between *.F and *.f files
142      (fails the "make/ln" test) and this program cannot find a suitable
143      replacement extension.  Please try a different build environment or
144      contact the <MITgcm-support@mitgcm.org> list for help.
145    
146    EOF
147                exit -1
148                return
149            fi
150        fi
151        rm -f genmake_hello.* $MAKEFILE
152        test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
153    
154        #  If we make it here, use the extensions
155        FS=$tfs
156        FS90=$tfs9
157        return
158    }
159    
160    
161    look_for_makedepend()  {
162    
163        #  The "original" makedepend is part of the Imake system that is
164        #  most often distributed with XFree86 or with an XFree86 source
165        #  package.  As a result, many machines (eg. generic Linux) do not
166        #  have a system-default "makedepend" available.  For those
167        #  systems, we have two fall-back options:
168        #
169        #    1) a makedepend implementation shipped with the cyrus-imapd
170        #       package:  ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
171        #
172        #    2) a known-buggy xmakedpend shell script
173        #
174        #  So the choices are, in order:
175        #
176        #    1) use the user-specified program
177        #    2) use a system-wide default
178        #    3) locally build and use the cyrus implementation
179        #    4) fall back to the buggy local xmakedpend script
180        #
181        if test "x${MAKEDEPEND}" = x ; then
182            which makedepend > /dev/null 2>&1
183            RV0=$?
184            test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
185            #  echo 'MAKEFILE="'$MAKEFILE'"'
186            cat <<EOF >> $MAKEFILE
187    #   THIS IS A TEST MAKEFILE GENERATED BY "genmake2"
188    #
189    #   Some "makedepend" implementations will die if they cannot
190    #   find a Makefile -- so this file is here to gives them an
191    #   empty one to find and parse.
192    EOF
193            cat <<EOF >> genmake_tc.f
194          program test
195          write(*,*) 'test'
196          stop
197          end
198    EOF
199            makedepend genmake_tc.f > /dev/null 2>&1
200            RV1=$?
201            test -f $MAKEFILE  &&  rm -f $MAKEFILE
202            test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
203            if test "x${RV0}${RV1}" = x00 ; then
204                MAKEDEPEND=makedepend
205            else
206                echo "    a system-default makedepend was not found."
207                
208                #  Try to build the cyrus implementation
209                build_cyrus_makedepend
210                RETVAL=$?
211                if test "x$RETVAL" != x0 ; then
212                    MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
213                fi
214                rm -f ./genmake_cy_md
215            fi
216        else
217            #  echo "MAKEDEPEND=${MAKEDEPEND}"
218            echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1
219            RETVAL=$?
220            if test x"$RETVAL" = x0 ; then
221                build_cyrus_makedepend
222            fi
223        fi
224    }
225    
226    
227    build_cyrus_makedepend()  {
228        rm -f ./genmake_cy_md
229        (
230            cd $ROOTDIR/tools/cyrus-imapd-makedepend  \
231                &&  ./configure > /dev/null 2>&1  \
232                &&  make > /dev/null 2>&1
233            if test -x ./makedepend.exe ; then
234                $LN ./makedepend.exe ./makedepend
235            fi
236            ./makedepend ifparser.c > /dev/null 2>&1  \
237                &&  echo "true"
238        ) > ./genmake_cy_md
239        grep true ./genmake_cy_md > /dev/null 2>&1
240        RETVAL=$?
241        rm -f ./genmake_cy_md
242        if test "x$RETVAL" = x0 ; then
243            MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
244            return 0
245        else
246            echo "WARNING: unable to build cyrus-imapd-makedepend"
247            return 1
248        fi
249    }
250    
251  # Guess possible config options for this host  # Guess possible config options for this host
252  find_possible_configs()  {  find_possible_configs()  {
253    
254      tmp1=`uname`"_"`uname -m`      tmp1=`uname`"_"`uname -m`
255      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
256      PLATFORM=`echo $tmp2 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`      tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
257        tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
258        tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
259        tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
260        PLATFORM=$tmp3
261        echo $PLATFORM | grep cygwin > /dev/null 2>&1  &&  PLATFORM=cygwin_ia32
262      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
263      echo "  The platform appears to be:  $PLATFORM"      echo "  The platform appears to be:  $PLATFORM"
 #     if test "x$OFLIST" = x ; then  
 #       echo "  No pre-defined options files were found matching this platform"  
 #       echo "  but examples for other platforms can be found in:"  
 #       echo "    $ROOTDIR/tools/build_options"  
 #     else  
 #       echo "  Options files (located in $ROOTDIR/tools/build_options) that"  
 #       echo "  may work with this machine are:"  
 #       for i in $OFLIST ; do  
 #           echo "    $i"  
 #       done  
 #     fi  
264            
265      echo "test" > test      echo "test" > test
266      ln -s ./test link      ln -s ./test link
# Line 103  find_possible_configs()  { Line 278  find_possible_configs()  {
278          CPP="cpp -traditional -P"          CPP="cpp -traditional -P"
279      fi      fi
280    
281      # look for possible fortran compilers      look_for_makedepend
282      tmp="$MITGCM_FC $FC g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"  
283        #================================================================
284        #  look for possible C compilers
285        tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc"
286        p_CC=
287        for c in $tmp ; do
288            rm -f ./genmake_hello.c  ./genmake_hello
289            cat >> genmake_hello.c << EOF
290    #include <stdio.h>
291    int main(int argc, char **argv) {
292      printf("Hello!\n");
293      return 0;
294    }
295    EOF
296            $c -o genmake_hello genmake_hello.c > /dev/null 2>&1
297            RETVAL=$?
298            if test "x${RETVAL}" = x0 ; then
299                p_CC="$p_CC $c"
300            fi
301        done
302        rm -f ./genmake_hello.c ./genmake_hello
303        if test "x${p_CC}" = x ; then
304            cat 1>&2 <<EOF
305    
306    Error: No C compilers were found in your path.  Please specify one using:
307    
308        1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
309        2) the CC or MITGCM_CC environment variables.
310    
311    EOF
312            exit 1
313        else
314            echo "  The possible C compilers found in your path are:"
315            echo "   "$p_CC
316            if test "x$CC" = x ; then
317                CC=`echo $p_CC | $AWK '{print $1}'`
318                echo "  Setting C compiler to: "$CC
319            fi
320        fi
321    
322        #================================================================
323        #  look for possible FORTRAN compilers
324        tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 gfortran"
325      p_FC=      p_FC=
326      for c in $tmp ; do      for c in $tmp ; do
327          rm -f ./hello.f ./hello          rm -f ./hello.f ./hello
# Line 121  EOF Line 338  EOF
338              p_FC="$p_FC $c"              p_FC="$p_FC $c"
339          fi          fi
340      done      done
341        rm -f ./hello.f ./hello
342      if test "x${p_FC}" = x ; then      if test "x${p_FC}" = x ; then
343          cat 1>&2 <<EOF          cat 1>&2 <<EOF
344    
# Line 128  Error: No Fortran compilers were found i Line 346  Error: No Fortran compilers were found i
346    
347      1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),      1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
348      2) a command-line option (eg. "-fc NAME"), or      2) a command-line option (eg. "-fc NAME"), or
349      3) the MITGCM_FC environment variable.      3) the FC or MITGCM_FC environment variables.
350    
351  EOF  EOF
352          exit 1          exit 1
353      else      else
354          echo "  The possible FORTRAN compilers found in your path are:"          echo "  The possible FORTRAN compilers found in your path are:"
355          echo "   "$p_FC          echo "   "$p_FC
         if test "x$FC" = x ; then  
             FC=`echo $p_FC | awk '{print $1}'`  
         fi  
356      fi      fi
357    
358      for i in $p_FC ; do      #  Use the first of the compilers found in the current PATH
359          p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i      #  that has a correctly-named optfile
360          if test -r $p_OF ; then      if test "x$OPTFILE" = x  -a  "x$FC" = x ; then
361              OPTFILE=$p_OF          for i in $p_FC ; do
362              echo "  The options file:  $p_OF"              OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
363              echo "    appears to match so we'll use it."              if test -r $OPTFILE ; then
364              break                  echo "  Setting OPTFILE to: "$OPTFILE
365          fi                  break
366      done              fi
367            done
368        fi
369    
370        if test "x$OPTFILE" = x ; then
371            OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
372            if test ! -r $OPTFILE ; then
373                 echo "  I looked for the file "$OPTFILE" but did not find it"
374            fi
375        fi
376    #    echo "  The options file:  $p_OF"
377    #    echo "    appears to match so we'll use it."
378    #   for i in $p_FC ; do
379    #p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
380    #if test -r $p_OF ; then
381    #    OPTFILE=$p_OF
382    #    echo "  The options file:  $p_OF"
383    #    echo "    appears to match so we'll use it."
384    #    break
385    #fi
386    #   done
387      if test "x$OPTFILE" = x ; then      if test "x$OPTFILE" = x ; then
388          cat 1>&2 <<EOF          cat 1>&2 <<EOF
389    
# Line 202  get_pdepend_list()  { Line 437  get_pdepend_list()  {
437      #  strip the comments and then convert the dependency file into      #  strip the comments and then convert the dependency file into
438      #  two arrays: PNAME, DNAME      #  two arrays: PNAME, DNAME
439      cat $1 | sed -e 's/#.*$//g' \      cat $1 | sed -e 's/#.*$//g' \
440          | awk 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \          | $AWK 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \
441          > ./.pd_tmp          > ./.pd_tmp
442      source ./.pd_tmp      . ./.pd_tmp
443      rm -f ./.pd_tmp      rm -f ./.pd_tmp
444    
445      echo -n "PNAME = "${}      printf "PNAME = "${}
446  }  }
447    
448    
449  #  Explain usage  #  Explain usage
450  usage()  {  usage()  {
451      echo  cat <<EOF
452      echo "Usage: "$0" [OPTIONS]"  
453      echo "  where [OPTIONS] can be:"  Usage: "$0" [OPTIONS]
454      echo    where [OPTIONS] can be:
455      echo "    -help | --help | -h | --h"  
456      echo "    -nooptfile | --nooptfile"      -help | --help | -h | --h
457      echo "      -optfile NAME | --optfile NAME | -of NAME | --of NAME"            Print this help message and exit.
458      echo "      -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME"  
459      echo "    -pdepend NAME | --pdepend NAME"      -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME
460      echo "      -pdepend=NAME | --pdepend=NAME"        -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME
461      echo "    -pdefault NAME | --pdefault NAME"            Use "NAME" as the adoptfile.  By default, the file at
462      echo "      -pdefault=NAME | --pdefault=NAME"            "tools/adjoint_options/adjoint_default" will be used.
463      echo "    -make NAME | -m NAME"  
464      echo "      --make=NAME | -m=NAME"      -nooptfile | --nooptfile
465      echo "    -makefile NAME | -mf NAME"        -optfile NAME | --optfile NAME | -of NAME | --of NAME
466      echo "      --makefile=NAME | -mf=NAME"        -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
467      echo "    -platform NAME | --platform NAME | -pl NAME | --pl NAME"            Use "NAME" as the optfile.  By default, an attempt will be
468      echo "      -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"            made to find an appropriate "standard" optfile in the
469      echo "    -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"            tools/build_options/ directory.
470      echo "      -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME"  
471      echo "    -mods NAME | --mods NAME | -mo NAME | --mo NAME"      -pdepend NAME | --pdepend NAME
472      echo "      -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME"        -pdepend=NAME | --pdepend=NAME
473      echo "    -disable NAME | --disable NAME"            Get package dependency information from "NAME".
474      echo "      -disable=NAME | --disable=NAME"  
475      echo "    -enable NAME | --enable NAME"      -pdefault NAME | --pdefault NAME
476      echo "      -enable=NAME | --enable=NAME"        -pdefault=NAME | --pdefault=NAME
477      echo "    -standarddirs NAME | --standarddirs NAME"            Get the default package list from "NAME".
478      echo "      -standarddirs=NAME | --standarddirs=NAME"  
479      echo "    -noopt NAME | --noopt NAME"      -make NAME | -m NAME
480      echo "      -noopt=NAME | --noopt=NAME"        --make=NAME | -m=NAME
481  #    echo "    -cpp NAME | --cpp NAME"            Use "NAME" for the MAKE program. The default is "make" but
482  #    echo "      -cpp=NAME | --cpp=NAME"            many platforms, "gmake" is the preferred choice.
483      echo "    -fortran NAME | --fortran NAME | -fc NAME | --fc NAME"  
484      echo "      -fc=NAME | --fc=NAME"      -makefile NAME | -mf NAME
485      echo "    -[no]ieee | --[no]ieee"        --makefile=NAME | -mf=NAME
486      echo "    -[no]mpi | --[no]mpi"            Call the makefile "NAME".  The default is "Makefile".
487      echo "    -[no]jam | --[no]jam"  
488      echo      -makedepend NAME | -md NAME
489      echo "  and NAME is a string such as:"        --makedepend=NAME | -md=NAME
490      echo            Use "NAME" for the MAKEDEPEND program.
491      echo "    --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'"  
492      echo "    -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'"      -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
493      echo "    -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"        -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
494      echo            Specify the location of the MITgcm ROOTDIR as "NAME".
495      echo "  which, depending upon your shell, may need to be single-quoted"            By default, genamke will try to find the location by
496      echo "  if it contains spaces, dashes, or other special characters."            looking in parent directories (up to the 5th parent).
497    
498        -mods NAME | --mods NAME | -mo NAME | --mo NAME
499          -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
500              Here, "NAME" specifies a list of directories that are
501              used for additional source code.  Files found in the
502              "mods list" are given preference over files of the same
503              name found elsewhere.
504    
505        -disable NAME | --disable NAME
506          -disable=NAME | --disable=NAME
507              Here "NAME" specifies a list of packages that we don't
508              want to use.  If this violates package dependencies,
509              genamke will exit with an error message.
510    
511        -enable NAME | --enable NAME
512          -enable=NAME | --enable=NAME
513              Here "NAME" specifies a list of packages that we wish
514              to specifically enable.  If this violates package
515              dependencies, genamke will exit with an error message.
516    
517        -standarddirs NAME | --standarddirs NAME
518          -standarddirs=NAME | --standarddirs=NAME
519              Here, "NAME" specifies a list of directories to be
520              used as the "standard" code.
521    
522        -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
523          -fc=NAME | --fc=NAME
524              Use "NAME" as the fortran compiler.  By default, genmake
525              will search for a working compiler by trying a list of
526              "usual suspects" such as g77, f77, etc.
527    
528        -cc NAME | --cc NAME | -cc=NAME | --cc=NAME
529              Use "NAME" as the C compiler.  By default, genmake
530              will search for a working compiler by trying a list of
531              "usual suspects" such as gcc, c89, cc, etc.
532    
533        -[no]ieee | --[no]ieee
534              Do or don't use IEEE numerics.  Note that this option
535              *only* works if it is supported by the OPTFILE that
536              is being used.
537    
538        -ts | --ts
539              Produce timing information per timestep
540        -papis | --papis
541              Produce summary MFlop/s with PAPI per timestep
542        -foolad | --foolad
543              Fool the AD code generator
544        -papi | --papi
545              Performance analysis with PAPI
546        -hpmt | --hpmt
547              Performance analysis with the HPM Toolkit
548    
549        -gsl | --gsl
550              Use GSL to control floating point rounding and precision
551    
552        -mpi | --mpi
553              Include MPI header files and link to MPI libraries
554        -mpi=PATH | --mpi=PATH
555              Include MPI header files and link to MPI libraries using MPI_ROOT
556              set to PATH. i.e. Include files from \$PATH/include, link to libraries
557              from \$PATH/lib and use binaries from \$PATH/bin.
558    
559        -bash NAME
560              Explicitly specify the Bourne or BASH shell to use
561    
562      While it is most often a single word, the "NAME" variables specified
563      above can in many cases be a space-delimited string such as:
564    
565        --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'
566        -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'
567        -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
568    
569      which, depending upon your shell, may need to be single-quoted.
570    
571      For more detailed genmake documentation, please see:
572    
573        http://mitgcm.org/devel_HOWTO/
574    
575    EOF
576    
577      exit 1      exit 1
578  }  }
579    
580  #eh3 # This is the generic configuration.  #  Build a CPP macro to automate calling C routines from FORTRAN
581  #eh3 set LN         = ( 'ln -s' )  get_fortran_c_namemangling()  {
582  #eh3 set CPP        = ( '/lib/cpp -P' )  
583  #eh3 set S64        = ( '$(TOOLSDIR)/set64bitConst.sh' )      #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
584  #eh3 set KPP        = (  )      if test ! "x$FC_NAMEMANGLE" = x ; then
585  #eh3 set FC         = ( 'f77' )          return 0
586  #eh3 set LINK       = $FC      fi
587  #eh3 set MAKEDEPEND = ( 'makedepend' )  
588  #eh3 set INCLUDES   = ( -I. )      default_nm="#define FC_NAMEMANGLE(X) X ## _"
589  #eh3 set FFLAGS     = (  )      
590  #eh3 set FOPTIM     = (  )      cat > genmake_test.c <<EOF
591  #eh3 set CFLAGS     = (  )  void tcall( char * string ) { tsub( string ); }
592  #eh3 set KFLAGS1    = (  )  EOF
593  #eh3 set KFLAGS2    = (  )      $MAKE genmake_test.o >> genmake_warnings 2>&1
594  #eh3 set LIBS       = (  )      RETVAL=$?
595  #eh3 set KPPFILES   = (  )      if test "x$RETVAL" != x0 ; then
596  #eh3 if (! $?NOOPTFILES ) set NOOPTFILES = (  )          FC_NAMEMANGLE=$default_nm
597  #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = (  )          cat <<EOF>> genmake_errors
598    
599    WARNING: C test compile fails
600    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
601    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
602    EOF
603            return 1
604        fi
605        c_tcall=`nm genmake_test.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
606        RETVAL=$?
607        if test "x$RETVAL" != x0 ; then
608            FC_NAMEMANGLE=$default_nm
609            cat <<EOF>> genmake_warnings
610    
611    WARNING: The "nm" command failed.
612    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
613    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
614    EOF
615            return 1
616        fi
617        cat > genmake_tcomp.$FS <<EOF
618          subroutine tcall( string )
619          character*(*) string
620          call tsub( string )
621          end
622    EOF
623        $FC $FFLAGS -c genmake_tcomp.$FS >> genmake_warnings 2>&1
624        RETVAL=$?
625        if test "x$RETVAL" != x0 ; then
626            FC_NAMEMANGLE=$default_nm
627            cat <<EOF>> genmake_warnings
628    
629    WARNING: FORTRAN test compile fails -- please see "genmake_errors"
630    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
631    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
632    EOF
633            return 1
634        fi
635        f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
636        RETVAL=$?
637        if test "x$RETVAL" != x0 ; then
638            FC_NAMEMANGLE=$default_nm
639            cat <<EOF>> genmake_warnings
640    
641    WARNING: The "nm" command failed.
642    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
643    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
644    EOF
645            return 1
646        fi
647    
648        c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
649        f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
650        c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
651        f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
652    
653        nmangle="X"
654        if test "x$c_a" != "x$f_a" ; then
655            comm="echo x$f_a | sed -e 's|x$c_a||'"
656            a=`eval $comm`
657            nmangle="$a ## $nmangle"
658        fi
659        if test "x$c_b" != "x$f_b" ; then
660            comm="echo x$f_b | sed -e 's|x$c_b||'"
661            b=`eval $comm`
662            nmangle="$nmangle ## $b"
663        fi
664    
665        FC_NAMEMANGLE="#define FC_NAMEMANGLE(X)  $nmangle"
666    
667        #  cleanup the testing files
668        rm -f genmake_tcomp.* genmake_test.*
669    }
670    
671    
672    check_HAVE_CLOC()  {
673        get_fortran_c_namemangling
674        cat <<EOF > genmake_tc_1.c
675    $FC_NAMEMANGLE
676    #include <stdio.h>
677    #include <stdlib.h>
678    #include <unistd.h>
679    #include <assert.h>
680    #include <sys/time.h>
681    void FC_NAMEMANGLE(cloc) ( double *curtim )
682    {
683     struct timeval tv1;
684     gettimeofday(&tv1 , (void *)NULL );
685     *curtim =  (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
686     *curtim = *curtim/1.E6;
687    }
688    EOF
689        make genmake_tc_1.o >> genmake_warnings 2>&1
690        RET_C=$?
691        cat <<EOF > genmake_tc_2.$FS
692          program hello
693          REAL*8 wtime
694          external cloc
695          call cloc(wtime)
696          print *," HELLO WORLD", wtime
697          end
698    EOF
699        $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_warnings 2>&1
700        RET_F=$?
701        test -x ./genmake_tc  &&  ./genmake_tc >> genmake_warnings 2>&1
702        RETVAL=$?
703        if test "x$RETVAL" = x0 ; then
704            HAVE_CLOC=t
705            DEFINES="$DEFINES -DHAVE_CLOC"
706        fi
707        rm -f genmake_tc*
708    }
709    
710    
711    check_HAVE_SIGREG()  {
712        get_fortran_c_namemangling
713        cat <<EOF > genmake_tc_1.c
714    $FC_NAMEMANGLE
715    #include <stdlib.h>
716    #include <stdio.h>
717    #include <signal.h>
718    #include <errno.h>
719    #include <ucontext.h>
720    
721    int * ip;
722    
723    static void killhandler(
724        unsigned int sn, siginfo_t  si, struct ucontext *sc )
725    {
726        *ip = *ip + 1;
727        return;
728    }
729    
730    void FC_NAMEMANGLE(sigreg) (int * aip)
731    {
732        struct sigaction s;
733        ip = aip;
734        s.sa_flags = SA_SIGINFO;
735        s.sa_sigaction = (void *)killhandler;
736        if(sigaction (SIGTERM,&s,(struct sigaction *)NULL)) {
737            printf("Sigaction returned error = %d\n", errno);
738            exit(0);
739        }
740        return;
741    }
742    EOF
743        make genmake_tc_1.o >> genmake_warnings 2>&1
744        RET_C=$?
745        cat <<EOF > genmake_tc_2.$FS
746          program hello
747          integer anint
748          common /iv/ anint
749          external sigreg
750          call sigreg(anint)
751          end
752    EOF
753        echo >> genmake_warnings
754        echo "running: check_HAVE_SIGREG()" >> genmake_warnings
755        cat genmake_tc_2.$FS >> genmake_warnings
756        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
757        echo $COMM >> genmake_warnings
758        $COMM >> genmake_warnings 2>&1
759        RETVAL=$?
760        if test "x$RETVAL" = x0 ; then
761            HAVE_SIGREG=t
762            DEFINES="$DEFINES -DHAVE_SIGREG"
763        fi
764        rm -f genmake_tc*
765    }
766    
767    
768    check_HAVE_SETRLSTK()  {
769        get_fortran_c_namemangling
770        cat <<EOF > genmake_tc_1.c
771    $FC_NAMEMANGLE
772    #include <sys/time.h>
773    #include <sys/resource.h>
774    #include <unistd.h>
775    void FC_NAMEMANGLE(setrlstk) ()
776    {
777        struct rlimit rls;
778        rls.rlim_cur = RLIM_INFINITY;
779        rls.rlim_max = RLIM_INFINITY;
780        setrlimit(RLIMIT_STACK, &rls);
781        return;
782    }
783    EOF
784        make genmake_tc_1.o >> genmake_warnings 2>&1
785        RET_C=$?
786        cat <<EOF > genmake_tc_2.$FS
787          program hello
788          external setrlstk
789          call setrlstk()
790          end
791    EOF
792        echo >> genmake_warnings
793        echo "running: check_HAVE_SETRLSTK()" >> genmake_warnings
794        cat genmake_tc_2.$FS >> genmake_warnings
795        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
796        echo $COMM >> genmake_warnings
797        $COMM >> genmake_warnings 2>&1
798        RETVAL=$?
799        if test "x$RETVAL" = x0 ; then
800            HAVE_SETRLSTK=t
801            DEFINES="$DEFINES -DHAVE_SETRLSTK"
802        fi
803        rm -f genmake_tc*
804    }
805    
806    
807    check_HAVE_STAT()  {
808        get_fortran_c_namemangling
809        cat <<EOF > genmake_tc_1.c
810    $FC_NAMEMANGLE
811    #include <stdio.h>
812    #include <stdlib.h>
813    #include <unistd.h>
814    #include <sys/stat.h>
815    #include <sys/types.h>
816    void FC_NAMEMANGLE(tfsize) ( int *nbyte )
817    {
818        char name[512];
819        struct stat astat;
820    
821        name[0] = 'a'; name[1] = '\0';
822        if (! stat(name, &astat))
823            *nbyte = (int)(astat.st_size);
824        else
825            *nbyte = -1;
826    }
827    EOF
828        make genmake_tc_1.o >> genmake_tc.log 2>&1
829        RET_C=$?
830        cat <<EOF > genmake_tc_2.$FS
831          program hello
832          integer nbyte
833          call tfsize(nbyte)
834          print *," HELLO WORLD", nbyte
835          end
836    EOF
837        echo >> genmake_warnings
838        echo "running: check_HAVE_STAT()" >> genmake_warnings
839        cat genmake_tc_2.$FS >> genmake_warnings
840        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
841        echo $COMM >> genmake_warnings
842        $COMM >> genmake_tc.log 2>&1
843        RETVAL=$?
844        if test "x$RETVAL" = x0 ; then
845            HAVE_STAT=t
846            DEFINES="$DEFINES -DHAVE_STAT"
847        fi
848        rm -f genmake_tc*
849    }
850    
851    
852    check_netcdf_libs()  {
853        if test ! "x$SKIP_NETCDF_CHECK" = x ; then
854            return
855        fi
856        echo >> genmake_warnings
857        echo "running: check_netcdf_libs()" >> genmake_warnings
858        cat <<EOF > genmake_tnc.F
859          program fgennc
860    #include "netcdf.inc"
861    EOF
862        if test ! "x$MPI" = x ; then
863            echo '#include "mpif.h"' >> genmake_tnc.F
864        fi
865        cat <<EOF >> genmake_tnc.F
866          integer iret, ncid, xid
867          iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
868          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
869          iret = nf_def_dim(ncid, 'X', 11, xid)
870          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
871          iret = nf_close(ncid)
872          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
873          end
874    EOF
875        echo "===  genmake_tnc.F  ===" > genmake_tnc.log
876        cat genmake_tnc.F >> genmake_tnc.log
877        echo "===  genmake_tnc.F  ===" >> genmake_tnc.log
878        RET_CPP=f
879        COMM="$CPP $DEFINES $INCLUDES genmake_tnc.F"
880        echo "$COMM" >> genmake_tnc.log
881        $COMM > genmake_tnc.$FS 2>/dev/null  &&  RET_CPP=t
882        if test "x$RET_CPP" = xf ; then
883            echo "  WARNING: CPP failed to pre-process the netcdf test." \
884                >> genmake_tnc.log
885            echo "    Please check that \$INCLUDES is properly set." \
886                >> genmake_tnc.log
887        fi
888        echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.$FS  \ " >> genmake_tnc.log
889        echo "  &&  $LINK -o genmake_tnc.o $LIBS" >> genmake_tnc.log
890        $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
891            &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
892        RET_COMPILE=$?
893        cat genmake_tnc.log >> genmake_warnings
894    
895        #EH3  Remove test program execution for machines that either disallow
896        #EH3  execution or cannot support it (eg. cross-compilers)
897        #EH3
898        #EH3 test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1
899        #EH3 RETVAL=$?
900        #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
901    
902        if test "x$RET_COMPILE" = x0 ; then
903            HAVE_NETCDF=t
904        else
905            # try again with "-lnetcdf" added to the libs
906            echo "try again with added '-lnetcdf'" > genmake_tnc.log
907            echo "$CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS \ " >> genmake_tnc.log
908            echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
909            echo " &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
910            $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null  \
911                &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
912                &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
913            RET_COMPILE=$?
914            cat genmake_tnc.log >> genmake_warnings
915            if test "x$RET_COMPILE" = x0 ; then
916                LIBS="$LIBS -lnetcdf"
917                HAVE_NETCDF=t
918            fi
919        fi
920        rm -f genmake_tnc*
921    }
922    
923    
924    
925    ###############################################################################
926    #   Sequential part of script starts here
927    ###############################################################################
928    
929  #  Set defaults here  #  Set defaults here
930  COMMANDL="$0 $@"  COMMANDL="$0 $@"
# Line 288  PLATFORM= Line 933  PLATFORM=
933  LN=  LN=
934  S64=  S64=
935  KPP=  KPP=
936  FC=  #FC=
937    #CC=gcc
938    #CPP=
939  LINK=  LINK=
940  DEFINES="-DWORDLENGTH=4"  DEFINES=
941  PACKAGES=  PACKAGES=
942  ENABLE=  ENABLE=
943  DISABLE=  DISABLE=
944  MAKEFILE=  # MAKEFILE=
945  MAKEDEPEND=  # MAKEDEPEND=
946  PDEPEND=  PDEPEND=
947  DUMPSTATE=t  DUMPSTATE=t
948  PDEFAULT=  PDEFAULT=
949  OPTFILE=  OPTFILE=
950  INCLUDES="-I."  INCLUDES="-I. $INCLUDES"
951  FFLAGS=  FFLAGS=
952  FOPTIM=  FOPTIM=
953  CFLAGS=  CFLAGS=
954  KFLAGS1=  KFLAGS1=
955  KFLAGS2=  KFLAGS2=
956    #LDADD=
957  LIBS=  LIBS=
958  KPPFILES=  KPPFILES=
959  NOOPTFILES=  NOOPTFILES=
960  NOOPTFLAGS=  NOOPTFLAGS=
961    MPI=
962    MPIPATH=
963    TS=
964    PAPIS=
965    FOOLAD=
966    PAPI=
967    HPMT=
968    GSL=
969    HAVE_TEST_L=
970    
971    # DEFINES checked by test compilation or command-line
972    HAVE_SYSTEM=
973    HAVE_FDATE=
974    FC_NAMEMANGLE=
975    HAVE_CLOC=
976    HAVE_SETRLSTK=
977    HAVE_STAT=
978    HAVE_NETCDF=
979    HAVE_ETIME=
980    IGNORE_TIME=
981    
982  MODS=  MODS=
983  TOOLSDIR=  TOOLSDIR=
984  SOURCEDIRS=  SOURCEDIRS=
985  INCLUDEDIRS=  INCLUDEDIRS=
986  STANDARDDIRS=  STANDARDDIRS="USE_THE_DEFAULT"
987    
988    G2ARGS=
989    BASH=
990  PWD=`pwd`  PWD=`pwd`
991  MAKE=make  test "x$MAKE" = x  &&  MAKE=make
992  THISHOSTNAME=`hostname`  test "x$AWK" = x   &&  AWK=awk
993    THISHOST=`hostname`
994  THISCWD=`pwd`  THISCWD=`pwd`
995  THISDATE=`date`  THISDATE=`date`
996    THISUSER=`echo $USER`
997    THISVER=
998  MACHINE=`uname -a`  MACHINE=`uname -a`
999  EXECUTABLE=  EXECUTABLE=
1000  EXEHOOK=  EXEHOOK=
# Line 331  IEEE= Line 1004  IEEE=
1004  if test "x$MITGCM_IEEE" != x ; then  if test "x$MITGCM_IEEE" != x ; then
1005      IEEE=$MITGCM_IEEE      IEEE=$MITGCM_IEEE
1006  fi  fi
1007    FS=
1008    FS90=
1009    
1010  AUTODIFF_PKG_USED=f  AUTODIFF_PKG_USED=f
1011  AD_OPTFILE=  AD_OPTFILE=
1012    TAF=
1013    AD_TAF_FLAGS=
1014    FTL_TAF_FLAGS=
1015    SVD_TAF_FLAGS=
1016    TAF_EXTRA=
1017    TAMC=
1018    AD_TAMC_FLAGS=
1019    FTL_TAF_FLAGS=
1020    SVD_TAMC_FLAGS=
1021    TAMC_EXTRA=
1022    
1023    
1024  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
1025  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"
1026  gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS"  gm_s2="FC CPP IEEE TS PAPIS PAPI HPMT GSL MPI JAM DUMPSTATE STANDARDDIRS"
1027    
1028  #  The following state is not directly set by command-line switches  #  The following state is not directly set by command-line switches
1029  gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "  gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
1030  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
1031  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE"
1032  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
1033    gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME"
1034    
1035  #  The following are all related to adjoint/tangent-linear stuff  #  The following are all related to adjoint/tangent-linear stuff
1036  gm_s7="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF DIFF_FLAGS AD_TAMC_FLAGS AD_TAF_FLAGS"  gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
1037  gm_s8="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"
1038  gm_s9=""  gm_s12="TAF_EXTRA TAMC_EXTRA"
1039    
1040  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7 $gm_s8"  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"
1041    gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
1042    
1043    cat <<EOF
1044    
1045    GENMAKE :
1046    
1047    A program for GENerating MAKEfiles for the MITgcm project.  For a
1048    quick list of options, use "genmake -h" or for more detail see:
1049    
1050      http://mitgcm.org/devel_HOWTO/
1051    
1052    EOF
1053    
 echo  
1054  echo "===  Processing options files and arguments  ==="  echo "===  Processing options files and arguments  ==="
1055  gm_local="genmake_local"  gm_local="genmake_local"
1056  for i in . $MODS ; do  for i in . $MODS ; do
1057      if test -r $i/$gm_local ; then      if test -r $i/$gm_local ; then
1058          source $i/$gm_local          . $i/$gm_local
1059          break          break
1060      fi      fi
1061  done  done
1062  echo -n "  getting local config information:  "  printf "  getting local config information:  "
1063  if test -e $gm_local ; then  if test -f $gm_local ; then
1064      echo "using $gm_local"      echo "using $gm_local"
1065      source $gm_local      . $gm_local
1066      # echo "DISABLE=$DISABLE"      # echo "DISABLE=$DISABLE"
1067      # echo "ENABLE=$ENABLE"      # echo "ENABLE=$ENABLE"
1068  else  else
1069      echo "none found"      echo "none found"
1070  fi  fi
1071    
1072  #  echo "$0::$1:$2:$3:$4:$5:$6:$7:"  #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
1073  #OPTIONS=  #OPTIONS=
1074  #n=0  #n=0
1075  #for i ; do  #for i ; do
# Line 384  fi Line 1081  fi
1081  #done  #done
1082  #parse_options  #parse_options
1083  ac_prev=  ac_prev=
1084  for ac_option ; do  for ac_option in "$@" ; do
1085    
1086        G2ARGS="$G2ARGS \"$ac_option\""
1087    
1088      # If the previous option needs an argument, assign it.      # If the previous option needs an argument, assign it.
1089      if test -n "$ac_prev"; then      if test -n "$ac_prev"; then
# Line 407  for ac_option ; do Line 1106  for ac_option ; do
1106          -optfile=* | --optfile=* | -of=* | --of=*)          -optfile=* | --optfile=* | -of=* | --of=*)
1107              OPTFILE=$ac_optarg ;;              OPTFILE=$ac_optarg ;;
1108                    
1109          -adoptfile | --adoptfile | -ad | --ad)          -adoptfile | --adoptfile | -adof | --adof)
1110              ac_prev=AD_OPTFILE ;;              ac_prev=AD_OPTFILE ;;
1111          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
1112              AD_OPTFILE=$ac_optarg ;;              AD_OPTFILE=$ac_optarg ;;
# Line 427  for ac_option ; do Line 1126  for ac_option ; do
1126          -make=* | --make=* | -m=* | --m=*)          -make=* | --make=* | -m=* | --m=*)
1127              MAKE=$ac_optarg ;;              MAKE=$ac_optarg ;;
1128                    
1129            -bash | --bash)
1130                ac_prev=BASH ;;
1131            -bash=* | --bash=*)
1132                BASH=$ac_optarg ;;
1133            
1134            -makedepend | --makedepend | -md | --md)
1135                ac_prev=MAKEDEPEND ;;
1136            -makedepend=* | --makedepend=* | -md=* | --md=*)
1137                MAKEDEPEND=$ac_optarg ;;
1138            
1139          -makefile | --makefile | -ma | --ma)          -makefile | --makefile | -ma | --ma)
1140              ac_prev=MAKEFILE ;;              ac_prev=MAKEFILE ;;
1141          -makefile=* | --makefile=* | -ma=* | --ma=*)          -makefile=* | --makefile=* | -ma=* | --ma=*)
1142              MAKEFILE=$ac_optarg ;;              MAKEFILE=$ac_optarg ;;
1143                    
1144          -platform | --platform | -pl | --pl)          -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
1145              ac_prev=PLATFORM ;;              echo "ERROR: The platform option has been removed.  Please specify"
1146          -platform=* | --platform=* | -pl=* | --pl=*)              echo "  the build options using the \"optfile\" mechanism."
1147              PLATFORM=$ac_optarg ;;              echo
1148                usage
1149                ;;
1150                    
1151          -rootdir | --rootdir | -rd | --rd)          -rootdir | --rootdir | -rd | --rd)
1152              ac_prev=ROOTDIR ;;              ac_prev=ROOTDIR ;;
# Line 462  for ac_option ; do Line 1173  for ac_option ; do
1173          -standarddirs=* | --standarddirs=*)          -standarddirs=* | --standarddirs=*)
1174              STANDARDDIRS=$ac_optarg ;;              STANDARDDIRS=$ac_optarg ;;
1175    
         -noopt | --noopt)  
             ac_prev=NOOPT ;;  
         -noopt=* | --noopt=*)  
             NOOPT=$ac_optarg ;;  
           
1176  #           -cpp | --cpp)  #           -cpp | --cpp)
1177  #               ac_prev=cpp ;;  #               ac_prev=cpp ;;
1178  #           -cpp=* | --cpp=*)  #           -cpp=* | --cpp=*)
1179  #               CPP=$ac_optarg ;;  #               CPP=$ac_optarg ;;
1180                        
1181            -cc | --cc)
1182                ac_prev=CC ;;
1183            -cc=* | --cc=*)
1184                CC=$ac_optarg ;;
1185            
1186          -fortran | --fortran | -fc | --fc)          -fortran | --fortran | -fc | --fc)
1187              ac_prev=FC ;;              ac_prev=FC ;;
1188          -fc=* | --fc=*)          -fc=* | --fc=*)
1189              FC=$ac_optarg ;;              FC=$ac_optarg ;;
1190                    
1191            -fs | --fs)
1192                ac_prev=FS ;;
1193            -fs=* | --fs=*)
1194                FS=$ac_optarg ;;
1195            
1196            -fs90 | --fs90)
1197                ac_prev=FS90 ;;
1198            -fs90=* | --fs90=*)
1199                FS90=$ac_optarg ;;
1200            
1201          -ieee | --ieee)          -ieee | --ieee)
1202              IEEE=true ;;              IEEE=true ;;
1203          -noieee | --noieee)          -noieee | --noieee)
1204              IEEE= ;;              IEEE= ;;
1205            
1206            -ts | --ts)
1207                TS=true ;;
1208            -papis | --papis)
1209                PAPIS=true ;;
1210            -foolad | --foolad)
1211                FOOLAD=true ;;
1212            -papi | --papi)
1213                PAPI=true ;;
1214            -hpmt | --hpmt)
1215                HPMT=true ;;
1216    
1217            -gsl | --gsl)
1218                GSL=true ;;
1219    
1220          -mpi | --mpi)          -mpi | --mpi)
1221              MPI=true ;;              MPI=true ;;
1222          -nompi | --nompi)          -mpi=* | --mpi=*)
1223              MPI= ;;              MPIPATH=$ac_optarg
1224                MPI=true ;;
1225                    
1226          -jam | --jam)  #       -jam | --jam)
1227              JAM=1 ;;  #           JAM=1 ;;
1228          -nojam | --nojam)  #       -nojam | --nojam)
1229              JAM=0 ;;  #           JAM=0 ;;
1230                    
1231          -ds | --ds)          -ds | --ds)
1232              DUMPSTATE=t ;;              DUMPSTATE=t ;;
1233                    
1234            -taf_extra | --taf_extra)
1235                ac_prev=TAF_EXTRA ;;
1236            -taf_extra=* | --taf_extra=*)
1237                TAF_EXTRA=$ac_optarg ;;
1238    
1239            -tamc_extra | --tamc_extra)
1240                ac_prev=TAMC_EXTRA ;;
1241            -tamc_extra=* | --tamc_extra=*)
1242                TAMC_EXTRA=$ac_optarg ;;
1243            
1244            -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1245                IGNORE_TIME="-DIGNORE_TIME" ;;
1246    
1247          -*)          -*)
1248              echo "Error: unrecognized option: "$ac_option              echo "Error: unrecognized option: "$ac_option
1249              usage              usage
# Line 509  for ac_option ; do Line 1258  for ac_option ; do
1258            
1259  done  done
1260    
1261    
1262  if test -f ./.genmakerc ; then  if test -f ./.genmakerc ; then
1263      echo      echo
1264      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
# Line 521  if test -f ./.genmakerc ; then Line 1271  if test -f ./.genmakerc ; then
1271      echo      echo
1272  fi  fi
1273    
1274    #  Find the MITgcm ${ROOTDIR}
1275  if test "x${ROOTDIR}" = x ; then  if test "x${ROOTDIR}" = x ; then
1276      if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1277        if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
1278          ROOTDIR=".."          ROOTDIR=".."
1279      else      else
1280          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1281              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
1282                  ROOTDIR=$d                  ROOTDIR=$d
1283                  echo -n "Warning:  ROOTDIR was not specified but there appears to be"                  printf "Warning:  ROOTDIR was not specified but there appears to be"
1284                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
1285                  break                  break
1286              fi              fi
# Line 546  if test ! -d ${ROOTDIR} ; then Line 1298  if test ! -d ${ROOTDIR} ; then
1298      exit 1      exit 1
1299  fi  fi
1300    
1301    #  Find the MITgcm ${THISVER}
1302    if test -f "${ROOTDIR}/doc/tag-index" ; then
1303        THISVER=`grep '^checkpoint' ${ROOTDIR}/doc/tag-index | head -1`
1304    fi
1305    
1306    if test "x$MAKEFILE" = x ; then
1307        MAKEFILE="Makefile"
1308    fi
1309    
1310  echo "  getting OPTFILE information:  "  echo "  getting OPTFILE information:  "
1311  if test "x${OPTFILE}" = x ; then  if test "x${OPTFILE}" = x ; then
1312      if test "x$MITGCM_OF" = x ; then      if test "x$MITGCM_OF" = x ; then
# Line 559  fi Line 1320  fi
1320  if test "x$OPTFILE" != xNONE ; then  if test "x$OPTFILE" != xNONE ; then
1321      if test -f "$OPTFILE" -a -r "$OPTFILE" ; then      if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
1322          echo "    using OPTFILE=\"$OPTFILE\""          echo "    using OPTFILE=\"$OPTFILE\""
1323          source "$OPTFILE"          . "$OPTFILE"
1324          RETVAL=$?          RETVAL=$?
1325          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
1326              echo -n "Error: failed to source OPTFILE \"$OPTFILE\""              printf "Error: failed to source OPTFILE \"$OPTFILE\""
1327              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1328              exit 1              exit 1
1329          fi          fi
# Line 586  fi Line 1347  fi
1347  if test "x${AD_OPTFILE}" != xNONE ; then  if test "x${AD_OPTFILE}" != xNONE ; then
1348      if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then      if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
1349          echo "    using AD_OPTFILE=\"$AD_OPTFILE\""          echo "    using AD_OPTFILE=\"$AD_OPTFILE\""
1350          source "$AD_OPTFILE"          . "$AD_OPTFILE"
1351          RETVAL=$?          RETVAL=$?
1352          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
1353              echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""              printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
1354              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1355              exit 1              exit 1
1356          fi          fi
# Line 602  if test "x${AD_OPTFILE}" != xNONE ; then Line 1363  if test "x${AD_OPTFILE}" != xNONE ; then
1363      fi      fi
1364  fi  fi
1365    
1366  #  Check that FC, LINK, CPP, and S64 are defined.  If not, complain  #====================================================================
1367  #  and abort!  #  Set default values if not set by the optfile
1368    #
1369    #  Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
1370    #  either set defaults or complain and abort!
1371    if test ! "x$BASH" = x ; then
1372        # add a trailing space so that it works within the Makefile syntax (see below)
1373        BASH="$BASH "
1374    fi
1375  if test "x$FC" = x ; then  if test "x$FC" = x ; then
1376      cat <<EOF 1>&2      cat <<EOF 1>&2
1377    
# Line 614  Error: no Fortran compiler: please speci Line 1382  Error: no Fortran compiler: please speci
1382  EOF  EOF
1383      exit 1      exit 1
1384  fi  fi
1385    if test "x$CC" = x ; then
1386        CC=cc
1387    #     cat <<EOF 1>&2
1388    # Error: no C compiler: please specify using one of the following:
1389    #   1) within the options file ("CC=...") as specified by "-of=OPTFILE"
1390    #   2) the "-cc=XXX" command-line option
1391    #   3) the "./genmake_local" file
1392    # EOF
1393    #     exit 1
1394    fi
1395  if test "x$LINK" = x ; then  if test "x$LINK" = x ; then
1396      LINK=$FC      LINK=$FC
1397  fi  fi
1398    if test "x$MAKE" = x ; then
1399        MAKE="make"
1400    fi
1401  if test "x$CPP" = x ; then  if test "x$CPP" = x ; then
1402      CPP="cpp"      CPP=cpp
1403  fi  fi
1404    #EH3 === UGLY ===
1405    #  The following is an ugly little hack to check for $CPP in /lib/ and
1406    #  it should eventually be replaced with a more general function that
1407    #  searches a combo of the user's path and a list of "usual suspects"
1408    #  to find the correct location for binaries such as $CPP.
1409    for i in " " "/lib/" ; do
1410        echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1411    done
1412    #EH3 === UGLY ===
1413  echo "#define A a" | $CPP > test_cpp 2>&1  echo "#define A a" | $CPP > test_cpp 2>&1
1414  RETVAL=$?  RETVAL=$?
1415  if test "x$RETVAL" != x0 ; then  if test "x$RETVAL" != x0 ; then
# Line 629  Error: C pre-processor "$CPP" failed the Line 1419  Error: C pre-processor "$CPP" failed the
1419    
1420    1) within the options file ("CPP=...") as specified by "-of=OPTFILE"    1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
1421    2) the "./genmake_local" file    2) the "./genmake_local" file
1422      3) with the CPP environment variable
1423    
1424  EOF  EOF
1425      exit 1      exit 1
1426  else  else
1427      rm -f test_cpp      rm -f test_cpp
1428  fi  fi
1429  if test "x$MAKEDEPEND" = x ; then  look_for_makedepend
1430      MAKEDEPEND=makedepend  if test "x$LN" = x ; then
1431        LN="ln -s"
1432    fi
1433    echo "test" > genmake_test_ln
1434    $LN genmake_test_ln genmake_tlink
1435    RETVAL=$?
1436    if test "x$RETVAL" != x0 ; then
1437        cat <<EOF 1>&2
1438    
1439    Error: The command "ln -s" failed -- please specify a working soft-link
1440      command in the optfile.
1441    
1442    EOF
1443        exit 1
1444    fi
1445    test -L genmake_tlink > /dev/null 2>&1
1446    RETVAL=$?
1447    if test "x$RETVAL" = x0 ; then
1448        HAVE_TEST_L=t
1449    fi
1450    rm -f genmake_test_ln genmake_tlink
1451    
1452    #  Check for broken *.F/*.f handling and fix if possible
1453    check_for_broken_Ff
1454    
1455    if test ! "x$MPI" = x ; then
1456          echo "  Turning on MPI cpp macros"
1457          DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
1458    fi
1459    
1460    if test ! "x$TS" = x ; then
1461          echo "  Turning on timing per timestep"
1462          if test ! "x$FOOLAD" = x ; then
1463                DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP"
1464          else
1465                DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1466          fi
1467    fi
1468    if test ! "x$PAPIS" = x ; then
1469          echo "  Turning on PAPI flop summary per timestep"
1470          echo "  Please make sure PAPIINC, PAPILIB are defined"
1471          if test ! "x$FOOLAD" = x ; then
1472                DEFINES="$DEFINES -DUSE_PAPI_FLOPS_SFP"
1473          else
1474                DEFINES="$DEFINES -DUSE_PAPI_FLOPS"
1475          fi
1476          INCLUDES="$INCLUDES $PAPIINC"
1477          LIBS="$LIBS $PAPILIB"
1478    fi
1479    if test ! "x$PAPI" = x ; then
1480          if test ! "x$PAPIS" = x ; then
1481              echo "  PAPI performance analysis and flop summary per timestep cannot co-exist!"
1482              echo "  Sticking with PAPI flop summary per timestep!"
1483          else
1484              echo "  Turning on performance analysis with PAPI"
1485              echo "  Please make sure PAPIINC, PAPILIB are defined"
1486              DEFINES="$DEFINES -DUSE_PAPI"
1487              INCLUDES="$INCLUDES $PAPIINC"
1488              LIBS="$LIBS $PAPILIB"
1489          fi
1490    fi
1491    if test ! "x$HPMT" = x ; then
1492          if test ! "x$PAPI" = x ; then
1493              echo "  PAPI and the HPM Toolkit cannot co-exist!"
1494              echo "  Sticking with PAPI!"
1495          else
1496              echo "  Turning on performance analysis with the HPM Toolkit"
1497              echo "  Please make sure HPMTINC, HPMTLIB are defined"
1498              DEFINES="$DEFINES -DUSE_LIBHPM"
1499              INCLUDES="$INCLUDES $HPMTINC"
1500              LIBS="$LIBS $HPMTLIB"
1501          fi
1502    fi
1503    if test ! "x$GSL" = x ; then
1504          echo "  Turning on use of GSL to control floating point calculations"
1505          echo "  Please make sure GSLINC, GSLLIB are defined"
1506          DEFINES="$DEFINES -DUSE_GSL_IEEE"
1507          INCLUDES="$INCLUDES $GSLINC"
1508          LIBS="$LIBS $GSLLIB"
1509    fi
1510    
1511    printf "\n===  Checking system libraries  ===\n"
1512    printf "  Do we have the system() command using $FC...  "
1513    cat > genmake_tcomp.$FS <<EOF
1514          program hello
1515          call system('echo hi')
1516          end
1517    EOF
1518    $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1519    RETVAL=$?
1520    if test "x$RETVAL" = x0 ; then
1521        HAVE_SYSTEM=t
1522        DEFINES="$DEFINES -DHAVE_SYSTEM"
1523        echo "yes"
1524    else
1525        HAVE_SYSTEM=
1526        echo "no"
1527  fi  fi
1528    rm -f genmake_tcomp*
1529    
1530    printf "  Do we have the fdate() command using $FC...  "
1531    cat > genmake_tcomp.$FS <<EOF
1532          program hello
1533          CHARACTER*(128) string
1534          string = ' '
1535          call fdate( string )
1536          print *, string
1537          end
1538    EOF
1539    $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1540    RETVAL=$?
1541    if test "x$RETVAL" = x0 ; then
1542        HAVE_FDATE=t
1543        DEFINES="$DEFINES -DHAVE_FDATE"
1544        echo "yes"
1545    else
1546        HAVE_FDATE=
1547        echo "no"
1548    fi
1549    rm -f genmake_tcomp*
1550    
1551    printf "  Do we have the etime() command using $FC...  "
1552    cat > genmake_tcomp.$FS <<EOF
1553          program hello
1554          REAL*4 ACTUAL, TARRAY(2)
1555          EXTERNAL ETIME
1556          REAL*4 ETIME
1557          actual = etime( tarray )
1558          print *, tarray
1559          end
1560    EOF
1561    $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1562    RETVAL=$?
1563    if test "x$RETVAL" = x0 ; then
1564        HAVE_ETIME=t
1565        DEFINES="$DEFINES -DHAVE_ETIME"
1566        echo "yes"
1567    else
1568        HAVE_ETIME=
1569        echo "no"
1570    fi
1571    rm -f genmake_tcomp*
1572    
1573    printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
1574    check_HAVE_CLOC
1575    if test "x$HAVE_CLOC" != x ; then
1576        echo "yes"
1577    else
1578        echo "no"
1579    fi
1580    rm -f genmake_t*
1581    
1582    printf "  Can we unlimit the stack size using $FC...  "
1583    check_HAVE_SETRLSTK
1584    if test "x$HAVE_SETRLSTK" != x ; then
1585        echo "yes"
1586    else
1587        echo "no"
1588    fi
1589    rm -f genmake_t*
1590    
1591    printf "  Can we register a signal handler using $FC...  "
1592    check_HAVE_SIGREG
1593    if test "x$HAVE_SIGREG" != x ; then
1594        echo "yes"
1595    else
1596        echo "no"
1597    fi
1598    rm -f genmake_t*
1599    
1600    printf "  Can we use stat() through C calls...  "
1601    check_HAVE_STAT
1602    if test "x$HAVE_STAT" != x ; then
1603        echo "yes"
1604    else
1605        echo "no"
1606    fi
1607    rm -f genmake_t*
1608    
1609    printf "  Can we create NetCDF-enabled binaries...  "
1610    check_netcdf_libs
1611    if test "x$HAVE_NETCDF" != x ; then
1612        echo "yes"
1613    else
1614        echo "no"
1615    fi
1616    DEFINES="$DEFINES $IGNORE_TIME"
1617    
1618  printf "\n===  Setting defaults  ===\n"  printf "\n===  Setting defaults  ===\n"
1619  echo -n "  Adding MODS directories:  "  printf "  Adding MODS directories:  "
1620  for d in $MODS ; do  for d in $MODS ; do
1621      if test ! -d $d ; then      if test ! -d $d ; then
1622          echo          echo
1623          echo "Error: MODS directory \"$d\" not found!"          echo "Error: MODS directory \"$d\" not found!"
1624          exit 1          exit 1
1625      else      else
1626          echo -n " $d"          printf " $d"
1627          SOURCEDIRS="$SOURCEDIRS $d"          SOURCEDIRS="$SOURCEDIRS $d"
1628          INCLUDEDIRS="$INCLUDEDIRS $d"          INCLUDEDIRS="$INCLUDEDIRS $d"
1629      fi      fi
1630  done  done
1631  echo  echo
1632    
 if test "x$MAKEFILE" = x ; then  
     MAKEFILE="Makefile"  
 fi  
1633  if test "x${PLATFORM}" = x ; then  if test "x${PLATFORM}" = x ; then
1634      PLATFORM=$p_PLATFORM      PLATFORM=$p_PLATFORM
1635  fi  fi
1636    
1637  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
1638      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1639        if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
1640          EXEDIR=../exe          EXEDIR=../exe
1641      else      else
1642          EXEDIR=.          EXEDIR=.
# Line 677  if test "x${TOOLSDIR}" = x ; then Line 1651  if test "x${TOOLSDIR}" = x ; then
1651      TOOLSDIR="$ROOTDIR/tools"      TOOLSDIR="$ROOTDIR/tools"
1652  fi  fi
1653  if test ! -d ${TOOLSDIR} ; then  if test ! -d ${TOOLSDIR} ; then
1654      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
1655      exit 1      exit 1
1656  fi  fi
1657  if test "x$S64" = x ; then  if test "x$S64" = x ; then
1658      S64='$(TOOLSDIR)/set64bitConst.sh'      echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1
1659        RETVAL=$?
1660        if test "x${RETVAL}" = x0 ; then
1661            S64='$(TOOLSDIR)/set64bitConst.sh'
1662        else
1663            echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1
1664            RETVAL=$?
1665            if test "x${RETVAL}" = x0 ; then
1666                S64='$(TOOLSDIR)/set64bitConst.csh'
1667            else
1668                cat <<EOF
1669    
1670    ERROR: neither of the two default scripts:
1671    
1672        ${TOOLSDIR}/set64bitConst.sh
1673        ${TOOLSDIR}/set64bitConst.csh
1674    
1675      are working so please check paths or specify (with \$S64) a
1676      working version of this script.
1677    
1678    EOF
1679                exit 1
1680            fi
1681        fi
1682  fi  fi
1683    THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
1684    
1685  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1686    
# Line 691  EXECUTABLE=${EXECUTABLE:-mitgcmuv} Line 1689  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1689  #  they appear as regular source code  #  they appear as regular source code
1690  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
1691      echo "  Making source files in eesupp from templates"      echo "  Making source files in eesupp from templates"
1692      $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1      ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1
1693      RETVAL=$?      RETVAL=$?
1694      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
1695          rm -f make_eesupp.errors          rm -f make_eesupp.errors
1696      else      else
1697          echo "Error: problem encountered while building source files in eesupp:"          echo "Error: problem encountered while building source files in eesupp:"
1698          cat make_eesupp.errors          cat make_eesupp.errors 1>&2
1699          exit 1          exit 1
1700      fi      fi
1701  fi  fi
1702    
1703    #same for exch2
1704    if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then
1705        echo "  Making source files in exch2 from  templates"
1706        ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1
1707        RETVAL=$?
1708        if test "x${RETVAL}" = x0 ; then
1709            rm -f make_exch2.errors
1710        else
1711            echo "Error: problem encountered while building source files in exch2:"
1712            cat make_exch2.errors 1>&2
1713            exit 1
1714        fi
1715    fi
1716    
1717  printf "\n===  Determining package settings  ===\n"  printf "\n===  Determining package settings  ===\n"
1718  if  test "x${PDEPEND}" = x ; then  if  test "x${PDEPEND}" = x ; then
1719      tmp=$ROOTDIR"/pkg/pkg_depend"      tmp=$ROOTDIR"/pkg/pkg_depend"
# Line 721  echo "  getting package dependency info Line 1733  echo "  getting package dependency info
1733  #  Strip the comments and then convert the dependency file into  #  Strip the comments and then convert the dependency file into
1734  #  two arrays: PNAME, DNAME  #  two arrays: PNAME, DNAME
1735  cat $PDEPEND | sed -e 's/#.*$//g' \  cat $PDEPEND | sed -e 's/#.*$//g' \
1736      | awk 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \      | $AWK 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \
1737      > ./.pd_tmp      > ./.pd_tmp
1738  RETVAL=$?  RETVAL=$?
1739  if test ! "x${RETVAL}" = x0 ; then  if test ! "x${RETVAL}" = x0 ; then
1740      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
1741      exit 1      exit 1
1742  fi  fi
1743  source ./.pd_tmp  . ./.pd_tmp
1744  rm -f ./.pd_tmp  rm -f ./.pd_tmp
1745    
1746  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"
1747  #  file should eventually be added so that, for convenience, one can  #  file should eventually be added so that, for convenience, one can
1748  #  specify groups of packages using names like "ocean" and "atmosphere".  #  specify groups of packages using names like "ocean" and "atmosphere".
1749  echo  -n "  checking default package list:  "  echo "  checking default package list:  "
1750  if test "x${PDEFAULT}" = x ; then  if test "x${PDEFAULT}" = x ; then
1751      for i in "." $MODS ; do      for i in "." $MODS ; do
1752          if test -r $i"/packages.conf" ; then          if test -r $i"/packages.conf" ; then
# Line 747  if test "x${PDEFAULT}" = x ; then Line 1759  if test "x${PDEFAULT}" = x ; then
1759      PDEFAULT="$ROOTDIR/pkg/pkg_default"      PDEFAULT="$ROOTDIR/pkg/pkg_default"
1760  fi  fi
1761  if test "x${PDEFAULT}" = xNONE ; then  if test "x${PDEFAULT}" = xNONE ; then
1762      echo "default packages file disabled"      echo "    default packages file disabled"
1763  else  else
1764      if test ! -r $PDEFAULT ; then      if test ! -r $PDEFAULT ; then
         echo ""  
1765          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""
1766      else      else
1767          echo "  using PDEFAULT=\"$PDEFAULT\""          echo "    using PDEFAULT=\"$PDEFAULT\""
1768          #  Strip the comments and add all the names          #  Strip the comments and add all the names
1769          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | awk '(NF>0){print $0}'`          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
1770          RETVAL=$?          RETVAL=$?
1771          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
1772              echo -n "Error: can't parse default package list "              printf "Error: can't parse default package list "
1773              echo "-- please check PDEFAULT=\"$PDEFAULT\""              echo "-- please check PDEFAULT=\"$PDEFAULT\""
1774              exit 1              exit 1
1775          fi          fi
# Line 766  else Line 1777  else
1777              PACKAGES="$PACKAGES $i"              PACKAGES="$PACKAGES $i"
1778          done          done
1779          echo "    before group expansion packages are: $PACKAGES"          echo "    before group expansion packages are: $PACKAGES"
1780          expand_pkg_groups          RET=1
1781            while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
1782          echo "    after group expansion packages are:  $PACKAGES"          echo "    after group expansion packages are:  $PACKAGES"
1783      fi      fi
1784  fi  fi
1785    
1786  echo "  applying DISABLE settings"  echo "  applying DISABLE settings"
1787    for i in $PACKAGES ; do
1788        echo $i >> ./.tmp_pack
1789    done
1790    for i in `grep  "-" ./.tmp_pack` ; do
1791        j=`echo $i | sed 's/[-]//'`
1792        DISABLE="$DISABLE $j"
1793    done
1794  pack=  pack=
1795  for p in $PACKAGES ; do  for p in $PACKAGES ; do
1796      addit="t"      addit="t"
# Line 788  PACKAGES="$pack" Line 1807  PACKAGES="$pack"
1807  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
1808  echo "" > ./.tmp_pack  echo "" > ./.tmp_pack
1809  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
1810    # Test if each explicitly referenced package exists
1811  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1812      if test ! -d "$ROOTDIR/pkg/$i" ; then      j=`echo $i | sed 's/[-+]//'`
1813        if test ! -d "$ROOTDIR/pkg/$j" ; then
1814          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
1815          exit 1          exit 1
1816      fi      fi
1817      echo $i >> ./.tmp_pack      echo $i >> ./.tmp_pack
1818  done  done
 pack=`cat ./.tmp_pack | sort | uniq`  
 rm -f ./.tmp_pack  
1819  PACKAGES=  PACKAGES=
1820  for i in $pack ; do  for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do
1821      PACKAGES="$PACKAGES $i"      PACKAGES="$PACKAGES $i"
1822  done  done
1823    rm -f ./.tmp_pack
1824  echo "    packages are:  $PACKAGES"  echo "    packages are:  $PACKAGES"
1825    
1826    #  Check availability of NetCDF and then either build the MNC template
1827    #  files or delete mnc from the list of available packages.
1828    echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1
1829    RETVAL=$?
1830    if test "x$RETVAL" = x0 ; then
1831        if test "x$HAVE_NETCDF" != xt ; then
1832            cat <<EOF
1833    
1834    *********************************************************************
1835    WARNING: the "mnc" package was enabled but tests failed to compile
1836      NetCDF applications.  Please check that:
1837    
1838      1) NetCDF is correctly installed for this compiler and
1839      2) the LIBS variable (within the "optfile") specifies the correct
1840           NetCDF library to link against.
1841    
1842      Due to this failure, the "mnc" package is now DISABLED.
1843    *********************************************************************
1844    
1845    EOF
1846            PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
1847            DISABLE="$DISABLE mnc"
1848        else
1849            ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
1850            RETVAL=$?
1851            if test "x${RETVAL}" = x0 ; then
1852                rm -f make_mnc.errors
1853            else
1854                echo "Error: problem encountered while building source files in pkg/mnc:"
1855                cat make_mnc.errors 1>&2
1856                exit 1
1857            fi
1858        fi
1859    fi
1860    
1861  echo "  applying package dependency rules"  echo "  applying package dependency rules"
1862  ck=  ck=
1863  while test "x$ck" != xtt ; do  while test "x$ck" != xtt ; do
# Line 867  while test "x$ck" != xtt ; do Line 1922  while test "x$ck" != xtt ; do
1922              echo "  the dependency rules for \"$dname\""              echo "  the dependency rules for \"$dname\""
1923              exit 1              exit 1
1924          fi          fi
1925          i=$(( $i + 1 ))          i=`echo "$i + 1" | bc -l`
1926            #i=$(( $i + 1 ))
1927      done      done
1928      ck=$ck"t"      ck=$ck"t"
1929  done  done
# Line 886  for i in $PACKAGES ; do Line 1942  for i in $PACKAGES ; do
1942      fi      fi
1943  done  done
1944    
 #  This is compatible with the old genmake.  The "DISABLE_*" flags  
 #  need to be replaced by the "ALLOW_*" flags set below.  
 #  
 # echo -n "  Setting package-specific CPP flags:  "  
 # pkrm=( mom_fluxform mom_vecinv generic_advdiff )  
 # pkrmdef=( -DDISABLE_MOM_FLUXFORM -DDISABLE_MOM_VECINV -DDISABLE_GENERIC_ADVDIFF -DDISABLE_DEBUGMODE )  
 # echo -n "  "  
 # i=0  
 # while test $i -lt "${#pkrm[@]}" ; do  
 #     echo "$PACKAGES" | grep "${pk[$i]}" > /dev/null 2>&1  
 #     RETVAL=$?  
 #     if test "x$RETVAL" = x1 ; then  
 #       DEFINES="$DEFINES ${pkdef[$i]}"  
 #       echo -n " ${pkdef[$i]}"  
 #     fi  
 #     i=$(( $i + 1 ))  
 # done  
 # echo  
   
1945  # Create a list of #define and #undef to enable/disable packages  # Create a list of #define and #undef to enable/disable packages
1946  PACKAGES_DOT_H=PACKAGES_CONFIG.h  PACKAGES_DOT_H=PACKAGES_CONFIG.h
 cat <<EOF >$PACKAGES_DOT_H".tmp"  
 C=== GENMAKE v2 ===  
 C  The following defines have been set by GENMAKE, so please do not  
 C  edit anything below these comments.  In general, you should  
 C  add or remove packages by re-running genmake with different  
 C  "-enable" and/or "-disable" options.  
   
 #ifndef PACKAGES_H  
 #define PACKAGES_H  
   
 C  Packages disabled by genmake:  
 EOF  
1947  #  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
1948  #  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
1949  #  file would eventually be split up so that all package-related #define  #  file would eventually be split up so that all package-related #define
1950  #  statements could be separated and handled only by genmake.  #  statements could be separated and handled only by genmake.
1951  names=`ls -1 "$ROOTDIR/pkg"`  names=`ls -1 "$ROOTDIR/pkg"`
1952  all_pack=  all_pack=
1953    DISABLED_PACKAGES=
1954  for n in $names ; do  for n in $names ; do
1955      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
1956          has_pack="f"          has_pack="f"
# Line 935  for n in $names ; do Line 1961  for n in $names ; do
1961              fi              fi
1962          done          done
1963          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
1964              undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1965              echo "#undef $undef" >> $PACKAGES_DOT_H".tmp"              DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
 #           DEFINES="$DEFINES -U$undef"  
   
 #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  
             case $n in  
                 mom_fluxform)  
                     DEFINES="$DEFINES -DDISABLE_MOM_FLUXFORM"  
                     ;;  
                 mom_vecinv)  
                     DEFINES="$DEFINES -DDISABLE_MOM_VECINV"  
                     ;;  
                 debug)  
                     DEFINES="$DEFINES -DDISABLE_DEBUGMODE"  
                     ;;  
             esac  
 #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  
   
1966          fi          fi
1967      fi      fi
1968  done  done
1969  cat <<EOF >>$PACKAGES_DOT_H".tmp"  ENABLED_PACKAGES=
   
 C  Packages enabled by genmake:  
 EOF  
1970  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1971      def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`      def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1972      echo "#define $def" >> $PACKAGES_DOT_H".tmp"      ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
1973  #eh3 DEFINES="$DEFINES -D$def"  #eh3 DEFINES="$DEFINES -D$def"
1974    
1975  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1976      case $i in      case $i in
1977          aim_v23)          aim_v23)
1978              echo "#define   ALLOW_AIM" >> $PACKAGES_DOT_H".tmp"              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
1979              DEFINES="$DEFINES -DALLOW_AIM"              echo "Warning: ALLOW_AIM is set to enable aim_v23."
             echo "Warning: ALLOW_AIM is set to enable aim_v23. This is REALLY ugly Jean-Michel :-)"  
1980              ;;              ;;
1981      esac      esac
1982  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1983    
1984  done  done
 cat <<EOF >>$PACKAGES_DOT_H".tmp"  
   
 #endif /* PACKAGES_H */  
 EOF  
   
 if test ! -f $PACKAGES_DOT_H ; then  
     mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H  
 else  
     cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H  
     RETVAL=$?  
     if test "x$RETVAL" = x0 ; then  
         rm -f $PACKAGES_DOT_H".tmp"  
     else  
         mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"  
         mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H  
     fi  
 fi  
1985    
1986  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS"
1987  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
1988  if test "x$STANDARDDIRS" = x ; then  if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
1989      STANDARDDIRS="eesupp model"      STANDARDDIRS="eesupp model"
1990  fi  fi
1991  for d in $STANDARDDIRS ; do  if test "x$STANDARDDIRS" != x ; then
1992      adr="$ROOTDIR/$d/src"      for d in $STANDARDDIRS ; do
1993      if test ! -d $adr ; then          adr="$ROOTDIR/$d/src"
1994          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""          if test ! -d $adr ; then
1995          echo "  is correct and that you correctly specified the STANDARDDIRS option"              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1996          exit 1              echo "  is correct and that you correctly specified the STANDARDDIRS option"
1997      else              exit 1
1998          SOURCEDIRS="$SOURCEDIRS $adr"          else
1999      fi              SOURCEDIRS="$SOURCEDIRS $adr"
2000      adr="$ROOTDIR/$d/inc"          fi
2001      if test ! -d $adr ; then          adr="$ROOTDIR/$d/inc"
2002          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""          if test ! -d $adr ; then
2003          echo "  is correct and that you correctly specified the STANDARDDIRS option"              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
2004          exit 1              echo "  is correct and that you correctly specified the STANDARDDIRS option"
2005      else              exit 1
2006          INCLUDEDIRS="$INCLUDEDIRS $adr"          else
2007      fi              INCLUDEDIRS="$INCLUDEDIRS $adr"
2008  done          fi
2009        done
2010    fi
2011    
2012  echo " Searching for CPP_OPTIONS.h in order to warn about the presence"  echo "  Searching for *OPTIONS.h files in order to warn about the presence"
2013  echo " of \"#define ALLOW_PKGNAME\"-type statements:"  echo "    of \"#define \"-type statements that are no longer allowed:"
2014  CPP_OPTIONS=  CPP_OPTIONS=
2015    CPP_EEOPTIONS=
2016  spaths=". $INCLUDEDIRS"  spaths=". $INCLUDEDIRS"
2017    names=`ls -1 "$ROOTDIR/pkg"`
2018  for i in $spaths ; do  for i in $spaths ; do
2019      try="$i/CPP_OPTIONS.h"      try="$i/CPP_OPTIONS.h"
2020      #  echo -n "    trying $try : "      if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
     if test -f $try -a -r $try ; then  
2021          echo "    found CPP_OPTIONS=\"$try\""          echo "    found CPP_OPTIONS=\"$try\""
2022          CPP_OPTIONS="$try"          CPP_OPTIONS="$try"
2023          break          # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
2024            for n in $names ; do
2025                test_for_package_in_cpp_options $CPP_OPTIONS $n
2026            done
2027        fi
2028        try="$i/CPP_EEOPTIONS.h"
2029        if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
2030            echo "    found CPP_EEOPTIONS=\"$try\""
2031            # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
2032    #**** not yet enabled ****
2033    #        test_for_mpi_in_cpp_eeoptions $try
2034    #**** not yet enabled ****
2035            CPP_EEOPTIONS="$try"
2036      fi      fi
2037  done  done
2038  if test "x$CPP_OPTIONS" = x ; then  if test "x$CPP_OPTIONS" = x ; then
2039      echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"      echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
2040      exit 1      exit 1
2041  fi  fi
 # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h  
 names=`ls -1 "$ROOTDIR/pkg"`  
 for n in $names ; do  
     test_for_package_in_cpp_options $CPP_OPTIONS $n  
 done  
   
2042    
2043  #  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
2044  #  compiler.  #  compiler.
# Line 1054  for i in $SOURCEDIRS ; do Line 2052  for i in $SOURCEDIRS ; do
2052          cat $i/$j >> ad_files          cat $i/$j >> ad_files
2053      done      done
2054  done  done
2055    if test ! "x"$FS = "x.f" ; then
2056  cat <<EOF > adjoint_sed      cat ad_files | sed -e "s/\.f/.$FS/g" > ad_files_f
2057  s/call adopen(/call adopen ( mythid,\\      mv -f ad_files_f ad_files
2058       \&           /g  fi
 s/call adclose(/call adclose( mythid,\\  
      \&           /g  
 s/call adread(/call adread ( mythid,\\  
      \&           /g  
 s/call adwrite(/call adwrite( mythid,\\  
      \&           /g  
   
 EOF  
2059    
2060  echo  echo
2061  echo "===  Creating the Makefile  ==="  echo "===  Creating the Makefile  ==="
2062  echo "  setting INCLUDES"  echo "  setting INCLUDES"
2063  for i in $INCLUDEDIRS ; do  for i in $INCLUDEDIRS ; do
2064      if ! test -d $i ; then      if test ! -d $i ; then
 #       INCLUDES="$INCLUDES -I$i"  
 #   else  
2065          echo "Warning: can't find INCLUDEDIRS=\"$i\""          echo "Warning: can't find INCLUDEDIRS=\"$i\""
2066      fi      fi
2067  done  done
2068    
2069    echo "  Creating the pseudo-MPI include directory"
2070    if test ! "x$DIVA" = x ; then
2071        INCLUDES="-I./mpi_headers $INCLUDES"
2072        rm -rf ./mpi_headers
2073        mkdir -p ./mpi_headers
2074    
2075        if test "x$MPIINCLUDEDIR" = x ; then
2076            if test "x$MPIHOME" = x ; then
2077                MPIHOME='/usr'
2078            fi
2079            MPIINCLUDEDIR='$MPIHOME/include'
2080        fi
2081        
2082        if test -r $MPIINCLUDEDIR/mpif.h ; then
2083            for i in $MPI_HEADER_FILES; do
2084                cp -p $MPIINCLUDEDIR/$i ./mpi_headers
2085            done
2086    
2087            perl -i -pe 's/MPI_DISPLACEMENT_CURRENT=-1_8/MPI_DISPLACEMENT_CURRENT=-1/g' mpi_headers/mpif.h
2088        else
2089            echo " We cannot create a copy of mpif.h!"
2090            exit -1
2091        fi
2092    fi
2093    
2094  echo "  Determining the list of source and include files"  echo "  Determining the list of source and include files"
2095  rm -rf .links.tmp  rm -rf .links.tmp
2096  mkdir .links.tmp  mkdir .links.tmp
2097  echo "# This section creates symbolic links" > srclinks.tmp  echo "# This section creates symbolic links" > srclinks.tmp
2098  echo "" >> srclinks.tmp  echo "" >> srclinks.tmp
2099  echo -n 'SRCFILES = '    > srclist.inc  printf 'SRCFILES = '    > srclist.inc
2100  echo -n 'CSRCFILES = '   > csrclist.inc  printf 'CSRCFILES = '   > csrclist.inc
2101  echo -n 'F90SRCFILES = ' > f90srclist.inc  printf 'F90SRCFILES = ' > f90srclist.inc
2102  echo -n 'HEADERFILES = ' > hlist.inc  printf 'HEADERFILES = ' > hlist.inc
2103  echo -n 'AD_FLOW_FILES = ' > ad_flow_files.inc  printf 'AD_FLOW_FILES = ' > ad_flow_files.inc
2104  alldirs="$SOURCEDIRS $INCLUDEDIRS ."  alldirs="$SOURCEDIRS $INCLUDEDIRS ."
2105  for d in $alldirs ; do  for d in $alldirs ; do
2106      deplist=      deplist=
# Line 1096  for d in $alldirs ; do Line 2109  for d in $alldirs ; do
2109      for sf in $sfiles ; do      for sf in $sfiles ; do
2110          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
2111              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
2112                  extn=`echo $sf | awk -F '.' '{print $NF}'`                  ignore_f=f
2113                  touch .links.tmp/$sf                  case $d/$sf in
2114                  deplist="$deplist $sf"                    ./$PACKAGES_DOT_H)
                 case $extn in  
                     F)  
                         echo    " \\"  >> srclist.inc  
                         echo -n " $sf" >> srclist.inc  
2115                          ;;                          ;;
2116                      F90)                    ./AD_CONFIG.h)
                         echo    " \\"  >> f90srclist.inc  
                         echo -n " $sf" >> f90srclist.inc  
2117                          ;;                          ;;
2118                      c)                    ./FC_NAMEMANGLE.h)
                         echo    " \\"  >> csrclist.inc  
                         echo -n " $sf" >> csrclist.inc  
2119                          ;;                          ;;
2120                      h)                    ./BUILD_INFO.h)
                         echo    " \\"  >> hlist.inc  
                         echo -n " $sf" >> hlist.inc  
2121                          ;;                          ;;
2122                      flow)                    *)
2123                          echo    " \\"  >> ad_flow_files.inc                          #  For the local directory *ONLY*,
2124                          echo -n " $sf" >> ad_flow_files.inc                          #  ignore all soft-links
2125                            if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then
2126                                ignore_f=t
2127                            else
2128                                touch .links.tmp/$sf
2129                                deplist="$deplist $sf"
2130                            fi
2131                          ;;                          ;;
2132                  esac                  esac
2133                    if test "x$ignore_f" = xf ; then
2134                        extn=`echo $sf | $AWK -F. '{print $NF}'`
2135                        case $extn in
2136                            F)
2137                                echo    " \\"  >> srclist.inc
2138                                printf " $sf" >> srclist.inc
2139                                ;;
2140                            F90)
2141                                echo    " \\"  >> f90srclist.inc
2142                                printf " $sf" >> f90srclist.inc
2143                                ;;
2144                            c)
2145                                echo    " \\"  >> csrclist.inc
2146                                printf " $sf" >> csrclist.inc
2147                                ;;
2148                            h)
2149                                echo    " \\"  >> hlist.inc
2150                                printf " $sf" >> hlist.inc
2151                                ;;
2152                            flow)
2153                                echo    " \\"  >> ad_flow_files.inc
2154                                printf " $sf" >> ad_flow_files.inc
2155                                ;;
2156                        esac
2157                    fi
2158              fi              fi
2159          fi          fi
2160      done      done
# Line 1138  echo "" >> f90srclist.inc Line 2172  echo "" >> f90srclist.inc
2172  echo "" >> hlist.inc  echo "" >> hlist.inc
2173  echo "" >> ad_flow_files.inc  echo "" >> ad_flow_files.inc
2174    
2175  if test -e $MAKEFILE ; then  if test -f $MAKEFILE ; then
2176      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.bak"
2177  fi  fi
2178  echo "  Writing makefile: $MAKEFILE"  echo "  Writing makefile: $MAKEFILE"
# Line 1147  echo "#    $MACHINE" >> $MAKEFILE Line 2181  echo "#    $MACHINE" >> $MAKEFILE
2181  echo "# This makefile was generated automatically on" >> $MAKEFILE  echo "# This makefile was generated automatically on" >> $MAKEFILE
2182  echo "#    $THISDATE" >> $MAKEFILE  echo "#    $THISDATE" >> $MAKEFILE
2183  echo "# by the command:" >> $MAKEFILE  echo "# by the command:" >> $MAKEFILE
2184  echo "#    $0 $@" >> $MAKEFILE  echo "#    $0 $G2ARGS" >> $MAKEFILE
2185  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
2186  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE  echo "#    ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
2187    
2188    EXE_AD=$EXECUTABLE"_ad"
2189    EXE_FTL=$EXECUTABLE"_ftl"
2190    EXE_SVD=$EXECUTABLE"_svd"
2191    
2192  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2193    #
2194    # OPTFILE="$OPTFILE"
2195  #  #
2196  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
2197  # SOURCEDIRS   : Directories containing the source (.F) files  # SOURCEDIRS   : Directories containing the source (.F) files
# Line 1180  TOOLSDIR    = ${TOOLSDIR} Line 2221  TOOLSDIR    = ${TOOLSDIR}
2221    
2222  #eh3  new defines for the adjoint work  #eh3  new defines for the adjoint work
2223  AUTODIFF    = ${ROOTDIR}/pkg/autodiff  AUTODIFF    = ${ROOTDIR}/pkg/autodiff
2224    EXE_AD      = ${EXE_AD}
2225    EXE_FTL     = ${EXE_FTL}
2226    EXE_SVD     = ${EXE_SVD}
2227    
2228    ENABLED_PACKAGES = ${ENABLED_PACKAGES}
2229    DISABLED_PACKAGES = ${DISABLED_PACKAGES}
2230    
2231    # These files are created by Makefile
2232    SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h
2233    
2234  EOF  EOF
2235    
# Line 1198  KPP = ${KPP} Line 2248  KPP = ${KPP}
2248  FC = ${FC}  FC = ${FC}
2249  # Fortran compiler  # Fortran compiler
2250  F90C = ${F90C}  F90C = ${F90C}
2251    # C compiler
2252    CC = ${CC}
2253  # Link editor  # Link editor
2254  LINK = ${LINK}  LINK = ${LINK} ${LDADD}
2255    
2256  # Defines for CPP  # Defines for CPP
2257  DEFINES = ${DEFINES}  DEFINES = ${DEFINES}
# Line 1220  CFLAGS = ${CFLAGS} Line 2272  CFLAGS = ${CFLAGS}
2272  NOOPTFILES = ${NOOPTFILES}  NOOPTFILES = ${NOOPTFILES}
2273  NOOPTFLAGS = ${NOOPTFLAGS}  NOOPTFLAGS = ${NOOPTFLAGS}
2274  # Flags and libraries needed for linking  # Flags and libraries needed for linking
2275  LIBS = ${LIBS} \$(XLIBS)  LIBS = ${LIBS}
2276  # Name of the Mekfile  # Name of the Mekfile
2277  MAKEFILE=${MAKEFILE}  MAKEFILE=${MAKEFILE}
2278    
# Line 1231  cat csrclist.inc      >> $MAKEFILE Line 2283  cat csrclist.inc      >> $MAKEFILE
2283  cat f90srclist.inc    >> $MAKEFILE  cat f90srclist.inc    >> $MAKEFILE
2284  cat hlist.inc         >> $MAKEFILE  cat hlist.inc         >> $MAKEFILE
2285  cat ad_flow_files.inc >> $MAKEFILE  cat ad_flow_files.inc >> $MAKEFILE
2286  echo               >> $MAKEFILE  echo >> $MAKEFILE
2287  echo 'F77FILES =  $(SRCFILES:.F=.f)'                                           >> $MAKEFILE  echo 'F77FILES =  $(SRCFILES:.F=.'$FS')'      >> $MAKEFILE
2288  echo 'F90FILES =  $(F90SRCFILES:.F90=.f90)'                                    >> $MAKEFILE  echo 'F90FILES =  $(F90SRCFILES:.F90=.'$FS90')' >> $MAKEFILE
2289  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
2290    echo >> $MAKEFILE
2291    echo '.SUFFIXES:' >> $MAKEFILE
2292    echo '.SUFFIXES: .o .'$FS' .p .F .c .'$FS90' .F90' >> $MAKEFILE
2293  rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc  rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc
2294  rm -f ad_flow_files.inc  rm -f ad_flow_files.inc
2295    
2296  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2297    
 .SUFFIXES:  
 .SUFFIXES: .o .f .p .F .c .F90 .f90  
   
2298  all: \$(EXECUTABLE)  all: \$(EXECUTABLE)
2299  \$(EXECUTABLE): \$(OBJFILES)  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(OBJFILES)
2300            @echo Creating \$@ ...
2301          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
2302  depend:  depend:
2303          @make links          @make links
2304          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
2305          ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE)          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2306            -rm -f makedepend.out
2307    
2308    lib: libmitgcmuv.a
2309    
2310    libmitgcmuv.a: \$(OBJFILES)
2311            ar rcv libmitgcmuv.a \$(OBJFILES)
2312    
2313  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES)
2314    
2315  small_f: \$(F77FILES) \$(F90FILES)  small_f: \$(F77FILES) \$(F90FILES)
2316    
# Line 1261  output.txt: \$(EXECUTABLE) Line 2319  output.txt: \$(EXECUTABLE)
2319          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
2320    
2321  clean:  clean:
2322          -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}          -rm -rf *.o *.$FS *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
2323  Clean:  Clean:
2324          @make clean          @make clean
2325          @make cleanlinks          @make cleanlinks
2326          -rm -f Makefile.bak genmake_state genmake_optfile make.log          -rm -f \$(SPECIAL_FILES)
2327            -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak
2328  CLEAN:  CLEAN:
2329          @make Clean          @make Clean
2330          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
2331          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
2332          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
2333          -rm -f \$(EXECUTABLE) output.txt          -rm -f \$(EXECUTABLE) output.txt STD*
2334    
2335  Makefile: makefile  #eh3 Makefile: makefile
2336  makefile:  makefile:
2337          ${0} $@          $THIS_SCRIPT $G2ARGS
2338  cleanlinks:  cleanlinks:
2339          -find . -type l -exec rm {} \;          -find . -type l -exec rm {} \;
2340    
2341  # The normal chain of rules is (  .F - .f - .o  )  # Special targets (SPECIAL_FILES) which are create by make
2342  .F.f:  ${PACKAGES_DOT_H}:
2343            @echo Creating \$@ ...
2344            @$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) > \$@
2345    AD_CONFIG.h:
2346            @echo Creating \$@ ...
2347            @$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 > \$@
2348    FC_NAMEMANGLE.h:
2349            @echo Creating \$@ ...
2350            echo "$FC_NAMEMANGLE" > \$@
2351    
2352    BUILD_INFO.h:
2353            @echo Creating \$@ ...
2354    EOF
2355    
2356    test ! "x$THISVER" = x  && echo "       -echo \"#define THISVER '$THISVER'\" > \$@"   >> $MAKEFILE
2357    test ! "x$THISUSER" = x && echo "       -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE
2358    test ! "x$THISDATE" = x && echo "       -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
2359    test ! "x$THISHOST" = x && echo "       -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
2360    
2361    cat >>$MAKEFILE <<EOF
2362    
2363    # The normal chain of rules is (  .F - .$FS - .o  )
2364    
2365    ## This nullifies any default implicit rules concerning these two file types:
2366    ## %.o : %.F
2367    
2368    .F.$FS:
2369          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2370  .f.o:  .$FS.o:
2371          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2372  .F90.f90:  .F90.$FS90:
2373          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2374  .f90.o:  .$FS90.o:
2375          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
2376  .c.o:  .c.o:
2377          \$(CC) \$(CFLAGS) -c \$<          \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$<
2378    
2379  # Special exceptions that use the ( .F - .p - .f - .o ) rule-chain  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
2380  .F.p:  .F.p:
2381          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2382  .p.f:  .p.$FS:
2383          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
2384    
2385  #=========================================  #=========================================
# Line 1303  cleanlinks: Line 2388  cleanlinks:
2388  TAMC           = ${TAMC}  TAMC           = ${TAMC}
2389  TAF            = ${TAF}  TAF            = ${TAF}
2390    
2391    TAF_EXTRA      = ${TAF_EXTRA}
2392    TAMC_EXTRA     = ${TAMC_EXTRA}
2393    
2394  EOF  EOF
2395    
2396  ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"  ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
# Line 1318  done Line 2406  done
2406    
2407  echo "  Add the source list for AD code generation"  echo "  Add the source list for AD code generation"
2408  echo >> $MAKEFILE  echo >> $MAKEFILE
2409  echo -n "AD_FILES = " >> $MAKEFILE  printf "AD_FILES = " >> $MAKEFILE
2410  AD_FILES=`cat ad_files`  AD_FILES=`cat ad_files`
2411  for i in $AD_FILES ; do  for i in $AD_FILES ; do
2412      echo    " \\" >> $MAKEFILE      echo    " \\" >> $MAKEFILE
2413      echo -n " $i" >> $MAKEFILE      printf " $i" >> $MAKEFILE
2414  done  done
2415  echo >> $MAKEFILE  echo >> $MAKEFILE
2416    rm -f ad_files
2417    
2418  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2419    
2420    # ... AD ...
2421  ad_input_code.f: \$(F77FILES)  adall: ad_taf
2422    adtaf: ad_taf_output.$FS
2423    adtamc: ad_tamc_output.$FS
2424    
2425    ad_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)
2426            @$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
2427            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
2428            -rm -f ad_config.template
2429            @make \$(F77FILES)
2430          @make \$(AD_FLOW_FILES)          @make \$(AD_FLOW_FILES)
2431          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.$FS
2432    
2433    ad_taf_output.$FS: ad_input_code.$FS
2434  ad_taf_output.f: ad_input_code.f          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2435          \$(TAF) \$(AD_TAF_FLAGS) ad_input_code.f          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
2436          cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f  
2437    adtafonly:
2438            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2439            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
2440    
2441  ad_taf: ad_taf_output.o \$(OBJFILES)  ad_taf: ad_taf_output.o \$(OBJFILES)
2442          \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
   
2443    
2444  ad_tamc_output.f: ad_input_code.f  ad_tamc_output.$FS: ad_input_code.$FS
2445          \$(TAMC) \$(AD_TAMC_FLAGS) ad_input_code.f          \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
2446          cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS
2447    
2448  ad_tamc: ad_tamc_output.o \$(OBJFILES)  ad_tamc: ad_tamc_output.o \$(OBJFILES)
2449          \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
   
2450    
2451  flt_taf_output.f: ad_input_code.f  adonlyfwd:
2452          \$(TAF) \$(FTL_TAF_FLAGS) ad_input_code.f          patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
2453          cat ad_input_code_ad.f | sed -f adjoint_sed > flt_taf_output.f  
2454    adtrick:
2455  flt_taf: flt_taf_output.o \$(OBJFILES)          patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
         \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) flt_taf_output.o \$(LIBS)  
2456    
2457    # ... FTL ...
2458    ftlall: ftl_taf
2459    ftltaf: ftl_taf_output.$FS
2460    ftltamc: ftl_tamc_output.$FS
2461    
2462    ftl_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)
2463            @$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
2464            cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
2465            -rm -f ftl_config.template
2466            @make \$(F77FILES)
2467            @make \$(AD_FLOW_FILES)
2468            cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.$FS
2469    
2470    ftl_taf_output.$FS: ftl_input_code.$FS
2471            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2472            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2473    
2474    ftltafonly:
2475            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2476            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2477    
2478    ftl_taf: ftl_taf_output.o \$(OBJFILES)
2479            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
2480    
2481    ftl_tamc_output.$FS: ftl_input_code.$FS
2482            \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
2483            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS
2484    
2485    ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
2486            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
2487    
2488    
2489    # ... SVD ...
2490    svdtaf: ad_taf_output.$FS ftl_taf_output.$FS
2491            @echo "--->>> Only ran TAF to generate SVD code!    <<<---"
2492            @echo "--->>> Do make svdall afterwards to compile. <<<---"
2493    svdall: svd_touch svd_taf
2494    
2495    svd_taf: \$(OBJFILES)
2496            \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
2497    
2498            @echo "--->>> Only COMPILE svd code! <<<---"
2499            @echo "--->>> Assumes you previously <<<---"
2500            @echo "--->>> did make svdtaf        <<<---"
2501    
2502    svd_touch:
2503            @echo "--->>> Only COMPILE svd code! <<<---"
2504            @echo "--->>> Assumes you previously <<<---"
2505            @echo "--->>> did make svdtaf        <<<---"
2506            touch ad_taf_output.$FS ftl_taf_output.$FS
2507            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS
2508            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS
2509            @$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
2510            cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
2511            -rm -f ftl_config.template
2512    
2513  #=========================================  #=========================================
2514    
# Line 1374  for i in $KPPFILES ; do Line 2525  for i in $KPPFILES ; do
2525      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
2526          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
2527      fi      fi
2528      echo "$base.f: $base.p" >> $MAKEFILE      echo "$base.$FS: $base.p" >> $MAKEFILE
2529  done  done
2530    
2531  echo "  Making list of NOOPTFILES"  echo "  Making list of NOOPTFILES"
# Line 1384  for i in $NOOPTFILES ; do Line 2535  for i in $NOOPTFILES ; do
2535      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
2536          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
2537      fi      fi
2538      echo "$base.o: $base.f" >> $MAKEFILE      echo "$base.o: $base.$FS" >> $MAKEFILE
2539      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
2540  done  done
2541    
# Line 1397  printf "\n\n# DO NOT DELETE\n" >> $MAKEF Line 2548  printf "\n\n# DO NOT DELETE\n" >> $MAKEF
2548    
2549  printf "\n===  Done  ===\n"  printf "\n===  Done  ===\n"
2550    
2551    # Create special header files
2552    $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"
2553    if test ! -f $PACKAGES_DOT_H ; then
2554        mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2555    else
2556        cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
2557        RETVAL=$?
2558        if test "x$RETVAL" = x0 ; then
2559            rm -f $PACKAGES_DOT_H".tmp"
2560        else
2561            mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
2562            mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2563        fi
2564    fi
2565    if test ! -f AD_CONFIG.h ; then
2566        $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
2567    fi
2568    
2569    
2570  #  Write the "state" for future records  #  Write the "state" for future records
2571  if test "x$DUMPSTATE" != xf ; then  if test "x$DUMPSTATE" != xf ; then
2572      echo -n "" > genmake_state      printf "" > genmake_state
2573      for i in $gm_state ; do      for i in $gm_state ; do
2574          t1="t2=\$$i"          t1="t2=\$$i"
2575          eval $t1          eval $t1

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.139

  ViewVC Help
Powered by ViewVC 1.1.22