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

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.203

  ViewVC Help
Powered by ViewVC 1.1.22