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

Legend:
Removed from v.1.58  
changed lines
  Added in v.1.272

  ViewVC Help
Powered by ViewVC 1.1.22