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

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.80

  ViewVC Help
Powered by ViewVC 1.1.22