/[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.38 by edhill, Fri Nov 14 12:52:56 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    #     if test "x$OFLIST" = x ; then
80    #       echo "  No pre-defined options files were found matching this platform"
81    #       echo "  but examples for other platforms can be found in:"
82    #       echo "    $ROOTDIR/tools/build_options"
83    #     else
84    #       echo "  Options files (located in $ROOTDIR/tools/build_options) that"
85    #       echo "  may work with this machine are:"
86    #       for i in $OFLIST ; do
87    #           echo "    $i"
88    #       done
89    #     fi
90        
91      echo "test" > test      echo "test" > test
92      ln -s ./test link      ln -s ./test link
93      RETVAL=$?      RETVAL=$?
94      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
95          p_LN="ln -s"          LN="ln -s"
96        else
97            echo "Error: \"ln -s\" does not appear to work on this system!"
98            echo "  For help, please contact <MITgcm-support@mitgcm.org>."
99            exit 1
100      fi      fi
101      rm -f test link      rm -f test link
102    
103      p_CPP=`which cpp`      if test "x$CPP" = x ; then
104                CPP="cpp -traditional -P"
105      RETVAL=$?      fi
106      if test "x${RETVAL}" = x0 ; then  
107          p_LN="ln -s"      # makedepend is not always available
108        if test "x${MAKEDEPEND}" = x ; then
109          which makedepend >& /dev/null
110          RETVAL=$?
111          if test "x${RETVAL}" = x1 ; then
112             echo "    makedepend was not found. Using xmakedpend instead."
113             MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
114          fi
115      fi      fi
     rm -f test link  
116    
117      # look for possible fortran compilers      # look for possible fortran compilers
118        tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"
119      p_FC=      p_FC=
120      for c in f77 g77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 ; do      for c in $tmp ; do
121          which $c > /dev/null 2>&1          rm -f ./hello.f ./hello
122            cat >> hello.f <<EOF
123          program hello
124          do i=1,3
125            print *, 'hello world : ', i
126          enddo
127          end
128    EOF
129            $c -o hello hello.f > /dev/null 2>&1
130          RETVAL=$?          RETVAL=$?
131          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
132              p_FC="$p_FC $c"              p_FC="$p_FC $c"
133          fi          fi
134      done      done
135      echo "Possible FORTRAN compilers appear to be:  "      rm -f ./hello.f ./hello
136      if test "x${p_FC}" = x ; then      if test "x${p_FC}" = x ; then
137          echo "  None found!!!"          cat 1>&2 <<EOF
138      else  
139          echo "  "$p_FC  Error: No Fortran compilers were found in your path.  Please specify one using:
140      fi  
141        1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
142        2) a command-line option (eg. "-fc NAME"), or
143        3) the MITGCM_FC environment variable.
144    
     # 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  
145  EOF  EOF
146          eval "$mpi_fort -showme test.f > out"          exit 1
147          RETVAL=$?      else
148          if test "x${RETVAL}" = x0 ; then          echo "  The possible FORTRAN compilers found in your path are:"
149              a=`cat out`          echo "   "$p_FC
150              for i in $a ; do          if test "x$FC" = x ; then
151                  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  
152          fi          fi
         rm -f test.f out  
153      fi      fi
154    
155  }      for i in $p_FC ; do
156            p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
157            if test -r $p_OF ; then
158                OPTFILE=$p_OF
159                echo "  The options file:  $p_OF"
160                echo "    appears to match so we'll use it."
161                break
162            fi
163        done
164        if test "x$OPTFILE" = x ; then
165            cat 1>&2 <<EOF
166    
167  parse_options()  {  Error: No options file was found in:  $ROOTDIR/tools/build_options/
168      that matches this platform ("$PLATFORM") and the compilers found in
169      your path.  Please specify an "optfile" using:
170    
171      ac_prev=      1) the command line (eg. "-optfile=path/to/OPTFILE"), or
172      for ac_option in "${OPTIONS[@]}" ; do      2) the MITGCM_OF environment variable.
173    
174      If you need help, please contact the developers at <MITgcm-support@mitgcm.org>.
175    
176    EOF
177            exit 1
178        fi
179        
180    #     # look for possible MPI libraries
181    #     mpi_libs=
182    #     mpi_fort=`which mpif77 2>/dev/null`
183    #     RETVAL=$?
184    #     if test "x${RETVAL}" = x0 ; then
185    #       cat >>test.f <<EOF
186    #       PROGRAM HELLO
187    #       DO 10, I=1,10
188    #       PRINT *,'Hello World'
189    #    10 CONTINUE
190    #       STOP
191    #       END
192    # EOF
193    #       eval "$mpi_fort -showme test.f > out"
194    #       RETVAL=$?
195    #       if test "x${RETVAL}" = x0 ; then
196    #           a=`cat out`
197    #           for i in $a ; do
198    #               case $i in
199    #                   -*)
200    #                       mpi_libs="$mpi_libs $i" ;;
201    #               esac
202    #           done
203    #           echo "The MPI libs appear to be:"
204    #           echo "  "$mpi_libs
205    #       fi
206    #       rm -f test.f out
207    #     fi
208    
         # 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  
209  }  }
210    
211  #  Parse the package dependency information  #  Parse the package dependency information
# Line 199  get_pdepend_list()  { Line 214  get_pdepend_list()  {
214      #  strip the comments and then convert the dependency file into      #  strip the comments and then convert the dependency file into
215      #  two arrays: PNAME, DNAME      #  two arrays: PNAME, DNAME
216      cat $1 | sed -e 's/#.*$//g' \      cat $1 | sed -e 's/#.*$//g' \
217          | 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} }' \
218          > ./.pd_tmp          > ./.pd_tmp
219      source ./.pd_tmp      . ./.pd_tmp
220      rm -f ./.pd_tmp      rm -f ./.pd_tmp
221    
222      echo -n "PNAME = "${}      echo -n "PNAME = "${}
# Line 210  get_pdepend_list()  { Line 225  get_pdepend_list()  {
225    
226  #  Explain usage  #  Explain usage
227  usage()  {  usage()  {
228      echo ""      echo
229      echo "Usage: "$0" [OPTIONS]"      echo "Usage: "$0" [OPTIONS]"
230      echo "  where [OPTIONS] can be:"$'\n'      echo "  where [OPTIONS] can be:"
231        echo
232      echo "    -help | --help | -h | --h"      echo "    -help | --help | -h | --h"
233      echo "    -nooptfile | --nooptfile"      echo "    -nooptfile | --nooptfile"
234      echo "      -optfile NAME | --optfile NAME | -of NAME | --of NAME"      echo "      -optfile NAME | --optfile NAME | -of NAME | --of NAME"
# Line 221  usage()  { Line 237  usage()  {
237      echo "      -pdepend=NAME | --pdepend=NAME"      echo "      -pdepend=NAME | --pdepend=NAME"
238      echo "    -pdefault NAME | --pdefault NAME"      echo "    -pdefault NAME | --pdefault NAME"
239      echo "      -pdefault=NAME | --pdefault=NAME"      echo "      -pdefault=NAME | --pdefault=NAME"
240      echo "    -makefile NAME | -ma NAME"      echo "    -make NAME | -m NAME"
241      echo "      --makefile=NAME | -ma=NAME"      echo "      --make=NAME | -m=NAME"
242        echo "    -makefile NAME | -mf NAME"
243        echo "      --makefile=NAME | -mf=NAME"
244      echo "    -platform NAME | --platform NAME | -pl NAME | --pl NAME"      echo "    -platform NAME | --platform NAME | -pl NAME | --pl NAME"
245      echo "      -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"      echo "      -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"
246      echo "    -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"      echo "    -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"
# Line 233  usage()  { Line 251  usage()  {
251      echo "      -disable=NAME | --disable=NAME"      echo "      -disable=NAME | --disable=NAME"
252      echo "    -enable NAME | --enable NAME"      echo "    -enable NAME | --enable NAME"
253      echo "      -enable=NAME | --enable=NAME"      echo "      -enable=NAME | --enable=NAME"
254        echo "    -standarddirs NAME | --standarddirs NAME"
255        echo "      -standarddirs=NAME | --standarddirs=NAME"
256      echo "    -noopt NAME | --noopt NAME"      echo "    -noopt NAME | --noopt NAME"
257      echo "      -noopt=NAME | --noopt=NAME"      echo "      -noopt=NAME | --noopt=NAME"
258  #    echo "    -cpp NAME | --cpp NAME"  #    echo "    -cpp NAME | --cpp NAME"
# Line 241  usage()  { Line 261  usage()  {
261      echo "      -fc=NAME | --fc=NAME"      echo "      -fc=NAME | --fc=NAME"
262      echo "    -[no]ieee | --[no]ieee"      echo "    -[no]ieee | --[no]ieee"
263      echo "    -[no]mpi | --[no]mpi"      echo "    -[no]mpi | --[no]mpi"
264      echo "    -[no]jam | --[no]jam"$'\n'      echo "    -[no]jam | --[no]jam"
265      echo "  and NAME is a string such as:"$'\n'      echo
266        echo "  and NAME is a string such as:"
267        echo
268      echo "    --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'"      echo "    --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'"
269      echo "    -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'"      echo "    -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'"
270      echo "    -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"$'\n'      echo "    -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"
271        echo
272      echo "  which, depending upon your shell, may need to be single-quoted"      echo "  which, depending upon your shell, may need to be single-quoted"
273      echo "  if it contains spaces, dashes, or other special characters."      echo "  if it contains spaces, dashes, or other special characters."
274      exit 1      exit 1
275  }  }
276    
277  # Dump all important state  #  Build a CPP macro to automate calling C routines from FORTRAN
278  dump_state()  {  get_fortran_c_namemangling()  {
279      fname=$1      default_nm="#define FC_NAMEMANGLE(X) X ## _"
280      echo " " > $fname      
281        cat > genmake_test.c <<EOF
282    void tcall( char * string ) { tsub( string ); }
283    EOF
284        $MAKE genmake_test.o > genmake_test.log 2>&1
285      RETVAL=$?      RETVAL=$?
286      if test "x${RETVAL}" = x ; then      if test "x$RETVAL" != x0 ; then
287          echo "Error: cannot write to $fname"          cat genmake_test.log >> genmake_errors
288          exit 1          FC_NAMEMANGLE=$default_nm
289            echo
290            echo "WARNING: C test compile fails -- please see \"genmake_errors\""
291            echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"
292            echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."
293            rm -f genmake_tcomp.* genmake_test.*
294            return 1
295        fi
296        c_tcall=`nm genmake_test.o | grep tcall | cut -d ' ' -f 3`
297        RETVAL=$?
298        if test "x$RETVAL" != x0 ; then
299            FC_NAMEMANGLE=$default_nm
300            echo
301            echo "WARNING: The \"nm\" command failed."
302            echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"
303            echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."
304            rm -f genmake_tcomp.* genmake_test.*
305            return 1
306        fi
307        cat > genmake_tcomp.f <<EOF
308          subroutine tcall( string )
309          character*(*) string
310          call tsub( string )
311          end
312    EOF
313        $FC $FFLAGS $DEFINES -c genmake_tcomp.f > genmake_tcomp.log 2>&1
314        RETVAL=$?
315        if test "x$RETVAL" != x0 ; then
316            cat genmake_tcomp.log >> genmake_errors
317            FC_NAMEMANGLE=$default_nm
318            echo
319            echo "WARNING: FORTRAN test compile fails -- please see \"genmake_errors\""
320            echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"
321            echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."
322            rm -f genmake_tcomp.* genmake_test.*
323            return 1
324        fi
325        f_tcall=`nm genmake_tcomp.o | grep tcall | cut -d ' ' -f 3`
326        RETVAL=$?
327        if test "x$RETVAL" != x0 ; then
328            FC_NAMEMANGLE=$default_nm
329            echo
330            echo "WARNING: The \"nm\" command failed."
331            echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"
332            echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."
333            rm -f genmake_tcomp.* genmake_test.*
334            return 1
335        fi
336    
337        c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
338        f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
339        c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
340        f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
341    
342        nmangle="X"
343        if test "x$c_a" != "x$f_a" ; then
344            comm="echo x$f_a | sed -e 's|x$c_a||'"
345            a=`eval $comm`
346            nmangle="$a ## $nmangle"
347        fi
348        if test "x$c_b" != "x$f_b" ; then
349            comm="echo x$f_b | sed -e 's|x$c_b||'"
350            b=`eval $comm`
351            nmangle="$nmangle ## $b"
352      fi      fi
     echo "makefile "$makefile > $fname  
 }  
353    
354        FC_NAMEMANGLE="#define FC_NAMEMANGLE(X)  $nmangle"
355    
356  #eh3 # This is the generic configuration.      #  cleanup the testing files
357  #eh3 set LN         = ( 'ln -s' )      rm -f genmake_tcomp.* genmake_test.*
358  #eh3 set CPP        = ( '/lib/cpp -P' )  }
 #eh3 set S64        = ( '$(TOOLSDIR)/set64bitConst.sh' )  
 #eh3 set KPP        = (  )  
 #eh3 set FC         = ( 'f77' )  
 #eh3 set LINK       = $FC  
 #eh3 set MAKEDEPEND = ( 'makedepend' )  
 #eh3 set INCLUDES   = ( -I. )  
 #eh3 set FFLAGS     = (  )  
 #eh3 set FOPTIM     = (  )  
 #eh3 set CFLAGS     = (  )  
 #eh3 set KFLAGS1    = (  )  
 #eh3 set KFLAGS2    = (  )  
 #eh3 set LIBS       = (  )  
 #eh3 set KPPFILES   = (  )  
 #eh3 if (! $?NOOPTFILES ) set NOOPTFILES = (  )  
 #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = (  )  
359    
360  #  Set defaults here  #  Set defaults here
361    COMMANDL="$0 $@"
362    
363  PLATFORM=  PLATFORM=
364  LN=  LN=
365  S64=  S64=
366  KPP=  KPP=
367  FC=  FC=
368  LINK=  LINK=
369    # DEFINES="-DWORDLENGTH=4"
370    DEFINES=
371  PACKAGES=  PACKAGES=
372  ENABLE=  ENABLE=
373  DISABLE=  DISABLE=
374  MAKEFILE=  MAKEFILE=
375  MAKEDEPEND=  MAKEDEPEND=
376  PDEPEND=  PDEPEND=
377    DUMPSTATE=t
378  PDEFAULT=  PDEFAULT=
379  OPTFILE=  OPTFILE=
380  INCLUDES=-I.  INCLUDES="-I."
381  FFLAGS=  FFLAGS=
382  FOPTIM=  FOPTIM=
383  CFLAGS=  CFLAGS=
# Line 309  KPPFILES= Line 388  KPPFILES=
388  NOOPTFILES=  NOOPTFILES=
389  NOOPTFLAGS=  NOOPTFLAGS=
390    
391    # DEFINES checked by test compilation
392    HAVE_SYSTEM=
393    HAVE_FDATE=
394    FC_NAMEMANGLE=
395    
396  MODS=  MODS=
397  TOOLSDIR=  TOOLSDIR=
398  SOURCEDIRS=  SOURCEDIRS=
399  INCLUDEDIRS=  INCLUDEDIRS=
400    STANDARDDIRS=
401    
402  PWD=`pwd`  PWD=`pwd`
403  MAKE=make  MAKE=make
404    AWK=awk
405  THISHOSTNAME=`hostname`  THISHOSTNAME=`hostname`
406  THISCWD=`pwd`  THISCWD=`pwd`
407  THISDATE=`date`  THISDATE=`date`
408  MACHINE=`uname -a`  MACHINE=`uname -a`
409    EXECUTABLE=
410    EXEHOOK=
411    EXEDIR=
412    PACKAGES_CONF=
413    IEEE=
414    if test "x$MITGCM_IEEE" != x ; then
415        IEEE=$MITGCM_IEEE
416    fi
417    
418    AUTODIFF_PKG_USED=f
419    AD_OPTFILE=
420    TAF=
421    AD_TAF_FLAGS=
422    FTL_TAF_FLAGS=
423    SVD_TAF_FLAGS=
424    TAF_EXTRA=
425    TAMC=
426    AD_TAMC_FLAGS=
427    FTL_TAF_FLAGS=
428    SVD_TAMC_FLAGS=
429    TAMC_EXTRA=
430    
431    
432    #  The following state can be set directly by command-line switches
433    gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"
434    gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS"
435    
436    #  The following state is not directly set by command-line switches
437    gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
438    gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
439    gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"
440    gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
441    gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE"
442    
443    #  The following are all related to adjoint/tangent-linear stuff
444    gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
445    gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
446    gm_s12="TAF_EXTRA TAMC_EXTRA"
447    
448  echo $'\n'"===  Processing options files and arguments  ==="  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"
449  gm_local="./gm_local"  gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
450    
451    
452    echo
453    echo "===  Processing options files and arguments  ==="
454    gm_local="genmake_local"
455    for i in . $MODS ; do
456        if test -r $i/$gm_local ; then
457            . $i/$gm_local
458            break
459        fi
460    done
461  echo -n "  getting local config information:  "  echo -n "  getting local config information:  "
462  if test -e $gm_local ; then  if test -e $gm_local ; then
463      echo "using $gm_local"      echo "using $gm_local"
464      source $gm_local      . $gm_local
465      echo "DISABLE=$DISABLE"$'\n'"ENABLE=$ENABLE"      # echo "DISABLE=$DISABLE"
466        # echo "ENABLE=$ENABLE"
467  else  else
468      echo "none found"      echo "none found"
469  fi  fi
470    
471  #  echo "$0::$1:$2:$3:$4:$5:$6:$7:"  #  echo "$0::$1:$2:$3:$4:$5:$6:$7:"
472  OPTIONS=()  #OPTIONS=
473  n=0  #n=0
474  for i ; do  #for i ; do
475     setvar="OPTIONS[$n]='$i'"  #   echo "$i  $n"
476     #  echo "  $setvar"  #   setvar="OPTIONS[$n]='$i'"
477     eval "$setvar"  #   #  echo "  $setvar"
478     n=$(( $n + 1 ))  #   eval "$setvar"
479  done  #   n=$(( $n + 1 ))
480  parse_options  #done
481    #parse_options
482  echo "  getting OPTFILE information:  "  ac_prev=
483  if test "x${OPTFILE}" = x ; then  for ac_option ; do
484      echo "Warning: no OPTFILE specified so we'll look for possible settings"  
485      echo $'\n'"===  Searching for possible settings for OPTFILE  ==="      # If the previous option needs an argument, assign it.
486      find_possible_configs      if test -n "$ac_prev"; then
487  else          eval "$ac_prev=\$ac_option"
488      if test "x$OPTFILE" = xNONE ; then          ac_prev=
489          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  
     fi  
 fi  
   
 echo $'\n'"===  Setting defaults  ==="  
 echo -n "  Adding MODS directories:  "  
 for d in $MODS ; do  
     if test ! -d $d ; then  
         echo $'\n\n'"Error: MODS directory \"$d\" not found!"  
         exit 1  
     else  
         echo -n " $d"  
         SOURCEDIRS="$SOURCEDIRS $d"  
         INCLUDEDIRS="$INCLUDEDIRS $d"  
490      fi      fi
491        
492        ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
493        
494        case $ac_option in
495            
496            -help | --help | -h | --h)
497                usage ;;
498            
499            -nooptfile | --nooptfile)
500                OPTFILE="NONE" ;;
501            -optfile | --optfile | -of | --of)
502                ac_prev=OPTFILE ;;
503            -optfile=* | --optfile=* | -of=* | --of=*)
504                OPTFILE=$ac_optarg ;;
505            
506            -adoptfile | --adoptfile | -ad | --ad)
507                ac_prev=AD_OPTFILE ;;
508            -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
509                AD_OPTFILE=$ac_optarg ;;
510            
511            -pdepend | --pdepend)
512                ac_prev=PDEPEND ;;
513            -pdepend=* | --pdepend=*)
514                PDEPEND=$ac_optarg ;;
515            
516            -pdefault | --pdefault)
517                ac_prev=PDEFAULT ;;
518            -pdefault=* | --pdefault=*)
519                PDEFAULT=$ac_optarg ;;
520            
521            -make | --make | -m | --m)
522                ac_prev=MAKE ;;
523            -make=* | --make=* | -m=* | --m=*)
524                MAKE=$ac_optarg ;;
525            
526            -makefile | --makefile | -ma | --ma)
527                ac_prev=MAKEFILE ;;
528            -makefile=* | --makefile=* | -ma=* | --ma=*)
529                MAKEFILE=$ac_optarg ;;
530            
531            -platform | --platform | -pl | --pl)
532                ac_prev=PLATFORM ;;
533            -platform=* | --platform=* | -pl=* | --pl=*)
534                PLATFORM=$ac_optarg ;;
535            
536            -rootdir | --rootdir | -rd | --rd)
537                ac_prev=ROOTDIR ;;
538            -rootdir=* | --rootdir=* | -rd=* | --rd=*)
539                ROOTDIR=$ac_optarg ;;
540            
541            -mods | --mods | -mo | --mo)
542                ac_prev=MODS ;;
543            -mods=* | --mods=* | -mo=* | --mo=*)
544                MODS=$ac_optarg ;;
545            
546            -disable | --disable)
547                ac_prev=DISABLE ;;
548            -disable=* | --disable=*)
549                DISABLE=$ac_optarg ;;
550            
551            -enable | --enable)
552                ac_prev=ENABLE ;;
553            -enable=* | --enable=*)
554                ENABLE=$ac_optarg ;;
555            
556            -standarddirs | --standarddirs)
557                ac_prev=STANDARDDIRS ;;
558            -standarddirs=* | --standarddirs=*)
559                STANDARDDIRS=$ac_optarg ;;
560    
561            -noopt | --noopt)
562                ac_prev=NOOPT ;;
563            -noopt=* | --noopt=*)
564                NOOPT=$ac_optarg ;;
565            
566    #           -cpp | --cpp)
567    #               ac_prev=cpp ;;
568    #           -cpp=* | --cpp=*)
569    #               CPP=$ac_optarg ;;
570                
571            -fortran | --fortran | -fc | --fc)
572                ac_prev=FC ;;
573            -fc=* | --fc=*)
574                FC=$ac_optarg ;;
575            
576            -ieee | --ieee)
577                IEEE=true ;;
578            -noieee | --noieee)
579                IEEE= ;;
580            
581            -mpi | --mpi)
582                MPI=true ;;
583            -nompi | --nompi)
584                MPI= ;;
585            
586            -jam | --jam)
587                JAM=1 ;;
588            -nojam | --nojam)
589                JAM=0 ;;
590            
591            -ds | --ds)
592                DUMPSTATE=t ;;
593            
594            -taf_extra | --taf_extra)
595                ac_prev=TAF_EXTRA ;;
596            -taf_extra=* | --taf_extra=*)
597                TAF_EXTRA=$ac_optarg ;;
598    
599            -tamc_extra | --tamc_extra)
600                ac_prev=TAMC_EXTRA ;;
601            -tamc_extra=* | --tamc_extra=*)
602                TAMC_EXTRA=$ac_optarg ;;
603    
604            -*)
605                echo "Error: unrecognized option: "$ac_option
606                usage
607                ;;
608            
609            *)
610                echo "Error: unrecognized argument: "$ac_option
611                usage
612                ;;
613            
614        esac
615        
616  done  done
 echo  
617    
618  if test "x$MAKEFILE" = x ; then  if test -f ./.genmakerc ; then
619      MAKEFILE="Makefile"      echo
620  fi      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
621  if test "x${PLATFORM}" = x ; then      echo "  file.  This file format is no longer supported.  Please see:"
622      PLATFORM=$p_PLATFORM      echo
623        echo "    http://mitgcm.org/devel_HOWTO/"
624        echo
625        echo "  for directions on how to setup and use the new \"genmake2\" input"
626        echo "  files and send an email to MITgcm-support@mitgcm.org if you want help."
627        echo
628  fi  fi
629    
630  if test "x${ROOTDIR}" = x ; then  if test "x${ROOTDIR}" = x ; then
# Line 414  if test ! -d ${ROOTDIR} ; then Line 652  if test ! -d ${ROOTDIR} ; then
652      exit 1      exit 1
653  fi  fi
654    
655    echo "  getting OPTFILE information:  "
656    if test "x${OPTFILE}" = x ; then
657        if test "x$MITGCM_OF" = x ; then
658            echo "Warning: no OPTFILE specified so we'll look for possible settings"
659            printf "\n===  Searching for possible settings for OPTFILE  ===\n"
660            find_possible_configs
661        else
662            OPTFILE=$MITGCM_OF
663        fi
664    fi
665    if test "x$OPTFILE" != xNONE ; then
666        if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
667            echo "    using OPTFILE=\"$OPTFILE\""
668            . "$OPTFILE"
669            RETVAL=$?
670            if test "x$RETVAL" != x0 ; then
671                echo -n "Error: failed to source OPTFILE \"$OPTFILE\""
672                echo "--please check that variable syntax is bash-compatible"
673                exit 1
674            fi
675            if test "x$DUMPSTATE" != xf ; then
676                cp -f $OPTFILE "genmake_optfile"
677            fi
678        else
679            echo "Error: can't read OPTFILE=\"$OPTFILE\""
680            exit 1
681        fi
682    fi
683    
684    echo "  getting AD_OPTFILE information:  "
685    if test "x${AD_OPTFILE}" = x ; then
686        if test "x$MITGCM_AD_OF" = x ; then
687            AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
688        else
689            AD_OPTFILE=$MITGCM_AD_OF
690        fi
691    fi
692    if test "x${AD_OPTFILE}" != xNONE ; then
693        if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
694            echo "    using AD_OPTFILE=\"$AD_OPTFILE\""
695            . "$AD_OPTFILE"
696            RETVAL=$?
697            if test "x$RETVAL" != x0 ; then
698                echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
699                echo "--please check that variable syntax is bash-compatible"
700                exit 1
701            fi
702            if test "x$DUMPSTATE" != xf ; then
703                cp -f $AD_OPTFILE "genmake_ad_optfile"
704            fi
705        else
706            echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
707            exit 1
708        fi
709    fi
710    
711    #  Check that FC, LINK, CPP, S64, and LN are defined.  If not,
712    #  complain and abort!
713    if test "x$FC" = x ; then
714        cat <<EOF 1>&2
715    
716    Error: no Fortran compiler: please specify using one of the following:
717      1) within the options file ("FC=...") as specified by "-of=OPTFILE"
718      2) the "-fc=XXX" command-line option
719      3) the "./genmake_local" file
720    EOF
721        exit 1
722    fi
723    if test "x$LINK" = x ; then
724        LINK=$FC
725    fi
726    if test "x$CPP" = x ; then
727        CPP="cpp"
728    fi
729    echo "#define A a" | $CPP > test_cpp 2>&1
730    RETVAL=$?
731    if test "x$RETVAL" != x0 ; then
732        cat <<EOF 1>&2
733    
734    Error: C pre-processor "$CPP" failed the test case: please specify using:
735    
736      1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
737      2) the "./genmake_local" file
738      3) with the CPP environment variable
739    
740    EOF
741        exit 1
742    else
743        rm -f test_cpp
744    fi
745    if test "x$MAKEDEPEND" = x ; then
746        MAKEDEPEND=makedepend
747    fi
748    if test "x$LN" = x ; then
749        LN="ln -s"
750    fi
751    echo "test" > genmake_test_ln
752    $LN genmake_test_ln genmake_tlink
753    RETVAL=$?
754    if test "x$RETVAL" != x0 ; then
755        cat <<EOF 1>&2
756    
757    Error: The command "ln -s" failed -- please specify a working soft-link
758      command in the optfile.
759    
760    EOF
761        exit 1
762    fi
763    rm -f genmake_test_ln genmake_tlink
764    
765    printf "\n===  Checking system libraries  ===\n"
766    echo -n "  Do we have the system() command using $FC...  "
767    cat > genmake_tcomp.f <<EOF
768          program hello
769          call system('echo hi')
770          end
771    EOF
772    $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1
773    RETVAL=$?
774    if test "x$RETVAL" = x0 ; then
775        HAVE_SYSTEM=t
776        DEFINES="$DEFINES -DHAVE_SYSTEM"
777        echo "yes"
778    else
779        HAVE_SYSTEM=
780        echo "no"
781    fi
782    rm -f genmake_tcomp*
783    
784    echo -n "  Do we have the fdate() command using $FC...  "
785    cat > genmake_tcomp.f <<EOF
786          program hello
787          CHARACTER(128) string
788          string = ' '
789          call fdate( string )
790          print *, string
791          end
792    EOF
793    $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1
794    RETVAL=$?
795    if test "x$RETVAL" = x0 ; then
796        HAVE_FDATE=t
797        DEFINES="$DEFINES -DHAVE_FDATE"
798        echo "yes"
799    else
800        HAVE_FDATE=
801        echo "no"
802    fi
803    rm -f genmake_tcomp*
804    
805    echo "  The name mangling convention for $FC is...  "
806    #FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) X ## _"
807    if test "x$FC_NAMEMANGLE" = x ; then
808        get_fortran_c_namemangling
809    fi
810    echo "    '$FC_NAMEMANGLE'"
811    echo "$FC_NAMEMANGLE" > FC_NAMEMANGLE.h.template
812    cmp FC_NAMEMANGLE.h FC_NAMEMANGLE.h.template > /dev/null 2>&1
813    RETVAL=$?
814    if test "x$RETVAL" != x0 ; then
815        mv -f FC_NAMEMANGLE.h.template FC_NAMEMANGLE.h
816    fi
817    
818    
819    printf "\n===  Setting defaults  ===\n"
820    echo -n "  Adding MODS directories:  "
821    for d in $MODS ; do
822        if test ! -d $d ; then
823            echo
824            echo "Error: MODS directory \"$d\" not found!"
825            exit 1
826        else
827            echo -n " $d"
828            SOURCEDIRS="$SOURCEDIRS $d"
829            INCLUDEDIRS="$INCLUDEDIRS $d"
830        fi
831    done
832    echo
833    
834    if test "x$MAKEFILE" = x ; then
835        MAKEFILE="Makefile"
836    fi
837    if test "x${PLATFORM}" = x ; then
838        PLATFORM=$p_PLATFORM
839    fi
840    
841  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
842      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then
843          EXEDIR=../exe          EXEDIR=../exe
# Line 433  if test ! -d ${TOOLSDIR} ; then Line 857  if test ! -d ${TOOLSDIR} ; then
857      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"
858      exit 1      exit 1
859  fi  fi
860    if test "x$S64" = x ; then
861        S64='$(TOOLSDIR)/set64bitConst.sh'
862    fi
863    
864  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
865    
# Line 441  EXECUTABLE=${EXECUTABLE:-mitgcmuv} Line 868  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
868  #  they appear as regular source code  #  they appear as regular source code
869  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
870      echo "  Making source files in eesupp from templates"      echo "  Making source files in eesupp from templates"
871      $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1      ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1
872      RETVAL=$?      RETVAL=$?
873      if test "x${RETVAL}" == "x0" ; then      if test "x${RETVAL}" = x0 ; then
874          rm -f make_eesupp.errors          rm -f make_eesupp.errors
875      else      else
876          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 879  if test -r $ROOTDIR"/eesupp/src/Makefile
879      fi      fi
880  fi  fi
881    
882  echo $'\n'"===  Determining package settings  ==="  printf "\n===  Determining package settings  ===\n"
883  if  test "x${PDEPEND}" = x ; then  if  test "x${PDEPEND}" = x ; then
884      tmp=$ROOTDIR"/pkg/pkg_depend"      tmp=$ROOTDIR"/pkg/pkg_depend"
885      if test -r $tmp ; then      if test -r $tmp ; then
# Line 471  echo "  getting package dependency info Line 898  echo "  getting package dependency info
898  #  Strip the comments and then convert the dependency file into  #  Strip the comments and then convert the dependency file into
899  #  two arrays: PNAME, DNAME  #  two arrays: PNAME, DNAME
900  cat $PDEPEND | sed -e 's/#.*$//g' \  cat $PDEPEND | sed -e 's/#.*$//g' \
901      | 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}' \
902      > ./.pd_tmp      > ./.pd_tmp
903  RETVAL=$?  RETVAL=$?
904  if test ! "x${RETVAL}" = x0 ; then  if test ! "x${RETVAL}" = x0 ; then
905      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
906      exit 1      exit 1
907  fi  fi
908  source ./.pd_tmp  . ./.pd_tmp
909  rm -f ./.pd_tmp  rm -f ./.pd_tmp
910    
911    #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"
912    #  file should eventually be added so that, for convenience, one can
913    #  specify groups of packages using names like "ocean" and "atmosphere".
914  echo  -n "  checking default package list:  "  echo  -n "  checking default package list:  "
915  if test "x${PDEFAULT}" = x ; then  if test "x${PDEFAULT}" = x ; then
916        for i in "." $MODS ; do
917            if test -r $i"/packages.conf" ; then
918                    PDEFAULT=$i"/packages.conf"
919                    break
920            fi
921        done
922    fi
923    if test "x${PDEFAULT}" = x ; then
924      PDEFAULT="$ROOTDIR/pkg/pkg_default"      PDEFAULT="$ROOTDIR/pkg/pkg_default"
925  fi  fi
926  if test "x${PDEFAULT}" = xNONE ; then  if test "x${PDEFAULT}" = xNONE ; then
# Line 494  else Line 932  else
932      else      else
933          echo "  using PDEFAULT=\"$PDEFAULT\""          echo "  using PDEFAULT=\"$PDEFAULT\""
934          #  Strip the comments and add all the names          #  Strip the comments and add all the names
935          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | awk '(NF>0){print $0}'`          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
936          RETVAL=$?          RETVAL=$?
937          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
938              echo -n "Error: can't parse default package list "              echo -n "Error: can't parse default package list "
# Line 504  else Line 942  else
942          for i in $def ; do          for i in $def ; do
943              PACKAGES="$PACKAGES $i"              PACKAGES="$PACKAGES $i"
944          done          done
945          echo "    packages are:  $PACKAGES"          echo "    before group expansion packages are: $PACKAGES"
946            expand_pkg_groups
947            echo "    after group expansion packages are:  $PACKAGES"
948      fi      fi
949  fi  fi
950    
# Line 523  for p in $PACKAGES ; do Line 963  for p in $PACKAGES ; do
963  done  done
964  PACKAGES="$pack"  PACKAGES="$pack"
965  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
966  rm -f ./.tmp_pack  echo "" > ./.tmp_pack
967  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
968  for i in $PACKAGES ; do  for i in $PACKAGES ; do
969      if test ! -d "$ROOTDIR/pkg/$i" ; then      if test ! -d "$ROOTDIR/pkg/$i" ; then
# Line 544  echo "  applying package dependency rule Line 984  echo "  applying package dependency rule
984  ck=  ck=
985  while test "x$ck" != xtt ; do  while test "x$ck" != xtt ; do
986      i=0      i=0
987      rtot=${#PNAME[@]}      # rtot=${#PNAME[@]}
988        rtot=$nname
989      while test $i -lt $rtot ; do      while test $i -lt $rtot ; do
990    
991          #  Is $pname in the current $PACKAGES list?          #  Is $pname in the current $PACKAGES list?
992          pname=${PNAME[$i]}          #  pname=${PNAME[$i]}
993            tmp="pname=\"\$PNAME_$i\""
994            eval $tmp
995          pin="f"          pin="f"
996          for p in $PACKAGES ; do          for p in $PACKAGES ; do
997              if test "x$p" = "x$pname" ; then              if test "x$p" = "x$pname" ; then
# Line 557  while test "x$ck" != xtt ; do Line 1000  while test "x$ck" != xtt ; do
1000          done          done
1001    
1002          #  Is the DNAME entry a (+) or (-) rule ?          #  Is the DNAME entry a (+) or (-) rule ?
1003            tmp="dname=\"\$DNAME_$i\""
1004            eval $tmp
1005          plus="-"          plus="-"
1006          echo "${DNAME[$i]}" | grep '^+' > /dev/null 2>&1          echo $dname | grep '^+' > /dev/null 2>&1
1007          RETVAL=$?          RETVAL=$?
1008          if test "x$RETVAL" = x0 ; then          if test "x$RETVAL" = x0 ; then
1009              plus="+"              plus="+"
1010          fi          fi
1011    
1012          #  Is $dname in the current $PACKAGES list?          #  Is $dname in the current $PACKAGES list?
1013          dname=`echo ${DNAME[$i]} | sed -e 's/^[+-]//'`          dname=`echo $dname | sed -e 's/^[+-]//'`
1014          din="f"          din="f"
1015          for p in $PACKAGES ; do          for p in $PACKAGES ; do
1016              if test "x$p" = "x$dname" ; then              if test "x$p" = "x$dname" ; then
# Line 609  for i in $PACKAGES ; do Line 1054  for i in $PACKAGES ; do
1054      if test -d $adr ; then      if test -d $adr ; then
1055          SOURCEDIRS="$SOURCEDIRS $adr"          SOURCEDIRS="$SOURCEDIRS $adr"
1056          INCLUDEDIRS="$INCLUDEDIRS $adr"          INCLUDEDIRS="$INCLUDEDIRS $adr"
1057            if test "x$i" = xautodiff ; then
1058                AUTODIFF_PKG_USED=t
1059            fi
1060      else      else
1061          echo "Error: the directory \"$adr\" for package $i doesn't exist"          echo "Error: the directory \"$adr\" for package $i doesn't exist"
1062          exit 1          exit 1
1063      fi      fi
1064  done  done
1065    
 #  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  
1066    
1067  echo "  Setting package-specific CPP flags in CPP_OPTIONS.h:"  # Create a list of #define and #undef to enable/disable packages
1068  CPP_OPTIONS=  PACKAGES_DOT_H=PACKAGES_CONFIG.h
1069  spaths=". $SOURCEDIRS"  cat <<EOF >$PACKAGES_DOT_H".tmp"
 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  
1070  C=== GENMAKE v2 ===  C=== GENMAKE v2 ===
1071  C  The following defines have been set by GENMAKE, so please edit  C  The following defines have been set by GENMAKE, so please do not
1072  C  them only if you know what you're doing.  In general, you should  C  edit anything below these comments.  In general, you should
1073  C  add or remove packages by re-running genmake with different  C  add or remove packages by re-running genmake with different
1074  C  "-enable" and/or "-disable" options.  C  "-enable" and/or "-disable" options.
1075    
1076    #ifndef PACKAGES_H
1077    #define PACKAGES_H
1078    
1079  C  Packages disabled by genmake:  C  Packages disabled by genmake:
1080  EOF  EOF
1081  #  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
# Line 686  for n in $names ; do Line 1094  for n in $names ; do
1094              fi              fi
1095          done          done
1096          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
1097              undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`
1098              echo "#undef $undef" >> CPP_OPTIONS.h.tmp              echo "#undef $undef" >> $PACKAGES_DOT_H".tmp"
   
 #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!!!  
   
1099          fi          fi
1100      fi      fi
1101  done  done
1102  cat <<EOF >>CPP_OPTIONS.h.tmp  cat <<EOF >>$PACKAGES_DOT_H".tmp"
1103    
1104  C  Packages enabled by genmake:  C  Packages enabled by genmake:
1105  EOF  EOF
1106  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1107      def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`      def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`
1108      echo "#define $def" >> CPP_OPTIONS.h.tmp      echo "#define $def" >> $PACKAGES_DOT_H".tmp"
1109    #eh3 DEFINES="$DEFINES -D$def"
1110    
1111  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1112      case $i in      case $i in
1113          aim_v23)          aim_v23)
1114              echo "#define   ALLOW_AIM" >> CPP_OPTIONS.h.tmp              echo "#define   ALLOW_AIM" >> $PACKAGES_DOT_H".tmp"
1115                DEFINES="$DEFINES -DALLOW_AIM"
1116                echo "Warning: ALLOW_AIM is set to enable aim_v23. This is REALLY ugly Jean-Michel :-)"
1117              ;;              ;;
1118      esac      esac
1119  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1120    
1121  done  done
1122  mv -f CPP_OPTIONS.h.tmp CPP_OPTIONS.h  cat <<EOF >>$PACKAGES_DOT_H".tmp"
1123    
1124    #endif /* PACKAGES_H */
1125    EOF
1126    
1127    if test ! -f $PACKAGES_DOT_H ; then
1128        mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
1129    else
1130        cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
1131        RETVAL=$?
1132        if test "x$RETVAL" = x0 ; then
1133            rm -f $PACKAGES_DOT_H".tmp"
1134        else
1135            mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
1136            mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
1137        fi
1138    fi
1139    
1140  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS"
1141  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
1142  STANDARDDIRS=${STANDARDDIRS:-"eesupp model"}  if test "x$STANDARDDIRS" = x ; then
1143        STANDARDDIRS="eesupp model"
1144    fi
1145  for d in $STANDARDDIRS ; do  for d in $STANDARDDIRS ; do
1146      adr="$ROOTDIR/$d/src"      adr="$ROOTDIR/$d/src"
1147      if test ! -d $adr ; then      if test ! -d $adr ; then
# Line 750  for d in $STANDARDDIRS ; do Line 1161  for d in $STANDARDDIRS ; do
1161      fi      fi
1162  done  done
1163    
1164    echo "  Searching for CPP_OPTIONS.h in order to warn about the presence"
1165    echo "    of \"#define ALLOW_PKGNAME\"-type statements:"
1166    CPP_OPTIONS=
1167    spaths=". $INCLUDEDIRS"
1168    for i in $spaths ; do
1169        try="$i/CPP_OPTIONS.h"
1170        #  echo -n "    trying $try : "
1171        if test -f $try -a -r $try ; then
1172            echo "    found CPP_OPTIONS=\"$try\""
1173            CPP_OPTIONS="$try"
1174            break
1175        fi
1176    done
1177    if test "x$CPP_OPTIONS" = x ; then
1178        echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
1179        exit 1
1180    fi
1181    # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
1182    names=`ls -1 "$ROOTDIR/pkg"`
1183    for n in $names ; do
1184        test_for_package_in_cpp_options $CPP_OPTIONS $n
1185    done
1186    
1187    
1188  echo $'\n'"===  Creating the Makefile  ==="  #  Here, we build the list of files to be "run through" the adjoint
1189    #  compiler.
1190    if test -f ./ad_files ; then
1191        rm -f ./ad_files
1192    fi
1193    echo "  Creating the list of files for the adjoint compiler."
1194    for i in $SOURCEDIRS ; do
1195        list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
1196        for j in $list_files ; do
1197            cat $i/$j >> ad_files
1198        done
1199    done
1200    
1201    cat <<EOF > adjoint_sed
1202    s/call adopen(/call adopen ( mythid,\\
1203         \&           /g
1204    s/call adclose(/call adclose( mythid,\\
1205         \&           /g
1206    s/call adread(/call adread ( mythid,\\
1207         \&           /g
1208    s/call adwrite(/call adwrite( mythid,\\
1209         \&           /g
1210    
1211    EOF
1212    
1213    echo
1214    echo "===  Creating the Makefile  ==="
1215  echo "  setting INCLUDES"  echo "  setting INCLUDES"
1216  for i in $INCLUDEDIRS ; do  for i in $INCLUDEDIRS ; do
1217      if test -d $i ; then      if ! test -d $i ; then
1218          INCLUDES="$INCLUDES -I$i"  #       INCLUDES="$INCLUDES -I$i"
1219      else  #   else
1220          echo "Warning: can't find INCLUDEDIRS=\"$i\""          echo "Warning: can't find INCLUDEDIRS=\"$i\""
1221      fi      fi
1222  done  done
# Line 766  rm -rf .links.tmp Line 1226  rm -rf .links.tmp
1226  mkdir .links.tmp  mkdir .links.tmp
1227  echo "# This section creates symbolic links" > srclinks.tmp  echo "# This section creates symbolic links" > srclinks.tmp
1228  echo "" >> srclinks.tmp  echo "" >> srclinks.tmp
1229  echo -n 'SRCFILES = ' > srclist.inc  echo -n 'SRCFILES = '    > srclist.inc
1230  echo -n 'CSRCFILES = ' > csrclist.inc  echo -n 'CSRCFILES = '   > csrclist.inc
1231    echo -n 'F90SRCFILES = ' > f90srclist.inc
1232  echo -n 'HEADERFILES = ' > hlist.inc  echo -n 'HEADERFILES = ' > hlist.inc
1233  alldirs=". $SOURCEDIRS $INCLUDEDIRS"  echo -n 'AD_FLOW_FILES = ' > ad_flow_files.inc
1234    alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1235  for d in $alldirs ; do  for d in $alldirs ; do
1236      deplist=      deplist=
1237      sfiles=`( cd $d; echo *.[h,c,F] )`      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
1238        sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
1239      for sf in $sfiles ; do      for sf in $sfiles ; do
1240          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
1241              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
1242                  extn=`echo $sf | awk -F '.' '{print $NF}'`                  extn=`echo $sf | $AWK -F '.' '{print $NF}'`
1243                  touch .links.tmp/$sf                  touch .links.tmp/$sf
1244                  deplist="$deplist $sf"                  deplist="$deplist $sf"
1245                  case $extn in                  case $extn in
# Line 784  for d in $alldirs ; do Line 1247  for d in $alldirs ; do
1247                          echo    " \\"  >> srclist.inc                          echo    " \\"  >> srclist.inc
1248                          echo -n " $sf" >> srclist.inc                          echo -n " $sf" >> srclist.inc
1249                          ;;                          ;;
1250                        F90)
1251                            echo    " \\"  >> f90srclist.inc
1252                            echo -n " $sf" >> f90srclist.inc
1253                            ;;
1254                      c)                      c)
1255                          echo    " \\"  >> csrclist.inc                          echo    " \\"  >> csrclist.inc
1256                          echo -n " $sf" >> csrclist.inc                          echo -n " $sf" >> csrclist.inc
# Line 792  for d in $alldirs ; do Line 1259  for d in $alldirs ; do
1259                          echo    " \\"  >> hlist.inc                          echo    " \\"  >> hlist.inc
1260                          echo -n " $sf" >> hlist.inc                          echo -n " $sf" >> hlist.inc
1261                          ;;                          ;;
1262                        flow)
1263                            echo    " \\"  >> ad_flow_files.inc
1264                            echo -n " $sf" >> ad_flow_files.inc
1265                            ;;
1266                  esac                  esac
1267              fi              fi
1268          fi          fi
1269      done      done
1270      if test "x$deplist" != x ; then      if test "x$deplist" != x ; then
1271          echo $'\n'"#  These files are linked from $d" >> srclinks.tmp          echo "" >> srclinks.tmp
1272            echo "#  These files are linked from $d" >> srclinks.tmp
1273          echo "$deplist :" >> srclinks.tmp          echo "$deplist :" >> srclinks.tmp
1274          echo $'\t$(LN) '$d'/$@ $@' >> srclinks.tmp          printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp
1275      fi      fi
1276  done  done
1277  rm -rf .links.tmp  rm -rf .links.tmp
1278  echo "" >> srclist.inc  echo "" >> srclist.inc
1279  echo "" >> csrclist.inc  echo "" >> csrclist.inc
1280    echo "" >> f90srclist.inc
1281  echo "" >> hlist.inc  echo "" >> hlist.inc
1282    echo "" >> ad_flow_files.inc
1283    
1284  if test -e $MAKEFILE ; then  if test -e $MAKEFILE ; then
1285      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.bak"
# Line 819  echo "# by the command:" >> $MAKEFILE Line 1293  echo "# by the command:" >> $MAKEFILE
1293  echo "#    $0 $@" >> $MAKEFILE  echo "#    $0 $@" >> $MAKEFILE
1294  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
1295  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE
1296    
1297    EXE_AD=$EXECUTABLE"_ad"
1298    EXE_FTL=$EXECUTABLE"_ftl"
1299    EXE_SVD=$EXECUTABLE"_svd"
1300    
1301  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
1302  #  #
1303  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
# Line 847  EXEDIR      = ${EXEDIR} Line 1326  EXEDIR      = ${EXEDIR}
1326  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}
1327  TOOLSDIR    = ${TOOLSDIR}  TOOLSDIR    = ${TOOLSDIR}
1328    
1329    #eh3  new defines for the adjoint work
1330    AUTODIFF    = ${ROOTDIR}/pkg/autodiff
1331    EXE_AD      = ${EXE_AD}
1332    EXE_FTL     = ${EXE_FTL}
1333    EXE_SVD     = ${EXE_SVD}
1334    
1335  EOF  EOF
1336    
1337  #  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 1347  MAKEDEPEND = ${MAKEDEPEND}
1347  KPP = ${KPP}  KPP = ${KPP}
1348  # Fortran compiler  # Fortran compiler
1349  FC = ${FC}  FC = ${FC}
1350    # Fortran compiler
1351    F90C = ${F90C}
1352  # Link editor  # Link editor
1353  LINK = ${LINK}  LINK = ${LINK}
1354    
# Line 875  KFLAGS2 = ${KFLAGS2} Line 1362  KFLAGS2 = ${KFLAGS2}
1362  # Optim./debug for FC  # Optim./debug for FC
1363  FFLAGS = ${FFLAGS}  FFLAGS = ${FFLAGS}
1364  FOPTIM = ${FOPTIM}  FOPTIM = ${FOPTIM}
1365    # Optim./debug for FC
1366    F90FLAGS = ${F90FLAGS}
1367    F90OPTIM = ${F90OPTIM}
1368  # Flags for CC  # Flags for CC
1369  CFLAGS = ${CFLAGS}  CFLAGS = ${CFLAGS}
1370  # Files that should not be optimized  # Files that should not be optimized
# Line 882  NOOPTFILES = ${NOOPTFILES} Line 1372  NOOPTFILES = ${NOOPTFILES}
1372  NOOPTFLAGS = ${NOOPTFLAGS}  NOOPTFLAGS = ${NOOPTFLAGS}
1373  # Flags and libraries needed for linking  # Flags and libraries needed for linking
1374  LIBS = ${LIBS} \$(XLIBS)  LIBS = ${LIBS} \$(XLIBS)
1375    # Name of the Mekfile
1376    MAKEFILE=${MAKEFILE}
1377    
1378  EOF  EOF
1379    
1380  cat srclist.inc  >> $MAKEFILE  cat srclist.inc       >> $MAKEFILE
1381  cat csrclist.inc >> $MAKEFILE  cat csrclist.inc      >> $MAKEFILE
1382  cat hlist.inc >> $MAKEFILE  cat f90srclist.inc    >> $MAKEFILE
1383  echo 'F77FILES =  $(SRCFILES:.F=.f)'                    >> $MAKEFILE  cat hlist.inc         >> $MAKEFILE
1384  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o)' >> $MAKEFILE  cat ad_flow_files.inc >> $MAKEFILE
1385    echo               >> $MAKEFILE
1386    echo 'F77FILES =  $(SRCFILES:.F=.f)'                                           >> $MAKEFILE
1387    echo 'F90FILES =  $(F90SRCFILES:.F90=.f90)'                                    >> $MAKEFILE
1388    echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
1389    
1390  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
1391    rm -f ad_flow_files.inc
1392    
1393  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
1394    
1395  .SUFFIXES:  .SUFFIXES:
1396  .SUFFIXES: .o .f .p .F .c  .SUFFIXES: .o .f .p .F .c .F90 .f90
1397    
1398  all: \$(EXECUTABLE)  all: \$(EXECUTABLE)
1399  \$(EXECUTABLE): \$(OBJFILES)  \$(EXECUTABLE): \$(OBJFILES)
# Line 904  all: \$(EXECUTABLE) Line 1401  all: \$(EXECUTABLE)
1401  depend:  depend:
1402          @make links          @make links
1403          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
1404            ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE)
1405    
1406  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES)  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)
1407    
1408  small_f: \$(F77FILES)  small_f: \$(F77FILES) \$(F90FILES)
1409    
1410  output.txt: \$(EXECUTABLE)  output.txt: \$(EXECUTABLE)
1411          @printf 'running ... '          @printf 'running ... '
1412          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
1413    
1414  clean:  clean:
1415          -rm -rf *.o *.f *.p ${RMFILES} work.{pc,pcl}          -cat AD_CONFIG.template > AD_CONFIG.h
1416            -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}
1417  Clean:  Clean:
1418          @make clean          @make clean
1419          @make cleanlinks          @make cleanlinks
1420          -rm -f Makefile.bak          -rm -f Makefile.bak genmake_state genmake_*optfile make.log
1421  CLEAN:  CLEAN:
1422          @make Clean          @make Clean
1423          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
1424          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
1425          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
1426          -rm -f \$(EXECUTABLE)          -rm -f \$(EXECUTABLE) output.txt
1427    
1428    #eh3 Makefile: makefile
1429  makefile:  makefile:
1430          ${0} $@          ${0} $@
1431  cleanlinks:  cleanlinks:
# Line 936  cleanlinks: Line 1436  cleanlinks:
1436          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1437  .f.o:  .f.o:
1438          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
1439    .F90.f90:
1440            \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1441    .f90.o:
1442            \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
1443  .c.o:  .c.o:
1444          \$(CC) \$(CFLAGS) -c \$<          \$(CC) \$(CFLAGS) -c \$<
1445    
# Line 945  cleanlinks: Line 1449  cleanlinks:
1449  .p.f:  .p.f:
1450          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
1451    
1452    #=========================================
1453    #===  Automatic Differentiation Rules  ===
1454    
1455    TAMC           = ${TAMC}
1456    TAF            = ${TAF}
1457    
1458    TAF_EXTRA      = ${TAF_EXTRA}
1459    TAMC_EXTRA     = ${TAMC_EXTRA}
1460    
1461    EOF
1462    
1463    ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
1464    ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF_FLAGS"
1465    ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
1466    for i in $ad_vars ; do
1467        name=$i
1468        t1="t2=\$"`echo $i`
1469        eval $t1
1470        printf "%-20s = " $name >> $MAKEFILE
1471        echo $t2 >> $MAKEFILE
1472    done
1473    
1474    echo "  Add the source list for AD code generation"
1475    echo >> $MAKEFILE
1476    echo -n "AD_FILES = " >> $MAKEFILE
1477    AD_FILES=`cat ad_files`
1478    for i in $AD_FILES ; do
1479        echo    " \\" >> $MAKEFILE
1480        echo -n " $i" >> $MAKEFILE
1481    done
1482    echo >> $MAKEFILE
1483    rm -f ad_files
1484    
1485    cat >>$MAKEFILE <<EOF
1486    
1487    # ... AD ...
1488    adall: ad_taf
1489    adtaf: ad_taf_output.f
1490    adtamc: ad_tamc_output.f
1491    
1492    ad_input_code.f: \$(AD_FILES) \$(HEADERFILES)
1493            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
1494            @make \$(F77FILES)
1495            @make \$(AD_FLOW_FILES)
1496            cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f
1497    
1498    ad_taf_output.f: ad_input_code.f
1499            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1500            cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f
1501    
1502    adtafonly:
1503            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1504            cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f
1505    
1506    ad_taf: ad_taf_output.o \$(OBJFILES)
1507            \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
1508    
1509    ad_tamc_output.f: ad_input_code.f
1510            \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f
1511            cat ad_input_code_ad.f | sed -f adjoint_sed > ad_tamc_output.f
1512    
1513    ad_tamc: ad_tamc_output.o \$(OBJFILES)
1514            \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
1515    
1516    
1517    # ... FTL ...
1518    ftlall: ftl_taf
1519    ftltaf: ftl_taf_output.f
1520    ftltamc: ftl_tamc_output.f
1521    
1522    ftl_input_code.f: \$(AD_FILES) \$(HEADERFILES)
1523            cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
1524            @make \$(F77FILES)
1525            @make \$(AD_FLOW_FILES)
1526            cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f
1527    
1528    ftl_taf_output.f: ftl_input_code.f
1529            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f
1530            cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_taf_output.f
1531    
1532    ftl_taf: ftl_taf_output.o \$(OBJFILES)
1533            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
1534    
1535    ftl_tamc_output.f: ftl_input_code.f
1536            \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f
1537            cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_tamc_output.f
1538    
1539    ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
1540            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
1541    
1542    
1543    # ... SVD ...
1544    svd: svd_taf
1545    svd_taf_f: svd_taf_output.f
1546    
1547    svd_input_code.f: \$(SRCFILES)
1548            cmp svd_config.template AD_CONFIG.h || cat svd_config.template > AD_CONFIG.h
1549            @make \$(F77FILES)
1550            @make \$(AD_FLOW_FILES)
1551            cat \$(AD_FLOW_FILES) \$(AD_FILES) > svd_input_code.f
1552    
1553    svd_taf_output.f: svd_input_code.f
1554            \$(TAF) \$(SVD_TAF_FLAGS) \$(TAF_EXTRA) svd_input_code.f
1555            cat svd_input_code_ad.f | sed -f adjoint_sed > svd_taf_output.f
1556    
1557    svd_taf: svd_taf_output.o \$(OBJFILES)
1558            \$(LINK) -o ${EXE_SVD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) svd_taf_output.o \$(LIBS)
1559    
1560    
1561    #=========================================
1562    
1563  EOF  EOF
1564    
1565    if test "x$EXEHOOK" != x ; then
1566        printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
1567    fi
1568    
1569  echo "  Making list of \"exceptions\" that need \".p\" files"  echo "  Making list of \"exceptions\" that need \".p\" files"
1570  for i in $KPPFILES ; do  for i in $KPPFILES ; do
1571      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 1584  for i in $NOOPTFILES ; do
1584          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
1585      fi      fi
1586      echo "$base.o: $base.f" >> $MAKEFILE      echo "$base.o: $base.f" >> $MAKEFILE
1587      echo $'\t$(FC) $(FFLAGS) $(NOOPTFLAGS) -c $<' >> $MAKEFILE      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
1588  done  done
1589    
1590  echo "  Add rules for links"  echo "  Add rules for links"
# Line 973  cat srclinks.tmp >> $MAKEFILE Line 1592  cat srclinks.tmp >> $MAKEFILE
1592  rm -f srclinks.tmp  rm -f srclinks.tmp
1593    
1594  echo "  Adding makedepend marker"  echo "  Adding makedepend marker"
1595  echo $'\n\n'"# DO NOT DELETE" >> $MAKEFILE  printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
1596    
1597    printf "\n===  Done  ===\n"
1598    
1599  echo $'\n'"===  Done  ==="  #  Write the "template" files for the adjoint builds
1600    cat >AD_CONFIG.template <<EOF
1601    C  WARNING: This file is automatically generated by genmake2 and
1602    C    used by the Makefile rules.  Please DO NOT EDIT this file
1603    C    unless you are CERTAIN that you know what you are doing.
1604    
1605    #undef ALLOW_ADJOINT_RUN
1606    #undef ALLOW_TANGENTLINEAR_RUN
1607    #undef ALLOW_ECCO_OPTIMIZATION
1608    EOF
1609    cat >ad_config.template <<EOF
1610    C  WARNING: This file is automatically generated by genmake2 and
1611    C    used by the Makefile rules.  Please DO NOT EDIT this file
1612    C    unless you are CERTAIN that you know what you are doing.
1613    
1614    #define ALLOW_ADJOINT_RUN
1615    #undef ALLOW_TANGENTLINEAR_RUN
1616    #undef ALLOW_ECCO_OPTIMIZATION
1617    EOF
1618    cat >ftl_config.template <<EOF
1619    C  WARNING: This file is automatically generated by genmake2 and
1620    C    used by the Makefile rules.  Please DO NOT EDIT this file
1621    C    unless you are CERTAIN that you know what you are doing.
1622    
1623    #undef ALLOW_ADJOINT_RUN
1624    #define ALLOW_TANGENTLINEAR_RUN
1625    #undef ALLOW_ECCO_OPTIMIZATION
1626    EOF
1627    cat >svd_config.template <<EOF
1628    C  WARNING: This file is automatically generated by genmake2 and
1629    C    used by the Makefile rules.  Please DO NOT EDIT this file
1630    C    unless you are CERTAIN that you know what you are doing.
1631    
1632    #undef ALLOW_ADJOINT_RUN
1633    #undef ALLOW_TANGENTLINEAR_RUN
1634    #undef ALLOW_ECCO_OPTIMIZATION
1635    EOF
1636    cp AD_CONFIG.template AD_CONFIG.h
1637    
1638    
1639    #  Write the "state" for future records
1640    if test "x$DUMPSTATE" != xf ; then
1641        echo -n "" > genmake_state
1642        for i in $gm_state ; do
1643            t1="t2=\$$i"
1644            eval $t1
1645            echo "$i='$t2'" >> genmake_state
1646        done
1647    fi

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

  ViewVC Help
Powered by ViewVC 1.1.22