/[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.18 by edhill, Tue Oct 21 20:42:16 2003 UTC revision 1.276 by jmc, Thu Jan 7 20:21:42 2016 UTC
# Line 1  Line 1 
1  #!/bin/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      grep -i "#define.*ALLOW_$pkg" $cpp_options > /dev/null 2>&1      test_for_string_in_file $cpp_options "^ *# *define *\<ALLOW_$pkg\>"
186      RETVAL=$?      test_for_string_in_file $cpp_options "^ *# *undef *\<ALLOW_$pkg\>"
187      if test "x${RETVAL}" = x0 ; then      test_for_string_in_file $cpp_options "^ *# *define *\<DISABLE_$pkg\>"
188          echo "Error: In $cpp_options there is an illegal line: #define ALLOW_$pkg"      test_for_string_in_file $cpp_options "^ *# *undef *\<DISABLE_$pkg\>"
189          exit 99  }
190      fi  
191      grep -i "#undef.*ALLOW_$pkg" $cpp_options > /dev/null 2>&1  # Search for particular CPP #cmds associated with MPI
192      RETVAL=$?  # usage: test_for_mpi_in_cpp_eeoptions CPP_file
193      if test "x${RETVAL}" = x0 ; then  test_for_mpi_in_cpp_eeoptions() {
194          echo "Error: In $cpp_options there is an illegal line: #undef ALLOW_$pkg"      cpp_options=$1
195          exit 99      test_for_string_in_file $cpp_options "^ *# *define *\<ALLOW_USE_MPI\>"
196      fi      test_for_string_in_file $cpp_options "^ *# *undef *\<ALLOW_USE_MPI\>"
197      grep -i "#define.*DISABLE_$pkg" $cpp_options > /dev/null 2>&1  }
198    
199    # Search for particular string in a file. Return 1 if detected, 0 if not
200    # usage: test_for_string_in_file file string
201    test_for_string_in_file() {
202        file=$1
203        strng=$2
204        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 "Error: In $cpp_options there is an illegal line: #define DISABLE_$pkg"          printf "Error: In $file there is an illegal line: "
208            grep -i "$strng" $file
209          exit 99          exit 99
210      fi      fi
211      grep -i "#undef.*DISABLE_$pkg" $cpp_options > /dev/null 2>&1      return 0
     RETVAL=$?  
     if test "x${RETVAL}" = x0 ; then  
         echo "Error: In $cpp_options there is an illegal line: #undef DISABLE_$pkg"  
         exit 99  
    fi  
212  }  }
213    
214  # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to  # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to
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      PLATFORM=`echo $tmp2 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`        program hello
258      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`        write(*,*) 'hi'
259      echo "  The platform appears to be:  $PLATFORM"        stop
260  #     if test "x$OFLIST" = x ; then        end
261  #       echo "  No pre-defined options files were found matching this platform"  EOF
262  #       echo "  but examples for other platforms can be found in:"      cp genmake_hello.F "genmake_hello."$tfs > /dev/null 2>&1
 #       echo "    $ROOTDIR/tools/build_options"  
 #     else  
 #       echo "  Options files (located in $ROOTDIR/tools/build_options) that"  
 #       echo "  may work with this machine are:"  
 #       for i in $OFLIST ; do  
 #           echo "    $i"  
 #       done  
 #     fi  
       
     echo "test" > test  
     ln -s ./test link  
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                FS='for'
267                FS90='fr9'
268                check_for_broken_Ff
269            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
281        rm -f genmake_hello.*
282    
283        #  Check the ability of ${MAKE} and ${LN} to use the current set
284        #  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
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        #  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
366            test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
367            #  echo 'MAKEFILE="'$MAKEFILE'"'
368            cat <<EOF >> $MAKEFILE
369    #   THIS IS A TEST MAKEFILE GENERATED BY "genmake2"
370    #
371    #   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
417    }
418    
419    build_cyrus_makedepend()  {
420        echo >> $LOGFILE
421        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      else
441          echo "Error: \"ln -s\" does not appear to work on this system!"          echo "WARNING: fail to build cyrus-imapd-makedepend" >> $LOGFILE
442          echo "  For help, please contact <MITgcm-support@mitgcm.org>."          return 1
         exit 1  
443      fi      fi
444      rm -f test link  }
445    
446      if test "x$CPP" = x ; then  build_embed_encode()
447          CPP="cpp -traditional -P"  {
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      fi
474        echo "OK"
475    }
476    
477      # look for possible fortran compilers  #  look for possible C compilers
478      tmp="$MITGCM_FC $FC g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"  look_for_C_compilers() {
479      p_FC=      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 ./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 128  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 164  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        }
 #     # look for possible MPI libraries  
 #     mpi_libs=  
 #     mpi_fort=`which mpif77 2>/dev/null`  
 #     RETVAL=$?  
 #     if test "x${RETVAL}" = x0 ; then  
 #       cat >>test.f <<EOF  
 #       PROGRAM HELLO  
 #       DO 10, I=1,10  
 #       PRINT *,'Hello World'  
 #    10 CONTINUE  
 #       STOP  
 #       END  
 # EOF  
 #       eval "$mpi_fort -showme test.f > out"  
 #       RETVAL=$?  
 #       if test "x${RETVAL}" = x0 ; then  
 #           a=`cat out`  
 #           for i in $a ; do  
 #               case $i in  
 #                   -*)  
 #                       mpi_libs="$mpi_libs $i" ;;  
 #               esac  
 #           done  
 #           echo "The MPI libs appear to be:"  
 #           echo "  "$mpi_libs  
 #       fi  
 #       rm -f test.f out  
 #     fi  
612    
613    #  Do a local copy of MPI headers files (in local dir ./mpi_headers/) after
614    #  checking for additional included headers (in case of chain of included header)
615    mpi_headers_do_local_copy() {
616    
617        dBug=0
618        rm -rf ./mpi_headers
619        if test -d $MPIINCLUDEDIR ; then
620    
621            #----- check for additional headers (chain of included headers)
622            echo -n '  Check MPI headers ... '
623            listIni=$MPI_HEADER_FILES
624            echo $listIni | grep "\<mpif.h\>" > /dev/null 2>&1
625            outp=$?
626            #- always check mpif.h (the only mpi-header included in standard MITgcm code)
627            if test $outp != 0 ; then listIni="mpif.h $listIni" ; fi
628            if test $dBug = 1 ; then echo "listIni='$listIni'" ; fi
629    
630            doCheck=1 ; list2copy='' ; list2check=$listIni
631            while test $doCheck = 1 ; do
632              newList=''
633              for i in $list2check ; do
634                if test -f $MPIINCLUDEDIR/$i ; then
635                  newInc=`grep '^ *include ' $MPIINCLUDEDIR/$i | \
636                    sed -e 's/^ *include //' -e 's/\!.*$//' -e "s/'//g"  -e 's/\"//g'`
637                  if test $dBug = 1 ; then echo -n "checking $i : newInc='$newInc'" ; fi
638                  for j in $newInc ; do
639                    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 202  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      source ./.pd_tmp      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
702      rm -f ./.pd_tmp      rm -f ./.pd_tmp
703    }
704    
705    #  Build a CPP macro to automate calling C routines from FORTRAN
706    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 ## _"
715    
716        cat > genmake_test.c <<EOF
717    void tcall( char * string ) { tsub( string ); }
718    EOF
719        COMM="$CC $CFLAGS -c genmake_test.c"
720        echo ' '$COMM >> $LOGFILE
721        $COMM >> $LOGFILE 2>&1
722        RETVAL=$?
723        if test "x$RETVAL" != x0 ; then
724            FC_NAMEMANGLE=$default_nm
725            cat <<EOF>> $LOGFILE
726    
727     WARNING: C test compile fails
728     WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
729     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
730    EOF
731            return 1
732        fi
733        c_tcall=`nm genmake_test.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
734        RETVAL=$?
735        if test "x$RETVAL" != x0 ; then
736            FC_NAMEMANGLE=$default_nm
737            cat <<EOF>> $LOGFILE
738    
739     WARNING: The "nm" command failed.
740     WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
741     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
742    EOF
743            return 1
744        fi
745        cat > genmake_tcomp.$FS <<EOF
746          subroutine tcall( string )
747          character*(*) string
748          call tsub( string )
749          end
750    EOF
751        COMM="$FC $FFLAGS -c genmake_tcomp.$FS"
752        echo ' '$COMM >> $LOGFILE
753        $COMM >> $LOGFILE 2>&1
754        RETVAL=$?
755        if test "x$RETVAL" != x0 ; then
756            FC_NAMEMANGLE=$default_nm
757            cat <<EOF>> $LOGFILE
758    
759     WARNING: FORTRAN test compile fails -- please see '$LOGFILE'
760     WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
761     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
762    EOF
763            return 1
764        fi
765        f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
766        RETVAL=$?
767        if test "x$RETVAL" != x0 ; then
768            FC_NAMEMANGLE=$default_nm
769            cat <<EOF>> $LOGFILE
770    
771     WARNING: The "nm" command failed.
772     WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
773     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
774    EOF
775            return 1
776        fi
777    
778        c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
779        f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
780        c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
781        f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
782    
783      echo -n "PNAME = "${}      nmangle="X"
784        if test "x$c_a" != "x$f_a" ; then
785            comm="echo x$f_a | sed -e 's|x$c_a||'"
786            a=`eval $comm`
787            nmangle="$a ## $nmangle"
788        fi
789        if test "x$c_b" != "x$f_b" ; then
790            comm="echo x$f_b | sed -e 's|x$c_b||'"
791            b=`eval $comm`
792            nmangle="$nmangle ## $b"
793        fi
794    
795        FC_NAMEMANGLE="#define FC_NAMEMANGLE(X)  $nmangle"
796    
797        #  cleanup the testing files
798        rm -f genmake_tcomp.* genmake_test.*
799    
800        echo " --> set FC_NAMEMANGLE='$FC_NAMEMANGLE'" >> $LOGFILE
801  }  }
802    
803    check_HAVE_CLOC()  {
804        echo >> $LOGFILE
805        echo "running: check_HAVE_CLOC()" >> $LOGFILE
806        get_fortran_c_namemangling
807        cat <<EOF > genmake_tc_1.c
808    $FC_NAMEMANGLE
809    #include <stdio.h>
810    #include <stdlib.h>
811    #include <unistd.h>
812    #include <assert.h>
813    #include <sys/time.h>
814    void FC_NAMEMANGLE(cloc) ( double *curtim )
815    {
816     struct timeval tv1;
817     gettimeofday(&tv1 , (void *)NULL );
818     *curtim =  (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
819     *curtim = *curtim/1.E6;
820    }
821    EOF
822        COMM="$CC $CFLAGS -c genmake_tc_1.c"
823        echo $COMM >> $LOGFILE
824        $COMM >> $LOGFILE 2>&1
825        RET_C=$?
826        cat <<EOF > genmake_tc_2.$FS
827          program hello
828          REAL*8 wtime
829          external cloc
830          call cloc(wtime)
831          print *," HELLO WORLD", wtime
832          end
833    EOF
834        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=$?
838        test -x ./genmake_tc  &&  ./genmake_tc >> $LOGFILE 2>&1
839        RETVAL=$?
840        if test "x$RETVAL" = x0 ; then
841            HAVE_CLOC=t
842        fi
843        rm -f genmake_tc*
844        echo " --> set HAVE_CLOC='$HAVE_CLOC'" >> $LOGFILE
845    }
846    
847  #  Explain usage  check_HAVE_SIGREG()  {
848  usage()  {      if test ! "x$HAVE_SIGREG" = x ; then
849      echo          return
850      echo "Usage: "$0" [OPTIONS]"      fi
851      echo "  where [OPTIONS] can be:"      echo >> $LOGFILE
852      echo      echo "running: check_HAVE_SIGREG()" >> $LOGFILE
853      echo "    -help | --help | -h | --h"      get_fortran_c_namemangling
854      echo "    -nooptfile | --nooptfile"      cat <<EOF > genmake_tc_1.c
855      echo "      -optfile NAME | --optfile NAME | -of NAME | --of NAME"  $FC_NAMEMANGLE
856      echo "      -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME"  #include <stdlib.h>
857      echo "    -pdepend NAME | --pdepend NAME"  #include <stdio.h>
858      echo "      -pdepend=NAME | --pdepend=NAME"  #include <signal.h>
859      echo "    -pdefault NAME | --pdefault NAME"  #include <errno.h>
860      echo "      -pdefault=NAME | --pdefault=NAME"  #include <ucontext.h>
861      echo "    -make NAME | -m NAME"  
862      echo "      --make=NAME | -m=NAME"  int * ip;
863      echo "    -makefile NAME | -mf NAME"  
864      echo "      --makefile=NAME | -mf=NAME"  static void killhandler(
865      echo "    -platform NAME | --platform NAME | -pl NAME | --pl NAME"      unsigned int sn, siginfo_t  si, struct ucontext *sc )
866      echo "      -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"  {
867      echo "    -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"      *ip = *ip + 1;
868      echo "      -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME"      return;
869      echo "    -mods NAME | --mods NAME | -mo NAME | --mo NAME"  }
870      echo "      -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME"  
871      echo "    -disable NAME | --disable NAME"  void FC_NAMEMANGLE(sigreg) (int * aip)
872      echo "      -disable=NAME | --disable=NAME"  {
873      echo "    -enable NAME | --enable NAME"      struct sigaction s;
874      echo "      -enable=NAME | --enable=NAME"      ip = aip;
875      echo "    -standarddirs NAME | --standarddirs NAME"      s.sa_flags = SA_SIGINFO;
876      echo "      -standarddirs=NAME | --standarddirs=NAME"      s.sa_sigaction = (void *)killhandler;
877      echo "    -noopt NAME | --noopt NAME"      if(sigaction (SIGTERM,&s,(struct sigaction *)NULL)) {
878      echo "      -noopt=NAME | --noopt=NAME"          printf("Sigaction returned error = %d\n", errno);
879  #    echo "    -cpp NAME | --cpp NAME"          exit(0);
880  #    echo "      -cpp=NAME | --cpp=NAME"      }
881      echo "    -fortran NAME | --fortran NAME | -fc NAME | --fc NAME"      return;
882      echo "      -fc=NAME | --fc=NAME"  }
883      echo "    -[no]ieee | --[no]ieee"  EOF
884      echo "    -[no]mpi | --[no]mpi"      COMM="$CC $CFLAGS -c genmake_tc_1.c"
885      echo "    -[no]jam | --[no]jam"      echo $COMM >> $LOGFILE
886      echo      $COMM >> $LOGFILE 2>&1
887      echo "  and NAME is a string such as:"      RET_C=$?
888      echo      cat <<EOF > genmake_tc_2.$FS
889      echo "    --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'"        program hello
890      echo "    -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'"        integer anint
891      echo "    -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"        common /iv/ anint
892      echo        external sigreg
893      echo "  which, depending upon your shell, may need to be single-quoted"        call sigreg(anint)
894      echo "  if it contains spaces, dashes, or other special characters."        end
895      exit 1  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  #eh3 # This is the generic configuration.  check_lapack_libs()  {
1090  #eh3 set LN         = ( 'ln -s' )      if test "x$CHECK_FOR_LAPACK" = xf ; then return ; fi
1091  #eh3 set CPP        = ( '/lib/cpp -P' )      echo >> $LOGFILE
1092  #eh3 set S64        = ( '$(TOOLSDIR)/set64bitConst.sh' )      echo "running: check_lapack_libs()" >> $LOGFILE
1093  #eh3 set KPP        = (  )      cat <<EOF > genmake_tla.F
1094  #eh3 set FC         = ( 'f77' )        program fgenla
1095  #eh3 set LINK       = $FC        integer info
1096  #eh3 set MAKEDEPEND = ( 'makedepend' )        integer ipiv( 2 )
1097  #eh3 set INCLUDES   = ( -I. )        double precision ab( 4, 2 ), b( 2 )
1098  #eh3 set FFLAGS     = (  )        data ab / 0., 0., 1., 2., 0., 2., 1., 0. /
1099  #eh3 set FOPTIM     = (  )        data b / 1., 1. /
1100  #eh3 set CFLAGS     = (  )        call dgbsv( 2, 1, 1, 1, ab, 4, ipiv, b, 2, info )
1101  #eh3 set KFLAGS1    = (  )        IF (info .NE. 0) write(*,*) 'Error:', info
1102  #eh3 set KFLAGS2    = (  )        write(*,*) b
1103  #eh3 set LIBS       = (  )        end
1104  #eh3 set KPPFILES   = (  )  EOF
1105  #eh3 if (! $?NOOPTFILES ) set NOOPTFILES = (  )      echo "===  genmake_tla.F  >>>" > genmake_tla.log
1106  #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = (  )      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 288  PLATFORM= Line 1238  PLATFORM=
1238  LN=  LN=
1239  S64=  S64=
1240  KPP=  KPP=
1241  FC=  #FC=
1242    #CC=gcc
1243    #CPP=
1244  LINK=  LINK=
1245  DEFINES="-DWORDLENGTH=4"  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    # 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=
1291    HAVE_FDATE=
1292    FC_NAMEMANGLE=
1293    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=
1304  SOURCEDIRS=  SOURCEDIRS=
1305  INCLUDEDIRS=  INCLUDEDIRS=
1306  STANDARDDIRS=  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  AD_OPTFILE=  AD_OPTFILE=
1336    CAT_SRC_FOR_TAF=1
1337  TAF=  TAF=
1338  AD_TAF_FLAGS=  AD_TAF_FLAGS=
1339  FTL_TAF_FLAGS=  FTL_TAF_FLAGS=
# Line 346  FTL_TAF_FLAGS= Line 1345  FTL_TAF_FLAGS=
1345  SVD_TAMC_FLAGS=  SVD_TAMC_FLAGS=
1346  TAMC_EXTRA=  TAMC_EXTRA=
1347    
1348    DIVA=
1349    MPIINCLUDEDIR=
1350    MPI_HEADER_FILES=
1351    LOCAL_MPI_HEADERS=
1352    
1353  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
1354  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"  gm_s1="ROOTDIR STANDARDDIRS MODS PKG_DEPEND PKG_GROUPS DISABLE ENABLE"
1355  gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS"  gm_s2="PLATFORM OPTFILE MAKE MAKEFILE MAKEDEPEND FC CC MPI OMP USE_R4"
1356    gm_s3="FEXTRAFLAGS IEEE DEVEL GSL TS PAPIS PCLS PAPI PCL HPMT DUMPSTATE"
1357    
1358  #  The following state is not directly set by command-line switches  #  The following state is not directly set by command-line switches
1359  gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "  gm_s4="LN S64 LINK PACKAGES INCLUDES FFLAGS FOPTIM"
1360  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"  gm_s5="CFLAGS LIBS KPP KFLAGS1 KFLAGS2 KPPFILES NOOPTFILES NOOPTFLAGS"
1361  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"  gm_s6="PWD TOOLSDIR SOURCEDIRS INCLUDEDIRS EXEDIR EXECUTABLE EXEHOOK"
1362  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"  gm_s7="TMP THISHOST THISUSER THISDATE THISVER MACHINE FC_NAMEMANGLE"
1363    gm_s8="HAVE_NETCDF HAVE_SYSTEM HAVE_FDATE HAVE_ETIME HAVE_LAPACK HAVE_FLUSH"
1364    
1365  #  The following are all related to adjoint/tangent-linear stuff  #  The following are all related to adjoint/tangent-linear stuff
1366  gm_s7="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"
1367  gm_s8="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"  gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
1368  gm_s9="TAF_EXTRA TAMC_EXTRA"  gm_s12="TAF_EXTRA TAMC_EXTRA DIVA MPIINCLUDEDIR MPI_HEADER_FILES"
1369    
1370  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7 $gm_s8 $gm_s9"  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7 $gm_s8"
1371    gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
1372    
1373    cat <<EOF
1374    
1375    GENMAKE :
1376    
1377    A program for GENerating MAKEfiles for the MITgcm project.
1378       For a quick list of options, use "genmake2 -h"
1379    or for more detail see the Developer's HOWTO manual at:
1380       http://mitgcm.org/public/docs.html
1381    
1382    EOF
1383    
1384    LOGFILE="genmake.log"
1385    #- clean-up previous genmake logfiles:
1386    rm -f genmake_state genmake_*optfile $LOGFILE
1387    
 echo  
1388  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  
         source $i/$gm_local  
         break  
     fi  
 done  
 echo -n "  getting local config information:  "  
 if test -e $gm_local ; then  
     echo "using $gm_local"  
     source $gm_local  
     # echo "DISABLE=$DISABLE"  
     # echo "ENABLE=$ENABLE"  
 else  
     echo "none found"  
 fi  
1389    
1390  #  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  
1391  #parse_options  #parse_options
1392  ac_prev=  ac_prev=
1393  for ac_option ; do  for ac_option in "$@" ; do
1394    
1395        G2ARGS="$G2ARGS \"$ac_option\""
1396    
1397      # If the previous option needs an argument, assign it.      # If the previous option needs an argument, assign it.
1398      if test -n "$ac_prev"; then      if test -n "$ac_prev"; then
# Line 404  for ac_option ; do Line 1400  for ac_option ; do
1400          ac_prev=          ac_prev=
1401          continue          continue
1402      fi      fi
1403        
1404      ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`      ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
1405        
1406      case $ac_option in      case $ac_option in
1407            
1408          -help | --help | -h | --h)          -help | --help | -h | --h)
1409              usage ;;              usage ;;
1410            
1411          -nooptfile | --nooptfile)          -nooptfile | --nooptfile)
1412              OPTFILE="NONE" ;;              OPTFILE="NONE" ;;
1413          -optfile | --optfile | -of | --of)          -optfile | --optfile | -of | --of)
1414              ac_prev=OPTFILE ;;              ac_prev=OPTFILE ;;
1415          -optfile=* | --optfile=* | -of=* | --of=*)          -optfile=* | --optfile=* | -of=* | --of=*)
1416              OPTFILE=$ac_optarg ;;              OPTFILE=$ac_optarg ;;
1417            
1418          -adoptfile | --adoptfile | -ad | --ad)          -oad | --oad)
1419                OPENAD="true" ; ALWAYS_USE_F90=1 ;;
1420            -nocat4ad | -dog4ad | -ncad | -dad)
1421                CAT_SRC_FOR_TAF=0 ;;
1422            -adoptfile | --adoptfile | -adof | --adof)
1423              ac_prev=AD_OPTFILE ;;              ac_prev=AD_OPTFILE ;;
1424          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
1425              AD_OPTFILE=$ac_optarg ;;              AD_OPTFILE=$ac_optarg ;;
1426            
1427          -pdepend | --pdepend)          -pdepend | --pdepend)
1428              ac_prev=PDEPEND ;;              ac_prev=PKG_DEPEND ;;
1429          -pdepend=* | --pdepend=*)          -pdepend=* | --pdepend=*)
1430              PDEPEND=$ac_optarg ;;              PKG_DEPEND=$ac_optarg ;;
1431            
1432          -pdefault | --pdefault)          -pgroups | --pgroups)
1433              ac_prev=PDEFAULT ;;              ac_prev=PKG_GROUPS ;;
1434          -pdefault=* | --pdefault=*)          -pgroups=* | --pgroups=*)
1435              PDEFAULT=$ac_optarg ;;              PKG_GROUPS=$ac_optarg ;;
1436            
1437          -make | --make | -m | --m)          -make | --make | -m | --m)
1438              ac_prev=MAKE ;;              ac_prev=MAKE ;;
1439          -make=* | --make=* | -m=* | --m=*)          -make=* | --make=* | -m=* | --m=*)
1440              MAKE=$ac_optarg ;;              MAKE=$ac_optarg ;;
1441            
1442          -makefile | --makefile | -ma | --ma)          -bash | --bash)
1443                ac_prev=BASH ;;
1444            -bash=* | --bash=*)
1445                BASH=$ac_optarg ;;
1446    
1447            -makedepend | --makedepend | -md | --md)
1448                ac_prev=MAKEDEPEND ;;
1449            -makedepend=* | --makedepend=* | -md=* | --md=*)
1450                MAKEDEPEND=$ac_optarg ;;
1451    
1452            -makefile | --makefile | -mf | --mf)
1453              ac_prev=MAKEFILE ;;              ac_prev=MAKEFILE ;;
1454          -makefile=* | --makefile=* | -ma=* | --ma=*)          -makefile=* | --makefile=* | -mf=* | --mf=*)
1455              MAKEFILE=$ac_optarg ;;              MAKEFILE=$ac_optarg ;;
1456            
1457          -platform | --platform | -pl | --pl)          -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
1458              ac_prev=PLATFORM ;;              echo "ERROR: The platform option has been removed.  Please specify"
1459          -platform=* | --platform=* | -pl=* | --pl=*)              echo "  the build options using the \"optfile\" mechanism."
1460              PLATFORM=$ac_optarg ;;              echo
1461                        usage
1462                ;;
1463    
1464          -rootdir | --rootdir | -rd | --rd)          -rootdir | --rootdir | -rd | --rd)
1465              ac_prev=ROOTDIR ;;              ac_prev=ROOTDIR ;;
1466          -rootdir=* | --rootdir=* | -rd=* | --rd=*)          -rootdir=* | --rootdir=* | -rd=* | --rd=*)
1467              ROOTDIR=$ac_optarg ;;              ROOTDIR=$ac_optarg ;;
1468            
1469          -mods | --mods | -mo | --mo)          -mods | --mods | -mo | --mo)
1470              ac_prev=MODS ;;              ac_prev=MODS ;;
1471          -mods=* | --mods=* | -mo=* | --mo=*)          -mods=* | --mods=* | -mo=* | --mo=*)
1472              MODS=$ac_optarg ;;              MODS=$ac_optarg ;;
1473            
1474          -disable | --disable)          -disable | --disable)
1475              ac_prev=DISABLE ;;              ac_prev=DISABLE ;;
1476          -disable=* | --disable=*)          -disable=* | --disable=*)
1477              DISABLE=$ac_optarg ;;              DISABLE=$ac_optarg ;;
1478            
1479          -enable | --enable)          -enable | --enable)
1480              ac_prev=ENABLE ;;              ac_prev=ENABLE ;;
1481          -enable=* | --enable=*)          -enable=* | --enable=*)
1482              ENABLE=$ac_optarg ;;              ENABLE=$ac_optarg ;;
1483            
1484          -standarddirs | --standarddirs)          -standarddirs | --standarddirs)
1485              ac_prev=STANDARDDIRS ;;              ac_prev=STANDARDDIRS ;;
1486          -standarddirs=* | --standarddirs=*)          -standarddirs=* | --standarddirs=*)
1487              STANDARDDIRS=$ac_optarg ;;              STANDARDDIRS=$ac_optarg ;;
1488    
         -noopt | --noopt)  
             ac_prev=NOOPT ;;  
         -noopt=* | --noopt=*)  
             NOOPT=$ac_optarg ;;  
           
1489  #           -cpp | --cpp)  #           -cpp | --cpp)
1490  #               ac_prev=cpp ;;  #               ac_prev=cpp ;;
1491  #           -cpp=* | --cpp=*)  #           -cpp=* | --cpp=*)
1492  #               CPP=$ac_optarg ;;  #               CPP=$ac_optarg ;;
1493                
1494            -cc | --cc)
1495                ac_prev=CC ;;
1496            -cc=* | --cc=*)
1497                CC=$ac_optarg ;;
1498    
1499          -fortran | --fortran | -fc | --fc)          -fortran | --fortran | -fc | --fc)
1500              ac_prev=FC ;;              ac_prev=FC ;;
1501          -fc=* | --fc=*)          -fc=* | --fc=*)
1502              FC=$ac_optarg ;;              FC=$ac_optarg ;;
1503            
1504            -fs | --fs)
1505                ac_prev=FS ;;
1506            -fs=* | --fs=*)
1507                FS=$ac_optarg ;;
1508    
1509            -fs90 | --fs90)
1510                ac_prev=FS90 ;;
1511            -fs90=* | --fs90=*)
1512                FS90=$ac_optarg ;;
1513    
1514            -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4 )
1515                USE_R4=true ;;
1516    
1517          -ieee | --ieee)          -ieee | --ieee)
1518              IEEE=true ;;              IEEE=true ;;
1519          -noieee | --noieee)          -noieee | --noieee)
1520              IEEE= ;;              echo "Warning: ignore option '$ac_option' (default is already without '-ieee')" ;;
1521                    -devel | --devel)
1522                IEEE=true ; DEVEL=true ;;
1523            -gsl | --gsl)
1524                GSL=true ;;
1525    
1526            -ts | --ts)
1527                TS=true ;;
1528            -papis | --papis)
1529                PAPIS=true ;;
1530            -pcls | --pcls)
1531                PCLS=true ;;
1532            -foolad | --foolad)
1533                FOOLAD=true ;;
1534            -papi | --papi)
1535                PAPI=true ;;
1536            -pcl | --pcl)
1537                PCL=true ;;
1538            -hpmt | --hpmt)
1539                HPMT=true ;;
1540    
1541          -mpi | --mpi)          -mpi | --mpi)
1542              MPI=true ;;              MPI=true ;;
1543          -nompi | --nompi)          -mpi=* | --mpi=*)
1544              MPI= ;;              MPIPATH=$ac_optarg
1545                        MPI=true ;;
1546          -jam | --jam)  
1547              JAM=1 ;;          -omp | --omp)
1548          -nojam | --nojam)              OMP=true ;;
1549              JAM=0 ;;          -omp=* | --omp=*)
1550                        OMPFLAG=$ac_optarg
1551                OMP=true ;;
1552    
1553          -ds | --ds)          -ds | --ds)
1554              DUMPSTATE=t ;;              DUMPSTATE=t ;;
1555            
1556            -extra_flag | --extra_flag)
1557                ac_prev=FEXTRAFLAGS ;;
1558            -extra_flag=* | --extra_flag=*)
1559                FEXTRAFLAGS=$ac_optarg ;;
1560    
1561          -taf_extra | --taf_extra)          -taf_extra | --taf_extra)
1562              ac_prev=TAF_EXTRA ;;              ac_prev=TAF_EXTRA ;;
1563          -taf_extra=* | --taf_extra=*)          -taf_extra=* | --taf_extra=*)
# Line 517  for ac_option ; do Line 1568  for ac_option ; do
1568          -tamc_extra=* | --tamc_extra=*)          -tamc_extra=* | --tamc_extra=*)
1569              TAMC_EXTRA=$ac_optarg ;;              TAMC_EXTRA=$ac_optarg ;;
1570    
1571            -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1572                IGNORE_TIME="-DIGNORE_TIME" ;;
1573    
1574            -es | --es | -embed-source | --embed-source)
1575                EMBED_SRC=t ;;
1576    
1577          -*)          -*)
1578              echo "Error: unrecognized option: "$ac_option              echo "Error: unrecognized option: "$ac_option
1579              usage              usage
1580              ;;              ;;
1581            
1582          *)          *)
1583              echo "Error: unrecognized argument: "$ac_option              echo "Error: unrecognized argument: "$ac_option
1584              usage              usage
1585              ;;              ;;
1586            
1587      esac      esac
1588        
1589  done  done
1590    
1591    #TMP=./genmk_$$
1592    #- try to put temporary files in system-local /tmp dir
1593    TMP=/tmp/genmk_${USER}_$$
1594    touch $TMP ; retVal=$?
1595    if [ $retVal -eq 0 ] ; then
1596      if test ! -r $TMP ; then TMP=./genmk_$$ ; fi
1597    else
1598      TMP=./genmk_$$
1599    fi
1600    rm -f $TMP
1601    #echo "  temp files: $TMP.*"
1602    
1603    printf "  getting local config information:  "
1604    if test -f $gm_local ; then
1605        echo "using $gm_local"
1606        . $gm_local
1607    else
1608        echo "none found"
1609    fi
1610    
1611  if test -f ./.genmakerc ; then  if test -f ./.genmakerc ; then
1612      echo      echo
1613      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
1614      echo "  file.  This file format is no longer supported.  Please see:"      echo "  file.  This file format is no longer supported.  For directions on"
1615      echo      echo "  how to setup and use the new \"genmake2\" script, please see:"
1616      echo "    http://mitgcm.org/devel_HOWTO/"      echo "    http://mitgcm.org/public/devel_HOWTO/"
1617        echo "  and send an email to MITgcm-support@mitgcm.org if you need help."
1618        echo "WARNING: ignore \"./.genmakerc\" and continue."
1619      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  
1620  fi  fi
1621    
1622    #  Find the MITgcm ${ROOTDIR}
1623  if test "x${ROOTDIR}" = x ; then  if test "x${ROOTDIR}" = x ; then
1624      if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1625        if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesupp -a -d ../pkg ; then
1626          ROOTDIR=".."          ROOTDIR=".."
1627      else      else
1628          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1629              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
1630                  ROOTDIR=$d                  ROOTDIR=$d
1631                  echo -n "Warning:  ROOTDIR was not specified but there appears to be"                  printf "Warning: ROOTDIR was not specified ;"
1632                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."                  echo " try using a local copy of MITgcm found at \"$ROOTDIR\""
1633                  break                  break
1634              fi              fi
1635          done          done
# Line 568  if test ! -d ${ROOTDIR} ; then Line 1646  if test ! -d ${ROOTDIR} ; then
1646      exit 1      exit 1
1647  fi  fi
1648    
1649  echo "  getting OPTFILE information:  "  #  Find the MITgcm ${THISVER}
1650    version_file="${ROOTDIR}/doc/tag-index"
1651    if test -f $version_file ; then
1652        THISVER=`$AWK '/^checkpoint/{print $1; exit}' $version_file`
1653    #-  remove ./BUILD_INFO.h file if older than version_file
1654        if test -f ./BUILD_INFO.h -a ./BUILD_INFO.h -ot $version_file ; then
1655            echo "  remove ./BUILD_INFO.h (older than ${version_file})"
1656            rm -f ./BUILD_INFO.h
1657        fi
1658    fi
1659    
1660    if test "x$MAKEFILE" = x ; then
1661        MAKEFILE="Makefile"
1662    fi
1663    
1664    echo "  getting OPTFILE information:"
1665  if test "x${OPTFILE}" = x ; then  if test "x${OPTFILE}" = x ; then
1666      if test "x$MITGCM_OF" = x ; then      if test "x$MITGCM_OF" = x ; then
1667          echo "Warning: no OPTFILE specified so we'll look for possible settings"          echo "Warning: no OPTFILE specified so we'll look for possible settings"
1668          printf "\n===  Searching for possible settings for OPTFILE  ===\n"          printf "\n===  Searching for possible settings for OPTFILE  ===\n"
1669          find_possible_configs          find_possible_optfile
1670      else      else
1671          OPTFILE=$MITGCM_OF          OPTFILE=$MITGCM_OF
1672      fi      fi
# Line 581  fi Line 1674  fi
1674  if test "x$OPTFILE" != xNONE ; then  if test "x$OPTFILE" != xNONE ; then
1675      if test -f "$OPTFILE" -a -r "$OPTFILE" ; then      if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
1676          echo "    using OPTFILE=\"$OPTFILE\""          echo "    using OPTFILE=\"$OPTFILE\""
1677          source "$OPTFILE"          . "$OPTFILE"
1678          RETVAL=$?          RETVAL=$?
1679          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
1680              echo -n "Error: failed to source OPTFILE \"$OPTFILE\""              printf "Error: failed to source OPTFILE \"$OPTFILE\""
1681              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1682              exit 1              exit 1
1683          fi          fi
1684          if test "x$DUMPSTATE" != xf ; then          if test "x$DUMPSTATE" = xt ; then
1685              cp -f $OPTFILE "genmake_optfile"              cp -f $OPTFILE "genmake_optfile"
1686          fi          fi
1687      else      else
# Line 597  if test "x$OPTFILE" != xNONE ; then Line 1690  if test "x$OPTFILE" != xNONE ; then
1690      fi      fi
1691  fi  fi
1692    
1693  echo "  getting AD_OPTFILE information:  "  echo "  getting AD_OPTFILE information:"
1694  if test "x${AD_OPTFILE}" = x ; then  if test "x${AD_OPTFILE}" = x ; then
1695      if test "x$MITGCM_AD_OF" = x ; then      if test "x$MITGCM_AD_OF" != x ; then
1696            AD_OPTFILE=$MITGCM_AD_OF
1697        elif test "x$OPENAD" = x ; then
1698          AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default          AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
1699      else      else
1700          AD_OPTFILE=$MITGCM_AD_OF          AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_oad
1701      fi      fi
1702  fi  fi
1703  if test "x${AD_OPTFILE}" != xNONE ; then  if test "x${AD_OPTFILE}" != xNONE ; then
1704      if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then      if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
1705          echo "    using AD_OPTFILE=\"$AD_OPTFILE\""          echo "    using AD_OPTFILE=\"$AD_OPTFILE\""
1706          source "$AD_OPTFILE"          . "$AD_OPTFILE"
1707          RETVAL=$?          RETVAL=$?
1708          if test "x$RETVAL" != x0 ; then          if test "x$RETVAL" != x0 ; then
1709              echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""              printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
1710              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1711              exit 1              exit 1
1712          fi          fi
1713          if test "x$DUMPSTATE" != xf ; then          if test "x$DUMPSTATE" = xt ; then
1714              cp -f $AD_OPTFILE "genmake_ad_optfile"              cp -f $AD_OPTFILE "genmake_ad_optfile"
1715          fi          fi
1716      else      else
# Line 624  if test "x${AD_OPTFILE}" != xNONE ; then Line 1719  if test "x${AD_OPTFILE}" != xNONE ; then
1719      fi      fi
1720  fi  fi
1721    
1722  #  Check that FC, LINK, CPP, and S64 are defined.  If not, complain  #====================================================================
1723  #  and abort!  #  Set default values if not set by the optfile
1724    #
1725    #  Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
1726    #  either set defaults or complain and abort!
1727    if test ! "x$BASH" = x ; then
1728        # add a trailing space so that it works within the Makefile syntax (see below)
1729        BASH="$BASH "
1730    fi
1731  if test "x$FC" = x ; then  if test "x$FC" = x ; then
1732      cat <<EOF 1>&2      cat <<EOF 1>&2
1733    
# Line 636  Error: no Fortran compiler: please speci Line 1738  Error: no Fortran compiler: please speci
1738  EOF  EOF
1739      exit 1      exit 1
1740  fi  fi
1741    if test "x$GET_FC_VERSION" != x ; then
1742      echo "Get compiler version using: $FC $GET_FC_VERSION" >> $LOGFILE
1743      ff=`echo $FC | sed 's/ .*//'` ; xx=`echo $ff | sed 's/^./& /' | sed 's/ .*//'`
1744      if test $xx != '/' ; then which $ff >> $LOGFILE ; fi
1745      $FC $GET_FC_VERSION > genmake_fc_vers1 2> genmake_fc_vers2
1746      if test -s genmake_fc_vers1 ; then
1747        cat genmake_fc_vers1 >> $LOGFILE
1748      else
1749        cat genmake_fc_vers2 >> $LOGFILE
1750      fi
1751      echo "<-- compiler version ----" >> $LOGFILE
1752      rm -f genmake_fc_vers1 genmake_fc_vers2
1753    fi
1754    
1755    if test "x$CC" = x ; then
1756        look_for_C_compilers
1757    fi
1758    
1759  if test "x$LINK" = x ; then  if test "x$LINK" = x ; then
1760      LINK=$FC      LINK=$FC
1761  fi  fi
1762    if test "x$MAKE" = x ; then
1763        MAKE="make"
1764    fi
1765  if test "x$CPP" = x ; then  if test "x$CPP" = x ; then
1766      CPP="cpp"      CPP="cpp -traditional -P"
1767  fi  fi
1768    #EH3 === UGLY ===
1769    #  The following is an ugly little hack to check for $CPP in /lib/ and
1770    #  it should eventually be replaced with a more general function that
1771    #  searches a combo of the user's path and a list of "usual suspects"
1772    #  to find the correct location for binaries such as $CPP.
1773    for i in " " "/lib/" ; do
1774        echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1775    done
1776    #EH3 === UGLY ===
1777  echo "#define A a" | $CPP > test_cpp 2>&1  echo "#define A a" | $CPP > test_cpp 2>&1
1778  RETVAL=$?  RETVAL=$?
1779  if test "x$RETVAL" != x0 ; then  if test "x$RETVAL" != x0 ; then
# Line 651  Error: C pre-processor "$CPP" failed the Line 1783  Error: C pre-processor "$CPP" failed the
1783    
1784    1) within the options file ("CPP=...") as specified by "-of=OPTFILE"    1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
1785    2) the "./genmake_local" file    2) the "./genmake_local" file
1786      3) with the CPP environment variable
1787    
1788  EOF  EOF
1789      exit 1      exit 1
1790  else  else
1791      rm -f test_cpp      rm -f test_cpp
1792  fi  fi
1793  if test "x$MAKEDEPEND" = x ; then  
1794      MAKEDEPEND=makedepend  look_for_makedepend
1795    
1796    #  Check that soft-link command is set and usable
1797    if test "x$LN" = x ; then
1798        LN="ln -s"
1799    fi
1800    echo "test" > genmake_test_ln
1801    $LN genmake_test_ln genmake_tlink
1802    RETVAL=$?
1803    if test "x$RETVAL" != x0 ; then
1804        cat <<EOF 1>&2
1805    
1806    Error: The command "$LN" failed -- please specify a working soft-link
1807      command in the optfile.
1808    
1809    EOF
1810        exit 1
1811    fi
1812    test -L genmake_tlink > /dev/null 2>&1
1813    RETVAL=$?
1814    if test "x$RETVAL" = x0 ; then
1815        HAVE_TEST_L=t
1816    fi
1817    rm -f genmake_test_ln genmake_tlink
1818    
1819    #  Check for broken *.F/*.f handling and fix if possible
1820    check_for_broken_Ff
1821    
1822    if test ! "x$MPI" = x ; then
1823          echo "  Turning on MPI cpp macros"
1824          DEFINES="$DEFINES -DALLOW_USE_MPI"
1825    #- To compile code older than checkpoint63s (2012/09/05), un-comment the following line:
1826    #     DEFINES="$DEFINES -DALWAYS_USE_MPI"
1827    fi
1828    if test ! "x$OMP" = x ; then
1829          echo "  Add OMPFLAG and turn on OpenMP cpp macros"
1830          FFLAGS="$FFLAGS $OMPFLAG"
1831          F90FLAGS="$F90FLAGS $OMPFLAG"
1832          DEFINES="$DEFINES -DUSE_OMP_THREADING"
1833    fi
1834    
1835    if test ! "x$USE_R4" = x ; then
1836          echo "  Turning on LET_RS_BE_REAL4 cpp flag"
1837          DEFINES="$DEFINES -DLET_RS_BE_REAL4"
1838    fi
1839    
1840    if test ! "x$TS" = x ; then
1841          echo "  Turning on timing per timestep"
1842          if test ! "x$FOOLAD" = x ; then
1843                DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP"
1844          else
1845                DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1846          fi
1847          PACKAGES="$PACKAGES showflops"
1848    fi
1849    if test ! "x$PAPIS" = x ; then
1850          echo "  Turning on PAPI flop summary per timestep"
1851          echo "  Please make sure PAPIINC, PAPILIB are defined"
1852          if test ! "x$FOOLAD" = x ; then
1853                DEFINES="$DEFINES -DUSE_PAPI_FLOPS_SFP"
1854          else
1855                DEFINES="$DEFINES -DUSE_PAPI_FLOPS"
1856          fi
1857          INCLUDES="$INCLUDES $PAPIINC"
1858          LIBS="$LIBS $PAPILIB"
1859          PACKAGES="$PACKAGES showflops"
1860    fi
1861    if test ! "x$PCLS" = x ; then
1862          echo "  Turning on PCL counter summary per timestep"
1863          echo "  Please make sure PCLINC, PCLLIB are defined"
1864          if test ! "x$FOOLAD" = x ; then
1865                DEFINES="$DEFINES -DUSE_PCL_FLOPS_SFP"
1866          else
1867                DEFINES="$DEFINES -DUSE_PCL_FLOPS"
1868          fi
1869          INCLUDES="$INCLUDES $PCLINC"
1870          LIBS="$LIBS $PCLLIB"
1871          PACKAGES="$PACKAGES showflops"
1872    fi
1873    if test ! "x$PAPI" = x ; then
1874          if test ! "x$PAPIS" = x ; then
1875              echo "  PAPI performance analysis and flop summary per timestep cannot co-exist!"
1876              echo "  Sticking with PAPI flop summary per timestep!"
1877          else
1878              echo "  Turning on performance analysis with PAPI"
1879              echo "  Please make sure PAPIINC, PAPILIB are defined"
1880              DEFINES="$DEFINES -DUSE_PAPI"
1881              INCLUDES="$INCLUDES $PAPIINC"
1882              LIBS="$LIBS $PAPILIB"
1883          fi
1884    fi
1885    if test ! "x$PCL" = x ; then
1886          if test ! "x$PCLS" = x ; then
1887              echo "  PCL performance analysis and flop summary per timestep cannot co-exist!"
1888              echo "  Sticking with PCL flop summary per timestep!"
1889          else
1890              echo "  Turning on performance analysis with PCL"
1891              echo "  Please make sure PCLINC, PCLLIB are defined"
1892              DEFINES="$DEFINES -DUSE_PCL"
1893              INCLUDES="$INCLUDES $PCLINC"
1894              LIBS="$LIBS $PCLLIB"
1895          fi
1896    fi
1897    if test ! "x$HPMT" = x ; then
1898          if test ! "x$PAPI" = x ; then
1899              echo "  PAPI and the HPM Toolkit cannot co-exist!"
1900              echo "  Sticking with PAPI!"
1901          else
1902            if test ! "x$PCL" = x ; then
1903              echo "  PCL and the HPM Toolkit cannot co-exist!"
1904              echo "  Sticking with PCL!"
1905            else
1906              echo "  Turning on performance analysis with the HPM Toolkit"
1907              echo "  Please make sure HPMTINC, HPMTLIB are defined"
1908              DEFINES="$DEFINES -DUSE_LIBHPM"
1909              INCLUDES="$INCLUDES $HPMTINC"
1910              LIBS="$LIBS $HPMTLIB"
1911            fi
1912          fi
1913    fi
1914    if test ! "x$GSL" = x ; then
1915          echo "  Turning on use of GSL to control floating point calculations"
1916          echo "  Please make sure GSLINC, GSLLIB are defined"
1917          DEFINES="$DEFINES -DUSE_GSL_IEEE"
1918          INCLUDES="$INCLUDES $GSLINC"
1919          LIBS="$LIBS $GSLLIB"
1920    fi
1921    #- if USE_EXTENDED_SRC is set, add EXTENDED_SRC_FLAG to FFLAGS :
1922    if test ! "x$USE_EXTENDED_SRC" = x ; then
1923          FFLAGS="$FFLAGS $EXTENDED_SRC_FLAG"
1924          F90FIXEDFORMAT="$F90FIXEDFORMAT $EXTENDED_SRC_FLAG"
1925    fi
1926    
1927    printf "\n===  Checking system libraries  ===\n"
1928    printf "  Do we have the system() command using $FC...  "
1929    cat > genmake_tcomp.$FS <<EOF
1930          program hello
1931          call system('echo hi')
1932          end
1933    EOF
1934    $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1935    RETVAL=$?
1936    if test "x$RETVAL" = x0 ; then
1937        HAVE_SYSTEM=t
1938        DEFINES="$DEFINES -DHAVE_SYSTEM"
1939        echo "yes"
1940    else
1941        HAVE_SYSTEM=
1942        echo "no"
1943    fi
1944    rm -f genmake_tcomp*
1945    
1946    printf "  Do we have the fdate() command using $FC...  "
1947    cat > genmake_tcomp.$FS <<EOF
1948          program hello
1949          CHARACTER*(128) string
1950          string = ' '
1951          call fdate( string )
1952          print *, string
1953          end
1954    EOF
1955    $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1956    RETVAL=$?
1957    if test "x$RETVAL" = x0 ; then
1958        HAVE_FDATE=t
1959        DEFINES="$DEFINES -DHAVE_FDATE"
1960        echo "yes"
1961    else
1962        HAVE_FDATE=
1963        echo "no"
1964    fi
1965    rm -f genmake_tcomp*
1966    
1967    printf "  Do we have the etime() command using $FC... "
1968    cat > genmake_tcomp.$FS <<EOF
1969          program hello
1970          REAL*4 actual, tarray(2)
1971          actual = -999.
1972          call ETIME( tarray, actual )
1973          if ( actual.ge.0. ) then
1974            print *, 0, tarray, actual
1975          else
1976            print *, 1, tarray, actual
1977          endif
1978          end
1979    EOF
1980    $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1981    RETVAL=$?
1982    if test "x$RETVAL" = x0 ; then
1983        echo -n 'c,'
1984        ./genmake_tcomp > genmake_tcomp.out 2>&1
1985        RETVAL=$?
1986    fi
1987    if test "x$RETVAL" = x0 ; then
1988        echo -n 'r:'
1989        RETVAL=`cat genmake_tcomp.out | $AWK '{print $1}'`
1990    fi
1991    if test "x$RETVAL" = x0 ; then
1992        HAVE_ETIME=t
1993        DEFINES="$DEFINES -DHAVE_ETIME"
1994        echo " yes"
1995    else
1996        HAVE_ETIME=
1997        echo " no"
1998    fi
1999    #mkdir chk_etime ; cp -p -f genmake_tcomp* chk_etime
2000    rm -f genmake_tcomp*
2001    
2002    printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
2003    check_HAVE_CLOC
2004    if test "x$HAVE_CLOC" != x ; then
2005        DEFINES="$DEFINES -DHAVE_CLOC"
2006        echo "yes"
2007    else
2008        echo "no"
2009        if test "x$EMBED_SRC" = xt ; then
2010            echo "    WARNING: you requested file embedding but it has"
2011            echo "      been disabled since C code cannot be called"
2012            EMBED_SRC=
2013        fi
2014    fi
2015    rm -f genmake_t*
2016    
2017    printf "  Can we unlimit the stack size using $FC...  "
2018    check_HAVE_SETRLSTK
2019    if test "x$HAVE_SETRLSTK" = xt ; then
2020        DEFINES="$DEFINES -DHAVE_SETRLSTK"
2021        echo "yes"
2022    else
2023        echo "no"
2024    fi
2025    rm -f genmake_t*
2026    
2027    printf "  Can we register a signal handler using $FC...  "
2028    check_HAVE_SIGREG
2029    if test "x$HAVE_SIGREG" = xt ; then
2030        DEFINES="$DEFINES -DHAVE_SIGREG"
2031        echo "yes"
2032    else
2033        echo "no"
2034    fi
2035    rm -f genmake_t*
2036    
2037    printf "  Can we use stat() through C calls...  "
2038    check_HAVE_STAT
2039    if test "x$HAVE_STAT" != x ; then
2040        DEFINES="$DEFINES -DHAVE_STAT"
2041        echo "yes"
2042    else
2043        echo "no"
2044    fi
2045    rm -f genmake_t*
2046    
2047    printf "  Can we create NetCDF-enabled binaries...  "
2048    check_netcdf_libs
2049    if test "x$HAVE_NETCDF" != x ; then
2050        DEFINES="$DEFINES -DHAVE_NETCDF"
2051        echo "yes"
2052    else
2053        echo "no"
2054    fi
2055    
2056    printf "  Can we create LAPACK-enabled binaries...  "
2057    check_lapack_libs
2058    if test "x$HAVE_LAPACK" != x ; then
2059        DEFINES="$DEFINES -DHAVE_LAPACK"
2060        echo "yes"
2061    else
2062        echo "no"
2063    fi
2064    
2065    printf "  Can we call FLUSH intrinsic subroutine...  "
2066    check_HAVE_FLUSH
2067    if test "x$HAVE_FLUSH" = xt ; then
2068        DEFINES="$DEFINES -DHAVE_FLUSH"
2069        echo "yes"
2070    else
2071        echo "no"
2072    fi
2073    
2074    DEFINES="$DEFINES $IGNORE_TIME"
2075    if test "x$EMBED_SRC" = xt ; then
2076        build_embed_encode
2077    fi
2078    if test "x$EMBED_SRC" = xt ; then
2079        ENABLE="$ENABLE embed_files"
2080    #   DEFINES="$DEFINES -DHAVE_EMBED_SRC"
2081  fi  fi
2082    
2083  printf "\n===  Setting defaults  ===\n"  printf "\n===  Setting defaults  ===\n"
2084  echo -n "  Adding MODS directories:  "  printf "  Adding MODS directories: "
2085  for d in $MODS ; do  for d in $MODS ; do
2086      if test ! -d $d ; then      if test ! -d $d ; then
2087          echo          echo
2088          echo "Error: MODS directory \"$d\" not found!"          echo "Error: MODS directory \"$d\" not found!"
2089          exit 1          exit 1
2090      else      else
2091          echo -n " $d"          printf "$d "
2092          SOURCEDIRS="$SOURCEDIRS $d"          SOURCEDIRS="$SOURCEDIRS $d"
2093          INCLUDEDIRS="$INCLUDEDIRS $d"          INCLUDEDIRS="$INCLUDEDIRS $d"
2094      fi      fi
2095  done  done
2096  echo  echo
2097    
2098  if test "x$MAKEFILE" = x ; then  #if test "x${PLATFORM}" = x ; then
2099      MAKEFILE="Makefile"  #    PLATFORM=$p_PLATFORM
2100  fi  #fi
 if test "x${PLATFORM}" = x ; then  
     PLATFORM=$p_PLATFORM  
 fi  
2101    
2102  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
2103      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
2104        if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
2105          EXEDIR=../exe          EXEDIR=../exe
2106      else      else
2107          EXEDIR=.          EXEDIR=.
# Line 699  if test "x${TOOLSDIR}" = x ; then Line 2116  if test "x${TOOLSDIR}" = x ; then
2116      TOOLSDIR="$ROOTDIR/tools"      TOOLSDIR="$ROOTDIR/tools"
2117  fi  fi
2118  if test ! -d ${TOOLSDIR} ; then  if test ! -d ${TOOLSDIR} ; then
2119      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
2120      exit 1      exit 1
2121  fi  fi
2122  if test "x$S64" = x ; then  if test "x$S64" = x ; then
2123      S64='$(TOOLSDIR)/set64bitConst.sh'      echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1
2124        RETVAL=$?
2125        if test "x${RETVAL}" = x0 ; then
2126            S64='$(TOOLSDIR)/set64bitConst.sh'
2127        else
2128            echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1
2129            RETVAL=$?
2130            if test "x${RETVAL}" = x0 ; then
2131                S64='$(TOOLSDIR)/set64bitConst.csh'
2132            else
2133                cat <<EOF
2134    
2135    ERROR: neither of the two default scripts:
2136    
2137        ${TOOLSDIR}/set64bitConst.sh
2138        ${TOOLSDIR}/set64bitConst.csh
2139    
2140      are working so please check paths or specify (with \$S64) a
2141      working version of this script.
2142    
2143    EOF
2144                exit 1
2145            fi
2146        fi
2147  fi  fi
2148    THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
2149    
2150  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
2151    
2152    #  Set Standard Code Directories:
2153    if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
2154        STANDARDDIRS="eesupp model"
2155    fi
2156    #  if model in Standard-Code-Dir, add eesupp (needed to compile model)
2157    echo " $STANDARDDIRS " | grep ' model ' > /dev/null 2>&1
2158    ckM=$?
2159    echo " $STANDARDDIRS " | grep ' eesupp ' > /dev/null 2>&1
2160    ckE=$?
2161    if test $ckM = 0 -a $ckE = 1 ; then
2162        STANDARDDIRS="$STANDARDDIRS eesupp"
2163    fi
2164    
2165  #  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
2166  #  generated from some template source files. We'll make them first so  #  generated from some template source files. We'll make them first so
2167  #  they appear as regular source code  #  they appear as regular source code
2168  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
2169      echo "  Making source files in eesupp from templates"      echo "  Making source files in eesupp from templates"
2170      $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1      ( cd $ROOTDIR"/eesupp/src/" && $MAKE clean_old && $MAKE \
2171        ) > make_eesupp.errors 2>&1
2172      RETVAL=$?      RETVAL=$?
2173      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
2174          rm -f make_eesupp.errors          rm -f make_eesupp.errors
2175      else      else
2176          echo "Error: problem encountered while building source files in eesupp:"          echo "Error: problem encountered while building source files in eesupp:"
2177          cat make_eesupp.errors          cat make_eesupp.errors 1>&2
2178          exit 1          exit 1
2179      fi      fi
2180  fi  fi
2181    
2182    #same for pkg/exch2 and pkg/regrid
2183    for pdir in exch2 regrid ; do
2184        if test -r $ROOTDIR"/pkg/${pdir}/Makefile" ; then
2185            echo "  Making source files in pkg/${pdir} from templates"
2186            ( cd $ROOTDIR"/pkg/"${pdir} && $MAKE clean_old && $MAKE \
2187            ) > make_${pdir}.errors 2>&1
2188            RETVAL=$?
2189            if test "x${RETVAL}" = x0 ; then
2190                rm -f make_${pdir}.errors
2191            else
2192                echo "Error: problem encountered while building source files in pkg/${pdir}:"
2193                cat make_${pdir}.errors 1>&2
2194                exit 1
2195            fi
2196        fi
2197    done
2198    
2199  printf "\n===  Determining package settings  ===\n"  printf "\n===  Determining package settings  ===\n"
2200  if  test "x${PDEPEND}" = x ; then  if  test "x${PKG_DEPEND}" = x ; then
2201      tmp=$ROOTDIR"/pkg/pkg_depend"      tmp=$ROOTDIR"/pkg/pkg_depend"
2202      if test -r $tmp ; then      if test -r $tmp ; then PKG_DEPEND=$tmp ; fi
2203          PDEPEND=$tmp  fi
2204      else  if  test "x${PKG_DEPEND}" = x ; then
2205          echo "Warning:  No package dependency information was specified."          echo "Warning:  No package dependency information was specified."
2206          echo "  Please check that ROOTDIR/pkg/pkg_depend exists."          echo "  Please check that ROOTDIR/pkg/pkg_depend exists."
     fi  
2207  else  else
2208      if test ! -r ${PDEPEND} ; then      if test ! -r ${PKG_DEPEND} ; then
2209          echo "Error:  can't read package dependency info from PDEPEND=\"$PDEPEND\""          echo "Error:  can't read package dependency info from PKG_DEPEND=\"$PKG_DEPEND\""
2210          exit 1          exit 1
2211      fi      fi
2212        echo "  getting package dependency info from  $PKG_DEPEND"
2213    #  Strip the comments and then convert the dependency file into arrays: PNAME, DNAME
2214        get_pdepend_list $PKG_DEPEND
2215  fi  fi
2216  echo "  getting package dependency info from  $PDEPEND"  
2217  #  Strip the comments and then convert the dependency file into  # A default package groups file "$ROOTDIR/pkg/pkg_groups" is provided
2218  #  two arrays: PNAME, DNAME  #  to define the "default_pkg_list" and package groups (for convenience, one
2219  cat $PDEPEND | sed -e 's/#.*$//g' \  #  can specify a group of packages using names like "ocean" and "atmosphere").
2220      | $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
2221      > ./.pd_tmp      tmp=$ROOTDIR"/pkg/pkg_groups"
2222  RETVAL=$?      if test -r $tmp ; then PKG_GROUPS=$tmp ; fi
2223  if test ! "x${RETVAL}" = x0 ; then  fi
2224      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""  if test "x${PKG_GROUPS}" = x ; then
2225      exit 1          echo "Warning:  No package groups information was specified."
2226            echo "  Please check that ROOTDIR/pkg/pkg_groups exists."
2227    else
2228        if test ! -r ${PKG_GROUPS} ; then
2229            echo "Error:  can't read package groups info from PKG_GROUPS=\"$PKG_GROUPS\""
2230            exit 1
2231        fi
2232        echo "  getting package groups info from      $PKG_GROUPS"
2233  fi  fi
 source ./.pd_tmp  
 rm -f ./.pd_tmp  
2234    
2235  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"  #  Search for packages to compile.
2236  #  file should eventually be added so that, for convenience, one can  echo "  checking list of packages to compile:"
2237  #  specify groups of packages using names like "ocean" and "atmosphere".  PKG_LIST=
2238  echo  -n "  checking default package list:  "  if test "x${PKG_LIST}" = x ; then
 if test "x${PDEFAULT}" = x ; then  
2239      for i in "." $MODS ; do      for i in "." $MODS ; do
2240          if test -r $i"/packages.conf" ; then          if test -r $i"/packages.conf" ; then
2241                  PDEFAULT=$i"/packages.conf"                  PKG_LIST=$i"/packages.conf"
2242                  break                  break
2243          fi          fi
2244      done      done
2245  fi  fi
2246  if test "x${PDEFAULT}" = x ; then  if test "x${PKG_LIST}" = x ; then
2247      PDEFAULT="$ROOTDIR/pkg/pkg_default"      pkg_list='default_pkg_list'
2248  fi      if test "x${PKG_GROUPS}" = x ; then
2249  if test "x${PDEFAULT}" = xNONE ; then          echo "Error:  need package groups info to expand pkg_list=\"$pkg_list\""
2250      echo "default packages file disabled"          exit 1
2251        fi
2252  else  else
2253      if test ! -r $PDEFAULT ; then      if test ! -r $PKG_LIST ; then
2254          echo ""          echo "Error:  can't read package list from PKG_LIST=\"$PKG_LIST\""
2255          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""          exit 1
2256      else      else
2257          echo "  using PDEFAULT=\"$PDEFAULT\""          echo "    using PKG_LIST=\"$PKG_LIST\""
2258          #  Strip the comments and add all the names          #  Strip the comments and add all the names
2259          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}'`
2260          RETVAL=$?          RETVAL=$?
2261          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
2262              echo -n "Error: can't parse default package list "              printf "Error: can't parse package list "
2263              echo "-- please check PDEFAULT=\"$PDEFAULT\""              echo "-- please check PKG_LIST=\"$PKG_LIST\""
2264              exit 1              exit 1
2265          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"  
2266      fi      fi
2267  fi  fi
2268    for i in $pkg_list ; do
2269        PACKAGES="$PACKAGES $i"
2270    done
2271    echo     "    before group expansion packages are:$PACKAGES"
2272    if test "x${PKG_GROUPS}" != x ; then
2273        RET=1
2274        while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
2275        echo "    after group expansion packages are: $PACKAGES"
2276    fi
2277    
2278  echo "  applying DISABLE settings"  echo "  applying DISABLE settings"
2279    echo "" > $TMP.pack
2280    for i in $PACKAGES ; do
2281        echo $i >> $TMP.pack
2282    done
2283    for i in `grep  "-" $TMP.pack` ; do
2284        j=`echo $i | sed 's/[-]//'`
2285        DISABLE="$DISABLE $j"
2286    done
2287  pack=  pack=
2288  for p in $PACKAGES ; do  for p in $PACKAGES ; do
2289      addit="t"      addit="t"
# Line 805  for p in $PACKAGES ; do Line 2295  for p in $PACKAGES ; do
2295      if test "x$addit" = xt ; then      if test "x$addit" = xt ; then
2296          pack="$pack $p"          pack="$pack $p"
2297      fi      fi
2298  done  done
2299  PACKAGES="$pack"  PACKAGES="$pack"
2300  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
2301  echo "" > ./.tmp_pack  echo "" > $TMP.pack
2302  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
2303  for i in $PACKAGES ; do  # Test if each explicitly referenced package exists
2304      if test ! -d "$ROOTDIR/pkg/$i" ; then  for i in $PACKAGES ; do
2305          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""      j=`echo $i | sed 's/[-+]//'`
2306          exit 1      if test ! -d "$ROOTDIR/pkg/$j" ; then
2307            echo "Error: dir '$ROOTDIR/pkg/$i' missing for package '$i'"
2308            exit 1
2309        fi
2310        echo $i >> $TMP.pack
2311    done
2312    PACKAGES=
2313    for i in `grep -v "-" $TMP.pack | sort | uniq` ; do
2314        PACKAGES="$PACKAGES $i"
2315    done
2316    rm -f $TMP.pack
2317    echo "    packages are: $PACKAGES"
2318    
2319    #  Check for package MNC: if NetCDF is available, then build the MNC
2320    #  template files ; otherwise, delete mnc from the list of packages.
2321    echo " $PACKAGES " | grep ' mnc ' > /dev/null 2>&1
2322    mnc_in=$?
2323    if test "x$HAVE_NETCDF" != xt ; then
2324        if test "x$mnc_in" = x0 ; then
2325            cat <<EOF
2326    *********************************************************************
2327    WARNING: the "mnc" package was enabled but tests failed to compile
2328      NetCDF applications.  Please check that:
2329    
2330      1) NetCDF is correctly installed for this compiler and
2331      2) the LIBS variable (within the "optfile") specifies the correct
2332           NetCDF library to link against.
2333    
2334      Due to this failure, the "mnc" package is now DISABLED.
2335    *********************************************************************
2336    EOF
2337            PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
2338            DISABLE="$DISABLE mnc"
2339        else
2340        #  this prevent to add mnc (due to pdepend rules) if not available
2341            DISABLE="$DISABLE mnc"
2342        fi
2343    else
2344        # we have NetCDF, we try to build MNC template files
2345        ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
2346        RETVAL=$?
2347        if test "x${RETVAL}" = x0 ; then
2348            rm -f make_mnc.errors
2349        else
2350            echo "Error: problem encountered while building source files in pkg/mnc:"
2351            cat make_mnc.errors 1>&2
2352            if test "x$mnc_in" = x0 ; then
2353                exit 1
2354            else
2355                DISABLE="$DISABLE mnc"
2356            fi
2357        fi
2358    fi
2359    
2360    #  Check for package PROFILES: if NetCDF is not available,
2361    #  then delete profiles from the list of available packages.
2362    if test "x$HAVE_NETCDF" != xt ; then
2363        echo " $PACKAGES " | grep ' profiles ' > /dev/null 2>&1
2364        RETVAL=$?
2365        if test "x$RETVAL" = x0 ; then
2366            cat <<EOF
2367    *********************************************************************
2368    WARNING: the "profiles" package was enabled but tests failed to
2369      compile NetCDF applications.  Please check that:
2370    
2371      1) NetCDF is correctly installed for this compiler and
2372      2) the LIBS variable (within the "optfile") specifies the correct
2373           NetCDF library to link against.
2374    
2375      Due to this failure, the "profiles" package is now DISABLED.
2376    *********************************************************************
2377    EOF
2378            PACKAGES=`echo $PACKAGES | sed -e 's/profiles//g'`
2379            DISABLE="$DISABLE profiles"
2380        else
2381        #  this prevent to add profiles (due to pdepend rules) if not available
2382            DISABLE="$DISABLE profiles"
2383        fi
2384    fi
2385    
2386    #  Make sure the openad package is enabled if using OpenAD
2387    if test "x$OPENAD" != x ; then
2388        echo " $PACKAGES " | grep ' openad ' > /dev/null 2>&1
2389        RETVAL=$?
2390        if test "x$RETVAL" != x0 ; then
2391            cat <<EOF
2392    
2393    *********************************************************************
2394    ERROR: when generating an adjoint with OpenAD, the openad package
2395      must be enabled.  Please add it to packages.conf.
2396    *********************************************************************
2397    
2398    EOF
2399            exit 1
2400      fi      fi
2401      echo $i >> ./.tmp_pack  fi
 done  
 pack=`cat ./.tmp_pack | sort | uniq`  
 rm -f ./.tmp_pack  
 PACKAGES=  
 for i in $pack ; do  
     PACKAGES="$PACKAGES $i"  
 done  
 echo "    packages are:  $PACKAGES"  
2402    
2403  echo "  applying package dependency rules"  if  test "x${PKG_DEPEND}" != x ; then
2404  ck=    echo "  applying package dependency rules"
2405  while test "x$ck" != xtt ; do    ck=
2406      while test "x$ck" != xtt ; do
2407      i=0      i=0
2408      # rtot=${#PNAME[@]}      # rtot=${#PNAME[@]}
2409      rtot=$nname      rtot=$nname
2410      while test $i -lt $rtot ; do      while test $i -le $rtot ; do
2411    
2412          #  Is $pname in the current $PACKAGES list?          #  Is $pname in the current $PACKAGES list?
2413          #  pname=${PNAME[$i]}          #  pname=${PNAME[$i]}
# Line 843  while test "x$ck" != xtt ; do Line 2419  while test "x$ck" != xtt ; do
2419                  pin="t"                  pin="t"
2420              fi              fi
2421          done          done
2422            #  or in the current $STANDARDDIRS list?
2423            for p in $STANDARDDIRS ; do
2424                if test "x$p" = "x$pname" ; then pin="t" ; fi
2425            done
2426    
2427          #  Is the DNAME entry a (+) or (-) rule ?          #  Is the DNAME entry a (+) or (-) rule ?
2428          tmp="dname=\"\$DNAME_$i\""          tmp="dname=\"\$DNAME_$i\""
# Line 865  while test "x$ck" != xtt ; do Line 2445  while test "x$ck" != xtt ; do
2445    
2446          #  Do we need to add $dname according to the dependency rules?          #  Do we need to add $dname according to the dependency rules?
2447          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
2448                #echo "   " $pname ": need to add :" $dname
2449              in_dis="f"              in_dis="f"
2450              for dis in $DISABLE ; do              for dis in $DISABLE ; do
2451                  if test "x$dis" = "x$dname" ; then                  if test "x$dis" = "x$dname" ; then
# Line 885  while test "x$ck" != xtt ; do Line 2466  while test "x$ck" != xtt ; do
2466          #  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?
2467          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
2468              echo "Error: can't satisfy package dependencies:"              echo "Error: can't satisfy package dependencies:"
2469              echo "  \"$pname\" was requested but is disallowed by"              echo "  \"$pname\" was requested but is disallowed by"
2470              echo "  the dependency rules for \"$dname\""              echo "  the dependency rules for \"$dname\""
2471              exit 1              exit 1
2472          fi          fi
2473          i=$(( $i + 1 ))          i=`echo "$i + 1" | bc -l`
2474            #i=$(( $i + 1 ))
2475      done      done
2476      ck=$ck"t"      ck=$ck"t"
2477  done    done
2478  echo "    packages are:  $PACKAGES"    echo "    packages are: $PACKAGES"
2479    fi
2480  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2481      adr="$ROOTDIR/pkg/$i"      adr="$ROOTDIR/pkg/$i"
2482      if test -d $adr ; then      if test -d $adr ; then
# Line 908  for i in $PACKAGES ; do Line 2491  for i in $PACKAGES ; do
2491      fi      fi
2492  done  done
2493    
 #  This is compatible with the old genmake.  The "DISABLE_*" flags  
 #  need to be replaced by the "ALLOW_*" flags set below.  
 #  
 # echo -n "  Setting package-specific CPP flags:  "  
 # pkrm=( mom_fluxform mom_vecinv generic_advdiff )  
 # pkrmdef=( -DDISABLE_MOM_FLUXFORM -DDISABLE_MOM_VECINV -DDISABLE_GENERIC_ADVDIFF -DDISABLE_DEBUGMODE )  
 # echo -n "  "  
 # i=0  
 # while test $i -lt "${#pkrm[@]}" ; do  
 #     echo "$PACKAGES" | grep "${pk[$i]}" > /dev/null 2>&1  
 #     RETVAL=$?  
 #     if test "x$RETVAL" = x1 ; then  
 #       DEFINES="$DEFINES ${pkdef[$i]}"  
 #       echo -n " ${pkdef[$i]}"  
 #     fi  
 #     i=$(( $i + 1 ))  
 # done  
 # echo  
   
2494  # Create a list of #define and #undef to enable/disable packages  # Create a list of #define and #undef to enable/disable packages
2495  PACKAGES_DOT_H=PACKAGES_CONFIG.h  PACKAGES_DOT_H=PACKAGES_CONFIG.h
2496  cat <<EOF >$PACKAGES_DOT_H".tmp"  #  The following UGLY HACK sets multiple "#undef"s and it needs to go
2497  C=== GENMAKE v2 ===  #  away.  On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
 C  The following defines have been set by GENMAKE, so please do not  
 C  edit anything below these comments.  In general, you should  
 C  add or remove packages by re-running genmake with different  
 C  "-enable" and/or "-disable" options.  
   
 #ifndef PACKAGES_H  
 #define PACKAGES_H  
   
 C  Packages disabled by genmake:  
 EOF  
 #  The following UGLY HACK sets multiple "#undef"s and it needs to go  
 #  away.  On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h  
2498  #  file would eventually be split up so that all package-related #define  #  file would eventually be split up so that all package-related #define
2499  #  statements could be separated and handled only by genmake.  #  statements could be separated and handled only by genmake.
2500  names=`ls -1 "$ROOTDIR/pkg"`  names=`ls -1 "$ROOTDIR/pkg"`
2501  all_pack=  all_pack=
2502    DISABLED_PACKAGES=
2503  for n in $names ; do  for n in $names ; do
2504      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
2505          has_pack="f"          has_pack="f"
# Line 957  for n in $names ; do Line 2510  for n in $names ; do
2510              fi              fi
2511          done          done
2512          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
2513              undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2514              echo "#undef $undef" >> $PACKAGES_DOT_H".tmp"              DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
 #           DEFINES="$DEFINES -U$undef"  
   
 #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  
             case $n in  
                 mom_fluxform)  
                     DEFINES="$DEFINES -DDISABLE_MOM_FLUXFORM"  
                     ;;  
                 mom_vecinv)  
                     DEFINES="$DEFINES -DDISABLE_MOM_VECINV"  
                     ;;  
                 debug)  
                     DEFINES="$DEFINES -DDISABLE_DEBUGMODE"  
                     ;;  
             esac  
 #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  
   
2515          fi          fi
2516      fi      fi
2517  done  done
2518  cat <<EOF >>$PACKAGES_DOT_H".tmp"  ENABLED_PACKAGES=
   
 C  Packages enabled by genmake:  
 EOF  
2519  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2520      def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`      def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2521      echo "#define $def" >> $PACKAGES_DOT_H".tmp"      ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
2522  #eh3 DEFINES="$DEFINES -D$def"  #eh3 DEFINES="$DEFINES -D$def"
2523    
2524  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
2525      case $i in      case $i in
2526          aim_v23)          aim_v23)
2527              echo "#define   ALLOW_AIM" >> $PACKAGES_DOT_H".tmp"              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
2528              DEFINES="$DEFINES -DALLOW_AIM"              echo "Warning: ALLOW_AIM is set to enable aim_v23."
             echo "Warning: ALLOW_AIM is set to enable aim_v23. This is REALLY ugly Jean-Michel :-)"  
2529              ;;              ;;
2530      esac      esac
2531  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
2532    
2533  done  done
 cat <<EOF >>$PACKAGES_DOT_H".tmp"  
   
 #endif /* PACKAGES_H */  
 EOF  
   
 if test ! -f $PACKAGES_DOT_H ; then  
     mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H  
 else  
     cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H  
     RETVAL=$?  
     if test "x$RETVAL" = x0 ; then  
         rm -f $PACKAGES_DOT_H".tmp"  
     else  
         mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"  
         mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H  
     fi  
 fi  
2534    
2535  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS='$STANDARDDIRS'"
2536  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
2537  if test "x$STANDARDDIRS" = x ; then  if test "x$STANDARDDIRS" != x ; then
2538      STANDARDDIRS="eesupp model"      for d in $STANDARDDIRS ; do
2539            adr="$ROOTDIR/$d/src"
2540            if test ! -d $adr ; then
2541                echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
2542                echo "  is correct and that you correctly specified the STANDARDDIRS option"
2543                exit 1
2544            else
2545                SOURCEDIRS="$SOURCEDIRS $adr"
2546            fi
2547            adr="$ROOTDIR/$d/inc"
2548            if test ! -d $adr ; then
2549                echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
2550                echo "  is correct and that you correctly specified the STANDARDDIRS option"
2551                exit 1
2552            else
2553                INCLUDEDIRS="$INCLUDEDIRS $adr"
2554            fi
2555        done
2556  fi  fi
 for d in $STANDARDDIRS ; do  
     adr="$ROOTDIR/$d/src"  
     if test ! -d $adr ; then  
         echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""  
         echo "  is correct and that you correctly specified the STANDARDDIRS option"  
         exit 1  
     else  
         SOURCEDIRS="$SOURCEDIRS $adr"  
     fi  
     adr="$ROOTDIR/$d/inc"  
     if test ! -d $adr ; then  
         echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""  
         echo "  is correct and that you correctly specified the STANDARDDIRS option"  
         exit 1  
     else  
         INCLUDEDIRS="$INCLUDEDIRS $adr"  
     fi  
 done  
2557    
2558  echo " Searching for CPP_OPTIONS.h in order to warn about the presence"  echo "  Searching for *OPTIONS.h files in order to warn about the presence"
2559  echo " of \"#define ALLOW_PKGNAME\"-type statements:"  echo "    of \"#define \"-type statements that are no longer allowed:"
2560  CPP_OPTIONS=  CPP_OPTIONS=
2561    CPP_EEOPTIONS=
2562  spaths=". $INCLUDEDIRS"  spaths=". $INCLUDEDIRS"
2563    names=`ls -1 "$ROOTDIR/pkg"`
2564  for i in $spaths ; do  for i in $spaths ; do
2565      try="$i/CPP_OPTIONS.h"      try="$i/CPP_OPTIONS.h"
2566      #  echo -n "    trying $try : "      if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
     if test -f $try -a -r $try ; then  
2567          echo "    found CPP_OPTIONS=\"$try\""          echo "    found CPP_OPTIONS=\"$try\""
2568          CPP_OPTIONS="$try"          CPP_OPTIONS="$try"
2569          break          # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
2570            for n in $names ; do
2571                test_for_package_in_cpp_options $CPP_OPTIONS $n
2572            done
2573        fi
2574        try="$i/CPP_EEOPTIONS.h"
2575        if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
2576            echo "    found CPP_EEOPTIONS=\"$try\""
2577            # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
2578    #**** not yet enabled ****
2579    #        test_for_mpi_in_cpp_eeoptions $try
2580    #**** not yet enabled ****
2581            CPP_EEOPTIONS="$try"
2582      fi      fi
2583  done  done
2584  if test "x$CPP_OPTIONS" = x ; then  if test "x$CPP_OPTIONS" = x ; then
2585      echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"      echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
2586      exit 1      exit 1
2587  fi  fi
 # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h  
 names=`ls -1 "$ROOTDIR/pkg"`  
 for n in $names ; do  
     test_for_package_in_cpp_options $CPP_OPTIONS $n  
 done  
   
2588    
2589  #  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
2590  #  compiler.  #  compiler.
2591  if test -f ./ad_files ; then  if test -f $TMP.adSrcFiles ; then
2592      rm -f ./ad_files      rm -f $TMP.adSrcFiles
2593  fi  fi
2594  echo "  Creating the list of files for the adjoint compiler."  echo "  Creating the list of files for the adjoint compiler."
2595    touch $TMP.adSrcFiles
2596  for i in $SOURCEDIRS ; do  for i in $SOURCEDIRS ; do
2597      list_files=`( cd $i && ls -1 *.list 2>/dev/null )`      list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
2598      for j in $list_files ; do      for j in $list_files ; do
2599          cat $i/$j >> ad_files          cat $i/$j >> $TMP.adSrcFiles
2600      done      done
2601  done  done
2602    if test ! "x"$FS = "x.f" ; then
2603  cat <<EOF > adjoint_sed      cat $TMP.adSrcFiles | sed -e "s/\.f/.$FS/g" > $TMP.adSrcFiles_f
2604  s/call adopen(/call adopen ( mythid,\\      mv -f $TMP.adSrcFiles_f $TMP.adSrcFiles
2605       \&           /g  fi
 s/call adclose(/call adclose( mythid,\\  
      \&           /g  
 s/call adread(/call adread ( mythid,\\  
      \&           /g  
 s/call adwrite(/call adwrite( mythid,\\  
      \&           /g  
   
 EOF  
2606    
2607  echo  echo
2608  echo "===  Creating the Makefile  ==="  echo "===  Creating the Makefile  ==="
2609  echo "  setting INCLUDES"  echo "  setting INCLUDES"
2610  for i in $INCLUDEDIRS ; do  for i in $INCLUDEDIRS ; do
2611      if ! test -d $i ; then      if test ! -d $i ; then
 #       INCLUDES="$INCLUDES -I$i"  
 #   else  
2612          echo "Warning: can't find INCLUDEDIRS=\"$i\""          echo "Warning: can't find INCLUDEDIRS=\"$i\""
2613      fi      fi
2614  done  done
2615    
2616    if test ! "x$DIVA" = x -a ! "x$MPI" = x ; then
2617        if test ! "x$MPIINCLUDEDIR" = x ; then
2618            #  Do a local copy of MPI headers files (in local dir ./mpi_headers/) after
2619            #   checking for additional included headers (in case of chain of included
2620            #   header); also set LOCAL_MPI_HEADERS (if not already set)
2621            mpi_headers_do_local_copy
2622        fi
2623    fi
2624    
2625  echo "  Determining the list of source and include files"  echo "  Determining the list of source and include files"
2626  rm -rf .links.tmp  rm -rf $TMP.links
2627  mkdir .links.tmp  mkdir $TMP.links
2628  echo "# This section creates symbolic links" > srclinks.tmp  touch $TMP.links/foo
2629  echo "" >> srclinks.tmp  if test ! -r "$TMP.links/foo" ; then
2630  echo -n 'SRCFILES = '    > srclist.inc      echo
2631  echo -n 'CSRCFILES = '   > csrclist.inc      echo "ERROR : something is wrong with your directory permissions or"
2632  echo -n 'F90SRCFILES = ' > f90srclist.inc      echo "   your user file-creation mask (\"umask\") since creating a"
2633  echo -n 'HEADERFILES = ' > hlist.inc      echo "   sub-dir, touch-ing a file within it, and then reading it is"
2634  echo -n 'AD_FLOW_FILES = ' > ad_flow_files.inc      echo "   not working.  Please try setting your umask to something"
2635        echo "   sane such as:"
2636        echo
2637        echo "      umask 0002"
2638        echo
2639        echo "   and please verify that you have the proper permissions for"
2640        echo "   creating sub-directories and then reading files created"
2641        echo "   within them."
2642        echo
2643        exit 1
2644    fi
2645    rm -f $TMP.links/foo
2646    
2647    if test "x$OPENAD" != x ; then
2648        OAD_DONT_COMPILE="/dev/null"
2649        OAD_DONT_TRANSFORM="/dev/null"
2650        OAD_KEEP_ORIGINAL="/dev/null"
2651        OAD_CB2M_FILES="/dev/null"
2652        OADTOOLS="$TOOLSDIR/OAD_support"
2653        echo "  looking for dontCompile file:  "
2654        for i in "." $MODS $OADTOOLS ; do
2655            if test -r $i"/dontCompile" ; then
2656                OAD_DONT_COMPILE=$i"/dontCompile"
2657                echo "     found $OAD_DONT_COMPILE"
2658                break
2659            fi
2660        done
2661        echo "  looking for dontTransform file:  "
2662        for i in "." $MODS $OADTOOLS ; do
2663            if test -r $i"/dontTransform" ; then
2664                OAD_DONT_TRANSFORM=$i"/dontTransform"
2665                echo "     found $OAD_DONT_TRANSFORM"
2666                break
2667            fi
2668        done
2669        echo "  looking for keepOriginal file:  "
2670        for i in "." $MODS $OADTOOLS ; do
2671            if test -r $i"/keepOriginal" ; then
2672                OAD_KEEP_ORIGINAL=$i"/keepOriginal"
2673                echo "     found $OAD_KEEP_ORIGINAL"
2674                break
2675            fi
2676        done
2677        echo "  looking for cb2mFiles:  "
2678        for i in "." $MODS $OADTOOLS ; do
2679            if test -r $i"/cb2mFiles" ; then
2680                OAD_CB2M_FILES=$i"/cb2mFiles"
2681                echo "     found $OAD_CB2M_FILES"
2682                break
2683            fi
2684        done
2685        echo "   OpenAD exceptions:  "
2686    fi
2687    
2688    echo "# This section creates symbolic links" > $TMP.srclinks
2689    echo "" >> $TMP.srclinks
2690    printf 'F77_SRC_FILES = ' > $TMP.F77srclist
2691    printf 'NON_AD_F77_SRC_FILES = ' > $TMP.nonADF77srclist
2692    printf 'C_SRC_FILES = '   > $TMP.csrclist
2693    printf 'F90_SRC_FILES = ' > $TMP.F90srclist
2694    printf 'H_SRC_FILES = '   > $TMP.hsrclist
2695    printf 'AD_FLOW_FILES = ' > $TMP.ad_flow_files
2696  alldirs="$SOURCEDIRS $INCLUDEDIRS ."  alldirs="$SOURCEDIRS $INCLUDEDIRS ."
2697  for d in $alldirs ; do  for d in $alldirs ; do
2698      deplist=      deplist=
2699      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
2700      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
2701        if test "x$OPENAD" != x ; then
2702            sfiles=`( echo $sfiles | grep -v _cb2m\. )`
2703        fi
2704      for sf in $sfiles ; do      for sf in $sfiles ; do
2705          if test ! -r ".links.tmp/$sf" ; then          if test ! -r "$TMP.links/$sf" ; then
2706              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
2707                  extn=`echo $sf | $AWK -F '.' '{print $NF}'`                  ignore_f=f
2708                  touch .links.tmp/$sf                  case $d/$sf in
2709                  deplist="$deplist $sf"                    ./$PACKAGES_DOT_H)
2710                  case $extn in                          ignore_f=t
2711                      F)                          ;;
2712                          echo    " \\"  >> srclist.inc                    ./AD_CONFIG.h)
2713                          echo -n " $sf" >> srclist.inc                          ignore_f=t
2714                            ;;
2715                      ./FC_NAMEMANGLE.h)
2716                            ignore_f=t
2717                            ;;
2718                      ./BUILD_INFO.h)
2719                            ignore_f=t
2720                            ;;
2721                      ./EMBEDDED_FILES.h)
2722                            ignore_f=t
2723                            ;;
2724                      *)
2725                            #  For the local directory *ONLY*,
2726                            #  ignore all soft-links
2727                            if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then
2728                                ignore_f=t
2729                            else
2730                                touch $TMP.links/$sf
2731                                deplist="$deplist $sf"
2732                            fi
2733                            ;;
2734                    esac
2735                    if test "x$ignore_f" = xf ; then
2736                        extn=`echo $sf | $AWK -F. '{print $NF}'`
2737                        case $extn in
2738                          F)
2739                            echo    " \\"  >> $TMP.F77srclist
2740                            printf " $sf" >> $TMP.F77srclist
2741                            if test "x$OPENAD" = x ; then
2742                                basename=${sf%%.F}
2743                                isAD=`egrep ^$basename.f'[  ]*' $TMP.adSrcFiles`
2744                                if test -z "$isAD" ; then
2745                                    echo    " \\"  >> $TMP.nonADF77srclist
2746                                    printf " $sf" >> $TMP.nonADF77srclist
2747                                fi
2748                            else #- OpenAD case:
2749                                basename=${sf%%.F}
2750                                isAD=`egrep ^$basename.f'[  ]*' $TMP.adSrcFiles`
2751                                if test -z "$isAD" ; then
2752                                    toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE}`
2753                                    if test -z "$toBeIgnored" ; then
2754                                        echo    " \\"  >> $TMP.nonADF77srclist
2755                                        printf " $sf" >> $TMP.nonADF77srclist
2756                                    else
2757                                        echo "    not to be compiled   :  $sf"
2758                                    fi
2759                                else # file is initially listed as an AD file we want to exclude it
2760                                     # or we want to retain the untransformed version
2761                                    notToBeTransformed=`egrep ^$basename'[      ]*' ${OAD_DONT_TRANSFORM}`
2762                                    untransformedVersionToBeKept=`egrep ^$basename'[      ]*' ${OAD_KEEP_ORIGINAL}`
2763                                    if test -n "$notToBeTransformed"; then
2764                                        echo "    not to be transformed:  $sf"
2765                                    fi
2766                                    if test -n "$untransformedVersionToBeKept" ; then
2767                                        echo "    original to be kept  :  $sf"
2768                                    fi
2769                                    if test -n "$notToBeTransformed" -o -n "$untransformedVersionToBeKept" ; then
2770                                        echo    " \\"  >> $TMP.nonADF77srclist
2771                                        printf " $sf" >> $TMP.nonADF77srclist
2772                                    fi
2773                                fi
2774                            fi
2775                          ;;                          ;;
2776                      F90)                      F90)
2777                          echo    " \\"  >> f90srclist.inc                          echo    " \\"  >> $TMP.F90srclist
2778                          echo -n " $sf" >> f90srclist.inc                          printf " $sf" >> $TMP.F90srclist
2779                          ;;                          ;;
2780                      c)                      c)
2781                          echo    " \\"  >> csrclist.inc                          echo    " \\"  >> $TMP.csrclist
2782                          echo -n " $sf" >> csrclist.inc                          printf " $sf" >> $TMP.csrclist
2783                          ;;                          ;;
2784                      h)                      h)
2785                          echo    " \\"  >> hlist.inc                          echo    " \\"  >> $TMP.hsrclist
2786                          echo -n " $sf" >> hlist.inc                          printf " $sf" >> $TMP.hsrclist
2787                          ;;                          ;;
2788                      flow)                      flow)
2789                          echo    " \\"  >> ad_flow_files.inc                          echo    " \\"  >> $TMP.ad_flow_files
2790                          echo -n " $sf" >> ad_flow_files.inc                          printf " $sf" >> $TMP.ad_flow_files
2791                          ;;                          ;;
2792                  esac                     esac
2793                    fi
2794              fi              fi
2795          fi          fi
2796      done      done
2797      if test "x$deplist" != x ; then      if test "x$deplist" != x ; then
2798          echo "" >> srclinks.tmp        if test "$d" != "." ; then
2799          echo "#  These files are linked from $d" >> srclinks.tmp          echo "" >> $TMP.srclinks
2800          echo "$deplist :" >> srclinks.tmp          echo "#  These files are linked from $d" >> $TMP.srclinks
2801          printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp          echo "$deplist :" >> $TMP.srclinks
2802    # We need to make sure that the link isn't already there.
2803    # This may happen when make thinks that a header file has to be "remade"
2804    # because a module it depends on has changed.  In this case we do nothing.
2805            printf "\tif [ ! -L \$@ ]; then \$(LN) %s/\$@ \$@; fi\n" $d >> $TMP.srclinks
2806          fi
2807      fi      fi
2808  done  done
2809  rm -rf .links.tmp  rm -rf $TMP.links
2810  echo "" >> srclist.inc  echo "" >> $TMP.F77srclist
2811  echo "" >> csrclist.inc  echo "" >> $TMP.nonADF77srclist
2812  echo "" >> f90srclist.inc  echo "" >> $TMP.csrclist
2813  echo "" >> hlist.inc  echo "" >> $TMP.F90srclist
2814  echo "" >> ad_flow_files.inc  echo "" >> $TMP.hsrclist
2815    echo "" >> $TMP.ad_flow_files
2816    
2817    CMDLINE=$0
2818    for xx in "$@" ; do nw=`echo $xx | wc -w`
2819        if test $nw = '1' ; then CMDLINE="$CMDLINE $xx"
2820                            else CMDLINE="$CMDLINE '$xx'" ; fi
2821    done
2822    
2823  if test -e $MAKEFILE ; then  if test -f $MAKEFILE ; then
2824      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.old"
2825  fi  fi
2826  echo "  Writing makefile: $MAKEFILE"  echo "  Writing makefile: $MAKEFILE"
2827  echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE  echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
# Line 1169  echo "#    $MACHINE" >> $MAKEFILE Line 2829  echo "#    $MACHINE" >> $MAKEFILE
2829  echo "# This makefile was generated automatically on" >> $MAKEFILE  echo "# This makefile was generated automatically on" >> $MAKEFILE
2830  echo "#    $THISDATE" >> $MAKEFILE  echo "#    $THISDATE" >> $MAKEFILE
2831  echo "# by the command:" >> $MAKEFILE  echo "# by the command:" >> $MAKEFILE
2832  echo "#    $0 $@" >> $MAKEFILE  echo "#    $CMDLINE"  >> $MAKEFILE
2833  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
2834  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE  echo "#    ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
2835    
2836    EXE_AD=$EXECUTABLE"_ad"
2837    EXE_FTL=$EXECUTABLE"_ftl"
2838    EXE_SVD=$EXECUTABLE"_svd"
2839    
2840  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2841  #  #
2842    # OPTFILE="$OPTFILE"
2843    #
2844  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
2845  # SOURCEDIRS   : Directories containing the source (.F) files  # SOURCEDIRS   : Directories containing the source (.F) files
2846  # INCLUDEDIRS  : Directories containing the header-source (.h) files  # INCLUDEDIRS  : Directories containing the header-source (.h) files
# Line 1184  cat >>$MAKEFILE <<EOF Line 2851  cat >>$MAKEFILE <<EOF
2851  # INCLUDES     : Directories searched for header files  # INCLUDES     : Directories searched for header files
2852  # DEFINES      : Macro definitions for CPP  # DEFINES      : Macro definitions for CPP
2853  # MAKEDEPEND   : Dependency generator  # MAKEDEPEND   : Dependency generator
 # KPP          : Special preprocessor command (specific to platform)  
 # KFLAGS       : Flags for KPP  
2854  # FC           : Fortran compiler command  # FC           : Fortran compiler command
2855  # FFLAGS       : Configuration/debugging options for FC  # FFLAGS       : Configuration/debugging options for FC
2856  # FOPTIM       : Optimization options for FC  # FOPTIM       : Optimization options for FC
# Line 1193  cat >>$MAKEFILE <<EOF Line 2858  cat >>$MAKEFILE <<EOF
2858  # LIBS         : Library flags /or/ additional optimization/debugging flags  # LIBS         : Library flags /or/ additional optimization/debugging flags
2859    
2860  ROOTDIR     = ${ROOTDIR}  ROOTDIR     = ${ROOTDIR}
2861  BUILDDIR    = ${BUILDDIR}    BUILDDIR    = ${BUILDDIR}
2862  SOURCEDIRS  = ${SOURCEDIRS}  SOURCEDIRS  = ${SOURCEDIRS}
2863  INCLUDEDIRS = ${INCLUDEDIRS}  INCLUDEDIRS = ${INCLUDEDIRS}
2864  EXEDIR      = ${EXEDIR}  EXEDIR      = ${EXEDIR}
2865  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}
2866  TOOLSDIR    = ${TOOLSDIR}  TOOLSDIR    = ${TOOLSDIR}
2867    OADTOOLS    = ${OADTOOLS}
2868    
2869  #eh3  new defines for the adjoint work  #eh3  new defines for the adjoint work
2870  AUTODIFF    = ${ROOTDIR}/pkg/autodiff  AUTODIFF    = ${ROOTDIR}/pkg/autodiff
2871    EXE_AD      = ${EXE_AD}
2872    EXE_FTL     = ${EXE_FTL}
2873    EXE_SVD     = ${EXE_SVD}
2874    
2875    ENABLED_PACKAGES = ${ENABLED_PACKAGES}
2876    DISABLED_PACKAGES = ${DISABLED_PACKAGES}
2877    
2878    # These files are created by Makefile
2879    SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h
2880  EOF  EOF
2881    
2882  #  Note: figure out some way to add Hyades JAM libraries here  if test "x$EMBED_SRC" = xt ; then
2883        echo "EMBEDDED_FILES = EMBEDDED_FILES.h" >>$MAKEFILE
2884    else
2885        echo "EMBEDDED_FILES = " >>$MAKEFILE
2886    fi
2887    
2888    # extract default cpp search path so we can pass it to makedepend
2889    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}'`
2890    
2891  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2892  # Unix ln (link)  # Unix ln (link)
2893  LN = ${LN}  LN = ${LN}
 # C preprocessor  
 CPP = cat \$< | ${S64} | ${CPP}  
2894  # Dependency generator  # Dependency generator
2895  MAKEDEPEND = ${MAKEDEPEND}  MAKEDEPEND = ${MAKEDEPEND}
2896  # Special preprocessor (KAP on DECs, FPP on Crays)  # Special preprocessor (KAP on DECs, FPP on Crays)
# Line 1220  KPP = ${KPP} Line 2899  KPP = ${KPP}
2899  FC = ${FC}  FC = ${FC}
2900  # Fortran compiler  # Fortran compiler
2901  F90C = ${F90C}  F90C = ${F90C}
2902    # C compiler
2903    CC = ${CC}
2904  # Link editor  # Link editor
2905  LINK = ${LINK}  LINK = ${LINK} ${LDADD}
2906    
2907  # Defines for CPP  # Defines for CPP
2908  DEFINES = ${DEFINES}  DEFINES = ${DEFINES}
2909  # Includes for CPP  # Includes for CPP
2910  INCLUDES = ${INCLUDES}  INCLUDES = ${INCLUDES}
2911    # default CPP includes for makedepend
2912    CPPINCLUDES = ${CPPINCLUDES}
2913  # Flags for KPP  # Flags for KPP
2914  KFLAGS1 = ${KFLAGS1}  KFLAGS1 = ${KFLAGS1}
2915  KFLAGS2 = ${KFLAGS2}  KFLAGS2 = ${KFLAGS2}
2916  # Optim./debug for FC  # Optim./debug for FC
2917  FFLAGS = ${FFLAGS}  FFLAGS = ${FFLAGS}
2918  FOPTIM = ${FOPTIM}  FOPTIM = ${FOPTIM} ${FEXTRAFLAGS}
2919  # Optim./debug for FC  # Optim./debug for FC
2920  F90FLAGS = ${F90FLAGS}  F90FLAGS = ${F90FLAGS}
2921  F90OPTIM = ${F90OPTIM}  F90OPTIM = ${F90OPTIM}
2922    F90FIXEDFORMAT = ${F90FIXEDFORMAT}
2923  # Flags for CC  # Flags for CC
2924  CFLAGS = ${CFLAGS}  CFLAGS = ${CFLAGS}
2925  # Files that should not be optimized  # Files that should not be optimized
2926  NOOPTFILES = ${NOOPTFILES}  NOOPTFILES = ${NOOPTFILES}
2927  NOOPTFLAGS = ${NOOPTFLAGS}  NOOPTFLAGS = ${NOOPTFLAGS}
2928  # Flags and libraries needed for linking  # Flags and libraries needed for linking
2929  LIBS = ${LIBS} \$(XLIBS)  LIBS = ${LIBS}
2930  # Name of the Mekfile  # Name of the makefile
2931  MAKEFILE=${MAKEFILE}  MAKEFILE = ${MAKEFILE}
2932    # Name of the make program
2933    MAKE = ${MAKE}
2934    
2935  EOF  EOF
2936    
2937  cat srclist.inc       >> $MAKEFILE  cat $TMP.F77srclist      >> $MAKEFILE
2938  cat csrclist.inc      >> $MAKEFILE  cat $TMP.nonADF77srclist >> $MAKEFILE
2939  cat f90srclist.inc    >> $MAKEFILE  cat $TMP.csrclist        >> $MAKEFILE
2940  cat hlist.inc         >> $MAKEFILE  cat $TMP.F90srclist      >> $MAKEFILE
2941  cat ad_flow_files.inc >> $MAKEFILE  cat $TMP.hsrclist        >> $MAKEFILE
2942  echo               >> $MAKEFILE  cat $TMP.ad_flow_files   >> $MAKEFILE
2943  echo 'F77FILES =  $(SRCFILES:.F=.f)'                                           >> $MAKEFILE  
2944  echo 'F90FILES =  $(F90SRCFILES:.F90=.f90)'                                    >> $MAKEFILE  rm -f $TMP.F77srclist $TMP.nonADF77srclist $TMP.csrclist $TMP.F90srclist $TMP.hsrclist $TMP.ad_flow_files
2945  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE  
2946    echo >> $MAKEFILE
2947    
2948  rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc  # add definitions for preprocessed sources
2949  rm -f ad_flow_files.inc  # and note that not all systems allow case sensitive extensions
2950    # hence the $FS and $FS90 here.
2951    # for fixed format f90 files we use ff90 or FF90 resp
2952    # but these are not expected to be the original source files
2953    
2954    echo 'F77_PP_SRC_FILES = $(F77_SRC_FILES:.F=.'$FS')'      >> $MAKEFILE
2955    echo 'F90_PP_SRC_FILES = $(F90_SRC_FILES:.F90=.'$FS90')' >> $MAKEFILE
2956    echo 'OBJFILES= $(F77_SRC_FILES:.F=.o) $(C_SRC_FILES:.c=.o) $(F90_SRC_FILES:.F90=.o)' >> $MAKEFILE
2957    echo 'FLOWFILES =  $(AD_FLOW_FILES:.flow=.flowdir)' >> $MAKEFILE
2958    echo >> $MAKEFILE
2959    echo '.SUFFIXES:' >> $MAKEFILE
2960    echo '.SUFFIXES: .o .'$FS' .p .F .c .f'$FS90' .'$FS90' .FF90 .F90 .flowdir .flow' >> $MAKEFILE
2961    
2962  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2963    
2964  .SUFFIXES:  all: fwd_exe_target
2965  .SUFFIXES: .o .f .p .F .c .F90 .f90  fwd_exe_target:
2966            @echo Update AD_CONFIG.h and make \$(EXECUTABLE)
2967            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Forward version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
2968            @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
2969            @-rm -f ad_config.template
2970            \$(MAKE) -f \$(MAKEFILE) \$(EXECUTABLE)
2971    
2972  all: \$(EXECUTABLE)  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(OBJFILES) \$(EMBEDDED_FILES)
2973  \$(EXECUTABLE): \$(OBJFILES)          @echo Creating \$@ ...
2974          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
2975    
2976  depend:  depend:
2977          @make links          @\$(MAKE) -f \$(MAKEFILE) links
2978          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(CPPINCLUDES) \$(F77_SRC_FILES)
2979          ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE)          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2980            -rm -f makedepend.out
2981    
2982  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)  lib: libmitgcmuv.a
2983    
2984  small_f: \$(F77FILES) \$(F90FILES)  libmitgcmuv.a: \$(OBJFILES)
2985            ar rcv libmitgcmuv.a \$(OBJFILES)
2986            ar d   libmitgcmuv.a main.o
2987    
2988  output.txt: \$(EXECUTABLE)  obj: \$(OBJFILES)
         @printf 'running ... '  
         @\$(EXECUTABLE) > \$@  
2989    
2990    links: \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(SPECIAL_FILES)
2991    
2992    small_f: \$(F77_PP_SRC_FILES) \$(F90_PP_SRC_FILES)
2993    
2994    # remove most of the files that "make" generates
2995  clean:  clean:
2996          -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}          -rm -rf *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
2997            -rm -rf *.o
2998            -rm -rf *.$FS *.flowdir
2999            -rm -rf *.f$FS90 \$(AD_CLEAN) ad_input*
3000    
3001    # remove most of the files that "make" and "make depend" generate
3002  Clean:  Clean:
3003          @make clean          @\$(MAKE) -f \$(MAKEFILE) clean
3004          @make cleanlinks          @\$(MAKE) -f \$(MAKEFILE) cleanlinks
3005          -rm -f Makefile.bak genmake_state genmake_optfile make.log          -rm -f \$(SPECIAL_FILES) f90mkdepend.log $MAKEFILE.old
3006            -rm -f taf_command taf_output taf_ad.log taf_ad_flow.log taf_ftl.log
3007    
3008    # remove also the executable, files that "genmake2" generates (except Makefile)
3009    #         and output from a run (plus log files from testreport)
3010  CLEAN:  CLEAN:
3011          @make Clean          @\$(MAKE) -f \$(MAKEFILE) Clean
3012            -rm -f \$(EXECUTABLE) \$(EXE_AD) \$(EXE_FTL) *.bak
3013            -rm -f $LOGFILE genmake_state genmake_*optfile
3014            -rm -f SIZE.h.mpi genmake.tr_log make.tr_log
3015            -rm -rf mpi_headers mnc_test_*
3016          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
3017          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
3018          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
3019          -rm -f \$(EXECUTABLE) output.txt          -rm -f *.txt STDOUT.* STDERR.* *diagnostics.log *.[0-9][0-9][0-9][0-9].log
3020            -rm -f datetime costfinal divided.ctrl snapshot* output_adm.txt.diva_*
3021            -rm -f *_MIT_CE_000.opt0000 costfunction*0000
3022            -rm -f oad_cp.[0-9][0-9][0-9].?????
3023    
 #eh3 Makefile: makefile  
3024  makefile:  makefile:
3025          ${0} $@          $THIS_SCRIPT $G2ARGS
3026  cleanlinks:  cleanlinks:
3027          -find . -type l -exec rm {} \;          -find . -type l -exec rm {} \;
3028    
3029  # The normal chain of rules is (  .F - .f - .o  )  # Special targets (SPECIAL_FILES) which are created by make
3030  .F.f:  ${PACKAGES_DOT_H}:
3031          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          @echo Creating \$@ ...
3032  .f.o:          @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@
3033    AD_CONFIG.h:
3034            @echo Creating \$@ ...
3035            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Default version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > \$@
3036    FC_NAMEMANGLE.h:
3037            @echo Creating \$@ ...
3038            echo "$FC_NAMEMANGLE" > \$@
3039    
3040    BUILD_INFO.h:
3041            @echo Creating \$@ ...
3042    EOF
3043    
3044    test ! "x$THISVER" = x  && echo "       -echo \"#define THISVER '$THISVER'\" > \$@"   >> $MAKEFILE
3045    test ! "x$THISUSER" = x && echo "       -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE
3046    test ! "x$THISDATE" = x && echo "       -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
3047    test ! "x$THISHOST" = x && echo "       -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
3048    
3049    if test "x$EMBED_SRC" = xt ; then
3050        cat >>$MAKEFILE <<EOF
3051    
3052    decode_files.o : EMBEDDED_FILES.h
3053    
3054    ##  \$(F77_PP_SRC_FILES)
3055    all_fF.tar.gz : \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile
3056            @echo Creating \$@ ...
3057            -tar -hcf all_fF.tar \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile
3058            -rm -f all_fF.tar.gz
3059            -gzip all_fF.tar
3060    
3061    EMBEDDED_FILES.h : all_fF.tar.gz
3062            @echo Creating \$@ ...
3063            -\${ROOTDIR}/tools/embed_encode/encode_files EMBEDDED_FILES.h all_fF.tar.gz
3064    
3065    EOF
3066    fi
3067    
3068    cat >>$MAKEFILE <<EOF
3069    
3070    # The normal chain of rules is (  .F - .$FS - .o  )
3071    
3072    ## This nullifies any default implicit rules concerning these two file types:
3073    ## %.o : %.F
3074    
3075    # C preprocessing and replacing the _d in constants:
3076    CPPCMD = cat \$< | ${CPP} \$(DEFINES) \$(INCLUDES) | ${S64}
3077    
3078    .F.$FS:
3079            \$(CPPCMD)  > \$@
3080    .$FS.o:
3081          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
3082  .F90.f90:  .F.o:
3083          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
3084  .f90.o:  .F90.$FS90:
3085            \$(CPPCMD)  > \$@
3086    .FF90.f$FS90:
3087            \$(CPPCMD)  > \$@
3088    .$FS90.o:
3089          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
3090    .f$FS90.o:
3091            cp \$< \$(basename  \$<).f90
3092            \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$(F90FIXEDFORMAT) \$(basename  \$<).f90
3093  .c.o:  .c.o:
3094          \$(CC) \$(CFLAGS) -c \$<          \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$<
3095    .flow.flowdir:
3096            \$(CPPCMD) > \$@
3097    
3098  # Special exceptions that use the ( .F - .p - .f - .o ) rule-chain  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
3099  .F.p:  .F.p:
3100          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPPCMD) > \$@
3101  .p.f:  .p.$FS:
3102          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
3103    
3104    EOF
3105    
3106  #=========================================  #=========================================
3107  #===  Automatic Differentiation Rules  ===  #===  Automatic Differentiation Rules  ===
3108    #===  for TAMC/TAF  ======================
3109    
3110    if test "x$OPENAD" = x ; then
3111    
3112    cat >>$MAKEFILE <<EOF
3113    
3114  TAMC           = ${TAMC}  TAMC           = ${TAMC}
3115  TAF            = ${TAF}  TAF            = ${TAF}
3116    
3117  TAF_EXTRA      = ${TAF_EXTRA}  TAF_EXTRA      = ${TAF_EXTRA}
3118  TAMC_EXTRA     = ${TAMC_EXTRA}  TAMC_EXTRA     = ${TAMC_EXTRA}
3119    LOCAL_MPI_HEADERS    = ${LOCAL_MPI_HEADERS}
3120    
3121  EOF  EOF
3122    
# Line 1335  ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF Line 3125  ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF
3125  ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"  ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
3126  for i in $ad_vars ; do  for i in $ad_vars ; do
3127      name=$i      name=$i
3128      t1="t2=\$"`echo $i`      t1="t2=\$"`echo "$i"`
3129      eval $t1      eval $t1
3130      printf "%-20s = " $name >> $MAKEFILE      printf "%-20s = " $name >> $MAKEFILE
3131      echo $t2 >> $MAKEFILE      echo "$t2" | sed -e 's| \+| |g' >> $MAKEFILE
3132  done  done
3133    
3134  echo "  Add the source list for AD code generation"  echo "  Add the source list for AD code generation"
3135  echo >> $MAKEFILE  echo >> $MAKEFILE
3136  echo -n "AD_FILES = " >> $MAKEFILE  printf "AD_FILES = " >> $MAKEFILE
3137  AD_FILES=`cat ad_files`  AD_FILES=`cat $TMP.adSrcFiles`
3138  for i in $AD_FILES ; do  for i in $AD_FILES ; do
3139      echo    " \\" >> $MAKEFILE      echo    " \\" >> $MAKEFILE
3140      echo -n " $i" >> $MAKEFILE      printf " $i" >> $MAKEFILE
3141  done  done
3142  echo >> $MAKEFILE  echo >> $MAKEFILE
3143    rm -f $TMP.adSrcFiles
3144    
3145    if test $CAT_SRC_FOR_TAF = 0 ; then
3146  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
3147    
3148  ad_input_code.f: \$(F77FILES)  # ... Utilities ...
3149          @make \$(AD_FLOW_FILES)  remove_comments:
3150          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f          sed -i.bak -f \$(TOOLSDIR)/remove_comments_sed \$(AD_FILES)
3151            @-rm -f \$(AD_FILES:.$FS=.$FS.bak)
3152    adj_sed:
3153            sed -i.bak -f \$(TOOLSDIR)/adjoint_sed \$(AD_FILES:.$FS=_ad.$FS)
3154            @-rm -f \$(AD_FILES:.$FS=_ad.$FS.bak)
3155    ftl_sed:
3156            sed -i.bak -f \$(TOOLSDIR)/adjoint_sed \$(AD_FILES:.$FS=_tl.$FS)
3157            @-rm -f \$(AD_FILES:.$FS=_tl.$FS.bak)
3158    adobjfiles: \$(AD_FILES:.$FS=_ad.o)
3159    ftlobjfiles: \$(AD_FILES:.$FS=_tl.o)
3160    EOF
3161    fi
3162    
3163    cat >>$MAKEFILE <<EOF
3164    
3165  # ... AD ...  # ... AD ...
3166  ad_taf_output.f: ad_input_code.f  adall: ad_exe_target
3167          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f  adtaf: ad_taf_output.$FS
3168          cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f  adtamc: ad_tamc_output.$FS
3169    
3170  ad_taf: ad_taf_output.o \$(OBJFILES)  ad_exe_target:
3171          \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)          @echo Update AD_CONFIG.h and make \$(EXE_AD)
3172            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3173  ad_tamc_output.f: ad_input_code.f          @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3174          \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f          @-rm -f ad_config.template
3175          cat ad_input_code_ad.f | sed -f adjoint_sed > ad_tamc_output.f          \$(MAKE) -f \$(MAKEFILE) \$(EXE_AD)
3176    
3177    ad_input_code.$FS: \$(AD_FILES) \$(AD_FLOW_FILES)
3178            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3179            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3180            @-rm -f ad_config.template
3181            @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3182            @\$(MAKE) -f \$(MAKEFILE) \$(FLOWFILES)
3183            cat \$(FLOWFILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ad_input_code.$FS
3184    
3185    adtafonly:
3186            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
3187            ls -l ad_input_code_ad.$FS
3188            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
3189    
3190    EOF
3191    
3192    if test $CAT_SRC_FOR_TAF = 1 ; then
3193    cat >>$MAKEFILE <<EOF
3194    # ... send 1 file to TAF ...
3195    ad_taf_output.$FS: ad_input_code.$FS
3196            @-rm -f ad_input_code_ad.$FS ; echo ''
3197            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
3198            ls -l ad_input_code_ad.$FS
3199            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
3200    
3201    \$(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)
3202            \$(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)
3203    
3204    adobj: ad_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o)
3205    
3206    EOF
3207    
3208    else
3209    cat >>$MAKEFILE <<EOF
3210    # ... send multiple files to TAF ...
3211    ad_taf_output.$FS: \$(AD_FLOW_FILES) \$(AD_FILES)
3212            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3213            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3214            @-rm -f ad_config.template
3215            @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3216            @\$(MAKE) -f \$(MAKEFILE) \$(FLOWFILES)
3217            @-rm -f \$(AD_FILES:.$FS=_ad.$FS) \$(AD_FILES:.$FS=_ad.o); echo ''
3218            \$(MAKE) -f \$(MAKEFILE) remove_comments
3219            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) \$(FLOWFILES) \$(AD_FILES)
3220            \$(MAKE) -f \$(MAKEFILE) adj_sed
3221            cat \$(AD_FILES:.$FS=_ad.$FS) > ad_taf_output.$FS
3222    
3223    \$(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)
3224            \$(MAKE) -f \$(MAKEFILE) adobjfiles
3225            \$(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)
3226    
3227    adobj: ad_taf_output.$FS \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o)
3228            \$(MAKE) -f \$(MAKEFILE) adobjfiles
3229    
3230    EOF
3231    fi
3232    
3233    cat >>$MAKEFILE <<EOF
3234    adonlyfwd:
3235            patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
3236    
3237    adtrick:
3238            patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
3239    
3240    ad_tamc_output.$FS: ad_input_code.$FS
3241            \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
3242            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS
3243    
3244  ad_tamc: ad_tamc_output.o \$(OBJFILES)  ad_tamc: ad_tamc_output.o \$(OBJFILES)
3245          \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
3246    
3247    # ... FTL ...
3248    ftlall: ftl_exe_target
3249    ftltaf: ftl_taf_output.$FS
3250    ftltamc: ftl_tamc_output.$FS
3251    
3252    ftl_exe_target:
3253            @echo Update AD_CONFIG.h and make \$(EXE_FTL)
3254            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
3255            @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3256            @-rm -f ad_config.template
3257            \$(MAKE) -f \$(MAKEFILE) \$(EXE_FTL)
3258    
3259    ftl_input_code.$FS: \$(AD_FILES)
3260            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
3261            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3262            @-rm -f ad_config.template
3263            @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3264            @\$(MAKE) -f \$(MAKEFILE) \$(AD_FLOW_FILES)
3265            cat \$(AD_FLOW_FILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ftl_input_code.$FS
3266    
3267    ftltafonly:
3268            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
3269            ls -l ftl_input_code_tl.$FS
3270            cat ftl_input_code_tl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
3271    
3272    EOF
3273    
3274    if test $CAT_SRC_FOR_TAF = 1 ; then
3275    cat >>$MAKEFILE <<EOF
3276    # ... send 1 file to TAF ...
3277    ftl_taf_output.$FS: ftl_input_code.$FS
3278            @-rm -f ftl_input_code_tl.$FS ; echo ''
3279            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
3280            ls -l ftl_input_code_tl.$FS
3281            cat ftl_input_code_tl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
3282    
3283    \$(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)
3284            \$(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)
3285    
3286  # ... FLT ...  EOF
 flt_taf_output.f: ad_input_code.f  
         \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f  
         cat ad_input_code_ad.f | sed -f adjoint_sed > flt_taf_output.f  
3287    
3288  flt_taf: flt_taf_output.o \$(OBJFILES)  else
3289          \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) flt_taf_output.o \$(LIBS)  cat >>$MAKEFILE <<EOF
3290    # ... send multiple files to TAF ...
3291    ftl_taf_output.$FS: \$(AD_FLOW_FILES) \$(AD_FILES)
3292            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
3293            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3294            @-rm -f ad_config.template
3295            @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3296            @\$(MAKE) -f \$(MAKEFILE) \$(AD_FLOW_FILES)
3297            @-rm -f \$(AD_FILES:.$FS=_tl.$FS) \$(AD_FILES:.$FS=_tl.o); echo ''
3298            \$(MAKE) -f \$(MAKEFILE) remove_comments
3299            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) \$(AD_FLOW_FILES) \$(AD_FILES)
3300            \$(MAKE) -f \$(MAKEFILE) ftl_sed
3301            cat \$(AD_FILES:.$FS=_tl.$FS) > ftl_taf_output.$FS
3302    
3303    \$(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)
3304            \$(MAKE) -f \$(MAKEFILE) ftlobjfiles
3305            \$(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)
3306    
3307  flt_tamc_output.f: ad_input_code.f  EOF
3308          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f  fi
         cat ad_input_code_ad.f | sed -f adjoint_sed > flt_tamc_output.f  
3309    
3310  flt_tamc: flt_tamc_output.o \$(OBJFILES)  cat >>$MAKEFILE <<EOF
3311          \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) flt_tamc_output.o \$(LIBS)  ftl_tamc_output.$FS: ftl_input_code.$FS
3312            \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
3313            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS
3314    
3315    ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
3316            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
3317    
3318  # ... SVD ...  # ... SVD ...
3319  svd_taf_output.f: ad_input_code.f  svdtaf: ad_taf_output.$FS ftl_taf_output.$FS
3320          \$(TAF) \$(SVD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f          @echo "--->>> Only ran TAF to generate SVD code!    <<<---"
3321          cat ad_input_code_ad.f | sed -f adjoint_sed > svd_taf_output.f          @echo "--->>> Do make svdall afterwards to compile. <<<---"
3322    svdall: svd_touch svd_taf
3323    
3324    svd_taf: \$(OBJFILES)
3325            \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
3326    
3327            @echo "--->>> Only COMPILE svd code! <<<---"
3328            @echo "--->>> Assumes you previously <<<---"
3329            @echo "--->>> did make svdtaf        <<<---"
3330    
3331    svd_touch:
3332            @echo "--->>> Only COMPILE svd code! <<<---"
3333            @echo "--->>> Assumes you previously <<<---"
3334            @echo "--->>> did make svdtaf        <<<---"
3335            touch ad_taf_output.$FS ftl_taf_output.$FS
3336            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS
3337            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS
3338            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "SVD version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
3339            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3340            @-rm -f ad_config.template
3341    
3342  svd_taf: svd_taf_output.o \$(OBJFILES)  EOF
3343          \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) svd_taf_output.o \$(LIBS)  
3344    fi
3345    
3346    #===  for OpenAD  ========================
3347    
3348  #=========================================  if test "x$OPENAD" != x ; then
3349    
3350    # ============ begin OpenAD specific section ==============
3351    
3352    cat >>$MAKEFILE <<EOF
3353    # ... OpenAD ...
3354    
3355    # all the source files linked from the various locations:
3356    ALL_LINKED_FILES= \
3357    \$(F77_SRC_FILES) \
3358    \$(C_SRC_FILES) \
3359    \$(H_SRC_FILES) \
3360    \$(F90_SRC_FILES) \
3361    \$(SPECIAL_FILES)
3362    
3363    ifndef OPENADROOT
3364      \$(error "Error:  environment variable OPENADROOT not defined!")
3365    endif
3366    
3367    ifndef XAIFSCHEMAROOT
3368      \$(error "Error:  environment variable XAIFSCHEMAROOT not defined!")
3369    endif
3370    
3371    ifndef XAIFBOOSTERROOT
3372      \$(error "Error:  environment variable XAIFBOOSTERROOT not defined!")
3373    endif
3374    
3375  EOF  EOF
3376    
3377    echo "  Add the source list for common block to module conversion "
3378    echo >> $MAKEFILE
3379    printf "CB2M_F90_SRC_NAMES = " >> $MAKEFILE
3380    for i in `cat ${OAD_CB2M_FILES}` ; do
3381      echo    " \\" >> $MAKEFILE
3382      printf " $i" >> $MAKEFILE
3383    done
3384    echo >> $MAKEFILE
3385    
3386    echo "  Add the source list for AD code generation"
3387    echo >> $MAKEFILE
3388    printf "AD_FILES = " >> $MAKEFILE
3389    for i in `cat ${OAD_CB2M_FILES}` ; do
3390      echo    " \\" >> $MAKEFILE
3391      printf " ${i}_mod.f$FS90" >> $MAKEFILE
3392    done
3393    AD_FILES=`cat $TMP.adSrcFiles`
3394    for i in $AD_FILES ; do
3395      basename=${i%%.f}
3396      toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE} ${OAD_DONT_TRANSFORM}`
3397      if test -z "$toBeIgnored" ; then
3398        echo    " \\" >> $MAKEFILE
3399        printf " $i" >> $MAKEFILE
3400      fi
3401    done
3402    echo >> $MAKEFILE
3403    rm -f $TMP.adSrcFiles
3404    
3405    cat >>$MAKEFILE <<EOF
3406    
3407    adAll: ad_exe_target
3408    .PHONY: adAll
3409    
3410    ad_exe_target:
3411            @echo Update AD_CONFIG.h and make \$(EXE_AD)
3412            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3413            @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3414            @-rm -f ad_config.template
3415            \$(MAKE) -f \$(MAKEFILE) \$(EXE_AD)
3416    
3417    CB2M_F90_PP_SRC_FILES=\$(addsuffix _mod.f$FS90, \$(CB2M_F90_SRC_NAMES))
3418    
3419    .PRECIOUS: \$(CB2M_F90_PP_SRC_FILES) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90)
3420    
3421    .PHONY: adDepend
3422    adDepend: \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) \$(addsuffix _mod.FF90, \$(CB2M_F90_SRC_NAMES)) \$(F77_SRC_FILES:.F=_cb2m.FF90)
3423            \$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)
3424            \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
3425            -rm -f makedepend.out
3426    
3427    OPENAD_SUPPORT_F90_SRC_FILES = \
3428    w2f__types.F90 \
3429    OAD_active.F90 \
3430    OAD_cp.F90 \
3431    OAD_rev.F90 \
3432    OAD_tape.F90 \
3433    OAD_regular_cp.F90 \
3434    revolve.F90
3435    
3436    OPENAD_SUPPORT_C_SRC_FILES = \
3437    iaddr.c \
3438    timeRatio.c
3439    
3440    f95_test_mods.f90: \$(OPENAD_SUPPORT_F90_SRC_FILES:F90=$FS90)
3441            cat \$^ > \$@
3442    
3443    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
3444            cat \$^ > \$@
3445    
3446    f95_test.out: f95_test_mods.f90 f95_test.f90
3447            f95 -fixed -w=unused -maxcontin=132 -c f95_test_mods.f90 > \$@ 2>&1
3448            f95 -fixed -w=unused -maxcontin=132 -c -fixed f95_test.f90 >> \$@ 2>&1
3449    
3450    CB2M_AD_FILES=\$(AD_FILES:.f=_cb2m.f$FS90)
3451    
3452    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)
3453    
3454    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)
3455    
3456    \$(EXE_AD): \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) postProcess.tag \$(AD_OBJ_FILES_S2)
3457            \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(AD_OBJ_FILES_S2) \$(LIBS)
3458    
3459    # create sources files modules from header files containing common blocks
3460    %_mod.FF90 : %.h \${OADTOOLS}/cb2mGetModules.csh \${OADTOOLS}/cb2mGetModules.awk
3461            \${OADTOOLS}/cb2mGetModules.csh $< \${OADTOOLS}/cb2mGetModules.awk
3462    
3463    # create new header files with USE statements for the new modules made above
3464    %_mod.h : %.h \${OADTOOLS}/cb2mGetHeaders.csh \${OADTOOLS}/cb2mGetHeaders.awk
3465            \${OADTOOLS}/cb2mGetHeaders.csh $< \${OADTOOLS}/cb2mGetHeaders.awk \$(CB2M_F90_SRC_NAMES)
3466    
3467    # change the include directives of everybody to refer to  the new header files with the USE statements
3468    %_cb2m.FF90 : %.F \${OADTOOLS}/cb2mUseModules.bash
3469            \${OADTOOLS}/cb2mUseModules.bash $< ${MPI}
3470    
3471    # makefile debug rule
3472    small_f: \$(CB2M_F90_PP_SRC_FILES)
3473    .PHONY: small_f
3474    
3475    ad_input_code.f$FS90:  \$(CB2M_AD_FILES)
3476            cat \$^ > \$@
3477    
3478    # canonicalizer
3479    ad_input_code_sf.pre.f90 : \$(CB2M_AD_FILES)
3480            \${OPENADFORTTK_BASE}/tools/SourceProcessing/preProcess.py --timing --r8 -H -S  -o \$@ \$^
3481    
3482    # replace stop statements (to avoid the implied unstructured control flow)  with print statements
3483    ad_input_code_sf.pre.s2p.f90 : ad_input_code_sf.pre.f90
3484            cat \$< | sed -f \${OADTOOLS}/stop2print.sed > ad_input_code_sf.pre.s2p.f90
3485    
3486    # F -> WHIRL
3487    ad_input_code_sf.pre.s2p.B: ad_input_code_sf.pre.s2p.f90
3488            \${OPEN64ROOT}/crayf90/sgi/mfef90 -r8 -z -F ad_input_code_sf.pre.s2p.f90
3489    
3490    # WHIRL -> XAIF
3491    ad_input_code_sf.pre.s2p.xaif : ad_input_code_sf.pre.s2p.B
3492            \${OPENADFORTTK}/bin/whirl2xaif -s -n --debug 1 -o \$@ \$<
3493    
3494    # XAIF -> XAIF'
3495    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
3496            \${XAIFBOOSTERROOT}/xaifBooster/algorithms/BasicBlockPreaccumulationReverse/driver/oadDriver -f -t forward_step -i \$< -c \${XAIFSCHEMAROOT}/schema/examples/inlinable_intrinsics.xaif -o \$@ -I -r
3497    
3498    # XAIF' -> WHIRL'
3499    ad_input_code_sf.pre.s2p.xb.x2w.B : ad_input_code_sf.pre.s2p.xb.xaif
3500            \${OPENADFORTTK}/bin/xaif2whirl --debug 1 ad_input_code_sf.pre.s2p.B \$<
3501    
3502    # WHIRL' -> F'
3503    ad_input_code_sf.pre.s2p.xb.x2w.w2f.f$FS90: ad_input_code_sf.pre.s2p.xb.x2w.B
3504            \${OPEN64ROOT}/whirl2f/whirl2f -FLIST:ftn_file=\$@ -openad \$<
3505    
3506    # insert template directives
3507    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
3508            \${OADTOOLS}/insertTemplateDir.bash \$< \$@
3509    
3510    PPEXTRAS=\$(notdir \$(wildcard \${OADTOOLS}/ad_template.*.F)) ad_inline.F
3511    # postprocess F'
3512    postProcess.tag: ad_input_code_sf.pre.s2p.xb.x2w.w2f.td.f$FS90 \$(PPEXTRAS:.F=.f) | w2f__types.f90
3513            \${OPENADFORTTK_BASE}/tools/SourceProcessing/postProcess.py --progress --timing --infoUnitFile w2f__types.f90 --outputFormat=fixed --separateOutput --pathSuffix "" --filenameSuffix "_oad" -m r -i ad_inline.f \$<
3514            # the target is a placeholder to trigger a single execution of the rule
3515            touch \$@
3516    # put this so make knows about the postprocessing output
3517    OAD_intrinsics_oad.f \$(CB2M_AD_FILES:.f$FS90=_oad.f): postProcess.tag
3518    
3519    # link the XAIF schema files
3520    %.xsd:
3521            \$(LN) \${XAIFSCHEMAROOT}/schema/\$@ .
3522    
3523    # link the support files:
3524    \$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES) \$(PPEXTRAS):
3525            \$(LN) \${OADTOOLS}/\$@ .
3526    
3527    AD_CLEAN += *_mod.h *_mod.F90 *.FF90 *.mod-whirl temp.sed oad_cp.* postProcess.tag
3528    
3529    # ============ end OpenAD specific section ==============
3530    
3531    EOF
3532    
3533    fi
3534    
3535    #=========================================
3536    
3537  if test "x$EXEHOOK" != x ; then  if test "x$EXEHOOK" != x ; then
3538      printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE      printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
3539  fi  fi
# Line 1413  for i in $KPPFILES ; do Line 3545  for i in $KPPFILES ; do
3545      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
3546          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
3547      fi      fi
3548      echo "$base.f: $base.p" >> $MAKEFILE      echo "$base.$FS: $base.p" >> $MAKEFILE
3549  done  done
3550    
3551  echo "  Making list of NOOPTFILES"  echo "  Making list of NOOPTFILES"
# Line 1423  for i in $NOOPTFILES ; do Line 3555  for i in $NOOPTFILES ; do
3555      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
3556          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
3557      fi      fi
3558      echo "$base.o: $base.f" >> $MAKEFILE      echo "$base.o: $base.$FS" >> $MAKEFILE
3559      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
3560  done  done
3561    
3562  echo "  Add rules for links"  echo "  Add rules for links"
3563  cat srclinks.tmp >> $MAKEFILE  cat $TMP.srclinks >> $MAKEFILE
3564  rm -f srclinks.tmp  rm -f $TMP.srclinks