/[MITgcm]/MITgcm/tools/genmake2
ViewVC logotype

Diff of /MITgcm/tools/genmake2

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1 by edhill, Sat Aug 16 14:01:08 2003 UTC revision 1.46 by adcroft, Tue Nov 25 14:18:50 2003 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/sh
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        grep -i "#define.*ALLOW_$pkg" $cpp_options > /dev/null 2>&1
17        RETVAL=$?
18        if test "x${RETVAL}" = x0 ; then
19            echo "Error: In $cpp_options there is an illegal line: #define ALLOW_$pkg"
20            exit 99
21        fi
22        grep -i "#undef.*ALLOW_$pkg" $cpp_options > /dev/null 2>&1
23        RETVAL=$?
24        if test "x${RETVAL}" = x0 ; then
25            echo "Error: In $cpp_options there is an illegal line: #undef ALLOW_$pkg"
26            exit 99
27        fi
28        grep -i "#define.*DISABLE_$pkg" $cpp_options > /dev/null 2>&1
29        RETVAL=$?
30        if test "x${RETVAL}" = x0 ; then
31            echo "Error: In $cpp_options there is an illegal line: #define DISABLE_$pkg"
32            exit 99
33        fi
34        grep -i "#undef.*DISABLE_$pkg" $cpp_options > /dev/null 2>&1
35        RETVAL=$?
36        if test "x${RETVAL}" = x0 ; then
37            echo "Error: In $cpp_options there is an illegal line: #undef DISABLE_$pkg"
38            exit 99
39       fi
40    }
41    
42    # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to
43    # the package list.
44    expand_pkg_groups() {
45        new_packages=
46        PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups"
47        if test -r $PKG_GROUPS ; then
48            cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp
49            cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp
50            matched=0
51            for i in $PACKAGES ; do
52                line=`grep "^ *$i" ./p2.tmp`
53                RETVAL=$?
54                if test "x$RETVAL" = x0 ; then
55                    matched=1
56                    replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`
57                    echo "    replacing \"$i\" with: $replace"
58                    new_packages="$new_packages $replace"
59                else
60                    new_packages="$new_packages $i"
61                fi
62            done
63            PACKAGES=$new_packages
64            rm -f ./p[1,2].tmp
65        else
66            echo "Warning: can't read package groups definition file: $PKG_GROUPS"
67        fi
68    }
69    
70  # Guess possible config options for this host  # Guess possible config options for this host
71  find_possible_configs()  {  find_possible_configs()  {
72    
73      p_PLATFORM=`uname`"-"`uname -m`      tmp1=`uname`"_"`uname -m`
74      echo "The platform appears to be:"      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
75      echo "  "$p_PLATFORM      tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
76        PLATFORM=`echo $tmp3 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
77      p_LN=      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
78        echo "  The platform appears to be:  $PLATFORM"
79        
80      echo "test" > test      echo "test" > test
81      ln -s ./test link      ln -s ./test link
82      RETVAL=$?      RETVAL=$?
83      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
84          p_LN="ln -s"          LN="ln -s"
85        else
86            echo "Error: \"ln -s\" does not appear to work on this system!"
87            echo "  For help, please contact <MITgcm-support@mitgcm.org>."
88            exit 1
89      fi      fi
90      rm -f test link      rm -f test link
91    
92      p_CPP=`which cpp`      if test "x$CPP" = x ; then
93                CPP="cpp -traditional -P"
94      RETVAL=$?      fi
95      if test "x${RETVAL}" = x0 ; then  
96          p_LN="ln -s"      # makedepend is not always available
97        if test "x${MAKEDEPEND}" = x ; then
98          which makedepend >& /dev/null
99          RETVAL=$?
100          if test "x${RETVAL}" = x1 ; then
101             echo "    makedepend was not found. Using xmakedpend instead."
102             MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
103          fi
104      fi      fi
     rm -f test link  
105    
106      # look for possible fortran compilers      # look for possible fortran compilers
107        tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"
108      p_FC=      p_FC=
109      for c in f77 g77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 ; do      for c in $tmp ; do
110          which $c > /dev/null 2>&1          rm -f ./hello.f ./hello
111            cat >> hello.f <<EOF
112          program hello
113          do i=1,3
114            print *, 'hello world : ', i
115          enddo
116          end
117    EOF
118            $c -o hello hello.f > /dev/null 2>&1
119          RETVAL=$?          RETVAL=$?
120          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
121              p_FC="$p_FC $c"              p_FC="$p_FC $c"
122          fi          fi
123      done      done
124      echo "Possible FORTRAN compilers appear to be:  "      rm -f ./hello.f ./hello
125      if test "x${p_FC}" = x ; then      if test "x${p_FC}" = x ; then
126          echo "  None found!!!"          cat 1>&2 <<EOF
127      else  
128          echo "  "$p_FC  Error: No Fortran compilers were found in your path.  Please specify one using:
129      fi  
130        1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
131        2) a command-line option (eg. "-fc NAME"), or
132        3) the MITGCM_FC environment variable.
133    
     # look for possible MPI libraries  
     mpi_libs=  
     mpi_fort=`which mpif77 2>/dev/null`  
     RETVAL=$?  
     if test "x${RETVAL}" = x0 ; then  
         cat >>test.f <<EOF  
       PROGRAM HELLO  
       DO 10, I=1,10  
       PRINT *,'Hello World'  
    10 CONTINUE  
       STOP  
       END  
134  EOF  EOF
135          eval "$mpi_fort -showme test.f > out"          exit 1
136          RETVAL=$?      else
137          if test "x${RETVAL}" = x0 ; then          echo "  The possible FORTRAN compilers found in your path are:"
138              a=`cat out`          echo "   "$p_FC
139              for i in $a ; do          if test "x$FC" = x ; then
140                  case $i in              FC=`echo $p_FC | $AWK '{print $1}'`
                     -*)  
                         mpi_libs="$mpi_libs $i" ;;  
                 esac  
             done  
             echo "The MPI libs appear to be:"  
             echo "  "$mpi_libs  
141          fi          fi
         rm -f test.f out  
142      fi      fi
143    
144  }      for i in $p_FC ; do
145            p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
146            if test -r $p_OF ; then
147                OPTFILE=$p_OF
148                echo "  The options file:  $p_OF"
149                echo "    appears to match so we'll use it."
150                break
151            fi
152        done
153        if test "x$OPTFILE" = x ; then
154            cat 1>&2 <<EOF
155    
156  parse_options()  {  Error: No options file was found in:  $ROOTDIR/tools/build_options/
157      that matches this platform ("$PLATFORM") and the compilers found in
158      your path.  Please specify an "optfile" using:
159    
160      ac_prev=      1) the command line (eg. "-optfile=path/to/OPTFILE"), or
161      for ac_option in "${OPTIONS[@]}" ; do      2) the MITGCM_OF environment variable.
162    
163      If you need help, please contact the developers at <MITgcm-support@mitgcm.org>.
164    
165    EOF
166            exit 1
167        fi
168        
169    #     # look for possible MPI libraries
170    #     mpi_libs=
171    #     mpi_fort=`which mpif77 2>/dev/null`
172    #     RETVAL=$?
173    #     if test "x${RETVAL}" = x0 ; then
174    #       cat >>test.f <<EOF
175    #       PROGRAM HELLO
176    #       DO 10, I=1,10
177    #       PRINT *,'Hello World'
178    #    10 CONTINUE
179    #       STOP
180    #       END
181    # EOF
182    #       eval "$mpi_fort -showme test.f > out"
183    #       RETVAL=$?
184    #       if test "x${RETVAL}" = x0 ; then
185    #           a=`cat out`
186    #           for i in $a ; do
187    #               case $i in
188    #                   -*)
189    #                       mpi_libs="$mpi_libs $i" ;;
190    #               esac
191    #           done
192    #           echo "The MPI libs appear to be:"
193    #           echo "  "$mpi_libs
194    #       fi
195    #       rm -f test.f out
196    #     fi
197    
         # echo "ac_option = :$ac_option:"  
           
         # If the previous option needs an argument, assign it.  
         if test -n "$ac_prev"; then  
             eval "$ac_prev=\$ac_option"  
             ac_prev=  
             continue  
         fi  
           
         ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`  
           
         case $ac_option in  
               
             -help | --help | -h | --h)  
                 usage ;;  
               
             -nooptfile | --nooptfile)  
                 OPTFILE="NONE" ;;  
             -optfile | --optfile | -of | --of)  
                 ac_prev=optfile ;;  
             -optfile=* | --optfile=* | -of=* | --of=*)  
                 OPTFILE=$ac_optarg ;;  
               
             -pdepend | --pdepend)  
                 ac_prev=pdepend ;;  
             -pdepend=* | --pdepend=*)  
                 PDEPEND=$ac_optarg ;;  
               
             -pdefault | --pdefault)  
                 ac_prev=pdefault ;;  
             -pdefault=* | --pdefault=*)  
                 PDEFAULT=$ac_optarg ;;  
               
             -makefile | -ma)  
                 ac_prev=makefile ;;  
             --makefile=* | -ma=*)  
                 MAKEFILE=$ac_optarg ;;  
               
             -platform | --platform | -pl | --pl)  
                 ac_prev=platform ;;  
             -platform=* | --platform=* | -pl=* | --pl=*)  
                 PLATFORM=$ac_optarg ;;  
   
             -rootdir | --rootdir | -rd | --rd)  
                 ac_prev=rootdir ;;  
             -rootdir=* | --rootdir=* | -rd=* | --rd=*)  
                 ROOTDIR=$ac_optarg ;;  
               
             -mods | --mods | -mo | --mo)  
                 ac_prev=mods ;;  
             -mods=* | --mods=* | -mo=* | --mo=*)  
                 MODS=$ac_optarg ;;  
               
             -disable | --disable)  
                 ac_prev=disable ;;  
             -disable=* | --disable=*)  
                 DISABLE=$ac_optarg ;;  
               
             -enable | --enable)  
                 ac_prev=enable ;;  
             -enable=* | --enable=*)  
                 ENABLE=$ac_optarg ;;  
               
             -noopt | --noopt)  
                 ac_prev=noopt ;;  
             -noopt=* | --noopt=*)  
                 NOOPT=$ac_optarg ;;  
               
 #           -cpp | --cpp)  
 #               ac_prev=cpp ;;  
 #           -cpp=* | --cpp=*)  
 #               CPP=$ac_optarg ;;  
               
             -fortran | --fortran | -fc | --fc)  
                 ac_prev=fc ;;  
             -fc=* | --fc=*)  
                 FC=$ac_optarg ;;  
               
             -ieee | --ieee)  
                 IEEE=1 ;;  
             -noieee | --noieee)  
                 IEEE=0 ;;  
               
             -mpi | --mpi)  
                 MPI=1 ;;  
             -nompi | --nompi)  
                 MPI=0 ;;  
               
             -jam | --jam)  
                 JAM=1 ;;  
             -nojam | --nojam)  
                 JAM=0 ;;  
               
             -*)  
                 echo "Error: unrecognized option: "$ac_option  
                 usage  
                 ;;  
               
             *)  
                 echo "Error: unrecognized argument: "$ac_option  
                 usage  
                 ;;  
               
         esac  
           
     done  
198  }  }
199    
200  #  Parse the package dependency information  #  Parse the package dependency information
# Line 199  get_pdepend_list()  { Line 203  get_pdepend_list()  {
203      #  strip the comments and then convert the dependency file into      #  strip the comments and then convert the dependency file into
204      #  two arrays: PNAME, DNAME      #  two arrays: PNAME, DNAME
205      cat $1 | sed -e 's/#.*$//g' \      cat $1 | sed -e 's/#.*$//g' \
206          | 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} }' \
207          > ./.pd_tmp          > ./.pd_tmp
208      source ./.pd_tmp      . ./.pd_tmp
209      rm -f ./.pd_tmp      rm -f ./.pd_tmp
210    
211      echo -n "PNAME = "${}      echo -n "PNAME = "${}
# Line 210  get_pdepend_list()  { Line 214  get_pdepend_list()  {
214    
215  #  Explain usage  #  Explain usage
216  usage()  {  usage()  {
217      echo ""  cat <<EOF
218      echo "Usage: "$0" [OPTIONS]"  
219      echo "  where [OPTIONS] can be:"$'\n'  Usage: "$0" [OPTIONS]
220      echo "    -help | --help | -h | --h"    where [OPTIONS] can be:
221      echo "    -nooptfile | --nooptfile"  
222      echo "      -optfile NAME | --optfile NAME | -of NAME | --of NAME"      -help | --help | -h | --h
223      echo "      -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME"            Print this help message and exit.
224      echo "    -pdepend NAME | --pdepend NAME"  
225      echo "      -pdepend=NAME | --pdepend=NAME"      -nooptfile | --nooptfile
226      echo "    -pdefault NAME | --pdefault NAME"        -optfile NAME | --optfile NAME | -of NAME | --of NAME
227      echo "      -pdefault=NAME | --pdefault=NAME"        -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
228      echo "    -makefile NAME | -ma NAME"            Use "NAME" as the optfile.  By default, an attempt will be
229      echo "      --makefile=NAME | -ma=NAME"            made to find an appropriate "standard" optfile in the
230      echo "    -platform NAME | --platform NAME | -pl NAME | --pl NAME"            tools/build_options/ directory.
231      echo "      -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"  
232      echo "    -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"      -pdepend NAME | --pdepend NAME
233      echo "      -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME"        -pdepend=NAME | --pdepend=NAME
234      echo "    -mods NAME | --mods NAME | -mo NAME | --mo NAME"            Get package dependency information from "NAME".
235      echo "      -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME"  
236      echo "    -disable NAME | --disable NAME"      -pdefault NAME | --pdefault NAME
237      echo "      -disable=NAME | --disable=NAME"        -pdefault=NAME | --pdefault=NAME
238      echo "    -enable NAME | --enable NAME"            Get the default package list from "NAME".
239      echo "      -enable=NAME | --enable=NAME"  
240      echo "    -noopt NAME | --noopt NAME"      -make NAME | -m NAME
241      echo "      -noopt=NAME | --noopt=NAME"        --make=NAME | -m=NAME
242  #    echo "    -cpp NAME | --cpp NAME"            Use "NAME" for the MAKE program. The default is "make" but
243  #    echo "      -cpp=NAME | --cpp=NAME"            many platforms, "gmake" is the preferred choice.
244      echo "    -fortran NAME | --fortran NAME | -fc NAME | --fc NAME"  
245      echo "      -fc=NAME | --fc=NAME"      -makefile NAME | -mf NAME
246      echo "    -[no]ieee | --[no]ieee"        --makefile=NAME | -mf=NAME
247      echo "    -[no]mpi | --[no]mpi"            Call the makefile "NAME".  The default is "Makefile".
248      echo "    -[no]jam | --[no]jam"$'\n'  
249      echo "  and NAME is a string such as:"$'\n'      -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
250      echo "    --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'"        -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
251      echo "    -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'"            Specify the location of the MITgcm ROOTDIR as "NAME".
252      echo "    -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"$'\n'            By default, genamke will try to find the location by
253      echo "  which, depending upon your shell, may need to be single-quoted"            looking in parent directories (up to the 5th parent).
254      echo "  if it contains spaces, dashes, or other special characters."  
255        -mods NAME | --mods NAME | -mo NAME | --mo NAME
256          -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
257              Here, "NAME" specifies a list of directories that are
258              used for additional source code.  Files found in the
259              "mods list" are given preference over files of the same
260              name found elsewhere.
261    
262        -disable NAME | --disable NAME
263          -disable=NAME | --disable=NAME
264              Here "NAME" specifies a list of packages that we don't
265              want to use.  If this violates package dependencies,
266              genamke will exit with an error message.
267    
268        -enable NAME | --enable NAME
269          -enable=NAME | --enable=NAME
270              Here "NAME" specifies a list of packages that we wish
271              to specifically enable.  If this violates package
272              dependencies, genamke will exit with an error message.
273    
274        -standarddirs NAME | --standarddirs NAME
275          -standarddirs=NAME | --standarddirs=NAME
276              Here, "NAME" specifies a list of directories to be
277              used as the "standard" code.
278    
279        -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
280          -fc=NAME | --fc=NAME
281              Use "NAME" as the fortran compiler.  By default, genmake
282              will search for a working compiler by trying a list of
283              "usual suspects" such as g77, f77, etc.
284    
285        -[no]ieee | --[no]ieee
286              Do or don't use IEEE numerics.  Note that this option
287              *only* works if it is supported by the OPTFILE that
288              is being used.
289    
290      While it is most often a single word, the "NAME" variables specified
291      above can in many cases be a space-delimited string such as:
292    
293        --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'
294        -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'
295        -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
296    
297      which, depending upon your shell, may need to be single-quoted.
298    
299      For more detailed genmake documentation, please see:
300    
301        http://mitgcm.org/devel_HOWTO/
302    
303    EOF
304    
305      exit 1      exit 1
306  }  }
307    
308  # Dump all important state  #  Build a CPP macro to automate calling C routines from FORTRAN
309  dump_state()  {  get_fortran_c_namemangling()  {
310      fname=$1      default_nm="#define FC_NAMEMANGLE(X) X ## _"
311      echo " " > $fname      
312        cat > genmake_test.c <<EOF
313    void tcall( char * string ) { tsub( string ); }
314    EOF
315        $MAKE genmake_test.o >> genmake_warnings 2>&1
316      RETVAL=$?      RETVAL=$?
317      if test "x${RETVAL}" = x ; then      if test "x$RETVAL" != x0 ; then
318          echo "Error: cannot write to $fname"          FC_NAMEMANGLE=$default_nm
319          exit 1          cat <<EOF>> genmake_errors
320    
321    WARNING: C test compile fails
322    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
323    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
324    EOF
325            return 1
326      fi      fi
327      echo "makefile "$makefile > $fname      c_tcall=`nm genmake_test.o | grep 'T ' | grep tcall | cut -d ' ' -f 3`
328        RETVAL=$?
329        if test "x$RETVAL" != x0 ; then
330            FC_NAMEMANGLE=$default_nm
331            cat <<EOF>> genmake_warnings
332    
333    WARNING: The "nm" command failed.
334    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
335    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
336    EOF
337            return 1
338        fi
339        cat > genmake_tcomp.f <<EOF
340          subroutine tcall( string )
341          character*(*) string
342          call tsub( string )
343          end
344    EOF
345        $FC $FFLAGS $DEFINES -c genmake_tcomp.f >> genmake_warnings 2>&1
346        RETVAL=$?
347        if test "x$RETVAL" != x0 ; then
348            FC_NAMEMANGLE=$default_nm
349            cat <<EOF>> genmake_warnings
350    
351    WARNING: FORTRAN test compile fails -- please see "genmake_errors"
352    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
353    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
354    EOF
355            return 1
356        fi
357        f_tcall=`nm genmake_tcomp.o | grep 'T ' | grep tcall | cut -d ' ' -f 3`
358        RETVAL=$?
359        if test "x$RETVAL" != x0 ; then
360            FC_NAMEMANGLE=$default_nm
361            cat <<EOF>> genmake_warnings
362    
363    WARNING: The "nm" command failed.
364    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
365    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
366    EOF
367            return 1
368        fi
369    
370        c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
371        f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
372        c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
373        f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
374    
375        nmangle="X"
376        if test "x$c_a" != "x$f_a" ; then
377            comm="echo x$f_a | sed -e 's|x$c_a||'"
378            a=`eval $comm`
379            nmangle="$a ## $nmangle"
380        fi
381        if test "x$c_b" != "x$f_b" ; then
382            comm="echo x$f_b | sed -e 's|x$c_b||'"
383            b=`eval $comm`
384            nmangle="$nmangle ## $b"
385        fi
386    
387        FC_NAMEMANGLE="#define FC_NAMEMANGLE(X)  $nmangle"
388    
389        #  cleanup the testing files
390        rm -f genmake_tcomp.* genmake_test.*
391  }  }
392    
393    
394  #eh3 # This is the generic configuration.  check_HAVE_CLOC()  {
395  #eh3 set LN         = ( 'ln -s' )      get_fortran_c_namemangling
396  #eh3 set CPP        = ( '/lib/cpp -P' )      cat <<EOF > genmake_tc_1.c
397  #eh3 set S64        = ( '$(TOOLSDIR)/set64bitConst.sh' )  $FC_NAMEMANGLE
398  #eh3 set KPP        = (  )  #include <stdio.h>
399  #eh3 set FC         = ( 'f77' )  #include <stdlib.h>
400  #eh3 set LINK       = $FC  #include <unistd.h>
401  #eh3 set MAKEDEPEND = ( 'makedepend' )  #include <assert.h>
402  #eh3 set INCLUDES   = ( -I. )  #include <sys/time.h>
403  #eh3 set FFLAGS     = (  )  void FC_NAMEMANGLE(cloc) ( double *curtim )
404  #eh3 set FOPTIM     = (  )  {
405  #eh3 set CFLAGS     = (  )   struct timeval tv1;
406  #eh3 set KFLAGS1    = (  )   gettimeofday(&tv1 , (void *)NULL );
407  #eh3 set KFLAGS2    = (  )   *curtim =  (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
408  #eh3 set LIBS       = (  )   *curtim = *curtim/1.E6;
409  #eh3 set KPPFILES   = (  )  }
410  #eh3 if (! $?NOOPTFILES ) set NOOPTFILES = (  )  EOF
411  #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = (  )      make genmake_tc_1.o >> genmake_tc.log 2>&1
412        RET_C=$?
413        cat <<EOF > genmake_tc_2.f
414          program hello
415          Real*8 wtime
416          external cloc
417          call cloc(wtime)
418          print *," HELLO WORLD", wtime
419          end program hello
420    EOF
421        $FC $FFLAGS -o genmake_tc genmake_tc_2.f genmake_tc_1.o >> genmake_tc.log 2>&1
422        RET_F=$?
423        test -x ./genmake_tc  &&  ./genmake_tc >> genmake_tc.log 2>&1
424        RETVAL=$?
425        if test "x$RETVAL" = x0 ; then
426            HAVE_CLOC=t
427            DEFINES="$DEFINES -DHAVE_CLOC"
428        fi
429        rm -f genmake_tc*
430    }
431    
432    
433  #  Set defaults here  #  Set defaults here
434    COMMANDL="$0 $@"
435    
436  PLATFORM=  PLATFORM=
437  LN=  LN=
438  S64=  S64=
439  KPP=  KPP=
440  FC=  FC=
441  LINK=  LINK=
442    # DEFINES="-DWORDLENGTH=4"
443    DEFINES=
444  PACKAGES=  PACKAGES=
445  ENABLE=  ENABLE=
446  DISABLE=  DISABLE=
447  MAKEFILE=  MAKEFILE=
448  MAKEDEPEND=  MAKEDEPEND=
449  PDEPEND=  PDEPEND=
450    DUMPSTATE=t
451  PDEFAULT=  PDEFAULT=
452  OPTFILE=  OPTFILE=
453  INCLUDES=-I.  INCLUDES="-I."
454  FFLAGS=  FFLAGS=
455  FOPTIM=  FOPTIM=
456  CFLAGS=  CFLAGS=
# Line 309  KPPFILES= Line 461  KPPFILES=
461  NOOPTFILES=  NOOPTFILES=
462  NOOPTFLAGS=  NOOPTFLAGS=
463    
464    # DEFINES checked by test compilation
465    HAVE_SYSTEM=
466    HAVE_FDATE=
467    FC_NAMEMANGLE=
468    HAVE_CLOC=
469    
470  MODS=  MODS=
471  TOOLSDIR=  TOOLSDIR=
472  SOURCEDIRS=  SOURCEDIRS=
473  INCLUDEDIRS=  INCLUDEDIRS=
474    STANDARDDIRS=
475    
476  PWD=`pwd`  PWD=`pwd`
477  MAKE=make  MAKE=make
478    AWK=awk
479  THISHOSTNAME=`hostname`  THISHOSTNAME=`hostname`
480  THISCWD=`pwd`  THISCWD=`pwd`
481  THISDATE=`date`  THISDATE=`date`
482  MACHINE=`uname -a`  MACHINE=`uname -a`
483    EXECUTABLE=
484    EXEHOOK=
485    EXEDIR=
486    PACKAGES_CONF=
487    IEEE=
488    if test "x$MITGCM_IEEE" != x ; then
489        IEEE=$MITGCM_IEEE
490    fi
491    
492    AUTODIFF_PKG_USED=f
493    AD_OPTFILE=
494    TAF=
495    AD_TAF_FLAGS=
496    FTL_TAF_FLAGS=
497    SVD_TAF_FLAGS=
498    TAF_EXTRA=
499    TAMC=
500    AD_TAMC_FLAGS=
501    FTL_TAF_FLAGS=
502    SVD_TAMC_FLAGS=
503    TAMC_EXTRA=
504    
505    
506    #  The following state can be set directly by command-line switches
507    gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"
508    gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS"
509    
510    #  The following state is not directly set by command-line switches
511    gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
512    gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
513    gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"
514    gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
515    gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE"
516    
517    #  The following are all related to adjoint/tangent-linear stuff
518    gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
519    gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
520    gm_s12="TAF_EXTRA TAMC_EXTRA"
521    
522    gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"
523    gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
524    
525    cat <<EOF
526    
527    GENMAKE :
528    
529    A program for GENerating MAKEfiles for the MITgcm project.  For a
530    quick list of options, use "genmake -h" or for more detail see:
531    
532      http://mitgcm.org/devel_HOWTO/
533    
534    EOF
535    
536  echo $'\n'"===  Processing options files and arguments  ==="  echo "===  Processing options files and arguments  ==="
537  gm_local="./gm_local"  gm_local="genmake_local"
538    for i in . $MODS ; do
539        if test -r $i/$gm_local ; then
540            . $i/$gm_local
541            break
542        fi
543    done
544  echo -n "  getting local config information:  "  echo -n "  getting local config information:  "
545  if test -e $gm_local ; then  if test -e $gm_local ; then
546      echo "using $gm_local"      echo "using $gm_local"
547      source $gm_local      . $gm_local
548      echo "DISABLE=$DISABLE"$'\n'"ENABLE=$ENABLE"      # echo "DISABLE=$DISABLE"
549        # echo "ENABLE=$ENABLE"
550  else  else
551      echo "none found"      echo "none found"
552  fi  fi
553    
554  #  echo "$0::$1:$2:$3:$4:$5:$6:$7:"  #  echo "$0::$1:$2:$3:$4:$5:$6:$7:"
555  OPTIONS=()  #OPTIONS=
556  n=0  #n=0
557  for i ; do  #for i ; do
558     setvar="OPTIONS[$n]='$i'"  #   echo "$i  $n"
559     #  echo "  $setvar"  #   setvar="OPTIONS[$n]='$i'"
560     eval "$setvar"  #   #  echo "  $setvar"
561     n=$(( $n + 1 ))  #   eval "$setvar"
562  done  #   n=$(( $n + 1 ))
563  parse_options  #done
564    #parse_options
565  echo "  getting OPTFILE information:  "  ac_prev=
566  if test "x${OPTFILE}" = x ; then  for ac_option ; do
567      echo "Warning: no OPTFILE specified so we'll look for possible settings"  
568      echo $'\n'"===  Searching for possible settings for OPTFILE  ==="      # If the previous option needs an argument, assign it.
569      find_possible_configs      if test -n "$ac_prev"; then
570  else          eval "$ac_prev=\$ac_option"
571      if test "x$OPTFILE" = xNONE ; then          ac_prev=
572          echo "    OPTFILE=NONE so we'll try to use default settings"          continue
     else  
         if test -f "$OPTFILE" -a -r "$OPTFILE" ; then  
             echo "    using OPTFILE=\"$OPTFILE\""  
             source "$OPTFILE"  
             RETVAL=$?  
             if test "x$RETVAL" != x0 ; then  
                 echo -n "Error: failed to source OPTFILE \"$OPTFILE\""  
                 echo "--please check that variable syntax is bash-compatible"  
                 exit 1  
             fi  
         else  
             echo "Error: can't read OPTFILE=\"$OPTFILE\""  
             exit 1  
         fi  
573      fi      fi
574  fi      
575        ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
576        
577        case $ac_option in
578            
579            -help | --help | -h | --h)
580                usage ;;
581            
582            -nooptfile | --nooptfile)
583                OPTFILE="NONE" ;;
584            -optfile | --optfile | -of | --of)
585                ac_prev=OPTFILE ;;
586            -optfile=* | --optfile=* | -of=* | --of=*)
587                OPTFILE=$ac_optarg ;;
588            
589            -adoptfile | --adoptfile | -ad | --ad)
590                ac_prev=AD_OPTFILE ;;
591            -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
592                AD_OPTFILE=$ac_optarg ;;
593            
594            -pdepend | --pdepend)
595                ac_prev=PDEPEND ;;
596            -pdepend=* | --pdepend=*)
597                PDEPEND=$ac_optarg ;;
598            
599            -pdefault | --pdefault)
600                ac_prev=PDEFAULT ;;
601            -pdefault=* | --pdefault=*)
602                PDEFAULT=$ac_optarg ;;
603            
604            -make | --make | -m | --m)
605                ac_prev=MAKE ;;
606            -make=* | --make=* | -m=* | --m=*)
607                MAKE=$ac_optarg ;;
608            
609            -makefile | --makefile | -ma | --ma)
610                ac_prev=MAKEFILE ;;
611            -makefile=* | --makefile=* | -ma=* | --ma=*)
612                MAKEFILE=$ac_optarg ;;
613            
614            -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
615                echo "ERROR: The platform option has been removed.  Please specify"
616                echo "  the build options using the \"optfile\" mechanism."
617                echo
618                usage
619                ;;
620            
621            -rootdir | --rootdir | -rd | --rd)
622                ac_prev=ROOTDIR ;;
623            -rootdir=* | --rootdir=* | -rd=* | --rd=*)
624                ROOTDIR=$ac_optarg ;;
625            
626            -mods | --mods | -mo | --mo)
627                ac_prev=MODS ;;
628            -mods=* | --mods=* | -mo=* | --mo=*)
629                MODS=$ac_optarg ;;
630            
631            -disable | --disable)
632                ac_prev=DISABLE ;;
633            -disable=* | --disable=*)
634                DISABLE=$ac_optarg ;;
635            
636            -enable | --enable)
637                ac_prev=ENABLE ;;
638            -enable=* | --enable=*)
639                ENABLE=$ac_optarg ;;
640            
641            -standarddirs | --standarddirs)
642                ac_prev=STANDARDDIRS ;;
643            -standarddirs=* | --standarddirs=*)
644                STANDARDDIRS=$ac_optarg ;;
645    
646  echo $'\n'"===  Setting defaults  ==="  #           -cpp | --cpp)
647  echo -n "  Adding MODS directories:  "  #               ac_prev=cpp ;;
648  for d in $MODS ; do  #           -cpp=* | --cpp=*)
649      if test ! -d $d ; then  #               CPP=$ac_optarg ;;
650          echo $'\n\n'"Error: MODS directory \"$d\" not found!"              
651          exit 1          -fortran | --fortran | -fc | --fc)
652      else              ac_prev=FC ;;
653          echo -n " $d"          -fc=* | --fc=*)
654          SOURCEDIRS="$SOURCEDIRS $d"              FC=$ac_optarg ;;
655          INCLUDEDIRS="$INCLUDEDIRS $d"          
656      fi          -ieee | --ieee)
657                IEEE=true ;;
658            -noieee | --noieee)
659                IEEE= ;;
660            
661    #       -jam | --jam)
662    #           JAM=1 ;;
663    #       -nojam | --nojam)
664    #           JAM=0 ;;
665            
666            -ds | --ds)
667                DUMPSTATE=t ;;
668            
669            -taf_extra | --taf_extra)
670                ac_prev=TAF_EXTRA ;;
671            -taf_extra=* | --taf_extra=*)
672                TAF_EXTRA=$ac_optarg ;;
673    
674            -tamc_extra | --tamc_extra)
675                ac_prev=TAMC_EXTRA ;;
676            -tamc_extra=* | --tamc_extra=*)
677                TAMC_EXTRA=$ac_optarg ;;
678    
679            -*)
680                echo "Error: unrecognized option: "$ac_option
681                usage
682                ;;
683            
684            *)
685                echo "Error: unrecognized argument: "$ac_option
686                usage
687                ;;
688            
689        esac
690        
691  done  done
 echo  
692    
693  if test "x$MAKEFILE" = x ; then  if test -f ./.genmakerc ; then
694      MAKEFILE="Makefile"      echo
695  fi      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
696  if test "x${PLATFORM}" = x ; then      echo "  file.  This file format is no longer supported.  Please see:"
697      PLATFORM=$p_PLATFORM      echo
698        echo "    http://mitgcm.org/devel_HOWTO/"
699        echo
700        echo "  for directions on how to setup and use the new \"genmake2\" input"
701        echo "  files and send an email to MITgcm-support@mitgcm.org if you want help."
702        echo
703  fi  fi
704    
705  if test "x${ROOTDIR}" = x ; then  if test "x${ROOTDIR}" = x ; then
# Line 414  if test ! -d ${ROOTDIR} ; then Line 727  if test ! -d ${ROOTDIR} ; then
727      exit 1      exit 1
728  fi  fi
729    
730    echo "  getting OPTFILE information:  "
731    if test "x${OPTFILE}" = x ; then
732        if test "x$MITGCM_OF" = x ; then
733            echo "Warning: no OPTFILE specified so we'll look for possible settings"
734            printf "\n===  Searching for possible settings for OPTFILE  ===\n"
735            find_possible_configs
736        else
737            OPTFILE=$MITGCM_OF
738        fi
739    fi
740    if test "x$OPTFILE" != xNONE ; then
741        if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
742            echo "    using OPTFILE=\"$OPTFILE\""
743            . "$OPTFILE"
744            RETVAL=$?
745            if test "x$RETVAL" != x0 ; then
746                echo -n "Error: failed to source OPTFILE \"$OPTFILE\""
747                echo "--please check that variable syntax is bash-compatible"
748                exit 1
749            fi
750            if test "x$DUMPSTATE" != xf ; then
751                cp -f $OPTFILE "genmake_optfile"
752            fi
753        else
754            echo "Error: can't read OPTFILE=\"$OPTFILE\""
755            exit 1
756        fi
757    fi
758    
759    echo "  getting AD_OPTFILE information:  "
760    if test "x${AD_OPTFILE}" = x ; then
761        if test "x$MITGCM_AD_OF" = x ; then
762            AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
763        else
764            AD_OPTFILE=$MITGCM_AD_OF
765        fi
766    fi
767    if test "x${AD_OPTFILE}" != xNONE ; then
768        if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
769            echo "    using AD_OPTFILE=\"$AD_OPTFILE\""
770            . "$AD_OPTFILE"
771            RETVAL=$?
772            if test "x$RETVAL" != x0 ; then
773                echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
774                echo "--please check that variable syntax is bash-compatible"
775                exit 1
776            fi
777            if test "x$DUMPSTATE" != xf ; then
778                cp -f $AD_OPTFILE "genmake_ad_optfile"
779            fi
780        else
781            echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
782            exit 1
783        fi
784    fi
785    
786    #  Check that FC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
787    #  either set defaults or complain and abort!
788    if test "x$FC" = x ; then
789        cat <<EOF 1>&2
790    
791    Error: no Fortran compiler: please specify using one of the following:
792      1) within the options file ("FC=...") as specified by "-of=OPTFILE"
793      2) the "-fc=XXX" command-line option
794      3) the "./genmake_local" file
795    EOF
796        exit 1
797    fi
798    if test "x$LINK" = x ; then
799        LINK=$FC
800    fi
801    if test "x$CPP" = x ; then
802        CPP="cpp"
803    fi
804    if test "x$MAKE" = x ; then
805        MAKE="make"
806    fi
807    echo "#define A a" | $CPP > test_cpp 2>&1
808    RETVAL=$?
809    if test "x$RETVAL" != x0 ; then
810        cat <<EOF 1>&2
811    
812    Error: C pre-processor "$CPP" failed the test case: please specify using:
813    
814      1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
815      2) the "./genmake_local" file
816      3) with the CPP environment variable
817    
818    EOF
819        exit 1
820    else
821        rm -f test_cpp
822    fi
823    if test "x$MAKEDEPEND" = x ; then
824        MAKEDEPEND=makedepend
825    fi
826    if test "x$LN" = x ; then
827        LN="ln -s"
828    fi
829    echo "test" > genmake_test_ln
830    $LN genmake_test_ln genmake_tlink
831    RETVAL=$?
832    if test "x$RETVAL" != x0 ; then
833        cat <<EOF 1>&2
834    
835    Error: The command "ln -s" failed -- please specify a working soft-link
836      command in the optfile.
837    
838    EOF
839        exit 1
840    fi
841    rm -f genmake_test_ln genmake_tlink
842    
843    
844    printf "\n===  Checking system libraries  ===\n"
845    echo -n "  Do we have the system() command using $FC...  "
846    cat > genmake_tcomp.f <<EOF
847          program hello
848          call system('echo hi')
849          end
850    EOF
851    $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1
852    RETVAL=$?
853    if test "x$RETVAL" = x0 ; then
854        HAVE_SYSTEM=t
855        DEFINES="$DEFINES -DHAVE_SYSTEM"
856        echo "yes"
857    else
858        HAVE_SYSTEM=
859        echo "no"
860    fi
861    rm -f genmake_tcomp*
862    
863    echo -n "  Do we have the fdate() command using $FC...  "
864    cat > genmake_tcomp.f <<EOF
865          program hello
866          CHARACTER(128) string
867          string = ' '
868          call fdate( string )
869          print *, string
870          end
871    EOF
872    $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1
873    RETVAL=$?
874    if test "x$RETVAL" = x0 ; then
875        HAVE_FDATE=t
876        DEFINES="$DEFINES -DHAVE_FDATE"
877        echo "yes"
878    else
879        HAVE_FDATE=
880        echo "no"
881    fi
882    rm -f genmake_tcomp*
883    
884    echo -n "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
885    check_HAVE_CLOC
886    if test "x$HAVE_CLOC" != x ; then
887        echo "yes"
888    else
889        echo "no"
890    fi
891    echo "$FC_NAMEMANGLE" > FC_NAMEMANGLE.h.template
892    cmp FC_NAMEMANGLE.h FC_NAMEMANGLE.h.template > /dev/null 2>&1
893    RETVAL=$?
894    if test "x$RETVAL" != x0 ; then
895        mv -f FC_NAMEMANGLE.h.template FC_NAMEMANGLE.h
896    fi
897    rm -f genmake_t*
898    
899    
900    printf "\n===  Setting defaults  ===\n"
901    echo -n "  Adding MODS directories:  "
902    for d in $MODS ; do
903        if test ! -d $d ; then
904            echo
905            echo "Error: MODS directory \"$d\" not found!"
906            exit 1
907        else
908            echo -n " $d"
909            SOURCEDIRS="$SOURCEDIRS $d"
910            INCLUDEDIRS="$INCLUDEDIRS $d"
911        fi
912    done
913    echo
914    
915    if test "x$MAKEFILE" = x ; then
916        MAKEFILE="Makefile"
917    fi
918    if test "x${PLATFORM}" = x ; then
919        PLATFORM=$p_PLATFORM
920    fi
921    
922  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
923      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then
924          EXEDIR=../exe          EXEDIR=../exe
# Line 433  if test ! -d ${TOOLSDIR} ; then Line 938  if test ! -d ${TOOLSDIR} ; then
938      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"
939      exit 1      exit 1
940  fi  fi
941    if test "x$S64" = x ; then
942        S64='$(TOOLSDIR)/set64bitConst.sh'
943    fi
944    THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
945    
946  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
947    
# Line 441  EXECUTABLE=${EXECUTABLE:-mitgcmuv} Line 950  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
950  #  they appear as regular source code  #  they appear as regular source code
951  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
952      echo "  Making source files in eesupp from templates"      echo "  Making source files in eesupp from templates"
953      $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1      ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1
954      RETVAL=$?      RETVAL=$?
955      if test "x${RETVAL}" == "x0" ; then      if test "x${RETVAL}" = x0 ; then
956          rm -f make_eesupp.errors          rm -f make_eesupp.errors
957      else      else
958          echo "Error: problem encountered while building source files in eesupp:"          echo "Error: problem encountered while building source files in eesupp:"
# Line 452  if test -r $ROOTDIR"/eesupp/src/Makefile Line 961  if test -r $ROOTDIR"/eesupp/src/Makefile
961      fi      fi
962  fi  fi
963    
964  echo $'\n'"===  Determining package settings  ==="  printf "\n===  Determining package settings  ===\n"
965  if  test "x${PDEPEND}" = x ; then  if  test "x${PDEPEND}" = x ; then
966      tmp=$ROOTDIR"/pkg/pkg_depend"      tmp=$ROOTDIR"/pkg/pkg_depend"
967      if test -r $tmp ; then      if test -r $tmp ; then
# Line 471  echo "  getting package dependency info Line 980  echo "  getting package dependency info
980  #  Strip the comments and then convert the dependency file into  #  Strip the comments and then convert the dependency file into
981  #  two arrays: PNAME, DNAME  #  two arrays: PNAME, DNAME
982  cat $PDEPEND | sed -e 's/#.*$//g' \  cat $PDEPEND | sed -e 's/#.*$//g' \
983      | awk 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \      | $AWK 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \
984      > ./.pd_tmp      > ./.pd_tmp
985  RETVAL=$?  RETVAL=$?
986  if test ! "x${RETVAL}" = x0 ; then  if test ! "x${RETVAL}" = x0 ; then
987      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
988      exit 1      exit 1
989  fi  fi
990  source ./.pd_tmp  . ./.pd_tmp
991  rm -f ./.pd_tmp  rm -f ./.pd_tmp
992    
993  echo  -n "  checking default package list:  "  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"
994    #  file should eventually be added so that, for convenience, one can
995    #  specify groups of packages using names like "ocean" and "atmosphere".
996    echo "  checking default package list:  "
997    if test "x${PDEFAULT}" = x ; then
998        for i in "." $MODS ; do
999            if test -r $i"/packages.conf" ; then
1000                    PDEFAULT=$i"/packages.conf"
1001                    break
1002            fi
1003        done
1004    fi
1005  if test "x${PDEFAULT}" = x ; then  if test "x${PDEFAULT}" = x ; then
1006      PDEFAULT="$ROOTDIR/pkg/pkg_default"      PDEFAULT="$ROOTDIR/pkg/pkg_default"
1007  fi  fi
1008  if test "x${PDEFAULT}" = xNONE ; then  if test "x${PDEFAULT}" = xNONE ; then
1009      echo "default packages file disabled"      echo "    default packages file disabled"
1010  else  else
1011      if test ! -r $PDEFAULT ; then      if test ! -r $PDEFAULT ; then
         echo ""  
1012          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""
1013      else      else
1014          echo "  using PDEFAULT=\"$PDEFAULT\""          echo "    using PDEFAULT=\"$PDEFAULT\""
1015          #  Strip the comments and add all the names          #  Strip the comments and add all the names
1016          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | awk '(NF>0){print $0}'`          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
1017          RETVAL=$?          RETVAL=$?
1018          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
1019              echo -n "Error: can't parse default package list "              echo -n "Error: can't parse default package list "
# Line 504  else Line 1023  else
1023          for i in $def ; do          for i in $def ; do
1024              PACKAGES="$PACKAGES $i"              PACKAGES="$PACKAGES $i"
1025          done          done
1026          echo "    packages are:  $PACKAGES"          echo "    before group expansion packages are: $PACKAGES"
1027            expand_pkg_groups
1028            echo "    after group expansion packages are:  $PACKAGES"
1029      fi      fi
1030  fi  fi
1031    
# Line 523  for p in $PACKAGES ; do Line 1044  for p in $PACKAGES ; do
1044  done  done
1045  PACKAGES="$pack"  PACKAGES="$pack"
1046  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
1047  rm -f ./.tmp_pack  echo "" > ./.tmp_pack
1048  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
1049  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1050      if test ! -d "$ROOTDIR/pkg/$i" ; then      if test ! -d "$ROOTDIR/pkg/$i" ; then
# Line 544  echo "  applying package dependency rule Line 1065  echo "  applying package dependency rule
1065  ck=  ck=
1066  while test "x$ck" != xtt ; do  while test "x$ck" != xtt ; do
1067      i=0      i=0
1068      rtot=${#PNAME[@]}      # rtot=${#PNAME[@]}
1069        rtot=$nname
1070      while test $i -lt $rtot ; do      while test $i -lt $rtot ; do
1071    
1072          #  Is $pname in the current $PACKAGES list?          #  Is $pname in the current $PACKAGES list?
1073          pname=${PNAME[$i]}          #  pname=${PNAME[$i]}
1074            tmp="pname=\"\$PNAME_$i\""
1075            eval $tmp
1076          pin="f"          pin="f"
1077          for p in $PACKAGES ; do          for p in $PACKAGES ; do
1078              if test "x$p" = "x$pname" ; then              if test "x$p" = "x$pname" ; then
# Line 557  while test "x$ck" != xtt ; do Line 1081  while test "x$ck" != xtt ; do
1081          done          done
1082    
1083          #  Is the DNAME entry a (+) or (-) rule ?          #  Is the DNAME entry a (+) or (-) rule ?
1084            tmp="dname=\"\$DNAME_$i\""
1085            eval $tmp
1086          plus="-"          plus="-"
1087          echo "${DNAME[$i]}" | grep '^+' > /dev/null 2>&1          echo $dname | grep '^+' > /dev/null 2>&1
1088          RETVAL=$?          RETVAL=$?
1089          if test "x$RETVAL" = x0 ; then          if test "x$RETVAL" = x0 ; then
1090              plus="+"              plus="+"
1091          fi          fi
1092    
1093          #  Is $dname in the current $PACKAGES list?          #  Is $dname in the current $PACKAGES list?
1094          dname=`echo ${DNAME[$i]} | sed -e 's/^[+-]//'`          dname=`echo $dname | sed -e 's/^[+-]//'`
1095          din="f"          din="f"
1096          for p in $PACKAGES ; do          for p in $PACKAGES ; do
1097              if test "x$p" = "x$dname" ; then              if test "x$p" = "x$dname" ; then
# Line 609  for i in $PACKAGES ; do Line 1135  for i in $PACKAGES ; do
1135      if test -d $adr ; then      if test -d $adr ; then
1136          SOURCEDIRS="$SOURCEDIRS $adr"          SOURCEDIRS="$SOURCEDIRS $adr"
1137          INCLUDEDIRS="$INCLUDEDIRS $adr"          INCLUDEDIRS="$INCLUDEDIRS $adr"
1138            if test "x$i" = xautodiff ; then
1139                AUTODIFF_PKG_USED=t
1140            fi
1141      else      else
1142          echo "Error: the directory \"$adr\" for package $i doesn't exist"          echo "Error: the directory \"$adr\" for package $i doesn't exist"
1143          exit 1          exit 1
1144      fi      fi
1145  done  done
1146    
 #  This is compatible with the old genmake.  The "DISABLE_*" flags  
 #  need to be replaced by the "ALLOW_*" flags set below.  
 #  
 # 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.  
1147    
1148  C  Packages disabled by genmake:  # Create a list of #define and #undef to enable/disable packages
1149  EOF  PACKAGES_DOT_H=PACKAGES_CONFIG.h
1150  #  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
1151  #  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
1152  #  file would eventually be split up so that all package-related #define  #  file would eventually be split up so that all package-related #define
1153  #  statements could be separated and handled only by genmake.  #  statements could be separated and handled only by genmake.
1154  names=`ls -1 "$ROOTDIR/pkg"`  names=`ls -1 "$ROOTDIR/pkg"`
1155  all_pack=  all_pack=
1156    DISABLED_PACKAGES=
1157  for n in $names ; do  for n in $names ; do
1158      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
1159          has_pack="f"          has_pack="f"
# Line 686  for n in $names ; do Line 1164  for n in $names ; do
1164              fi              fi
1165          done          done
1166          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
1167              undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`
1168              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!!!  
   
1169          fi          fi
1170      fi      fi
1171  done  done
1172  cat <<EOF >>CPP_OPTIONS.h.tmp  ENABLED_PACKAGES=
   
 C  Packages enabled by genmake:  
 EOF  
1173  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1174      def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`      def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`
1175      echo "#define $def" >> CPP_OPTIONS.h.tmp      ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
1176    #eh3 DEFINES="$DEFINES -D$def"
1177    
1178  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1179      case $i in      case $i in
1180          aim_v23)          aim_v23)
1181              echo "#define   ALLOW_AIM" >> CPP_OPTIONS.h.tmp              DEFINES="$DEFINES -DALLOW_AIM"
1182                ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
1183                echo "Warning: ALLOW_AIM is set to enable aim_v23. This is REALLY ugly Jean-Michel :-)"
1184              ;;              ;;
1185      esac      esac
1186  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1187    
1188  done  done
 mv -f CPP_OPTIONS.h.tmp CPP_OPTIONS.h  
1189    
1190  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS"
1191  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
1192  STANDARDDIRS=${STANDARDDIRS:-"eesupp model"}  if test "x$STANDARDDIRS" = x ; then
1193        STANDARDDIRS="eesupp model"
1194    fi
1195  for d in $STANDARDDIRS ; do  for d in $STANDARDDIRS ; do
1196      adr="$ROOTDIR/$d/src"      adr="$ROOTDIR/$d/src"
1197      if test ! -d $adr ; then      if test ! -d $adr ; then
# Line 750  for d in $STANDARDDIRS ; do Line 1211  for d in $STANDARDDIRS ; do
1211      fi      fi
1212  done  done
1213    
1214    echo "  Searching for CPP_OPTIONS.h in order to warn about the presence"
1215    echo "    of \"#define ALLOW_PKGNAME\"-type statements:"
1216    CPP_OPTIONS=
1217    spaths=". $INCLUDEDIRS"
1218    for i in $spaths ; do
1219        try="$i/CPP_OPTIONS.h"
1220        #  echo -n "    trying $try : "
1221        if test -f $try -a -r $try ; then
1222            echo "    found CPP_OPTIONS=\"$try\""
1223            CPP_OPTIONS="$try"
1224            break
1225        fi
1226    done
1227    if test "x$CPP_OPTIONS" = x ; then
1228        echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
1229        exit 1
1230    fi
1231    # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
1232    names=`ls -1 "$ROOTDIR/pkg"`
1233    for n in $names ; do
1234        test_for_package_in_cpp_options $CPP_OPTIONS $n
1235    done
1236    
1237    
1238    #  Here, we build the list of files to be "run through" the adjoint
1239    #  compiler.
1240    if test -f ./ad_files ; then
1241        rm -f ./ad_files
1242    fi
1243    echo "  Creating the list of files for the adjoint compiler."
1244    for i in $SOURCEDIRS ; do
1245        list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
1246        for j in $list_files ; do
1247            cat $i/$j >> ad_files
1248        done
1249    done
1250    
1251  echo $'\n'"===  Creating the Makefile  ==="  echo
1252    echo "===  Creating the Makefile  ==="
1253  echo "  setting INCLUDES"  echo "  setting INCLUDES"
1254  for i in $INCLUDEDIRS ; do  for i in $INCLUDEDIRS ; do
1255      if test -d $i ; then      if ! test -d $i ; then
1256          INCLUDES="$INCLUDES -I$i"  #       INCLUDES="$INCLUDES -I$i"
1257      else  #   else
1258          echo "Warning: can't find INCLUDEDIRS=\"$i\""          echo "Warning: can't find INCLUDEDIRS=\"$i\""
1259      fi      fi
1260  done  done
# Line 766  rm -rf .links.tmp Line 1264  rm -rf .links.tmp
1264  mkdir .links.tmp  mkdir .links.tmp
1265  echo "# This section creates symbolic links" > srclinks.tmp  echo "# This section creates symbolic links" > srclinks.tmp
1266  echo "" >> srclinks.tmp  echo "" >> srclinks.tmp
1267  echo -n 'SRCFILES = ' > srclist.inc  echo -n 'SRCFILES = '    > srclist.inc
1268  echo -n 'CSRCFILES = ' > csrclist.inc  echo -n 'CSRCFILES = '   > csrclist.inc
1269    echo -n 'F90SRCFILES = ' > f90srclist.inc
1270  echo -n 'HEADERFILES = ' > hlist.inc  echo -n 'HEADERFILES = ' > hlist.inc
1271  alldirs=". $SOURCEDIRS $INCLUDEDIRS"  echo -n 'AD_FLOW_FILES = ' > ad_flow_files.inc
1272    alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1273  for d in $alldirs ; do  for d in $alldirs ; do
1274      deplist=      deplist=
1275      sfiles=`( cd $d; echo *.[h,c,F] )`      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
1276        sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
1277      for sf in $sfiles ; do      for sf in $sfiles ; do
1278          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
1279              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
1280                  extn=`echo $sf | awk -F '.' '{print $NF}'`                  case $d/$sf in
1281                  touch .links.tmp/$sf                    ./$PACKAGES_DOT_H)
1282                  deplist="$deplist $sf"                          ;;
1283                      ./AD_CONFIG.h)
1284                            ;;
1285                      ./FC_NAMEMANGLE.h)
1286                            ;;
1287                      *)
1288                            touch .links.tmp/$sf
1289                            deplist="$deplist $sf"
1290                            ;;
1291                    esac
1292                    extn=`echo $sf | $AWK -F '.' '{print $NF}'`
1293                  case $extn in                  case $extn in
1294                      F)                      F)
1295                          echo    " \\"  >> srclist.inc                          echo    " \\"  >> srclist.inc
1296                          echo -n " $sf" >> srclist.inc                          echo -n " $sf" >> srclist.inc
1297                          ;;                          ;;
1298                        F90)
1299                            echo    " \\"  >> f90srclist.inc
1300                            echo -n " $sf" >> f90srclist.inc
1301                            ;;
1302                      c)                      c)
1303                          echo    " \\"  >> csrclist.inc                          echo    " \\"  >> csrclist.inc
1304                          echo -n " $sf" >> csrclist.inc                          echo -n " $sf" >> csrclist.inc
# Line 792  for d in $alldirs ; do Line 1307  for d in $alldirs ; do
1307                          echo    " \\"  >> hlist.inc                          echo    " \\"  >> hlist.inc
1308                          echo -n " $sf" >> hlist.inc                          echo -n " $sf" >> hlist.inc
1309                          ;;                          ;;
1310                        flow)
1311                            echo    " \\"  >> ad_flow_files.inc
1312                            echo -n " $sf" >> ad_flow_files.inc
1313                            ;;
1314                  esac                  esac
1315              fi              fi
1316          fi          fi
1317      done      done
1318      if test "x$deplist" != x ; then      if test "x$deplist" != x ; then
1319          echo $'\n'"#  These files are linked from $d" >> srclinks.tmp          echo "" >> srclinks.tmp
1320            echo "#  These files are linked from $d" >> srclinks.tmp
1321          echo "$deplist :" >> srclinks.tmp          echo "$deplist :" >> srclinks.tmp
1322          echo $'\t$(LN) '$d'/$@ $@' >> srclinks.tmp          printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp
1323      fi      fi
1324  done  done
1325  rm -rf .links.tmp  rm -rf .links.tmp
1326  echo "" >> srclist.inc  echo "" >> srclist.inc
1327  echo "" >> csrclist.inc  echo "" >> csrclist.inc
1328    echo "" >> f90srclist.inc
1329  echo "" >> hlist.inc  echo "" >> hlist.inc
1330    echo "" >> ad_flow_files.inc
1331    
1332  if test -e $MAKEFILE ; then  if test -e $MAKEFILE ; then
1333      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.bak"
# Line 819  echo "# by the command:" >> $MAKEFILE Line 1341  echo "# by the command:" >> $MAKEFILE
1341  echo "#    $0 $@" >> $MAKEFILE  echo "#    $0 $@" >> $MAKEFILE
1342  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
1343  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE
1344    
1345    EXE_AD=$EXECUTABLE"_ad"
1346    EXE_FTL=$EXECUTABLE"_ftl"
1347    EXE_SVD=$EXECUTABLE"_svd"
1348    
1349  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
1350  #  #
1351  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
# Line 847  EXEDIR      = ${EXEDIR} Line 1374  EXEDIR      = ${EXEDIR}
1374  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}
1375  TOOLSDIR    = ${TOOLSDIR}  TOOLSDIR    = ${TOOLSDIR}
1376    
1377    #eh3  new defines for the adjoint work
1378    AUTODIFF    = ${ROOTDIR}/pkg/autodiff
1379    EXE_AD      = ${EXE_AD}
1380    EXE_FTL     = ${EXE_FTL}
1381    EXE_SVD     = ${EXE_SVD}
1382    
1383    ENABLED_PACKAGES = ${ENABLED_PACKAGES}
1384    DISABLED_PACKAGES = ${DISABLED_PACKAGES}
1385    
1386  EOF  EOF
1387    
1388  #  Note: figure out some way to add Hyades JAM libraries here  #  Note: figure out some way to add Hyades JAM libraries here
# Line 862  MAKEDEPEND = ${MAKEDEPEND} Line 1398  MAKEDEPEND = ${MAKEDEPEND}
1398  KPP = ${KPP}  KPP = ${KPP}
1399  # Fortran compiler  # Fortran compiler
1400  FC = ${FC}  FC = ${FC}
1401    # Fortran compiler
1402    F90C = ${F90C}
1403  # Link editor  # Link editor
1404  LINK = ${LINK}  LINK = ${LINK}
1405    
# Line 875  KFLAGS2 = ${KFLAGS2} Line 1413  KFLAGS2 = ${KFLAGS2}
1413  # Optim./debug for FC  # Optim./debug for FC
1414  FFLAGS = ${FFLAGS}  FFLAGS = ${FFLAGS}
1415  FOPTIM = ${FOPTIM}  FOPTIM = ${FOPTIM}
1416    # Optim./debug for FC
1417    F90FLAGS = ${F90FLAGS}
1418    F90OPTIM = ${F90OPTIM}
1419  # Flags for CC  # Flags for CC
1420  CFLAGS = ${CFLAGS}  CFLAGS = ${CFLAGS}
1421  # Files that should not be optimized  # Files that should not be optimized
# Line 882  NOOPTFILES = ${NOOPTFILES} Line 1423  NOOPTFILES = ${NOOPTFILES}
1423  NOOPTFLAGS = ${NOOPTFLAGS}  NOOPTFLAGS = ${NOOPTFLAGS}
1424  # Flags and libraries needed for linking  # Flags and libraries needed for linking
1425  LIBS = ${LIBS} \$(XLIBS)  LIBS = ${LIBS} \$(XLIBS)
1426    # Name of the Mekfile
1427    MAKEFILE=${MAKEFILE}
1428    
1429  EOF  EOF
1430    
1431  cat srclist.inc  >> $MAKEFILE  cat srclist.inc       >> $MAKEFILE
1432  cat csrclist.inc >> $MAKEFILE  cat csrclist.inc      >> $MAKEFILE
1433  cat hlist.inc >> $MAKEFILE  cat f90srclist.inc    >> $MAKEFILE
1434  echo 'F77FILES =  $(SRCFILES:.F=.f)'                    >> $MAKEFILE  cat hlist.inc         >> $MAKEFILE
1435  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o)' >> $MAKEFILE  cat ad_flow_files.inc >> $MAKEFILE
1436    echo               >> $MAKEFILE
1437    echo 'F77FILES =  $(SRCFILES:.F=.f)'                                           >> $MAKEFILE
1438    echo 'F90FILES =  $(F90SRCFILES:.F90=.f90)'                                    >> $MAKEFILE
1439    echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
1440    
1441  rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp  rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc
1442    rm -f ad_flow_files.inc
1443    
1444  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
1445    
1446  .SUFFIXES:  .SUFFIXES:
1447  .SUFFIXES: .o .f .p .F .c  .SUFFIXES: .o .f .p .F .c .F90 .f90
1448    
1449  all: \$(EXECUTABLE)  all: \$(EXECUTABLE)
1450  \$(EXECUTABLE): \$(OBJFILES)  \$(EXECUTABLE): links \$(OBJFILES)
1451            @echo Creating \$@ ...
1452          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
1453  depend:  depend:
1454          @make links          @make links
1455          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
1456            \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
1457    
1458  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES)  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) ${PACKAGES_DOT_H} AD_CONFIG.h
1459    
1460  small_f: \$(F77FILES)  small_f: \$(F77FILES) \$(F90FILES)
1461    
1462  output.txt: \$(EXECUTABLE)  output.txt: \$(EXECUTABLE)
1463          @printf 'running ... '          @printf 'running ... '
1464          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
1465    
1466  clean:  clean:
1467          -rm -rf *.o *.f *.p ${RMFILES} work.{pc,pcl}          -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl} *.template
1468  Clean:  Clean:
1469          @make clean          @make clean
1470          @make cleanlinks          @make cleanlinks
1471          -rm -f Makefile.bak          -rm -f ${PACKAGES_DOT_H} AD_CONFIG.h
1472            -rm -f Makefile.bak genmake_state genmake_*optfile genmake_warnings make.log
1473  CLEAN:  CLEAN:
1474          @make Clean          @make Clean
1475          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
1476          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
1477          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
1478          -rm -f \$(EXECUTABLE)          -rm -f \$(EXECUTABLE) output.txt
1479    
1480    #eh3 Makefile: makefile
1481  makefile:  makefile:
1482          ${0} $@          $THIS_SCRIPT $@
1483  cleanlinks:  cleanlinks:
1484          -find . -type l -exec rm {} \;          -find . -type l -exec rm {} \;
1485    
1486    # Special targets
1487    ${PACKAGES_DOT_H}:
1488            @echo Creating \$@ ...
1489            @\$(TOOLSDIR)/convert_cpp_cmd2defines "Warngin - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@
1490    AD_CONFIG.h:
1491            @echo Creating \$@ ...
1492            @\$(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 > \$@
1493    
1494  # The normal chain of rules is (  .F - .f - .o  )  # The normal chain of rules is (  .F - .f - .o  )
1495  .F.f:  .F.f:
1496          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1497  .f.o:  .f.o:
1498          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
1499    .F90.f90:
1500            \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1501    .f90.o:
1502            \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
1503  .c.o:  .c.o:
1504          \$(CC) \$(CFLAGS) -c \$<          \$(CC) \$(CFLAGS) -c \$<
1505    
# Line 945  cleanlinks: Line 1509  cleanlinks:
1509  .p.f:  .p.f:
1510          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
1511    
1512    #=========================================
1513    #===  Automatic Differentiation Rules  ===
1514    
1515    TAMC           = ${TAMC}
1516    TAF            = ${TAF}
1517    
1518    TAF_EXTRA      = ${TAF_EXTRA}
1519    TAMC_EXTRA     = ${TAMC_EXTRA}
1520    
1521  EOF  EOF
1522    
1523    ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
1524    ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF_FLAGS"
1525    ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
1526    for i in $ad_vars ; do
1527        name=$i
1528        t1="t2=\$"`echo $i`
1529        eval $t1
1530        printf "%-20s = " $name >> $MAKEFILE
1531        echo $t2 >> $MAKEFILE
1532    done
1533    
1534    echo "  Add the source list for AD code generation"
1535    echo >> $MAKEFILE
1536    echo -n "AD_FILES = " >> $MAKEFILE
1537    AD_FILES=`cat ad_files`
1538    for i in $AD_FILES ; do
1539        echo    " \\" >> $MAKEFILE
1540        echo -n " $i" >> $MAKEFILE
1541    done
1542    echo >> $MAKEFILE
1543    rm -f ad_files
1544    
1545    cat >>$MAKEFILE <<EOF
1546    
1547    # ... AD ...
1548    adall: ad_taf
1549    adtaf: ad_taf_output.f
1550    adtamc: ad_tamc_output.f
1551    
1552    ad_input_code.f: links \$(AD_FILES) \$(HEADERFILES)
1553            @\$(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
1554            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
1555            -rm -f ad_config.template
1556            @make \$(F77FILES)
1557            @make \$(AD_FLOW_FILES)
1558            cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f
1559    
1560    ad_taf_output.f: ad_input_code.f
1561            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1562            cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f
1563    
1564    adtafonly:
1565            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1566            cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f
1567    
1568    ad_taf: ad_taf_output.o \$(OBJFILES)
1569            \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
1570    
1571    ad_tamc_output.f: ad_input_code.f
1572            \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f
1573            cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.f
1574    
1575    ad_tamc: ad_tamc_output.o \$(OBJFILES)
1576            \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
1577    
1578    
1579    # ... FTL ...
1580    ftlall: ftl_taf
1581    ftltaf: ftl_taf_output.f
1582    ftltamc: ftl_tamc_output.f
1583    
1584    ftl_input_code.f: links \$(AD_FILES) \$(HEADERFILES)
1585            @\$(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
1586            cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
1587            -rm -f ftl_config.template
1588            @make \$(F77FILES)
1589            @make \$(AD_FLOW_FILES)
1590            cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f
1591    
1592    ftl_taf_output.f: ftl_input_code.f
1593            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f
1594            cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f
1595    
1596    ftltafonly:
1597            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f
1598            cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f
1599    
1600    ftl_taf: ftl_taf_output.o \$(OBJFILES)
1601            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
1602    
1603    ftl_tamc_output.f: ftl_input_code.f
1604            \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f
1605            cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.f
1606    
1607    ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
1608            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
1609    
1610    
1611    # ... SVD ...
1612    svdtaf: ad_taf_output.f ftl_taf_output.f
1613    svdall: svd_taf
1614    
1615    svd_taf: ad_taf_output.o ftl_taf_output.o \$(OBJFILES)
1616            \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
1617    
1618    
1619    #=========================================
1620    
1621    EOF
1622    
1623    if test "x$EXEHOOK" != x ; then
1624        printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
1625    fi
1626    
1627  echo "  Making list of \"exceptions\" that need \".p\" files"  echo "  Making list of \"exceptions\" that need \".p\" files"
1628  for i in $KPPFILES ; do  for i in $KPPFILES ; do
1629      base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`      base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
# Line 965  for i in $NOOPTFILES ; do Line 1642  for i in $NOOPTFILES ; do
1642          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
1643      fi      fi
1644      echo "$base.o: $base.f" >> $MAKEFILE      echo "$base.o: $base.f" >> $MAKEFILE
1645      echo $'\t$(FC) $(FFLAGS) $(NOOPTFLAGS) -c $<' >> $MAKEFILE      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
1646  done  done
1647    
1648  echo "  Add rules for links"  echo "  Add rules for links"
# Line 973  cat srclinks.tmp >> $MAKEFILE Line 1650  cat srclinks.tmp >> $MAKEFILE
1650  rm -f srclinks.tmp  rm -f srclinks.tmp
1651    
1652  echo "  Adding makedepend marker"  echo "  Adding makedepend marker"
1653  echo $'\n\n'"# DO NOT DELETE" >> $MAKEFILE  printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
1654    
1655    printf "\n===  Done  ===\n"
1656    
1657  echo $'\n'"===  Done  ==="  
1658    #  Write the "state" for future records
1659    if test "x$DUMPSTATE" != xf ; then
1660        echo -n "" > genmake_state
1661        for i in $gm_state ; do
1662            t1="t2=\$$i"
1663            eval $t1
1664            echo "$i='$t2'" >> genmake_state
1665        done
1666    fi

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

  ViewVC Help
Powered by ViewVC 1.1.22