/[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.36 by edhill, Fri Nov 14 02:48:18 2003 UTC revision 1.76 by edhill, Thu Apr 8 21:32:11 2004 UTC
# Line 1  Line 1 
1  #!/bin/sh  #! /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='fs'
101                FS90='fs90'
102                check_for_broken_Ff
103            else
104                cat <<EOF 2>&1
105    ERROR: Your file system cannot distinguish between *.F and *.f files
106      (fails the "cp" test) and this program cannot find a suitable
107      replacement extension.  Please try a different build environment or
108      contact the <MITgcm-support@mitgcm.org> list for help.
109    
110    EOF
111                exit -1
112            fi
113            return
114        fi
115        rm -f genmake_hello.*
116    
117        #  Check the ability of ${MAKE} and ${LN} to use the current set
118        #  of extensions.
119        cat <<EOF >> genmake_hello.F
120          program hello
121          write(*,*) 'hi'
122          stop
123          end
124    EOF
125        test -e Makefile  &&  mv -f Makefile Makefile.bak
126        cat <<EOF >> Makefile
127    .SUFFIXES:
128    genmake_hello.$tfs: genmake_hello.F
129            $LN genmake_hello.F genmake_hello.$tfs
130    EOF
131        $MAKE "genmake_hello."$tfs > /dev/null 2>&1
132        RETVAL=$?
133        if test "x$RETVAL" != x0 -o ! -e "genmake_hello."$tfs ; then
134            if test "x$FS" = x ; then
135                FS='fs'
136                FS90='fs9'
137                check_for_broken_Ff
138            else
139                cat <<EOF 2>&1
140    ERROR: Your file system cannot distinguish between *.F and *.f files
141      (fails the "make/ln" test) and this program cannot find a suitable
142      replacement extension.  Please try a different build environment or
143      contact the <MITgcm-support@mitgcm.org> list for help.
144    
145    EOF
146                exit -1
147                return
148            fi
149        fi
150        rm -f genmake_hello.* Makefile
151        test -e Makefile  &&  mv -f Makefile.bak Makefile
152    
153        #  If we make it here, use the extensions
154        FS=$tfs
155        FS90=$tfs9
156        return
157    }
158    
159    
160  # Guess possible config options for this host  # Guess possible config options for this host
161  find_possible_configs()  {  find_possible_configs()  {
162    
163      tmp1=`uname`"_"`uname -m`      tmp1=`uname`"_"`uname -m`
164      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
165      tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`      tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
166      PLATFORM=`echo $tmp3 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`      tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
167        tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
168        tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
169        PLATFORM=$tmp3
170      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
171      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  
172            
173      echo "test" > test      echo "test" > test
174      ln -s ./test link      ln -s ./test link
# Line 104  find_possible_configs()  { Line 186  find_possible_configs()  {
186          CPP="cpp -traditional -P"          CPP="cpp -traditional -P"
187      fi      fi
188    
189      # makedepend is not always available      #  The "original" makedepend is part of the Imake system that is
190        #  most often distributed with XFree86 or with an XFree86 source
191        #  package.  As a result, many machines (eg. generic Linux) do not
192        #  have a system-default "makedepend" available.  For those
193        #  systems, we have two fall-back options:
194        #
195        #    1) a makedepend implementation shipped with the cyrus-imapd
196        #       package:  ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
197        #
198        #    2) a known-buggy xmakedpend shell script
199        #
200        #  So the choices are, in order:
201        #
202        #    1) use the user-specified program
203        #    2) use a system-wide default
204        #    3) locally build and use the cyrus implementation
205        #    4) fall back to the buggy local xmakedpend script
206        #
207      if test "x${MAKEDEPEND}" = x ; then      if test "x${MAKEDEPEND}" = x ; then
208        which makedepend >& /dev/null        which makedepend > /dev/null 2>&1
209        RETVAL=$?        RETVAL=$?
210        if test "x${RETVAL}" = x1 ; then        if test ! "x${RETVAL}" = x0 ; then
211           echo "    makedepend was not found. Using xmakedpend instead."           echo "    a system-default makedepend was not found."
212           MAKEDEPEND='$(TOOLSDIR)/xmakedepend'  
213             #  Try to build the cyrus impl
214             rm -f ./genmake_cy_md
215             (
216                 cd $ROOTDIR/tools/cyrus-imapd-makedepend  \
217                     &&  ./configure > /dev/null 2>&1  \
218                     &&  make > /dev/null 2>&1  \
219                     &&  ./makedepend ifparser.c > /dev/null 2>&1  \
220                     &&  echo "true"
221             ) > ./genmake_cy_md
222             grep true ./genmake_cy_md > /dev/null 2>&1
223             RETVAL=$?
224             if test "x$RETVAL" = x0 ; then
225                 MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
226             else
227                 MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
228             fi
229             rm -f ./genmake_cy_md
230        fi        fi
231      fi      fi
232    
# Line 149  EOF Line 265  EOF
265          echo "   "$p_FC          echo "   "$p_FC
266          if test "x$FC" = x ; then          if test "x$FC" = x ; then
267              FC=`echo $p_FC | $AWK '{print $1}'`              FC=`echo $p_FC | $AWK '{print $1}'`
268                echo "  Setting FORTRAN compiler to: "$FC
269          fi          fi
270      fi      fi
271    
272      for i in $p_FC ; do      if test "x$OPTFILE" = x ; then
273          p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i          OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
274          if test -r $p_OF ; then          if test ! -r $OPTFILE ; then
275              OPTFILE=$p_OF               echo "  I looked for the file "$OPTFILE" but did not find it"
276              echo "  The options file:  $p_OF"          fi
277              echo "    appears to match so we'll use it."      fi
278              break  #    echo "  The options file:  $p_OF"
279          fi  #    echo "    appears to match so we'll use it."
280      done  #   for i in $p_FC ; do
281    #p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
282    #if test -r $p_OF ; then
283    #    OPTFILE=$p_OF
284    #    echo "  The options file:  $p_OF"
285    #    echo "    appears to match so we'll use it."
286    #    break
287    #fi
288    #   done
289      if test "x$OPTFILE" = x ; then      if test "x$OPTFILE" = x ; then
290          cat 1>&2 <<EOF          cat 1>&2 <<EOF
291    
# Line 219  get_pdepend_list()  { Line 344  get_pdepend_list()  {
344      . ./.pd_tmp      . ./.pd_tmp
345      rm -f ./.pd_tmp      rm -f ./.pd_tmp
346    
347      echo -n "PNAME = "${}      printf "PNAME = "${}
348  }  }
349    
350    
351  #  Explain usage  #  Explain usage
352  usage()  {  usage()  {
353      echo  cat <<EOF
354      echo "Usage: "$0" [OPTIONS]"  
355      echo "  where [OPTIONS] can be:"  Usage: "$0" [OPTIONS]
356      echo    where [OPTIONS] can be:
357      echo "    -help | --help | -h | --h"  
358      echo "    -nooptfile | --nooptfile"      -help | --help | -h | --h
359      echo "      -optfile NAME | --optfile NAME | -of NAME | --of NAME"            Print this help message and exit.
360      echo "      -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME"  
361      echo "    -pdepend NAME | --pdepend NAME"      -nooptfile | --nooptfile
362      echo "      -pdepend=NAME | --pdepend=NAME"        -optfile NAME | --optfile NAME | -of NAME | --of NAME
363      echo "    -pdefault NAME | --pdefault NAME"        -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
364      echo "      -pdefault=NAME | --pdefault=NAME"            Use "NAME" as the optfile.  By default, an attempt will be
365      echo "    -make NAME | -m NAME"            made to find an appropriate "standard" optfile in the
366      echo "      --make=NAME | -m=NAME"            tools/build_options/ directory.
367      echo "    -makefile NAME | -mf NAME"  
368      echo "      --makefile=NAME | -mf=NAME"      -pdepend NAME | --pdepend NAME
369      echo "    -platform NAME | --platform NAME | -pl NAME | --pl NAME"        -pdepend=NAME | --pdepend=NAME
370      echo "      -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"            Get package dependency information from "NAME".
371      echo "    -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"  
372      echo "      -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME"      -pdefault NAME | --pdefault NAME
373      echo "    -mods NAME | --mods NAME | -mo NAME | --mo NAME"        -pdefault=NAME | --pdefault=NAME
374      echo "      -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME"            Get the default package list from "NAME".
375      echo "    -disable NAME | --disable NAME"  
376      echo "      -disable=NAME | --disable=NAME"      -make NAME | -m NAME
377      echo "    -enable NAME | --enable NAME"        --make=NAME | -m=NAME
378      echo "      -enable=NAME | --enable=NAME"            Use "NAME" for the MAKE program. The default is "make" but
379      echo "    -standarddirs NAME | --standarddirs NAME"            many platforms, "gmake" is the preferred choice.
380      echo "      -standarddirs=NAME | --standarddirs=NAME"  
381      echo "    -noopt NAME | --noopt NAME"      -makefile NAME | -mf NAME
382      echo "      -noopt=NAME | --noopt=NAME"        --makefile=NAME | -mf=NAME
383  #    echo "    -cpp NAME | --cpp NAME"            Call the makefile "NAME".  The default is "Makefile".
384  #    echo "      -cpp=NAME | --cpp=NAME"  
385      echo "    -fortran NAME | --fortran NAME | -fc NAME | --fc NAME"      -makedepend NAME | -md NAME
386      echo "      -fc=NAME | --fc=NAME"        --makedepend=NAME | -md=NAME
387      echo "    -[no]ieee | --[no]ieee"            Use "NAME" for the MAKEDEPEND program.
388      echo "    -[no]mpi | --[no]mpi"  
389      echo "    -[no]jam | --[no]jam"      -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
390      echo        -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
391      echo "  and NAME is a string such as:"            Specify the location of the MITgcm ROOTDIR as "NAME".
392      echo            By default, genamke will try to find the location by
393      echo "    --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'"            looking in parent directories (up to the 5th parent).
394      echo "    -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'"  
395      echo "    -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"      -mods NAME | --mods NAME | -mo NAME | --mo NAME
396      echo        -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
397      echo "  which, depending upon your shell, may need to be single-quoted"            Here, "NAME" specifies a list of directories that are
398      echo "  if it contains spaces, dashes, or other special characters."            used for additional source code.  Files found in the
399              "mods list" are given preference over files of the same
400              name found elsewhere.
401    
402        -disable NAME | --disable NAME
403          -disable=NAME | --disable=NAME
404              Here "NAME" specifies a list of packages that we don't
405              want to use.  If this violates package dependencies,
406              genamke will exit with an error message.
407    
408        -enable NAME | --enable NAME
409          -enable=NAME | --enable=NAME
410              Here "NAME" specifies a list of packages that we wish
411              to specifically enable.  If this violates package
412              dependencies, genamke will exit with an error message.
413    
414        -standarddirs NAME | --standarddirs NAME
415          -standarddirs=NAME | --standarddirs=NAME
416              Here, "NAME" specifies a list of directories to be
417              used as the "standard" code.
418    
419        -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
420          -fc=NAME | --fc=NAME
421              Use "NAME" as the fortran compiler.  By default, genmake
422              will search for a working compiler by trying a list of
423              "usual suspects" such as g77, f77, etc.
424    
425        -[no]ieee | --[no]ieee
426              Do or don't use IEEE numerics.  Note that this option
427              *only* works if it is supported by the OPTFILE that
428              is being used.
429    
430        -mpi | --mpi
431              Include MPI header files and link to MPI libraries
432        -mpi=PATH | --mpi=PATH
433              Include MPI header files and link to MPI libraries using MPI_ROOT
434              set to PATH. i.e. Include files from $PATH/include, link to libraries
435              from $PATH/lib and use binaries from $PATH/bin.
436    
437        -bash NAME
438              Explicitly specify the Bourne or BASH shell to use
439    
440      While it is most often a single word, the "NAME" variables specified
441      above can in many cases be a space-delimited string such as:
442    
443        --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'
444        -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'
445        -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
446    
447      which, depending upon your shell, may need to be single-quoted.
448    
449      For more detailed genmake documentation, please see:
450    
451        http://mitgcm.org/devel_HOWTO/
452    
453    EOF
454    
455      exit 1      exit 1
456  }  }
457    
# Line 281  get_fortran_c_namemangling()  { Line 462  get_fortran_c_namemangling()  {
462      cat > genmake_test.c <<EOF      cat > genmake_test.c <<EOF
463  void tcall( char * string ) { tsub( string ); }  void tcall( char * string ) { tsub( string ); }
464  EOF  EOF
465      $MAKE genmake_test.o > genmake_test.log 2>&1      $MAKE genmake_test.o >> genmake_warnings 2>&1
466      RETVAL=$?      RETVAL=$?
467      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
         cat genmake_test.log >> genmake_errors  
468          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
469          echo          cat <<EOF>> genmake_errors
470          echo "WARNING: C test compile fails -- please see \"genmake_errors\""  
471          echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"  WARNING: C test compile fails
472          echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."  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          return 1
476      fi      fi
477      c_tcall=`nm genmake_test.o | grep tcall | cut -d ' ' -f 3`      c_tcall=`nm genmake_test.o | grep 'T ' | grep tcall | cut -d ' ' -f 3`
478      RETVAL=$?      RETVAL=$?
479      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
480          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
481          echo          cat <<EOF>> genmake_warnings
482          echo "WARNING: The \"nm\" command failed."  
483          echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"  WARNING: The "nm" command failed.
484          echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
485    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
486    EOF
487          return 1          return 1
488      fi      fi
489      cat > genmake_tcomp.f <<EOF      cat > genmake_tcomp.f <<EOF
# Line 308  EOF Line 492  EOF
492        call tsub( string )        call tsub( string )
493        end        end
494  EOF  EOF
495      $FC $FFLAGS $DEFINES -c genmake_tcomp.f > genmake_tcomp.log 2>&1      $FC $FFLAGS $DEFINES -c genmake_tcomp.f >> genmake_warnings 2>&1
496      RETVAL=$?      RETVAL=$?
497      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
         cat genmake_tcomp.log >> genmake_errors  
498          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
499          echo          cat <<EOF>> genmake_warnings
500          echo "WARNING: FORTRAN test compile fails -- please see \"genmake_errors\""  
501          echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"  WARNING: FORTRAN test compile fails -- please see "genmake_errors"
502          echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
503    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
504    EOF
505          return 1          return 1
506      fi      fi
507      f_tcall=`nm genmake_tcomp.o | grep tcall | cut -d ' ' -f 3`      f_tcall=`nm genmake_tcomp.o | grep 'T ' | grep tcall | cut -d ' ' -f 3`
508      RETVAL=$?      RETVAL=$?
509      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
510          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
511          echo          cat <<EOF>> genmake_warnings
512          echo "WARNING: The \"nm\" command failed."  
513          echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"  WARNING: The "nm" command failed.
514          echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
515    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
516    EOF
517          return 1          return 1
518      fi      fi
519    
# Line 353  EOF Line 540  EOF
540      rm -f genmake_tcomp.* genmake_test.*      rm -f genmake_tcomp.* genmake_test.*
541  }  }
542    
543    
544    check_HAVE_CLOC()  {
545        get_fortran_c_namemangling
546        cat <<EOF > genmake_tc_1.c
547    $FC_NAMEMANGLE
548    #include <stdio.h>
549    #include <stdlib.h>
550    #include <unistd.h>
551    #include <assert.h>
552    #include <sys/time.h>
553    void FC_NAMEMANGLE(cloc) ( double *curtim )
554    {
555     struct timeval tv1;
556     gettimeofday(&tv1 , (void *)NULL );
557     *curtim =  (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
558     *curtim = *curtim/1.E6;
559    }
560    EOF
561        make genmake_tc_1.o >> genmake_tc.log 2>&1
562        RET_C=$?
563        cat <<EOF > genmake_tc_2.f
564          program hello
565          Real*8 wtime
566          external cloc
567          call cloc(wtime)
568          print *," HELLO WORLD", wtime
569          end program hello
570    EOF
571        $FC $FFLAGS -o genmake_tc genmake_tc_2.f genmake_tc_1.o >> genmake_tc.log 2>&1
572        RET_F=$?
573        test -x ./genmake_tc  &&  ./genmake_tc >> genmake_tc.log 2>&1
574        RETVAL=$?
575        if test "x$RETVAL" = x0 ; then
576            HAVE_CLOC=t
577            DEFINES="$DEFINES -DHAVE_CLOC"
578        fi
579        rm -f genmake_tc*
580    }
581    
582    
583    check_netcdf_libs()  {
584        cat <<EOF > genmake_tnc.for
585          program fgennc
586    #include "netcdf.inc"
587          integer iret, ncid, xid
588          iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
589          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
590          iret = nf_def_dim(ncid, 'X', 11, xid)
591          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
592          iret = nf_close(ncid)
593          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
594          end
595    EOF
596        $CPP genmake_tnc.for > genmake_tnc.f  \
597            &&  $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f $LIBS >> genmake_tnc.log 2>&1
598        RET_COMPILE=$?
599        test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1
600        RETVAL=$?
601        if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
602            HAVE_NETCDF=t
603        else
604            # try again with "-lnetcdf" added to the libs
605            $CPP genmake_tnc.for > genmake_tnc.f  \
606                &&  $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f \
607                $LIBS -lnetcdf >> genmake_tnc_2.log 2>&1
608            RET_COMPILE=$?
609            test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1
610            RETVAL=$?
611            if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
612                LIBS="$LIBS -lnetcdf"
613                HAVE_NETCDF=t
614            else
615                cat genmake_tnc.log >> genmake_warnings
616            fi
617        fi
618        rm -f genmake_tnc*
619    }
620    
621    
622    
623    ###############################################################################
624    #   Sequential part of script starts here
625    ###############################################################################
626    
627  #  Set defaults here  #  Set defaults here
628  COMMANDL="$0 $@"  COMMANDL="$0 $@"
629    
# Line 361  LN= Line 632  LN=
632  S64=  S64=
633  KPP=  KPP=
634  FC=  FC=
635    CPP=
636  LINK=  LINK=
 # DEFINES="-DWORDLENGTH=4"  
637  DEFINES=  DEFINES=
638  PACKAGES=  PACKAGES=
639  ENABLE=  ENABLE=
# Line 379  FOPTIM= Line 650  FOPTIM=
650  CFLAGS=  CFLAGS=
651  KFLAGS1=  KFLAGS1=
652  KFLAGS2=  KFLAGS2=
653    #LDADD=
654  LIBS=  LIBS=
655  KPPFILES=  KPPFILES=
656  NOOPTFILES=  NOOPTFILES=
657  NOOPTFLAGS=  NOOPTFLAGS=
658    MPI=
659    MPIPATH=
660    
661  # DEFINES checked by test compilation  # DEFINES checked by test compilation
662  HAVE_SYSTEM=  HAVE_SYSTEM=
663  HAVE_FDATE=  HAVE_FDATE=
664  FC_NAMEMANGLE=  FC_NAMEMANGLE=
665    HAVE_CLOC=
666    HAVE_NETCDF=
667    
668  MODS=  MODS=
669  TOOLSDIR=  TOOLSDIR=
670  SOURCEDIRS=  SOURCEDIRS=
671  INCLUDEDIRS=  INCLUDEDIRS=
672  STANDARDDIRS=  STANDARDDIRS="USE_THE_DEFAULT"
673    
674    G2ARGS=
675    BASH=
676  PWD=`pwd`  PWD=`pwd`
677  MAKE=make  MAKE=make
678  AWK=awk  AWK=awk
# Line 410  IEEE= Line 688  IEEE=
688  if test "x$MITGCM_IEEE" != x ; then  if test "x$MITGCM_IEEE" != x ; then
689      IEEE=$MITGCM_IEEE      IEEE=$MITGCM_IEEE
690  fi  fi
691    FS=
692    FS90=
693    
694  AUTODIFF_PKG_USED=f  AUTODIFF_PKG_USED=f
695  AD_OPTFILE=  AD_OPTFILE=
# Line 426  TAMC_EXTRA= Line 706  TAMC_EXTRA=
706    
707    
708  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
709  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"
710  gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS"  gm_s2="FC CPP IEEE MPI JAM DUMPSTATE STANDARDDIRS"
711    
712  #  The following state is not directly set by command-line switches  #  The following state is not directly set by command-line switches
713  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 "
# Line 444  gm_s12="TAF_EXTRA TAMC_EXTRA" Line 724  gm_s12="TAF_EXTRA TAMC_EXTRA"
724  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"
725  gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"  gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
726    
727    cat <<EOF
728    
729    GENMAKE :
730    
731    A program for GENerating MAKEfiles for the MITgcm project.  For a
732    quick list of options, use "genmake -h" or for more detail see:
733    
734      http://mitgcm.org/devel_HOWTO/
735    
736    EOF
737    
 echo  
738  echo "===  Processing options files and arguments  ==="  echo "===  Processing options files and arguments  ==="
739  gm_local="genmake_local"  gm_local="genmake_local"
740  for i in . $MODS ; do  for i in . $MODS ; do
# Line 454  for i in . $MODS ; do Line 743  for i in . $MODS ; do
743          break          break
744      fi      fi
745  done  done
746  echo -n "  getting local config information:  "  printf "  getting local config information:  "
747  if test -e $gm_local ; then  if test -e $gm_local ; then
748      echo "using $gm_local"      echo "using $gm_local"
749      . $gm_local      . $gm_local
# Line 478  fi Line 767  fi
767  ac_prev=  ac_prev=
768  for ac_option ; do  for ac_option ; do
769    
770        G2ARGS="$G2ARGS \"$ac_option\""
771    
772      # If the previous option needs an argument, assign it.      # If the previous option needs an argument, assign it.
773      if test -n "$ac_prev"; then      if test -n "$ac_prev"; then
774          eval "$ac_prev=\$ac_option"          eval "$ac_prev=\$ac_option"
# Line 499  for ac_option ; do Line 790  for ac_option ; do
790          -optfile=* | --optfile=* | -of=* | --of=*)          -optfile=* | --optfile=* | -of=* | --of=*)
791              OPTFILE=$ac_optarg ;;              OPTFILE=$ac_optarg ;;
792                    
793          -adoptfile | --adoptfile | -ad | --ad)          -adoptfile | --adoptfile | -adof | --adof)
794              ac_prev=AD_OPTFILE ;;              ac_prev=AD_OPTFILE ;;
795          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
796              AD_OPTFILE=$ac_optarg ;;              AD_OPTFILE=$ac_optarg ;;
# Line 519  for ac_option ; do Line 810  for ac_option ; do
810          -make=* | --make=* | -m=* | --m=*)          -make=* | --make=* | -m=* | --m=*)
811              MAKE=$ac_optarg ;;              MAKE=$ac_optarg ;;
812                    
813            -bash | --bash)
814                ac_prev=BASH ;;
815            -bash=* | --bash=*)
816                BASH=$ac_optarg ;;
817            
818            -makedepend | --makedepend | -md | --md)
819                ac_prev=MAKEDEPEND ;;
820            -makedepend=* | --makedepend=* | -md=* | --md=*)
821                MAKEDEPEND=$ac_optarg ;;
822            
823          -makefile | --makefile | -ma | --ma)          -makefile | --makefile | -ma | --ma)
824              ac_prev=MAKEFILE ;;              ac_prev=MAKEFILE ;;
825          -makefile=* | --makefile=* | -ma=* | --ma=*)          -makefile=* | --makefile=* | -ma=* | --ma=*)
826              MAKEFILE=$ac_optarg ;;              MAKEFILE=$ac_optarg ;;
827                    
828          -platform | --platform | -pl | --pl)          -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
829              ac_prev=PLATFORM ;;              echo "ERROR: The platform option has been removed.  Please specify"
830          -platform=* | --platform=* | -pl=* | --pl=*)              echo "  the build options using the \"optfile\" mechanism."
831              PLATFORM=$ac_optarg ;;              echo
832                usage
833                ;;
834                    
835          -rootdir | --rootdir | -rd | --rd)          -rootdir | --rootdir | -rd | --rd)
836              ac_prev=ROOTDIR ;;              ac_prev=ROOTDIR ;;
# Line 554  for ac_option ; do Line 857  for ac_option ; do
857          -standarddirs=* | --standarddirs=*)          -standarddirs=* | --standarddirs=*)
858              STANDARDDIRS=$ac_optarg ;;              STANDARDDIRS=$ac_optarg ;;
859    
         -noopt | --noopt)  
             ac_prev=NOOPT ;;  
         -noopt=* | --noopt=*)  
             NOOPT=$ac_optarg ;;  
           
860  #           -cpp | --cpp)  #           -cpp | --cpp)
861  #               ac_prev=cpp ;;  #               ac_prev=cpp ;;
862  #           -cpp=* | --cpp=*)  #           -cpp=* | --cpp=*)
# Line 569  for ac_option ; do Line 867  for ac_option ; do
867          -fc=* | --fc=*)          -fc=* | --fc=*)
868              FC=$ac_optarg ;;              FC=$ac_optarg ;;
869                    
870            -fs | --fs)
871                ac_prev=FS ;;
872            -fs=* | --fs=*)
873                FS=$ac_optarg ;;
874            
875            -fs90 | --fs90)
876                ac_prev=FS90 ;;
877            -fs90=* | --fs90=*)
878                FS90=$ac_optarg ;;
879            
880          -ieee | --ieee)          -ieee | --ieee)
881              IEEE=true ;;              IEEE=true ;;
882          -noieee | --noieee)          -noieee | --noieee)
883              IEEE= ;;              IEEE= ;;
884            
885          -mpi | --mpi)          -mpi | --mpi)
886              MPI=true ;;              MPI=true ;;
887          -nompi | --nompi)          -mpi=* | --mpi=*)
888              MPI= ;;              MPIPATH=$ac_optarg
889                MPI=true ;;
890                    
891          -jam | --jam)  #       -jam | --jam)
892              JAM=1 ;;  #           JAM=1 ;;
893          -nojam | --nojam)  #       -nojam | --nojam)
894              JAM=0 ;;  #           JAM=0 ;;
895                    
896          -ds | --ds)          -ds | --ds)
897              DUMPSTATE=t ;;              DUMPSTATE=t ;;
# Line 630  if test "x${ROOTDIR}" = x ; then Line 939  if test "x${ROOTDIR}" = x ; then
939          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
940              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
941                  ROOTDIR=$d                  ROOTDIR=$d
942                  echo -n "Warning:  ROOTDIR was not specified but there appears to be"                  printf "Warning:  ROOTDIR was not specified but there appears to be"
943                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
944                  break                  break
945              fi              fi
# Line 664  if test "x$OPTFILE" != xNONE ; then Line 973  if test "x$OPTFILE" != xNONE ; then
973          . "$OPTFILE"          . "$OPTFILE"
974          RETVAL=$?          RETVAL=$?
975          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
976              echo -n "Error: failed to source OPTFILE \"$OPTFILE\""              printf "Error: failed to source OPTFILE \"$OPTFILE\""
977              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
978              exit 1              exit 1
979          fi          fi
# Line 677  if test "x$OPTFILE" != xNONE ; then Line 986  if test "x$OPTFILE" != xNONE ; then
986      fi      fi
987  fi  fi
988    
989    #  Check for broken systems that cannot correctly distinguish *.F and *.f files
990    check_for_broken_Ff
991    
992  echo "  getting AD_OPTFILE information:  "  echo "  getting AD_OPTFILE information:  "
993  if test "x${AD_OPTFILE}" = x ; then  if test "x${AD_OPTFILE}" = x ; then
994      if test "x$MITGCM_AD_OF" = x ; then      if test "x$MITGCM_AD_OF" = x ; then
# Line 691  if test "x${AD_OPTFILE}" != xNONE ; then Line 1003  if test "x${AD_OPTFILE}" != xNONE ; then
1003          . "$AD_OPTFILE"          . "$AD_OPTFILE"
1004          RETVAL=$?          RETVAL=$?
1005          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
1006              echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""              printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
1007              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1008              exit 1              exit 1
1009          fi          fi
# Line 704  if test "x${AD_OPTFILE}" != xNONE ; then Line 1016  if test "x${AD_OPTFILE}" != xNONE ; then
1016      fi      fi
1017  fi  fi
1018    
1019  #  Check that FC, LINK, CPP, S64, and LN are defined.  If not,  #  Check that FC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
1020  #  complain and abort!  #  either set defaults or complain and abort!
1021    if test ! "x$BASH" = x ; then
1022        # add a trailing space so that it works within the Makefile syntax (see below)
1023        BASH="$BASH "
1024    fi
1025  if test "x$FC" = x ; then  if test "x$FC" = x ; then
1026      cat <<EOF 1>&2      cat <<EOF 1>&2
1027    
# Line 719  fi Line 1035  fi
1035  if test "x$LINK" = x ; then  if test "x$LINK" = x ; then
1036      LINK=$FC      LINK=$FC
1037  fi  fi
1038    if test "x$MAKE" = x ; then
1039        MAKE="make"
1040    fi
1041  if test "x$CPP" = x ; then  if test "x$CPP" = x ; then
1042      CPP="cpp"      CPP=cpp
1043  fi  fi
1044    #EH3 === UGLY ===
1045    #  The following is an ugly little hack to check for $CPP in /lib/ and
1046    #  it should eventually be replaced with a more general function that
1047    #  searches a combo of the user's path and a list of "usual suspects"
1048    #  to find the correct location for binaries such as $CPP.
1049    for i in " " "/lib/" ; do
1050        echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1051    done
1052    #EH3 === UGLY ===
1053  echo "#define A a" | $CPP > test_cpp 2>&1  echo "#define A a" | $CPP > test_cpp 2>&1
1054  RETVAL=$?  RETVAL=$?
1055  if test "x$RETVAL" != x0 ; then  if test "x$RETVAL" != x0 ; then
# Line 758  EOF Line 1086  EOF
1086  fi  fi
1087  rm -f genmake_test_ln genmake_tlink  rm -f genmake_test_ln genmake_tlink
1088    
1089    if test ! "x$MPI" = x ; then
1090          echo "  Turning on MPI cpp macros"
1091          DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
1092    fi
1093    
1094  printf "\n===  Checking system libraries  ===\n"  printf "\n===  Checking system libraries  ===\n"
1095  echo -n "  Do we have the system() command using $FC...  "  printf "  Do we have the system() command using $FC...  "
1096  cat > genmake_tcomp.f <<EOF  cat > genmake_tcomp.f <<EOF
1097        program hello        program hello
1098        call system('echo hi')        call system('echo hi')
# Line 777  else Line 1110  else
1110  fi  fi
1111  rm -f genmake_tcomp*  rm -f genmake_tcomp*
1112    
1113  echo -n "  Do we have the fdate() command using $FC...  "  printf "  Do we have the fdate() command using $FC...  "
1114  cat > genmake_tcomp.f <<EOF  cat > genmake_tcomp.f <<EOF
1115        program hello        program hello
1116        CHARACTER(128) string        CHARACTER(128) string
# Line 798  else Line 1131  else
1131  fi  fi
1132  rm -f genmake_tcomp*  rm -f genmake_tcomp*
1133    
1134  echo "  The name mangling convention for $FC is...  "  printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
1135  #FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) X ## _"  check_HAVE_CLOC
1136  if test "x$FC_NAMEMANGLE" = x ; then  if test "x$HAVE_CLOC" != x ; then
1137      get_fortran_c_namemangling      echo "yes"
1138    else
1139        echo "no"
1140  fi  fi
1141  echo "    '$FC_NAMEMANGLE'"  rm -f genmake_t*
1142  echo "$FC_NAMEMANGLE" > FC_NAMEMANGLE.h.template  
1143  cmp FC_NAMEMANGLE.h FC_NAMEMANGLE.h.template > /dev/null 2>&1  printf "  Can we create NetCDF-enabled binaries...  "
1144  RETVAL=$?  check_netcdf_libs
1145  if test "x$RETVAL" != x0 ; then  if test "x$HAVE_NETCDF" != x ; then
1146      mv -f FC_NAMEMANGLE.h.template FC_NAMEMANGLE.h      echo "yes"
1147    else
1148        echo "no"
1149  fi  fi
1150    
1151    
1152  printf "\n===  Setting defaults  ===\n"  printf "\n===  Setting defaults  ===\n"
1153  echo -n "  Adding MODS directories:  "  printf "  Adding MODS directories:  "
1154  for d in $MODS ; do  for d in $MODS ; do
1155      if test ! -d $d ; then      if test ! -d $d ; then
1156          echo          echo
1157          echo "Error: MODS directory \"$d\" not found!"          echo "Error: MODS directory \"$d\" not found!"
1158          exit 1          exit 1
1159      else      else
1160          echo -n " $d"          printf " $d"
1161          SOURCEDIRS="$SOURCEDIRS $d"          SOURCEDIRS="$SOURCEDIRS $d"
1162          INCLUDEDIRS="$INCLUDEDIRS $d"          INCLUDEDIRS="$INCLUDEDIRS $d"
1163      fi      fi
# Line 850  if test "x${TOOLSDIR}" = x ; then Line 1187  if test "x${TOOLSDIR}" = x ; then
1187      TOOLSDIR="$ROOTDIR/tools"      TOOLSDIR="$ROOTDIR/tools"
1188  fi  fi
1189  if test ! -d ${TOOLSDIR} ; then  if test ! -d ${TOOLSDIR} ; then
1190      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
1191      exit 1      exit 1
1192  fi  fi
1193  if test "x$S64" = x ; then  if test "x$S64" = x ; then
1194      S64='$(TOOLSDIR)/set64bitConst.sh'      S64='$(TOOLSDIR)/set64bitConst.sh'
1195  fi  fi
1196    THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
1197    
1198  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1199    
# Line 870  if test -r $ROOTDIR"/eesupp/src/Makefile Line 1208  if test -r $ROOTDIR"/eesupp/src/Makefile
1208          rm -f make_eesupp.errors          rm -f make_eesupp.errors
1209      else      else
1210          echo "Error: problem encountered while building source files in eesupp:"          echo "Error: problem encountered while building source files in eesupp:"
1211          cat make_eesupp.errors          cat make_eesupp.errors 1>&2
1212          exit 1          exit 1
1213      fi      fi
1214  fi  fi
1215    
1216    #same for exch2
1217    if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then
1218        echo "  Making source files in exch2 from  templates"
1219        ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1
1220        RETVAL=$?
1221        if test "x${RETVAL}" = x0 ; then
1222            rm -f make_exch2.errors
1223        else
1224            echo "Error: problem encountered while building source files in exch2:"
1225            cat make_exch2.errors 1>&2
1226            exit 1
1227        fi
1228    fi
1229    
1230  printf "\n===  Determining package settings  ===\n"  printf "\n===  Determining package settings  ===\n"
1231  if  test "x${PDEPEND}" = x ; then  if  test "x${PDEPEND}" = x ; then
1232      tmp=$ROOTDIR"/pkg/pkg_depend"      tmp=$ROOTDIR"/pkg/pkg_depend"
# Line 907  rm -f ./.pd_tmp Line 1259  rm -f ./.pd_tmp
1259  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"
1260  #  file should eventually be added so that, for convenience, one can  #  file should eventually be added so that, for convenience, one can
1261  #  specify groups of packages using names like "ocean" and "atmosphere".  #  specify groups of packages using names like "ocean" and "atmosphere".
1262  echo  -n "  checking default package list:  "  echo "  checking default package list:  "
1263  if test "x${PDEFAULT}" = x ; then  if test "x${PDEFAULT}" = x ; then
1264      for i in "." $MODS ; do      for i in "." $MODS ; do
1265          if test -r $i"/packages.conf" ; then          if test -r $i"/packages.conf" ; then
# Line 920  if test "x${PDEFAULT}" = x ; then Line 1272  if test "x${PDEFAULT}" = x ; then
1272      PDEFAULT="$ROOTDIR/pkg/pkg_default"      PDEFAULT="$ROOTDIR/pkg/pkg_default"
1273  fi  fi
1274  if test "x${PDEFAULT}" = xNONE ; then  if test "x${PDEFAULT}" = xNONE ; then
1275      echo "default packages file disabled"      echo "    default packages file disabled"
1276  else  else
1277      if test ! -r $PDEFAULT ; then      if test ! -r $PDEFAULT ; then
         echo ""  
1278          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""
1279      else      else
1280          echo "  using PDEFAULT=\"$PDEFAULT\""          echo "    using PDEFAULT=\"$PDEFAULT\""
1281          #  Strip the comments and add all the names          #  Strip the comments and add all the names
1282          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
1283          RETVAL=$?          RETVAL=$?
1284          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
1285              echo -n "Error: can't parse default package list "              printf "Error: can't parse default package list "
1286              echo "-- please check PDEFAULT=\"$PDEFAULT\""              echo "-- please check PDEFAULT=\"$PDEFAULT\""
1287              exit 1              exit 1
1288          fi          fi
# Line 939  else Line 1290  else
1290              PACKAGES="$PACKAGES $i"              PACKAGES="$PACKAGES $i"
1291          done          done
1292          echo "    before group expansion packages are: $PACKAGES"          echo "    before group expansion packages are: $PACKAGES"
1293          expand_pkg_groups          while ! expand_pkg_groups; do echo > /dev/null; done
1294          echo "    after group expansion packages are:  $PACKAGES"          echo "    after group expansion packages are:  $PACKAGES"
1295      fi      fi
1296  fi  fi
1297    
1298  echo "  applying DISABLE settings"  echo "  applying DISABLE settings"
1299    for i in $PACKAGES ; do
1300        echo $i >> ./.tmp_pack
1301    done
1302    for i in `grep  "-" ./.tmp_pack` ; do
1303        j=`echo $i | sed 's/[-]//'`
1304        DISABLE="$DISABLE $j"
1305    done
1306  pack=  pack=
1307  for p in $PACKAGES ; do  for p in $PACKAGES ; do
1308      addit="t"      addit="t"
# Line 961  PACKAGES="$pack" Line 1319  PACKAGES="$pack"
1319  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
1320  echo "" > ./.tmp_pack  echo "" > ./.tmp_pack
1321  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
1322    # Test if each explicitly referenced package exists
1323  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1324      if test ! -d "$ROOTDIR/pkg/$i" ; then      j=`echo $i | sed 's/[-+]//'`
1325        if test ! -d "$ROOTDIR/pkg/$j" ; then
1326          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
1327          exit 1          exit 1
1328      fi      fi
1329      echo $i >> ./.tmp_pack      echo $i >> ./.tmp_pack
1330  done  done
 pack=`cat ./.tmp_pack | sort | uniq`  
 rm -f ./.tmp_pack  
1331  PACKAGES=  PACKAGES=
1332  for i in $pack ; do  for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do
1333      PACKAGES="$PACKAGES $i"      PACKAGES="$PACKAGES $i"
1334  done  done
1335    rm -f ./.tmp_pack
1336  echo "    packages are:  $PACKAGES"  echo "    packages are:  $PACKAGES"
1337    
1338  echo "  applying package dependency rules"  echo "  applying package dependency rules"
# Line 1059  for i in $PACKAGES ; do Line 1418  for i in $PACKAGES ; do
1418      fi      fi
1419  done  done
1420    
1421    #  Build MNC templates and check for ability to build and use NetCDF
1422    echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1
1423    RETVAL=$?
1424    if test "x$RETVAL" = x0 ; then
1425        ( cd $ROOTDIR"/pkg/mnc" && $MAKE templates ) > make_mnc.errors 2>&1
1426        RETVAL=$?
1427        if test "x${RETVAL}" = x0 ; then
1428            rm -f make_mnc.errors
1429        else
1430            echo "Error: problem encountered while building source files in pkg/mnc:"
1431            cat make_mnc.errors 1>&2
1432            exit 1
1433        fi
1434        if test "x$HAVE_NETCDF" != xt ; then
1435            cat <<EOF
1436    
1437  # Create a list of #define and #undef to enable/disable packages  WARNING: the "mnc" package has been enabled but tests failed to
1438  PACKAGES_DOT_H=PACKAGES_CONFIG.h    compile and/or execute NetCDF applications.  Please check that:
 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  
1439    
1440  C  Packages disabled by genmake:    1) NetCDF is installed for your compiler and
1441      2) the LIBS variable (within the 'optfile") specifies the correct
1442           NetCDF library to link against.
1443      
1444  EOF  EOF
1445        fi
1446    fi
1447    
1448    # Create a list of #define and #undef to enable/disable packages
1449    PACKAGES_DOT_H=PACKAGES_CONFIG.h
1450  #  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
1451  #  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
1452  #  file would eventually be split up so that all package-related #define  #  file would eventually be split up so that all package-related #define
1453  #  statements could be separated and handled only by genmake.  #  statements could be separated and handled only by genmake.
1454  names=`ls -1 "$ROOTDIR/pkg"`  names=`ls -1 "$ROOTDIR/pkg"`
1455  all_pack=  all_pack=
1456    DISABLED_PACKAGES=
1457  for n in $names ; do  for n in $names ; do
1458      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
1459          has_pack="f"          has_pack="f"
# Line 1091  for n in $names ; do Line 1465  for n in $names ; do
1465          done          done
1466          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
1467              undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`
1468              echo "#undef $undef" >> $PACKAGES_DOT_H".tmp"              DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
1469          fi          fi
1470      fi      fi
1471  done  done
1472  cat <<EOF >>$PACKAGES_DOT_H".tmp"  ENABLED_PACKAGES=
   
 C  Packages enabled by genmake:  
 EOF  
1473  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1474      def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`      def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`
1475      echo "#define $def" >> $PACKAGES_DOT_H".tmp"      ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
1476  #eh3 DEFINES="$DEFINES -D$def"  #eh3 DEFINES="$DEFINES -D$def"
1477    
1478  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1479      case $i in      case $i in
1480          aim_v23)          aim_v23)
1481              echo "#define   ALLOW_AIM" >> $PACKAGES_DOT_H".tmp"              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
1482              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 :-)"  
1483              ;;              ;;
1484      esac      esac
1485  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1486    
1487  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  
1488    
1489  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS"
1490  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
1491  if test "x$STANDARDDIRS" = x ; then  if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
1492      STANDARDDIRS="eesupp model"      STANDARDDIRS="eesupp model"
1493  fi  fi
1494  for d in $STANDARDDIRS ; do  if test "x$STANDARDDIRS" != x ; then
1495      adr="$ROOTDIR/$d/src"      for d in $STANDARDDIRS ; do
1496      if test ! -d $adr ; then          adr="$ROOTDIR/$d/src"
1497          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""          if test ! -d $adr ; then
1498          echo "  is correct and that you correctly specified the STANDARDDIRS option"              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1499          exit 1              echo "  is correct and that you correctly specified the STANDARDDIRS option"
1500      else              exit 1
1501          SOURCEDIRS="$SOURCEDIRS $adr"          else
1502      fi              SOURCEDIRS="$SOURCEDIRS $adr"
1503      adr="$ROOTDIR/$d/inc"          fi
1504      if test ! -d $adr ; then          adr="$ROOTDIR/$d/inc"
1505          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""          if test ! -d $adr ; then
1506          echo "  is correct and that you correctly specified the STANDARDDIRS option"              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1507          exit 1              echo "  is correct and that you correctly specified the STANDARDDIRS option"
1508      else              exit 1
1509          INCLUDEDIRS="$INCLUDEDIRS $adr"          else
1510      fi              INCLUDEDIRS="$INCLUDEDIRS $adr"
1511  done          fi
1512        done
1513    fi
1514    
1515  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"
1516  echo "    of \"#define ALLOW_PKGNAME\"-type statements:"  echo "    of \"#define \"-type statements that are no longer allowed:"
1517  CPP_OPTIONS=  CPP_OPTIONS=
1518    CPP_EEOPTIONS=
1519  spaths=". $INCLUDEDIRS"  spaths=". $INCLUDEDIRS"
1520    names=`ls -1 "$ROOTDIR/pkg"`
1521  for i in $spaths ; do  for i in $spaths ; do
1522      try="$i/CPP_OPTIONS.h"      try="$i/CPP_OPTIONS.h"
1523      #  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  
1524          echo "    found CPP_OPTIONS=\"$try\""          echo "    found CPP_OPTIONS=\"$try\""
1525          CPP_OPTIONS="$try"          CPP_OPTIONS="$try"
1526          break          # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
1527            for n in $names ; do
1528                test_for_package_in_cpp_options $CPP_OPTIONS $n
1529            done
1530        fi
1531        try="$i/CPP_EEOPTIONS.h"
1532        if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
1533            echo "    found CPP_EEOPTIONS=\"$try\""
1534            # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
1535    #**** not yet enabled ****
1536    #        test_for_mpi_in_cpp_eeoptions $try
1537    #**** not yet enabled ****
1538            CPP_EEOPTIONS="$try"
1539      fi      fi
1540  done  done
1541  if test "x$CPP_OPTIONS" = x ; then  if test "x$CPP_OPTIONS" = x ; then
1542      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"
1543      exit 1      exit 1
1544  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  
   
1545    
1546  #  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
1547  #  compiler.  #  compiler.
# Line 1194  for i in $SOURCEDIRS ; do Line 1556  for i in $SOURCEDIRS ; do
1556      done      done
1557  done  done
1558    
 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  
1559    
1560  echo  echo
1561  echo "===  Creating the Makefile  ==="  echo "===  Creating the Makefile  ==="
# Line 1222  rm -rf .links.tmp Line 1573  rm -rf .links.tmp
1573  mkdir .links.tmp  mkdir .links.tmp
1574  echo "# This section creates symbolic links" > srclinks.tmp  echo "# This section creates symbolic links" > srclinks.tmp
1575  echo "" >> srclinks.tmp  echo "" >> srclinks.tmp
1576  echo -n 'SRCFILES = '    > srclist.inc  printf 'SRCFILES = '    > srclist.inc
1577  echo -n 'CSRCFILES = '   > csrclist.inc  printf 'CSRCFILES = '   > csrclist.inc
1578  echo -n 'F90SRCFILES = ' > f90srclist.inc  printf 'F90SRCFILES = ' > f90srclist.inc
1579  echo -n 'HEADERFILES = ' > hlist.inc  printf 'HEADERFILES = ' > hlist.inc
1580  echo -n 'AD_FLOW_FILES = ' > ad_flow_files.inc  printf 'AD_FLOW_FILES = ' > ad_flow_files.inc
1581  alldirs="$SOURCEDIRS $INCLUDEDIRS ."  alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1582  for d in $alldirs ; do  for d in $alldirs ; do
1583      deplist=      deplist=
# Line 1235  for d in $alldirs ; do Line 1586  for d in $alldirs ; do
1586      for sf in $sfiles ; do      for sf in $sfiles ; do
1587          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
1588              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
1589                    case $d/$sf in
1590                      ./$PACKAGES_DOT_H)
1591                            ;;
1592                      ./AD_CONFIG.h)
1593                            ;;
1594                      ./FC_NAMEMANGLE.h)
1595                            ;;
1596                      *)
1597                            touch .links.tmp/$sf
1598                            deplist="$deplist $sf"
1599                            ;;
1600                    esac
1601                  extn=`echo $sf | $AWK -F '.' '{print $NF}'`                  extn=`echo $sf | $AWK -F '.' '{print $NF}'`
                 touch .links.tmp/$sf  
                 deplist="$deplist $sf"  
1602                  case $extn in                  case $extn in
1603                      F)                      F)
1604                          echo    " \\"  >> srclist.inc                          echo    " \\"  >> srclist.inc
1605                          echo -n " $sf" >> srclist.inc                          printf " $sf" >> srclist.inc
1606                          ;;                          ;;
1607                      F90)                      F90)
1608                          echo    " \\"  >> f90srclist.inc                          echo    " \\"  >> f90srclist.inc
1609                          echo -n " $sf" >> f90srclist.inc                          printf " $sf" >> f90srclist.inc
1610                          ;;                          ;;
1611                      c)                      c)
1612                          echo    " \\"  >> csrclist.inc                          echo    " \\"  >> csrclist.inc
1613                          echo -n " $sf" >> csrclist.inc                          printf " $sf" >> csrclist.inc
1614                          ;;                          ;;
1615                      h)                      h)
1616                          echo    " \\"  >> hlist.inc                          echo    " \\"  >> hlist.inc
1617                          echo -n " $sf" >> hlist.inc                          printf " $sf" >> hlist.inc
1618                          ;;                          ;;
1619                      flow)                      flow)
1620                          echo    " \\"  >> ad_flow_files.inc                          echo    " \\"  >> ad_flow_files.inc
1621                          echo -n " $sf" >> ad_flow_files.inc                          printf " $sf" >> ad_flow_files.inc
1622                          ;;                          ;;
1623                  esac                  esac
1624              fi              fi
# Line 1286  echo "#    $MACHINE" >> $MAKEFILE Line 1647  echo "#    $MACHINE" >> $MAKEFILE
1647  echo "# This makefile was generated automatically on" >> $MAKEFILE  echo "# This makefile was generated automatically on" >> $MAKEFILE
1648  echo "#    $THISDATE" >> $MAKEFILE  echo "#    $THISDATE" >> $MAKEFILE
1649  echo "# by the command:" >> $MAKEFILE  echo "# by the command:" >> $MAKEFILE
1650  echo "#    $0 $@" >> $MAKEFILE  echo "#    $0 $G2ARGS" >> $MAKEFILE
1651  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
1652  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE
1653    
# Line 1295  EXE_FTL=$EXECUTABLE"_ftl" Line 1656  EXE_FTL=$EXECUTABLE"_ftl"
1656  EXE_SVD=$EXECUTABLE"_svd"  EXE_SVD=$EXECUTABLE"_svd"
1657    
1658  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
1659    #
1660    # OPTFILE="$OPTFILE"
1661  #  #
1662  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
1663  # SOURCEDIRS   : Directories containing the source (.F) files  # SOURCEDIRS   : Directories containing the source (.F) files
# Line 1328  EXE_AD      = ${EXE_AD} Line 1691  EXE_AD      = ${EXE_AD}
1691  EXE_FTL     = ${EXE_FTL}  EXE_FTL     = ${EXE_FTL}
1692  EXE_SVD     = ${EXE_SVD}  EXE_SVD     = ${EXE_SVD}
1693    
1694    ENABLED_PACKAGES = ${ENABLED_PACKAGES}
1695    DISABLED_PACKAGES = ${DISABLED_PACKAGES}
1696    
1697    # These files are created by Makefile
1698    SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h
1699    
1700  EOF  EOF
1701    
1702  #  Note: figure out some way to add Hyades JAM libraries here  #  Note: figure out some way to add Hyades JAM libraries here
# Line 1346  FC = ${FC} Line 1715  FC = ${FC}
1715  # Fortran compiler  # Fortran compiler
1716  F90C = ${F90C}  F90C = ${F90C}
1717  # Link editor  # Link editor
1718  LINK = ${LINK}  LINK = ${LINK} ${LDADD}
1719    
1720  # Defines for CPP  # Defines for CPP
1721  DEFINES = ${DEFINES}  DEFINES = ${DEFINES}
# Line 1378  cat csrclist.inc      >> $MAKEFILE Line 1747  cat csrclist.inc      >> $MAKEFILE
1747  cat f90srclist.inc    >> $MAKEFILE  cat f90srclist.inc    >> $MAKEFILE
1748  cat hlist.inc         >> $MAKEFILE  cat hlist.inc         >> $MAKEFILE
1749  cat ad_flow_files.inc >> $MAKEFILE  cat ad_flow_files.inc >> $MAKEFILE
1750  echo               >> $MAKEFILE  echo >> $MAKEFILE
1751  echo 'F77FILES =  $(SRCFILES:.F=.f)'                                           >> $MAKEFILE  echo 'F77FILES =  $(SRCFILES:.F=.'$FS')'      >> $MAKEFILE
1752  echo 'F90FILES =  $(F90SRCFILES:.F90=.f90)'                                    >> $MAKEFILE  echo 'F90FILES =  $(F90SRCFILES:.F=.'$FS90')' >> $MAKEFILE
1753  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
1754    echo >> $MAKEFILE
1755    echo '.SUFFIXES:' >> $MAKEFILE
1756    echo '.SUFFIXES: .o .F .p .'$FS' .c .F90 .'$FS90 >> $MAKEFILE
1757  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
1758  rm -f ad_flow_files.inc  rm -f ad_flow_files.inc
1759    
1760  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
1761    
 .SUFFIXES:  
 .SUFFIXES: .o .f .p .F .c .F90 .f90  
   
1762  all: \$(EXECUTABLE)  all: \$(EXECUTABLE)
1763  \$(EXECUTABLE): \$(OBJFILES)  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(OBJFILES)
1764            @echo Creating \$@ ...
1765          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
1766  depend:  depend:
1767          @make links          @make links
1768          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
1769          ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE)          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
1770            -rm -f makedepend.out
1771    
1772  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES)
1773    
1774  small_f: \$(F77FILES) \$(F90FILES)  small_f: \$(F77FILES) \$(F90FILES)
1775    
# Line 1408  output.txt: \$(EXECUTABLE) Line 1778  output.txt: \$(EXECUTABLE)
1778          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
1779    
1780  clean:  clean:
1781          -cat AD_CONFIG.template > AD_CONFIG.h          -rm -rf *.o *.$FS *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
         -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}  
1782  Clean:  Clean:
1783          @make clean          @make clean
1784          @make cleanlinks          @make cleanlinks
1785          -rm -f Makefile.bak genmake_state genmake_*optfile make.log          -rm -f \$(SPECIAL_FILES)
1786            -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak
1787  CLEAN:  CLEAN:
1788          @make Clean          @make Clean
1789          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
# Line 1423  CLEAN: Line 1793  CLEAN:
1793    
1794  #eh3 Makefile: makefile  #eh3 Makefile: makefile
1795  makefile:  makefile:
1796          ${0} $@          $THIS_SCRIPT $G2ARGS
1797  cleanlinks:  cleanlinks:
1798          -find . -type l -exec rm {} \;          -find . -type l -exec rm {} \;
1799    
1800  # The normal chain of rules is (  .F - .f - .o  )  # Special targets ($SPECIAL_FILES) which are create by make
1801  .F.f:  ${PACKAGES_DOT_H}:
1802            @echo Creating \$@ ...
1803            @$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) > \$@
1804    AD_CONFIG.h:
1805            @echo Creating \$@ ...
1806            @$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 > \$@
1807    FC_NAMEMANGLE.h:
1808            @echo Creating \$@ ...
1809            echo "$FC_NAMEMANGLE" > \$@
1810    
1811    # The normal chain of rules is (  .F - .$FS - .o  )
1812    
1813    %.o : %.F
1814    
1815    .F.$FS:
1816          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1817  .f.o:  .$FS.o:
1818          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
1819  .F90.f90:  .F90.$FS90:
1820          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1821  .f90.o:  .$FS90.o:
1822          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
1823  .c.o:  .c.o:
1824          \$(CC) \$(CFLAGS) -c \$<          \$(CC) \$(CFLAGS) -c \$<
1825    
1826  # Special exceptions that use the ( .F - .p - .f - .o ) rule-chain  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
1827  .F.p:  .F.p:
1828          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1829  .p.f:  .p.$FS:
1830          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
1831    
1832  #=========================================  #=========================================
# Line 1469  done Line 1853  done
1853    
1854  echo "  Add the source list for AD code generation"  echo "  Add the source list for AD code generation"
1855  echo >> $MAKEFILE  echo >> $MAKEFILE
1856  echo -n "AD_FILES = " >> $MAKEFILE  printf "AD_FILES = " >> $MAKEFILE
1857  AD_FILES=`cat ad_files`  AD_FILES=`cat ad_files`
1858  for i in $AD_FILES ; do  for i in $AD_FILES ; do
1859      echo    " \\" >> $MAKEFILE      echo    " \\" >> $MAKEFILE
1860      echo -n " $i" >> $MAKEFILE      printf " $i" >> $MAKEFILE
1861  done  done
1862  echo >> $MAKEFILE  echo >> $MAKEFILE
1863  rm -f ad_files  rm -f ad_files
# Line 1486  adtaf: ad_taf_output.f Line 1870  adtaf: ad_taf_output.f
1870  adtamc: ad_tamc_output.f  adtamc: ad_tamc_output.f
1871    
1872  ad_input_code.f: \$(AD_FILES) \$(HEADERFILES)  ad_input_code.f: \$(AD_FILES) \$(HEADERFILES)
1873            @$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
1874          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
1875            -rm -f ad_config.template
1876          @make \$(F77FILES)          @make \$(F77FILES)
1877          @make \$(AD_FLOW_FILES)          @make \$(AD_FLOW_FILES)
1878          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f
1879    
1880  ad_taf_output.f: ad_input_code.f  ad_taf_output.f: ad_input_code.f
1881          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1882          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
1883    
1884    adtafonly:
1885            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1886            cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f
1887    
1888  ad_taf: ad_taf_output.o \$(OBJFILES)  ad_taf: ad_taf_output.o \$(OBJFILES)
1889          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
1890    
1891  ad_tamc_output.f: ad_input_code.f  ad_tamc_output.f: ad_input_code.f
1892          \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f          \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f
1893          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
1894    
1895  ad_tamc: ad_tamc_output.o \$(OBJFILES)  ad_tamc: ad_tamc_output.o \$(OBJFILES)
1896          \$(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 1512  ftltaf: ftl_taf_output.f Line 1902  ftltaf: ftl_taf_output.f
1902  ftltamc: ftl_tamc_output.f  ftltamc: ftl_tamc_output.f
1903    
1904  ftl_input_code.f: \$(AD_FILES) \$(HEADERFILES)  ftl_input_code.f: \$(AD_FILES) \$(HEADERFILES)
1905            @$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
1906          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
1907            -rm -f ftl_config.template
1908          @make \$(F77FILES)          @make \$(F77FILES)
1909          @make \$(AD_FLOW_FILES)          @make \$(AD_FLOW_FILES)
1910          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f
1911    
1912  ftl_taf_output.f: ftl_input_code.f  ftl_taf_output.f: ftl_input_code.f
1913          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f
1914          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
1915    
1916    ftltafonly:
1917            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f
1918            cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f
1919    
1920  ftl_taf: ftl_taf_output.o \$(OBJFILES)  ftl_taf: ftl_taf_output.o \$(OBJFILES)
1921          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
1922    
1923  ftl_tamc_output.f: ftl_input_code.f  ftl_tamc_output.f: ftl_input_code.f
1924          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f
1925          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
1926    
1927  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
1928          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
1929    
1930    
1931  # ... SVD ...  # ... SVD ...
1932  svd: svd_taf  svdtaf: ad_taf_output.f ftl_taf_output.f
1933  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  
1934    
1935  svd_taf_output.f: svd_input_code.f  svd_taf: ad_taf_output.o ftl_taf_output.o \$(OBJFILES)
1936          \$(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)  
1937    
1938    
1939  #=========================================  #=========================================
# Line 1565  for i in $KPPFILES ; do Line 1951  for i in $KPPFILES ; do
1951      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
1952          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
1953      fi      fi
1954      echo "$base.f: $base.p" >> $MAKEFILE      echo "$base.$FS: $base.p" >> $MAKEFILE
1955  done  done
1956    
1957  echo "  Making list of NOOPTFILES"  echo "  Making list of NOOPTFILES"
# Line 1575  for i in $NOOPTFILES ; do Line 1961  for i in $NOOPTFILES ; do
1961      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
1962          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
1963      fi      fi
1964      echo "$base.o: $base.f" >> $MAKEFILE      echo "$base.o: $base.$FS" >> $MAKEFILE
1965      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
1966  done  done
1967    
# Line 1588  printf "\n\n# DO NOT DELETE\n" >> $MAKEF Line 1974  printf "\n\n# DO NOT DELETE\n" >> $MAKEF
1974    
1975  printf "\n===  Done  ===\n"  printf "\n===  Done  ===\n"
1976    
1977  #  Write the "template" files for the adjoint builds  # Create special header files
1978  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"
1979  C  WARNING: This file is automatically generated by genmake2 and  if test ! -f $PACKAGES_DOT_H ; then
1980  C    used by the Makefile rules.  Please DO NOT EDIT this file      mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
1981  C    unless you are CERTAIN that you know what you are doing.  else
1982        cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
1983  #undef ALLOW_ADJOINT_RUN      RETVAL=$?
1984  #undef ALLOW_TANGENTLINEAR_RUN      if test "x$RETVAL" = x0 ; then
1985  #undef ALLOW_ECCO_OPTIMIZATION          rm -f $PACKAGES_DOT_H".tmp"
1986  EOF      else
1987  cat >ad_config.template <<EOF          mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
1988  C  WARNING: This file is automatically generated by genmake2 and          mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
1989  C    used by the Makefile rules.  Please DO NOT EDIT this file      fi
1990  C    unless you are CERTAIN that you know what you are doing.  fi
1991    if test ! -f AD_CONFIG.h ; then
1992  #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
1993  #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  
1994    
1995    
1996  #  Write the "state" for future records  #  Write the "state" for future records
1997  if test "x$DUMPSTATE" != xf ; then  if test "x$DUMPSTATE" != xf ; then
1998      echo -n "" > genmake_state      printf "" > genmake_state
1999      for i in $gm_state ; do      for i in $gm_state ; do
2000          t1="t2=\$$i"          t1="t2=\$$i"
2001          eval $t1          eval $t1

Legend:
Removed from v.1.36  
changed lines
  Added in v.1.76

  ViewVC Help
Powered by ViewVC 1.1.22