/[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.33 by adcroft, Thu Nov 13 15:10:40 2003 UTC revision 1.126 by ce107, Fri Aug 5 23:31:56 2005 UTC
# Line 1  Line 1 
1  #!/bin/bash  #! /usr/bin/env bash
2  #  #
3  # $Header$  # $Header$
4  #  #
# Line 13  Line 13 
13  test_for_package_in_cpp_options() {  test_for_package_in_cpp_options() {
14      cpp_options=$1      cpp_options=$1
15      pkg=$2      pkg=$2
16      grep -i "#define.*ALLOW_$pkg" $cpp_options > /dev/null 2>&1      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg" || exit 99
17      RETVAL=$?      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg" || exit 99
18      if test "x${RETVAL}" = x0 ; then      test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg" || exit 99
19          echo "Error: In $cpp_options there is an illegal line: #define ALLOW_$pkg"      test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg" || exit 99
20          exit 99  }
21      fi  
22      grep -i "#undef.*ALLOW_$pkg" $cpp_options > /dev/null 2>&1  # Search for particular CPP #cmds associated with MPI
23      RETVAL=$?  # usage: test_for_mpi_in_cpp_eeoptions CPP_file
24      if test "x${RETVAL}" = x0 ; then  test_for_mpi_in_cpp_eeoptions() {
25          echo "Error: In $cpp_options there is an illegal line: #undef ALLOW_$pkg"      cpp_options=$1
26          exit 99      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI" || exit 99
27      fi      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI" || exit 99
28      grep -i "#define.*DISABLE_$pkg" $cpp_options > /dev/null 2>&1      test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI" || exit 99
29        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI" || exit 99
30    }
31    
32    # Search for particular string in a file. Return 1 if detected, 0 if not
33    # usage: test_for_string_in_file file string
34    test_for_string_in_file() {
35        file=$1
36        strng=$2
37        grep -i "$strng" $file > /dev/null 2>&1
38      RETVAL=$?      RETVAL=$?
39      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
40          echo "Error: In $cpp_options there is an illegal line: #define DISABLE_$pkg"          printf "Error: In $file there is an illegal line: "
41          exit 99          grep -i "$strng" $file
42            return 1
43      fi      fi
44      grep -i "#undef.*DISABLE_$pkg" $cpp_options > /dev/null 2>&1      return 0
     RETVAL=$?  
     if test "x${RETVAL}" = x0 ; then  
         echo "Error: In $cpp_options there is an illegal line: #undef DISABLE_$pkg"  
         exit 99  
    fi  
45  }  }
46    
47  # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to  # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to
# Line 62  expand_pkg_groups() { Line 67  expand_pkg_groups() {
67          done          done
68          PACKAGES=$new_packages          PACKAGES=$new_packages
69          rm -f ./p[1,2].tmp          rm -f ./p[1,2].tmp
70            return $matched
71      else      else
72          echo "Warning: can't read package groups definition file: $PKG_GROUPS"          echo "Warning: can't read package groups definition file: $PKG_GROUPS"
73      fi      fi
74  }  }
75    
76    #  Check for broken environments (eg. cygwin, MacOSX w/HFS+) that
77    #  cannot distinguish [*.F/*.F90] from [*.f/*.f90] files.
78    check_for_broken_Ff()  {
79        #  Do we have defaults for $FS and/or $FS90 ?
80        tfs=f
81        tfs9=f90
82        if test "x$FS" != x ; then
83            tfs="$FS"
84        fi
85        if test "x$FS90" != x ; then
86            tfs9="$FS90"
87        fi
88    
89        #  First check the ability to create a *.F/.f pair.
90        cat <<EOF >> genmake_hello.F
91          program hello
92          write(*,*) 'hi'
93          stop
94          end
95    EOF
96        cp genmake_hello.F "genmake_hello."$tfs > /dev/null 2>&1
97        RETVAL=$?
98        if test "x$RETVAL" != x0 ; then
99            if test "x$FS" = x ; then
100                FS='for'
101                FS90='fr9'
102                check_for_broken_Ff
103            else
104                cat <<EOF 2>&1
105    ERROR: Your file system cannot distinguish between *.F and *.f files
106      (fails the "cp" test) and this program cannot find a suitable
107      replacement extension.  Please try a different build environment or
108      contact the <MITgcm-support@mitgcm.org> list for help.
109    
110    EOF
111                exit -1
112            fi
113            return
114        fi
115        rm -f genmake_hello.*
116    
117        #  Check the ability of ${MAKE} and ${LN} to use the current set
118        #  of extensions.
119        cat <<EOF >> genmake_hello.F
120          program hello
121          write(*,*) 'hi'
122          stop
123          end
124    EOF
125        test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
126        cat <<EOF >> $MAKEFILE
127    .SUFFIXES:
128    .SUFFIXES: .$tfs .F
129    .F.$tfs:
130            $LN \$< \$@
131    EOF
132        $MAKE "genmake_hello."$tfs > /dev/null 2>&1
133        RETVAL=$?
134        if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then
135            if test "x$FS" = x ; then
136                FS='for'
137                FS90='fr9'
138                check_for_broken_Ff
139            else
140                cat <<EOF 2>&1
141    ERROR: Your file system cannot distinguish between *.F and *.f files
142      (fails the "make/ln" test) and this program cannot find a suitable
143      replacement extension.  Please try a different build environment or
144      contact the <MITgcm-support@mitgcm.org> list for help.
145    
146    EOF
147                exit -1
148                return
149            fi
150        fi
151        rm -f genmake_hello.* $MAKEFILE
152        test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
153    
154        #  If we make it here, use the extensions
155        FS=$tfs
156        FS90=$tfs9
157        return
158    }
159    
160    
161    look_for_makedepend()  {
162    
163        #  The "original" makedepend is part of the Imake system that is
164        #  most often distributed with XFree86 or with an XFree86 source
165        #  package.  As a result, many machines (eg. generic Linux) do not
166        #  have a system-default "makedepend" available.  For those
167        #  systems, we have two fall-back options:
168        #
169        #    1) a makedepend implementation shipped with the cyrus-imapd
170        #       package:  ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
171        #
172        #    2) a known-buggy xmakedpend shell script
173        #
174        #  So the choices are, in order:
175        #
176        #    1) use the user-specified program
177        #    2) use a system-wide default
178        #    3) locally build and use the cyrus implementation
179        #    4) fall back to the buggy local xmakedpend script
180        #
181        if test "x${MAKEDEPEND}" = x ; then
182            which makedepend > /dev/null 2>&1
183            RV0=$?
184            test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
185            #  echo 'MAKEFILE="'$MAKEFILE'"'
186            cat <<EOF >> $MAKEFILE
187    #   THIS IS A TEST MAKEFILE GENERATED BY "genmake2"
188    #
189    #   Some "makedepend" implementations will die if they cannot
190    #   find a Makefile -- so this file is here to gives them an
191    #   empty one to find and parse.
192    EOF
193            cat <<EOF >> genmake_tc.f
194          program test
195          write(*,*) 'test'
196          stop
197          end
198    EOF
199            makedepend genmake_tc.f > /dev/null 2>&1
200            RV1=$?
201            test -f $MAKEFILE  &&  rm -f $MAKEFILE
202            test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
203            if test "x${RV0}${RV1}" = x00 ; then
204                MAKEDEPEND=makedepend
205            else
206                echo "    a system-default makedepend was not found."
207                
208                #  Try to build the cyrus implementation
209                build_cyrus_makedepend
210                RETVAL=$?
211                if test "x$RETVAL" != x0 ; then
212                    MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
213                fi
214                rm -f ./genmake_cy_md
215            fi
216        else
217            #  echo "MAKEDEPEND=${MAKEDEPEND}"
218            echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1
219            RETVAL=$?
220            if test x"$RETVAL" = x0 ; then
221                build_cyrus_makedepend
222            fi
223        fi
224    }
225    
226    
227    build_cyrus_makedepend()  {
228        rm -f ./genmake_cy_md
229        (
230            cd $ROOTDIR/tools/cyrus-imapd-makedepend  \
231                &&  ./configure > /dev/null 2>&1  \
232                &&  make > /dev/null 2>&1
233            if test -x ./makedepend.exe ; then
234                $LN ./makedepend.exe ./makedepend
235            fi
236            ./makedepend ifparser.c > /dev/null 2>&1  \
237                &&  echo "true"
238        ) > ./genmake_cy_md
239        grep true ./genmake_cy_md > /dev/null 2>&1
240        RETVAL=$?
241        rm -f ./genmake_cy_md
242        if test "x$RETVAL" = x0 ; then
243            MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
244            return 0
245        else
246            echo "WARNING: unable to build cyrus-imapd-makedepend"
247            return 1
248        fi
249    }
250    
251  # Guess possible config options for this host  # Guess possible config options for this host
252  find_possible_configs()  {  find_possible_configs()  {
253    
254      tmp1=`uname`"_"`uname -m`      tmp1=`uname`"_"`uname -m`
255      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
256      tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`      tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
257      PLATFORM=`echo $tmp3 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`      tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
258        tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
259        tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
260        PLATFORM=$tmp3
261        echo $PLATFORM | grep cygwin > /dev/null 2>&1  &&  PLATFORM=cygwin_ia32
262      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
263      echo "  The platform appears to be:  $PLATFORM"      echo "  The platform appears to be:  $PLATFORM"
 #     if test "x$OFLIST" = x ; then  
 #       echo "  No pre-defined options files were found matching this platform"  
 #       echo "  but examples for other platforms can be found in:"  
 #       echo "    $ROOTDIR/tools/build_options"  
 #     else  
 #       echo "  Options files (located in $ROOTDIR/tools/build_options) that"  
 #       echo "  may work with this machine are:"  
 #       for i in $OFLIST ; do  
 #           echo "    $i"  
 #       done  
 #     fi  
264            
265      echo "test" > test      echo "test" > test
266      ln -s ./test link      ln -s ./test link
# Line 104  find_possible_configs()  { Line 278  find_possible_configs()  {
278          CPP="cpp -traditional -P"          CPP="cpp -traditional -P"
279      fi      fi
280    
281      # makedepend is not always available      look_for_makedepend
282      if test "x${MAKEDEPEND}" = x ; then  
283        which makedepend >& /dev/null      #================================================================
284        RETVAL=$?      #  look for possible C compilers
285        if test "x${RETVAL}" = x1 ; then      tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc"
286           echo "    makedepend was not found. Using xmakedpend instead."      p_CC=
287           MAKEDEPEND='$(TOOLSDIR)/xmakedepend'      for c in $tmp ; do
288        fi          rm -f ./genmake_hello.c  ./genmake_hello
289            cat >> genmake_hello.c << EOF
290    #include <stdio.h>
291    int main(int argc, char **argv) {
292      printf("Hello!\n");
293      return 0;
294    }
295    EOF
296            $c -o genmake_hello genmake_hello.c > /dev/null 2>&1
297            RETVAL=$?
298            if test "x${RETVAL}" = x0 ; then
299                p_CC="$p_CC $c"
300            fi
301        done
302        rm -f ./genmake_hello.c ./genmake_hello
303        if test "x${p_CC}" = x ; then
304            cat 1>&2 <<EOF
305    
306    Error: No C compilers were found in your path.  Please specify one using:
307    
308        1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
309        2) the CC or MITGCM_CC environment variables.
310    
311    EOF
312            exit 1
313        else
314            echo "  The possible C compilers found in your path are:"
315            echo "   "$p_CC
316            if test "x$CC" = x ; then
317                CC=`echo $p_CC | $AWK '{print $1}'`
318                echo "  Setting C compiler to: "$CC
319            fi
320      fi      fi
321    
322      # look for possible fortran compilers      #================================================================
323      tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"      #  look for possible FORTRAN compilers
324        tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 gfortran"
325      p_FC=      p_FC=
326      for c in $tmp ; do      for c in $tmp ; do
327          rm -f ./hello.f ./hello          rm -f ./hello.f ./hello
# Line 140  Error: No Fortran compilers were found i Line 346  Error: No Fortran compilers were found i
346    
347      1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),      1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
348      2) a command-line option (eg. "-fc NAME"), or      2) a command-line option (eg. "-fc NAME"), or
349      3) the MITGCM_FC environment variable.      3) the FC or MITGCM_FC environment variables.
350    
351  EOF  EOF
352          exit 1          exit 1
# Line 149  EOF Line 355  EOF
355          echo "   "$p_FC          echo "   "$p_FC
356          if test "x$FC" = x ; then          if test "x$FC" = x ; then
357              FC=`echo $p_FC | $AWK '{print $1}'`              FC=`echo $p_FC | $AWK '{print $1}'`
358                echo "  Setting FORTRAN compiler to: "$FC
359          fi          fi
360      fi      fi
361    
362      for i in $p_FC ; do      if test "x$OPTFILE" = x ; then
363          p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i          OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
364          if test -r $p_OF ; then          if test ! -r $OPTFILE ; then
365              OPTFILE=$p_OF               echo "  I looked for the file "$OPTFILE" but did not find it"
366              echo "  The options file:  $p_OF"          fi
367              echo "    appears to match so we'll use it."      fi
368              break  #    echo "  The options file:  $p_OF"
369          fi  #    echo "    appears to match so we'll use it."
370      done  #   for i in $p_FC ; do
371    #p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
372    #if test -r $p_OF ; then
373    #    OPTFILE=$p_OF
374    #    echo "  The options file:  $p_OF"
375    #    echo "    appears to match so we'll use it."
376    #    break
377    #fi
378    #   done
379      if test "x$OPTFILE" = x ; then      if test "x$OPTFILE" = x ; then
380          cat 1>&2 <<EOF          cat 1>&2 <<EOF
381    
# Line 216  get_pdepend_list()  { Line 431  get_pdepend_list()  {
431      cat $1 | sed -e 's/#.*$//g' \      cat $1 | sed -e 's/#.*$//g' \
432          | $AWK 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \          | $AWK 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \
433          > ./.pd_tmp          > ./.pd_tmp
434      source ./.pd_tmp      . ./.pd_tmp
435      rm -f ./.pd_tmp      rm -f ./.pd_tmp
436    
437      echo -n "PNAME = "${}      printf "PNAME = "${}
438  }  }
439    
440    
441  #  Explain usage  #  Explain usage
442  usage()  {  usage()  {
443      echo  cat <<EOF
444      echo "Usage: "$0" [OPTIONS]"  
445      echo "  where [OPTIONS] can be:"  Usage: "$0" [OPTIONS]
446      echo    where [OPTIONS] can be:
447      echo "    -help | --help | -h | --h"  
448      echo "    -nooptfile | --nooptfile"      -help | --help | -h | --h
449      echo "      -optfile NAME | --optfile NAME | -of NAME | --of NAME"            Print this help message and exit.
450      echo "      -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME"  
451      echo "    -pdepend NAME | --pdepend NAME"      -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME
452      echo "      -pdepend=NAME | --pdepend=NAME"        -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME
453      echo "    -pdefault NAME | --pdefault NAME"            Use "NAME" as the adoptfile.  By default, the file at
454      echo "      -pdefault=NAME | --pdefault=NAME"            "tools/adjoint_options/adjoint_default" will be used.
455      echo "    -make NAME | -m NAME"  
456      echo "      --make=NAME | -m=NAME"      -nooptfile | --nooptfile
457      echo "    -makefile NAME | -mf NAME"        -optfile NAME | --optfile NAME | -of NAME | --of NAME
458      echo "      --makefile=NAME | -mf=NAME"        -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
459      echo "    -platform NAME | --platform NAME | -pl NAME | --pl NAME"            Use "NAME" as the optfile.  By default, an attempt will be
460      echo "      -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"            made to find an appropriate "standard" optfile in the
461      echo "    -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"            tools/build_options/ directory.
462      echo "      -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME"  
463      echo "    -mods NAME | --mods NAME | -mo NAME | --mo NAME"      -pdepend NAME | --pdepend NAME
464      echo "      -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME"        -pdepend=NAME | --pdepend=NAME
465      echo "    -disable NAME | --disable NAME"            Get package dependency information from "NAME".
466      echo "      -disable=NAME | --disable=NAME"  
467      echo "    -enable NAME | --enable NAME"      -pdefault NAME | --pdefault NAME
468      echo "      -enable=NAME | --enable=NAME"        -pdefault=NAME | --pdefault=NAME
469      echo "    -standarddirs NAME | --standarddirs NAME"            Get the default package list from "NAME".
470      echo "      -standarddirs=NAME | --standarddirs=NAME"  
471      echo "    -noopt NAME | --noopt NAME"      -make NAME | -m NAME
472      echo "      -noopt=NAME | --noopt=NAME"        --make=NAME | -m=NAME
473  #    echo "    -cpp NAME | --cpp NAME"            Use "NAME" for the MAKE program. The default is "make" but
474  #    echo "      -cpp=NAME | --cpp=NAME"            many platforms, "gmake" is the preferred choice.
475      echo "    -fortran NAME | --fortran NAME | -fc NAME | --fc NAME"  
476      echo "      -fc=NAME | --fc=NAME"      -makefile NAME | -mf NAME
477      echo "    -[no]ieee | --[no]ieee"        --makefile=NAME | -mf=NAME
478      echo "    -[no]mpi | --[no]mpi"            Call the makefile "NAME".  The default is "Makefile".
479      echo "    -[no]jam | --[no]jam"  
480      echo      -makedepend NAME | -md NAME
481      echo "  and NAME is a string such as:"        --makedepend=NAME | -md=NAME
482      echo            Use "NAME" for the MAKEDEPEND program.
483      echo "    --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'"  
484      echo "    -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'"      -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
485      echo "    -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"        -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
486      echo            Specify the location of the MITgcm ROOTDIR as "NAME".
487      echo "  which, depending upon your shell, may need to be single-quoted"            By default, genamke will try to find the location by
488      echo "  if it contains spaces, dashes, or other special characters."            looking in parent directories (up to the 5th parent).
489    
490        -mods NAME | --mods NAME | -mo NAME | --mo NAME
491          -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
492              Here, "NAME" specifies a list of directories that are
493              used for additional source code.  Files found in the
494              "mods list" are given preference over files of the same
495              name found elsewhere.
496    
497        -disable NAME | --disable NAME
498          -disable=NAME | --disable=NAME
499              Here "NAME" specifies a list of packages that we don't
500              want to use.  If this violates package dependencies,
501              genamke will exit with an error message.
502    
503        -enable NAME | --enable NAME
504          -enable=NAME | --enable=NAME
505              Here "NAME" specifies a list of packages that we wish
506              to specifically enable.  If this violates package
507              dependencies, genamke will exit with an error message.
508    
509        -standarddirs NAME | --standarddirs NAME
510          -standarddirs=NAME | --standarddirs=NAME
511              Here, "NAME" specifies a list of directories to be
512              used as the "standard" code.
513    
514        -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
515          -fc=NAME | --fc=NAME
516              Use "NAME" as the fortran compiler.  By default, genmake
517              will search for a working compiler by trying a list of
518              "usual suspects" such as g77, f77, etc.
519    
520        -cc NAME | --cc NAME | -cc=NAME | --cc=NAME
521              Use "NAME" as the C compiler.  By default, genmake
522              will search for a working compiler by trying a list of
523              "usual suspects" such as gcc, c89, cc, etc.
524    
525        -[no]ieee | --[no]ieee
526              Do or don't use IEEE numerics.  Note that this option
527              *only* works if it is supported by the OPTFILE that
528              is being used.
529    
530        -ts | --ts
531              Produce timing information per timestep
532    
533        -mpi | --mpi
534              Include MPI header files and link to MPI libraries
535        -mpi=PATH | --mpi=PATH
536              Include MPI header files and link to MPI libraries using MPI_ROOT
537              set to PATH. i.e. Include files from \$PATH/include, link to libraries
538              from \$PATH/lib and use binaries from \$PATH/bin.
539    
540        -bash NAME
541              Explicitly specify the Bourne or BASH shell to use
542    
543      While it is most often a single word, the "NAME" variables specified
544      above can in many cases be a space-delimited string such as:
545    
546        --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'
547        -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'
548        -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
549    
550      which, depending upon your shell, may need to be single-quoted.
551    
552      For more detailed genmake documentation, please see:
553    
554        http://mitgcm.org/devel_HOWTO/
555    
556    EOF
557    
558      exit 1      exit 1
559  }  }
560    
561  #  Build a CPP macro to automate calling C routines from FORTRAN  #  Build a CPP macro to automate calling C routines from FORTRAN
562  get_fortran_c_namemangling()  {  get_fortran_c_namemangling()  {
563    
564        #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
565        if test ! "x$FC_NAMEMANGLE" = x ; then
566            return 0
567        fi
568    
569      default_nm="#define FC_NAMEMANGLE(X) X ## _"      default_nm="#define FC_NAMEMANGLE(X) X ## _"
570            
571      cat > genmake_test.c <<EOF      cat > genmake_test.c <<EOF
572  void tcall( char * string ) { tsub( string ); }  void tcall( char * string ) { tsub( string ); }
573  EOF  EOF
574      $MAKE genmake_test.o > genmake_test.log 2>&1      $MAKE genmake_test.o >> genmake_warnings 2>&1
575      RETVAL=$?      RETVAL=$?
576      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
         cat genmake_test.log >> genmake_errors  
577          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
578          echo          cat <<EOF>> genmake_errors
579          echo "WARNING: C test compile fails -- please see \"genmake_errors\""  
580          echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"  WARNING: C test compile fails
581          echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
582    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
583    EOF
584          return 1          return 1
585      fi      fi
586      c_tcall=`nm genmake_test.o | grep tcall | cut -d ' ' -f 3`      c_tcall=`nm genmake_test.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
587      RETVAL=$?      RETVAL=$?
588      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
589          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
590          echo          cat <<EOF>> genmake_warnings
591          echo "WARNING: The \"nm\" command failed."  
592          echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"  WARNING: The "nm" command failed.
593          echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
594    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
595    EOF
596          return 1          return 1
597      fi      fi
598      cat > genmake_tcomp.f <<EOF      cat > genmake_tcomp.$FS <<EOF
599        subroutine tcall( string )        subroutine tcall( string )
600        character*(*) string        character*(*) string
601        call tsub( string )        call tsub( string )
602        end        end
603  EOF  EOF
604      $FC $FFLAGS $DEFINES -c genmake_tcomp.f > genmake_tcomp.log 2>&1      $FC $FFLAGS $DEFINES -c genmake_tcomp.$FS >> genmake_warnings 2>&1
605      RETVAL=$?      RETVAL=$?
606      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
         cat genmake_tcomp.log >> genmake_errors  
607          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
608          echo          cat <<EOF>> genmake_warnings
609          echo "WARNING: FORTRAN test compile fails -- please see \"genmake_errors\""  
610          echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"  WARNING: FORTRAN test compile fails -- please see "genmake_errors"
611          echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
612    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
613    EOF
614          return 1          return 1
615      fi      fi
616      f_tcall=`nm genmake_tcomp.o | grep tcall | cut -d ' ' -f 3`      f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
617      RETVAL=$?      RETVAL=$?
618      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
619          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
620          echo          cat <<EOF>> genmake_warnings
621          echo "WARNING: The \"nm\" command failed."  
622          echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"  WARNING: The "nm" command failed.
623          echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
624    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
625    EOF
626          return 1          return 1
627      fi      fi
628    
# Line 353  EOF Line 649  EOF
649      rm -f genmake_tcomp.* genmake_test.*      rm -f genmake_tcomp.* genmake_test.*
650  }  }
651    
652    
653    check_HAVE_CLOC()  {
654        get_fortran_c_namemangling
655        cat <<EOF > genmake_tc_1.c
656    $FC_NAMEMANGLE
657    #include <stdio.h>
658    #include <stdlib.h>
659    #include <unistd.h>
660    #include <assert.h>
661    #include <sys/time.h>
662    void FC_NAMEMANGLE(cloc) ( double *curtim )
663    {
664     struct timeval tv1;
665     gettimeofday(&tv1 , (void *)NULL );
666     *curtim =  (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
667     *curtim = *curtim/1.E6;
668    }
669    EOF
670        make genmake_tc_1.o >> genmake_warnings 2>&1
671        RET_C=$?
672        cat <<EOF > genmake_tc_2.$FS
673          program hello
674          Real*8 wtime
675          external cloc
676          call cloc(wtime)
677          print *," HELLO WORLD", wtime
678          end program hello
679    EOF
680        $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_warnings 2>&1
681        RET_F=$?
682        test -x ./genmake_tc  &&  ./genmake_tc >> genmake_warnings 2>&1
683        RETVAL=$?
684        if test "x$RETVAL" = x0 ; then
685            HAVE_CLOC=t
686            DEFINES="$DEFINES -DHAVE_CLOC"
687        fi
688        rm -f genmake_tc*
689    }
690    
691    
692    check_HAVE_STAT()  {
693        get_fortran_c_namemangling
694        cat <<EOF > genmake_tc_1.c
695    $FC_NAMEMANGLE
696    #include <stdio.h>
697    #include <stdlib.h>
698    #include <unistd.h>
699    #include <sys/stat.h>
700    #include <sys/types.h>
701    void FC_NAMEMANGLE(tfsize) ( int *nbyte )
702    {
703        char name[512];
704        struct stat astat;
705    
706        name[0] = 'a'; name[1] = '\0';
707        if (! stat(name, &astat))
708            *nbyte = (int)(astat.st_size);
709        else
710            *nbyte = -1;
711    }
712    EOF
713        make genmake_tc_1.o >> genmake_tc.log 2>&1
714        RET_C=$?
715        cat <<EOF > genmake_tc_2.$FS
716          program hello
717          integer nbyte
718          call tfsize(nbyte)
719          print *," HELLO WORLD", nbyte
720          end program hello
721    EOF
722        $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_tc.log 2>&1
723        RET_F=$?
724        test -x ./genmake_tc  &&  ./genmake_tc >> genmake_tc.log 2>&1
725        RETVAL=$?
726        if test "x$RETVAL" = x0 ; then
727            HAVE_STAT=t
728            DEFINES="$DEFINES -DHAVE_STAT"
729        fi
730        rm -f genmake_tc*
731    }
732    
733    
734    check_netcdf_libs()  {
735        if test ! "x$SKIP_NETCDF_CHECK" = x ; then
736            return
737        fi
738        echo "" > genmake_tnc.log
739        cat <<EOF > genmake_tnc.F
740          program fgennc
741    #include "netcdf.inc"
742    EOF
743        if test ! "x$MPI" = x ; then
744            echo '#include "mpif.h"' >> genmake_tnc.F
745        fi
746        cat <<EOF >> genmake_tnc.F
747          integer iret, ncid, xid
748          iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
749          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
750          iret = nf_def_dim(ncid, 'X', 11, xid)
751          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
752          iret = nf_close(ncid)
753          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
754          end
755    EOF
756        echo "Executing:" > genmake_tnc.log
757        echo "  $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS" \
758            > genmake_tnc.log
759        RET_CPP=f
760        $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null  \
761            &&  RET_CPP=t
762        if test "x$RET_CPP" = xf ; then
763            echo "  WARNING: CPP failed to pre-process the netcdf test." \
764                > genmake_tnc.log
765            echo "    Please check that \$INCLUDES is properly set." \
766                > genmake_tnc.log
767        fi
768        echo "Executing:" > genmake_tnc.log
769        echo "  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS" > genmake_tnc.log
770        echo "  $LINK -o genmake_tnc.o $LIBS" > genmake_tnc.log
771        $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
772            &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
773        RET_COMPILE=$?
774    
775        #EH3  Remove test program execution for machines that either disallow
776        #EH3  execution or cannot support it (eg. cross-compilers)
777        #EH3
778        #EH3 test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1
779        #EH3 RETVAL=$?
780        #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
781    
782        if test "x$RET_COMPILE" = x0 ; then
783            HAVE_NETCDF=t
784        else
785            # try again with "-lnetcdf" added to the libs
786            $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null  \
787                &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
788                &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
789            RET_COMPILE=$?
790            if test "x$RET_COMPILE" = x0 ; then
791                LIBS="$LIBS -lnetcdf"
792                HAVE_NETCDF=t
793            else
794                cat genmake_tnc.log >> genmake_warnings
795            fi
796        fi
797        rm -f genmake_tnc*
798    }
799    
800    
801    
802    ###############################################################################
803    #   Sequential part of script starts here
804    ###############################################################################
805    
806  #  Set defaults here  #  Set defaults here
807  COMMANDL="$0 $@"  COMMANDL="$0 $@"
808    
# Line 360  PLATFORM= Line 810  PLATFORM=
810  LN=  LN=
811  S64=  S64=
812  KPP=  KPP=
813  FC=  #FC=
814    #CC=gcc
815    #CPP=
816  LINK=  LINK=
 # DEFINES="-DWORDLENGTH=4"  
817  DEFINES=  DEFINES=
818  PACKAGES=  PACKAGES=
819  ENABLE=  ENABLE=
820  DISABLE=  DISABLE=
821  MAKEFILE=  # MAKEFILE=
822  MAKEDEPEND=  # MAKEDEPEND=
823  PDEPEND=  PDEPEND=
824  DUMPSTATE=t  DUMPSTATE=t
825  PDEFAULT=  PDEFAULT=
826  OPTFILE=  OPTFILE=
827  INCLUDES="-I."  INCLUDES="-I. $INCLUDES"
828  FFLAGS=  FFLAGS=
829  FOPTIM=  FOPTIM=
830  CFLAGS=  CFLAGS=
831  KFLAGS1=  KFLAGS1=
832  KFLAGS2=  KFLAGS2=
833    #LDADD=
834  LIBS=  LIBS=
835  KPPFILES=  KPPFILES=
836  NOOPTFILES=  NOOPTFILES=
837  NOOPTFLAGS=  NOOPTFLAGS=
838    MPI=
839    MPIPATH=
840    TS=
841    
842  # DEFINES checked by test compilation  # DEFINES checked by test compilation or command-line
843  HAVE_SYSTEM=  HAVE_SYSTEM=
844  HAVE_FDATE=  HAVE_FDATE=
845  FC_NAMEMANGLE=  FC_NAMEMANGLE=
846    HAVE_CLOC=
847    HAVE_STAT=
848    HAVE_NETCDF=
849    HAVE_ETIME=
850    IGNORE_TIME=
851    
852  MODS=  MODS=
853  TOOLSDIR=  TOOLSDIR=
854  SOURCEDIRS=  SOURCEDIRS=
855  INCLUDEDIRS=  INCLUDEDIRS=
856  STANDARDDIRS=  STANDARDDIRS="USE_THE_DEFAULT"
857    
858    G2ARGS=
859    BASH=
860  PWD=`pwd`  PWD=`pwd`
861  MAKE=make  test "x$MAKE" = x  &&  MAKE=make
862  AWK=awk  test "x$AWK" = x   &&  AWK=awk
863  THISHOSTNAME=`hostname`  THISHOST=`hostname`
864  THISCWD=`pwd`  THISCWD=`pwd`
865  THISDATE=`date`  THISDATE=`date`
866    THISUSER=`echo $USER`
867    THISVER=
868  MACHINE=`uname -a`  MACHINE=`uname -a`
869  EXECUTABLE=  EXECUTABLE=
870  EXEHOOK=  EXEHOOK=
# Line 410  IEEE= Line 874  IEEE=
874  if test "x$MITGCM_IEEE" != x ; then  if test "x$MITGCM_IEEE" != x ; then
875      IEEE=$MITGCM_IEEE      IEEE=$MITGCM_IEEE
876  fi  fi
877    FS=
878    FS90=
879    
880  AUTODIFF_PKG_USED=f  AUTODIFF_PKG_USED=f
881  AD_OPTFILE=  AD_OPTFILE=
# Line 426  TAMC_EXTRA= Line 892  TAMC_EXTRA=
892    
893    
894  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
895  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"
896  gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS"  gm_s2="FC CPP IEEE TS MPI JAM DUMPSTATE STANDARDDIRS"
897    
898  #  The following state is not directly set by command-line switches  #  The following state is not directly set by command-line switches
899  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 "
900  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
901  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE"
902  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
903  gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE"  gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME"
904    
905  #  The following are all related to adjoint/tangent-linear stuff  #  The following are all related to adjoint/tangent-linear stuff
906  gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"  gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
# Line 444  gm_s12="TAF_EXTRA TAMC_EXTRA" Line 910  gm_s12="TAF_EXTRA TAMC_EXTRA"
910  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"
911  gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"  gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
912    
913    cat <<EOF
914    
915    GENMAKE :
916    
917    A program for GENerating MAKEfiles for the MITgcm project.  For a
918    quick list of options, use "genmake -h" or for more detail see:
919    
920      http://mitgcm.org/devel_HOWTO/
921    
922    EOF
923    
 echo  
924  echo "===  Processing options files and arguments  ==="  echo "===  Processing options files and arguments  ==="
925  gm_local="genmake_local"  gm_local="genmake_local"
926  for i in . $MODS ; do  for i in . $MODS ; do
927      if test -r $i/$gm_local ; then      if test -r $i/$gm_local ; then
928          source $i/$gm_local          . $i/$gm_local
929          break          break
930      fi      fi
931  done  done
932  echo -n "  getting local config information:  "  printf "  getting local config information:  "
933  if test -e $gm_local ; then  if test -f $gm_local ; then
934      echo "using $gm_local"      echo "using $gm_local"
935      source $gm_local      . $gm_local
936      # echo "DISABLE=$DISABLE"      # echo "DISABLE=$DISABLE"
937      # echo "ENABLE=$ENABLE"      # echo "ENABLE=$ENABLE"
938  else  else
939      echo "none found"      echo "none found"
940  fi  fi
941    
942  #  echo "$0::$1:$2:$3:$4:$5:$6:$7:"  #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
943  #OPTIONS=  #OPTIONS=
944  #n=0  #n=0
945  #for i ; do  #for i ; do
# Line 476  fi Line 951  fi
951  #done  #done
952  #parse_options  #parse_options
953  ac_prev=  ac_prev=
954  for ac_option ; do  for ac_option in "$@" ; do
955    
956        G2ARGS="$G2ARGS \"$ac_option\""
957    
958      # If the previous option needs an argument, assign it.      # If the previous option needs an argument, assign it.
959      if test -n "$ac_prev"; then      if test -n "$ac_prev"; then
# Line 499  for ac_option ; do Line 976  for ac_option ; do
976          -optfile=* | --optfile=* | -of=* | --of=*)          -optfile=* | --optfile=* | -of=* | --of=*)
977              OPTFILE=$ac_optarg ;;              OPTFILE=$ac_optarg ;;
978                    
979          -adoptfile | --adoptfile | -ad | --ad)          -adoptfile | --adoptfile | -adof | --adof)
980              ac_prev=AD_OPTFILE ;;              ac_prev=AD_OPTFILE ;;
981          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
982              AD_OPTFILE=$ac_optarg ;;              AD_OPTFILE=$ac_optarg ;;
# Line 519  for ac_option ; do Line 996  for ac_option ; do
996          -make=* | --make=* | -m=* | --m=*)          -make=* | --make=* | -m=* | --m=*)
997              MAKE=$ac_optarg ;;              MAKE=$ac_optarg ;;
998                    
999            -bash | --bash)
1000                ac_prev=BASH ;;
1001            -bash=* | --bash=*)
1002                BASH=$ac_optarg ;;
1003            
1004            -makedepend | --makedepend | -md | --md)
1005                ac_prev=MAKEDEPEND ;;
1006            -makedepend=* | --makedepend=* | -md=* | --md=*)
1007                MAKEDEPEND=$ac_optarg ;;
1008            
1009          -makefile | --makefile | -ma | --ma)          -makefile | --makefile | -ma | --ma)
1010              ac_prev=MAKEFILE ;;              ac_prev=MAKEFILE ;;
1011          -makefile=* | --makefile=* | -ma=* | --ma=*)          -makefile=* | --makefile=* | -ma=* | --ma=*)
1012              MAKEFILE=$ac_optarg ;;              MAKEFILE=$ac_optarg ;;
1013                    
1014          -platform | --platform | -pl | --pl)          -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
1015              ac_prev=PLATFORM ;;              echo "ERROR: The platform option has been removed.  Please specify"
1016          -platform=* | --platform=* | -pl=* | --pl=*)              echo "  the build options using the \"optfile\" mechanism."
1017              PLATFORM=$ac_optarg ;;              echo
1018                usage
1019                ;;
1020                    
1021          -rootdir | --rootdir | -rd | --rd)          -rootdir | --rootdir | -rd | --rd)
1022              ac_prev=ROOTDIR ;;              ac_prev=ROOTDIR ;;
# Line 554  for ac_option ; do Line 1043  for ac_option ; do
1043          -standarddirs=* | --standarddirs=*)          -standarddirs=* | --standarddirs=*)
1044              STANDARDDIRS=$ac_optarg ;;              STANDARDDIRS=$ac_optarg ;;
1045    
         -noopt | --noopt)  
             ac_prev=NOOPT ;;  
         -noopt=* | --noopt=*)  
             NOOPT=$ac_optarg ;;  
           
1046  #           -cpp | --cpp)  #           -cpp | --cpp)
1047  #               ac_prev=cpp ;;  #               ac_prev=cpp ;;
1048  #           -cpp=* | --cpp=*)  #           -cpp=* | --cpp=*)
1049  #               CPP=$ac_optarg ;;  #               CPP=$ac_optarg ;;
1050                        
1051            -cc | --cc)
1052                ac_prev=CC ;;
1053            -cc=* | --cc=*)
1054                CC=$ac_optarg ;;
1055            
1056          -fortran | --fortran | -fc | --fc)          -fortran | --fortran | -fc | --fc)
1057              ac_prev=FC ;;              ac_prev=FC ;;
1058          -fc=* | --fc=*)          -fc=* | --fc=*)
1059              FC=$ac_optarg ;;              FC=$ac_optarg ;;
1060                    
1061            -fs | --fs)
1062                ac_prev=FS ;;
1063            -fs=* | --fs=*)
1064                FS=$ac_optarg ;;
1065            
1066            -fs90 | --fs90)
1067                ac_prev=FS90 ;;
1068            -fs90=* | --fs90=*)
1069                FS90=$ac_optarg ;;
1070            
1071          -ieee | --ieee)          -ieee | --ieee)
1072              IEEE=true ;;              IEEE=true ;;
1073          -noieee | --noieee)          -noieee | --noieee)
1074              IEEE= ;;              IEEE= ;;
1075            
1076            -ts | --ts)
1077                TS=true ;;
1078    
1079          -mpi | --mpi)          -mpi | --mpi)
1080              MPI=true ;;              MPI=true ;;
1081          -nompi | --nompi)          -mpi=* | --mpi=*)
1082              MPI= ;;              MPIPATH=$ac_optarg
1083                MPI=true ;;
1084                    
1085          -jam | --jam)  #       -jam | --jam)
1086              JAM=1 ;;  #           JAM=1 ;;
1087          -nojam | --nojam)  #       -nojam | --nojam)
1088              JAM=0 ;;  #           JAM=0 ;;
1089                    
1090          -ds | --ds)          -ds | --ds)
1091              DUMPSTATE=t ;;              DUMPSTATE=t ;;
# Line 596  for ac_option ; do Line 1099  for ac_option ; do
1099              ac_prev=TAMC_EXTRA ;;              ac_prev=TAMC_EXTRA ;;
1100          -tamc_extra=* | --tamc_extra=*)          -tamc_extra=* | --tamc_extra=*)
1101              TAMC_EXTRA=$ac_optarg ;;              TAMC_EXTRA=$ac_optarg ;;
1102            
1103            -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1104                IGNORE_TIME="-DIGNORE_TIME" ;;
1105    
1106          -*)          -*)
1107              echo "Error: unrecognized option: "$ac_option              echo "Error: unrecognized option: "$ac_option
# Line 611  for ac_option ; do Line 1117  for ac_option ; do
1117            
1118  done  done
1119    
1120    
1121  if test -f ./.genmakerc ; then  if test -f ./.genmakerc ; then
1122      echo      echo
1123      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
# Line 623  if test -f ./.genmakerc ; then Line 1130  if test -f ./.genmakerc ; then
1130      echo      echo
1131  fi  fi
1132    
1133    #  Find the MITgcm ${ROOTDIR}
1134  if test "x${ROOTDIR}" = x ; then  if test "x${ROOTDIR}" = x ; then
1135      if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1136        if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
1137          ROOTDIR=".."          ROOTDIR=".."
1138      else      else
1139          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1140              if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then              if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
1141                  ROOTDIR=$d                  ROOTDIR=$d
1142                  echo -n "Warning:  ROOTDIR was not specified but there appears to be"                  printf "Warning:  ROOTDIR was not specified but there appears to be"
1143                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
1144                  break                  break
1145              fi              fi
# Line 648  if test ! -d ${ROOTDIR} ; then Line 1157  if test ! -d ${ROOTDIR} ; then
1157      exit 1      exit 1
1158  fi  fi
1159    
1160    #  Find the MITgcm ${THISVER}
1161    if test -f "${ROOTDIR}/doc/tag-index" ; then
1162        THISVER=`grep '^checkpoint' ${ROOTDIR}/doc/tag-index | head -1`
1163    fi
1164    
1165    if test "x$MAKEFILE" = x ; then
1166        MAKEFILE="Makefile"
1167    fi
1168    
1169  echo "  getting OPTFILE information:  "  echo "  getting OPTFILE information:  "
1170  if test "x${OPTFILE}" = x ; then  if test "x${OPTFILE}" = x ; then
1171      if test "x$MITGCM_OF" = x ; then      if test "x$MITGCM_OF" = x ; then
# Line 661  fi Line 1179  fi
1179  if test "x$OPTFILE" != xNONE ; then  if test "x$OPTFILE" != xNONE ; then
1180      if test -f "$OPTFILE" -a -r "$OPTFILE" ; then      if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
1181          echo "    using OPTFILE=\"$OPTFILE\""          echo "    using OPTFILE=\"$OPTFILE\""
1182          source "$OPTFILE"          . "$OPTFILE"
1183          RETVAL=$?          RETVAL=$?
1184          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
1185              echo -n "Error: failed to source OPTFILE \"$OPTFILE\""              printf "Error: failed to source OPTFILE \"$OPTFILE\""
1186              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1187              exit 1              exit 1
1188          fi          fi
# Line 688  fi Line 1206  fi
1206  if test "x${AD_OPTFILE}" != xNONE ; then  if test "x${AD_OPTFILE}" != xNONE ; then
1207      if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then      if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
1208          echo "    using AD_OPTFILE=\"$AD_OPTFILE\""          echo "    using AD_OPTFILE=\"$AD_OPTFILE\""
1209          source "$AD_OPTFILE"          . "$AD_OPTFILE"
1210          RETVAL=$?          RETVAL=$?
1211          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
1212              echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""              printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
1213              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1214              exit 1              exit 1
1215          fi          fi
# Line 704  if test "x${AD_OPTFILE}" != xNONE ; then Line 1222  if test "x${AD_OPTFILE}" != xNONE ; then
1222      fi      fi
1223  fi  fi
1224    
1225  #  Check that FC, LINK, CPP, and S64 are defined.  If not, complain  #====================================================================
1226  #  and abort!  #  Set default values if not set by the optfile
1227    #
1228    #  Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
1229    #  either set defaults or complain and abort!
1230    if test ! "x$BASH" = x ; then
1231        # add a trailing space so that it works within the Makefile syntax (see below)
1232        BASH="$BASH "
1233    fi
1234  if test "x$FC" = x ; then  if test "x$FC" = x ; then
1235      cat <<EOF 1>&2      cat <<EOF 1>&2
1236    
# Line 716  Error: no Fortran compiler: please speci Line 1241  Error: no Fortran compiler: please speci
1241  EOF  EOF
1242      exit 1      exit 1
1243  fi  fi
1244    if test "x$CC" = x ; then
1245        CC=cc
1246    #     cat <<EOF 1>&2
1247    # Error: no C compiler: please specify using one of the following:
1248    #   1) within the options file ("CC=...") as specified by "-of=OPTFILE"
1249    #   2) the "-cc=XXX" command-line option
1250    #   3) the "./genmake_local" file
1251    # EOF
1252    #     exit 1
1253    fi
1254  if test "x$LINK" = x ; then  if test "x$LINK" = x ; then
1255      LINK=$FC      LINK=$FC
1256  fi  fi
1257    if test "x$MAKE" = x ; then
1258        MAKE="make"
1259    fi
1260  if test "x$CPP" = x ; then  if test "x$CPP" = x ; then
1261      CPP="cpp"      CPP=cpp
1262  fi  fi
1263    #EH3 === UGLY ===
1264    #  The following is an ugly little hack to check for $CPP in /lib/ and
1265    #  it should eventually be replaced with a more general function that
1266    #  searches a combo of the user's path and a list of "usual suspects"
1267    #  to find the correct location for binaries such as $CPP.
1268    for i in " " "/lib/" ; do
1269        echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1270    done
1271    #EH3 === UGLY ===
1272  echo "#define A a" | $CPP > test_cpp 2>&1  echo "#define A a" | $CPP > test_cpp 2>&1
1273  RETVAL=$?  RETVAL=$?
1274  if test "x$RETVAL" != x0 ; then  if test "x$RETVAL" != x0 ; then
# Line 738  EOF Line 1285  EOF
1285  else  else
1286      rm -f test_cpp      rm -f test_cpp
1287  fi  fi
1288  if test "x$MAKEDEPEND" = x ; then  look_for_makedepend
1289      MAKEDEPEND=makedepend  if test "x$LN" = x ; then
1290        LN="ln -s"
1291    fi
1292    echo "test" > genmake_test_ln
1293    $LN genmake_test_ln genmake_tlink
1294    RETVAL=$?
1295    if test "x$RETVAL" != x0 ; then
1296        cat <<EOF 1>&2
1297    
1298    Error: The command "ln -s" failed -- please specify a working soft-link
1299      command in the optfile.
1300    
1301    EOF
1302        exit 1
1303    fi
1304    rm -f genmake_test_ln genmake_tlink
1305    
1306    #  Check for broken *.F/*.f handling and fix if possible
1307    check_for_broken_Ff
1308    
1309    if test ! "x$MPI" = x ; then
1310          echo "  Turning on MPI cpp macros"
1311          DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
1312  fi  fi
1313    
1314    if test ! "x$TS" = x ; then
1315          echo "  Turning on timing per timestep"
1316          DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1317    fi
1318    
1319  printf "\n===  Checking system libraries  ===\n"  printf "\n===  Checking system libraries  ===\n"
1320  echo -n "  Do we have the system() command using $FC...  "  printf "  Do we have the system() command using $FC...  "
1321  cat > genmake_tcomp.f <<EOF  cat > genmake_tcomp.$FS <<EOF
1322        program hello        program hello
1323        call system('echo hi')        call system('echo hi')
1324        end        end
1325  EOF  EOF
1326  $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1  $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1327  RETVAL=$?  RETVAL=$?
1328  if test "x$RETVAL" = x0 ; then  if test "x$RETVAL" = x0 ; then
1329      HAVE_SYSTEM=t      HAVE_SYSTEM=t
# Line 762  else Line 1335  else
1335  fi  fi
1336  rm -f genmake_tcomp*  rm -f genmake_tcomp*
1337    
1338  echo -n "  Do we have the fdate() command using $FC...  "  printf "  Do we have the fdate() command using $FC...  "
1339  cat > genmake_tcomp.f <<EOF  cat > genmake_tcomp.$FS <<EOF
1340        program hello        program hello
1341        CHARACTER(128) string        CHARACTER(128) string
1342        string = ' '        string = ' '
# Line 771  cat > genmake_tcomp.f <<EOF Line 1344  cat > genmake_tcomp.f <<EOF
1344        print *, string        print *, string
1345        end        end
1346  EOF  EOF
1347  $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1  $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1348  RETVAL=$?  RETVAL=$?
1349  if test "x$RETVAL" = x0 ; then  if test "x$RETVAL" = x0 ; then
1350      HAVE_FDATE=t      HAVE_FDATE=t
# Line 783  else Line 1356  else
1356  fi  fi
1357  rm -f genmake_tcomp*  rm -f genmake_tcomp*
1358    
1359  echo "  The name mangling convention for $FC is...  "  printf "  Do we have the etime() command using $FC...  "
1360  #FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) X ## _"  cat > genmake_tcomp.$FS <<EOF
1361  if test "x$FC_NAMEMANGLE" = x ; then        program hello
1362      get_fortran_c_namemangling        REAL*4 ACTUAL, TARRAY(2)
1363  fi        EXTERNAL ETIME
1364  echo "    '$FC_NAMEMANGLE'"        REAL*4 ETIME
1365  echo "$FC_NAMEMANGLE" > FC_NAMEMANGLE.h.template        actual = etime( tarray )
1366  cmp FC_NAMEMANGLE.h FC_NAMEMANGLE.h.template > /dev/null 2>&1        print *, tarray
1367          end
1368    EOF
1369    $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1370  RETVAL=$?  RETVAL=$?
1371  if test "x$RETVAL" != x0 ; then  if test "x$RETVAL" = x0 ; then
1372      mv -f FC_NAMEMANGLE.h.template FC_NAMEMANGLE.h      HAVE_ETIME=t
1373        DEFINES="$DEFINES -DHAVE_ETIME"
1374        echo "yes"
1375    else
1376        HAVE_ETIME=
1377        echo "no"
1378    fi
1379    rm -f genmake_tcomp*
1380    
1381    printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
1382    check_HAVE_CLOC
1383    if test "x$HAVE_CLOC" != x ; then
1384        echo "yes"
1385    else
1386        echo "no"
1387  fi  fi
1388    rm -f genmake_t*
1389    
1390    printf "  Can we use stat() through C calls...  "
1391    check_HAVE_STAT
1392    if test "x$HAVE_STAT" != x ; then
1393        echo "yes"
1394    else
1395        echo "no"
1396    fi
1397    rm -f genmake_t*
1398    
1399    printf "  Can we create NetCDF-enabled binaries...  "
1400    check_netcdf_libs
1401    if test "x$HAVE_NETCDF" != x ; then
1402        echo "yes"
1403    else
1404        echo "no"
1405    fi
1406    DEFINES="$DEFINES $IGNORE_TIME"
1407    
1408  printf "\n===  Setting defaults  ===\n"  printf "\n===  Setting defaults  ===\n"
1409  echo -n "  Adding MODS directories:  "  printf "  Adding MODS directories:  "
1410  for d in $MODS ; do  for d in $MODS ; do
1411      if test ! -d $d ; then      if test ! -d $d ; then
1412          echo          echo
1413          echo "Error: MODS directory \"$d\" not found!"          echo "Error: MODS directory \"$d\" not found!"
1414          exit 1          exit 1
1415      else      else
1416          echo -n " $d"          printf " $d"
1417          SOURCEDIRS="$SOURCEDIRS $d"          SOURCEDIRS="$SOURCEDIRS $d"
1418          INCLUDEDIRS="$INCLUDEDIRS $d"          INCLUDEDIRS="$INCLUDEDIRS $d"
1419      fi      fi
1420  done  done
1421  echo  echo
1422    
 if test "x$MAKEFILE" = x ; then  
     MAKEFILE="Makefile"  
 fi  
1423  if test "x${PLATFORM}" = x ; then  if test "x${PLATFORM}" = x ; then
1424      PLATFORM=$p_PLATFORM      PLATFORM=$p_PLATFORM
1425  fi  fi
1426    
1427  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
1428      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1429        if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
1430          EXEDIR=../exe          EXEDIR=../exe
1431      else      else
1432          EXEDIR=.          EXEDIR=.
# Line 835  if test "x${TOOLSDIR}" = x ; then Line 1441  if test "x${TOOLSDIR}" = x ; then
1441      TOOLSDIR="$ROOTDIR/tools"      TOOLSDIR="$ROOTDIR/tools"
1442  fi  fi
1443  if test ! -d ${TOOLSDIR} ; then  if test ! -d ${TOOLSDIR} ; then
1444      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
1445      exit 1      exit 1
1446  fi  fi
1447  if test "x$S64" = x ; then  if test "x$S64" = x ; then
1448      S64='$(TOOLSDIR)/set64bitConst.sh'      echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1
1449        RETVAL=$?
1450        if test "x${RETVAL}" = x0 ; then
1451            S64='$(TOOLSDIR)/set64bitConst.sh'
1452        else
1453            echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1
1454            RETVAL=$?
1455            if test "x${RETVAL}" = x0 ; then
1456                S64='$(TOOLSDIR)/set64bitConst.csh'
1457            else
1458                cat <<EOF
1459    
1460    ERROR: neither of the two default scripts:
1461    
1462        ${TOOLSDIR}/set64bitConst.sh
1463        ${TOOLSDIR}/set64bitConst.csh
1464    
1465      are working so please check paths or specify (with \$S64) a
1466      working version of this script.
1467    
1468    EOF
1469                exit 1
1470            fi
1471        fi
1472  fi  fi
1473    THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
1474    
1475  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1476    
# Line 849  EXECUTABLE=${EXECUTABLE:-mitgcmuv} Line 1479  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1479  #  they appear as regular source code  #  they appear as regular source code
1480  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
1481      echo "  Making source files in eesupp from templates"      echo "  Making source files in eesupp from templates"
1482      $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1      ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1
1483      RETVAL=$?      RETVAL=$?
1484      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
1485          rm -f make_eesupp.errors          rm -f make_eesupp.errors
1486      else      else
1487          echo "Error: problem encountered while building source files in eesupp:"          echo "Error: problem encountered while building source files in eesupp:"
1488          cat make_eesupp.errors          cat make_eesupp.errors 1>&2
1489          exit 1          exit 1
1490      fi      fi
1491  fi  fi
1492    
1493    #same for exch2
1494    if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then
1495        echo "  Making source files in exch2 from  templates"
1496        ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1
1497        RETVAL=$?
1498        if test "x${RETVAL}" = x0 ; then
1499            rm -f make_exch2.errors
1500        else
1501            echo "Error: problem encountered while building source files in exch2:"
1502            cat make_exch2.errors 1>&2
1503            exit 1
1504        fi
1505    fi
1506    
1507  printf "\n===  Determining package settings  ===\n"  printf "\n===  Determining package settings  ===\n"
1508  if  test "x${PDEPEND}" = x ; then  if  test "x${PDEPEND}" = x ; then
1509      tmp=$ROOTDIR"/pkg/pkg_depend"      tmp=$ROOTDIR"/pkg/pkg_depend"
# Line 886  if test ! "x${RETVAL}" = x0 ; then Line 1530  if test ! "x${RETVAL}" = x0 ; then
1530      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
1531      exit 1      exit 1
1532  fi  fi
1533  source ./.pd_tmp  . ./.pd_tmp
1534  rm -f ./.pd_tmp  rm -f ./.pd_tmp
1535    
1536  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"
1537  #  file should eventually be added so that, for convenience, one can  #  file should eventually be added so that, for convenience, one can
1538  #  specify groups of packages using names like "ocean" and "atmosphere".  #  specify groups of packages using names like "ocean" and "atmosphere".
1539  echo  -n "  checking default package list:  "  echo "  checking default package list:  "
1540  if test "x${PDEFAULT}" = x ; then  if test "x${PDEFAULT}" = x ; then
1541      for i in "." $MODS ; do      for i in "." $MODS ; do
1542          if test -r $i"/packages.conf" ; then          if test -r $i"/packages.conf" ; then
# Line 905  if test "x${PDEFAULT}" = x ; then Line 1549  if test "x${PDEFAULT}" = x ; then
1549      PDEFAULT="$ROOTDIR/pkg/pkg_default"      PDEFAULT="$ROOTDIR/pkg/pkg_default"
1550  fi  fi
1551  if test "x${PDEFAULT}" = xNONE ; then  if test "x${PDEFAULT}" = xNONE ; then
1552      echo "default packages file disabled"      echo "    default packages file disabled"
1553  else  else
1554      if test ! -r $PDEFAULT ; then      if test ! -r $PDEFAULT ; then
         echo ""  
1555          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""
1556      else      else
1557          echo "  using PDEFAULT=\"$PDEFAULT\""          echo "    using PDEFAULT=\"$PDEFAULT\""
1558          #  Strip the comments and add all the names          #  Strip the comments and add all the names
1559          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
1560          RETVAL=$?          RETVAL=$?
1561          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
1562              echo -n "Error: can't parse default package list "              printf "Error: can't parse default package list "
1563              echo "-- please check PDEFAULT=\"$PDEFAULT\""              echo "-- please check PDEFAULT=\"$PDEFAULT\""
1564              exit 1              exit 1
1565          fi          fi
# Line 924  else Line 1567  else
1567              PACKAGES="$PACKAGES $i"              PACKAGES="$PACKAGES $i"
1568          done          done
1569          echo "    before group expansion packages are: $PACKAGES"          echo "    before group expansion packages are: $PACKAGES"
1570          expand_pkg_groups          RET=1
1571            while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
1572          echo "    after group expansion packages are:  $PACKAGES"          echo "    after group expansion packages are:  $PACKAGES"
1573      fi      fi
1574  fi  fi
1575    
1576  echo "  applying DISABLE settings"  echo "  applying DISABLE settings"
1577    for i in $PACKAGES ; do
1578        echo $i >> ./.tmp_pack
1579    done
1580    for i in `grep  "-" ./.tmp_pack` ; do
1581        j=`echo $i | sed 's/[-]//'`
1582        DISABLE="$DISABLE $j"
1583    done
1584  pack=  pack=
1585  for p in $PACKAGES ; do  for p in $PACKAGES ; do
1586      addit="t"      addit="t"
# Line 946  PACKAGES="$pack" Line 1597  PACKAGES="$pack"
1597  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
1598  echo "" > ./.tmp_pack  echo "" > ./.tmp_pack
1599  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
1600    # Test if each explicitly referenced package exists
1601  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1602      if test ! -d "$ROOTDIR/pkg/$i" ; then      j=`echo $i | sed 's/[-+]//'`
1603        if test ! -d "$ROOTDIR/pkg/$j" ; then
1604          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
1605          exit 1          exit 1
1606      fi      fi
1607      echo $i >> ./.tmp_pack      echo $i >> ./.tmp_pack
1608  done  done
 pack=`cat ./.tmp_pack | sort | uniq`  
 rm -f ./.tmp_pack  
1609  PACKAGES=  PACKAGES=
1610  for i in $pack ; do  for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do
1611      PACKAGES="$PACKAGES $i"      PACKAGES="$PACKAGES $i"
1612  done  done
1613    rm -f ./.tmp_pack
1614  echo "    packages are:  $PACKAGES"  echo "    packages are:  $PACKAGES"
1615    
1616    #  Check availability of NetCDF and then either build the MNC template
1617    #  files or delete mnc from the list of available packages.
1618    echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1
1619    RETVAL=$?
1620    if test "x$RETVAL" = x0 ; then
1621        if test "x$HAVE_NETCDF" != xt ; then
1622            cat <<EOF
1623    
1624    *********************************************************************
1625    WARNING: the "mnc" package was enabled but tests failed to compile
1626      NetCDF applications.  Please check that:
1627    
1628      1) NetCDF is correctly installed for this compiler and
1629      2) the LIBS variable (within the "optfile") specifies the correct
1630           NetCDF library to link against.
1631    
1632      Due to this failure, the "mnc" package is now DISABLED.
1633    *********************************************************************
1634    
1635    EOF
1636            PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
1637            DISABLE="$DISABLE mnc"
1638        else
1639            ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
1640            RETVAL=$?
1641            if test "x${RETVAL}" = x0 ; then
1642                rm -f make_mnc.errors
1643            else
1644                echo "Error: problem encountered while building source files in pkg/mnc:"
1645                cat make_mnc.errors 1>&2
1646                exit 1
1647            fi
1648        fi
1649    fi
1650    
1651  echo "  applying package dependency rules"  echo "  applying package dependency rules"
1652  ck=  ck=
1653  while test "x$ck" != xtt ; do  while test "x$ck" != xtt ; do
# Line 1025  while test "x$ck" != xtt ; do Line 1712  while test "x$ck" != xtt ; do
1712              echo "  the dependency rules for \"$dname\""              echo "  the dependency rules for \"$dname\""
1713              exit 1              exit 1
1714          fi          fi
1715          i=$(( $i + 1 ))          i=`echo "$i + 1" | bc -l`
1716            #i=$(( $i + 1 ))
1717      done      done
1718      ck=$ck"t"      ck=$ck"t"
1719  done  done
# Line 1044  for i in $PACKAGES ; do Line 1732  for i in $PACKAGES ; do
1732      fi      fi
1733  done  done
1734    
   
1735  # Create a list of #define and #undef to enable/disable packages  # Create a list of #define and #undef to enable/disable packages
1736  PACKAGES_DOT_H=PACKAGES_CONFIG.h  PACKAGES_DOT_H=PACKAGES_CONFIG.h
 cat <<EOF >$PACKAGES_DOT_H".tmp"  
 C=== GENMAKE v2 ===  
 C  The following defines have been set by GENMAKE, so please do not  
 C  edit anything below these comments.  In general, you should  
 C  add or remove packages by re-running genmake with different  
 C  "-enable" and/or "-disable" options.  
   
 #ifndef PACKAGES_H  
 #define PACKAGES_H  
   
 C  Packages disabled by genmake:  
 EOF  
1737  #  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
1738  #  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
1739  #  file would eventually be split up so that all package-related #define  #  file would eventually be split up so that all package-related #define
1740  #  statements could be separated and handled only by genmake.  #  statements could be separated and handled only by genmake.
1741  names=`ls -1 "$ROOTDIR/pkg"`  names=`ls -1 "$ROOTDIR/pkg"`
1742  all_pack=  all_pack=
1743    DISABLED_PACKAGES=
1744  for n in $names ; do  for n in $names ; do
1745      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
1746          has_pack="f"          has_pack="f"
# Line 1075  for n in $names ; do Line 1751  for n in $names ; do
1751              fi              fi
1752          done          done
1753          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
1754              undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1755              echo "#undef $undef" >> $PACKAGES_DOT_H".tmp"              DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
1756          fi          fi
1757      fi      fi
1758  done  done
1759  cat <<EOF >>$PACKAGES_DOT_H".tmp"  ENABLED_PACKAGES=
   
 C  Packages enabled by genmake:  
 EOF  
1760  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1761      def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`      def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1762      echo "#define $def" >> $PACKAGES_DOT_H".tmp"      ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
1763  #eh3 DEFINES="$DEFINES -D$def"  #eh3 DEFINES="$DEFINES -D$def"
1764    
1765  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1766      case $i in      case $i in
1767          aim_v23)          aim_v23)
1768              echo "#define   ALLOW_AIM" >> $PACKAGES_DOT_H".tmp"              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
1769              DEFINES="$DEFINES -DALLOW_AIM"              echo "Warning: ALLOW_AIM is set to enable aim_v23."
             echo "Warning: ALLOW_AIM is set to enable aim_v23. This is REALLY ugly Jean-Michel :-)"  
1770              ;;              ;;
1771      esac      esac
1772  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1773    
1774  done  done
 cat <<EOF >>$PACKAGES_DOT_H".tmp"  
   
 #endif /* PACKAGES_H */  
 EOF  
   
 if test ! -f $PACKAGES_DOT_H ; then  
     mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H  
 else  
     cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H  
     RETVAL=$?  
     if test "x$RETVAL" = x0 ; then  
         rm -f $PACKAGES_DOT_H".tmp"  
     else  
         mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"  
         mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H  
     fi  
 fi  
1775    
1776  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS"
1777  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
1778  if test "x$STANDARDDIRS" = x ; then  if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
1779      STANDARDDIRS="eesupp model"      STANDARDDIRS="eesupp model"
1780  fi  fi
1781  for d in $STANDARDDIRS ; do  if test "x$STANDARDDIRS" != x ; then
1782      adr="$ROOTDIR/$d/src"      for d in $STANDARDDIRS ; do
1783      if test ! -d $adr ; then          adr="$ROOTDIR/$d/src"
1784          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""          if test ! -d $adr ; then
1785          echo "  is correct and that you correctly specified the STANDARDDIRS option"              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1786          exit 1              echo "  is correct and that you correctly specified the STANDARDDIRS option"
1787      else              exit 1
1788          SOURCEDIRS="$SOURCEDIRS $adr"          else
1789      fi              SOURCEDIRS="$SOURCEDIRS $adr"
1790      adr="$ROOTDIR/$d/inc"          fi
1791      if test ! -d $adr ; then          adr="$ROOTDIR/$d/inc"
1792          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""          if test ! -d $adr ; then
1793          echo "  is correct and that you correctly specified the STANDARDDIRS option"              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1794          exit 1              echo "  is correct and that you correctly specified the STANDARDDIRS option"
1795      else              exit 1
1796          INCLUDEDIRS="$INCLUDEDIRS $adr"          else
1797      fi              INCLUDEDIRS="$INCLUDEDIRS $adr"
1798  done          fi
1799        done
1800    fi
1801    
1802  echo "  Searching for CPP_OPTIONS.h in order to warn about the presence"  echo "  Searching for *OPTIONS.h files in order to warn about the presence"
1803  echo "    of \"#define ALLOW_PKGNAME\"-type statements:"  echo "    of \"#define \"-type statements that are no longer allowed:"
1804  CPP_OPTIONS=  CPP_OPTIONS=
1805    CPP_EEOPTIONS=
1806  spaths=". $INCLUDEDIRS"  spaths=". $INCLUDEDIRS"
1807    names=`ls -1 "$ROOTDIR/pkg"`
1808  for i in $spaths ; do  for i in $spaths ; do
1809      try="$i/CPP_OPTIONS.h"      try="$i/CPP_OPTIONS.h"
1810      #  echo -n "    trying $try : "      if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
     if test -f $try -a -r $try ; then  
1811          echo "    found CPP_OPTIONS=\"$try\""          echo "    found CPP_OPTIONS=\"$try\""
1812          CPP_OPTIONS="$try"          CPP_OPTIONS="$try"
1813          break          # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
1814            for n in $names ; do
1815                test_for_package_in_cpp_options $CPP_OPTIONS $n
1816            done
1817        fi
1818        try="$i/CPP_EEOPTIONS.h"
1819        if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
1820            echo "    found CPP_EEOPTIONS=\"$try\""
1821            # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
1822    #**** not yet enabled ****
1823    #        test_for_mpi_in_cpp_eeoptions $try
1824    #**** not yet enabled ****
1825            CPP_EEOPTIONS="$try"
1826      fi      fi
1827  done  done
1828  if test "x$CPP_OPTIONS" = x ; then  if test "x$CPP_OPTIONS" = x ; then
1829      echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"      echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
1830      exit 1      exit 1
1831  fi  fi
 # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h  
 names=`ls -1 "$ROOTDIR/pkg"`  
 for n in $names ; do  
     test_for_package_in_cpp_options $CPP_OPTIONS $n  
 done  
   
1832    
1833  #  Here, we build the list of files to be "run through" the adjoint  #  Here, we build the list of files to be "run through" the adjoint
1834  #  compiler.  #  compiler.
# Line 1178  for i in $SOURCEDIRS ; do Line 1842  for i in $SOURCEDIRS ; do
1842          cat $i/$j >> ad_files          cat $i/$j >> ad_files
1843      done      done
1844  done  done
1845    if test ! "x"$FS = "x.f" ; then
1846  cat <<EOF > adjoint_sed      cat ad_files | sed -e "s/\.f/.$FS/g" > ad_files_f
1847  s/call adopen(/call adopen ( mythid,\\      mv -f ad_files_f ad_files
1848       \&           /g  fi
 s/call adclose(/call adclose( mythid,\\  
      \&           /g  
 s/call adread(/call adread ( mythid,\\  
      \&           /g  
 s/call adwrite(/call adwrite( mythid,\\  
      \&           /g  
   
 EOF  
1849    
1850  echo  echo
1851  echo "===  Creating the Makefile  ==="  echo "===  Creating the Makefile  ==="
1852  echo "  setting INCLUDES"  echo "  setting INCLUDES"
1853  for i in $INCLUDEDIRS ; do  for i in $INCLUDEDIRS ; do
1854      if ! test -d $i ; then      if test ! -d $i ; then
 #       INCLUDES="$INCLUDES -I$i"  
 #   else  
1855          echo "Warning: can't find INCLUDEDIRS=\"$i\""          echo "Warning: can't find INCLUDEDIRS=\"$i\""
1856      fi      fi
1857  done  done
# Line 1207  rm -rf .links.tmp Line 1861  rm -rf .links.tmp
1861  mkdir .links.tmp  mkdir .links.tmp
1862  echo "# This section creates symbolic links" > srclinks.tmp  echo "# This section creates symbolic links" > srclinks.tmp
1863  echo "" >> srclinks.tmp  echo "" >> srclinks.tmp
1864  echo -n 'SRCFILES = '    > srclist.inc  printf 'SRCFILES = '    > srclist.inc
1865  echo -n 'CSRCFILES = '   > csrclist.inc  printf 'CSRCFILES = '   > csrclist.inc
1866  echo -n 'F90SRCFILES = ' > f90srclist.inc  printf 'F90SRCFILES = ' > f90srclist.inc
1867  echo -n 'HEADERFILES = ' > hlist.inc  printf 'HEADERFILES = ' > hlist.inc
1868  echo -n 'AD_FLOW_FILES = ' > ad_flow_files.inc  printf 'AD_FLOW_FILES = ' > ad_flow_files.inc
1869  alldirs="$SOURCEDIRS $INCLUDEDIRS ."  alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1870  for d in $alldirs ; do  for d in $alldirs ; do
1871      deplist=      deplist=
# Line 1220  for d in $alldirs ; do Line 1874  for d in $alldirs ; do
1874      for sf in $sfiles ; do      for sf in $sfiles ; do
1875          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
1876              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
1877                  extn=`echo $sf | $AWK -F '.' '{print $NF}'`                  case $d/$sf in
1878                  touch .links.tmp/$sf                    ./$PACKAGES_DOT_H)
1879                  deplist="$deplist $sf"                          ;;
1880                      ./AD_CONFIG.h)
1881                            ;;
1882                      ./FC_NAMEMANGLE.h)
1883                            ;;
1884                      ./BUILD_INFO.h)
1885                            ;;
1886                      *)
1887                            touch .links.tmp/$sf
1888                            deplist="$deplist $sf"
1889                            ;;
1890                    esac
1891                    extn=`echo $sf | $AWK -F. '{print $NF}'`
1892                  case $extn in                  case $extn in
1893                      F)                      F)
1894                          echo    " \\"  >> srclist.inc                          echo    " \\"  >> srclist.inc
1895                          echo -n " $sf" >> srclist.inc                          printf " $sf" >> srclist.inc
1896                          ;;                          ;;
1897                      F90)                      F90)
1898                          echo    " \\"  >> f90srclist.inc                          echo    " \\"  >> f90srclist.inc
1899                          echo -n " $sf" >> f90srclist.inc                          printf " $sf" >> f90srclist.inc
1900                          ;;                          ;;
1901                      c)                      c)
1902                          echo    " \\"  >> csrclist.inc                          echo    " \\"  >> csrclist.inc
1903                          echo -n " $sf" >> csrclist.inc                          printf " $sf" >> csrclist.inc
1904                          ;;                          ;;
1905                      h)                      h)
1906                          echo    " \\"  >> hlist.inc                          echo    " \\"  >> hlist.inc
1907                          echo -n " $sf" >> hlist.inc                          printf " $sf" >> hlist.inc
1908                          ;;                          ;;
1909                      flow)                      flow)
1910                          echo    " \\"  >> ad_flow_files.inc                          echo    " \\"  >> ad_flow_files.inc
1911                          echo -n " $sf" >> ad_flow_files.inc                          printf " $sf" >> ad_flow_files.inc
1912                          ;;                          ;;
1913                  esac                  esac
1914              fi              fi
# Line 1262  echo "" >> f90srclist.inc Line 1928  echo "" >> f90srclist.inc
1928  echo "" >> hlist.inc  echo "" >> hlist.inc
1929  echo "" >> ad_flow_files.inc  echo "" >> ad_flow_files.inc
1930    
1931  if test -e $MAKEFILE ; then  if test -f $MAKEFILE ; then
1932      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.bak"
1933  fi  fi
1934  echo "  Writing makefile: $MAKEFILE"  echo "  Writing makefile: $MAKEFILE"
# Line 1271  echo "#    $MACHINE" >> $MAKEFILE Line 1937  echo "#    $MACHINE" >> $MAKEFILE
1937  echo "# This makefile was generated automatically on" >> $MAKEFILE  echo "# This makefile was generated automatically on" >> $MAKEFILE
1938  echo "#    $THISDATE" >> $MAKEFILE  echo "#    $THISDATE" >> $MAKEFILE
1939  echo "# by the command:" >> $MAKEFILE  echo "# by the command:" >> $MAKEFILE
1940  echo "#    $0 $@" >> $MAKEFILE  echo "#    $0 $G2ARGS" >> $MAKEFILE
1941  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
1942  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE  echo "#    ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
1943    
1944  EXE_AD=$EXECUTABLE"_ad"  EXE_AD=$EXECUTABLE"_ad"
1945  EXE_FTL=$EXECUTABLE"_ftl"  EXE_FTL=$EXECUTABLE"_ftl"
1946  EXE_SVD=$EXECUTABLE"_svd"  EXE_SVD=$EXECUTABLE"_svd"
1947    
1948  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
1949    #
1950    # OPTFILE="$OPTFILE"
1951  #  #
1952  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
1953  # SOURCEDIRS   : Directories containing the source (.F) files  # SOURCEDIRS   : Directories containing the source (.F) files
# Line 1313  EXE_AD      = ${EXE_AD} Line 1981  EXE_AD      = ${EXE_AD}
1981  EXE_FTL     = ${EXE_FTL}  EXE_FTL     = ${EXE_FTL}
1982  EXE_SVD     = ${EXE_SVD}  EXE_SVD     = ${EXE_SVD}
1983    
1984    ENABLED_PACKAGES = ${ENABLED_PACKAGES}
1985    DISABLED_PACKAGES = ${DISABLED_PACKAGES}
1986    
1987    # These files are created by Makefile
1988    SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h
1989    
1990  EOF  EOF
1991    
1992  #  Note: figure out some way to add Hyades JAM libraries here  #  Note: figure out some way to add Hyades JAM libraries here
# Line 1330  KPP = ${KPP} Line 2004  KPP = ${KPP}
2004  FC = ${FC}  FC = ${FC}
2005  # Fortran compiler  # Fortran compiler
2006  F90C = ${F90C}  F90C = ${F90C}
2007    # C compiler
2008    CC = ${CC}
2009  # Link editor  # Link editor
2010  LINK = ${LINK}  LINK = ${LINK} ${LDADD}
2011    
2012  # Defines for CPP  # Defines for CPP
2013  DEFINES = ${DEFINES}  DEFINES = ${DEFINES}
# Line 1352  CFLAGS = ${CFLAGS} Line 2028  CFLAGS = ${CFLAGS}
2028  NOOPTFILES = ${NOOPTFILES}  NOOPTFILES = ${NOOPTFILES}
2029  NOOPTFLAGS = ${NOOPTFLAGS}  NOOPTFLAGS = ${NOOPTFLAGS}
2030  # Flags and libraries needed for linking  # Flags and libraries needed for linking
2031  LIBS = ${LIBS} \$(XLIBS)  LIBS = ${LIBS}
2032  # Name of the Mekfile  # Name of the Mekfile
2033  MAKEFILE=${MAKEFILE}  MAKEFILE=${MAKEFILE}
2034    
# Line 1363  cat csrclist.inc      >> $MAKEFILE Line 2039  cat csrclist.inc      >> $MAKEFILE
2039  cat f90srclist.inc    >> $MAKEFILE  cat f90srclist.inc    >> $MAKEFILE
2040  cat hlist.inc         >> $MAKEFILE  cat hlist.inc         >> $MAKEFILE
2041  cat ad_flow_files.inc >> $MAKEFILE  cat ad_flow_files.inc >> $MAKEFILE
2042  echo               >> $MAKEFILE  echo >> $MAKEFILE
2043  echo 'F77FILES =  $(SRCFILES:.F=.f)'                                           >> $MAKEFILE  echo 'F77FILES =  $(SRCFILES:.F=.'$FS')'      >> $MAKEFILE
2044  echo 'F90FILES =  $(F90SRCFILES:.F90=.f90)'                                    >> $MAKEFILE  echo 'F90FILES =  $(F90SRCFILES:.F=.'$FS90')' >> $MAKEFILE
2045  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
2046    echo >> $MAKEFILE
2047    echo '.SUFFIXES:' >> $MAKEFILE
2048    echo '.SUFFIXES: .o .'$FS' .p .F .c .'$FS90' .F90' >> $MAKEFILE
2049  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
2050  rm -f ad_flow_files.inc  rm -f ad_flow_files.inc
2051    
2052  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2053    
 .SUFFIXES:  
 .SUFFIXES: .o .f .p .F .c .F90 .f90  
   
2054  all: \$(EXECUTABLE)  all: \$(EXECUTABLE)
2055  \$(EXECUTABLE): \$(OBJFILES)  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(OBJFILES)
2056            @echo Creating \$@ ...
2057          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
2058  depend:  depend:
2059          @make links          @make links
2060          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
2061          ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE)          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2062            -rm -f makedepend.out
2063    
2064  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES)
2065    
2066  small_f: \$(F77FILES) \$(F90FILES)  small_f: \$(F77FILES) \$(F90FILES)
2067    
# Line 1393  output.txt: \$(EXECUTABLE) Line 2070  output.txt: \$(EXECUTABLE)
2070          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
2071    
2072  clean:  clean:
2073          -cat AD_CONFIG.template > AD_CONFIG.h          -rm -rf *.o *.$FS *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
         -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}  
2074  Clean:  Clean:
2075          @make clean          @make clean
2076          @make cleanlinks          @make cleanlinks
2077          -rm -f Makefile.bak genmake_state genmake_*optfile make.log          -rm -f \$(SPECIAL_FILES)
2078            -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak
2079  CLEAN:  CLEAN:
2080          @make Clean          @make Clean
2081          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
2082          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
2083          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
2084          -rm -f \$(EXECUTABLE) output.txt          -rm -f \$(EXECUTABLE) output.txt STD*
2085    
2086  #eh3 Makefile: makefile  #eh3 Makefile: makefile
2087  makefile:  makefile:
2088          ${0} $@          $THIS_SCRIPT $G2ARGS
2089  cleanlinks:  cleanlinks:
2090          -find . -type l -exec rm {} \;          -find . -type l -exec rm {} \;
2091    
2092  # The normal chain of rules is (  .F - .f - .o  )  # Special targets (SPECIAL_FILES) which are create by make
2093  .F.f:  ${PACKAGES_DOT_H}:
2094            @echo Creating \$@ ...
2095            @$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) > \$@
2096    AD_CONFIG.h:
2097            @echo Creating \$@ ...
2098            @$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 > \$@
2099    FC_NAMEMANGLE.h:
2100            @echo Creating \$@ ...
2101            echo "$FC_NAMEMANGLE" > \$@
2102    
2103    BUILD_INFO.h:
2104            @echo Creating \$@ ...
2105    EOF
2106    
2107    test ! "x$THISVER" = x  && echo "       -echo \"#define THISVER '$THISVER'\" > \$@"   >> $MAKEFILE
2108    test ! "x$THISUSER" = x && echo "       -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE
2109    test ! "x$THISDATE" = x && echo "       -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
2110    test ! "x$THISHOST" = x && echo "       -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
2111    
2112    cat >>$MAKEFILE <<EOF
2113    
2114    # The normal chain of rules is (  .F - .$FS - .o  )
2115    
2116    ## This nullifies any default implicit rules concerning these two file types:
2117    ## %.o : %.F
2118    
2119    .F.$FS:
2120          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2121  .f.o:  .$FS.o:
2122          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2123  .F90.f90:  .F90.$FS90:
2124          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2125  .f90.o:  .$FS90.o:
2126          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
2127  .c.o:  .c.o:
2128          \$(CC) \$(CFLAGS) -c \$<          \$(CC) \$(CFLAGS) -c \$<
2129    
2130  # Special exceptions that use the ( .F - .p - .f - .o ) rule-chain  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
2131  .F.p:  .F.p:
2132          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2133  .p.f:  .p.$FS:
2134          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
2135    
2136  #=========================================  #=========================================
# Line 1454  done Line 2157  done
2157    
2158  echo "  Add the source list for AD code generation"  echo "  Add the source list for AD code generation"
2159  echo >> $MAKEFILE  echo >> $MAKEFILE
2160  echo -n "AD_FILES = " >> $MAKEFILE  printf "AD_FILES = " >> $MAKEFILE
2161  AD_FILES=`cat ad_files`  AD_FILES=`cat ad_files`
2162  for i in $AD_FILES ; do  for i in $AD_FILES ; do
2163      echo    " \\" >> $MAKEFILE      echo    " \\" >> $MAKEFILE
2164      echo -n " $i" >> $MAKEFILE      printf " $i" >> $MAKEFILE
2165  done  done
2166  echo >> $MAKEFILE  echo >> $MAKEFILE
2167  rm -f ad_files  rm -f ad_files
# Line 1467  cat >>$MAKEFILE <<EOF Line 2170  cat >>$MAKEFILE <<EOF
2170    
2171  # ... AD ...  # ... AD ...
2172  adall: ad_taf  adall: ad_taf
2173  adtaf: ad_taf_output.f  adtaf: ad_taf_output.$FS
2174  adtamc: ad_tamc_output.f  adtamc: ad_tamc_output.$FS
2175    
2176  ad_input_code.f: \$(AD_FILES) \$(HEADERFILES)  ad_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)
2177            @$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
2178          cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h          cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
2179            -rm -f ad_config.template
2180          @make \$(F77FILES)          @make \$(F77FILES)
2181          @make \$(AD_FLOW_FILES)          @make \$(AD_FLOW_FILES)
2182          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.$FS
2183    
2184  ad_taf_output.f: ad_input_code.f  ad_taf_output.$FS: ad_input_code.$FS
2185          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2186          cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
2187    
2188    adtafonly:
2189            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2190            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
2191    
2192  ad_taf: ad_taf_output.o \$(OBJFILES)  ad_taf: ad_taf_output.o \$(OBJFILES)
2193          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
2194    
2195  ad_tamc_output.f: ad_input_code.f  ad_tamc_output.$FS: ad_input_code.$FS
2196          \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f          \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
2197          cat ad_input_code_ad.f | sed -f adjoint_sed > ad_tamc_output.f          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS
2198    
2199  ad_tamc: ad_tamc_output.o \$(OBJFILES)  ad_tamc: ad_tamc_output.o \$(OBJFILES)
2200          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
2201    
2202    adonlyfwd:
2203            patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
2204    
2205    adtrick:
2206            patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
2207    
2208  # ... FTL ...  # ... FTL ...
2209  ftlall: ftl_taf  ftlall: ftl_taf
2210  ftltaf: ftl_taf_output.f  ftltaf: ftl_taf_output.$FS
2211  ftltamc: ftl_tamc_output.f  ftltamc: ftl_tamc_output.$FS
2212    
2213  ftl_input_code.f: \$(AD_FILES) \$(HEADERFILES)  ftl_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)
2214            @$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
2215          cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h          cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
2216            -rm -f ftl_config.template
2217          @make \$(F77FILES)          @make \$(F77FILES)
2218          @make \$(AD_FLOW_FILES)          @make \$(AD_FLOW_FILES)
2219          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.$FS
2220    
2221  ftl_taf_output.f: ftl_input_code.f  ftl_taf_output.$FS: ftl_input_code.$FS
2222          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2223          cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_taf_output.f          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2224    
2225    ftltafonly:
2226            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2227            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2228    
2229  ftl_taf: ftl_taf_output.o \$(OBJFILES)  ftl_taf: ftl_taf_output.o \$(OBJFILES)
2230          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
2231    
2232  ftl_tamc_output.f: ftl_input_code.f  ftl_tamc_output.$FS: ftl_input_code.$FS
2233          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
2234          cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_tamc_output.f          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS
2235    
2236  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
2237          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
2238    
2239    
2240  # ... SVD ...  # ... SVD ...
2241  svd: svd_taf  svdtaf: ad_taf_output.$FS ftl_taf_output.$FS
2242  svd_taf_f: svd_taf_output.f          @echo "--->>> Only ran TAF to generate SVD code!    <<<---"
2243            @echo "--->>> Do make svdall afterwards to compile. <<<---"
2244  svd_input_code.f: \$(SRCFILES)  svdall: svd_touch svd_taf
2245          cmp svd_config.template AD_CONFIG.h || cat svd_config.template > AD_CONFIG.h  
2246          @make \$(F77FILES)  svd_taf: \$(OBJFILES)
2247          @make \$(AD_FLOW_FILES)          \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
2248          cat \$(AD_FLOW_FILES) \$(AD_FILES) > svd_input_code.f  
2249            @echo "--->>> Only COMPILE svd code! <<<---"
2250  svd_taf_output.f: svd_input_code.f          @echo "--->>> Assumes you previously <<<---"
2251          \$(TAF) \$(SVD_TAF_FLAGS) \$(TAF_EXTRA) svd_input_code.f          @echo "--->>> did make svdtaf        <<<---"
2252          cat svd_input_code_ad.f | sed -f adjoint_sed > svd_taf_output.f  
2253    svd_touch:
2254  svd_taf: svd_taf_output.o \$(OBJFILES)          @echo "--->>> Only COMPILE svd code! <<<---"
2255          \$(LINK) -o ${EXE_SVD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) svd_taf_output.o \$(LIBS)          @echo "--->>> Assumes you previously <<<---"
2256            @echo "--->>> did make svdtaf        <<<---"
2257            touch ad_taf_output.$FS ftl_taf_output.$FS
2258            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS
2259            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS
2260            @$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
2261            cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
2262            -rm -f ftl_config.template
2263    
2264  #=========================================  #=========================================
2265    
# Line 1550  for i in $KPPFILES ; do Line 2276  for i in $KPPFILES ; do
2276      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
2277          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
2278      fi      fi
2279      echo "$base.f: $base.p" >> $MAKEFILE      echo "$base.$FS: $base.p" >> $MAKEFILE
2280  done  done
2281    
2282  echo "  Making list of NOOPTFILES"  echo "  Making list of NOOPTFILES"
# Line 1560  for i in $NOOPTFILES ; do Line 2286  for i in $NOOPTFILES ; do
2286      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
2287          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
2288      fi      fi
2289      echo "$base.o: $base.f" >> $MAKEFILE      echo "$base.o: $base.$FS" >> $MAKEFILE
2290      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
2291  done  done
2292    
# Line 1573  printf "\n\n# DO NOT DELETE\n" >> $MAKEF Line 2299  printf "\n\n# DO NOT DELETE\n" >> $MAKEF
2299    
2300  printf "\n===  Done  ===\n"  printf "\n===  Done  ===\n"
2301    
2302  #  Write the "template" files for the adjoint builds  # Create special header files
2303  cat >AD_CONFIG.template <<EOF  $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"
2304  C  WARNING: This file is automatically generated by genmake2 and  if test ! -f $PACKAGES_DOT_H ; then
2305  C    used by the Makefile rules.  Please DO NOT EDIT this file      mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2306  C    unless you are CERTAIN that you know what you are doing.  else
2307        cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
2308  #undef ALLOW_ADJOINT_RUN      RETVAL=$?
2309  #undef ALLOW_TANGENTLINEAR_RUN      if test "x$RETVAL" = x0 ; then
2310  #undef ALLOW_ECCO_OPTIMIZATION          rm -f $PACKAGES_DOT_H".tmp"
2311  EOF      else
2312  cat >ad_config.template <<EOF          mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
2313  C  WARNING: This file is automatically generated by genmake2 and          mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2314  C    used by the Makefile rules.  Please DO NOT EDIT this file      fi
2315  C    unless you are CERTAIN that you know what you are doing.  fi
2316    if test ! -f AD_CONFIG.h ; then
2317  #define ALLOW_ADJOINT_RUN      $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
2318  #undef ALLOW_TANGENTLINEAR_RUN  fi
 #undef ALLOW_ECCO_OPTIMIZATION  
 EOF  
 cat >ftl_config.template <<EOF  
 C  WARNING: This file is automatically generated by genmake2 and  
 C    used by the Makefile rules.  Please DO NOT EDIT this file  
 C    unless you are CERTAIN that you know what you are doing.  
   
 #undef ALLOW_ADJOINT_RUN  
 #define ALLOW_TANGENTLINEAR_RUN  
 #undef ALLOW_ECCO_OPTIMIZATION  
 EOF  
 cat >svd_config.template <<EOF  
 C  WARNING: This file is automatically generated by genmake2 and  
 C    used by the Makefile rules.  Please DO NOT EDIT this file  
 C    unless you are CERTAIN that you know what you are doing.  
   
 #undef ALLOW_ADJOINT_RUN  
 #undef ALLOW_TANGENTLINEAR_RUN  
 #undef ALLOW_ECCO_OPTIMIZATION  
 EOF  
 cp AD_CONFIG.template AD_CONFIG.h  
2319    
2320    
2321  #  Write the "state" for future records  #  Write the "state" for future records
2322  if test "x$DUMPSTATE" != xf ; then  if test "x$DUMPSTATE" != xf ; then
2323      echo -n "" > genmake_state      printf "" > genmake_state
2324      for i in $gm_state ; do      for i in $gm_state ; do
2325          t1="t2=\$$i"          t1="t2=\$$i"
2326          eval $t1          eval $t1

Legend:
Removed from v.1.33  
changed lines
  Added in v.1.126

  ViewVC Help
Powered by ViewVC 1.1.22