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

Legend:
Removed from v.1.48  
changed lines
  Added in v.1.279

  ViewVC Help
Powered by ViewVC 1.1.22