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

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.142

  ViewVC Help
Powered by ViewVC 1.1.22