/[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.13.2.6 by edhill, Tue Oct 21 03:06:07 2003 UTC revision 1.146 by edhill, Fri Apr 7 02:53:55 2006 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[ ]"
17      RETVAL=$?      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg[ ]"
18      if test "x${RETVAL}" = x0 ; then      test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg[ ]"
19          echo "Error: In $cpp_options there is an illegal line: #define ALLOW_$pkg"      test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg[ ]"
20          exit 99      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg$"
21      fi      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg$"
22      grep -i "#undef.*ALLOW_$pkg" $cpp_options > /dev/null 2>&1      test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg$"
23      RETVAL=$?      test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg$"
24      if test "x${RETVAL}" = x0 ; then  }
25          echo "Error: In $cpp_options there is an illegal line: #undef ALLOW_$pkg"  
26          exit 99  # Search for particular CPP #cmds associated with MPI
27      fi  # usage: test_for_mpi_in_cpp_eeoptions CPP_file
28      grep -i "#define.*DISABLE_$pkg" $cpp_options > /dev/null 2>&1  test_for_mpi_in_cpp_eeoptions() {
29        cpp_options=$1
30        test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI[ ]"
31        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI[ ]"
32        test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI[ ]"
33        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI[ ]"
34        test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI$"
35        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI$"
36        test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI$"
37        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI$"
38    }
39    
40    # Search for particular string in a file. Return 1 if detected, 0 if not
41    # usage: test_for_string_in_file file string
42    test_for_string_in_file() {
43        file=$1
44        strng=$2
45        grep -i "$strng" $file > /dev/null 2>&1
46      RETVAL=$?      RETVAL=$?
47      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
48          echo "Error: In $cpp_options there is an illegal line: #define DISABLE_$pkg"          printf "Error: In $file there is an illegal line: "
49            grep -i "$strng" $file
50          exit 99          exit 99
51      fi      fi
52      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  
53  }  }
54    
55  # 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 59  expand_pkg_groups() {
59      PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups"      PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups"
60      if test -r $PKG_GROUPS ; then      if test -r $PKG_GROUPS ; then
61          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
62          cat ./p1.tmp | awk '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp          cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp
63          matched=0          matched=0
64          for i in $PACKAGES ; do          for i in $PACKAGES ; do
65              line=`grep "^ *$i" ./p2.tmp`              line=`grep "^ *$i" ./p2.tmp`
66              RETVAL=$?              RETVAL=$?
67              if test "x$RETVAL" = x0 ; then              if test "x$RETVAL" = x0 ; then
68                  matched=1                  matched=1
69                  replace=`echo $line | awk '{ $1=""; $2=""; print $0 }'`                  replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`
70                  echo "    replacing \"$i\" with: $replace"                  echo "    replacing \"$i\" with: $replace"
71                  new_packages="$new_packages $replace"                  new_packages="$new_packages $replace"
72              else              else
# Line 62  expand_pkg_groups() { Line 75  expand_pkg_groups() {
75          done          done
76          PACKAGES=$new_packages          PACKAGES=$new_packages
77          rm -f ./p[1,2].tmp          rm -f ./p[1,2].tmp
78            return $matched
79      else      else
80          echo "Warning: can't read package groups definition file: $PKG_GROUPS"          echo "Warning: can't read package groups definition file: $PKG_GROUPS"
81      fi      fi
82  }  }
83    
84    #  Check for broken environments (eg. cygwin, MacOSX w/HFS+) that
85    #  cannot distinguish [*.F/*.F90] from [*.f/*.f90] files.
86    check_for_broken_Ff()  {
87        #  Do we have defaults for $FS and/or $FS90 ?
88        tfs=f
89        tfs9=f90
90        if test "x$FS" != x ; then
91            tfs="$FS"
92        fi
93        if test "x$FS90" != x ; then
94            tfs9="$FS90"
95        fi
96    
97        #  First check the ability to create a *.F/.f pair.
98        cat <<EOF >> genmake_hello.F
99          program hello
100          write(*,*) 'hi'
101          stop
102          end
103    EOF
104        cp genmake_hello.F "genmake_hello."$tfs > /dev/null 2>&1
105        RETVAL=$?
106        if test "x$RETVAL" != x0 ; then
107            if test "x$FS" = x ; then
108                FS='for'
109                FS90='fr9'
110                check_for_broken_Ff
111            else
112                cat <<EOF 2>&1
113    ERROR: Your file system cannot distinguish between *.F and *.f files
114      (fails the "cp" test) and this program cannot find a suitable
115      replacement extension.  Please try a different build environment or
116      contact the <MITgcm-support@mitgcm.org> list for help.
117    
118    EOF
119                exit -1
120            fi
121            return
122        fi
123        rm -f genmake_hello.*
124    
125        #  Check the ability of ${MAKE} and ${LN} to use the current set
126        #  of extensions.
127        cat <<EOF >> genmake_hello.F
128          program hello
129          write(*,*) 'hi'
130          stop
131          end
132    EOF
133        test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
134        cat <<EOF >> $MAKEFILE
135    .SUFFIXES:
136    .SUFFIXES: .$tfs .F
137    .F.$tfs:
138            $LN \$< \$@
139    EOF
140        $MAKE "genmake_hello."$tfs > /dev/null 2>&1
141        RETVAL=$?
142        if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then
143            if test "x$FS" = x ; then
144                FS='for'
145                FS90='fr9'
146                check_for_broken_Ff
147            else
148                cat <<EOF 2>&1
149    ERROR: Your file system cannot distinguish between *.F and *.f files
150      (fails the "make/ln" test) and this program cannot find a suitable
151      replacement extension.  Please try a different build environment or
152      contact the <MITgcm-support@mitgcm.org> list for help.
153    
154    EOF
155                exit -1
156                return
157            fi
158        fi
159        rm -f genmake_hello.* $MAKEFILE
160        test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
161    
162        #  If we make it here, use the extensions
163        FS=$tfs
164        FS90=$tfs9
165        return
166    }
167    
168    
169    look_for_makedepend()  {
170    
171        #  The "original" makedepend is part of the Imake system that is
172        #  most often distributed with XFree86 or with an XFree86 source
173        #  package.  As a result, many machines (eg. generic Linux) do not
174        #  have a system-default "makedepend" available.  For those
175        #  systems, we have two fall-back options:
176        #
177        #    1) a makedepend implementation shipped with the cyrus-imapd
178        #       package:  ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
179        #
180        #    2) a known-buggy xmakedpend shell script
181        #
182        #  So the choices are, in order:
183        #
184        #    1) use the user-specified program
185        #    2) use a system-wide default
186        #    3) locally build and use the cyrus implementation
187        #    4) fall back to the buggy local xmakedpend script
188        #
189        if test "x${MAKEDEPEND}" = x ; then
190            which makedepend > /dev/null 2>&1
191            RV0=$?
192            test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
193            #  echo 'MAKEFILE="'$MAKEFILE'"'
194            cat <<EOF >> $MAKEFILE
195    #   THIS IS A TEST MAKEFILE GENERATED BY "genmake2"
196    #
197    #   Some "makedepend" implementations will die if they cannot
198    #   find a Makefile -- so this file is here to gives them an
199    #   empty one to find and parse.
200    EOF
201            cat <<EOF >> genmake_tc.f
202          program test
203          write(*,*) 'test'
204          stop
205          end
206    EOF
207            makedepend genmake_tc.f > /dev/null 2>&1
208            RV1=$?
209            test -f $MAKEFILE  &&  rm -f $MAKEFILE
210            test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
211            if test "x${RV0}${RV1}" = x00 ; then
212                MAKEDEPEND=makedepend
213            else
214                echo "    a system-default makedepend was not found."
215                
216                #  Try to build the cyrus implementation
217                build_cyrus_makedepend
218                RETVAL=$?
219                if test "x$RETVAL" != x0 ; then
220                    MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
221                fi
222                rm -f ./genmake_cy_md
223            fi
224        else
225            #  echo "MAKEDEPEND=${MAKEDEPEND}"
226            echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1
227            RETVAL=$?
228            if test x"$RETVAL" = x0 ; then
229                build_cyrus_makedepend
230            fi
231        fi
232    }
233    
234    
235    build_cyrus_makedepend()  {
236        rm -f ./genmake_cy_md
237        (
238            cd $ROOTDIR/tools/cyrus-imapd-makedepend  \
239                &&  ./configure > /dev/null 2>&1  \
240                &&  make > /dev/null 2>&1
241            if test -x ./makedepend.exe ; then
242                $LN ./makedepend.exe ./makedepend
243            fi
244            ./makedepend ifparser.c > /dev/null 2>&1  \
245                &&  echo "true"
246        ) > ./genmake_cy_md
247        grep true ./genmake_cy_md > /dev/null 2>&1
248        RETVAL=$?
249        rm -f ./genmake_cy_md
250        if test "x$RETVAL" = x0 ; then
251            MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
252            return 0
253        else
254            echo "WARNING: unable to build cyrus-imapd-makedepend"
255            return 1
256        fi
257    }
258    
259    
260    build_embed_encode()
261    {
262        printf "  building the embed-encode utility...  "
263        if test ! -e "$ROOTDIR/tools/embed_encode/encode_files" ; then
264            if test ! -d "$ROOTDIR/tools/embed_encode" ; then
265                echo
266                echo "    Error: can't locate \"$ROOTDIR/tools/embed_encode\""
267                echo
268                EMBED_SRC=f
269                return 1
270            fi
271            clist="cc gcc c89 $CC"
272            for ic in $clist ; do
273                comm="$ic -o encode_files encode_files.c"
274                ( cd $ROOTDIR/tools/embed_encode && $comm ) > /dev/null 2>&1
275                RETVAL=$?
276                if test "x$RETVAL" = x0 ; then
277                    echo "OK"
278                    DEFINES="$DEFINES -DHAVE_EMBED_SRC"
279                    return 0
280                fi
281            done
282            echo
283            echo "    Error: unable to build $ROOTDIR/embed_encode/encode_files"
284            echo "      so it has been disabled"
285            echo
286            EMBED_SRC=f
287            return 1
288        fi
289        echo "OK"
290        DEFINES="$DEFINES -DHAVE_EMBED_SRC"
291    }
292    
293    
294  # Guess possible config options for this host  # Guess possible config options for this host
295  find_possible_configs()  {  find_possible_configs()  {
296    
297      tmp1=`uname`"_"`uname -m`      tmp1=`uname`"_"`uname -m`
298      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
299      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/'`
300        tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
301        tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
302        tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
303        PLATFORM=$tmp3
304        echo $PLATFORM | grep cygwin > /dev/null 2>&1  &&  PLATFORM=cygwin_ia32
305      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
306      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  
307            
308      echo "test" > test      echo "test" > test
309      ln -s ./test link      ln -s ./test link
# Line 103  find_possible_configs()  { Line 321  find_possible_configs()  {
321          CPP="cpp -traditional -P"          CPP="cpp -traditional -P"
322      fi      fi
323    
324      # look for possible fortran compilers      look_for_makedepend
325      tmp="$MITGCM_FC $FC g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"  
326        #================================================================
327        #  look for possible C compilers
328        tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc"
329        p_CC=
330        for c in $tmp ; do
331            rm -f ./genmake_hello.c  ./genmake_hello
332            cat >> genmake_hello.c << EOF
333    #include <stdio.h>
334    int main(int argc, char **argv) {
335      printf("Hello!\n");
336      return 0;
337    }
338    EOF
339            $c -o genmake_hello genmake_hello.c > /dev/null 2>&1
340            RETVAL=$?
341            if test "x${RETVAL}" = x0 ; then
342                p_CC="$p_CC $c"
343            fi
344        done
345        rm -f ./genmake_hello.c ./genmake_hello
346        if test "x${p_CC}" = x ; then
347            cat 1>&2 <<EOF
348    
349    Error: No C compilers were found in your path.  Please specify one using:
350    
351        1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
352        2) the CC or MITGCM_CC environment variables.
353    
354    EOF
355            exit 1
356        else
357            echo "  The possible C compilers found in your path are:"
358            echo "   "$p_CC
359            if test "x$CC" = x ; then
360                CC=`echo $p_CC | $AWK '{print $1}'`
361                echo "  Setting C compiler to: "$CC
362            fi
363        fi
364    
365        #================================================================
366        #  look for possible FORTRAN compilers
367        tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 gfortran"
368      p_FC=      p_FC=
369      for c in $tmp ; do      for c in $tmp ; do
370          rm -f ./hello.f ./hello          rm -f ./hello.f ./hello
# Line 121  EOF Line 381  EOF
381              p_FC="$p_FC $c"              p_FC="$p_FC $c"
382          fi          fi
383      done      done
384        rm -f ./hello.f ./hello
385      if test "x${p_FC}" = x ; then      if test "x${p_FC}" = x ; then
386          cat 1>&2 <<EOF          cat 1>&2 <<EOF
387    
# Line 128  Error: No Fortran compilers were found i Line 389  Error: No Fortran compilers were found i
389    
390      1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),      1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
391      2) a command-line option (eg. "-fc NAME"), or      2) a command-line option (eg. "-fc NAME"), or
392      3) the MITGCM_FC environment variable.      3) the FC or MITGCM_FC environment variables.
393    
394  EOF  EOF
395          exit 1          exit 1
396      else      else
397          echo "  The possible FORTRAN compilers found in your path are:"          echo "  The possible FORTRAN compilers found in your path are:"
398          echo "   "$p_FC          echo "   "$p_FC
         if test "x$FC" = x ; then  
             FC=`echo $p_FC | awk '{print $1}'`  
         fi  
399      fi      fi
400    
401      for i in $p_FC ; do      #  Use the first of the compilers found in the current PATH
402          p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i      #  that has a correctly-named optfile
403          if test -r $p_OF ; then      if test "x$OPTFILE" = x  -a  "x$FC" = x ; then
404              OPTFILE=$p_OF          for i in $p_FC ; do
405              echo "  The options file:  $p_OF"              OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
406              echo "    appears to match so we'll use it."              if test -r $OPTFILE ; then
407              break                  echo "  Setting OPTFILE to: "$OPTFILE
408          fi                  break
409      done              fi
410            done
411        fi
412    
413        if test "x$OPTFILE" = x ; then
414            OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
415            if test ! -r $OPTFILE ; then
416                 echo "  I looked for the file "$OPTFILE" but did not find it"
417            fi
418        fi
419    #    echo "  The options file:  $p_OF"
420    #    echo "    appears to match so we'll use it."
421    #   for i in $p_FC ; do
422    #p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
423    #if test -r $p_OF ; then
424    #    OPTFILE=$p_OF
425    #    echo "  The options file:  $p_OF"
426    #    echo "    appears to match so we'll use it."
427    #    break
428    #fi
429    #   done
430      if test "x$OPTFILE" = x ; then      if test "x$OPTFILE" = x ; then
431          cat 1>&2 <<EOF          cat 1>&2 <<EOF
432    
# Line 202  get_pdepend_list()  { Line 480  get_pdepend_list()  {
480      #  strip the comments and then convert the dependency file into      #  strip the comments and then convert the dependency file into
481      #  two arrays: PNAME, DNAME      #  two arrays: PNAME, DNAME
482      cat $1 | sed -e 's/#.*$//g' \      cat $1 | sed -e 's/#.*$//g' \
483          | 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} }' \
484          > ./.pd_tmp          > ./.pd_tmp
485      source ./.pd_tmp      . ./.pd_tmp
486      rm -f ./.pd_tmp      rm -f ./.pd_tmp
487    
488      echo -n "PNAME = "${}      printf "PNAME = "${}
489  }  }
490    
491    
492  #  Explain usage  #  Explain usage
493  usage()  {  usage()  {
494      echo  cat <<EOF
495      echo "Usage: "$0" [OPTIONS]"  
496      echo "  where [OPTIONS] can be:"  Usage: "$0" [OPTIONS]
497      echo    where [OPTIONS] can be:
498      echo "    -help | --help | -h | --h"  
499      echo "    -nooptfile | --nooptfile"      -help | --help | -h | --h
500      echo "      -optfile NAME | --optfile NAME | -of NAME | --of NAME"            Print this help message and exit.
501      echo "      -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME"  
502      echo "    -pdepend NAME | --pdepend NAME"      -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME
503      echo "      -pdepend=NAME | --pdepend=NAME"        -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME
504      echo "    -pdefault NAME | --pdefault NAME"            Use "NAME" as the adoptfile.  By default, the file at
505      echo "      -pdefault=NAME | --pdefault=NAME"            "tools/adjoint_options/adjoint_default" will be used.
506      echo "    -make NAME | -m NAME"  
507      echo "      --make=NAME | -m=NAME"      -nooptfile | --nooptfile
508      echo "    -makefile NAME | -mf NAME"        -optfile NAME | --optfile NAME | -of NAME | --of NAME
509      echo "      --makefile=NAME | -mf=NAME"        -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
510      echo "    -platform NAME | --platform NAME | -pl NAME | --pl NAME"            Use "NAME" as the optfile.  By default, an attempt will be
511      echo "      -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"            made to find an appropriate "standard" optfile in the
512      echo "    -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"            tools/build_options/ directory.
513      echo "      -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME"  
514      echo "    -mods NAME | --mods NAME | -mo NAME | --mo NAME"      -pdepend NAME | --pdepend NAME
515      echo "      -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME"        -pdepend=NAME | --pdepend=NAME
516      echo "    -disable NAME | --disable NAME"            Get package dependency information from "NAME".
517      echo "      -disable=NAME | --disable=NAME"  
518      echo "    -enable NAME | --enable NAME"      -pdefault NAME | --pdefault NAME
519      echo "      -enable=NAME | --enable=NAME"        -pdefault=NAME | --pdefault=NAME
520      echo "    -standarddirs NAME | --standarddirs NAME"            Get the default package list from "NAME".
521      echo "      -standarddirs=NAME | --standarddirs=NAME"  
522      echo "    -noopt NAME | --noopt NAME"      -make NAME | -m NAME
523      echo "      -noopt=NAME | --noopt=NAME"        --make=NAME | -m=NAME
524  #    echo "    -cpp NAME | --cpp NAME"            Use "NAME" for the MAKE program. The default is "make" but
525  #    echo "      -cpp=NAME | --cpp=NAME"            many platforms, "gmake" is the preferred choice.
526      echo "    -fortran NAME | --fortran NAME | -fc NAME | --fc NAME"  
527      echo "      -fc=NAME | --fc=NAME"      -makefile NAME | -mf NAME
528      echo "    -[no]ieee | --[no]ieee"        --makefile=NAME | -mf=NAME
529      echo "    -[no]mpi | --[no]mpi"            Call the makefile "NAME".  The default is "Makefile".
530      echo "    -[no]jam | --[no]jam"  
531      echo      -makedepend NAME | -md NAME
532      echo "  and NAME is a string such as:"        --makedepend=NAME | -md=NAME
533      echo            Use "NAME" for the MAKEDEPEND program.
534      echo "    --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'"  
535      echo "    -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'"      -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
536      echo "    -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"        -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
537      echo            Specify the location of the MITgcm ROOTDIR as "NAME".
538      echo "  which, depending upon your shell, may need to be single-quoted"            By default, genamke will try to find the location by
539      echo "  if it contains spaces, dashes, or other special characters."            looking in parent directories (up to the 5th parent).
540    
541        -mods NAME | --mods NAME | -mo NAME | --mo NAME
542          -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
543              Here, "NAME" specifies a list of directories that are
544              used for additional source code.  Files found in the
545              "mods list" are given preference over files of the same
546              name found elsewhere.
547    
548        -disable NAME | --disable NAME
549          -disable=NAME | --disable=NAME
550              Here "NAME" specifies a list of packages that we don't
551              want to use.  If this violates package dependencies,
552              genamke will exit with an error message.
553    
554        -enable NAME | --enable NAME
555          -enable=NAME | --enable=NAME
556              Here "NAME" specifies a list of packages that we wish
557              to specifically enable.  If this violates package
558              dependencies, genamke will exit with an error message.
559    
560        -standarddirs NAME | --standarddirs NAME
561          -standarddirs=NAME | --standarddirs=NAME
562              Here, "NAME" specifies a list of directories to be
563              used as the "standard" code.
564    
565        -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
566          -fc=NAME | --fc=NAME
567              Use "NAME" as the fortran compiler.  By default, genmake
568              will search for a working compiler by trying a list of
569              "usual suspects" such as g77, f77, etc.
570    
571        -cc NAME | --cc NAME | -cc=NAME | --cc=NAME
572              Use "NAME" as the C compiler.  By default, genmake
573              will search for a working compiler by trying a list of
574              "usual suspects" such as gcc, c89, cc, etc.
575    
576        -[no]ieee | --[no]ieee
577              Do or don't use IEEE numerics.  Note that this option
578              *only* works if it is supported by the OPTFILE that
579              is being used.
580    
581        -ignoretime | -ignore_time | --ignoretime | --ignore_time
582              Ignore all the "wall clock" routines entirely.  This will
583              not in any way hurt the model results -- it simply means
584              that the code that checks how long the model spends in
585              various routines will give junk values.
586    
587        -ts | --ts
588              Produce timing information per timestep
589        -papis | --papis
590              Produce summary MFlop/s with PAPI per timestep
591        -foolad | --foolad
592              Fool the AD code generator
593        -papi | --papi
594              Performance analysis with PAPI
595        -hpmt | --hpmt
596              Performance analysis with the HPM Toolkit
597    
598        -gsl | --gsl
599              Use GSL to control floating point rounding and precision
600    
601        -mpi | --mpi
602              Include MPI header files and link to MPI libraries
603        -mpi=PATH | --mpi=PATH
604              Include MPI header files and link to MPI libraries using MPI_ROOT
605              set to PATH. i.e. Include files from \$PATH/include, link to libraries
606              from \$PATH/lib and use binaries from \$PATH/bin.
607    
608        -es | --es | -embed-source | --embed-source
609              Embed a tarball containing the full source code
610              (including the Makefile, etc.) used to build the
611              executable [off by default]
612    
613        -bash NAME
614              Explicitly specify the Bourne or BASH shell to use
615    
616      While it is most often a single word, the "NAME" variables specified
617      above can in many cases be a space-delimited string such as:
618    
619        --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'
620        -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'
621        -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
622    
623      which, depending upon your shell, may need to be single-quoted.
624    
625      For more detailed genmake documentation, please see:
626    
627        http://mitgcm.org/devel_HOWTO/
628    
629    EOF
630    
631      exit 1      exit 1
632  }  }
633    
634  #eh3 # This is the generic configuration.  #  Build a CPP macro to automate calling C routines from FORTRAN
635  #eh3 set LN         = ( 'ln -s' )  get_fortran_c_namemangling()  {
636  #eh3 set CPP        = ( '/lib/cpp -P' )  
637  #eh3 set S64        = ( '$(TOOLSDIR)/set64bitConst.sh' )      #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
638  #eh3 set KPP        = (  )      if test ! "x$FC_NAMEMANGLE" = x ; then
639  #eh3 set FC         = ( 'f77' )          return 0
640  #eh3 set LINK       = $FC      fi
641  #eh3 set MAKEDEPEND = ( 'makedepend' )  
642  #eh3 set INCLUDES   = ( -I. )      default_nm="#define FC_NAMEMANGLE(X) X ## _"
643  #eh3 set FFLAGS     = (  )      
644  #eh3 set FOPTIM     = (  )      cat > genmake_test.c <<EOF
645  #eh3 set CFLAGS     = (  )  void tcall( char * string ) { tsub( string ); }
646  #eh3 set KFLAGS1    = (  )  EOF
647  #eh3 set KFLAGS2    = (  )      $MAKE genmake_test.o >> genmake_warnings 2>&1
648  #eh3 set LIBS       = (  )      RETVAL=$?
649  #eh3 set KPPFILES   = (  )      if test "x$RETVAL" != x0 ; then
650  #eh3 if (! $?NOOPTFILES ) set NOOPTFILES = (  )          FC_NAMEMANGLE=$default_nm
651  #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = (  )          cat <<EOF>> genmake_errors
652    
653    WARNING: C test compile fails
654    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
655    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
656    EOF
657            return 1
658        fi
659        c_tcall=`nm genmake_test.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
660        RETVAL=$?
661        if test "x$RETVAL" != x0 ; then
662            FC_NAMEMANGLE=$default_nm
663            cat <<EOF>> genmake_warnings
664    
665    WARNING: The "nm" command failed.
666    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
667    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
668    EOF
669            return 1
670        fi
671        cat > genmake_tcomp.$FS <<EOF
672          subroutine tcall( string )
673          character*(*) string
674          call tsub( string )
675          end
676    EOF
677        $FC $FFLAGS -c genmake_tcomp.$FS >> genmake_warnings 2>&1
678        RETVAL=$?
679        if test "x$RETVAL" != x0 ; then
680            FC_NAMEMANGLE=$default_nm
681            cat <<EOF>> genmake_warnings
682    
683    WARNING: FORTRAN test compile fails -- please see "genmake_errors"
684    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
685    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
686    EOF
687            return 1
688        fi
689        f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
690        RETVAL=$?
691        if test "x$RETVAL" != x0 ; then
692            FC_NAMEMANGLE=$default_nm
693            cat <<EOF>> genmake_warnings
694    
695    WARNING: The "nm" command failed.
696    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
697    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
698    EOF
699            return 1
700        fi
701    
702        c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
703        f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
704        c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
705        f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
706    
707        nmangle="X"
708        if test "x$c_a" != "x$f_a" ; then
709            comm="echo x$f_a | sed -e 's|x$c_a||'"
710            a=`eval $comm`
711            nmangle="$a ## $nmangle"
712        fi
713        if test "x$c_b" != "x$f_b" ; then
714            comm="echo x$f_b | sed -e 's|x$c_b||'"
715            b=`eval $comm`
716            nmangle="$nmangle ## $b"
717        fi
718    
719        FC_NAMEMANGLE="#define FC_NAMEMANGLE(X)  $nmangle"
720    
721        #  cleanup the testing files
722        rm -f genmake_tcomp.* genmake_test.*
723    }
724    
725    
726    check_HAVE_CLOC()  {
727        get_fortran_c_namemangling
728        cat <<EOF > genmake_tc_1.c
729    $FC_NAMEMANGLE
730    #include <stdio.h>
731    #include <stdlib.h>
732    #include <unistd.h>
733    #include <assert.h>
734    #include <sys/time.h>
735    void FC_NAMEMANGLE(cloc) ( double *curtim )
736    {
737     struct timeval tv1;
738     gettimeofday(&tv1 , (void *)NULL );
739     *curtim =  (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
740     *curtim = *curtim/1.E6;
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          REAL*8 wtime
748          external cloc
749          call cloc(wtime)
750          print *," HELLO WORLD", wtime
751          end
752    EOF
753        $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_warnings 2>&1
754        RET_F=$?
755        test -x ./genmake_tc  &&  ./genmake_tc >> genmake_warnings 2>&1
756        RETVAL=$?
757        if test "x$RETVAL" = x0 ; then
758            HAVE_CLOC=t
759            DEFINES="$DEFINES -DHAVE_CLOC"
760        fi
761        rm -f genmake_tc*
762    }
763    
764    
765    check_HAVE_SIGREG()  {
766        get_fortran_c_namemangling
767        cat <<EOF > genmake_tc_1.c
768    $FC_NAMEMANGLE
769    #include <stdlib.h>
770    #include <stdio.h>
771    #include <signal.h>
772    #include <errno.h>
773    #include <ucontext.h>
774    
775    int * ip;
776    
777    static void killhandler(
778        unsigned int sn, siginfo_t  si, struct ucontext *sc )
779    {
780        *ip = *ip + 1;
781        return;
782    }
783    
784    void FC_NAMEMANGLE(sigreg) (int * aip)
785    {
786        struct sigaction s;
787        ip = aip;
788        s.sa_flags = SA_SIGINFO;
789        s.sa_sigaction = (void *)killhandler;
790        if(sigaction (SIGTERM,&s,(struct sigaction *)NULL)) {
791            printf("Sigaction returned error = %d\n", errno);
792            exit(0);
793        }
794        return;
795    }
796    EOF
797        make genmake_tc_1.o >> genmake_warnings 2>&1
798        RET_C=$?
799        cat <<EOF > genmake_tc_2.$FS
800          program hello
801          integer anint
802          common /iv/ anint
803          external sigreg
804          call sigreg(anint)
805          end
806    EOF
807        echo >> genmake_warnings
808        echo "running: check_HAVE_SIGREG()" >> genmake_warnings
809        cat genmake_tc_2.$FS >> genmake_warnings
810        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
811        echo $COMM >> genmake_warnings
812        $COMM >> genmake_warnings 2>&1
813        RETVAL=$?
814        if test "x$RETVAL" = x0 ; then
815            HAVE_SIGREG=t
816            DEFINES="$DEFINES -DHAVE_SIGREG"
817        fi
818        rm -f genmake_tc*
819    }
820    
821    
822    check_HAVE_SETRLSTK()  {
823        get_fortran_c_namemangling
824        cat <<EOF > genmake_tc_1.c
825    $FC_NAMEMANGLE
826    #include <sys/time.h>
827    #include <sys/resource.h>
828    #include <unistd.h>
829    void FC_NAMEMANGLE(setrlstk) ()
830    {
831        struct rlimit rls;
832        rls.rlim_cur = RLIM_INFINITY;
833        rls.rlim_max = RLIM_INFINITY;
834        setrlimit(RLIMIT_STACK, &rls);
835        return;
836    }
837    EOF
838        make genmake_tc_1.o >> genmake_warnings 2>&1
839        RET_C=$?
840        cat <<EOF > genmake_tc_2.$FS
841          program hello
842          external setrlstk
843          call setrlstk()
844          end
845    EOF
846        echo >> genmake_warnings
847        echo "running: check_HAVE_SETRLSTK()" >> genmake_warnings
848        cat genmake_tc_2.$FS >> genmake_warnings
849        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
850        echo $COMM >> genmake_warnings
851        $COMM >> genmake_warnings 2>&1
852        RETVAL=$?
853        if test "x$RETVAL" = x0 ; then
854            HAVE_SETRLSTK=t
855            DEFINES="$DEFINES -DHAVE_SETRLSTK"
856        fi
857        rm -f genmake_tc*
858    }
859    
860    
861    check_HAVE_STAT()  {
862        get_fortran_c_namemangling
863        cat <<EOF > genmake_tc_1.c
864    $FC_NAMEMANGLE
865    #include <stdio.h>
866    #include <stdlib.h>
867    #include <unistd.h>
868    #include <sys/stat.h>
869    #include <sys/types.h>
870    void FC_NAMEMANGLE(tfsize) ( int *nbyte )
871    {
872        char name[512];
873        struct stat astat;
874    
875        name[0] = 'a'; name[1] = '\0';
876        if (! stat(name, &astat))
877            *nbyte = (int)(astat.st_size);
878        else
879            *nbyte = -1;
880    }
881    EOF
882        make genmake_tc_1.o >> genmake_tc.log 2>&1
883        RET_C=$?
884        cat <<EOF > genmake_tc_2.$FS
885          program hello
886          integer nbyte
887          call tfsize(nbyte)
888          print *," HELLO WORLD", nbyte
889          end
890    EOF
891        echo >> genmake_warnings
892        echo "running: check_HAVE_STAT()" >> genmake_warnings
893        cat genmake_tc_2.$FS >> genmake_warnings
894        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
895        echo $COMM >> genmake_warnings
896        $COMM >> genmake_tc.log 2>&1
897        RETVAL=$?
898        if test "x$RETVAL" = x0 ; then
899            HAVE_STAT=t
900            DEFINES="$DEFINES -DHAVE_STAT"
901        fi
902        rm -f genmake_tc*
903    }
904    
905    
906    check_netcdf_libs()  {
907        if test ! "x$SKIP_NETCDF_CHECK" = x ; then
908            return
909        fi
910        echo >> genmake_warnings
911        echo "running: check_netcdf_libs()" >> genmake_warnings
912        cat <<EOF > genmake_tnc.F
913          program fgennc
914    #include "netcdf.inc"
915    EOF
916        if test ! "x$MPI" = x ; then
917            echo '#include "mpif.h"' >> genmake_tnc.F
918        fi
919        cat <<EOF >> genmake_tnc.F
920          integer iret, ncid, xid
921          iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
922          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
923          iret = nf_def_dim(ncid, 'X', 11, xid)
924          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
925          iret = nf_close(ncid)
926          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
927          end
928    EOF
929        echo "===  genmake_tnc.F  ===" > genmake_tnc.log
930        cat genmake_tnc.F >> genmake_tnc.log
931        echo "===  genmake_tnc.F  ===" >> genmake_tnc.log
932        RET_CPP=f
933        COMM="$CPP $DEFINES $INCLUDES genmake_tnc.F"
934        echo "$COMM" >> genmake_tnc.log
935        $COMM > genmake_tnc.$FS 2>/dev/null  &&  RET_CPP=t
936        if test "x$RET_CPP" = xf ; then
937            echo "  WARNING: CPP failed to pre-process the netcdf test." \
938                >> genmake_tnc.log
939            echo "    Please check that \$INCLUDES is properly set." \
940                >> genmake_tnc.log
941        fi
942        echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.$FS  \ " >> genmake_tnc.log
943        echo "  &&  $LINK -o genmake_tnc.o $LIBS" >> genmake_tnc.log
944        $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
945            &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
946        RET_COMPILE=$?
947        cat genmake_tnc.log >> genmake_warnings
948    
949        #EH3  Remove test program execution for machines that either disallow
950        #EH3  execution or cannot support it (eg. cross-compilers)
951        #EH3
952        #EH3 test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1
953        #EH3 RETVAL=$?
954        #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
955    
956        if test "x$RET_COMPILE" = x0 ; then
957            HAVE_NETCDF=t
958        else
959            # try again with "-lnetcdf" added to the libs
960            echo "try again with added '-lnetcdf'" > genmake_tnc.log
961            echo "$CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS \ " >> genmake_tnc.log
962            echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
963            echo " &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
964            $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null  \
965                &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
966                &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
967            RET_COMPILE=$?
968            cat genmake_tnc.log >> genmake_warnings
969            if test "x$RET_COMPILE" = x0 ; then
970                LIBS="$LIBS -lnetcdf"
971                HAVE_NETCDF=t
972            fi
973        fi
974        rm -f genmake_tnc*
975    }
976    
977    
978    
979    ###############################################################################
980    #   Sequential part of script starts here
981    ###############################################################################
982    
983  #  Set defaults here  #  Set defaults here
984  COMMANDL="$0 $@"  COMMANDL="$0 $@"
# Line 288  PLATFORM= Line 987  PLATFORM=
987  LN=  LN=
988  S64=  S64=
989  KPP=  KPP=
990  FC=  #FC=
991    #CC=gcc
992    #CPP=
993  LINK=  LINK=
994  DEFINES="-DWORDLENGTH=4"  DEFINES=
995  PACKAGES=  PACKAGES=
996  ENABLE=  ENABLE=
997  DISABLE=  DISABLE=
998  MAKEFILE=  # MAKEFILE=
999  MAKEDEPEND=  # MAKEDEPEND=
1000  PDEPEND=  PDEPEND=
1001  DUMPSTATE=t  DUMPSTATE=t
1002  PDEFAULT=  PDEFAULT=
1003  OPTFILE=  OPTFILE=
1004  INCLUDES="-I."  INCLUDES="-I. $INCLUDES"
1005  FFLAGS=  FFLAGS=
1006  FOPTIM=  FOPTIM=
1007  CFLAGS=  CFLAGS=
1008  KFLAGS1=  KFLAGS1=
1009  KFLAGS2=  KFLAGS2=
1010    #LDADD=
1011  LIBS=  LIBS=
1012  KPPFILES=  KPPFILES=
1013  NOOPTFILES=  NOOPTFILES=
1014  NOOPTFLAGS=  NOOPTFLAGS=
1015    MPI=
1016    MPIPATH=
1017    TS=
1018    PAPIS=
1019    FOOLAD=
1020    PAPI=
1021    HPMT=
1022    GSL=
1023    HAVE_TEST_L=
1024    
1025    # DEFINES checked by test compilation or command-line
1026    HAVE_SYSTEM=
1027    HAVE_FDATE=
1028    FC_NAMEMANGLE=
1029    HAVE_CLOC=
1030    HAVE_SETRLSTK=
1031    HAVE_STAT=
1032    HAVE_NETCDF=
1033    HAVE_ETIME=
1034    IGNORE_TIME=
1035    
1036  MODS=  MODS=
1037  TOOLSDIR=  TOOLSDIR=
1038  SOURCEDIRS=  SOURCEDIRS=
1039  INCLUDEDIRS=  INCLUDEDIRS=
1040  STANDARDDIRS=  STANDARDDIRS="USE_THE_DEFAULT"
1041    
1042    G2ARGS=
1043    BASH=
1044  PWD=`pwd`  PWD=`pwd`
1045  MAKE=make  test "x$MAKE" = x  &&  MAKE=make
1046  THISHOSTNAME=`hostname`  test "x$AWK" = x   &&  AWK=awk
1047    EMBED_SRC=
1048    THISHOST=`hostname`
1049  THISCWD=`pwd`  THISCWD=`pwd`
1050  THISDATE=`date`  THISDATE=`date`
1051    THISUSER=`echo $USER`
1052    THISVER=
1053  MACHINE=`uname -a`  MACHINE=`uname -a`
1054  EXECUTABLE=  EXECUTABLE=
1055  EXEHOOK=  EXEHOOK=
# Line 331  IEEE= Line 1059  IEEE=
1059  if test "x$MITGCM_IEEE" != x ; then  if test "x$MITGCM_IEEE" != x ; then
1060      IEEE=$MITGCM_IEEE      IEEE=$MITGCM_IEEE
1061  fi  fi
1062    FS=
1063    FS90=
1064    
1065  AUTODIFF_PKG_USED=f  AUTODIFF_PKG_USED=f
1066  AD_OPTFILE=  AD_OPTFILE=
1067    TAF=
1068    AD_TAF_FLAGS=
1069    FTL_TAF_FLAGS=
1070    SVD_TAF_FLAGS=
1071    TAF_EXTRA=
1072    TAMC=
1073    AD_TAMC_FLAGS=
1074    FTL_TAF_FLAGS=
1075    SVD_TAMC_FLAGS=
1076    TAMC_EXTRA=
1077    
1078    
1079  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
1080  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"
1081  gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS"  gm_s2="FC CPP IEEE TS PAPIS PAPI HPMT GSL MPI JAM DUMPSTATE STANDARDDIRS"
1082    
1083  #  The following state is not directly set by command-line switches  #  The following state is not directly set by command-line switches
1084  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 "
1085  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
1086  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE"
1087  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
1088    gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME"
1089    
1090  #  The following are all related to adjoint/tangent-linear stuff  #  The following are all related to adjoint/tangent-linear stuff
1091  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"
1092  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"
1093  gm_s9=""  gm_s12="TAF_EXTRA TAMC_EXTRA"
1094    
1095  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"
1096    gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
1097    
1098    cat <<EOF
1099    
1100    GENMAKE :
1101    
1102    A program for GENerating MAKEfiles for the MITgcm project.  For a
1103    quick list of options, use "genmake -h" or for more detail see:
1104    
1105      http://mitgcm.org/devel_HOWTO/
1106    
1107    EOF
1108    
 echo  
1109  echo "===  Processing options files and arguments  ==="  echo "===  Processing options files and arguments  ==="
1110  gm_local="genmake_local"  gm_local="genmake_local"
1111  for i in . $MODS ; do  for i in . $MODS ; do
1112      if test -r $i/$gm_local ; then      if test -r $i/$gm_local ; then
1113          source $i/$gm_local          . $i/$gm_local
1114          break          break
1115      fi      fi
1116  done  done
1117  echo -n "  getting local config information:  "  printf "  getting local config information:  "
1118  if test -e $gm_local ; then  if test -f $gm_local ; then
1119      echo "using $gm_local"      echo "using $gm_local"
1120      source $gm_local      . $gm_local
1121      # echo "DISABLE=$DISABLE"      # echo "DISABLE=$DISABLE"
1122      # echo "ENABLE=$ENABLE"      # echo "ENABLE=$ENABLE"
1123  else  else
1124      echo "none found"      echo "none found"
1125  fi  fi
1126    
1127  #  echo "$0::$1:$2:$3:$4:$5:$6:$7:"  #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
1128  #OPTIONS=  #OPTIONS=
1129  #n=0  #n=0
1130  #for i ; do  #for i ; do
# Line 384  fi Line 1136  fi
1136  #done  #done
1137  #parse_options  #parse_options
1138  ac_prev=  ac_prev=
1139  for ac_option ; do  for ac_option in "$@" ; do
1140    
1141        G2ARGS="$G2ARGS \"$ac_option\""
1142    
1143      # If the previous option needs an argument, assign it.      # If the previous option needs an argument, assign it.
1144      if test -n "$ac_prev"; then      if test -n "$ac_prev"; then
# Line 407  for ac_option ; do Line 1161  for ac_option ; do
1161          -optfile=* | --optfile=* | -of=* | --of=*)          -optfile=* | --optfile=* | -of=* | --of=*)
1162              OPTFILE=$ac_optarg ;;              OPTFILE=$ac_optarg ;;
1163                    
1164          -adoptfile | --adoptfile | -ad | --ad)          -adoptfile | --adoptfile | -adof | --adof)
1165              ac_prev=AD_OPTFILE ;;              ac_prev=AD_OPTFILE ;;
1166          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
1167              AD_OPTFILE=$ac_optarg ;;              AD_OPTFILE=$ac_optarg ;;
# Line 427  for ac_option ; do Line 1181  for ac_option ; do
1181          -make=* | --make=* | -m=* | --m=*)          -make=* | --make=* | -m=* | --m=*)
1182              MAKE=$ac_optarg ;;              MAKE=$ac_optarg ;;
1183                    
1184            -bash | --bash)
1185                ac_prev=BASH ;;
1186            -bash=* | --bash=*)
1187                BASH=$ac_optarg ;;
1188            
1189            -makedepend | --makedepend | -md | --md)
1190                ac_prev=MAKEDEPEND ;;
1191            -makedepend=* | --makedepend=* | -md=* | --md=*)
1192                MAKEDEPEND=$ac_optarg ;;
1193            
1194          -makefile | --makefile | -ma | --ma)          -makefile | --makefile | -ma | --ma)
1195              ac_prev=MAKEFILE ;;              ac_prev=MAKEFILE ;;
1196          -makefile=* | --makefile=* | -ma=* | --ma=*)          -makefile=* | --makefile=* | -ma=* | --ma=*)
1197              MAKEFILE=$ac_optarg ;;              MAKEFILE=$ac_optarg ;;
1198                    
1199          -platform | --platform | -pl | --pl)          -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
1200              ac_prev=PLATFORM ;;              echo "ERROR: The platform option has been removed.  Please specify"
1201          -platform=* | --platform=* | -pl=* | --pl=*)              echo "  the build options using the \"optfile\" mechanism."
1202              PLATFORM=$ac_optarg ;;              echo
1203                usage
1204                ;;
1205                    
1206          -rootdir | --rootdir | -rd | --rd)          -rootdir | --rootdir | -rd | --rd)
1207              ac_prev=ROOTDIR ;;              ac_prev=ROOTDIR ;;
# Line 462  for ac_option ; do Line 1228  for ac_option ; do
1228          -standarddirs=* | --standarddirs=*)          -standarddirs=* | --standarddirs=*)
1229              STANDARDDIRS=$ac_optarg ;;              STANDARDDIRS=$ac_optarg ;;
1230    
         -noopt | --noopt)  
             ac_prev=NOOPT ;;  
         -noopt=* | --noopt=*)  
             NOOPT=$ac_optarg ;;  
           
1231  #           -cpp | --cpp)  #           -cpp | --cpp)
1232  #               ac_prev=cpp ;;  #               ac_prev=cpp ;;
1233  #           -cpp=* | --cpp=*)  #           -cpp=* | --cpp=*)
1234  #               CPP=$ac_optarg ;;  #               CPP=$ac_optarg ;;
1235                        
1236            -cc | --cc)
1237                ac_prev=CC ;;
1238            -cc=* | --cc=*)
1239                CC=$ac_optarg ;;
1240            
1241          -fortran | --fortran | -fc | --fc)          -fortran | --fortran | -fc | --fc)
1242              ac_prev=FC ;;              ac_prev=FC ;;
1243          -fc=* | --fc=*)          -fc=* | --fc=*)
1244              FC=$ac_optarg ;;              FC=$ac_optarg ;;
1245                    
1246            -fs | --fs)
1247                ac_prev=FS ;;
1248            -fs=* | --fs=*)
1249                FS=$ac_optarg ;;
1250            
1251            -fs90 | --fs90)
1252                ac_prev=FS90 ;;
1253            -fs90=* | --fs90=*)
1254                FS90=$ac_optarg ;;
1255            
1256          -ieee | --ieee)          -ieee | --ieee)
1257              IEEE=true ;;              IEEE=true ;;
1258          -noieee | --noieee)          -noieee | --noieee)
1259              IEEE= ;;              IEEE= ;;
1260            
1261            -ts | --ts)
1262                TS=true ;;
1263            -papis | --papis)
1264                PAPIS=true ;;
1265            -foolad | --foolad)
1266                FOOLAD=true ;;
1267            -papi | --papi)
1268                PAPI=true ;;
1269            -hpmt | --hpmt)
1270                HPMT=true ;;
1271    
1272            -gsl | --gsl)
1273                GSL=true ;;
1274    
1275          -mpi | --mpi)          -mpi | --mpi)
1276              MPI=true ;;              MPI=true ;;
1277          -nompi | --nompi)          -mpi=* | --mpi=*)
1278              MPI= ;;              MPIPATH=$ac_optarg
1279                MPI=true ;;
1280                    
1281          -jam | --jam)  #       -jam | --jam)
1282              JAM=1 ;;  #           JAM=1 ;;
1283          -nojam | --nojam)  #       -nojam | --nojam)
1284              JAM=0 ;;  #           JAM=0 ;;
1285                    
1286          -ds | --ds)          -ds | --ds)
1287              DUMPSTATE=t ;;              DUMPSTATE=t ;;
1288                    
1289            -taf_extra | --taf_extra)
1290                ac_prev=TAF_EXTRA ;;
1291            -taf_extra=* | --taf_extra=*)
1292                TAF_EXTRA=$ac_optarg ;;
1293    
1294            -tamc_extra | --tamc_extra)
1295                ac_prev=TAMC_EXTRA ;;
1296            -tamc_extra=* | --tamc_extra=*)
1297                TAMC_EXTRA=$ac_optarg ;;
1298            
1299            -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1300                IGNORE_TIME="-DIGNORE_TIME" ;;
1301    
1302            -es | --es | -embed-source | --embed-source)
1303                EMBED_SRC=t ;;
1304    
1305          -*)          -*)
1306              echo "Error: unrecognized option: "$ac_option              echo "Error: unrecognized option: "$ac_option
1307              usage              usage
# Line 509  for ac_option ; do Line 1316  for ac_option ; do
1316            
1317  done  done
1318    
1319    
1320  if test -f ./.genmakerc ; then  if test -f ./.genmakerc ; then
1321      echo      echo
1322      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 1329  if test -f ./.genmakerc ; then
1329      echo      echo
1330  fi  fi
1331    
1332    #  Find the MITgcm ${ROOTDIR}
1333  if test "x${ROOTDIR}" = x ; then  if test "x${ROOTDIR}" = x ; then
1334      if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1335        if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
1336          ROOTDIR=".."          ROOTDIR=".."
1337      else      else
1338          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1339              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
1340                  ROOTDIR=$d                  ROOTDIR=$d
1341                  echo -n "Warning:  ROOTDIR was not specified but there appears to be"                  printf "Warning:  ROOTDIR was not specified but there appears to be"
1342                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
1343                  break                  break
1344              fi              fi
# Line 546  if test ! -d ${ROOTDIR} ; then Line 1356  if test ! -d ${ROOTDIR} ; then
1356      exit 1      exit 1
1357  fi  fi
1358    
1359    #  Find the MITgcm ${THISVER}
1360    if test -f "${ROOTDIR}/doc/tag-index" ; then
1361        THISVER=`grep '^checkpoint' ${ROOTDIR}/doc/tag-index | head -1`
1362    fi
1363    
1364    if test "x$MAKEFILE" = x ; then
1365        MAKEFILE="Makefile"
1366    fi
1367    
1368  echo "  getting OPTFILE information:  "  echo "  getting OPTFILE information:  "
1369  if test "x${OPTFILE}" = x ; then  if test "x${OPTFILE}" = x ; then
1370      if test "x$MITGCM_OF" = x ; then      if test "x$MITGCM_OF" = x ; then
# Line 559  fi Line 1378  fi
1378  if test "x$OPTFILE" != xNONE ; then  if test "x$OPTFILE" != xNONE ; then
1379      if test -f "$OPTFILE" -a -r "$OPTFILE" ; then      if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
1380          echo "    using OPTFILE=\"$OPTFILE\""          echo "    using OPTFILE=\"$OPTFILE\""
1381          source "$OPTFILE"          . "$OPTFILE"
1382          RETVAL=$?          RETVAL=$?
1383          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
1384              echo -n "Error: failed to source OPTFILE \"$OPTFILE\""              printf "Error: failed to source OPTFILE \"$OPTFILE\""
1385              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1386              exit 1              exit 1
1387          fi          fi
# Line 586  fi Line 1405  fi
1405  if test "x${AD_OPTFILE}" != xNONE ; then  if test "x${AD_OPTFILE}" != xNONE ; then
1406      if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then      if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
1407          echo "    using AD_OPTFILE=\"$AD_OPTFILE\""          echo "    using AD_OPTFILE=\"$AD_OPTFILE\""
1408          source "$AD_OPTFILE"          . "$AD_OPTFILE"
1409          RETVAL=$?          RETVAL=$?
1410          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
1411              echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""              printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
1412              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1413              exit 1              exit 1
1414          fi          fi
# Line 602  if test "x${AD_OPTFILE}" != xNONE ; then Line 1421  if test "x${AD_OPTFILE}" != xNONE ; then
1421      fi      fi
1422  fi  fi
1423    
1424  #  Check that FC, LINK, CPP, and S64 are defined.  If not, complain  #====================================================================
1425  #  and abort!  #  Set default values if not set by the optfile
1426    #
1427    #  Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
1428    #  either set defaults or complain and abort!
1429    if test ! "x$BASH" = x ; then
1430        # add a trailing space so that it works within the Makefile syntax (see below)
1431        BASH="$BASH "
1432    fi
1433  if test "x$FC" = x ; then  if test "x$FC" = x ; then
1434      cat <<EOF 1>&2      cat <<EOF 1>&2
1435    
# Line 614  Error: no Fortran compiler: please speci Line 1440  Error: no Fortran compiler: please speci
1440  EOF  EOF
1441      exit 1      exit 1
1442  fi  fi
1443    if test "x$CC" = x ; then
1444        CC=cc
1445    #     cat <<EOF 1>&2
1446    # Error: no C compiler: please specify using one of the following:
1447    #   1) within the options file ("CC=...") as specified by "-of=OPTFILE"
1448    #   2) the "-cc=XXX" command-line option
1449    #   3) the "./genmake_local" file
1450    # EOF
1451    #     exit 1
1452    fi
1453  if test "x$LINK" = x ; then  if test "x$LINK" = x ; then
1454      LINK=$FC      LINK=$FC
1455  fi  fi
1456    if test "x$MAKE" = x ; then
1457        MAKE="make"
1458    fi
1459  if test "x$CPP" = x ; then  if test "x$CPP" = x ; then
1460      CPP="cpp"      CPP=cpp
1461  fi  fi
1462    #EH3 === UGLY ===
1463    #  The following is an ugly little hack to check for $CPP in /lib/ and
1464    #  it should eventually be replaced with a more general function that
1465    #  searches a combo of the user's path and a list of "usual suspects"
1466    #  to find the correct location for binaries such as $CPP.
1467    for i in " " "/lib/" ; do
1468        echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1469    done
1470    #EH3 === UGLY ===
1471  echo "#define A a" | $CPP > test_cpp 2>&1  echo "#define A a" | $CPP > test_cpp 2>&1
1472  RETVAL=$?  RETVAL=$?
1473  if test "x$RETVAL" != x0 ; then  if test "x$RETVAL" != x0 ; then
# Line 629  Error: C pre-processor "$CPP" failed the Line 1477  Error: C pre-processor "$CPP" failed the
1477    
1478    1) within the options file ("CPP=...") as specified by "-of=OPTFILE"    1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
1479    2) the "./genmake_local" file    2) the "./genmake_local" file
1480      3) with the CPP environment variable
1481    
1482  EOF  EOF
1483      exit 1      exit 1
1484  else  else
1485      rm -f test_cpp      rm -f test_cpp
1486  fi  fi
1487  if test "x$MAKEDEPEND" = x ; then  look_for_makedepend
1488      MAKEDEPEND=makedepend  if test "x$LN" = x ; then
1489        LN="ln -s"
1490    fi
1491    echo "test" > genmake_test_ln
1492    $LN genmake_test_ln genmake_tlink
1493    RETVAL=$?
1494    if test "x$RETVAL" != x0 ; then
1495        cat <<EOF 1>&2
1496    
1497    Error: The command "ln -s" failed -- please specify a working soft-link
1498      command in the optfile.
1499    
1500    EOF
1501        exit 1
1502    fi
1503    test -L genmake_tlink > /dev/null 2>&1
1504    RETVAL=$?
1505    if test "x$RETVAL" = x0 ; then
1506        HAVE_TEST_L=t
1507  fi  fi
1508    rm -f genmake_test_ln genmake_tlink
1509    
1510    #  Check for broken *.F/*.f handling and fix if possible
1511    check_for_broken_Ff
1512    
1513    if test ! "x$MPI" = x ; then
1514          echo "  Turning on MPI cpp macros"
1515          DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
1516    fi
1517    
1518    if test ! "x$TS" = x ; then
1519          echo "  Turning on timing per timestep"
1520          if test ! "x$FOOLAD" = x ; then
1521                DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP"
1522          else
1523                DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1524          fi
1525    fi
1526    if test ! "x$PAPIS" = x ; then
1527          echo "  Turning on PAPI flop summary per timestep"
1528          echo "  Please make sure PAPIINC, PAPILIB are defined"
1529          if test ! "x$FOOLAD" = x ; then
1530                DEFINES="$DEFINES -DUSE_PAPI_FLOPS_SFP"
1531          else
1532                DEFINES="$DEFINES -DUSE_PAPI_FLOPS"
1533          fi
1534          INCLUDES="$INCLUDES $PAPIINC"
1535          LIBS="$LIBS $PAPILIB"
1536    fi
1537    if test ! "x$PAPI" = x ; then
1538          if test ! "x$PAPIS" = x ; then
1539              echo "  PAPI performance analysis and flop summary per timestep cannot co-exist!"
1540              echo "  Sticking with PAPI flop summary per timestep!"
1541          else
1542              echo "  Turning on performance analysis with PAPI"
1543              echo "  Please make sure PAPIINC, PAPILIB are defined"
1544              DEFINES="$DEFINES -DUSE_PAPI"
1545              INCLUDES="$INCLUDES $PAPIINC"
1546              LIBS="$LIBS $PAPILIB"
1547          fi
1548    fi
1549    if test ! "x$HPMT" = x ; then
1550          if test ! "x$PAPI" = x ; then
1551              echo "  PAPI and the HPM Toolkit cannot co-exist!"
1552              echo "  Sticking with PAPI!"
1553          else
1554              echo "  Turning on performance analysis with the HPM Toolkit"
1555              echo "  Please make sure HPMTINC, HPMTLIB are defined"
1556              DEFINES="$DEFINES -DUSE_LIBHPM"
1557              INCLUDES="$INCLUDES $HPMTINC"
1558              LIBS="$LIBS $HPMTLIB"
1559          fi
1560    fi
1561    if test ! "x$GSL" = x ; then
1562          echo "  Turning on use of GSL to control floating point calculations"
1563          echo "  Please make sure GSLINC, GSLLIB are defined"
1564          DEFINES="$DEFINES -DUSE_GSL_IEEE"
1565          INCLUDES="$INCLUDES $GSLINC"
1566          LIBS="$LIBS $GSLLIB"
1567    fi
1568    
1569    printf "\n===  Checking system libraries  ===\n"
1570    printf "  Do we have the system() command using $FC...  "
1571    cat > genmake_tcomp.$FS <<EOF
1572          program hello
1573          call system('echo hi')
1574          end
1575    EOF
1576    $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1577    RETVAL=$?
1578    if test "x$RETVAL" = x0 ; then
1579        HAVE_SYSTEM=t
1580        DEFINES="$DEFINES -DHAVE_SYSTEM"
1581        echo "yes"
1582    else
1583        HAVE_SYSTEM=
1584        echo "no"
1585    fi
1586    rm -f genmake_tcomp*
1587    
1588    printf "  Do we have the fdate() command using $FC...  "
1589    cat > genmake_tcomp.$FS <<EOF
1590          program hello
1591          CHARACTER*(128) string
1592          string = ' '
1593          call fdate( string )
1594          print *, string
1595          end
1596    EOF
1597    $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1598    RETVAL=$?
1599    if test "x$RETVAL" = x0 ; then
1600        HAVE_FDATE=t
1601        DEFINES="$DEFINES -DHAVE_FDATE"
1602        echo "yes"
1603    else
1604        HAVE_FDATE=
1605        echo "no"
1606    fi
1607    rm -f genmake_tcomp*
1608    
1609    printf "  Do we have the etime() command using $FC...  "
1610    cat > genmake_tcomp.$FS <<EOF
1611          program hello
1612          REAL*4 ACTUAL, TARRAY(2)
1613          EXTERNAL ETIME
1614          REAL*4 ETIME
1615          actual = etime( tarray )
1616          print *, tarray
1617          end
1618    EOF
1619    $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1620    RETVAL=$?
1621    if test "x$RETVAL" = x0 ; then
1622        HAVE_ETIME=t
1623        DEFINES="$DEFINES -DHAVE_ETIME"
1624        echo "yes"
1625    else
1626        HAVE_ETIME=
1627        echo "no"
1628    fi
1629    rm -f genmake_tcomp*
1630    
1631    printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
1632    check_HAVE_CLOC
1633    if test "x$HAVE_CLOC" != x ; then
1634        echo "yes"
1635    else
1636        echo "no"
1637        if test "x$EMBED_SRC" = xt ; then
1638            echo "    WARNING: you requested file embedding but it has"
1639            echo "      been disabled since C code cannot be called"
1640            EMBED_SRC=
1641        fi
1642    fi
1643    rm -f genmake_t*
1644    
1645    printf "  Can we unlimit the stack size using $FC...  "
1646    check_HAVE_SETRLSTK
1647    if test "x$HAVE_SETRLSTK" != x ; then
1648        echo "yes"
1649    else
1650        echo "no"
1651    fi
1652    rm -f genmake_t*
1653    
1654    printf "  Can we register a signal handler using $FC...  "
1655    check_HAVE_SIGREG
1656    if test "x$HAVE_SIGREG" != x ; then
1657        echo "yes"
1658    else
1659        echo "no"
1660    fi
1661    rm -f genmake_t*
1662    
1663    printf "  Can we use stat() through C calls...  "
1664    check_HAVE_STAT
1665    if test "x$HAVE_STAT" != x ; then
1666        echo "yes"
1667    else
1668        echo "no"
1669    fi
1670    rm -f genmake_t*
1671    
1672    printf "  Can we create NetCDF-enabled binaries...  "
1673    check_netcdf_libs
1674    if test "x$HAVE_NETCDF" != x ; then
1675        echo "yes"
1676    else
1677        echo "no"
1678    fi
1679    DEFINES="$DEFINES $IGNORE_TIME"
1680    
1681    if test "x$EMBED_SRC" = xt ; then
1682        build_embed_encode
1683    fi
1684    if test "x$EMBED_SRC" = xt ; then
1685        ENABLE="$ENABLE embed_files"
1686    fi
1687    
1688    
1689  printf "\n===  Setting defaults  ===\n"  printf "\n===  Setting defaults  ===\n"
1690  echo -n "  Adding MODS directories:  "  printf "  Adding MODS directories:  "
1691  for d in $MODS ; do  for d in $MODS ; do
1692      if test ! -d $d ; then      if test ! -d $d ; then
1693          echo          echo
1694          echo "Error: MODS directory \"$d\" not found!"          echo "Error: MODS directory \"$d\" not found!"
1695          exit 1          exit 1
1696      else      else
1697          echo -n " $d"          printf " $d"
1698          SOURCEDIRS="$SOURCEDIRS $d"          SOURCEDIRS="$SOURCEDIRS $d"
1699          INCLUDEDIRS="$INCLUDEDIRS $d"          INCLUDEDIRS="$INCLUDEDIRS $d"
1700      fi      fi
1701  done  done
1702  echo  echo
1703    
 if test "x$MAKEFILE" = x ; then  
     MAKEFILE="Makefile"  
 fi  
1704  if test "x${PLATFORM}" = x ; then  if test "x${PLATFORM}" = x ; then
1705      PLATFORM=$p_PLATFORM      PLATFORM=$p_PLATFORM
1706  fi  fi
1707    
1708  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
1709      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1710        if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
1711          EXEDIR=../exe          EXEDIR=../exe
1712      else      else
1713          EXEDIR=.          EXEDIR=.
# Line 677  if test "x${TOOLSDIR}" = x ; then Line 1722  if test "x${TOOLSDIR}" = x ; then
1722      TOOLSDIR="$ROOTDIR/tools"      TOOLSDIR="$ROOTDIR/tools"
1723  fi  fi
1724  if test ! -d ${TOOLSDIR} ; then  if test ! -d ${TOOLSDIR} ; then
1725      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
1726      exit 1      exit 1
1727  fi  fi
1728  if test "x$S64" = x ; then  if test "x$S64" = x ; then
1729      S64='$(TOOLSDIR)/set64bitConst.sh'      echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1
1730        RETVAL=$?
1731        if test "x${RETVAL}" = x0 ; then
1732            S64='$(TOOLSDIR)/set64bitConst.sh'
1733        else
1734            echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1
1735            RETVAL=$?
1736            if test "x${RETVAL}" = x0 ; then
1737                S64='$(TOOLSDIR)/set64bitConst.csh'
1738            else
1739                cat <<EOF
1740    
1741    ERROR: neither of the two default scripts:
1742    
1743        ${TOOLSDIR}/set64bitConst.sh
1744        ${TOOLSDIR}/set64bitConst.csh
1745    
1746      are working so please check paths or specify (with \$S64) a
1747      working version of this script.
1748    
1749    EOF
1750                exit 1
1751            fi
1752        fi
1753  fi  fi
1754    THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
1755    
1756  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1757    
# Line 691  EXECUTABLE=${EXECUTABLE:-mitgcmuv} Line 1760  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1760  #  they appear as regular source code  #  they appear as regular source code
1761  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
1762      echo "  Making source files in eesupp from templates"      echo "  Making source files in eesupp from templates"
1763      $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1      ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1
1764      RETVAL=$?      RETVAL=$?
1765      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
1766          rm -f make_eesupp.errors          rm -f make_eesupp.errors
1767      else      else
1768          echo "Error: problem encountered while building source files in eesupp:"          echo "Error: problem encountered while building source files in eesupp:"
1769          cat make_eesupp.errors          cat make_eesupp.errors 1>&2
1770          exit 1          exit 1
1771      fi      fi
1772  fi  fi
1773    
1774    #same for exch2
1775    if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then
1776        echo "  Making source files in exch2 from  templates"
1777        ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1
1778        RETVAL=$?
1779        if test "x${RETVAL}" = x0 ; then
1780            rm -f make_exch2.errors
1781        else
1782            echo "Error: problem encountered while building source files in exch2:"
1783            cat make_exch2.errors 1>&2
1784            exit 1
1785        fi
1786    fi
1787    
1788  printf "\n===  Determining package settings  ===\n"  printf "\n===  Determining package settings  ===\n"
1789  if  test "x${PDEPEND}" = x ; then  if  test "x${PDEPEND}" = x ; then
1790      tmp=$ROOTDIR"/pkg/pkg_depend"      tmp=$ROOTDIR"/pkg/pkg_depend"
# Line 721  echo "  getting package dependency info Line 1804  echo "  getting package dependency info
1804  #  Strip the comments and then convert the dependency file into  #  Strip the comments and then convert the dependency file into
1805  #  two arrays: PNAME, DNAME  #  two arrays: PNAME, DNAME
1806  cat $PDEPEND | sed -e 's/#.*$//g' \  cat $PDEPEND | sed -e 's/#.*$//g' \
1807      | 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}' \
1808      > ./.pd_tmp      > ./.pd_tmp
1809  RETVAL=$?  RETVAL=$?
1810  if test ! "x${RETVAL}" = x0 ; then  if test ! "x${RETVAL}" = x0 ; then
1811      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
1812      exit 1      exit 1
1813  fi  fi
1814  source ./.pd_tmp  . ./.pd_tmp
1815  rm -f ./.pd_tmp  rm -f ./.pd_tmp
1816    
1817  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"
1818  #  file should eventually be added so that, for convenience, one can  #  file should eventually be added so that, for convenience, one can
1819  #  specify groups of packages using names like "ocean" and "atmosphere".  #  specify groups of packages using names like "ocean" and "atmosphere".
1820  echo  -n "  checking default package list:  "  echo "  checking default package list:  "
1821  if test "x${PDEFAULT}" = x ; then  if test "x${PDEFAULT}" = x ; then
1822      for i in "." $MODS ; do      for i in "." $MODS ; do
1823          if test -r $i"/packages.conf" ; then          if test -r $i"/packages.conf" ; then
# Line 747  if test "x${PDEFAULT}" = x ; then Line 1830  if test "x${PDEFAULT}" = x ; then
1830      PDEFAULT="$ROOTDIR/pkg/pkg_default"      PDEFAULT="$ROOTDIR/pkg/pkg_default"
1831  fi  fi
1832  if test "x${PDEFAULT}" = xNONE ; then  if test "x${PDEFAULT}" = xNONE ; then
1833      echo "default packages file disabled"      echo "    default packages file disabled"
1834  else  else
1835      if test ! -r $PDEFAULT ; then      if test ! -r $PDEFAULT ; then
         echo ""  
1836          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""
1837      else      else
1838          echo "  using PDEFAULT=\"$PDEFAULT\""          echo "    using PDEFAULT=\"$PDEFAULT\""
1839          #  Strip the comments and add all the names          #  Strip the comments and add all the names
1840          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | awk '(NF>0){print $0}'`          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
1841          RETVAL=$?          RETVAL=$?
1842          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
1843              echo -n "Error: can't parse default package list "              printf "Error: can't parse default package list "
1844              echo "-- please check PDEFAULT=\"$PDEFAULT\""              echo "-- please check PDEFAULT=\"$PDEFAULT\""
1845              exit 1              exit 1
1846          fi          fi
# Line 766  else Line 1848  else
1848              PACKAGES="$PACKAGES $i"              PACKAGES="$PACKAGES $i"
1849          done          done
1850          echo "    before group expansion packages are: $PACKAGES"          echo "    before group expansion packages are: $PACKAGES"
1851          expand_pkg_groups          RET=1
1852            while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
1853          echo "    after group expansion packages are:  $PACKAGES"          echo "    after group expansion packages are:  $PACKAGES"
1854      fi      fi
1855  fi  fi
1856    
1857  echo "  applying DISABLE settings"  echo "  applying DISABLE settings"
1858    for i in $PACKAGES ; do
1859        echo $i >> ./.tmp_pack
1860    done
1861    for i in `grep  "-" ./.tmp_pack` ; do
1862        j=`echo $i | sed 's/[-]//'`
1863        DISABLE="$DISABLE $j"
1864    done
1865  pack=  pack=
1866  for p in $PACKAGES ; do  for p in $PACKAGES ; do
1867      addit="t"      addit="t"
# Line 788  PACKAGES="$pack" Line 1878  PACKAGES="$pack"
1878  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
1879  echo "" > ./.tmp_pack  echo "" > ./.tmp_pack
1880  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
1881    # Test if each explicitly referenced package exists
1882  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1883      if test ! -d "$ROOTDIR/pkg/$i" ; then      j=`echo $i | sed 's/[-+]//'`
1884        if test ! -d "$ROOTDIR/pkg/$j" ; then
1885          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
1886          exit 1          exit 1
1887      fi      fi
1888      echo $i >> ./.tmp_pack      echo $i >> ./.tmp_pack
1889  done  done
 pack=`cat ./.tmp_pack | sort | uniq`  
 rm -f ./.tmp_pack  
1890  PACKAGES=  PACKAGES=
1891  for i in $pack ; do  for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do
1892      PACKAGES="$PACKAGES $i"      PACKAGES="$PACKAGES $i"
1893  done  done
1894    rm -f ./.tmp_pack
1895  echo "    packages are:  $PACKAGES"  echo "    packages are:  $PACKAGES"
1896    
1897    #  Check availability of NetCDF and then either build the MNC template
1898    #  files or delete mnc from the list of available packages.
1899    echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1
1900    RETVAL=$?
1901    if test "x$RETVAL" = x0 ; then
1902        if test "x$HAVE_NETCDF" != xt ; then
1903            cat <<EOF
1904    
1905    *********************************************************************
1906    WARNING: the "mnc" package was enabled but tests failed to compile
1907      NetCDF applications.  Please check that:
1908    
1909      1) NetCDF is correctly installed for this compiler and
1910      2) the LIBS variable (within the "optfile") specifies the correct
1911           NetCDF library to link against.
1912    
1913      Due to this failure, the "mnc" package is now DISABLED.
1914    *********************************************************************
1915    
1916    EOF
1917            PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
1918            DISABLE="$DISABLE mnc"
1919        else
1920            ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
1921            RETVAL=$?
1922            if test "x${RETVAL}" = x0 ; then
1923                rm -f make_mnc.errors
1924            else
1925                echo "Error: problem encountered while building source files in pkg/mnc:"
1926                cat make_mnc.errors 1>&2
1927                exit 1
1928            fi
1929        fi
1930    fi
1931    
1932  echo "  applying package dependency rules"  echo "  applying package dependency rules"
1933  ck=  ck=
1934  while test "x$ck" != xtt ; do  while test "x$ck" != xtt ; do
# Line 867  while test "x$ck" != xtt ; do Line 1993  while test "x$ck" != xtt ; do
1993              echo "  the dependency rules for \"$dname\""              echo "  the dependency rules for \"$dname\""
1994              exit 1              exit 1
1995          fi          fi
1996          i=$(( $i + 1 ))          i=`echo "$i + 1" | bc -l`
1997            #i=$(( $i + 1 ))
1998      done      done
1999      ck=$ck"t"      ck=$ck"t"
2000  done  done
# Line 886  for i in $PACKAGES ; do Line 2013  for i in $PACKAGES ; do
2013      fi      fi
2014  done  done
2015    
 #  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  
   
2016  # Create a list of #define and #undef to enable/disable packages  # Create a list of #define and #undef to enable/disable packages
2017  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  
2018  #  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
2019  #  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
2020  #  file would eventually be split up so that all package-related #define  #  file would eventually be split up so that all package-related #define
2021  #  statements could be separated and handled only by genmake.  #  statements could be separated and handled only by genmake.
2022  names=`ls -1 "$ROOTDIR/pkg"`  names=`ls -1 "$ROOTDIR/pkg"`
2023  all_pack=  all_pack=
2024    DISABLED_PACKAGES=
2025  for n in $names ; do  for n in $names ; do
2026      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
2027          has_pack="f"          has_pack="f"
# Line 935  for n in $names ; do Line 2032  for n in $names ; do
2032              fi              fi
2033          done          done
2034          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
2035              undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2036              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!!!  
   
2037          fi          fi
2038      fi      fi
2039  done  done
2040  cat <<EOF >>$PACKAGES_DOT_H".tmp"  ENABLED_PACKAGES=
   
 C  Packages enabled by genmake:  
 EOF  
2041  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2042      def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`      def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2043      echo "#define $def" >> $PACKAGES_DOT_H".tmp"      ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
2044  #eh3 DEFINES="$DEFINES -D$def"  #eh3 DEFINES="$DEFINES -D$def"
2045    
2046  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
2047      case $i in      case $i in
2048          aim_v23)          aim_v23)
2049              echo "#define   ALLOW_AIM" >> $PACKAGES_DOT_H".tmp"              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
2050              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 :-)"  
2051              ;;              ;;
2052      esac      esac
2053  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
2054    
2055  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  
2056    
2057  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS"
2058  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
2059  if test "x$STANDARDDIRS" = x ; then  if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
2060      STANDARDDIRS="eesupp model"      STANDARDDIRS="eesupp model"
2061  fi  fi
2062  for d in $STANDARDDIRS ; do  if test "x$STANDARDDIRS" != x ; then
2063      adr="$ROOTDIR/$d/src"      for d in $STANDARDDIRS ; do
2064      if test ! -d $adr ; then          adr="$ROOTDIR/$d/src"
2065          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""          if test ! -d $adr ; then
2066          echo "  is correct and that you correctly specified the STANDARDDIRS option"              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
2067          exit 1              echo "  is correct and that you correctly specified the STANDARDDIRS option"
2068      else              exit 1
2069          SOURCEDIRS="$SOURCEDIRS $adr"          else
2070      fi              SOURCEDIRS="$SOURCEDIRS $adr"
2071      adr="$ROOTDIR/$d/inc"          fi
2072      if test ! -d $adr ; then          adr="$ROOTDIR/$d/inc"
2073          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""          if test ! -d $adr ; then
2074          echo "  is correct and that you correctly specified the STANDARDDIRS option"              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
2075          exit 1              echo "  is correct and that you correctly specified the STANDARDDIRS option"
2076      else              exit 1
2077          INCLUDEDIRS="$INCLUDEDIRS $adr"          else
2078      fi              INCLUDEDIRS="$INCLUDEDIRS $adr"
2079  done          fi
2080        done
2081    fi
2082    
2083  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"
2084  echo " of \"#define ALLOW_PKGNAME\"-type statements:"  echo "    of \"#define \"-type statements that are no longer allowed:"
2085  CPP_OPTIONS=  CPP_OPTIONS=
2086    CPP_EEOPTIONS=
2087  spaths=". $INCLUDEDIRS"  spaths=". $INCLUDEDIRS"
2088    names=`ls -1 "$ROOTDIR/pkg"`
2089  for i in $spaths ; do  for i in $spaths ; do
2090      try="$i/CPP_OPTIONS.h"      try="$i/CPP_OPTIONS.h"
2091      #  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  
2092          echo "    found CPP_OPTIONS=\"$try\""          echo "    found CPP_OPTIONS=\"$try\""
2093          CPP_OPTIONS="$try"          CPP_OPTIONS="$try"
2094          break          # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
2095            for n in $names ; do
2096                test_for_package_in_cpp_options $CPP_OPTIONS $n
2097            done
2098        fi
2099        try="$i/CPP_EEOPTIONS.h"
2100        if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
2101            echo "    found CPP_EEOPTIONS=\"$try\""
2102            # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
2103    #**** not yet enabled ****
2104    #        test_for_mpi_in_cpp_eeoptions $try
2105    #**** not yet enabled ****
2106            CPP_EEOPTIONS="$try"
2107      fi      fi
2108  done  done
2109  if test "x$CPP_OPTIONS" = x ; then  if test "x$CPP_OPTIONS" = x ; then
2110      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"
2111      exit 1      exit 1
2112  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  
   
2113    
2114  #  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
2115  #  compiler.  #  compiler.
# Line 1054  for i in $SOURCEDIRS ; do Line 2123  for i in $SOURCEDIRS ; do
2123          cat $i/$j >> ad_files          cat $i/$j >> ad_files
2124      done      done
2125  done  done
2126    if test ! "x"$FS = "x.f" ; then
2127  cat <<EOF > adjoint_sed      cat ad_files | sed -e "s/\.f/.$FS/g" > ad_files_f
2128  s/call adopen(/call adopen ( mythid,\\      mv -f ad_files_f ad_files
2129       \&           /g  fi
 s/call adclose(/call adclose( mythid,\\  
      \&           /g  
 s/call adread(/call adread ( mythid,\\  
      \&           /g  
 s/call adwrite(/call adwrite( mythid,\\  
      \&           /g  
   
 EOF  
2130    
2131  echo  echo
2132  echo "===  Creating the Makefile  ==="  echo "===  Creating the Makefile  ==="
2133  echo "  setting INCLUDES"  echo "  setting INCLUDES"
2134  for i in $INCLUDEDIRS ; do  for i in $INCLUDEDIRS ; do
2135      if ! test -d $i ; then      if test ! -d $i ; then
 #       INCLUDES="$INCLUDES -I$i"  
 #   else  
2136          echo "Warning: can't find INCLUDEDIRS=\"$i\""          echo "Warning: can't find INCLUDEDIRS=\"$i\""
2137      fi      fi
2138  done  done
2139    
2140    if test ! "x$DIVA" = x ; then
2141        echo "  Creating the pseudo-MPI include directory"
2142        INCLUDES="-I./mpi_headers $INCLUDES"
2143        rm -rf ./mpi_headers
2144        mkdir -p ./mpi_headers
2145    
2146        if test "x$MPIINCLUDEDIR" = x ; then
2147            if test "x$MPIHOME" = x ; then
2148                MPIHOME='/usr'
2149            fi
2150            MPIINCLUDEDIR='$MPIHOME/include'
2151        fi
2152        
2153        if test -r $MPIINCLUDEDIR/mpif.h ; then
2154            for i in $MPI_HEADER_FILES; do
2155                cp -p $MPIINCLUDEDIR/$i ./mpi_headers
2156            done
2157    
2158            perl -i -pe 's/MPI_DISPLACEMENT_CURRENT=-1_8/MPI_DISPLACEMENT_CURRENT=-1/g' mpi_headers/mpif.h
2159        else
2160            echo " We cannot create a copy of mpif.h!"
2161            exit -1
2162        fi
2163    fi
2164    
2165  echo "  Determining the list of source and include files"  echo "  Determining the list of source and include files"
2166  rm -rf .links.tmp  rm -rf .links.tmp
2167  mkdir .links.tmp  mkdir .links.tmp
2168    touch .links.tmp/foo
2169    if test ! -r ".links.tmp/foo" ; then
2170        echo
2171        echo "ERROR : something is wrong with your directory permissions or"
2172        echo "   your user file-creation mask (\"umask\") since creating a"
2173        echo "   sub-dir, touch-ing a file within it, and then reading it is"
2174        echo "   not working.  Please try setting your umask to something"
2175        echo "   sane such as:"
2176        echo
2177        echo "      umask 0002"
2178        echo
2179        echo "   and please verify that you have the proper permissions for"
2180        echo "   creating sub-directories and then reading files created"
2181        echo "   within them."
2182        echo
2183        exit 1
2184    fi
2185    rm -f .links.tmp/foo
2186  echo "# This section creates symbolic links" > srclinks.tmp  echo "# This section creates symbolic links" > srclinks.tmp
2187  echo "" >> srclinks.tmp  echo "" >> srclinks.tmp
2188  echo -n 'SRCFILES = '    > srclist.inc  printf 'SRCFILES = '    > srclist.inc
2189  echo -n 'CSRCFILES = '   > csrclist.inc  printf 'CSRCFILES = '   > csrclist.inc
2190  echo -n 'F90SRCFILES = ' > f90srclist.inc  printf 'F90SRCFILES = ' > f90srclist.inc
2191  echo -n 'HEADERFILES = ' > hlist.inc  printf 'HEADERFILES = ' > hlist.inc
2192  echo -n 'AD_FLOW_FILES = ' > ad_flow_files.inc  printf 'AD_FLOW_FILES = ' > ad_flow_files.inc
2193  alldirs="$SOURCEDIRS $INCLUDEDIRS ."  alldirs="$SOURCEDIRS $INCLUDEDIRS ."
2194  for d in $alldirs ; do  for d in $alldirs ; do
2195      deplist=      deplist=
# Line 1096  for d in $alldirs ; do Line 2198  for d in $alldirs ; do
2198      for sf in $sfiles ; do      for sf in $sfiles ; do
2199          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
2200              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
2201                  extn=`echo $sf | awk -F '.' '{print $NF}'`                  ignore_f=f
2202                  touch .links.tmp/$sf                  case $d/$sf in
2203                  deplist="$deplist $sf"                    ./$PACKAGES_DOT_H)
2204                  case $extn in                          ignore_f=t
                     F)  
                         echo    " \\"  >> srclist.inc  
                         echo -n " $sf" >> srclist.inc  
2205                          ;;                          ;;
2206                      F90)                    ./AD_CONFIG.h)
2207                          echo    " \\"  >> f90srclist.inc                          ignore_f=t
                         echo -n " $sf" >> f90srclist.inc  
2208                          ;;                          ;;
2209                      c)                    ./FC_NAMEMANGLE.h)
2210                          echo    " \\"  >> csrclist.inc                          ignore_f=t
                         echo -n " $sf" >> csrclist.inc  
2211                          ;;                          ;;
2212                      h)                    ./BUILD_INFO.h)
2213                          echo    " \\"  >> hlist.inc                          ignore_f=t
                         echo -n " $sf" >> hlist.inc  
2214                          ;;                          ;;
2215                      flow)                    ./EMBEDDED_FILES.h)
2216                          echo    " \\"  >> ad_flow_files.inc                          ignore_f=t
                         echo -n " $sf" >> ad_flow_files.inc  
2217                          ;;                          ;;
2218                  esac                    *)
2219                            #  For the local directory *ONLY*,
2220                            #  ignore all soft-links
2221                            if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then
2222                                ignore_f=t
2223                            else
2224                                touch .links.tmp/$sf
2225                                deplist="$deplist $sf"
2226                            fi
2227                            ;;
2228                    esac
2229                    if test "x$ignore_f" = xf ; then
2230                        extn=`echo $sf | $AWK -F. '{print $NF}'`
2231                        case $extn in
2232                            F)
2233                                echo    " \\"  >> srclist.inc
2234                                printf " $sf" >> srclist.inc
2235                                ;;
2236                            F90)
2237                                echo    " \\"  >> f90srclist.inc
2238                                printf " $sf" >> f90srclist.inc
2239                                ;;
2240                            c)
2241                                echo    " \\"  >> csrclist.inc
2242                                printf " $sf" >> csrclist.inc
2243                                ;;
2244                            h)
2245                                echo    " \\"  >> hlist.inc
2246                                printf " $sf" >> hlist.inc
2247                                ;;
2248                            flow)
2249                                echo    " \\"  >> ad_flow_files.inc
2250                                printf " $sf" >> ad_flow_files.inc
2251                                ;;
2252                        esac
2253                    fi
2254              fi              fi
2255          fi          fi
2256      done      done
# Line 1138  echo "" >> f90srclist.inc Line 2268  echo "" >> f90srclist.inc
2268  echo "" >> hlist.inc  echo "" >> hlist.inc
2269  echo "" >> ad_flow_files.inc  echo "" >> ad_flow_files.inc
2270    
2271  if test -e $MAKEFILE ; then  if test -f $MAKEFILE ; then
2272      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.bak"
2273  fi  fi
2274  echo "  Writing makefile: $MAKEFILE"  echo "  Writing makefile: $MAKEFILE"
# Line 1147  echo "#    $MACHINE" >> $MAKEFILE Line 2277  echo "#    $MACHINE" >> $MAKEFILE
2277  echo "# This makefile was generated automatically on" >> $MAKEFILE  echo "# This makefile was generated automatically on" >> $MAKEFILE
2278  echo "#    $THISDATE" >> $MAKEFILE  echo "#    $THISDATE" >> $MAKEFILE
2279  echo "# by the command:" >> $MAKEFILE  echo "# by the command:" >> $MAKEFILE
2280  echo "#    $0 $@" >> $MAKEFILE  echo "#    $0 $G2ARGS" >> $MAKEFILE
2281  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
2282  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE  echo "#    ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
2283    
2284    EXE_AD=$EXECUTABLE"_ad"
2285    EXE_FTL=$EXECUTABLE"_ftl"
2286    EXE_SVD=$EXECUTABLE"_svd"
2287    
2288  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2289    #
2290    # OPTFILE="$OPTFILE"
2291  #  #
2292  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
2293  # SOURCEDIRS   : Directories containing the source (.F) files  # SOURCEDIRS   : Directories containing the source (.F) files
# Line 1180  TOOLSDIR    = ${TOOLSDIR} Line 2317  TOOLSDIR    = ${TOOLSDIR}
2317    
2318  #eh3  new defines for the adjoint work  #eh3  new defines for the adjoint work
2319  AUTODIFF    = ${ROOTDIR}/pkg/autodiff  AUTODIFF    = ${ROOTDIR}/pkg/autodiff
2320    EXE_AD      = ${EXE_AD}
2321    EXE_FTL     = ${EXE_FTL}
2322    EXE_SVD     = ${EXE_SVD}
2323    
2324    ENABLED_PACKAGES = ${ENABLED_PACKAGES}
2325    DISABLED_PACKAGES = ${DISABLED_PACKAGES}
2326    
2327    # These files are created by Makefile
2328    SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h
2329  EOF  EOF
2330    
2331  #  Note: figure out some way to add Hyades JAM libraries here  if test "x$EMBED_SRC" = xt ; then
2332        echo "EMBEDDED_FILES = EMBEDDED_FILES.h" >>$MAKEFILE
2333    else
2334        echo "EMBEDDED_FILES = " >>$MAKEFILE
2335    fi
2336    
2337    #  Note: figure out some way to add Hyades JAM libraries here
2338  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2339  # Unix ln (link)  # Unix ln (link)
2340  LN = ${LN}  LN = ${LN}
# Line 1198  KPP = ${KPP} Line 2348  KPP = ${KPP}
2348  FC = ${FC}  FC = ${FC}
2349  # Fortran compiler  # Fortran compiler
2350  F90C = ${F90C}  F90C = ${F90C}
2351    # C compiler
2352    CC = ${CC}
2353  # Link editor  # Link editor
2354  LINK = ${LINK}  LINK = ${LINK} ${LDADD}
2355    
2356  # Defines for CPP  # Defines for CPP
2357  DEFINES = ${DEFINES}  DEFINES = ${DEFINES}
# Line 1220  CFLAGS = ${CFLAGS} Line 2372  CFLAGS = ${CFLAGS}
2372  NOOPTFILES = ${NOOPTFILES}  NOOPTFILES = ${NOOPTFILES}
2373  NOOPTFLAGS = ${NOOPTFLAGS}  NOOPTFLAGS = ${NOOPTFLAGS}
2374  # Flags and libraries needed for linking  # Flags and libraries needed for linking
2375  LIBS = ${LIBS} \$(XLIBS)  LIBS = ${LIBS}
2376  # Name of the Mekfile  # Name of the Mekfile
2377  MAKEFILE=${MAKEFILE}  MAKEFILE=${MAKEFILE}
2378    
# Line 1231  cat csrclist.inc      >> $MAKEFILE Line 2383  cat csrclist.inc      >> $MAKEFILE
2383  cat f90srclist.inc    >> $MAKEFILE  cat f90srclist.inc    >> $MAKEFILE
2384  cat hlist.inc         >> $MAKEFILE  cat hlist.inc         >> $MAKEFILE
2385  cat ad_flow_files.inc >> $MAKEFILE  cat ad_flow_files.inc >> $MAKEFILE
2386  echo               >> $MAKEFILE  echo >> $MAKEFILE
2387  echo 'F77FILES =  $(SRCFILES:.F=.f)'                                           >> $MAKEFILE  echo 'F77FILES =  $(SRCFILES:.F=.'$FS')'      >> $MAKEFILE
2388  echo 'F90FILES =  $(F90SRCFILES:.F90=.f90)'                                    >> $MAKEFILE  echo 'F90FILES =  $(F90SRCFILES:.F90=.'$FS90')' >> $MAKEFILE
2389  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
2390    echo >> $MAKEFILE
2391    echo '.SUFFIXES:' >> $MAKEFILE
2392    echo '.SUFFIXES: .o .'$FS' .p .F .c .'$FS90' .F90' >> $MAKEFILE
2393  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
2394  rm -f ad_flow_files.inc  rm -f ad_flow_files.inc
2395    
2396  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2397    
 .SUFFIXES:  
 .SUFFIXES: .o .f .p .F .c .F90 .f90  
   
2398  all: \$(EXECUTABLE)  all: \$(EXECUTABLE)
2399  \$(EXECUTABLE): \$(OBJFILES)  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(OBJFILES) \$(EMBEDDED_FILES)
2400            @echo Creating \$@ ...
2401          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
2402  depend:  depend:
2403          @make links          @make links
2404          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
2405          ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE)          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2406            -rm -f makedepend.out
2407    
2408    lib: libmitgcmuv.a
2409    
2410  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)  libmitgcmuv.a: \$(OBJFILES)
2411            ar rcv libmitgcmuv.a \$(OBJFILES)
2412    
2413    links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES)
2414    
2415  small_f: \$(F77FILES) \$(F90FILES)  small_f: \$(F77FILES) \$(F90FILES)
2416    
# Line 1261  output.txt: \$(EXECUTABLE) Line 2419  output.txt: \$(EXECUTABLE)
2419          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
2420    
2421  clean:  clean:
2422          -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}          -rm -rf *.o *.$FS *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
2423  Clean:  Clean:
2424          @make clean          @make clean
2425          @make cleanlinks          @make cleanlinks
2426          -rm -f Makefile.bak genmake_state genmake_optfile make.log          -rm -f \$(SPECIAL_FILES)
2427            -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak
2428  CLEAN:  CLEAN:
2429          @make Clean          @make Clean
2430          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
2431          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
2432          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
2433          -rm -f \$(EXECUTABLE) output.txt          -rm -f \$(EXECUTABLE) *.txt STD* *diagnostics.log datetime
2434            -rm -rf mnc_test_*
2435    
2436  Makefile: makefile  #eh3 Makefile: makefile
2437  makefile:  makefile:
2438          ${0} $@          $THIS_SCRIPT $G2ARGS
2439  cleanlinks:  cleanlinks:
2440          -find . -type l -exec rm {} \;          -find . -type l -exec rm {} \;
2441    
2442  # The normal chain of rules is (  .F - .f - .o  )  # Special targets (SPECIAL_FILES) which are create by make
2443  .F.f:  ${PACKAGES_DOT_H}:
2444            @echo Creating \$@ ...
2445            @$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) > \$@
2446    AD_CONFIG.h:
2447            @echo Creating \$@ ...
2448            @$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 > \$@
2449    FC_NAMEMANGLE.h:
2450            @echo Creating \$@ ...
2451            echo "$FC_NAMEMANGLE" > \$@
2452    
2453    BUILD_INFO.h:
2454            @echo Creating \$@ ...
2455    EOF
2456    
2457    test ! "x$THISVER" = x  && echo "       -echo \"#define THISVER '$THISVER'\" > \$@"   >> $MAKEFILE
2458    test ! "x$THISUSER" = x && echo "       -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE
2459    test ! "x$THISDATE" = x && echo "       -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
2460    test ! "x$THISHOST" = x && echo "       -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
2461    
2462    if test "x$EMBED_SRC" = xt ; then
2463        cat >>$MAKEFILE <<EOF
2464    
2465    decode_files.o : EMBEDDED_FILES.h
2466    
2467    ##  \$(F77FILES)
2468    all_fF.tar.gz : \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(F77FILES) Makefile
2469            @echo Creating \$@ ...
2470            -tar -hcf all_fF.tar \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(F77FILES) Makefile
2471            -rm -f all_fF.tar.gz
2472            -gzip all_fF.tar
2473    
2474    EMBEDDED_FILES.h : all_fF.tar.gz
2475            @echo Creating \$@ ...
2476            -\${ROOTDIR}/tools/embed_encode/encode_files EMBEDDED_FILES.h all_fF.tar.gz
2477    
2478    EOF
2479    fi
2480    
2481    cat >>$MAKEFILE <<EOF
2482    
2483    # The normal chain of rules is (  .F - .$FS - .o  )
2484    
2485    ## This nullifies any default implicit rules concerning these two file types:
2486    ## %.o : %.F
2487    
2488    .F.$FS:
2489          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2490  .f.o:  .$FS.o:
2491          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2492  .F90.f90:  .F90.$FS90:
2493          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2494  .f90.o:  .$FS90.o:
2495          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
2496  .c.o:  .c.o:
2497          \$(CC) \$(CFLAGS) -c \$<          \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$<
2498    
2499  # Special exceptions that use the ( .F - .p - .f - .o ) rule-chain  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
2500  .F.p:  .F.p:
2501          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2502  .p.f:  .p.$FS:
2503          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
2504    
2505  #=========================================  #=========================================
# Line 1303  cleanlinks: Line 2508  cleanlinks:
2508  TAMC           = ${TAMC}  TAMC           = ${TAMC}
2509  TAF            = ${TAF}  TAF            = ${TAF}
2510    
2511    TAF_EXTRA      = ${TAF_EXTRA}
2512    TAMC_EXTRA     = ${TAMC_EXTRA}
2513    
2514  EOF  EOF
2515    
2516  ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"  ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
# Line 1318  done Line 2526  done
2526    
2527  echo "  Add the source list for AD code generation"  echo "  Add the source list for AD code generation"
2528  echo >> $MAKEFILE  echo >> $MAKEFILE
2529  echo -n "AD_FILES = " >> $MAKEFILE  printf "AD_FILES = " >> $MAKEFILE
2530  AD_FILES=`cat ad_files`  AD_FILES=`cat ad_files`
2531  for i in $AD_FILES ; do  for i in $AD_FILES ; do
2532      echo    " \\" >> $MAKEFILE      echo    " \\" >> $MAKEFILE
2533      echo -n " $i" >> $MAKEFILE      printf " $i" >> $MAKEFILE
2534  done  done
2535  echo >> $MAKEFILE  echo >> $MAKEFILE
2536    rm -f ad_files
2537    
2538  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2539    
2540    # ... AD ...
2541  ad_input_code.f: \$(F77FILES)  adall: ad_taf
2542    adtaf: ad_taf_output.$FS
2543    adtamc: ad_tamc_output.$FS
2544    
2545    ad_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)
2546            @$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
2547            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
2548            -rm -f ad_config.template
2549            @make \$(F77FILES)
2550          @make \$(AD_FLOW_FILES)          @make \$(AD_FLOW_FILES)
2551          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.$FS
2552    
2553    ad_taf_output.$FS: ad_input_code.$FS
2554  ad_taf_output.f: ad_input_code.f          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2555          \$(TAF) \$(AD_TAF_FLAGS) ad_input_code.f          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
2556          cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f  
2557    adtafonly:
2558            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2559            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
2560    
2561  ad_taf: ad_taf_output.o \$(OBJFILES)  ad_taf: ad_taf_output.o \$(OBJFILES)
2562          \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
   
2563    
2564  ad_tamc_output.f: ad_input_code.f  ad_tamc_output.$FS: ad_input_code.$FS
2565          \$(TAMC) \$(AD_TAMC_FLAGS) ad_input_code.f          \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
2566          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
2567    
2568  ad_tamc: ad_tamc_output.o \$(OBJFILES)  ad_tamc: ad_tamc_output.o \$(OBJFILES)
2569          \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
2570    
2571    adonlyfwd:
2572            patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
2573    
2574    adtrick:
2575            patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
2576    
2577  flt_taf_output.f: ad_input_code.f  # ... FTL ...
2578          \$(TAF) \$(FTL_TAF_FLAGS) ad_input_code.f  ftlall: ftl_taf
2579          cat ad_input_code_ad.f | sed -f adjoint_sed > flt_taf_output.f  ftltaf: ftl_taf_output.$FS
2580    ftltamc: ftl_tamc_output.$FS
2581  flt_taf: flt_taf_output.o \$(OBJFILES)  
2582          \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) flt_taf_output.o \$(LIBS)  ftl_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)
2583            @$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
2584            cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
2585            -rm -f ftl_config.template
2586            @make \$(F77FILES)
2587            @make \$(AD_FLOW_FILES)
2588            cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.$FS
2589    
2590    ftl_taf_output.$FS: ftl_input_code.$FS
2591            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2592            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2593    
2594    ftltafonly:
2595            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2596            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2597    
2598    ftl_taf: ftl_taf_output.o \$(OBJFILES)
2599            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
2600    
2601    ftl_tamc_output.$FS: ftl_input_code.$FS
2602            \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
2603            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS
2604    
2605    ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
2606            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
2607    
2608    
2609    # ... SVD ...
2610    svdtaf: ad_taf_output.$FS ftl_taf_output.$FS
2611            @echo "--->>> Only ran TAF to generate SVD code!    <<<---"
2612            @echo "--->>> Do make svdall afterwards to compile. <<<---"
2613    svdall: svd_touch svd_taf
2614    
2615    svd_taf: \$(OBJFILES)
2616            \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
2617    
2618            @echo "--->>> Only COMPILE svd code! <<<---"
2619            @echo "--->>> Assumes you previously <<<---"
2620            @echo "--->>> did make svdtaf        <<<---"
2621    
2622    svd_touch:
2623            @echo "--->>> Only COMPILE svd code! <<<---"
2624            @echo "--->>> Assumes you previously <<<---"
2625            @echo "--->>> did make svdtaf        <<<---"
2626            touch ad_taf_output.$FS ftl_taf_output.$FS
2627            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS
2628            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS
2629            @$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
2630            cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
2631            -rm -f ftl_config.template
2632    
2633  #=========================================  #=========================================
2634    
# Line 1374  for i in $KPPFILES ; do Line 2645  for i in $KPPFILES ; do
2645      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
2646          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
2647      fi      fi
2648      echo "$base.f: $base.p" >> $MAKEFILE      echo "$base.$FS: $base.p" >> $MAKEFILE
2649  done  done
2650    
2651  echo "  Making list of NOOPTFILES"  echo "  Making list of NOOPTFILES"
# Line 1384  for i in $NOOPTFILES ; do Line 2655  for i in $NOOPTFILES ; do
2655      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
2656          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
2657      fi      fi
2658      echo "$base.o: $base.f" >> $MAKEFILE      echo "$base.o: $base.$FS" >> $MAKEFILE
2659      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
2660  done  done
2661    
# Line 1397  printf "\n\n# DO NOT DELETE\n" >> $MAKEF Line 2668  printf "\n\n# DO NOT DELETE\n" >> $MAKEF
2668    
2669  printf "\n===  Done  ===\n"  printf "\n===  Done  ===\n"
2670    
2671    # Create special header files
2672    $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"
2673    if test ! -f $PACKAGES_DOT_H ; then
2674        mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2675    else
2676        cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
2677        RETVAL=$?
2678        if test "x$RETVAL" = x0 ; then
2679            rm -f $PACKAGES_DOT_H".tmp"
2680        else
2681            mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
2682            mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2683        fi
2684    fi
2685    if test ! -f AD_CONFIG.h ; then
2686        $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
2687    fi
2688    
2689    
2690  #  Write the "state" for future records  #  Write the "state" for future records
2691  if test "x$DUMPSTATE" != xf ; then  if test "x$DUMPSTATE" != xf ; then
2692      echo -n "" > genmake_state      printf "" > genmake_state
2693      for i in $gm_state ; do      for i in $gm_state ; do
2694          t1="t2=\$$i"          t1="t2=\$$i"
2695          eval $t1          eval $t1

Legend:
Removed from v.1.13.2.6  
changed lines
  Added in v.1.146

  ViewVC Help
Powered by ViewVC 1.1.22