/[MITgcm]/MITgcm/tools/genmake2
ViewVC logotype

Diff of /MITgcm/tools/genmake2

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.36 by edhill, Fri Nov 14 02:48:18 2003 UTC revision 1.237 by jmc, Fri Aug 24 23:41:17 2012 UTC
# Line 1  Line 1 
1  #!/bin/sh  #! /usr/bin/env bash
2  #  #
3  # $Header$  # $Header$
4    # $Name$
5  #  #
6  # Makefile generator for MITgcm UV codes  # Makefile generator for MITgcm UV codes
7  #   created  by cnh 03/98  #   created  by cnh 03/98
# Line 8  Line 9 
9  #   modified by aja 01/00  #   modified by aja 01/00
10  #   rewritten in bash by eh3 08/03  #   rewritten in bash by eh3 08/03
11    
12    #  Explain usage
13    usage()  {
14    cat <<EOF
15    
16    Usage: "$0" [OPTIONS]
17      where [OPTIONS] can be:
18    
19        -help | --help | -h | --h
20              Print this help message and exit.
21    
22        -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME
23          -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME
24              Use "NAME" as the adoptfile.  By default, the file at
25              "tools/adjoint_options/adjoint_default" will be used.
26    
27        -nooptfile | --nooptfile
28          -optfile NAME | --optfile NAME | -of NAME | --of NAME
29          -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
30              Use "NAME" as the optfile.  By default, an attempt will be
31              made to find an appropriate "standard" optfile in the
32              tools/build_options/ directory.
33    
34        -pdepend NAME | --pdepend NAME
35          -pdepend=NAME | --pdepend=NAME
36              Get package dependency information from "NAME".
37    
38        -pgroups NAME | --pgroups NAME
39          -pgroups=NAME | --pgroups=NAME
40              Get the package groups information from "NAME".
41    
42        -bash NAME
43              Explicitly specify the Bourne or BASH shell to use
44    
45        -make NAME | -m NAME
46          --make=NAME | -m=NAME
47              Use "NAME" for the MAKE program. The default is "make" but
48              many platforms, "gmake" is the preferred choice.
49    
50        -makefile NAME | -mf NAME
51          --makefile=NAME | -mf=NAME
52              Call the makefile "NAME".  The default is "Makefile".
53    
54        -makedepend NAME | -md NAME
55          --makedepend=NAME | -md=NAME
56              Use "NAME" for the MAKEDEPEND program.
57    
58        -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
59          -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
60              Specify the location of the MITgcm ROOTDIR as "NAME".
61              By default, genamke will try to find the location by
62              looking in parent directories (up to the 5th parent).
63    
64        -mods NAME | --mods NAME | -mo NAME | --mo NAME
65          -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
66              Here, "NAME" specifies a list of directories that are
67              used for additional source code.  Files found in the
68              "mods list" are given preference over files of the same
69              name found elsewhere.
70    
71        -disable NAME | --disable NAME
72          -disable=NAME | --disable=NAME
73              Here "NAME" specifies a list of packages that we don't
74              want to use.  If this violates package dependencies,
75              genamke will exit with an error message.
76    
77        -enable NAME | --enable NAME
78          -enable=NAME | --enable=NAME
79              Here "NAME" specifies a list of packages that we wish
80              to specifically enable.  If this violates package
81              dependencies, genamke will exit with an error message.
82    
83        -standarddirs NAME | --standarddirs NAME
84          -standarddirs=NAME | --standarddirs=NAME
85              Here, "NAME" specifies a list of directories to be
86              used as the "standard" code.
87    
88        -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
89          -fc=NAME | --fc=NAME
90              Use "NAME" as the fortran compiler.  By default, genmake
91              will search for a working compiler by trying a list of
92              "usual suspects" such as g77, f77, etc.
93    
94        -cc NAME | --cc NAME | -cc=NAME | --cc=NAME
95              Use "NAME" as the C compiler.  By default, genmake
96              will search for a working compiler by trying a list of
97              "usual suspects" such as gcc, c89, cc, etc.
98    
99        -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4
100              Use "real*4" type for _RS variable (#undef REAL4_IS_SLOW)
101              *only* works if CPP_EEOPTIONS.h allows this.
102    
103        -ignoretime | -ignore_time | --ignoretime | --ignore_time
104              Ignore all the "wall clock" routines entirely.  This will
105              not in any way hurt the model results -- it simply means
106              that the code that checks how long the model spends in
107              various routines will give junk values.
108    
109        -ts | --ts
110              Produce timing information per timestep
111        -papis | --papis
112              Produce summary MFlop/s (and IPC) with PAPI per timestep
113        -pcls | --pcls
114              Produce summary MFlop/s etc. with PCL per timestep
115        -foolad | --foolad
116              Fool the AD code generator
117        -papi | --papi
118              Performance analysis with PAPI
119        -pcl | --pcl
120              Performance analysis with PCL
121        -hpmt | --hpmt
122              Performance analysis with the HPM Toolkit
123    
124        -ieee | --ieee
125              use IEEE numerics.  Note that this option *only* works
126              if it is supported by the OPTFILE that is being used.
127        -devel | --devel
128              Add additional warning and debugging flags for development
129              (if supported by the OPTFILE); also switch to IEEE numerics.
130        -gsl | --gsl
131              Use GSL to control floating point rounding and precision
132    
133        -mpi | --mpi
134              Include MPI header files and link to MPI libraries
135        -mpi=PATH | --mpi=PATH
136              Include MPI header files and link to MPI libraries using MPI_ROOT
137              set to PATH. i.e. Include files from \$PATH/include, link to libraries
138              from \$PATH/lib and use binaries from \$PATH/bin.
139    
140        -omp | --omp
141              Activate OpenMP code + use Compiler option OMPFLAG
142        -omp=OMPFLAG | --omp=OMPFLAG
143              Activate OpenMP code + use Compiler option OMPFLAG
144    
145        -es | --es | -embed-source | --embed-source
146              Embed a tarball containing the full source code
147              (including the Makefile, etc.) used to build the
148              executable [off by default]
149    
150        -ds | --ds
151              Report genmake internal variables status (DUMPSTATE)
152              to file "genmake_state" (for debug purpose)
153    
154      While it is most often a single word, the "NAME" variables specified
155      above can in many cases be a space-delimited string such as:
156    
157        --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'
158        -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'
159        -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
160    
161      which, depending upon your shell, may need to be single-quoted.
162    
163      For more detailed genmake documentation, please see:
164    
165        http://mitgcm.org/public/devel_HOWTO/
166    
167    EOF
168    
169        exit 1
170    }
171    
172  # Search for particular CPP #cmds associated with packages  # Search for particular CPP #cmds associated with packages
173  # usage: test_for_package_in_cpp_options CPP_file package_name  # usage: test_for_package_in_cpp_options CPP_file package_name
174  test_for_package_in_cpp_options() {  test_for_package_in_cpp_options() {
175      cpp_options=$1      cpp_options=$1
176      pkg=$2      pkg=$2
177      grep -i "#define.*ALLOW_$pkg" $cpp_options > /dev/null 2>&1      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg[ ]"
178      RETVAL=$?      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg[ ]"
179      if test "x${RETVAL}" = x0 ; then      test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg[ ]"
180          echo "Error: In $cpp_options there is an illegal line: #define ALLOW_$pkg"      test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg[ ]"
181          exit 99      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg$"
182      fi      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg$"
183      grep -i "#undef.*ALLOW_$pkg" $cpp_options > /dev/null 2>&1      test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg$"
184      RETVAL=$?      test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg$"
185      if test "x${RETVAL}" = x0 ; then  }
186          echo "Error: In $cpp_options there is an illegal line: #undef ALLOW_$pkg"  
187          exit 99  # Search for particular CPP #cmds associated with MPI
188      fi  # usage: test_for_mpi_in_cpp_eeoptions CPP_file
189      grep -i "#define.*DISABLE_$pkg" $cpp_options > /dev/null 2>&1  test_for_mpi_in_cpp_eeoptions() {
190        cpp_options=$1
191        test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI[ ]"
192        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI[ ]"
193        test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI[ ]"
194        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI[ ]"
195        test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI$"
196        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI$"
197        test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI$"
198        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI$"
199    }
200    
201    # Search for particular string in a file. Return 1 if detected, 0 if not
202    # usage: test_for_string_in_file file string
203    test_for_string_in_file() {
204        file=$1
205        strng=$2
206        grep -i "$strng" $file > /dev/null 2>&1
207      RETVAL=$?      RETVAL=$?
208      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
209          echo "Error: In $cpp_options there is an illegal line: #define DISABLE_$pkg"          printf "Error: In $file there is an illegal line: "
210            grep -i "$strng" $file
211          exit 99          exit 99
212      fi      fi
213      grep -i "#undef.*DISABLE_$pkg" $cpp_options > /dev/null 2>&1      return 0
     RETVAL=$?  
     if test "x${RETVAL}" = x0 ; then  
         echo "Error: In $cpp_options there is an illegal line: #undef DISABLE_$pkg"  
         exit 99  
    fi  
214  }  }
215    
216  # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to  # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to
217  # the package list.  # the package list.
218  expand_pkg_groups() {  expand_pkg_groups() {
219      new_packages=      new_packages=
     PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups"  
220      if test -r $PKG_GROUPS ; then      if test -r $PKG_GROUPS ; then
221          cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp          cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp
222          cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp          cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp
# Line 54  expand_pkg_groups() { Line 227  expand_pkg_groups() {
227              if test "x$RETVAL" = x0 ; then              if test "x$RETVAL" = x0 ; then
228                  matched=1                  matched=1
229                  replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`                  replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`
230                  echo "    replacing \"$i\" with: $replace"                  echo "    replacing \"$i\" with:$replace"
231                  new_packages="$new_packages $replace"                  new_packages="$new_packages $replace"
232              else              else
233                  new_packages="$new_packages $i"                  new_packages="$new_packages $i"
# Line 62  expand_pkg_groups() { Line 235  expand_pkg_groups() {
235          done          done
236          PACKAGES=$new_packages          PACKAGES=$new_packages
237          rm -f ./p[1,2].tmp          rm -f ./p[1,2].tmp
238            return $matched
239      else      else
240          echo "Warning: can't read package groups definition file: $PKG_GROUPS"          echo "Warning: can't read package groups definition file: $PKG_GROUPS"
241      fi      fi
242  }  }
243    
244  # Guess possible config options for this host  #  Check for broken environments (eg. cygwin, MacOSX w/HFS+) that
245  find_possible_configs()  {  #  cannot distinguish [*.F/*.F90] from [*.f/*.f90] files.
246    check_for_broken_Ff()  {
247        #  Do we have defaults for $FS and/or $FS90 ?
248        tfs=f
249        tfs9=f90
250        if test "x$FS" != x ; then
251            tfs="$FS"
252        fi
253        if test "x$FS90" != x ; then
254            tfs9="$FS90"
255        fi
256    
257      tmp1=`uname`"_"`uname -m`      #  First check the ability to create a *.F/.f pair.
258      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`      cat <<EOF >> genmake_hello.F
259      tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`        program hello
260      PLATFORM=`echo $tmp3 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`        write(*,*) 'hi'
261      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`        stop
262      echo "  The platform appears to be:  $PLATFORM"        end
263  #     if test "x$OFLIST" = x ; then  EOF
264  #       echo "  No pre-defined options files were found matching this platform"      cp genmake_hello.F "genmake_hello."$tfs > /dev/null 2>&1
 #       echo "  but examples for other platforms can be found in:"  
 #       echo "    $ROOTDIR/tools/build_options"  
 #     else  
 #       echo "  Options files (located in $ROOTDIR/tools/build_options) that"  
 #       echo "  may work with this machine are:"  
 #       for i in $OFLIST ; do  
 #           echo "    $i"  
 #       done  
 #     fi  
       
     echo "test" > test  
     ln -s ./test link  
265      RETVAL=$?      RETVAL=$?
266      if test "x${RETVAL}" = x0 ; then      if test "x$RETVAL" != x0 ; then
267          LN="ln -s"          if test "x$FS" = x ; then
268      else              FS='for'
269          echo "Error: \"ln -s\" does not appear to work on this system!"              FS90='fr9'
270          echo "  For help, please contact <MITgcm-support@mitgcm.org>."              check_for_broken_Ff
271          exit 1          else
272                cat <<EOF 2>&1
273    ERROR: Your file system cannot distinguish between *.F and *.f files
274      (fails the "cp" test) and this program cannot find a suitable
275      replacement extension.  Please try a different build environment or
276      contact the <MITgcm-support@mitgcm.org> list for help.
277    
278    EOF
279                exit -1
280            fi
281            return
282      fi      fi
283      rm -f test link      rm -f genmake_hello.*
284    
285      if test "x$CPP" = x ; then      #  Check the ability of ${MAKE} and ${LN} to use the current set
286          CPP="cpp -traditional -P"      #  of extensions.
287        cat <<EOF >> genmake_hello.F
288          program hello
289          write(*,*) 'hi'
290          stop
291          end
292    EOF
293        test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
294        cat <<EOF >> $MAKEFILE
295    .SUFFIXES:
296    .SUFFIXES: .$tfs .F
297    .F.$tfs:
298            $LN \$< \$@
299    EOF
300        $MAKE -f $MAKEFILE "genmake_hello."$tfs > /dev/null 2>&1
301        RETVAL=$?
302        if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then
303            if test "x$FS" = x ; then
304                FS='for'
305                FS90='fr9'
306                check_for_broken_Ff
307            else
308                echo "ERROR: test: '$MAKE -f $MAKEFILE genmake_hello.$tfs' Failed"
309                echo "       see simple makefile: '$MAKEFILE' (left here)"
310                echo "  Please check (1) your '$MAKE' command, (2) your '$LN' command"
311                echo "           and (3) the allowed sufix '.F' and '.$tfs' in makefile"
312                echo "  or contact the <MITgcm-support@mitgcm.org> list for help."
313                echo ""
314                exit -1
315                return
316            fi
317      fi      fi
318        rm -f genmake_hello.* $MAKEFILE
319        test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
320    
321        #  If we make it here, use the extensions
322        FS=$tfs
323        FS90=$tfs9
324        return
325    }
326    
327      # makedepend is not always available  look_for_makedepend()  {
328    
329        #  The "original" makedepend is part of the Imake system that is
330        #  most often distributed with XFree86 or with an XFree86 source
331        #  package.  As a result, many machines (eg. generic Linux) do not
332        #  have a system-default "makedepend" available.  For those
333        #  systems, we have two fall-back options:
334        #
335        #    1) a makedepend implementation shipped with the cyrus-imapd
336        #       package:  ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
337        #
338        #    2) a known-buggy xmakedpend shell script
339        #
340        #  So the choices are, in order:
341        #
342        #    1) use the user-specified program
343        #    2) use a system-wide default
344        #    3) locally build and use the cyrus implementation
345        #    4) fall back to the buggy local xmakedpend script
346        #
347        echo >> $LOGFILE
348        echo "running: look_for_makedepend()" >> $LOGFILE
349        if test "x${MAKEDEPEND}" != x ; then
350            echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1
351            RETVAL=$?
352            if test x"$RETVAL" = x0 ; then
353                build_cyrus_makedepend
354                RETVAL=$?
355                if test "x$RETVAL" != x0 ; then
356                    echo "WARNING: unable to build cyrus-makedepend. Try 'makedepend'"
357                    MAKEDEPEND=
358                fi
359            else
360                echo "${MAKEDEPEND}" | grep 'tools.xmakedepend' > /dev/null 2>&1
361                RETVAL=$?
362                if test "x$RETVAL" = x0 ; then
363                    MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
364                fi
365                echo " -->     MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
366            fi
367        fi
368      if test "x${MAKEDEPEND}" = x ; then      if test "x${MAKEDEPEND}" = x ; then
369        which makedepend >& /dev/null          which makedepend > /dev/null 2>&1
370        RETVAL=$?          RV0=$?
371        if test "x${RETVAL}" = x1 ; then          test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
372           echo "    makedepend was not found. Using xmakedpend instead."          #  echo 'MAKEFILE="'$MAKEFILE'"'
373           MAKEDEPEND='$(TOOLSDIR)/xmakedepend'          cat <<EOF >> $MAKEFILE
374        fi  #   THIS IS A TEST MAKEFILE GENERATED BY "genmake2"
375    #
376    #   Some "makedepend" implementations will die if they cannot
377    #   find a Makefile -- so this file is here to gives them an
378    #   empty one to find and parse.
379    EOF
380            cat <<EOF >> genmake_tc.f
381          program test
382          write(*,*) 'test'
383          stop
384          end
385    EOF
386            makedepend -f $MAKEFILE genmake_tc.f > /dev/null 2>&1
387            RV1=$?
388            test -f $MAKEFILE  &&  rm -f $MAKEFILE
389            test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
390            if test "x${RV0}${RV1}" = x00 ; then
391                MAKEDEPEND=makedepend
392                echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
393            else
394                echo "    system-default makedepend not found. Try to build cyrus-makedepend"
395                #  Try to build the cyrus implementation
396                build_cyrus_makedepend
397                RETVAL=$?
398                if test "x$RETVAL" != x0 ; then
399                    echo "WARNING: unable to build cyrus-makedepend. Use local xmakedepend"
400                    MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
401                    echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
402                fi
403            fi
404      fi      fi
405    }
406    
407      # look for possible fortran compilers  build_cyrus_makedepend()  {
408      tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"      echo >> $LOGFILE
409      p_FC=      echo "running: build_cyrus_makedepend()" >> $LOGFILE
410        rm -f ./genmake_cy_md
411        (
412            cd $ROOTDIR/tools/cyrus-imapd-makedepend  \
413                &&  ./configure > /dev/null 2>&1  \
414                &&  make > /dev/null 2>&1
415            if test -x ./makedepend.exe ; then
416                $LN ./makedepend.exe ./makedepend
417            fi
418            ./makedepend ifparser.c > /dev/null 2>&1  \
419                &&  echo "true"
420        ) > ./genmake_cy_md
421        grep true ./genmake_cy_md > /dev/null 2>&1
422        RETVAL=$?
423        rm -f ./genmake_cy_md
424        if test "x$RETVAL" = x0 ; then
425            MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
426            echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
427            return 0
428        else
429            echo "WARNING: fail to build cyrus-imapd-makedepend" >> $LOGFILE
430            return 1
431        fi
432    }
433    
434    build_embed_encode()
435    {
436        printf "  building the embed-encode utility...  "
437        if test ! -e "$ROOTDIR/tools/embed_encode/encode_files" ; then
438            if test ! -d "$ROOTDIR/tools/embed_encode" ; then
439                echo
440                echo "    Error: can't locate \"$ROOTDIR/tools/embed_encode\""
441                echo
442                EMBED_SRC=f
443                return 1
444            fi
445            clist="cc gcc c89 $CC"
446            for ic in $clist ; do
447                comm="$ic -o encode_files encode_files.c"
448                ( cd $ROOTDIR/tools/embed_encode && $comm ) > /dev/null 2>&1
449                RETVAL=$?
450                if test "x$RETVAL" = x0 ; then
451                    echo "OK"
452                    return 0
453                fi
454            done
455            echo
456            echo "    Error: unable to build $ROOTDIR/embed_encode/encode_files"
457            echo "      so it has been disabled"
458            echo
459            EMBED_SRC=f
460            return 1
461        fi
462        echo "OK"
463    }
464    
465    #  look for possible C compilers
466    look_for_C_compilers() {
467        echo >> $LOGFILE
468        echo "running: look_for_C_compilers()" >> $LOGFILE
469        rm -f ./genmake_hello.c  ./genmake_hello
470        cat >> genmake_hello.c << EOF
471    #include <stdio.h>
472    int main(int argc, char **argv) {
473      printf("Hello!\n");
474      return 0;
475    }
476    EOF
477        tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc icc"
478        p_CC=
479      for c in $tmp ; do      for c in $tmp ; do
480          rm -f ./hello.f ./hello          COMM="$c $CFLAGS -o genmake_hello genmake_hello.c"
481          cat >> hello.f <<EOF          echo $COMM >> $LOGFILE
482            $COMM >> $LOGFILE 2>&1
483            RETVAL=$?
484            if test "x${RETVAL}" = x0 ; then
485                echo " $c test successful" >> $LOGFILE
486                p_CC="$p_CC $c"
487            fi
488        done
489        rm -f ./genmake_hello.c ./genmake_hello
490        if test "x${p_CC}" = x ; then
491            cat 1>&2 <<EOF
492    
493    Error: No C compilers were found in your path.  Please specify one using:
494    
495        1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
496        2) the CC or MITGCM_CC environment variables.
497    
498    EOF
499            exit 1
500        else
501            echo "  The possible C compilers found in your path are: $p_CC" | tee -a $LOGFILE
502            if test "x$CC" = x ; then
503                CC=`echo $p_CC | $AWK '{print $1}'`
504                echo "  Setting C compiler to: "$CC
505            fi
506        fi
507        echo " --> set CC='$CC'" >> $LOGFILE
508    }
509    
510    # Guess possible config options for this host
511    find_possible_optfile()  {
512    
513        echo >> $LOGFILE
514        echo "running: find_possible_optfile()" >> $LOGFILE
515        tmp1=`uname`"_"`uname -m`
516        tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
517        tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
518        tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
519        tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
520        tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
521        PLATFORM=$tmp3
522        echo $PLATFORM | grep cygwin > /dev/null 2>&1  &&  PLATFORM=cygwin_ia32
523        OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
524        echo "  The platform appears to be:  $PLATFORM" | tee -a $LOGFILE
525    
526        #================================================================
527        #  look for possible FORTRAN compilers
528        echo "  look for possible FORTRAN compilers" >> $LOGFILE
529        tmp="$MITGCM_FC $FC efc gfortran g77 f77 pgf77 pgf95 ifc ifort f90 f95 mpif77 mpf77 mpxlf95 g95"
530        p_FC=
531        rm -f ./genmake_hello.f
532        cat >> genmake_hello.f <<EOF
533        program hello        program hello
534        do i=1,3        do i=1,3
535          print *, 'hello world : ', i          print *, 'hello world : ', i
536        enddo        enddo
537        end        end
538  EOF  EOF
539          $c -o hello hello.f > /dev/null 2>&1      for f in $tmp ; do
540            COMM="$f -o genmake_hello genmake_hello.f"
541            echo $COMM >> $LOGFILE
542            $COMM >> $LOGFILE 2>&1
543          RETVAL=$?          RETVAL=$?
544          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
545              p_FC="$p_FC $c"              echo " $f test successful" >> $LOGFILE
546                p_FC="$p_FC $f"
547          fi          fi
548      done      done
549      rm -f ./hello.f ./hello      rm -f ./genmake_hello.f ./genmake_hello
550      if test "x${p_FC}" = x ; then      if test "x${p_FC}" = x ; then
551          cat 1>&2 <<EOF          cat 1>&2 <<EOF
552    
# Line 140  Error: No Fortran compilers were found i Line 554  Error: No Fortran compilers were found i
554    
555      1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),      1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
556      2) a command-line option (eg. "-fc NAME"), or      2) a command-line option (eg. "-fc NAME"), or
557      3) the MITGCM_FC environment variable.      3) the FC or MITGCM_FC environment variables.
558    
559  EOF  EOF
560          exit 1          exit 1
561      else      else
562          echo "  The possible FORTRAN compilers found in your path are:"          echo "  The possible FORTRAN compilers found in your path are: $p_FC" | tee -a $LOGFILE
         echo "   "$p_FC  
         if test "x$FC" = x ; then  
             FC=`echo $p_FC | $AWK '{print $1}'`  
         fi  
563      fi      fi
564    
565      for i in $p_FC ; do      #  Use the first of the compilers found in the current PATH
566          p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i      #  that has a correctly-named optfile
567          if test -r $p_OF ; then      if test "x$OPTFILE" = x  -a  "x$FC" = x ; then
568              OPTFILE=$p_OF          for i in $p_FC ; do
569              echo "  The options file:  $p_OF"              OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
570              echo "    appears to match so we'll use it."              if test -r $OPTFILE ; then
571              break                  echo "  Setting OPTFILE to: "$OPTFILE | tee -a $LOGFILE
572                    break
573                fi
574            done
575        fi
576    
577        if test "x$OPTFILE" = x ; then
578            OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
579            if test ! -r $OPTFILE ; then
580                 echo "  I looked for the file "$OPTFILE" but did not find it"
581          fi          fi
582      done      fi
583    
584      if test "x$OPTFILE" = x ; then      if test "x$OPTFILE" = x ; then
585          cat 1>&2 <<EOF          cat 1>&2 <<EOF
586    
# Line 176  Error: No options file was found in:  $R Line 596  Error: No options file was found in:  $R
596  EOF  EOF
597          exit 1          exit 1
598      fi      fi
599        
600  #     # look for possible MPI libraries  #     # look for possible MPI libraries
601  #     mpi_libs=  #     mpi_libs=
602  #     mpi_fort=`which mpif77 2>/dev/null`  #     mpi_fort=`which mpif77 2>/dev/null`
# Line 195  EOF Line 615  EOF
615  #       if test "x${RETVAL}" = x0 ; then  #       if test "x${RETVAL}" = x0 ; then
616  #           a=`cat out`  #           a=`cat out`
617  #           for i in $a ; do  #           for i in $a ; do
618  #               case $i in  #               case $i in
619  #                   -*)  #                   -*)
620  #                       mpi_libs="$mpi_libs $i" ;;  #                       mpi_libs="$mpi_libs $i" ;;
621  #               esac  #               esac
# Line 205  EOF Line 625  EOF
625  #       fi  #       fi
626  #       rm -f test.f out  #       rm -f test.f out
627  #     fi  #     fi
   
628  }  }
629    
630  #  Parse the package dependency information  #  Parse the package dependency information
# Line 214  get_pdepend_list()  { Line 633  get_pdepend_list()  {
633      #  strip the comments and then convert the dependency file into      #  strip the comments and then convert the dependency file into
634      #  two arrays: PNAME, DNAME      #  two arrays: PNAME, DNAME
635      cat $1 | sed -e 's/#.*$//g' \      cat $1 | sed -e 's/#.*$//g' \
636          | $AWK 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \          | $AWK 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \
637          > ./.pd_tmp          > ./.pd_tmp
638        RETVAL=$?
639        if test ! "x${RETVAL}" = x0 ; then
640          echo "Error: unable to parse package dependencies -- please check PKG_DEPEND=\"$1\""
641          exit 1
642        fi
643      . ./.pd_tmp      . ./.pd_tmp
644      rm -f ./.pd_tmp      rm -f ./.pd_tmp
   
     echo -n "PNAME = "${}  
 }  
   
   
 #  Explain usage  
 usage()  {  
     echo  
     echo "Usage: "$0" [OPTIONS]"  
     echo "  where [OPTIONS] can be:"  
     echo  
     echo "    -help | --help | -h | --h"  
     echo "    -nooptfile | --nooptfile"  
     echo "      -optfile NAME | --optfile NAME | -of NAME | --of NAME"  
     echo "      -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME"  
     echo "    -pdepend NAME | --pdepend NAME"  
     echo "      -pdepend=NAME | --pdepend=NAME"  
     echo "    -pdefault NAME | --pdefault NAME"  
     echo "      -pdefault=NAME | --pdefault=NAME"  
     echo "    -make NAME | -m NAME"  
     echo "      --make=NAME | -m=NAME"  
     echo "    -makefile NAME | -mf NAME"  
     echo "      --makefile=NAME | -mf=NAME"  
     echo "    -platform NAME | --platform NAME | -pl NAME | --pl NAME"  
     echo "      -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"  
     echo "    -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"  
     echo "      -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME"  
     echo "    -mods NAME | --mods NAME | -mo NAME | --mo NAME"  
     echo "      -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME"  
     echo "    -disable NAME | --disable NAME"  
     echo "      -disable=NAME | --disable=NAME"  
     echo "    -enable NAME | --enable NAME"  
     echo "      -enable=NAME | --enable=NAME"  
     echo "    -standarddirs NAME | --standarddirs NAME"  
     echo "      -standarddirs=NAME | --standarddirs=NAME"  
     echo "    -noopt NAME | --noopt NAME"  
     echo "      -noopt=NAME | --noopt=NAME"  
 #    echo "    -cpp NAME | --cpp NAME"  
 #    echo "      -cpp=NAME | --cpp=NAME"  
     echo "    -fortran NAME | --fortran NAME | -fc NAME | --fc NAME"  
     echo "      -fc=NAME | --fc=NAME"  
     echo "    -[no]ieee | --[no]ieee"  
     echo "    -[no]mpi | --[no]mpi"  
     echo "    -[no]jam | --[no]jam"  
     echo  
     echo "  and NAME is a string such as:"  
     echo  
     echo "    --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'"  
     echo "    -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'"  
     echo "    -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"  
     echo  
     echo "  which, depending upon your shell, may need to be single-quoted"  
     echo "  if it contains spaces, dashes, or other special characters."  
     exit 1  
645  }  }
646    
647  #  Build a CPP macro to automate calling C routines from FORTRAN  #  Build a CPP macro to automate calling C routines from FORTRAN
648  get_fortran_c_namemangling()  {  get_fortran_c_namemangling()  {
649    
650        #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
651        if test ! "x$FC_NAMEMANGLE" = x ; then
652            return 0
653        fi
654        echo " running: get_fortran_c_namemangling()" >> $LOGFILE
655    
656      default_nm="#define FC_NAMEMANGLE(X) X ## _"      default_nm="#define FC_NAMEMANGLE(X) X ## _"
657        
658      cat > genmake_test.c <<EOF      cat > genmake_test.c <<EOF
659  void tcall( char * string ) { tsub( string ); }  void tcall( char * string ) { tsub( string ); }
660  EOF  EOF
661      $MAKE genmake_test.o > genmake_test.log 2>&1      COMM="$CC $CFLAGS -c genmake_test.c"
662        echo ' '$COMM >> $LOGFILE
663        $COMM >> $LOGFILE 2>&1
664      RETVAL=$?      RETVAL=$?
665      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
         cat genmake_test.log >> genmake_errors  
666          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
667          echo          cat <<EOF>> $LOGFILE
668          echo "WARNING: C test compile fails -- please see \"genmake_errors\""  
669          echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"   WARNING: C test compile fails
670          echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
671     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
672    EOF
673          return 1          return 1
674      fi      fi
675      c_tcall=`nm genmake_test.o | grep tcall | cut -d ' ' -f 3`      c_tcall=`nm genmake_test.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
676      RETVAL=$?      RETVAL=$?
677      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
678          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
679          echo          cat <<EOF>> $LOGFILE
680          echo "WARNING: The \"nm\" command failed."  
681          echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"   WARNING: The "nm" command failed.
682          echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
683     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
684    EOF
685          return 1          return 1
686      fi      fi
687      cat > genmake_tcomp.f <<EOF      cat > genmake_tcomp.$FS <<EOF
688        subroutine tcall( string )        subroutine tcall( string )
689        character*(*) string        character*(*) string
690        call tsub( string )        call tsub( string )
691        end        end
692  EOF  EOF
693      $FC $FFLAGS $DEFINES -c genmake_tcomp.f > genmake_tcomp.log 2>&1      COMM="$FC $FFLAGS -c genmake_tcomp.$FS"
694        echo ' '$COMM >> $LOGFILE
695        $COMM >> $LOGFILE 2>&1
696      RETVAL=$?      RETVAL=$?
697      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
         cat genmake_tcomp.log >> genmake_errors  
698          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
699          echo          cat <<EOF>> $LOGFILE
700          echo "WARNING: FORTRAN test compile fails -- please see \"genmake_errors\""  
701          echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"   WARNING: FORTRAN test compile fails -- please see '$LOGFILE'
702          echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
703     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
704    EOF
705          return 1          return 1
706      fi      fi
707      f_tcall=`nm genmake_tcomp.o | grep tcall | cut -d ' ' -f 3`      f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
708      RETVAL=$?      RETVAL=$?
709      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
710          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
711          echo          cat <<EOF>> $LOGFILE
712          echo "WARNING: The \"nm\" command failed."  
713          echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"   WARNING: The "nm" command failed.
714          echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
715     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
716    EOF
717          return 1          return 1
718      fi      fi
719    
# Line 351  EOF Line 738  EOF
738    
739      #  cleanup the testing files      #  cleanup the testing files
740      rm -f genmake_tcomp.* genmake_test.*      rm -f genmake_tcomp.* genmake_test.*
741    
742        echo " --> set FC_NAMEMANGLE='$FC_NAMEMANGLE'" >> $LOGFILE
743  }  }
744    
745    check_HAVE_CLOC()  {
746        echo >> $LOGFILE
747        echo "running: check_HAVE_CLOC()" >> $LOGFILE
748        get_fortran_c_namemangling
749        cat <<EOF > genmake_tc_1.c
750    $FC_NAMEMANGLE
751    #include <stdio.h>
752    #include <stdlib.h>
753    #include <unistd.h>
754    #include <assert.h>
755    #include <sys/time.h>
756    void FC_NAMEMANGLE(cloc) ( double *curtim )
757    {
758     struct timeval tv1;
759     gettimeofday(&tv1 , (void *)NULL );
760     *curtim =  (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
761     *curtim = *curtim/1.E6;
762    }
763    EOF
764        COMM="$CC $CFLAGS -c genmake_tc_1.c"
765        echo $COMM >> $LOGFILE
766        $COMM >> $LOGFILE 2>&1
767        RET_C=$?
768        cat <<EOF > genmake_tc_2.$FS
769          program hello
770          REAL*8 wtime
771          external cloc
772          call cloc(wtime)
773          print *," HELLO WORLD", wtime
774          end
775    EOF
776        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
777        echo $COMM >> $LOGFILE
778        $COMM >> $LOGFILE 2>&1
779        RET_F=$?
780        test -x ./genmake_tc  &&  ./genmake_tc >> $LOGFILE 2>&1
781        RETVAL=$?
782        if test "x$RETVAL" = x0 ; then
783            HAVE_CLOC=t
784        fi
785        rm -f genmake_tc*
786        echo " --> set HAVE_CLOC='$HAVE_CLOC'" >> $LOGFILE
787    }
788    
789    check_HAVE_SIGREG()  {
790        if test ! "x$HAVE_SIGREG" = x ; then
791            return
792        fi
793        echo >> $LOGFILE
794        echo "running: check_HAVE_SIGREG()" >> $LOGFILE
795        get_fortran_c_namemangling
796        cat <<EOF > genmake_tc_1.c
797    $FC_NAMEMANGLE
798    #include <stdlib.h>
799    #include <stdio.h>
800    #include <signal.h>
801    #include <errno.h>
802    #include <ucontext.h>
803    
804    int * ip;
805    
806    static void killhandler(
807        unsigned int sn, siginfo_t  si, struct ucontext *sc )
808    {
809        *ip = *ip + 1;
810        return;
811    }
812    
813    void FC_NAMEMANGLE(sigreg) (int * aip)
814    {
815        struct sigaction s;
816        ip = aip;
817        s.sa_flags = SA_SIGINFO;
818        s.sa_sigaction = (void *)killhandler;
819        if(sigaction (SIGTERM,&s,(struct sigaction *)NULL)) {
820            printf("Sigaction returned error = %d\n", errno);
821            exit(0);
822        }
823        return;
824    }
825    EOF
826        COMM="$CC $CFLAGS -c genmake_tc_1.c"
827        echo $COMM >> $LOGFILE
828        $COMM >> $LOGFILE 2>&1
829        RET_C=$?
830        cat <<EOF > genmake_tc_2.$FS
831          program hello
832          integer anint
833          common /iv/ anint
834          external sigreg
835          call sigreg(anint)
836          end
837    EOF
838        cat genmake_tc_2.$FS >> $LOGFILE
839        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
840        echo $COMM >> $LOGFILE
841        $COMM >> $LOGFILE 2>&1
842        RETVAL=$?
843        if test "x$RETVAL" = x0 ; then
844            HAVE_SIGREG=t
845        fi
846        rm -f genmake_tc*
847        echo " --> set HAVE_SIGREG='$HAVE_SIGREG'" >> $LOGFILE
848    }
849    
850    check_HAVE_SETRLSTK()  {
851        if test ! "x$HAVE_SETRLSTK" = x ; then
852            return
853        fi
854        echo >> $LOGFILE
855        echo "running: check_HAVE_SETRLSTK()" >> $LOGFILE
856        get_fortran_c_namemangling
857        cat <<EOF > genmake_tc_1.c
858    $FC_NAMEMANGLE
859    #include <sys/time.h>
860    #include <sys/resource.h>
861    #include <unistd.h>
862    void FC_NAMEMANGLE(setrlstk) ()
863    {
864        struct rlimit rls;
865        rls.rlim_cur = RLIM_INFINITY;
866        rls.rlim_max = RLIM_INFINITY;
867        setrlimit(RLIMIT_STACK, &rls);
868        return;
869    }
870    EOF
871        COMM="$CC $CFLAGS -c genmake_tc_1.c"
872        echo $COMM >> $LOGFILE
873        $COMM >> $LOGFILE 2>&1
874        RET_C=$?
875        cat <<EOF > genmake_tc_2.$FS
876          program hello
877          external setrlstk
878          call setrlstk()
879          end
880    EOF
881        cat genmake_tc_2.$FS >> $LOGFILE
882        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
883        echo $COMM >> $LOGFILE
884        $COMM >> $LOGFILE 2>&1
885        RETVAL=$?
886        if test "x$RETVAL" = x0 ; then
887            HAVE_SETRLSTK=t
888        fi
889        rm -f genmake_tc*
890        echo " --> set HAVE_SETRLSTK='$HAVE_SETRLSTK'" >> $LOGFILE
891    }
892    
893    check_HAVE_STAT()  {
894        echo >> $LOGFILE
895        echo "running: check_HAVE_STAT()" >> $LOGFILE
896        get_fortran_c_namemangling
897        cat <<EOF > genmake_tc_1.c
898    $FC_NAMEMANGLE
899    #include <stdio.h>
900    #include <stdlib.h>
901    #include <unistd.h>
902    #include <sys/stat.h>
903    #include <sys/types.h>
904    void FC_NAMEMANGLE(tfsize) ( int *nbyte )
905    {
906        char name[512];
907        struct stat astat;
908    
909        name[0] = 'a'; name[1] = '\0';
910        if (! stat(name, &astat))
911            *nbyte = (int)(astat.st_size);
912        else
913            *nbyte = -1;
914    }
915    EOF
916        COMM="$CC $CFLAGS -c genmake_tc_1.c"
917        echo $COMM >> $LOGFILE
918        $COMM >> genmake_tc.log 2>&1
919        RET_C=$?
920        cat <<EOF > genmake_tc_2.$FS
921          program hello
922          integer nbyte
923          call tfsize(nbyte)
924          print *," HELLO WORLD", nbyte
925          end
926    EOF
927        cat genmake_tc_2.$FS >> $LOGFILE
928        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
929        echo $COMM >> $LOGFILE
930        $COMM >> genmake_tc.log 2>&1
931        RETVAL=$?
932        if test "x$RETVAL" = x0 ; then
933            HAVE_STAT=t
934        fi
935        rm -f genmake_tc*
936        echo " --> set HAVE_STAT='$HAVE_STAT'" >> $LOGFILE
937    }
938    
939    check_netcdf_libs()  {
940        if test ! "x$SKIP_NETCDF_CHECK" = x ; then
941            return
942        fi
943        echo >> $LOGFILE
944        echo "running: check_netcdf_libs()" >> $LOGFILE
945        cat <<EOF > genmake_tnc.F
946          program fgennc
947    #include "netcdf.inc"
948    EOF
949        if test ! "x$MPI" = x ; then
950            echo '#include "mpif.h"' >> genmake_tnc.F
951        fi
952        cat <<EOF >> genmake_tnc.F
953          integer iret, ncid, xid
954          iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
955          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
956          iret = nf_def_dim(ncid, 'X', 11, xid)
957          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
958          iret = nf_close(ncid)
959          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
960          end
961    EOF
962        echo "===  genmake_tnc.F  >>>" > genmake_tnc.log
963        cat genmake_tnc.F >> genmake_tnc.log
964        echo "<<<  genmake_tnc.F  ===" >> genmake_tnc.log
965        RET_CPP=f
966        COMM="cat genmake_tnc.F | $CPP $DEFINES $INCLUDES"
967        echo "$COMM" >> genmake_tnc.log
968        eval $COMM > genmake_tnc.$FS 2>/dev/null  &&  RET_CPP=t
969        if test "x$RET_CPP" = xf ; then
970            echo "  WARNING: CPP failed to pre-process the netcdf test." \
971                >> genmake_tnc.log
972            echo "    Please check that \$INCLUDES is properly set." \
973                >> genmake_tnc.log
974        fi
975        echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.$FS  \ " >> genmake_tnc.log
976        echo "  &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc.o $LIBS" >> genmake_tnc.log
977        $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
978            &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
979        RET_COMPILE=$?
980        cat genmake_tnc.log >> $LOGFILE
981    
982        #EH3  Remove test program execution for machines that either disallow
983        #EH3  execution or cannot support it (eg. cross-compilers)
984        #EH3
985        #EH3 test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1
986        #EH3 RETVAL=$?
987        #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
988    
989        if test "x$RET_COMPILE" = x0 ; then
990            HAVE_NETCDF=t
991            echo "check_netcdf: successful" >> $LOGFILE
992        else
993            # try again with "-lnetcdf" added to the libs
994            echo "==> try again with added '-lnetcdf'" > genmake_tnc.log
995            echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log
996            echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
997            echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
998            cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null  \
999                &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
1000                &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
1001            RET_COMPILE=$?
1002            echo >> $LOGFILE
1003            cat genmake_tnc.log >> $LOGFILE
1004            if test "x$RET_COMPILE" = x0 ; then
1005                LIBS="$LIBS -lnetcdf"
1006                HAVE_NETCDF=t
1007                echo "check_netcdf: successful" >> $LOGFILE
1008            else
1009            # try again with "-lnetcdff" added to the libs
1010                echo "==> try again with added '-lnetcdff -lnetcdf'" > genmake_tnc.log
1011                echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log
1012                echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
1013                echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
1014                cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null  \
1015                    &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
1016                    &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdff -lnetcdf >> genmake_tnc.log 2>&1
1017                RET_COMPILE=$?
1018                echo >> $LOGFILE
1019                cat genmake_tnc.log >> $LOGFILE
1020                if test "x$RET_COMPILE" = x0 ; then
1021                    LIBS="$LIBS -lnetcdff -lnetcdf"
1022                    HAVE_NETCDF=t
1023                    echo "check_netcdf: successful" >> $LOGFILE
1024                fi
1025            fi
1026        fi
1027        rm -f genmake_tnc*
1028        echo " --> set HAVE_NETCDF='$HAVE_NETCDF'" >> $LOGFILE
1029    }
1030    
1031    check_lapack_libs()  {
1032        if test ! "x$SKIP_LAPACK_CHECK" = x ; then
1033            return
1034        fi
1035        echo >> $LOGFILE
1036        echo "running: check_lapack_libs()" >> $LOGFILE
1037        cat <<EOF > genmake_tla.F
1038          program fgenla
1039          integer info
1040          integer ipiv( 2 )
1041          double precision ab( 4, 2 ), b( 2 )
1042          data ab / 0., 0., 1., 2., 0., 2., 1., 0. /
1043          data b / 1., 1. /
1044          call dgbsv( 2, 1, 1, 1, ab, 4, ipiv, b, 2, info )
1045          IF (info .NE. 0) write(*,*) 'Error:', info
1046          write(*,*) b
1047          end
1048    EOF
1049        echo "===  genmake_tla.F  >>>" > genmake_tla.log
1050        cat genmake_tla.F >> genmake_tla.log
1051        echo "<<<  genmake_tla.F  ===" >> genmake_tla.log
1052        RET_CPP=f
1053        COMM="cat genmake_tla.F | $CPP $DEFINES $INCLUDES"
1054        echo "$COMM" >> genmake_tla.log
1055        eval $COMM > genmake_tla.$FS 2>/dev/null  &&  RET_CPP=t
1056        if test "x$RET_CPP" = xf ; then
1057            echo "  WARNING: CPP failed to pre-process the lapack test." \
1058                >> genmake_tla.log
1059            echo "    Please check that \$INCLUDES is properly set." \
1060                >> genmake_tla.log
1061        fi
1062        echo "$FC $FFLAGS $FOPTIM -c genmake_tla.$FS  \ " >> genmake_tla.log
1063        echo "  &&  $LINK $FFLAGS $FOPTIM -o genmake_tla.o $LIBS" >> genmake_tla.log
1064        $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
1065            &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS >> genmake_tla.log 2>&1
1066        RET_COMPILE=$?
1067        cat genmake_tla.log >> $LOGFILE
1068    
1069        # test program execution not always possible (see check_netcdf_libs)
1070        #
1071        #test -x ./genmake_tla  &&  ./genmake_tla >> genmake_tla.log 2>&1
1072        #RETVAL=$?
1073        #if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
1074    
1075        if test "x$RET_COMPILE" = x0 ; then
1076            HAVE_LAPACK=t
1077            echo "check_lapack: successful" >> $LOGFILE
1078        else
1079            # try again with "-llapack" added to the libs
1080            echo "==> try again with added '-llapack'" > genmake_tla.log
1081            echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1082            echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1083            echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack" >> genmake_tla.log
1084            cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null  \
1085                &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
1086                &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack >> genmake_tla.log 2>&1
1087            RET_COMPILE=$?
1088            echo >> $LOGFILE
1089            cat genmake_tla.log >> $LOGFILE
1090            if test "x$RET_COMPILE" = x0 ; then
1091                LIBS="$LIBS -llapack"
1092                HAVE_LAPACK=t
1093                echo "check_lapack: successful" >> $LOGFILE
1094            else
1095            # try again with "-lf77blas -lcblas" added to the libs
1096                echo "==> try again with added '-llapack -lf77blas -lcblas'" > genmake_tla.log
1097                echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1098                echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1099                echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas" >> genmake_tla.log
1100                cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null  \
1101                    &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
1102                    &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas >> genmake_tla.log 2>&1
1103                RET_COMPILE=$?
1104                echo >> $LOGFILE
1105                cat genmake_tla.log >> $LOGFILE
1106                if test "x$RET_COMPILE" = x0 ; then
1107                    LIBS="$LIBS -llapack -lf77blas -lcblas"
1108                    HAVE_LAPACK=t
1109                    echo "check_lapack: successful" >> $LOGFILE
1110                else
1111                # try again with "-latlas" added to the libs
1112                    echo "==> try again with added '-llapack -lf77blas -lcblas -latlas'" > genmake_tla.log
1113                    echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1114                    echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1115                    echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas -latlas" >> genmake_tla.log
1116                    cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null  \
1117                        &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
1118                        &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas -latlas >> genmake_tla.log 2>&1
1119                    RET_COMPILE=$?
1120                    echo >> $LOGFILE
1121                    cat genmake_tla.log >> $LOGFILE
1122                    if test "x$RET_COMPILE" = x0 ; then
1123                        LIBS="$LIBS -llapack -lf77blas -lcblas -latlas"
1124                        HAVE_LAPACK=t
1125                        echo "check_lapack: successful" >> $LOGFILE
1126                    fi
1127                fi
1128            fi
1129        fi
1130        rm -f genmake_tla*
1131        echo " --> set HAVE_LAPACK='$HAVE_LAPACK'" >> $LOGFILE
1132    }
1133    
1134    
1135    ###############################################################################
1136    #   Sequential part of script starts here
1137    ###############################################################################
1138    
1139  #  Set defaults here  #  Set defaults here
1140  COMMANDL="$0 $@"  COMMANDL="$0 $@"
1141    
# Line 360  PLATFORM= Line 1143  PLATFORM=
1143  LN=  LN=
1144  S64=  S64=
1145  KPP=  KPP=
1146  FC=  #FC=
1147    #CC=gcc
1148    #CPP=
1149  LINK=  LINK=
 # DEFINES="-DWORDLENGTH=4"  
1150  DEFINES=  DEFINES=
1151  PACKAGES=  PACKAGES=
1152  ENABLE=  ENABLE=
1153  DISABLE=  DISABLE=
1154  MAKEFILE=  # MAKEFILE=
1155  MAKEDEPEND=  # MAKEDEPEND=
1156  PDEPEND=  PKG_DEPEND=
1157  DUMPSTATE=t  PKG_GROUPS=
1158  PDEFAULT=  DUMPSTATE=f
1159  OPTFILE=  OPTFILE=
1160  INCLUDES="-I."  INCLUDES="-I. $INCLUDES"
1161  FFLAGS=  FFLAGS=
1162  FOPTIM=  FOPTIM=
1163    FEXTRAFLAGS=
1164    USE_EXTENDED_SRC=
1165    EXTENDED_SRC_FLAG=
1166    GET_FC_VERSION=
1167  CFLAGS=  CFLAGS=
1168  KFLAGS1=  KFLAGS1=
1169  KFLAGS2=  KFLAGS2=
1170    #LDADD=
1171  LIBS=  LIBS=
1172  KPPFILES=  KPPFILES=
1173  NOOPTFILES=  NOOPTFILES=
1174  NOOPTFLAGS=  NOOPTFLAGS=
1175    MPI=
1176    MPIPATH=
1177    OMP=
1178    OMPFLAG=
1179    USE_R4=
1180    TS=
1181    PAPIS=
1182    PCLS=
1183    FOOLAD=
1184    PAPI=
1185    PCL=
1186    HPMT=
1187    GSL=
1188    DEVEL=
1189    HAVE_TEST_L=
1190    
1191  # DEFINES checked by test compilation  # DEFINES checked by test compilation or command-line
1192  HAVE_SYSTEM=  HAVE_SYSTEM=
1193  HAVE_FDATE=  HAVE_FDATE=
1194  FC_NAMEMANGLE=  FC_NAMEMANGLE=
1195    HAVE_CLOC=
1196    # HAVE_SETRLSTK=
1197    HAVE_STAT=
1198    HAVE_NETCDF=
1199    HAVE_ETIME=
1200    IGNORE_TIME=
1201    HAVE_LAPACK=
1202    
1203  MODS=  MODS=
1204  TOOLSDIR=  TOOLSDIR=
1205  SOURCEDIRS=  SOURCEDIRS=
1206  INCLUDEDIRS=  INCLUDEDIRS=
1207  STANDARDDIRS=  STANDARDDIRS="USE_THE_DEFAULT"
1208    
1209    #- local config file
1210    gm_local="genmake_local"
1211    
1212    G2ARGS=
1213    BASH=
1214  PWD=`pwd`  PWD=`pwd`
1215  MAKE=make  test "x$MAKE" = x  &&  MAKE=make
1216  AWK=awk  test "x$AWK" = x   &&  AWK=awk
1217  THISHOSTNAME=`hostname`  EMBED_SRC=
1218    THISHOST=`hostname`
1219  THISCWD=`pwd`  THISCWD=`pwd`
1220  THISDATE=`date`  THISDATE=`date`
1221    THISUSER=`echo $USER`
1222    THISVER=
1223  MACHINE=`uname -a`  MACHINE=`uname -a`
1224  EXECUTABLE=  EXECUTABLE=
1225  EXEHOOK=  EXEHOOK=
1226  EXEDIR=  EXEDIR=
 PACKAGES_CONF=  
1227  IEEE=  IEEE=
1228  if test "x$MITGCM_IEEE" != x ; then  if test "x$MITGCM_IEEE" != x ; then
1229      IEEE=$MITGCM_IEEE      IEEE=$MITGCM_IEEE
1230  fi  fi
1231    FS=
1232    FS90=
1233    
1234  AUTODIFF_PKG_USED=f  AUTODIFF_PKG_USED=f
1235  AD_OPTFILE=  AD_OPTFILE=
# Line 424  FTL_TAF_FLAGS= Line 1244  FTL_TAF_FLAGS=
1244  SVD_TAMC_FLAGS=  SVD_TAMC_FLAGS=
1245  TAMC_EXTRA=  TAMC_EXTRA=
1246    
   
1247  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
1248  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"  gm_s1="OPTFILE PKG_DEPEND PKG_GROUPS DISABLE ENABLE MAKEFILE MAKEDEPEND PLATFORM"
1249  gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS"  gm_s2="FC CC MPI OMP USE_R4 TS PAPIS PCLS PAPI PCL HPMT IEEE DEVEL GSL FEXTRAFLAGS"
1250    gm_s3="ROOTDIR STANDARDDIRS MODS DUMPSTATE"
1251    
1252  #  The following state is not directly set by command-line switches  #  The following state is not directly set by command-line switches
1253  gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "  gm_s4="LN S64 LINK MAKE PACKAGES INCLUDES FFLAGS FOPTIM"
1254  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"  gm_s5="CFLAGS LIBS KPP KFLAGS1 KFLAGS2 KPPFILES NOOPTFILES NOOPTFLAGS"
1255  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"  gm_s6="TOOLSDIR SOURCEDIRS INCLUDEDIRS EXEDIR EXECUTABLE EXEHOOK"
1256  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"  gm_s7="PWD THISHOST THISUSER THISDATE THISVER MACHINE"
1257  gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE"  gm_s8="FC_NAMEMANGLE HAVE_NETCDF HAVE_SYSTEM HAVE_FDATE HAVE_ETIME HAVE_LAPACK"
1258    
1259  #  The following are all related to adjoint/tangent-linear stuff  #  The following are all related to adjoint/tangent-linear stuff
1260  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"
1261  gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"  gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
1262  gm_s12="TAF_EXTRA TAMC_EXTRA"  gm_s12="TAF_EXTRA TAMC_EXTRA"
1263    
1264  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7 $gm_s8"
1265  gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"  gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
1266    
1267    cat <<EOF
1268    
1269    GENMAKE :
1270    
1271    A program for GENerating MAKEfiles for the MITgcm project.
1272       For a quick list of options, use "genmake2 -h"
1273    or for more detail see the Developer's HOWTO manual at:
1274       http://mitgcm.org/public/docs.html
1275    
1276    EOF
1277    
1278    LOGFILE="genmake.log"
1279    #- clean-up previous genmake logfiles:
1280    rm -f genmake_state genmake_*optfile $LOGFILE
1281    
 echo  
1282  echo "===  Processing options files and arguments  ==="  echo "===  Processing options files and arguments  ==="
 gm_local="genmake_local"  
 for i in . $MODS ; do  
     if test -r $i/$gm_local ; then  
         . $i/$gm_local  
         break  
     fi  
 done  
 echo -n "  getting local config information:  "  
 if test -e $gm_local ; then  
     echo "using $gm_local"  
     . $gm_local  
     # echo "DISABLE=$DISABLE"  
     # echo "ENABLE=$ENABLE"  
 else  
     echo "none found"  
 fi  
1283    
1284  #  echo "$0::$1:$2:$3:$4:$5:$6:$7:"  #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
 #OPTIONS=  
 #n=0  
 #for i ; do  
 #   echo "$i  $n"  
 #   setvar="OPTIONS[$n]='$i'"  
 #   #  echo "  $setvar"  
 #   eval "$setvar"  
 #   n=$(( $n + 1 ))  
 #done  
1285  #parse_options  #parse_options
1286  ac_prev=  ac_prev=
1287  for ac_option ; do  for ac_option in "$@" ; do
1288    
1289        G2ARGS="$G2ARGS \"$ac_option\""
1290    
1291      # If the previous option needs an argument, assign it.      # If the previous option needs an argument, assign it.
1292      if test -n "$ac_prev"; then      if test -n "$ac_prev"; then
# Line 484  for ac_option ; do Line 1294  for ac_option ; do
1294          ac_prev=          ac_prev=
1295          continue          continue
1296      fi      fi
1297        
1298      ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`      ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
1299        
1300      case $ac_option in      case $ac_option in
1301            
1302          -help | --help | -h | --h)          -help | --help | -h | --h)
1303              usage ;;              usage ;;
1304            
1305          -nooptfile | --nooptfile)          -nooptfile | --nooptfile)
1306              OPTFILE="NONE" ;;              OPTFILE="NONE" ;;
1307          -optfile | --optfile | -of | --of)          -optfile | --optfile | -of | --of)
1308              ac_prev=OPTFILE ;;              ac_prev=OPTFILE ;;
1309          -optfile=* | --optfile=* | -of=* | --of=*)          -optfile=* | --optfile=* | -of=* | --of=*)
1310              OPTFILE=$ac_optarg ;;              OPTFILE=$ac_optarg ;;
1311            
1312          -adoptfile | --adoptfile | -ad | --ad)          -adoptfile | --adoptfile | -adof | --adof)
1313              ac_prev=AD_OPTFILE ;;              ac_prev=AD_OPTFILE ;;
1314          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
1315              AD_OPTFILE=$ac_optarg ;;              AD_OPTFILE=$ac_optarg ;;
1316            
1317          -pdepend | --pdepend)          -pdepend | --pdepend)
1318              ac_prev=PDEPEND ;;              ac_prev=PKG_DEPEND ;;
1319          -pdepend=* | --pdepend=*)          -pdepend=* | --pdepend=*)
1320              PDEPEND=$ac_optarg ;;              PKG_DEPEND=$ac_optarg ;;
1321            
1322          -pdefault | --pdefault)          -pgroups | --pgroups)
1323              ac_prev=PDEFAULT ;;              ac_prev=PKG_GROUPS ;;
1324          -pdefault=* | --pdefault=*)          -pgroups=* | --pgroups=*)
1325              PDEFAULT=$ac_optarg ;;              PKG_GROUPS=$ac_optarg ;;
1326            
1327          -make | --make | -m | --m)          -make | --make | -m | --m)
1328              ac_prev=MAKE ;;              ac_prev=MAKE ;;
1329          -make=* | --make=* | -m=* | --m=*)          -make=* | --make=* | -m=* | --m=*)
1330              MAKE=$ac_optarg ;;              MAKE=$ac_optarg ;;
1331            
1332          -makefile | --makefile | -ma | --ma)          -bash | --bash)
1333                ac_prev=BASH ;;
1334            -bash=* | --bash=*)
1335                BASH=$ac_optarg ;;
1336    
1337            -makedepend | --makedepend | -md | --md)
1338                ac_prev=MAKEDEPEND ;;
1339            -makedepend=* | --makedepend=* | -md=* | --md=*)
1340                MAKEDEPEND=$ac_optarg ;;
1341    
1342            -makefile | --makefile | -mf | --mf)
1343              ac_prev=MAKEFILE ;;              ac_prev=MAKEFILE ;;
1344          -makefile=* | --makefile=* | -ma=* | --ma=*)          -makefile=* | --makefile=* | -mf=* | --mf=*)
1345              MAKEFILE=$ac_optarg ;;              MAKEFILE=$ac_optarg ;;
1346            
1347          -platform | --platform | -pl | --pl)          -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
1348              ac_prev=PLATFORM ;;              echo "ERROR: The platform option has been removed.  Please specify"
1349          -platform=* | --platform=* | -pl=* | --pl=*)              echo "  the build options using the \"optfile\" mechanism."
1350              PLATFORM=$ac_optarg ;;              echo
1351                        usage
1352                ;;
1353    
1354          -rootdir | --rootdir | -rd | --rd)          -rootdir | --rootdir | -rd | --rd)
1355              ac_prev=ROOTDIR ;;              ac_prev=ROOTDIR ;;
1356          -rootdir=* | --rootdir=* | -rd=* | --rd=*)          -rootdir=* | --rootdir=* | -rd=* | --rd=*)
1357              ROOTDIR=$ac_optarg ;;              ROOTDIR=$ac_optarg ;;
1358            
1359          -mods | --mods | -mo | --mo)          -mods | --mods | -mo | --mo)
1360              ac_prev=MODS ;;              ac_prev=MODS ;;
1361          -mods=* | --mods=* | -mo=* | --mo=*)          -mods=* | --mods=* | -mo=* | --mo=*)
1362              MODS=$ac_optarg ;;              MODS=$ac_optarg ;;
1363            
1364          -disable | --disable)          -disable | --disable)
1365              ac_prev=DISABLE ;;              ac_prev=DISABLE ;;
1366          -disable=* | --disable=*)          -disable=* | --disable=*)
1367              DISABLE=$ac_optarg ;;              DISABLE=$ac_optarg ;;
1368            
1369          -enable | --enable)          -enable | --enable)
1370              ac_prev=ENABLE ;;              ac_prev=ENABLE ;;
1371          -enable=* | --enable=*)          -enable=* | --enable=*)
1372              ENABLE=$ac_optarg ;;              ENABLE=$ac_optarg ;;
1373            
1374          -standarddirs | --standarddirs)          -standarddirs | --standarddirs)
1375              ac_prev=STANDARDDIRS ;;              ac_prev=STANDARDDIRS ;;
1376          -standarddirs=* | --standarddirs=*)          -standarddirs=* | --standarddirs=*)
1377              STANDARDDIRS=$ac_optarg ;;              STANDARDDIRS=$ac_optarg ;;
1378    
         -noopt | --noopt)  
             ac_prev=NOOPT ;;  
         -noopt=* | --noopt=*)  
             NOOPT=$ac_optarg ;;  
           
1379  #           -cpp | --cpp)  #           -cpp | --cpp)
1380  #               ac_prev=cpp ;;  #               ac_prev=cpp ;;
1381  #           -cpp=* | --cpp=*)  #           -cpp=* | --cpp=*)
1382  #               CPP=$ac_optarg ;;  #               CPP=$ac_optarg ;;
1383                
1384            -cc | --cc)
1385                ac_prev=CC ;;
1386            -cc=* | --cc=*)
1387                CC=$ac_optarg ;;
1388    
1389          -fortran | --fortran | -fc | --fc)          -fortran | --fortran | -fc | --fc)
1390              ac_prev=FC ;;              ac_prev=FC ;;
1391          -fc=* | --fc=*)          -fc=* | --fc=*)
1392              FC=$ac_optarg ;;              FC=$ac_optarg ;;
1393            
1394            -fs | --fs)
1395                ac_prev=FS ;;
1396            -fs=* | --fs=*)
1397                FS=$ac_optarg ;;
1398    
1399            -fs90 | --fs90)
1400                ac_prev=FS90 ;;
1401            -fs90=* | --fs90=*)
1402                FS90=$ac_optarg ;;
1403    
1404            -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4 )
1405                USE_R4=true ;;
1406    
1407          -ieee | --ieee)          -ieee | --ieee)
1408              IEEE=true ;;              IEEE=true ;;
1409          -noieee | --noieee)          -noieee | --noieee)
1410              IEEE= ;;              echo "Warning: ignore option '$ac_option' (default is already without '-ieee')" ;;
1411                    -devel | --devel)
1412                IEEE=true ; DEVEL=true ;;
1413            -gsl | --gsl)
1414                GSL=true ;;
1415    
1416            -ts | --ts)
1417                TS=true ;;
1418            -papis | --papis)
1419                PAPIS=true ;;
1420            -pcls | --pcls)
1421                PCLS=true ;;
1422            -foolad | --foolad)
1423                FOOLAD=true ;;
1424            -papi | --papi)
1425                PAPI=true ;;
1426            -pcl | --pcl)
1427                PCL=true ;;
1428            -hpmt | --hpmt)
1429                HPMT=true ;;
1430    
1431          -mpi | --mpi)          -mpi | --mpi)
1432              MPI=true ;;              MPI=true ;;
1433          -nompi | --nompi)          -mpi=* | --mpi=*)
1434              MPI= ;;              MPIPATH=$ac_optarg
1435                        MPI=true ;;
1436          -jam | --jam)  
1437              JAM=1 ;;          -omp | --omp)
1438          -nojam | --nojam)              OMP=true ;;
1439              JAM=0 ;;          -omp=* | --omp=*)
1440                        OMPFLAG=$ac_optarg
1441                OMP=true ;;
1442    
1443          -ds | --ds)          -ds | --ds)
1444              DUMPSTATE=t ;;              DUMPSTATE=t ;;
1445            
1446            -extra_flag | --extra_flag)
1447                ac_prev=FEXTRAFLAGS ;;
1448            -extra_flag=* | --extra_flag=*)
1449                FEXTRAFLAGS=$ac_optarg ;;
1450    
1451          -taf_extra | --taf_extra)          -taf_extra | --taf_extra)
1452              ac_prev=TAF_EXTRA ;;              ac_prev=TAF_EXTRA ;;
1453          -taf_extra=* | --taf_extra=*)          -taf_extra=* | --taf_extra=*)
# Line 597  for ac_option ; do Line 1458  for ac_option ; do
1458          -tamc_extra=* | --tamc_extra=*)          -tamc_extra=* | --tamc_extra=*)
1459              TAMC_EXTRA=$ac_optarg ;;              TAMC_EXTRA=$ac_optarg ;;
1460    
1461            -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1462                IGNORE_TIME="-DIGNORE_TIME" ;;
1463    
1464            -es | --es | -embed-source | --embed-source)
1465                EMBED_SRC=t ;;
1466    
1467          -*)          -*)
1468              echo "Error: unrecognized option: "$ac_option              echo "Error: unrecognized option: "$ac_option
1469              usage              usage
1470              ;;              ;;
1471            
1472          *)          *)
1473              echo "Error: unrecognized argument: "$ac_option              echo "Error: unrecognized argument: "$ac_option
1474              usage              usage
1475              ;;              ;;
1476            
1477      esac      esac
1478        
1479  done  done
1480    
1481    printf "  getting local config information:  "
1482    if test -f $gm_local ; then
1483        echo "using $gm_local"
1484        . $gm_local
1485    else
1486        echo "none found"
1487    fi
1488    
1489  if test -f ./.genmakerc ; then  if test -f ./.genmakerc ; then
1490      echo      echo
1491      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
1492      echo "  file.  This file format is no longer supported.  Please see:"      echo "  file.  This file format is no longer supported.  For directions on"
1493      echo      echo "  how to setup and use the new \"genmake2\" script, please see:"
1494      echo "    http://mitgcm.org/devel_HOWTO/"      echo "    http://mitgcm.org/public/devel_HOWTO/"
1495        echo "  and send an email to MITgcm-support@mitgcm.org if you need help."
1496        echo "WARNING: ignore \"./.genmakerc\" and continue."
1497      echo      echo
     echo "  for directions on how to setup and use the new \"genmake2\" input"  
     echo "  files and send an email to MITgcm-support@mitgcm.org if you want help."  
     echo  
1498  fi  fi
1499    
1500    #  Find the MITgcm ${ROOTDIR}
1501  if test "x${ROOTDIR}" = x ; then  if test "x${ROOTDIR}" = x ; then
1502      if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1503        if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesupp -a -d ../pkg ; then
1504          ROOTDIR=".."          ROOTDIR=".."
1505      else      else
1506          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1507              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
1508                  ROOTDIR=$d                  ROOTDIR=$d
1509                  echo -n "Warning:  ROOTDIR was not specified but there appears to be"                  printf "Warning: ROOTDIR was not specified ;"
1510                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."                  echo " try using a local copy of MITgcm found at \"$ROOTDIR\""
1511                  break                  break
1512              fi              fi
1513          done          done
# Line 648  if test ! -d ${ROOTDIR} ; then Line 1524  if test ! -d ${ROOTDIR} ; then
1524      exit 1      exit 1
1525  fi  fi
1526    
1527  echo "  getting OPTFILE information:  "  #  Find the MITgcm ${THISVER}
1528    version_file="${ROOTDIR}/doc/tag-index"
1529    if test -f $version_file ; then
1530        THISVER=`$AWK '/^checkpoint/{print $1; exit}' $version_file`
1531    #-  remove ./BUILD_INFO.h file if older than version_file
1532        if test -f ./BUILD_INFO.h -a ./BUILD_INFO.h -ot $version_file ; then
1533            echo "  remove ./BUILD_INFO.h (older than ${version_file})"
1534            rm -f ./BUILD_INFO.h
1535        fi
1536    fi
1537    
1538    if test "x$MAKEFILE" = x ; then
1539        MAKEFILE="Makefile"
1540    fi
1541    
1542    echo "  getting OPTFILE information:"
1543  if test "x${OPTFILE}" = x ; then  if test "x${OPTFILE}" = x ; then
1544      if test "x$MITGCM_OF" = x ; then      if test "x$MITGCM_OF" = x ; then
1545          echo "Warning: no OPTFILE specified so we'll look for possible settings"          echo "Warning: no OPTFILE specified so we'll look for possible settings"
1546          printf "\n===  Searching for possible settings for OPTFILE  ===\n"          printf "\n===  Searching for possible settings for OPTFILE  ===\n"
1547          find_possible_configs          find_possible_optfile
1548      else      else
1549          OPTFILE=$MITGCM_OF          OPTFILE=$MITGCM_OF
1550      fi      fi
# Line 664  if test "x$OPTFILE" != xNONE ; then Line 1555  if test "x$OPTFILE" != xNONE ; then
1555          . "$OPTFILE"          . "$OPTFILE"
1556          RETVAL=$?          RETVAL=$?
1557          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
1558              echo -n "Error: failed to source OPTFILE \"$OPTFILE\""              printf "Error: failed to source OPTFILE \"$OPTFILE\""
1559              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1560              exit 1              exit 1
1561          fi          fi
1562          if test "x$DUMPSTATE" != xf ; then          if test "x$DUMPSTATE" = xt ; then
1563              cp -f $OPTFILE "genmake_optfile"              cp -f $OPTFILE "genmake_optfile"
1564          fi          fi
1565      else      else
# Line 677  if test "x$OPTFILE" != xNONE ; then Line 1568  if test "x$OPTFILE" != xNONE ; then
1568      fi      fi
1569  fi  fi
1570    
1571  echo "  getting AD_OPTFILE information:  "  echo "  getting AD_OPTFILE information:"
1572  if test "x${AD_OPTFILE}" = x ; then  if test "x${AD_OPTFILE}" = x ; then
1573      if test "x$MITGCM_AD_OF" = x ; then      if test "x$MITGCM_AD_OF" = x ; then
1574          AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default          AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
# Line 691  if test "x${AD_OPTFILE}" != xNONE ; then Line 1582  if test "x${AD_OPTFILE}" != xNONE ; then
1582          . "$AD_OPTFILE"          . "$AD_OPTFILE"
1583          RETVAL=$?          RETVAL=$?
1584          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
1585              echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""              printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
1586              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1587              exit 1              exit 1
1588          fi          fi
1589          if test "x$DUMPSTATE" != xf ; then          if test "x$DUMPSTATE" = xt ; then
1590              cp -f $AD_OPTFILE "genmake_ad_optfile"              cp -f $AD_OPTFILE "genmake_ad_optfile"
1591          fi          fi
1592      else      else
# Line 704  if test "x${AD_OPTFILE}" != xNONE ; then Line 1595  if test "x${AD_OPTFILE}" != xNONE ; then
1595      fi      fi
1596  fi  fi
1597    
1598  #  Check that FC, LINK, CPP, S64, and LN are defined.  If not,  #====================================================================
1599  #  complain and abort!  #  Set default values if not set by the optfile
1600    #
1601    #  Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
1602    #  either set defaults or complain and abort!
1603    if test ! "x$BASH" = x ; then
1604        # add a trailing space so that it works within the Makefile syntax (see below)
1605        BASH="$BASH "
1606    fi
1607  if test "x$FC" = x ; then  if test "x$FC" = x ; then
1608      cat <<EOF 1>&2      cat <<EOF 1>&2
1609    
# Line 716  Error: no Fortran compiler: please speci Line 1614  Error: no Fortran compiler: please speci
1614  EOF  EOF
1615      exit 1      exit 1
1616  fi  fi
1617    if test "x$GET_FC_VERSION" != x ; then
1618      echo "Get compiler version using: $FC $GET_FC_VERSION" >> $LOGFILE
1619      ff=`echo $FC | sed 's/ .*//'` ; xx=`echo $ff | sed 's/^./& /' | sed 's/ .*//'`
1620      if test $xx != '/' ; then which $ff >> $LOGFILE ; fi
1621      $FC $GET_FC_VERSION > genmake_fc_vers1 2> genmake_fc_vers2
1622      if test -s genmake_fc_vers1 ; then
1623        cat genmake_fc_vers1 >> $LOGFILE
1624      else
1625        cat genmake_fc_vers2 >> $LOGFILE
1626      fi
1627      echo "<-- compiler version ----" >> $LOGFILE
1628      rm -f genmake_fc_vers1 genmake_fc_vers2
1629    fi
1630    
1631    if test "x$CC" = x ; then
1632        look_for_C_compilers
1633    fi
1634    
1635  if test "x$LINK" = x ; then  if test "x$LINK" = x ; then
1636      LINK=$FC      LINK=$FC
1637  fi  fi
1638    if test "x$MAKE" = x ; then
1639        MAKE="make"
1640    fi
1641  if test "x$CPP" = x ; then  if test "x$CPP" = x ; then
1642      CPP="cpp"      CPP="cpp -traditional -P"
1643  fi  fi
1644    #EH3 === UGLY ===
1645    #  The following is an ugly little hack to check for $CPP in /lib/ and
1646    #  it should eventually be replaced with a more general function that
1647    #  searches a combo of the user's path and a list of "usual suspects"
1648    #  to find the correct location for binaries such as $CPP.
1649    for i in " " "/lib/" ; do
1650        echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1651    done
1652    #EH3 === UGLY ===
1653  echo "#define A a" | $CPP > test_cpp 2>&1  echo "#define A a" | $CPP > test_cpp 2>&1
1654  RETVAL=$?  RETVAL=$?
1655  if test "x$RETVAL" != x0 ; then  if test "x$RETVAL" != x0 ; then
# Line 738  EOF Line 1666  EOF
1666  else  else
1667      rm -f test_cpp      rm -f test_cpp
1668  fi  fi
1669  if test "x$MAKEDEPEND" = x ; then  
1670      MAKEDEPEND=makedepend  look_for_makedepend
1671  fi  
1672    #  Check that soft-link command is set and usable
1673  if test "x$LN" = x ; then  if test "x$LN" = x ; then
1674      LN="ln -s"      LN="ln -s"
1675  fi  fi
# Line 750  RETVAL=$? Line 1679  RETVAL=$?
1679  if test "x$RETVAL" != x0 ; then  if test "x$RETVAL" != x0 ; then
1680      cat <<EOF 1>&2      cat <<EOF 1>&2
1681    
1682  Error: The command "ln -s" failed -- please specify a working soft-link  Error: The command "$LN" failed -- please specify a working soft-link
1683    command in the optfile.    command in the optfile.
1684    
1685  EOF  EOF
1686      exit 1      exit 1
1687  fi  fi
1688    test -L genmake_tlink > /dev/null 2>&1
1689    RETVAL=$?
1690    if test "x$RETVAL" = x0 ; then
1691        HAVE_TEST_L=t
1692    fi
1693  rm -f genmake_test_ln genmake_tlink  rm -f genmake_test_ln genmake_tlink
1694    
1695    #  Check for broken *.F/*.f handling and fix if possible
1696    check_for_broken_Ff
1697    
1698    if test ! "x$MPI" = x ; then
1699          echo "  Turning on MPI cpp macros"
1700          DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
1701    fi
1702    if test ! "x$OMP" = x ; then
1703          echo "  Add OMPFLAG and turn on OpenMP cpp macros"
1704          FFLAGS="$FFLAGS $OMPFLAG"
1705          F90FLAGS="$F90FLAGS $OMPFLAG"
1706          DEFINES="$DEFINES -DUSE_OMP_THREADING"
1707    fi
1708    
1709    if test ! "x$USE_R4" = x ; then
1710          echo "  Turning on LET_RS_BE_REAL4 cpp flag"
1711          DEFINES="$DEFINES -DLET_RS_BE_REAL4"
1712    fi
1713    
1714    if test ! "x$TS" = x ; then
1715          echo "  Turning on timing per timestep"
1716          if test ! "x$FOOLAD" = x ; then
1717                DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP"
1718          else
1719                DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1720          fi
1721          PACKAGES="$PACKAGES showflops"
1722    fi
1723    if test ! "x$PAPIS" = x ; then
1724          echo "  Turning on PAPI flop summary per timestep"
1725          echo "  Please make sure PAPIINC, PAPILIB are defined"
1726          if test ! "x$FOOLAD" = x ; then
1727                DEFINES="$DEFINES -DUSE_PAPI_FLOPS_SFP"
1728          else
1729                DEFINES="$DEFINES -DUSE_PAPI_FLOPS"
1730          fi
1731          INCLUDES="$INCLUDES $PAPIINC"
1732          LIBS="$LIBS $PAPILIB"
1733          PACKAGES="$PACKAGES showflops"
1734    fi
1735    if test ! "x$PCLS" = x ; then
1736          echo "  Turning on PCL counter summary per timestep"
1737          echo "  Please make sure PCLINC, PCLLIB are defined"
1738          if test ! "x$FOOLAD" = x ; then
1739                DEFINES="$DEFINES -DUSE_PCL_FLOPS_SFP"
1740          else
1741                DEFINES="$DEFINES -DUSE_PCL_FLOPS"
1742          fi
1743          INCLUDES="$INCLUDES $PCLINC"
1744          LIBS="$LIBS $PCLLIB"
1745          PACKAGES="$PACKAGES showflops"
1746    fi
1747    if test ! "x$PAPI" = x ; then
1748          if test ! "x$PAPIS" = x ; then
1749              echo "  PAPI performance analysis and flop summary per timestep cannot co-exist!"
1750              echo "  Sticking with PAPI flop summary per timestep!"
1751          else
1752              echo "  Turning on performance analysis with PAPI"
1753              echo "  Please make sure PAPIINC, PAPILIB are defined"
1754              DEFINES="$DEFINES -DUSE_PAPI"
1755              INCLUDES="$INCLUDES $PAPIINC"
1756              LIBS="$LIBS $PAPILIB"
1757          fi
1758    fi
1759    if test ! "x$PCL" = x ; then
1760          if test ! "x$PCLS" = x ; then
1761              echo "  PCL performance analysis and flop summary per timestep cannot co-exist!"
1762              echo "  Sticking with PCL flop summary per timestep!"
1763          else
1764              echo "  Turning on performance analysis with PCL"
1765              echo "  Please make sure PCLINC, PCLLIB are defined"
1766              DEFINES="$DEFINES -DUSE_PCL"
1767              INCLUDES="$INCLUDES $PCLINC"
1768              LIBS="$LIBS $PCLLIB"
1769          fi
1770    fi
1771    if test ! "x$HPMT" = x ; then
1772          if test ! "x$PAPI" = x ; then
1773              echo "  PAPI and the HPM Toolkit cannot co-exist!"
1774              echo "  Sticking with PAPI!"
1775          else
1776            if test ! "x$PCL" = x ; then
1777              echo "  PCL and the HPM Toolkit cannot co-exist!"
1778              echo "  Sticking with PCL!"
1779            else
1780              echo "  Turning on performance analysis with the HPM Toolkit"
1781              echo "  Please make sure HPMTINC, HPMTLIB are defined"
1782              DEFINES="$DEFINES -DUSE_LIBHPM"
1783              INCLUDES="$INCLUDES $HPMTINC"
1784              LIBS="$LIBS $HPMTLIB"
1785            fi
1786          fi
1787    fi
1788    if test ! "x$GSL" = x ; then
1789          echo "  Turning on use of GSL to control floating point calculations"
1790          echo "  Please make sure GSLINC, GSLLIB are defined"
1791          DEFINES="$DEFINES -DUSE_GSL_IEEE"
1792          INCLUDES="$INCLUDES $GSLINC"
1793          LIBS="$LIBS $GSLLIB"
1794    fi
1795    #- if USE_EXTENDED_SRC is set, add EXTENDED_SRC_FLAG to FFLAGS :
1796    if test ! "x$USE_EXTENDED_SRC" = x ; then
1797          FFLAGS="$FFLAGS $EXTENDED_SRC_FLAG"
1798          F90FIXEDFORMAT="$F90FIXEDFORMAT $EXTENDED_SRC_FLAG"
1799    fi
1800    
1801  printf "\n===  Checking system libraries  ===\n"  printf "\n===  Checking system libraries  ===\n"
1802  echo -n "  Do we have the system() command using $FC...  "  printf "  Do we have the system() command using $FC...  "
1803  cat > genmake_tcomp.f <<EOF  cat > genmake_tcomp.$FS <<EOF
1804        program hello        program hello
1805        call system('echo hi')        call system('echo hi')
1806        end        end
1807  EOF  EOF
1808  $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
1809  RETVAL=$?  RETVAL=$?
1810  if test "x$RETVAL" = x0 ; then  if test "x$RETVAL" = x0 ; then
1811      HAVE_SYSTEM=t      HAVE_SYSTEM=t
# Line 777  else Line 1817  else
1817  fi  fi
1818  rm -f genmake_tcomp*  rm -f genmake_tcomp*
1819    
1820  echo -n "  Do we have the fdate() command using $FC...  "  printf "  Do we have the fdate() command using $FC...  "
1821  cat > genmake_tcomp.f <<EOF  cat > genmake_tcomp.$FS <<EOF
1822        program hello        program hello
1823        CHARACTER(128) string        CHARACTER*(128) string
1824        string = ' '        string = ' '
1825        call fdate( string )        call fdate( string )
1826        print *, string        print *, string
1827        end        end
1828  EOF  EOF
1829  $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
1830  RETVAL=$?  RETVAL=$?
1831  if test "x$RETVAL" = x0 ; then  if test "x$RETVAL" = x0 ; then
1832      HAVE_FDATE=t      HAVE_FDATE=t
# Line 798  else Line 1838  else
1838  fi  fi
1839  rm -f genmake_tcomp*  rm -f genmake_tcomp*
1840    
1841  echo "  The name mangling convention for $FC is...  "  printf "  Do we have the etime() command using $FC...  "
1842  #FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) X ## _"  cat > genmake_tcomp.$FS <<EOF
1843  if test "x$FC_NAMEMANGLE" = x ; then        program hello
1844      get_fortran_c_namemangling        REAL*4 ACTUAL, TARRAY(2)
1845  fi        EXTERNAL ETIME
1846  echo "    '$FC_NAMEMANGLE'"        REAL*4 ETIME
1847  echo "$FC_NAMEMANGLE" > FC_NAMEMANGLE.h.template        actual = etime( tarray )
1848  cmp FC_NAMEMANGLE.h FC_NAMEMANGLE.h.template > /dev/null 2>&1        print *, tarray
1849          end
1850    EOF
1851    $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1852  RETVAL=$?  RETVAL=$?
1853  if test "x$RETVAL" != x0 ; then  if test "x$RETVAL" = x0 ; then
1854      mv -f FC_NAMEMANGLE.h.template FC_NAMEMANGLE.h      HAVE_ETIME=t
1855        DEFINES="$DEFINES -DHAVE_ETIME"
1856        echo "yes"
1857    else
1858        HAVE_ETIME=
1859        echo "no"
1860    fi
1861    rm -f genmake_tcomp*
1862    
1863    printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
1864    check_HAVE_CLOC
1865    if test "x$HAVE_CLOC" != x ; then
1866        DEFINES="$DEFINES -DHAVE_CLOC"
1867        echo "yes"
1868    else
1869        echo "no"
1870        if test "x$EMBED_SRC" = xt ; then
1871            echo "    WARNING: you requested file embedding but it has"
1872            echo "      been disabled since C code cannot be called"
1873            EMBED_SRC=
1874        fi
1875    fi
1876    rm -f genmake_t*
1877    
1878    printf "  Can we unlimit the stack size using $FC...  "
1879    check_HAVE_SETRLSTK
1880    if test "x$HAVE_SETRLSTK" = xt ; then
1881        DEFINES="$DEFINES -DHAVE_SETRLSTK"
1882        echo "yes"
1883    else
1884        echo "no"
1885  fi  fi
1886    rm -f genmake_t*
1887    
1888    printf "  Can we register a signal handler using $FC...  "
1889    check_HAVE_SIGREG
1890    if test "x$HAVE_SIGREG" = xt ; then
1891        DEFINES="$DEFINES -DHAVE_SIGREG"
1892        echo "yes"
1893    else
1894        echo "no"
1895    fi
1896    rm -f genmake_t*
1897    
1898    printf "  Can we use stat() through C calls...  "
1899    check_HAVE_STAT
1900    if test "x$HAVE_STAT" != x ; then
1901        DEFINES="$DEFINES -DHAVE_STAT"
1902        echo "yes"
1903    else
1904        echo "no"
1905    fi
1906    rm -f genmake_t*
1907    
1908    printf "  Can we create NetCDF-enabled binaries...  "
1909    check_netcdf_libs
1910    if test "x$HAVE_NETCDF" != x ; then
1911        DEFINES="$DEFINES -DHAVE_NETCDF"
1912        echo "yes"
1913    else
1914        echo "no"
1915    fi
1916    
1917    printf "  Can we create LAPACK-enabled binaries...  "
1918    check_lapack_libs
1919    if test "x$HAVE_LAPACK" != x ; then
1920        DEFINES="$DEFINES -DHAVE_LAPACK"
1921        echo "yes"
1922    else
1923        echo "no"
1924    fi
1925    DEFINES="$DEFINES $IGNORE_TIME"
1926    
1927    if test "x$EMBED_SRC" = xt ; then
1928        build_embed_encode
1929    fi
1930    if test "x$EMBED_SRC" = xt ; then
1931        ENABLE="$ENABLE embed_files"
1932    #   DEFINES="$DEFINES -DHAVE_EMBED_SRC"
1933    fi
1934    
1935  printf "\n===  Setting defaults  ===\n"  printf "\n===  Setting defaults  ===\n"
1936  echo -n "  Adding MODS directories:  "  printf "  Adding MODS directories: "
1937  for d in $MODS ; do  for d in $MODS ; do
1938      if test ! -d $d ; then      if test ! -d $d ; then
1939          echo          echo
1940          echo "Error: MODS directory \"$d\" not found!"          echo "Error: MODS directory \"$d\" not found!"
1941          exit 1          exit 1
1942      else      else
1943          echo -n " $d"          printf "$d "
1944          SOURCEDIRS="$SOURCEDIRS $d"          SOURCEDIRS="$SOURCEDIRS $d"
1945          INCLUDEDIRS="$INCLUDEDIRS $d"          INCLUDEDIRS="$INCLUDEDIRS $d"
1946      fi      fi
1947  done  done
1948  echo  echo
1949    
1950  if test "x$MAKEFILE" = x ; then  #if test "x${PLATFORM}" = x ; then
1951      MAKEFILE="Makefile"  #    PLATFORM=$p_PLATFORM
1952  fi  #fi
 if test "x${PLATFORM}" = x ; then  
     PLATFORM=$p_PLATFORM  
 fi  
1953    
1954  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
1955      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1956        if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
1957          EXEDIR=../exe          EXEDIR=../exe
1958      else      else
1959          EXEDIR=.          EXEDIR=.
# Line 850  if test "x${TOOLSDIR}" = x ; then Line 1968  if test "x${TOOLSDIR}" = x ; then
1968      TOOLSDIR="$ROOTDIR/tools"      TOOLSDIR="$ROOTDIR/tools"
1969  fi  fi
1970  if test ! -d ${TOOLSDIR} ; then  if test ! -d ${TOOLSDIR} ; then
1971      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
1972      exit 1      exit 1
1973  fi  fi
1974  if test "x$S64" = x ; then  if test "x$S64" = x ; then
1975      S64='$(TOOLSDIR)/set64bitConst.sh'      echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1
1976        RETVAL=$?
1977        if test "x${RETVAL}" = x0 ; then
1978            S64='$(TOOLSDIR)/set64bitConst.sh'
1979        else
1980            echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1
1981            RETVAL=$?
1982            if test "x${RETVAL}" = x0 ; then
1983                S64='$(TOOLSDIR)/set64bitConst.csh'
1984            else
1985                cat <<EOF
1986    
1987    ERROR: neither of the two default scripts:
1988    
1989        ${TOOLSDIR}/set64bitConst.sh
1990        ${TOOLSDIR}/set64bitConst.csh
1991    
1992      are working so please check paths or specify (with \$S64) a
1993      working version of this script.
1994    
1995    EOF
1996                exit 1
1997            fi
1998        fi
1999  fi  fi
2000    THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
2001    
2002  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
2003    
2004    #  Set Standard Code Directories:
2005    if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
2006        STANDARDDIRS="eesupp model"
2007    fi
2008    #  if model in Standard-Code-Dir, add eesupp (needed to compile model)
2009    echo " $STANDARDDIRS " | grep ' model ' > /dev/null 2>&1
2010    ckM=$?
2011    echo " $STANDARDDIRS " | grep ' eesupp ' > /dev/null 2>&1
2012    ckE=$?
2013    if test $ckM = 0 -a $ckE = 1 ; then
2014        STANDARDDIRS="$STANDARDDIRS eesupp"
2015    fi
2016    
2017  #  We have a special set of source files in eesupp/src which are  #  We have a special set of source files in eesupp/src which are
2018  #  generated from some template source files. We'll make them first so  #  generated from some template source files. We'll make them first so
2019  #  they appear as regular source code  #  they appear as regular source code
2020  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
2021      echo "  Making source files in eesupp from templates"      echo "  Making source files in eesupp from templates"
2022      ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1      ( cd $ROOTDIR"/eesupp/src/" && $MAKE clean_old && $MAKE \
2023        ) > make_eesupp.errors 2>&1
2024      RETVAL=$?      RETVAL=$?
2025      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
2026          rm -f make_eesupp.errors          rm -f make_eesupp.errors
2027      else      else
2028          echo "Error: problem encountered while building source files in eesupp:"          echo "Error: problem encountered while building source files in eesupp:"
2029          cat make_eesupp.errors          cat make_eesupp.errors 1>&2
2030          exit 1          exit 1
2031      fi      fi
2032  fi  fi
2033    
2034    #same for pkg/exch2 and pkg/regrid
2035    for pdir in exch2 regrid ; do
2036        if test -r $ROOTDIR"/pkg/${pdir}/Makefile" ; then
2037            echo "  Making source files in pkg/${pdir} from templates"
2038            ( cd $ROOTDIR"/pkg/"${pdir} && $MAKE clean_old && $MAKE \
2039            ) > make_${pdir}.errors 2>&1
2040            RETVAL=$?
2041            if test "x${RETVAL}" = x0 ; then
2042                rm -f make_${pdir}.errors
2043            else
2044                echo "Error: problem encountered while building source files in pkg/${pdir}:"
2045                cat make_${pdir}.errors 1>&2
2046                exit 1
2047            fi
2048        fi
2049    done
2050    
2051  printf "\n===  Determining package settings  ===\n"  printf "\n===  Determining package settings  ===\n"
2052  if  test "x${PDEPEND}" = x ; then  if  test "x${PKG_DEPEND}" = x ; then
2053      tmp=$ROOTDIR"/pkg/pkg_depend"      tmp=$ROOTDIR"/pkg/pkg_depend"
2054      if test -r $tmp ; then      if test -r $tmp ; then PKG_DEPEND=$tmp ; fi
2055          PDEPEND=$tmp  fi
2056      else  if  test "x${PKG_DEPEND}" = x ; then
2057          echo "Warning:  No package dependency information was specified."          echo "Warning:  No package dependency information was specified."
2058          echo "  Please check that ROOTDIR/pkg/pkg_depend exists."          echo "  Please check that ROOTDIR/pkg/pkg_depend exists."
     fi  
2059  else  else
2060      if test ! -r ${PDEPEND} ; then      if test ! -r ${PKG_DEPEND} ; then
2061          echo "Error:  can't read package dependency info from PDEPEND=\"$PDEPEND\""          echo "Error:  can't read package dependency info from PKG_DEPEND=\"$PKG_DEPEND\""
2062          exit 1          exit 1
2063      fi      fi
2064        echo "  getting package dependency info from  $PKG_DEPEND"
2065    #  Strip the comments and then convert the dependency file into arrays: PNAME, DNAME
2066        get_pdepend_list $PKG_DEPEND
2067  fi  fi
2068  echo "  getting package dependency info from  $PDEPEND"  
2069  #  Strip the comments and then convert the dependency file into  # A default package groups file "$ROOTDIR/pkg/pkg_groups" is provided
2070  #  two arrays: PNAME, DNAME  #  to define the "default_pkg_list" and package groups (for convenience, one
2071  cat $PDEPEND | sed -e 's/#.*$//g' \  #  can specify a group of packages using names like "ocean" and "atmosphere").
2072      | $AWK 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \  if test "x${PKG_GROUPS}" = x ; then
2073      > ./.pd_tmp      tmp=$ROOTDIR"/pkg/pkg_groups"
2074  RETVAL=$?      if test -r $tmp ; then PKG_GROUPS=$tmp ; fi
2075  if test ! "x${RETVAL}" = x0 ; then  fi
2076      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""  if test "x${PKG_GROUPS}" = x ; then
2077      exit 1          echo "Warning:  No package groups information was specified."
2078            echo "  Please check that ROOTDIR/pkg/pkg_groups exists."
2079    else
2080        if test ! -r ${PKG_GROUPS} ; then
2081            echo "Error:  can't read package groups info from PKG_GROUPS=\"$PKG_GROUPS\""
2082            exit 1
2083        fi
2084        echo "  getting package groups info from      $PKG_GROUPS"
2085  fi  fi
 . ./.pd_tmp  
 rm -f ./.pd_tmp  
2086    
2087  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"  #  Search for packages to compile.
2088  #  file should eventually be added so that, for convenience, one can  echo "  checking list of packages to compile:"
2089  #  specify groups of packages using names like "ocean" and "atmosphere".  PKG_LIST=
2090  echo  -n "  checking default package list:  "  if test "x${PKG_LIST}" = x ; then
 if test "x${PDEFAULT}" = x ; then  
2091      for i in "." $MODS ; do      for i in "." $MODS ; do
2092          if test -r $i"/packages.conf" ; then          if test -r $i"/packages.conf" ; then
2093                  PDEFAULT=$i"/packages.conf"                  PKG_LIST=$i"/packages.conf"
2094                  break                  break
2095          fi          fi
2096      done      done
2097  fi  fi
2098  if test "x${PDEFAULT}" = x ; then  if test "x${PKG_LIST}" = x ; then
2099      PDEFAULT="$ROOTDIR/pkg/pkg_default"      pkg_list='default_pkg_list'
2100  fi      if test "x${PKG_GROUPS}" = x ; then
2101  if test "x${PDEFAULT}" = xNONE ; then          echo "Error:  need package groups info to expand pkg_list=\"$pkg_list\""
2102      echo "default packages file disabled"          exit 1
2103        fi
2104  else  else
2105      if test ! -r $PDEFAULT ; then      if test ! -r $PKG_LIST ; then
2106          echo ""          echo "Error:  can't read package list from PKG_LIST=\"$PKG_LIST\""
2107          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""          exit 1
2108      else      else
2109          echo "  using PDEFAULT=\"$PDEFAULT\""          echo "    using PKG_LIST=\"$PKG_LIST\""
2110          #  Strip the comments and add all the names          #  Strip the comments and add all the names
2111          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`          pkg_list=`cat $PKG_LIST | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
2112          RETVAL=$?          RETVAL=$?
2113          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
2114              echo -n "Error: can't parse default package list "              printf "Error: can't parse package list "
2115              echo "-- please check PDEFAULT=\"$PDEFAULT\""              echo "-- please check PKG_LIST=\"$PKG_LIST\""
2116              exit 1              exit 1
2117          fi          fi
         for i in $def ; do  
             PACKAGES="$PACKAGES $i"  
         done  
         echo "    before group expansion packages are: $PACKAGES"  
         expand_pkg_groups  
         echo "    after group expansion packages are:  $PACKAGES"  
2118      fi      fi
2119  fi  fi
2120    for i in $pkg_list ; do
2121        PACKAGES="$PACKAGES $i"
2122    done
2123    echo     "    before group expansion packages are:$PACKAGES"
2124    if test "x${PKG_GROUPS}" != x ; then
2125        RET=1
2126        while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
2127        echo "    after group expansion packages are: $PACKAGES"
2128    fi
2129    
2130  echo "  applying DISABLE settings"  echo "  applying DISABLE settings"
2131    echo "" > ./.tmp_pack
2132    for i in $PACKAGES ; do
2133        echo $i >> ./.tmp_pack
2134    done
2135    for i in `grep  "-" ./.tmp_pack` ; do
2136        j=`echo $i | sed 's/[-]//'`
2137        DISABLE="$DISABLE $j"
2138    done
2139  pack=  pack=
2140  for p in $PACKAGES ; do  for p in $PACKAGES ; do
2141      addit="t"      addit="t"
# Line 961  PACKAGES="$pack" Line 2152  PACKAGES="$pack"
2152  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
2153  echo "" > ./.tmp_pack  echo "" > ./.tmp_pack
2154  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
2155    # Test if each explicitly referenced package exists
2156  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2157      if test ! -d "$ROOTDIR/pkg/$i" ; then      j=`echo $i | sed 's/[-+]//'`
2158          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""      if test ! -d "$ROOTDIR/pkg/$j" ; then
2159            echo "Error: dir '$ROOTDIR/pkg/$i' missing for package '$i'"
2160          exit 1          exit 1
2161      fi      fi
2162      echo $i >> ./.tmp_pack      echo $i >> ./.tmp_pack
2163  done  done
 pack=`cat ./.tmp_pack | sort | uniq`  
 rm -f ./.tmp_pack  
2164  PACKAGES=  PACKAGES=
2165  for i in $pack ; do  for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do
2166      PACKAGES="$PACKAGES $i"      PACKAGES="$PACKAGES $i"
2167  done  done
2168  echo "    packages are:  $PACKAGES"  rm -f ./.tmp_pack
2169    echo "    packages are: $PACKAGES"
2170    
2171    #  Check for package MNC: if NetCDF is available, then build the MNC
2172    #  template files ; otherwise, delete mnc from the list of packages.
2173    echo " $PACKAGES " | grep ' mnc ' > /dev/null 2>&1
2174    mnc_in=$?
2175    if test "x$HAVE_NETCDF" != xt ; then
2176        if test "x$mnc_in" = x0 ; then
2177            cat <<EOF
2178    *********************************************************************
2179    WARNING: the "mnc" package was enabled but tests failed to compile
2180      NetCDF applications.  Please check that:
2181    
2182      1) NetCDF is correctly installed for this compiler and
2183      2) the LIBS variable (within the "optfile") specifies the correct
2184           NetCDF library to link against.
2185    
2186      Due to this failure, the "mnc" package is now DISABLED.
2187    *********************************************************************
2188    EOF
2189            PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
2190            DISABLE="$DISABLE mnc"
2191        else
2192        #  this prevent to add mnc (due to pdepend rules) if not available
2193            DISABLE="$DISABLE mnc"
2194        fi
2195    else
2196        # we have NetCDF, we try to build MNC template files
2197        ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
2198        RETVAL=$?
2199        if test "x${RETVAL}" = x0 ; then
2200            rm -f make_mnc.errors
2201        else
2202            echo "Error: problem encountered while building source files in pkg/mnc:"
2203            cat make_mnc.errors 1>&2
2204            if test "x$mnc_in" = x0 ; then
2205                exit 1
2206            else
2207                DISABLE="$DISABLE mnc"
2208            fi
2209        fi
2210    fi
2211    
2212    #  Check for package PROFILES: if NetCDF is not available,
2213    #  then delete profiles from the list of available packages.
2214    if test "x$HAVE_NETCDF" != xt ; then
2215        echo " $PACKAGES " | grep ' profiles ' > /dev/null 2>&1
2216        RETVAL=$?
2217        if test "x$RETVAL" = x0 ; then
2218            cat <<EOF
2219    *********************************************************************
2220    WARNING: the "profiles" package was enabled but tests failed to
2221      compile NetCDF applications.  Please check that:
2222    
2223      1) NetCDF is correctly installed for this compiler and
2224      2) the LIBS variable (within the "optfile") specifies the correct
2225           NetCDF library to link against.
2226    
2227      Due to this failure, the "profiles" package is now DISABLED.
2228    *********************************************************************
2229    EOF
2230            PACKAGES=`echo $PACKAGES | sed -e 's/profiles//g'`
2231            DISABLE="$DISABLE profiles"
2232        else
2233        #  this prevent to add profiles (due to pdepend rules) if not available
2234            DISABLE="$DISABLE profiles"
2235        fi
2236    fi
2237    
2238    #  Check for package RADTRANS: if LAPACK is not available,
2239    #  then issue a warning that the direct radtrans solver is not available.
2240    if test "x$HAVE_LAPACK" != xt ; then
2241        echo " $PACKAGES " | grep ' radtrans ' > /dev/null 2>&1
2242        RETVAL=$?
2243        if test "x$RETVAL" = x0 ; then
2244            cat <<EOF
2245    *********************************************************************
2246    WARNING: the "radtrans" package was enabled but tests failed to
2247      compile LAPACK applications.  This means that the direct radtrans
2248      solver is not available and compilation will fail if it is enabled.
2249      If you want to use the direct solver, please check that:
2250    
2251      1) LAPACK is correctly installed for this compiler and
2252      2) the LIBS variable (within the "optfile") specifies the correct
2253         LAPACK library to link against.
2254    *********************************************************************
2255    EOF
2256        fi
2257    fi
2258    
2259  echo "  applying package dependency rules"  if  test "x${PKG_DEPEND}" != x ; then
2260  ck=    echo "  applying package dependency rules"
2261  while test "x$ck" != xtt ; do    ck=
2262      while test "x$ck" != xtt ; do
2263      i=0      i=0
2264      # rtot=${#PNAME[@]}      # rtot=${#PNAME[@]}
2265      rtot=$nname      rtot=$nname
2266      while test $i -lt $rtot ; do      while test $i -le $rtot ; do
2267    
2268          #  Is $pname in the current $PACKAGES list?          #  Is $pname in the current $PACKAGES list?
2269          #  pname=${PNAME[$i]}          #  pname=${PNAME[$i]}
# Line 994  while test "x$ck" != xtt ; do Line 2275  while test "x$ck" != xtt ; do
2275                  pin="t"                  pin="t"
2276              fi              fi
2277          done          done
2278            #  or in the current $STANDARDDIRS list?
2279            for p in $STANDARDDIRS ; do
2280                if test "x$p" = "x$pname" ; then pin="t" ; fi
2281            done
2282    
2283          #  Is the DNAME entry a (+) or (-) rule ?          #  Is the DNAME entry a (+) or (-) rule ?
2284          tmp="dname=\"\$DNAME_$i\""          tmp="dname=\"\$DNAME_$i\""
# Line 1016  while test "x$ck" != xtt ; do Line 2301  while test "x$ck" != xtt ; do
2301    
2302          #  Do we need to add $dname according to the dependency rules?          #  Do we need to add $dname according to the dependency rules?
2303          if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then          if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then
2304                #echo "   " $pname ": need to add :" $dname
2305              in_dis="f"              in_dis="f"
2306              for dis in $DISABLE ; do              for dis in $DISABLE ; do
2307                  if test "x$dis" = "x$dname" ; then                  if test "x$dis" = "x$dname" ; then
# Line 1036  while test "x$ck" != xtt ; do Line 2322  while test "x$ck" != xtt ; do
2322          #  Do we need to get rid of $dname according to the dependency rules?          #  Do we need to get rid of $dname according to the dependency rules?
2323          if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then          if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then
2324              echo "Error: can't satisfy package dependencies:"              echo "Error: can't satisfy package dependencies:"
2325              echo "  \"$pname\" was requested but is disallowed by"              echo "  \"$pname\" was requested but is disallowed by"
2326              echo "  the dependency rules for \"$dname\""              echo "  the dependency rules for \"$dname\""
2327              exit 1              exit 1
2328          fi          fi
2329          i=$(( $i + 1 ))          i=`echo "$i + 1" | bc -l`
2330            #i=$(( $i + 1 ))
2331      done      done
2332      ck=$ck"t"      ck=$ck"t"
2333  done    done
2334  echo "    packages are:  $PACKAGES"    echo "    packages are: $PACKAGES"
2335    fi
2336  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2337      adr="$ROOTDIR/pkg/$i"      adr="$ROOTDIR/pkg/$i"
2338      if test -d $adr ; then      if test -d $adr ; then
# Line 1059  for i in $PACKAGES ; do Line 2347  for i in $PACKAGES ; do
2347      fi      fi
2348  done  done
2349    
   
2350  # Create a list of #define and #undef to enable/disable packages  # Create a list of #define and #undef to enable/disable packages
2351  PACKAGES_DOT_H=PACKAGES_CONFIG.h  PACKAGES_DOT_H=PACKAGES_CONFIG.h
2352  cat <<EOF >$PACKAGES_DOT_H".tmp"  #  The following UGLY HACK sets multiple "#undef"s and it needs to go
2353  C=== GENMAKE v2 ===  #  away.  On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
 C  The following defines have been set by GENMAKE, so please do not  
 C  edit anything below these comments.  In general, you should  
 C  add or remove packages by re-running genmake with different  
 C  "-enable" and/or "-disable" options.  
   
 #ifndef PACKAGES_H  
 #define PACKAGES_H  
   
 C  Packages disabled by genmake:  
 EOF  
 #  The following UGLY HACK sets multiple "#undef"s and it needs to go  
 #  away.  On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h  
2354  #  file would eventually be split up so that all package-related #define  #  file would eventually be split up so that all package-related #define
2355  #  statements could be separated and handled only by genmake.  #  statements could be separated and handled only by genmake.
2356  names=`ls -1 "$ROOTDIR/pkg"`  names=`ls -1 "$ROOTDIR/pkg"`
2357  all_pack=  all_pack=
2358    DISABLED_PACKAGES=
2359  for n in $names ; do  for n in $names ; do
2360      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
2361          has_pack="f"          has_pack="f"
# Line 1090  for n in $names ; do Line 2366  for n in $names ; do
2366              fi              fi
2367          done          done
2368          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
2369              undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2370              echo "#undef $undef" >> $PACKAGES_DOT_H".tmp"              DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
2371          fi          fi
2372      fi      fi
2373  done  done
2374  cat <<EOF >>$PACKAGES_DOT_H".tmp"  ENABLED_PACKAGES=
   
 C  Packages enabled by genmake:  
 EOF  
2375  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2376      def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`      def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2377      echo "#define $def" >> $PACKAGES_DOT_H".tmp"      ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
2378  #eh3 DEFINES="$DEFINES -D$def"  #eh3 DEFINES="$DEFINES -D$def"
2379    
2380  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
2381      case $i in      case $i in
2382          aim_v23)          aim_v23)
2383              echo "#define   ALLOW_AIM" >> $PACKAGES_DOT_H".tmp"              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
2384              DEFINES="$DEFINES -DALLOW_AIM"              echo "Warning: ALLOW_AIM is set to enable aim_v23."
             echo "Warning: ALLOW_AIM is set to enable aim_v23. This is REALLY ugly Jean-Michel :-)"  
2385              ;;              ;;
2386      esac      esac
2387  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
2388    
2389  done  done
 cat <<EOF >>$PACKAGES_DOT_H".tmp"  
   
 #endif /* PACKAGES_H */  
 EOF  
   
 if test ! -f $PACKAGES_DOT_H ; then  
     mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H  
 else  
     cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H  
     RETVAL=$?  
     if test "x$RETVAL" = x0 ; then  
         rm -f $PACKAGES_DOT_H".tmp"  
     else  
         mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"  
         mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H  
     fi  
 fi  
2390    
2391  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS='$STANDARDDIRS'"
2392  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
2393  if test "x$STANDARDDIRS" = x ; then  if test "x$STANDARDDIRS" != x ; then
2394      STANDARDDIRS="eesupp model"      for d in $STANDARDDIRS ; do
2395            adr="$ROOTDIR/$d/src"
2396            if test ! -d $adr ; then
2397                echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
2398                echo "  is correct and that you correctly specified the STANDARDDIRS option"
2399                exit 1
2400            else
2401                SOURCEDIRS="$SOURCEDIRS $adr"
2402            fi
2403            adr="$ROOTDIR/$d/inc"
2404            if test ! -d $adr ; then
2405                echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
2406                echo "  is correct and that you correctly specified the STANDARDDIRS option"
2407                exit 1
2408            else
2409                INCLUDEDIRS="$INCLUDEDIRS $adr"
2410            fi
2411        done
2412  fi  fi
 for d in $STANDARDDIRS ; do  
     adr="$ROOTDIR/$d/src"  
     if test ! -d $adr ; then  
         echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""  
         echo "  is correct and that you correctly specified the STANDARDDIRS option"  
         exit 1  
     else  
         SOURCEDIRS="$SOURCEDIRS $adr"  
     fi  
     adr="$ROOTDIR/$d/inc"  
     if test ! -d $adr ; then  
         echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""  
         echo "  is correct and that you correctly specified the STANDARDDIRS option"  
         exit 1  
     else  
         INCLUDEDIRS="$INCLUDEDIRS $adr"  
     fi  
 done  
2413    
2414  echo "  Searching for CPP_OPTIONS.h in order to warn about the presence"  echo "  Searching for *OPTIONS.h files in order to warn about the presence"
2415  echo "    of \"#define ALLOW_PKGNAME\"-type statements:"  echo "    of \"#define \"-type statements that are no longer allowed:"
2416  CPP_OPTIONS=  CPP_OPTIONS=
2417    CPP_EEOPTIONS=
2418  spaths=". $INCLUDEDIRS"  spaths=". $INCLUDEDIRS"
2419    names=`ls -1 "$ROOTDIR/pkg"`
2420  for i in $spaths ; do  for i in $spaths ; do
2421      try="$i/CPP_OPTIONS.h"      try="$i/CPP_OPTIONS.h"
2422      #  echo -n "    trying $try : "      if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
     if test -f $try -a -r $try ; then  
2423          echo "    found CPP_OPTIONS=\"$try\""          echo "    found CPP_OPTIONS=\"$try\""
2424          CPP_OPTIONS="$try"          CPP_OPTIONS="$try"
2425          break          # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
2426            for n in $names ; do
2427                test_for_package_in_cpp_options $CPP_OPTIONS $n
2428            done
2429        fi
2430        try="$i/CPP_EEOPTIONS.h"
2431        if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
2432            echo "    found CPP_EEOPTIONS=\"$try\""
2433            # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
2434    #**** not yet enabled ****
2435    #        test_for_mpi_in_cpp_eeoptions $try
2436    #**** not yet enabled ****
2437            CPP_EEOPTIONS="$try"
2438      fi      fi
2439  done  done
2440  if test "x$CPP_OPTIONS" = x ; then  if test "x$CPP_OPTIONS" = x ; then
2441      echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"      echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
2442      exit 1      exit 1
2443  fi  fi
 # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h  
 names=`ls -1 "$ROOTDIR/pkg"`  
 for n in $names ; do  
     test_for_package_in_cpp_options $CPP_OPTIONS $n  
 done  
   
2444    
2445  #  Here, we build the list of files to be "run through" the adjoint  #  Here, we build the list of files to be "run through" the adjoint
2446  #  compiler.  #  compiler.
2447  if test -f ./ad_files ; then  if test -f ./adSrcFiles.tmp ; then
2448      rm -f ./ad_files      rm -f ./adSrcFiles.tmp
2449  fi  fi
2450  echo "  Creating the list of files for the adjoint compiler."  echo "  Creating the list of files for the adjoint compiler."
2451    touch adSrcFiles.tmp
2452  for i in $SOURCEDIRS ; do  for i in $SOURCEDIRS ; do
2453      list_files=`( cd $i && ls -1 *.list 2>/dev/null )`      list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
2454      for j in $list_files ; do      for j in $list_files ; do
2455          cat $i/$j >> ad_files          cat $i/$j >> adSrcFiles.tmp
2456      done      done
2457  done  done
2458    if test ! "x"$FS = "x.f" ; then
2459  cat <<EOF > adjoint_sed      cat adSrcFiles.tmp | sed -e "s/\.f/.$FS/g" > adSrcFiles.tmp_f
2460  s/call adopen(/call adopen ( mythid,\\      mv -f adSrcFiles.tmp_f adSrcFiles.tmp
2461       \&           /g  fi
 s/call adclose(/call adclose( mythid,\\  
      \&           /g  
 s/call adread(/call adread ( mythid,\\  
      \&           /g  
 s/call adwrite(/call adwrite( mythid,\\  
      \&           /g  
   
 EOF  
2462    
2463  echo  echo
2464  echo "===  Creating the Makefile  ==="  echo "===  Creating the Makefile  ==="
2465  echo "  setting INCLUDES"  echo "  setting INCLUDES"
2466  for i in $INCLUDEDIRS ; do  for i in $INCLUDEDIRS ; do
2467      if ! test -d $i ; then      if test ! -d $i ; then
 #       INCLUDES="$INCLUDES -I$i"  
 #   else  
2468          echo "Warning: can't find INCLUDEDIRS=\"$i\""          echo "Warning: can't find INCLUDEDIRS=\"$i\""
2469      fi      fi
2470  done  done
2471    
2472    if test ! "x$DIVA" = x ; then
2473        echo "  Creating the pseudo-MPI include directory"
2474        INCLUDES="-I./mpi_headers $INCLUDES"
2475        rm -rf ./mpi_headers
2476        mkdir -p ./mpi_headers
2477    
2478        if test "x$MPIINCLUDEDIR" = x ; then
2479            if test "x$MPIHOME" = x ; then
2480                MPIHOME='/usr'
2481            fi
2482            MPIINCLUDEDIR='$MPIHOME/include'
2483        fi
2484    
2485        if test -r $MPIINCLUDEDIR/mpif.h ; then
2486            for i in $MPI_HEADER_FILES; do
2487                cp -p $MPIINCLUDEDIR/$i ./mpi_headers
2488            done
2489    
2490            perl -i -pe 's/MPI_DISPLACEMENT_CURRENT=-1_8/MPI_DISPLACEMENT_CURRENT=-1/g' mpi_headers/mpif.h
2491        else
2492            echo " We cannot create a copy of mpif.h!"
2493    #       exit -1
2494        fi
2495    fi
2496    
2497  echo "  Determining the list of source and include files"  echo "  Determining the list of source and include files"
2498  rm -rf .links.tmp  rm -rf .links.tmp
2499  mkdir .links.tmp  mkdir .links.tmp
2500    touch .links.tmp/foo
2501    if test ! -r ".links.tmp/foo" ; then
2502        echo
2503        echo "ERROR : something is wrong with your directory permissions or"
2504        echo "   your user file-creation mask (\"umask\") since creating a"
2505        echo "   sub-dir, touch-ing a file within it, and then reading it is"
2506        echo "   not working.  Please try setting your umask to something"
2507        echo "   sane such as:"
2508        echo
2509        echo "      umask 0002"
2510        echo
2511        echo "   and please verify that you have the proper permissions for"
2512        echo "   creating sub-directories and then reading files created"
2513        echo "   within them."
2514        echo
2515        exit 1
2516    fi
2517    rm -f .links.tmp/foo
2518    
2519    if test "x$OPENAD" != x ; then
2520        OAD_DONT_COMPILE="/dev/null"
2521        OAD_DONT_TRANSFORM="/dev/null"
2522        OAD_KEEP_ORIGINAL="/dev/null"
2523        OAD_CB2M_FILES="/dev/null"
2524        echo "  looking for dontCompile file:  "
2525        for i in "." $MODS ; do
2526            if test -r $i"/dontCompile" ; then
2527                OAD_DONT_COMPILE=$i"/dontCompile"
2528                echo "     found $OAD_DONT_COMPILE"
2529                break
2530            fi
2531        done
2532        echo "  looking for dontTransform file:  "
2533        for i in "." $MODS ; do
2534            if test -r $i"/dontTransform" ; then
2535                OAD_DONT_TRANSFORM=$i"/dontTransform"
2536                echo "     found $OAD_DONT_TRANSFORM"
2537                break
2538            fi
2539        done
2540        echo "  looking for keepOriginal file:  "
2541        for i in "." $MODS ; do
2542            if test -r $i"/keepOriginal" ; then
2543                OAD_KEEP_ORIGINAL=$i"/keepOriginal"
2544                echo "     found $OAD_KEEP_ORIGINAL"
2545                break
2546            fi
2547        done
2548        echo "  looking for cb2mFiles:  "
2549        for i in "." $MODS ; do
2550            if test -r $i"/cb2mFiles" ; then
2551                OAD_CB2M_FILES=$i"/cb2mFiles"
2552                echo "     found $OAD_CB2M_FILES"
2553                break
2554            fi
2555        done
2556        echo "   OpenAD exceptions:  "
2557    fi
2558    
2559  echo "# This section creates symbolic links" > srclinks.tmp  echo "# This section creates symbolic links" > srclinks.tmp
2560  echo "" >> srclinks.tmp  echo "" >> srclinks.tmp
2561  echo -n 'SRCFILES = '    > srclist.inc  printf 'F77_SRC_FILES = ' > F77srclist.tmp
2562  echo -n 'CSRCFILES = '   > csrclist.inc  printf 'NON_AD_F77_SRC_FILES = ' > nonADF77srclist.tmp
2563  echo -n 'F90SRCFILES = ' > f90srclist.inc  printf 'C_SRC_FILES = '   > csrclist.tmp
2564  echo -n 'HEADERFILES = ' > hlist.inc  printf 'F90_SRC_FILES = ' > F90srclist.tmp
2565  echo -n 'AD_FLOW_FILES = ' > ad_flow_files.inc  printf 'H_SRC_FILES = '   > hsrclist.tmp
2566    printf 'AD_FLOW_FILES = ' > ad_flow_files.tmp
2567  alldirs="$SOURCEDIRS $INCLUDEDIRS ."  alldirs="$SOURCEDIRS $INCLUDEDIRS ."
2568  for d in $alldirs ; do  for d in $alldirs ; do
2569      deplist=      deplist=
2570      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
2571      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
2572        if test "x$OPENAD" != x ; then
2573            sfiles=`( echo $sfiles | grep -v _cb2m\. )`
2574        fi
2575      for sf in $sfiles ; do      for sf in $sfiles ; do
2576          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
2577              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
2578                  extn=`echo $sf | $AWK -F '.' '{print $NF}'`                  ignore_f=f
2579                  touch .links.tmp/$sf                  case $d/$sf in
2580                  deplist="$deplist $sf"                    ./$PACKAGES_DOT_H)
2581                  case $extn in                          ignore_f=t
2582                      F)                          ;;
2583                          echo    " \\"  >> srclist.inc                    ./AD_CONFIG.h)
2584                          echo -n " $sf" >> srclist.inc                          ignore_f=t
2585                            ;;
2586                      ./FC_NAMEMANGLE.h)
2587                            ignore_f=t
2588                            ;;
2589                      ./BUILD_INFO.h)
2590                            ignore_f=t
2591                            ;;
2592                      ./EMBEDDED_FILES.h)
2593                            ignore_f=t
2594                            ;;
2595                      *)
2596                            #  For the local directory *ONLY*,
2597                            #  ignore all soft-links
2598                            if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then
2599                                ignore_f=t
2600                            else
2601                                touch .links.tmp/$sf
2602                                deplist="$deplist $sf"
2603                            fi
2604                            ;;
2605                    esac
2606                    if test "x$ignore_f" = xf ; then
2607                        extn=`echo $sf | $AWK -F. '{print $NF}'`
2608                        case $extn in
2609                          F)
2610                            echo    " \\"  >> F77srclist.tmp
2611                            printf " $sf" >> F77srclist.tmp
2612                            if test "x$OPENAD" != x ; then
2613                                basename=${sf%%.F}
2614                                isAD=`egrep ^$basename.f'[  ]*' adSrcFiles.tmp`
2615                                if test -z "$isAD" ; then
2616                                    toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE}`
2617                                    if test -z "$toBeIgnored" ; then
2618                                        echo    " \\"  >> nonADF77srclist.tmp
2619                                        printf " $sf" >> nonADF77srclist.tmp
2620                                    else
2621                                        echo "    not to be compiled   :  $sf"
2622                                    fi
2623                                else # file is initially listed as an AD file we want to exclude it
2624                                     # or we want to retain the untransformed version
2625                                    notToBeTransformed=`egrep ^$basename'[      ]*' ${OAD_DONT_TRANSFORM}`
2626                                    untransformedVersionToBeKept=`egrep ^$basename'[      ]*' ${OAD_KEEP_ORIGINAL}`
2627                                    if test -n "$notToBeTransformed"; then
2628                                        echo "    not to be transformed:  $sf"
2629                                    fi
2630                                    if test -n "$untransformedVersionToBeKept" ; then
2631                                        echo "    original to be kept  :  $sf"
2632                                    fi
2633                                    if test -n "$notToBeTransformed" -o -n "$untransformedVersionToBeKept" ; then
2634                                        echo    " \\"  >> nonADF77srclist.tmp
2635                                        printf " $sf" >> nonADF77srclist.tmp
2636                                    fi
2637                                fi
2638                            fi
2639                          ;;                          ;;
2640                      F90)                      F90)
2641                          echo    " \\"  >> f90srclist.inc                          echo    " \\"  >> F90srclist.tmp
2642                          echo -n " $sf" >> f90srclist.inc                          printf " $sf" >> F90srclist.tmp
2643                          ;;                          ;;
2644                      c)                      c)
2645                          echo    " \\"  >> csrclist.inc                          echo    " \\"  >> csrclist.tmp
2646                          echo -n " $sf" >> csrclist.inc                          printf " $sf" >> csrclist.tmp
2647                          ;;                          ;;
2648                      h)                      h)
2649                          echo    " \\"  >> hlist.inc                          echo    " \\"  >> hsrclist.tmp
2650                          echo -n " $sf" >> hlist.inc                          printf " $sf" >> hsrclist.tmp
2651                          ;;                          ;;
2652                      flow)                      flow)
2653                          echo    " \\"  >> ad_flow_files.inc                          echo    " \\"  >> ad_flow_files.tmp
2654                          echo -n " $sf" >> ad_flow_files.inc                          printf " $sf" >> ad_flow_files.tmp
2655                          ;;                          ;;
2656                  esac                     esac
2657                    fi
2658              fi              fi
2659          fi          fi
2660      done      done
2661      if test "x$deplist" != x ; then      if test "x$deplist" != x ; then
2662          if test "$d" != "." ; then
2663          echo "" >> srclinks.tmp          echo "" >> srclinks.tmp
2664          echo "#  These files are linked from $d" >> srclinks.tmp          echo "#  These files are linked from $d" >> srclinks.tmp
2665          echo "$deplist :" >> srclinks.tmp          echo "$deplist :" >> srclinks.tmp
2666          printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp  # We need to make sure that the link isn't already there.
2667    # This may happen when make thinks that a header file has to be "remade"
2668    # because a module it depends on has changed.  In this case we do nothing.
2669            printf "\tif [ ! -L \$@ ]; then \$(LN) %s/\$@ \$@; fi\n" $d >> srclinks.tmp
2670          fi
2671      fi      fi
2672  done  done
2673  rm -rf .links.tmp  rm -rf .links.tmp
2674  echo "" >> srclist.inc  echo "" >> F77srclist.tmp
2675  echo "" >> csrclist.inc  echo "" >> nonADF77srclist.tmp
2676  echo "" >> f90srclist.inc  echo "" >> csrclist.tmp
2677  echo "" >> hlist.inc  echo "" >> F90srclist.tmp
2678  echo "" >> ad_flow_files.inc  echo "" >> hsrclist.tmp
2679    echo "" >> ad_flow_files.tmp
2680    
2681    CMDLINE=$0
2682    for xx in "$@" ; do nw=`echo $xx | wc -w`
2683        if test $nw = '1' ; then CMDLINE="$CMDLINE $xx"
2684                            else CMDLINE="$CMDLINE '$xx'" ; fi
2685    done
2686    
2687  if test -e $MAKEFILE ; then  if test -f $MAKEFILE ; then
2688      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.old"
2689  fi  fi
2690  echo "  Writing makefile: $MAKEFILE"  echo "  Writing makefile: $MAKEFILE"
2691  echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE  echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
# Line 1286  echo "#    $MACHINE" >> $MAKEFILE Line 2693  echo "#    $MACHINE" >> $MAKEFILE
2693  echo "# This makefile was generated automatically on" >> $MAKEFILE  echo "# This makefile was generated automatically on" >> $MAKEFILE
2694  echo "#    $THISDATE" >> $MAKEFILE  echo "#    $THISDATE" >> $MAKEFILE
2695  echo "# by the command:" >> $MAKEFILE  echo "# by the command:" >> $MAKEFILE
2696  echo "#    $0 $@" >> $MAKEFILE  echo "#    $CMDLINE"  >> $MAKEFILE
2697  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
2698  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE  echo "#    ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
2699    
2700  EXE_AD=$EXECUTABLE"_ad"  EXE_AD=$EXECUTABLE"_ad"
2701  EXE_FTL=$EXECUTABLE"_ftl"  EXE_FTL=$EXECUTABLE"_ftl"
2702  EXE_SVD=$EXECUTABLE"_svd"  EXE_SVD=$EXECUTABLE"_svd"
2703    
2704  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2705  #  #
2706    # OPTFILE="$OPTFILE"
2707    #
2708  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
2709  # SOURCEDIRS   : Directories containing the source (.F) files  # SOURCEDIRS   : Directories containing the source (.F) files
2710  # INCLUDEDIRS  : Directories containing the header-source (.h) files  # INCLUDEDIRS  : Directories containing the header-source (.h) files
# Line 1315  cat >>$MAKEFILE <<EOF Line 2724  cat >>$MAKEFILE <<EOF
2724  # LIBS         : Library flags /or/ additional optimization/debugging flags  # LIBS         : Library flags /or/ additional optimization/debugging flags
2725    
2726  ROOTDIR     = ${ROOTDIR}  ROOTDIR     = ${ROOTDIR}
2727  BUILDDIR    = ${BUILDDIR}    BUILDDIR    = ${BUILDDIR}
2728  SOURCEDIRS  = ${SOURCEDIRS}  SOURCEDIRS  = ${SOURCEDIRS}
2729  INCLUDEDIRS = ${INCLUDEDIRS}  INCLUDEDIRS = ${INCLUDEDIRS}
2730  EXEDIR      = ${EXEDIR}  EXEDIR      = ${EXEDIR}
# Line 1328  EXE_AD      = ${EXE_AD} Line 2737  EXE_AD      = ${EXE_AD}
2737  EXE_FTL     = ${EXE_FTL}  EXE_FTL     = ${EXE_FTL}
2738  EXE_SVD     = ${EXE_SVD}  EXE_SVD     = ${EXE_SVD}
2739    
2740    ENABLED_PACKAGES = ${ENABLED_PACKAGES}
2741    DISABLED_PACKAGES = ${DISABLED_PACKAGES}
2742    
2743    # These files are created by Makefile
2744    SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h
2745  EOF  EOF
2746    
2747  #  Note: figure out some way to add Hyades JAM libraries here  if test "x$EMBED_SRC" = xt ; then
2748        echo "EMBEDDED_FILES = EMBEDDED_FILES.h" >>$MAKEFILE
2749    else
2750        echo "EMBEDDED_FILES = " >>$MAKEFILE
2751    fi
2752    
2753  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2754  # Unix ln (link)  # Unix ln (link)
2755  LN = ${LN}  LN = ${LN}
# Line 1345  KPP = ${KPP} Line 2763  KPP = ${KPP}
2763  FC = ${FC}  FC = ${FC}
2764  # Fortran compiler  # Fortran compiler
2765  F90C = ${F90C}  F90C = ${F90C}
2766    # C compiler
2767    CC = ${CC}
2768  # Link editor  # Link editor
2769  LINK = ${LINK}  LINK = ${LINK} ${LDADD}
2770    
2771  # Defines for CPP  # Defines for CPP
2772  DEFINES = ${DEFINES}  DEFINES = ${DEFINES}
# Line 1356  INCLUDES = ${INCLUDES} Line 2776  INCLUDES = ${INCLUDES}
2776  KFLAGS1 = ${KFLAGS1}  KFLAGS1 = ${KFLAGS1}
2777  KFLAGS2 = ${KFLAGS2}  KFLAGS2 = ${KFLAGS2}
2778  # Optim./debug for FC  # Optim./debug for FC
2779  FFLAGS = ${FFLAGS}  FFLAGS = ${FFLAGS} ${FEXTRAFLAGS}
2780  FOPTIM = ${FOPTIM}  FOPTIM = ${FOPTIM}
2781  # Optim./debug for FC  # Optim./debug for FC
2782  F90FLAGS = ${F90FLAGS}  F90FLAGS = ${F90FLAGS}
2783  F90OPTIM = ${F90OPTIM}  F90OPTIM = ${F90OPTIM}
2784    F90FIXEDFORMAT = ${F90FIXEDFORMAT}
2785  # Flags for CC  # Flags for CC
2786  CFLAGS = ${CFLAGS}  CFLAGS = ${CFLAGS}
2787  # Files that should not be optimized  # Files that should not be optimized
2788  NOOPTFILES = ${NOOPTFILES}  NOOPTFILES = ${NOOPTFILES}
2789  NOOPTFLAGS = ${NOOPTFLAGS}  NOOPTFLAGS = ${NOOPTFLAGS}
2790  # Flags and libraries needed for linking  # Flags and libraries needed for linking
2791  LIBS = ${LIBS} \$(XLIBS)  LIBS = ${LIBS}
2792  # Name of the Mekfile  # Name of the makefile
2793  MAKEFILE=${MAKEFILE}  MAKEFILE=${MAKEFILE}
2794    
2795  EOF  EOF
2796    
2797  cat srclist.inc       >> $MAKEFILE  cat F77srclist.tmp      >> $MAKEFILE
2798  cat csrclist.inc      >> $MAKEFILE  cat nonADF77srclist.tmp >> $MAKEFILE
2799  cat f90srclist.inc    >> $MAKEFILE  cat csrclist.tmp        >> $MAKEFILE
2800  cat hlist.inc         >> $MAKEFILE  cat F90srclist.tmp      >> $MAKEFILE
2801  cat ad_flow_files.inc >> $MAKEFILE  cat hsrclist.tmp        >> $MAKEFILE
2802  echo               >> $MAKEFILE  cat ad_flow_files.tmp   >> $MAKEFILE
 echo 'F77FILES =  $(SRCFILES:.F=.f)'                                           >> $MAKEFILE  
 echo 'F90FILES =  $(F90SRCFILES:.F90=.f90)'                                    >> $MAKEFILE  
 echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE  
2803    
2804  rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc  rm -f F77srclist.tmp nonADF77srclist.tmp csrclist.tmp F90srclist.tmp hsrclist.tmp ad_flow_files.tmp
 rm -f ad_flow_files.inc  
2805    
2806  cat >>$MAKEFILE <<EOF  echo >> $MAKEFILE
2807    
2808  .SUFFIXES:  # add definitions for preprocessed sources
2809  .SUFFIXES: .o .f .p .F .c .F90 .f90  # and note that not all systems allow case sensitive extensions
2810    # hence the $FS and $FS90 here.
2811    # for fixed format f90 files we use ff90 or FF90 resp
2812    # but these are not expected to be the original source files
2813    
2814    echo 'F77_PP_SRC_FILES = $(F77_SRC_FILES:.F=.'$FS')'      >> $MAKEFILE
2815    echo 'F90_PP_SRC_FILES = $(F90_SRC_FILES:.F90=.'$FS90')' >> $MAKEFILE
2816    echo 'OBJFILES= $(F77_SRC_FILES:.F=.o) $(C_SRC_FILES:.c=.o) $(F90_SRC_FILES:.F90=.o)' >> $MAKEFILE
2817    echo 'FLOWFILES =  $(AD_FLOW_FILES:.flow=.flowdir)' >> $MAKEFILE
2818    echo >> $MAKEFILE
2819    echo '.SUFFIXES:' >> $MAKEFILE
2820    echo '.SUFFIXES: .o .'$FS' .p .F .c .f'$FS90' .'$FS90' .FF90 .F90 .flowdir .flow' >> $MAKEFILE
2821    
2822    cat >>$MAKEFILE <<EOF
2823    
2824  all: \$(EXECUTABLE)  all: \$(EXECUTABLE)
2825  \$(EXECUTABLE): \$(OBJFILES)  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(OBJFILES) \$(EMBEDDED_FILES)
2826            @echo Creating \$@ ...
2827          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
2828    
2829  depend:  depend:
2830          @make links          @make -f \$(MAKEFILE) links
2831          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)
2832          ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE)          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2833            -rm -f makedepend.out
2834    
2835  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)  lib: libmitgcmuv.a
2836    
2837  small_f: \$(F77FILES) \$(F90FILES)  libmitgcmuv.a: \$(OBJFILES)
2838            ar rcv libmitgcmuv.a \$(OBJFILES)
2839            ar d   libmitgcmuv.a main.o
2840    
2841    obj: \$(OBJFILES)
2842    
2843    links: \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(SPECIAL_FILES)
2844    
2845    small_f: \$(F77_PP_SRC_FILES) \$(F90_PP_SRC_FILES)
2846    
2847  output.txt: \$(EXECUTABLE)  output.txt: \$(EXECUTABLE)
2848          @printf 'running ... '          @printf 'running ... '
2849          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
2850    
2851    # remove most of the files that "make" generates
2852  clean:  clean:
2853          -cat AD_CONFIG.template > AD_CONFIG.h          -rm -rf *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
2854          -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}          -rm -rf *.o
2855            -rm -rf *.$FS *.flowdir
2856            -rm -rf *.f$FS90 \$(AD_CLEAN) ad_input*
2857    
2858    # remove most of the files that "make" and "make depend" generate
2859  Clean:  Clean:
2860          @make clean          @make -f \$(MAKEFILE) clean
2861          @make cleanlinks          @make -f \$(MAKEFILE) cleanlinks
2862          -rm -f Makefile.bak genmake_state genmake_*optfile make.log          -rm -f \$(SPECIAL_FILES) f90mkdepend.log $MAKEFILE.old
2863            -rm -f taf_command taf_output taf_ad.log taf_ad_flow.log taf_ftl.log
2864            -rm -f genmake_warnings genmake_errors make.log
2865    
2866    # remove also the executable, files that "genmake2" generates (except Makefile)
2867    #         and output from a run (plus log files from testreport)
2868  CLEAN:  CLEAN:
2869          @make Clean          @make -f \$(MAKEFILE) Clean
2870            -rm -f \$(EXECUTABLE) \$(EXE_AD) \$(EXE_FTL) *.bak
2871            -rm -f $LOGFILE genmake_state genmake_*optfile
2872            -rm -f SIZE.h.mpi genmake.tr_log make.tr_log
2873          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
2874          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
2875          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
2876          -rm -f \$(EXECUTABLE) output.txt          -rm -f *.txt STD* *diagnostics.log datetime
2877            -rm -f *_MIT_CE_000.opt0000 costfunction*0000
2878            -rm -rf mnc_test_*
2879    
 #eh3 Makefile: makefile  
2880  makefile:  makefile:
2881          ${0} $@          $THIS_SCRIPT $G2ARGS
2882  cleanlinks:  cleanlinks:
2883          -find . -type l -exec rm {} \;          -find . -type l -exec rm {} \;
2884    
2885  # The normal chain of rules is (  .F - .f - .o  )  # Special targets (SPECIAL_FILES) which are created by make
2886  .F.f:  ${PACKAGES_DOT_H}:
2887            @echo Creating \$@ ...
2888            @$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) > \$@
2889    AD_CONFIG.h:
2890            @echo Creating \$@ ...
2891            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > \$@
2892    FC_NAMEMANGLE.h:
2893            @echo Creating \$@ ...
2894            echo "$FC_NAMEMANGLE" > \$@
2895    
2896    BUILD_INFO.h:
2897            @echo Creating \$@ ...
2898    EOF
2899    
2900    test ! "x$THISVER" = x  && echo "       -echo \"#define THISVER '$THISVER'\" > \$@"   >> $MAKEFILE
2901    test ! "x$THISUSER" = x && echo "       -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE
2902    test ! "x$THISDATE" = x && echo "       -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
2903    test ! "x$THISHOST" = x && echo "       -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
2904    
2905    if test "x$EMBED_SRC" = xt ; then
2906        cat >>$MAKEFILE <<EOF
2907    
2908    decode_files.o : EMBEDDED_FILES.h
2909    
2910    ##  \$(F77_PP_SRC_FILES)
2911    all_fF.tar.gz : \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile
2912            @echo Creating \$@ ...
2913            -tar -hcf all_fF.tar \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile
2914            -rm -f all_fF.tar.gz
2915            -gzip all_fF.tar
2916    
2917    EMBEDDED_FILES.h : all_fF.tar.gz
2918            @echo Creating \$@ ...
2919            -\${ROOTDIR}/tools/embed_encode/encode_files EMBEDDED_FILES.h all_fF.tar.gz
2920    
2921    EOF
2922    fi
2923    
2924    cat >>$MAKEFILE <<EOF
2925    
2926    # The normal chain of rules is (  .F - .$FS - .o  )
2927    
2928    ## This nullifies any default implicit rules concerning these two file types:
2929    ## %.o : %.F
2930    
2931    .F.$FS:
2932          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2933  .f.o:  .$FS.o:
2934            \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2935    .F.o:
2936          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2937  .F90.f90:  .F90.$FS90:
2938          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2939  .f90.o:  .FF90.f$FS90:
2940            \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2941    .$FS90.o:
2942          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
2943    .f$FS90.o:
2944            cp \$< \$(basename  \$<).f90
2945            \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$(F90FIXEDFORMAT) \$(basename  \$<).f90
2946  .c.o:  .c.o:
2947          \$(CC) \$(CFLAGS) -c \$<          \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$<
2948    .flow.flowdir:
2949            \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2950    
2951  # Special exceptions that use the ( .F - .p - .f - .o ) rule-chain  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
2952  .F.p:  .F.p:
2953          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2954  .p.f:  .p.$FS:
2955          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
2956    
2957    EOF
2958    
2959  #=========================================  #=========================================
2960  #===  Automatic Differentiation Rules  ===  #===  Automatic Differentiation Rules  ===
2961    #===  for TAMC/TAF  ======================
2962    
2963    if test "x$OPENAD" = x ; then
2964    
2965    cat >>$MAKEFILE <<EOF
2966    
2967  TAMC           = ${TAMC}  TAMC           = ${TAMC}
2968  TAF            = ${TAF}  TAF            = ${TAF}
# Line 1461  ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF Line 2977  ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF
2977  ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"  ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
2978  for i in $ad_vars ; do  for i in $ad_vars ; do
2979      name=$i      name=$i
2980      t1="t2=\$"`echo $i`      t1="t2=\$"`echo "$i"`
2981      eval $t1      eval $t1
2982      printf "%-20s = " $name >> $MAKEFILE      printf "%-20s = " $name >> $MAKEFILE
2983      echo $t2 >> $MAKEFILE      echo "$t2" | sed -e 's| \+| |g' >> $MAKEFILE
2984  done  done
2985    
2986  echo "  Add the source list for AD code generation"  echo "  Add the source list for AD code generation"
2987  echo >> $MAKEFILE  echo >> $MAKEFILE
2988  echo -n "AD_FILES = " >> $MAKEFILE  printf "AD_FILES = " >> $MAKEFILE
2989  AD_FILES=`cat ad_files`  AD_FILES=`cat adSrcFiles.tmp`
2990  for i in $AD_FILES ; do  for i in $AD_FILES ; do
2991      echo    " \\" >> $MAKEFILE      echo    " \\" >> $MAKEFILE
2992      echo -n " $i" >> $MAKEFILE      printf " $i" >> $MAKEFILE
2993  done  done
2994  echo >> $MAKEFILE  echo >> $MAKEFILE
2995  rm -f ad_files  rm -f adSrcFiles.tmp
2996    
2997  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2998    
2999  # ... AD ...  # ... AD ...
3000  adall: ad_taf  adall: \$(EXE_AD)
3001  adtaf: ad_taf_output.f  adtaf: ad_taf_output.$FS
3002  adtamc: ad_tamc_output.f  adtamc: ad_tamc_output.$FS
3003    
3004  ad_input_code.f: \$(AD_FILES) \$(HEADERFILES)  ad_input_code.$FS: \$(AD_FILES) \$(H_SRC_FILES) \$(AD_FLOW_FILES)
3005            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3006          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
3007          @make \$(F77FILES)          -rm -f ad_config.template
3008          @make \$(AD_FLOW_FILES)          @make -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3009          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f          @make -f \$(MAKEFILE) \$(FLOWFILES)
3010            cat \$(FLOWFILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ad_input_code.$FS
3011  ad_taf_output.f: ad_input_code.f  
3012          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f  ad_taf_output.$FS: ad_input_code.$FS
3013          cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
3014            ls -l ad_input_code_ad.$FS
3015  ad_taf: ad_taf_output.o \$(OBJFILES)          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
3016          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)  
3017    adtafonly:
3018  ad_tamc_output.f: ad_input_code.f          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
3019          \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f          ls -l ad_input_code_ad.$FS
3020          cat ad_input_code_ad.f | sed -f adjoint_sed > ad_tamc_output.f          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
3021    
3022    \${EXE_AD}: ad_taf_output.o \$(OBJFILES)
3023            \$(LINK) -o \${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
3024    
3025    ad_tamc_output.$FS: ad_input_code.$FS
3026            \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
3027            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS
3028    
3029  ad_tamc: ad_tamc_output.o \$(OBJFILES)  ad_tamc: ad_tamc_output.o \$(OBJFILES)
3030          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
3031    
3032    adonlyfwd:
3033            patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
3034    
3035    adtrick:
3036            patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
3037    
3038    adobj: ad_taf_output.o \$(OBJFILES)
3039    
3040  # ... FTL ...  # ... FTL ...
3041  ftlall: ftl_taf  ftlall: \$(EXE_FTL)
3042  ftltaf: ftl_taf_output.f  ftltaf: ftl_taf_output.$FS
3043  ftltamc: ftl_tamc_output.f  ftltamc: ftl_tamc_output.$FS
3044    
3045  ftl_input_code.f: \$(AD_FILES) \$(HEADERFILES)  ftl_input_code.$FS: \$(AD_FILES) \$(H_SRC_FILES)
3046            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ftl_config.template
3047          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
3048          @make \$(F77FILES)          -rm -f ftl_config.template
3049          @make \$(AD_FLOW_FILES)          @make -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3050          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f          @make -f \$(MAKEFILE) \$(AD_FLOW_FILES)
3051            cat \$(AD_FLOW_FILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ftl_input_code.$FS
3052  ftl_taf_output.f: ftl_input_code.f  
3053          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f  ftl_taf_output.$FS: ftl_input_code.$FS
3054          cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_taf_output.f          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
3055            ls -l ftl_input_code_ftl.$FS
3056  ftl_taf: ftl_taf_output.o \$(OBJFILES)          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
3057          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)  
3058    ftltafonly:
3059  ftl_tamc_output.f: ftl_input_code.f          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
3060          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f          ls -l ftl_input_code_ftl.$FS
3061          cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_tamc_output.f          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
3062    
3063    \${EXE_FTL}: ftl_taf_output.o \$(OBJFILES)
3064            \$(LINK) -o \${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
3065    
3066    ftl_tamc_output.$FS: ftl_input_code.$FS
3067            \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
3068            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS
3069    
3070  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
3071          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
   
3072    
3073  # ... SVD ...  # ... SVD ...
3074  svd: svd_taf  svdtaf: ad_taf_output.$FS ftl_taf_output.$FS
3075  svd_taf_f: svd_taf_output.f          @echo "--->>> Only ran TAF to generate SVD code!    <<<---"
3076            @echo "--->>> Do make svdall afterwards to compile. <<<---"
3077    svdall: svd_touch svd_taf
3078    
3079    svd_taf: \$(OBJFILES)
3080            \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
3081    
3082            @echo "--->>> Only COMPILE svd code! <<<---"
3083            @echo "--->>> Assumes you previously <<<---"
3084            @echo "--->>> did make svdtaf        <<<---"
3085    
3086    svd_touch:
3087            @echo "--->>> Only COMPILE svd code! <<<---"
3088            @echo "--->>> Assumes you previously <<<---"
3089            @echo "--->>> did make svdtaf        <<<---"
3090            touch ad_taf_output.$FS ftl_taf_output.$FS
3091            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS
3092            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS
3093            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ftl_config.template
3094            cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
3095            -rm -f ftl_config.template
3096    
3097  svd_input_code.f: \$(SRCFILES)  EOF
         cmp svd_config.template AD_CONFIG.h || cat svd_config.template > AD_CONFIG.h  
         @make \$(F77FILES)  
         @make \$(AD_FLOW_FILES)  
         cat \$(AD_FLOW_FILES) \$(AD_FILES) > svd_input_code.f  
   
 svd_taf_output.f: svd_input_code.f  
         \$(TAF) \$(SVD_TAF_FLAGS) \$(TAF_EXTRA) svd_input_code.f  
         cat svd_input_code_ad.f | sed -f adjoint_sed > svd_taf_output.f  
3098    
3099  svd_taf: svd_taf_output.o \$(OBJFILES)  fi
         \$(LINK) -o ${EXE_SVD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) svd_taf_output.o \$(LIBS)  
3100    
3101    #===  for OpenAD  ========================
3102    
3103  #=========================================  if test "x$OPENAD" != x ; then
3104    
3105    # ============ begin OpenAD specific section ==============
3106    
3107    cat >>$MAKEFILE <<EOF
3108    
3109    # all the source files linked from the various locations:
3110    ALL_LINKED_FILES= \
3111    \$(F77_SRC_FILES) \
3112    \$(C_SRC_FILES) \
3113    \$(H_SRC_FILES) \
3114    \$(F90_SRC_FILES) \
3115    \$(SPECIAL_FILES)
3116    
3117    ifndef OPENADROOT
3118      \$(error "Error:  environment variable OPENADROOT not defined!")
3119    endif
3120    
3121    ifndef XAIFSCHEMAROOT
3122      \$(error "Error:  environment variable XAIFSCHEMAROOT not defined!")
3123    endif
3124    
3125    ifndef XAIFBOOSTERROOT
3126      \$(error "Error:  environment variable XAIFBOOSTERROOT not defined!")
3127    endif
3128    
3129    EOF
3130    
3131    echo "  Add the source list for common block to module conversion "
3132    echo >> $MAKEFILE
3133    printf "CB2M_F90_SRC_NAMES = " >> $MAKEFILE
3134    for i in `cat ${OAD_CB2M_FILES}` ; do
3135      echo    " \\" >> $MAKEFILE
3136      printf " $i" >> $MAKEFILE
3137    done
3138    echo >> $MAKEFILE
3139    
3140    echo "  Add the source list for AD code generation"
3141    echo >> $MAKEFILE
3142    printf "AD_FILES = " >> $MAKEFILE
3143    for i in `cat ${OAD_CB2M_FILES}` ; do
3144      echo    " \\" >> $MAKEFILE
3145      printf " ${i}_mod.f$FS90" >> $MAKEFILE
3146    done
3147    AD_FILES=`cat adSrcFiles.tmp`
3148    for i in $AD_FILES ; do
3149      basename=${i%%.f}
3150      toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE} ${OAD_DONT_TRANSFORM}`
3151      if test -z "$toBeIgnored" ; then
3152        echo    " \\" >> $MAKEFILE
3153        printf " $i" >> $MAKEFILE
3154      fi
3155    done
3156    echo >> $MAKEFILE
3157    rm -f adSrcFiles.tmp
3158    
3159    cat >>$MAKEFILE <<EOF
3160    
3161    adAll: \$(EXE_AD)
3162    .PHONY: adAll
3163    
3164    CB2M_F90_PP_SRC_FILES=\$(addsuffix _mod.f$FS90, \$(CB2M_F90_SRC_NAMES))
3165    
3166    .PRECIOUS: \$(CB2M_F90_PP_SRC_FILES) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90)
3167    
3168    .PHONY: adDepend
3169    adDepend: \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) \$(addsuffix _mod.FF90, \$(CB2M_F90_SRC_NAMES)) \$(F77_SRC_FILES:.F=_cb2m.FF90)
3170            \$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)
3171            \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
3172            -rm -f makedepend.out
3173    
3174    OPENAD_SUPPORT_F90_SRC_FILES = \
3175    w2f__types.F90 \
3176    OAD_active.F90 \
3177    OAD_cp.F90 \
3178    OAD_rev.F90 \
3179    OAD_tape.F90
3180    
3181    OPENAD_SUPPORT_C_SRC_FILES = \
3182    iaddr.c \
3183    timeRatio.c
3184    
3185    f95_test_mods.f90: \$(OPENAD_SUPPORT_F90_SRC_FILES:F90=$FS90)
3186            cat \$^ > \$@
3187    
3188    f95_test.f90: all_mods.xb.x2w.w2f.pp.f$FS90 \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90) ad_input_code.w2f.pre.xb.x2w.w2f.td.pp.f$FS90
3189            cat \$^ > \$@
3190    
3191    f95_test.out: f95_test_mods.f90 f95_test.f90
3192            f95 -fixed -w=unused -maxcontin=132 -c f95_test_mods.f90 > \$@ 2>&1
3193            f95 -fixed -w=unused -maxcontin=132 -c -fixed f95_test.f90 >> \$@ 2>&1
3194    
3195    CB2M_AD_FILES=\$(AD_FILES:.f=_cb2m.f$FS90)
3196    
3197    AD_OBJ_FILES_S1=\$(OPENAD_SUPPORT_F90_SRC_FILES:.F90=.o) \$(OPENAD_SUPPORT_C_SRC_FILES:.c=.o)  OAD_intrinsics_oad.o \$(CB2M_AD_FILES:.f$FS90=_oad.o)
3198    
3199    AD_OBJ_FILES_S2=\$(AD_OBJ_FILES_S1) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.o) \$(C_SRC_FILES:.c=.o) \$(F90_SRC_FILES:.F90=.o)
3200    
3201    \$(EXE_AD): \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) postProcess.tag \$(AD_OBJ_FILES_S2)
3202            \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(AD_OBJ_FILES_S2) \$(LIBS)
3203    
3204    # create sources files modules from header files containing common blocks
3205    %_mod.FF90 : %.h ../OAD_support/cb2mGetModules.csh ../OAD_support/cb2mGetModules.awk
3206            ../OAD_support/cb2mGetModules.csh $< ../OAD_support/cb2mGetModules.awk
3207    
3208    # create new header files with USE statements for the new modules made above
3209    %_mod.h : %.h ../OAD_support/cb2mGetHeaders.csh ../OAD_support/cb2mGetHeaders.awk
3210            ../OAD_support/cb2mGetHeaders.csh $< ../OAD_support/cb2mGetHeaders.awk \$(CB2M_F90_SRC_NAMES)
3211    
3212    # change the include directives of everybody to refer to  the new header files with the USE statements
3213    %_cb2m.FF90 : %.F ../OAD_support/cb2mUseModules.bash
3214            ../OAD_support/cb2mUseModules.bash $< ${MPI}
3215    
3216    # makefile debug rule
3217    small_f: \$(CB2M_F90_PP_SRC_FILES)
3218    .PHONY: small_f
3219    
3220    ad_output.txt: \$(EXE_AD)
3221            @printf 'linking data files ... '
3222            \$(LN) -f ../input_ad/data* ../input_ad/eedata .
3223            \$(LN) -f ../../global_ocean.90x40x15/input/*.bin .
3224            @printf 'running ... '
3225            @./\$(EXE_AD) > \$@
3226    
3227    ad_input_code.f$FS90:  \$(CB2M_AD_FILES)
3228            cat \$^ > \$@
3229    
3230    # canonicalizer
3231    ad_input_code_sf.pre.f90 : \$(CB2M_AD_FILES)
3232            \${OPENADFORTTK_BASE}/tools/SourceProcessing/preProcess.py --timing --r8 -H -S  -o \$@ \$^
3233    
3234    # replace stop statements (to avoid the implied unstructured control flow)  with print statements
3235    ad_input_code_sf.pre.s2p.f90 : ad_input_code_sf.pre.f90
3236            cat \$< | sed -f ../OAD_support/stop2print.sed > ad_input_code_sf.pre.s2p.f90
3237    
3238    # F -> WHIRL
3239    ad_input_code_sf.pre.s2p.B: ad_input_code_sf.pre.s2p.f90
3240            \${OPEN64ROOT}/crayf90/sgi/mfef90 -r8 -z -F ad_input_code_sf.pre.s2p.f90
3241    
3242    # WHIRL -> XAIF
3243    ad_input_code_sf.pre.s2p.xaif : ad_input_code_sf.pre.s2p.B
3244            \${OPENADFORTTK}/bin/whirl2xaif -s -n --debug 1 -o \$@ \$<
3245    
3246    # XAIF -> XAIF'
3247    ad_input_code_sf.pre.s2p.xb.xaif : ad_input_code_sf.pre.s2p.xaif xaif.xsd xaif_base.xsd xaif_inlinable_intrinsics.xsd xaif_derivative_propagator.xsd xaif_output.xsd
3248            \${XAIFBOOSTERROOT}/xaifBooster/algorithms/BasicBlockPreaccumulationReverse/driver/oadDriver -f -t forward_step -i \$< -c \${XAIFSCHEMAROOT}/schema/examples/inlinable_intrinsics.xaif -o \$@ -I -r
3249    
3250    # XAIF' -> WHIRL'
3251    ad_input_code_sf.pre.s2p.xb.x2w.B : ad_input_code_sf.pre.s2p.xb.xaif
3252            \${OPENADFORTTK}/bin/xaif2whirl --debug 1 ad_input_code_sf.pre.s2p.B \$<
3253    
3254    # WHIRL' -> F'
3255    ad_input_code_sf.pre.s2p.xb.x2w.w2f.f$FS90: ad_input_code_sf.pre.s2p.xb.x2w.B
3256            \${OPEN64ROOT}/whirl2f/whirl2f -FLIST:ftn_file=\$@ -openad \$<
3257    
3258    # insert template directives
3259    ad_input_code_sf.pre.s2p.xb.x2w.w2f.td.f$FS90: ad_input_code_sf.pre.s2p.xb.x2w.w2f.f$FS90 ../OAD_support/insertTemplateDir.bash
3260            ../OAD_support/insertTemplateDir.bash \$< \$@
3261    
3262    PPEXTRAS=\$(wildcard ../OAD_support/ad_template.*.F) ../OAD_support/ad_inline.F
3263    # postprocess F'
3264    postProcess.tag: ad_input_code_sf.pre.s2p.xb.x2w.w2f.td.f$FS90 \$(PPEXTRAS:.F=.f) | w2f__types.f90
3265            \${OPENADFORTTK_BASE}/tools/SourceProcessing/postProcess.py --progress --timing --infoUnitFile w2f__types.f90 --outputFormat=fixed --separateOutput --pathSuffix "" --filenameSuffix "_oad" -m r -i ../OAD_support/ad_inline.f \$<
3266            # the target is a placeholder to trigger a single execution of the rule
3267            touch \$@
3268    # put this so make knows about the postprocessing output
3269    OAD_intrinsics_oad.f \$(CB2M_AD_FILES:.f$FS90=_oad.f): postProcess.tag
3270    
3271    # link the XAIF schema files
3272    %.xsd:
3273            \$(LN) \${XAIFSCHEMAROOT}/schema/\$@ .
3274    
3275    # link the support files:
3276    \$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES):
3277            \$(LN) ../OAD_support/\$@ .
3278    
3279    AD_CLEAN += *_mod.h *_mod.F90 *.FF90 *.mod-whirl temp.sed oad_cp.* postProcess.tag \$(PPEXTRAS:.F=.f)
3280    
3281    # ============ end OpenAD specific section ==============
3282    
3283  EOF  EOF
3284    
3285    fi
3286    
3287    #=========================================
3288    
3289  if test "x$EXEHOOK" != x ; then  if test "x$EXEHOOK" != x ; then
3290      printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE      printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
3291  fi  fi
# Line 1565  for i in $KPPFILES ; do Line 3297  for i in $KPPFILES ; do
3297      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
3298          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
3299      fi      fi
3300      echo "$base.f: $base.p" >> $MAKEFILE      echo "$base.$FS: $base.p" >> $MAKEFILE
3301  done  done
3302    
3303  echo "  Making list of NOOPTFILES"  echo "  Making list of NOOPTFILES"
# Line 1575  for i in $NOOPTFILES ; do Line 3307  for i in $NOOPTFILES ; do
3307      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
3308          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
3309      fi      fi
3310      echo "$base.o: $base.f" >> $MAKEFILE      echo "$base.o: $base.$FS" >> $MAKEFILE
3311      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
3312  done  done
3313    
# Line 1588  printf "\n\n# DO NOT DELETE\n" >> $MAKEF Line 3320  printf "\n\n# DO NOT DELETE\n" >> $MAKEF
3320    
3321  printf "\n===  Done  ===\n"  printf "\n===  Done  ===\n"
3322    
3323  #  Write the "template" files for the adjoint builds  # Create special header files
3324  cat >AD_CONFIG.template <<EOF  $BASH $TOOLSDIR/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" $DISABLED_PACKAGES " " "Enabled packages:" $ENABLED_PACKAGES > $PACKAGES_DOT_H".tmp"
3325  C  WARNING: This file is automatically generated by genmake2 and  if test ! -f $PACKAGES_DOT_H ; then
3326  C    used by the Makefile rules.  Please DO NOT EDIT this file      mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
3327  C    unless you are CERTAIN that you know what you are doing.  else
3328        cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
3329  #undef ALLOW_ADJOINT_RUN      RETVAL=$?
3330  #undef ALLOW_TANGENTLINEAR_RUN      if test "x$RETVAL" = x0 ; then
3331  #undef ALLOW_ECCO_OPTIMIZATION          rm -f $PACKAGES_DOT_H".tmp"
3332  EOF      else
3333  cat >ad_config.template <<EOF          mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
3334  C  WARNING: This file is automatically generated by genmake2 and          mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
3335  C    used by the Makefile rules.  Please DO NOT EDIT this file      fi
3336  C    unless you are CERTAIN that you know what you are doing.  fi
3337    if test ! -f AD_CONFIG.h ; then
3338  #define ALLOW_ADJOINT_RUN      $BASH $TOOLSDIR/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > AD_CONFIG.h
3339  #undef ALLOW_TANGENTLINEAR_RUN  fi
 #undef ALLOW_ECCO_OPTIMIZATION  
 EOF  
 cat >ftl_config.template <<EOF  
 C  WARNING: This file is automatically generated by genmake2 and  
 C    used by the Makefile rules.  Please DO NOT EDIT this file  
 C    unless you are CERTAIN that you know what you are doing.  
   
 #undef ALLOW_ADJOINT_RUN  
 #define ALLOW_TANGENTLINEAR_RUN  
 #undef ALLOW_ECCO_OPTIMIZATION  
 EOF  
 cat >svd_config.template <<EOF  
 C  WARNING: This file is automatically generated by genmake2 and  
 C    used by the Makefile rules.  Please DO NOT EDIT this file  
 C    unless you are CERTAIN that you know what you are doing.  
   
 #undef ALLOW_ADJOINT_RUN  
 #undef ALLOW_TANGENTLINEAR_RUN  
 #undef ALLOW_ECCO_OPTIMIZATION  
 EOF  
 cp AD_CONFIG.template AD_CONFIG.h  
   
3340    
3341  #  Write the "state" for future records  #  Write the "state" for future records
3342  if test "x$DUMPSTATE" != xf ; then  if test "x$DUMPSTATE" = xt ; then
3343      echo -n "" > genmake_state      printf "" > genmake_state
3344      for i in $gm_state ; do      for i in $gm_state ; do
3345          t1="t2=\$$i"          t1="t2=\$$i"
3346          eval $t1          eval $t1
3347          echo "$i='$t2'" >> genmake_state          echo "$i='$t2'" | sed -e 's/  */ /g' >> genmake_state
3348      done      done
3349  fi  fi

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

  ViewVC Help
Powered by ViewVC 1.1.22