/[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.1 by edhill, Sat Aug 16 14:01:08 2003 UTC revision 1.145 by jmc, Wed Mar 29 19:28:02 2006 UTC
# Line 1  Line 1 
1  #!/bin/bash  #! /usr/bin/env bash
2  #  #
3  # $Header$  # $Header$
4  #  #
# Line 8  Line 8 
8  #   modified by aja 01/00  #   modified by aja 01/00
9  #   rewritten in bash by eh3 08/03  #   rewritten in bash by eh3 08/03
10    
11    # Search for particular CPP #cmds associated with packages
12    # usage: test_for_package_in_cpp_options CPP_file package_name
13    test_for_package_in_cpp_options() {
14        cpp_options=$1
15        pkg=$2
16        test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg" || exit 99
17        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg" || exit 99
18        test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg" || exit 99
19        test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg" || exit 99
20    }
21    
22    # Search for particular CPP #cmds associated with MPI
23    # usage: test_for_mpi_in_cpp_eeoptions CPP_file
24    test_for_mpi_in_cpp_eeoptions() {
25        cpp_options=$1
26        test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI" || exit 99
27        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI" || exit 99
28        test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI" || exit 99
29        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI" || exit 99
30    }
31    
32    # Search for particular string in a file. Return 1 if detected, 0 if not
33    # usage: test_for_string_in_file file string
34    test_for_string_in_file() {
35        file=$1
36        strng=$2
37        grep -i "$strng" $file > /dev/null 2>&1
38        RETVAL=$?
39        if test "x${RETVAL}" = x0 ; then
40            printf "Error: In $file there is an illegal line: "
41            grep -i "$strng" $file
42            return 1
43        fi
44        return 0
45    }
46    
47    # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to
48    # the package list.
49    expand_pkg_groups() {
50        new_packages=
51        PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups"
52        if test -r $PKG_GROUPS ; then
53            cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp
54            cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp
55            matched=0
56            for i in $PACKAGES ; do
57                line=`grep "^ *$i" ./p2.tmp`
58                RETVAL=$?
59                if test "x$RETVAL" = x0 ; then
60                    matched=1
61                    replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`
62                    echo "    replacing \"$i\" with: $replace"
63                    new_packages="$new_packages $replace"
64                else
65                    new_packages="$new_packages $i"
66                fi
67            done
68            PACKAGES=$new_packages
69            rm -f ./p[1,2].tmp
70            return $matched
71        else
72            echo "Warning: can't read package groups definition file: $PKG_GROUPS"
73        fi
74    }
75    
76    #  Check for broken environments (eg. cygwin, MacOSX w/HFS+) that
77    #  cannot distinguish [*.F/*.F90] from [*.f/*.f90] files.
78    check_for_broken_Ff()  {
79        #  Do we have defaults for $FS and/or $FS90 ?
80        tfs=f
81        tfs9=f90
82        if test "x$FS" != x ; then
83            tfs="$FS"
84        fi
85        if test "x$FS90" != x ; then
86            tfs9="$FS90"
87        fi
88    
89        #  First check the ability to create a *.F/.f pair.
90        cat <<EOF >> genmake_hello.F
91          program hello
92          write(*,*) 'hi'
93          stop
94          end
95    EOF
96        cp genmake_hello.F "genmake_hello."$tfs > /dev/null 2>&1
97        RETVAL=$?
98        if test "x$RETVAL" != x0 ; then
99            if test "x$FS" = x ; then
100                FS='for'
101                FS90='fr9'
102                check_for_broken_Ff
103            else
104                cat <<EOF 2>&1
105    ERROR: Your file system cannot distinguish between *.F and *.f files
106      (fails the "cp" test) and this program cannot find a suitable
107      replacement extension.  Please try a different build environment or
108      contact the <MITgcm-support@mitgcm.org> list for help.
109    
110    EOF
111                exit -1
112            fi
113            return
114        fi
115        rm -f genmake_hello.*
116    
117        #  Check the ability of ${MAKE} and ${LN} to use the current set
118        #  of extensions.
119        cat <<EOF >> genmake_hello.F
120          program hello
121          write(*,*) 'hi'
122          stop
123          end
124    EOF
125        test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
126        cat <<EOF >> $MAKEFILE
127    .SUFFIXES:
128    .SUFFIXES: .$tfs .F
129    .F.$tfs:
130            $LN \$< \$@
131    EOF
132        $MAKE "genmake_hello."$tfs > /dev/null 2>&1
133        RETVAL=$?
134        if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then
135            if test "x$FS" = x ; then
136                FS='for'
137                FS90='fr9'
138                check_for_broken_Ff
139            else
140                cat <<EOF 2>&1
141    ERROR: Your file system cannot distinguish between *.F and *.f files
142      (fails the "make/ln" test) and this program cannot find a suitable
143      replacement extension.  Please try a different build environment or
144      contact the <MITgcm-support@mitgcm.org> list for help.
145    
146    EOF
147                exit -1
148                return
149            fi
150        fi
151        rm -f genmake_hello.* $MAKEFILE
152        test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
153    
154        #  If we make it here, use the extensions
155        FS=$tfs
156        FS90=$tfs9
157        return
158    }
159    
160    
161    look_for_makedepend()  {
162    
163        #  The "original" makedepend is part of the Imake system that is
164        #  most often distributed with XFree86 or with an XFree86 source
165        #  package.  As a result, many machines (eg. generic Linux) do not
166        #  have a system-default "makedepend" available.  For those
167        #  systems, we have two fall-back options:
168        #
169        #    1) a makedepend implementation shipped with the cyrus-imapd
170        #       package:  ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
171        #
172        #    2) a known-buggy xmakedpend shell script
173        #
174        #  So the choices are, in order:
175        #
176        #    1) use the user-specified program
177        #    2) use a system-wide default
178        #    3) locally build and use the cyrus implementation
179        #    4) fall back to the buggy local xmakedpend script
180        #
181        if test "x${MAKEDEPEND}" = x ; then
182            which makedepend > /dev/null 2>&1
183            RV0=$?
184            test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
185            #  echo 'MAKEFILE="'$MAKEFILE'"'
186            cat <<EOF >> $MAKEFILE
187    #   THIS IS A TEST MAKEFILE GENERATED BY "genmake2"
188    #
189    #   Some "makedepend" implementations will die if they cannot
190    #   find a Makefile -- so this file is here to gives them an
191    #   empty one to find and parse.
192    EOF
193            cat <<EOF >> genmake_tc.f
194          program test
195          write(*,*) 'test'
196          stop
197          end
198    EOF
199            makedepend genmake_tc.f > /dev/null 2>&1
200            RV1=$?
201            test -f $MAKEFILE  &&  rm -f $MAKEFILE
202            test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
203            if test "x${RV0}${RV1}" = x00 ; then
204                MAKEDEPEND=makedepend
205            else
206                echo "    a system-default makedepend was not found."
207                
208                #  Try to build the cyrus implementation
209                build_cyrus_makedepend
210                RETVAL=$?
211                if test "x$RETVAL" != x0 ; then
212                    MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
213                fi
214                rm -f ./genmake_cy_md
215            fi
216        else
217            #  echo "MAKEDEPEND=${MAKEDEPEND}"
218            echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1
219            RETVAL=$?
220            if test x"$RETVAL" = x0 ; then
221                build_cyrus_makedepend
222            fi
223        fi
224    }
225    
226    
227    build_cyrus_makedepend()  {
228        rm -f ./genmake_cy_md
229        (
230            cd $ROOTDIR/tools/cyrus-imapd-makedepend  \
231                &&  ./configure > /dev/null 2>&1  \
232                &&  make > /dev/null 2>&1
233            if test -x ./makedepend.exe ; then
234                $LN ./makedepend.exe ./makedepend
235            fi
236            ./makedepend ifparser.c > /dev/null 2>&1  \
237                &&  echo "true"
238        ) > ./genmake_cy_md
239        grep true ./genmake_cy_md > /dev/null 2>&1
240        RETVAL=$?
241        rm -f ./genmake_cy_md
242        if test "x$RETVAL" = x0 ; then
243            MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
244            return 0
245        else
246            echo "WARNING: unable to build cyrus-imapd-makedepend"
247            return 1
248        fi
249    }
250    
251    
252    build_embed_encode()
253    {
254        printf "  building the embed-encode utility...  "
255        if test ! -e "$ROOTDIR/tools/embed_encode/encode_files" ; then
256            if test ! -d "$ROOTDIR/tools/embed_encode" ; then
257                echo
258                echo "    Error: can't locate \"$ROOTDIR/tools/embed_encode\""
259                echo
260                EMBED_SRC=f
261                return 1
262            fi
263            clist="cc gcc c89 $CC"
264            for ic in $clist ; do
265                comm="$ic -o encode_files encode_files.c"
266                ( cd $ROOTDIR/tools/embed_encode && $comm ) > /dev/null 2>&1
267                RETVAL=$?
268                if test "x$RETVAL" = x0 ; then
269                    echo "OK"
270                    DEFINES="$DEFINES -DHAVE_EMBED_SRC"
271                    return 0
272                fi
273            done
274            echo
275            echo "    Error: unable to build $ROOTDIR/embed_encode/encode_files"
276            echo "      so it has been disabled"
277            echo
278            EMBED_SRC=f
279            return 1
280        fi
281        echo "OK"
282        DEFINES="$DEFINES -DHAVE_EMBED_SRC"
283    }
284    
285    
286  # Guess possible config options for this host  # Guess possible config options for this host
287  find_possible_configs()  {  find_possible_configs()  {
288    
289      p_PLATFORM=`uname`"-"`uname -m`      tmp1=`uname`"_"`uname -m`
290      echo "The platform appears to be:"      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
291      echo "  "$p_PLATFORM      tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
292        tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
293      p_LN=      tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
294        tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
295        PLATFORM=$tmp3
296        echo $PLATFORM | grep cygwin > /dev/null 2>&1  &&  PLATFORM=cygwin_ia32
297        OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
298        echo "  The platform appears to be:  $PLATFORM"
299        
300      echo "test" > test      echo "test" > test
301      ln -s ./test link      ln -s ./test link
302      RETVAL=$?      RETVAL=$?
303      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
304          p_LN="ln -s"          LN="ln -s"
305        else
306            echo "Error: \"ln -s\" does not appear to work on this system!"
307            echo "  For help, please contact <MITgcm-support@mitgcm.org>."
308            exit 1
309      fi      fi
310      rm -f test link      rm -f test link
311    
312      p_CPP=`which cpp`      if test "x$CPP" = x ; then
313                CPP="cpp -traditional -P"
     RETVAL=$?  
     if test "x${RETVAL}" = x0 ; then  
         p_LN="ln -s"  
314      fi      fi
     rm -f test link  
315    
316      # look for possible fortran compilers      look_for_makedepend
317      p_FC=  
318      for c in f77 g77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 ; do      #================================================================
319          which $c > /dev/null 2>&1      #  look for possible C compilers
320        tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc"
321        p_CC=
322        for c in $tmp ; do
323            rm -f ./genmake_hello.c  ./genmake_hello
324            cat >> genmake_hello.c << EOF
325    #include <stdio.h>
326    int main(int argc, char **argv) {
327      printf("Hello!\n");
328      return 0;
329    }
330    EOF
331            $c -o genmake_hello genmake_hello.c > /dev/null 2>&1
332          RETVAL=$?          RETVAL=$?
333          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
334              p_FC="$p_FC $c"              p_CC="$p_CC $c"
335          fi          fi
336      done      done
337      echo "Possible FORTRAN compilers appear to be:  "      rm -f ./genmake_hello.c ./genmake_hello
338      if test "x${p_FC}" = x ; then      if test "x${p_CC}" = x ; then
339          echo "  None found!!!"          cat 1>&2 <<EOF
340    
341    Error: No C compilers were found in your path.  Please specify one using:
342    
343        1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
344        2) the CC or MITGCM_CC environment variables.
345    
346    EOF
347            exit 1
348      else      else
349          echo "  "$p_FC          echo "  The possible C compilers found in your path are:"
350            echo "   "$p_CC
351            if test "x$CC" = x ; then
352                CC=`echo $p_CC | $AWK '{print $1}'`
353                echo "  Setting C compiler to: "$CC
354            fi
355      fi      fi
356    
357      # look for possible MPI libraries      #================================================================
358      mpi_libs=      #  look for possible FORTRAN compilers
359      mpi_fort=`which mpif77 2>/dev/null`      tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 gfortran"
360      RETVAL=$?      p_FC=
361      if test "x${RETVAL}" = x0 ; then      for c in $tmp ; do
362          cat >>test.f <<EOF          rm -f ./hello.f ./hello
363        PROGRAM HELLO          cat >> hello.f <<EOF
364        DO 10, I=1,10        program hello
365        PRINT *,'Hello World'        do i=1,3
366     10 CONTINUE          print *, 'hello world : ', i
367        STOP        enddo
368        END        end
369  EOF  EOF
370          eval "$mpi_fort -showme test.f > out"          $c -o hello hello.f > /dev/null 2>&1
371          RETVAL=$?          RETVAL=$?
372          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
373              a=`cat out`              p_FC="$p_FC $c"
             for i in $a ; do  
                 case $i in  
                     -*)  
                         mpi_libs="$mpi_libs $i" ;;  
                 esac  
             done  
             echo "The MPI libs appear to be:"  
             echo "  "$mpi_libs  
374          fi          fi
375          rm -f test.f out      done
376        rm -f ./hello.f ./hello
377        if test "x${p_FC}" = x ; then
378            cat 1>&2 <<EOF
379    
380    Error: No Fortran compilers were found in your path.  Please specify one using:
381    
382        1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
383        2) a command-line option (eg. "-fc NAME"), or
384        3) the FC or MITGCM_FC environment variables.
385    
386    EOF
387            exit 1
388        else
389            echo "  The possible FORTRAN compilers found in your path are:"
390            echo "   "$p_FC
391      fi      fi
392    
393  }      #  Use the first of the compilers found in the current PATH
394        #  that has a correctly-named optfile
395        if test "x$OPTFILE" = x  -a  "x$FC" = x ; then
396            for i in $p_FC ; do
397                OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
398                if test -r $OPTFILE ; then
399                    echo "  Setting OPTFILE to: "$OPTFILE
400                    break
401                fi
402            done
403        fi
404    
405  parse_options()  {      if test "x$OPTFILE" = x ; then
406            OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
407            if test ! -r $OPTFILE ; then
408                 echo "  I looked for the file "$OPTFILE" but did not find it"
409            fi
410        fi
411    #    echo "  The options file:  $p_OF"
412    #    echo "    appears to match so we'll use it."
413    #   for i in $p_FC ; do
414    #p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
415    #if test -r $p_OF ; then
416    #    OPTFILE=$p_OF
417    #    echo "  The options file:  $p_OF"
418    #    echo "    appears to match so we'll use it."
419    #    break
420    #fi
421    #   done
422        if test "x$OPTFILE" = x ; then
423            cat 1>&2 <<EOF
424    
425    Error: No options file was found in:  $ROOTDIR/tools/build_options/
426      that matches this platform ("$PLATFORM") and the compilers found in
427      your path.  Please specify an "optfile" using:
428    
429      ac_prev=      1) the command line (eg. "-optfile=path/to/OPTFILE"), or
430      for ac_option in "${OPTIONS[@]}" ; do      2) the MITGCM_OF environment variable.
431    
432      If you need help, please contact the developers at <MITgcm-support@mitgcm.org>.
433    
434    EOF
435            exit 1
436        fi
437        
438    #     # look for possible MPI libraries
439    #     mpi_libs=
440    #     mpi_fort=`which mpif77 2>/dev/null`
441    #     RETVAL=$?
442    #     if test "x${RETVAL}" = x0 ; then
443    #       cat >>test.f <<EOF
444    #       PROGRAM HELLO
445    #       DO 10, I=1,10
446    #       PRINT *,'Hello World'
447    #    10 CONTINUE
448    #       STOP
449    #       END
450    # EOF
451    #       eval "$mpi_fort -showme test.f > out"
452    #       RETVAL=$?
453    #       if test "x${RETVAL}" = x0 ; then
454    #           a=`cat out`
455    #           for i in $a ; do
456    #               case $i in
457    #                   -*)
458    #                       mpi_libs="$mpi_libs $i" ;;
459    #               esac
460    #           done
461    #           echo "The MPI libs appear to be:"
462    #           echo "  "$mpi_libs
463    #       fi
464    #       rm -f test.f out
465    #     fi
466    
         # echo "ac_option = :$ac_option:"  
           
         # If the previous option needs an argument, assign it.  
         if test -n "$ac_prev"; then  
             eval "$ac_prev=\$ac_option"  
             ac_prev=  
             continue  
         fi  
           
         ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`  
           
         case $ac_option in  
               
             -help | --help | -h | --h)  
                 usage ;;  
               
             -nooptfile | --nooptfile)  
                 OPTFILE="NONE" ;;  
             -optfile | --optfile | -of | --of)  
                 ac_prev=optfile ;;  
             -optfile=* | --optfile=* | -of=* | --of=*)  
                 OPTFILE=$ac_optarg ;;  
               
             -pdepend | --pdepend)  
                 ac_prev=pdepend ;;  
             -pdepend=* | --pdepend=*)  
                 PDEPEND=$ac_optarg ;;  
               
             -pdefault | --pdefault)  
                 ac_prev=pdefault ;;  
             -pdefault=* | --pdefault=*)  
                 PDEFAULT=$ac_optarg ;;  
               
             -makefile | -ma)  
                 ac_prev=makefile ;;  
             --makefile=* | -ma=*)  
                 MAKEFILE=$ac_optarg ;;  
               
             -platform | --platform | -pl | --pl)  
                 ac_prev=platform ;;  
             -platform=* | --platform=* | -pl=* | --pl=*)  
                 PLATFORM=$ac_optarg ;;  
   
             -rootdir | --rootdir | -rd | --rd)  
                 ac_prev=rootdir ;;  
             -rootdir=* | --rootdir=* | -rd=* | --rd=*)  
                 ROOTDIR=$ac_optarg ;;  
               
             -mods | --mods | -mo | --mo)  
                 ac_prev=mods ;;  
             -mods=* | --mods=* | -mo=* | --mo=*)  
                 MODS=$ac_optarg ;;  
               
             -disable | --disable)  
                 ac_prev=disable ;;  
             -disable=* | --disable=*)  
                 DISABLE=$ac_optarg ;;  
               
             -enable | --enable)  
                 ac_prev=enable ;;  
             -enable=* | --enable=*)  
                 ENABLE=$ac_optarg ;;  
               
             -noopt | --noopt)  
                 ac_prev=noopt ;;  
             -noopt=* | --noopt=*)  
                 NOOPT=$ac_optarg ;;  
               
 #           -cpp | --cpp)  
 #               ac_prev=cpp ;;  
 #           -cpp=* | --cpp=*)  
 #               CPP=$ac_optarg ;;  
               
             -fortran | --fortran | -fc | --fc)  
                 ac_prev=fc ;;  
             -fc=* | --fc=*)  
                 FC=$ac_optarg ;;  
               
             -ieee | --ieee)  
                 IEEE=1 ;;  
             -noieee | --noieee)  
                 IEEE=0 ;;  
               
             -mpi | --mpi)  
                 MPI=1 ;;  
             -nompi | --nompi)  
                 MPI=0 ;;  
               
             -jam | --jam)  
                 JAM=1 ;;  
             -nojam | --nojam)  
                 JAM=0 ;;  
               
             -*)  
                 echo "Error: unrecognized option: "$ac_option  
                 usage  
                 ;;  
               
             *)  
                 echo "Error: unrecognized argument: "$ac_option  
                 usage  
                 ;;  
               
         esac  
           
     done  
467  }  }
468    
469  #  Parse the package dependency information  #  Parse the package dependency information
# Line 199  get_pdepend_list()  { Line 472  get_pdepend_list()  {
472      #  strip the comments and then convert the dependency file into      #  strip the comments and then convert the dependency file into
473      #  two arrays: PNAME, DNAME      #  two arrays: PNAME, DNAME
474      cat $1 | sed -e 's/#.*$//g' \      cat $1 | sed -e 's/#.*$//g' \
475          | awk 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \          | $AWK 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \
476          > ./.pd_tmp          > ./.pd_tmp
477      source ./.pd_tmp      . ./.pd_tmp
478      rm -f ./.pd_tmp      rm -f ./.pd_tmp
479    
480      echo -n "PNAME = "${}      printf "PNAME = "${}
481  }  }
482    
483    
484  #  Explain usage  #  Explain usage
485  usage()  {  usage()  {
486      echo ""  cat <<EOF
487      echo "Usage: "$0" [OPTIONS]"  
488      echo "  where [OPTIONS] can be:"$'\n'  Usage: "$0" [OPTIONS]
489      echo "    -help | --help | -h | --h"    where [OPTIONS] can be:
490      echo "    -nooptfile | --nooptfile"  
491      echo "      -optfile NAME | --optfile NAME | -of NAME | --of NAME"      -help | --help | -h | --h
492      echo "      -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME"            Print this help message and exit.
493      echo "    -pdepend NAME | --pdepend NAME"  
494      echo "      -pdepend=NAME | --pdepend=NAME"      -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME
495      echo "    -pdefault NAME | --pdefault NAME"        -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME
496      echo "      -pdefault=NAME | --pdefault=NAME"            Use "NAME" as the adoptfile.  By default, the file at
497      echo "    -makefile NAME | -ma NAME"            "tools/adjoint_options/adjoint_default" will be used.
498      echo "      --makefile=NAME | -ma=NAME"  
499      echo "    -platform NAME | --platform NAME | -pl NAME | --pl NAME"      -nooptfile | --nooptfile
500      echo "      -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"        -optfile NAME | --optfile NAME | -of NAME | --of NAME
501      echo "    -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"        -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
502      echo "      -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME"            Use "NAME" as the optfile.  By default, an attempt will be
503      echo "    -mods NAME | --mods NAME | -mo NAME | --mo NAME"            made to find an appropriate "standard" optfile in the
504      echo "      -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME"            tools/build_options/ directory.
505      echo "    -disable NAME | --disable NAME"  
506      echo "      -disable=NAME | --disable=NAME"      -pdepend NAME | --pdepend NAME
507      echo "    -enable NAME | --enable NAME"        -pdepend=NAME | --pdepend=NAME
508      echo "      -enable=NAME | --enable=NAME"            Get package dependency information from "NAME".
509      echo "    -noopt NAME | --noopt NAME"  
510      echo "      -noopt=NAME | --noopt=NAME"      -pdefault NAME | --pdefault NAME
511  #    echo "    -cpp NAME | --cpp NAME"        -pdefault=NAME | --pdefault=NAME
512  #    echo "      -cpp=NAME | --cpp=NAME"            Get the default package list from "NAME".
513      echo "    -fortran NAME | --fortran NAME | -fc NAME | --fc NAME"  
514      echo "      -fc=NAME | --fc=NAME"      -make NAME | -m NAME
515      echo "    -[no]ieee | --[no]ieee"        --make=NAME | -m=NAME
516      echo "    -[no]mpi | --[no]mpi"            Use "NAME" for the MAKE program. The default is "make" but
517      echo "    -[no]jam | --[no]jam"$'\n'            many platforms, "gmake" is the preferred choice.
518      echo "  and NAME is a string such as:"$'\n'  
519      echo "    --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'"      -makefile NAME | -mf NAME
520      echo "    -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'"        --makefile=NAME | -mf=NAME
521      echo "    -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"$'\n'            Call the makefile "NAME".  The default is "Makefile".
522      echo "  which, depending upon your shell, may need to be single-quoted"  
523      echo "  if it contains spaces, dashes, or other special characters."      -makedepend NAME | -md NAME
524          --makedepend=NAME | -md=NAME
525              Use "NAME" for the MAKEDEPEND program.
526    
527        -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
528          -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
529              Specify the location of the MITgcm ROOTDIR as "NAME".
530              By default, genamke will try to find the location by
531              looking in parent directories (up to the 5th parent).
532    
533        -mods NAME | --mods NAME | -mo NAME | --mo NAME
534          -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
535              Here, "NAME" specifies a list of directories that are
536              used for additional source code.  Files found in the
537              "mods list" are given preference over files of the same
538              name found elsewhere.
539    
540        -disable NAME | --disable NAME
541          -disable=NAME | --disable=NAME
542              Here "NAME" specifies a list of packages that we don't
543              want to use.  If this violates package dependencies,
544              genamke will exit with an error message.
545    
546        -enable NAME | --enable NAME
547          -enable=NAME | --enable=NAME
548              Here "NAME" specifies a list of packages that we wish
549              to specifically enable.  If this violates package
550              dependencies, genamke will exit with an error message.
551    
552        -standarddirs NAME | --standarddirs NAME
553          -standarddirs=NAME | --standarddirs=NAME
554              Here, "NAME" specifies a list of directories to be
555              used as the "standard" code.
556    
557        -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
558          -fc=NAME | --fc=NAME
559              Use "NAME" as the fortran compiler.  By default, genmake
560              will search for a working compiler by trying a list of
561              "usual suspects" such as g77, f77, etc.
562    
563        -cc NAME | --cc NAME | -cc=NAME | --cc=NAME
564              Use "NAME" as the C compiler.  By default, genmake
565              will search for a working compiler by trying a list of
566              "usual suspects" such as gcc, c89, cc, etc.
567    
568        -[no]ieee | --[no]ieee
569              Do or don't use IEEE numerics.  Note that this option
570              *only* works if it is supported by the OPTFILE that
571              is being used.
572    
573        -ignoretime | -ignore_time | --ignoretime | --ignore_time
574              Ignore all the "wall clock" routines entirely.  This will
575              not in any way hurt the model results -- it simply means
576              that the code that checks how long the model spends in
577              various routines will give junk values.
578    
579        -ts | --ts
580              Produce timing information per timestep
581        -papis | --papis
582              Produce summary MFlop/s with PAPI per timestep
583        -foolad | --foolad
584              Fool the AD code generator
585        -papi | --papi
586              Performance analysis with PAPI
587        -hpmt | --hpmt
588              Performance analysis with the HPM Toolkit
589    
590        -gsl | --gsl
591              Use GSL to control floating point rounding and precision
592    
593        -mpi | --mpi
594              Include MPI header files and link to MPI libraries
595        -mpi=PATH | --mpi=PATH
596              Include MPI header files and link to MPI libraries using MPI_ROOT
597              set to PATH. i.e. Include files from \$PATH/include, link to libraries
598              from \$PATH/lib and use binaries from \$PATH/bin.
599    
600        -es | --es | -embed-source | --embed-source
601              Embed a tarball containing the full source code
602              (including the Makefile, etc.) used to build the
603              executable [off by default]
604    
605        -bash NAME
606              Explicitly specify the Bourne or BASH shell to use
607    
608      While it is most often a single word, the "NAME" variables specified
609      above can in many cases be a space-delimited string such as:
610    
611        --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'
612        -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'
613        -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
614    
615      which, depending upon your shell, may need to be single-quoted.
616    
617      For more detailed genmake documentation, please see:
618    
619        http://mitgcm.org/devel_HOWTO/
620    
621    EOF
622    
623      exit 1      exit 1
624  }  }
625    
626  # Dump all important state  #  Build a CPP macro to automate calling C routines from FORTRAN
627  dump_state()  {  get_fortran_c_namemangling()  {
628      fname=$1  
629      echo " " > $fname      #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
630        if test ! "x$FC_NAMEMANGLE" = x ; then
631            return 0
632        fi
633    
634        default_nm="#define FC_NAMEMANGLE(X) X ## _"
635        
636        cat > genmake_test.c <<EOF
637    void tcall( char * string ) { tsub( string ); }
638    EOF
639        $MAKE genmake_test.o >> genmake_warnings 2>&1
640        RETVAL=$?
641        if test "x$RETVAL" != x0 ; then
642            FC_NAMEMANGLE=$default_nm
643            cat <<EOF>> genmake_errors
644    
645    WARNING: C test compile fails
646    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
647    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
648    EOF
649            return 1
650        fi
651        c_tcall=`nm genmake_test.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
652      RETVAL=$?      RETVAL=$?
653      if test "x${RETVAL}" = x ; then      if test "x$RETVAL" != x0 ; then
654          echo "Error: cannot write to $fname"          FC_NAMEMANGLE=$default_nm
655          exit 1          cat <<EOF>> genmake_warnings
656    
657    WARNING: The "nm" command failed.
658    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
659    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
660    EOF
661            return 1
662        fi
663        cat > genmake_tcomp.$FS <<EOF
664          subroutine tcall( string )
665          character*(*) string
666          call tsub( string )
667          end
668    EOF
669        $FC $FFLAGS -c genmake_tcomp.$FS >> genmake_warnings 2>&1
670        RETVAL=$?
671        if test "x$RETVAL" != x0 ; then
672            FC_NAMEMANGLE=$default_nm
673            cat <<EOF>> genmake_warnings
674    
675    WARNING: FORTRAN test compile fails -- please see "genmake_errors"
676    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
677    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
678    EOF
679            return 1
680        fi
681        f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
682        RETVAL=$?
683        if test "x$RETVAL" != x0 ; then
684            FC_NAMEMANGLE=$default_nm
685            cat <<EOF>> genmake_warnings
686    
687    WARNING: The "nm" command failed.
688    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
689    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
690    EOF
691            return 1
692        fi
693    
694        c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
695        f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
696        c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
697        f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
698    
699        nmangle="X"
700        if test "x$c_a" != "x$f_a" ; then
701            comm="echo x$f_a | sed -e 's|x$c_a||'"
702            a=`eval $comm`
703            nmangle="$a ## $nmangle"
704      fi      fi
705      echo "makefile "$makefile > $fname      if test "x$c_b" != "x$f_b" ; then
706            comm="echo x$f_b | sed -e 's|x$c_b||'"
707            b=`eval $comm`
708            nmangle="$nmangle ## $b"
709        fi
710    
711        FC_NAMEMANGLE="#define FC_NAMEMANGLE(X)  $nmangle"
712    
713        #  cleanup the testing files
714        rm -f genmake_tcomp.* genmake_test.*
715    }
716    
717    
718    check_HAVE_CLOC()  {
719        get_fortran_c_namemangling
720        cat <<EOF > genmake_tc_1.c
721    $FC_NAMEMANGLE
722    #include <stdio.h>
723    #include <stdlib.h>
724    #include <unistd.h>
725    #include <assert.h>
726    #include <sys/time.h>
727    void FC_NAMEMANGLE(cloc) ( double *curtim )
728    {
729     struct timeval tv1;
730     gettimeofday(&tv1 , (void *)NULL );
731     *curtim =  (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
732     *curtim = *curtim/1.E6;
733    }
734    EOF
735        make genmake_tc_1.o >> genmake_warnings 2>&1
736        RET_C=$?
737        cat <<EOF > genmake_tc_2.$FS
738          program hello
739          REAL*8 wtime
740          external cloc
741          call cloc(wtime)
742          print *," HELLO WORLD", wtime
743          end
744    EOF
745        $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_warnings 2>&1
746        RET_F=$?
747        test -x ./genmake_tc  &&  ./genmake_tc >> genmake_warnings 2>&1
748        RETVAL=$?
749        if test "x$RETVAL" = x0 ; then
750            HAVE_CLOC=t
751            DEFINES="$DEFINES -DHAVE_CLOC"
752        fi
753        rm -f genmake_tc*
754  }  }
755    
756    
757  #eh3 # This is the generic configuration.  check_HAVE_SIGREG()  {
758  #eh3 set LN         = ( 'ln -s' )      get_fortran_c_namemangling
759  #eh3 set CPP        = ( '/lib/cpp -P' )      cat <<EOF > genmake_tc_1.c
760  #eh3 set S64        = ( '$(TOOLSDIR)/set64bitConst.sh' )  $FC_NAMEMANGLE
761  #eh3 set KPP        = (  )  #include <stdlib.h>
762  #eh3 set FC         = ( 'f77' )  #include <stdio.h>
763  #eh3 set LINK       = $FC  #include <signal.h>
764  #eh3 set MAKEDEPEND = ( 'makedepend' )  #include <errno.h>
765  #eh3 set INCLUDES   = ( -I. )  #include <ucontext.h>
766  #eh3 set FFLAGS     = (  )  
767  #eh3 set FOPTIM     = (  )  int * ip;
768  #eh3 set CFLAGS     = (  )  
769  #eh3 set KFLAGS1    = (  )  static void killhandler(
770  #eh3 set KFLAGS2    = (  )      unsigned int sn, siginfo_t  si, struct ucontext *sc )
771  #eh3 set LIBS       = (  )  {
772  #eh3 set KPPFILES   = (  )      *ip = *ip + 1;
773  #eh3 if (! $?NOOPTFILES ) set NOOPTFILES = (  )      return;
774  #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = (  )  }
775    
776    void FC_NAMEMANGLE(sigreg) (int * aip)
777    {
778        struct sigaction s;
779        ip = aip;
780        s.sa_flags = SA_SIGINFO;
781        s.sa_sigaction = (void *)killhandler;
782        if(sigaction (SIGTERM,&s,(struct sigaction *)NULL)) {
783            printf("Sigaction returned error = %d\n", errno);
784            exit(0);
785        }
786        return;
787    }
788    EOF
789        make genmake_tc_1.o >> genmake_warnings 2>&1
790        RET_C=$?
791        cat <<EOF > genmake_tc_2.$FS
792          program hello
793          integer anint
794          common /iv/ anint
795          external sigreg
796          call sigreg(anint)
797          end
798    EOF
799        echo >> genmake_warnings
800        echo "running: check_HAVE_SIGREG()" >> genmake_warnings
801        cat genmake_tc_2.$FS >> genmake_warnings
802        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
803        echo $COMM >> genmake_warnings
804        $COMM >> genmake_warnings 2>&1
805        RETVAL=$?
806        if test "x$RETVAL" = x0 ; then
807            HAVE_SIGREG=t
808            DEFINES="$DEFINES -DHAVE_SIGREG"
809        fi
810        rm -f genmake_tc*
811    }
812    
813    
814    check_HAVE_SETRLSTK()  {
815        get_fortran_c_namemangling
816        cat <<EOF > genmake_tc_1.c
817    $FC_NAMEMANGLE
818    #include <sys/time.h>
819    #include <sys/resource.h>
820    #include <unistd.h>
821    void FC_NAMEMANGLE(setrlstk) ()
822    {
823        struct rlimit rls;
824        rls.rlim_cur = RLIM_INFINITY;
825        rls.rlim_max = RLIM_INFINITY;
826        setrlimit(RLIMIT_STACK, &rls);
827        return;
828    }
829    EOF
830        make genmake_tc_1.o >> genmake_warnings 2>&1
831        RET_C=$?
832        cat <<EOF > genmake_tc_2.$FS
833          program hello
834          external setrlstk
835          call setrlstk()
836          end
837    EOF
838        echo >> genmake_warnings
839        echo "running: check_HAVE_SETRLSTK()" >> genmake_warnings
840        cat genmake_tc_2.$FS >> genmake_warnings
841        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
842        echo $COMM >> genmake_warnings
843        $COMM >> genmake_warnings 2>&1
844        RETVAL=$?
845        if test "x$RETVAL" = x0 ; then
846            HAVE_SETRLSTK=t
847            DEFINES="$DEFINES -DHAVE_SETRLSTK"
848        fi
849        rm -f genmake_tc*
850    }
851    
852    
853    check_HAVE_STAT()  {
854        get_fortran_c_namemangling
855        cat <<EOF > genmake_tc_1.c
856    $FC_NAMEMANGLE
857    #include <stdio.h>
858    #include <stdlib.h>
859    #include <unistd.h>
860    #include <sys/stat.h>
861    #include <sys/types.h>
862    void FC_NAMEMANGLE(tfsize) ( int *nbyte )
863    {
864        char name[512];
865        struct stat astat;
866    
867        name[0] = 'a'; name[1] = '\0';
868        if (! stat(name, &astat))
869            *nbyte = (int)(astat.st_size);
870        else
871            *nbyte = -1;
872    }
873    EOF
874        make genmake_tc_1.o >> genmake_tc.log 2>&1
875        RET_C=$?
876        cat <<EOF > genmake_tc_2.$FS
877          program hello
878          integer nbyte
879          call tfsize(nbyte)
880          print *," HELLO WORLD", nbyte
881          end
882    EOF
883        echo >> genmake_warnings
884        echo "running: check_HAVE_STAT()" >> genmake_warnings
885        cat genmake_tc_2.$FS >> genmake_warnings
886        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
887        echo $COMM >> genmake_warnings
888        $COMM >> genmake_tc.log 2>&1
889        RETVAL=$?
890        if test "x$RETVAL" = x0 ; then
891            HAVE_STAT=t
892            DEFINES="$DEFINES -DHAVE_STAT"
893        fi
894        rm -f genmake_tc*
895    }
896    
897    
898    check_netcdf_libs()  {
899        if test ! "x$SKIP_NETCDF_CHECK" = x ; then
900            return
901        fi
902        echo >> genmake_warnings
903        echo "running: check_netcdf_libs()" >> genmake_warnings
904        cat <<EOF > genmake_tnc.F
905          program fgennc
906    #include "netcdf.inc"
907    EOF
908        if test ! "x$MPI" = x ; then
909            echo '#include "mpif.h"' >> genmake_tnc.F
910        fi
911        cat <<EOF >> genmake_tnc.F
912          integer iret, ncid, xid
913          iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
914          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
915          iret = nf_def_dim(ncid, 'X', 11, xid)
916          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
917          iret = nf_close(ncid)
918          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
919          end
920    EOF
921        echo "===  genmake_tnc.F  ===" > genmake_tnc.log
922        cat genmake_tnc.F >> genmake_tnc.log
923        echo "===  genmake_tnc.F  ===" >> genmake_tnc.log
924        RET_CPP=f
925        COMM="$CPP $DEFINES $INCLUDES genmake_tnc.F"
926        echo "$COMM" >> genmake_tnc.log
927        $COMM > genmake_tnc.$FS 2>/dev/null  &&  RET_CPP=t
928        if test "x$RET_CPP" = xf ; then
929            echo "  WARNING: CPP failed to pre-process the netcdf test." \
930                >> genmake_tnc.log
931            echo "    Please check that \$INCLUDES is properly set." \
932                >> genmake_tnc.log
933        fi
934        echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.$FS  \ " >> genmake_tnc.log
935        echo "  &&  $LINK -o genmake_tnc.o $LIBS" >> genmake_tnc.log
936        $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
937            &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
938        RET_COMPILE=$?
939        cat genmake_tnc.log >> genmake_warnings
940    
941        #EH3  Remove test program execution for machines that either disallow
942        #EH3  execution or cannot support it (eg. cross-compilers)
943        #EH3
944        #EH3 test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1
945        #EH3 RETVAL=$?
946        #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
947    
948        if test "x$RET_COMPILE" = x0 ; then
949            HAVE_NETCDF=t
950        else
951            # try again with "-lnetcdf" added to the libs
952            echo "try again with added '-lnetcdf'" > genmake_tnc.log
953            echo "$CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS \ " >> genmake_tnc.log
954            echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
955            echo " &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
956            $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null  \
957                &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
958                &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
959            RET_COMPILE=$?
960            cat genmake_tnc.log >> genmake_warnings
961            if test "x$RET_COMPILE" = x0 ; then
962                LIBS="$LIBS -lnetcdf"
963                HAVE_NETCDF=t
964            fi
965        fi
966        rm -f genmake_tnc*
967    }
968    
969    
970    
971    ###############################################################################
972    #   Sequential part of script starts here
973    ###############################################################################
974    
975  #  Set defaults here  #  Set defaults here
976    COMMANDL="$0 $@"
977    
978  PLATFORM=  PLATFORM=
979  LN=  LN=
980  S64=  S64=
981  KPP=  KPP=
982  FC=  #FC=
983    #CC=gcc
984    #CPP=
985  LINK=  LINK=
986    DEFINES=
987  PACKAGES=  PACKAGES=
988  ENABLE=  ENABLE=
989  DISABLE=  DISABLE=
990  MAKEFILE=  # MAKEFILE=
991  MAKEDEPEND=  # MAKEDEPEND=
992  PDEPEND=  PDEPEND=
993    DUMPSTATE=t
994  PDEFAULT=  PDEFAULT=
995  OPTFILE=  OPTFILE=
996  INCLUDES=-I.  INCLUDES="-I. $INCLUDES"
997  FFLAGS=  FFLAGS=
998  FOPTIM=  FOPTIM=
999  CFLAGS=  CFLAGS=
1000  KFLAGS1=  KFLAGS1=
1001  KFLAGS2=  KFLAGS2=
1002    #LDADD=
1003  LIBS=  LIBS=
1004  KPPFILES=  KPPFILES=
1005  NOOPTFILES=  NOOPTFILES=
1006  NOOPTFLAGS=  NOOPTFLAGS=
1007    MPI=
1008    MPIPATH=
1009    TS=
1010    PAPIS=
1011    FOOLAD=
1012    PAPI=
1013    HPMT=
1014    GSL=
1015    HAVE_TEST_L=
1016    
1017    # DEFINES checked by test compilation or command-line
1018    HAVE_SYSTEM=
1019    HAVE_FDATE=
1020    FC_NAMEMANGLE=
1021    HAVE_CLOC=
1022    HAVE_SETRLSTK=
1023    HAVE_STAT=
1024    HAVE_NETCDF=
1025    HAVE_ETIME=
1026    IGNORE_TIME=
1027    
1028  MODS=  MODS=
1029  TOOLSDIR=  TOOLSDIR=
1030  SOURCEDIRS=  SOURCEDIRS=
1031  INCLUDEDIRS=  INCLUDEDIRS=
1032    STANDARDDIRS="USE_THE_DEFAULT"
1033    
1034    G2ARGS=
1035    BASH=
1036    PWD=`pwd`
1037    test "x$MAKE" = x  &&  MAKE=make
1038    test "x$AWK" = x   &&  AWK=awk
1039    EMBED_SRC=
1040    THISHOST=`hostname`
1041    THISCWD=`pwd`
1042    THISDATE=`date`
1043    THISUSER=`echo $USER`
1044    THISVER=
1045    MACHINE=`uname -a`
1046    EXECUTABLE=
1047    EXEHOOK=
1048    EXEDIR=
1049    PACKAGES_CONF=
1050    IEEE=
1051    if test "x$MITGCM_IEEE" != x ; then
1052        IEEE=$MITGCM_IEEE
1053    fi
1054    FS=
1055    FS90=
1056    
1057    AUTODIFF_PKG_USED=f
1058    AD_OPTFILE=
1059    TAF=
1060    AD_TAF_FLAGS=
1061    FTL_TAF_FLAGS=
1062    SVD_TAF_FLAGS=
1063    TAF_EXTRA=
1064    TAMC=
1065    AD_TAMC_FLAGS=
1066    FTL_TAF_FLAGS=
1067    SVD_TAMC_FLAGS=
1068    TAMC_EXTRA=
1069    
1070    
1071    #  The following state can be set directly by command-line switches
1072    gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"
1073    gm_s2="FC CPP IEEE TS PAPIS PAPI HPMT GSL MPI JAM DUMPSTATE STANDARDDIRS"
1074    
1075    #  The following state is not directly set by command-line switches
1076    gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
1077    gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
1078    gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE"
1079    gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
1080    gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME"
1081    
1082    #  The following are all related to adjoint/tangent-linear stuff
1083    gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
1084    gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
1085    gm_s12="TAF_EXTRA TAMC_EXTRA"
1086    
1087    gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"
1088    gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
1089    
1090    cat <<EOF
1091    
1092    GENMAKE :
1093    
1094    A program for GENerating MAKEfiles for the MITgcm project.  For a
1095    quick list of options, use "genmake -h" or for more detail see:
1096    
1097      http://mitgcm.org/devel_HOWTO/
1098    
1099    EOF
1100    
1101    echo "===  Processing options files and arguments  ==="
1102    gm_local="genmake_local"
1103    for i in . $MODS ; do
1104        if test -r $i/$gm_local ; then
1105            . $i/$gm_local
1106            break
1107        fi
1108    done
1109    printf "  getting local config information:  "
1110    if test -f $gm_local ; then
1111        echo "using $gm_local"
1112        . $gm_local
1113        # echo "DISABLE=$DISABLE"
1114        # echo "ENABLE=$ENABLE"
1115    else
1116        echo "none found"
1117    fi
1118    
1119    #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
1120    #OPTIONS=
1121    #n=0
1122    #for i ; do
1123    #   echo "$i  $n"
1124    #   setvar="OPTIONS[$n]='$i'"
1125    #   #  echo "  $setvar"
1126    #   eval "$setvar"
1127    #   n=$(( $n + 1 ))
1128    #done
1129    #parse_options
1130    ac_prev=
1131    for ac_option in "$@" ; do
1132    
1133        G2ARGS="$G2ARGS \"$ac_option\""
1134    
1135        # If the previous option needs an argument, assign it.
1136        if test -n "$ac_prev"; then
1137            eval "$ac_prev=\$ac_option"
1138            ac_prev=
1139            continue
1140        fi
1141        
1142        ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
1143        
1144        case $ac_option in
1145            
1146            -help | --help | -h | --h)
1147                usage ;;
1148            
1149            -nooptfile | --nooptfile)
1150                OPTFILE="NONE" ;;
1151            -optfile | --optfile | -of | --of)
1152                ac_prev=OPTFILE ;;
1153            -optfile=* | --optfile=* | -of=* | --of=*)
1154                OPTFILE=$ac_optarg ;;
1155            
1156            -adoptfile | --adoptfile | -adof | --adof)
1157                ac_prev=AD_OPTFILE ;;
1158            -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
1159                AD_OPTFILE=$ac_optarg ;;
1160            
1161            -pdepend | --pdepend)
1162                ac_prev=PDEPEND ;;
1163            -pdepend=* | --pdepend=*)
1164                PDEPEND=$ac_optarg ;;
1165            
1166            -pdefault | --pdefault)
1167                ac_prev=PDEFAULT ;;
1168            -pdefault=* | --pdefault=*)
1169                PDEFAULT=$ac_optarg ;;
1170            
1171            -make | --make | -m | --m)
1172                ac_prev=MAKE ;;
1173            -make=* | --make=* | -m=* | --m=*)
1174                MAKE=$ac_optarg ;;
1175            
1176            -bash | --bash)
1177                ac_prev=BASH ;;
1178            -bash=* | --bash=*)
1179                BASH=$ac_optarg ;;
1180            
1181            -makedepend | --makedepend | -md | --md)
1182                ac_prev=MAKEDEPEND ;;
1183            -makedepend=* | --makedepend=* | -md=* | --md=*)
1184                MAKEDEPEND=$ac_optarg ;;
1185            
1186            -makefile | --makefile | -ma | --ma)
1187                ac_prev=MAKEFILE ;;
1188            -makefile=* | --makefile=* | -ma=* | --ma=*)
1189                MAKEFILE=$ac_optarg ;;
1190            
1191            -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
1192                echo "ERROR: The platform option has been removed.  Please specify"
1193                echo "  the build options using the \"optfile\" mechanism."
1194                echo
1195                usage
1196                ;;
1197            
1198            -rootdir | --rootdir | -rd | --rd)
1199                ac_prev=ROOTDIR ;;
1200            -rootdir=* | --rootdir=* | -rd=* | --rd=*)
1201                ROOTDIR=$ac_optarg ;;
1202            
1203            -mods | --mods | -mo | --mo)
1204                ac_prev=MODS ;;
1205            -mods=* | --mods=* | -mo=* | --mo=*)
1206                MODS=$ac_optarg ;;
1207            
1208            -disable | --disable)
1209                ac_prev=DISABLE ;;
1210            -disable=* | --disable=*)
1211                DISABLE=$ac_optarg ;;
1212            
1213            -enable | --enable)
1214                ac_prev=ENABLE ;;
1215            -enable=* | --enable=*)
1216                ENABLE=$ac_optarg ;;
1217            
1218            -standarddirs | --standarddirs)
1219                ac_prev=STANDARDDIRS ;;
1220            -standarddirs=* | --standarddirs=*)
1221                STANDARDDIRS=$ac_optarg ;;
1222    
1223    #           -cpp | --cpp)
1224    #               ac_prev=cpp ;;
1225    #           -cpp=* | --cpp=*)
1226    #               CPP=$ac_optarg ;;
1227            
1228            -cc | --cc)
1229                ac_prev=CC ;;
1230            -cc=* | --cc=*)
1231                CC=$ac_optarg ;;
1232            
1233            -fortran | --fortran | -fc | --fc)
1234                ac_prev=FC ;;
1235            -fc=* | --fc=*)
1236                FC=$ac_optarg ;;
1237            
1238            -fs | --fs)
1239                ac_prev=FS ;;
1240            -fs=* | --fs=*)
1241                FS=$ac_optarg ;;
1242            
1243            -fs90 | --fs90)
1244                ac_prev=FS90 ;;
1245            -fs90=* | --fs90=*)
1246                FS90=$ac_optarg ;;
1247            
1248            -ieee | --ieee)
1249                IEEE=true ;;
1250            -noieee | --noieee)
1251                IEEE= ;;
1252    
1253            -ts | --ts)
1254                TS=true ;;
1255            -papis | --papis)
1256                PAPIS=true ;;
1257            -foolad | --foolad)
1258                FOOLAD=true ;;
1259            -papi | --papi)
1260                PAPI=true ;;
1261            -hpmt | --hpmt)
1262                HPMT=true ;;
1263    
1264            -gsl | --gsl)
1265                GSL=true ;;
1266    
1267            -mpi | --mpi)
1268                MPI=true ;;
1269            -mpi=* | --mpi=*)
1270                MPIPATH=$ac_optarg
1271                MPI=true ;;
1272            
1273    #       -jam | --jam)
1274    #           JAM=1 ;;
1275    #       -nojam | --nojam)
1276    #           JAM=0 ;;
1277            
1278            -ds | --ds)
1279                DUMPSTATE=t ;;
1280            
1281            -taf_extra | --taf_extra)
1282                ac_prev=TAF_EXTRA ;;
1283            -taf_extra=* | --taf_extra=*)
1284                TAF_EXTRA=$ac_optarg ;;
1285    
1286            -tamc_extra | --tamc_extra)
1287                ac_prev=TAMC_EXTRA ;;
1288            -tamc_extra=* | --tamc_extra=*)
1289                TAMC_EXTRA=$ac_optarg ;;
1290            
1291            -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1292                IGNORE_TIME="-DIGNORE_TIME" ;;
1293    
1294            -es | --es | -embed-source | --embed-source)
1295                EMBED_SRC=t ;;
1296    
1297            -*)
1298                echo "Error: unrecognized option: "$ac_option
1299                usage
1300                ;;
1301            
1302            *)
1303                echo "Error: unrecognized argument: "$ac_option
1304                usage
1305                ;;
1306            
1307        esac
1308        
1309    done
1310    
1311    
1312    if test -f ./.genmakerc ; then
1313        echo
1314        echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
1315        echo "  file.  This file format is no longer supported.  Please see:"
1316        echo
1317        echo "    http://mitgcm.org/devel_HOWTO/"
1318        echo
1319        echo "  for directions on how to setup and use the new \"genmake2\" input"
1320        echo "  files and send an email to MITgcm-support@mitgcm.org if you want help."
1321        echo
1322    fi
1323    
1324    #  Find the MITgcm ${ROOTDIR}
1325    if test "x${ROOTDIR}" = x ; then
1326        tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1327        if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
1328            ROOTDIR=".."
1329        else
1330            for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1331                if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
1332                    ROOTDIR=$d
1333                    printf "Warning:  ROOTDIR was not specified but there appears to be"
1334                    echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
1335                    break
1336                fi
1337            done
1338        fi
1339    fi
1340    if test "x${ROOTDIR}" = x ; then
1341        echo "Error: Cannot determine ROOTDIR for MITgcm code."
1342        echo "  Please specify a ROOTDIR using either an options "
1343        echo "  file or a command-line option."
1344        exit 1
1345    fi
1346    if test ! -d ${ROOTDIR} ; then
1347        echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
1348        exit 1
1349    fi
1350    
1351    #  Find the MITgcm ${THISVER}
1352    if test -f "${ROOTDIR}/doc/tag-index" ; then
1353        THISVER=`grep '^checkpoint' ${ROOTDIR}/doc/tag-index | head -1`
1354    fi
1355    
1356    if test "x$MAKEFILE" = x ; then
1357        MAKEFILE="Makefile"
1358    fi
1359    
1360    echo "  getting OPTFILE information:  "
1361    if test "x${OPTFILE}" = x ; then
1362        if test "x$MITGCM_OF" = x ; then
1363            echo "Warning: no OPTFILE specified so we'll look for possible settings"
1364            printf "\n===  Searching for possible settings for OPTFILE  ===\n"
1365            find_possible_configs
1366        else
1367            OPTFILE=$MITGCM_OF
1368        fi
1369    fi
1370    if test "x$OPTFILE" != xNONE ; then
1371        if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
1372            echo "    using OPTFILE=\"$OPTFILE\""
1373            . "$OPTFILE"
1374            RETVAL=$?
1375            if test "x$RETVAL" != x0 ; then
1376                printf "Error: failed to source OPTFILE \"$OPTFILE\""
1377                echo "--please check that variable syntax is bash-compatible"
1378                exit 1
1379            fi
1380            if test "x$DUMPSTATE" != xf ; then
1381                cp -f $OPTFILE "genmake_optfile"
1382            fi
1383        else
1384            echo "Error: can't read OPTFILE=\"$OPTFILE\""
1385            exit 1
1386        fi
1387    fi
1388    
1389    echo "  getting AD_OPTFILE information:  "
1390    if test "x${AD_OPTFILE}" = x ; then
1391        if test "x$MITGCM_AD_OF" = x ; then
1392            AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
1393        else
1394            AD_OPTFILE=$MITGCM_AD_OF
1395        fi
1396    fi
1397    if test "x${AD_OPTFILE}" != xNONE ; then
1398        if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
1399            echo "    using AD_OPTFILE=\"$AD_OPTFILE\""
1400            . "$AD_OPTFILE"
1401            RETVAL=$?
1402            if test "x$RETVAL" != x0 ; then
1403                printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
1404                echo "--please check that variable syntax is bash-compatible"
1405                exit 1
1406            fi
1407            if test "x$DUMPSTATE" != xf ; then
1408                cp -f $AD_OPTFILE "genmake_ad_optfile"
1409            fi
1410        else
1411            echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
1412            exit 1
1413        fi
1414    fi
1415    
1416    #====================================================================
1417    #  Set default values if not set by the optfile
1418    #
1419    #  Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
1420    #  either set defaults or complain and abort!
1421    if test ! "x$BASH" = x ; then
1422        # add a trailing space so that it works within the Makefile syntax (see below)
1423        BASH="$BASH "
1424    fi
1425    if test "x$FC" = x ; then
1426        cat <<EOF 1>&2
1427    
1428    Error: no Fortran compiler: please specify using one of the following:
1429      1) within the options file ("FC=...") as specified by "-of=OPTFILE"
1430      2) the "-fc=XXX" command-line option
1431      3) the "./genmake_local" file
1432    EOF
1433        exit 1
1434    fi
1435    if test "x$CC" = x ; then
1436        CC=cc
1437    #     cat <<EOF 1>&2
1438    # Error: no C compiler: please specify using one of the following:
1439    #   1) within the options file ("CC=...") as specified by "-of=OPTFILE"
1440    #   2) the "-cc=XXX" command-line option
1441    #   3) the "./genmake_local" file
1442    # EOF
1443    #     exit 1
1444    fi
1445    if test "x$LINK" = x ; then
1446        LINK=$FC
1447    fi
1448    if test "x$MAKE" = x ; then
1449        MAKE="make"
1450    fi
1451    if test "x$CPP" = x ; then
1452        CPP=cpp
1453    fi
1454    #EH3 === UGLY ===
1455    #  The following is an ugly little hack to check for $CPP in /lib/ and
1456    #  it should eventually be replaced with a more general function that
1457    #  searches a combo of the user's path and a list of "usual suspects"
1458    #  to find the correct location for binaries such as $CPP.
1459    for i in " " "/lib/" ; do
1460        echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1461    done
1462    #EH3 === UGLY ===
1463    echo "#define A a" | $CPP > test_cpp 2>&1
1464    RETVAL=$?
1465    if test "x$RETVAL" != x0 ; then
1466        cat <<EOF 1>&2
1467    
1468    Error: C pre-processor "$CPP" failed the test case: please specify using:
1469    
1470      1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
1471      2) the "./genmake_local" file
1472      3) with the CPP environment variable
1473    
1474    EOF
1475        exit 1
1476    else
1477        rm -f test_cpp
1478    fi
1479    look_for_makedepend
1480    if test "x$LN" = x ; then
1481        LN="ln -s"
1482    fi
1483    echo "test" > genmake_test_ln
1484    $LN genmake_test_ln genmake_tlink
1485    RETVAL=$?
1486    if test "x$RETVAL" != x0 ; then
1487        cat <<EOF 1>&2
1488    
1489    Error: The command "ln -s" failed -- please specify a working soft-link
1490      command in the optfile.
1491    
1492    EOF
1493        exit 1
1494    fi
1495    test -L genmake_tlink > /dev/null 2>&1
1496    RETVAL=$?
1497    if test "x$RETVAL" = x0 ; then
1498        HAVE_TEST_L=t
1499    fi
1500    rm -f genmake_test_ln genmake_tlink
1501    
1502    #  Check for broken *.F/*.f handling and fix if possible
1503    check_for_broken_Ff
1504    
1505    if test ! "x$MPI" = x ; then
1506          echo "  Turning on MPI cpp macros"
1507          DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
1508    fi
1509    
1510  PWD=`pwd`  if test ! "x$TS" = x ; then
1511  MAKE=make        echo "  Turning on timing per timestep"
1512  THISHOSTNAME=`hostname`        if test ! "x$FOOLAD" = x ; then
1513  THISCWD=`pwd`              DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP"
1514  THISDATE=`date`        else
1515  MACHINE=`uname -a`              DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1516          fi
1517    fi
1518    if test ! "x$PAPIS" = x ; then
1519          echo "  Turning on PAPI flop summary per timestep"
1520          echo "  Please make sure PAPIINC, PAPILIB are defined"
1521          if test ! "x$FOOLAD" = x ; then
1522                DEFINES="$DEFINES -DUSE_PAPI_FLOPS_SFP"
1523          else
1524                DEFINES="$DEFINES -DUSE_PAPI_FLOPS"
1525          fi
1526          INCLUDES="$INCLUDES $PAPIINC"
1527          LIBS="$LIBS $PAPILIB"
1528    fi
1529    if test ! "x$PAPI" = x ; then
1530          if test ! "x$PAPIS" = x ; then
1531              echo "  PAPI performance analysis and flop summary per timestep cannot co-exist!"
1532              echo "  Sticking with PAPI flop summary per timestep!"
1533          else
1534              echo "  Turning on performance analysis with PAPI"
1535              echo "  Please make sure PAPIINC, PAPILIB are defined"
1536              DEFINES="$DEFINES -DUSE_PAPI"
1537              INCLUDES="$INCLUDES $PAPIINC"
1538              LIBS="$LIBS $PAPILIB"
1539          fi
1540    fi
1541    if test ! "x$HPMT" = x ; then
1542          if test ! "x$PAPI" = x ; then
1543              echo "  PAPI and the HPM Toolkit cannot co-exist!"
1544              echo "  Sticking with PAPI!"
1545          else
1546              echo "  Turning on performance analysis with the HPM Toolkit"
1547              echo "  Please make sure HPMTINC, HPMTLIB are defined"
1548              DEFINES="$DEFINES -DUSE_LIBHPM"
1549              INCLUDES="$INCLUDES $HPMTINC"
1550              LIBS="$LIBS $HPMTLIB"
1551          fi
1552    fi
1553    if test ! "x$GSL" = x ; then
1554          echo "  Turning on use of GSL to control floating point calculations"
1555          echo "  Please make sure GSLINC, GSLLIB are defined"
1556          DEFINES="$DEFINES -DUSE_GSL_IEEE"
1557          INCLUDES="$INCLUDES $GSLINC"
1558          LIBS="$LIBS $GSLLIB"
1559    fi
1560    
1561  echo $'\n'"===  Processing options files and arguments  ==="  printf "\n===  Checking system libraries  ===\n"
1562  gm_local="./gm_local"  printf "  Do we have the system() command using $FC...  "
1563  echo -n "  getting local config information:  "  cat > genmake_tcomp.$FS <<EOF
1564  if test -e $gm_local ; then        program hello
1565      echo "using $gm_local"        call system('echo hi')
1566      source $gm_local        end
1567      echo "DISABLE=$DISABLE"$'\n'"ENABLE=$ENABLE"  EOF
1568    $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1569    RETVAL=$?
1570    if test "x$RETVAL" = x0 ; then
1571        HAVE_SYSTEM=t
1572        DEFINES="$DEFINES -DHAVE_SYSTEM"
1573        echo "yes"
1574  else  else
1575      echo "none found"      HAVE_SYSTEM=
1576        echo "no"
1577  fi  fi
1578    rm -f genmake_tcomp*
1579    
1580  #  echo "$0::$1:$2:$3:$4:$5:$6:$7:"  printf "  Do we have the fdate() command using $FC...  "
1581  OPTIONS=()  cat > genmake_tcomp.$FS <<EOF
1582  n=0        program hello
1583  for i ; do        CHARACTER*(128) string
1584     setvar="OPTIONS[$n]='$i'"        string = ' '
1585     #  echo "  $setvar"        call fdate( string )
1586     eval "$setvar"        print *, string
1587     n=$(( $n + 1 ))        end
1588  done  EOF
1589  parse_options  $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1590    RETVAL=$?
1591    if test "x$RETVAL" = x0 ; then
1592        HAVE_FDATE=t
1593        DEFINES="$DEFINES -DHAVE_FDATE"
1594        echo "yes"
1595    else
1596        HAVE_FDATE=
1597        echo "no"
1598    fi
1599    rm -f genmake_tcomp*
1600    
1601  echo "  getting OPTFILE information:  "  printf "  Do we have the etime() command using $FC...  "
1602  if test "x${OPTFILE}" = x ; then  cat > genmake_tcomp.$FS <<EOF
1603      echo "Warning: no OPTFILE specified so we'll look for possible settings"        program hello
1604      echo $'\n'"===  Searching for possible settings for OPTFILE  ==="        REAL*4 ACTUAL, TARRAY(2)
1605      find_possible_configs        EXTERNAL ETIME
1606  else        REAL*4 ETIME
1607      if test "x$OPTFILE" = xNONE ; then        actual = etime( tarray )
1608          echo "    OPTFILE=NONE so we'll try to use default settings"        print *, tarray
1609      else        end
1610          if test -f "$OPTFILE" -a -r "$OPTFILE" ; then  EOF
1611              echo "    using OPTFILE=\"$OPTFILE\""  $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1612              source "$OPTFILE"  RETVAL=$?
1613              RETVAL=$?  if test "x$RETVAL" = x0 ; then
1614              if test "x$RETVAL" != x0 ; then      HAVE_ETIME=t
1615                  echo -n "Error: failed to source OPTFILE \"$OPTFILE\""      DEFINES="$DEFINES -DHAVE_ETIME"
1616                  echo "--please check that variable syntax is bash-compatible"      echo "yes"
1617                  exit 1  else
1618              fi      HAVE_ETIME=
1619          else      echo "no"
1620              echo "Error: can't read OPTFILE=\"$OPTFILE\""  fi
1621              exit 1  rm -f genmake_tcomp*
1622          fi  
1623    printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
1624    check_HAVE_CLOC
1625    if test "x$HAVE_CLOC" != x ; then
1626        echo "yes"
1627    else
1628        echo "no"
1629        if test "x$EMBED_SRC" = xt ; then
1630            echo "    WARNING: you requested file embedding but it has"
1631            echo "      been disabled since C code cannot be called"
1632            EMBED_SRC=
1633      fi      fi
1634  fi  fi
1635    rm -f genmake_t*
1636    
1637    printf "  Can we unlimit the stack size using $FC...  "
1638    check_HAVE_SETRLSTK
1639    if test "x$HAVE_SETRLSTK" != x ; then
1640        echo "yes"
1641    else
1642        echo "no"
1643    fi
1644    rm -f genmake_t*
1645    
1646    printf "  Can we register a signal handler using $FC...  "
1647    check_HAVE_SIGREG
1648    if test "x$HAVE_SIGREG" != x ; then
1649        echo "yes"
1650    else
1651        echo "no"
1652    fi
1653    rm -f genmake_t*
1654    
1655    printf "  Can we use stat() through C calls...  "
1656    check_HAVE_STAT
1657    if test "x$HAVE_STAT" != x ; then
1658        echo "yes"
1659    else
1660        echo "no"
1661    fi
1662    rm -f genmake_t*
1663    
1664    printf "  Can we create NetCDF-enabled binaries...  "
1665    check_netcdf_libs
1666    if test "x$HAVE_NETCDF" != x ; then
1667        echo "yes"
1668    else
1669        echo "no"
1670    fi
1671    DEFINES="$DEFINES $IGNORE_TIME"
1672    
1673    if test "x$EMBED_SRC" = xt ; then
1674        build_embed_encode
1675    fi
1676    if test "x$EMBED_SRC" = xt ; then
1677        ENABLE="$ENABLE embed_files"
1678    fi
1679    
1680    
1681  echo $'\n'"===  Setting defaults  ==="  printf "\n===  Setting defaults  ===\n"
1682  echo -n "  Adding MODS directories:  "  printf "  Adding MODS directories:  "
1683  for d in $MODS ; do  for d in $MODS ; do
1684      if test ! -d $d ; then      if test ! -d $d ; then
1685          echo $'\n\n'"Error: MODS directory \"$d\" not found!"          echo
1686            echo "Error: MODS directory \"$d\" not found!"
1687          exit 1          exit 1
1688      else      else
1689          echo -n " $d"          printf " $d"
1690          SOURCEDIRS="$SOURCEDIRS $d"          SOURCEDIRS="$SOURCEDIRS $d"
1691          INCLUDEDIRS="$INCLUDEDIRS $d"          INCLUDEDIRS="$INCLUDEDIRS $d"
1692      fi      fi
1693  done  done
1694  echo  echo
1695    
 if test "x$MAKEFILE" = x ; then  
     MAKEFILE="Makefile"  
 fi  
1696  if test "x${PLATFORM}" = x ; then  if test "x${PLATFORM}" = x ; then
1697      PLATFORM=$p_PLATFORM      PLATFORM=$p_PLATFORM
1698  fi  fi
1699    
 if test "x${ROOTDIR}" = x ; then  
     if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then  
         ROOTDIR=".."  
     else  
         for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do  
             if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then  
                 ROOTDIR=$d  
                 echo -n "Warning:  ROOTDIR was not specified but there appears to be"  
                 echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."  
                 break  
             fi  
         done  
     fi  
 fi  
 if test "x${ROOTDIR}" = x ; then  
     echo "Error: Cannot determine ROOTDIR for MITgcm code."  
     echo "  Please specify a ROOTDIR using either an options "  
     echo "  file or a command-line option."  
     exit 1  
 fi  
 if test ! -d ${ROOTDIR} ; then  
     echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"  
     exit 1  
 fi  
   
1700  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
1701      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1702        if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
1703          EXEDIR=../exe          EXEDIR=../exe
1704      else      else
1705          EXEDIR=.          EXEDIR=.
# Line 430  if test "x${TOOLSDIR}" = x ; then Line 1714  if test "x${TOOLSDIR}" = x ; then
1714      TOOLSDIR="$ROOTDIR/tools"      TOOLSDIR="$ROOTDIR/tools"
1715  fi  fi
1716  if test ! -d ${TOOLSDIR} ; then  if test ! -d ${TOOLSDIR} ; then
1717      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
1718      exit 1      exit 1
1719  fi  fi
1720    if test "x$S64" = x ; then
1721        echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1
1722        RETVAL=$?
1723        if test "x${RETVAL}" = x0 ; then
1724            S64='$(TOOLSDIR)/set64bitConst.sh'
1725        else
1726            echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1
1727            RETVAL=$?
1728            if test "x${RETVAL}" = x0 ; then
1729                S64='$(TOOLSDIR)/set64bitConst.csh'
1730            else
1731                cat <<EOF
1732    
1733    ERROR: neither of the two default scripts:
1734    
1735        ${TOOLSDIR}/set64bitConst.sh
1736        ${TOOLSDIR}/set64bitConst.csh
1737    
1738      are working so please check paths or specify (with \$S64) a
1739      working version of this script.
1740    
1741    EOF
1742                exit 1
1743            fi
1744        fi
1745    fi
1746    THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
1747    
1748  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1749    
# Line 441  EXECUTABLE=${EXECUTABLE:-mitgcmuv} Line 1752  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1752  #  they appear as regular source code  #  they appear as regular source code
1753  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
1754      echo "  Making source files in eesupp from templates"      echo "  Making source files in eesupp from templates"
1755      $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1      ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1
1756      RETVAL=$?      RETVAL=$?
1757      if test "x${RETVAL}" == "x0" ; then      if test "x${RETVAL}" = x0 ; then
1758          rm -f make_eesupp.errors          rm -f make_eesupp.errors
1759      else      else
1760          echo "Error: problem encountered while building source files in eesupp:"          echo "Error: problem encountered while building source files in eesupp:"
1761          cat make_eesupp.errors          cat make_eesupp.errors 1>&2
1762          exit 1          exit 1
1763      fi      fi
1764  fi  fi
1765    
1766  echo $'\n'"===  Determining package settings  ==="  #same for exch2
1767    if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then
1768        echo "  Making source files in exch2 from  templates"
1769        ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1
1770        RETVAL=$?
1771        if test "x${RETVAL}" = x0 ; then
1772            rm -f make_exch2.errors
1773        else
1774            echo "Error: problem encountered while building source files in exch2:"
1775            cat make_exch2.errors 1>&2
1776            exit 1
1777        fi
1778    fi
1779    
1780    printf "\n===  Determining package settings  ===\n"
1781  if  test "x${PDEPEND}" = x ; then  if  test "x${PDEPEND}" = x ; then
1782      tmp=$ROOTDIR"/pkg/pkg_depend"      tmp=$ROOTDIR"/pkg/pkg_depend"
1783      if test -r $tmp ; then      if test -r $tmp ; then
# Line 471  echo "  getting package dependency info Line 1796  echo "  getting package dependency info
1796  #  Strip the comments and then convert the dependency file into  #  Strip the comments and then convert the dependency file into
1797  #  two arrays: PNAME, DNAME  #  two arrays: PNAME, DNAME
1798  cat $PDEPEND | sed -e 's/#.*$//g' \  cat $PDEPEND | sed -e 's/#.*$//g' \
1799      | awk 'BEGIN{nn=-1;} (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}' \
1800      > ./.pd_tmp      > ./.pd_tmp
1801  RETVAL=$?  RETVAL=$?
1802  if test ! "x${RETVAL}" = x0 ; then  if test ! "x${RETVAL}" = x0 ; then
1803      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
1804      exit 1      exit 1
1805  fi  fi
1806  source ./.pd_tmp  . ./.pd_tmp
1807  rm -f ./.pd_tmp  rm -f ./.pd_tmp
1808    
1809  echo  -n "  checking default package list:  "  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"
1810    #  file should eventually be added so that, for convenience, one can
1811    #  specify groups of packages using names like "ocean" and "atmosphere".
1812    echo "  checking default package list:  "
1813    if test "x${PDEFAULT}" = x ; then
1814        for i in "." $MODS ; do
1815            if test -r $i"/packages.conf" ; then
1816                    PDEFAULT=$i"/packages.conf"
1817                    break
1818            fi
1819        done
1820    fi
1821  if test "x${PDEFAULT}" = x ; then  if test "x${PDEFAULT}" = x ; then
1822      PDEFAULT="$ROOTDIR/pkg/pkg_default"      PDEFAULT="$ROOTDIR/pkg/pkg_default"
1823  fi  fi
1824  if test "x${PDEFAULT}" = xNONE ; then  if test "x${PDEFAULT}" = xNONE ; then
1825      echo "default packages file disabled"      echo "    default packages file disabled"
1826  else  else
1827      if test ! -r $PDEFAULT ; then      if test ! -r $PDEFAULT ; then
         echo ""  
1828          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""
1829      else      else
1830          echo "  using PDEFAULT=\"$PDEFAULT\""          echo "    using PDEFAULT=\"$PDEFAULT\""
1831          #  Strip the comments and add all the names          #  Strip the comments and add all the names
1832          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | awk '(NF>0){print $0}'`          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
1833          RETVAL=$?          RETVAL=$?
1834          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
1835              echo -n "Error: can't parse default package list "              printf "Error: can't parse default package list "
1836              echo "-- please check PDEFAULT=\"$PDEFAULT\""              echo "-- please check PDEFAULT=\"$PDEFAULT\""
1837              exit 1              exit 1
1838          fi          fi
1839          for i in $def ; do          for i in $def ; do
1840              PACKAGES="$PACKAGES $i"              PACKAGES="$PACKAGES $i"
1841          done          done
1842          echo "    packages are:  $PACKAGES"          echo "    before group expansion packages are: $PACKAGES"
1843            RET=1
1844            while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
1845            echo "    after group expansion packages are:  $PACKAGES"
1846      fi      fi
1847  fi  fi
1848    
1849  echo "  applying DISABLE settings"  echo "  applying DISABLE settings"
1850    for i in $PACKAGES ; do
1851        echo $i >> ./.tmp_pack
1852    done
1853    for i in `grep  "-" ./.tmp_pack` ; do
1854        j=`echo $i | sed 's/[-]//'`
1855        DISABLE="$DISABLE $j"
1856    done
1857  pack=  pack=
1858  for p in $PACKAGES ; do  for p in $PACKAGES ; do
1859      addit="t"      addit="t"
# Line 523  for p in $PACKAGES ; do Line 1868  for p in $PACKAGES ; do
1868  done  done
1869  PACKAGES="$pack"  PACKAGES="$pack"
1870  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
1871  rm -f ./.tmp_pack  echo "" > ./.tmp_pack
1872  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
1873    # Test if each explicitly referenced package exists
1874  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1875      if test ! -d "$ROOTDIR/pkg/$i" ; then      j=`echo $i | sed 's/[-+]//'`
1876        if test ! -d "$ROOTDIR/pkg/$j" ; then
1877          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
1878          exit 1          exit 1
1879      fi      fi
1880      echo $i >> ./.tmp_pack      echo $i >> ./.tmp_pack
1881  done  done
 pack=`cat ./.tmp_pack | sort | uniq`  
 rm -f ./.tmp_pack  
1882  PACKAGES=  PACKAGES=
1883  for i in $pack ; do  for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do
1884      PACKAGES="$PACKAGES $i"      PACKAGES="$PACKAGES $i"
1885  done  done
1886    rm -f ./.tmp_pack
1887  echo "    packages are:  $PACKAGES"  echo "    packages are:  $PACKAGES"
1888    
1889    #  Check availability of NetCDF and then either build the MNC template
1890    #  files or delete mnc from the list of available packages.
1891    echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1
1892    RETVAL=$?
1893    if test "x$RETVAL" = x0 ; then
1894        if test "x$HAVE_NETCDF" != xt ; then
1895            cat <<EOF
1896    
1897    *********************************************************************
1898    WARNING: the "mnc" package was enabled but tests failed to compile
1899      NetCDF applications.  Please check that:
1900    
1901      1) NetCDF is correctly installed for this compiler and
1902      2) the LIBS variable (within the "optfile") specifies the correct
1903           NetCDF library to link against.
1904    
1905      Due to this failure, the "mnc" package is now DISABLED.
1906    *********************************************************************
1907    
1908    EOF
1909            PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
1910            DISABLE="$DISABLE mnc"
1911        else
1912            ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
1913            RETVAL=$?
1914            if test "x${RETVAL}" = x0 ; then
1915                rm -f make_mnc.errors
1916            else
1917                echo "Error: problem encountered while building source files in pkg/mnc:"
1918                cat make_mnc.errors 1>&2
1919                exit 1
1920            fi
1921        fi
1922    fi
1923    
1924  echo "  applying package dependency rules"  echo "  applying package dependency rules"
1925  ck=  ck=
1926  while test "x$ck" != xtt ; do  while test "x$ck" != xtt ; do
1927      i=0      i=0
1928      rtot=${#PNAME[@]}      # rtot=${#PNAME[@]}
1929        rtot=$nname
1930      while test $i -lt $rtot ; do      while test $i -lt $rtot ; do
1931    
1932          #  Is $pname in the current $PACKAGES list?          #  Is $pname in the current $PACKAGES list?
1933          pname=${PNAME[$i]}          #  pname=${PNAME[$i]}
1934            tmp="pname=\"\$PNAME_$i\""
1935            eval $tmp
1936          pin="f"          pin="f"
1937          for p in $PACKAGES ; do          for p in $PACKAGES ; do
1938              if test "x$p" = "x$pname" ; then              if test "x$p" = "x$pname" ; then
# Line 557  while test "x$ck" != xtt ; do Line 1941  while test "x$ck" != xtt ; do
1941          done          done
1942    
1943          #  Is the DNAME entry a (+) or (-) rule ?          #  Is the DNAME entry a (+) or (-) rule ?
1944            tmp="dname=\"\$DNAME_$i\""
1945            eval $tmp
1946          plus="-"          plus="-"
1947          echo "${DNAME[$i]}" | grep '^+' > /dev/null 2>&1          echo $dname | grep '^+' > /dev/null 2>&1
1948          RETVAL=$?          RETVAL=$?
1949          if test "x$RETVAL" = x0 ; then          if test "x$RETVAL" = x0 ; then
1950              plus="+"              plus="+"
1951          fi          fi
1952    
1953          #  Is $dname in the current $PACKAGES list?          #  Is $dname in the current $PACKAGES list?
1954          dname=`echo ${DNAME[$i]} | sed -e 's/^[+-]//'`          dname=`echo $dname | sed -e 's/^[+-]//'`
1955          din="f"          din="f"
1956          for p in $PACKAGES ; do          for p in $PACKAGES ; do
1957              if test "x$p" = "x$dname" ; then              if test "x$p" = "x$dname" ; then
# Line 599  while test "x$ck" != xtt ; do Line 1985  while test "x$ck" != xtt ; do
1985              echo "  the dependency rules for \"$dname\""              echo "  the dependency rules for \"$dname\""
1986              exit 1              exit 1
1987          fi          fi
1988          i=$(( $i + 1 ))          i=`echo "$i + 1" | bc -l`
1989            #i=$(( $i + 1 ))
1990      done      done
1991      ck=$ck"t"      ck=$ck"t"
1992  done  done
# Line 609  for i in $PACKAGES ; do Line 1996  for i in $PACKAGES ; do
1996      if test -d $adr ; then      if test -d $adr ; then
1997          SOURCEDIRS="$SOURCEDIRS $adr"          SOURCEDIRS="$SOURCEDIRS $adr"
1998          INCLUDEDIRS="$INCLUDEDIRS $adr"          INCLUDEDIRS="$INCLUDEDIRS $adr"
1999            if test "x$i" = xautodiff ; then
2000                AUTODIFF_PKG_USED=t
2001            fi
2002      else      else
2003          echo "Error: the directory \"$adr\" for package $i doesn't exist"          echo "Error: the directory \"$adr\" for package $i doesn't exist"
2004          exit 1          exit 1
2005      fi      fi
2006  done  done
2007    
2008  #  This is compatible with the old genmake.  The "DISABLE_*" flags  # Create a list of #define and #undef to enable/disable packages
2009  #  need to be replaced by the "ALLOW_*" flags set below.  PACKAGES_DOT_H=PACKAGES_CONFIG.h
 #  
 # echo -n "  Setting package-specific CPP flags:  "  
 # pkrm=( mom_fluxform mom_vecinv generic_advdiff )  
 # pkrmdef=( -DDISABLE_MOM_FLUXFORM -DDISABLE_MOM_VECINV -DDISABLE_GENERIC_ADVDIFF -DDISABLE_DEBUGMODE )  
 # echo -n "  "  
 # i=0  
 # while test $i -lt "${#pkrm[@]}" ; do  
 #     echo "$PACKAGES" | grep "${pk[$i]}" > /dev/null 2>&1  
 #     RETVAL=$?  
 #     if test "x$RETVAL" = x1 ; then  
 #       DEFINES="$DEFINES ${pkdef[$i]}"  
 #       echo -n " ${pkdef[$i]}"  
 #     fi  
 #     i=$(( $i + 1 ))  
 # done  
 # echo  
   
 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  
2010  #  The following UGLY HACK sets multiple "#undef"s and it needs to go  #  The following UGLY HACK sets multiple "#undef"s and it needs to go
2011  #  away.  On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h  #  away.  On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
2012  #  file would eventually be split up so that all package-related #define  #  file would eventually be split up so that all package-related #define
2013  #  statements could be separated and handled only by genmake.  #  statements could be separated and handled only by genmake.
2014  names=`ls -1 "$ROOTDIR/pkg"`  names=`ls -1 "$ROOTDIR/pkg"`
2015  all_pack=  all_pack=
2016    DISABLED_PACKAGES=
2017  for n in $names ; do  for n in $names ; do
2018      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
2019          has_pack="f"          has_pack="f"
# Line 686  for n in $names ; do Line 2024  for n in $names ; do
2024              fi              fi
2025          done          done
2026          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
2027              undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2028              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!!!  
   
2029          fi          fi
2030      fi      fi
2031  done  done
2032  cat <<EOF >>CPP_OPTIONS.h.tmp  ENABLED_PACKAGES=
   
 C  Packages enabled by genmake:  
 EOF  
2033  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2034      def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`      def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2035      echo "#define $def" >> CPP_OPTIONS.h.tmp      ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
2036    #eh3 DEFINES="$DEFINES -D$def"
2037    
2038  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
2039      case $i in      case $i in
2040          aim_v23)          aim_v23)
2041              echo "#define   ALLOW_AIM" >> CPP_OPTIONS.h.tmp              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
2042                echo "Warning: ALLOW_AIM is set to enable aim_v23."
2043              ;;              ;;
2044      esac      esac
2045  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
2046    
2047  done  done
 mv -f CPP_OPTIONS.h.tmp CPP_OPTIONS.h  
2048    
2049  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS"
2050  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
2051  STANDARDDIRS=${STANDARDDIRS:-"eesupp model"}  if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
2052  for d in $STANDARDDIRS ; do      STANDARDDIRS="eesupp model"
2053      adr="$ROOTDIR/$d/src"  fi
2054      if test ! -d $adr ; then  if test "x$STANDARDDIRS" != x ; then
2055          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""      for d in $STANDARDDIRS ; do
2056          echo "  is correct and that you correctly specified the STANDARDDIRS option"          adr="$ROOTDIR/$d/src"
2057          exit 1          if test ! -d $adr ; then
2058      else              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
2059          SOURCEDIRS="$SOURCEDIRS $adr"              echo "  is correct and that you correctly specified the STANDARDDIRS option"
2060      fi              exit 1
2061      adr="$ROOTDIR/$d/inc"          else
2062      if test ! -d $adr ; then              SOURCEDIRS="$SOURCEDIRS $adr"
2063          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""          fi
2064          echo "  is correct and that you correctly specified the STANDARDDIRS option"          adr="$ROOTDIR/$d/inc"
2065          exit 1          if test ! -d $adr ; then
2066      else              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
2067          INCLUDEDIRS="$INCLUDEDIRS $adr"              echo "  is correct and that you correctly specified the STANDARDDIRS option"
2068                exit 1
2069            else
2070                INCLUDEDIRS="$INCLUDEDIRS $adr"
2071            fi
2072        done
2073    fi
2074    
2075    echo "  Searching for *OPTIONS.h files in order to warn about the presence"
2076    echo "    of \"#define \"-type statements that are no longer allowed:"
2077    CPP_OPTIONS=
2078    CPP_EEOPTIONS=
2079    spaths=". $INCLUDEDIRS"
2080    names=`ls -1 "$ROOTDIR/pkg"`
2081    for i in $spaths ; do
2082        try="$i/CPP_OPTIONS.h"
2083        if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
2084            echo "    found CPP_OPTIONS=\"$try\""
2085            CPP_OPTIONS="$try"
2086            # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
2087            for n in $names ; do
2088                test_for_package_in_cpp_options $CPP_OPTIONS $n
2089            done
2090        fi
2091        try="$i/CPP_EEOPTIONS.h"
2092        if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
2093            echo "    found CPP_EEOPTIONS=\"$try\""
2094            # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
2095    #**** not yet enabled ****
2096    #        test_for_mpi_in_cpp_eeoptions $try
2097    #**** not yet enabled ****
2098            CPP_EEOPTIONS="$try"
2099      fi      fi
2100  done  done
2101    if test "x$CPP_OPTIONS" = x ; then
2102        echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
2103        exit 1
2104    fi
2105    
2106    #  Here, we build the list of files to be "run through" the adjoint
2107    #  compiler.
2108    if test -f ./ad_files ; then
2109        rm -f ./ad_files
2110    fi
2111    echo "  Creating the list of files for the adjoint compiler."
2112    for i in $SOURCEDIRS ; do
2113        list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
2114        for j in $list_files ; do
2115            cat $i/$j >> ad_files
2116        done
2117    done
2118    if test ! "x"$FS = "x.f" ; then
2119        cat ad_files | sed -e "s/\.f/.$FS/g" > ad_files_f
2120        mv -f ad_files_f ad_files
2121    fi
2122    
2123  echo $'\n'"===  Creating the Makefile  ==="  echo
2124    echo "===  Creating the Makefile  ==="
2125  echo "  setting INCLUDES"  echo "  setting INCLUDES"
2126  for i in $INCLUDEDIRS ; do  for i in $INCLUDEDIRS ; do
2127      if test -d $i ; then      if test ! -d $i ; then
         INCLUDES="$INCLUDES -I$i"  
     else  
2128          echo "Warning: can't find INCLUDEDIRS=\"$i\""          echo "Warning: can't find INCLUDEDIRS=\"$i\""
2129      fi      fi
2130  done  done
2131    
2132    if test ! "x$DIVA" = x ; then
2133        echo "  Creating the pseudo-MPI include directory"
2134        INCLUDES="-I./mpi_headers $INCLUDES"
2135        rm -rf ./mpi_headers
2136        mkdir -p ./mpi_headers
2137    
2138        if test "x$MPIINCLUDEDIR" = x ; then
2139            if test "x$MPIHOME" = x ; then
2140                MPIHOME='/usr'
2141            fi
2142            MPIINCLUDEDIR='$MPIHOME/include'
2143        fi
2144        
2145        if test -r $MPIINCLUDEDIR/mpif.h ; then
2146            for i in $MPI_HEADER_FILES; do
2147                cp -p $MPIINCLUDEDIR/$i ./mpi_headers
2148            done
2149    
2150            perl -i -pe 's/MPI_DISPLACEMENT_CURRENT=-1_8/MPI_DISPLACEMENT_CURRENT=-1/g' mpi_headers/mpif.h
2151        else
2152            echo " We cannot create a copy of mpif.h!"
2153            exit -1
2154        fi
2155    fi
2156    
2157  echo "  Determining the list of source and include files"  echo "  Determining the list of source and include files"
2158  rm -rf .links.tmp  rm -rf .links.tmp
2159  mkdir .links.tmp  mkdir .links.tmp
2160    touch .links.tmp/foo
2161    if test ! -r ".links.tmp/foo" ; then
2162        echo
2163        echo "ERROR : something is wrong with your directory permissions or"
2164        echo "   your user file-creation mask (\"umask\") since creating a"
2165        echo "   sub-dir, touch-ing a file within it, and then reading it is"
2166        echo "   not working.  Please try setting your umask to something"
2167        echo "   sane such as:"
2168        echo
2169        echo "      umask 0002"
2170        echo
2171        echo "   and please verify that you have the proper permissions for"
2172        echo "   creating sub-directories and then reading files created"
2173        echo "   within them."
2174        echo
2175        exit 1
2176    fi
2177    rm -f .links.tmp/foo
2178  echo "# This section creates symbolic links" > srclinks.tmp  echo "# This section creates symbolic links" > srclinks.tmp
2179  echo "" >> srclinks.tmp  echo "" >> srclinks.tmp
2180  echo -n 'SRCFILES = ' > srclist.inc  printf 'SRCFILES = '    > srclist.inc
2181  echo -n 'CSRCFILES = ' > csrclist.inc  printf 'CSRCFILES = '   > csrclist.inc
2182  echo -n 'HEADERFILES = ' > hlist.inc  printf 'F90SRCFILES = ' > f90srclist.inc
2183  alldirs=". $SOURCEDIRS $INCLUDEDIRS"  printf 'HEADERFILES = ' > hlist.inc
2184    printf 'AD_FLOW_FILES = ' > ad_flow_files.inc
2185    alldirs="$SOURCEDIRS $INCLUDEDIRS ."
2186  for d in $alldirs ; do  for d in $alldirs ; do
2187      deplist=      deplist=
2188      sfiles=`( cd $d; echo *.[h,c,F] )`      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
2189        sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
2190      for sf in $sfiles ; do      for sf in $sfiles ; do
2191          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
2192              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
2193                  extn=`echo $sf | awk -F '.' '{print $NF}'`                  ignore_f=f
2194                  touch .links.tmp/$sf                  case $d/$sf in
2195                  deplist="$deplist $sf"                    ./$PACKAGES_DOT_H)
2196                  case $extn in                          ignore_f=t
2197                      F)                          ;;
2198                          echo    " \\"  >> srclist.inc                    ./AD_CONFIG.h)
2199                          echo -n " $sf" >> srclist.inc                          ignore_f=t
2200                            ;;
2201                      ./FC_NAMEMANGLE.h)
2202                            ignore_f=t
2203                          ;;                          ;;
2204                      c)                    ./BUILD_INFO.h)
2205                          echo    " \\"  >> csrclist.inc                          ignore_f=t
                         echo -n " $sf" >> csrclist.inc  
2206                          ;;                          ;;
2207                      h)                    ./EMBEDDED_FILES.h)
2208                          echo    " \\"  >> hlist.inc                          ignore_f=t
                         echo -n " $sf" >> hlist.inc  
2209                          ;;                          ;;
2210                  esac                    *)
2211                            #  For the local directory *ONLY*,
2212                            #  ignore all soft-links
2213                            if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then
2214                                ignore_f=t
2215                            else
2216                                touch .links.tmp/$sf
2217                                deplist="$deplist $sf"
2218                            fi
2219                            ;;
2220                    esac
2221                    if test "x$ignore_f" = xf ; then
2222                        extn=`echo $sf | $AWK -F. '{print $NF}'`
2223                        case $extn in
2224                            F)
2225                                echo    " \\"  >> srclist.inc
2226                                printf " $sf" >> srclist.inc
2227                                ;;
2228                            F90)
2229                                echo    " \\"  >> f90srclist.inc
2230                                printf " $sf" >> f90srclist.inc
2231                                ;;
2232                            c)
2233                                echo    " \\"  >> csrclist.inc
2234                                printf " $sf" >> csrclist.inc
2235                                ;;
2236                            h)
2237                                echo    " \\"  >> hlist.inc
2238                                printf " $sf" >> hlist.inc
2239                                ;;
2240                            flow)
2241                                echo    " \\"  >> ad_flow_files.inc
2242                                printf " $sf" >> ad_flow_files.inc
2243                                ;;
2244                        esac
2245                    fi
2246              fi              fi
2247          fi          fi
2248      done      done
2249      if test "x$deplist" != x ; then      if test "x$deplist" != x ; then
2250          echo $'\n'"#  These files are linked from $d" >> srclinks.tmp          echo "" >> srclinks.tmp
2251            echo "#  These files are linked from $d" >> srclinks.tmp
2252          echo "$deplist :" >> srclinks.tmp          echo "$deplist :" >> srclinks.tmp
2253          echo $'\t$(LN) '$d'/$@ $@' >> srclinks.tmp          printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp
2254      fi      fi
2255  done  done
2256  rm -rf .links.tmp  rm -rf .links.tmp
2257  echo "" >> srclist.inc  echo "" >> srclist.inc
2258  echo "" >> csrclist.inc  echo "" >> csrclist.inc
2259    echo "" >> f90srclist.inc
2260  echo "" >> hlist.inc  echo "" >> hlist.inc
2261    echo "" >> ad_flow_files.inc
2262    
2263  if test -e $MAKEFILE ; then  if test -f $MAKEFILE ; then
2264      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.bak"
2265  fi  fi
2266  echo "  Writing makefile: $MAKEFILE"  echo "  Writing makefile: $MAKEFILE"
# Line 816  echo "#    $MACHINE" >> $MAKEFILE Line 2269  echo "#    $MACHINE" >> $MAKEFILE
2269  echo "# This makefile was generated automatically on" >> $MAKEFILE  echo "# This makefile was generated automatically on" >> $MAKEFILE
2270  echo "#    $THISDATE" >> $MAKEFILE  echo "#    $THISDATE" >> $MAKEFILE
2271  echo "# by the command:" >> $MAKEFILE  echo "# by the command:" >> $MAKEFILE
2272  echo "#    $0 $@" >> $MAKEFILE  echo "#    $0 $G2ARGS" >> $MAKEFILE
2273  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
2274  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE  echo "#    ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
2275    
2276    EXE_AD=$EXECUTABLE"_ad"
2277    EXE_FTL=$EXECUTABLE"_ftl"
2278    EXE_SVD=$EXECUTABLE"_svd"
2279    
2280  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2281    #
2282    # OPTFILE="$OPTFILE"
2283  #  #
2284  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
2285  # SOURCEDIRS   : Directories containing the source (.F) files  # SOURCEDIRS   : Directories containing the source (.F) files
# Line 847  EXEDIR      = ${EXEDIR} Line 2307  EXEDIR      = ${EXEDIR}
2307  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}
2308  TOOLSDIR    = ${TOOLSDIR}  TOOLSDIR    = ${TOOLSDIR}
2309    
2310    #eh3  new defines for the adjoint work
2311    AUTODIFF    = ${ROOTDIR}/pkg/autodiff
2312    EXE_AD      = ${EXE_AD}
2313    EXE_FTL     = ${EXE_FTL}
2314    EXE_SVD     = ${EXE_SVD}
2315    
2316    ENABLED_PACKAGES = ${ENABLED_PACKAGES}
2317    DISABLED_PACKAGES = ${DISABLED_PACKAGES}
2318    
2319    # These files are created by Makefile
2320    SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h
2321  EOF  EOF
2322    
2323  #  Note: figure out some way to add Hyades JAM libraries here  if test "x$EMBED_SRC" = xt ; then
2324        echo "EMBEDDED_FILES = EMBEDDED_FILES.h" >>$MAKEFILE
2325    else
2326        echo "EMBEDDED_FILES = " >>$MAKEFILE
2327    fi
2328    
2329    #  Note: figure out some way to add Hyades JAM libraries here
2330  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2331  # Unix ln (link)  # Unix ln (link)
2332  LN = ${LN}  LN = ${LN}
# Line 862  MAKEDEPEND = ${MAKEDEPEND} Line 2338  MAKEDEPEND = ${MAKEDEPEND}
2338  KPP = ${KPP}  KPP = ${KPP}
2339  # Fortran compiler  # Fortran compiler
2340  FC = ${FC}  FC = ${FC}
2341    # Fortran compiler
2342    F90C = ${F90C}
2343    # C compiler
2344    CC = ${CC}
2345  # Link editor  # Link editor
2346  LINK = ${LINK}  LINK = ${LINK} ${LDADD}
2347    
2348  # Defines for CPP  # Defines for CPP
2349  DEFINES = ${DEFINES}  DEFINES = ${DEFINES}
# Line 875  KFLAGS2 = ${KFLAGS2} Line 2355  KFLAGS2 = ${KFLAGS2}
2355  # Optim./debug for FC  # Optim./debug for FC
2356  FFLAGS = ${FFLAGS}  FFLAGS = ${FFLAGS}
2357  FOPTIM = ${FOPTIM}  FOPTIM = ${FOPTIM}
2358    # Optim./debug for FC
2359    F90FLAGS = ${F90FLAGS}
2360    F90OPTIM = ${F90OPTIM}
2361  # Flags for CC  # Flags for CC
2362  CFLAGS = ${CFLAGS}  CFLAGS = ${CFLAGS}
2363  # Files that should not be optimized  # Files that should not be optimized
2364  NOOPTFILES = ${NOOPTFILES}  NOOPTFILES = ${NOOPTFILES}
2365  NOOPTFLAGS = ${NOOPTFLAGS}  NOOPTFLAGS = ${NOOPTFLAGS}
2366  # Flags and libraries needed for linking  # Flags and libraries needed for linking
2367  LIBS = ${LIBS} \$(XLIBS)  LIBS = ${LIBS}
2368    # Name of the Mekfile
2369    MAKEFILE=${MAKEFILE}
2370    
2371  EOF  EOF
2372    
2373  cat srclist.inc  >> $MAKEFILE  cat srclist.inc       >> $MAKEFILE
2374  cat csrclist.inc >> $MAKEFILE  cat csrclist.inc      >> $MAKEFILE
2375  cat hlist.inc >> $MAKEFILE  cat f90srclist.inc    >> $MAKEFILE
2376  echo 'F77FILES =  $(SRCFILES:.F=.f)'                    >> $MAKEFILE  cat hlist.inc         >> $MAKEFILE
2377  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o)' >> $MAKEFILE  cat ad_flow_files.inc >> $MAKEFILE
2378    echo >> $MAKEFILE
2379  rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp  echo 'F77FILES =  $(SRCFILES:.F=.'$FS')'      >> $MAKEFILE
2380    echo 'F90FILES =  $(F90SRCFILES:.F90=.'$FS90')' >> $MAKEFILE
2381    echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
2382    echo >> $MAKEFILE
2383    echo '.SUFFIXES:' >> $MAKEFILE
2384    echo '.SUFFIXES: .o .'$FS' .p .F .c .'$FS90' .F90' >> $MAKEFILE
2385    rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc
2386    rm -f ad_flow_files.inc
2387    
2388  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2389    
 .SUFFIXES:  
 .SUFFIXES: .o .f .p .F .c  
   
2390  all: \$(EXECUTABLE)  all: \$(EXECUTABLE)
2391  \$(EXECUTABLE): \$(OBJFILES)  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(OBJFILES) \$(EMBEDDED_FILES)
2392            @echo Creating \$@ ...
2393          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
2394  depend:  depend:
2395          @make links          @make links
2396          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
2397            \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2398            -rm -f makedepend.out
2399    
2400  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES)  lib: libmitgcmuv.a
2401    
2402  small_f: \$(F77FILES)  libmitgcmuv.a: \$(OBJFILES)
2403            ar rcv libmitgcmuv.a \$(OBJFILES)
2404    
2405    links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES)
2406    
2407    small_f: \$(F77FILES) \$(F90FILES)
2408    
2409  output.txt: \$(EXECUTABLE)  output.txt: \$(EXECUTABLE)
2410          @printf 'running ... '          @printf 'running ... '
2411          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
2412    
2413  clean:  clean:
2414          -rm -rf *.o *.f *.p ${RMFILES} work.{pc,pcl}          -rm -rf *.o *.$FS *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
2415  Clean:  Clean:
2416          @make clean          @make clean
2417          @make cleanlinks          @make cleanlinks
2418          -rm -f Makefile.bak          -rm -f \$(SPECIAL_FILES)
2419            -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak
2420  CLEAN:  CLEAN:
2421          @make Clean          @make Clean
2422          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
2423          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
2424          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
2425          -rm -f \$(EXECUTABLE)          -rm -f \$(EXECUTABLE) *.txt STD* *diagnostics.log datetime
2426            -rm -rf mnc_test_*
2427    
2428    #eh3 Makefile: makefile
2429  makefile:  makefile:
2430          ${0} $@          $THIS_SCRIPT $G2ARGS
2431  cleanlinks:  cleanlinks:
2432          -find . -type l -exec rm {} \;          -find . -type l -exec rm {} \;
2433    
2434  # The normal chain of rules is (  .F - .f - .o  )  # Special targets (SPECIAL_FILES) which are create by make
2435  .F.f:  ${PACKAGES_DOT_H}:
2436            @echo Creating \$@ ...
2437            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@
2438    AD_CONFIG.h:
2439            @echo Creating \$@ ...
2440            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > \$@
2441    FC_NAMEMANGLE.h:
2442            @echo Creating \$@ ...
2443            echo "$FC_NAMEMANGLE" > \$@
2444    
2445    BUILD_INFO.h:
2446            @echo Creating \$@ ...
2447    EOF
2448    
2449    test ! "x$THISVER" = x  && echo "       -echo \"#define THISVER '$THISVER'\" > \$@"   >> $MAKEFILE
2450    test ! "x$THISUSER" = x && echo "       -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE
2451    test ! "x$THISDATE" = x && echo "       -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
2452    test ! "x$THISHOST" = x && echo "       -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
2453    
2454    if test "x$EMBED_SRC" = xt ; then
2455        cat >>$MAKEFILE <<EOF
2456    
2457    decode_files.o : EMBEDDED_FILES.h
2458    
2459    ##  \$(F77FILES)
2460    all_fF.tar.gz : \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(F77FILES) Makefile
2461            @echo Creating \$@ ...
2462            -tar -hcf all_fF.tar \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(F77FILES) Makefile
2463            -rm -f all_fF.tar.gz
2464            -gzip all_fF.tar
2465    
2466    EMBEDDED_FILES.h : all_fF.tar.gz
2467            @echo Creating \$@ ...
2468            -\${ROOTDIR}/tools/embed_encode/encode_files EMBEDDED_FILES.h all_fF.tar.gz
2469    
2470    EOF
2471    fi
2472    
2473    cat >>$MAKEFILE <<EOF
2474    
2475    # The normal chain of rules is (  .F - .$FS - .o  )
2476    
2477    ## This nullifies any default implicit rules concerning these two file types:
2478    ## %.o : %.F
2479    
2480    .F.$FS:
2481          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2482  .f.o:  .$FS.o:
2483          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2484    .F90.$FS90:
2485            \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2486    .$FS90.o:
2487            \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
2488  .c.o:  .c.o:
2489          \$(CC) \$(CFLAGS) -c \$<          \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$<
2490    
2491  # Special exceptions that use the ( .F - .p - .f - .o ) rule-chain  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
2492  .F.p:  .F.p:
2493          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2494  .p.f:  .p.$FS:
2495          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
2496    
2497    #=========================================
2498    #===  Automatic Differentiation Rules  ===
2499    
2500    TAMC           = ${TAMC}
2501    TAF            = ${TAF}
2502    
2503    TAF_EXTRA      = ${TAF_EXTRA}
2504    TAMC_EXTRA     = ${TAMC_EXTRA}
2505    
2506    EOF
2507    
2508    ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
2509    ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF_FLAGS"
2510    ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
2511    for i in $ad_vars ; do
2512        name=$i
2513        t1="t2=\$"`echo $i`
2514        eval $t1
2515        printf "%-20s = " $name >> $MAKEFILE
2516        echo $t2 >> $MAKEFILE
2517    done
2518    
2519    echo "  Add the source list for AD code generation"
2520    echo >> $MAKEFILE
2521    printf "AD_FILES = " >> $MAKEFILE
2522    AD_FILES=`cat ad_files`
2523    for i in $AD_FILES ; do
2524        echo    " \\" >> $MAKEFILE
2525        printf " $i" >> $MAKEFILE
2526    done
2527    echo >> $MAKEFILE
2528    rm -f ad_files
2529    
2530    cat >>$MAKEFILE <<EOF
2531    
2532    # ... AD ...
2533    adall: ad_taf
2534    adtaf: ad_taf_output.$FS
2535    adtamc: ad_tamc_output.$FS
2536    
2537    ad_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)
2538            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > ad_config.template
2539            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
2540            -rm -f ad_config.template
2541            @make \$(F77FILES)
2542            @make \$(AD_FLOW_FILES)
2543            cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.$FS
2544    
2545    ad_taf_output.$FS: ad_input_code.$FS
2546            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2547            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
2548    
2549    adtafonly:
2550            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2551            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
2552    
2553    ad_taf: ad_taf_output.o \$(OBJFILES)
2554            \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
2555    
2556    ad_tamc_output.$FS: ad_input_code.$FS
2557            \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
2558            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS
2559    
2560    ad_tamc: ad_tamc_output.o \$(OBJFILES)
2561            \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
2562    
2563    adonlyfwd:
2564            patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
2565    
2566    adtrick:
2567            patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
2568    
2569    # ... FTL ...
2570    ftlall: ftl_taf
2571    ftltaf: ftl_taf_output.$FS
2572    ftltamc: ftl_tamc_output.$FS
2573    
2574    ftl_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)
2575            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > ftl_config.template
2576            cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
2577            -rm -f ftl_config.template
2578            @make \$(F77FILES)
2579            @make \$(AD_FLOW_FILES)
2580            cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.$FS
2581    
2582    ftl_taf_output.$FS: ftl_input_code.$FS
2583            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2584            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2585    
2586    ftltafonly:
2587            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2588            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2589    
2590    ftl_taf: ftl_taf_output.o \$(OBJFILES)
2591            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
2592    
2593    ftl_tamc_output.$FS: ftl_input_code.$FS
2594            \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
2595            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS
2596    
2597    ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
2598            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
2599    
2600    
2601    # ... SVD ...
2602    svdtaf: ad_taf_output.$FS ftl_taf_output.$FS
2603            @echo "--->>> Only ran TAF to generate SVD code!    <<<---"
2604            @echo "--->>> Do make svdall afterwards to compile. <<<---"
2605    svdall: svd_touch svd_taf
2606    
2607    svd_taf: \$(OBJFILES)
2608            \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
2609    
2610            @echo "--->>> Only COMPILE svd code! <<<---"
2611            @echo "--->>> Assumes you previously <<<---"
2612            @echo "--->>> did make svdtaf        <<<---"
2613    
2614    svd_touch:
2615            @echo "--->>> Only COMPILE svd code! <<<---"
2616            @echo "--->>> Assumes you previously <<<---"
2617            @echo "--->>> did make svdtaf        <<<---"
2618            touch ad_taf_output.$FS ftl_taf_output.$FS
2619            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS
2620            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS
2621            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > ftl_config.template
2622            cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
2623            -rm -f ftl_config.template
2624    
2625    #=========================================
2626    
2627  EOF  EOF
2628    
2629    if test "x$EXEHOOK" != x ; then
2630        printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
2631    fi
2632    
2633  echo "  Making list of \"exceptions\" that need \".p\" files"  echo "  Making list of \"exceptions\" that need \".p\" files"
2634  for i in $KPPFILES ; do  for i in $KPPFILES ; do
2635      base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`      base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
# Line 954  for i in $KPPFILES ; do Line 2637  for i in $KPPFILES ; do
2637      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
2638          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
2639      fi      fi
2640      echo "$base.f: $base.p" >> $MAKEFILE      echo "$base.$FS: $base.p" >> $MAKEFILE
2641  done  done
2642    
2643  echo "  Making list of NOOPTFILES"  echo "  Making list of NOOPTFILES"
# Line 964  for i in $NOOPTFILES ; do Line 2647  for i in $NOOPTFILES ; do
2647      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
2648          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
2649      fi      fi
2650      echo "$base.o: $base.f" >> $MAKEFILE      echo "$base.o: $base.$FS" >> $MAKEFILE
2651      echo $'\t$(FC) $(FFLAGS) $(NOOPTFLAGS) -c $<' >> $MAKEFILE      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
2652  done  done
2653    
2654  echo "  Add rules for links"  echo "  Add rules for links"
# Line 973  cat srclinks.tmp >> $MAKEFILE Line 2656  cat srclinks.tmp >> $MAKEFILE
2656  rm -f srclinks.tmp  rm -f srclinks.tmp
2657    
2658  echo "  Adding makedepend marker"  echo "  Adding makedepend marker"
2659  echo $'\n\n'"# DO NOT DELETE" >> $MAKEFILE  printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
2660    
2661    printf "\n===  Done  ===\n"
2662    
2663    # Create special header files
2664    $BASH $TOOLSDIR/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" $DISABLED_PACKAGES " " "Enabled packages:" $ENABLED_PACKAGES > $PACKAGES_DOT_H".tmp"
2665    if test ! -f $PACKAGES_DOT_H ; then
2666        mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2667    else
2668        cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
2669        RETVAL=$?
2670        if test "x$RETVAL" = x0 ; then
2671            rm -f $PACKAGES_DOT_H".tmp"
2672        else
2673            mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
2674            mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2675        fi
2676    fi
2677    if test ! -f AD_CONFIG.h ; then
2678        $BASH $TOOLSDIR/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > AD_CONFIG.h
2679    fi
2680    
2681    
2682  echo $'\n'"===  Done  ==="  #  Write the "state" for future records
2683    if test "x$DUMPSTATE" != xf ; then
2684        printf "" > genmake_state
2685        for i in $gm_state ; do
2686            t1="t2=\$$i"
2687            eval $t1
2688            echo "$i='$t2'" >> genmake_state
2689        done
2690    fi

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.145

  ViewVC Help
Powered by ViewVC 1.1.22