/[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.9 by adcroft, Fri Sep 26 18:16:38 2003 UTC revision 1.84 by edhill, Mon Jul 12 15:49:08 2004 UTC
# Line 1  Line 1 
1  #!/bin/bash  #! /usr/bin/env sh
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 -e Makefile  &&  mv -f Makefile Makefile.bak
126        cat <<EOF >> Makefile
127    %.$tfs : %.F
128    .SUFFIXES:
129    genmake_hello.$tfs: genmake_hello.F
130            $LN genmake_hello.F genmake_hello.$tfs
131    EOF
132        $MAKE "genmake_hello."$tfs > /dev/null 2>&1
133        RETVAL=$?
134        if test "x$RETVAL" != x0 -o ! -e "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 -e Makefile  &&  mv -f Makefile.bak 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          cat <<EOF >> genmake_tc.f
185          program test
186          write(*,*) 'test'
187          stop
188          end
189    EOF
190          makedepend genmake_tc.f > /dev/null 2>&1
191          RV1=$?
192          if test ! "x${RV0}${RV1}" = x00 ; then
193             echo "    a system-default makedepend was not found."
194    
195             #  Try to build the cyrus impl
196             rm -f ./genmake_cy_md
197             (
198                 cd $ROOTDIR/tools/cyrus-imapd-makedepend  \
199                     &&  ./configure > /dev/null 2>&1  \
200                     &&  make > /dev/null 2>&1
201                 if test -x ./makedepend.exe ; then
202                     $LN ./makedepend.exe ./makedepend
203                 fi
204                 ./makedepend ifparser.c > /dev/null 2>&1  \
205                     &&  echo "true"
206             ) > ./genmake_cy_md
207             grep true ./genmake_cy_md > /dev/null 2>&1
208             RETVAL=$?
209             if test "x$RETVAL" = x0 ; then
210                 MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
211             else
212                 MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
213             fi
214             rm -f ./genmake_cy_md
215          fi
216        fi
217    }
218    
219    
220  # Guess possible config options for this host  # Guess possible config options for this host
221  find_possible_configs()  {  find_possible_configs()  {
222    
223      p_PLATFORM=`uname`"-"`uname -m`      tmp1=`uname`"_"`uname -m`
224      echo "The platform appears to be:"      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
225      echo "  "$p_PLATFORM      tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
226        tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
227      p_LN=      tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
228        tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
229        PLATFORM=$tmp3
230        echo $PLATFORM | grep cygwin > /dev/null 2>&1  &&  PLATFORM=cygwin_ia32
231        OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
232        echo "  The platform appears to be:  $PLATFORM"
233        
234      echo "test" > test      echo "test" > test
235      ln -s ./test link      ln -s ./test link
236      RETVAL=$?      RETVAL=$?
237      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
238          p_LN="ln -s"          LN="ln -s"
239        else
240            echo "Error: \"ln -s\" does not appear to work on this system!"
241            echo "  For help, please contact <MITgcm-support@mitgcm.org>."
242            exit 1
243      fi      fi
244      rm -f test link      rm -f test link
245    
246      p_CPP=`which cpp`      if test "x$CPP" = x ; then
247                CPP="cpp -traditional -P"
     RETVAL=$?  
     if test "x${RETVAL}" = x0 ; then  
         p_LN="ln -s"  
248      fi      fi
249      rm -f test link  
250        look_for_makedepend
251    
252      # look for possible fortran compilers      # look for possible fortran compilers
253        tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"
254      p_FC=      p_FC=
255      for c in f77 g77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 ; do      for c in $tmp ; do
256          which $c > /dev/null 2>&1          rm -f ./hello.f ./hello
257            cat >> hello.f <<EOF
258          program hello
259          do i=1,3
260            print *, 'hello world : ', i
261          enddo
262          end
263    EOF
264            $c -o hello hello.f > /dev/null 2>&1
265          RETVAL=$?          RETVAL=$?
266          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
267              p_FC="$p_FC $c"              p_FC="$p_FC $c"
268          fi          fi
269      done      done
270      echo "Possible FORTRAN compilers appear to be:  "      rm -f ./hello.f ./hello
271      if test "x${p_FC}" = x ; then      if test "x${p_FC}" = x ; then
272          echo "  None found!!!"          cat 1>&2 <<EOF
273    
274    Error: No Fortran compilers were found in your path.  Please specify one using:
275    
276        1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
277        2) a command-line option (eg. "-fc NAME"), or
278        3) the MITGCM_FC environment variable.
279    
280    EOF
281            exit 1
282      else      else
283          echo "  "$p_FC          echo "  The possible FORTRAN compilers found in your path are:"
284            echo "   "$p_FC
285            if test "x$FC" = x ; then
286                FC=`echo $p_FC | $AWK '{print $1}'`
287                echo "  Setting FORTRAN compiler to: "$FC
288            fi
289      fi      fi
290    
291      # look for possible MPI libraries      if test "x$OPTFILE" = x ; then
292      mpi_libs=          OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
293      mpi_fort=`which mpif77 2>/dev/null`          if test ! -r $OPTFILE ; then
294      RETVAL=$?               echo "  I looked for the file "$OPTFILE" but did not find it"
295      if test "x${RETVAL}" = x0 ; then          fi
296          cat >>test.f <<EOF      fi
297        PROGRAM HELLO  #    echo "  The options file:  $p_OF"
298        DO 10, I=1,10  #    echo "    appears to match so we'll use it."
299        PRINT *,'Hello World'  #   for i in $p_FC ; do
300     10 CONTINUE  #p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
301        STOP  #if test -r $p_OF ; then
302        END  #    OPTFILE=$p_OF
303    #    echo "  The options file:  $p_OF"
304    #    echo "    appears to match so we'll use it."
305    #    break
306    #fi
307    #   done
308        if test "x$OPTFILE" = x ; then
309            cat 1>&2 <<EOF
310    
311    Error: No options file was found in:  $ROOTDIR/tools/build_options/
312      that matches this platform ("$PLATFORM") and the compilers found in
313      your path.  Please specify an "optfile" using:
314    
315        1) the command line (eg. "-optfile=path/to/OPTFILE"), or
316        2) the MITGCM_OF environment variable.
317    
318      If you need help, please contact the developers at <MITgcm-support@mitgcm.org>.
319    
320  EOF  EOF
321          eval "$mpi_fort -showme test.f > out"          exit 1
         RETVAL=$?  
         if test "x${RETVAL}" = x0 ; then  
             a=`cat out`  
             for i in $a ; do  
                 case $i in  
                     -*)  
                         mpi_libs="$mpi_libs $i" ;;  
                 esac  
             done  
             echo "The MPI libs appear to be:"  
             echo "  "$mpi_libs  
         fi  
         rm -f test.f out  
322      fi      fi
323        
324    #     # look for possible MPI libraries
325    #     mpi_libs=
326    #     mpi_fort=`which mpif77 2>/dev/null`
327    #     RETVAL=$?
328    #     if test "x${RETVAL}" = x0 ; then
329    #       cat >>test.f <<EOF
330    #       PROGRAM HELLO
331    #       DO 10, I=1,10
332    #       PRINT *,'Hello World'
333    #    10 CONTINUE
334    #       STOP
335    #       END
336    # EOF
337    #       eval "$mpi_fort -showme test.f > out"
338    #       RETVAL=$?
339    #       if test "x${RETVAL}" = x0 ; then
340    #           a=`cat out`
341    #           for i in $a ; do
342    #               case $i in
343    #                   -*)
344    #                       mpi_libs="$mpi_libs $i" ;;
345    #               esac
346    #           done
347    #           echo "The MPI libs appear to be:"
348    #           echo "  "$mpi_libs
349    #       fi
350    #       rm -f test.f out
351    #     fi
352    
353  }  }
354    
# Line 86  get_pdepend_list()  { Line 358  get_pdepend_list()  {
358      #  strip the comments and then convert the dependency file into      #  strip the comments and then convert the dependency file into
359      #  two arrays: PNAME, DNAME      #  two arrays: PNAME, DNAME
360      cat $1 | sed -e 's/#.*$//g' \      cat $1 | sed -e 's/#.*$//g' \
361          | 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} }' \
362          > ./.pd_tmp          > ./.pd_tmp
363      source ./.pd_tmp      . ./.pd_tmp
364      rm -f ./.pd_tmp      rm -f ./.pd_tmp
365    
366      echo -n "PNAME = "${}      printf "PNAME = "${}
367  }  }
368    
369    
370  #  Explain usage  #  Explain usage
371  usage()  {  usage()  {
372      echo  cat <<EOF
373      echo "Usage: "$0" [OPTIONS]"  
374      echo "  where [OPTIONS] can be:"  Usage: "$0" [OPTIONS]
375      echo    where [OPTIONS] can be:
376      echo "    -help | --help | -h | --h"  
377      echo "    -nooptfile | --nooptfile"      -help | --help | -h | --h
378      echo "      -optfile NAME | --optfile NAME | -of NAME | --of NAME"            Print this help message and exit.
379      echo "      -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME"  
380      echo "    -pdepend NAME | --pdepend NAME"      -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME
381      echo "      -pdepend=NAME | --pdepend=NAME"        -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME
382      echo "    -pdefault NAME | --pdefault NAME"            Use "NAME" as the adoptfile.  By default, the file at
383      echo "      -pdefault=NAME | --pdefault=NAME"            "tools/adjoint_options/adjoint_default" will be used.
384      echo "    -make NAME | -m NAME"  
385      echo "      --make=NAME | -m=NAME"      -nooptfile | --nooptfile
386      echo "    -makefile NAME | -mf NAME"        -optfile NAME | --optfile NAME | -of NAME | --of NAME
387      echo "      --makefile=NAME | -mf=NAME"        -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
388      echo "    -platform NAME | --platform NAME | -pl NAME | --pl NAME"            Use "NAME" as the optfile.  By default, an attempt will be
389      echo "      -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"            made to find an appropriate "standard" optfile in the
390      echo "    -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"            tools/build_options/ directory.
391      echo "      -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME"  
392      echo "    -mods NAME | --mods NAME | -mo NAME | --mo NAME"      -pdepend NAME | --pdepend NAME
393      echo "      -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME"        -pdepend=NAME | --pdepend=NAME
394      echo "    -disable NAME | --disable NAME"            Get package dependency information from "NAME".
395      echo "      -disable=NAME | --disable=NAME"  
396      echo "    -enable NAME | --enable NAME"      -pdefault NAME | --pdefault NAME
397      echo "      -enable=NAME | --enable=NAME"        -pdefault=NAME | --pdefault=NAME
398      echo "    -noopt NAME | --noopt NAME"            Get the default package list from "NAME".
399      echo "      -noopt=NAME | --noopt=NAME"  
400  #    echo "    -cpp NAME | --cpp NAME"      -make NAME | -m NAME
401  #    echo "      -cpp=NAME | --cpp=NAME"        --make=NAME | -m=NAME
402      echo "    -fortran NAME | --fortran NAME | -fc NAME | --fc NAME"            Use "NAME" for the MAKE program. The default is "make" but
403      echo "      -fc=NAME | --fc=NAME"            many platforms, "gmake" is the preferred choice.
404      echo "    -[no]ieee | --[no]ieee"  
405      echo "    -[no]mpi | --[no]mpi"      -makefile NAME | -mf NAME
406      echo "    -[no]jam | --[no]jam"        --makefile=NAME | -mf=NAME
407      echo            Call the makefile "NAME".  The default is "Makefile".
408      echo "  and NAME is a string such as:"  
409      echo      -makedepend NAME | -md NAME
410      echo "    --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'"        --makedepend=NAME | -md=NAME
411      echo "    -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'"            Use "NAME" for the MAKEDEPEND program.
412      echo "    -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"  
413      echo      -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
414      echo "  which, depending upon your shell, may need to be single-quoted"        -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
415      echo "  if it contains spaces, dashes, or other special characters."            Specify the location of the MITgcm ROOTDIR as "NAME".
416              By default, genamke will try to find the location by
417              looking in parent directories (up to the 5th parent).
418    
419        -mods NAME | --mods NAME | -mo NAME | --mo NAME
420          -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
421              Here, "NAME" specifies a list of directories that are
422              used for additional source code.  Files found in the
423              "mods list" are given preference over files of the same
424              name found elsewhere.
425    
426        -disable NAME | --disable NAME
427          -disable=NAME | --disable=NAME
428              Here "NAME" specifies a list of packages that we don't
429              want to use.  If this violates package dependencies,
430              genamke will exit with an error message.
431    
432        -enable NAME | --enable NAME
433          -enable=NAME | --enable=NAME
434              Here "NAME" specifies a list of packages that we wish
435              to specifically enable.  If this violates package
436              dependencies, genamke will exit with an error message.
437    
438        -standarddirs NAME | --standarddirs NAME
439          -standarddirs=NAME | --standarddirs=NAME
440              Here, "NAME" specifies a list of directories to be
441              used as the "standard" code.
442    
443        -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
444          -fc=NAME | --fc=NAME
445              Use "NAME" as the fortran compiler.  By default, genmake
446              will search for a working compiler by trying a list of
447              "usual suspects" such as g77, f77, etc.
448    
449        -[no]ieee | --[no]ieee
450              Do or don't use IEEE numerics.  Note that this option
451              *only* works if it is supported by the OPTFILE that
452              is being used.
453    
454        -mpi | --mpi
455              Include MPI header files and link to MPI libraries
456        -mpi=PATH | --mpi=PATH
457              Include MPI header files and link to MPI libraries using MPI_ROOT
458              set to PATH. i.e. Include files from $PATH/include, link to libraries
459              from $PATH/lib and use binaries from $PATH/bin.
460    
461        -bash NAME
462              Explicitly specify the Bourne or BASH shell to use
463    
464      While it is most often a single word, the "NAME" variables specified
465      above can in many cases be a space-delimited string such as:
466    
467        --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'
468        -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'
469        -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
470    
471      which, depending upon your shell, may need to be single-quoted.
472    
473      For more detailed genmake documentation, please see:
474    
475        http://mitgcm.org/devel_HOWTO/
476    
477    EOF
478    
479      exit 1      exit 1
480  }  }
481    
482  #eh3 # This is the generic configuration.  #  Build a CPP macro to automate calling C routines from FORTRAN
483  #eh3 set LN         = ( 'ln -s' )  get_fortran_c_namemangling()  {
484  #eh3 set CPP        = ( '/lib/cpp -P' )      default_nm="#define FC_NAMEMANGLE(X) X ## _"
485  #eh3 set S64        = ( '$(TOOLSDIR)/set64bitConst.sh' )      
486  #eh3 set KPP        = (  )      cat > genmake_test.c <<EOF
487  #eh3 set FC         = ( 'f77' )  void tcall( char * string ) { tsub( string ); }
488  #eh3 set LINK       = $FC  EOF
489  #eh3 set MAKEDEPEND = ( 'makedepend' )      $MAKE genmake_test.o >> genmake_warnings 2>&1
490  #eh3 set INCLUDES   = ( -I. )      RETVAL=$?
491  #eh3 set FFLAGS     = (  )      if test "x$RETVAL" != x0 ; then
492  #eh3 set FOPTIM     = (  )          FC_NAMEMANGLE=$default_nm
493  #eh3 set CFLAGS     = (  )          cat <<EOF>> genmake_errors
494  #eh3 set KFLAGS1    = (  )  
495  #eh3 set KFLAGS2    = (  )  WARNING: C test compile fails
496  #eh3 set LIBS       = (  )  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
497  #eh3 set KPPFILES   = (  )  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
498  #eh3 if (! $?NOOPTFILES ) set NOOPTFILES = (  )  EOF
499  #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = (  )          return 1
500        fi
501        c_tcall=`nm genmake_test.o | grep 'T ' | grep tcall | cut -d ' ' -f 3`
502        RETVAL=$?
503        if test "x$RETVAL" != x0 ; then
504            FC_NAMEMANGLE=$default_nm
505            cat <<EOF>> genmake_warnings
506    
507    WARNING: The "nm" command failed.
508    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
509    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
510    EOF
511            return 1
512        fi
513        cat > genmake_tcomp.f <<EOF
514          subroutine tcall( string )
515          character*(*) string
516          call tsub( string )
517          end
518    EOF
519        $FC $FFLAGS $DEFINES -c genmake_tcomp.f >> genmake_warnings 2>&1
520        RETVAL=$?
521        if test "x$RETVAL" != x0 ; then
522            FC_NAMEMANGLE=$default_nm
523            cat <<EOF>> genmake_warnings
524    
525    WARNING: FORTRAN test compile fails -- please see "genmake_errors"
526    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
527    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
528    EOF
529            return 1
530        fi
531        f_tcall=`nm genmake_tcomp.o | grep 'T ' | grep tcall | cut -d ' ' -f 3`
532        RETVAL=$?
533        if test "x$RETVAL" != x0 ; then
534            FC_NAMEMANGLE=$default_nm
535            cat <<EOF>> genmake_warnings
536    
537    WARNING: The "nm" command failed.
538    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
539    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
540    EOF
541            return 1
542        fi
543    
544        c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
545        f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
546        c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
547        f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
548    
549        nmangle="X"
550        if test "x$c_a" != "x$f_a" ; then
551            comm="echo x$f_a | sed -e 's|x$c_a||'"
552            a=`eval $comm`
553            nmangle="$a ## $nmangle"
554        fi
555        if test "x$c_b" != "x$f_b" ; then
556            comm="echo x$f_b | sed -e 's|x$c_b||'"
557            b=`eval $comm`
558            nmangle="$nmangle ## $b"
559        fi
560    
561        FC_NAMEMANGLE="#define FC_NAMEMANGLE(X)  $nmangle"
562    
563        #  cleanup the testing files
564        rm -f genmake_tcomp.* genmake_test.*
565    }
566    
567    
568    check_HAVE_CLOC()  {
569        get_fortran_c_namemangling
570        cat <<EOF > genmake_tc_1.c
571    $FC_NAMEMANGLE
572    #include <stdio.h>
573    #include <stdlib.h>
574    #include <unistd.h>
575    #include <assert.h>
576    #include <sys/time.h>
577    void FC_NAMEMANGLE(cloc) ( double *curtim )
578    {
579     struct timeval tv1;
580     gettimeofday(&tv1 , (void *)NULL );
581     *curtim =  (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
582     *curtim = *curtim/1.E6;
583    }
584    EOF
585        make genmake_tc_1.o >> genmake_tc.log 2>&1
586        RET_C=$?
587        cat <<EOF > genmake_tc_2.f
588          program hello
589          Real*8 wtime
590          external cloc
591          call cloc(wtime)
592          print *," HELLO WORLD", wtime
593          end program hello
594    EOF
595        $FC $FFLAGS -o genmake_tc genmake_tc_2.f genmake_tc_1.o >> genmake_tc.log 2>&1
596        RET_F=$?
597        test -x ./genmake_tc  &&  ./genmake_tc >> genmake_tc.log 2>&1
598        RETVAL=$?
599        if test "x$RETVAL" = x0 ; then
600            HAVE_CLOC=t
601            DEFINES="$DEFINES -DHAVE_CLOC"
602        fi
603        rm -f genmake_tc*
604    }
605    
606    
607    check_netcdf_libs()  {
608        cat <<EOF > genmake_tnc.for
609          program fgennc
610    #include "netcdf.inc"
611          integer iret, ncid, xid
612          iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
613          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
614          iret = nf_def_dim(ncid, 'X', 11, xid)
615          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
616          iret = nf_close(ncid)
617          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
618          end
619    EOF
620        $CPP genmake_tnc.for > genmake_tnc.f  \
621            &&  $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f $LIBS >> genmake_tnc.log 2>&1
622        RET_COMPILE=$?
623        test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1
624        RETVAL=$?
625        if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
626            HAVE_NETCDF=t
627        else
628            # try again with "-lnetcdf" added to the libs
629            $CPP genmake_tnc.for > genmake_tnc.f  \
630                &&  $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f \
631                $LIBS -lnetcdf >> genmake_tnc_2.log 2>&1
632            RET_COMPILE=$?
633            test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1
634            RETVAL=$?
635            if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
636                LIBS="$LIBS -lnetcdf"
637                HAVE_NETCDF=t
638            else
639                cat genmake_tnc.log >> genmake_warnings
640            fi
641        fi
642        rm -f genmake_tnc*
643    }
644    
645    
646    
647    ###############################################################################
648    #   Sequential part of script starts here
649    ###############################################################################
650    
651  #  Set defaults here  #  Set defaults here
652  COMMANDL="$0 $@"  COMMANDL="$0 $@"
# Line 171  LN= Line 656  LN=
656  S64=  S64=
657  KPP=  KPP=
658  FC=  FC=
659    CPP=
660  LINK=  LINK=
661    DEFINES=
662  PACKAGES=  PACKAGES=
663  ENABLE=  ENABLE=
664  DISABLE=  DISABLE=
665  MAKEFILE=  MAKEFILE=
666  MAKEDEPEND=  MAKEDEPEND=
667  PDEPEND=  PDEPEND=
668  DUMPSTATE=f  DUMPSTATE=t
669  PDEFAULT=  PDEFAULT=
670  OPTFILE=  OPTFILE=
671  INCLUDES="-I."  INCLUDES="-I."
# Line 187  FOPTIM= Line 674  FOPTIM=
674  CFLAGS=  CFLAGS=
675  KFLAGS1=  KFLAGS1=
676  KFLAGS2=  KFLAGS2=
677    #LDADD=
678  LIBS=  LIBS=
679  KPPFILES=  KPPFILES=
680  NOOPTFILES=  NOOPTFILES=
681  NOOPTFLAGS=  NOOPTFLAGS=
682    MPI=
683    MPIPATH=
684    
685    # DEFINES checked by test compilation
686    HAVE_SYSTEM=
687    HAVE_FDATE=
688    FC_NAMEMANGLE=
689    HAVE_CLOC=
690    HAVE_NETCDF=
691    HAVE_ETIME=
692    
693  MODS=  MODS=
694  TOOLSDIR=  TOOLSDIR=
695  SOURCEDIRS=  SOURCEDIRS=
696  INCLUDEDIRS=  INCLUDEDIRS=
697    STANDARDDIRS="USE_THE_DEFAULT"
698    
699    G2ARGS=
700    BASH=
701  PWD=`pwd`  PWD=`pwd`
702  MAKE=make  MAKE=make
703    AWK=awk
704  THISHOSTNAME=`hostname`  THISHOSTNAME=`hostname`
705  THISCWD=`pwd`  THISCWD=`pwd`
706  THISDATE=`date`  THISDATE=`date`
# Line 206  MACHINE=`uname -a` Line 708  MACHINE=`uname -a`
708  EXECUTABLE=  EXECUTABLE=
709  EXEHOOK=  EXEHOOK=
710  EXEDIR=  EXEDIR=
711    PACKAGES_CONF=
712    IEEE=
713    if test "x$MITGCM_IEEE" != x ; then
714        IEEE=$MITGCM_IEEE
715    fi
716    FS=
717    FS90=
718    
719    AUTODIFF_PKG_USED=f
720    AD_OPTFILE=
721    TAF=
722    AD_TAF_FLAGS=
723    FTL_TAF_FLAGS=
724    SVD_TAF_FLAGS=
725    TAF_EXTRA=
726    TAMC=
727    AD_TAMC_FLAGS=
728    FTL_TAF_FLAGS=
729    SVD_TAMC_FLAGS=
730    TAMC_EXTRA=
731    
732    
733  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
734  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"
735  gm_s2="FC IEEE MPI JAM DUMPSTATE"  gm_s2="FC CPP IEEE MPI JAM DUMPSTATE STANDARDDIRS"
736    
737  #  The following state is not directly set by command-line switches  #  The following state is not directly set by command-line switches
738  gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "  gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
739  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
740  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"
741  gm_s6="EXECUTABLE EXEHOOK EXEDIR"  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
742    gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME"
743    
744  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6"  #  The following are all related to adjoint/tangent-linear stuff
745    gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
746    gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
747    gm_s12="TAF_EXTRA TAMC_EXTRA"
748    
749    gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"
750    gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
751    
752    cat <<EOF
753    
754    GENMAKE :
755    
756    A program for GENerating MAKEfiles for the MITgcm project.  For a
757    quick list of options, use "genmake -h" or for more detail see:
758    
759      http://mitgcm.org/devel_HOWTO/
760    
761    EOF
762    
 echo  
763  echo "===  Processing options files and arguments  ==="  echo "===  Processing options files and arguments  ==="
764  gm_local="./gm_local"  gm_local="genmake_local"
765  echo -n "  getting local config information:  "  for i in . $MODS ; do
766        if test -r $i/$gm_local ; then
767            . $i/$gm_local
768            break
769        fi
770    done
771    printf "  getting local config information:  "
772  if test -e $gm_local ; then  if test -e $gm_local ; then
773      echo "using $gm_local"      echo "using $gm_local"
774      source $gm_local      . $gm_local
775      # echo "DISABLE=$DISABLE"      # echo "DISABLE=$DISABLE"
776      # echo "ENABLE=$ENABLE"      # echo "ENABLE=$ENABLE"
777  else  else
# Line 244  fi Line 789  fi
789  #   n=$(( $n + 1 ))  #   n=$(( $n + 1 ))
790  #done  #done
791  #parse_options  #parse_options
   
792  ac_prev=  ac_prev=
793  for ac_option ; do  for ac_option ; do
794    
795        G2ARGS="$G2ARGS \"$ac_option\""
796    
797      # If the previous option needs an argument, assign it.      # If the previous option needs an argument, assign it.
798      if test -n "$ac_prev"; then      if test -n "$ac_prev"; then
799          eval "$ac_prev=\$ac_option"          eval "$ac_prev=\$ac_option"
# Line 269  for ac_option ; do Line 815  for ac_option ; do
815          -optfile=* | --optfile=* | -of=* | --of=*)          -optfile=* | --optfile=* | -of=* | --of=*)
816              OPTFILE=$ac_optarg ;;              OPTFILE=$ac_optarg ;;
817                    
818            -adoptfile | --adoptfile | -adof | --adof)
819                ac_prev=AD_OPTFILE ;;
820            -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
821                AD_OPTFILE=$ac_optarg ;;
822            
823          -pdepend | --pdepend)          -pdepend | --pdepend)
824              ac_prev=PDEPEND ;;              ac_prev=PDEPEND ;;
825          -pdepend=* | --pdepend=*)          -pdepend=* | --pdepend=*)
# Line 284  for ac_option ; do Line 835  for ac_option ; do
835          -make=* | --make=* | -m=* | --m=*)          -make=* | --make=* | -m=* | --m=*)
836              MAKE=$ac_optarg ;;              MAKE=$ac_optarg ;;
837                    
838            -bash | --bash)
839                ac_prev=BASH ;;
840            -bash=* | --bash=*)
841                BASH=$ac_optarg ;;
842            
843            -makedepend | --makedepend | -md | --md)
844                ac_prev=MAKEDEPEND ;;
845            -makedepend=* | --makedepend=* | -md=* | --md=*)
846                MAKEDEPEND=$ac_optarg ;;
847            
848          -makefile | --makefile | -ma | --ma)          -makefile | --makefile | -ma | --ma)
849              ac_prev=MAKEFILE ;;              ac_prev=MAKEFILE ;;
850          -makefile=* | --makefile=* | -ma=* | --ma=*)          -makefile=* | --makefile=* | -ma=* | --ma=*)
851              MAKEFILE=$ac_optarg ;;              MAKEFILE=$ac_optarg ;;
852                    
853          -platform | --platform | -pl | --pl)          -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
854              ac_prev=PLATFORM ;;              echo "ERROR: The platform option has been removed.  Please specify"
855          -platform=* | --platform=* | -pl=* | --pl=*)              echo "  the build options using the \"optfile\" mechanism."
856              PLATFORM=$ac_optarg ;;              echo
857                usage
858                ;;
859                    
860          -rootdir | --rootdir | -rd | --rd)          -rootdir | --rootdir | -rd | --rd)
861              ac_prev=ROOTDIR ;;              ac_prev=ROOTDIR ;;
# Line 314  for ac_option ; do Line 877  for ac_option ; do
877          -enable=* | --enable=*)          -enable=* | --enable=*)
878              ENABLE=$ac_optarg ;;              ENABLE=$ac_optarg ;;
879                    
880          -noopt | --noopt)          -standarddirs | --standarddirs)
881              ac_prev=NOOPT ;;              ac_prev=STANDARDDIRS ;;
882          -noopt=* | --noopt=*)          -standarddirs=* | --standarddirs=*)
883              NOOPT=$ac_optarg ;;              STANDARDDIRS=$ac_optarg ;;
884            
885  #           -cpp | --cpp)  #           -cpp | --cpp)
886  #               ac_prev=cpp ;;  #               ac_prev=cpp ;;
887  #           -cpp=* | --cpp=*)  #           -cpp=* | --cpp=*)
# Line 329  for ac_option ; do Line 892  for ac_option ; do
892          -fc=* | --fc=*)          -fc=* | --fc=*)
893              FC=$ac_optarg ;;              FC=$ac_optarg ;;
894                    
895            -fs | --fs)
896                ac_prev=FS ;;
897            -fs=* | --fs=*)
898                FS=$ac_optarg ;;
899            
900            -fs90 | --fs90)
901                ac_prev=FS90 ;;
902            -fs90=* | --fs90=*)
903                FS90=$ac_optarg ;;
904            
905          -ieee | --ieee)          -ieee | --ieee)
906              IEEE=1 ;;              IEEE=true ;;
907          -noieee | --noieee)          -noieee | --noieee)
908              IEEE=0 ;;              IEEE= ;;
909            
910          -mpi | --mpi)          -mpi | --mpi)
911              MPI=1 ;;              MPI=true ;;
912          -nompi | --nompi)          -mpi=* | --mpi=*)
913              MPI=0 ;;              MPIPATH=$ac_optarg
914                        MPI=true ;;
915          -jam | --jam)          
916              JAM=1 ;;  #       -jam | --jam)
917          -nojam | --nojam)  #           JAM=1 ;;
918              JAM=0 ;;  #       -nojam | --nojam)
919    #           JAM=0 ;;
920                    
921          -ds | --ds)          -ds | --ds)
922              DUMPSTATE=t ;;              DUMPSTATE=t ;;
923                    
924            -taf_extra | --taf_extra)
925                ac_prev=TAF_EXTRA ;;
926            -taf_extra=* | --taf_extra=*)
927                TAF_EXTRA=$ac_optarg ;;
928    
929            -tamc_extra | --tamc_extra)
930                ac_prev=TAMC_EXTRA ;;
931            -tamc_extra=* | --tamc_extra=*)
932                TAMC_EXTRA=$ac_optarg ;;
933    
934          -*)          -*)
935              echo "Error: unrecognized option: "$ac_option              echo "Error: unrecognized option: "$ac_option
936              usage              usage
# Line 361  for ac_option ; do Line 945  for ac_option ; do
945            
946  done  done
947    
948    if test -f ./.genmakerc ; then
949        echo
950        echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
951        echo "  file.  This file format is no longer supported.  Please see:"
952        echo
953        echo "    http://mitgcm.org/devel_HOWTO/"
954        echo
955        echo "  for directions on how to setup and use the new \"genmake2\" input"
956        echo "  files and send an email to MITgcm-support@mitgcm.org if you want help."
957        echo
958    fi
959    
960    if test "x${ROOTDIR}" = x ; then
961        if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
962            ROOTDIR=".."
963        else
964            for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
965                if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
966                    ROOTDIR=$d
967                    printf "Warning:  ROOTDIR was not specified but there appears to be"
968                    echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
969                    break
970                fi
971            done
972        fi
973    fi
974    if test "x${ROOTDIR}" = x ; then
975        echo "Error: Cannot determine ROOTDIR for MITgcm code."
976        echo "  Please specify a ROOTDIR using either an options "
977        echo "  file or a command-line option."
978        exit 1
979    fi
980    if test ! -d ${ROOTDIR} ; then
981        echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
982        exit 1
983    fi
984    
985  echo "  getting OPTFILE information:  "  echo "  getting OPTFILE information:  "
986  if test "x${OPTFILE}" = x ; then  if test "x${OPTFILE}" = x ; then
987      echo "Warning: no OPTFILE specified so we'll look for possible settings"      if test "x$MITGCM_OF" = x ; then
988      printf "\n===  Searching for possible settings for OPTFILE  ===\n"          echo "Warning: no OPTFILE specified so we'll look for possible settings"
989      find_possible_configs          printf "\n===  Searching for possible settings for OPTFILE  ===\n"
990  else          find_possible_configs
     if test "x$OPTFILE" = xNONE ; then  
         echo "    OPTFILE=NONE so we'll try to use default settings"  
991      else      else
992          if test -f "$OPTFILE" -a -r "$OPTFILE" ; then          OPTFILE=$MITGCM_OF
993              echo "    using OPTFILE=\"$OPTFILE\""      fi
994              source "$OPTFILE"  fi
995              RETVAL=$?  if test "x$OPTFILE" != xNONE ; then
996              if test "x$RETVAL" != x0 ; then      if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
997                  echo -n "Error: failed to source OPTFILE \"$OPTFILE\""          echo "    using OPTFILE=\"$OPTFILE\""
998                  echo "--please check that variable syntax is bash-compatible"          . "$OPTFILE"
999                  exit 1          RETVAL=$?
1000              fi          if test "x$RETVAL" != x0 ; then
1001              if test "x$DUMPSTATE" != xf ; then              printf "Error: failed to source OPTFILE \"$OPTFILE\""
1002                  cp -f $OPTFILE "gm_optfile"              echo "--please check that variable syntax is bash-compatible"
1003              fi              exit 1
1004          else          fi
1005              echo "Error: can't read OPTFILE=\"$OPTFILE\""          if test "x$DUMPSTATE" != xf ; then
1006                cp -f $OPTFILE "genmake_optfile"
1007            fi
1008        else
1009            echo "Error: can't read OPTFILE=\"$OPTFILE\""
1010            exit 1
1011        fi
1012    fi
1013    
1014    #  Check for broken systems that cannot correctly distinguish *.F and *.f files
1015    # check_for_broken_Ff
1016    
1017    echo "  getting AD_OPTFILE information:  "
1018    if test "x${AD_OPTFILE}" = x ; then
1019        if test "x$MITGCM_AD_OF" = x ; then
1020            AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
1021        else
1022            AD_OPTFILE=$MITGCM_AD_OF
1023        fi
1024    fi
1025    if test "x${AD_OPTFILE}" != xNONE ; then
1026        if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
1027            echo "    using AD_OPTFILE=\"$AD_OPTFILE\""
1028            . "$AD_OPTFILE"
1029            RETVAL=$?
1030            if test "x$RETVAL" != x0 ; then
1031                printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
1032                echo "--please check that variable syntax is bash-compatible"
1033              exit 1              exit 1
1034          fi          fi
1035            if test "x$DUMPSTATE" != xf ; then
1036                cp -f $AD_OPTFILE "genmake_ad_optfile"
1037            fi
1038        else
1039            echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
1040            exit 1
1041      fi      fi
1042  fi  fi
1043    
1044  #  Check that FC, LINK, CPP, and S64 are defined.  If not, complain  #  Check that FC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
1045  #  and abort!  #  either set defaults or complain and abort!
1046    if test ! "x$BASH" = x ; then
1047        # add a trailing space so that it works within the Makefile syntax (see below)
1048        BASH="$BASH "
1049    fi
1050  if test "x$FC" = x ; then  if test "x$FC" = x ; then
1051      cat <<EOF 1>&2      cat <<EOF 1>&2
1052    
1053  Error: no Fortran compiler: please specify using one of the following:  Error: no Fortran compiler: please specify using one of the following:
1054    1) within the options file ("FC=...") as specified by "-of=OPTFILE"    1) within the options file ("FC=...") as specified by "-of=OPTFILE"
1055    2) the "-fc=XXX" command-line option    2) the "-fc=XXX" command-line option
1056    3) the "./gm_local" file    3) the "./genmake_local" file
1057  EOF  EOF
1058      exit 1      exit 1
1059  fi  fi
1060  if test "x$LINK" = x ; then  if test "x$LINK" = x ; then
1061      LINK=$FC      LINK=$FC
1062  fi  fi
1063    if test "x$MAKE" = x ; then
1064        MAKE="make"
1065    fi
1066  if test "x$CPP" = x ; then  if test "x$CPP" = x ; then
1067        CPP=cpp
1068    fi
1069    #EH3 === UGLY ===
1070    #  The following is an ugly little hack to check for $CPP in /lib/ and
1071    #  it should eventually be replaced with a more general function that
1072    #  searches a combo of the user's path and a list of "usual suspects"
1073    #  to find the correct location for binaries such as $CPP.
1074    for i in " " "/lib/" ; do
1075        echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1076    done
1077    #EH3 === UGLY ===
1078    echo "#define A a" | $CPP > test_cpp 2>&1
1079    RETVAL=$?
1080    if test "x$RETVAL" != x0 ; then
1081      cat <<EOF 1>&2      cat <<EOF 1>&2
1082    
1083  Error: no C pre-processor: please specify using one of the following:  Error: C pre-processor "$CPP" failed the test case: please specify using:
1084    
1085    1) within the options file ("CPP=...") as specified by "-of=OPTFILE"    1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
1086    2) the "./gm_local" file    2) the "./genmake_local" file
1087      3) with the CPP environment variable
1088    
1089  EOF  EOF
1090      exit 1      exit 1
1091    else
1092        rm -f test_cpp
1093  fi  fi
1094  if test "x$S64" = x ; then  look_for_makedepend
1095    if test "x$LN" = x ; then
1096        LN="ln -s"
1097    fi
1098    echo "test" > genmake_test_ln
1099    $LN genmake_test_ln genmake_tlink
1100    RETVAL=$?
1101    if test "x$RETVAL" != x0 ; then
1102      cat <<EOF 1>&2      cat <<EOF 1>&2
1103    
1104  Error: no C pre-processor: please specify using one of the following:  Error: The command "ln -s" failed -- please specify a working soft-link
1105    1) within the options file ("S64=...") as specified by "-of=OPTFILE"    command in the optfile.
1106    2) the "./gm_local" file  
1107  EOF  EOF
1108      exit 1      exit 1
1109  fi  fi
1110    rm -f genmake_test_ln genmake_tlink
1111    
1112    #  Check for broken *.F/*.f handling and fix if possible
1113    check_for_broken_Ff
1114    
1115    if test ! "x$MPI" = x ; then
1116          echo "  Turning on MPI cpp macros"
1117          DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
1118    fi
1119    
1120    printf "\n===  Checking system libraries  ===\n"
1121    printf "  Do we have the system() command using $FC...  "
1122    cat > genmake_tcomp.f <<EOF
1123          program hello
1124          call system('echo hi')
1125          end
1126    EOF
1127    $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1
1128    RETVAL=$?
1129    if test "x$RETVAL" = x0 ; then
1130        HAVE_SYSTEM=t
1131        DEFINES="$DEFINES -DHAVE_SYSTEM"
1132        echo "yes"
1133    else
1134        HAVE_SYSTEM=
1135        echo "no"
1136    fi
1137    rm -f genmake_tcomp*
1138    
1139    printf "  Do we have the fdate() command using $FC...  "
1140    cat > genmake_tcomp.f <<EOF
1141          program hello
1142          CHARACTER(128) string
1143          string = ' '
1144          call fdate( string )
1145          print *, string
1146          end
1147    EOF
1148    $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1
1149    RETVAL=$?
1150    if test "x$RETVAL" = x0 ; then
1151        HAVE_FDATE=t
1152        DEFINES="$DEFINES -DHAVE_FDATE"
1153        echo "yes"
1154    else
1155        HAVE_FDATE=
1156        echo "no"
1157    fi
1158    rm -f genmake_tcomp*
1159    
1160    printf "  Do we have the etime() command using $FC...  "
1161    cat > genmake_tcomp.f <<EOF
1162          program hello
1163          REAL*4 ACTUAL, TARRAY(2)
1164          EXTERNAL ETIME
1165          REAL*4 ETIME
1166          actual = etime( tarray )
1167          print *, tarray
1168          end
1169    EOF
1170    $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1
1171    RETVAL=$?
1172    if test "x$RETVAL" = x0 ; then
1173        HAVE_ETIME=t
1174        DEFINES="$DEFINES -DHAVE_ETIME"
1175        echo "yes"
1176    else
1177        HAVE_ETIME=
1178        echo "no"
1179    fi
1180    rm -f genmake_tcomp*
1181    
1182    printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
1183    check_HAVE_CLOC
1184    if test "x$HAVE_CLOC" != x ; then
1185        echo "yes"
1186    else
1187        echo "no"
1188    fi
1189    rm -f genmake_t*
1190    
1191    printf "  Can we create NetCDF-enabled binaries...  "
1192    check_netcdf_libs
1193    if test "x$HAVE_NETCDF" != x ; then
1194        echo "yes"
1195    else
1196        echo "no"
1197    fi
1198    
1199    
1200  printf "\n===  Setting defaults  ===\n"  printf "\n===  Setting defaults  ===\n"
1201  echo -n "  Adding MODS directories:  "  printf "  Adding MODS directories:  "
1202  for d in $MODS ; do  for d in $MODS ; do
1203      if test ! -d $d ; then      if test ! -d $d ; then
1204          echo          echo
1205          echo "Error: MODS directory \"$d\" not found!"          echo "Error: MODS directory \"$d\" not found!"
1206          exit 1          exit 1
1207      else      else
1208          echo -n " $d"          printf " $d"
1209          SOURCEDIRS="$SOURCEDIRS $d"          SOURCEDIRS="$SOURCEDIRS $d"
1210          INCLUDEDIRS="$INCLUDEDIRS $d"          INCLUDEDIRS="$INCLUDEDIRS $d"
1211      fi      fi
# Line 446  if test "x${PLATFORM}" = x ; then Line 1219  if test "x${PLATFORM}" = x ; then
1219      PLATFORM=$p_PLATFORM      PLATFORM=$p_PLATFORM
1220  fi  fi
1221    
 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  
   
1222  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
1223      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then
1224          EXEDIR=../exe          EXEDIR=../exe
# Line 487  if test "x${TOOLSDIR}" = x ; then Line 1235  if test "x${TOOLSDIR}" = x ; then
1235      TOOLSDIR="$ROOTDIR/tools"      TOOLSDIR="$ROOTDIR/tools"
1236  fi  fi
1237  if test ! -d ${TOOLSDIR} ; then  if test ! -d ${TOOLSDIR} ; then
1238      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
1239      exit 1      exit 1
1240  fi  fi
1241    if test "x$S64" = x ; then
1242        S64='$(TOOLSDIR)/set64bitConst.sh'
1243    fi
1244    THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
1245    
1246  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1247    
# Line 498  EXECUTABLE=${EXECUTABLE:-mitgcmuv} Line 1250  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1250  #  they appear as regular source code  #  they appear as regular source code
1251  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
1252      echo "  Making source files in eesupp from templates"      echo "  Making source files in eesupp from templates"
1253      $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1      ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1
1254      RETVAL=$?      RETVAL=$?
1255      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
1256          rm -f make_eesupp.errors          rm -f make_eesupp.errors
1257      else      else
1258          echo "Error: problem encountered while building source files in eesupp:"          echo "Error: problem encountered while building source files in eesupp:"
1259          cat make_eesupp.errors          cat make_eesupp.errors 1>&2
1260          exit 1          exit 1
1261      fi      fi
1262  fi  fi
1263    
1264    #same for exch2
1265    if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then
1266        echo "  Making source files in exch2 from  templates"
1267        ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1
1268        RETVAL=$?
1269        if test "x${RETVAL}" = x0 ; then
1270            rm -f make_exch2.errors
1271        else
1272            echo "Error: problem encountered while building source files in exch2:"
1273            cat make_exch2.errors 1>&2
1274            exit 1
1275        fi
1276    fi
1277    
1278  printf "\n===  Determining package settings  ===\n"  printf "\n===  Determining package settings  ===\n"
1279  if  test "x${PDEPEND}" = x ; then  if  test "x${PDEPEND}" = x ; then
1280      tmp=$ROOTDIR"/pkg/pkg_depend"      tmp=$ROOTDIR"/pkg/pkg_depend"
# Line 528  echo "  getting package dependency info Line 1294  echo "  getting package dependency info
1294  #  Strip the comments and then convert the dependency file into  #  Strip the comments and then convert the dependency file into
1295  #  two arrays: PNAME, DNAME  #  two arrays: PNAME, DNAME
1296  cat $PDEPEND | sed -e 's/#.*$//g' \  cat $PDEPEND | sed -e 's/#.*$//g' \
1297      | awk 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \      | $AWK 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \
1298      > ./.pd_tmp      > ./.pd_tmp
1299  RETVAL=$?  RETVAL=$?
1300  if test ! "x${RETVAL}" = x0 ; then  if test ! "x${RETVAL}" = x0 ; then
1301      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
1302      exit 1      exit 1
1303  fi  fi
1304  source ./.pd_tmp  . ./.pd_tmp
1305  rm -f ./.pd_tmp  rm -f ./.pd_tmp
1306    
1307  echo  -n "  checking default package list:  "  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"
1308    #  file should eventually be added so that, for convenience, one can
1309    #  specify groups of packages using names like "ocean" and "atmosphere".
1310    echo "  checking default package list:  "
1311    if test "x${PDEFAULT}" = x ; then
1312        for i in "." $MODS ; do
1313            if test -r $i"/packages.conf" ; then
1314                    PDEFAULT=$i"/packages.conf"
1315                    break
1316            fi
1317        done
1318    fi
1319  if test "x${PDEFAULT}" = x ; then  if test "x${PDEFAULT}" = x ; then
1320      PDEFAULT="$ROOTDIR/pkg/pkg_default"      PDEFAULT="$ROOTDIR/pkg/pkg_default"
1321  fi  fi
1322  if test "x${PDEFAULT}" = xNONE ; then  if test "x${PDEFAULT}" = xNONE ; then
1323      echo "default packages file disabled"      echo "    default packages file disabled"
1324  else  else
1325      if test ! -r $PDEFAULT ; then      if test ! -r $PDEFAULT ; then
         echo ""  
1326          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""
1327      else      else
1328          echo "  using PDEFAULT=\"$PDEFAULT\""          echo "    using PDEFAULT=\"$PDEFAULT\""
1329          #  Strip the comments and add all the names          #  Strip the comments and add all the names
1330          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | awk '(NF>0){print $0}'`          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
1331          RETVAL=$?          RETVAL=$?
1332          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
1333              echo -n "Error: can't parse default package list "              printf "Error: can't parse default package list "
1334              echo "-- please check PDEFAULT=\"$PDEFAULT\""              echo "-- please check PDEFAULT=\"$PDEFAULT\""
1335              exit 1              exit 1
1336          fi          fi
1337          for i in $def ; do          for i in $def ; do
1338              PACKAGES="$PACKAGES $i"              PACKAGES="$PACKAGES $i"
1339          done          done
1340          echo "    packages are:  $PACKAGES"          echo "    before group expansion packages are: $PACKAGES"
1341            while ! expand_pkg_groups; do echo > /dev/null; done
1342            echo "    after group expansion packages are:  $PACKAGES"
1343      fi      fi
1344  fi  fi
1345    
1346  echo "  applying DISABLE settings"  echo "  applying DISABLE settings"
1347    for i in $PACKAGES ; do
1348        echo $i >> ./.tmp_pack
1349    done
1350    for i in `grep  "-" ./.tmp_pack` ; do
1351        j=`echo $i | sed 's/[-]//'`
1352        DISABLE="$DISABLE $j"
1353    done
1354  pack=  pack=
1355  for p in $PACKAGES ; do  for p in $PACKAGES ; do
1356      addit="t"      addit="t"
# Line 580  for p in $PACKAGES ; do Line 1365  for p in $PACKAGES ; do
1365  done  done
1366  PACKAGES="$pack"  PACKAGES="$pack"
1367  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
1368  rm -f ./.tmp_pack  echo "" > ./.tmp_pack
1369  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
1370    # Test if each explicitly referenced package exists
1371  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1372      if test ! -d "$ROOTDIR/pkg/$i" ; then      j=`echo $i | sed 's/[-+]//'`
1373        if test ! -d "$ROOTDIR/pkg/$j" ; then
1374          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
1375          exit 1          exit 1
1376      fi      fi
1377      echo $i >> ./.tmp_pack      echo $i >> ./.tmp_pack
1378  done  done
 pack=`cat ./.tmp_pack | sort | uniq`  
 rm -f ./.tmp_pack  
1379  PACKAGES=  PACKAGES=
1380  for i in $pack ; do  for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do
1381      PACKAGES="$PACKAGES $i"      PACKAGES="$PACKAGES $i"
1382  done  done
1383    rm -f ./.tmp_pack
1384  echo "    packages are:  $PACKAGES"  echo "    packages are:  $PACKAGES"
1385    
1386  echo "  applying package dependency rules"  echo "  applying package dependency rules"
# Line 671  for i in $PACKAGES ; do Line 1457  for i in $PACKAGES ; do
1457      if test -d $adr ; then      if test -d $adr ; then
1458          SOURCEDIRS="$SOURCEDIRS $adr"          SOURCEDIRS="$SOURCEDIRS $adr"
1459          INCLUDEDIRS="$INCLUDEDIRS $adr"          INCLUDEDIRS="$INCLUDEDIRS $adr"
1460            if test "x$i" = xautodiff ; then
1461                AUTODIFF_PKG_USED=t
1462            fi
1463      else      else
1464          echo "Error: the directory \"$adr\" for package $i doesn't exist"          echo "Error: the directory \"$adr\" for package $i doesn't exist"
1465          exit 1          exit 1
1466      fi      fi
1467  done  done
1468    
1469  #  This is compatible with the old genmake.  The "DISABLE_*" flags  #  Build MNC templates and check for ability to build and use NetCDF
1470  #  need to be replaced by the "ALLOW_*" flags set below.  echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1
1471  #  RETVAL=$?
1472  # echo -n "  Setting package-specific CPP flags:  "  if test "x$RETVAL" = x0 ; then
1473  # pkrm=( mom_fluxform mom_vecinv generic_advdiff )      ( cd $ROOTDIR"/pkg/mnc" && $MAKE templates ) > make_mnc.errors 2>&1
1474  # pkrmdef=( -DDISABLE_MOM_FLUXFORM -DDISABLE_MOM_VECINV -DDISABLE_GENERIC_ADVDIFF -DDISABLE_DEBUGMODE )      RETVAL=$?
1475  # echo -n "  "      if test "x${RETVAL}" = x0 ; then
1476  # i=0          rm -f make_mnc.errors
1477  # while test $i -lt "${#pkrm[@]}" ; do      else
1478  #     echo "$PACKAGES" | grep "${pk[$i]}" > /dev/null 2>&1          echo "Error: problem encountered while building source files in pkg/mnc:"
1479  #     RETVAL=$?          cat make_mnc.errors 1>&2
1480  #     if test "x$RETVAL" = x1 ; then          exit 1
1481  #       DEFINES="$DEFINES ${pkdef[$i]}"      fi
1482  #       echo -n " ${pkdef[$i]}"      if test "x$HAVE_NETCDF" != xt ; then
1483  #     fi          cat <<EOF
 #     i=$(( $i + 1 ))  
 # done  
 # echo  
1484    
1485  echo "  Setting package-specific CPP flags in CPP_OPTIONS.h:"  WARNING: the "mnc" package has been enabled but tests failed to
1486  CPP_OPTIONS=    compile and/or execute NetCDF applications.  Please check that:
1487  spaths="$SOURCEDIRS"  
1488  for i in $spaths ; do    1) NetCDF is installed for your compiler and
1489      try="$i/CPP_OPTIONS.h"    2) the LIBS variable (within the 'optfile") specifies the correct
1490      #  echo -n "    trying $try : "         NetCDF library to link against.
1491      if test -f $try -a -r $try ; then    
1492          echo "    found CPP_OPTIONS=\"$try\""  EOF
         CPP_OPTIONS="$try"  
         if test "x$i" != "x." ; then  
             cp -f $CPP_OPTIONS .  
         fi  
         break  
1493      fi      fi
 done  
 if test "x$CPP_OPTIONS" = x ; then  
     echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"  
     exit 1  
1494  fi  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.  
1495    
1496  C  Packages disabled by genmake:  # Create a list of #define and #undef to enable/disable packages
1497  EOF  PACKAGES_DOT_H=PACKAGES_CONFIG.h
1498  #  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
1499  #  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
1500  #  file would eventually be split up so that all package-related #define  #  file would eventually be split up so that all package-related #define
1501  #  statements could be separated and handled only by genmake.  #  statements could be separated and handled only by genmake.
1502  names=`ls -1 "$ROOTDIR/pkg"`  names=`ls -1 "$ROOTDIR/pkg"`
1503  all_pack=  all_pack=
1504    DISABLED_PACKAGES=
1505  for n in $names ; do  for n in $names ; do
1506      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
1507          has_pack="f"          has_pack="f"
# Line 748  for n in $names ; do Line 1512  for n in $names ; do
1512              fi              fi
1513          done          done
1514          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
1515              undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`
1516              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!!!  
   
1517          fi          fi
1518      fi      fi
1519  done  done
1520  cat <<EOF >>CPP_OPTIONS.h.tmp  ENABLED_PACKAGES=
   
 C  Packages enabled by genmake:  
 EOF  
1521  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1522      def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`      def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`
1523      echo "#define $def" >> CPP_OPTIONS.h.tmp      ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
1524    #eh3 DEFINES="$DEFINES -D$def"
1525    
1526  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1527      case $i in      case $i in
1528          aim_v23)          aim_v23)
1529              echo "#define   ALLOW_AIM" >> CPP_OPTIONS.h.tmp              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
1530                echo "Warning: ALLOW_AIM is set to enable aim_v23."
1531              ;;              ;;
1532      esac      esac
1533  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1534    
1535  done  done
 mv -f CPP_OPTIONS.h.tmp CPP_OPTIONS.h  
1536    
1537  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS"
1538  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
1539  STANDARDDIRS=${STANDARDDIRS:-"eesupp model"}  if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
1540  for d in $STANDARDDIRS ; do      STANDARDDIRS="eesupp model"
1541      adr="$ROOTDIR/$d/src"  fi
1542      if test ! -d $adr ; then  if test "x$STANDARDDIRS" != x ; then
1543          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""      for d in $STANDARDDIRS ; do
1544          echo "  is correct and that you correctly specified the STANDARDDIRS option"          adr="$ROOTDIR/$d/src"
1545          exit 1          if test ! -d $adr ; then
1546      else              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1547          SOURCEDIRS="$SOURCEDIRS $adr"              echo "  is correct and that you correctly specified the STANDARDDIRS option"
1548      fi              exit 1
1549      adr="$ROOTDIR/$d/inc"          else
1550      if test ! -d $adr ; then              SOURCEDIRS="$SOURCEDIRS $adr"
1551          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""          fi
1552          echo "  is correct and that you correctly specified the STANDARDDIRS option"          adr="$ROOTDIR/$d/inc"
1553          exit 1          if test ! -d $adr ; then
1554      else              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1555          INCLUDEDIRS="$INCLUDEDIRS $adr"              echo "  is correct and that you correctly specified the STANDARDDIRS option"
1556                exit 1
1557            else
1558                INCLUDEDIRS="$INCLUDEDIRS $adr"
1559            fi
1560        done
1561    fi
1562    
1563    echo "  Searching for *OPTIONS.h files in order to warn about the presence"
1564    echo "    of \"#define \"-type statements that are no longer allowed:"
1565    CPP_OPTIONS=
1566    CPP_EEOPTIONS=
1567    spaths=". $INCLUDEDIRS"
1568    names=`ls -1 "$ROOTDIR/pkg"`
1569    for i in $spaths ; do
1570        try="$i/CPP_OPTIONS.h"
1571        if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
1572            echo "    found CPP_OPTIONS=\"$try\""
1573            CPP_OPTIONS="$try"
1574            # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
1575            for n in $names ; do
1576                test_for_package_in_cpp_options $CPP_OPTIONS $n
1577            done
1578        fi
1579        try="$i/CPP_EEOPTIONS.h"
1580        if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
1581            echo "    found CPP_EEOPTIONS=\"$try\""
1582            # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
1583    #**** not yet enabled ****
1584    #        test_for_mpi_in_cpp_eeoptions $try
1585    #**** not yet enabled ****
1586            CPP_EEOPTIONS="$try"
1587      fi      fi
1588  done  done
1589    if test "x$CPP_OPTIONS" = x ; then
1590        echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
1591        exit 1
1592    fi
1593    
1594    #  Here, we build the list of files to be "run through" the adjoint
1595    #  compiler.
1596    if test -f ./ad_files ; then
1597        rm -f ./ad_files
1598    fi
1599    echo "  Creating the list of files for the adjoint compiler."
1600    for i in $SOURCEDIRS ; do
1601        list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
1602        for j in $list_files ; do
1603            cat $i/$j >> ad_files
1604        done
1605    done
1606    
1607    
1608  echo  echo
1609  echo "===  Creating the Makefile  ==="  echo "===  Creating the Makefile  ==="
1610  echo "  setting INCLUDES"  echo "  setting INCLUDES"
1611  for i in $INCLUDEDIRS ; do  for i in $INCLUDEDIRS ; do
1612      if test -d $i ; then      if ! test -d $i ; then
1613          INCLUDES="$INCLUDES -I$i"  #       INCLUDES="$INCLUDES -I$i"
1614      else  #   else
1615          echo "Warning: can't find INCLUDEDIRS=\"$i\""          echo "Warning: can't find INCLUDEDIRS=\"$i\""
1616      fi      fi
1617  done  done
# Line 829  rm -rf .links.tmp Line 1621  rm -rf .links.tmp
1621  mkdir .links.tmp  mkdir .links.tmp
1622  echo "# This section creates symbolic links" > srclinks.tmp  echo "# This section creates symbolic links" > srclinks.tmp
1623  echo "" >> srclinks.tmp  echo "" >> srclinks.tmp
1624  echo -n 'SRCFILES = '    > srclist.inc  printf 'SRCFILES = '    > srclist.inc
1625  echo -n 'CSRCFILES = '   > csrclist.inc  printf 'CSRCFILES = '   > csrclist.inc
1626  echo -n 'F90SRCFILES = ' > f90srclist.inc  printf 'F90SRCFILES = ' > f90srclist.inc
1627  echo -n 'HEADERFILES = ' > hlist.inc  printf 'HEADERFILES = ' > hlist.inc
1628    printf 'AD_FLOW_FILES = ' > ad_flow_files.inc
1629  alldirs="$SOURCEDIRS $INCLUDEDIRS ."  alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1630  for d in $alldirs ; do  for d in $alldirs ; do
1631      deplist=      deplist=
1632      sfiles=`( cd $d; echo *.[h,c,F] )`      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
1633      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
1634      for sf in $sfiles ; do      for sf in $sfiles ; do
1635          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
1636              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
1637                  extn=`echo $sf | awk -F '.' '{print $NF}'`                  case $d/$sf in
1638                  touch .links.tmp/$sf                    ./$PACKAGES_DOT_H)
1639                  deplist="$deplist $sf"                          ;;
1640                      ./AD_CONFIG.h)
1641                            ;;
1642                      ./FC_NAMEMANGLE.h)
1643                            ;;
1644                      *)
1645                            touch .links.tmp/$sf
1646                            deplist="$deplist $sf"
1647                            ;;
1648                    esac
1649                    extn=`echo $sf | $AWK -F '.' '{print $NF}'`
1650                  case $extn in                  case $extn in
1651                      F)                      F)
1652                          echo    " \\"  >> srclist.inc                          echo    " \\"  >> srclist.inc
1653                          echo -n " $sf" >> srclist.inc                          printf " $sf" >> srclist.inc
1654                          ;;                          ;;
1655                      F90)                      F90)
1656                          echo    " \\"  >> f90srclist.inc                          echo    " \\"  >> f90srclist.inc
1657                          echo -n " $sf" >> f90srclist.inc                          printf " $sf" >> f90srclist.inc
1658                          ;;                          ;;
1659                      c)                      c)
1660                          echo    " \\"  >> csrclist.inc                          echo    " \\"  >> csrclist.inc
1661                          echo -n " $sf" >> csrclist.inc                          printf " $sf" >> csrclist.inc
1662                          ;;                          ;;
1663                      h)                      h)
1664                          echo    " \\"  >> hlist.inc                          echo    " \\"  >> hlist.inc
1665                          echo -n " $sf" >> hlist.inc                          printf " $sf" >> hlist.inc
1666                            ;;
1667                        flow)
1668                            echo    " \\"  >> ad_flow_files.inc
1669                            printf " $sf" >> ad_flow_files.inc
1670                          ;;                          ;;
1671                  esac                  esac
1672              fi              fi
# Line 877  echo "" >> srclist.inc Line 1684  echo "" >> srclist.inc
1684  echo "" >> csrclist.inc  echo "" >> csrclist.inc
1685  echo "" >> f90srclist.inc  echo "" >> f90srclist.inc
1686  echo "" >> hlist.inc  echo "" >> hlist.inc
1687    echo "" >> ad_flow_files.inc
1688    
1689  if test -e $MAKEFILE ; then  if test -e $MAKEFILE ; then
1690      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.bak"
# Line 887  echo "#    $MACHINE" >> $MAKEFILE Line 1695  echo "#    $MACHINE" >> $MAKEFILE
1695  echo "# This makefile was generated automatically on" >> $MAKEFILE  echo "# This makefile was generated automatically on" >> $MAKEFILE
1696  echo "#    $THISDATE" >> $MAKEFILE  echo "#    $THISDATE" >> $MAKEFILE
1697  echo "# by the command:" >> $MAKEFILE  echo "# by the command:" >> $MAKEFILE
1698  echo "#    $0 $@" >> $MAKEFILE  echo "#    $0 $G2ARGS" >> $MAKEFILE
1699  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
1700  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE
1701    
1702    EXE_AD=$EXECUTABLE"_ad"
1703    EXE_FTL=$EXECUTABLE"_ftl"
1704    EXE_SVD=$EXECUTABLE"_svd"
1705    
1706  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
1707    #
1708    # OPTFILE="$OPTFILE"
1709  #  #
1710  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
1711  # SOURCEDIRS   : Directories containing the source (.F) files  # SOURCEDIRS   : Directories containing the source (.F) files
# Line 918  EXEDIR      = ${EXEDIR} Line 1733  EXEDIR      = ${EXEDIR}
1733  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}
1734  TOOLSDIR    = ${TOOLSDIR}  TOOLSDIR    = ${TOOLSDIR}
1735    
1736    #eh3  new defines for the adjoint work
1737    AUTODIFF    = ${ROOTDIR}/pkg/autodiff
1738    EXE_AD      = ${EXE_AD}
1739    EXE_FTL     = ${EXE_FTL}
1740    EXE_SVD     = ${EXE_SVD}
1741    
1742    ENABLED_PACKAGES = ${ENABLED_PACKAGES}
1743    DISABLED_PACKAGES = ${DISABLED_PACKAGES}
1744    
1745    # These files are created by Makefile
1746    SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h
1747    
1748  EOF  EOF
1749    
1750  #  Note: figure out some way to add Hyades JAM libraries here  #  Note: figure out some way to add Hyades JAM libraries here
# Line 936  FC = ${FC} Line 1763  FC = ${FC}
1763  # Fortran compiler  # Fortran compiler
1764  F90C = ${F90C}  F90C = ${F90C}
1765  # Link editor  # Link editor
1766  LINK = ${LINK}  LINK = ${LINK} ${LDADD}
1767    
1768  # Defines for CPP  # Defines for CPP
1769  DEFINES = ${DEFINES}  DEFINES = ${DEFINES}
# Line 963  MAKEFILE=${MAKEFILE} Line 1790  MAKEFILE=${MAKEFILE}
1790    
1791  EOF  EOF
1792    
1793  cat srclist.inc    >> $MAKEFILE  cat srclist.inc       >> $MAKEFILE
1794  cat csrclist.inc   >> $MAKEFILE  cat csrclist.inc      >> $MAKEFILE
1795  cat f90srclist.inc >> $MAKEFILE  cat f90srclist.inc    >> $MAKEFILE
1796  cat hlist.inc      >> $MAKEFILE  cat hlist.inc         >> $MAKEFILE
1797  echo 'F77FILES =  $(SRCFILES:.F=.f)'                                           >> $MAKEFILE  cat ad_flow_files.inc >> $MAKEFILE
1798  echo 'F90FILES =  $(F90SRCFILES:.F90=.f90)'                                    >> $MAKEFILE  echo >> $MAKEFILE
1799    echo 'F77FILES =  $(SRCFILES:.F=.'$FS')'      >> $MAKEFILE
1800    echo 'F90FILES =  $(F90SRCFILES:.F=.'$FS90')' >> $MAKEFILE
1801  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
1802    echo >> $MAKEFILE
1803    echo '.SUFFIXES:' >> $MAKEFILE
1804    echo '.SUFFIXES: .o .'$FS' .p .F .c .'$FS90' .F90' >> $MAKEFILE
1805  rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc  rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc
1806    rm -f ad_flow_files.inc
1807    
1808  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
1809    
 .SUFFIXES:  
 .SUFFIXES: .o .f .p .F .c .F90 .f90  
   
1810  all: \$(EXECUTABLE)  all: \$(EXECUTABLE)
1811  \$(EXECUTABLE): \$(OBJFILES)  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(OBJFILES)
1812            @echo Creating \$@ ...
1813          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
1814  depend:  depend:
1815          @make links          @make links
1816          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
1817          ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE)          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
1818            -rm -f makedepend.out
1819    
1820  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES)
1821    
1822  small_f: \$(F77FILES) \$(F90FILES)  small_f: \$(F77FILES) \$(F90FILES)
1823    
# Line 995  output.txt: \$(EXECUTABLE) Line 1826  output.txt: \$(EXECUTABLE)
1826          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
1827    
1828  clean:  clean:
1829          -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}          -rm -rf *.o *.$FS *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
1830  Clean:  Clean:
1831          @make clean          @make clean
1832          @make cleanlinks          @make cleanlinks
1833          -rm -f Makefile.bak          -rm -f \$(SPECIAL_FILES)
1834            -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak
1835  CLEAN:  CLEAN:
1836          @make Clean          @make Clean
1837          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
1838          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
1839          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
1840          -rm -f \$(EXECUTABLE)          -rm -f \$(EXECUTABLE) output.txt STD*
1841    
1842    #eh3 Makefile: makefile
1843  makefile:  makefile:
1844          ${0} $@          $THIS_SCRIPT $G2ARGS
1845  cleanlinks:  cleanlinks:
1846          -find . -type l -exec rm {} \;          -find . -type l -exec rm {} \;
1847    
1848  # The normal chain of rules is (  .F - .f - .o  )  # Special targets ($SPECIAL_FILES) which are create by make
1849  .F.f:  ${PACKAGES_DOT_H}:
1850            @echo Creating \$@ ...
1851            @$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) > \$@
1852    AD_CONFIG.h:
1853            @echo Creating \$@ ...
1854            @$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 > \$@
1855    FC_NAMEMANGLE.h:
1856            @echo Creating \$@ ...
1857            echo "$FC_NAMEMANGLE" > \$@
1858    
1859    # The normal chain of rules is (  .F - .$FS - .o  )
1860    
1861    %.o : %.F
1862    
1863    .F.$FS:
1864          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1865  .f.o:  .$FS.o:
1866          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
1867  .F90.f90:  .F90.$FS90:
1868          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1869  .f90.o:  .$FS90.o:
1870          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
1871  .c.o:  .c.o:
1872          \$(CC) \$(CFLAGS) -c \$<          \$(CC) \$(CFLAGS) -c \$<
1873    
1874  # Special exceptions that use the ( .F - .p - .f - .o ) rule-chain  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
1875  .F.p:  .F.p:
1876          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1877  .p.f:  .p.$FS:
1878          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
1879    
1880    #=========================================
1881    #===  Automatic Differentiation Rules  ===
1882    
1883    TAMC           = ${TAMC}
1884    TAF            = ${TAF}
1885    
1886    TAF_EXTRA      = ${TAF_EXTRA}
1887    TAMC_EXTRA     = ${TAMC_EXTRA}
1888    
1889    EOF
1890    
1891    ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
1892    ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF_FLAGS"
1893    ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
1894    for i in $ad_vars ; do
1895        name=$i
1896        t1="t2=\$"`echo $i`
1897        eval $t1
1898        printf "%-20s = " $name >> $MAKEFILE
1899        echo $t2 >> $MAKEFILE
1900    done
1901    
1902    echo "  Add the source list for AD code generation"
1903    echo >> $MAKEFILE
1904    printf "AD_FILES = " >> $MAKEFILE
1905    AD_FILES=`cat ad_files`
1906    for i in $AD_FILES ; do
1907        echo    " \\" >> $MAKEFILE
1908        printf " $i" >> $MAKEFILE
1909    done
1910    echo >> $MAKEFILE
1911    rm -f ad_files
1912    
1913    cat >>$MAKEFILE <<EOF
1914    
1915    # ... AD ...
1916    adall: ad_taf
1917    adtaf: ad_taf_output.f
1918    adtamc: ad_tamc_output.f
1919    
1920    ad_input_code.f: \$(AD_FILES) \$(HEADERFILES)
1921            @$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
1922            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
1923            -rm -f ad_config.template
1924            @make \$(F77FILES)
1925            @make \$(AD_FLOW_FILES)
1926            cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f
1927    
1928    ad_taf_output.f: ad_input_code.f
1929            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1930            cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f
1931    
1932    adtafonly:
1933            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1934            cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f
1935    
1936    ad_taf: ad_taf_output.o \$(OBJFILES)
1937            \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
1938    
1939    ad_tamc_output.f: ad_input_code.f
1940            \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f
1941            cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.f
1942    
1943    ad_tamc: ad_tamc_output.o \$(OBJFILES)
1944            \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
1945    
1946    
1947    # ... FTL ...
1948    ftlall: ftl_taf
1949    ftltaf: ftl_taf_output.f
1950    ftltamc: ftl_tamc_output.f
1951    
1952    ftl_input_code.f: \$(AD_FILES) \$(HEADERFILES)
1953            @$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
1954            cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
1955            -rm -f ftl_config.template
1956            @make \$(F77FILES)
1957            @make \$(AD_FLOW_FILES)
1958            cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f
1959    
1960    ftl_taf_output.f: ftl_input_code.f
1961            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f
1962            cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f
1963    
1964    ftltafonly:
1965            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f
1966            cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f
1967    
1968    ftl_taf: ftl_taf_output.o \$(OBJFILES)
1969            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
1970    
1971    ftl_tamc_output.f: ftl_input_code.f
1972            \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f
1973            cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.f
1974    
1975    ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
1976            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
1977    
1978    
1979    # ... SVD ...
1980    svdtaf: ad_taf_output.f ftl_taf_output.f
1981    svdall: svd_taf
1982    
1983    svd_taf: ad_taf_output.o ftl_taf_output.o \$(OBJFILES)
1984            \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
1985    
1986    
1987    #=========================================
1988    
1989  EOF  EOF
1990    
1991  if test "x$EXEHOOK" != x ; then  if test "x$EXEHOOK" != x ; then
# Line 1043  for i in $KPPFILES ; do Line 1999  for i in $KPPFILES ; do
1999      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
2000          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
2001      fi      fi
2002      echo "$base.f: $base.p" >> $MAKEFILE      echo "$base.$FS: $base.p" >> $MAKEFILE
2003  done  done
2004    
2005  echo "  Making list of NOOPTFILES"  echo "  Making list of NOOPTFILES"
# Line 1053  for i in $NOOPTFILES ; do Line 2009  for i in $NOOPTFILES ; do
2009      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
2010          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
2011      fi      fi
2012      echo "$base.o: $base.f" >> $MAKEFILE      echo "$base.o: $base.$FS" >> $MAKEFILE
2013      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
2014  done  done
2015    
# Line 1066  printf "\n\n# DO NOT DELETE\n" >> $MAKEF Line 2022  printf "\n\n# DO NOT DELETE\n" >> $MAKEF
2022    
2023  printf "\n===  Done  ===\n"  printf "\n===  Done  ===\n"
2024    
2025    # Create special header files
2026    $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"
2027    if test ! -f $PACKAGES_DOT_H ; then
2028        mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2029    else
2030        cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
2031        RETVAL=$?
2032        if test "x$RETVAL" = x0 ; then
2033            rm -f $PACKAGES_DOT_H".tmp"
2034        else
2035            mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
2036            mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2037        fi
2038    fi
2039    if test ! -f AD_CONFIG.h ; then
2040        $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
2041    fi
2042    
2043    
2044  #  Write the "state" for future records  #  Write the "state" for future records
2045  if test "x$DUMPSTATE" != xf ; then  if test "x$DUMPSTATE" != xf ; then
2046      echo -n "" > gm_state      printf "" > genmake_state
2047      for i in $gm_state ; do      for i in $gm_state ; do
2048          t1="t2=\$$i"          t1="t2=\$$i"
2049          eval $t1          eval $t1
2050          echo "$i='$t2'" >> gm_state          echo "$i='$t2'" >> genmake_state
2051      done      done
2052  fi  fi

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.84

  ViewVC Help
Powered by ViewVC 1.1.22