/[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.6 by edhill, Fri Sep 5 00:25:42 2003 UTC revision 1.39 by edhill, Fri Nov 14 19:01:36 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    
139    Error: No Fortran compilers were found in your path.  Please specify one using:
140    
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    
145    EOF
146            exit 1
147      else      else
148          echo "  "$p_FC          echo "  The possible FORTRAN compilers found in your path are:"
149            echo "   "$p_FC
150            if test "x$FC" = x ; then
151                FC=`echo $p_FC | $AWK '{print $1}'`
152            fi
153      fi      fi
154    
155      # look for possible MPI libraries      for i in $p_FC ; do
156      mpi_libs=          p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
157      mpi_fort=`which mpif77 2>/dev/null`          if test -r $p_OF ; then
158      RETVAL=$?              OPTFILE=$p_OF
159      if test "x${RETVAL}" = x0 ; then              echo "  The options file:  $p_OF"
160          cat >>test.f <<EOF              echo "    appears to match so we'll use it."
161        PROGRAM HELLO              break
       DO 10, I=1,10  
       PRINT *,'Hello World'  
    10 CONTINUE  
       STOP  
       END  
 EOF  
         eval "$mpi_fort -showme test.f > out"  
         RETVAL=$?  
         if test "x${RETVAL}" = x0 ; then  
             a=`cat out`  
             for i in $a ; do  
                 case $i in  
                     -*)  
                         mpi_libs="$mpi_libs $i" ;;  
                 esac  
             done  
             echo "The MPI libs appear to be:"  
             echo "  "$mpi_libs  
162          fi          fi
163          rm -f test.f out      done
164        if test "x$OPTFILE" = x ; then
165            cat 1>&2 <<EOF
166    
167    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        1) the command line (eg. "-optfile=path/to/OPTFILE"), or
172        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      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    
209  }  }
210    
# Line 86  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 123  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 144  usage()  { Line 274  usage()  {
274      exit 1      exit 1
275  }  }
276    
277  #eh3 # This is the generic configuration.  #  Build a CPP macro to automate calling C routines from FORTRAN
278  #eh3 set LN         = ( 'ln -s' )  get_fortran_c_namemangling()  {
279  #eh3 set CPP        = ( '/lib/cpp -P' )      default_nm="#define FC_NAMEMANGLE(X) X ## _"
280  #eh3 set S64        = ( '$(TOOLSDIR)/set64bitConst.sh' )      
281  #eh3 set KPP        = (  )      cat > genmake_test.c <<EOF
282  #eh3 set FC         = ( 'f77' )  void tcall( char * string ) { tsub( string ); }
283  #eh3 set LINK       = $FC  EOF
284  #eh3 set MAKEDEPEND = ( 'makedepend' )      $MAKE genmake_test.o >> genmake_warnings 2>&1
285  #eh3 set INCLUDES   = ( -I. )      RETVAL=$?
286  #eh3 set FFLAGS     = (  )      if test "x$RETVAL" != x0 ; then
287  #eh3 set FOPTIM     = (  )          FC_NAMEMANGLE=$default_nm
288  #eh3 set CFLAGS     = (  )          cat <<EOF>> genmake_errors
289  #eh3 set KFLAGS1    = (  )  
290  #eh3 set KFLAGS2    = (  )  WARNING: C test compile fails
291  #eh3 set LIBS       = (  )  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
292  #eh3 set KPPFILES   = (  )  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
293  #eh3 if (! $?NOOPTFILES ) set NOOPTFILES = (  )  EOF
294  #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = (  )          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            cat <<EOF>> genmake_warnings
301    
302    WARNING: The "nm" command failed.
303    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
304    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
305    EOF
306            return 1
307        fi
308        cat > genmake_tcomp.f <<EOF
309          subroutine tcall( string )
310          character*(*) string
311          call tsub( string )
312          end
313    EOF
314        $FC $FFLAGS $DEFINES -c genmake_tcomp.f >> genmake_warnings 2>&1
315        RETVAL=$?
316        if test "x$RETVAL" != x0 ; then
317            FC_NAMEMANGLE=$default_nm
318            cat <<EOF>> genmake_warnings
319    
320    WARNING: FORTRAN test compile fails -- please see "genmake_errors"
321    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
322    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
323    EOF
324            return 1
325        fi
326        f_tcall=`nm genmake_tcomp.o | grep tcall | cut -d ' ' -f 3`
327        RETVAL=$?
328        if test "x$RETVAL" != x0 ; then
329            FC_NAMEMANGLE=$default_nm
330            cat <<EOF>> genmake_warnings
331    
332    WARNING: The "nm" command failed.
333    WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
334    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
335    EOF
336            return 1
337        fi
338    
339        c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
340        f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
341        c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
342        f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
343    
344        nmangle="X"
345        if test "x$c_a" != "x$f_a" ; then
346            comm="echo x$f_a | sed -e 's|x$c_a||'"
347            a=`eval $comm`
348            nmangle="$a ## $nmangle"
349        fi
350        if test "x$c_b" != "x$f_b" ; then
351            comm="echo x$f_b | sed -e 's|x$c_b||'"
352            b=`eval $comm`
353            nmangle="$nmangle ## $b"
354        fi
355    
356        FC_NAMEMANGLE="#define FC_NAMEMANGLE(X)  $nmangle"
357    
358        #  cleanup the testing files
359        rm -f genmake_tcomp.* genmake_test.*
360    }
361    
362    
363    check_HAVE_CLOC()  {
364        get_fortran_c_namemangling
365        cat <<EOF > genmake_tc_1.c
366    $FC_NAMEMANGLE
367    #include <stdio.h>
368    #include <stdlib.h>
369    #include <unistd.h>
370    #include <assert.h>
371    #include <sys/time.h>
372    void FC_NAMEMANGLE(cloc) ( double *curtim )
373    {
374     struct timeval tv1;
375     gettimeofday(&tv1 , (void *)NULL );
376     *curtim =  (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
377     *curtim = *curtim/1.E6;
378    }
379    EOF
380        make genmake_tc_1.o >> genmake_tc.log 2>&1
381        RET_C=$?
382        cat <<EOF > genmake_tc_2.f
383          program hello
384          Real*8 wtime
385          external cloc
386          call cloc(wtime)
387          print *," HELLO WORLD", wtime
388          end program hello
389    EOF
390        $FC $FFLAGS -o genmake_tc genmake_tc_2.f genmake_tc_1.o >> genmake_tc.log 2>&1
391        RET_F=$?
392        test -x ./genmake_tc  &&  ./genmake_tc >> genmake_tc.log 2>&1
393        RETVAL=$?
394        if test "x$RETVAL" = x0 ; then
395            HAVE_CLOC=t
396            DEFINES="$DEFINES -DHAVE_CLOC"
397        fi
398        rm -f genmake_tc*
399    }
400    
401    
402  #  Set defaults here  #  Set defaults here
403  COMMANDL="$0 $@"  COMMANDL="$0 $@"
# Line 172  S64= Line 408  S64=
408  KPP=  KPP=
409  FC=  FC=
410  LINK=  LINK=
411    # DEFINES="-DWORDLENGTH=4"
412    DEFINES=
413  PACKAGES=  PACKAGES=
414  ENABLE=  ENABLE=
415  DISABLE=  DISABLE=
416  MAKEFILE=  MAKEFILE=
417  MAKEDEPEND=  MAKEDEPEND=
418  PDEPEND=  PDEPEND=
419  DUMPSTATE=f  DUMPSTATE=t
420  PDEFAULT=  PDEFAULT=
421  OPTFILE=  OPTFILE=
422  INCLUDES="-I."  INCLUDES="-I."
# Line 192  KPPFILES= Line 430  KPPFILES=
430  NOOPTFILES=  NOOPTFILES=
431  NOOPTFLAGS=  NOOPTFLAGS=
432    
433    # DEFINES checked by test compilation
434    HAVE_SYSTEM=
435    HAVE_FDATE=
436    FC_NAMEMANGLE=
437    HAVE_CLOC=
438    
439  MODS=  MODS=
440  TOOLSDIR=  TOOLSDIR=
441  SOURCEDIRS=  SOURCEDIRS=
442  INCLUDEDIRS=  INCLUDEDIRS=
443    STANDARDDIRS=
444    
445  PWD=`pwd`  PWD=`pwd`
446  MAKE=make  MAKE=make
447    AWK=awk
448  THISHOSTNAME=`hostname`  THISHOSTNAME=`hostname`
449  THISCWD=`pwd`  THISCWD=`pwd`
450  THISDATE=`date`  THISDATE=`date`
451  MACHINE=`uname -a`  MACHINE=`uname -a`
452    EXECUTABLE=
453    EXEHOOK=
454    EXEDIR=
455    PACKAGES_CONF=
456    IEEE=
457    if test "x$MITGCM_IEEE" != x ; then
458        IEEE=$MITGCM_IEEE
459    fi
460    
461    AUTODIFF_PKG_USED=f
462    AD_OPTFILE=
463    TAF=
464    AD_TAF_FLAGS=
465    FTL_TAF_FLAGS=
466    SVD_TAF_FLAGS=
467    TAF_EXTRA=
468    TAMC=
469    AD_TAMC_FLAGS=
470    FTL_TAF_FLAGS=
471    SVD_TAMC_FLAGS=
472    TAMC_EXTRA=
473    
474    
475  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
476  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"
477  gm_s2="FC IEEE MPI JAM DUMPSTATE"  gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS"
478    
479  #  The following state is not directly set by command-line switches  #  The following state is not directly set by command-line switches
480  gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "  gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
481  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
482  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"
483    gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
484    gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE"
485    
486  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5"  #  The following are all related to adjoint/tangent-linear stuff
487    gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
488    gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
489    gm_s12="TAF_EXTRA TAMC_EXTRA"
490    
491    gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"
492    gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
493    
494    
495  echo  echo
496  echo "===  Processing options files and arguments  ==="  echo "===  Processing options files and arguments  ==="
497  gm_local="./gm_local"  gm_local="genmake_local"
498    for i in . $MODS ; do
499        if test -r $i/$gm_local ; then
500            . $i/$gm_local
501            break
502        fi
503    done
504  echo -n "  getting local config information:  "  echo -n "  getting local config information:  "
505  if test -e $gm_local ; then  if test -e $gm_local ; then
506      echo "using $gm_local"      echo "using $gm_local"
507      source $gm_local      . $gm_local
508      # echo "DISABLE=$DISABLE"      # echo "DISABLE=$DISABLE"
509      # echo "ENABLE=$ENABLE"      # echo "ENABLE=$ENABLE"
510  else  else
# Line 240  fi Line 522  fi
522  #   n=$(( $n + 1 ))  #   n=$(( $n + 1 ))
523  #done  #done
524  #parse_options  #parse_options
   
525  ac_prev=  ac_prev=
526  for ac_option ; do  for ac_option ; do
527    
# Line 265  for ac_option ; do Line 546  for ac_option ; do
546          -optfile=* | --optfile=* | -of=* | --of=*)          -optfile=* | --optfile=* | -of=* | --of=*)
547              OPTFILE=$ac_optarg ;;              OPTFILE=$ac_optarg ;;
548                    
549            -adoptfile | --adoptfile | -ad | --ad)
550                ac_prev=AD_OPTFILE ;;
551            -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
552                AD_OPTFILE=$ac_optarg ;;
553            
554          -pdepend | --pdepend)          -pdepend | --pdepend)
555              ac_prev=PDEPEND ;;              ac_prev=PDEPEND ;;
556          -pdepend=* | --pdepend=*)          -pdepend=* | --pdepend=*)
# Line 310  for ac_option ; do Line 596  for ac_option ; do
596          -enable=* | --enable=*)          -enable=* | --enable=*)
597              ENABLE=$ac_optarg ;;              ENABLE=$ac_optarg ;;
598                    
599            -standarddirs | --standarddirs)
600                ac_prev=STANDARDDIRS ;;
601            -standarddirs=* | --standarddirs=*)
602                STANDARDDIRS=$ac_optarg ;;
603    
604          -noopt | --noopt)          -noopt | --noopt)
605              ac_prev=NOOPT ;;              ac_prev=NOOPT ;;
606          -noopt=* | --noopt=*)          -noopt=* | --noopt=*)
# Line 326  for ac_option ; do Line 617  for ac_option ; do
617              FC=$ac_optarg ;;              FC=$ac_optarg ;;
618                    
619          -ieee | --ieee)          -ieee | --ieee)
620              IEEE=1 ;;              IEEE=true ;;
621          -noieee | --noieee)          -noieee | --noieee)
622              IEEE=0 ;;              IEEE= ;;
623                    
624          -mpi | --mpi)          -mpi | --mpi)
625              MPI=1 ;;              MPI=true ;;
626          -nompi | --nompi)          -nompi | --nompi)
627              MPI=0 ;;              MPI= ;;
628                    
629          -jam | --jam)          -jam | --jam)
630              JAM=1 ;;              JAM=1 ;;
# Line 343  for ac_option ; do Line 634  for ac_option ; do
634          -ds | --ds)          -ds | --ds)
635              DUMPSTATE=t ;;              DUMPSTATE=t ;;
636                    
637            -taf_extra | --taf_extra)
638                ac_prev=TAF_EXTRA ;;
639            -taf_extra=* | --taf_extra=*)
640                TAF_EXTRA=$ac_optarg ;;
641    
642            -tamc_extra | --tamc_extra)
643                ac_prev=TAMC_EXTRA ;;
644            -tamc_extra=* | --tamc_extra=*)
645                TAMC_EXTRA=$ac_optarg ;;
646    
647          -*)          -*)
648              echo "Error: unrecognized option: "$ac_option              echo "Error: unrecognized option: "$ac_option
649              usage              usage
# Line 357  for ac_option ; do Line 658  for ac_option ; do
658            
659  done  done
660    
661    if test -f ./.genmakerc ; then
662        echo
663        echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
664        echo "  file.  This file format is no longer supported.  Please see:"
665        echo
666        echo "    http://mitgcm.org/devel_HOWTO/"
667        echo
668        echo "  for directions on how to setup and use the new \"genmake2\" input"
669        echo "  files and send an email to MITgcm-support@mitgcm.org if you want help."
670        echo
671    fi
672    
673    if test "x${ROOTDIR}" = x ; then
674        if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
675            ROOTDIR=".."
676        else
677            for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
678                if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
679                    ROOTDIR=$d
680                    echo -n "Warning:  ROOTDIR was not specified but there appears to be"
681                    echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
682                    break
683                fi
684            done
685        fi
686    fi
687    if test "x${ROOTDIR}" = x ; then
688        echo "Error: Cannot determine ROOTDIR for MITgcm code."
689        echo "  Please specify a ROOTDIR using either an options "
690        echo "  file or a command-line option."
691        exit 1
692    fi
693    if test ! -d ${ROOTDIR} ; then
694        echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
695        exit 1
696    fi
697    
698  echo "  getting OPTFILE information:  "  echo "  getting OPTFILE information:  "
699  if test "x${OPTFILE}" = x ; then  if test "x${OPTFILE}" = x ; then
700      echo "Warning: no OPTFILE specified so we'll look for possible settings"      if test "x$MITGCM_OF" = x ; then
701      printf "\n===  Searching for possible settings for OPTFILE  ===\n"          echo "Warning: no OPTFILE specified so we'll look for possible settings"
702      find_possible_configs          printf "\n===  Searching for possible settings for OPTFILE  ===\n"
703  else          find_possible_configs
     if test "x$OPTFILE" = xNONE ; then  
         echo "    OPTFILE=NONE so we'll try to use default settings"  
704      else      else
705          if test -f "$OPTFILE" -a -r "$OPTFILE" ; then          OPTFILE=$MITGCM_OF
706              echo "    using OPTFILE=\"$OPTFILE\""      fi
707              source "$OPTFILE"  fi
708              RETVAL=$?  if test "x$OPTFILE" != xNONE ; then
709              if test "x$RETVAL" != x0 ; then      if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
710                  echo -n "Error: failed to source OPTFILE \"$OPTFILE\""          echo "    using OPTFILE=\"$OPTFILE\""
711                  echo "--please check that variable syntax is bash-compatible"          . "$OPTFILE"
712                  exit 1          RETVAL=$?
713              fi          if test "x$RETVAL" != x0 ; then
714              if test "x$DUMPSTATE" != xf ; then              echo -n "Error: failed to source OPTFILE \"$OPTFILE\""
715                  cp -f $OPTFILE "gm_optfile"              echo "--please check that variable syntax is bash-compatible"
             fi  
         else  
             echo "Error: can't read OPTFILE=\"$OPTFILE\""  
716              exit 1              exit 1
717          fi          fi
718            if test "x$DUMPSTATE" != xf ; then
719                cp -f $OPTFILE "genmake_optfile"
720            fi
721        else
722            echo "Error: can't read OPTFILE=\"$OPTFILE\""
723            exit 1
724      fi      fi
725  fi  fi
726    
727    echo "  getting AD_OPTFILE information:  "
728    if test "x${AD_OPTFILE}" = x ; then
729        if test "x$MITGCM_AD_OF" = x ; then
730            AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
731        else
732            AD_OPTFILE=$MITGCM_AD_OF
733        fi
734    fi
735    if test "x${AD_OPTFILE}" != xNONE ; then
736        if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
737            echo "    using AD_OPTFILE=\"$AD_OPTFILE\""
738            . "$AD_OPTFILE"
739            RETVAL=$?
740            if test "x$RETVAL" != x0 ; then
741                echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
742                echo "--please check that variable syntax is bash-compatible"
743                exit 1
744            fi
745            if test "x$DUMPSTATE" != xf ; then
746                cp -f $AD_OPTFILE "genmake_ad_optfile"
747            fi
748        else
749            echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
750            exit 1
751        fi
752    fi
753    
754    #  Check that FC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
755    #  either set defaults or complain and abort!
756    if test "x$FC" = x ; then
757        cat <<EOF 1>&2
758    
759    Error: no Fortran compiler: please specify using one of the following:
760      1) within the options file ("FC=...") as specified by "-of=OPTFILE"
761      2) the "-fc=XXX" command-line option
762      3) the "./genmake_local" file
763    EOF
764        exit 1
765    fi
766    if test "x$LINK" = x ; then
767        LINK=$FC
768    fi
769    if test "x$CPP" = x ; then
770        CPP="cpp"
771    fi
772    if test "x$MAKE" = x ; then
773        MAKE="make"
774    fi
775    echo "#define A a" | $CPP > test_cpp 2>&1
776    RETVAL=$?
777    if test "x$RETVAL" != x0 ; then
778        cat <<EOF 1>&2
779    
780    Error: C pre-processor "$CPP" failed the test case: please specify using:
781    
782      1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
783      2) the "./genmake_local" file
784      3) with the CPP environment variable
785    
786    EOF
787        exit 1
788    else
789        rm -f test_cpp
790    fi
791    if test "x$MAKEDEPEND" = x ; then
792        MAKEDEPEND=makedepend
793    fi
794    if test "x$LN" = x ; then
795        LN="ln -s"
796    fi
797    echo "test" > genmake_test_ln
798    $LN genmake_test_ln genmake_tlink
799    RETVAL=$?
800    if test "x$RETVAL" != x0 ; then
801        cat <<EOF 1>&2
802    
803    Error: The command "ln -s" failed -- please specify a working soft-link
804      command in the optfile.
805    
806    EOF
807        exit 1
808    fi
809    rm -f genmake_test_ln genmake_tlink
810    
811    
812    printf "\n===  Checking system libraries  ===\n"
813    echo -n "  Do we have the system() command using $FC...  "
814    cat > genmake_tcomp.f <<EOF
815          program hello
816          call system('echo hi')
817          end
818    EOF
819    $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1
820    RETVAL=$?
821    if test "x$RETVAL" = x0 ; then
822        HAVE_SYSTEM=t
823        DEFINES="$DEFINES -DHAVE_SYSTEM"
824        echo "yes"
825    else
826        HAVE_SYSTEM=
827        echo "no"
828    fi
829    rm -f genmake_tcomp*
830    
831    echo -n "  Do we have the fdate() command using $FC...  "
832    cat > genmake_tcomp.f <<EOF
833          program hello
834          CHARACTER(128) string
835          string = ' '
836          call fdate( string )
837          print *, string
838          end
839    EOF
840    $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1
841    RETVAL=$?
842    if test "x$RETVAL" = x0 ; then
843        HAVE_FDATE=t
844        DEFINES="$DEFINES -DHAVE_FDATE"
845        echo "yes"
846    else
847        HAVE_FDATE=
848        echo "no"
849    fi
850    rm -f genmake_tcomp*
851    
852    echo -n "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
853    check_HAVE_CLOC
854    if test "x$HAVE_CLOC" != x ; then
855        echo "yes"
856    else
857        echo "no"
858    fi
859    echo "$FC_NAMEMANGLE" > FC_NAMEMANGLE.h.template
860    cmp FC_NAMEMANGLE.h FC_NAMEMANGLE.h.template > /dev/null 2>&1
861    RETVAL=$?
862    if test "x$RETVAL" != x0 ; then
863        mv -f FC_NAMEMANGLE.h.template FC_NAMEMANGLE.h
864    fi
865    rm -f genmake_t*
866    
867    
868  printf "\n===  Setting defaults  ===\n"  printf "\n===  Setting defaults  ===\n"
869  echo -n "  Adding MODS directories:  "  echo -n "  Adding MODS directories:  "
870  for d in $MODS ; do  for d in $MODS ; do
# Line 407  if test "x${PLATFORM}" = x ; then Line 887  if test "x${PLATFORM}" = x ; then
887      PLATFORM=$p_PLATFORM      PLATFORM=$p_PLATFORM
888  fi  fi
889    
 if test "x${ROOTDIR}" = x ; then  
     if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then  
         ROOTDIR=".."  
     else  
         for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do  
             if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then  
                 ROOTDIR=$d  
                 echo -n "Warning:  ROOTDIR was not specified but there appears to be"  
                 echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."  
                 break  
             fi  
         done  
     fi  
 fi  
 if test "x${ROOTDIR}" = x ; then  
     echo "Error: Cannot determine ROOTDIR for MITgcm code."  
     echo "  Please specify a ROOTDIR using either an options "  
     echo "  file or a command-line option."  
     exit 1  
 fi  
 if test ! -d ${ROOTDIR} ; then  
     echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"  
     exit 1  
 fi  
   
890  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
891      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then
892          EXEDIR=../exe          EXEDIR=../exe
# Line 451  if test ! -d ${TOOLSDIR} ; then Line 906  if test ! -d ${TOOLSDIR} ; then
906      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"
907      exit 1      exit 1
908  fi  fi
909    if test "x$S64" = x ; then
910        S64='$(TOOLSDIR)/set64bitConst.sh'
911    fi
912    
913  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
914    
# Line 459  EXECUTABLE=${EXECUTABLE:-mitgcmuv} Line 917  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
917  #  they appear as regular source code  #  they appear as regular source code
918  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
919      echo "  Making source files in eesupp from templates"      echo "  Making source files in eesupp from templates"
920      $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1      ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1
921      RETVAL=$?      RETVAL=$?
922      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
923          rm -f make_eesupp.errors          rm -f make_eesupp.errors
# Line 489  echo "  getting package dependency info Line 947  echo "  getting package dependency info
947  #  Strip the comments and then convert the dependency file into  #  Strip the comments and then convert the dependency file into
948  #  two arrays: PNAME, DNAME  #  two arrays: PNAME, DNAME
949  cat $PDEPEND | sed -e 's/#.*$//g' \  cat $PDEPEND | sed -e 's/#.*$//g' \
950      | awk 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \      | $AWK 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \
951      > ./.pd_tmp      > ./.pd_tmp
952  RETVAL=$?  RETVAL=$?
953  if test ! "x${RETVAL}" = x0 ; then  if test ! "x${RETVAL}" = x0 ; then
954      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
955      exit 1      exit 1
956  fi  fi
957  source ./.pd_tmp  . ./.pd_tmp
958  rm -f ./.pd_tmp  rm -f ./.pd_tmp
959    
960    #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"
961    #  file should eventually be added so that, for convenience, one can
962    #  specify groups of packages using names like "ocean" and "atmosphere".
963  echo  -n "  checking default package list:  "  echo  -n "  checking default package list:  "
964  if test "x${PDEFAULT}" = x ; then  if test "x${PDEFAULT}" = x ; then
965        for i in "." $MODS ; do
966            if test -r $i"/packages.conf" ; then
967                    PDEFAULT=$i"/packages.conf"
968                    break
969            fi
970        done
971    fi
972    if test "x${PDEFAULT}" = x ; then
973      PDEFAULT="$ROOTDIR/pkg/pkg_default"      PDEFAULT="$ROOTDIR/pkg/pkg_default"
974  fi  fi
975  if test "x${PDEFAULT}" = xNONE ; then  if test "x${PDEFAULT}" = xNONE ; then
# Line 512  else Line 981  else
981      else      else
982          echo "  using PDEFAULT=\"$PDEFAULT\""          echo "  using PDEFAULT=\"$PDEFAULT\""
983          #  Strip the comments and add all the names          #  Strip the comments and add all the names
984          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | awk '(NF>0){print $0}'`          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
985          RETVAL=$?          RETVAL=$?
986          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
987              echo -n "Error: can't parse default package list "              echo -n "Error: can't parse default package list "
# Line 522  else Line 991  else
991          for i in $def ; do          for i in $def ; do
992              PACKAGES="$PACKAGES $i"              PACKAGES="$PACKAGES $i"
993          done          done
994          echo "    packages are:  $PACKAGES"          echo "    before group expansion packages are: $PACKAGES"
995            expand_pkg_groups
996            echo "    after group expansion packages are:  $PACKAGES"
997      fi      fi
998  fi  fi
999    
# Line 541  for p in $PACKAGES ; do Line 1012  for p in $PACKAGES ; do
1012  done  done
1013  PACKAGES="$pack"  PACKAGES="$pack"
1014  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
1015  rm -f ./.tmp_pack  echo "" > ./.tmp_pack
1016  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
1017  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1018      if test ! -d "$ROOTDIR/pkg/$i" ; then      if test ! -d "$ROOTDIR/pkg/$i" ; then
# Line 632  for i in $PACKAGES ; do Line 1103  for i in $PACKAGES ; do
1103      if test -d $adr ; then      if test -d $adr ; then
1104          SOURCEDIRS="$SOURCEDIRS $adr"          SOURCEDIRS="$SOURCEDIRS $adr"
1105          INCLUDEDIRS="$INCLUDEDIRS $adr"          INCLUDEDIRS="$INCLUDEDIRS $adr"
1106            if test "x$i" = xautodiff ; then
1107                AUTODIFF_PKG_USED=t
1108            fi
1109      else      else
1110          echo "Error: the directory \"$adr\" for package $i doesn't exist"          echo "Error: the directory \"$adr\" for package $i doesn't exist"
1111          exit 1          exit 1
1112      fi      fi
1113  done  done
1114    
 #  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  
1115    
1116  echo "  Setting package-specific CPP flags in CPP_OPTIONS.h:"  # Create a list of #define and #undef to enable/disable packages
1117  CPP_OPTIONS=  PACKAGES_DOT_H=PACKAGES_CONFIG.h
1118  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  
1119  C=== GENMAKE v2 ===  C=== GENMAKE v2 ===
1120  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
1121  C  them only if you know what you're doing.  In general, you should  C  edit anything below these comments.  In general, you should
1122  C  add or remove packages by re-running genmake with different  C  add or remove packages by re-running genmake with different
1123  C  "-enable" and/or "-disable" options.  C  "-enable" and/or "-disable" options.
1124    
1125    #ifndef PACKAGES_H
1126    #define PACKAGES_H
1127    
1128  C  Packages disabled by genmake:  C  Packages disabled by genmake:
1129  EOF  EOF
1130  #  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 709  for n in $names ; do Line 1143  for n in $names ; do
1143              fi              fi
1144          done          done
1145          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
1146              undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`
1147              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!!!  
   
1148          fi          fi
1149      fi      fi
1150  done  done
1151  cat <<EOF >>CPP_OPTIONS.h.tmp  cat <<EOF >>$PACKAGES_DOT_H".tmp"
1152    
1153  C  Packages enabled by genmake:  C  Packages enabled by genmake:
1154  EOF  EOF
1155  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1156      def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`      def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`
1157      echo "#define $def" >> CPP_OPTIONS.h.tmp      echo "#define $def" >> $PACKAGES_DOT_H".tmp"
1158    #eh3 DEFINES="$DEFINES -D$def"
1159    
1160  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1161      case $i in      case $i in
1162          aim_v23)          aim_v23)
1163              echo "#define   ALLOW_AIM" >> CPP_OPTIONS.h.tmp              echo "#define   ALLOW_AIM" >> $PACKAGES_DOT_H".tmp"
1164                DEFINES="$DEFINES -DALLOW_AIM"
1165                echo "Warning: ALLOW_AIM is set to enable aim_v23. This is REALLY ugly Jean-Michel :-)"
1166              ;;              ;;
1167      esac      esac
1168  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1169    
1170  done  done
1171  mv -f CPP_OPTIONS.h.tmp CPP_OPTIONS.h  cat <<EOF >>$PACKAGES_DOT_H".tmp"
1172    
1173    #endif /* PACKAGES_H */
1174    EOF
1175    
1176    if test ! -f $PACKAGES_DOT_H ; then
1177        mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
1178    else
1179        cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
1180        RETVAL=$?
1181        if test "x$RETVAL" = x0 ; then
1182            rm -f $PACKAGES_DOT_H".tmp"
1183        else
1184            mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
1185            mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
1186        fi
1187    fi
1188    
1189  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS"
1190  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
1191  STANDARDDIRS=${STANDARDDIRS:-"eesupp model"}  if test "x$STANDARDDIRS" = x ; then
1192        STANDARDDIRS="eesupp model"
1193    fi
1194  for d in $STANDARDDIRS ; do  for d in $STANDARDDIRS ; do
1195      adr="$ROOTDIR/$d/src"      adr="$ROOTDIR/$d/src"
1196      if test ! -d $adr ; then      if test ! -d $adr ; then
# Line 773  for d in $STANDARDDIRS ; do Line 1210  for d in $STANDARDDIRS ; do
1210      fi      fi
1211  done  done
1212    
1213    echo "  Searching for CPP_OPTIONS.h in order to warn about the presence"
1214    echo "    of \"#define ALLOW_PKGNAME\"-type statements:"
1215    CPP_OPTIONS=
1216    spaths=". $INCLUDEDIRS"
1217    for i in $spaths ; do
1218        try="$i/CPP_OPTIONS.h"
1219        #  echo -n "    trying $try : "
1220        if test -f $try -a -r $try ; then
1221            echo "    found CPP_OPTIONS=\"$try\""
1222            CPP_OPTIONS="$try"
1223            break
1224        fi
1225    done
1226    if test "x$CPP_OPTIONS" = x ; then
1227        echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
1228        exit 1
1229    fi
1230    # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
1231    names=`ls -1 "$ROOTDIR/pkg"`
1232    for n in $names ; do
1233        test_for_package_in_cpp_options $CPP_OPTIONS $n
1234    done
1235    
1236    
1237    #  Here, we build the list of files to be "run through" the adjoint
1238    #  compiler.
1239    if test -f ./ad_files ; then
1240        rm -f ./ad_files
1241    fi
1242    echo "  Creating the list of files for the adjoint compiler."
1243    for i in $SOURCEDIRS ; do
1244        list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
1245        for j in $list_files ; do
1246            cat $i/$j >> ad_files
1247        done
1248    done
1249    
1250    cat <<EOF > adjoint_sed
1251    s/call adopen(/call adopen ( mythid,\\
1252         \&           /g
1253    s/call adclose(/call adclose( mythid,\\
1254         \&           /g
1255    s/call adread(/call adread ( mythid,\\
1256         \&           /g
1257    s/call adwrite(/call adwrite( mythid,\\
1258         \&           /g
1259    
1260    EOF
1261    
1262  echo  echo
1263  echo "===  Creating the Makefile  ==="  echo "===  Creating the Makefile  ==="
1264  echo "  setting INCLUDES"  echo "  setting INCLUDES"
1265  for i in $INCLUDEDIRS ; do  for i in $INCLUDEDIRS ; do
1266      if test -d $i ; then      if ! test -d $i ; then
1267          INCLUDES="$INCLUDES -I$i"  #       INCLUDES="$INCLUDES -I$i"
1268      else  #   else
1269          echo "Warning: can't find INCLUDEDIRS=\"$i\""          echo "Warning: can't find INCLUDEDIRS=\"$i\""
1270      fi      fi
1271  done  done
# Line 794  echo -n 'SRCFILES = '    > srclist.inc Line 1279  echo -n 'SRCFILES = '    > srclist.inc
1279  echo -n 'CSRCFILES = '   > csrclist.inc  echo -n 'CSRCFILES = '   > csrclist.inc
1280  echo -n 'F90SRCFILES = ' > f90srclist.inc  echo -n 'F90SRCFILES = ' > f90srclist.inc
1281  echo -n 'HEADERFILES = ' > hlist.inc  echo -n 'HEADERFILES = ' > hlist.inc
1282  alldirs=". $SOURCEDIRS $INCLUDEDIRS"  echo -n 'AD_FLOW_FILES = ' > ad_flow_files.inc
1283    alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1284  for d in $alldirs ; do  for d in $alldirs ; do
1285      deplist=      deplist=
1286      sfiles=`( cd $d; echo *.[h,c,F] )`      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
1287      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
1288      for sf in $sfiles ; do      for sf in $sfiles ; do
1289          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
1290              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
1291                  extn=`echo $sf | awk -F '.' '{print $NF}'`                  extn=`echo $sf | $AWK -F '.' '{print $NF}'`
1292                  touch .links.tmp/$sf                  touch .links.tmp/$sf
1293                  deplist="$deplist $sf"                  deplist="$deplist $sf"
1294                  case $extn in                  case $extn in
# Line 822  for d in $alldirs ; do Line 1308  for d in $alldirs ; do
1308                          echo    " \\"  >> hlist.inc                          echo    " \\"  >> hlist.inc
1309                          echo -n " $sf" >> hlist.inc                          echo -n " $sf" >> hlist.inc
1310                          ;;                          ;;
1311                        flow)
1312                            echo    " \\"  >> ad_flow_files.inc
1313                            echo -n " $sf" >> ad_flow_files.inc
1314                            ;;
1315                  esac                  esac
1316              fi              fi
1317          fi          fi
# Line 838  echo "" >> srclist.inc Line 1328  echo "" >> srclist.inc
1328  echo "" >> csrclist.inc  echo "" >> csrclist.inc
1329  echo "" >> f90srclist.inc  echo "" >> f90srclist.inc
1330  echo "" >> hlist.inc  echo "" >> hlist.inc
1331    echo "" >> ad_flow_files.inc
1332    
1333  if test -e $MAKEFILE ; then  if test -e $MAKEFILE ; then
1334      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.bak"
# Line 851  echo "# by the command:" >> $MAKEFILE Line 1342  echo "# by the command:" >> $MAKEFILE
1342  echo "#    $0 $@" >> $MAKEFILE  echo "#    $0 $@" >> $MAKEFILE
1343  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
1344  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE
1345    
1346    EXE_AD=$EXECUTABLE"_ad"
1347    EXE_FTL=$EXECUTABLE"_ftl"
1348    EXE_SVD=$EXECUTABLE"_svd"
1349    
1350  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
1351  #  #
1352  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
# Line 879  EXEDIR      = ${EXEDIR} Line 1375  EXEDIR      = ${EXEDIR}
1375  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}
1376  TOOLSDIR    = ${TOOLSDIR}  TOOLSDIR    = ${TOOLSDIR}
1377    
1378    #eh3  new defines for the adjoint work
1379    AUTODIFF    = ${ROOTDIR}/pkg/autodiff
1380    EXE_AD      = ${EXE_AD}
1381    EXE_FTL     = ${EXE_FTL}
1382    EXE_SVD     = ${EXE_SVD}
1383    
1384  EOF  EOF
1385    
1386  #  Note: figure out some way to add Hyades JAM libraries here  #  Note: figure out some way to add Hyades JAM libraries here
# Line 924  MAKEFILE=${MAKEFILE} Line 1426  MAKEFILE=${MAKEFILE}
1426    
1427  EOF  EOF
1428    
1429  cat srclist.inc    >> $MAKEFILE  cat srclist.inc       >> $MAKEFILE
1430  cat csrclist.inc   >> $MAKEFILE  cat csrclist.inc      >> $MAKEFILE
1431  cat f90srclist.inc >> $MAKEFILE  cat f90srclist.inc    >> $MAKEFILE
1432  cat hlist.inc      >> $MAKEFILE  cat hlist.inc         >> $MAKEFILE
1433    cat ad_flow_files.inc >> $MAKEFILE
1434    echo               >> $MAKEFILE
1435  echo 'F77FILES =  $(SRCFILES:.F=.f)'                                           >> $MAKEFILE  echo 'F77FILES =  $(SRCFILES:.F=.f)'                                           >> $MAKEFILE
1436  echo 'F90FILES =  $(F90SRCFILES:.F90=.f90)'                                    >> $MAKEFILE  echo 'F90FILES =  $(F90SRCFILES:.F90=.f90)'                                    >> $MAKEFILE
1437  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
1438    
1439  rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc  rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc
1440    rm -f ad_flow_files.inc
1441    
1442  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
1443    
# Line 945  all: \$(EXECUTABLE) Line 1450  all: \$(EXECUTABLE)
1450  depend:  depend:
1451          @make links          @make links
1452          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
1453          ../../../tools/f90mkdepend >> \$(MAKEFILE)          ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE)
1454    
1455  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)
1456    
# Line 956  output.txt: \$(EXECUTABLE) Line 1461  output.txt: \$(EXECUTABLE)
1461          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
1462    
1463  clean:  clean:
1464            -cat AD_CONFIG.template > AD_CONFIG.h
1465          -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}          -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}
1466  Clean:  Clean:
1467          @make clean          @make clean
1468          @make cleanlinks          @make cleanlinks
1469          -rm -f Makefile.bak          -rm -f Makefile.bak genmake_state genmake_*optfile make.log
1470  CLEAN:  CLEAN:
1471          @make Clean          @make Clean
1472          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
1473          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
1474          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
1475          -rm -f \$(EXECUTABLE)          -rm -f \$(EXECUTABLE) output.txt
1476    
1477    #eh3 Makefile: makefile
1478  makefile:  makefile:
1479          ${0} $@          ${0} $@
1480  cleanlinks:  cleanlinks:
# Line 991  cleanlinks: Line 1498  cleanlinks:
1498  .p.f:  .p.f:
1499          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
1500    
1501    #=========================================
1502    #===  Automatic Differentiation Rules  ===
1503    
1504    TAMC           = ${TAMC}
1505    TAF            = ${TAF}
1506    
1507    TAF_EXTRA      = ${TAF_EXTRA}
1508    TAMC_EXTRA     = ${TAMC_EXTRA}
1509    
1510  EOF  EOF
1511    
1512    ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
1513    ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF_FLAGS"
1514    ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
1515    for i in $ad_vars ; do
1516        name=$i
1517        t1="t2=\$"`echo $i`
1518        eval $t1
1519        printf "%-20s = " $name >> $MAKEFILE
1520        echo $t2 >> $MAKEFILE
1521    done
1522    
1523    echo "  Add the source list for AD code generation"
1524    echo >> $MAKEFILE
1525    echo -n "AD_FILES = " >> $MAKEFILE
1526    AD_FILES=`cat ad_files`
1527    for i in $AD_FILES ; do
1528        echo    " \\" >> $MAKEFILE
1529        echo -n " $i" >> $MAKEFILE
1530    done
1531    echo >> $MAKEFILE
1532    rm -f ad_files
1533    
1534    cat >>$MAKEFILE <<EOF
1535    
1536    # ... AD ...
1537    adall: ad_taf
1538    adtaf: ad_taf_output.f
1539    adtamc: ad_tamc_output.f
1540    
1541    ad_input_code.f: \$(AD_FILES) \$(HEADERFILES)
1542            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
1543            @make \$(F77FILES)
1544            @make \$(AD_FLOW_FILES)
1545            cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f
1546    
1547    ad_taf_output.f: ad_input_code.f
1548            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1549            cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f
1550    
1551    adtafonly:
1552            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1553            cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f
1554    
1555    ad_taf: ad_taf_output.o \$(OBJFILES)
1556            \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
1557    
1558    ad_tamc_output.f: ad_input_code.f
1559            \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f
1560            cat ad_input_code_ad.f | sed -f adjoint_sed > ad_tamc_output.f
1561    
1562    ad_tamc: ad_tamc_output.o \$(OBJFILES)
1563            \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
1564    
1565    
1566    # ... FTL ...
1567    ftlall: ftl_taf
1568    ftltaf: ftl_taf_output.f
1569    ftltamc: ftl_tamc_output.f
1570    
1571    ftl_input_code.f: \$(AD_FILES) \$(HEADERFILES)
1572            cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
1573            @make \$(F77FILES)
1574            @make \$(AD_FLOW_FILES)
1575            cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f
1576    
1577    ftl_taf_output.f: ftl_input_code.f
1578            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f
1579            cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_taf_output.f
1580    
1581    ftl_taf: ftl_taf_output.o \$(OBJFILES)
1582            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
1583    
1584    ftl_tamc_output.f: ftl_input_code.f
1585            \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f
1586            cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_tamc_output.f
1587    
1588    ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
1589            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
1590    
1591    
1592    # ... SVD ...
1593    svd: svd_taf
1594    svd_taf_f: svd_taf_output.f
1595    
1596    svd_input_code.f: \$(SRCFILES)
1597            cmp svd_config.template AD_CONFIG.h || cat svd_config.template > AD_CONFIG.h
1598            @make \$(F77FILES)
1599            @make \$(AD_FLOW_FILES)
1600            cat \$(AD_FLOW_FILES) \$(AD_FILES) > svd_input_code.f
1601    
1602    svd_taf_output.f: svd_input_code.f
1603            \$(TAF) \$(SVD_TAF_FLAGS) \$(TAF_EXTRA) svd_input_code.f
1604            cat svd_input_code_ad.f | sed -f adjoint_sed > svd_taf_output.f
1605    
1606    svd_taf: svd_taf_output.o \$(OBJFILES)
1607            \$(LINK) -o ${EXE_SVD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) svd_taf_output.o \$(LIBS)
1608    
1609    
1610    #=========================================
1611    
1612    EOF
1613    
1614    if test "x$EXEHOOK" != x ; then
1615        printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
1616    fi
1617    
1618  echo "  Making list of \"exceptions\" that need \".p\" files"  echo "  Making list of \"exceptions\" that need \".p\" files"
1619  for i in $KPPFILES ; do  for i in $KPPFILES ; do
1620      base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`      base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
# Line 1023  printf "\n\n# DO NOT DELETE\n" >> $MAKEF Line 1645  printf "\n\n# DO NOT DELETE\n" >> $MAKEF
1645    
1646  printf "\n===  Done  ===\n"  printf "\n===  Done  ===\n"
1647    
1648    #  Write the "template" files for the adjoint builds
1649    cat >AD_CONFIG.template <<EOF
1650    C  WARNING: This file is automatically generated by genmake2 and
1651    C    used by the Makefile rules.  Please DO NOT EDIT this file
1652    C    unless you are CERTAIN that you know what you are doing.
1653    
1654    #undef ALLOW_ADJOINT_RUN
1655    #undef ALLOW_TANGENTLINEAR_RUN
1656    #undef ALLOW_ECCO_OPTIMIZATION
1657    EOF
1658    cat >ad_config.template <<EOF
1659    C  WARNING: This file is automatically generated by genmake2 and
1660    C    used by the Makefile rules.  Please DO NOT EDIT this file
1661    C    unless you are CERTAIN that you know what you are doing.
1662    
1663    #define ALLOW_ADJOINT_RUN
1664    #undef ALLOW_TANGENTLINEAR_RUN
1665    #undef ALLOW_ECCO_OPTIMIZATION
1666    EOF
1667    cat >ftl_config.template <<EOF
1668    C  WARNING: This file is automatically generated by genmake2 and
1669    C    used by the Makefile rules.  Please DO NOT EDIT this file
1670    C    unless you are CERTAIN that you know what you are doing.
1671    
1672    #undef ALLOW_ADJOINT_RUN
1673    #define ALLOW_TANGENTLINEAR_RUN
1674    #undef ALLOW_ECCO_OPTIMIZATION
1675    EOF
1676    cat >svd_config.template <<EOF
1677    C  WARNING: This file is automatically generated by genmake2 and
1678    C    used by the Makefile rules.  Please DO NOT EDIT this file
1679    C    unless you are CERTAIN that you know what you are doing.
1680    
1681    #undef ALLOW_ADJOINT_RUN
1682    #undef ALLOW_TANGENTLINEAR_RUN
1683    #undef ALLOW_ECCO_OPTIMIZATION
1684    EOF
1685    cp AD_CONFIG.template AD_CONFIG.h
1686    
1687    
1688  #  Write the "state" for future records  #  Write the "state" for future records
1689  if test "x$DUMPSTATE" != xf ; then  if test "x$DUMPSTATE" != xf ; then
1690      echo -n "" > gm_state      echo -n "" > genmake_state
1691      for i in $gm_state ; do      for i in $gm_state ; do
1692          t1="t2=\$$i"          t1="t2=\$$i"
1693          eval $t1          eval $t1
1694          echo "$i='$t2'" >> gm_state          echo "$i='$t2'" >> genmake_state
1695      done      done
1696  fi  fi

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.39

  ViewVC Help
Powered by ViewVC 1.1.22