/[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.13 by edhill, Fri Oct 10 18:38:57 2003 UTC revision 1.31 by edhill, Wed Nov 12 21:14:57 2003 UTC
# Line 46  expand_pkg_groups() { Line 46  expand_pkg_groups() {
46      PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups"      PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups"
47      if test -r $PKG_GROUPS ; then      if test -r $PKG_GROUPS ; then
48          cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp          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          cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp
50          matched=0          matched=0
51          for i in $PACKAGES ; do          for i in $PACKAGES ; do
52              line=`grep "^ *$i" ./p2.tmp`              line=`grep "^ *$i" ./p2.tmp`
53              RETVAL=$?              RETVAL=$?
54              if test "x$RETVAL" = x0 ; then              if test "x$RETVAL" = x0 ; then
55                  matched=1                  matched=1
56                  replace=`echo $line | awk '{ $1=""; $2=""; print $0 }'`                  replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`
57                  echo "    replacing \"$i\" with: $replace"                  echo "    replacing \"$i\" with: $replace"
58                  new_packages="$new_packages $replace"                  new_packages="$new_packages $replace"
59              else              else
# Line 72  find_possible_configs()  { Line 72  find_possible_configs()  {
72    
73      tmp1=`uname`"_"`uname -m`      tmp1=`uname`"_"`uname -m`
74      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
75      PLATFORM=`echo $tmp2 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`      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      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
78      echo "  The platform appears to be:  $PLATFORM"      echo "  The platform appears to be:  $PLATFORM"
79  #     if test "x$OFLIST" = x ; then  #     if test "x$OFLIST" = x ; then
# Line 104  find_possible_configs()  { Line 105  find_possible_configs()  {
105      fi      fi
106    
107      # look for possible fortran compilers      # look for possible fortran compilers
108      tmp="$MITGCM_FC $FC g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"      tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"
109      p_FC=      p_FC=
110      for c in $tmp ; do      for c in $tmp ; do
111          rm -f ./hello.f ./hello          rm -f ./hello.f ./hello
# Line 121  EOF Line 122  EOF
122              p_FC="$p_FC $c"              p_FC="$p_FC $c"
123          fi          fi
124      done      done
125        rm -f ./hello.f ./hello
126      if test "x${p_FC}" = x ; then      if test "x${p_FC}" = x ; then
127          cat 1>&2 <<EOF          cat 1>&2 <<EOF
128    
# Line 136  EOF Line 138  EOF
138          echo "  The possible FORTRAN compilers found in your path are:"          echo "  The possible FORTRAN compilers found in your path are:"
139          echo "   "$p_FC          echo "   "$p_FC
140          if test "x$FC" = x ; then          if test "x$FC" = x ; then
141              FC=`echo $p_FC | awk '{print $1}'`              FC=`echo $p_FC | $AWK '{print $1}'`
142          fi          fi
143      fi      fi
144    
# Line 202  get_pdepend_list()  { Line 204  get_pdepend_list()  {
204      #  strip the comments and then convert the dependency file into      #  strip the comments and then convert the dependency file into
205      #  two arrays: PNAME, DNAME      #  two arrays: PNAME, DNAME
206      cat $1 | sed -e 's/#.*$//g' \      cat $1 | sed -e 's/#.*$//g' \
207          | 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} }' \
208          > ./.pd_tmp          > ./.pd_tmp
209      source ./.pd_tmp      source ./.pd_tmp
210      rm -f ./.pd_tmp      rm -f ./.pd_tmp
# Line 262  usage()  { Line 264  usage()  {
264      exit 1      exit 1
265  }  }
266    
267  #eh3 # This is the generic configuration.  #  Build a CPP macro to automate calling C routines from FORTRAN
268  #eh3 set LN         = ( 'ln -s' )  get_fortran_c_namemangling()  {
269  #eh3 set CPP        = ( '/lib/cpp -P' )      default_nm="#define FC_NAMEMANGLE(X) X ## _"
270  #eh3 set S64        = ( '$(TOOLSDIR)/set64bitConst.sh' )      
271  #eh3 set KPP        = (  )      cat > genmake_test.c <<EOF
272  #eh3 set FC         = ( 'f77' )  void tcall( char * string ) { tsub( string ); }
273  #eh3 set LINK       = $FC  EOF
274  #eh3 set MAKEDEPEND = ( 'makedepend' )      $MAKE genmake_test.o > genmake_test.log 2>&1
275  #eh3 set INCLUDES   = ( -I. )      RETVAL=$?
276  #eh3 set FFLAGS     = (  )      if test "x$RETVAL" != x0 ; then
277  #eh3 set FOPTIM     = (  )          cat genmake_test.log >> genmake_errors
278  #eh3 set CFLAGS     = (  )          FC_NAMEMANGLE=$default_nm
279  #eh3 set KFLAGS1    = (  )          echo
280  #eh3 set KFLAGS2    = (  )          echo "WARNING: C test compile fails -- please see \"genmake_errors\""
281  #eh3 set LIBS       = (  )          echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"
282  #eh3 set KPPFILES   = (  )          echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."
283  #eh3 if (! $?NOOPTFILES ) set NOOPTFILES = (  )          return 1
284  #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = (  )      fi
285        c_tcall=`nm genmake_test.o | grep tcall | cut -d ' ' -f 3`
286        RETVAL=$?
287        if test "x$RETVAL" != x0 ; then
288            FC_NAMEMANGLE=$default_nm
289            echo
290            echo "WARNING: The \"nm\" command failed."
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            return 1
294        fi
295        cat > genmake_tcomp.f <<EOF
296          subroutine tcall( string )
297          character*(*) string
298          call tsub( string )
299          end
300    EOF
301        $FC $FFLAGS $DEFINES -c genmake_tcomp.f > genmake_tcomp.log 2>&1
302        RETVAL=$?
303        if test "x$RETVAL" != x0 ; then
304            cat genmake_tcomp.log >> genmake_errors
305            FC_NAMEMANGLE=$default_nm
306            echo
307            echo "WARNING: FORTRAN test compile fails -- please see \"genmake_errors\""
308            echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"
309            echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."
310            return 1
311        fi
312        f_tcall=`nm genmake_tcomp.o | grep tcall | cut -d ' ' -f 3`
313        RETVAL=$?
314        if test "x$RETVAL" != x0 ; then
315            FC_NAMEMANGLE=$default_nm
316            echo
317            echo "WARNING: The \"nm\" command failed."
318            echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"
319            echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."
320            return 1
321        fi
322    
323        c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
324        f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
325        c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
326        f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
327    
328        nmangle="X"
329        if test "x$c_a" != "x$f_a" ; then
330            comm="echo x$f_a | sed -e 's|x$c_a||'"
331            a=`eval $comm`
332            nmangle="$a ## $nmangle"
333        fi
334        if test "x$c_b" != "x$f_b" ; then
335            comm="echo x$f_b | sed -e 's|x$c_b||'"
336            b=`eval $comm`
337            nmangle="$nmangle ## $b"
338        fi
339    
340        FC_NAMEMANGLE="#define FC_NAMEMANGLE(X)  $nmangle"
341    }
342    
343  #  Set defaults here  #  Set defaults here
344  COMMANDL="$0 $@"  COMMANDL="$0 $@"
# Line 290  S64= Line 349  S64=
349  KPP=  KPP=
350  FC=  FC=
351  LINK=  LINK=
352  DEFINES="-DWORDLENGTH=4"  # DEFINES="-DWORDLENGTH=4"
353    DEFINES=
354  PACKAGES=  PACKAGES=
355  ENABLE=  ENABLE=
356  DISABLE=  DISABLE=
# Line 311  KPPFILES= Line 371  KPPFILES=
371  NOOPTFILES=  NOOPTFILES=
372  NOOPTFLAGS=  NOOPTFLAGS=
373    
374    # DEFINES checked by test compilation
375    HAVE_SYSTEM=
376    HAVE_FDATE=
377    FC_NAMEMANGLE=
378    
379  MODS=  MODS=
380  TOOLSDIR=  TOOLSDIR=
381  SOURCEDIRS=  SOURCEDIRS=
# Line 319  STANDARDDIRS= Line 384  STANDARDDIRS=
384    
385  PWD=`pwd`  PWD=`pwd`
386  MAKE=make  MAKE=make
387    AWK=awk
388  THISHOSTNAME=`hostname`  THISHOSTNAME=`hostname`
389  THISCWD=`pwd`  THISCWD=`pwd`
390  THISDATE=`date`  THISDATE=`date`
# Line 332  if test "x$MITGCM_IEEE" != x ; then Line 398  if test "x$MITGCM_IEEE" != x ; then
398      IEEE=$MITGCM_IEEE      IEEE=$MITGCM_IEEE
399  fi  fi
400    
401    AUTODIFF_PKG_USED=f
402    AD_OPTFILE=
403    TAF=
404    AD_TAF_FLAGS=
405    FTL_TAF_FLAGS=
406    SVD_TAF_FLAGS=
407    TAF_EXTRA=
408    TAMC=
409    AD_TAMC_FLAGS=
410    FTL_TAF_FLAGS=
411    SVD_TAMC_FLAGS=
412    TAMC_EXTRA=
413    
414    
415  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
416  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"
417  gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS"  gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS"
# Line 341  gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPE Line 421  gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPE
421  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
422  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"
423  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
424    gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE"
425    
426    #  The following are all related to adjoint/tangent-linear stuff
427    gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
428    gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
429    gm_s12="TAF_EXTRA TAMC_EXTRA"
430    
431  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6"  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"
432    gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
433    
434    
435  echo  echo
# Line 375  fi Line 462  fi
462  #   n=$(( $n + 1 ))  #   n=$(( $n + 1 ))
463  #done  #done
464  #parse_options  #parse_options
   
465  ac_prev=  ac_prev=
466  for ac_option ; do  for ac_option ; do
467    
# Line 400  for ac_option ; do Line 486  for ac_option ; do
486          -optfile=* | --optfile=* | -of=* | --of=*)          -optfile=* | --optfile=* | -of=* | --of=*)
487              OPTFILE=$ac_optarg ;;              OPTFILE=$ac_optarg ;;
488                    
489            -adoptfile | --adoptfile | -ad | --ad)
490                ac_prev=AD_OPTFILE ;;
491            -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
492                AD_OPTFILE=$ac_optarg ;;
493            
494          -pdepend | --pdepend)          -pdepend | --pdepend)
495              ac_prev=PDEPEND ;;              ac_prev=PDEPEND ;;
496          -pdepend=* | --pdepend=*)          -pdepend=* | --pdepend=*)
# Line 483  for ac_option ; do Line 574  for ac_option ; do
574          -ds | --ds)          -ds | --ds)
575              DUMPSTATE=t ;;              DUMPSTATE=t ;;
576                    
577            -taf_extra | --taf_extra)
578                ac_prev=TAF_EXTRA ;;
579            -taf_extra=* | --taf_extra=*)
580                TAF_EXTRA=$ac_optarg ;;
581    
582            -tamc_extra | --tamc_extra)
583                ac_prev=TAMC_EXTRA ;;
584            -tamc_extra=* | --tamc_extra=*)
585                TAMC_EXTRA=$ac_optarg ;;
586    
587          -*)          -*)
588              echo "Error: unrecognized option: "$ac_option              echo "Error: unrecognized option: "$ac_option
589              usage              usage
# Line 563  if test "x$OPTFILE" != xNONE ; then Line 664  if test "x$OPTFILE" != xNONE ; then
664      fi      fi
665  fi  fi
666    
667    echo "  getting AD_OPTFILE information:  "
668    if test "x${AD_OPTFILE}" = x ; then
669        if test "x$MITGCM_AD_OF" = x ; then
670            AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
671        else
672            AD_OPTFILE=$MITGCM_AD_OF
673        fi
674    fi
675    if test "x${AD_OPTFILE}" != xNONE ; then
676        if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
677            echo "    using AD_OPTFILE=\"$AD_OPTFILE\""
678            source "$AD_OPTFILE"
679            RETVAL=$?
680            if test "x$RETVAL" != x0 ; then
681                echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
682                echo "--please check that variable syntax is bash-compatible"
683                exit 1
684            fi
685            if test "x$DUMPSTATE" != xf ; then
686                cp -f $AD_OPTFILE "genmake_ad_optfile"
687            fi
688        else
689            echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
690            exit 1
691        fi
692    fi
693    
694  #  Check that FC, LINK, CPP, and S64 are defined.  If not, complain  #  Check that FC, LINK, CPP, and S64 are defined.  If not, complain
695  #  and abort!  #  and abort!
696  if test "x$FC" = x ; then  if test "x$FC" = x ; then
# Line 590  Error: C pre-processor "$CPP" failed the Line 718  Error: C pre-processor "$CPP" failed the
718    
719    1) within the options file ("CPP=...") as specified by "-of=OPTFILE"    1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
720    2) the "./genmake_local" file    2) the "./genmake_local" file
721      3) with the CPP environment variable
722    
723  EOF  EOF
724      exit 1      exit 1
# Line 600  if test "x$MAKEDEPEND" = x ; then Line 729  if test "x$MAKEDEPEND" = x ; then
729      MAKEDEPEND=makedepend      MAKEDEPEND=makedepend
730  fi  fi
731    
732    
733    printf "\n===  Checking system libraries  ===\n"
734    echo -n "  Do we have the system() command using $FC...  "
735    cat > genmake_tcomp.f <<EOF
736          program hello
737          call system('echo hi')
738          end
739    EOF
740    $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1
741    RETVAL=$?
742    if test "x$RETVAL" = x0 ; then
743        HAVE_SYSTEM=t
744        DEFINES="$DEFINES -DHAVE_SYSTEM"
745        echo "yes"
746    else
747        HAVE_SYSTEM=
748        echo "no"
749    fi
750    rm -f genmake_tcomp*
751    
752    echo -n "  Do we have the fdate() command using $FC...  "
753    cat > genmake_tcomp.f <<EOF
754          program hello
755          CHARACTER(128) string
756          string = ' '
757          call fdate( string )
758          print *, string
759          end
760    EOF
761    $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1
762    RETVAL=$?
763    if test "x$RETVAL" = x0 ; then
764        HAVE_FDATE=t
765        DEFINES="$DEFINES -DHAVE_FDATE"
766        echo "yes"
767    else
768        HAVE_FDATE=
769        echo "no"
770    fi
771    rm -f genmake_tcomp*
772    
773    echo "  The name mangling convention for $FC is...  "
774    #FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) X ## _"
775    if test "x$FC_NAMEMANGLE" = x ; then
776        get_fortran_c_namemangling
777    fi
778    echo "    '$FC_NAMEMANGLE'"
779    echo "$FC_NAMEMANGLE" > FC_NAMEMANGLE.h.template
780    cmp FC_NAMEMANGLE.h FC_NAMEMANGLE.h.template > /dev/null 2>&1
781    RETVAL=$?
782    if test "x$RETVAL" != x0 ; then
783        mv -f FC_NAMEMANGLE.h.template FC_NAMEMANGLE.h
784    fi
785    
786    
787  printf "\n===  Setting defaults  ===\n"  printf "\n===  Setting defaults  ===\n"
788  echo -n "  Adding MODS directories:  "  echo -n "  Adding MODS directories:  "
789  for d in $MODS ; do  for d in $MODS ; do
# Line 682  echo "  getting package dependency info Line 866  echo "  getting package dependency info
866  #  Strip the comments and then convert the dependency file into  #  Strip the comments and then convert the dependency file into
867  #  two arrays: PNAME, DNAME  #  two arrays: PNAME, DNAME
868  cat $PDEPEND | sed -e 's/#.*$//g' \  cat $PDEPEND | sed -e 's/#.*$//g' \
869      | 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}' \
870      > ./.pd_tmp      > ./.pd_tmp
871  RETVAL=$?  RETVAL=$?
872  if test ! "x${RETVAL}" = x0 ; then  if test ! "x${RETVAL}" = x0 ; then
# Line 716  else Line 900  else
900      else      else
901          echo "  using PDEFAULT=\"$PDEFAULT\""          echo "  using PDEFAULT=\"$PDEFAULT\""
902          #  Strip the comments and add all the names          #  Strip the comments and add all the names
903          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | awk '(NF>0){print $0}'`          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
904          RETVAL=$?          RETVAL=$?
905          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
906              echo -n "Error: can't parse default package list "              echo -n "Error: can't parse default package list "
# Line 838  for i in $PACKAGES ; do Line 1022  for i in $PACKAGES ; do
1022      if test -d $adr ; then      if test -d $adr ; then
1023          SOURCEDIRS="$SOURCEDIRS $adr"          SOURCEDIRS="$SOURCEDIRS $adr"
1024          INCLUDEDIRS="$INCLUDEDIRS $adr"          INCLUDEDIRS="$INCLUDEDIRS $adr"
1025            if test "x$i" = xautodiff ; then
1026                AUTODIFF_PKG_USED=t
1027            fi
1028      else      else
1029          echo "Error: the directory \"$adr\" for package $i doesn't exist"          echo "Error: the directory \"$adr\" for package $i doesn't exist"
1030          exit 1          exit 1
1031      fi      fi
1032  done  done
1033    
 #  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  
1034    
1035  # Create a list of #define and #undef to enable/disable packages  # Create a list of #define and #undef to enable/disable packages
1036  PACKAGES_DOT_H=PACKAGES_CONFIG.h  PACKAGES_DOT_H=PACKAGES_CONFIG.h
# Line 893  for n in $names ; do Line 1062  for n in $names ; do
1062              fi              fi
1063          done          done
1064          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
1065              undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`
1066              echo "#undef $undef" >> $PACKAGES_DOT_H".tmp"              echo "#undef $undef" >> $PACKAGES_DOT_H".tmp"
 #           DEFINES="$DEFINES -U$undef"  
   
 #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  
             case $n in  
                 mom_fluxform)  
                     DEFINES="$DEFINES -DDISABLE_MOM_FLUXFORM"  
                     ;;  
                 mom_vecinv)  
                     DEFINES="$DEFINES -DDISABLE_MOM_VECINV"  
                     ;;  
                 debug)  
                     DEFINES="$DEFINES -DDISABLE_DEBUGMODE"  
                     ;;  
             esac  
 #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  
   
1067          fi          fi
1068      fi      fi
1069  done  done
# Line 919  cat <<EOF >>$PACKAGES_DOT_H".tmp" Line 1072  cat <<EOF >>$PACKAGES_DOT_H".tmp"
1072  C  Packages enabled by genmake:  C  Packages enabled by genmake:
1073  EOF  EOF
1074  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1075      def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`      def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`
1076      echo "#define $def" >> $PACKAGES_DOT_H".tmp"      echo "#define $def" >> $PACKAGES_DOT_H".tmp"
1077  #eh3 DEFINES="$DEFINES -D$def"  #eh3 DEFINES="$DEFINES -D$def"
1078    
# Line 976  for d in $STANDARDDIRS ; do Line 1129  for d in $STANDARDDIRS ; do
1129      fi      fi
1130  done  done
1131    
1132  echo " Searching for CPP_OPTIONS.h in order to warn about the presence"  echo "  Searching for CPP_OPTIONS.h in order to warn about the presence"
1133  echo " of \"#define ALLOW_PKGNAME\"-type statements:"  echo "    of \"#define ALLOW_PKGNAME\"-type statements:"
1134  CPP_OPTIONS=  CPP_OPTIONS=
1135  spaths=". $INCLUDEDIRS"  spaths=". $INCLUDEDIRS"
1136  for i in $spaths ; do  for i in $spaths ; do
# Line 1000  for n in $names ; do Line 1153  for n in $names ; do
1153  done  done
1154    
1155    
1156    #  Here, we build the list of files to be "run through" the adjoint
1157    #  compiler.
1158    if test -f ./ad_files ; then
1159        rm -f ./ad_files
1160    fi
1161    echo "  Creating the list of files for the adjoint compiler."
1162    for i in $SOURCEDIRS ; do
1163        list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
1164        for j in $list_files ; do
1165            cat $i/$j >> ad_files
1166        done
1167    done
1168    
1169    cat <<EOF > adjoint_sed
1170    s/call adopen(/call adopen ( mythid,\\
1171         \&           /g
1172    s/call adclose(/call adclose( mythid,\\
1173         \&           /g
1174    s/call adread(/call adread ( mythid,\\
1175         \&           /g
1176    s/call adwrite(/call adwrite( mythid,\\
1177         \&           /g
1178    
1179    EOF
1180    
1181  echo  echo
1182  echo "===  Creating the Makefile  ==="  echo "===  Creating the Makefile  ==="
1183  echo "  setting INCLUDES"  echo "  setting INCLUDES"
# Line 1020  echo -n 'SRCFILES = '    > srclist.inc Line 1198  echo -n 'SRCFILES = '    > srclist.inc
1198  echo -n 'CSRCFILES = '   > csrclist.inc  echo -n 'CSRCFILES = '   > csrclist.inc
1199  echo -n 'F90SRCFILES = ' > f90srclist.inc  echo -n 'F90SRCFILES = ' > f90srclist.inc
1200  echo -n 'HEADERFILES = ' > hlist.inc  echo -n 'HEADERFILES = ' > hlist.inc
1201    echo -n 'AD_FLOW_FILES = ' > ad_flow_files.inc
1202  alldirs="$SOURCEDIRS $INCLUDEDIRS ."  alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1203  for d in $alldirs ; do  for d in $alldirs ; do
1204      deplist=      deplist=
1205      sfiles=`( cd $d; echo *.[h,c,F] )`      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
1206      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
1207      for sf in $sfiles ; do      for sf in $sfiles ; do
1208          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
1209              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
1210                  extn=`echo $sf | awk -F '.' '{print $NF}'`                  extn=`echo $sf | $AWK -F '.' '{print $NF}'`
1211                  touch .links.tmp/$sf                  touch .links.tmp/$sf
1212                  deplist="$deplist $sf"                  deplist="$deplist $sf"
1213                  case $extn in                  case $extn in
# Line 1048  for d in $alldirs ; do Line 1227  for d in $alldirs ; do
1227                          echo    " \\"  >> hlist.inc                          echo    " \\"  >> hlist.inc
1228                          echo -n " $sf" >> hlist.inc                          echo -n " $sf" >> hlist.inc
1229                          ;;                          ;;
1230                        flow)
1231                            echo    " \\"  >> ad_flow_files.inc
1232                            echo -n " $sf" >> ad_flow_files.inc
1233                            ;;
1234                  esac                  esac
1235              fi              fi
1236          fi          fi
# Line 1064  echo "" >> srclist.inc Line 1247  echo "" >> srclist.inc
1247  echo "" >> csrclist.inc  echo "" >> csrclist.inc
1248  echo "" >> f90srclist.inc  echo "" >> f90srclist.inc
1249  echo "" >> hlist.inc  echo "" >> hlist.inc
1250    echo "" >> ad_flow_files.inc
1251    
1252  if test -e $MAKEFILE ; then  if test -e $MAKEFILE ; then
1253      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.bak"
# Line 1077  echo "# by the command:" >> $MAKEFILE Line 1261  echo "# by the command:" >> $MAKEFILE
1261  echo "#    $0 $@" >> $MAKEFILE  echo "#    $0 $@" >> $MAKEFILE
1262  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
1263  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE
1264    
1265    EXE_AD=$EXECUTABLE"_ad"
1266    EXE_FTL=$EXECUTABLE"_ftl"
1267    EXE_SVD=$EXECUTABLE"_svd"
1268    
1269  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
1270  #  #
1271  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
# Line 1105  EXEDIR      = ${EXEDIR} Line 1294  EXEDIR      = ${EXEDIR}
1294  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}
1295  TOOLSDIR    = ${TOOLSDIR}  TOOLSDIR    = ${TOOLSDIR}
1296    
1297    #eh3  new defines for the adjoint work
1298    AUTODIFF    = ${ROOTDIR}/pkg/autodiff
1299    EXE_AD      = ${EXE_AD}
1300    EXE_FTL     = ${EXE_FTL}
1301    EXE_SVD     = ${EXE_SVD}
1302    
1303  EOF  EOF
1304    
1305  #  Note: figure out some way to add Hyades JAM libraries here  #  Note: figure out some way to add Hyades JAM libraries here
# Line 1150  MAKEFILE=${MAKEFILE} Line 1345  MAKEFILE=${MAKEFILE}
1345    
1346  EOF  EOF
1347    
1348  cat srclist.inc    >> $MAKEFILE  cat srclist.inc       >> $MAKEFILE
1349  cat csrclist.inc   >> $MAKEFILE  cat csrclist.inc      >> $MAKEFILE
1350  cat f90srclist.inc >> $MAKEFILE  cat f90srclist.inc    >> $MAKEFILE
1351  cat hlist.inc      >> $MAKEFILE  cat hlist.inc         >> $MAKEFILE
1352    cat ad_flow_files.inc >> $MAKEFILE
1353    echo               >> $MAKEFILE
1354  echo 'F77FILES =  $(SRCFILES:.F=.f)'                                           >> $MAKEFILE  echo 'F77FILES =  $(SRCFILES:.F=.f)'                                           >> $MAKEFILE
1355  echo 'F90FILES =  $(F90SRCFILES:.F90=.f90)'                                    >> $MAKEFILE  echo 'F90FILES =  $(F90SRCFILES:.F90=.f90)'                                    >> $MAKEFILE
1356  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
1357    
1358  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
1359    rm -f ad_flow_files.inc
1360    
1361  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
1362    
# Line 1182  output.txt: \$(EXECUTABLE) Line 1380  output.txt: \$(EXECUTABLE)
1380          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
1381    
1382  clean:  clean:
1383            -cat AD_CONFIG.template > AD_CONFIG.h
1384          -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}          -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}
1385  Clean:  Clean:
1386          @make clean          @make clean
1387          @make cleanlinks          @make cleanlinks
1388          -rm -f Makefile.bak genmake_state genmake_optfile make.log          -rm -f Makefile.bak genmake_state genmake_*optfile make.log
1389  CLEAN:  CLEAN:
1390          @make Clean          @make Clean
1391          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
# Line 1194  CLEAN: Line 1393  CLEAN:
1393          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
1394          -rm -f \$(EXECUTABLE) output.txt          -rm -f \$(EXECUTABLE) output.txt
1395    
1396    #eh3 Makefile: makefile
1397  makefile:  makefile:
1398          ${0} $@          ${0} $@
1399  cleanlinks:  cleanlinks:
# Line 1217  cleanlinks: Line 1417  cleanlinks:
1417  .p.f:  .p.f:
1418          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
1419    
1420    #=========================================
1421    #===  Automatic Differentiation Rules  ===
1422    
1423    TAMC           = ${TAMC}
1424    TAF            = ${TAF}
1425    
1426    TAF_EXTRA      = ${TAF_EXTRA}
1427    TAMC_EXTRA     = ${TAMC_EXTRA}
1428    
1429    EOF
1430    
1431    ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
1432    ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF_FLAGS"
1433    ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
1434    for i in $ad_vars ; do
1435        name=$i
1436        t1="t2=\$"`echo $i`
1437        eval $t1
1438        printf "%-20s = " $name >> $MAKEFILE
1439        echo $t2 >> $MAKEFILE
1440    done
1441    
1442    echo "  Add the source list for AD code generation"
1443    echo >> $MAKEFILE
1444    echo -n "AD_FILES = " >> $MAKEFILE
1445    AD_FILES=`cat ad_files`
1446    for i in $AD_FILES ; do
1447        echo    " \\" >> $MAKEFILE
1448        echo -n " $i" >> $MAKEFILE
1449    done
1450    echo >> $MAKEFILE
1451    rm -f ad_files
1452    
1453    cat >>$MAKEFILE <<EOF
1454    
1455    # ... AD ...
1456    adall: ad_taf
1457    adtaf: ad_taf_output.f
1458    adtamc: ad_tamc_output.f
1459    
1460    ad_input_code.f: \$(AD_FILES) \$(HEADERFILES)
1461            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
1462            @make \$(F77FILES)
1463            @make \$(AD_FLOW_FILES)
1464            cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f
1465    
1466    ad_taf_output.f: ad_input_code.f
1467            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1468            cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f
1469    
1470    ad_taf: ad_taf_output.o \$(OBJFILES)
1471            \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
1472    
1473    ad_tamc_output.f: ad_input_code.f
1474            \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f
1475            cat ad_input_code_ad.f | sed -f adjoint_sed > ad_tamc_output.f
1476    
1477    ad_tamc: ad_tamc_output.o \$(OBJFILES)
1478            \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
1479    
1480    
1481    # ... FTL ...
1482    ftlall: ftl_taf
1483    ftltaf: ftl_taf_output.f
1484    ftltamc: ftl_tamc_output.f
1485    
1486    ftl_input_code.f: \$(AD_FILES) \$(HEADERFILES)
1487            cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
1488            @make \$(F77FILES)
1489            @make \$(AD_FLOW_FILES)
1490            cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f
1491    
1492    ftl_taf_output.f: ftl_input_code.f
1493            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f
1494            cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_taf_output.f
1495    
1496    ftl_taf: ftl_taf_output.o \$(OBJFILES)
1497            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
1498    
1499    ftl_tamc_output.f: ftl_input_code.f
1500            \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f
1501            cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_tamc_output.f
1502    
1503    ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
1504            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
1505    
1506    
1507    # ... SVD ...
1508    svd: svd_taf
1509    svd_taf_f: svd_taf_output.f
1510    
1511    svd_input_code.f: \$(SRCFILES)
1512            cmp svd_config.template AD_CONFIG.h || cat svd_config.template > AD_CONFIG.h
1513            @make \$(F77FILES)
1514            @make \$(AD_FLOW_FILES)
1515            cat \$(AD_FLOW_FILES) \$(AD_FILES) > svd_input_code.f
1516    
1517    svd_taf_output.f: svd_input_code.f
1518            \$(TAF) \$(SVD_TAF_FLAGS) \$(TAF_EXTRA) svd_input_code.f
1519            cat svd_input_code_ad.f | sed -f adjoint_sed > svd_taf_output.f
1520    
1521    svd_taf: svd_taf_output.o \$(OBJFILES)
1522            \$(LINK) -o ${EXE_SVD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) svd_taf_output.o \$(LIBS)
1523    
1524    
1525    #=========================================
1526    
1527  EOF  EOF
1528    
1529  if test "x$EXEHOOK" != x ; then  if test "x$EXEHOOK" != x ; then
# Line 1253  printf "\n\n# DO NOT DELETE\n" >> $MAKEF Line 1560  printf "\n\n# DO NOT DELETE\n" >> $MAKEF
1560    
1561  printf "\n===  Done  ===\n"  printf "\n===  Done  ===\n"
1562    
1563    #  Write the "template" files for the adjoint builds
1564    cat >AD_CONFIG.template <<EOF
1565    C  WARNING: This file is automatically generated by genmake2 and
1566    C    used by the Makefile rules.  Please DO NOT EDIT this file
1567    C    unless you are CERTAIN that you know what you are doing.
1568    
1569    #undef ALLOW_ADJOINT_RUN
1570    #undef ALLOW_TANGENTLINEAR_RUN
1571    #undef ALLOW_ECCO_OPTIMIZATION
1572    EOF
1573    cat >ad_config.template <<EOF
1574    C  WARNING: This file is automatically generated by genmake2 and
1575    C    used by the Makefile rules.  Please DO NOT EDIT this file
1576    C    unless you are CERTAIN that you know what you are doing.
1577    
1578    #define ALLOW_ADJOINT_RUN
1579    #undef ALLOW_TANGENTLINEAR_RUN
1580    #undef ALLOW_ECCO_OPTIMIZATION
1581    EOF
1582    cat >ftl_config.template <<EOF
1583    C  WARNING: This file is automatically generated by genmake2 and
1584    C    used by the Makefile rules.  Please DO NOT EDIT this file
1585    C    unless you are CERTAIN that you know what you are doing.
1586    
1587    #undef ALLOW_ADJOINT_RUN
1588    #define ALLOW_TANGENTLINEAR_RUN
1589    #undef ALLOW_ECCO_OPTIMIZATION
1590    EOF
1591    cat >svd_config.template <<EOF
1592    C  WARNING: This file is automatically generated by genmake2 and
1593    C    used by the Makefile rules.  Please DO NOT EDIT this file
1594    C    unless you are CERTAIN that you know what you are doing.
1595    
1596    #undef ALLOW_ADJOINT_RUN
1597    #undef ALLOW_TANGENTLINEAR_RUN
1598    #undef ALLOW_ECCO_OPTIMIZATION
1599    EOF
1600    cp AD_CONFIG.template AD_CONFIG.h
1601    
1602    
1603  #  Write the "state" for future records  #  Write the "state" for future records
1604  if test "x$DUMPSTATE" != xf ; then  if test "x$DUMPSTATE" != xf ; then

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.31

  ViewVC Help
Powered by ViewVC 1.1.22