/[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.64 by edhill, Sun Jan 25 00:22:57 2004 UTC revision 1.146 by edhill, Fri Apr 7 02:53:55 2006 UTC
# 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      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg[ ]"
17      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg[ ]"
18      test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg[ ]"
19      test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg[ ]"
20        test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg$"
21        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg$"
22        test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg$"
23        test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg$"
24  }  }
25    
26  # Search for particular CPP #cmds associated with MPI  # Search for particular CPP #cmds associated with MPI
27  # usage: test_for_mpi_in_cpp_eeoptions CPP_file  # usage: test_for_mpi_in_cpp_eeoptions CPP_file
28  test_for_mpi_in_cpp_eeoptions() {  test_for_mpi_in_cpp_eeoptions() {
29      cpp_options=$1      cpp_options=$1
30      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI[ ]"
31      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI[ ]"
32      test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI[ ]"
33      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI" || exit 99      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI[ ]"
34        test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI$"
35        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI$"
36        test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI$"
37        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI$"
38  }  }
39    
40  # Search for particular string in a file. Return 1 if detected, 0 if not  # Search for particular string in a file. Return 1 if detected, 0 if not
# Line 37  test_for_string_in_file() { Line 45  test_for_string_in_file() {
45      grep -i "$strng" $file > /dev/null 2>&1      grep -i "$strng" $file > /dev/null 2>&1
46      RETVAL=$?      RETVAL=$?
47      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
48          echo -n "Error: In $file there is an illegal line: "          printf "Error: In $file there is an illegal line: "
49          grep -i "$strng" $file          grep -i "$strng" $file
50          return 1          exit 99
51      fi      fi
52      return 0      return 0
53  }  }
# Line 67  expand_pkg_groups() { Line 75  expand_pkg_groups() {
75          done          done
76          PACKAGES=$new_packages          PACKAGES=$new_packages
77          rm -f ./p[1,2].tmp          rm -f ./p[1,2].tmp
78            return $matched
79      else      else
80          echo "Warning: can't read package groups definition file: $PKG_GROUPS"          echo "Warning: can't read package groups definition file: $PKG_GROUPS"
81      fi      fi
82  }  }
83    
84    #  Check for broken environments (eg. cygwin, MacOSX w/HFS+) that
85    #  cannot distinguish [*.F/*.F90] from [*.f/*.f90] files.
86    check_for_broken_Ff()  {
87        #  Do we have defaults for $FS and/or $FS90 ?
88        tfs=f
89        tfs9=f90
90        if test "x$FS" != x ; then
91            tfs="$FS"
92        fi
93        if test "x$FS90" != x ; then
94            tfs9="$FS90"
95        fi
96    
97        #  First check the ability to create a *.F/.f pair.
98        cat <<EOF >> genmake_hello.F
99          program hello
100          write(*,*) 'hi'
101          stop
102          end
103    EOF
104        cp genmake_hello.F "genmake_hello."$tfs > /dev/null 2>&1
105        RETVAL=$?
106        if test "x$RETVAL" != x0 ; then
107            if test "x$FS" = x ; then
108                FS='for'
109                FS90='fr9'
110                check_for_broken_Ff
111            else
112                cat <<EOF 2>&1
113    ERROR: Your file system cannot distinguish between *.F and *.f files
114      (fails the "cp" test) and this program cannot find a suitable
115      replacement extension.  Please try a different build environment or
116      contact the <MITgcm-support@mitgcm.org> list for help.
117    
118    EOF
119                exit -1
120            fi
121            return
122        fi
123        rm -f genmake_hello.*
124    
125        #  Check the ability of ${MAKE} and ${LN} to use the current set
126        #  of extensions.
127        cat <<EOF >> genmake_hello.F
128          program hello
129          write(*,*) 'hi'
130          stop
131          end
132    EOF
133        test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
134        cat <<EOF >> $MAKEFILE
135    .SUFFIXES:
136    .SUFFIXES: .$tfs .F
137    .F.$tfs:
138            $LN \$< \$@
139    EOF
140        $MAKE "genmake_hello."$tfs > /dev/null 2>&1
141        RETVAL=$?
142        if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then
143            if test "x$FS" = x ; then
144                FS='for'
145                FS90='fr9'
146                check_for_broken_Ff
147            else
148                cat <<EOF 2>&1
149    ERROR: Your file system cannot distinguish between *.F and *.f files
150      (fails the "make/ln" test) and this program cannot find a suitable
151      replacement extension.  Please try a different build environment or
152      contact the <MITgcm-support@mitgcm.org> list for help.
153    
154    EOF
155                exit -1
156                return
157            fi
158        fi
159        rm -f genmake_hello.* $MAKEFILE
160        test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
161    
162        #  If we make it here, use the extensions
163        FS=$tfs
164        FS90=$tfs9
165        return
166    }
167    
168    
169    look_for_makedepend()  {
170    
171        #  The "original" makedepend is part of the Imake system that is
172        #  most often distributed with XFree86 or with an XFree86 source
173        #  package.  As a result, many machines (eg. generic Linux) do not
174        #  have a system-default "makedepend" available.  For those
175        #  systems, we have two fall-back options:
176        #
177        #    1) a makedepend implementation shipped with the cyrus-imapd
178        #       package:  ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
179        #
180        #    2) a known-buggy xmakedpend shell script
181        #
182        #  So the choices are, in order:
183        #
184        #    1) use the user-specified program
185        #    2) use a system-wide default
186        #    3) locally build and use the cyrus implementation
187        #    4) fall back to the buggy local xmakedpend script
188        #
189        if test "x${MAKEDEPEND}" = x ; then
190            which makedepend > /dev/null 2>&1
191            RV0=$?
192            test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
193            #  echo 'MAKEFILE="'$MAKEFILE'"'
194            cat <<EOF >> $MAKEFILE
195    #   THIS IS A TEST MAKEFILE GENERATED BY "genmake2"
196    #
197    #   Some "makedepend" implementations will die if they cannot
198    #   find a Makefile -- so this file is here to gives them an
199    #   empty one to find and parse.
200    EOF
201            cat <<EOF >> genmake_tc.f
202          program test
203          write(*,*) 'test'
204          stop
205          end
206    EOF
207            makedepend genmake_tc.f > /dev/null 2>&1
208            RV1=$?
209            test -f $MAKEFILE  &&  rm -f $MAKEFILE
210            test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
211            if test "x${RV0}${RV1}" = x00 ; then
212                MAKEDEPEND=makedepend
213            else
214                echo "    a system-default makedepend was not found."
215                
216                #  Try to build the cyrus implementation
217                build_cyrus_makedepend
218                RETVAL=$?
219                if test "x$RETVAL" != x0 ; then
220                    MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
221                fi
222                rm -f ./genmake_cy_md
223            fi
224        else
225            #  echo "MAKEDEPEND=${MAKEDEPEND}"
226            echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1
227            RETVAL=$?
228            if test x"$RETVAL" = x0 ; then
229                build_cyrus_makedepend
230            fi
231        fi
232    }
233    
234    
235    build_cyrus_makedepend()  {
236        rm -f ./genmake_cy_md
237        (
238            cd $ROOTDIR/tools/cyrus-imapd-makedepend  \
239                &&  ./configure > /dev/null 2>&1  \
240                &&  make > /dev/null 2>&1
241            if test -x ./makedepend.exe ; then
242                $LN ./makedepend.exe ./makedepend
243            fi
244            ./makedepend ifparser.c > /dev/null 2>&1  \
245                &&  echo "true"
246        ) > ./genmake_cy_md
247        grep true ./genmake_cy_md > /dev/null 2>&1
248        RETVAL=$?
249        rm -f ./genmake_cy_md
250        if test "x$RETVAL" = x0 ; then
251            MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
252            return 0
253        else
254            echo "WARNING: unable to build cyrus-imapd-makedepend"
255            return 1
256        fi
257    }
258    
259    
260    build_embed_encode()
261    {
262        printf "  building the embed-encode utility...  "
263        if test ! -e "$ROOTDIR/tools/embed_encode/encode_files" ; then
264            if test ! -d "$ROOTDIR/tools/embed_encode" ; then
265                echo
266                echo "    Error: can't locate \"$ROOTDIR/tools/embed_encode\""
267                echo
268                EMBED_SRC=f
269                return 1
270            fi
271            clist="cc gcc c89 $CC"
272            for ic in $clist ; do
273                comm="$ic -o encode_files encode_files.c"
274                ( cd $ROOTDIR/tools/embed_encode && $comm ) > /dev/null 2>&1
275                RETVAL=$?
276                if test "x$RETVAL" = x0 ; then
277                    echo "OK"
278                    DEFINES="$DEFINES -DHAVE_EMBED_SRC"
279                    return 0
280                fi
281            done
282            echo
283            echo "    Error: unable to build $ROOTDIR/embed_encode/encode_files"
284            echo "      so it has been disabled"
285            echo
286            EMBED_SRC=f
287            return 1
288        fi
289        echo "OK"
290        DEFINES="$DEFINES -DHAVE_EMBED_SRC"
291    }
292    
293    
294  # Guess possible config options for this host  # Guess possible config options for this host
295  find_possible_configs()  {  find_possible_configs()  {
296    
# Line 80  find_possible_configs()  { Line 299  find_possible_configs()  {
299      tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`      tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
300      tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`      tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
301      tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`      tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
302      PLATFORM=$tmp2      tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
303        PLATFORM=$tmp3
304        echo $PLATFORM | grep cygwin > /dev/null 2>&1  &&  PLATFORM=cygwin_ia32
305      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
306      echo "  The platform appears to be:  $PLATFORM"      echo "  The platform appears to be:  $PLATFORM"
307            
# Line 100  find_possible_configs()  { Line 321  find_possible_configs()  {
321          CPP="cpp -traditional -P"          CPP="cpp -traditional -P"
322      fi      fi
323    
324      # makedepend is not always available      look_for_makedepend
325      if test "x${MAKEDEPEND}" = x ; then  
326        which makedepend >& /dev/null      #================================================================
327        RETVAL=$?      #  look for possible C compilers
328        if test "x${RETVAL}" = x1 ; then      tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc"
329           echo "    makedepend was not found. Using xmakedpend instead."      p_CC=
330           MAKEDEPEND='$(TOOLSDIR)/xmakedepend'      for c in $tmp ; do
331        fi          rm -f ./genmake_hello.c  ./genmake_hello
332            cat >> genmake_hello.c << EOF
333    #include <stdio.h>
334    int main(int argc, char **argv) {
335      printf("Hello!\n");
336      return 0;
337    }
338    EOF
339            $c -o genmake_hello genmake_hello.c > /dev/null 2>&1
340            RETVAL=$?
341            if test "x${RETVAL}" = x0 ; then
342                p_CC="$p_CC $c"
343            fi
344        done
345        rm -f ./genmake_hello.c ./genmake_hello
346        if test "x${p_CC}" = x ; then
347            cat 1>&2 <<EOF
348    
349    Error: No C compilers were found in your path.  Please specify one using:
350    
351        1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
352        2) the CC or MITGCM_CC environment variables.
353    
354    EOF
355            exit 1
356        else
357            echo "  The possible C compilers found in your path are:"
358            echo "   "$p_CC
359            if test "x$CC" = x ; then
360                CC=`echo $p_CC | $AWK '{print $1}'`
361                echo "  Setting C compiler to: "$CC
362            fi
363      fi      fi
364    
365      # look for possible fortran compilers      #================================================================
366      tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"      #  look for possible FORTRAN compilers
367        tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 gfortran"
368      p_FC=      p_FC=
369      for c in $tmp ; do      for c in $tmp ; do
370          rm -f ./hello.f ./hello          rm -f ./hello.f ./hello
# Line 136  Error: No Fortran compilers were found i Line 389  Error: No Fortran compilers were found i
389    
390      1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),      1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
391      2) a command-line option (eg. "-fc NAME"), or      2) a command-line option (eg. "-fc NAME"), or
392      3) the MITGCM_FC environment variable.      3) the FC or MITGCM_FC environment variables.
393    
394  EOF  EOF
395          exit 1          exit 1
396      else      else
397          echo "  The possible FORTRAN compilers found in your path are:"          echo "  The possible FORTRAN compilers found in your path are:"
398          echo "   "$p_FC          echo "   "$p_FC
         if test "x$FC" = x ; then  
             FC=`echo $p_FC | $AWK '{print $1}'`  
         fi  
399      fi      fi
400    
401      for i in $p_FC ; do      #  Use the first of the compilers found in the current PATH
402          p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i      #  that has a correctly-named optfile
403          if test -r $p_OF ; then      if test "x$OPTFILE" = x  -a  "x$FC" = x ; then
404              OPTFILE=$p_OF          for i in $p_FC ; do
405              echo "  The options file:  $p_OF"              OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
406              echo "    appears to match so we'll use it."              if test -r $OPTFILE ; then
407              break                  echo "  Setting OPTFILE to: "$OPTFILE
408          fi                  break
409      done              fi
410            done
411        fi
412    
413        if test "x$OPTFILE" = x ; then
414            OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
415            if test ! -r $OPTFILE ; then
416                 echo "  I looked for the file "$OPTFILE" but did not find it"
417            fi
418        fi
419    #    echo "  The options file:  $p_OF"
420    #    echo "    appears to match so we'll use it."
421    #   for i in $p_FC ; do
422    #p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
423    #if test -r $p_OF ; then
424    #    OPTFILE=$p_OF
425    #    echo "  The options file:  $p_OF"
426    #    echo "    appears to match so we'll use it."
427    #    break
428    #fi
429    #   done
430      if test "x$OPTFILE" = x ; then      if test "x$OPTFILE" = x ; then
431          cat 1>&2 <<EOF          cat 1>&2 <<EOF
432    
# Line 215  get_pdepend_list()  { Line 485  get_pdepend_list()  {
485      . ./.pd_tmp      . ./.pd_tmp
486      rm -f ./.pd_tmp      rm -f ./.pd_tmp
487    
488      echo -n "PNAME = "${}      printf "PNAME = "${}
489  }  }
490    
491    
# Line 229  Usage: "$0" [OPTIONS] Line 499  Usage: "$0" [OPTIONS]
499      -help | --help | -h | --h      -help | --help | -h | --h
500            Print this help message and exit.            Print this help message and exit.
501    
502        -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME
503          -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME
504              Use "NAME" as the adoptfile.  By default, the file at
505              "tools/adjoint_options/adjoint_default" will be used.
506    
507      -nooptfile | --nooptfile      -nooptfile | --nooptfile
508        -optfile NAME | --optfile NAME | -of NAME | --of NAME        -optfile NAME | --optfile NAME | -of NAME | --of NAME
509        -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME        -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
# Line 253  Usage: "$0" [OPTIONS] Line 528  Usage: "$0" [OPTIONS]
528        --makefile=NAME | -mf=NAME        --makefile=NAME | -mf=NAME
529            Call the makefile "NAME".  The default is "Makefile".            Call the makefile "NAME".  The default is "Makefile".
530    
531        -makedepend NAME | -md NAME
532          --makedepend=NAME | -md=NAME
533              Use "NAME" for the MAKEDEPEND program.
534    
535      -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME      -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
536        -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME        -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
537            Specify the location of the MITgcm ROOTDIR as "NAME".            Specify the location of the MITgcm ROOTDIR as "NAME".
# Line 289  Usage: "$0" [OPTIONS] Line 568  Usage: "$0" [OPTIONS]
568            will search for a working compiler by trying a list of            will search for a working compiler by trying a list of
569            "usual suspects" such as g77, f77, etc.            "usual suspects" such as g77, f77, etc.
570    
571        -cc NAME | --cc NAME | -cc=NAME | --cc=NAME
572              Use "NAME" as the C compiler.  By default, genmake
573              will search for a working compiler by trying a list of
574              "usual suspects" such as gcc, c89, cc, etc.
575    
576      -[no]ieee | --[no]ieee      -[no]ieee | --[no]ieee
577            Do or don't use IEEE numerics.  Note that this option            Do or don't use IEEE numerics.  Note that this option
578            *only* works if it is supported by the OPTFILE that            *only* works if it is supported by the OPTFILE that
579            is being used.            is being used.
580    
581        -ignoretime | -ignore_time | --ignoretime | --ignore_time
582              Ignore all the "wall clock" routines entirely.  This will
583              not in any way hurt the model results -- it simply means
584              that the code that checks how long the model spends in
585              various routines will give junk values.
586    
587        -ts | --ts
588              Produce timing information per timestep
589        -papis | --papis
590              Produce summary MFlop/s with PAPI per timestep
591        -foolad | --foolad
592              Fool the AD code generator
593        -papi | --papi
594              Performance analysis with PAPI
595        -hpmt | --hpmt
596              Performance analysis with the HPM Toolkit
597    
598        -gsl | --gsl
599              Use GSL to control floating point rounding and precision
600    
601        -mpi | --mpi
602              Include MPI header files and link to MPI libraries
603        -mpi=PATH | --mpi=PATH
604              Include MPI header files and link to MPI libraries using MPI_ROOT
605              set to PATH. i.e. Include files from \$PATH/include, link to libraries
606              from \$PATH/lib and use binaries from \$PATH/bin.
607    
608        -es | --es | -embed-source | --embed-source
609              Embed a tarball containing the full source code
610              (including the Makefile, etc.) used to build the
611              executable [off by default]
612    
613        -bash NAME
614              Explicitly specify the Bourne or BASH shell to use
615    
616    While it is most often a single word, the "NAME" variables specified    While it is most often a single word, the "NAME" variables specified
617    above can in many cases be a space-delimited string such as:    above can in many cases be a space-delimited string such as:
618    
# Line 314  EOF Line 633  EOF
633    
634  #  Build a CPP macro to automate calling C routines from FORTRAN  #  Build a CPP macro to automate calling C routines from FORTRAN
635  get_fortran_c_namemangling()  {  get_fortran_c_namemangling()  {
636    
637        #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
638        if test ! "x$FC_NAMEMANGLE" = x ; then
639            return 0
640        fi
641    
642      default_nm="#define FC_NAMEMANGLE(X) X ## _"      default_nm="#define FC_NAMEMANGLE(X) X ## _"
643            
644      cat > genmake_test.c <<EOF      cat > genmake_test.c <<EOF
# Line 331  WARNING: Please contact <MITgcm-support@ Line 656  WARNING: Please contact <MITgcm-support@
656  EOF  EOF
657          return 1          return 1
658      fi      fi
659      c_tcall=`nm genmake_test.o | grep 'T ' | grep tcall | cut -d ' ' -f 3`      c_tcall=`nm genmake_test.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
660      RETVAL=$?      RETVAL=$?
661      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
662          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
# Line 343  WARNING: Please contact <MITgcm-support@ Line 668  WARNING: Please contact <MITgcm-support@
668  EOF  EOF
669          return 1          return 1
670      fi      fi
671      cat > genmake_tcomp.f <<EOF      cat > genmake_tcomp.$FS <<EOF
672        subroutine tcall( string )        subroutine tcall( string )
673        character*(*) string        character*(*) string
674        call tsub( string )        call tsub( string )
675        end        end
676  EOF  EOF
677      $FC $FFLAGS $DEFINES -c genmake_tcomp.f >> genmake_warnings 2>&1      $FC $FFLAGS -c genmake_tcomp.$FS >> genmake_warnings 2>&1
678      RETVAL=$?      RETVAL=$?
679      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
680          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
# Line 361  WARNING: Please contact <MITgcm-support@ Line 686  WARNING: Please contact <MITgcm-support@
686  EOF  EOF
687          return 1          return 1
688      fi      fi
689      f_tcall=`nm genmake_tcomp.o | grep 'T ' | grep tcall | cut -d ' ' -f 3`      f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
690      RETVAL=$?      RETVAL=$?
691      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
692          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
# Line 415  void FC_NAMEMANGLE(cloc) ( double *curti Line 740  void FC_NAMEMANGLE(cloc) ( double *curti
740   *curtim = *curtim/1.E6;   *curtim = *curtim/1.E6;
741  }  }
742  EOF  EOF
743      make genmake_tc_1.o >> genmake_tc.log 2>&1      make genmake_tc_1.o >> genmake_warnings 2>&1
744      RET_C=$?      RET_C=$?
745      cat <<EOF > genmake_tc_2.f      cat <<EOF > genmake_tc_2.$FS
746        program hello        program hello
747        Real*8 wtime        REAL*8 wtime
748        external cloc        external cloc
749        call cloc(wtime)        call cloc(wtime)
750        print *," HELLO WORLD", wtime        print *," HELLO WORLD", wtime
751        end program hello        end
752  EOF  EOF
753      $FC $FFLAGS -o genmake_tc genmake_tc_2.f genmake_tc_1.o >> genmake_tc.log 2>&1      $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_warnings 2>&1
754      RET_F=$?      RET_F=$?
755      test -x ./genmake_tc  &&  ./genmake_tc >> genmake_tc.log 2>&1      test -x ./genmake_tc  &&  ./genmake_tc >> genmake_warnings 2>&1
756      RETVAL=$?      RETVAL=$?
757      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
758          HAVE_CLOC=t          HAVE_CLOC=t
# Line 437  EOF Line 762  EOF
762  }  }
763    
764    
765    check_HAVE_SIGREG()  {
766        get_fortran_c_namemangling
767        cat <<EOF > genmake_tc_1.c
768    $FC_NAMEMANGLE
769    #include <stdlib.h>
770    #include <stdio.h>
771    #include <signal.h>
772    #include <errno.h>
773    #include <ucontext.h>
774    
775    int * ip;
776    
777    static void killhandler(
778        unsigned int sn, siginfo_t  si, struct ucontext *sc )
779    {
780        *ip = *ip + 1;
781        return;
782    }
783    
784    void FC_NAMEMANGLE(sigreg) (int * aip)
785    {
786        struct sigaction s;
787        ip = aip;
788        s.sa_flags = SA_SIGINFO;
789        s.sa_sigaction = (void *)killhandler;
790        if(sigaction (SIGTERM,&s,(struct sigaction *)NULL)) {
791            printf("Sigaction returned error = %d\n", errno);
792            exit(0);
793        }
794        return;
795    }
796    EOF
797        make genmake_tc_1.o >> genmake_warnings 2>&1
798        RET_C=$?
799        cat <<EOF > genmake_tc_2.$FS
800          program hello
801          integer anint
802          common /iv/ anint
803          external sigreg
804          call sigreg(anint)
805          end
806    EOF
807        echo >> genmake_warnings
808        echo "running: check_HAVE_SIGREG()" >> genmake_warnings
809        cat genmake_tc_2.$FS >> genmake_warnings
810        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
811        echo $COMM >> genmake_warnings
812        $COMM >> genmake_warnings 2>&1
813        RETVAL=$?
814        if test "x$RETVAL" = x0 ; then
815            HAVE_SIGREG=t
816            DEFINES="$DEFINES -DHAVE_SIGREG"
817        fi
818        rm -f genmake_tc*
819    }
820    
821    
822    check_HAVE_SETRLSTK()  {
823        get_fortran_c_namemangling
824        cat <<EOF > genmake_tc_1.c
825    $FC_NAMEMANGLE
826    #include <sys/time.h>
827    #include <sys/resource.h>
828    #include <unistd.h>
829    void FC_NAMEMANGLE(setrlstk) ()
830    {
831        struct rlimit rls;
832        rls.rlim_cur = RLIM_INFINITY;
833        rls.rlim_max = RLIM_INFINITY;
834        setrlimit(RLIMIT_STACK, &rls);
835        return;
836    }
837    EOF
838        make genmake_tc_1.o >> genmake_warnings 2>&1
839        RET_C=$?
840        cat <<EOF > genmake_tc_2.$FS
841          program hello
842          external setrlstk
843          call setrlstk()
844          end
845    EOF
846        echo >> genmake_warnings
847        echo "running: check_HAVE_SETRLSTK()" >> genmake_warnings
848        cat genmake_tc_2.$FS >> genmake_warnings
849        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
850        echo $COMM >> genmake_warnings
851        $COMM >> genmake_warnings 2>&1
852        RETVAL=$?
853        if test "x$RETVAL" = x0 ; then
854            HAVE_SETRLSTK=t
855            DEFINES="$DEFINES -DHAVE_SETRLSTK"
856        fi
857        rm -f genmake_tc*
858    }
859    
860    
861    check_HAVE_STAT()  {
862        get_fortran_c_namemangling
863        cat <<EOF > genmake_tc_1.c
864    $FC_NAMEMANGLE
865    #include <stdio.h>
866    #include <stdlib.h>
867    #include <unistd.h>
868    #include <sys/stat.h>
869    #include <sys/types.h>
870    void FC_NAMEMANGLE(tfsize) ( int *nbyte )
871    {
872        char name[512];
873        struct stat astat;
874    
875        name[0] = 'a'; name[1] = '\0';
876        if (! stat(name, &astat))
877            *nbyte = (int)(astat.st_size);
878        else
879            *nbyte = -1;
880    }
881    EOF
882        make genmake_tc_1.o >> genmake_tc.log 2>&1
883        RET_C=$?
884        cat <<EOF > genmake_tc_2.$FS
885          program hello
886          integer nbyte
887          call tfsize(nbyte)
888          print *," HELLO WORLD", nbyte
889          end
890    EOF
891        echo >> genmake_warnings
892        echo "running: check_HAVE_STAT()" >> genmake_warnings
893        cat genmake_tc_2.$FS >> genmake_warnings
894        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
895        echo $COMM >> genmake_warnings
896        $COMM >> genmake_tc.log 2>&1
897        RETVAL=$?
898        if test "x$RETVAL" = x0 ; then
899            HAVE_STAT=t
900            DEFINES="$DEFINES -DHAVE_STAT"
901        fi
902        rm -f genmake_tc*
903    }
904    
905    
906  check_netcdf_libs()  {  check_netcdf_libs()  {
907        if test ! "x$SKIP_NETCDF_CHECK" = x ; then
908            return
909        fi
910        echo >> genmake_warnings
911        echo "running: check_netcdf_libs()" >> genmake_warnings
912      cat <<EOF > genmake_tnc.F      cat <<EOF > genmake_tnc.F
913        program fgennc        program fgennc
914  #include "netcdf.inc"  #include "netcdf.inc"
915    EOF
916        if test ! "x$MPI" = x ; then
917            echo '#include "mpif.h"' >> genmake_tnc.F
918        fi
919        cat <<EOF >> genmake_tnc.F
920        integer iret, ncid, xid        integer iret, ncid, xid
921        iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)        iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
922        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
# Line 450  check_netcdf_libs()  { Line 926  check_netcdf_libs()  {
926        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
927        end        end
928  EOF  EOF
929      $CPP genmake_tnc.F > genmake_tnc.f  \      echo "===  genmake_tnc.F  ===" > genmake_tnc.log
930          &&  $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f $LIBS >> genmake_tnc.log 2>&1      cat genmake_tnc.F >> genmake_tnc.log
931        echo "===  genmake_tnc.F  ===" >> genmake_tnc.log
932        RET_CPP=f
933        COMM="$CPP $DEFINES $INCLUDES genmake_tnc.F"
934        echo "$COMM" >> genmake_tnc.log
935        $COMM > genmake_tnc.$FS 2>/dev/null  &&  RET_CPP=t
936        if test "x$RET_CPP" = xf ; then
937            echo "  WARNING: CPP failed to pre-process the netcdf test." \
938                >> genmake_tnc.log
939            echo "    Please check that \$INCLUDES is properly set." \
940                >> genmake_tnc.log
941        fi
942        echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.$FS  \ " >> genmake_tnc.log
943        echo "  &&  $LINK -o genmake_tnc.o $LIBS" >> genmake_tnc.log
944        $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
945            &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
946      RET_COMPILE=$?      RET_COMPILE=$?
947      test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1      cat genmake_tnc.log >> genmake_warnings
948      RETVAL=$?  
949      if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then      #EH3  Remove test program execution for machines that either disallow
950        #EH3  execution or cannot support it (eg. cross-compilers)
951        #EH3
952        #EH3 test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1
953        #EH3 RETVAL=$?
954        #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
955    
956        if test "x$RET_COMPILE" = x0 ; then
957          HAVE_NETCDF=t          HAVE_NETCDF=t
958      else      else
959            # try again with "-lnetcdf" added to the libs
960            echo "try again with added '-lnetcdf'" > genmake_tnc.log
961            echo "$CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS \ " >> genmake_tnc.log
962            echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
963            echo " &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
964            $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null  \
965                &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
966                &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
967            RET_COMPILE=$?
968          cat genmake_tnc.log >> genmake_warnings          cat genmake_tnc.log >> genmake_warnings
969            if test "x$RET_COMPILE" = x0 ; then
970                LIBS="$LIBS -lnetcdf"
971                HAVE_NETCDF=t
972            fi
973      fi      fi
974      rm -f genmake_tnc*      rm -f genmake_tnc*
975  }  }
976    
977    
978    
979    ###############################################################################
980    #   Sequential part of script starts here
981    ###############################################################################
982    
983  #  Set defaults here  #  Set defaults here
984  COMMANDL="$0 $@"  COMMANDL="$0 $@"
985    
# Line 471  PLATFORM= Line 987  PLATFORM=
987  LN=  LN=
988  S64=  S64=
989  KPP=  KPP=
990  FC=  #FC=
991  CPP=  #CC=gcc
992    #CPP=
993  LINK=  LINK=
 # DEFINES="-DWORDLENGTH=4"  
994  DEFINES=  DEFINES=
995  PACKAGES=  PACKAGES=
996  ENABLE=  ENABLE=
997  DISABLE=  DISABLE=
998  MAKEFILE=  # MAKEFILE=
999  MAKEDEPEND=  # MAKEDEPEND=
1000  PDEPEND=  PDEPEND=
1001  DUMPSTATE=t  DUMPSTATE=t
1002  PDEFAULT=  PDEFAULT=
1003  OPTFILE=  OPTFILE=
1004  INCLUDES="-I."  INCLUDES="-I. $INCLUDES"
1005  FFLAGS=  FFLAGS=
1006  FOPTIM=  FOPTIM=
1007  CFLAGS=  CFLAGS=
1008  KFLAGS1=  KFLAGS1=
1009  KFLAGS2=  KFLAGS2=
1010    #LDADD=
1011  LIBS=  LIBS=
1012  KPPFILES=  KPPFILES=
1013  NOOPTFILES=  NOOPTFILES=
1014  NOOPTFLAGS=  NOOPTFLAGS=
1015    MPI=
1016    MPIPATH=
1017    TS=
1018    PAPIS=
1019    FOOLAD=
1020    PAPI=
1021    HPMT=
1022    GSL=
1023    HAVE_TEST_L=
1024    
1025  # DEFINES checked by test compilation  # DEFINES checked by test compilation or command-line
1026  HAVE_SYSTEM=  HAVE_SYSTEM=
1027  HAVE_FDATE=  HAVE_FDATE=
1028  FC_NAMEMANGLE=  FC_NAMEMANGLE=
1029  HAVE_CLOC=  HAVE_CLOC=
1030    HAVE_SETRLSTK=
1031    HAVE_STAT=
1032  HAVE_NETCDF=  HAVE_NETCDF=
1033    HAVE_ETIME=
1034    IGNORE_TIME=
1035    
1036  MODS=  MODS=
1037  TOOLSDIR=  TOOLSDIR=
# Line 509  SOURCEDIRS= Line 1039  SOURCEDIRS=
1039  INCLUDEDIRS=  INCLUDEDIRS=
1040  STANDARDDIRS="USE_THE_DEFAULT"  STANDARDDIRS="USE_THE_DEFAULT"
1041    
1042    G2ARGS=
1043    BASH=
1044  PWD=`pwd`  PWD=`pwd`
1045  MAKE=make  test "x$MAKE" = x  &&  MAKE=make
1046  AWK=awk  test "x$AWK" = x   &&  AWK=awk
1047  THISHOSTNAME=`hostname`  EMBED_SRC=
1048    THISHOST=`hostname`
1049  THISCWD=`pwd`  THISCWD=`pwd`
1050  THISDATE=`date`  THISDATE=`date`
1051    THISUSER=`echo $USER`
1052    THISVER=
1053  MACHINE=`uname -a`  MACHINE=`uname -a`
1054  EXECUTABLE=  EXECUTABLE=
1055  EXEHOOK=  EXEHOOK=
# Line 524  IEEE= Line 1059  IEEE=
1059  if test "x$MITGCM_IEEE" != x ; then  if test "x$MITGCM_IEEE" != x ; then
1060      IEEE=$MITGCM_IEEE      IEEE=$MITGCM_IEEE
1061  fi  fi
1062    FS=
1063    FS90=
1064    
1065  AUTODIFF_PKG_USED=f  AUTODIFF_PKG_USED=f
1066  AD_OPTFILE=  AD_OPTFILE=
# Line 541  TAMC_EXTRA= Line 1078  TAMC_EXTRA=
1078    
1079  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
1080  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"
1081  gm_s2="FC CPP IEEE MPI JAM DUMPSTATE STANDARDDIRS"  gm_s2="FC CPP IEEE TS PAPIS PAPI HPMT GSL MPI JAM DUMPSTATE STANDARDDIRS"
1082    
1083  #  The following state is not directly set by command-line switches  #  The following state is not directly set by command-line switches
1084  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 "
1085  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
1086  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE"
1087  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
1088  gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE"  gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME"
1089    
1090  #  The following are all related to adjoint/tangent-linear stuff  #  The following are all related to adjoint/tangent-linear stuff
1091  gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"  gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
# Line 577  for i in . $MODS ; do Line 1114  for i in . $MODS ; do
1114          break          break
1115      fi      fi
1116  done  done
1117  echo -n "  getting local config information:  "  printf "  getting local config information:  "
1118  if test -e $gm_local ; then  if test -f $gm_local ; then
1119      echo "using $gm_local"      echo "using $gm_local"
1120      . $gm_local      . $gm_local
1121      # echo "DISABLE=$DISABLE"      # echo "DISABLE=$DISABLE"
# Line 587  else Line 1124  else
1124      echo "none found"      echo "none found"
1125  fi  fi
1126    
1127  #  echo "$0::$1:$2:$3:$4:$5:$6:$7:"  #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
1128  #OPTIONS=  #OPTIONS=
1129  #n=0  #n=0
1130  #for i ; do  #for i ; do
# Line 599  fi Line 1136  fi
1136  #done  #done
1137  #parse_options  #parse_options
1138  ac_prev=  ac_prev=
1139  for ac_option ; do  for ac_option in "$@" ; do
1140    
1141        G2ARGS="$G2ARGS \"$ac_option\""
1142    
1143      # If the previous option needs an argument, assign it.      # If the previous option needs an argument, assign it.
1144      if test -n "$ac_prev"; then      if test -n "$ac_prev"; then
# Line 642  for ac_option ; do Line 1181  for ac_option ; do
1181          -make=* | --make=* | -m=* | --m=*)          -make=* | --make=* | -m=* | --m=*)
1182              MAKE=$ac_optarg ;;              MAKE=$ac_optarg ;;
1183                    
1184            -bash | --bash)
1185                ac_prev=BASH ;;
1186            -bash=* | --bash=*)
1187                BASH=$ac_optarg ;;
1188            
1189            -makedepend | --makedepend | -md | --md)
1190                ac_prev=MAKEDEPEND ;;
1191            -makedepend=* | --makedepend=* | -md=* | --md=*)
1192                MAKEDEPEND=$ac_optarg ;;
1193            
1194          -makefile | --makefile | -ma | --ma)          -makefile | --makefile | -ma | --ma)
1195              ac_prev=MAKEFILE ;;              ac_prev=MAKEFILE ;;
1196          -makefile=* | --makefile=* | -ma=* | --ma=*)          -makefile=* | --makefile=* | -ma=* | --ma=*)
# Line 683  for ac_option ; do Line 1232  for ac_option ; do
1232  #               ac_prev=cpp ;;  #               ac_prev=cpp ;;
1233  #           -cpp=* | --cpp=*)  #           -cpp=* | --cpp=*)
1234  #               CPP=$ac_optarg ;;  #               CPP=$ac_optarg ;;
1235                        
1236            -cc | --cc)
1237                ac_prev=CC ;;
1238            -cc=* | --cc=*)
1239                CC=$ac_optarg ;;
1240            
1241          -fortran | --fortran | -fc | --fc)          -fortran | --fortran | -fc | --fc)
1242              ac_prev=FC ;;              ac_prev=FC ;;
1243          -fc=* | --fc=*)          -fc=* | --fc=*)
1244              FC=$ac_optarg ;;              FC=$ac_optarg ;;
1245                    
1246            -fs | --fs)
1247                ac_prev=FS ;;
1248            -fs=* | --fs=*)
1249                FS=$ac_optarg ;;
1250            
1251            -fs90 | --fs90)
1252                ac_prev=FS90 ;;
1253            -fs90=* | --fs90=*)
1254                FS90=$ac_optarg ;;
1255            
1256          -ieee | --ieee)          -ieee | --ieee)
1257              IEEE=true ;;              IEEE=true ;;
1258          -noieee | --noieee)          -noieee | --noieee)
1259              IEEE= ;;              IEEE= ;;
1260    
1261            -ts | --ts)
1262                TS=true ;;
1263            -papis | --papis)
1264                PAPIS=true ;;
1265            -foolad | --foolad)
1266                FOOLAD=true ;;
1267            -papi | --papi)
1268                PAPI=true ;;
1269            -hpmt | --hpmt)
1270                HPMT=true ;;
1271    
1272            -gsl | --gsl)
1273                GSL=true ;;
1274    
1275            -mpi | --mpi)
1276                MPI=true ;;
1277            -mpi=* | --mpi=*)
1278                MPIPATH=$ac_optarg
1279                MPI=true ;;
1280                    
1281  #       -jam | --jam)  #       -jam | --jam)
1282  #           JAM=1 ;;  #           JAM=1 ;;
# Line 711  for ac_option ; do Line 1295  for ac_option ; do
1295              ac_prev=TAMC_EXTRA ;;              ac_prev=TAMC_EXTRA ;;
1296          -tamc_extra=* | --tamc_extra=*)          -tamc_extra=* | --tamc_extra=*)
1297              TAMC_EXTRA=$ac_optarg ;;              TAMC_EXTRA=$ac_optarg ;;
1298            
1299            -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1300                IGNORE_TIME="-DIGNORE_TIME" ;;
1301    
1302            -es | --es | -embed-source | --embed-source)
1303                EMBED_SRC=t ;;
1304    
1305          -*)          -*)
1306              echo "Error: unrecognized option: "$ac_option              echo "Error: unrecognized option: "$ac_option
# Line 726  for ac_option ; do Line 1316  for ac_option ; do
1316            
1317  done  done
1318    
1319    
1320  if test -f ./.genmakerc ; then  if test -f ./.genmakerc ; then
1321      echo      echo
1322      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
# Line 738  if test -f ./.genmakerc ; then Line 1329  if test -f ./.genmakerc ; then
1329      echo      echo
1330  fi  fi
1331    
1332    #  Find the MITgcm ${ROOTDIR}
1333  if test "x${ROOTDIR}" = x ; then  if test "x${ROOTDIR}" = x ; then
1334      if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1335        if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
1336          ROOTDIR=".."          ROOTDIR=".."
1337      else      else
1338          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1339              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
1340                  ROOTDIR=$d                  ROOTDIR=$d
1341                  echo -n "Warning:  ROOTDIR was not specified but there appears to be"                  printf "Warning:  ROOTDIR was not specified but there appears to be"
1342                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
1343                  break                  break
1344              fi              fi
# Line 763  if test ! -d ${ROOTDIR} ; then Line 1356  if test ! -d ${ROOTDIR} ; then
1356      exit 1      exit 1
1357  fi  fi
1358    
1359    #  Find the MITgcm ${THISVER}
1360    if test -f "${ROOTDIR}/doc/tag-index" ; then
1361        THISVER=`grep '^checkpoint' ${ROOTDIR}/doc/tag-index | head -1`
1362    fi
1363    
1364    if test "x$MAKEFILE" = x ; then
1365        MAKEFILE="Makefile"
1366    fi
1367    
1368  echo "  getting OPTFILE information:  "  echo "  getting OPTFILE information:  "
1369  if test "x${OPTFILE}" = x ; then  if test "x${OPTFILE}" = x ; then
1370      if test "x$MITGCM_OF" = x ; then      if test "x$MITGCM_OF" = x ; then
# Line 779  if test "x$OPTFILE" != xNONE ; then Line 1381  if test "x$OPTFILE" != xNONE ; then
1381          . "$OPTFILE"          . "$OPTFILE"
1382          RETVAL=$?          RETVAL=$?
1383          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
1384              echo -n "Error: failed to source OPTFILE \"$OPTFILE\""              printf "Error: failed to source OPTFILE \"$OPTFILE\""
1385              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1386              exit 1              exit 1
1387          fi          fi
# Line 806  if test "x${AD_OPTFILE}" != xNONE ; then Line 1408  if test "x${AD_OPTFILE}" != xNONE ; then
1408          . "$AD_OPTFILE"          . "$AD_OPTFILE"
1409          RETVAL=$?          RETVAL=$?
1410          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
1411              echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""              printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
1412              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1413              exit 1              exit 1
1414          fi          fi
# Line 819  if test "x${AD_OPTFILE}" != xNONE ; then Line 1421  if test "x${AD_OPTFILE}" != xNONE ; then
1421      fi      fi
1422  fi  fi
1423    
1424  #  Check that FC, LINK, CPP, S64, LN, and MAKE are defined.  If not,  #====================================================================
1425    #  Set default values if not set by the optfile
1426    #
1427    #  Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
1428  #  either set defaults or complain and abort!  #  either set defaults or complain and abort!
1429    if test ! "x$BASH" = x ; then
1430        # add a trailing space so that it works within the Makefile syntax (see below)
1431        BASH="$BASH "
1432    fi
1433  if test "x$FC" = x ; then  if test "x$FC" = x ; then
1434      cat <<EOF 1>&2      cat <<EOF 1>&2
1435    
# Line 831  Error: no Fortran compiler: please speci Line 1440  Error: no Fortran compiler: please speci
1440  EOF  EOF
1441      exit 1      exit 1
1442  fi  fi
1443    if test "x$CC" = x ; then
1444        CC=cc
1445    #     cat <<EOF 1>&2
1446    # Error: no C compiler: please specify using one of the following:
1447    #   1) within the options file ("CC=...") as specified by "-of=OPTFILE"
1448    #   2) the "-cc=XXX" command-line option
1449    #   3) the "./genmake_local" file
1450    # EOF
1451    #     exit 1
1452    fi
1453  if test "x$LINK" = x ; then  if test "x$LINK" = x ; then
1454      LINK=$FC      LINK=$FC
1455  fi  fi
# Line 841  if test "x$CPP" = x ; then Line 1460  if test "x$CPP" = x ; then
1460      CPP=cpp      CPP=cpp
1461  fi  fi
1462  #EH3 === UGLY ===  #EH3 === UGLY ===
1463  #  The following an ugly little hack to check for $CPP in /lib/ and it  #  The following is an ugly little hack to check for $CPP in /lib/ and
1464  #  should eventually be replaced with a more general function that  #  it should eventually be replaced with a more general function that
1465  #  searches a combo of the user's path and a list of "usual suspects"  #  searches a combo of the user's path and a list of "usual suspects"
1466  #  to find the correct location for binaries such as $CPP.  #  to find the correct location for binaries such as $CPP.
1467  for i in " " "/lib/" ; do  for i in " " "/lib/" ; do
# Line 865  EOF Line 1484  EOF
1484  else  else
1485      rm -f test_cpp      rm -f test_cpp
1486  fi  fi
1487  if test "x$MAKEDEPEND" = x ; then  look_for_makedepend
     MAKEDEPEND=makedepend  
 fi  
1488  if test "x$LN" = x ; then  if test "x$LN" = x ; then
1489      LN="ln -s"      LN="ln -s"
1490  fi  fi
# Line 883  Error: The command "ln -s" failed -- ple Line 1500  Error: The command "ln -s" failed -- ple
1500  EOF  EOF
1501      exit 1      exit 1
1502  fi  fi
1503    test -L genmake_tlink > /dev/null 2>&1
1504    RETVAL=$?
1505    if test "x$RETVAL" = x0 ; then
1506        HAVE_TEST_L=t
1507    fi
1508  rm -f genmake_test_ln genmake_tlink  rm -f genmake_test_ln genmake_tlink
1509    
1510    #  Check for broken *.F/*.f handling and fix if possible
1511    check_for_broken_Ff
1512    
1513    if test ! "x$MPI" = x ; then
1514          echo "  Turning on MPI cpp macros"
1515          DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
1516    fi
1517    
1518    if test ! "x$TS" = x ; then
1519          echo "  Turning on timing per timestep"
1520          if test ! "x$FOOLAD" = x ; then
1521                DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP"
1522          else
1523                DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1524          fi
1525    fi
1526    if test ! "x$PAPIS" = x ; then
1527          echo "  Turning on PAPI flop summary per timestep"
1528          echo "  Please make sure PAPIINC, PAPILIB are defined"
1529          if test ! "x$FOOLAD" = x ; then
1530                DEFINES="$DEFINES -DUSE_PAPI_FLOPS_SFP"
1531          else
1532                DEFINES="$DEFINES -DUSE_PAPI_FLOPS"
1533          fi
1534          INCLUDES="$INCLUDES $PAPIINC"
1535          LIBS="$LIBS $PAPILIB"
1536    fi
1537    if test ! "x$PAPI" = x ; then
1538          if test ! "x$PAPIS" = x ; then
1539              echo "  PAPI performance analysis and flop summary per timestep cannot co-exist!"
1540              echo "  Sticking with PAPI flop summary per timestep!"
1541          else
1542              echo "  Turning on performance analysis with PAPI"
1543              echo "  Please make sure PAPIINC, PAPILIB are defined"
1544              DEFINES="$DEFINES -DUSE_PAPI"
1545              INCLUDES="$INCLUDES $PAPIINC"
1546              LIBS="$LIBS $PAPILIB"
1547          fi
1548    fi
1549    if test ! "x$HPMT" = x ; then
1550          if test ! "x$PAPI" = x ; then
1551              echo "  PAPI and the HPM Toolkit cannot co-exist!"
1552              echo "  Sticking with PAPI!"
1553          else
1554              echo "  Turning on performance analysis with the HPM Toolkit"
1555              echo "  Please make sure HPMTINC, HPMTLIB are defined"
1556              DEFINES="$DEFINES -DUSE_LIBHPM"
1557              INCLUDES="$INCLUDES $HPMTINC"
1558              LIBS="$LIBS $HPMTLIB"
1559          fi
1560    fi
1561    if test ! "x$GSL" = x ; then
1562          echo "  Turning on use of GSL to control floating point calculations"
1563          echo "  Please make sure GSLINC, GSLLIB are defined"
1564          DEFINES="$DEFINES -DUSE_GSL_IEEE"
1565          INCLUDES="$INCLUDES $GSLINC"
1566          LIBS="$LIBS $GSLLIB"
1567    fi
1568    
1569  printf "\n===  Checking system libraries  ===\n"  printf "\n===  Checking system libraries  ===\n"
1570  echo -n "  Do we have the system() command using $FC...  "  printf "  Do we have the system() command using $FC...  "
1571  cat > genmake_tcomp.f <<EOF  cat > genmake_tcomp.$FS <<EOF
1572        program hello        program hello
1573        call system('echo hi')        call system('echo hi')
1574        end        end
1575  EOF  EOF
1576  $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1  $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1577  RETVAL=$?  RETVAL=$?
1578  if test "x$RETVAL" = x0 ; then  if test "x$RETVAL" = x0 ; then
1579      HAVE_SYSTEM=t      HAVE_SYSTEM=t
# Line 905  else Line 1585  else
1585  fi  fi
1586  rm -f genmake_tcomp*  rm -f genmake_tcomp*
1587    
1588  echo -n "  Do we have the fdate() command using $FC...  "  printf "  Do we have the fdate() command using $FC...  "
1589  cat > genmake_tcomp.f <<EOF  cat > genmake_tcomp.$FS <<EOF
1590        program hello        program hello
1591        CHARACTER(128) string        CHARACTER*(128) string
1592        string = ' '        string = ' '
1593        call fdate( string )        call fdate( string )
1594        print *, string        print *, string
1595        end        end
1596  EOF  EOF
1597  $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1  $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1598  RETVAL=$?  RETVAL=$?
1599  if test "x$RETVAL" = x0 ; then  if test "x$RETVAL" = x0 ; then
1600      HAVE_FDATE=t      HAVE_FDATE=t
# Line 926  else Line 1606  else
1606  fi  fi
1607  rm -f genmake_tcomp*  rm -f genmake_tcomp*
1608    
1609  echo -n "  Can we call simple C routines (here, \"cloc()\") using $FC...  "  printf "  Do we have the etime() command using $FC...  "
1610    cat > genmake_tcomp.$FS <<EOF
1611          program hello
1612          REAL*4 ACTUAL, TARRAY(2)
1613          EXTERNAL ETIME
1614          REAL*4 ETIME
1615          actual = etime( tarray )
1616          print *, tarray
1617          end
1618    EOF
1619    $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1620    RETVAL=$?
1621    if test "x$RETVAL" = x0 ; then
1622        HAVE_ETIME=t
1623        DEFINES="$DEFINES -DHAVE_ETIME"
1624        echo "yes"
1625    else
1626        HAVE_ETIME=
1627        echo "no"
1628    fi
1629    rm -f genmake_tcomp*
1630    
1631    printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
1632  check_HAVE_CLOC  check_HAVE_CLOC
1633  if test "x$HAVE_CLOC" != x ; then  if test "x$HAVE_CLOC" != x ; then
1634      echo "yes"      echo "yes"
1635  else  else
1636      echo "no"      echo "no"
1637        if test "x$EMBED_SRC" = xt ; then
1638            echo "    WARNING: you requested file embedding but it has"
1639            echo "      been disabled since C code cannot be called"
1640            EMBED_SRC=
1641        fi
1642  fi  fi
1643  rm -f genmake_t*  rm -f genmake_t*
1644    
1645  echo -n "  Can we create NetCDF-enabled binaries...  "  printf "  Can we unlimit the stack size using $FC...  "
1646    check_HAVE_SETRLSTK
1647    if test "x$HAVE_SETRLSTK" != x ; then
1648        echo "yes"
1649    else
1650        echo "no"
1651    fi
1652    rm -f genmake_t*
1653    
1654    printf "  Can we register a signal handler using $FC...  "
1655    check_HAVE_SIGREG
1656    if test "x$HAVE_SIGREG" != x ; then
1657        echo "yes"
1658    else
1659        echo "no"
1660    fi
1661    rm -f genmake_t*
1662    
1663    printf "  Can we use stat() through C calls...  "
1664    check_HAVE_STAT
1665    if test "x$HAVE_STAT" != x ; then
1666        echo "yes"
1667    else
1668        echo "no"
1669    fi
1670    rm -f genmake_t*
1671    
1672    printf "  Can we create NetCDF-enabled binaries...  "
1673  check_netcdf_libs  check_netcdf_libs
1674  if test "x$HAVE_NETCDF" != x ; then  if test "x$HAVE_NETCDF" != x ; then
1675      echo "yes"      echo "yes"
1676  else  else
1677      echo "no"      echo "no"
1678  fi  fi
1679    DEFINES="$DEFINES $IGNORE_TIME"
1680    
1681    if test "x$EMBED_SRC" = xt ; then
1682        build_embed_encode
1683    fi
1684    if test "x$EMBED_SRC" = xt ; then
1685        ENABLE="$ENABLE embed_files"
1686    fi
1687    
1688    
1689  printf "\n===  Setting defaults  ===\n"  printf "\n===  Setting defaults  ===\n"
1690  echo -n "  Adding MODS directories:  "  printf "  Adding MODS directories:  "
1691  for d in $MODS ; do  for d in $MODS ; do
1692      if test ! -d $d ; then      if test ! -d $d ; then
1693          echo          echo
1694          echo "Error: MODS directory \"$d\" not found!"          echo "Error: MODS directory \"$d\" not found!"
1695          exit 1          exit 1
1696      else      else
1697          echo -n " $d"          printf " $d"
1698          SOURCEDIRS="$SOURCEDIRS $d"          SOURCEDIRS="$SOURCEDIRS $d"
1699          INCLUDEDIRS="$INCLUDEDIRS $d"          INCLUDEDIRS="$INCLUDEDIRS $d"
1700      fi      fi
1701  done  done
1702  echo  echo
1703    
 if test "x$MAKEFILE" = x ; then  
     MAKEFILE="Makefile"  
 fi  
1704  if test "x${PLATFORM}" = x ; then  if test "x${PLATFORM}" = x ; then
1705      PLATFORM=$p_PLATFORM      PLATFORM=$p_PLATFORM
1706  fi  fi
1707    
1708  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
1709      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1710        if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
1711          EXEDIR=../exe          EXEDIR=../exe
1712      else      else
1713          EXEDIR=.          EXEDIR=.
# Line 982  if test "x${TOOLSDIR}" = x ; then Line 1722  if test "x${TOOLSDIR}" = x ; then
1722      TOOLSDIR="$ROOTDIR/tools"      TOOLSDIR="$ROOTDIR/tools"
1723  fi  fi
1724  if test ! -d ${TOOLSDIR} ; then  if test ! -d ${TOOLSDIR} ; then
1725      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
1726      exit 1      exit 1
1727  fi  fi
1728  if test "x$S64" = x ; then  if test "x$S64" = x ; then
1729      S64='$(TOOLSDIR)/set64bitConst.sh'      echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1
1730        RETVAL=$?
1731        if test "x${RETVAL}" = x0 ; then
1732            S64='$(TOOLSDIR)/set64bitConst.sh'
1733        else
1734            echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1
1735            RETVAL=$?
1736            if test "x${RETVAL}" = x0 ; then
1737                S64='$(TOOLSDIR)/set64bitConst.csh'
1738            else
1739                cat <<EOF
1740    
1741    ERROR: neither of the two default scripts:
1742    
1743        ${TOOLSDIR}/set64bitConst.sh
1744        ${TOOLSDIR}/set64bitConst.csh
1745    
1746      are working so please check paths or specify (with \$S64) a
1747      working version of this script.
1748    
1749    EOF
1750                exit 1
1751            fi
1752        fi
1753  fi  fi
1754  THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`  THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
1755    
# Line 1077  else Line 1840  else
1840          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
1841          RETVAL=$?          RETVAL=$?
1842          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
1843              echo -n "Error: can't parse default package list "              printf "Error: can't parse default package list "
1844              echo "-- please check PDEFAULT=\"$PDEFAULT\""              echo "-- please check PDEFAULT=\"$PDEFAULT\""
1845              exit 1              exit 1
1846          fi          fi
# Line 1085  else Line 1848  else
1848              PACKAGES="$PACKAGES $i"              PACKAGES="$PACKAGES $i"
1849          done          done
1850          echo "    before group expansion packages are: $PACKAGES"          echo "    before group expansion packages are: $PACKAGES"
1851          expand_pkg_groups          RET=1
1852            while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
1853          echo "    after group expansion packages are:  $PACKAGES"          echo "    after group expansion packages are:  $PACKAGES"
1854      fi      fi
1855  fi  fi
1856    
1857  echo "  applying DISABLE settings"  echo "  applying DISABLE settings"
1858    for i in $PACKAGES ; do
1859        echo $i >> ./.tmp_pack
1860    done
1861    for i in `grep  "-" ./.tmp_pack` ; do
1862        j=`echo $i | sed 's/[-]//'`
1863        DISABLE="$DISABLE $j"
1864    done
1865  pack=  pack=
1866  for p in $PACKAGES ; do  for p in $PACKAGES ; do
1867      addit="t"      addit="t"
# Line 1107  PACKAGES="$pack" Line 1878  PACKAGES="$pack"
1878  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
1879  echo "" > ./.tmp_pack  echo "" > ./.tmp_pack
1880  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
1881    # Test if each explicitly referenced package exists
1882  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1883      if test ! -d "$ROOTDIR/pkg/$i" ; then      j=`echo $i | sed 's/[-+]//'`
1884        if test ! -d "$ROOTDIR/pkg/$j" ; then
1885          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
1886          exit 1          exit 1
1887      fi      fi
1888      echo $i >> ./.tmp_pack      echo $i >> ./.tmp_pack
1889  done  done
 pack=`cat ./.tmp_pack | sort | uniq`  
 rm -f ./.tmp_pack  
1890  PACKAGES=  PACKAGES=
1891  for i in $pack ; do  for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do
1892      PACKAGES="$PACKAGES $i"      PACKAGES="$PACKAGES $i"
1893  done  done
1894    rm -f ./.tmp_pack
1895  echo "    packages are:  $PACKAGES"  echo "    packages are:  $PACKAGES"
1896    
1897    #  Check availability of NetCDF and then either build the MNC template
1898    #  files or delete mnc from the list of available packages.
1899    echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1
1900    RETVAL=$?
1901    if test "x$RETVAL" = x0 ; then
1902        if test "x$HAVE_NETCDF" != xt ; then
1903            cat <<EOF
1904    
1905    *********************************************************************
1906    WARNING: the "mnc" package was enabled but tests failed to compile
1907      NetCDF applications.  Please check that:
1908    
1909      1) NetCDF is correctly installed for this compiler and
1910      2) the LIBS variable (within the "optfile") specifies the correct
1911           NetCDF library to link against.
1912    
1913      Due to this failure, the "mnc" package is now DISABLED.
1914    *********************************************************************
1915    
1916    EOF
1917            PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
1918            DISABLE="$DISABLE mnc"
1919        else
1920            ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
1921            RETVAL=$?
1922            if test "x${RETVAL}" = x0 ; then
1923                rm -f make_mnc.errors
1924            else
1925                echo "Error: problem encountered while building source files in pkg/mnc:"
1926                cat make_mnc.errors 1>&2
1927                exit 1
1928            fi
1929        fi
1930    fi
1931    
1932  echo "  applying package dependency rules"  echo "  applying package dependency rules"
1933  ck=  ck=
1934  while test "x$ck" != xtt ; do  while test "x$ck" != xtt ; do
# Line 1186  while test "x$ck" != xtt ; do Line 1993  while test "x$ck" != xtt ; do
1993              echo "  the dependency rules for \"$dname\""              echo "  the dependency rules for \"$dname\""
1994              exit 1              exit 1
1995          fi          fi
1996          i=$(( $i + 1 ))          i=`echo "$i + 1" | bc -l`
1997            #i=$(( $i + 1 ))
1998      done      done
1999      ck=$ck"t"      ck=$ck"t"
2000  done  done
# Line 1205  for i in $PACKAGES ; do Line 2013  for i in $PACKAGES ; do
2013      fi      fi
2014  done  done
2015    
 #  Build MNC templates and check for ability to build and use NetCDF  
 echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1  
 RETVAL=$?  
 if test "x$RETVAL" = x0 ; then  
     ( cd $ROOTDIR"/pkg/mnc" && $MAKE templates ) > make_mnc.errors 2>&1  
     RETVAL=$?  
     if test "x${RETVAL}" = x0 ; then  
         rm -f make_mnc.errors  
     else  
         echo "Error: problem encountered while building source files in pkg/mnc:"  
         cat make_mnc.errors 1>&2  
         exit 1  
     fi  
     if test "x$HAVE_NETCDF" != xt ; then  
         cat <<EOF  
   
 WARNING: the "mnc" package has been enabled but tests failed to  
   compile and/or execute NetCDF applications.  Please check that:  
   
   1) NetCDF is installed for your compiler and  
   2) the LIBS variable (within the 'optfile") specifies the correct  
        NetCDF library to link against.  
     
 EOF  
     fi  
 fi  
   
2016  # Create a list of #define and #undef to enable/disable packages  # Create a list of #define and #undef to enable/disable packages
2017  PACKAGES_DOT_H=PACKAGES_CONFIG.h  PACKAGES_DOT_H=PACKAGES_CONFIG.h
2018  #  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
# Line 1251  for n in $names ; do Line 2032  for n in $names ; do
2032              fi              fi
2033          done          done
2034          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
2035              undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2036              DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"              DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
2037          fi          fi
2038      fi      fi
2039  done  done
2040  ENABLED_PACKAGES=  ENABLED_PACKAGES=
2041  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2042      def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`      def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2043      ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"      ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
2044  #eh3 DEFINES="$DEFINES -D$def"  #eh3 DEFINES="$DEFINES -D$def"
2045    
# Line 1342  for i in $SOURCEDIRS ; do Line 2123  for i in $SOURCEDIRS ; do
2123          cat $i/$j >> ad_files          cat $i/$j >> ad_files
2124      done      done
2125  done  done
2126    if test ! "x"$FS = "x.f" ; then
2127        cat ad_files | sed -e "s/\.f/.$FS/g" > ad_files_f
2128        mv -f ad_files_f ad_files
2129    fi
2130    
2131  echo  echo
2132  echo "===  Creating the Makefile  ==="  echo "===  Creating the Makefile  ==="
2133  echo "  setting INCLUDES"  echo "  setting INCLUDES"
2134  for i in $INCLUDEDIRS ; do  for i in $INCLUDEDIRS ; do
2135      if ! test -d $i ; then      if test ! -d $i ; then
 #       INCLUDES="$INCLUDES -I$i"  
 #   else  
2136          echo "Warning: can't find INCLUDEDIRS=\"$i\""          echo "Warning: can't find INCLUDEDIRS=\"$i\""
2137      fi      fi
2138  done  done
2139    
2140    if test ! "x$DIVA" = x ; then
2141        echo "  Creating the pseudo-MPI include directory"
2142        INCLUDES="-I./mpi_headers $INCLUDES"
2143        rm -rf ./mpi_headers
2144        mkdir -p ./mpi_headers
2145    
2146        if test "x$MPIINCLUDEDIR" = x ; then
2147            if test "x$MPIHOME" = x ; then
2148                MPIHOME='/usr'
2149            fi
2150            MPIINCLUDEDIR='$MPIHOME/include'
2151        fi
2152        
2153        if test -r $MPIINCLUDEDIR/mpif.h ; then
2154            for i in $MPI_HEADER_FILES; do
2155                cp -p $MPIINCLUDEDIR/$i ./mpi_headers
2156            done
2157    
2158            perl -i -pe 's/MPI_DISPLACEMENT_CURRENT=-1_8/MPI_DISPLACEMENT_CURRENT=-1/g' mpi_headers/mpif.h
2159        else
2160            echo " We cannot create a copy of mpif.h!"
2161            exit -1
2162        fi
2163    fi
2164    
2165  echo "  Determining the list of source and include files"  echo "  Determining the list of source and include files"
2166  rm -rf .links.tmp  rm -rf .links.tmp
2167  mkdir .links.tmp  mkdir .links.tmp
2168    touch .links.tmp/foo
2169    if test ! -r ".links.tmp/foo" ; then
2170        echo
2171        echo "ERROR : something is wrong with your directory permissions or"
2172        echo "   your user file-creation mask (\"umask\") since creating a"
2173        echo "   sub-dir, touch-ing a file within it, and then reading it is"
2174        echo "   not working.  Please try setting your umask to something"
2175        echo "   sane such as:"
2176        echo
2177        echo "      umask 0002"
2178        echo
2179        echo "   and please verify that you have the proper permissions for"
2180        echo "   creating sub-directories and then reading files created"
2181        echo "   within them."
2182        echo
2183        exit 1
2184    fi
2185    rm -f .links.tmp/foo
2186  echo "# This section creates symbolic links" > srclinks.tmp  echo "# This section creates symbolic links" > srclinks.tmp
2187  echo "" >> srclinks.tmp  echo "" >> srclinks.tmp
2188  echo -n 'SRCFILES = '    > srclist.inc  printf 'SRCFILES = '    > srclist.inc
2189  echo -n 'CSRCFILES = '   > csrclist.inc  printf 'CSRCFILES = '   > csrclist.inc
2190  echo -n 'F90SRCFILES = ' > f90srclist.inc  printf 'F90SRCFILES = ' > f90srclist.inc
2191  echo -n 'HEADERFILES = ' > hlist.inc  printf 'HEADERFILES = ' > hlist.inc
2192  echo -n 'AD_FLOW_FILES = ' > ad_flow_files.inc  printf 'AD_FLOW_FILES = ' > ad_flow_files.inc
2193  alldirs="$SOURCEDIRS $INCLUDEDIRS ."  alldirs="$SOURCEDIRS $INCLUDEDIRS ."
2194  for d in $alldirs ; do  for d in $alldirs ; do
2195      deplist=      deplist=
# Line 1373  for d in $alldirs ; do Line 2198  for d in $alldirs ; do
2198      for sf in $sfiles ; do      for sf in $sfiles ; do
2199          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
2200              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
2201                    ignore_f=f
2202                  case $d/$sf in                  case $d/$sf in
2203                    ./$PACKAGES_DOT_H)                    ./$PACKAGES_DOT_H)
2204                            ignore_f=t
2205                          ;;                          ;;
2206                    ./AD_CONFIG.h)                    ./AD_CONFIG.h)
2207                            ignore_f=t
2208                          ;;                          ;;
2209                    ./FC_NAMEMANGLE.h)                    ./FC_NAMEMANGLE.h)
2210                            ignore_f=t
2211                          ;;                          ;;
2212                    *)                    ./BUILD_INFO.h)
2213                          touch .links.tmp/$sf                          ignore_f=t
                         deplist="$deplist $sf"  
                         ;;  
                 esac  
                 extn=`echo $sf | $AWK -F '.' '{print $NF}'`  
                 case $extn in  
                     F)  
                         echo    " \\"  >> srclist.inc  
                         echo -n " $sf" >> srclist.inc  
2214                          ;;                          ;;
2215                      F90)                    ./EMBEDDED_FILES.h)
2216                          echo    " \\"  >> f90srclist.inc                          ignore_f=t
                         echo -n " $sf" >> f90srclist.inc  
2217                          ;;                          ;;
2218                      c)                    *)
2219                          echo    " \\"  >> csrclist.inc                          #  For the local directory *ONLY*,
2220                          echo -n " $sf" >> csrclist.inc                          #  ignore all soft-links
2221                          ;;                          if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then
2222                      h)                              ignore_f=t
2223                          echo    " \\"  >> hlist.inc                          else
2224                          echo -n " $sf" >> hlist.inc                              touch .links.tmp/$sf
2225                          ;;                              deplist="$deplist $sf"
2226                      flow)                          fi
                         echo    " \\"  >> ad_flow_files.inc  
                         echo -n " $sf" >> ad_flow_files.inc  
2227                          ;;                          ;;
2228                  esac                  esac
2229                    if test "x$ignore_f" = xf ; then
2230                        extn=`echo $sf | $AWK -F. '{print $NF}'`
2231                        case $extn in
2232                            F)
2233                                echo    " \\"  >> srclist.inc
2234                                printf " $sf" >> srclist.inc
2235                                ;;
2236                            F90)
2237                                echo    " \\"  >> f90srclist.inc
2238                                printf " $sf" >> f90srclist.inc
2239                                ;;
2240                            c)
2241                                echo    " \\"  >> csrclist.inc
2242                                printf " $sf" >> csrclist.inc
2243                                ;;
2244                            h)
2245                                echo    " \\"  >> hlist.inc
2246                                printf " $sf" >> hlist.inc
2247                                ;;
2248                            flow)
2249                                echo    " \\"  >> ad_flow_files.inc
2250                                printf " $sf" >> ad_flow_files.inc
2251                                ;;
2252                        esac
2253                    fi
2254              fi              fi
2255          fi          fi
2256      done      done
# Line 1425  echo "" >> f90srclist.inc Line 2268  echo "" >> f90srclist.inc
2268  echo "" >> hlist.inc  echo "" >> hlist.inc
2269  echo "" >> ad_flow_files.inc  echo "" >> ad_flow_files.inc
2270    
2271  if test -e $MAKEFILE ; then  if test -f $MAKEFILE ; then
2272      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.bak"
2273  fi  fi
2274  echo "  Writing makefile: $MAKEFILE"  echo "  Writing makefile: $MAKEFILE"
# Line 1434  echo "#    $MACHINE" >> $MAKEFILE Line 2277  echo "#    $MACHINE" >> $MAKEFILE
2277  echo "# This makefile was generated automatically on" >> $MAKEFILE  echo "# This makefile was generated automatically on" >> $MAKEFILE
2278  echo "#    $THISDATE" >> $MAKEFILE  echo "#    $THISDATE" >> $MAKEFILE
2279  echo "# by the command:" >> $MAKEFILE  echo "# by the command:" >> $MAKEFILE
2280  echo "#    $0 $@" >> $MAKEFILE  echo "#    $0 $G2ARGS" >> $MAKEFILE
2281  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
2282  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE  echo "#    ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
2283    
2284  EXE_AD=$EXECUTABLE"_ad"  EXE_AD=$EXECUTABLE"_ad"
2285  EXE_FTL=$EXECUTABLE"_ftl"  EXE_FTL=$EXECUTABLE"_ftl"
# Line 1482  ENABLED_PACKAGES = ${ENABLED_PACKAGES} Line 2325  ENABLED_PACKAGES = ${ENABLED_PACKAGES}
2325  DISABLED_PACKAGES = ${DISABLED_PACKAGES}  DISABLED_PACKAGES = ${DISABLED_PACKAGES}
2326    
2327  # These files are created by Makefile  # These files are created by Makefile
2328  SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h  SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h
   
2329  EOF  EOF
2330    
2331  #  Note: figure out some way to add Hyades JAM libraries here  if test "x$EMBED_SRC" = xt ; then
2332        echo "EMBEDDED_FILES = EMBEDDED_FILES.h" >>$MAKEFILE
2333    else
2334        echo "EMBEDDED_FILES = " >>$MAKEFILE
2335    fi
2336    
2337    #  Note: figure out some way to add Hyades JAM libraries here
2338  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2339  # Unix ln (link)  # Unix ln (link)
2340  LN = ${LN}  LN = ${LN}
# Line 1501  KPP = ${KPP} Line 2348  KPP = ${KPP}
2348  FC = ${FC}  FC = ${FC}
2349  # Fortran compiler  # Fortran compiler
2350  F90C = ${F90C}  F90C = ${F90C}
2351    # C compiler
2352    CC = ${CC}
2353  # Link editor  # Link editor
2354  LINK = ${LINK}  LINK = ${LINK} ${LDADD}
2355    
2356  # Defines for CPP  # Defines for CPP
2357  DEFINES = ${DEFINES}  DEFINES = ${DEFINES}
# Line 1523  CFLAGS = ${CFLAGS} Line 2372  CFLAGS = ${CFLAGS}
2372  NOOPTFILES = ${NOOPTFILES}  NOOPTFILES = ${NOOPTFILES}
2373  NOOPTFLAGS = ${NOOPTFLAGS}  NOOPTFLAGS = ${NOOPTFLAGS}
2374  # Flags and libraries needed for linking  # Flags and libraries needed for linking
2375  LIBS = ${LIBS} \$(XLIBS)  LIBS = ${LIBS}
2376  # Name of the Mekfile  # Name of the Mekfile
2377  MAKEFILE=${MAKEFILE}  MAKEFILE=${MAKEFILE}
2378    
# Line 1534  cat csrclist.inc      >> $MAKEFILE Line 2383  cat csrclist.inc      >> $MAKEFILE
2383  cat f90srclist.inc    >> $MAKEFILE  cat f90srclist.inc    >> $MAKEFILE
2384  cat hlist.inc         >> $MAKEFILE  cat hlist.inc         >> $MAKEFILE
2385  cat ad_flow_files.inc >> $MAKEFILE  cat ad_flow_files.inc >> $MAKEFILE
2386  echo               >> $MAKEFILE  echo >> $MAKEFILE
2387  echo 'F77FILES =  $(SRCFILES:.F=.f)'                                           >> $MAKEFILE  echo 'F77FILES =  $(SRCFILES:.F=.'$FS')'      >> $MAKEFILE
2388  echo 'F90FILES =  $(F90SRCFILES:.F90=.f90)'                                    >> $MAKEFILE  echo 'F90FILES =  $(F90SRCFILES:.F90=.'$FS90')' >> $MAKEFILE
2389  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
2390    echo >> $MAKEFILE
2391    echo '.SUFFIXES:' >> $MAKEFILE
2392    echo '.SUFFIXES: .o .'$FS' .p .F .c .'$FS90' .F90' >> $MAKEFILE
2393  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
2394  rm -f ad_flow_files.inc  rm -f ad_flow_files.inc
2395    
2396  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2397    
 .SUFFIXES:  
 .SUFFIXES: .o .f .p .F .c .F90 .f90  
   
2398  all: \$(EXECUTABLE)  all: \$(EXECUTABLE)
2399  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(OBJFILES)  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(OBJFILES) \$(EMBEDDED_FILES)
2400          @echo Creating \$@ ...          @echo Creating \$@ ...
2401          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
2402  depend:  depend:
2403          @make links          @make links
2404          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
2405          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2406            -rm -f makedepend.out
2407    
2408    lib: libmitgcmuv.a
2409    
2410    libmitgcmuv.a: \$(OBJFILES)
2411            ar rcv libmitgcmuv.a \$(OBJFILES)
2412    
2413  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES)  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES)
2414    
# Line 1565  output.txt: \$(EXECUTABLE) Line 2419  output.txt: \$(EXECUTABLE)
2419          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
2420    
2421  clean:  clean:
2422          -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl} *.template          -rm -rf *.o *.$FS *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
2423  Clean:  Clean:
2424          @make clean          @make clean
2425          @make cleanlinks          @make cleanlinks
# Line 1576  CLEAN: Line 2430  CLEAN:
2430          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
2431          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
2432          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
2433          -rm -f \$(EXECUTABLE) output.txt          -rm -f \$(EXECUTABLE) *.txt STD* *diagnostics.log datetime
2434            -rm -rf mnc_test_*
2435    
2436  #eh3 Makefile: makefile  #eh3 Makefile: makefile
2437  makefile:  makefile:
2438          $THIS_SCRIPT $@          $THIS_SCRIPT $G2ARGS
2439  cleanlinks:  cleanlinks:
2440          -find . -type l -exec rm {} \;          -find . -type l -exec rm {} \;
2441    
2442  # Special targets ($SPECIAL_FILES) which are create by make  # Special targets (SPECIAL_FILES) which are create by make
2443  ${PACKAGES_DOT_H}:  ${PACKAGES_DOT_H}:
2444          @echo Creating \$@ ...          @echo Creating \$@ ...
2445          @\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@          @$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) > \$@
2446  AD_CONFIG.h:  AD_CONFIG.h:
2447          @echo Creating \$@ ...          @echo Creating \$@ ...
2448          @\$(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 > \$@          @$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 > \$@
2449  FC_NAMEMANGLE.h:  FC_NAMEMANGLE.h:
2450          @echo Creating \$@ ...          @echo Creating \$@ ...
2451          echo "$FC_NAMEMANGLE" > \$@          echo "$FC_NAMEMANGLE" > \$@
2452    
2453  # The normal chain of rules is (  .F - .f - .o  )  BUILD_INFO.h:
2454  .F.f:          @echo Creating \$@ ...
2455    EOF
2456    
2457    test ! "x$THISVER" = x  && echo "       -echo \"#define THISVER '$THISVER'\" > \$@"   >> $MAKEFILE
2458    test ! "x$THISUSER" = x && echo "       -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE
2459    test ! "x$THISDATE" = x && echo "       -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
2460    test ! "x$THISHOST" = x && echo "       -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
2461    
2462    if test "x$EMBED_SRC" = xt ; then
2463        cat >>$MAKEFILE <<EOF
2464    
2465    decode_files.o : EMBEDDED_FILES.h
2466    
2467    ##  \$(F77FILES)
2468    all_fF.tar.gz : \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(F77FILES) Makefile
2469            @echo Creating \$@ ...
2470            -tar -hcf all_fF.tar \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(F77FILES) Makefile
2471            -rm -f all_fF.tar.gz
2472            -gzip all_fF.tar
2473    
2474    EMBEDDED_FILES.h : all_fF.tar.gz
2475            @echo Creating \$@ ...
2476            -\${ROOTDIR}/tools/embed_encode/encode_files EMBEDDED_FILES.h all_fF.tar.gz
2477    
2478    EOF
2479    fi
2480    
2481    cat >>$MAKEFILE <<EOF
2482    
2483    # The normal chain of rules is (  .F - .$FS - .o  )
2484    
2485    ## This nullifies any default implicit rules concerning these two file types:
2486    ## %.o : %.F
2487    
2488    .F.$FS:
2489          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2490  .f.o:  .$FS.o:
2491          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2492  .F90.f90:  .F90.$FS90:
2493          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2494  .f90.o:  .$FS90.o:
2495          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
2496  .c.o:  .c.o:
2497          \$(CC) \$(CFLAGS) -c \$<          \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$<
2498    
2499  # Special exceptions that use the ( .F - .p - .f - .o ) rule-chain  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
2500  .F.p:  .F.p:
2501          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2502  .p.f:  .p.$FS:
2503          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
2504    
2505  #=========================================  #=========================================
# Line 1637  done Line 2526  done
2526    
2527  echo "  Add the source list for AD code generation"  echo "  Add the source list for AD code generation"
2528  echo >> $MAKEFILE  echo >> $MAKEFILE
2529  echo -n "AD_FILES = " >> $MAKEFILE  printf "AD_FILES = " >> $MAKEFILE
2530  AD_FILES=`cat ad_files`  AD_FILES=`cat ad_files`
2531  for i in $AD_FILES ; do  for i in $AD_FILES ; do
2532      echo    " \\" >> $MAKEFILE      echo    " \\" >> $MAKEFILE
2533      echo -n " $i" >> $MAKEFILE      printf " $i" >> $MAKEFILE
2534  done  done
2535  echo >> $MAKEFILE  echo >> $MAKEFILE
2536  rm -f ad_files  rm -f ad_files
# Line 1650  cat >>$MAKEFILE <<EOF Line 2539  cat >>$MAKEFILE <<EOF
2539    
2540  # ... AD ...  # ... AD ...
2541  adall: ad_taf  adall: ad_taf
2542  adtaf: ad_taf_output.f  adtaf: ad_taf_output.$FS
2543  adtamc: ad_tamc_output.f  adtamc: ad_tamc_output.$FS
2544    
2545  ad_input_code.f: \$(AD_FILES) \$(HEADERFILES)  ad_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)
2546          @\$(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          @$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
2547          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
2548          -rm -f ad_config.template          -rm -f ad_config.template
2549          @make \$(F77FILES)          @make \$(F77FILES)
2550          @make \$(AD_FLOW_FILES)          @make \$(AD_FLOW_FILES)
2551          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.$FS
2552    
2553  ad_taf_output.f: ad_input_code.f  ad_taf_output.$FS: ad_input_code.$FS
2554          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2555          cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
2556    
2557  adtafonly:  adtafonly:
2558          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2559          cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
2560    
2561  ad_taf: ad_taf_output.o \$(OBJFILES)  ad_taf: ad_taf_output.o \$(OBJFILES)
2562          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
2563    
2564  ad_tamc_output.f: ad_input_code.f  ad_tamc_output.$FS: ad_input_code.$FS
2565          \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f          \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
2566          cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.f          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS
2567    
2568  ad_tamc: ad_tamc_output.o \$(OBJFILES)  ad_tamc: ad_tamc_output.o \$(OBJFILES)
2569          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
2570    
2571    adonlyfwd:
2572            patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
2573    
2574    adtrick:
2575            patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
2576    
2577  # ... FTL ...  # ... FTL ...
2578  ftlall: ftl_taf  ftlall: ftl_taf
2579  ftltaf: ftl_taf_output.f  ftltaf: ftl_taf_output.$FS
2580  ftltamc: ftl_tamc_output.f  ftltamc: ftl_tamc_output.$FS
2581    
2582  ftl_input_code.f: \$(AD_FILES) \$(HEADERFILES)  ftl_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)
2583          @\$(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          @$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
2584          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
2585          -rm -f ftl_config.template          -rm -f ftl_config.template
2586          @make \$(F77FILES)          @make \$(F77FILES)
2587          @make \$(AD_FLOW_FILES)          @make \$(AD_FLOW_FILES)
2588          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.$FS
2589    
2590  ftl_taf_output.f: ftl_input_code.f  ftl_taf_output.$FS: ftl_input_code.$FS
2591          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2592          cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2593    
2594  ftltafonly:  ftltafonly:
2595          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2596          cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2597    
2598  ftl_taf: ftl_taf_output.o \$(OBJFILES)  ftl_taf: ftl_taf_output.o \$(OBJFILES)
2599          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
2600    
2601  ftl_tamc_output.f: ftl_input_code.f  ftl_tamc_output.$FS: ftl_input_code.$FS
2602          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
2603          cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.f          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS
2604    
2605  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
2606          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
2607    
2608    
2609  # ... SVD ...  # ... SVD ...
2610  svdtaf: ad_taf_output.f ftl_taf_output.f  svdtaf: ad_taf_output.$FS ftl_taf_output.$FS
2611  svdall: svd_taf          @echo "--->>> Only ran TAF to generate SVD code!    <<<---"
2612            @echo "--->>> Do make svdall afterwards to compile. <<<---"
2613    svdall: svd_touch svd_taf
2614    
2615  svd_taf: ad_taf_output.o ftl_taf_output.o \$(OBJFILES)  svd_taf: \$(OBJFILES)
2616          \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)          \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
2617    
2618            @echo "--->>> Only COMPILE svd code! <<<---"
2619            @echo "--->>> Assumes you previously <<<---"
2620            @echo "--->>> did make svdtaf        <<<---"
2621    
2622    svd_touch:
2623            @echo "--->>> Only COMPILE svd code! <<<---"
2624            @echo "--->>> Assumes you previously <<<---"
2625            @echo "--->>> did make svdtaf        <<<---"
2626            touch ad_taf_output.$FS ftl_taf_output.$FS
2627            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS
2628            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS
2629            @$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
2630            cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
2631            -rm -f ftl_config.template
2632    
2633  #=========================================  #=========================================
2634    
# Line 1735  for i in $KPPFILES ; do Line 2645  for i in $KPPFILES ; do
2645      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
2646          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
2647      fi      fi
2648      echo "$base.f: $base.p" >> $MAKEFILE      echo "$base.$FS: $base.p" >> $MAKEFILE
2649  done  done
2650    
2651  echo "  Making list of NOOPTFILES"  echo "  Making list of NOOPTFILES"
# Line 1745  for i in $NOOPTFILES ; do Line 2655  for i in $NOOPTFILES ; do
2655      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
2656          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
2657      fi      fi
2658      echo "$base.o: $base.f" >> $MAKEFILE      echo "$base.o: $base.$FS" >> $MAKEFILE
2659      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
2660  done  done
2661    
# Line 1759  printf "\n\n# DO NOT DELETE\n" >> $MAKEF Line 2669  printf "\n\n# DO NOT DELETE\n" >> $MAKEF
2669  printf "\n===  Done  ===\n"  printf "\n===  Done  ===\n"
2670    
2671  # Create special header files  # Create special header files
2672  $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"  $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"
2673  if test ! -f $PACKAGES_DOT_H ; then  if test ! -f $PACKAGES_DOT_H ; then
2674      mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H      mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2675  else  else
# Line 1773  else Line 2683  else
2683      fi      fi
2684  fi  fi
2685  if test ! -f AD_CONFIG.h ; then  if test ! -f AD_CONFIG.h ; then
2686      $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      $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
2687  fi  fi
2688    
2689    
2690  #  Write the "state" for future records  #  Write the "state" for future records
2691  if test "x$DUMPSTATE" != xf ; then  if test "x$DUMPSTATE" != xf ; then
2692      echo -n "" > genmake_state      printf "" > genmake_state
2693      for i in $gm_state ; do      for i in $gm_state ; do
2694          t1="t2=\$$i"          t1="t2=\$$i"
2695          eval $t1          eval $t1

Legend:
Removed from v.1.64  
changed lines
  Added in v.1.146

  ViewVC Help
Powered by ViewVC 1.1.22