/[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.15 by edhill, Tue Oct 21 18:35:08 2003 UTC revision 1.124 by edhill, Tue Jun 7 20:52:42 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      PLATFORM=`echo $tmp2 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`      tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
257        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 103  find_possible_configs()  { Line 278  find_possible_configs()  {
278          CPP="cpp -traditional -P"          CPP="cpp -traditional -P"
279      fi      fi
280    
281      # look for possible fortran compilers      look_for_makedepend
282      tmp="$MITGCM_FC $FC g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"  
283        #================================================================
284        #  look for possible C compilers
285        tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc"
286        p_CC=
287        for c in $tmp ; do
288            rm -f ./genmake_hello.c  ./genmake_hello
289            cat >> genmake_hello.c << EOF
290    #include <stdio.h>
291    int main(int argc, char **argv) {
292      printf("Hello!\n");
293      return 0;
294    }
295    EOF
296            $c -o genmake_hello genmake_hello.c > /dev/null 2>&1
297            RETVAL=$?
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
321    
322        #================================================================
323        #  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 121  EOF Line 338  EOF
338              p_FC="$p_FC $c"              p_FC="$p_FC $c"
339          fi          fi
340      done      done
341        rm -f ./hello.f ./hello
342      if test "x${p_FC}" = x ; then      if test "x${p_FC}" = x ; then
343          cat 1>&2 <<EOF          cat 1>&2 <<EOF
344    
# Line 128  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 137  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 204  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        -mpi | --mpi
531              Include MPI header files and link to MPI libraries
532        -mpi=PATH | --mpi=PATH
533              Include MPI header files and link to MPI libraries using MPI_ROOT
534              set to PATH. i.e. Include files from \$PATH/include, link to libraries
535              from \$PATH/lib and use binaries from \$PATH/bin.
536    
537        -bash NAME
538              Explicitly specify the Bourne or BASH shell to use
539    
540      While it is most often a single word, the "NAME" variables specified
541      above can in many cases be a space-delimited string such as:
542    
543        --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'
544        -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'
545        -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
546    
547      which, depending upon your shell, may need to be single-quoted.
548    
549      For more detailed genmake documentation, please see:
550    
551        http://mitgcm.org/devel_HOWTO/
552    
553    EOF
554    
555      exit 1      exit 1
556  }  }
557    
558  #eh3 # This is the generic configuration.  #  Build a CPP macro to automate calling C routines from FORTRAN
559  #eh3 set LN         = ( 'ln -s' )  get_fortran_c_namemangling()  {
560  #eh3 set CPP        = ( '/lib/cpp -P' )  
561  #eh3 set S64        = ( '$(TOOLSDIR)/set64bitConst.sh' )      #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
562  #eh3 set KPP        = (  )      if test ! "x$FC_NAMEMANGLE" = x ; then
563  #eh3 set FC         = ( 'f77' )          return 0
564  #eh3 set LINK       = $FC      fi
565  #eh3 set MAKEDEPEND = ( 'makedepend' )  
566  #eh3 set INCLUDES   = ( -I. )      default_nm="#define FC_NAMEMANGLE(X) X ## _"
567  #eh3 set FFLAGS     = (  )      
568  #eh3 set FOPTIM     = (  )      cat > genmake_test.c <<EOF
569  #eh3 set CFLAGS     = (  )  void tcall( char * string ) { tsub( string ); }
570  #eh3 set KFLAGS1    = (  )  EOF
571  #eh3 set KFLAGS2    = (  )      $MAKE genmake_test.o >> genmake_warnings 2>&1
572  #eh3 set LIBS       = (  )      RETVAL=$?
573  #eh3 set KPPFILES   = (  )      if test "x$RETVAL" != x0 ; then
574  #eh3 if (! $?NOOPTFILES ) set NOOPTFILES = (  )          FC_NAMEMANGLE=$default_nm
575  #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = (  )          cat <<EOF>> genmake_errors
576    
577    WARNING: C test compile fails
578    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
579    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
580    EOF
581            return 1
582        fi
583        c_tcall=`nm genmake_test.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
584        RETVAL=$?
585        if test "x$RETVAL" != x0 ; then
586            FC_NAMEMANGLE=$default_nm
587            cat <<EOF>> genmake_warnings
588    
589    WARNING: The "nm" command failed.
590    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
591    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
592    EOF
593            return 1
594        fi
595        cat > genmake_tcomp.$FS <<EOF
596          subroutine tcall( string )
597          character*(*) string
598          call tsub( string )
599          end
600    EOF
601        $FC $FFLAGS $DEFINES -c genmake_tcomp.$FS >> genmake_warnings 2>&1
602        RETVAL=$?
603        if test "x$RETVAL" != x0 ; then
604            FC_NAMEMANGLE=$default_nm
605            cat <<EOF>> genmake_warnings
606    
607    WARNING: FORTRAN test compile fails -- please see "genmake_errors"
608    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
609    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
610    EOF
611            return 1
612        fi
613        f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
614        RETVAL=$?
615        if test "x$RETVAL" != x0 ; then
616            FC_NAMEMANGLE=$default_nm
617            cat <<EOF>> genmake_warnings
618    
619    WARNING: The "nm" command failed.
620    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
621    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
622    EOF
623            return 1
624        fi
625    
626        c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
627        f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
628        c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
629        f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
630    
631        nmangle="X"
632        if test "x$c_a" != "x$f_a" ; then
633            comm="echo x$f_a | sed -e 's|x$c_a||'"
634            a=`eval $comm`
635            nmangle="$a ## $nmangle"
636        fi
637        if test "x$c_b" != "x$f_b" ; then
638            comm="echo x$f_b | sed -e 's|x$c_b||'"
639            b=`eval $comm`
640            nmangle="$nmangle ## $b"
641        fi
642    
643        FC_NAMEMANGLE="#define FC_NAMEMANGLE(X)  $nmangle"
644    
645        #  cleanup the testing files
646        rm -f genmake_tcomp.* genmake_test.*
647    }
648    
649    
650    check_HAVE_CLOC()  {
651        get_fortran_c_namemangling
652        cat <<EOF > genmake_tc_1.c
653    $FC_NAMEMANGLE
654    #include <stdio.h>
655    #include <stdlib.h>
656    #include <unistd.h>
657    #include <assert.h>
658    #include <sys/time.h>
659    void FC_NAMEMANGLE(cloc) ( double *curtim )
660    {
661     struct timeval tv1;
662     gettimeofday(&tv1 , (void *)NULL );
663     *curtim =  (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
664     *curtim = *curtim/1.E6;
665    }
666    EOF
667        make genmake_tc_1.o >> genmake_warnings 2>&1
668        RET_C=$?
669        cat <<EOF > genmake_tc_2.$FS
670          program hello
671          Real*8 wtime
672          external cloc
673          call cloc(wtime)
674          print *," HELLO WORLD", wtime
675          end program hello
676    EOF
677        $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_warnings 2>&1
678        RET_F=$?
679        test -x ./genmake_tc  &&  ./genmake_tc >> genmake_warnings 2>&1
680        RETVAL=$?
681        if test "x$RETVAL" = x0 ; then
682            HAVE_CLOC=t
683            DEFINES="$DEFINES -DHAVE_CLOC"
684        fi
685        rm -f genmake_tc*
686    }
687    
688    
689    check_HAVE_STAT()  {
690        get_fortran_c_namemangling
691        cat <<EOF > genmake_tc_1.c
692    $FC_NAMEMANGLE
693    #include <stdio.h>
694    #include <stdlib.h>
695    #include <unistd.h>
696    #include <sys/stat.h>
697    #include <sys/types.h>
698    void FC_NAMEMANGLE(tfsize) ( int *nbyte )
699    {
700        char name[512];
701        struct stat astat;
702    
703        name[0] = 'a'; name[1] = '\0';
704        if (! stat(name, &astat))
705            *nbyte = (int)(astat.st_size);
706        else
707            *nbyte = -1;
708    }
709    EOF
710        make genmake_tc_1.o >> genmake_tc.log 2>&1
711        RET_C=$?
712        cat <<EOF > genmake_tc_2.$FS
713          program hello
714          integer nbyte
715          call tfsize(nbyte)
716          print *," HELLO WORLD", nbyte
717          end program hello
718    EOF
719        $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_tc.log 2>&1
720        RET_F=$?
721        test -x ./genmake_tc  &&  ./genmake_tc >> genmake_tc.log 2>&1
722        RETVAL=$?
723        if test "x$RETVAL" = x0 ; then
724            HAVE_STAT=t
725            DEFINES="$DEFINES -DHAVE_STAT"
726        fi
727        rm -f genmake_tc*
728    }
729    
730    
731    check_netcdf_libs()  {
732        if test ! "x$SKIP_NETCDF_CHECK" = x ; then
733            return
734        fi
735        echo "" > genmake_tnc.log
736        cat <<EOF > genmake_tnc.F
737          program fgennc
738    #include "netcdf.inc"
739    EOF
740        if test ! "x$MPI" = x ; then
741            echo '#include "mpif.h"' >> genmake_tnc.F
742        fi
743        cat <<EOF >> genmake_tnc.F
744          integer iret, ncid, xid
745          iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
746          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
747          iret = nf_def_dim(ncid, 'X', 11, xid)
748          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
749          iret = nf_close(ncid)
750          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
751          end
752    EOF
753        echo "Executing:" > genmake_tnc.log
754        echo "  $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS" \
755            > genmake_tnc.log
756        RET_CPP=f
757        $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null  \
758            &&  RET_CPP=t
759        if test "x$RET_CPP" = xf ; then
760            echo "  WARNING: CPP failed to pre-process the netcdf test." \
761                > genmake_tnc.log
762            echo "    Please check that \$INCLUDES is properly set." \
763                > genmake_tnc.log
764        fi
765        echo "Executing:" > genmake_tnc.log
766        echo "  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS" > genmake_tnc.log
767        echo "  $LINK -o genmake_tnc.o $LIBS" > genmake_tnc.log
768        $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
769            &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
770        RET_COMPILE=$?
771    
772        #EH3  Remove test program execution for machines that either disallow
773        #EH3  execution or cannot support it (eg. cross-compilers)
774        #EH3
775        #EH3 test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1
776        #EH3 RETVAL=$?
777        #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
778    
779        if test "x$RET_COMPILE" = x0 ; then
780            HAVE_NETCDF=t
781        else
782            # try again with "-lnetcdf" added to the libs
783            $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null  \
784                &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
785                &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
786            RET_COMPILE=$?
787            if test "x$RET_COMPILE" = x0 ; then
788                LIBS="$LIBS -lnetcdf"
789                HAVE_NETCDF=t
790            else
791                cat genmake_tnc.log >> genmake_warnings
792            fi
793        fi
794        rm -f genmake_tnc*
795    }
796    
797    
798    
799    ###############################################################################
800    #   Sequential part of script starts here
801    ###############################################################################
802    
803  #  Set defaults here  #  Set defaults here
804  COMMANDL="$0 $@"  COMMANDL="$0 $@"
# Line 288  PLATFORM= Line 807  PLATFORM=
807  LN=  LN=
808  S64=  S64=
809  KPP=  KPP=
810  FC=  #FC=
811    #CC=gcc
812    #CPP=
813  LINK=  LINK=
814  DEFINES="-DWORDLENGTH=4"  DEFINES=
815  PACKAGES=  PACKAGES=
816  ENABLE=  ENABLE=
817  DISABLE=  DISABLE=
818  MAKEFILE=  # MAKEFILE=
819  MAKEDEPEND=  # MAKEDEPEND=
820  PDEPEND=  PDEPEND=
821  DUMPSTATE=t  DUMPSTATE=t
822  PDEFAULT=  PDEFAULT=
823  OPTFILE=  OPTFILE=
824  INCLUDES="-I."  INCLUDES="-I. $INCLUDES"
825  FFLAGS=  FFLAGS=
826  FOPTIM=  FOPTIM=
827  CFLAGS=  CFLAGS=
828  KFLAGS1=  KFLAGS1=
829  KFLAGS2=  KFLAGS2=
830    #LDADD=
831  LIBS=  LIBS=
832  KPPFILES=  KPPFILES=
833  NOOPTFILES=  NOOPTFILES=
834  NOOPTFLAGS=  NOOPTFLAGS=
835    MPI=
836    MPIPATH=
837    
838    # DEFINES checked by test compilation or command-line
839    HAVE_SYSTEM=
840    HAVE_FDATE=
841    FC_NAMEMANGLE=
842    HAVE_CLOC=
843    HAVE_STAT=
844    HAVE_NETCDF=
845    HAVE_ETIME=
846    IGNORE_TIME=
847    
848  MODS=  MODS=
849  TOOLSDIR=  TOOLSDIR=
850  SOURCEDIRS=  SOURCEDIRS=
851  INCLUDEDIRS=  INCLUDEDIRS=
852  STANDARDDIRS=  STANDARDDIRS="USE_THE_DEFAULT"
853    
854    G2ARGS=
855    BASH=
856  PWD=`pwd`  PWD=`pwd`
857  MAKE=make  test "x$MAKE" = x  &&  MAKE=make
858  AWK=awk  test "x$AWK" = x   &&  AWK=awk
859  THISHOSTNAME=`hostname`  THISHOST=`hostname`
860  THISCWD=`pwd`  THISCWD=`pwd`
861  THISDATE=`date`  THISDATE=`date`
862    THISUSER=`echo $USER`
863    THISVER=
864  MACHINE=`uname -a`  MACHINE=`uname -a`
865  EXECUTABLE=  EXECUTABLE=
866  EXEHOOK=  EXEHOOK=
# Line 332  IEEE= Line 870  IEEE=
870  if test "x$MITGCM_IEEE" != x ; then  if test "x$MITGCM_IEEE" != x ; then
871      IEEE=$MITGCM_IEEE      IEEE=$MITGCM_IEEE
872  fi  fi
873    FS=
874    FS90=
875    
876  AUTODIFF_PKG_USED=f  AUTODIFF_PKG_USED=f
877  AD_OPTFILE=  AD_OPTFILE=
878    TAF=
879    AD_TAF_FLAGS=
880    FTL_TAF_FLAGS=
881    SVD_TAF_FLAGS=
882    TAF_EXTRA=
883    TAMC=
884    AD_TAMC_FLAGS=
885    FTL_TAF_FLAGS=
886    SVD_TAMC_FLAGS=
887    TAMC_EXTRA=
888    
889    
890  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
891  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"
892  gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS"  gm_s2="FC CPP IEEE MPI JAM DUMPSTATE STANDARDDIRS"
893    
894  #  The following state is not directly set by command-line switches  #  The following state is not directly set by command-line switches
895  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 "
896  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
897  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE"
898  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
899    gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME"
900    
901  #  The following are all related to adjoint/tangent-linear stuff  #  The following are all related to adjoint/tangent-linear stuff
902  gm_s7="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF DIFF_FLAGS AD_TAMC_FLAGS AD_TAF_FLAGS"  gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
903  gm_s8="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"  gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
904  gm_s9=""  gm_s12="TAF_EXTRA TAMC_EXTRA"
905    
906  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7 $gm_s8"  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"
907    gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
908    
909    cat <<EOF
910    
911    GENMAKE :
912    
913    A program for GENerating MAKEfiles for the MITgcm project.  For a
914    quick list of options, use "genmake -h" or for more detail see:
915    
916      http://mitgcm.org/devel_HOWTO/
917    
918    EOF
919    
 echo  
920  echo "===  Processing options files and arguments  ==="  echo "===  Processing options files and arguments  ==="
921  gm_local="genmake_local"  gm_local="genmake_local"
922  for i in . $MODS ; do  for i in . $MODS ; do
923      if test -r $i/$gm_local ; then      if test -r $i/$gm_local ; then
924          source $i/$gm_local          . $i/$gm_local
925          break          break
926      fi      fi
927  done  done
928  echo -n "  getting local config information:  "  printf "  getting local config information:  "
929  if test -e $gm_local ; then  if test -f $gm_local ; then
930      echo "using $gm_local"      echo "using $gm_local"
931      source $gm_local      . $gm_local
932      # echo "DISABLE=$DISABLE"      # echo "DISABLE=$DISABLE"
933      # echo "ENABLE=$ENABLE"      # echo "ENABLE=$ENABLE"
934  else  else
935      echo "none found"      echo "none found"
936  fi  fi
937    
938  #  echo "$0::$1:$2:$3:$4:$5:$6:$7:"  #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
939  #OPTIONS=  #OPTIONS=
940  #n=0  #n=0
941  #for i ; do  #for i ; do
# Line 385  fi Line 947  fi
947  #done  #done
948  #parse_options  #parse_options
949  ac_prev=  ac_prev=
950  for ac_option ; do  for ac_option in "$@" ; do
951    
952        G2ARGS="$G2ARGS \"$ac_option\""
953    
954      # If the previous option needs an argument, assign it.      # If the previous option needs an argument, assign it.
955      if test -n "$ac_prev"; then      if test -n "$ac_prev"; then
# Line 408  for ac_option ; do Line 972  for ac_option ; do
972          -optfile=* | --optfile=* | -of=* | --of=*)          -optfile=* | --optfile=* | -of=* | --of=*)
973              OPTFILE=$ac_optarg ;;              OPTFILE=$ac_optarg ;;
974                    
975          -adoptfile | --adoptfile | -ad | --ad)          -adoptfile | --adoptfile | -adof | --adof)
976              ac_prev=AD_OPTFILE ;;              ac_prev=AD_OPTFILE ;;
977          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
978              AD_OPTFILE=$ac_optarg ;;              AD_OPTFILE=$ac_optarg ;;
# Line 428  for ac_option ; do Line 992  for ac_option ; do
992          -make=* | --make=* | -m=* | --m=*)          -make=* | --make=* | -m=* | --m=*)
993              MAKE=$ac_optarg ;;              MAKE=$ac_optarg ;;
994                    
995            -bash | --bash)
996                ac_prev=BASH ;;
997            -bash=* | --bash=*)
998                BASH=$ac_optarg ;;
999            
1000            -makedepend | --makedepend | -md | --md)
1001                ac_prev=MAKEDEPEND ;;
1002            -makedepend=* | --makedepend=* | -md=* | --md=*)
1003                MAKEDEPEND=$ac_optarg ;;
1004            
1005          -makefile | --makefile | -ma | --ma)          -makefile | --makefile | -ma | --ma)
1006              ac_prev=MAKEFILE ;;              ac_prev=MAKEFILE ;;
1007          -makefile=* | --makefile=* | -ma=* | --ma=*)          -makefile=* | --makefile=* | -ma=* | --ma=*)
1008              MAKEFILE=$ac_optarg ;;              MAKEFILE=$ac_optarg ;;
1009                    
1010          -platform | --platform | -pl | --pl)          -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
1011              ac_prev=PLATFORM ;;              echo "ERROR: The platform option has been removed.  Please specify"
1012          -platform=* | --platform=* | -pl=* | --pl=*)              echo "  the build options using the \"optfile\" mechanism."
1013              PLATFORM=$ac_optarg ;;              echo
1014                usage
1015                ;;
1016                    
1017          -rootdir | --rootdir | -rd | --rd)          -rootdir | --rootdir | -rd | --rd)
1018              ac_prev=ROOTDIR ;;              ac_prev=ROOTDIR ;;
# Line 463  for ac_option ; do Line 1039  for ac_option ; do
1039          -standarddirs=* | --standarddirs=*)          -standarddirs=* | --standarddirs=*)
1040              STANDARDDIRS=$ac_optarg ;;              STANDARDDIRS=$ac_optarg ;;
1041    
         -noopt | --noopt)  
             ac_prev=NOOPT ;;  
         -noopt=* | --noopt=*)  
             NOOPT=$ac_optarg ;;  
           
1042  #           -cpp | --cpp)  #           -cpp | --cpp)
1043  #               ac_prev=cpp ;;  #               ac_prev=cpp ;;
1044  #           -cpp=* | --cpp=*)  #           -cpp=* | --cpp=*)
1045  #               CPP=$ac_optarg ;;  #               CPP=$ac_optarg ;;
1046                        
1047            -cc | --cc)
1048                ac_prev=CC ;;
1049            -cc=* | --cc=*)
1050                CC=$ac_optarg ;;
1051            
1052          -fortran | --fortran | -fc | --fc)          -fortran | --fortran | -fc | --fc)
1053              ac_prev=FC ;;              ac_prev=FC ;;
1054          -fc=* | --fc=*)          -fc=* | --fc=*)
1055              FC=$ac_optarg ;;              FC=$ac_optarg ;;
1056                    
1057            -fs | --fs)
1058                ac_prev=FS ;;
1059            -fs=* | --fs=*)
1060                FS=$ac_optarg ;;
1061            
1062            -fs90 | --fs90)
1063                ac_prev=FS90 ;;
1064            -fs90=* | --fs90=*)
1065                FS90=$ac_optarg ;;
1066            
1067          -ieee | --ieee)          -ieee | --ieee)
1068              IEEE=true ;;              IEEE=true ;;
1069          -noieee | --noieee)          -noieee | --noieee)
1070              IEEE= ;;              IEEE= ;;
1071            
1072          -mpi | --mpi)          -mpi | --mpi)
1073              MPI=true ;;              MPI=true ;;
1074          -nompi | --nompi)          -mpi=* | --mpi=*)
1075              MPI= ;;              MPIPATH=$ac_optarg
1076                MPI=true ;;
1077                    
1078          -jam | --jam)  #       -jam | --jam)
1079              JAM=1 ;;  #           JAM=1 ;;
1080          -nojam | --nojam)  #       -nojam | --nojam)
1081              JAM=0 ;;  #           JAM=0 ;;
1082                    
1083          -ds | --ds)          -ds | --ds)
1084              DUMPSTATE=t ;;              DUMPSTATE=t ;;
1085                    
1086            -taf_extra | --taf_extra)
1087                ac_prev=TAF_EXTRA ;;
1088            -taf_extra=* | --taf_extra=*)
1089                TAF_EXTRA=$ac_optarg ;;
1090    
1091            -tamc_extra | --tamc_extra)
1092                ac_prev=TAMC_EXTRA ;;
1093            -tamc_extra=* | --tamc_extra=*)
1094                TAMC_EXTRA=$ac_optarg ;;
1095            
1096            -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1097                IGNORE_TIME="-DIGNORE_TIME" ;;
1098    
1099          -*)          -*)
1100              echo "Error: unrecognized option: "$ac_option              echo "Error: unrecognized option: "$ac_option
1101              usage              usage
# Line 510  for ac_option ; do Line 1110  for ac_option ; do
1110            
1111  done  done
1112    
1113    
1114  if test -f ./.genmakerc ; then  if test -f ./.genmakerc ; then
1115      echo      echo
1116      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 522  if test -f ./.genmakerc ; then Line 1123  if test -f ./.genmakerc ; then
1123      echo      echo
1124  fi  fi
1125    
1126    #  Find the MITgcm ${ROOTDIR}
1127  if test "x${ROOTDIR}" = x ; then  if test "x${ROOTDIR}" = x ; then
1128      if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1129        if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
1130          ROOTDIR=".."          ROOTDIR=".."
1131      else      else
1132          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1133              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
1134                  ROOTDIR=$d                  ROOTDIR=$d
1135                  echo -n "Warning:  ROOTDIR was not specified but there appears to be"                  printf "Warning:  ROOTDIR was not specified but there appears to be"
1136                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
1137                  break                  break
1138              fi              fi
# Line 547  if test ! -d ${ROOTDIR} ; then Line 1150  if test ! -d ${ROOTDIR} ; then
1150      exit 1      exit 1
1151  fi  fi
1152    
1153    #  Find the MITgcm ${THISVER}
1154    if test -f "${ROOTDIR}/doc/tag-index" ; then
1155        THISVER=`grep checkpoint ${ROOTDIR}/doc/tag-index | head -1`
1156    fi
1157    
1158    if test "x$MAKEFILE" = x ; then
1159        MAKEFILE="Makefile"
1160    fi
1161    
1162  echo "  getting OPTFILE information:  "  echo "  getting OPTFILE information:  "
1163  if test "x${OPTFILE}" = x ; then  if test "x${OPTFILE}" = x ; then
1164      if test "x$MITGCM_OF" = x ; then      if test "x$MITGCM_OF" = x ; then
# Line 560  fi Line 1172  fi
1172  if test "x$OPTFILE" != xNONE ; then  if test "x$OPTFILE" != xNONE ; then
1173      if test -f "$OPTFILE" -a -r "$OPTFILE" ; then      if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
1174          echo "    using OPTFILE=\"$OPTFILE\""          echo "    using OPTFILE=\"$OPTFILE\""
1175          source "$OPTFILE"          . "$OPTFILE"
1176          RETVAL=$?          RETVAL=$?
1177          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
1178              echo -n "Error: failed to source OPTFILE \"$OPTFILE\""              printf "Error: failed to source OPTFILE \"$OPTFILE\""
1179              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1180              exit 1              exit 1
1181          fi          fi
# Line 587  fi Line 1199  fi
1199  if test "x${AD_OPTFILE}" != xNONE ; then  if test "x${AD_OPTFILE}" != xNONE ; then
1200      if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then      if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
1201          echo "    using AD_OPTFILE=\"$AD_OPTFILE\""          echo "    using AD_OPTFILE=\"$AD_OPTFILE\""
1202          source "$AD_OPTFILE"          . "$AD_OPTFILE"
1203          RETVAL=$?          RETVAL=$?
1204          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
1205              echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""              printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
1206              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1207              exit 1              exit 1
1208          fi          fi
# Line 603  if test "x${AD_OPTFILE}" != xNONE ; then Line 1215  if test "x${AD_OPTFILE}" != xNONE ; then
1215      fi      fi
1216  fi  fi
1217    
1218  #  Check that FC, LINK, CPP, and S64 are defined.  If not, complain  #====================================================================
1219  #  and abort!  #  Set default values if not set by the optfile
1220    #
1221    #  Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
1222    #  either set defaults or complain and abort!
1223    if test ! "x$BASH" = x ; then
1224        # add a trailing space so that it works within the Makefile syntax (see below)
1225        BASH="$BASH "
1226    fi
1227  if test "x$FC" = x ; then  if test "x$FC" = x ; then
1228      cat <<EOF 1>&2      cat <<EOF 1>&2
1229    
# Line 615  Error: no Fortran compiler: please speci Line 1234  Error: no Fortran compiler: please speci
1234  EOF  EOF
1235      exit 1      exit 1
1236  fi  fi
1237    if test "x$CC" = x ; then
1238        CC=cc
1239    #     cat <<EOF 1>&2
1240    # Error: no C compiler: please specify using one of the following:
1241    #   1) within the options file ("CC=...") as specified by "-of=OPTFILE"
1242    #   2) the "-cc=XXX" command-line option
1243    #   3) the "./genmake_local" file
1244    # EOF
1245    #     exit 1
1246    fi
1247  if test "x$LINK" = x ; then  if test "x$LINK" = x ; then
1248      LINK=$FC      LINK=$FC
1249  fi  fi
1250    if test "x$MAKE" = x ; then
1251        MAKE="make"
1252    fi
1253  if test "x$CPP" = x ; then  if test "x$CPP" = x ; then
1254      CPP="cpp"      CPP=cpp
1255  fi  fi
1256    #EH3 === UGLY ===
1257    #  The following is an ugly little hack to check for $CPP in /lib/ and
1258    #  it should eventually be replaced with a more general function that
1259    #  searches a combo of the user's path and a list of "usual suspects"
1260    #  to find the correct location for binaries such as $CPP.
1261    for i in " " "/lib/" ; do
1262        echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1263    done
1264    #EH3 === UGLY ===
1265  echo "#define A a" | $CPP > test_cpp 2>&1  echo "#define A a" | $CPP > test_cpp 2>&1
1266  RETVAL=$?  RETVAL=$?
1267  if test "x$RETVAL" != x0 ; then  if test "x$RETVAL" != x0 ; then
# Line 630  Error: C pre-processor "$CPP" failed the Line 1271  Error: C pre-processor "$CPP" failed the
1271    
1272    1) within the options file ("CPP=...") as specified by "-of=OPTFILE"    1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
1273    2) the "./genmake_local" file    2) the "./genmake_local" file
1274      3) with the CPP environment variable
1275    
1276  EOF  EOF
1277      exit 1      exit 1
1278  else  else
1279      rm -f test_cpp      rm -f test_cpp
1280  fi  fi
1281  if test "x$MAKEDEPEND" = x ; then  look_for_makedepend
1282      MAKEDEPEND=makedepend  if test "x$LN" = x ; then
1283        LN="ln -s"
1284    fi
1285    echo "test" > genmake_test_ln
1286    $LN genmake_test_ln genmake_tlink
1287    RETVAL=$?
1288    if test "x$RETVAL" != x0 ; then
1289        cat <<EOF 1>&2
1290    
1291    Error: The command "ln -s" failed -- please specify a working soft-link
1292      command in the optfile.
1293    
1294    EOF
1295        exit 1
1296    fi
1297    rm -f genmake_test_ln genmake_tlink
1298    
1299    #  Check for broken *.F/*.f handling and fix if possible
1300    check_for_broken_Ff
1301    
1302    if test ! "x$MPI" = x ; then
1303          echo "  Turning on MPI cpp macros"
1304          DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
1305    fi
1306    
1307    printf "\n===  Checking system libraries  ===\n"
1308    printf "  Do we have the system() command using $FC...  "
1309    cat > genmake_tcomp.$FS <<EOF
1310          program hello
1311          call system('echo hi')
1312          end
1313    EOF
1314    $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1315    RETVAL=$?
1316    if test "x$RETVAL" = x0 ; then
1317        HAVE_SYSTEM=t
1318        DEFINES="$DEFINES -DHAVE_SYSTEM"
1319        echo "yes"
1320    else
1321        HAVE_SYSTEM=
1322        echo "no"
1323    fi
1324    rm -f genmake_tcomp*
1325    
1326    printf "  Do we have the fdate() command using $FC...  "
1327    cat > genmake_tcomp.$FS <<EOF
1328          program hello
1329          CHARACTER(128) string
1330          string = ' '
1331          call fdate( string )
1332          print *, string
1333          end
1334    EOF
1335    $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1336    RETVAL=$?
1337    if test "x$RETVAL" = x0 ; then
1338        HAVE_FDATE=t
1339        DEFINES="$DEFINES -DHAVE_FDATE"
1340        echo "yes"
1341    else
1342        HAVE_FDATE=
1343        echo "no"
1344    fi
1345    rm -f genmake_tcomp*
1346    
1347    printf "  Do we have the etime() command using $FC...  "
1348    cat > genmake_tcomp.$FS <<EOF
1349          program hello
1350          REAL*4 ACTUAL, TARRAY(2)
1351          EXTERNAL ETIME
1352          REAL*4 ETIME
1353          actual = etime( tarray )
1354          print *, tarray
1355          end
1356    EOF
1357    $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1358    RETVAL=$?
1359    if test "x$RETVAL" = x0 ; then
1360        HAVE_ETIME=t
1361        DEFINES="$DEFINES -DHAVE_ETIME"
1362        echo "yes"
1363    else
1364        HAVE_ETIME=
1365        echo "no"
1366    fi
1367    rm -f genmake_tcomp*
1368    
1369    printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
1370    check_HAVE_CLOC
1371    if test "x$HAVE_CLOC" != x ; then
1372        echo "yes"
1373    else
1374        echo "no"
1375    fi
1376    rm -f genmake_t*
1377    
1378    printf "  Can we use stat() through C calls...  "
1379    check_HAVE_STAT
1380    if test "x$HAVE_STAT" != x ; then
1381        echo "yes"
1382    else
1383        echo "no"
1384    fi
1385    rm -f genmake_t*
1386    
1387    printf "  Can we create NetCDF-enabled binaries...  "
1388    check_netcdf_libs
1389    if test "x$HAVE_NETCDF" != x ; then
1390        echo "yes"
1391    else
1392        echo "no"
1393  fi  fi
1394    DEFINES="$DEFINES $IGNORE_TIME"
1395    
1396  printf "\n===  Setting defaults  ===\n"  printf "\n===  Setting defaults  ===\n"
1397  echo -n "  Adding MODS directories:  "  printf "  Adding MODS directories:  "
1398  for d in $MODS ; do  for d in $MODS ; do
1399      if test ! -d $d ; then      if test ! -d $d ; then
1400          echo          echo
1401          echo "Error: MODS directory \"$d\" not found!"          echo "Error: MODS directory \"$d\" not found!"
1402          exit 1          exit 1
1403      else      else
1404          echo -n " $d"          printf " $d"
1405          SOURCEDIRS="$SOURCEDIRS $d"          SOURCEDIRS="$SOURCEDIRS $d"
1406          INCLUDEDIRS="$INCLUDEDIRS $d"          INCLUDEDIRS="$INCLUDEDIRS $d"
1407      fi      fi
1408  done  done
1409  echo  echo
1410    
 if test "x$MAKEFILE" = x ; then  
     MAKEFILE="Makefile"  
 fi  
1411  if test "x${PLATFORM}" = x ; then  if test "x${PLATFORM}" = x ; then
1412      PLATFORM=$p_PLATFORM      PLATFORM=$p_PLATFORM
1413  fi  fi
1414    
1415  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
1416      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1417        if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
1418          EXEDIR=../exe          EXEDIR=../exe
1419      else      else
1420          EXEDIR=.          EXEDIR=.
# Line 678  if test "x${TOOLSDIR}" = x ; then Line 1429  if test "x${TOOLSDIR}" = x ; then
1429      TOOLSDIR="$ROOTDIR/tools"      TOOLSDIR="$ROOTDIR/tools"
1430  fi  fi
1431  if test ! -d ${TOOLSDIR} ; then  if test ! -d ${TOOLSDIR} ; then
1432      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
1433      exit 1      exit 1
1434  fi  fi
1435  if test "x$S64" = x ; then  if test "x$S64" = x ; then
1436      S64='$(TOOLSDIR)/set64bitConst.sh'      echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1
1437        RETVAL=$?
1438        if test "x${RETVAL}" = x0 ; then
1439            S64='$(TOOLSDIR)/set64bitConst.sh'
1440        else
1441            echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1
1442            RETVAL=$?
1443            if test "x${RETVAL}" = x0 ; then
1444                S64='$(TOOLSDIR)/set64bitConst.csh'
1445            else
1446                cat <<EOF
1447    
1448    ERROR: neither of the two default scripts:
1449    
1450        ${TOOLSDIR}/set64bitConst.sh
1451        ${TOOLSDIR}/set64bitConst.csh
1452    
1453      are working so please check paths or specify (with \$S64) a
1454      working version of this script.
1455    
1456    EOF
1457                exit 1
1458            fi
1459        fi
1460  fi  fi
1461    THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
1462    
1463  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1464    
# Line 692  EXECUTABLE=${EXECUTABLE:-mitgcmuv} Line 1467  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1467  #  they appear as regular source code  #  they appear as regular source code
1468  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
1469      echo "  Making source files in eesupp from templates"      echo "  Making source files in eesupp from templates"
1470      $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1      ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1
1471      RETVAL=$?      RETVAL=$?
1472      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
1473          rm -f make_eesupp.errors          rm -f make_eesupp.errors
1474      else      else
1475          echo "Error: problem encountered while building source files in eesupp:"          echo "Error: problem encountered while building source files in eesupp:"
1476          cat make_eesupp.errors          cat make_eesupp.errors 1>&2
1477          exit 1          exit 1
1478      fi      fi
1479  fi  fi
1480    
1481    #same for exch2
1482    if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then
1483        echo "  Making source files in exch2 from  templates"
1484        ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1
1485        RETVAL=$?
1486        if test "x${RETVAL}" = x0 ; then
1487            rm -f make_exch2.errors
1488        else
1489            echo "Error: problem encountered while building source files in exch2:"
1490            cat make_exch2.errors 1>&2
1491            exit 1
1492        fi
1493    fi
1494    
1495  printf "\n===  Determining package settings  ===\n"  printf "\n===  Determining package settings  ===\n"
1496  if  test "x${PDEPEND}" = x ; then  if  test "x${PDEPEND}" = x ; then
1497      tmp=$ROOTDIR"/pkg/pkg_depend"      tmp=$ROOTDIR"/pkg/pkg_depend"
# Line 729  if test ! "x${RETVAL}" = x0 ; then Line 1518  if test ! "x${RETVAL}" = x0 ; then
1518      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
1519      exit 1      exit 1
1520  fi  fi
1521  source ./.pd_tmp  . ./.pd_tmp
1522  rm -f ./.pd_tmp  rm -f ./.pd_tmp
1523    
1524  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"
1525  #  file should eventually be added so that, for convenience, one can  #  file should eventually be added so that, for convenience, one can
1526  #  specify groups of packages using names like "ocean" and "atmosphere".  #  specify groups of packages using names like "ocean" and "atmosphere".
1527  echo  -n "  checking default package list:  "  echo "  checking default package list:  "
1528  if test "x${PDEFAULT}" = x ; then  if test "x${PDEFAULT}" = x ; then
1529      for i in "." $MODS ; do      for i in "." $MODS ; do
1530          if test -r $i"/packages.conf" ; then          if test -r $i"/packages.conf" ; then
# Line 748  if test "x${PDEFAULT}" = x ; then Line 1537  if test "x${PDEFAULT}" = x ; then
1537      PDEFAULT="$ROOTDIR/pkg/pkg_default"      PDEFAULT="$ROOTDIR/pkg/pkg_default"
1538  fi  fi
1539  if test "x${PDEFAULT}" = xNONE ; then  if test "x${PDEFAULT}" = xNONE ; then
1540      echo "default packages file disabled"      echo "    default packages file disabled"
1541  else  else
1542      if test ! -r $PDEFAULT ; then      if test ! -r $PDEFAULT ; then
         echo ""  
1543          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""
1544      else      else
1545          echo "  using PDEFAULT=\"$PDEFAULT\""          echo "    using PDEFAULT=\"$PDEFAULT\""
1546          #  Strip the comments and add all the names          #  Strip the comments and add all the names
1547          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
1548          RETVAL=$?          RETVAL=$?
1549          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
1550              echo -n "Error: can't parse default package list "              printf "Error: can't parse default package list "
1551              echo "-- please check PDEFAULT=\"$PDEFAULT\""              echo "-- please check PDEFAULT=\"$PDEFAULT\""
1552              exit 1              exit 1
1553          fi          fi
# Line 767  else Line 1555  else
1555              PACKAGES="$PACKAGES $i"              PACKAGES="$PACKAGES $i"
1556          done          done
1557          echo "    before group expansion packages are: $PACKAGES"          echo "    before group expansion packages are: $PACKAGES"
1558          expand_pkg_groups          RET=1
1559            while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
1560          echo "    after group expansion packages are:  $PACKAGES"          echo "    after group expansion packages are:  $PACKAGES"
1561      fi      fi
1562  fi  fi
1563    
1564  echo "  applying DISABLE settings"  echo "  applying DISABLE settings"
1565    for i in $PACKAGES ; do
1566        echo $i >> ./.tmp_pack
1567    done
1568    for i in `grep  "-" ./.tmp_pack` ; do
1569        j=`echo $i | sed 's/[-]//'`
1570        DISABLE="$DISABLE $j"
1571    done
1572  pack=  pack=
1573  for p in $PACKAGES ; do  for p in $PACKAGES ; do
1574      addit="t"      addit="t"
# Line 789  PACKAGES="$pack" Line 1585  PACKAGES="$pack"
1585  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
1586  echo "" > ./.tmp_pack  echo "" > ./.tmp_pack
1587  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
1588    # Test if each explicitly referenced package exists
1589  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1590      if test ! -d "$ROOTDIR/pkg/$i" ; then      j=`echo $i | sed 's/[-+]//'`
1591        if test ! -d "$ROOTDIR/pkg/$j" ; then
1592          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
1593          exit 1          exit 1
1594      fi      fi
1595      echo $i >> ./.tmp_pack      echo $i >> ./.tmp_pack
1596  done  done
 pack=`cat ./.tmp_pack | sort | uniq`  
 rm -f ./.tmp_pack  
1597  PACKAGES=  PACKAGES=
1598  for i in $pack ; do  for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do
1599      PACKAGES="$PACKAGES $i"      PACKAGES="$PACKAGES $i"
1600  done  done
1601    rm -f ./.tmp_pack
1602  echo "    packages are:  $PACKAGES"  echo "    packages are:  $PACKAGES"
1603    
1604    #  Check availability of NetCDF and then either build the MNC template
1605    #  files or delete mnc from the list of available packages.
1606    echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1
1607    RETVAL=$?
1608    if test "x$RETVAL" = x0 ; then
1609        if test "x$HAVE_NETCDF" != xt ; then
1610            cat <<EOF
1611    
1612    *********************************************************************
1613    WARNING: the "mnc" package was enabled but tests failed to compile
1614      NetCDF applications.  Please check that:
1615    
1616      1) NetCDF is correctly installed for this compiler and
1617      2) the LIBS variable (within the "optfile") specifies the correct
1618           NetCDF library to link against.
1619    
1620      Due to this failure, the "mnc" package is now DISABLED.
1621    *********************************************************************
1622    
1623    EOF
1624            PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
1625            DISABLE="$DISABLE mnc"
1626        else
1627            ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
1628            RETVAL=$?
1629            if test "x${RETVAL}" = x0 ; then
1630                rm -f make_mnc.errors
1631            else
1632                echo "Error: problem encountered while building source files in pkg/mnc:"
1633                cat make_mnc.errors 1>&2
1634                exit 1
1635            fi
1636        fi
1637    fi
1638    
1639  echo "  applying package dependency rules"  echo "  applying package dependency rules"
1640  ck=  ck=
1641  while test "x$ck" != xtt ; do  while test "x$ck" != xtt ; do
# Line 868  while test "x$ck" != xtt ; do Line 1700  while test "x$ck" != xtt ; do
1700              echo "  the dependency rules for \"$dname\""              echo "  the dependency rules for \"$dname\""
1701              exit 1              exit 1
1702          fi          fi
1703          i=$(( $i + 1 ))          i=`echo "$i + 1" | bc -l`
1704            #i=$(( $i + 1 ))
1705      done      done
1706      ck=$ck"t"      ck=$ck"t"
1707  done  done
# Line 887  for i in $PACKAGES ; do Line 1720  for i in $PACKAGES ; do
1720      fi      fi
1721  done  done
1722    
 #  This is compatible with the old genmake.  The "DISABLE_*" flags  
 #  need to be replaced by the "ALLOW_*" flags set below.  
 #  
 # echo -n "  Setting package-specific CPP flags:  "  
 # pkrm=( mom_fluxform mom_vecinv generic_advdiff )  
 # pkrmdef=( -DDISABLE_MOM_FLUXFORM -DDISABLE_MOM_VECINV -DDISABLE_GENERIC_ADVDIFF -DDISABLE_DEBUGMODE )  
 # echo -n "  "  
 # i=0  
 # while test $i -lt "${#pkrm[@]}" ; do  
 #     echo "$PACKAGES" | grep "${pk[$i]}" > /dev/null 2>&1  
 #     RETVAL=$?  
 #     if test "x$RETVAL" = x1 ; then  
 #       DEFINES="$DEFINES ${pkdef[$i]}"  
 #       echo -n " ${pkdef[$i]}"  
 #     fi  
 #     i=$(( $i + 1 ))  
 # done  
 # echo  
   
1723  # Create a list of #define and #undef to enable/disable packages  # Create a list of #define and #undef to enable/disable packages
1724  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  
1725  #  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
1726  #  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
1727  #  file would eventually be split up so that all package-related #define  #  file would eventually be split up so that all package-related #define
1728  #  statements could be separated and handled only by genmake.  #  statements could be separated and handled only by genmake.
1729  names=`ls -1 "$ROOTDIR/pkg"`  names=`ls -1 "$ROOTDIR/pkg"`
1730  all_pack=  all_pack=
1731    DISABLED_PACKAGES=
1732  for n in $names ; do  for n in $names ; do
1733      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
1734          has_pack="f"          has_pack="f"
# Line 936  for n in $names ; do Line 1739  for n in $names ; do
1739              fi              fi
1740          done          done
1741          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
1742              undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1743              echo "#undef $undef" >> $PACKAGES_DOT_H".tmp"              DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
 #           DEFINES="$DEFINES -U$undef"  
   
 #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  
             case $n in  
                 mom_fluxform)  
                     DEFINES="$DEFINES -DDISABLE_MOM_FLUXFORM"  
                     ;;  
                 mom_vecinv)  
                     DEFINES="$DEFINES -DDISABLE_MOM_VECINV"  
                     ;;  
                 debug)  
                     DEFINES="$DEFINES -DDISABLE_DEBUGMODE"  
                     ;;  
             esac  
 #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  
   
1744          fi          fi
1745      fi      fi
1746  done  done
1747  cat <<EOF >>$PACKAGES_DOT_H".tmp"  ENABLED_PACKAGES=
   
 C  Packages enabled by genmake:  
 EOF  
1748  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1749      def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`      def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1750      echo "#define $def" >> $PACKAGES_DOT_H".tmp"      ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
1751  #eh3 DEFINES="$DEFINES -D$def"  #eh3 DEFINES="$DEFINES -D$def"
1752    
1753  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1754      case $i in      case $i in
1755          aim_v23)          aim_v23)
1756              echo "#define   ALLOW_AIM" >> $PACKAGES_DOT_H".tmp"              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
1757              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 :-)"  
1758              ;;              ;;
1759      esac      esac
1760  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1761    
1762  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  
1763    
1764  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS"
1765  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
1766  if test "x$STANDARDDIRS" = x ; then  if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
1767      STANDARDDIRS="eesupp model"      STANDARDDIRS="eesupp model"
1768  fi  fi
1769  for d in $STANDARDDIRS ; do  if test "x$STANDARDDIRS" != x ; then
1770      adr="$ROOTDIR/$d/src"      for d in $STANDARDDIRS ; do
1771      if test ! -d $adr ; then          adr="$ROOTDIR/$d/src"
1772          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""          if test ! -d $adr ; then
1773          echo "  is correct and that you correctly specified the STANDARDDIRS option"              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1774          exit 1              echo "  is correct and that you correctly specified the STANDARDDIRS option"
1775      else              exit 1
1776          SOURCEDIRS="$SOURCEDIRS $adr"          else
1777      fi              SOURCEDIRS="$SOURCEDIRS $adr"
1778      adr="$ROOTDIR/$d/inc"          fi
1779      if test ! -d $adr ; then          adr="$ROOTDIR/$d/inc"
1780          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""          if test ! -d $adr ; then
1781          echo "  is correct and that you correctly specified the STANDARDDIRS option"              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1782          exit 1              echo "  is correct and that you correctly specified the STANDARDDIRS option"
1783      else              exit 1
1784          INCLUDEDIRS="$INCLUDEDIRS $adr"          else
1785      fi              INCLUDEDIRS="$INCLUDEDIRS $adr"
1786  done          fi
1787        done
1788    fi
1789    
1790  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"
1791  echo " of \"#define ALLOW_PKGNAME\"-type statements:"  echo "    of \"#define \"-type statements that are no longer allowed:"
1792  CPP_OPTIONS=  CPP_OPTIONS=
1793    CPP_EEOPTIONS=
1794  spaths=". $INCLUDEDIRS"  spaths=". $INCLUDEDIRS"
1795    names=`ls -1 "$ROOTDIR/pkg"`
1796  for i in $spaths ; do  for i in $spaths ; do
1797      try="$i/CPP_OPTIONS.h"      try="$i/CPP_OPTIONS.h"
1798      #  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  
1799          echo "    found CPP_OPTIONS=\"$try\""          echo "    found CPP_OPTIONS=\"$try\""
1800          CPP_OPTIONS="$try"          CPP_OPTIONS="$try"
1801          break          # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
1802            for n in $names ; do
1803                test_for_package_in_cpp_options $CPP_OPTIONS $n
1804            done
1805        fi
1806        try="$i/CPP_EEOPTIONS.h"
1807        if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
1808            echo "    found CPP_EEOPTIONS=\"$try\""
1809            # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
1810    #**** not yet enabled ****
1811    #        test_for_mpi_in_cpp_eeoptions $try
1812    #**** not yet enabled ****
1813            CPP_EEOPTIONS="$try"
1814      fi      fi
1815  done  done
1816  if test "x$CPP_OPTIONS" = x ; then  if test "x$CPP_OPTIONS" = x ; then
1817      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"
1818      exit 1      exit 1
1819  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  
   
1820    
1821  #  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
1822  #  compiler.  #  compiler.
# Line 1055  for i in $SOURCEDIRS ; do Line 1830  for i in $SOURCEDIRS ; do
1830          cat $i/$j >> ad_files          cat $i/$j >> ad_files
1831      done      done
1832  done  done
1833    if test ! "x"$FS = "x.f" ; then
1834  cat <<EOF > adjoint_sed      cat ad_files | sed -e "s/\.f/.$FS/g" > ad_files_f
1835  s/call adopen(/call adopen ( mythid,\\      mv -f ad_files_f ad_files
1836       \&           /g  fi
 s/call adclose(/call adclose( mythid,\\  
      \&           /g  
 s/call adread(/call adread ( mythid,\\  
      \&           /g  
 s/call adwrite(/call adwrite( mythid,\\  
      \&           /g  
   
 EOF  
1837    
1838  echo  echo
1839  echo "===  Creating the Makefile  ==="  echo "===  Creating the Makefile  ==="
1840  echo "  setting INCLUDES"  echo "  setting INCLUDES"
1841  for i in $INCLUDEDIRS ; do  for i in $INCLUDEDIRS ; do
1842      if ! test -d $i ; then      if test ! -d $i ; then
 #       INCLUDES="$INCLUDES -I$i"  
 #   else  
1843          echo "Warning: can't find INCLUDEDIRS=\"$i\""          echo "Warning: can't find INCLUDEDIRS=\"$i\""
1844      fi      fi
1845  done  done
# Line 1084  rm -rf .links.tmp Line 1849  rm -rf .links.tmp
1849  mkdir .links.tmp  mkdir .links.tmp
1850  echo "# This section creates symbolic links" > srclinks.tmp  echo "# This section creates symbolic links" > srclinks.tmp
1851  echo "" >> srclinks.tmp  echo "" >> srclinks.tmp
1852  echo -n 'SRCFILES = '    > srclist.inc  printf 'SRCFILES = '    > srclist.inc
1853  echo -n 'CSRCFILES = '   > csrclist.inc  printf 'CSRCFILES = '   > csrclist.inc
1854  echo -n 'F90SRCFILES = ' > f90srclist.inc  printf 'F90SRCFILES = ' > f90srclist.inc
1855  echo -n 'HEADERFILES = ' > hlist.inc  printf 'HEADERFILES = ' > hlist.inc
1856  echo -n 'AD_FLOW_FILES = ' > ad_flow_files.inc  printf 'AD_FLOW_FILES = ' > ad_flow_files.inc
1857  alldirs="$SOURCEDIRS $INCLUDEDIRS ."  alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1858  for d in $alldirs ; do  for d in $alldirs ; do
1859      deplist=      deplist=
# Line 1097  for d in $alldirs ; do Line 1862  for d in $alldirs ; do
1862      for sf in $sfiles ; do      for sf in $sfiles ; do
1863          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
1864              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
1865                  extn=`echo $sf | $AWK -F '.' '{print $NF}'`                  case $d/$sf in
1866                  touch .links.tmp/$sf                    ./$PACKAGES_DOT_H)
1867                  deplist="$deplist $sf"                          ;;
1868                      ./AD_CONFIG.h)
1869                            ;;
1870                      ./FC_NAMEMANGLE.h)
1871                            ;;
1872                      ./BUILD_INFO.h)
1873                            ;;
1874                      *)
1875                            touch .links.tmp/$sf
1876                            deplist="$deplist $sf"
1877                            ;;
1878                    esac
1879                    extn=`echo $sf | $AWK -F. '{print $NF}'`
1880                  case $extn in                  case $extn in
1881                      F)                      F)
1882                          echo    " \\"  >> srclist.inc                          echo    " \\"  >> srclist.inc
1883                          echo -n " $sf" >> srclist.inc                          printf " $sf" >> srclist.inc
1884                          ;;                          ;;
1885                      F90)                      F90)
1886                          echo    " \\"  >> f90srclist.inc                          echo    " \\"  >> f90srclist.inc
1887                          echo -n " $sf" >> f90srclist.inc                          printf " $sf" >> f90srclist.inc
1888                          ;;                          ;;
1889                      c)                      c)
1890                          echo    " \\"  >> csrclist.inc                          echo    " \\"  >> csrclist.inc
1891                          echo -n " $sf" >> csrclist.inc                          printf " $sf" >> csrclist.inc
1892                          ;;                          ;;
1893                      h)                      h)
1894                          echo    " \\"  >> hlist.inc                          echo    " \\"  >> hlist.inc
1895                          echo -n " $sf" >> hlist.inc                          printf " $sf" >> hlist.inc
1896                          ;;                          ;;
1897                      flow)                      flow)
1898                          echo    " \\"  >> ad_flow_files.inc                          echo    " \\"  >> ad_flow_files.inc
1899                          echo -n " $sf" >> ad_flow_files.inc                          printf " $sf" >> ad_flow_files.inc
1900                          ;;                          ;;
1901                  esac                  esac
1902              fi              fi
# Line 1139  echo "" >> f90srclist.inc Line 1916  echo "" >> f90srclist.inc
1916  echo "" >> hlist.inc  echo "" >> hlist.inc
1917  echo "" >> ad_flow_files.inc  echo "" >> ad_flow_files.inc
1918    
1919  if test -e $MAKEFILE ; then  if test -f $MAKEFILE ; then
1920      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.bak"
1921  fi  fi
1922  echo "  Writing makefile: $MAKEFILE"  echo "  Writing makefile: $MAKEFILE"
# Line 1148  echo "#    $MACHINE" >> $MAKEFILE Line 1925  echo "#    $MACHINE" >> $MAKEFILE
1925  echo "# This makefile was generated automatically on" >> $MAKEFILE  echo "# This makefile was generated automatically on" >> $MAKEFILE
1926  echo "#    $THISDATE" >> $MAKEFILE  echo "#    $THISDATE" >> $MAKEFILE
1927  echo "# by the command:" >> $MAKEFILE  echo "# by the command:" >> $MAKEFILE
1928  echo "#    $0 $@" >> $MAKEFILE  echo "#    $0 $G2ARGS" >> $MAKEFILE
1929  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
1930  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE  echo "#    ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
1931    
1932    EXE_AD=$EXECUTABLE"_ad"
1933    EXE_FTL=$EXECUTABLE"_ftl"
1934    EXE_SVD=$EXECUTABLE"_svd"
1935    
1936  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
1937    #
1938    # OPTFILE="$OPTFILE"
1939  #  #
1940  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
1941  # SOURCEDIRS   : Directories containing the source (.F) files  # SOURCEDIRS   : Directories containing the source (.F) files
# Line 1181  TOOLSDIR    = ${TOOLSDIR} Line 1965  TOOLSDIR    = ${TOOLSDIR}
1965    
1966  #eh3  new defines for the adjoint work  #eh3  new defines for the adjoint work
1967  AUTODIFF    = ${ROOTDIR}/pkg/autodiff  AUTODIFF    = ${ROOTDIR}/pkg/autodiff
1968    EXE_AD      = ${EXE_AD}
1969    EXE_FTL     = ${EXE_FTL}
1970    EXE_SVD     = ${EXE_SVD}
1971    
1972    ENABLED_PACKAGES = ${ENABLED_PACKAGES}
1973    DISABLED_PACKAGES = ${DISABLED_PACKAGES}
1974    
1975    # These files are created by Makefile
1976    SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h
1977    
1978  EOF  EOF
1979    
# Line 1199  KPP = ${KPP} Line 1992  KPP = ${KPP}
1992  FC = ${FC}  FC = ${FC}
1993  # Fortran compiler  # Fortran compiler
1994  F90C = ${F90C}  F90C = ${F90C}
1995    # C compiler
1996    CC = ${CC}
1997  # Link editor  # Link editor
1998  LINK = ${LINK}  LINK = ${LINK} ${LDADD}
1999    
2000  # Defines for CPP  # Defines for CPP
2001  DEFINES = ${DEFINES}  DEFINES = ${DEFINES}
# Line 1221  CFLAGS = ${CFLAGS} Line 2016  CFLAGS = ${CFLAGS}
2016  NOOPTFILES = ${NOOPTFILES}  NOOPTFILES = ${NOOPTFILES}
2017  NOOPTFLAGS = ${NOOPTFLAGS}  NOOPTFLAGS = ${NOOPTFLAGS}
2018  # Flags and libraries needed for linking  # Flags and libraries needed for linking
2019  LIBS = ${LIBS} \$(XLIBS)  LIBS = ${LIBS}
2020  # Name of the Mekfile  # Name of the Mekfile
2021  MAKEFILE=${MAKEFILE}  MAKEFILE=${MAKEFILE}
2022    
# Line 1232  cat csrclist.inc      >> $MAKEFILE Line 2027  cat csrclist.inc      >> $MAKEFILE
2027  cat f90srclist.inc    >> $MAKEFILE  cat f90srclist.inc    >> $MAKEFILE
2028  cat hlist.inc         >> $MAKEFILE  cat hlist.inc         >> $MAKEFILE
2029  cat ad_flow_files.inc >> $MAKEFILE  cat ad_flow_files.inc >> $MAKEFILE
2030  echo               >> $MAKEFILE  echo >> $MAKEFILE
2031  echo 'F77FILES =  $(SRCFILES:.F=.f)'                                           >> $MAKEFILE  echo 'F77FILES =  $(SRCFILES:.F=.'$FS')'      >> $MAKEFILE
2032  echo 'F90FILES =  $(F90SRCFILES:.F90=.f90)'                                    >> $MAKEFILE  echo 'F90FILES =  $(F90SRCFILES:.F=.'$FS90')' >> $MAKEFILE
2033  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
2034    echo >> $MAKEFILE
2035    echo '.SUFFIXES:' >> $MAKEFILE
2036    echo '.SUFFIXES: .o .'$FS' .p .F .c .'$FS90' .F90' >> $MAKEFILE
2037  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
2038  rm -f ad_flow_files.inc  rm -f ad_flow_files.inc
2039    
2040  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2041    
 .SUFFIXES:  
 .SUFFIXES: .o .f .p .F .c .F90 .f90  
   
2042  all: \$(EXECUTABLE)  all: \$(EXECUTABLE)
2043  \$(EXECUTABLE): \$(OBJFILES)  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(OBJFILES)
2044            @echo Creating \$@ ...
2045          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
2046  depend:  depend:
2047          @make links          @make links
2048          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
2049          ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE)          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2050            -rm -f makedepend.out
2051    
2052  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES)
2053    
2054  small_f: \$(F77FILES) \$(F90FILES)  small_f: \$(F77FILES) \$(F90FILES)
2055    
# Line 1262  output.txt: \$(EXECUTABLE) Line 2058  output.txt: \$(EXECUTABLE)
2058          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
2059    
2060  clean:  clean:
2061          -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}          -rm -rf *.o *.$FS *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
2062  Clean:  Clean:
2063          @make clean          @make clean
2064          @make cleanlinks          @make cleanlinks
2065          -rm -f Makefile.bak genmake_state genmake_optfile make.log          -rm -f \$(SPECIAL_FILES)
2066            -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak
2067  CLEAN:  CLEAN:
2068          @make Clean          @make Clean
2069          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
2070          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
2071          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
2072          -rm -f \$(EXECUTABLE) output.txt          -rm -f \$(EXECUTABLE) output.txt STD*
2073    
2074  Makefile: makefile  #eh3 Makefile: makefile
2075  makefile:  makefile:
2076          ${0} $@          $THIS_SCRIPT $G2ARGS
2077  cleanlinks:  cleanlinks:
2078          -find . -type l -exec rm {} \;          -find . -type l -exec rm {} \;
2079    
2080  # The normal chain of rules is (  .F - .f - .o  )  # Special targets (SPECIAL_FILES) which are create by make
2081  .F.f:  ${PACKAGES_DOT_H}:
2082            @echo Creating \$@ ...
2083            @$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) > \$@
2084    AD_CONFIG.h:
2085            @echo Creating \$@ ...
2086            @$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 > \$@
2087    FC_NAMEMANGLE.h:
2088            @echo Creating \$@ ...
2089            echo "$FC_NAMEMANGLE" > \$@
2090    
2091    BUILD_INFO.h:
2092            @echo Creating \$@ ...
2093    EOF
2094    
2095    test ! "x$THISVER" = x  && echo "       -echo \"#define THISVER '$THISVER'\" > \$@"   >> $MAKEFILE
2096    test ! "x$THISUSER" = x && echo "       -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE
2097    test ! "x$THISDATE" = x && echo "       -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
2098    test ! "x$THISHOST" = x && echo "       -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
2099    
2100    cat >>$MAKEFILE <<EOF
2101    
2102    # The normal chain of rules is (  .F - .$FS - .o  )
2103    
2104    ## This nullifies any default implicit rules concerning these two file types:
2105    ## %.o : %.F
2106    
2107    .F.$FS:
2108          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2109  .f.o:  .$FS.o:
2110          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2111  .F90.f90:  .F90.$FS90:
2112          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2113  .f90.o:  .$FS90.o:
2114          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
2115  .c.o:  .c.o:
2116          \$(CC) \$(CFLAGS) -c \$<          \$(CC) \$(CFLAGS) -c \$<
2117    
2118  # Special exceptions that use the ( .F - .p - .f - .o ) rule-chain  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
2119  .F.p:  .F.p:
2120          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2121  .p.f:  .p.$FS:
2122          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
2123    
2124  #=========================================  #=========================================
# Line 1304  cleanlinks: Line 2127  cleanlinks:
2127  TAMC           = ${TAMC}  TAMC           = ${TAMC}
2128  TAF            = ${TAF}  TAF            = ${TAF}
2129    
2130    TAF_EXTRA      = ${TAF_EXTRA}
2131    TAMC_EXTRA     = ${TAMC_EXTRA}
2132    
2133  EOF  EOF
2134    
2135  ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"  ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
# Line 1319  done Line 2145  done
2145    
2146  echo "  Add the source list for AD code generation"  echo "  Add the source list for AD code generation"
2147  echo >> $MAKEFILE  echo >> $MAKEFILE
2148  echo -n "AD_FILES = " >> $MAKEFILE  printf "AD_FILES = " >> $MAKEFILE
2149  AD_FILES=`cat ad_files`  AD_FILES=`cat ad_files`
2150  for i in $AD_FILES ; do  for i in $AD_FILES ; do
2151      echo    " \\" >> $MAKEFILE      echo    " \\" >> $MAKEFILE
2152      echo -n " $i" >> $MAKEFILE      printf " $i" >> $MAKEFILE
2153  done  done
2154  echo >> $MAKEFILE  echo >> $MAKEFILE
2155    rm -f ad_files
2156    
2157  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2158    
2159    # ... AD ...
2160  ad_input_code.f: \$(F77FILES)  adall: ad_taf
2161    adtaf: ad_taf_output.$FS
2162    adtamc: ad_tamc_output.$FS
2163    
2164    ad_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)
2165            @$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
2166            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
2167            -rm -f ad_config.template
2168            @make \$(F77FILES)
2169          @make \$(AD_FLOW_FILES)          @make \$(AD_FLOW_FILES)
2170          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.$FS
   
2171    
2172  ad_taf_output.f: ad_input_code.f  ad_taf_output.$FS: ad_input_code.$FS
2173          \$(TAF) \$(AD_TAF_FLAGS) ad_input_code.f          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2174          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
2175    
2176    adtafonly:
2177            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2178            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
2179    
2180  ad_taf: ad_taf_output.o \$(OBJFILES)  ad_taf: ad_taf_output.o \$(OBJFILES)
2181          \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
   
2182    
2183  ad_tamc_output.f: ad_input_code.f  ad_tamc_output.$FS: ad_input_code.$FS
2184          \$(TAMC) \$(AD_TAMC_FLAGS) ad_input_code.f          \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
2185          cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS
2186    
2187  ad_tamc: ad_tamc_output.o \$(OBJFILES)  ad_tamc: ad_tamc_output.o \$(OBJFILES)
2188          \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
2189    
2190    adonlyfwd:
2191            patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
2192    
2193    adtrick:
2194            patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
2195    
2196  flt_taf_output.f: ad_input_code.f  # ... FTL ...
2197          \$(TAF) \$(FTL_TAF_FLAGS) ad_input_code.f  ftlall: ftl_taf
2198          cat ad_input_code_ad.f | sed -f adjoint_sed > flt_taf_output.f  ftltaf: ftl_taf_output.$FS
2199    ftltamc: ftl_tamc_output.$FS
2200  flt_taf: flt_taf_output.o \$(OBJFILES)  
2201          \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) flt_taf_output.o \$(LIBS)  ftl_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)
2202            @$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
2203            cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
2204            -rm -f ftl_config.template
2205            @make \$(F77FILES)
2206            @make \$(AD_FLOW_FILES)
2207            cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.$FS
2208    
2209    ftl_taf_output.$FS: ftl_input_code.$FS
2210            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2211            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2212    
2213    ftltafonly:
2214            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2215            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2216    
2217    ftl_taf: ftl_taf_output.o \$(OBJFILES)
2218            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
2219    
2220    ftl_tamc_output.$FS: ftl_input_code.$FS
2221            \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
2222            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS
2223    
2224    ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
2225            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
2226    
2227    
2228    # ... SVD ...
2229    svdtaf: ad_taf_output.$FS ftl_taf_output.$FS
2230            @echo "--->>> Only ran TAF to generate SVD code!    <<<---"
2231            @echo "--->>> Do make svdall afterwards to compile. <<<---"
2232    svdall: svd_touch svd_taf
2233    
2234    svd_taf: \$(OBJFILES)
2235            \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
2236    
2237            @echo "--->>> Only COMPILE svd code! <<<---"
2238            @echo "--->>> Assumes you previously <<<---"
2239            @echo "--->>> did make svdtaf        <<<---"
2240    
2241    svd_touch:
2242            @echo "--->>> Only COMPILE svd code! <<<---"
2243            @echo "--->>> Assumes you previously <<<---"
2244            @echo "--->>> did make svdtaf        <<<---"
2245            touch ad_taf_output.$FS ftl_taf_output.$FS
2246            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS
2247            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS
2248            @$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
2249            cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
2250            -rm -f ftl_config.template
2251    
2252  #=========================================  #=========================================
2253    
# Line 1375  for i in $KPPFILES ; do Line 2264  for i in $KPPFILES ; do
2264      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
2265          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
2266      fi      fi
2267      echo "$base.f: $base.p" >> $MAKEFILE      echo "$base.$FS: $base.p" >> $MAKEFILE
2268  done  done
2269    
2270  echo "  Making list of NOOPTFILES"  echo "  Making list of NOOPTFILES"
# Line 1385  for i in $NOOPTFILES ; do Line 2274  for i in $NOOPTFILES ; do
2274      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
2275          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
2276      fi      fi
2277      echo "$base.o: $base.f" >> $MAKEFILE      echo "$base.o: $base.$FS" >> $MAKEFILE
2278      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
2279  done  done
2280    
# Line 1398  printf "\n\n# DO NOT DELETE\n" >> $MAKEF Line 2287  printf "\n\n# DO NOT DELETE\n" >> $MAKEF
2287    
2288  printf "\n===  Done  ===\n"  printf "\n===  Done  ===\n"
2289    
2290    # Create special header files
2291    $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"
2292    if test ! -f $PACKAGES_DOT_H ; then
2293        mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2294    else
2295        cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
2296        RETVAL=$?
2297        if test "x$RETVAL" = x0 ; then
2298            rm -f $PACKAGES_DOT_H".tmp"
2299        else
2300            mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
2301            mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2302        fi
2303    fi
2304    if test ! -f AD_CONFIG.h ; then
2305        $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
2306    fi
2307    
2308    
2309  #  Write the "state" for future records  #  Write the "state" for future records
2310  if test "x$DUMPSTATE" != xf ; then  if test "x$DUMPSTATE" != xf ; then
2311      echo -n "" > genmake_state      printf "" > genmake_state
2312      for i in $gm_state ; do      for i in $gm_state ; do
2313          t1="t2=\$$i"          t1="t2=\$$i"
2314          eval $t1          eval $t1

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.124

  ViewVC Help
Powered by ViewVC 1.1.22