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

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.260

  ViewVC Help
Powered by ViewVC 1.1.22