/[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.1 by edhill, Sat Aug 16 14:01:08 2003 UTC revision 1.135 by edhill, Thu Nov 17 20:06:08 2005 UTC
# Line 1  Line 1 
1  #!/bin/bash  #! /usr/bin/env bash
2  #  #
3  # $Header$  # $Header$
4  #  #
# Line 8  Line 8 
8  #   modified by aja 01/00  #   modified by aja 01/00
9  #   rewritten in bash by eh3 08/03  #   rewritten in bash by eh3 08/03
10    
11    # Search for particular CPP #cmds associated with packages
12    # usage: test_for_package_in_cpp_options CPP_file package_name
13    test_for_package_in_cpp_options() {
14        cpp_options=$1
15        pkg=$2
16        test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg" || exit 99
17        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg" || exit 99
18        test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg" || exit 99
19        test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg" || exit 99
20    }
21    
22    # Search for particular CPP #cmds associated with MPI
23    # usage: test_for_mpi_in_cpp_eeoptions CPP_file
24    test_for_mpi_in_cpp_eeoptions() {
25        cpp_options=$1
26        test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI" || exit 99
27        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI" || exit 99
28        test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI" || exit 99
29        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI" || exit 99
30    }
31    
32    # Search for particular string in a file. Return 1 if detected, 0 if not
33    # usage: test_for_string_in_file file string
34    test_for_string_in_file() {
35        file=$1
36        strng=$2
37        grep -i "$strng" $file > /dev/null 2>&1
38        RETVAL=$?
39        if test "x${RETVAL}" = x0 ; then
40            printf "Error: In $file there is an illegal line: "
41            grep -i "$strng" $file
42            return 1
43        fi
44        return 0
45    }
46    
47    # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to
48    # the package list.
49    expand_pkg_groups() {
50        new_packages=
51        PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups"
52        if test -r $PKG_GROUPS ; then
53            cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp
54            cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp
55            matched=0
56            for i in $PACKAGES ; do
57                line=`grep "^ *$i" ./p2.tmp`
58                RETVAL=$?
59                if test "x$RETVAL" = x0 ; then
60                    matched=1
61                    replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`
62                    echo "    replacing \"$i\" with: $replace"
63                    new_packages="$new_packages $replace"
64                else
65                    new_packages="$new_packages $i"
66                fi
67            done
68            PACKAGES=$new_packages
69            rm -f ./p[1,2].tmp
70            return $matched
71        else
72            echo "Warning: can't read package groups definition file: $PKG_GROUPS"
73        fi
74    }
75    
76    #  Check for broken environments (eg. cygwin, MacOSX w/HFS+) that
77    #  cannot distinguish [*.F/*.F90] from [*.f/*.f90] files.
78    check_for_broken_Ff()  {
79        #  Do we have defaults for $FS and/or $FS90 ?
80        tfs=f
81        tfs9=f90
82        if test "x$FS" != x ; then
83            tfs="$FS"
84        fi
85        if test "x$FS90" != x ; then
86            tfs9="$FS90"
87        fi
88    
89        #  First check the ability to create a *.F/.f pair.
90        cat <<EOF >> genmake_hello.F
91          program hello
92          write(*,*) 'hi'
93          stop
94          end
95    EOF
96        cp genmake_hello.F "genmake_hello."$tfs > /dev/null 2>&1
97        RETVAL=$?
98        if test "x$RETVAL" != x0 ; then
99            if test "x$FS" = x ; then
100                FS='for'
101                FS90='fr9'
102                check_for_broken_Ff
103            else
104                cat <<EOF 2>&1
105    ERROR: Your file system cannot distinguish between *.F and *.f files
106      (fails the "cp" test) and this program cannot find a suitable
107      replacement extension.  Please try a different build environment or
108      contact the <MITgcm-support@mitgcm.org> list for help.
109    
110    EOF
111                exit -1
112            fi
113            return
114        fi
115        rm -f genmake_hello.*
116    
117        #  Check the ability of ${MAKE} and ${LN} to use the current set
118        #  of extensions.
119        cat <<EOF >> genmake_hello.F
120          program hello
121          write(*,*) 'hi'
122          stop
123          end
124    EOF
125        test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
126        cat <<EOF >> $MAKEFILE
127    .SUFFIXES:
128    .SUFFIXES: .$tfs .F
129    .F.$tfs:
130            $LN \$< \$@
131    EOF
132        $MAKE "genmake_hello."$tfs > /dev/null 2>&1
133        RETVAL=$?
134        if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then
135            if test "x$FS" = x ; then
136                FS='for'
137                FS90='fr9'
138                check_for_broken_Ff
139            else
140                cat <<EOF 2>&1
141    ERROR: Your file system cannot distinguish between *.F and *.f files
142      (fails the "make/ln" test) and this program cannot find a suitable
143      replacement extension.  Please try a different build environment or
144      contact the <MITgcm-support@mitgcm.org> list for help.
145    
146    EOF
147                exit -1
148                return
149            fi
150        fi
151        rm -f genmake_hello.* $MAKEFILE
152        test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
153    
154        #  If we make it here, use the extensions
155        FS=$tfs
156        FS90=$tfs9
157        return
158    }
159    
160    
161    look_for_makedepend()  {
162    
163        #  The "original" makedepend is part of the Imake system that is
164        #  most often distributed with XFree86 or with an XFree86 source
165        #  package.  As a result, many machines (eg. generic Linux) do not
166        #  have a system-default "makedepend" available.  For those
167        #  systems, we have two fall-back options:
168        #
169        #    1) a makedepend implementation shipped with the cyrus-imapd
170        #       package:  ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
171        #
172        #    2) a known-buggy xmakedpend shell script
173        #
174        #  So the choices are, in order:
175        #
176        #    1) use the user-specified program
177        #    2) use a system-wide default
178        #    3) locally build and use the cyrus implementation
179        #    4) fall back to the buggy local xmakedpend script
180        #
181        if test "x${MAKEDEPEND}" = x ; then
182            which makedepend > /dev/null 2>&1
183            RV0=$?
184            test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
185            #  echo 'MAKEFILE="'$MAKEFILE'"'
186            cat <<EOF >> $MAKEFILE
187    #   THIS IS A TEST MAKEFILE GENERATED BY "genmake2"
188    #
189    #   Some "makedepend" implementations will die if they cannot
190    #   find a Makefile -- so this file is here to gives them an
191    #   empty one to find and parse.
192    EOF
193            cat <<EOF >> genmake_tc.f
194          program test
195          write(*,*) 'test'
196          stop
197          end
198    EOF
199            makedepend genmake_tc.f > /dev/null 2>&1
200            RV1=$?
201            test -f $MAKEFILE  &&  rm -f $MAKEFILE
202            test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
203            if test "x${RV0}${RV1}" = x00 ; then
204                MAKEDEPEND=makedepend
205            else
206                echo "    a system-default makedepend was not found."
207                
208                #  Try to build the cyrus implementation
209                build_cyrus_makedepend
210                RETVAL=$?
211                if test "x$RETVAL" != x0 ; then
212                    MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
213                fi
214                rm -f ./genmake_cy_md
215            fi
216        else
217            #  echo "MAKEDEPEND=${MAKEDEPEND}"
218            echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1
219            RETVAL=$?
220            if test x"$RETVAL" = x0 ; then
221                build_cyrus_makedepend
222            fi
223        fi
224    }
225    
226    
227    build_cyrus_makedepend()  {
228        rm -f ./genmake_cy_md
229        (
230            cd $ROOTDIR/tools/cyrus-imapd-makedepend  \
231                &&  ./configure > /dev/null 2>&1  \
232                &&  make > /dev/null 2>&1
233            if test -x ./makedepend.exe ; then
234                $LN ./makedepend.exe ./makedepend
235            fi
236            ./makedepend ifparser.c > /dev/null 2>&1  \
237                &&  echo "true"
238        ) > ./genmake_cy_md
239        grep true ./genmake_cy_md > /dev/null 2>&1
240        RETVAL=$?
241        rm -f ./genmake_cy_md
242        if test "x$RETVAL" = x0 ; then
243            MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
244            return 0
245        else
246            echo "WARNING: unable to build cyrus-imapd-makedepend"
247            return 1
248        fi
249    }
250    
251  # Guess possible config options for this host  # Guess possible config options for this host
252  find_possible_configs()  {  find_possible_configs()  {
253    
254      p_PLATFORM=`uname`"-"`uname -m`      tmp1=`uname`"_"`uname -m`
255      echo "The platform appears to be:"      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
256      echo "  "$p_PLATFORM      tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
257        tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
258      p_LN=      tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
259        tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
260        PLATFORM=$tmp3
261        echo $PLATFORM | grep cygwin > /dev/null 2>&1  &&  PLATFORM=cygwin_ia32
262        OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
263        echo "  The platform appears to be:  $PLATFORM"
264        
265      echo "test" > test      echo "test" > test
266      ln -s ./test link      ln -s ./test link
267      RETVAL=$?      RETVAL=$?
268      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
269          p_LN="ln -s"          LN="ln -s"
270        else
271            echo "Error: \"ln -s\" does not appear to work on this system!"
272            echo "  For help, please contact <MITgcm-support@mitgcm.org>."
273            exit 1
274      fi      fi
275      rm -f test link      rm -f test link
276    
277      p_CPP=`which cpp`      if test "x$CPP" = x ; then
278                CPP="cpp -traditional -P"
     RETVAL=$?  
     if test "x${RETVAL}" = x0 ; then  
         p_LN="ln -s"  
279      fi      fi
     rm -f test link  
280    
281      # look for possible fortran compilers      look_for_makedepend
282      p_FC=  
283      for c in f77 g77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 ; do      #================================================================
284          which $c > /dev/null 2>&1      #  look for possible C compilers
285        tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc"
286        p_CC=
287        for c in $tmp ; do
288            rm -f ./genmake_hello.c  ./genmake_hello
289            cat >> genmake_hello.c << EOF
290    #include <stdio.h>
291    int main(int argc, char **argv) {
292      printf("Hello!\n");
293      return 0;
294    }
295    EOF
296            $c -o genmake_hello genmake_hello.c > /dev/null 2>&1
297          RETVAL=$?          RETVAL=$?
298          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
299              p_FC="$p_FC $c"              p_CC="$p_CC $c"
300          fi          fi
301      done      done
302      echo "Possible FORTRAN compilers appear to be:  "      rm -f ./genmake_hello.c ./genmake_hello
303      if test "x${p_FC}" = x ; then      if test "x${p_CC}" = x ; then
304          echo "  None found!!!"          cat 1>&2 <<EOF
305    
306    Error: No C compilers were found in your path.  Please specify one using:
307    
308        1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
309        2) the CC or MITGCM_CC environment variables.
310    
311    EOF
312            exit 1
313      else      else
314          echo "  "$p_FC          echo "  The possible C compilers found in your path are:"
315            echo "   "$p_CC
316            if test "x$CC" = x ; then
317                CC=`echo $p_CC | $AWK '{print $1}'`
318                echo "  Setting C compiler to: "$CC
319            fi
320      fi      fi
321    
322      # look for possible MPI libraries      #================================================================
323      mpi_libs=      #  look for possible FORTRAN compilers
324      mpi_fort=`which mpif77 2>/dev/null`      tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 gfortran"
325      RETVAL=$?      p_FC=
326      if test "x${RETVAL}" = x0 ; then      for c in $tmp ; do
327          cat >>test.f <<EOF          rm -f ./hello.f ./hello
328        PROGRAM HELLO          cat >> hello.f <<EOF
329        DO 10, I=1,10        program hello
330        PRINT *,'Hello World'        do i=1,3
331     10 CONTINUE          print *, 'hello world : ', i
332        STOP        enddo
333        END        end
334  EOF  EOF
335          eval "$mpi_fort -showme test.f > out"          $c -o hello hello.f > /dev/null 2>&1
336          RETVAL=$?          RETVAL=$?
337          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
338              a=`cat out`              p_FC="$p_FC $c"
339              for i in $a ; do          fi
340                  case $i in      done
341                      -*)      rm -f ./hello.f ./hello
342                          mpi_libs="$mpi_libs $i" ;;      if test "x${p_FC}" = x ; then
343                  esac          cat 1>&2 <<EOF
344              done  
345              echo "The MPI libs appear to be:"  Error: No Fortran compilers were found in your path.  Please specify one using:
346              echo "  "$mpi_libs  
347        1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
348        2) a command-line option (eg. "-fc NAME"), or
349        3) the FC or MITGCM_FC environment variables.
350    
351    EOF
352            exit 1
353        else
354            echo "  The possible FORTRAN compilers found in your path are:"
355            echo "   "$p_FC
356            if test "x$FC" = x ; then
357                FC=`echo $p_FC | $AWK '{print $1}'`
358                echo "  Setting FORTRAN compiler to: "$FC
359          fi          fi
         rm -f test.f out  
360      fi      fi
361    
362  }      if test "x$OPTFILE" = x ; then
363            OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
364            if test ! -r $OPTFILE ; then
365                 echo "  I looked for the file "$OPTFILE" but did not find it"
366            fi
367        fi
368    #    echo "  The options file:  $p_OF"
369    #    echo "    appears to match so we'll use it."
370    #   for i in $p_FC ; do
371    #p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
372    #if test -r $p_OF ; then
373    #    OPTFILE=$p_OF
374    #    echo "  The options file:  $p_OF"
375    #    echo "    appears to match so we'll use it."
376    #    break
377    #fi
378    #   done
379        if test "x$OPTFILE" = x ; then
380            cat 1>&2 <<EOF
381    
382    Error: No options file was found in:  $ROOTDIR/tools/build_options/
383      that matches this platform ("$PLATFORM") and the compilers found in
384      your path.  Please specify an "optfile" using:
385    
386  parse_options()  {      1) the command line (eg. "-optfile=path/to/OPTFILE"), or
387        2) the MITGCM_OF environment variable.
388    
389      ac_prev=    If you need help, please contact the developers at <MITgcm-support@mitgcm.org>.
390      for ac_option in "${OPTIONS[@]}" ; do  
391    EOF
392            exit 1
393        fi
394        
395    #     # look for possible MPI libraries
396    #     mpi_libs=
397    #     mpi_fort=`which mpif77 2>/dev/null`
398    #     RETVAL=$?
399    #     if test "x${RETVAL}" = x0 ; then
400    #       cat >>test.f <<EOF
401    #       PROGRAM HELLO
402    #       DO 10, I=1,10
403    #       PRINT *,'Hello World'
404    #    10 CONTINUE
405    #       STOP
406    #       END
407    # EOF
408    #       eval "$mpi_fort -showme test.f > out"
409    #       RETVAL=$?
410    #       if test "x${RETVAL}" = x0 ; then
411    #           a=`cat out`
412    #           for i in $a ; do
413    #               case $i in
414    #                   -*)
415    #                       mpi_libs="$mpi_libs $i" ;;
416    #               esac
417    #           done
418    #           echo "The MPI libs appear to be:"
419    #           echo "  "$mpi_libs
420    #       fi
421    #       rm -f test.f out
422    #     fi
423    
         # echo "ac_option = :$ac_option:"  
           
         # If the previous option needs an argument, assign it.  
         if test -n "$ac_prev"; then  
             eval "$ac_prev=\$ac_option"  
             ac_prev=  
             continue  
         fi  
           
         ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`  
           
         case $ac_option in  
               
             -help | --help | -h | --h)  
                 usage ;;  
               
             -nooptfile | --nooptfile)  
                 OPTFILE="NONE" ;;  
             -optfile | --optfile | -of | --of)  
                 ac_prev=optfile ;;  
             -optfile=* | --optfile=* | -of=* | --of=*)  
                 OPTFILE=$ac_optarg ;;  
               
             -pdepend | --pdepend)  
                 ac_prev=pdepend ;;  
             -pdepend=* | --pdepend=*)  
                 PDEPEND=$ac_optarg ;;  
               
             -pdefault | --pdefault)  
                 ac_prev=pdefault ;;  
             -pdefault=* | --pdefault=*)  
                 PDEFAULT=$ac_optarg ;;  
               
             -makefile | -ma)  
                 ac_prev=makefile ;;  
             --makefile=* | -ma=*)  
                 MAKEFILE=$ac_optarg ;;  
               
             -platform | --platform | -pl | --pl)  
                 ac_prev=platform ;;  
             -platform=* | --platform=* | -pl=* | --pl=*)  
                 PLATFORM=$ac_optarg ;;  
   
             -rootdir | --rootdir | -rd | --rd)  
                 ac_prev=rootdir ;;  
             -rootdir=* | --rootdir=* | -rd=* | --rd=*)  
                 ROOTDIR=$ac_optarg ;;  
               
             -mods | --mods | -mo | --mo)  
                 ac_prev=mods ;;  
             -mods=* | --mods=* | -mo=* | --mo=*)  
                 MODS=$ac_optarg ;;  
               
             -disable | --disable)  
                 ac_prev=disable ;;  
             -disable=* | --disable=*)  
                 DISABLE=$ac_optarg ;;  
               
             -enable | --enable)  
                 ac_prev=enable ;;  
             -enable=* | --enable=*)  
                 ENABLE=$ac_optarg ;;  
               
             -noopt | --noopt)  
                 ac_prev=noopt ;;  
             -noopt=* | --noopt=*)  
                 NOOPT=$ac_optarg ;;  
               
 #           -cpp | --cpp)  
 #               ac_prev=cpp ;;  
 #           -cpp=* | --cpp=*)  
 #               CPP=$ac_optarg ;;  
               
             -fortran | --fortran | -fc | --fc)  
                 ac_prev=fc ;;  
             -fc=* | --fc=*)  
                 FC=$ac_optarg ;;  
               
             -ieee | --ieee)  
                 IEEE=1 ;;  
             -noieee | --noieee)  
                 IEEE=0 ;;  
               
             -mpi | --mpi)  
                 MPI=1 ;;  
             -nompi | --nompi)  
                 MPI=0 ;;  
               
             -jam | --jam)  
                 JAM=1 ;;  
             -nojam | --nojam)  
                 JAM=0 ;;  
               
             -*)  
                 echo "Error: unrecognized option: "$ac_option  
                 usage  
                 ;;  
               
             *)  
                 echo "Error: unrecognized argument: "$ac_option  
                 usage  
                 ;;  
               
         esac  
           
     done  
424  }  }
425    
426  #  Parse the package dependency information  #  Parse the package dependency information
# Line 199  get_pdepend_list()  { Line 429  get_pdepend_list()  {
429      #  strip the comments and then convert the dependency file into      #  strip the comments and then convert the dependency file into
430      #  two arrays: PNAME, DNAME      #  two arrays: PNAME, DNAME
431      cat $1 | sed -e 's/#.*$//g' \      cat $1 | sed -e 's/#.*$//g' \
432          | 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} }' \
433          > ./.pd_tmp          > ./.pd_tmp
434      source ./.pd_tmp      . ./.pd_tmp
435      rm -f ./.pd_tmp      rm -f ./.pd_tmp
436    
437      echo -n "PNAME = "${}      printf "PNAME = "${}
438  }  }
439    
440    
441  #  Explain usage  #  Explain usage
442  usage()  {  usage()  {
443      echo ""  cat <<EOF
444      echo "Usage: "$0" [OPTIONS]"  
445      echo "  where [OPTIONS] can be:"$'\n'  Usage: "$0" [OPTIONS]
446      echo "    -help | --help | -h | --h"    where [OPTIONS] can be:
447      echo "    -nooptfile | --nooptfile"  
448      echo "      -optfile NAME | --optfile NAME | -of NAME | --of NAME"      -help | --help | -h | --h
449      echo "      -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME"            Print this help message and exit.
450      echo "    -pdepend NAME | --pdepend NAME"  
451      echo "      -pdepend=NAME | --pdepend=NAME"      -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME
452      echo "    -pdefault NAME | --pdefault NAME"        -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME
453      echo "      -pdefault=NAME | --pdefault=NAME"            Use "NAME" as the adoptfile.  By default, the file at
454      echo "    -makefile NAME | -ma NAME"            "tools/adjoint_options/adjoint_default" will be used.
455      echo "      --makefile=NAME | -ma=NAME"  
456      echo "    -platform NAME | --platform NAME | -pl NAME | --pl NAME"      -nooptfile | --nooptfile
457      echo "      -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"        -optfile NAME | --optfile NAME | -of NAME | --of NAME
458      echo "    -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"        -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
459      echo "      -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME"            Use "NAME" as the optfile.  By default, an attempt will be
460      echo "    -mods NAME | --mods NAME | -mo NAME | --mo NAME"            made to find an appropriate "standard" optfile in the
461      echo "      -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME"            tools/build_options/ directory.
462      echo "    -disable NAME | --disable NAME"  
463      echo "      -disable=NAME | --disable=NAME"      -pdepend NAME | --pdepend NAME
464      echo "    -enable NAME | --enable NAME"        -pdepend=NAME | --pdepend=NAME
465      echo "      -enable=NAME | --enable=NAME"            Get package dependency information from "NAME".
466      echo "    -noopt NAME | --noopt NAME"  
467      echo "      -noopt=NAME | --noopt=NAME"      -pdefault NAME | --pdefault NAME
468  #    echo "    -cpp NAME | --cpp NAME"        -pdefault=NAME | --pdefault=NAME
469  #    echo "      -cpp=NAME | --cpp=NAME"            Get the default package list from "NAME".
470      echo "    -fortran NAME | --fortran NAME | -fc NAME | --fc NAME"  
471      echo "      -fc=NAME | --fc=NAME"      -make NAME | -m NAME
472      echo "    -[no]ieee | --[no]ieee"        --make=NAME | -m=NAME
473      echo "    -[no]mpi | --[no]mpi"            Use "NAME" for the MAKE program. The default is "make" but
474      echo "    -[no]jam | --[no]jam"$'\n'            many platforms, "gmake" is the preferred choice.
475      echo "  and NAME is a string such as:"$'\n'  
476      echo "    --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'"      -makefile NAME | -mf NAME
477      echo "    -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'"        --makefile=NAME | -mf=NAME
478      echo "    -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"$'\n'            Call the makefile "NAME".  The default is "Makefile".
479      echo "  which, depending upon your shell, may need to be single-quoted"  
480      echo "  if it contains spaces, dashes, or other special characters."      -makedepend NAME | -md NAME
481          --makedepend=NAME | -md=NAME
482              Use "NAME" for the MAKEDEPEND program.
483    
484        -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
485          -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
486              Specify the location of the MITgcm ROOTDIR as "NAME".
487              By default, genamke will try to find the location by
488              looking in parent directories (up to the 5th parent).
489    
490        -mods NAME | --mods NAME | -mo NAME | --mo NAME
491          -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
492              Here, "NAME" specifies a list of directories that are
493              used for additional source code.  Files found in the
494              "mods list" are given preference over files of the same
495              name found elsewhere.
496    
497        -disable NAME | --disable NAME
498          -disable=NAME | --disable=NAME
499              Here "NAME" specifies a list of packages that we don't
500              want to use.  If this violates package dependencies,
501              genamke will exit with an error message.
502    
503        -enable NAME | --enable NAME
504          -enable=NAME | --enable=NAME
505              Here "NAME" specifies a list of packages that we wish
506              to specifically enable.  If this violates package
507              dependencies, genamke will exit with an error message.
508    
509        -standarddirs NAME | --standarddirs NAME
510          -standarddirs=NAME | --standarddirs=NAME
511              Here, "NAME" specifies a list of directories to be
512              used as the "standard" code.
513    
514        -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
515          -fc=NAME | --fc=NAME
516              Use "NAME" as the fortran compiler.  By default, genmake
517              will search for a working compiler by trying a list of
518              "usual suspects" such as g77, f77, etc.
519    
520        -cc NAME | --cc NAME | -cc=NAME | --cc=NAME
521              Use "NAME" as the C compiler.  By default, genmake
522              will search for a working compiler by trying a list of
523              "usual suspects" such as gcc, c89, cc, etc.
524    
525        -[no]ieee | --[no]ieee
526              Do or don't use IEEE numerics.  Note that this option
527              *only* works if it is supported by the OPTFILE that
528              is being used.
529    
530        -ts | --ts
531              Produce timing information per timestep
532    
533        -mpi | --mpi
534              Include MPI header files and link to MPI libraries
535        -mpi=PATH | --mpi=PATH
536              Include MPI header files and link to MPI libraries using MPI_ROOT
537              set to PATH. i.e. Include files from \$PATH/include, link to libraries
538              from \$PATH/lib and use binaries from \$PATH/bin.
539    
540        -bash NAME
541              Explicitly specify the Bourne or BASH shell to use
542    
543      While it is most often a single word, the "NAME" variables specified
544      above can in many cases be a space-delimited string such as:
545    
546        --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'
547        -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'
548        -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
549    
550      which, depending upon your shell, may need to be single-quoted.
551    
552      For more detailed genmake documentation, please see:
553    
554        http://mitgcm.org/devel_HOWTO/
555    
556    EOF
557    
558      exit 1      exit 1
559  }  }
560    
561  # Dump all important state  #  Build a CPP macro to automate calling C routines from FORTRAN
562  dump_state()  {  get_fortran_c_namemangling()  {
563      fname=$1  
564      echo " " > $fname      #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
565      RETVAL=$?      if test ! "x$FC_NAMEMANGLE" = x ; then
566      if test "x${RETVAL}" = x ; then          return 0
567          echo "Error: cannot write to $fname"      fi
568          exit 1  
569      fi      default_nm="#define FC_NAMEMANGLE(X) X ## _"
570      echo "makefile "$makefile > $fname      
571  }      cat > genmake_test.c <<EOF
572    void tcall( char * string ) { tsub( string ); }
573    EOF
574        $MAKE genmake_test.o >> genmake_warnings 2>&1
575        RETVAL=$?
576        if test "x$RETVAL" != x0 ; then
577            FC_NAMEMANGLE=$default_nm
578            cat <<EOF>> genmake_errors
579    
580    WARNING: C test compile fails
581    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
582    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
583    EOF
584            return 1
585        fi
586        c_tcall=`nm genmake_test.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
587        RETVAL=$?
588        if test "x$RETVAL" != x0 ; then
589            FC_NAMEMANGLE=$default_nm
590            cat <<EOF>> genmake_warnings
591    
592    WARNING: The "nm" command failed.
593    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
594    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
595    EOF
596            return 1
597        fi
598        cat > genmake_tcomp.$FS <<EOF
599          subroutine tcall( string )
600          character*(*) string
601          call tsub( string )
602          end
603    EOF
604        $FC $FFLAGS -c genmake_tcomp.$FS >> genmake_warnings 2>&1
605        RETVAL=$?
606        if test "x$RETVAL" != x0 ; then
607            FC_NAMEMANGLE=$default_nm
608            cat <<EOF>> genmake_warnings
609    
610    WARNING: FORTRAN test compile fails -- please see "genmake_errors"
611    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
612    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
613    EOF
614            return 1
615        fi
616        f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
617        RETVAL=$?
618        if test "x$RETVAL" != x0 ; then
619            FC_NAMEMANGLE=$default_nm
620            cat <<EOF>> genmake_warnings
621    
622    WARNING: The "nm" command failed.
623    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
624    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
625    EOF
626            return 1
627        fi
628    
629        c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
630        f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
631        c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
632        f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
633    
634        nmangle="X"
635        if test "x$c_a" != "x$f_a" ; then
636            comm="echo x$f_a | sed -e 's|x$c_a||'"
637            a=`eval $comm`
638            nmangle="$a ## $nmangle"
639        fi
640        if test "x$c_b" != "x$f_b" ; then
641            comm="echo x$f_b | sed -e 's|x$c_b||'"
642            b=`eval $comm`
643            nmangle="$nmangle ## $b"
644        fi
645    
646        FC_NAMEMANGLE="#define FC_NAMEMANGLE(X)  $nmangle"
647    
648        #  cleanup the testing files
649        rm -f genmake_tcomp.* genmake_test.*
650    }
651    
652    
653    check_HAVE_CLOC()  {
654        get_fortran_c_namemangling
655        cat <<EOF > genmake_tc_1.c
656    $FC_NAMEMANGLE
657    #include <stdio.h>
658    #include <stdlib.h>
659    #include <unistd.h>
660    #include <assert.h>
661    #include <sys/time.h>
662    void FC_NAMEMANGLE(cloc) ( double *curtim )
663    {
664     struct timeval tv1;
665     gettimeofday(&tv1 , (void *)NULL );
666     *curtim =  (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
667     *curtim = *curtim/1.E6;
668    }
669    EOF
670        make genmake_tc_1.o >> genmake_warnings 2>&1
671        RET_C=$?
672        cat <<EOF > genmake_tc_2.$FS
673          program hello
674          REAL*8 wtime
675          external cloc
676          call cloc(wtime)
677          print *," HELLO WORLD", wtime
678          end
679    EOF
680        $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_warnings 2>&1
681        RET_F=$?
682        test -x ./genmake_tc  &&  ./genmake_tc >> genmake_warnings 2>&1
683        RETVAL=$?
684        if test "x$RETVAL" = x0 ; then
685            HAVE_CLOC=t
686            DEFINES="$DEFINES -DHAVE_CLOC"
687        fi
688        rm -f genmake_tc*
689    }
690    
691    
692    check_HAVE_SETRLSTK()  {
693        get_fortran_c_namemangling
694        cat <<EOF > genmake_tc_1.c
695    $FC_NAMEMANGLE
696    #include <sys/time.h>
697    #include <sys/resource.h>
698    #include <unistd.h>
699    void FC_NAMEMANGLE(setrlstk) ()
700    {
701        struct rlimit rls;
702        rls.rlim_cur = RLIM_INFINITY;
703        rls.rlim_max = RLIM_INFINITY;
704        setrlimit(RLIMIT_STACK, &rls);
705        return;
706    }
707    EOF
708        make genmake_tc_1.o >> genmake_warnings 2>&1
709        RET_C=$?
710        cat <<EOF > genmake_tc_2.$FS
711          program hello
712          external setrlstk
713          call setrlstk()
714          end
715    EOF
716        echo >> genmake_warnings
717        echo "running: check_HAVE_SETRLSTK()" >> genmake_warnings
718        cat genmake_tc_2.$FS >> genmake_warnings
719        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
720        echo $COMM >> genmake_warnings
721        $COMM >> genmake_warnings 2>&1
722        RETVAL=$?
723        if test "x$RETVAL" = x0 ; then
724            HAVE_SETRLSTK=t
725            DEFINES="$DEFINES -DHAVE_SETRLSTK"
726        fi
727        rm -f genmake_tc*
728    }
729    
730    
731    check_HAVE_STAT()  {
732        get_fortran_c_namemangling
733        cat <<EOF > genmake_tc_1.c
734    $FC_NAMEMANGLE
735    #include <stdio.h>
736    #include <stdlib.h>
737    #include <unistd.h>
738    #include <sys/stat.h>
739    #include <sys/types.h>
740    void FC_NAMEMANGLE(tfsize) ( int *nbyte )
741    {
742        char name[512];
743        struct stat astat;
744    
745        name[0] = 'a'; name[1] = '\0';
746        if (! stat(name, &astat))
747            *nbyte = (int)(astat.st_size);
748        else
749            *nbyte = -1;
750    }
751    EOF
752        make genmake_tc_1.o >> genmake_tc.log 2>&1
753        RET_C=$?
754        cat <<EOF > genmake_tc_2.$FS
755          program hello
756          integer nbyte
757          call tfsize(nbyte)
758          print *," HELLO WORLD", nbyte
759          end
760    EOF
761        echo >> genmake_warnings
762        echo "running: check_HAVE_STAT()" >> genmake_warnings
763        cat genmake_tc_2.$FS >> genmake_warnings
764        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
765        echo $COMM >> genmake_warnings
766        $COMM >> genmake_tc.log 2>&1
767        RETVAL=$?
768        if test "x$RETVAL" = x0 ; then
769            HAVE_STAT=t
770            DEFINES="$DEFINES -DHAVE_STAT"
771        fi
772        rm -f genmake_tc*
773    }
774    
775    
776    check_netcdf_libs()  {
777        if test ! "x$SKIP_NETCDF_CHECK" = x ; then
778            return
779        fi
780        echo >> genmake_warnings
781        echo "running: check_netcdf_libs()" >> genmake_warnings
782        cat <<EOF > genmake_tnc.F
783          program fgennc
784    #include "netcdf.inc"
785    EOF
786        if test ! "x$MPI" = x ; then
787            echo '#include "mpif.h"' >> genmake_tnc.F
788        fi
789        cat <<EOF >> genmake_tnc.F
790          integer iret, ncid, xid
791          iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
792          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
793          iret = nf_def_dim(ncid, 'X', 11, xid)
794          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
795          iret = nf_close(ncid)
796          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
797          end
798    EOF
799        echo "===  genmake_tnc.F  ===" > genmake_tnc.log
800        cat genmake_tnc.F >> genmake_tnc.log
801        echo "===  genmake_tnc.F  ===" >> genmake_tnc.log
802        RET_CPP=f
803        COMM="$CPP $DEFINES $INCLUDES genmake_tnc.F"
804        echo "$COMM" >> genmake_tnc.log
805        $COMM > genmake_tnc.$FS 2>/dev/null  &&  RET_CPP=t
806        if test "x$RET_CPP" = xf ; then
807            echo "  WARNING: CPP failed to pre-process the netcdf test." \
808                >> genmake_tnc.log
809            echo "    Please check that \$INCLUDES is properly set." \
810                >> genmake_tnc.log
811        fi
812        echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.$FS  \ " >> genmake_tnc.log
813        echo "  &&  $LINK -o genmake_tnc.o $LIBS" >> genmake_tnc.log
814        $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
815            &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
816        RET_COMPILE=$?
817        cat genmake_tnc.log >> genmake_warnings
818    
819        #EH3  Remove test program execution for machines that either disallow
820        #EH3  execution or cannot support it (eg. cross-compilers)
821        #EH3
822        #EH3 test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1
823        #EH3 RETVAL=$?
824        #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
825    
826        if test "x$RET_COMPILE" = x0 ; then
827            HAVE_NETCDF=t
828        else
829            # try again with "-lnetcdf" added to the libs
830            echo "try again with added '-lnetcdf'" > genmake_tnc.log
831            echo "$CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS \ " >> genmake_tnc.log
832            echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
833            echo " &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
834            $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null  \
835                &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
836                &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
837            RET_COMPILE=$?
838            cat genmake_tnc.log >> genmake_warnings
839            if test "x$RET_COMPILE" = x0 ; then
840                LIBS="$LIBS -lnetcdf"
841                HAVE_NETCDF=t
842            fi
843        fi
844        rm -f genmake_tnc*
845    }
846    
847    
848    
849    ###############################################################################
850    #   Sequential part of script starts here
851    ###############################################################################
852    
853    #  Set defaults here
854    COMMANDL="$0 $@"
855    
856    PLATFORM=
857    LN=
858    S64=
859    KPP=
860    #FC=
861    #CC=gcc
862    #CPP=
863    LINK=
864    DEFINES=
865    PACKAGES=
866    ENABLE=
867    DISABLE=
868    # MAKEFILE=
869    # MAKEDEPEND=
870    PDEPEND=
871    DUMPSTATE=t
872    PDEFAULT=
873    OPTFILE=
874    INCLUDES="-I. $INCLUDES"
875    FFLAGS=
876    FOPTIM=
877    CFLAGS=
878    KFLAGS1=
879    KFLAGS2=
880    #LDADD=
881    LIBS=
882    KPPFILES=
883    NOOPTFILES=
884    NOOPTFLAGS=
885    MPI=
886    MPIPATH=
887    TS=
888    HAVE_TEST_L=
889    
890    # DEFINES checked by test compilation or command-line
891    HAVE_SYSTEM=
892    HAVE_FDATE=
893    FC_NAMEMANGLE=
894    HAVE_CLOC=
895    HAVE_SETRLSTK=
896    HAVE_STAT=
897    HAVE_NETCDF=
898    HAVE_ETIME=
899    IGNORE_TIME=
900    
901    MODS=
902    TOOLSDIR=
903    SOURCEDIRS=
904    INCLUDEDIRS=
905    STANDARDDIRS="USE_THE_DEFAULT"
906    
907    G2ARGS=
908    BASH=
909    PWD=`pwd`
910    test "x$MAKE" = x  &&  MAKE=make
911    test "x$AWK" = x   &&  AWK=awk
912    THISHOST=`hostname`
913    THISCWD=`pwd`
914    THISDATE=`date`
915    THISUSER=`echo $USER`
916    THISVER=
917    MACHINE=`uname -a`
918    EXECUTABLE=
919    EXEHOOK=
920    EXEDIR=
921    PACKAGES_CONF=
922    IEEE=
923    if test "x$MITGCM_IEEE" != x ; then
924        IEEE=$MITGCM_IEEE
925    fi
926    FS=
927    FS90=
928    
929    AUTODIFF_PKG_USED=f
930    AD_OPTFILE=
931    TAF=
932    AD_TAF_FLAGS=
933    FTL_TAF_FLAGS=
934    SVD_TAF_FLAGS=
935    TAF_EXTRA=
936    TAMC=
937    AD_TAMC_FLAGS=
938    FTL_TAF_FLAGS=
939    SVD_TAMC_FLAGS=
940    TAMC_EXTRA=
941    
942    
943    #  The following state can be set directly by command-line switches
944    gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"
945    gm_s2="FC CPP IEEE TS MPI JAM DUMPSTATE STANDARDDIRS"
946    
947    #  The following state is not directly set by command-line switches
948    gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
949    gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
950    gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE"
951    gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
952    gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME"
953    
954    #  The following are all related to adjoint/tangent-linear stuff
955    gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
956    gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
957    gm_s12="TAF_EXTRA TAMC_EXTRA"
958    
959    gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"
960    gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
961    
962    cat <<EOF
963    
964    GENMAKE :
965    
966    A program for GENerating MAKEfiles for the MITgcm project.  For a
967    quick list of options, use "genmake -h" or for more detail see:
968    
969      http://mitgcm.org/devel_HOWTO/
970    
971    EOF
972    
973    echo "===  Processing options files and arguments  ==="
974    gm_local="genmake_local"
975    for i in . $MODS ; do
976        if test -r $i/$gm_local ; then
977            . $i/$gm_local
978            break
979        fi
980    done
981    printf "  getting local config information:  "
982    if test -f $gm_local ; then
983        echo "using $gm_local"
984        . $gm_local
985        # echo "DISABLE=$DISABLE"
986        # echo "ENABLE=$ENABLE"
987    else
988        echo "none found"
989    fi
990    
991    #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
992    #OPTIONS=
993    #n=0
994    #for i ; do
995    #   echo "$i  $n"
996    #   setvar="OPTIONS[$n]='$i'"
997    #   #  echo "  $setvar"
998    #   eval "$setvar"
999    #   n=$(( $n + 1 ))
1000    #done
1001    #parse_options
1002    ac_prev=
1003    for ac_option in "$@" ; do
1004    
1005        G2ARGS="$G2ARGS \"$ac_option\""
1006    
1007        # If the previous option needs an argument, assign it.
1008        if test -n "$ac_prev"; then
1009            eval "$ac_prev=\$ac_option"
1010            ac_prev=
1011            continue
1012        fi
1013        
1014        ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
1015        
1016        case $ac_option in
1017            
1018            -help | --help | -h | --h)
1019                usage ;;
1020            
1021            -nooptfile | --nooptfile)
1022                OPTFILE="NONE" ;;
1023            -optfile | --optfile | -of | --of)
1024                ac_prev=OPTFILE ;;
1025            -optfile=* | --optfile=* | -of=* | --of=*)
1026                OPTFILE=$ac_optarg ;;
1027            
1028            -adoptfile | --adoptfile | -adof | --adof)
1029                ac_prev=AD_OPTFILE ;;
1030            -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
1031                AD_OPTFILE=$ac_optarg ;;
1032            
1033            -pdepend | --pdepend)
1034                ac_prev=PDEPEND ;;
1035            -pdepend=* | --pdepend=*)
1036                PDEPEND=$ac_optarg ;;
1037            
1038            -pdefault | --pdefault)
1039                ac_prev=PDEFAULT ;;
1040            -pdefault=* | --pdefault=*)
1041                PDEFAULT=$ac_optarg ;;
1042            
1043            -make | --make | -m | --m)
1044                ac_prev=MAKE ;;
1045            -make=* | --make=* | -m=* | --m=*)
1046                MAKE=$ac_optarg ;;
1047            
1048            -bash | --bash)
1049                ac_prev=BASH ;;
1050            -bash=* | --bash=*)
1051                BASH=$ac_optarg ;;
1052            
1053            -makedepend | --makedepend | -md | --md)
1054                ac_prev=MAKEDEPEND ;;
1055            -makedepend=* | --makedepend=* | -md=* | --md=*)
1056                MAKEDEPEND=$ac_optarg ;;
1057            
1058            -makefile | --makefile | -ma | --ma)
1059                ac_prev=MAKEFILE ;;
1060            -makefile=* | --makefile=* | -ma=* | --ma=*)
1061                MAKEFILE=$ac_optarg ;;
1062            
1063            -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
1064                echo "ERROR: The platform option has been removed.  Please specify"
1065                echo "  the build options using the \"optfile\" mechanism."
1066                echo
1067                usage
1068                ;;
1069            
1070            -rootdir | --rootdir | -rd | --rd)
1071                ac_prev=ROOTDIR ;;
1072            -rootdir=* | --rootdir=* | -rd=* | --rd=*)
1073                ROOTDIR=$ac_optarg ;;
1074            
1075            -mods | --mods | -mo | --mo)
1076                ac_prev=MODS ;;
1077            -mods=* | --mods=* | -mo=* | --mo=*)
1078                MODS=$ac_optarg ;;
1079            
1080            -disable | --disable)
1081                ac_prev=DISABLE ;;
1082            -disable=* | --disable=*)
1083                DISABLE=$ac_optarg ;;
1084            
1085            -enable | --enable)
1086                ac_prev=ENABLE ;;
1087            -enable=* | --enable=*)
1088                ENABLE=$ac_optarg ;;
1089            
1090            -standarddirs | --standarddirs)
1091                ac_prev=STANDARDDIRS ;;
1092            -standarddirs=* | --standarddirs=*)
1093                STANDARDDIRS=$ac_optarg ;;
1094    
1095    #           -cpp | --cpp)
1096    #               ac_prev=cpp ;;
1097    #           -cpp=* | --cpp=*)
1098    #               CPP=$ac_optarg ;;
1099            
1100            -cc | --cc)
1101                ac_prev=CC ;;
1102            -cc=* | --cc=*)
1103                CC=$ac_optarg ;;
1104            
1105            -fortran | --fortran | -fc | --fc)
1106                ac_prev=FC ;;
1107            -fc=* | --fc=*)
1108                FC=$ac_optarg ;;
1109            
1110            -fs | --fs)
1111                ac_prev=FS ;;
1112            -fs=* | --fs=*)
1113                FS=$ac_optarg ;;
1114            
1115            -fs90 | --fs90)
1116                ac_prev=FS90 ;;
1117            -fs90=* | --fs90=*)
1118                FS90=$ac_optarg ;;
1119            
1120            -ieee | --ieee)
1121                IEEE=true ;;
1122            -noieee | --noieee)
1123                IEEE= ;;
1124    
1125            -ts | --ts)
1126                TS=true ;;
1127    
1128            -mpi | --mpi)
1129                MPI=true ;;
1130            -mpi=* | --mpi=*)
1131                MPIPATH=$ac_optarg
1132                MPI=true ;;
1133            
1134    #       -jam | --jam)
1135    #           JAM=1 ;;
1136    #       -nojam | --nojam)
1137    #           JAM=0 ;;
1138            
1139            -ds | --ds)
1140                DUMPSTATE=t ;;
1141            
1142            -taf_extra | --taf_extra)
1143                ac_prev=TAF_EXTRA ;;
1144            -taf_extra=* | --taf_extra=*)
1145                TAF_EXTRA=$ac_optarg ;;
1146    
1147            -tamc_extra | --tamc_extra)
1148                ac_prev=TAMC_EXTRA ;;
1149            -tamc_extra=* | --tamc_extra=*)
1150                TAMC_EXTRA=$ac_optarg ;;
1151            
1152            -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1153                IGNORE_TIME="-DIGNORE_TIME" ;;
1154    
1155            -*)
1156                echo "Error: unrecognized option: "$ac_option
1157                usage
1158                ;;
1159            
1160            *)
1161                echo "Error: unrecognized argument: "$ac_option
1162                usage
1163                ;;
1164            
1165        esac
1166        
1167    done
1168    
1169    
1170    if test -f ./.genmakerc ; then
1171        echo
1172        echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
1173        echo "  file.  This file format is no longer supported.  Please see:"
1174        echo
1175        echo "    http://mitgcm.org/devel_HOWTO/"
1176        echo
1177        echo "  for directions on how to setup and use the new \"genmake2\" input"
1178        echo "  files and send an email to MITgcm-support@mitgcm.org if you want help."
1179        echo
1180    fi
1181    
1182    #  Find the MITgcm ${ROOTDIR}
1183    if test "x${ROOTDIR}" = x ; then
1184        tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1185        if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
1186            ROOTDIR=".."
1187        else
1188            for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1189                if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
1190                    ROOTDIR=$d
1191                    printf "Warning:  ROOTDIR was not specified but there appears to be"
1192                    echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
1193                    break
1194                fi
1195            done
1196        fi
1197    fi
1198    if test "x${ROOTDIR}" = x ; then
1199        echo "Error: Cannot determine ROOTDIR for MITgcm code."
1200        echo "  Please specify a ROOTDIR using either an options "
1201        echo "  file or a command-line option."
1202        exit 1
1203    fi
1204    if test ! -d ${ROOTDIR} ; then
1205        echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
1206        exit 1
1207    fi
1208    
1209    #  Find the MITgcm ${THISVER}
1210    if test -f "${ROOTDIR}/doc/tag-index" ; then
1211        THISVER=`grep '^checkpoint' ${ROOTDIR}/doc/tag-index | head -1`
1212    fi
1213    
1214    if test "x$MAKEFILE" = x ; then
1215        MAKEFILE="Makefile"
1216    fi
1217    
1218    echo "  getting OPTFILE information:  "
1219    if test "x${OPTFILE}" = x ; then
1220        if test "x$MITGCM_OF" = x ; then
1221            echo "Warning: no OPTFILE specified so we'll look for possible settings"
1222            printf "\n===  Searching for possible settings for OPTFILE  ===\n"
1223            find_possible_configs
1224        else
1225            OPTFILE=$MITGCM_OF
1226        fi
1227    fi
1228    if test "x$OPTFILE" != xNONE ; then
1229        if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
1230            echo "    using OPTFILE=\"$OPTFILE\""
1231            . "$OPTFILE"
1232            RETVAL=$?
1233            if test "x$RETVAL" != x0 ; then
1234                printf "Error: failed to source OPTFILE \"$OPTFILE\""
1235                echo "--please check that variable syntax is bash-compatible"
1236                exit 1
1237            fi
1238            if test "x$DUMPSTATE" != xf ; then
1239                cp -f $OPTFILE "genmake_optfile"
1240            fi
1241        else
1242            echo "Error: can't read OPTFILE=\"$OPTFILE\""
1243            exit 1
1244        fi
1245    fi
1246    
1247    echo "  getting AD_OPTFILE information:  "
1248    if test "x${AD_OPTFILE}" = x ; then
1249        if test "x$MITGCM_AD_OF" = x ; then
1250            AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
1251        else
1252            AD_OPTFILE=$MITGCM_AD_OF
1253        fi
1254    fi
1255    if test "x${AD_OPTFILE}" != xNONE ; then
1256        if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
1257            echo "    using AD_OPTFILE=\"$AD_OPTFILE\""
1258            . "$AD_OPTFILE"
1259            RETVAL=$?
1260            if test "x$RETVAL" != x0 ; then
1261                printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
1262                echo "--please check that variable syntax is bash-compatible"
1263                exit 1
1264            fi
1265            if test "x$DUMPSTATE" != xf ; then
1266                cp -f $AD_OPTFILE "genmake_ad_optfile"
1267            fi
1268        else
1269            echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
1270            exit 1
1271        fi
1272    fi
1273    
1274    #====================================================================
1275    #  Set default values if not set by the optfile
1276    #
1277    #  Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
1278    #  either set defaults or complain and abort!
1279    if test ! "x$BASH" = x ; then
1280        # add a trailing space so that it works within the Makefile syntax (see below)
1281        BASH="$BASH "
1282    fi
1283    if test "x$FC" = x ; then
1284        cat <<EOF 1>&2
1285    
1286    Error: no Fortran compiler: please specify using one of the following:
1287      1) within the options file ("FC=...") as specified by "-of=OPTFILE"
1288      2) the "-fc=XXX" command-line option
1289      3) the "./genmake_local" file
1290    EOF
1291        exit 1
1292    fi
1293    if test "x$CC" = x ; then
1294        CC=cc
1295    #     cat <<EOF 1>&2
1296    # Error: no C compiler: please specify using one of the following:
1297    #   1) within the options file ("CC=...") as specified by "-of=OPTFILE"
1298    #   2) the "-cc=XXX" command-line option
1299    #   3) the "./genmake_local" file
1300    # EOF
1301    #     exit 1
1302    fi
1303    if test "x$LINK" = x ; then
1304        LINK=$FC
1305    fi
1306    if test "x$MAKE" = x ; then
1307        MAKE="make"
1308    fi
1309    if test "x$CPP" = x ; then
1310        CPP=cpp
1311    fi
1312    #EH3 === UGLY ===
1313    #  The following is an ugly little hack to check for $CPP in /lib/ and
1314    #  it should eventually be replaced with a more general function that
1315    #  searches a combo of the user's path and a list of "usual suspects"
1316    #  to find the correct location for binaries such as $CPP.
1317    for i in " " "/lib/" ; do
1318        echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1319    done
1320    #EH3 === UGLY ===
1321    echo "#define A a" | $CPP > test_cpp 2>&1
1322    RETVAL=$?
1323    if test "x$RETVAL" != x0 ; then
1324        cat <<EOF 1>&2
1325    
1326    Error: C pre-processor "$CPP" failed the test case: please specify using:
1327    
1328      1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
1329      2) the "./genmake_local" file
1330      3) with the CPP environment variable
1331    
1332    EOF
1333        exit 1
1334    else
1335        rm -f test_cpp
1336    fi
1337    look_for_makedepend
1338    if test "x$LN" = x ; then
1339        LN="ln -s"
1340    fi
1341    echo "test" > genmake_test_ln
1342    $LN genmake_test_ln genmake_tlink
1343    RETVAL=$?
1344    if test "x$RETVAL" != x0 ; then
1345        cat <<EOF 1>&2
1346    
1347    Error: The command "ln -s" failed -- please specify a working soft-link
1348      command in the optfile.
1349    
1350    EOF
1351        exit 1
1352    fi
1353    test -L genmake_tlink > /dev/null 2>&1
1354    RETVAL=$?
1355    if test "x$RETVAL" = x0 ; then
1356        HAVE_TEST_L=t
1357    fi
1358    rm -f genmake_test_ln genmake_tlink
1359    
1360    #  Check for broken *.F/*.f handling and fix if possible
1361    check_for_broken_Ff
1362    
1363    if test ! "x$MPI" = x ; then
1364          echo "  Turning on MPI cpp macros"
1365          DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
1366    fi
1367    
1368  #eh3 # This is the generic configuration.  if test ! "x$TS" = x ; then
1369  #eh3 set LN         = ( 'ln -s' )        echo "  Turning on timing per timestep"
1370  #eh3 set CPP        = ( '/lib/cpp -P' )        DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1371  #eh3 set S64        = ( '$(TOOLSDIR)/set64bitConst.sh' )  fi
 #eh3 set KPP        = (  )  
 #eh3 set FC         = ( 'f77' )  
 #eh3 set LINK       = $FC  
 #eh3 set MAKEDEPEND = ( 'makedepend' )  
 #eh3 set INCLUDES   = ( -I. )  
 #eh3 set FFLAGS     = (  )  
 #eh3 set FOPTIM     = (  )  
 #eh3 set CFLAGS     = (  )  
 #eh3 set KFLAGS1    = (  )  
 #eh3 set KFLAGS2    = (  )  
 #eh3 set LIBS       = (  )  
 #eh3 set KPPFILES   = (  )  
 #eh3 if (! $?NOOPTFILES ) set NOOPTFILES = (  )  
 #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = (  )  
1372    
1373  #  Set defaults here  printf "\n===  Checking system libraries  ===\n"
1374  PLATFORM=  printf "  Do we have the system() command using $FC...  "
1375  LN=  cat > genmake_tcomp.$FS <<EOF
1376  S64=        program hello
1377  KPP=        call system('echo hi')
1378  FC=        end
1379  LINK=  EOF
1380  PACKAGES=  $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1381  ENABLE=  RETVAL=$?
1382  DISABLE=  if test "x$RETVAL" = x0 ; then
1383  MAKEFILE=      HAVE_SYSTEM=t
1384  MAKEDEPEND=      DEFINES="$DEFINES -DHAVE_SYSTEM"
1385  PDEPEND=      echo "yes"
1386  PDEFAULT=  else
1387  OPTFILE=      HAVE_SYSTEM=
1388  INCLUDES=-I.      echo "no"
1389  FFLAGS=  fi
1390  FOPTIM=  rm -f genmake_tcomp*
 CFLAGS=  
 KFLAGS1=  
 KFLAGS2=  
 LIBS=  
 KPPFILES=  
 NOOPTFILES=  
 NOOPTFLAGS=  
1391    
1392  MODS=  printf "  Do we have the fdate() command using $FC...  "
1393  TOOLSDIR=  cat > genmake_tcomp.$FS <<EOF
1394  SOURCEDIRS=        program hello
1395  INCLUDEDIRS=        CHARACTER*(128) string
1396          string = ' '
1397          call fdate( string )
1398          print *, string
1399          end
1400    EOF
1401    $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1402    RETVAL=$?
1403    if test "x$RETVAL" = x0 ; then
1404        HAVE_FDATE=t
1405        DEFINES="$DEFINES -DHAVE_FDATE"
1406        echo "yes"
1407    else
1408        HAVE_FDATE=
1409        echo "no"
1410    fi
1411    rm -f genmake_tcomp*
1412    
1413  PWD=`pwd`  printf "  Do we have the etime() command using $FC...  "
1414  MAKE=make  cat > genmake_tcomp.$FS <<EOF
1415  THISHOSTNAME=`hostname`        program hello
1416  THISCWD=`pwd`        REAL*4 ACTUAL, TARRAY(2)
1417  THISDATE=`date`        EXTERNAL ETIME
1418  MACHINE=`uname -a`        REAL*4 ETIME
1419          actual = etime( tarray )
1420          print *, tarray
1421          end
1422    EOF
1423    $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1424    RETVAL=$?
1425    if test "x$RETVAL" = x0 ; then
1426        HAVE_ETIME=t
1427        DEFINES="$DEFINES -DHAVE_ETIME"
1428        echo "yes"
1429    else
1430        HAVE_ETIME=
1431        echo "no"
1432    fi
1433    rm -f genmake_tcomp*
1434    
1435  echo $'\n'"===  Processing options files and arguments  ==="  printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
1436  gm_local="./gm_local"  check_HAVE_CLOC
1437  echo -n "  getting local config information:  "  if test "x$HAVE_CLOC" != x ; then
1438  if test -e $gm_local ; then      echo "yes"
     echo "using $gm_local"  
     source $gm_local  
     echo "DISABLE=$DISABLE"$'\n'"ENABLE=$ENABLE"  
1439  else  else
1440      echo "none found"      echo "no"
1441  fi  fi
1442    rm -f genmake_t*
1443    
1444  #  echo "$0::$1:$2:$3:$4:$5:$6:$7:"  printf "  Can we unlimit the stack size using $FC...  "
1445  OPTIONS=()  check_HAVE_SETRLSTK
1446  n=0  if test "x$HAVE_SETRLSTK" != x ; then
1447  for i ; do      echo "yes"
1448     setvar="OPTIONS[$n]='$i'"  else
1449     #  echo "  $setvar"      echo "no"
1450     eval "$setvar"  fi
1451     n=$(( $n + 1 ))  rm -f genmake_t*
 done  
 parse_options  
1452    
1453  echo "  getting OPTFILE information:  "  printf "  Can we use stat() through C calls...  "
1454  if test "x${OPTFILE}" = x ; then  check_HAVE_STAT
1455      echo "Warning: no OPTFILE specified so we'll look for possible settings"  if test "x$HAVE_STAT" != x ; then
1456      echo $'\n'"===  Searching for possible settings for OPTFILE  ==="      echo "yes"
1457      find_possible_configs  else
1458  else      echo "no"
1459      if test "x$OPTFILE" = xNONE ; then  fi
1460          echo "    OPTFILE=NONE so we'll try to use default settings"  rm -f genmake_t*
1461      else  
1462          if test -f "$OPTFILE" -a -r "$OPTFILE" ; then  printf "  Can we create NetCDF-enabled binaries...  "
1463              echo "    using OPTFILE=\"$OPTFILE\""  check_netcdf_libs
1464              source "$OPTFILE"  if test "x$HAVE_NETCDF" != x ; then
1465              RETVAL=$?      echo "yes"
1466              if test "x$RETVAL" != x0 ; then  else
1467                  echo -n "Error: failed to source OPTFILE \"$OPTFILE\""      echo "no"
                 echo "--please check that variable syntax is bash-compatible"  
                 exit 1  
             fi  
         else  
             echo "Error: can't read OPTFILE=\"$OPTFILE\""  
             exit 1  
         fi  
     fi  
1468  fi  fi
1469    DEFINES="$DEFINES $IGNORE_TIME"
1470    
1471  echo $'\n'"===  Setting defaults  ==="  printf "\n===  Setting defaults  ===\n"
1472  echo -n "  Adding MODS directories:  "  printf "  Adding MODS directories:  "
1473  for d in $MODS ; do  for d in $MODS ; do
1474      if test ! -d $d ; then      if test ! -d $d ; then
1475          echo $'\n\n'"Error: MODS directory \"$d\" not found!"          echo
1476            echo "Error: MODS directory \"$d\" not found!"
1477          exit 1          exit 1
1478      else      else
1479          echo -n " $d"          printf " $d"
1480          SOURCEDIRS="$SOURCEDIRS $d"          SOURCEDIRS="$SOURCEDIRS $d"
1481          INCLUDEDIRS="$INCLUDEDIRS $d"          INCLUDEDIRS="$INCLUDEDIRS $d"
1482      fi      fi
1483  done  done
1484  echo  echo
1485    
 if test "x$MAKEFILE" = x ; then  
     MAKEFILE="Makefile"  
 fi  
1486  if test "x${PLATFORM}" = x ; then  if test "x${PLATFORM}" = x ; then
1487      PLATFORM=$p_PLATFORM      PLATFORM=$p_PLATFORM
1488  fi  fi
1489    
 if test "x${ROOTDIR}" = x ; then  
     if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then  
         ROOTDIR=".."  
     else  
         for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do  
             if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then  
                 ROOTDIR=$d  
                 echo -n "Warning:  ROOTDIR was not specified but there appears to be"  
                 echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."  
                 break  
             fi  
         done  
     fi  
 fi  
 if test "x${ROOTDIR}" = x ; then  
     echo "Error: Cannot determine ROOTDIR for MITgcm code."  
     echo "  Please specify a ROOTDIR using either an options "  
     echo "  file or a command-line option."  
     exit 1  
 fi  
 if test ! -d ${ROOTDIR} ; then  
     echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"  
     exit 1  
 fi  
   
1490  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
1491      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1492        if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
1493          EXEDIR=../exe          EXEDIR=../exe
1494      else      else
1495          EXEDIR=.          EXEDIR=.
# Line 430  if test "x${TOOLSDIR}" = x ; then Line 1504  if test "x${TOOLSDIR}" = x ; then
1504      TOOLSDIR="$ROOTDIR/tools"      TOOLSDIR="$ROOTDIR/tools"
1505  fi  fi
1506  if test ! -d ${TOOLSDIR} ; then  if test ! -d ${TOOLSDIR} ; then
1507      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
1508      exit 1      exit 1
1509  fi  fi
1510    if test "x$S64" = x ; then
1511        echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1
1512        RETVAL=$?
1513        if test "x${RETVAL}" = x0 ; then
1514            S64='$(TOOLSDIR)/set64bitConst.sh'
1515        else
1516            echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1
1517            RETVAL=$?
1518            if test "x${RETVAL}" = x0 ; then
1519                S64='$(TOOLSDIR)/set64bitConst.csh'
1520            else
1521                cat <<EOF
1522    
1523    ERROR: neither of the two default scripts:
1524    
1525        ${TOOLSDIR}/set64bitConst.sh
1526        ${TOOLSDIR}/set64bitConst.csh
1527    
1528      are working so please check paths or specify (with \$S64) a
1529      working version of this script.
1530    
1531    EOF
1532                exit 1
1533            fi
1534        fi
1535    fi
1536    THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
1537    
1538  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1539    
# Line 441  EXECUTABLE=${EXECUTABLE:-mitgcmuv} Line 1542  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1542  #  they appear as regular source code  #  they appear as regular source code
1543  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
1544      echo "  Making source files in eesupp from templates"      echo "  Making source files in eesupp from templates"
1545      $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1      ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1
1546      RETVAL=$?      RETVAL=$?
1547      if test "x${RETVAL}" == "x0" ; then      if test "x${RETVAL}" = x0 ; then
1548          rm -f make_eesupp.errors          rm -f make_eesupp.errors
1549      else      else
1550          echo "Error: problem encountered while building source files in eesupp:"          echo "Error: problem encountered while building source files in eesupp:"
1551          cat make_eesupp.errors          cat make_eesupp.errors 1>&2
1552          exit 1          exit 1
1553      fi      fi
1554  fi  fi
1555    
1556  echo $'\n'"===  Determining package settings  ==="  #same for exch2
1557    if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then
1558        echo "  Making source files in exch2 from  templates"
1559        ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1
1560        RETVAL=$?
1561        if test "x${RETVAL}" = x0 ; then
1562            rm -f make_exch2.errors
1563        else
1564            echo "Error: problem encountered while building source files in exch2:"
1565            cat make_exch2.errors 1>&2
1566            exit 1
1567        fi
1568    fi
1569    
1570    printf "\n===  Determining package settings  ===\n"
1571  if  test "x${PDEPEND}" = x ; then  if  test "x${PDEPEND}" = x ; then
1572      tmp=$ROOTDIR"/pkg/pkg_depend"      tmp=$ROOTDIR"/pkg/pkg_depend"
1573      if test -r $tmp ; then      if test -r $tmp ; then
# Line 471  echo "  getting package dependency info Line 1586  echo "  getting package dependency info
1586  #  Strip the comments and then convert the dependency file into  #  Strip the comments and then convert the dependency file into
1587  #  two arrays: PNAME, DNAME  #  two arrays: PNAME, DNAME
1588  cat $PDEPEND | sed -e 's/#.*$//g' \  cat $PDEPEND | sed -e 's/#.*$//g' \
1589      | awk 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \      | $AWK 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \
1590      > ./.pd_tmp      > ./.pd_tmp
1591  RETVAL=$?  RETVAL=$?
1592  if test ! "x${RETVAL}" = x0 ; then  if test ! "x${RETVAL}" = x0 ; then
1593      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
1594      exit 1      exit 1
1595  fi  fi
1596  source ./.pd_tmp  . ./.pd_tmp
1597  rm -f ./.pd_tmp  rm -f ./.pd_tmp
1598    
1599  echo  -n "  checking default package list:  "  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"
1600    #  file should eventually be added so that, for convenience, one can
1601    #  specify groups of packages using names like "ocean" and "atmosphere".
1602    echo "  checking default package list:  "
1603    if test "x${PDEFAULT}" = x ; then
1604        for i in "." $MODS ; do
1605            if test -r $i"/packages.conf" ; then
1606                    PDEFAULT=$i"/packages.conf"
1607                    break
1608            fi
1609        done
1610    fi
1611  if test "x${PDEFAULT}" = x ; then  if test "x${PDEFAULT}" = x ; then
1612      PDEFAULT="$ROOTDIR/pkg/pkg_default"      PDEFAULT="$ROOTDIR/pkg/pkg_default"
1613  fi  fi
1614  if test "x${PDEFAULT}" = xNONE ; then  if test "x${PDEFAULT}" = xNONE ; then
1615      echo "default packages file disabled"      echo "    default packages file disabled"
1616  else  else
1617      if test ! -r $PDEFAULT ; then      if test ! -r $PDEFAULT ; then
         echo ""  
1618          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""
1619      else      else
1620          echo "  using PDEFAULT=\"$PDEFAULT\""          echo "    using PDEFAULT=\"$PDEFAULT\""
1621          #  Strip the comments and add all the names          #  Strip the comments and add all the names
1622          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | awk '(NF>0){print $0}'`          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
1623          RETVAL=$?          RETVAL=$?
1624          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
1625              echo -n "Error: can't parse default package list "              printf "Error: can't parse default package list "
1626              echo "-- please check PDEFAULT=\"$PDEFAULT\""              echo "-- please check PDEFAULT=\"$PDEFAULT\""
1627              exit 1              exit 1
1628          fi          fi
1629          for i in $def ; do          for i in $def ; do
1630              PACKAGES="$PACKAGES $i"              PACKAGES="$PACKAGES $i"
1631          done          done
1632          echo "    packages are:  $PACKAGES"          echo "    before group expansion packages are: $PACKAGES"
1633            RET=1
1634            while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
1635            echo "    after group expansion packages are:  $PACKAGES"
1636      fi      fi
1637  fi  fi
1638    
1639  echo "  applying DISABLE settings"  echo "  applying DISABLE settings"
1640    for i in $PACKAGES ; do
1641        echo $i >> ./.tmp_pack
1642    done
1643    for i in `grep  "-" ./.tmp_pack` ; do
1644        j=`echo $i | sed 's/[-]//'`
1645        DISABLE="$DISABLE $j"
1646    done
1647  pack=  pack=
1648  for p in $PACKAGES ; do  for p in $PACKAGES ; do
1649      addit="t"      addit="t"
# Line 523  for p in $PACKAGES ; do Line 1658  for p in $PACKAGES ; do
1658  done  done
1659  PACKAGES="$pack"  PACKAGES="$pack"
1660  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
1661  rm -f ./.tmp_pack  echo "" > ./.tmp_pack
1662  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
1663    # Test if each explicitly referenced package exists
1664  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1665      if test ! -d "$ROOTDIR/pkg/$i" ; then      j=`echo $i | sed 's/[-+]//'`
1666        if test ! -d "$ROOTDIR/pkg/$j" ; then
1667          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
1668          exit 1          exit 1
1669      fi      fi
1670      echo $i >> ./.tmp_pack      echo $i >> ./.tmp_pack
1671  done  done
 pack=`cat ./.tmp_pack | sort | uniq`  
 rm -f ./.tmp_pack  
1672  PACKAGES=  PACKAGES=
1673  for i in $pack ; do  for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do
1674      PACKAGES="$PACKAGES $i"      PACKAGES="$PACKAGES $i"
1675  done  done
1676    rm -f ./.tmp_pack
1677  echo "    packages are:  $PACKAGES"  echo "    packages are:  $PACKAGES"
1678    
1679    #  Check availability of NetCDF and then either build the MNC template
1680    #  files or delete mnc from the list of available packages.
1681    echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1
1682    RETVAL=$?
1683    if test "x$RETVAL" = x0 ; then
1684        if test "x$HAVE_NETCDF" != xt ; then
1685            cat <<EOF
1686    
1687    *********************************************************************
1688    WARNING: the "mnc" package was enabled but tests failed to compile
1689      NetCDF applications.  Please check that:
1690    
1691      1) NetCDF is correctly installed for this compiler and
1692      2) the LIBS variable (within the "optfile") specifies the correct
1693           NetCDF library to link against.
1694    
1695      Due to this failure, the "mnc" package is now DISABLED.
1696    *********************************************************************
1697    
1698    EOF
1699            PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
1700            DISABLE="$DISABLE mnc"
1701        else
1702            ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
1703            RETVAL=$?
1704            if test "x${RETVAL}" = x0 ; then
1705                rm -f make_mnc.errors
1706            else
1707                echo "Error: problem encountered while building source files in pkg/mnc:"
1708                cat make_mnc.errors 1>&2
1709                exit 1
1710            fi
1711        fi
1712    fi
1713    
1714  echo "  applying package dependency rules"  echo "  applying package dependency rules"
1715  ck=  ck=
1716  while test "x$ck" != xtt ; do  while test "x$ck" != xtt ; do
1717      i=0      i=0
1718      rtot=${#PNAME[@]}      # rtot=${#PNAME[@]}
1719        rtot=$nname
1720      while test $i -lt $rtot ; do      while test $i -lt $rtot ; do
1721    
1722          #  Is $pname in the current $PACKAGES list?          #  Is $pname in the current $PACKAGES list?
1723          pname=${PNAME[$i]}          #  pname=${PNAME[$i]}
1724            tmp="pname=\"\$PNAME_$i\""
1725            eval $tmp
1726          pin="f"          pin="f"
1727          for p in $PACKAGES ; do          for p in $PACKAGES ; do
1728              if test "x$p" = "x$pname" ; then              if test "x$p" = "x$pname" ; then
# Line 557  while test "x$ck" != xtt ; do Line 1731  while test "x$ck" != xtt ; do
1731          done          done
1732    
1733          #  Is the DNAME entry a (+) or (-) rule ?          #  Is the DNAME entry a (+) or (-) rule ?
1734            tmp="dname=\"\$DNAME_$i\""
1735            eval $tmp
1736          plus="-"          plus="-"
1737          echo "${DNAME[$i]}" | grep '^+' > /dev/null 2>&1          echo $dname | grep '^+' > /dev/null 2>&1
1738          RETVAL=$?          RETVAL=$?
1739          if test "x$RETVAL" = x0 ; then          if test "x$RETVAL" = x0 ; then
1740              plus="+"              plus="+"
1741          fi          fi
1742    
1743          #  Is $dname in the current $PACKAGES list?          #  Is $dname in the current $PACKAGES list?
1744          dname=`echo ${DNAME[$i]} | sed -e 's/^[+-]//'`          dname=`echo $dname | sed -e 's/^[+-]//'`
1745          din="f"          din="f"
1746          for p in $PACKAGES ; do          for p in $PACKAGES ; do
1747              if test "x$p" = "x$dname" ; then              if test "x$p" = "x$dname" ; then
# Line 599  while test "x$ck" != xtt ; do Line 1775  while test "x$ck" != xtt ; do
1775              echo "  the dependency rules for \"$dname\""              echo "  the dependency rules for \"$dname\""
1776              exit 1              exit 1
1777          fi          fi
1778          i=$(( $i + 1 ))          i=`echo "$i + 1" | bc -l`
1779            #i=$(( $i + 1 ))
1780      done      done
1781      ck=$ck"t"      ck=$ck"t"
1782  done  done
# Line 609  for i in $PACKAGES ; do Line 1786  for i in $PACKAGES ; do
1786      if test -d $adr ; then      if test -d $adr ; then
1787          SOURCEDIRS="$SOURCEDIRS $adr"          SOURCEDIRS="$SOURCEDIRS $adr"
1788          INCLUDEDIRS="$INCLUDEDIRS $adr"          INCLUDEDIRS="$INCLUDEDIRS $adr"
1789            if test "x$i" = xautodiff ; then
1790                AUTODIFF_PKG_USED=t
1791            fi
1792      else      else
1793          echo "Error: the directory \"$adr\" for package $i doesn't exist"          echo "Error: the directory \"$adr\" for package $i doesn't exist"
1794          exit 1          exit 1
1795      fi      fi
1796  done  done
1797    
1798  #  This is compatible with the old genmake.  The "DISABLE_*" flags  # Create a list of #define and #undef to enable/disable packages
1799  #  need to be replaced by the "ALLOW_*" flags set below.  PACKAGES_DOT_H=PACKAGES_CONFIG.h
 #  
 # 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  
   
 echo "  Setting package-specific CPP flags in CPP_OPTIONS.h:"  
 CPP_OPTIONS=  
 spaths=". $SOURCEDIRS"  
 for i in $spaths ; do  
     try="$i/CPP_OPTIONS.h"  
     #  echo -n "    trying $try : "  
     if test -f $try -a -r $try ; then  
         echo "    found CPP_OPTIONS=\"$try\""  
         CPP_OPTIONS="$try"  
         if test "x$i" != "x." ; then  
             cp -f $CPP_OPTIONS .  
         fi  
         break  
     fi  
 done  
 if test "x$CPP_OPTIONS" = x ; then  
     echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"  
     exit 1  
 fi  
 if test -e CPP_OPTIONS.h ; then  
     if test ! -e CPP_OPTIONS.h.bak ; then  
         cp -f CPP_OPTIONS.h CPP_OPTIONS.h.bak  
     fi  
     cat CPP_OPTIONS.h \  
         | awk 'BEGIN{p=1;} ($1=="C===" && $2=="GENMAKE"){p=0;} {if (p==1) print $0}' \  
         > CPP_OPTIONS.h.tmp  
 fi  
 cat <<EOF >>CPP_OPTIONS.h.tmp  
 C=== GENMAKE v2 ===  
 C  The following defines have been set by GENMAKE, so please edit  
 C  them only if you know what you're doing.  In general, you should  
 C  add or remove packages by re-running genmake with different  
 C  "-enable" and/or "-disable" options.  
   
 C  Packages disabled by genmake:  
 EOF  
1800  #  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
1801  #  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
1802  #  file would eventually be split up so that all package-related #define  #  file would eventually be split up so that all package-related #define
1803  #  statements could be separated and handled only by genmake.  #  statements could be separated and handled only by genmake.
1804  names=`ls -1 "$ROOTDIR/pkg"`  names=`ls -1 "$ROOTDIR/pkg"`
1805  all_pack=  all_pack=
1806    DISABLED_PACKAGES=
1807  for n in $names ; do  for n in $names ; do
1808      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
1809          has_pack="f"          has_pack="f"
# Line 686  for n in $names ; do Line 1814  for n in $names ; do
1814              fi              fi
1815          done          done
1816          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
1817              undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1818              echo "#undef $undef" >> CPP_OPTIONS.h.tmp              DISABLED_PACKAGES="$DISABLED_PACKAGES -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"  
                     ;;  
                 generic_advdiff)  
                     DEFINES="$DEFINES -DDISABLE_GENERIC_ADVDIFF"  
                     ;;  
                 debug)  
                     DEFINES="$DEFINES -DDISABLE_DEBUGMODE"  
                     ;;  
             esac  
 #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  
   
1819          fi          fi
1820      fi      fi
1821  done  done
1822  cat <<EOF >>CPP_OPTIONS.h.tmp  ENABLED_PACKAGES=
   
 C  Packages enabled by genmake:  
 EOF  
1823  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1824      def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`      def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1825      echo "#define $def" >> CPP_OPTIONS.h.tmp      ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
1826    #eh3 DEFINES="$DEFINES -D$def"
1827    
1828  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1829      case $i in      case $i in
1830          aim_v23)          aim_v23)
1831              echo "#define   ALLOW_AIM" >> CPP_OPTIONS.h.tmp              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
1832                echo "Warning: ALLOW_AIM is set to enable aim_v23."
1833              ;;              ;;
1834      esac      esac
1835  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1836    
1837  done  done
 mv -f CPP_OPTIONS.h.tmp CPP_OPTIONS.h  
1838    
1839  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS"
1840  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
1841  STANDARDDIRS=${STANDARDDIRS:-"eesupp model"}  if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
1842  for d in $STANDARDDIRS ; do      STANDARDDIRS="eesupp model"
1843      adr="$ROOTDIR/$d/src"  fi
1844      if test ! -d $adr ; then  if test "x$STANDARDDIRS" != x ; then
1845          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""      for d in $STANDARDDIRS ; do
1846          echo "  is correct and that you correctly specified the STANDARDDIRS option"          adr="$ROOTDIR/$d/src"
1847          exit 1          if test ! -d $adr ; then
1848      else              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1849          SOURCEDIRS="$SOURCEDIRS $adr"              echo "  is correct and that you correctly specified the STANDARDDIRS option"
1850      fi              exit 1
1851      adr="$ROOTDIR/$d/inc"          else
1852      if test ! -d $adr ; then              SOURCEDIRS="$SOURCEDIRS $adr"
1853          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""          fi
1854          echo "  is correct and that you correctly specified the STANDARDDIRS option"          adr="$ROOTDIR/$d/inc"
1855          exit 1          if test ! -d $adr ; then
1856      else              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1857          INCLUDEDIRS="$INCLUDEDIRS $adr"              echo "  is correct and that you correctly specified the STANDARDDIRS option"
1858                exit 1
1859            else
1860                INCLUDEDIRS="$INCLUDEDIRS $adr"
1861            fi
1862        done
1863    fi
1864    
1865    echo "  Searching for *OPTIONS.h files in order to warn about the presence"
1866    echo "    of \"#define \"-type statements that are no longer allowed:"
1867    CPP_OPTIONS=
1868    CPP_EEOPTIONS=
1869    spaths=". $INCLUDEDIRS"
1870    names=`ls -1 "$ROOTDIR/pkg"`
1871    for i in $spaths ; do
1872        try="$i/CPP_OPTIONS.h"
1873        if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
1874            echo "    found CPP_OPTIONS=\"$try\""
1875            CPP_OPTIONS="$try"
1876            # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
1877            for n in $names ; do
1878                test_for_package_in_cpp_options $CPP_OPTIONS $n
1879            done
1880        fi
1881        try="$i/CPP_EEOPTIONS.h"
1882        if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
1883            echo "    found CPP_EEOPTIONS=\"$try\""
1884            # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
1885    #**** not yet enabled ****
1886    #        test_for_mpi_in_cpp_eeoptions $try
1887    #**** not yet enabled ****
1888            CPP_EEOPTIONS="$try"
1889      fi      fi
1890  done  done
1891    if test "x$CPP_OPTIONS" = x ; then
1892        echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
1893        exit 1
1894    fi
1895    
1896    #  Here, we build the list of files to be "run through" the adjoint
1897    #  compiler.
1898    if test -f ./ad_files ; then
1899        rm -f ./ad_files
1900    fi
1901    echo "  Creating the list of files for the adjoint compiler."
1902    for i in $SOURCEDIRS ; do
1903        list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
1904        for j in $list_files ; do
1905            cat $i/$j >> ad_files
1906        done
1907    done
1908    if test ! "x"$FS = "x.f" ; then
1909        cat ad_files | sed -e "s/\.f/.$FS/g" > ad_files_f
1910        mv -f ad_files_f ad_files
1911    fi
1912    
1913  echo $'\n'"===  Creating the Makefile  ==="  echo
1914    echo "===  Creating the Makefile  ==="
1915  echo "  setting INCLUDES"  echo "  setting INCLUDES"
1916  for i in $INCLUDEDIRS ; do  for i in $INCLUDEDIRS ; do
1917      if test -d $i ; then      if test ! -d $i ; then
         INCLUDES="$INCLUDES -I$i"  
     else  
1918          echo "Warning: can't find INCLUDEDIRS=\"$i\""          echo "Warning: can't find INCLUDEDIRS=\"$i\""
1919      fi      fi
1920  done  done
# Line 766  rm -rf .links.tmp Line 1924  rm -rf .links.tmp
1924  mkdir .links.tmp  mkdir .links.tmp
1925  echo "# This section creates symbolic links" > srclinks.tmp  echo "# This section creates symbolic links" > srclinks.tmp
1926  echo "" >> srclinks.tmp  echo "" >> srclinks.tmp
1927  echo -n 'SRCFILES = ' > srclist.inc  printf 'SRCFILES = '    > srclist.inc
1928  echo -n 'CSRCFILES = ' > csrclist.inc  printf 'CSRCFILES = '   > csrclist.inc
1929  echo -n 'HEADERFILES = ' > hlist.inc  printf 'F90SRCFILES = ' > f90srclist.inc
1930  alldirs=". $SOURCEDIRS $INCLUDEDIRS"  printf 'HEADERFILES = ' > hlist.inc
1931    printf 'AD_FLOW_FILES = ' > ad_flow_files.inc
1932    alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1933  for d in $alldirs ; do  for d in $alldirs ; do
1934      deplist=      deplist=
1935      sfiles=`( cd $d; echo *.[h,c,F] )`      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
1936        sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
1937      for sf in $sfiles ; do      for sf in $sfiles ; do
1938          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
1939              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
1940                  extn=`echo $sf | awk -F '.' '{print $NF}'`                  ignore_f=f
1941                  touch .links.tmp/$sf                  case $d/$sf in
1942                  deplist="$deplist $sf"                    ./$PACKAGES_DOT_H)
1943                  case $extn in                          ;;
1944                      F)                    ./AD_CONFIG.h)
                         echo    " \\"  >> srclist.inc  
                         echo -n " $sf" >> srclist.inc  
1945                          ;;                          ;;
1946                      c)                    ./FC_NAMEMANGLE.h)
                         echo    " \\"  >> csrclist.inc  
                         echo -n " $sf" >> csrclist.inc  
1947                          ;;                          ;;
1948                      h)                    ./BUILD_INFO.h)
                         echo    " \\"  >> hlist.inc  
                         echo -n " $sf" >> hlist.inc  
1949                          ;;                          ;;
1950                  esac                    *)
1951                            #  For the local directory *ONLY*,
1952                            #  ignore all soft-links
1953                            if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then
1954                                ignore_f=t
1955                            else
1956                                touch .links.tmp/$sf
1957                                deplist="$deplist $sf"
1958                            fi
1959                            ;;
1960                    esac
1961                    if test "x$ignore_f" = xf ; then
1962                        extn=`echo $sf | $AWK -F. '{print $NF}'`
1963                        case $extn in
1964                            F)
1965                                echo    " \\"  >> srclist.inc
1966                                printf " $sf" >> srclist.inc
1967                                ;;
1968                            F90)
1969                                echo    " \\"  >> f90srclist.inc
1970                                printf " $sf" >> f90srclist.inc
1971                                ;;
1972                            c)
1973                                echo    " \\"  >> csrclist.inc
1974                                printf " $sf" >> csrclist.inc
1975                                ;;
1976                            h)
1977                                echo    " \\"  >> hlist.inc
1978                                printf " $sf" >> hlist.inc
1979                                ;;
1980                            flow)
1981                                echo    " \\"  >> ad_flow_files.inc
1982                                printf " $sf" >> ad_flow_files.inc
1983                                ;;
1984                        esac
1985                    fi
1986              fi              fi
1987          fi          fi
1988      done      done
1989      if test "x$deplist" != x ; then      if test "x$deplist" != x ; then
1990          echo $'\n'"#  These files are linked from $d" >> srclinks.tmp          echo "" >> srclinks.tmp
1991            echo "#  These files are linked from $d" >> srclinks.tmp
1992          echo "$deplist :" >> srclinks.tmp          echo "$deplist :" >> srclinks.tmp
1993          echo $'\t$(LN) '$d'/$@ $@' >> srclinks.tmp          printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp
1994      fi      fi
1995  done  done
1996  rm -rf .links.tmp  rm -rf .links.tmp
1997  echo "" >> srclist.inc  echo "" >> srclist.inc
1998  echo "" >> csrclist.inc  echo "" >> csrclist.inc
1999    echo "" >> f90srclist.inc
2000  echo "" >> hlist.inc  echo "" >> hlist.inc
2001    echo "" >> ad_flow_files.inc
2002    
2003  if test -e $MAKEFILE ; then  if test -f $MAKEFILE ; then
2004      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.bak"
2005  fi  fi
2006  echo "  Writing makefile: $MAKEFILE"  echo "  Writing makefile: $MAKEFILE"
# Line 816  echo "#    $MACHINE" >> $MAKEFILE Line 2009  echo "#    $MACHINE" >> $MAKEFILE
2009  echo "# This makefile was generated automatically on" >> $MAKEFILE  echo "# This makefile was generated automatically on" >> $MAKEFILE
2010  echo "#    $THISDATE" >> $MAKEFILE  echo "#    $THISDATE" >> $MAKEFILE
2011  echo "# by the command:" >> $MAKEFILE  echo "# by the command:" >> $MAKEFILE
2012  echo "#    $0 $@" >> $MAKEFILE  echo "#    $0 $G2ARGS" >> $MAKEFILE
2013  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
2014  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE  echo "#    ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
2015    
2016    EXE_AD=$EXECUTABLE"_ad"
2017    EXE_FTL=$EXECUTABLE"_ftl"
2018    EXE_SVD=$EXECUTABLE"_svd"
2019    
2020  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2021    #
2022    # OPTFILE="$OPTFILE"
2023  #  #
2024  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
2025  # SOURCEDIRS   : Directories containing the source (.F) files  # SOURCEDIRS   : Directories containing the source (.F) files
# Line 847  EXEDIR      = ${EXEDIR} Line 2047  EXEDIR      = ${EXEDIR}
2047  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}
2048  TOOLSDIR    = ${TOOLSDIR}  TOOLSDIR    = ${TOOLSDIR}
2049    
2050    #eh3  new defines for the adjoint work
2051    AUTODIFF    = ${ROOTDIR}/pkg/autodiff
2052    EXE_AD      = ${EXE_AD}
2053    EXE_FTL     = ${EXE_FTL}
2054    EXE_SVD     = ${EXE_SVD}
2055    
2056    ENABLED_PACKAGES = ${ENABLED_PACKAGES}
2057    DISABLED_PACKAGES = ${DISABLED_PACKAGES}
2058    
2059    # These files are created by Makefile
2060    SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h
2061    
2062  EOF  EOF
2063    
2064  #  Note: figure out some way to add Hyades JAM libraries here  #  Note: figure out some way to add Hyades JAM libraries here
# Line 862  MAKEDEPEND = ${MAKEDEPEND} Line 2074  MAKEDEPEND = ${MAKEDEPEND}
2074  KPP = ${KPP}  KPP = ${KPP}
2075  # Fortran compiler  # Fortran compiler
2076  FC = ${FC}  FC = ${FC}
2077    # Fortran compiler
2078    F90C = ${F90C}
2079    # C compiler
2080    CC = ${CC}
2081  # Link editor  # Link editor
2082  LINK = ${LINK}  LINK = ${LINK} ${LDADD}
2083    
2084  # Defines for CPP  # Defines for CPP
2085  DEFINES = ${DEFINES}  DEFINES = ${DEFINES}
# Line 875  KFLAGS2 = ${KFLAGS2} Line 2091  KFLAGS2 = ${KFLAGS2}
2091  # Optim./debug for FC  # Optim./debug for FC
2092  FFLAGS = ${FFLAGS}  FFLAGS = ${FFLAGS}
2093  FOPTIM = ${FOPTIM}  FOPTIM = ${FOPTIM}
2094    # Optim./debug for FC
2095    F90FLAGS = ${F90FLAGS}
2096    F90OPTIM = ${F90OPTIM}
2097  # Flags for CC  # Flags for CC
2098  CFLAGS = ${CFLAGS}  CFLAGS = ${CFLAGS}
2099  # Files that should not be optimized  # Files that should not be optimized
2100  NOOPTFILES = ${NOOPTFILES}  NOOPTFILES = ${NOOPTFILES}
2101  NOOPTFLAGS = ${NOOPTFLAGS}  NOOPTFLAGS = ${NOOPTFLAGS}
2102  # Flags and libraries needed for linking  # Flags and libraries needed for linking
2103  LIBS = ${LIBS} \$(XLIBS)  LIBS = ${LIBS}
2104    # Name of the Mekfile
2105    MAKEFILE=${MAKEFILE}
2106    
2107  EOF  EOF
2108    
2109  cat srclist.inc  >> $MAKEFILE  cat srclist.inc       >> $MAKEFILE
2110  cat csrclist.inc >> $MAKEFILE  cat csrclist.inc      >> $MAKEFILE
2111  cat hlist.inc >> $MAKEFILE  cat f90srclist.inc    >> $MAKEFILE
2112  echo 'F77FILES =  $(SRCFILES:.F=.f)'                    >> $MAKEFILE  cat hlist.inc         >> $MAKEFILE
2113  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o)' >> $MAKEFILE  cat ad_flow_files.inc >> $MAKEFILE
2114    echo >> $MAKEFILE
2115  rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp  echo 'F77FILES =  $(SRCFILES:.F=.'$FS')'      >> $MAKEFILE
2116    echo 'F90FILES =  $(F90SRCFILES:.F90=.'$FS90')' >> $MAKEFILE
2117    echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
2118    echo >> $MAKEFILE
2119    echo '.SUFFIXES:' >> $MAKEFILE
2120    echo '.SUFFIXES: .o .'$FS' .p .F .c .'$FS90' .F90' >> $MAKEFILE
2121    rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc
2122    rm -f ad_flow_files.inc
2123    
2124  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2125    
 .SUFFIXES:  
 .SUFFIXES: .o .f .p .F .c  
   
2126  all: \$(EXECUTABLE)  all: \$(EXECUTABLE)
2127  \$(EXECUTABLE): \$(OBJFILES)  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(OBJFILES)
2128            @echo Creating \$@ ...
2129          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
2130  depend:  depend:
2131          @make links          @make links
2132          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
2133            \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2134            -rm -f makedepend.out
2135    
2136    lib: libmitgcmuv.a
2137    
2138  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES)  libmitgcmuv.a: \$(OBJFILES)
2139            ar rcv libmitgcmuv.a \$(OBJFILES)
2140    
2141  small_f: \$(F77FILES)  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES)
2142    
2143    small_f: \$(F77FILES) \$(F90FILES)
2144    
2145  output.txt: \$(EXECUTABLE)  output.txt: \$(EXECUTABLE)
2146          @printf 'running ... '          @printf 'running ... '
2147          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
2148    
2149  clean:  clean:
2150          -rm -rf *.o *.f *.p ${RMFILES} work.{pc,pcl}          -rm -rf *.o *.$FS *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
2151  Clean:  Clean:
2152          @make clean          @make clean
2153          @make cleanlinks          @make cleanlinks
2154          -rm -f Makefile.bak          -rm -f \$(SPECIAL_FILES)
2155            -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak
2156  CLEAN:  CLEAN:
2157          @make Clean          @make Clean
2158          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
2159          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
2160          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
2161          -rm -f \$(EXECUTABLE)          -rm -f \$(EXECUTABLE) output.txt STD*
2162    
2163    #eh3 Makefile: makefile
2164  makefile:  makefile:
2165          ${0} $@          $THIS_SCRIPT $G2ARGS
2166  cleanlinks:  cleanlinks:
2167          -find . -type l -exec rm {} \;          -find . -type l -exec rm {} \;
2168    
2169  # The normal chain of rules is (  .F - .f - .o  )  # Special targets (SPECIAL_FILES) which are create by make
2170  .F.f:  ${PACKAGES_DOT_H}:
2171            @echo Creating \$@ ...
2172            @$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) > \$@
2173    AD_CONFIG.h:
2174            @echo Creating \$@ ...
2175            @$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 > \$@
2176    FC_NAMEMANGLE.h:
2177            @echo Creating \$@ ...
2178            echo "$FC_NAMEMANGLE" > \$@
2179    
2180    BUILD_INFO.h:
2181            @echo Creating \$@ ...
2182    EOF
2183    
2184    test ! "x$THISVER" = x  && echo "       -echo \"#define THISVER '$THISVER'\" > \$@"   >> $MAKEFILE
2185    test ! "x$THISUSER" = x && echo "       -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE
2186    test ! "x$THISDATE" = x && echo "       -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
2187    test ! "x$THISHOST" = x && echo "       -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
2188    
2189    cat >>$MAKEFILE <<EOF
2190    
2191    # The normal chain of rules is (  .F - .$FS - .o  )
2192    
2193    ## This nullifies any default implicit rules concerning these two file types:
2194    ## %.o : %.F
2195    
2196    .F.$FS:
2197          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2198  .f.o:  .$FS.o:
2199          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2200    .F90.$FS90:
2201            \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2202    .$FS90.o:
2203            \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
2204  .c.o:  .c.o:
2205          \$(CC) \$(CFLAGS) -c \$<          \$(CC) \$(CFLAGS) -c \$<
2206    
2207  # Special exceptions that use the ( .F - .p - .f - .o ) rule-chain  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
2208  .F.p:  .F.p:
2209          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2210  .p.f:  .p.$FS:
2211          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
2212    
2213    #=========================================
2214    #===  Automatic Differentiation Rules  ===
2215    
2216    TAMC           = ${TAMC}
2217    TAF            = ${TAF}
2218    
2219    TAF_EXTRA      = ${TAF_EXTRA}
2220    TAMC_EXTRA     = ${TAMC_EXTRA}
2221    
2222    EOF
2223    
2224    ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
2225    ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF_FLAGS"
2226    ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
2227    for i in $ad_vars ; do
2228        name=$i
2229        t1="t2=\$"`echo $i`
2230        eval $t1
2231        printf "%-20s = " $name >> $MAKEFILE
2232        echo $t2 >> $MAKEFILE
2233    done
2234    
2235    echo "  Add the source list for AD code generation"
2236    echo >> $MAKEFILE
2237    printf "AD_FILES = " >> $MAKEFILE
2238    AD_FILES=`cat ad_files`
2239    for i in $AD_FILES ; do
2240        echo    " \\" >> $MAKEFILE
2241        printf " $i" >> $MAKEFILE
2242    done
2243    echo >> $MAKEFILE
2244    rm -f ad_files
2245    
2246    cat >>$MAKEFILE <<EOF
2247    
2248    # ... AD ...
2249    adall: ad_taf
2250    adtaf: ad_taf_output.$FS
2251    adtamc: ad_tamc_output.$FS
2252    
2253    ad_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)
2254            @$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
2255            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
2256            -rm -f ad_config.template
2257            @make \$(F77FILES)
2258            @make \$(AD_FLOW_FILES)
2259            cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.$FS
2260    
2261    ad_taf_output.$FS: ad_input_code.$FS
2262            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2263            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
2264    
2265    adtafonly:
2266            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2267            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
2268    
2269    ad_taf: ad_taf_output.o \$(OBJFILES)
2270            \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
2271    
2272    ad_tamc_output.$FS: ad_input_code.$FS
2273            \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
2274            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS
2275    
2276    ad_tamc: ad_tamc_output.o \$(OBJFILES)
2277            \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
2278    
2279    adonlyfwd:
2280            patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
2281    
2282    adtrick:
2283            patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
2284    
2285    # ... FTL ...
2286    ftlall: ftl_taf
2287    ftltaf: ftl_taf_output.$FS
2288    ftltamc: ftl_tamc_output.$FS
2289    
2290    ftl_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)
2291            @$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
2292            cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
2293            -rm -f ftl_config.template
2294            @make \$(F77FILES)
2295            @make \$(AD_FLOW_FILES)
2296            cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.$FS
2297    
2298    ftl_taf_output.$FS: ftl_input_code.$FS
2299            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2300            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2301    
2302    ftltafonly:
2303            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2304            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2305    
2306    ftl_taf: ftl_taf_output.o \$(OBJFILES)
2307            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
2308    
2309    ftl_tamc_output.$FS: ftl_input_code.$FS
2310            \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
2311            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS
2312    
2313    ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
2314            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
2315    
2316    
2317    # ... SVD ...
2318    svdtaf: ad_taf_output.$FS ftl_taf_output.$FS
2319            @echo "--->>> Only ran TAF to generate SVD code!    <<<---"
2320            @echo "--->>> Do make svdall afterwards to compile. <<<---"
2321    svdall: svd_touch svd_taf
2322    
2323    svd_taf: \$(OBJFILES)
2324            \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
2325    
2326            @echo "--->>> Only COMPILE svd code! <<<---"
2327            @echo "--->>> Assumes you previously <<<---"
2328            @echo "--->>> did make svdtaf        <<<---"
2329    
2330    svd_touch:
2331            @echo "--->>> Only COMPILE svd code! <<<---"
2332            @echo "--->>> Assumes you previously <<<---"
2333            @echo "--->>> did make svdtaf        <<<---"
2334            touch ad_taf_output.$FS ftl_taf_output.$FS
2335            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS
2336            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS
2337            @$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
2338            cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
2339            -rm -f ftl_config.template
2340    
2341    #=========================================
2342    
2343  EOF  EOF
2344    
2345    if test "x$EXEHOOK" != x ; then
2346        printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
2347    fi
2348    
2349  echo "  Making list of \"exceptions\" that need \".p\" files"  echo "  Making list of \"exceptions\" that need \".p\" files"
2350  for i in $KPPFILES ; do  for i in $KPPFILES ; do
2351      base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`      base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
# Line 954  for i in $KPPFILES ; do Line 2353  for i in $KPPFILES ; do
2353      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
2354          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
2355      fi      fi
2356      echo "$base.f: $base.p" >> $MAKEFILE      echo "$base.$FS: $base.p" >> $MAKEFILE
2357  done  done
2358    
2359  echo "  Making list of NOOPTFILES"  echo "  Making list of NOOPTFILES"
# Line 964  for i in $NOOPTFILES ; do Line 2363  for i in $NOOPTFILES ; do
2363      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
2364          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
2365      fi      fi
2366      echo "$base.o: $base.f" >> $MAKEFILE      echo "$base.o: $base.$FS" >> $MAKEFILE
2367      echo $'\t$(FC) $(FFLAGS) $(NOOPTFLAGS) -c $<' >> $MAKEFILE      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
2368  done  done
2369    
2370  echo "  Add rules for links"  echo "  Add rules for links"
# Line 973  cat srclinks.tmp >> $MAKEFILE Line 2372  cat srclinks.tmp >> $MAKEFILE
2372  rm -f srclinks.tmp  rm -f srclinks.tmp
2373    
2374  echo "  Adding makedepend marker"  echo "  Adding makedepend marker"
2375  echo $'\n\n'"# DO NOT DELETE" >> $MAKEFILE  printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
2376    
2377    printf "\n===  Done  ===\n"
2378    
2379    # Create special header files
2380    $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"
2381    if test ! -f $PACKAGES_DOT_H ; then
2382        mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2383    else
2384        cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
2385        RETVAL=$?
2386        if test "x$RETVAL" = x0 ; then
2387            rm -f $PACKAGES_DOT_H".tmp"
2388        else
2389            mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
2390            mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2391        fi
2392    fi
2393    if test ! -f AD_CONFIG.h ; then
2394        $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
2395    fi
2396    
2397    
2398  echo $'\n'"===  Done  ==="  #  Write the "state" for future records
2399    if test "x$DUMPSTATE" != xf ; then
2400        printf "" > genmake_state
2401        for i in $gm_state ; do
2402            t1="t2=\$$i"
2403            eval $t1
2404            echo "$i='$t2'" >> genmake_state
2405        done
2406    fi

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.135

  ViewVC Help
Powered by ViewVC 1.1.22