/[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.24 by cnh, Wed Oct 29 13:42:10 2003 UTC revision 1.75 by edhill, Wed Apr 7 20:28:09 2004 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        #  First check the ability to create a *.F/.f pair.
80        cat <<EOF >> ./hello.F
81          program hello
82          write(*,*) 'hi'
83          stop
84          end
85    EOF
86        cp ./hello.F ./hello.f
87        RETVAL=$?
88        if test "x$RETVAL" != x0 ; then
89            FEXT='fp'
90            F90EXT='fp90'
91            return
92        fi
93        rm -f ./hello.f
94    
95        #  Then check the ability of ${MAKE} to use the two.
96        test -e Makefile  &&  mv -f Makefile Makefile.bak
97        cat <<EOF >> Makefile
98    .SUFFIXES:
99    hello.f: hello.F
100            cp -f hello.F hello.f
101    EOF
102        ( $MAKE hello.f ) > /dev/null 2>&1
103        RETVAL=$?
104        if test "x$RETVAL" != x0 -o ! -f ./hello.f ; then
105            FEXT='fp'
106            F90EXT='fp90'
107            return
108        fi
109        rm -f ./hello.f ./hello.F Makefile
110        test -e Makefile  &&  mv -f Makefile.bak Makefile
111    
112        #  Both tests passed, so use the default.
113        FEXT='F'
114        F90EXT='F90'
115    }
116    
117    
118  # Guess possible config options for this host  # Guess possible config options for this host
119  find_possible_configs()  {  find_possible_configs()  {
120    
121      tmp1=`uname`"_"`uname -m`      tmp1=`uname`"_"`uname -m`
122      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
123      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/'`
124        tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
125        tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
126        tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
127        PLATFORM=$tmp3
128      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
129      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  
130            
131      echo "test" > test      echo "test" > test
132      ln -s ./test link      ln -s ./test link
# Line 103  find_possible_configs()  { Line 144  find_possible_configs()  {
144          CPP="cpp -traditional -P"          CPP="cpp -traditional -P"
145      fi      fi
146    
147        #  The "original" makedepend is part of the Imake system that is
148        #  most often distributed with XFree86 or with an XFree86 source
149        #  package.  As a result, many machines (eg. generic Linux) do not
150        #  have a system-default "makedepend" available.  For those
151        #  systems, we have two fall-back options:
152        #
153        #    1) a makedepend implementation shipped with the cyrus-imapd
154        #       package:  ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
155        #
156        #    2) a known-buggy xmakedpend shell script
157        #
158        #  So the choices are, in order:
159        #
160        #    1) use the user-specified program
161        #    2) use a system-wide default
162        #    3) locally build and use the cyrus implementation
163        #    4) fall back to the buggy local xmakedpend script
164        #
165        if test "x${MAKEDEPEND}" = x ; then
166          which makedepend > /dev/null 2>&1
167          RETVAL=$?
168          if test ! "x${RETVAL}" = x0 ; then
169             echo "    a system-default makedepend was not found."
170    
171             #  Try to build the cyrus impl
172             rm -f ./genmake_cy_md
173             (
174                 cd $ROOTDIR/tools/cyrus-imapd-makedepend  \
175                     &&  ./configure > /dev/null 2>&1  \
176                     &&  make > /dev/null 2>&1  \
177                     &&  ./makedepend ifparser.c > /dev/null 2>&1  \
178                     &&  echo "true"
179             ) > ./genmake_cy_md
180             grep true ./genmake_cy_md > /dev/null 2>&1
181             RETVAL=$?
182             if test "x$RETVAL" = x0 ; then
183                 MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
184             else
185                 MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
186             fi
187             rm -f ./genmake_cy_md
188          fi
189        fi
190    
191      # look for possible fortran compilers      # look for possible fortran compilers
192      tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"      tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"
193      p_FC=      p_FC=
# Line 138  EOF Line 223  EOF
223          echo "   "$p_FC          echo "   "$p_FC
224          if test "x$FC" = x ; then          if test "x$FC" = x ; then
225              FC=`echo $p_FC | $AWK '{print $1}'`              FC=`echo $p_FC | $AWK '{print $1}'`
226                echo "  Setting FORTRAN compiler to: "$FC
227          fi          fi
228      fi      fi
229    
230      for i in $p_FC ; do      if test "x$OPTFILE" = x ; then
231          p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i          OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
232          if test -r $p_OF ; then          if test ! -r $OPTFILE ; then
233              OPTFILE=$p_OF               echo "  I looked for the file "$OPTFILE" but did not find it"
234              echo "  The options file:  $p_OF"          fi
235              echo "    appears to match so we'll use it."      fi
236              break  #    echo "  The options file:  $p_OF"
237          fi  #    echo "    appears to match so we'll use it."
238      done  #   for i in $p_FC ; do
239    #p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
240    #if test -r $p_OF ; then
241    #    OPTFILE=$p_OF
242    #    echo "  The options file:  $p_OF"
243    #    echo "    appears to match so we'll use it."
244    #    break
245    #fi
246    #   done
247      if test "x$OPTFILE" = x ; then      if test "x$OPTFILE" = x ; then
248          cat 1>&2 <<EOF          cat 1>&2 <<EOF
249    
# Line 205  get_pdepend_list()  { Line 299  get_pdepend_list()  {
299      cat $1 | sed -e 's/#.*$//g' \      cat $1 | sed -e 's/#.*$//g' \
300          | $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} }' \
301          > ./.pd_tmp          > ./.pd_tmp
302      source ./.pd_tmp      . ./.pd_tmp
303      rm -f ./.pd_tmp      rm -f ./.pd_tmp
304    
305      echo -n "PNAME = "${}      printf "PNAME = "${}
306  }  }
307    
308    
309  #  Explain usage  #  Explain usage
310  usage()  {  usage()  {
311      echo  cat <<EOF
312      echo "Usage: "$0" [OPTIONS]"  
313      echo "  where [OPTIONS] can be:"  Usage: "$0" [OPTIONS]
314      echo    where [OPTIONS] can be:
315      echo "    -help | --help | -h | --h"  
316      echo "    -nooptfile | --nooptfile"      -help | --help | -h | --h
317      echo "      -optfile NAME | --optfile NAME | -of NAME | --of NAME"            Print this help message and exit.
318      echo "      -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME"  
319      echo "    -pdepend NAME | --pdepend NAME"      -nooptfile | --nooptfile
320      echo "      -pdepend=NAME | --pdepend=NAME"        -optfile NAME | --optfile NAME | -of NAME | --of NAME
321      echo "    -pdefault NAME | --pdefault NAME"        -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
322      echo "      -pdefault=NAME | --pdefault=NAME"            Use "NAME" as the optfile.  By default, an attempt will be
323      echo "    -make NAME | -m NAME"            made to find an appropriate "standard" optfile in the
324      echo "      --make=NAME | -m=NAME"            tools/build_options/ directory.
325      echo "    -makefile NAME | -mf NAME"  
326      echo "      --makefile=NAME | -mf=NAME"      -pdepend NAME | --pdepend NAME
327      echo "    -platform NAME | --platform NAME | -pl NAME | --pl NAME"        -pdepend=NAME | --pdepend=NAME
328      echo "      -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"            Get package dependency information from "NAME".
329      echo "    -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"  
330      echo "      -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME"      -pdefault NAME | --pdefault NAME
331      echo "    -mods NAME | --mods NAME | -mo NAME | --mo NAME"        -pdefault=NAME | --pdefault=NAME
332      echo "      -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME"            Get the default package list from "NAME".
333      echo "    -disable NAME | --disable NAME"  
334      echo "      -disable=NAME | --disable=NAME"      -make NAME | -m NAME
335      echo "    -enable NAME | --enable NAME"        --make=NAME | -m=NAME
336      echo "      -enable=NAME | --enable=NAME"            Use "NAME" for the MAKE program. The default is "make" but
337      echo "    -standarddirs NAME | --standarddirs NAME"            many platforms, "gmake" is the preferred choice.
338      echo "      -standarddirs=NAME | --standarddirs=NAME"  
339      echo "    -noopt NAME | --noopt NAME"      -makefile NAME | -mf NAME
340      echo "      -noopt=NAME | --noopt=NAME"        --makefile=NAME | -mf=NAME
341  #    echo "    -cpp NAME | --cpp NAME"            Call the makefile "NAME".  The default is "Makefile".
342  #    echo "      -cpp=NAME | --cpp=NAME"  
343      echo "    -fortran NAME | --fortran NAME | -fc NAME | --fc NAME"      -makedepend NAME | -md NAME
344      echo "      -fc=NAME | --fc=NAME"        --makedepend=NAME | -md=NAME
345      echo "    -[no]ieee | --[no]ieee"            Use "NAME" for the MAKEDEPEND program.
346      echo "    -[no]mpi | --[no]mpi"  
347      echo "    -[no]jam | --[no]jam"      -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
348      echo        -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
349      echo "  and NAME is a string such as:"            Specify the location of the MITgcm ROOTDIR as "NAME".
350      echo            By default, genamke will try to find the location by
351      echo "    --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'"            looking in parent directories (up to the 5th parent).
352      echo "    -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'"  
353      echo "    -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"      -mods NAME | --mods NAME | -mo NAME | --mo NAME
354      echo        -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
355      echo "  which, depending upon your shell, may need to be single-quoted"            Here, "NAME" specifies a list of directories that are
356      echo "  if it contains spaces, dashes, or other special characters."            used for additional source code.  Files found in the
357              "mods list" are given preference over files of the same
358              name found elsewhere.
359    
360        -disable NAME | --disable NAME
361          -disable=NAME | --disable=NAME
362              Here "NAME" specifies a list of packages that we don't
363              want to use.  If this violates package dependencies,
364              genamke will exit with an error message.
365    
366        -enable NAME | --enable NAME
367          -enable=NAME | --enable=NAME
368              Here "NAME" specifies a list of packages that we wish
369              to specifically enable.  If this violates package
370              dependencies, genamke will exit with an error message.
371    
372        -standarddirs NAME | --standarddirs NAME
373          -standarddirs=NAME | --standarddirs=NAME
374              Here, "NAME" specifies a list of directories to be
375              used as the "standard" code.
376    
377        -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
378          -fc=NAME | --fc=NAME
379              Use "NAME" as the fortran compiler.  By default, genmake
380              will search for a working compiler by trying a list of
381              "usual suspects" such as g77, f77, etc.
382    
383        -[no]ieee | --[no]ieee
384              Do or don't use IEEE numerics.  Note that this option
385              *only* works if it is supported by the OPTFILE that
386              is being used.
387    
388        -mpi | --mpi
389              Include MPI header files and link to MPI libraries
390        -mpi=PATH | --mpi=PATH
391              Include MPI header files and link to MPI libraries using MPI_ROOT
392              set to PATH. i.e. Include files from $PATH/include, link to libraries
393              from $PATH/lib and use binaries from $PATH/bin.
394    
395        -bash NAME
396              Explicitly specify the Bourne or BASH shell to use
397    
398      While it is most often a single word, the "NAME" variables specified
399      above can in many cases be a space-delimited string such as:
400    
401        --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'
402        -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'
403        -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
404    
405      which, depending upon your shell, may need to be single-quoted.
406    
407      For more detailed genmake documentation, please see:
408    
409        http://mitgcm.org/devel_HOWTO/
410    
411    EOF
412    
413      exit 1      exit 1
414  }  }
415    
416  #eh3 # This is the generic configuration.  #  Build a CPP macro to automate calling C routines from FORTRAN
417  #eh3 set LN         = ( 'ln -s' )  get_fortran_c_namemangling()  {
418  #eh3 set CPP        = ( '/lib/cpp -P' )      default_nm="#define FC_NAMEMANGLE(X) X ## _"
419  #eh3 set S64        = ( '$(TOOLSDIR)/set64bitConst.sh' )      
420  #eh3 set KPP        = (  )      cat > genmake_test.c <<EOF
421  #eh3 set FC         = ( 'f77' )  void tcall( char * string ) { tsub( string ); }
422  #eh3 set LINK       = $FC  EOF
423  #eh3 set MAKEDEPEND = ( 'makedepend' )      $MAKE genmake_test.o >> genmake_warnings 2>&1
424  #eh3 set INCLUDES   = ( -I. )      RETVAL=$?
425  #eh3 set FFLAGS     = (  )      if test "x$RETVAL" != x0 ; then
426  #eh3 set FOPTIM     = (  )          FC_NAMEMANGLE=$default_nm
427  #eh3 set CFLAGS     = (  )          cat <<EOF>> genmake_errors
428  #eh3 set KFLAGS1    = (  )  
429  #eh3 set KFLAGS2    = (  )  WARNING: C test compile fails
430  #eh3 set LIBS       = (  )  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
431  #eh3 set KPPFILES   = (  )  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
432  #eh3 if (! $?NOOPTFILES ) set NOOPTFILES = (  )  EOF
433  #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = (  )          return 1
434        fi
435        c_tcall=`nm genmake_test.o | grep 'T ' | grep tcall | cut -d ' ' -f 3`
436        RETVAL=$?
437        if test "x$RETVAL" != x0 ; then
438            FC_NAMEMANGLE=$default_nm
439            cat <<EOF>> genmake_warnings
440    
441    WARNING: The "nm" command failed.
442    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
443    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
444    EOF
445            return 1
446        fi
447        cat > genmake_tcomp.f <<EOF
448          subroutine tcall( string )
449          character*(*) string
450          call tsub( string )
451          end
452    EOF
453        $FC $FFLAGS $DEFINES -c genmake_tcomp.f >> genmake_warnings 2>&1
454        RETVAL=$?
455        if test "x$RETVAL" != x0 ; then
456            FC_NAMEMANGLE=$default_nm
457            cat <<EOF>> genmake_warnings
458    
459    WARNING: FORTRAN test compile fails -- please see "genmake_errors"
460    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
461    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
462    EOF
463            return 1
464        fi
465        f_tcall=`nm genmake_tcomp.o | grep 'T ' | grep tcall | cut -d ' ' -f 3`
466        RETVAL=$?
467        if test "x$RETVAL" != x0 ; then
468            FC_NAMEMANGLE=$default_nm
469            cat <<EOF>> genmake_warnings
470    
471    WARNING: The "nm" command failed.
472    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
473    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
474    EOF
475            return 1
476        fi
477    
478        c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
479        f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
480        c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
481        f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
482    
483        nmangle="X"
484        if test "x$c_a" != "x$f_a" ; then
485            comm="echo x$f_a | sed -e 's|x$c_a||'"
486            a=`eval $comm`
487            nmangle="$a ## $nmangle"
488        fi
489        if test "x$c_b" != "x$f_b" ; then
490            comm="echo x$f_b | sed -e 's|x$c_b||'"
491            b=`eval $comm`
492            nmangle="$nmangle ## $b"
493        fi
494    
495        FC_NAMEMANGLE="#define FC_NAMEMANGLE(X)  $nmangle"
496    
497        #  cleanup the testing files
498        rm -f genmake_tcomp.* genmake_test.*
499    }
500    
501    
502    check_HAVE_CLOC()  {
503        get_fortran_c_namemangling
504        cat <<EOF > genmake_tc_1.c
505    $FC_NAMEMANGLE
506    #include <stdio.h>
507    #include <stdlib.h>
508    #include <unistd.h>
509    #include <assert.h>
510    #include <sys/time.h>
511    void FC_NAMEMANGLE(cloc) ( double *curtim )
512    {
513     struct timeval tv1;
514     gettimeofday(&tv1 , (void *)NULL );
515     *curtim =  (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
516     *curtim = *curtim/1.E6;
517    }
518    EOF
519        make genmake_tc_1.o >> genmake_tc.log 2>&1
520        RET_C=$?
521        cat <<EOF > genmake_tc_2.f
522          program hello
523          Real*8 wtime
524          external cloc
525          call cloc(wtime)
526          print *," HELLO WORLD", wtime
527          end program hello
528    EOF
529        $FC $FFLAGS -o genmake_tc genmake_tc_2.f genmake_tc_1.o >> genmake_tc.log 2>&1
530        RET_F=$?
531        test -x ./genmake_tc  &&  ./genmake_tc >> genmake_tc.log 2>&1
532        RETVAL=$?
533        if test "x$RETVAL" = x0 ; then
534            HAVE_CLOC=t
535            DEFINES="$DEFINES -DHAVE_CLOC"
536        fi
537        rm -f genmake_tc*
538    }
539    
540    
541    check_netcdf_libs()  {
542        cat <<EOF > genmake_tnc.for
543          program fgennc
544    #include "netcdf.inc"
545          integer iret, ncid, xid
546          iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
547          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
548          iret = nf_def_dim(ncid, 'X', 11, xid)
549          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
550          iret = nf_close(ncid)
551          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
552          end
553    EOF
554        $CPP genmake_tnc.for > genmake_tnc.f  \
555            &&  $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f $LIBS >> genmake_tnc.log 2>&1
556        RET_COMPILE=$?
557        test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1
558        RETVAL=$?
559        if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
560            HAVE_NETCDF=t
561        else
562            # try again with "-lnetcdf" added to the libs
563            $CPP genmake_tnc.for > genmake_tnc.f  \
564                &&  $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f \
565                $LIBS -lnetcdf >> genmake_tnc_2.log 2>&1
566            RET_COMPILE=$?
567            test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1
568            RETVAL=$?
569            if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
570                LIBS="$LIBS -lnetcdf"
571                HAVE_NETCDF=t
572            else
573                cat genmake_tnc.log >> genmake_warnings
574            fi
575        fi
576        rm -f genmake_tnc*
577    }
578    
579    
580    
581    ###############################################################################
582    #   Sequential part of script starts here
583    ###############################################################################
584    
585  #  Set defaults here  #  Set defaults here
586  COMMANDL="$0 $@"  COMMANDL="$0 $@"
# Line 290  LN= Line 590  LN=
590  S64=  S64=
591  KPP=  KPP=
592  FC=  FC=
593    CPP=
594  LINK=  LINK=
595  DEFINES="-DWORDLENGTH=4"  DEFINES=
596  PACKAGES=  PACKAGES=
597  ENABLE=  ENABLE=
598  DISABLE=  DISABLE=
# Line 307  FOPTIM= Line 608  FOPTIM=
608  CFLAGS=  CFLAGS=
609  KFLAGS1=  KFLAGS1=
610  KFLAGS2=  KFLAGS2=
611    #LDADD=
612  LIBS=  LIBS=
613  KPPFILES=  KPPFILES=
614  NOOPTFILES=  NOOPTFILES=
615  NOOPTFLAGS=  NOOPTFLAGS=
616    MPI=
617    MPIPATH=
618    
619    # DEFINES checked by test compilation
620    HAVE_SYSTEM=
621    HAVE_FDATE=
622    FC_NAMEMANGLE=
623    HAVE_CLOC=
624    HAVE_NETCDF=
625    
626  MODS=  MODS=
627  TOOLSDIR=  TOOLSDIR=
628  SOURCEDIRS=  SOURCEDIRS=
629  INCLUDEDIRS=  INCLUDEDIRS=
630  STANDARDDIRS=  STANDARDDIRS="USE_THE_DEFAULT"
631    
632    G2ARGS=
633    BASH=
634  PWD=`pwd`  PWD=`pwd`
635  MAKE=make  MAKE=make
636  AWK=awk  AWK=awk
# Line 333  IEEE= Line 646  IEEE=
646  if test "x$MITGCM_IEEE" != x ; then  if test "x$MITGCM_IEEE" != x ; then
647      IEEE=$MITGCM_IEEE      IEEE=$MITGCM_IEEE
648  fi  fi
649    FEXT=
650    F90EXT=
651    
652  AUTODIFF_PKG_USED=f  AUTODIFF_PKG_USED=f
653  AD_OPTFILE=  AD_OPTFILE=
# Line 349  TAMC_EXTRA= Line 664  TAMC_EXTRA=
664    
665    
666  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
667  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"
668  gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS"  gm_s2="FC CPP IEEE MPI JAM DUMPSTATE STANDARDDIRS"
669    
670  #  The following state is not directly set by command-line switches  #  The following state is not directly set by command-line switches
671  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 "
672  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
673  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"
674  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
675    gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE"
676    
677  #  The following are all related to adjoint/tangent-linear stuff  #  The following are all related to adjoint/tangent-linear stuff
678  gm_s7="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"  gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
679  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"
680  gm_s9="TAF_EXTRA TAMC_EXTRA"  gm_s12="TAF_EXTRA TAMC_EXTRA"
681    
682  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7 $gm_s8 $gm_s9"  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"
683    gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
684    
685    cat <<EOF
686    
687    GENMAKE :
688    
689    A program for GENerating MAKEfiles for the MITgcm project.  For a
690    quick list of options, use "genmake -h" or for more detail see:
691    
692      http://mitgcm.org/devel_HOWTO/
693    
694    EOF
695    
 echo  
696  echo "===  Processing options files and arguments  ==="  echo "===  Processing options files and arguments  ==="
697  gm_local="genmake_local"  gm_local="genmake_local"
698  for i in . $MODS ; do  for i in . $MODS ; do
699      if test -r $i/$gm_local ; then      if test -r $i/$gm_local ; then
700          source $i/$gm_local          . $i/$gm_local
701          break          break
702      fi      fi
703  done  done
704  echo -n "  getting local config information:  "  printf "  getting local config information:  "
705  if test -e $gm_local ; then  if test -e $gm_local ; then
706      echo "using $gm_local"      echo "using $gm_local"
707      source $gm_local      . $gm_local
708      # echo "DISABLE=$DISABLE"      # echo "DISABLE=$DISABLE"
709      # echo "ENABLE=$ENABLE"      # echo "ENABLE=$ENABLE"
710  else  else
# Line 399  fi Line 725  fi
725  ac_prev=  ac_prev=
726  for ac_option ; do  for ac_option ; do
727    
728        G2ARGS="$G2ARGS \"$ac_option\""
729    
730      # If the previous option needs an argument, assign it.      # If the previous option needs an argument, assign it.
731      if test -n "$ac_prev"; then      if test -n "$ac_prev"; then
732          eval "$ac_prev=\$ac_option"          eval "$ac_prev=\$ac_option"
# Line 420  for ac_option ; do Line 748  for ac_option ; do
748          -optfile=* | --optfile=* | -of=* | --of=*)          -optfile=* | --optfile=* | -of=* | --of=*)
749              OPTFILE=$ac_optarg ;;              OPTFILE=$ac_optarg ;;
750                    
751          -adoptfile | --adoptfile | -ad | --ad)          -adoptfile | --adoptfile | -adof | --adof)
752              ac_prev=AD_OPTFILE ;;              ac_prev=AD_OPTFILE ;;
753          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
754              AD_OPTFILE=$ac_optarg ;;              AD_OPTFILE=$ac_optarg ;;
# Line 440  for ac_option ; do Line 768  for ac_option ; do
768          -make=* | --make=* | -m=* | --m=*)          -make=* | --make=* | -m=* | --m=*)
769              MAKE=$ac_optarg ;;              MAKE=$ac_optarg ;;
770                    
771            -bash | --bash)
772                ac_prev=BASH ;;
773            -bash=* | --bash=*)
774                BASH=$ac_optarg ;;
775            
776            -makedepend | --makedepend | -md | --md)
777                ac_prev=MAKEDEPEND ;;
778            -makedepend=* | --makedepend=* | -md=* | --md=*)
779                MAKEDEPEND=$ac_optarg ;;
780            
781          -makefile | --makefile | -ma | --ma)          -makefile | --makefile | -ma | --ma)
782              ac_prev=MAKEFILE ;;              ac_prev=MAKEFILE ;;
783          -makefile=* | --makefile=* | -ma=* | --ma=*)          -makefile=* | --makefile=* | -ma=* | --ma=*)
784              MAKEFILE=$ac_optarg ;;              MAKEFILE=$ac_optarg ;;
785                    
786          -platform | --platform | -pl | --pl)          -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
787              ac_prev=PLATFORM ;;              echo "ERROR: The platform option has been removed.  Please specify"
788          -platform=* | --platform=* | -pl=* | --pl=*)              echo "  the build options using the \"optfile\" mechanism."
789              PLATFORM=$ac_optarg ;;              echo
790                usage
791                ;;
792                    
793          -rootdir | --rootdir | -rd | --rd)          -rootdir | --rootdir | -rd | --rd)
794              ac_prev=ROOTDIR ;;              ac_prev=ROOTDIR ;;
# Line 475  for ac_option ; do Line 815  for ac_option ; do
815          -standarddirs=* | --standarddirs=*)          -standarddirs=* | --standarddirs=*)
816              STANDARDDIRS=$ac_optarg ;;              STANDARDDIRS=$ac_optarg ;;
817    
         -noopt | --noopt)  
             ac_prev=NOOPT ;;  
         -noopt=* | --noopt=*)  
             NOOPT=$ac_optarg ;;  
           
818  #           -cpp | --cpp)  #           -cpp | --cpp)
819  #               ac_prev=cpp ;;  #               ac_prev=cpp ;;
820  #           -cpp=* | --cpp=*)  #           -cpp=* | --cpp=*)
# Line 494  for ac_option ; do Line 829  for ac_option ; do
829              IEEE=true ;;              IEEE=true ;;
830          -noieee | --noieee)          -noieee | --noieee)
831              IEEE= ;;              IEEE= ;;
832            
833          -mpi | --mpi)          -mpi | --mpi)
834              MPI=true ;;              MPI=true ;;
835          -nompi | --nompi)          -mpi=* | --mpi=*)
836              MPI= ;;              MPIPATH=$ac_optarg
837                MPI=true ;;
838                    
839          -jam | --jam)  #       -jam | --jam)
840              JAM=1 ;;  #           JAM=1 ;;
841          -nojam | --nojam)  #       -nojam | --nojam)
842              JAM=0 ;;  #           JAM=0 ;;
843                    
844          -ds | --ds)          -ds | --ds)
845              DUMPSTATE=t ;;              DUMPSTATE=t ;;
# Line 551  if test "x${ROOTDIR}" = x ; then Line 887  if test "x${ROOTDIR}" = x ; then
887          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
888              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
889                  ROOTDIR=$d                  ROOTDIR=$d
890                  echo -n "Warning:  ROOTDIR was not specified but there appears to be"                  printf "Warning:  ROOTDIR was not specified but there appears to be"
891                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
892                  break                  break
893              fi              fi
# Line 582  fi Line 918  fi
918  if test "x$OPTFILE" != xNONE ; then  if test "x$OPTFILE" != xNONE ; then
919      if test -f "$OPTFILE" -a -r "$OPTFILE" ; then      if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
920          echo "    using OPTFILE=\"$OPTFILE\""          echo "    using OPTFILE=\"$OPTFILE\""
921          source "$OPTFILE"          . "$OPTFILE"
922          RETVAL=$?          RETVAL=$?
923          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
924              echo -n "Error: failed to source OPTFILE \"$OPTFILE\""              printf "Error: failed to source OPTFILE \"$OPTFILE\""
925              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
926              exit 1              exit 1
927          fi          fi
# Line 598  if test "x$OPTFILE" != xNONE ; then Line 934  if test "x$OPTFILE" != xNONE ; then
934      fi      fi
935  fi  fi
936    
937    #  Check for broken systems that cannot correctly distinguish *.F and *.f files
938    if test "x$FEXT" = x -a "x$F90EXT" = x ; then
939        check_for_broken_Ff
940    fi
941    
942  echo "  getting AD_OPTFILE information:  "  echo "  getting AD_OPTFILE information:  "
943  if test "x${AD_OPTFILE}" = x ; then  if test "x${AD_OPTFILE}" = x ; then
944      if test "x$MITGCM_AD_OF" = x ; then      if test "x$MITGCM_AD_OF" = x ; then
# Line 609  fi Line 950  fi
950  if test "x${AD_OPTFILE}" != xNONE ; then  if test "x${AD_OPTFILE}" != xNONE ; then
951      if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then      if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
952          echo "    using AD_OPTFILE=\"$AD_OPTFILE\""          echo "    using AD_OPTFILE=\"$AD_OPTFILE\""
953          source "$AD_OPTFILE"          . "$AD_OPTFILE"
954          RETVAL=$?          RETVAL=$?
955          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
956              echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""              printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
957              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
958              exit 1              exit 1
959          fi          fi
# Line 625  if test "x${AD_OPTFILE}" != xNONE ; then Line 966  if test "x${AD_OPTFILE}" != xNONE ; then
966      fi      fi
967  fi  fi
968    
969  #  Check that FC, LINK, CPP, and S64 are defined.  If not, complain  #  Check that FC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
970  #  and abort!  #  either set defaults or complain and abort!
971    if test ! "x$BASH" = x ; then
972        # add a trailing space so that it works within the Makefile syntax (see below)
973        BASH="$BASH "
974    fi
975  if test "x$FC" = x ; then  if test "x$FC" = x ; then
976      cat <<EOF 1>&2      cat <<EOF 1>&2
977    
# Line 640  fi Line 985  fi
985  if test "x$LINK" = x ; then  if test "x$LINK" = x ; then
986      LINK=$FC      LINK=$FC
987  fi  fi
988    if test "x$MAKE" = x ; then
989        MAKE="make"
990    fi
991  if test "x$CPP" = x ; then  if test "x$CPP" = x ; then
992      CPP="cpp"      CPP=cpp
993  fi  fi
994    #EH3 === UGLY ===
995    #  The following an ugly little hack to check for $CPP in /lib/ and it
996    #  should eventually be replaced with a more general function that
997    #  searches a combo of the user's path and a list of "usual suspects"
998    #  to find the correct location for binaries such as $CPP.
999    for i in " " "/lib/" ; do
1000        echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1001    done
1002    #EH3 === UGLY ===
1003  echo "#define A a" | $CPP > test_cpp 2>&1  echo "#define A a" | $CPP > test_cpp 2>&1
1004  RETVAL=$?  RETVAL=$?
1005  if test "x$RETVAL" != x0 ; then  if test "x$RETVAL" != x0 ; then
# Line 652  Error: C pre-processor "$CPP" failed the Line 1009  Error: C pre-processor "$CPP" failed the
1009    
1010    1) within the options file ("CPP=...") as specified by "-of=OPTFILE"    1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
1011    2) the "./genmake_local" file    2) the "./genmake_local" file
1012      3) with the CPP environment variable
1013    
1014  EOF  EOF
1015      exit 1      exit 1
# Line 661  fi Line 1019  fi
1019  if test "x$MAKEDEPEND" = x ; then  if test "x$MAKEDEPEND" = x ; then
1020      MAKEDEPEND=makedepend      MAKEDEPEND=makedepend
1021  fi  fi
1022    if test "x$LN" = x ; then
1023        LN="ln -s"
1024    fi
1025    echo "test" > genmake_test_ln
1026    $LN genmake_test_ln genmake_tlink
1027    RETVAL=$?
1028    if test "x$RETVAL" != x0 ; then
1029        cat <<EOF 1>&2
1030    
1031    Error: The command "ln -s" failed -- please specify a working soft-link
1032      command in the optfile.
1033    
1034    EOF
1035        exit 1
1036    fi
1037    rm -f genmake_test_ln genmake_tlink
1038    
1039    if test ! "x$MPI" = x ; then
1040          echo "  Turning on MPI cpp macros"
1041          DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
1042    fi
1043    
1044    printf "\n===  Checking system libraries  ===\n"
1045    printf "  Do we have the system() command using $FC...  "
1046    cat > genmake_tcomp.f <<EOF
1047          program hello
1048          call system('echo hi')
1049          end
1050    EOF
1051    $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1
1052    RETVAL=$?
1053    if test "x$RETVAL" = x0 ; then
1054        HAVE_SYSTEM=t
1055        DEFINES="$DEFINES -DHAVE_SYSTEM"
1056        echo "yes"
1057    else
1058        HAVE_SYSTEM=
1059        echo "no"
1060    fi
1061    rm -f genmake_tcomp*
1062    
1063    printf "  Do we have the fdate() command using $FC...  "
1064    cat > genmake_tcomp.f <<EOF
1065          program hello
1066          CHARACTER(128) string
1067          string = ' '
1068          call fdate( string )
1069          print *, string
1070          end
1071    EOF
1072    $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1
1073    RETVAL=$?
1074    if test "x$RETVAL" = x0 ; then
1075        HAVE_FDATE=t
1076        DEFINES="$DEFINES -DHAVE_FDATE"
1077        echo "yes"
1078    else
1079        HAVE_FDATE=
1080        echo "no"
1081    fi
1082    rm -f genmake_tcomp*
1083    
1084    printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
1085    check_HAVE_CLOC
1086    if test "x$HAVE_CLOC" != x ; then
1087        echo "yes"
1088    else
1089        echo "no"
1090    fi
1091    rm -f genmake_t*
1092    
1093    printf "  Can we create NetCDF-enabled binaries...  "
1094    check_netcdf_libs
1095    if test "x$HAVE_NETCDF" != x ; then
1096        echo "yes"
1097    else
1098        echo "no"
1099    fi
1100    
1101    
1102  printf "\n===  Setting defaults  ===\n"  printf "\n===  Setting defaults  ===\n"
1103  echo -n "  Adding MODS directories:  "  printf "  Adding MODS directories:  "
1104  for d in $MODS ; do  for d in $MODS ; do
1105      if test ! -d $d ; then      if test ! -d $d ; then
1106          echo          echo
1107          echo "Error: MODS directory \"$d\" not found!"          echo "Error: MODS directory \"$d\" not found!"
1108          exit 1          exit 1
1109      else      else
1110          echo -n " $d"          printf " $d"
1111          SOURCEDIRS="$SOURCEDIRS $d"          SOURCEDIRS="$SOURCEDIRS $d"
1112          INCLUDEDIRS="$INCLUDEDIRS $d"          INCLUDEDIRS="$INCLUDEDIRS $d"
1113      fi      fi
# Line 700  if test "x${TOOLSDIR}" = x ; then Line 1137  if test "x${TOOLSDIR}" = x ; then
1137      TOOLSDIR="$ROOTDIR/tools"      TOOLSDIR="$ROOTDIR/tools"
1138  fi  fi
1139  if test ! -d ${TOOLSDIR} ; then  if test ! -d ${TOOLSDIR} ; then
1140      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
1141      exit 1      exit 1
1142  fi  fi
1143  if test "x$S64" = x ; then  if test "x$S64" = x ; then
1144      S64='$(TOOLSDIR)/set64bitConst.sh'      S64='$(TOOLSDIR)/set64bitConst.sh'
1145  fi  fi
1146    THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
1147    
1148  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1149    
# Line 714  EXECUTABLE=${EXECUTABLE:-mitgcmuv} Line 1152  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1152  #  they appear as regular source code  #  they appear as regular source code
1153  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
1154      echo "  Making source files in eesupp from templates"      echo "  Making source files in eesupp from templates"
1155      $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1      ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1
1156      RETVAL=$?      RETVAL=$?
1157      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
1158          rm -f make_eesupp.errors          rm -f make_eesupp.errors
1159      else      else
1160          echo "Error: problem encountered while building source files in eesupp:"          echo "Error: problem encountered while building source files in eesupp:"
1161          cat make_eesupp.errors          cat make_eesupp.errors 1>&2
1162          exit 1          exit 1
1163      fi      fi
1164  fi  fi
1165    
1166    #same for exch2
1167    if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then
1168        echo "  Making source files in exch2 from  templates"
1169        ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1
1170        RETVAL=$?
1171        if test "x${RETVAL}" = x0 ; then
1172            rm -f make_exch2.errors
1173        else
1174            echo "Error: problem encountered while building source files in exch2:"
1175            cat make_exch2.errors 1>&2
1176            exit 1
1177        fi
1178    fi
1179    
1180  printf "\n===  Determining package settings  ===\n"  printf "\n===  Determining package settings  ===\n"
1181  if  test "x${PDEPEND}" = x ; then  if  test "x${PDEPEND}" = x ; then
1182      tmp=$ROOTDIR"/pkg/pkg_depend"      tmp=$ROOTDIR"/pkg/pkg_depend"
# Line 751  if test ! "x${RETVAL}" = x0 ; then Line 1203  if test ! "x${RETVAL}" = x0 ; then
1203      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
1204      exit 1      exit 1
1205  fi  fi
1206  source ./.pd_tmp  . ./.pd_tmp
1207  rm -f ./.pd_tmp  rm -f ./.pd_tmp
1208    
1209  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"
1210  #  file should eventually be added so that, for convenience, one can  #  file should eventually be added so that, for convenience, one can
1211  #  specify groups of packages using names like "ocean" and "atmosphere".  #  specify groups of packages using names like "ocean" and "atmosphere".
1212  echo  -n "  checking default package list:  "  echo "  checking default package list:  "
1213  if test "x${PDEFAULT}" = x ; then  if test "x${PDEFAULT}" = x ; then
1214      for i in "." $MODS ; do      for i in "." $MODS ; do
1215          if test -r $i"/packages.conf" ; then          if test -r $i"/packages.conf" ; then
# Line 770  if test "x${PDEFAULT}" = x ; then Line 1222  if test "x${PDEFAULT}" = x ; then
1222      PDEFAULT="$ROOTDIR/pkg/pkg_default"      PDEFAULT="$ROOTDIR/pkg/pkg_default"
1223  fi  fi
1224  if test "x${PDEFAULT}" = xNONE ; then  if test "x${PDEFAULT}" = xNONE ; then
1225      echo "default packages file disabled"      echo "    default packages file disabled"
1226  else  else
1227      if test ! -r $PDEFAULT ; then      if test ! -r $PDEFAULT ; then
         echo ""  
1228          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""
1229      else      else
1230          echo "  using PDEFAULT=\"$PDEFAULT\""          echo "    using PDEFAULT=\"$PDEFAULT\""
1231          #  Strip the comments and add all the names          #  Strip the comments and add all the names
1232          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
1233          RETVAL=$?          RETVAL=$?
1234          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
1235              echo -n "Error: can't parse default package list "              printf "Error: can't parse default package list "
1236              echo "-- please check PDEFAULT=\"$PDEFAULT\""              echo "-- please check PDEFAULT=\"$PDEFAULT\""
1237              exit 1              exit 1
1238          fi          fi
# Line 789  else Line 1240  else
1240              PACKAGES="$PACKAGES $i"              PACKAGES="$PACKAGES $i"
1241          done          done
1242          echo "    before group expansion packages are: $PACKAGES"          echo "    before group expansion packages are: $PACKAGES"
1243          expand_pkg_groups          while ! expand_pkg_groups; do echo > /dev/null; done
1244          echo "    after group expansion packages are:  $PACKAGES"          echo "    after group expansion packages are:  $PACKAGES"
1245      fi      fi
1246  fi  fi
1247    
1248  echo "  applying DISABLE settings"  echo "  applying DISABLE settings"
1249    for i in $PACKAGES ; do
1250        echo $i >> ./.tmp_pack
1251    done
1252    for i in `grep  "-" ./.tmp_pack` ; do
1253        j=`echo $i | sed 's/[-]//'`
1254        DISABLE="$DISABLE $j"
1255    done
1256  pack=  pack=
1257  for p in $PACKAGES ; do  for p in $PACKAGES ; do
1258      addit="t"      addit="t"
# Line 811  PACKAGES="$pack" Line 1269  PACKAGES="$pack"
1269  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
1270  echo "" > ./.tmp_pack  echo "" > ./.tmp_pack
1271  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
1272    # Test if each explicitly referenced package exists
1273  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1274      if test ! -d "$ROOTDIR/pkg/$i" ; then      j=`echo $i | sed 's/[-+]//'`
1275        if test ! -d "$ROOTDIR/pkg/$j" ; then
1276          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
1277          exit 1          exit 1
1278      fi      fi
1279      echo $i >> ./.tmp_pack      echo $i >> ./.tmp_pack
1280  done  done
 pack=`cat ./.tmp_pack | sort | uniq`  
 rm -f ./.tmp_pack  
1281  PACKAGES=  PACKAGES=
1282  for i in $pack ; do  for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do
1283      PACKAGES="$PACKAGES $i"      PACKAGES="$PACKAGES $i"
1284  done  done
1285    rm -f ./.tmp_pack
1286  echo "    packages are:  $PACKAGES"  echo "    packages are:  $PACKAGES"
1287    
1288  echo "  applying package dependency rules"  echo "  applying package dependency rules"
# Line 909  for i in $PACKAGES ; do Line 1368  for i in $PACKAGES ; do
1368      fi      fi
1369  done  done
1370    
1371  #  This is compatible with the old genmake.  The "DISABLE_*" flags  #  Build MNC templates and check for ability to build and use NetCDF
1372  #  need to be replaced by the "ALLOW_*" flags set below.  echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1
1373  #  RETVAL=$?
1374  # echo -n "  Setting package-specific CPP flags:  "  if test "x$RETVAL" = x0 ; then
1375  # pkrm=( mom_fluxform mom_vecinv generic_advdiff )      ( cd $ROOTDIR"/pkg/mnc" && $MAKE templates ) > make_mnc.errors 2>&1
1376  # pkrmdef=( -DDISABLE_MOM_FLUXFORM -DDISABLE_MOM_VECINV -DDISABLE_GENERIC_ADVDIFF -DDISABLE_DEBUGMODE )      RETVAL=$?
1377  # echo -n "  "      if test "x${RETVAL}" = x0 ; then
1378  # i=0          rm -f make_mnc.errors
1379  # while test $i -lt "${#pkrm[@]}" ; do      else
1380  #     echo "$PACKAGES" | grep "${pk[$i]}" > /dev/null 2>&1          echo "Error: problem encountered while building source files in pkg/mnc:"
1381  #     RETVAL=$?          cat make_mnc.errors 1>&2
1382  #     if test "x$RETVAL" = x1 ; then          exit 1
1383  #       DEFINES="$DEFINES ${pkdef[$i]}"      fi
1384  #       echo -n " ${pkdef[$i]}"      if test "x$HAVE_NETCDF" != xt ; then
1385  #     fi          cat <<EOF
 #     i=$(( $i + 1 ))  
 # done  
 # echo  
   
 # Create a list of #define and #undef to enable/disable packages  
 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.  
1386    
1387  #ifndef PACKAGES_H  WARNING: the "mnc" package has been enabled but tests failed to
1388  #define PACKAGES_H    compile and/or execute NetCDF applications.  Please check that:
1389    
1390  C  Packages disabled by genmake:    1) NetCDF is installed for your compiler and
1391      2) the LIBS variable (within the 'optfile") specifies the correct
1392           NetCDF library to link against.
1393      
1394  EOF  EOF
1395        fi
1396    fi
1397    
1398    # Create a list of #define and #undef to enable/disable packages
1399    PACKAGES_DOT_H=PACKAGES_CONFIG.h
1400  #  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
1401  #  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
1402  #  file would eventually be split up so that all package-related #define  #  file would eventually be split up so that all package-related #define
1403  #  statements could be separated and handled only by genmake.  #  statements could be separated and handled only by genmake.
1404  names=`ls -1 "$ROOTDIR/pkg"`  names=`ls -1 "$ROOTDIR/pkg"`
1405  all_pack=  all_pack=
1406    DISABLED_PACKAGES=
1407  for n in $names ; do  for n in $names ; do
1408      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
1409          has_pack="f"          has_pack="f"
# Line 959  for n in $names ; do Line 1415  for n in $names ; do
1415          done          done
1416          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
1417              undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`
1418              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!!!  
   
1419          fi          fi
1420      fi      fi
1421  done  done
1422  cat <<EOF >>$PACKAGES_DOT_H".tmp"  ENABLED_PACKAGES=
   
 C  Packages enabled by genmake:  
 EOF  
1423  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1424      def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`      def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`
1425      echo "#define $def" >> $PACKAGES_DOT_H".tmp"      ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
1426  #eh3 DEFINES="$DEFINES -D$def"  #eh3 DEFINES="$DEFINES -D$def"
1427    
1428  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1429      case $i in      case $i in
1430          aim_v23)          aim_v23)
1431              echo "#define   ALLOW_AIM" >> $PACKAGES_DOT_H".tmp"              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
1432              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 :-)"  
1433              ;;              ;;
1434      esac      esac
1435  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1436    
1437  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  
1438    
1439  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS"
1440  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
1441  if test "x$STANDARDDIRS" = x ; then  if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
1442      STANDARDDIRS="eesupp model"      STANDARDDIRS="eesupp model"
1443  fi  fi
1444  for d in $STANDARDDIRS ; do  if test "x$STANDARDDIRS" != x ; then
1445      adr="$ROOTDIR/$d/src"      for d in $STANDARDDIRS ; do
1446      if test ! -d $adr ; then          adr="$ROOTDIR/$d/src"
1447          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""          if test ! -d $adr ; then
1448          echo "  is correct and that you correctly specified the STANDARDDIRS option"              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1449          exit 1              echo "  is correct and that you correctly specified the STANDARDDIRS option"
1450      else              exit 1
1451          SOURCEDIRS="$SOURCEDIRS $adr"          else
1452      fi              SOURCEDIRS="$SOURCEDIRS $adr"
1453      adr="$ROOTDIR/$d/inc"          fi
1454      if test ! -d $adr ; then          adr="$ROOTDIR/$d/inc"
1455          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""          if test ! -d $adr ; then
1456          echo "  is correct and that you correctly specified the STANDARDDIRS option"              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1457          exit 1              echo "  is correct and that you correctly specified the STANDARDDIRS option"
1458      else              exit 1
1459          INCLUDEDIRS="$INCLUDEDIRS $adr"          else
1460      fi              INCLUDEDIRS="$INCLUDEDIRS $adr"
1461  done          fi
1462        done
1463    fi
1464    
1465  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"
1466  echo "    of \"#define ALLOW_PKGNAME\"-type statements:"  echo "    of \"#define \"-type statements that are no longer allowed:"
1467  CPP_OPTIONS=  CPP_OPTIONS=
1468    CPP_EEOPTIONS=
1469  spaths=". $INCLUDEDIRS"  spaths=". $INCLUDEDIRS"
1470    names=`ls -1 "$ROOTDIR/pkg"`
1471  for i in $spaths ; do  for i in $spaths ; do
1472      try="$i/CPP_OPTIONS.h"      try="$i/CPP_OPTIONS.h"
1473      #  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  
1474          echo "    found CPP_OPTIONS=\"$try\""          echo "    found CPP_OPTIONS=\"$try\""
1475          CPP_OPTIONS="$try"          CPP_OPTIONS="$try"
1476          break          # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
1477            for n in $names ; do
1478                test_for_package_in_cpp_options $CPP_OPTIONS $n
1479            done
1480        fi
1481        try="$i/CPP_EEOPTIONS.h"
1482        if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
1483            echo "    found CPP_EEOPTIONS=\"$try\""
1484            # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
1485    #**** not yet enabled ****
1486    #        test_for_mpi_in_cpp_eeoptions $try
1487    #**** not yet enabled ****
1488            CPP_EEOPTIONS="$try"
1489      fi      fi
1490  done  done
1491  if test "x$CPP_OPTIONS" = x ; then  if test "x$CPP_OPTIONS" = x ; then
1492      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"
1493      exit 1      exit 1
1494  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  
   
1495    
1496  #  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
1497  #  compiler.  #  compiler.
# Line 1078  for i in $SOURCEDIRS ; do Line 1506  for i in $SOURCEDIRS ; do
1506      done      done
1507  done  done
1508    
 cat <<EOF > adjoint_sed  
 s/call adopen(/call adopen ( mythid,\\  
      \&           /g  
 s/call adclose(/call adclose( mythid,\\  
      \&           /g  
 s/call adread(/call adread ( mythid,\\  
      \&           /g  
 s/call adwrite(/call adwrite( mythid,\\  
      \&           /g  
   
 EOF  
1509    
1510  echo  echo
1511  echo "===  Creating the Makefile  ==="  echo "===  Creating the Makefile  ==="
# Line 1106  rm -rf .links.tmp Line 1523  rm -rf .links.tmp
1523  mkdir .links.tmp  mkdir .links.tmp
1524  echo "# This section creates symbolic links" > srclinks.tmp  echo "# This section creates symbolic links" > srclinks.tmp
1525  echo "" >> srclinks.tmp  echo "" >> srclinks.tmp
1526  echo -n 'SRCFILES = '    > srclist.inc  printf 'SRCFILES = '    > srclist.inc
1527  echo -n 'CSRCFILES = '   > csrclist.inc  printf 'CSRCFILES = '   > csrclist.inc
1528  echo -n 'F90SRCFILES = ' > f90srclist.inc  printf 'F90SRCFILES = ' > f90srclist.inc
1529  echo -n 'HEADERFILES = ' > hlist.inc  printf 'HEADERFILES = ' > hlist.inc
1530  echo -n 'AD_FLOW_FILES = ' > ad_flow_files.inc  printf 'AD_FLOW_FILES = ' > ad_flow_files.inc
1531  alldirs="$SOURCEDIRS $INCLUDEDIRS ."  alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1532  for d in $alldirs ; do  for d in $alldirs ; do
1533      deplist=      deplist=
# Line 1119  for d in $alldirs ; do Line 1536  for d in $alldirs ; do
1536      for sf in $sfiles ; do      for sf in $sfiles ; do
1537          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
1538              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
1539                    case $d/$sf in
1540                      ./$PACKAGES_DOT_H)
1541                            ;;
1542                      ./AD_CONFIG.h)
1543                            ;;
1544                      ./FC_NAMEMANGLE.h)
1545                            ;;
1546                      *)
1547                            touch .links.tmp/$sf
1548                            deplist="$deplist $sf"
1549                            ;;
1550                    esac
1551                  extn=`echo $sf | $AWK -F '.' '{print $NF}'`                  extn=`echo $sf | $AWK -F '.' '{print $NF}'`
                 touch .links.tmp/$sf  
                 deplist="$deplist $sf"  
1552                  case $extn in                  case $extn in
1553                      F)                      F)
1554                          echo    " \\"  >> srclist.inc                          echo    " \\"  >> srclist.inc
1555                          echo -n " $sf" >> srclist.inc                          printf " $sf" >> srclist.inc
1556                          ;;                          ;;
1557                      F90)                      F90)
1558                          echo    " \\"  >> f90srclist.inc                          echo    " \\"  >> f90srclist.inc
1559                          echo -n " $sf" >> f90srclist.inc                          printf " $sf" >> f90srclist.inc
1560                          ;;                          ;;
1561                      c)                      c)
1562                          echo    " \\"  >> csrclist.inc                          echo    " \\"  >> csrclist.inc
1563                          echo -n " $sf" >> csrclist.inc                          printf " $sf" >> csrclist.inc
1564                          ;;                          ;;
1565                      h)                      h)
1566                          echo    " \\"  >> hlist.inc                          echo    " \\"  >> hlist.inc
1567                          echo -n " $sf" >> hlist.inc                          printf " $sf" >> hlist.inc
1568                          ;;                          ;;
1569                      flow)                      flow)
1570                          echo    " \\"  >> ad_flow_files.inc                          echo    " \\"  >> ad_flow_files.inc
1571                          echo -n " $sf" >> ad_flow_files.inc                          printf " $sf" >> ad_flow_files.inc
1572                          ;;                          ;;
1573                  esac                  esac
1574              fi              fi
# Line 1170  echo "#    $MACHINE" >> $MAKEFILE Line 1597  echo "#    $MACHINE" >> $MAKEFILE
1597  echo "# This makefile was generated automatically on" >> $MAKEFILE  echo "# This makefile was generated automatically on" >> $MAKEFILE
1598  echo "#    $THISDATE" >> $MAKEFILE  echo "#    $THISDATE" >> $MAKEFILE
1599  echo "# by the command:" >> $MAKEFILE  echo "# by the command:" >> $MAKEFILE
1600  echo "#    $0 $@" >> $MAKEFILE  echo "#    $0 $G2ARGS" >> $MAKEFILE
1601  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
1602  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE
1603    
# Line 1179  EXE_FTL=$EXECUTABLE"_ftl" Line 1606  EXE_FTL=$EXECUTABLE"_ftl"
1606  EXE_SVD=$EXECUTABLE"_svd"  EXE_SVD=$EXECUTABLE"_svd"
1607    
1608  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
1609    #
1610    # OPTFILE="$OPTFILE"
1611  #  #
1612  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
1613  # SOURCEDIRS   : Directories containing the source (.F) files  # SOURCEDIRS   : Directories containing the source (.F) files
# Line 1212  EXE_AD      = ${EXE_AD} Line 1641  EXE_AD      = ${EXE_AD}
1641  EXE_FTL     = ${EXE_FTL}  EXE_FTL     = ${EXE_FTL}
1642  EXE_SVD     = ${EXE_SVD}  EXE_SVD     = ${EXE_SVD}
1643    
1644    ENABLED_PACKAGES = ${ENABLED_PACKAGES}
1645    DISABLED_PACKAGES = ${DISABLED_PACKAGES}
1646    
1647    # These files are created by Makefile
1648    SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h
1649    
1650  EOF  EOF
1651    
1652  #  Note: figure out some way to add Hyades JAM libraries here  #  Note: figure out some way to add Hyades JAM libraries here
# Line 1230  FC = ${FC} Line 1665  FC = ${FC}
1665  # Fortran compiler  # Fortran compiler
1666  F90C = ${F90C}  F90C = ${F90C}
1667  # Link editor  # Link editor
1668  LINK = ${LINK}  LINK = ${LINK} ${LDADD}
1669    
1670  # Defines for CPP  # Defines for CPP
1671  DEFINES = ${DEFINES}  DEFINES = ${DEFINES}
# Line 1262  cat csrclist.inc      >> $MAKEFILE Line 1697  cat csrclist.inc      >> $MAKEFILE
1697  cat f90srclist.inc    >> $MAKEFILE  cat f90srclist.inc    >> $MAKEFILE
1698  cat hlist.inc         >> $MAKEFILE  cat hlist.inc         >> $MAKEFILE
1699  cat ad_flow_files.inc >> $MAKEFILE  cat ad_flow_files.inc >> $MAKEFILE
1700  echo               >> $MAKEFILE  echo >> $MAKEFILE
1701  echo 'F77FILES =  $(SRCFILES:.F=.f)'                                           >> $MAKEFILE  echo 'F77FILES =  $(SRCFILES:.'$FEXT'=.f)'        >> $MAKEFILE
1702  echo 'F90FILES =  $(F90SRCFILES:.F90=.f90)'                                    >> $MAKEFILE  echo 'F90FILES =  $(F90SRCFILES:.'$F90EXT'=.f90)' >> $MAKEFILE
1703  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE  echo 'OBJFILES =  $(SRCFILES:.'$FEXT'=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.'$F90EXT'=.o)' >> $MAKEFILE
1704    echo >> $MAKEFILE
1705    echo '.SUFFIXES:' >> $MAKEFILE
1706    echo '.SUFFIXES: .o .f .p .'$FEXT' .c .'$F90EXT' .f90' >> $MAKEFILE
1707    
1708  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
1709  rm -f ad_flow_files.inc  rm -f ad_flow_files.inc
1710    
1711  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
1712    
 .SUFFIXES:  
 .SUFFIXES: .o .f .p .F .c .F90 .f90  
   
1713  all: \$(EXECUTABLE)  all: \$(EXECUTABLE)
1714  \$(EXECUTABLE): \$(OBJFILES)  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(OBJFILES)
1715            @echo Creating \$@ ...
1716          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
1717  depend:  depend:
1718          @make links          @make links
1719          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
1720          ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE)          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
1721            -rm -f makedepend.out
1722    
1723  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES)
1724    
1725  small_f: \$(F77FILES) \$(F90FILES)  small_f: \$(F77FILES) \$(F90FILES)
1726    
# Line 1292  output.txt: \$(EXECUTABLE) Line 1729  output.txt: \$(EXECUTABLE)
1729          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
1730    
1731  clean:  clean:
1732          -cat AD_CONFIG.template > AD_CONFIG.h          -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl} *.template
         -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}  
1733  Clean:  Clean:
1734          @make clean          @make clean
1735          @make cleanlinks          @make cleanlinks
1736          -rm -f Makefile.bak genmake_state genmake_*optfile make.log          -rm -f \$(SPECIAL_FILES)
1737            -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak
1738  CLEAN:  CLEAN:
1739          @make Clean          @make Clean
1740          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
# Line 1307  CLEAN: Line 1744  CLEAN:
1744    
1745  #eh3 Makefile: makefile  #eh3 Makefile: makefile
1746  makefile:  makefile:
1747          ${0} $@          $THIS_SCRIPT $G2ARGS
1748  cleanlinks:  cleanlinks:
1749          -find . -type l -exec rm {} \;          -find . -type l -exec rm {} \;
1750    
1751  # The normal chain of rules is (  .F - .f - .o  )  # Special targets ($SPECIAL_FILES) which are create by make
1752  .F.f:  ${PACKAGES_DOT_H}:
1753            @echo Creating \$@ ...
1754            @$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) > \$@
1755    AD_CONFIG.h:
1756            @echo Creating \$@ ...
1757            @$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 > \$@
1758    FC_NAMEMANGLE.h:
1759            @echo Creating \$@ ...
1760            echo "$FC_NAMEMANGLE" > \$@
1761    
1762    # The normal chain of rules is (  .$FEXT - .f - .o  )
1763    .$FEXT.f:
1764          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1765  .f.o:  .f.o:
1766          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
1767  .F90.f90:  .$F90EXT.f90:
1768          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1769  .f90.o:  .f90.o:
1770          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
1771  .c.o:  .c.o:
1772          \$(CC) \$(CFLAGS) -c \$<          \$(CC) \$(CFLAGS) -c \$<
1773    
1774  # Special exceptions that use the ( .F - .p - .f - .o ) rule-chain  # Special exceptions that use the ( .$FEXT - .p - .f - .o ) rule-chain
1775  .F.p:  .$FEXT.p:
1776          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1777  .p.f:  .p.f:
1778          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
# Line 1353  done Line 1801  done
1801    
1802  echo "  Add the source list for AD code generation"  echo "  Add the source list for AD code generation"
1803  echo >> $MAKEFILE  echo >> $MAKEFILE
1804  echo -n "AD_FILES = " >> $MAKEFILE  printf "AD_FILES = " >> $MAKEFILE
1805  AD_FILES=`cat ad_files`  AD_FILES=`cat ad_files`
1806  for i in $AD_FILES ; do  for i in $AD_FILES ; do
1807      echo    " \\" >> $MAKEFILE      echo    " \\" >> $MAKEFILE
1808      echo -n " $i" >> $MAKEFILE      printf " $i" >> $MAKEFILE
1809  done  done
1810  echo >> $MAKEFILE  echo >> $MAKEFILE
1811  rm -f ad_files  rm -f ad_files
# Line 1369  adall: ad_taf Line 1817  adall: ad_taf
1817  adtaf: ad_taf_output.f  adtaf: ad_taf_output.f
1818  adtamc: ad_tamc_output.f  adtamc: ad_tamc_output.f
1819    
1820  ad_input_code.f: \$(SRCFILES) \$(HEADERFILES)  ad_input_code.f: \$(AD_FILES) \$(HEADERFILES)
1821            @$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
1822          cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h          cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
1823            -rm -f ad_config.template
1824          @make \$(F77FILES)          @make \$(F77FILES)
1825          @make \$(AD_FLOW_FILES)          @make \$(AD_FLOW_FILES)
1826          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f
1827    
1828  ad_taf_output.f: ad_input_code.f  ad_taf_output.f: ad_input_code.f
1829          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1830          cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f          cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f
1831    
1832    adtafonly:
1833            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1834            cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f
1835    
1836  ad_taf: ad_taf_output.o \$(OBJFILES)  ad_taf: ad_taf_output.o \$(OBJFILES)
1837          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
1838    
1839  ad_tamc_output.f: ad_input_code.f  ad_tamc_output.f: ad_input_code.f
1840          \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f          \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f
1841          cat ad_input_code_ad.f | sed -f adjoint_sed > ad_tamc_output.f          cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.f
1842    
1843  ad_tamc: ad_tamc_output.o \$(OBJFILES)  ad_tamc: ad_tamc_output.o \$(OBJFILES)
1844          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
# Line 1395  ftlall: ftl_taf Line 1849  ftlall: ftl_taf
1849  ftltaf: ftl_taf_output.f  ftltaf: ftl_taf_output.f
1850  ftltamc: ftl_tamc_output.f  ftltamc: ftl_tamc_output.f
1851    
1852  ftl_input_code.f: \$(SRCFILES)  ftl_input_code.f: \$(AD_FILES) \$(HEADERFILES)
1853            @$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
1854          cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h          cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
1855            -rm -f ftl_config.template
1856          @make \$(F77FILES)          @make \$(F77FILES)
1857          @make \$(AD_FLOW_FILES)          @make \$(AD_FLOW_FILES)
1858          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f
1859    
1860  ftl_taf_output.f: ftl_input_code.f  ftl_taf_output.f: ftl_input_code.f
1861          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f
1862          cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_taf_output.f          cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f
1863    
1864    ftltafonly:
1865            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f
1866            cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f
1867    
1868  ftl_taf: ftl_taf_output.o \$(OBJFILES)  ftl_taf: ftl_taf_output.o \$(OBJFILES)
1869          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
1870    
1871  ftl_tamc_output.f: ftl_input_code.f  ftl_tamc_output.f: ftl_input_code.f
1872          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f
1873          cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_tamc_output.f          cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.f
1874    
1875  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
1876          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
1877    
1878    
1879  # ... SVD ...  # ... SVD ...
1880  svd: svd_taf  svdtaf: ad_taf_output.f ftl_taf_output.f
1881  svd_taf_f: svd_taf_output.f  svdall: svd_taf
   
 svd_input_code.f: \$(SRCFILES)  
         cmp svd_config.template AD_CONFIG.h || cat svd_config.template > AD_CONFIG.h  
         @make \$(F77FILES)  
         @make \$(AD_FLOW_FILES)  
         cat \$(AD_FLOW_FILES) \$(AD_FILES) > svd_input_code.f  
1882    
1883  svd_taf_output.f: svd_input_code.f  svd_taf: ad_taf_output.o ftl_taf_output.o \$(OBJFILES)
1884          \$(TAF) \$(SVD_TAF_FLAGS) \$(TAF_EXTRA) svd_input_code.f          \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
         cat svd_input_code_ad.f | sed -f adjoint_sed > svd_taf_output.f  
   
 svd_taf: svd_taf_output.o \$(OBJFILES)  
         \$(LINK) -o ${EXE_SVD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) svd_taf_output.o \$(LIBS)  
1885    
1886    
1887  #=========================================  #=========================================
# Line 1472  printf "\n\n# DO NOT DELETE\n" >> $MAKEF Line 1922  printf "\n\n# DO NOT DELETE\n" >> $MAKEF
1922    
1923  printf "\n===  Done  ===\n"  printf "\n===  Done  ===\n"
1924    
1925  #  Write the "template" files for the adjoint builds  # Create special header files
1926  cat >AD_CONFIG.template <<EOF  $BASH $TOOLSDIR/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" $DISABLED_PACKAGES " " "Enabled packages:" $ENABLED_PACKAGES > $PACKAGES_DOT_H".tmp"
1927  C  WARNING: This file is automatically generated by genmake2 and  if test ! -f $PACKAGES_DOT_H ; then
1928  C    used by the Makefile rules.  Please DO NOT EDIT this file      mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
1929  C    unless you are CERTAIN that you know what you are doing.  else
1930        cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
1931  #undef ALLOW_ADJOINT_RUN      RETVAL=$?
1932  #undef ALLOW_TANGENTLINEAR_RUN      if test "x$RETVAL" = x0 ; then
1933  #undef ALLOW_ECCO_OPTIMIZATION          rm -f $PACKAGES_DOT_H".tmp"
1934  EOF      else
1935  cat >ad_config.template <<EOF          mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
1936  C  WARNING: This file is automatically generated by genmake2 and          mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
1937  C    used by the Makefile rules.  Please DO NOT EDIT this file      fi
1938  C    unless you are CERTAIN that you know what you are doing.  fi
1939    if test ! -f AD_CONFIG.h ; then
1940  #define ALLOW_ADJOINT_RUN      $BASH $TOOLSDIR/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > AD_CONFIG.h
1941  #undef ALLOW_TANGENTLINEAR_RUN  fi
 #undef ALLOW_ECCO_OPTIMIZATION  
 EOF  
 cat >ftl_config.template <<EOF  
 C  WARNING: This file is automatically generated by genmake2 and  
 C    used by the Makefile rules.  Please DO NOT EDIT this file  
 C    unless you are CERTAIN that you know what you are doing.  
   
 #undef ALLOW_ADJOINT_RUN  
 #define ALLOW_TANGENTLINEAR_RUN  
 #undef ALLOW_ECCO_OPTIMIZATION  
 EOF  
 cat >svd_config.template <<EOF  
 C  WARNING: This file is automatically generated by genmake2 and  
 C    used by the Makefile rules.  Please DO NOT EDIT this file  
 C    unless you are CERTAIN that you know what you are doing.  
   
 #undef ALLOW_ADJOINT_RUN  
 #undef ALLOW_TANGENTLINEAR_RUN  
 #undef ALLOW_ECCO_OPTIMIZATION  
 EOF  
 cp AD_CONFIG.template AD_CONFIG.h  
1942    
1943    
1944  #  Write the "state" for future records  #  Write the "state" for future records
1945  if test "x$DUMPSTATE" != xf ; then  if test "x$DUMPSTATE" != xf ; then
1946      echo -n "" > genmake_state      printf "" > genmake_state
1947      for i in $gm_state ; do      for i in $gm_state ; do
1948          t1="t2=\$$i"          t1="t2=\$$i"
1949          eval $t1          eval $t1

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.75

  ViewVC Help
Powered by ViewVC 1.1.22