/[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.7 by edhill, Mon Sep 22 19:06:12 2003 UTC revision 1.132 by cnh, Fri Sep 16 00:50:49 2005 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  # Guess possible config options for this host  # Guess possible config options for this host
252  find_possible_configs()  {  find_possible_configs()  {
253    
254      p_PLATFORM=`uname`"-"`uname -m`      tmp1=`uname`"_"`uname -m`
255      echo "The platform appears to be:"      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
256      echo "  "$p_PLATFORM      tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
257        tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
258      p_LN=      tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
259        tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
260        PLATFORM=$tmp3
261        echo $PLATFORM | grep cygwin > /dev/null 2>&1  &&  PLATFORM=cygwin_ia32
262        OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
263        echo "  The platform appears to be:  $PLATFORM"
264        
265      echo "test" > test      echo "test" > test
266      ln -s ./test link      ln -s ./test link
267      RETVAL=$?      RETVAL=$?
268      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
269          p_LN="ln -s"          LN="ln -s"
270        else
271            echo "Error: \"ln -s\" does not appear to work on this system!"
272            echo "  For help, please contact <MITgcm-support@mitgcm.org>."
273            exit 1
274      fi      fi
275      rm -f test link      rm -f test link
276    
277      p_CPP=`which cpp`      if test "x$CPP" = x ; then
278                CPP="cpp -traditional -P"
     RETVAL=$?  
     if test "x${RETVAL}" = x0 ; then  
         p_LN="ln -s"  
279      fi      fi
     rm -f test link  
280    
281      # look for possible fortran compilers      look_for_makedepend
282      p_FC=  
283      for c in f77 g77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 ; do      #================================================================
284          which $c > /dev/null 2>&1      #  look for possible C compilers
285        tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc"
286        p_CC=
287        for c in $tmp ; do
288            rm -f ./genmake_hello.c  ./genmake_hello
289            cat >> genmake_hello.c << EOF
290    #include <stdio.h>
291    int main(int argc, char **argv) {
292      printf("Hello!\n");
293      return 0;
294    }
295    EOF
296            $c -o genmake_hello genmake_hello.c > /dev/null 2>&1
297          RETVAL=$?          RETVAL=$?
298          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
299              p_FC="$p_FC $c"              p_CC="$p_CC $c"
300          fi          fi
301      done      done
302      echo "Possible FORTRAN compilers appear to be:  "      rm -f ./genmake_hello.c ./genmake_hello
303      if test "x${p_FC}" = x ; then      if test "x${p_CC}" = x ; then
304          echo "  None found!!!"          cat 1>&2 <<EOF
305    
306    Error: No C compilers were found in your path.  Please specify one using:
307    
308        1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
309        2) the CC or MITGCM_CC environment variables.
310    
311    EOF
312            exit 1
313      else      else
314          echo "  "$p_FC          echo "  The possible C compilers found in your path are:"
315            echo "   "$p_CC
316            if test "x$CC" = x ; then
317                CC=`echo $p_CC | $AWK '{print $1}'`
318                echo "  Setting C compiler to: "$CC
319            fi
320      fi      fi
321    
322      # look for possible MPI libraries      #================================================================
323      mpi_libs=      #  look for possible FORTRAN compilers
324      mpi_fort=`which mpif77 2>/dev/null`      tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 gfortran"
325      RETVAL=$?      p_FC=
326      if test "x${RETVAL}" = x0 ; then      for c in $tmp ; do
327          cat >>test.f <<EOF          rm -f ./hello.f ./hello
328        PROGRAM HELLO          cat >> hello.f <<EOF
329        DO 10, I=1,10        program hello
330        PRINT *,'Hello World'        do i=1,3
331     10 CONTINUE          print *, 'hello world : ', i
332        STOP        enddo
333        END        end
334  EOF  EOF
335          eval "$mpi_fort -showme test.f > out"          $c -o hello hello.f > /dev/null 2>&1
336          RETVAL=$?          RETVAL=$?
337          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
338              a=`cat out`              p_FC="$p_FC $c"
339              for i in $a ; do          fi
340                  case $i in      done
341                      -*)      rm -f ./hello.f ./hello
342                          mpi_libs="$mpi_libs $i" ;;      if test "x${p_FC}" = x ; then
343                  esac          cat 1>&2 <<EOF
344              done  
345              echo "The MPI libs appear to be:"  Error: No Fortran compilers were found in your path.  Please specify one using:
346              echo "  "$mpi_libs  
347        1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
348        2) a command-line option (eg. "-fc NAME"), or
349        3) the FC or MITGCM_FC environment variables.
350    
351    EOF
352            exit 1
353        else
354            echo "  The possible FORTRAN compilers found in your path are:"
355            echo "   "$p_FC
356            if test "x$FC" = x ; then
357                FC=`echo $p_FC | $AWK '{print $1}'`
358                echo "  Setting FORTRAN compiler to: "$FC
359          fi          fi
         rm -f test.f out  
360      fi      fi
361    
362        if test "x$OPTFILE" = x ; then
363            OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
364            if test ! -r $OPTFILE ; then
365                 echo "  I looked for the file "$OPTFILE" but did not find it"
366            fi
367        fi
368    #    echo "  The options file:  $p_OF"
369    #    echo "    appears to match so we'll use it."
370    #   for i in $p_FC ; do
371    #p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
372    #if test -r $p_OF ; then
373    #    OPTFILE=$p_OF
374    #    echo "  The options file:  $p_OF"
375    #    echo "    appears to match so we'll use it."
376    #    break
377    #fi
378    #   done
379        if test "x$OPTFILE" = x ; then
380            cat 1>&2 <<EOF
381    
382    Error: No options file was found in:  $ROOTDIR/tools/build_options/
383      that matches this platform ("$PLATFORM") and the compilers found in
384      your path.  Please specify an "optfile" using:
385    
386        1) the command line (eg. "-optfile=path/to/OPTFILE"), or
387        2) the MITGCM_OF environment variable.
388    
389      If you need help, please contact the developers at <MITgcm-support@mitgcm.org>.
390    
391    EOF
392            exit 1
393        fi
394        
395    #     # look for possible MPI libraries
396    #     mpi_libs=
397    #     mpi_fort=`which mpif77 2>/dev/null`
398    #     RETVAL=$?
399    #     if test "x${RETVAL}" = x0 ; then
400    #       cat >>test.f <<EOF
401    #       PROGRAM HELLO
402    #       DO 10, I=1,10
403    #       PRINT *,'Hello World'
404    #    10 CONTINUE
405    #       STOP
406    #       END
407    # EOF
408    #       eval "$mpi_fort -showme test.f > out"
409    #       RETVAL=$?
410    #       if test "x${RETVAL}" = x0 ; then
411    #           a=`cat out`
412    #           for i in $a ; do
413    #               case $i in
414    #                   -*)
415    #                       mpi_libs="$mpi_libs $i" ;;
416    #               esac
417    #           done
418    #           echo "The MPI libs appear to be:"
419    #           echo "  "$mpi_libs
420    #       fi
421    #       rm -f test.f out
422    #     fi
423    
424  }  }
425    
426  #  Parse the package dependency information  #  Parse the package dependency information
# Line 86  get_pdepend_list()  { Line 429  get_pdepend_list()  {
429      #  strip the comments and then convert the dependency file into      #  strip the comments and then convert the dependency file into
430      #  two arrays: PNAME, DNAME      #  two arrays: PNAME, DNAME
431      cat $1 | sed -e 's/#.*$//g' \      cat $1 | sed -e 's/#.*$//g' \
432          | 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} }' \
433          > ./.pd_tmp          > ./.pd_tmp
434      source ./.pd_tmp      . ./.pd_tmp
435      rm -f ./.pd_tmp      rm -f ./.pd_tmp
436    
437      echo -n "PNAME = "${}      printf "PNAME = "${}
438  }  }
439    
440    
441  #  Explain usage  #  Explain usage
442  usage()  {  usage()  {
443      echo  cat <<EOF
444      echo "Usage: "$0" [OPTIONS]"  
445      echo "  where [OPTIONS] can be:"  Usage: "$0" [OPTIONS]
446      echo    where [OPTIONS] can be:
447      echo "    -help | --help | -h | --h"  
448      echo "    -nooptfile | --nooptfile"      -help | --help | -h | --h
449      echo "      -optfile NAME | --optfile NAME | -of NAME | --of NAME"            Print this help message and exit.
450      echo "      -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME"  
451      echo "    -pdepend NAME | --pdepend NAME"      -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME
452      echo "      -pdepend=NAME | --pdepend=NAME"        -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME
453      echo "    -pdefault NAME | --pdefault NAME"            Use "NAME" as the adoptfile.  By default, the file at
454      echo "      -pdefault=NAME | --pdefault=NAME"            "tools/adjoint_options/adjoint_default" will be used.
455      echo "    -make NAME | -m NAME"  
456      echo "      --make=NAME | -m=NAME"      -nooptfile | --nooptfile
457      echo "    -makefile NAME | -mf NAME"        -optfile NAME | --optfile NAME | -of NAME | --of NAME
458      echo "      --makefile=NAME | -mf=NAME"        -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
459      echo "    -platform NAME | --platform NAME | -pl NAME | --pl NAME"            Use "NAME" as the optfile.  By default, an attempt will be
460      echo "      -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"            made to find an appropriate "standard" optfile in the
461      echo "    -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"            tools/build_options/ directory.
462      echo "      -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME"  
463      echo "    -mods NAME | --mods NAME | -mo NAME | --mo NAME"      -pdepend NAME | --pdepend NAME
464      echo "      -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME"        -pdepend=NAME | --pdepend=NAME
465      echo "    -disable NAME | --disable NAME"            Get package dependency information from "NAME".
466      echo "      -disable=NAME | --disable=NAME"  
467      echo "    -enable NAME | --enable NAME"      -pdefault NAME | --pdefault NAME
468      echo "      -enable=NAME | --enable=NAME"        -pdefault=NAME | --pdefault=NAME
469      echo "    -noopt NAME | --noopt NAME"            Get the default package list from "NAME".
470      echo "      -noopt=NAME | --noopt=NAME"  
471  #    echo "    -cpp NAME | --cpp NAME"      -make NAME | -m NAME
472  #    echo "      -cpp=NAME | --cpp=NAME"        --make=NAME | -m=NAME
473      echo "    -fortran NAME | --fortran NAME | -fc NAME | --fc NAME"            Use "NAME" for the MAKE program. The default is "make" but
474      echo "      -fc=NAME | --fc=NAME"            many platforms, "gmake" is the preferred choice.
475      echo "    -[no]ieee | --[no]ieee"  
476      echo "    -[no]mpi | --[no]mpi"      -makefile NAME | -mf NAME
477      echo "    -[no]jam | --[no]jam"        --makefile=NAME | -mf=NAME
478      echo            Call the makefile "NAME".  The default is "Makefile".
479      echo "  and NAME is a string such as:"  
480      echo      -makedepend NAME | -md NAME
481      echo "    --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'"        --makedepend=NAME | -md=NAME
482      echo "    -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'"            Use "NAME" for the MAKEDEPEND program.
483      echo "    -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"  
484      echo      -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
485      echo "  which, depending upon your shell, may need to be single-quoted"        -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
486      echo "  if it contains spaces, dashes, or other special characters."            Specify the location of the MITgcm ROOTDIR as "NAME".
487              By default, genamke will try to find the location by
488              looking in parent directories (up to the 5th parent).
489    
490        -mods NAME | --mods NAME | -mo NAME | --mo NAME
491          -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
492              Here, "NAME" specifies a list of directories that are
493              used for additional source code.  Files found in the
494              "mods list" are given preference over files of the same
495              name found elsewhere.
496    
497        -disable NAME | --disable NAME
498          -disable=NAME | --disable=NAME
499              Here "NAME" specifies a list of packages that we don't
500              want to use.  If this violates package dependencies,
501              genamke will exit with an error message.
502    
503        -enable NAME | --enable NAME
504          -enable=NAME | --enable=NAME
505              Here "NAME" specifies a list of packages that we wish
506              to specifically enable.  If this violates package
507              dependencies, genamke will exit with an error message.
508    
509        -standarddirs NAME | --standarddirs NAME
510          -standarddirs=NAME | --standarddirs=NAME
511              Here, "NAME" specifies a list of directories to be
512              used as the "standard" code.
513    
514        -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
515          -fc=NAME | --fc=NAME
516              Use "NAME" as the fortran compiler.  By default, genmake
517              will search for a working compiler by trying a list of
518              "usual suspects" such as g77, f77, etc.
519    
520        -cc NAME | --cc NAME | -cc=NAME | --cc=NAME
521              Use "NAME" as the C compiler.  By default, genmake
522              will search for a working compiler by trying a list of
523              "usual suspects" such as gcc, c89, cc, etc.
524    
525        -[no]ieee | --[no]ieee
526              Do or don't use IEEE numerics.  Note that this option
527              *only* works if it is supported by the OPTFILE that
528              is being used.
529    
530        -ts | --ts
531              Produce timing information per timestep
532    
533        -mpi | --mpi
534              Include MPI header files and link to MPI libraries
535        -mpi=PATH | --mpi=PATH
536              Include MPI header files and link to MPI libraries using MPI_ROOT
537              set to PATH. i.e. Include files from \$PATH/include, link to libraries
538              from \$PATH/lib and use binaries from \$PATH/bin.
539    
540        -bash NAME
541              Explicitly specify the Bourne or BASH shell to use
542    
543      While it is most often a single word, the "NAME" variables specified
544      above can in many cases be a space-delimited string such as:
545    
546        --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'
547        -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'
548        -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
549    
550      which, depending upon your shell, may need to be single-quoted.
551    
552      For more detailed genmake documentation, please see:
553    
554        http://mitgcm.org/devel_HOWTO/
555    
556    EOF
557    
558      exit 1      exit 1
559  }  }
560    
561  #eh3 # This is the generic configuration.  #  Build a CPP macro to automate calling C routines from FORTRAN
562  #eh3 set LN         = ( 'ln -s' )  get_fortran_c_namemangling()  {
563  #eh3 set CPP        = ( '/lib/cpp -P' )  
564  #eh3 set S64        = ( '$(TOOLSDIR)/set64bitConst.sh' )      #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
565  #eh3 set KPP        = (  )      if test ! "x$FC_NAMEMANGLE" = x ; then
566  #eh3 set FC         = ( 'f77' )          return 0
567  #eh3 set LINK       = $FC      fi
568  #eh3 set MAKEDEPEND = ( 'makedepend' )  
569  #eh3 set INCLUDES   = ( -I. )      default_nm="#define FC_NAMEMANGLE(X) X ## _"
570  #eh3 set FFLAGS     = (  )      
571  #eh3 set FOPTIM     = (  )      cat > genmake_test.c <<EOF
572  #eh3 set CFLAGS     = (  )  void tcall( char * string ) { tsub( string ); }
573  #eh3 set KFLAGS1    = (  )  EOF
574  #eh3 set KFLAGS2    = (  )      $MAKE genmake_test.o >> genmake_warnings 2>&1
575  #eh3 set LIBS       = (  )      RETVAL=$?
576  #eh3 set KPPFILES   = (  )      if test "x$RETVAL" != x0 ; then
577  #eh3 if (! $?NOOPTFILES ) set NOOPTFILES = (  )          FC_NAMEMANGLE=$default_nm
578  #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = (  )          cat <<EOF>> genmake_errors
579    
580    WARNING: C test compile fails
581    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
582    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
583    EOF
584            return 1
585        fi
586        c_tcall=`nm genmake_test.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
587        RETVAL=$?
588        if test "x$RETVAL" != x0 ; then
589            FC_NAMEMANGLE=$default_nm
590            cat <<EOF>> genmake_warnings
591    
592    WARNING: The "nm" command failed.
593    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
594    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
595    EOF
596            return 1
597        fi
598        cat > genmake_tcomp.$FS <<EOF
599          subroutine tcall( string )
600          character*(*) string
601          call tsub( string )
602          end
603    EOF
604        $FC $FFLAGS $DEFINES -c genmake_tcomp.$FS >> genmake_warnings 2>&1
605        RETVAL=$?
606        if test "x$RETVAL" != x0 ; then
607            FC_NAMEMANGLE=$default_nm
608            cat <<EOF>> genmake_warnings
609    
610    WARNING: FORTRAN test compile fails -- please see "genmake_errors"
611    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
612    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
613    EOF
614            return 1
615        fi
616        f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
617        RETVAL=$?
618        if test "x$RETVAL" != x0 ; then
619            FC_NAMEMANGLE=$default_nm
620            cat <<EOF>> genmake_warnings
621    
622    WARNING: The "nm" command failed.
623    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
624    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
625    EOF
626            return 1
627        fi
628    
629        c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
630        f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
631        c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
632        f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
633    
634        nmangle="X"
635        if test "x$c_a" != "x$f_a" ; then
636            comm="echo x$f_a | sed -e 's|x$c_a||'"
637            a=`eval $comm`
638            nmangle="$a ## $nmangle"
639        fi
640        if test "x$c_b" != "x$f_b" ; then
641            comm="echo x$f_b | sed -e 's|x$c_b||'"
642            b=`eval $comm`
643            nmangle="$nmangle ## $b"
644        fi
645    
646        FC_NAMEMANGLE="#define FC_NAMEMANGLE(X)  $nmangle"
647    
648        #  cleanup the testing files
649        rm -f genmake_tcomp.* genmake_test.*
650    }
651    
652    
653    check_HAVE_CLOC()  {
654        get_fortran_c_namemangling
655        cat <<EOF > genmake_tc_1.c
656    $FC_NAMEMANGLE
657    #include <stdio.h>
658    #include <stdlib.h>
659    #include <unistd.h>
660    #include <assert.h>
661    #include <sys/time.h>
662    void FC_NAMEMANGLE(cloc) ( double *curtim )
663    {
664     struct timeval tv1;
665     gettimeofday(&tv1 , (void *)NULL );
666     *curtim =  (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
667     *curtim = *curtim/1.E6;
668    }
669    EOF
670        make genmake_tc_1.o >> genmake_warnings 2>&1
671        RET_C=$?
672        cat <<EOF > genmake_tc_2.$FS
673          program hello
674          REAL*8 wtime
675          external cloc
676          call cloc(wtime)
677          print *," HELLO WORLD", wtime
678          end
679    EOF
680        $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_warnings 2>&1
681        RET_F=$?
682        test -x ./genmake_tc  &&  ./genmake_tc >> genmake_warnings 2>&1
683        RETVAL=$?
684        if test "x$RETVAL" = x0 ; then
685            HAVE_CLOC=t
686            DEFINES="$DEFINES -DHAVE_CLOC"
687        fi
688        rm -f genmake_tc*
689    }
690    
691    
692    check_HAVE_SETRLSTK()  {
693        get_fortran_c_namemangling
694        cat <<EOF > genmake_tc_1.c
695    $FC_NAMEMANGLE
696    #include <sys/time.h>
697    #include <sys/resource.h>
698    #include <unistd.h>
699    void FC_NAMEMANGLE(setrlstk) ()
700    {
701        struct rlimit rls;
702        rls.rlim_cur = RLIM_INFINITY;
703        rls.rlim_max = RLIM_INFINITY;
704        setrlimit(RLIMIT_STACK, &rls);
705        return;
706    }
707    EOF
708        make genmake_tc_1.o >> genmake_warnings 2>&1
709        RET_C=$?
710        cat <<EOF > genmake_tc_2.$FS
711          program hello
712          external setrlstk
713          call setrlstk()
714          end
715    EOF
716        $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_warnings 2>&1
717        RET_F=$?
718        test -x ./genmake_tc  &&  ./genmake_tc >> genmake_warnings 2>&1
719        RETVAL=$?
720        if test "x$RETVAL" = x0 ; then
721            HAVE_SETRLSTK=t
722            DEFINES="$DEFINES -DHAVE_SETRLSTK"
723        fi
724        rm -f genmake_tc*
725    }
726    
727    
728    check_HAVE_STAT()  {
729        get_fortran_c_namemangling
730        cat <<EOF > genmake_tc_1.c
731    $FC_NAMEMANGLE
732    #include <stdio.h>
733    #include <stdlib.h>
734    #include <unistd.h>
735    #include <sys/stat.h>
736    #include <sys/types.h>
737    void FC_NAMEMANGLE(tfsize) ( int *nbyte )
738    {
739        char name[512];
740        struct stat astat;
741    
742        name[0] = 'a'; name[1] = '\0';
743        if (! stat(name, &astat))
744            *nbyte = (int)(astat.st_size);
745        else
746            *nbyte = -1;
747    }
748    EOF
749        make genmake_tc_1.o >> genmake_tc.log 2>&1
750        RET_C=$?
751        cat <<EOF > genmake_tc_2.$FS
752          program hello
753          integer nbyte
754          call tfsize(nbyte)
755          print *," HELLO WORLD", nbyte
756          end
757    EOF
758        $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_tc.log 2>&1
759        RET_F=$?
760        test -x ./genmake_tc  &&  ./genmake_tc >> genmake_tc.log 2>&1
761        RETVAL=$?
762        if test "x$RETVAL" = x0 ; then
763            HAVE_STAT=t
764            DEFINES="$DEFINES -DHAVE_STAT"
765        fi
766        rm -f genmake_tc*
767    }
768    
769    
770    check_netcdf_libs()  {
771        if test ! "x$SKIP_NETCDF_CHECK" = x ; then
772            return
773        fi
774        echo "" > genmake_tnc.log
775        cat <<EOF > genmake_tnc.F
776          program fgennc
777    #include "netcdf.inc"
778    EOF
779        if test ! "x$MPI" = x ; then
780            echo '#include "mpif.h"' >> genmake_tnc.F
781        fi
782        cat <<EOF >> genmake_tnc.F
783          integer iret, ncid, xid
784          iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
785          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
786          iret = nf_def_dim(ncid, 'X', 11, xid)
787          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
788          iret = nf_close(ncid)
789          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
790          end
791    EOF
792        echo "Executing:" > genmake_tnc.log
793        echo "  $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS" \
794            > genmake_tnc.log
795        RET_CPP=f
796        $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null  \
797            &&  RET_CPP=t
798        if test "x$RET_CPP" = xf ; then
799            echo "  WARNING: CPP failed to pre-process the netcdf test." \
800                > genmake_tnc.log
801            echo "    Please check that \$INCLUDES is properly set." \
802                > genmake_tnc.log
803        fi
804        echo "Executing:" > genmake_tnc.log
805        echo "  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS" > genmake_tnc.log
806        echo "  $LINK -o genmake_tnc.o $LIBS" > genmake_tnc.log
807        $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
808            &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
809        RET_COMPILE=$?
810    
811        #EH3  Remove test program execution for machines that either disallow
812        #EH3  execution or cannot support it (eg. cross-compilers)
813        #EH3
814        #EH3 test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1
815        #EH3 RETVAL=$?
816        #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
817    
818        if test "x$RET_COMPILE" = x0 ; then
819            HAVE_NETCDF=t
820        else
821            # try again with "-lnetcdf" added to the libs
822            $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null  \
823                &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
824                &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
825            RET_COMPILE=$?
826            if test "x$RET_COMPILE" = x0 ; then
827                LIBS="$LIBS -lnetcdf"
828                HAVE_NETCDF=t
829            else
830                cat genmake_tnc.log >> genmake_warnings
831            fi
832        fi
833        rm -f genmake_tnc*
834    }
835    
836    
837    
838    ###############################################################################
839    #   Sequential part of script starts here
840    ###############################################################################
841    
842  #  Set defaults here  #  Set defaults here
843  COMMANDL="$0 $@"  COMMANDL="$0 $@"
# Line 170  PLATFORM= Line 846  PLATFORM=
846  LN=  LN=
847  S64=  S64=
848  KPP=  KPP=
849  FC=  #FC=
850    #CC=gcc
851    #CPP=
852  LINK=  LINK=
853    DEFINES=
854  PACKAGES=  PACKAGES=
855  ENABLE=  ENABLE=
856  DISABLE=  DISABLE=
857  MAKEFILE=  # MAKEFILE=
858  MAKEDEPEND=  # MAKEDEPEND=
859  PDEPEND=  PDEPEND=
860  DUMPSTATE=f  DUMPSTATE=t
861  PDEFAULT=  PDEFAULT=
862  OPTFILE=  OPTFILE=
863  INCLUDES="-I."  INCLUDES="-I. $INCLUDES"
864  FFLAGS=  FFLAGS=
865  FOPTIM=  FOPTIM=
866  CFLAGS=  CFLAGS=
867  KFLAGS1=  KFLAGS1=
868  KFLAGS2=  KFLAGS2=
869    #LDADD=
870  LIBS=  LIBS=
871  KPPFILES=  KPPFILES=
872  NOOPTFILES=  NOOPTFILES=
873  NOOPTFLAGS=  NOOPTFLAGS=
874    MPI=
875    MPIPATH=
876    TS=
877    HAVE_TEST_L=
878    
879    # DEFINES checked by test compilation or command-line
880    HAVE_SYSTEM=
881    HAVE_FDATE=
882    FC_NAMEMANGLE=
883    HAVE_CLOC=
884    HAVE_SETRLSTK=
885    HAVE_STAT=
886    HAVE_NETCDF=
887    HAVE_ETIME=
888    IGNORE_TIME=
889    
890  MODS=  MODS=
891  TOOLSDIR=  TOOLSDIR=
892  SOURCEDIRS=  SOURCEDIRS=
893  INCLUDEDIRS=  INCLUDEDIRS=
894    STANDARDDIRS="USE_THE_DEFAULT"
895    
896    G2ARGS=
897    BASH=
898  PWD=`pwd`  PWD=`pwd`
899  MAKE=make  test "x$MAKE" = x  &&  MAKE=make
900  THISHOSTNAME=`hostname`  test "x$AWK" = x   &&  AWK=awk
901    THISHOST=`hostname`
902  THISCWD=`pwd`  THISCWD=`pwd`
903  THISDATE=`date`  THISDATE=`date`
904    THISUSER=`echo $USER`
905    THISVER=
906  MACHINE=`uname -a`  MACHINE=`uname -a`
907  EXECUTABLE=  EXECUTABLE=
908  EXEHOOK=  EXEHOOK=
909  EXEDIR=  EXEDIR=
910    PACKAGES_CONF=
911    IEEE=
912    if test "x$MITGCM_IEEE" != x ; then
913        IEEE=$MITGCM_IEEE
914    fi
915    FS=
916    FS90=
917    
918    AUTODIFF_PKG_USED=f
919    AD_OPTFILE=
920    TAF=
921    AD_TAF_FLAGS=
922    FTL_TAF_FLAGS=
923    SVD_TAF_FLAGS=
924    TAF_EXTRA=
925    TAMC=
926    AD_TAMC_FLAGS=
927    FTL_TAF_FLAGS=
928    SVD_TAMC_FLAGS=
929    TAMC_EXTRA=
930    
931    
932  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
933  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"
934  gm_s2="FC IEEE MPI JAM DUMPSTATE"  gm_s2="FC CPP IEEE TS MPI JAM DUMPSTATE STANDARDDIRS"
935    
936  #  The following state is not directly set by command-line switches  #  The following state is not directly set by command-line switches
937  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 "
938  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
939  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE"
940  gm_s6="EXECUTABLE EXEHOOK EXEDIR"  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
941    gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME"
942    
943  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6"  #  The following are all related to adjoint/tangent-linear stuff
944    gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
945    gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
946    gm_s12="TAF_EXTRA TAMC_EXTRA"
947    
948    gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"
949    gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
950    
951    cat <<EOF
952    
953    GENMAKE :
954    
955    A program for GENerating MAKEfiles for the MITgcm project.  For a
956    quick list of options, use "genmake -h" or for more detail see:
957    
958      http://mitgcm.org/devel_HOWTO/
959    
960    EOF
961    
 echo  
962  echo "===  Processing options files and arguments  ==="  echo "===  Processing options files and arguments  ==="
963  gm_local="./gm_local"  gm_local="genmake_local"
964  echo -n "  getting local config information:  "  for i in . $MODS ; do
965  if test -e $gm_local ; then      if test -r $i/$gm_local ; then
966            . $i/$gm_local
967            break
968        fi
969    done
970    printf "  getting local config information:  "
971    if test -f $gm_local ; then
972      echo "using $gm_local"      echo "using $gm_local"
973      source $gm_local      . $gm_local
974      # echo "DISABLE=$DISABLE"      # echo "DISABLE=$DISABLE"
975      # echo "ENABLE=$ENABLE"      # echo "ENABLE=$ENABLE"
976  else  else
977      echo "none found"      echo "none found"
978  fi  fi
979    
980  #  echo "$0::$1:$2:$3:$4:$5:$6:$7:"  #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
981  #OPTIONS=  #OPTIONS=
982  #n=0  #n=0
983  #for i ; do  #for i ; do
# Line 244  fi Line 988  fi
988  #   n=$(( $n + 1 ))  #   n=$(( $n + 1 ))
989  #done  #done
990  #parse_options  #parse_options
   
991  ac_prev=  ac_prev=
992  for ac_option ; do  for ac_option in "$@" ; do
993    
994        G2ARGS="$G2ARGS \"$ac_option\""
995    
996      # If the previous option needs an argument, assign it.      # If the previous option needs an argument, assign it.
997      if test -n "$ac_prev"; then      if test -n "$ac_prev"; then
# Line 269  for ac_option ; do Line 1014  for ac_option ; do
1014          -optfile=* | --optfile=* | -of=* | --of=*)          -optfile=* | --optfile=* | -of=* | --of=*)
1015              OPTFILE=$ac_optarg ;;              OPTFILE=$ac_optarg ;;
1016                    
1017            -adoptfile | --adoptfile | -adof | --adof)
1018                ac_prev=AD_OPTFILE ;;
1019            -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
1020                AD_OPTFILE=$ac_optarg ;;
1021            
1022          -pdepend | --pdepend)          -pdepend | --pdepend)
1023              ac_prev=PDEPEND ;;              ac_prev=PDEPEND ;;
1024          -pdepend=* | --pdepend=*)          -pdepend=* | --pdepend=*)
# Line 284  for ac_option ; do Line 1034  for ac_option ; do
1034          -make=* | --make=* | -m=* | --m=*)          -make=* | --make=* | -m=* | --m=*)
1035              MAKE=$ac_optarg ;;              MAKE=$ac_optarg ;;
1036                    
1037            -bash | --bash)
1038                ac_prev=BASH ;;
1039            -bash=* | --bash=*)
1040                BASH=$ac_optarg ;;
1041            
1042            -makedepend | --makedepend | -md | --md)
1043                ac_prev=MAKEDEPEND ;;
1044            -makedepend=* | --makedepend=* | -md=* | --md=*)
1045                MAKEDEPEND=$ac_optarg ;;
1046            
1047          -makefile | --makefile | -ma | --ma)          -makefile | --makefile | -ma | --ma)
1048              ac_prev=MAKEFILE ;;              ac_prev=MAKEFILE ;;
1049          -makefile=* | --makefile=* | -ma=* | --ma=*)          -makefile=* | --makefile=* | -ma=* | --ma=*)
1050              MAKEFILE=$ac_optarg ;;              MAKEFILE=$ac_optarg ;;
1051                    
1052          -platform | --platform | -pl | --pl)          -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
1053              ac_prev=PLATFORM ;;              echo "ERROR: The platform option has been removed.  Please specify"
1054          -platform=* | --platform=* | -pl=* | --pl=*)              echo "  the build options using the \"optfile\" mechanism."
1055              PLATFORM=$ac_optarg ;;              echo
1056                usage
1057                ;;
1058                    
1059          -rootdir | --rootdir | -rd | --rd)          -rootdir | --rootdir | -rd | --rd)
1060              ac_prev=ROOTDIR ;;              ac_prev=ROOTDIR ;;
# Line 314  for ac_option ; do Line 1076  for ac_option ; do
1076          -enable=* | --enable=*)          -enable=* | --enable=*)
1077              ENABLE=$ac_optarg ;;              ENABLE=$ac_optarg ;;
1078                    
1079          -noopt | --noopt)          -standarddirs | --standarddirs)
1080              ac_prev=NOOPT ;;              ac_prev=STANDARDDIRS ;;
1081          -noopt=* | --noopt=*)          -standarddirs=* | --standarddirs=*)
1082              NOOPT=$ac_optarg ;;              STANDARDDIRS=$ac_optarg ;;
1083            
1084  #           -cpp | --cpp)  #           -cpp | --cpp)
1085  #               ac_prev=cpp ;;  #               ac_prev=cpp ;;
1086  #           -cpp=* | --cpp=*)  #           -cpp=* | --cpp=*)
1087  #               CPP=$ac_optarg ;;  #               CPP=$ac_optarg ;;
1088                        
1089            -cc | --cc)
1090                ac_prev=CC ;;
1091            -cc=* | --cc=*)
1092                CC=$ac_optarg ;;
1093            
1094          -fortran | --fortran | -fc | --fc)          -fortran | --fortran | -fc | --fc)
1095              ac_prev=FC ;;              ac_prev=FC ;;
1096          -fc=* | --fc=*)          -fc=* | --fc=*)
1097              FC=$ac_optarg ;;              FC=$ac_optarg ;;
1098                    
1099            -fs | --fs)
1100                ac_prev=FS ;;
1101            -fs=* | --fs=*)
1102                FS=$ac_optarg ;;
1103            
1104            -fs90 | --fs90)
1105                ac_prev=FS90 ;;
1106            -fs90=* | --fs90=*)
1107                FS90=$ac_optarg ;;
1108            
1109          -ieee | --ieee)          -ieee | --ieee)
1110              IEEE=1 ;;              IEEE=true ;;
1111          -noieee | --noieee)          -noieee | --noieee)
1112              IEEE=0 ;;              IEEE= ;;
1113            
1114            -ts | --ts)
1115                TS=true ;;
1116    
1117          -mpi | --mpi)          -mpi | --mpi)
1118              MPI=1 ;;              MPI=true ;;
1119          -nompi | --nompi)          -mpi=* | --mpi=*)
1120              MPI=0 ;;              MPIPATH=$ac_optarg
1121                        MPI=true ;;
1122          -jam | --jam)          
1123              JAM=1 ;;  #       -jam | --jam)
1124          -nojam | --nojam)  #           JAM=1 ;;
1125              JAM=0 ;;  #       -nojam | --nojam)
1126    #           JAM=0 ;;
1127                    
1128          -ds | --ds)          -ds | --ds)
1129              DUMPSTATE=t ;;              DUMPSTATE=t ;;
1130                    
1131            -taf_extra | --taf_extra)
1132                ac_prev=TAF_EXTRA ;;
1133            -taf_extra=* | --taf_extra=*)
1134                TAF_EXTRA=$ac_optarg ;;
1135    
1136            -tamc_extra | --tamc_extra)
1137                ac_prev=TAMC_EXTRA ;;
1138            -tamc_extra=* | --tamc_extra=*)
1139                TAMC_EXTRA=$ac_optarg ;;
1140            
1141            -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1142                IGNORE_TIME="-DIGNORE_TIME" ;;
1143    
1144          -*)          -*)
1145              echo "Error: unrecognized option: "$ac_option              echo "Error: unrecognized option: "$ac_option
1146              usage              usage
# Line 361  for ac_option ; do Line 1155  for ac_option ; do
1155            
1156  done  done
1157    
 echo "  getting OPTFILE information:  "  
 if test "x${OPTFILE}" = x ; then  
     echo "Warning: no OPTFILE specified so we'll look for possible settings"  
     printf "\n===  Searching for possible settings for OPTFILE  ===\n"  
     find_possible_configs  
 else  
     if test "x$OPTFILE" = xNONE ; then  
         echo "    OPTFILE=NONE so we'll try to use default settings"  
     else  
         if test -f "$OPTFILE" -a -r "$OPTFILE" ; then  
             echo "    using OPTFILE=\"$OPTFILE\""  
             source "$OPTFILE"  
             RETVAL=$?  
             if test "x$RETVAL" != x0 ; then  
                 echo -n "Error: failed to source OPTFILE \"$OPTFILE\""  
                 echo "--please check that variable syntax is bash-compatible"  
                 exit 1  
             fi  
             if test "x$DUMPSTATE" != xf ; then  
                 cp -f $OPTFILE "gm_optfile"  
             fi  
         else  
             echo "Error: can't read OPTFILE=\"$OPTFILE\""  
             exit 1  
         fi  
     fi  
 fi  
1158    
1159  printf "\n===  Setting defaults  ===\n"  if test -f ./.genmakerc ; then
1160  echo -n "  Adding MODS directories:  "      echo
1161  for d in $MODS ; do      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
1162      if test ! -d $d ; then      echo "  file.  This file format is no longer supported.  Please see:"
1163          echo      echo
1164          echo "Error: MODS directory \"$d\" not found!"      echo "    http://mitgcm.org/devel_HOWTO/"
1165          exit 1      echo
1166      else      echo "  for directions on how to setup and use the new \"genmake2\" input"
1167          echo -n " $d"      echo "  files and send an email to MITgcm-support@mitgcm.org if you want help."
1168          SOURCEDIRS="$SOURCEDIRS $d"      echo
         INCLUDEDIRS="$INCLUDEDIRS $d"  
     fi  
 done  
 echo  
   
 if test "x$MAKEFILE" = x ; then  
     MAKEFILE="Makefile"  
 fi  
 if test "x${PLATFORM}" = x ; then  
     PLATFORM=$p_PLATFORM  
1169  fi  fi
1170    
1171    #  Find the MITgcm ${ROOTDIR}
1172  if test "x${ROOTDIR}" = x ; then  if test "x${ROOTDIR}" = x ; then
1173      if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1174        if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
1175          ROOTDIR=".."          ROOTDIR=".."
1176      else      else
1177          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1178              if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then              if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
1179                  ROOTDIR=$d                  ROOTDIR=$d
1180                  echo -n "Warning:  ROOTDIR was not specified but there appears to be"                  printf "Warning:  ROOTDIR was not specified but there appears to be"
1181                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
1182                  break                  break
1183              fi              fi
# Line 436  if test ! -d ${ROOTDIR} ; then Line 1195  if test ! -d ${ROOTDIR} ; then
1195      exit 1      exit 1
1196  fi  fi
1197    
1198    #  Find the MITgcm ${THISVER}
1199    if test -f "${ROOTDIR}/doc/tag-index" ; then
1200        THISVER=`grep '^checkpoint' ${ROOTDIR}/doc/tag-index | head -1`
1201    fi
1202    
1203    if test "x$MAKEFILE" = x ; then
1204        MAKEFILE="Makefile"
1205    fi
1206    
1207    echo "  getting OPTFILE information:  "
1208    if test "x${OPTFILE}" = x ; then
1209        if test "x$MITGCM_OF" = x ; then
1210            echo "Warning: no OPTFILE specified so we'll look for possible settings"
1211            printf "\n===  Searching for possible settings for OPTFILE  ===\n"
1212            find_possible_configs
1213        else
1214            OPTFILE=$MITGCM_OF
1215        fi
1216    fi
1217    if test "x$OPTFILE" != xNONE ; then
1218        if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
1219            echo "    using OPTFILE=\"$OPTFILE\""
1220            . "$OPTFILE"
1221            RETVAL=$?
1222            if test "x$RETVAL" != x0 ; then
1223                printf "Error: failed to source OPTFILE \"$OPTFILE\""
1224                echo "--please check that variable syntax is bash-compatible"
1225                exit 1
1226            fi
1227            if test "x$DUMPSTATE" != xf ; then
1228                cp -f $OPTFILE "genmake_optfile"
1229            fi
1230        else
1231            echo "Error: can't read OPTFILE=\"$OPTFILE\""
1232            exit 1
1233        fi
1234    fi
1235    
1236    echo "  getting AD_OPTFILE information:  "
1237    if test "x${AD_OPTFILE}" = x ; then
1238        if test "x$MITGCM_AD_OF" = x ; then
1239            AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
1240        else
1241            AD_OPTFILE=$MITGCM_AD_OF
1242        fi
1243    fi
1244    if test "x${AD_OPTFILE}" != xNONE ; then
1245        if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
1246            echo "    using AD_OPTFILE=\"$AD_OPTFILE\""
1247            . "$AD_OPTFILE"
1248            RETVAL=$?
1249            if test "x$RETVAL" != x0 ; then
1250                printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
1251                echo "--please check that variable syntax is bash-compatible"
1252                exit 1
1253            fi
1254            if test "x$DUMPSTATE" != xf ; then
1255                cp -f $AD_OPTFILE "genmake_ad_optfile"
1256            fi
1257        else
1258            echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
1259            exit 1
1260        fi
1261    fi
1262    
1263    #====================================================================
1264    #  Set default values if not set by the optfile
1265    #
1266    #  Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
1267    #  either set defaults or complain and abort!
1268    if test ! "x$BASH" = x ; then
1269        # add a trailing space so that it works within the Makefile syntax (see below)
1270        BASH="$BASH "
1271    fi
1272    if test "x$FC" = x ; then
1273        cat <<EOF 1>&2
1274    
1275    Error: no Fortran compiler: please specify using one of the following:
1276      1) within the options file ("FC=...") as specified by "-of=OPTFILE"
1277      2) the "-fc=XXX" command-line option
1278      3) the "./genmake_local" file
1279    EOF
1280        exit 1
1281    fi
1282    if test "x$CC" = x ; then
1283        CC=cc
1284    #     cat <<EOF 1>&2
1285    # Error: no C compiler: please specify using one of the following:
1286    #   1) within the options file ("CC=...") as specified by "-of=OPTFILE"
1287    #   2) the "-cc=XXX" command-line option
1288    #   3) the "./genmake_local" file
1289    # EOF
1290    #     exit 1
1291    fi
1292    if test "x$LINK" = x ; then
1293        LINK=$FC
1294    fi
1295    if test "x$MAKE" = x ; then
1296        MAKE="make"
1297    fi
1298    if test "x$CPP" = x ; then
1299        CPP=cpp
1300    fi
1301    #EH3 === UGLY ===
1302    #  The following is an ugly little hack to check for $CPP in /lib/ and
1303    #  it should eventually be replaced with a more general function that
1304    #  searches a combo of the user's path and a list of "usual suspects"
1305    #  to find the correct location for binaries such as $CPP.
1306    for i in " " "/lib/" ; do
1307        echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1308    done
1309    #EH3 === UGLY ===
1310    echo "#define A a" | $CPP > test_cpp 2>&1
1311    RETVAL=$?
1312    if test "x$RETVAL" != x0 ; then
1313        cat <<EOF 1>&2
1314    
1315    Error: C pre-processor "$CPP" failed the test case: please specify using:
1316    
1317      1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
1318      2) the "./genmake_local" file
1319      3) with the CPP environment variable
1320    
1321    EOF
1322        exit 1
1323    else
1324        rm -f test_cpp
1325    fi
1326    look_for_makedepend
1327    if test "x$LN" = x ; then
1328        LN="ln -s"
1329    fi
1330    echo "test" > genmake_test_ln
1331    $LN genmake_test_ln genmake_tlink
1332    RETVAL=$?
1333    if test "x$RETVAL" != x0 ; then
1334        cat <<EOF 1>&2
1335    
1336    Error: The command "ln -s" failed -- please specify a working soft-link
1337      command in the optfile.
1338    
1339    EOF
1340        exit 1
1341    fi
1342    test -L genmake_tlink > /dev/null 2>&1
1343    RETVAL=$?
1344    if test "x$RETVAL" = x0 ; then
1345        HAVE_TEST_L=t
1346    fi
1347    rm -f genmake_test_ln genmake_tlink
1348    
1349    #  Check for broken *.F/*.f handling and fix if possible
1350    check_for_broken_Ff
1351    
1352    if test ! "x$MPI" = x ; then
1353          echo "  Turning on MPI cpp macros"
1354          DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
1355    fi
1356    
1357    if test ! "x$TS" = x ; then
1358          echo "  Turning on timing per timestep"
1359          DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1360    fi
1361    
1362    printf "\n===  Checking system libraries  ===\n"
1363    printf "  Do we have the system() command using $FC...  "
1364    cat > genmake_tcomp.$FS <<EOF
1365          program hello
1366          call system('echo hi')
1367          end
1368    EOF
1369    $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1370    RETVAL=$?
1371    if test "x$RETVAL" = x0 ; then
1372        HAVE_SYSTEM=t
1373        DEFINES="$DEFINES -DHAVE_SYSTEM"
1374        echo "yes"
1375    else
1376        HAVE_SYSTEM=
1377        echo "no"
1378    fi
1379    rm -f genmake_tcomp*
1380    
1381    printf "  Do we have the fdate() command using $FC...  "
1382    cat > genmake_tcomp.$FS <<EOF
1383          program hello
1384          CHARACTER*(128) string
1385          string = ' '
1386          call fdate( string )
1387          print *, string
1388          end
1389    EOF
1390    $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1391    RETVAL=$?
1392    if test "x$RETVAL" = x0 ; then
1393        HAVE_FDATE=t
1394        DEFINES="$DEFINES -DHAVE_FDATE"
1395        echo "yes"
1396    else
1397        HAVE_FDATE=
1398        echo "no"
1399    fi
1400    rm -f genmake_tcomp*
1401    
1402    printf "  Do we have the etime() command using $FC...  "
1403    cat > genmake_tcomp.$FS <<EOF
1404          program hello
1405          REAL*4 ACTUAL, TARRAY(2)
1406          EXTERNAL ETIME
1407          REAL*4 ETIME
1408          actual = etime( tarray )
1409          print *, tarray
1410          end
1411    EOF
1412    $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1413    RETVAL=$?
1414    if test "x$RETVAL" = x0 ; then
1415        HAVE_ETIME=t
1416        DEFINES="$DEFINES -DHAVE_ETIME"
1417        echo "yes"
1418    else
1419        HAVE_ETIME=
1420        echo "no"
1421    fi
1422    rm -f genmake_tcomp*
1423    
1424    printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
1425    check_HAVE_CLOC
1426    if test "x$HAVE_CLOC" != x ; then
1427        echo "yes"
1428    else
1429        echo "no"
1430    fi
1431    rm -f genmake_t*
1432    
1433    printf "  Can we unlimit the stack size using $FC...  "
1434    check_HAVE_SETRLSTK
1435    if test "x$HAVE_SETRLSTK" != x ; then
1436        echo "yes"
1437    else
1438        echo "no"
1439    fi
1440    rm -f genmake_t*
1441    
1442    printf "  Can we use stat() through C calls...  "
1443    check_HAVE_STAT
1444    if test "x$HAVE_STAT" != x ; then
1445        echo "yes"
1446    else
1447        echo "no"
1448    fi
1449    rm -f genmake_t*
1450    
1451    printf "  Can we create NetCDF-enabled binaries...  "
1452    check_netcdf_libs
1453    if test "x$HAVE_NETCDF" != x ; then
1454        echo "yes"
1455    else
1456        echo "no"
1457    fi
1458    DEFINES="$DEFINES $IGNORE_TIME"
1459    
1460    printf "\n===  Setting defaults  ===\n"
1461    printf "  Adding MODS directories:  "
1462    for d in $MODS ; do
1463        if test ! -d $d ; then
1464            echo
1465            echo "Error: MODS directory \"$d\" not found!"
1466            exit 1
1467        else
1468            printf " $d"
1469            SOURCEDIRS="$SOURCEDIRS $d"
1470            INCLUDEDIRS="$INCLUDEDIRS $d"
1471        fi
1472    done
1473    echo
1474    
1475    if test "x${PLATFORM}" = x ; then
1476        PLATFORM=$p_PLATFORM
1477    fi
1478    
1479  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
1480      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1481        if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
1482          EXEDIR=../exe          EXEDIR=../exe
1483      else      else
1484          EXEDIR=.          EXEDIR=.
# Line 452  if test "x${TOOLSDIR}" = x ; then Line 1493  if test "x${TOOLSDIR}" = x ; then
1493      TOOLSDIR="$ROOTDIR/tools"      TOOLSDIR="$ROOTDIR/tools"
1494  fi  fi
1495  if test ! -d ${TOOLSDIR} ; then  if test ! -d ${TOOLSDIR} ; then
1496      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
1497      exit 1      exit 1
1498  fi  fi
1499    if test "x$S64" = x ; then
1500        echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1
1501        RETVAL=$?
1502        if test "x${RETVAL}" = x0 ; then
1503            S64='$(TOOLSDIR)/set64bitConst.sh'
1504        else
1505            echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1
1506            RETVAL=$?
1507            if test "x${RETVAL}" = x0 ; then
1508                S64='$(TOOLSDIR)/set64bitConst.csh'
1509            else
1510                cat <<EOF
1511    
1512    ERROR: neither of the two default scripts:
1513    
1514        ${TOOLSDIR}/set64bitConst.sh
1515        ${TOOLSDIR}/set64bitConst.csh
1516    
1517      are working so please check paths or specify (with \$S64) a
1518      working version of this script.
1519    
1520    EOF
1521                exit 1
1522            fi
1523        fi
1524    fi
1525    THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
1526    
1527  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1528    
# Line 463  EXECUTABLE=${EXECUTABLE:-mitgcmuv} Line 1531  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1531  #  they appear as regular source code  #  they appear as regular source code
1532  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
1533      echo "  Making source files in eesupp from templates"      echo "  Making source files in eesupp from templates"
1534      $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1      ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1
1535      RETVAL=$?      RETVAL=$?
1536      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
1537          rm -f make_eesupp.errors          rm -f make_eesupp.errors
1538      else      else
1539          echo "Error: problem encountered while building source files in eesupp:"          echo "Error: problem encountered while building source files in eesupp:"
1540          cat make_eesupp.errors          cat make_eesupp.errors 1>&2
1541          exit 1          exit 1
1542      fi      fi
1543  fi  fi
1544    
1545    #same for exch2
1546    if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then
1547        echo "  Making source files in exch2 from  templates"
1548        ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1
1549        RETVAL=$?
1550        if test "x${RETVAL}" = x0 ; then
1551            rm -f make_exch2.errors
1552        else
1553            echo "Error: problem encountered while building source files in exch2:"
1554            cat make_exch2.errors 1>&2
1555            exit 1
1556        fi
1557    fi
1558    
1559  printf "\n===  Determining package settings  ===\n"  printf "\n===  Determining package settings  ===\n"
1560  if  test "x${PDEPEND}" = x ; then  if  test "x${PDEPEND}" = x ; then
1561      tmp=$ROOTDIR"/pkg/pkg_depend"      tmp=$ROOTDIR"/pkg/pkg_depend"
# Line 493  echo "  getting package dependency info Line 1575  echo "  getting package dependency info
1575  #  Strip the comments and then convert the dependency file into  #  Strip the comments and then convert the dependency file into
1576  #  two arrays: PNAME, DNAME  #  two arrays: PNAME, DNAME
1577  cat $PDEPEND | sed -e 's/#.*$//g' \  cat $PDEPEND | sed -e 's/#.*$//g' \
1578      | 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}' \
1579      > ./.pd_tmp      > ./.pd_tmp
1580  RETVAL=$?  RETVAL=$?
1581  if test ! "x${RETVAL}" = x0 ; then  if test ! "x${RETVAL}" = x0 ; then
1582      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
1583      exit 1      exit 1
1584  fi  fi
1585  source ./.pd_tmp  . ./.pd_tmp
1586  rm -f ./.pd_tmp  rm -f ./.pd_tmp
1587    
1588  echo  -n "  checking default package list:  "  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"
1589    #  file should eventually be added so that, for convenience, one can
1590    #  specify groups of packages using names like "ocean" and "atmosphere".
1591    echo "  checking default package list:  "
1592    if test "x${PDEFAULT}" = x ; then
1593        for i in "." $MODS ; do
1594            if test -r $i"/packages.conf" ; then
1595                    PDEFAULT=$i"/packages.conf"
1596                    break
1597            fi
1598        done
1599    fi
1600  if test "x${PDEFAULT}" = x ; then  if test "x${PDEFAULT}" = x ; then
1601      PDEFAULT="$ROOTDIR/pkg/pkg_default"      PDEFAULT="$ROOTDIR/pkg/pkg_default"
1602  fi  fi
1603  if test "x${PDEFAULT}" = xNONE ; then  if test "x${PDEFAULT}" = xNONE ; then
1604      echo "default packages file disabled"      echo "    default packages file disabled"
1605  else  else
1606      if test ! -r $PDEFAULT ; then      if test ! -r $PDEFAULT ; then
         echo ""  
1607          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""
1608      else      else
1609          echo "  using PDEFAULT=\"$PDEFAULT\""          echo "    using PDEFAULT=\"$PDEFAULT\""
1610          #  Strip the comments and add all the names          #  Strip the comments and add all the names
1611          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | awk '(NF>0){print $0}'`          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
1612          RETVAL=$?          RETVAL=$?
1613          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
1614              echo -n "Error: can't parse default package list "              printf "Error: can't parse default package list "
1615              echo "-- please check PDEFAULT=\"$PDEFAULT\""              echo "-- please check PDEFAULT=\"$PDEFAULT\""
1616              exit 1              exit 1
1617          fi          fi
1618          for i in $def ; do          for i in $def ; do
1619              PACKAGES="$PACKAGES $i"              PACKAGES="$PACKAGES $i"
1620          done          done
1621          echo "    packages are:  $PACKAGES"          echo "    before group expansion packages are: $PACKAGES"
1622            RET=1
1623            while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
1624            echo "    after group expansion packages are:  $PACKAGES"
1625      fi      fi
1626  fi  fi
1627    
1628  echo "  applying DISABLE settings"  echo "  applying DISABLE settings"
1629    for i in $PACKAGES ; do
1630        echo $i >> ./.tmp_pack
1631    done
1632    for i in `grep  "-" ./.tmp_pack` ; do
1633        j=`echo $i | sed 's/[-]//'`
1634        DISABLE="$DISABLE $j"
1635    done
1636  pack=  pack=
1637  for p in $PACKAGES ; do  for p in $PACKAGES ; do
1638      addit="t"      addit="t"
# Line 545  for p in $PACKAGES ; do Line 1647  for p in $PACKAGES ; do
1647  done  done
1648  PACKAGES="$pack"  PACKAGES="$pack"
1649  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
1650  rm -f ./.tmp_pack  echo "" > ./.tmp_pack
1651  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
1652    # Test if each explicitly referenced package exists
1653  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1654      if test ! -d "$ROOTDIR/pkg/$i" ; then      j=`echo $i | sed 's/[-+]//'`
1655        if test ! -d "$ROOTDIR/pkg/$j" ; then
1656          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
1657          exit 1          exit 1
1658      fi      fi
1659      echo $i >> ./.tmp_pack      echo $i >> ./.tmp_pack
1660  done  done
 pack=`cat ./.tmp_pack | sort | uniq`  
 rm -f ./.tmp_pack  
1661  PACKAGES=  PACKAGES=
1662  for i in $pack ; do  for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do
1663      PACKAGES="$PACKAGES $i"      PACKAGES="$PACKAGES $i"
1664  done  done
1665    rm -f ./.tmp_pack
1666  echo "    packages are:  $PACKAGES"  echo "    packages are:  $PACKAGES"
1667    
1668    #  Check availability of NetCDF and then either build the MNC template
1669    #  files or delete mnc from the list of available packages.
1670    echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1
1671    RETVAL=$?
1672    if test "x$RETVAL" = x0 ; then
1673        if test "x$HAVE_NETCDF" != xt ; then
1674            cat <<EOF
1675    
1676    *********************************************************************
1677    WARNING: the "mnc" package was enabled but tests failed to compile
1678      NetCDF applications.  Please check that:
1679    
1680      1) NetCDF is correctly installed for this compiler and
1681      2) the LIBS variable (within the "optfile") specifies the correct
1682           NetCDF library to link against.
1683    
1684      Due to this failure, the "mnc" package is now DISABLED.
1685    *********************************************************************
1686    
1687    EOF
1688            PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
1689            DISABLE="$DISABLE mnc"
1690        else
1691            ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
1692            RETVAL=$?
1693            if test "x${RETVAL}" = x0 ; then
1694                rm -f make_mnc.errors
1695            else
1696                echo "Error: problem encountered while building source files in pkg/mnc:"
1697                cat make_mnc.errors 1>&2
1698                exit 1
1699            fi
1700        fi
1701    fi
1702    
1703  echo "  applying package dependency rules"  echo "  applying package dependency rules"
1704  ck=  ck=
1705  while test "x$ck" != xtt ; do  while test "x$ck" != xtt ; do
# Line 626  while test "x$ck" != xtt ; do Line 1764  while test "x$ck" != xtt ; do
1764              echo "  the dependency rules for \"$dname\""              echo "  the dependency rules for \"$dname\""
1765              exit 1              exit 1
1766          fi          fi
1767          i=$(( $i + 1 ))          i=`echo "$i + 1" | bc -l`
1768            #i=$(( $i + 1 ))
1769      done      done
1770      ck=$ck"t"      ck=$ck"t"
1771  done  done
# Line 636  for i in $PACKAGES ; do Line 1775  for i in $PACKAGES ; do
1775      if test -d $adr ; then      if test -d $adr ; then
1776          SOURCEDIRS="$SOURCEDIRS $adr"          SOURCEDIRS="$SOURCEDIRS $adr"
1777          INCLUDEDIRS="$INCLUDEDIRS $adr"          INCLUDEDIRS="$INCLUDEDIRS $adr"
1778            if test "x$i" = xautodiff ; then
1779                AUTODIFF_PKG_USED=t
1780            fi
1781      else      else
1782          echo "Error: the directory \"$adr\" for package $i doesn't exist"          echo "Error: the directory \"$adr\" for package $i doesn't exist"
1783          exit 1          exit 1
1784      fi      fi
1785  done  done
1786    
1787  #  This is compatible with the old genmake.  The "DISABLE_*" flags  # Create a list of #define and #undef to enable/disable packages
1788  #  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  
1789  #  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
1790  #  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
1791  #  file would eventually be split up so that all package-related #define  #  file would eventually be split up so that all package-related #define
1792  #  statements could be separated and handled only by genmake.  #  statements could be separated and handled only by genmake.
1793  names=`ls -1 "$ROOTDIR/pkg"`  names=`ls -1 "$ROOTDIR/pkg"`
1794  all_pack=  all_pack=
1795    DISABLED_PACKAGES=
1796  for n in $names ; do  for n in $names ; do
1797      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
1798          has_pack="f"          has_pack="f"
# Line 713  for n in $names ; do Line 1803  for n in $names ; do
1803              fi              fi
1804          done          done
1805          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
1806              undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1807              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!!!  
   
1808          fi          fi
1809      fi      fi
1810  done  done
1811  cat <<EOF >>CPP_OPTIONS.h.tmp  ENABLED_PACKAGES=
   
 C  Packages enabled by genmake:  
 EOF  
1812  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1813      def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`      def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1814      echo "#define $def" >> CPP_OPTIONS.h.tmp      ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
1815    #eh3 DEFINES="$DEFINES -D$def"
1816    
1817  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1818      case $i in      case $i in
1819          aim_v23)          aim_v23)
1820              echo "#define   ALLOW_AIM" >> CPP_OPTIONS.h.tmp              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
1821                echo "Warning: ALLOW_AIM is set to enable aim_v23."
1822              ;;              ;;
1823      esac      esac
1824  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1825    
1826  done  done
 mv -f CPP_OPTIONS.h.tmp CPP_OPTIONS.h  
1827    
1828  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS"
1829  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
1830  STANDARDDIRS=${STANDARDDIRS:-"eesupp model"}  if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
1831  for d in $STANDARDDIRS ; do      STANDARDDIRS="eesupp model"
1832      adr="$ROOTDIR/$d/src"  fi
1833      if test ! -d $adr ; then  if test "x$STANDARDDIRS" != x ; then
1834          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""      for d in $STANDARDDIRS ; do
1835          echo "  is correct and that you correctly specified the STANDARDDIRS option"          adr="$ROOTDIR/$d/src"
1836          exit 1          if test ! -d $adr ; then
1837      else              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1838          SOURCEDIRS="$SOURCEDIRS $adr"              echo "  is correct and that you correctly specified the STANDARDDIRS option"
1839      fi              exit 1
1840      adr="$ROOTDIR/$d/inc"          else
1841      if test ! -d $adr ; then              SOURCEDIRS="$SOURCEDIRS $adr"
1842          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""          fi
1843          echo "  is correct and that you correctly specified the STANDARDDIRS option"          adr="$ROOTDIR/$d/inc"
1844          exit 1          if test ! -d $adr ; then
1845      else              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1846          INCLUDEDIRS="$INCLUDEDIRS $adr"              echo "  is correct and that you correctly specified the STANDARDDIRS option"
1847                exit 1
1848            else
1849                INCLUDEDIRS="$INCLUDEDIRS $adr"
1850            fi
1851        done
1852    fi
1853    
1854    echo "  Searching for *OPTIONS.h files in order to warn about the presence"
1855    echo "    of \"#define \"-type statements that are no longer allowed:"
1856    CPP_OPTIONS=
1857    CPP_EEOPTIONS=
1858    spaths=". $INCLUDEDIRS"
1859    names=`ls -1 "$ROOTDIR/pkg"`
1860    for i in $spaths ; do
1861        try="$i/CPP_OPTIONS.h"
1862        if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
1863            echo "    found CPP_OPTIONS=\"$try\""
1864            CPP_OPTIONS="$try"
1865            # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
1866            for n in $names ; do
1867                test_for_package_in_cpp_options $CPP_OPTIONS $n
1868            done
1869        fi
1870        try="$i/CPP_EEOPTIONS.h"
1871        if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
1872            echo "    found CPP_EEOPTIONS=\"$try\""
1873            # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
1874    #**** not yet enabled ****
1875    #        test_for_mpi_in_cpp_eeoptions $try
1876    #**** not yet enabled ****
1877            CPP_EEOPTIONS="$try"
1878      fi      fi
1879  done  done
1880    if test "x$CPP_OPTIONS" = x ; then
1881        echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
1882        exit 1
1883    fi
1884    
1885    #  Here, we build the list of files to be "run through" the adjoint
1886    #  compiler.
1887    if test -f ./ad_files ; then
1888        rm -f ./ad_files
1889    fi
1890    echo "  Creating the list of files for the adjoint compiler."
1891    for i in $SOURCEDIRS ; do
1892        list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
1893        for j in $list_files ; do
1894            cat $i/$j >> ad_files
1895        done
1896    done
1897    if test ! "x"$FS = "x.f" ; then
1898        cat ad_files | sed -e "s/\.f/.$FS/g" > ad_files_f
1899        mv -f ad_files_f ad_files
1900    fi
1901    
1902  echo  echo
1903  echo "===  Creating the Makefile  ==="  echo "===  Creating the Makefile  ==="
1904  echo "  setting INCLUDES"  echo "  setting INCLUDES"
1905  for i in $INCLUDEDIRS ; do  for i in $INCLUDEDIRS ; do
1906      if test -d $i ; then      if test ! -d $i ; then
         INCLUDES="$INCLUDES -I$i"  
     else  
1907          echo "Warning: can't find INCLUDEDIRS=\"$i\""          echo "Warning: can't find INCLUDEDIRS=\"$i\""
1908      fi      fi
1909  done  done
# Line 794  rm -rf .links.tmp Line 1913  rm -rf .links.tmp
1913  mkdir .links.tmp  mkdir .links.tmp
1914  echo "# This section creates symbolic links" > srclinks.tmp  echo "# This section creates symbolic links" > srclinks.tmp
1915  echo "" >> srclinks.tmp  echo "" >> srclinks.tmp
1916  echo -n 'SRCFILES = '    > srclist.inc  printf 'SRCFILES = '    > srclist.inc
1917  echo -n 'CSRCFILES = '   > csrclist.inc  printf 'CSRCFILES = '   > csrclist.inc
1918  echo -n 'F90SRCFILES = ' > f90srclist.inc  printf 'F90SRCFILES = ' > f90srclist.inc
1919  echo -n 'HEADERFILES = ' > hlist.inc  printf 'HEADERFILES = ' > hlist.inc
1920  alldirs=". $SOURCEDIRS $INCLUDEDIRS"  printf 'AD_FLOW_FILES = ' > ad_flow_files.inc
1921    alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1922  for d in $alldirs ; do  for d in $alldirs ; do
1923      deplist=      deplist=
1924      sfiles=`( cd $d; echo *.[h,c,F] )`      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
1925      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
1926      for sf in $sfiles ; do      for sf in $sfiles ; do
1927          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
1928              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
1929                  extn=`echo $sf | awk -F '.' '{print $NF}'`                  ignore_f=f
1930                  touch .links.tmp/$sf                  case $d/$sf in
1931                  deplist="$deplist $sf"                    ./$PACKAGES_DOT_H)
                 case $extn in  
                     F)  
                         echo    " \\"  >> srclist.inc  
                         echo -n " $sf" >> srclist.inc  
1932                          ;;                          ;;
1933                      F90)                    ./AD_CONFIG.h)
                         echo    " \\"  >> f90srclist.inc  
                         echo -n " $sf" >> f90srclist.inc  
1934                          ;;                          ;;
1935                      c)                    ./FC_NAMEMANGLE.h)
                         echo    " \\"  >> csrclist.inc  
                         echo -n " $sf" >> csrclist.inc  
1936                          ;;                          ;;
1937                      h)                    ./BUILD_INFO.h)
                         echo    " \\"  >> hlist.inc  
                         echo -n " $sf" >> hlist.inc  
1938                          ;;                          ;;
1939                  esac                    *)
1940                            #  For the local directory *ONLY*,
1941                            #  ignore all soft-links
1942                            if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then
1943                                ignore_f=t
1944                            else
1945                                touch .links.tmp/$sf
1946                                deplist="$deplist $sf"
1947                            fi
1948                            ;;
1949                    esac
1950                    if test "x$ignore_f" = xf ; then
1951                        extn=`echo $sf | $AWK -F. '{print $NF}'`
1952                        case $extn in
1953                            F)
1954                                echo    " \\"  >> srclist.inc
1955                                printf " $sf" >> srclist.inc
1956                                ;;
1957                            F90)
1958                                echo    " \\"  >> f90srclist.inc
1959                                printf " $sf" >> f90srclist.inc
1960                                ;;
1961                            c)
1962                                echo    " \\"  >> csrclist.inc
1963                                printf " $sf" >> csrclist.inc
1964                                ;;
1965                            h)
1966                                echo    " \\"  >> hlist.inc
1967                                printf " $sf" >> hlist.inc
1968                                ;;
1969                            flow)
1970                                echo    " \\"  >> ad_flow_files.inc
1971                                printf " $sf" >> ad_flow_files.inc
1972                                ;;
1973                        esac
1974                    fi
1975              fi              fi
1976          fi          fi
1977      done      done
# Line 842  echo "" >> srclist.inc Line 1987  echo "" >> srclist.inc
1987  echo "" >> csrclist.inc  echo "" >> csrclist.inc
1988  echo "" >> f90srclist.inc  echo "" >> f90srclist.inc
1989  echo "" >> hlist.inc  echo "" >> hlist.inc
1990    echo "" >> ad_flow_files.inc
1991    
1992  if test -e $MAKEFILE ; then  if test -f $MAKEFILE ; then
1993      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.bak"
1994  fi  fi
1995  echo "  Writing makefile: $MAKEFILE"  echo "  Writing makefile: $MAKEFILE"
# Line 852  echo "#    $MACHINE" >> $MAKEFILE Line 1998  echo "#    $MACHINE" >> $MAKEFILE
1998  echo "# This makefile was generated automatically on" >> $MAKEFILE  echo "# This makefile was generated automatically on" >> $MAKEFILE
1999  echo "#    $THISDATE" >> $MAKEFILE  echo "#    $THISDATE" >> $MAKEFILE
2000  echo "# by the command:" >> $MAKEFILE  echo "# by the command:" >> $MAKEFILE
2001  echo "#    $0 $@" >> $MAKEFILE  echo "#    $0 $G2ARGS" >> $MAKEFILE
2002  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
2003  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE  echo "#    ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
2004    
2005    EXE_AD=$EXECUTABLE"_ad"
2006    EXE_FTL=$EXECUTABLE"_ftl"
2007    EXE_SVD=$EXECUTABLE"_svd"
2008    
2009  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2010    #
2011    # OPTFILE="$OPTFILE"
2012  #  #
2013  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
2014  # SOURCEDIRS   : Directories containing the source (.F) files  # SOURCEDIRS   : Directories containing the source (.F) files
# Line 883  EXEDIR      = ${EXEDIR} Line 2036  EXEDIR      = ${EXEDIR}
2036  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}
2037  TOOLSDIR    = ${TOOLSDIR}  TOOLSDIR    = ${TOOLSDIR}
2038    
2039    #eh3  new defines for the adjoint work
2040    AUTODIFF    = ${ROOTDIR}/pkg/autodiff
2041    EXE_AD      = ${EXE_AD}
2042    EXE_FTL     = ${EXE_FTL}
2043    EXE_SVD     = ${EXE_SVD}
2044    
2045    ENABLED_PACKAGES = ${ENABLED_PACKAGES}
2046    DISABLED_PACKAGES = ${DISABLED_PACKAGES}
2047    
2048    # These files are created by Makefile
2049    SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h
2050    
2051  EOF  EOF
2052    
2053  #  Note: figure out some way to add Hyades JAM libraries here  #  Note: figure out some way to add Hyades JAM libraries here
# Line 900  KPP = ${KPP} Line 2065  KPP = ${KPP}
2065  FC = ${FC}  FC = ${FC}
2066  # Fortran compiler  # Fortran compiler
2067  F90C = ${F90C}  F90C = ${F90C}
2068    # C compiler
2069    CC = ${CC}
2070  # Link editor  # Link editor
2071  LINK = ${LINK}  LINK = ${LINK} ${LDADD}
2072    
2073  # Defines for CPP  # Defines for CPP
2074  DEFINES = ${DEFINES}  DEFINES = ${DEFINES}
# Line 922  CFLAGS = ${CFLAGS} Line 2089  CFLAGS = ${CFLAGS}
2089  NOOPTFILES = ${NOOPTFILES}  NOOPTFILES = ${NOOPTFILES}
2090  NOOPTFLAGS = ${NOOPTFLAGS}  NOOPTFLAGS = ${NOOPTFLAGS}
2091  # Flags and libraries needed for linking  # Flags and libraries needed for linking
2092  LIBS = ${LIBS} \$(XLIBS)  LIBS = ${LIBS}
2093  # Name of the Mekfile  # Name of the Mekfile
2094  MAKEFILE=${MAKEFILE}  MAKEFILE=${MAKEFILE}
2095    
2096  EOF  EOF
2097    
2098  cat srclist.inc    >> $MAKEFILE  cat srclist.inc       >> $MAKEFILE
2099  cat csrclist.inc   >> $MAKEFILE  cat csrclist.inc      >> $MAKEFILE
2100  cat f90srclist.inc >> $MAKEFILE  cat f90srclist.inc    >> $MAKEFILE
2101  cat hlist.inc      >> $MAKEFILE  cat hlist.inc         >> $MAKEFILE
2102  echo 'F77FILES =  $(SRCFILES:.F=.f)'                                           >> $MAKEFILE  cat ad_flow_files.inc >> $MAKEFILE
2103  echo 'F90FILES =  $(F90SRCFILES:.F90=.f90)'                                    >> $MAKEFILE  echo >> $MAKEFILE
2104    echo 'F77FILES =  $(SRCFILES:.F=.'$FS')'      >> $MAKEFILE
2105    echo 'F90FILES =  $(F90SRCFILES:.F90=.'$FS90')' >> $MAKEFILE
2106  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
2107    echo >> $MAKEFILE
2108    echo '.SUFFIXES:' >> $MAKEFILE
2109    echo '.SUFFIXES: .o .'$FS' .p .F .c .'$FS90' .F90' >> $MAKEFILE
2110  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
2111    rm -f ad_flow_files.inc
2112    
2113  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2114    
 .SUFFIXES:  
 .SUFFIXES: .o .f .p .F .c .F90 .f90  
   
2115  all: \$(EXECUTABLE)  all: \$(EXECUTABLE)
2116  \$(EXECUTABLE): \$(OBJFILES)  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(OBJFILES)
2117            @echo Creating \$@ ...
2118          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
2119  depend:  depend:
2120          @make links          @make links
2121          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
2122          ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE)          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2123            -rm -f makedepend.out
2124    
2125    lib: libmitgcmuv.a
2126    
2127  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)  libmitgcmuv.a: \$(OBJFILES)
2128            ar rcv libmitgcmuv.a \$(OBJFILES)
2129    
2130    links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES)
2131    
2132  small_f: \$(F77FILES) \$(F90FILES)  small_f: \$(F77FILES) \$(F90FILES)
2133    
# Line 960  output.txt: \$(EXECUTABLE) Line 2136  output.txt: \$(EXECUTABLE)
2136          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
2137    
2138  clean:  clean:
2139          -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}          -rm -rf *.o *.$FS *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
2140  Clean:  Clean:
2141          @make clean          @make clean
2142          @make cleanlinks          @make cleanlinks
2143          -rm -f Makefile.bak          -rm -f \$(SPECIAL_FILES)
2144            -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak
2145  CLEAN:  CLEAN:
2146          @make Clean          @make Clean
2147          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
2148          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
2149          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
2150          -rm -f \$(EXECUTABLE)          -rm -f \$(EXECUTABLE) output.txt STD*
2151    
2152    #eh3 Makefile: makefile
2153  makefile:  makefile:
2154          ${0} $@          $THIS_SCRIPT $G2ARGS
2155  cleanlinks:  cleanlinks:
2156          -find . -type l -exec rm {} \;          -find . -type l -exec rm {} \;
2157    
2158  # The normal chain of rules is (  .F - .f - .o  )  # Special targets (SPECIAL_FILES) which are create by make
2159  .F.f:  ${PACKAGES_DOT_H}:
2160            @echo Creating \$@ ...
2161            @$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) > \$@
2162    AD_CONFIG.h:
2163            @echo Creating \$@ ...
2164            @$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 > \$@
2165    FC_NAMEMANGLE.h:
2166            @echo Creating \$@ ...
2167            echo "$FC_NAMEMANGLE" > \$@
2168    
2169    BUILD_INFO.h:
2170            @echo Creating \$@ ...
2171    EOF
2172    
2173    test ! "x$THISVER" = x  && echo "       -echo \"#define THISVER '$THISVER'\" > \$@"   >> $MAKEFILE
2174    test ! "x$THISUSER" = x && echo "       -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE
2175    test ! "x$THISDATE" = x && echo "       -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
2176    test ! "x$THISHOST" = x && echo "       -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
2177    
2178    cat >>$MAKEFILE <<EOF
2179    
2180    # The normal chain of rules is (  .F - .$FS - .o  )
2181    
2182    ## This nullifies any default implicit rules concerning these two file types:
2183    ## %.o : %.F
2184    
2185    .F.$FS:
2186          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2187  .f.o:  .$FS.o:
2188          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2189  .F90.f90:  .F90.$FS90:
2190          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2191  .f90.o:  .$FS90.o:
2192          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
2193  .c.o:  .c.o:
2194          \$(CC) \$(CFLAGS) -c \$<          \$(CC) \$(CFLAGS) -c \$<
2195    
2196  # Special exceptions that use the ( .F - .p - .f - .o ) rule-chain  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
2197  .F.p:  .F.p:
2198          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2199  .p.f:  .p.$FS:
2200          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
2201    
2202    #=========================================
2203    #===  Automatic Differentiation Rules  ===
2204    
2205    TAMC           = ${TAMC}
2206    TAF            = ${TAF}
2207    
2208    TAF_EXTRA      = ${TAF_EXTRA}
2209    TAMC_EXTRA     = ${TAMC_EXTRA}
2210    
2211    EOF
2212    
2213    ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
2214    ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF_FLAGS"
2215    ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
2216    for i in $ad_vars ; do
2217        name=$i
2218        t1="t2=\$"`echo $i`
2219        eval $t1
2220        printf "%-20s = " $name >> $MAKEFILE
2221        echo $t2 >> $MAKEFILE
2222    done
2223    
2224    echo "  Add the source list for AD code generation"
2225    echo >> $MAKEFILE
2226    printf "AD_FILES = " >> $MAKEFILE
2227    AD_FILES=`cat ad_files`
2228    for i in $AD_FILES ; do
2229        echo    " \\" >> $MAKEFILE
2230        printf " $i" >> $MAKEFILE
2231    done
2232    echo >> $MAKEFILE
2233    rm -f ad_files
2234    
2235    cat >>$MAKEFILE <<EOF
2236    
2237    # ... AD ...
2238    adall: ad_taf
2239    adtaf: ad_taf_output.$FS
2240    adtamc: ad_tamc_output.$FS
2241    
2242    ad_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)
2243            @$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
2244            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
2245            -rm -f ad_config.template
2246            @make \$(F77FILES)
2247            @make \$(AD_FLOW_FILES)
2248            cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.$FS
2249    
2250    ad_taf_output.$FS: ad_input_code.$FS
2251            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2252            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
2253    
2254    adtafonly:
2255            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2256            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
2257    
2258    ad_taf: ad_taf_output.o \$(OBJFILES)
2259            \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
2260    
2261    ad_tamc_output.$FS: ad_input_code.$FS
2262            \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
2263            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS
2264    
2265    ad_tamc: ad_tamc_output.o \$(OBJFILES)
2266            \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
2267    
2268    adonlyfwd:
2269            patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
2270    
2271    adtrick:
2272            patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
2273    
2274    # ... FTL ...
2275    ftlall: ftl_taf
2276    ftltaf: ftl_taf_output.$FS
2277    ftltamc: ftl_tamc_output.$FS
2278    
2279    ftl_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)
2280            @$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
2281            cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
2282            -rm -f ftl_config.template
2283            @make \$(F77FILES)
2284            @make \$(AD_FLOW_FILES)
2285            cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.$FS
2286    
2287    ftl_taf_output.$FS: ftl_input_code.$FS
2288            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2289            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2290    
2291    ftltafonly:
2292            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2293            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2294    
2295    ftl_taf: ftl_taf_output.o \$(OBJFILES)
2296            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
2297    
2298    ftl_tamc_output.$FS: ftl_input_code.$FS
2299            \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
2300            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS
2301    
2302    ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
2303            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
2304    
2305    
2306    # ... SVD ...
2307    svdtaf: ad_taf_output.$FS ftl_taf_output.$FS
2308            @echo "--->>> Only ran TAF to generate SVD code!    <<<---"
2309            @echo "--->>> Do make svdall afterwards to compile. <<<---"
2310    svdall: svd_touch svd_taf
2311    
2312    svd_taf: \$(OBJFILES)
2313            \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
2314    
2315            @echo "--->>> Only COMPILE svd code! <<<---"
2316            @echo "--->>> Assumes you previously <<<---"
2317            @echo "--->>> did make svdtaf        <<<---"
2318    
2319    svd_touch:
2320            @echo "--->>> Only COMPILE svd code! <<<---"
2321            @echo "--->>> Assumes you previously <<<---"
2322            @echo "--->>> did make svdtaf        <<<---"
2323            touch ad_taf_output.$FS ftl_taf_output.$FS
2324            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS
2325            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS
2326            @$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
2327            cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
2328            -rm -f ftl_config.template
2329    
2330    #=========================================
2331    
2332  EOF  EOF
2333    
2334  if test "x$EXEHOOK" != x ; then  if test "x$EXEHOOK" != x ; then
# Line 1008  for i in $KPPFILES ; do Line 2342  for i in $KPPFILES ; do
2342      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
2343          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
2344      fi      fi
2345      echo "$base.f: $base.p" >> $MAKEFILE      echo "$base.$FS: $base.p" >> $MAKEFILE
2346  done  done
2347    
2348  echo "  Making list of NOOPTFILES"  echo "  Making list of NOOPTFILES"
# Line 1018  for i in $NOOPTFILES ; do Line 2352  for i in $NOOPTFILES ; do
2352      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
2353          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
2354      fi      fi
2355      echo "$base.o: $base.f" >> $MAKEFILE      echo "$base.o: $base.$FS" >> $MAKEFILE
2356      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
2357  done  done
2358    
# Line 1031  printf "\n\n# DO NOT DELETE\n" >> $MAKEF Line 2365  printf "\n\n# DO NOT DELETE\n" >> $MAKEF
2365    
2366  printf "\n===  Done  ===\n"  printf "\n===  Done  ===\n"
2367    
2368    # Create special header files
2369    $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"
2370    if test ! -f $PACKAGES_DOT_H ; then
2371        mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2372    else
2373        cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
2374        RETVAL=$?
2375        if test "x$RETVAL" = x0 ; then
2376            rm -f $PACKAGES_DOT_H".tmp"
2377        else
2378            mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
2379            mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2380        fi
2381    fi
2382    if test ! -f AD_CONFIG.h ; then
2383        $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
2384    fi
2385    
2386    
2387  #  Write the "state" for future records  #  Write the "state" for future records
2388  if test "x$DUMPSTATE" != xf ; then  if test "x$DUMPSTATE" != xf ; then
2389      echo -n "" > gm_state      printf "" > genmake_state
2390      for i in $gm_state ; do      for i in $gm_state ; do
2391          t1="t2=\$$i"          t1="t2=\$$i"
2392          eval $t1          eval $t1
2393          echo "$i='$t2'" >> gm_state          echo "$i='$t2'" >> genmake_state
2394      done      done
2395  fi  fi

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.132

  ViewVC Help
Powered by ViewVC 1.1.22