/[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.14 by edhill, Tue Oct 21 15:29:20 2003 UTC revision 1.23 by edhill, Fri Oct 24 05:52:05 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 121  EOF Line 121  EOF
121              p_FC="$p_FC $c"              p_FC="$p_FC $c"
122          fi          fi
123      done      done
124        rm -f ./hello.f ./hello
125      if test "x${p_FC}" = x ; then      if test "x${p_FC}" = x ; then
126          cat 1>&2 <<EOF          cat 1>&2 <<EOF
127    
# Line 136  EOF Line 137  EOF
137          echo "  The possible FORTRAN compilers found in your path are:"          echo "  The possible FORTRAN compilers found in your path are:"
138          echo "   "$p_FC          echo "   "$p_FC
139          if test "x$FC" = x ; then          if test "x$FC" = x ; then
140              FC=`echo $p_FC | awk '{print $1}'`              FC=`echo $p_FC | $AWK '{print $1}'`
141          fi          fi
142      fi      fi
143    
# Line 202  get_pdepend_list()  { Line 203  get_pdepend_list()  {
203      #  strip the comments and then convert the dependency file into      #  strip the comments and then convert the dependency file into
204      #  two arrays: PNAME, DNAME      #  two arrays: PNAME, DNAME
205      cat $1 | sed -e 's/#.*$//g' \      cat $1 | sed -e 's/#.*$//g' \
206          | awk 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \          | $AWK 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \
207          > ./.pd_tmp          > ./.pd_tmp
208      source ./.pd_tmp      source ./.pd_tmp
209      rm -f ./.pd_tmp      rm -f ./.pd_tmp
# Line 319  STANDARDDIRS= Line 320  STANDARDDIRS=
320    
321  PWD=`pwd`  PWD=`pwd`
322  MAKE=make  MAKE=make
323    AWK=awk
324  THISHOSTNAME=`hostname`  THISHOSTNAME=`hostname`
325  THISCWD=`pwd`  THISCWD=`pwd`
326  THISDATE=`date`  THISDATE=`date`
# Line 334  fi Line 336  fi
336    
337  AUTODIFF_PKG_USED=f  AUTODIFF_PKG_USED=f
338  AD_OPTFILE=  AD_OPTFILE=
339    TAF=
340    AD_TAF_FLAGS=
341    FTL_TAF_FLAGS=
342    SVD_TAF_FLAGS=
343    TAF_EXTRA=
344    TAMC=
345    AD_TAMC_FLAGS=
346    FTL_TAF_FLAGS=
347    SVD_TAMC_FLAGS=
348    TAMC_EXTRA=
349    
350    
351  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
352  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"
# Line 346  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS P Line 359  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS P
359  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
360    
361  #  The following are all related to adjoint/tangent-linear stuff  #  The following are all related to adjoint/tangent-linear stuff
362  gm_s7="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF DIFF_FLAGS AD_TAMC_FLAGS AD_TAF_FLAGS"  gm_s7="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
363  gm_s8="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"  gm_s8="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
364  gm_s9=""  gm_s9="TAF_EXTRA TAMC_EXTRA"
365    
366  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7 $gm_s8"  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7 $gm_s8 $gm_s9"
367    
368    
369  echo  echo
# Line 495  for ac_option ; do Line 508  for ac_option ; do
508          -ds | --ds)          -ds | --ds)
509              DUMPSTATE=t ;;              DUMPSTATE=t ;;
510                    
511            -taf_extra | --taf_extra)
512                ac_prev=TAF_EXTRA ;;
513            -taf_extra=* | --taf_extra=*)
514                TAF_EXTRA=$ac_optarg ;;
515    
516            -tamc_extra | --tamc_extra)
517                ac_prev=TAMC_EXTRA ;;
518            -tamc_extra=* | --tamc_extra=*)
519                TAMC_EXTRA=$ac_optarg ;;
520    
521          -*)          -*)
522              echo "Error: unrecognized option: "$ac_option              echo "Error: unrecognized option: "$ac_option
523              usage              usage
# Line 721  echo "  getting package dependency info Line 744  echo "  getting package dependency info
744  #  Strip the comments and then convert the dependency file into  #  Strip the comments and then convert the dependency file into
745  #  two arrays: PNAME, DNAME  #  two arrays: PNAME, DNAME
746  cat $PDEPEND | sed -e 's/#.*$//g' \  cat $PDEPEND | sed -e 's/#.*$//g' \
747      | 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}' \
748      > ./.pd_tmp      > ./.pd_tmp
749  RETVAL=$?  RETVAL=$?
750  if test ! "x${RETVAL}" = x0 ; then  if test ! "x${RETVAL}" = x0 ; then
# Line 755  else Line 778  else
778      else      else
779          echo "  using PDEFAULT=\"$PDEFAULT\""          echo "  using PDEFAULT=\"$PDEFAULT\""
780          #  Strip the comments and add all the names          #  Strip the comments and add all the names
781          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | awk '(NF>0){print $0}'`          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
782          RETVAL=$?          RETVAL=$?
783          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
784              echo -n "Error: can't parse default package list "              echo -n "Error: can't parse default package list "
# Line 935  for n in $names ; do Line 958  for n in $names ; do
958              fi              fi
959          done          done
960          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
961              undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`
962              echo "#undef $undef" >> $PACKAGES_DOT_H".tmp"              echo "#undef $undef" >> $PACKAGES_DOT_H".tmp"
963  #           DEFINES="$DEFINES -U$undef"  #           DEFINES="$DEFINES -U$undef"
964    
# Line 961  cat <<EOF >>$PACKAGES_DOT_H".tmp" Line 984  cat <<EOF >>$PACKAGES_DOT_H".tmp"
984  C  Packages enabled by genmake:  C  Packages enabled by genmake:
985  EOF  EOF
986  for i in $PACKAGES ; do  for i in $PACKAGES ; do
987      def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`      def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`
988      echo "#define $def" >> $PACKAGES_DOT_H".tmp"      echo "#define $def" >> $PACKAGES_DOT_H".tmp"
989  #eh3 DEFINES="$DEFINES -D$def"  #eh3 DEFINES="$DEFINES -D$def"
990    
# Line 1018  for d in $STANDARDDIRS ; do Line 1041  for d in $STANDARDDIRS ; do
1041      fi      fi
1042  done  done
1043    
1044  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"
1045  echo " of \"#define ALLOW_PKGNAME\"-type statements:"  echo "    of \"#define ALLOW_PKGNAME\"-type statements:"
1046  CPP_OPTIONS=  CPP_OPTIONS=
1047  spaths=". $INCLUDEDIRS"  spaths=". $INCLUDEDIRS"
1048  for i in $spaths ; do  for i in $spaths ; do
# Line 1096  for d in $alldirs ; do Line 1119  for d in $alldirs ; do
1119      for sf in $sfiles ; do      for sf in $sfiles ; do
1120          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
1121              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
1122                  extn=`echo $sf | awk -F '.' '{print $NF}'`                  extn=`echo $sf | $AWK -F '.' '{print $NF}'`
1123                  touch .links.tmp/$sf                  touch .links.tmp/$sf
1124                  deplist="$deplist $sf"                  deplist="$deplist $sf"
1125                  case $extn in                  case $extn in
# Line 1150  echo "# by the command:" >> $MAKEFILE Line 1173  echo "# by the command:" >> $MAKEFILE
1173  echo "#    $0 $@" >> $MAKEFILE  echo "#    $0 $@" >> $MAKEFILE
1174  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
1175  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE
1176    
1177    EXE_AD=$EXECUTABLE"_ad"
1178    EXE_FTL=$EXECUTABLE"_ftl"
1179    EXE_SVD=$EXECUTABLE"_svd"
1180    
1181  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
1182  #  #
1183  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
# Line 1180  TOOLSDIR    = ${TOOLSDIR} Line 1208  TOOLSDIR    = ${TOOLSDIR}
1208    
1209  #eh3  new defines for the adjoint work  #eh3  new defines for the adjoint work
1210  AUTODIFF    = ${ROOTDIR}/pkg/autodiff  AUTODIFF    = ${ROOTDIR}/pkg/autodiff
1211    EXE_AD      = ${EXE_AD}
1212    EXE_FTL     = ${EXE_FTL}
1213    EXE_SVD     = ${EXE_SVD}
1214    
1215  EOF  EOF
1216    
# Line 1261  output.txt: \$(EXECUTABLE) Line 1292  output.txt: \$(EXECUTABLE)
1292          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
1293    
1294  clean:  clean:
1295            -cat AD_CONFIG.template > AD_CONFIG.h
1296          -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}          -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}
1297  Clean:  Clean:
1298          @make clean          @make clean
1299          @make cleanlinks          @make cleanlinks
1300          -rm -f Makefile.bak genmake_state genmake_optfile make.log          -rm -f Makefile.bak genmake_state genmake_*optfile make.log
1301  CLEAN:  CLEAN:
1302          @make Clean          @make Clean
1303          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
# Line 1273  CLEAN: Line 1305  CLEAN:
1305          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
1306          -rm -f \$(EXECUTABLE) output.txt          -rm -f \$(EXECUTABLE) output.txt
1307    
1308  Makefile: makefile  #eh3 Makefile: makefile
1309  makefile:  makefile:
1310          ${0} $@          ${0} $@
1311  cleanlinks:  cleanlinks:
# Line 1303  cleanlinks: Line 1335  cleanlinks:
1335  TAMC           = ${TAMC}  TAMC           = ${TAMC}
1336  TAF            = ${TAF}  TAF            = ${TAF}
1337    
1338    TAF_EXTRA      = ${TAF_EXTRA}
1339    TAMC_EXTRA     = ${TAMC_EXTRA}
1340    
1341  EOF  EOF
1342    
1343  ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"  ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
# Line 1325  for i in $AD_FILES ; do Line 1360  for i in $AD_FILES ; do
1360      echo -n " $i" >> $MAKEFILE      echo -n " $i" >> $MAKEFILE
1361  done  done
1362  echo >> $MAKEFILE  echo >> $MAKEFILE
1363    rm -f ad_files
1364    
1365  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
1366    
1367    # ... AD ...
1368  ad_input_code.f: \$(F77FILES)  adall: ad_taf
1369    adtaf: ad_taf_output.f
1370    adtamc: ad_tamc_output.f
1371    
1372    ad_input_code.f: \$(SRCFILES) \$(HEADERFILES)
1373            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
1374            @make \$(F77FILES)
1375          @make \$(AD_FLOW_FILES)          @make \$(AD_FLOW_FILES)
1376          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f
1377    
   
1378  ad_taf_output.f: ad_input_code.f  ad_taf_output.f: ad_input_code.f
1379          \$(TAF) \$(AD_TAF_FLAGS) ad_input_code.f          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1380          cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f          cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f
1381    
1382  ad_taf: ad_taf_output.o \$(OBJFILES)  ad_taf: ad_taf_output.o \$(OBJFILES)
1383          \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
   
1384    
1385  ad_tamc_output.f: ad_input_code.f  ad_tamc_output.f: ad_input_code.f
1386          \$(TAMC) \$(AD_TAMC_FLAGS) ad_input_code.f          \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f
1387          cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f          cat ad_input_code_ad.f | sed -f adjoint_sed > ad_tamc_output.f
1388    
1389  ad_tamc: ad_tamc_output.o \$(OBJFILES)  ad_tamc: ad_tamc_output.o \$(OBJFILES)
1390          \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
1391    
1392    
1393    # ... FTL ...
1394    ftlall: ftl_taf
1395    ftltaf: ftl_taf_output.f
1396    ftltamc: ftl_tamc_output.f
1397    
1398    ftl_input_code.f: \$(SRCFILES)
1399            cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
1400            @make \$(F77FILES)
1401            @make \$(AD_FLOW_FILES)
1402            cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f
1403    
1404    ftl_taf_output.f: ftl_input_code.f
1405            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f
1406            cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_taf_output.f
1407    
1408    ftl_taf: ftl_taf_output.o \$(OBJFILES)
1409            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
1410    
1411    ftl_tamc_output.f: ftl_input_code.f
1412            \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f
1413            cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_tamc_output.f
1414    
1415    ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
1416            \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
1417    
1418    
1419    # ... SVD ...
1420    svd: svd_taf
1421    svd_taf_f: svd_taf_output.f
1422    
1423  flt_taf_output.f: ad_input_code.f  svd_input_code.f: \$(SRCFILES)
1424          \$(TAF) \$(FTL_TAF_FLAGS) ad_input_code.f          cmp svd_config.template AD_CONFIG.h || cat svd_config.template > AD_CONFIG.h
1425          cat ad_input_code_ad.f | sed -f adjoint_sed > flt_taf_output.f          @make \$(F77FILES)
1426            @make \$(AD_FLOW_FILES)
1427            cat \$(AD_FLOW_FILES) \$(AD_FILES) > svd_input_code.f
1428    
1429  flt_taf: flt_taf_output.o \$(OBJFILES)  svd_taf_output.f: svd_input_code.f
1430          \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) flt_taf_output.o \$(LIBS)          \$(TAF) \$(SVD_TAF_FLAGS) \$(TAF_EXTRA) svd_input_code.f
1431            cat svd_input_code_ad.f | sed -f adjoint_sed > svd_taf_output.f
1432    
1433    svd_taf: svd_taf_output.o \$(OBJFILES)
1434            \$(LINK) -o ${EXE_SVD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) svd_taf_output.o \$(LIBS)
1435    
1436    
1437  #=========================================  #=========================================
# Line 1397  printf "\n\n# DO NOT DELETE\n" >> $MAKEF Line 1472  printf "\n\n# DO NOT DELETE\n" >> $MAKEF
1472    
1473  printf "\n===  Done  ===\n"  printf "\n===  Done  ===\n"
1474    
1475    #  Write the "template" files for the adjoint builds
1476    cat >AD_CONFIG.template <<EOF
1477    C  WARNING: This file is automatically generated by genmake2 and
1478    C    used by the Makefile rules.  Please DO NOT EDIT this file
1479    C    unless you are CERTAIN that you know what you are doing.
1480    
1481    #undef ALLOW_ADJOINT_RUN
1482    #undef ALLOW_TANGENTLINEAR_RUN
1483    #undef ALLOW_ECCO_OPTIMIZATION
1484    EOF
1485    cat >ad_config.template <<EOF
1486    C  WARNING: This file is automatically generated by genmake2 and
1487    C    used by the Makefile rules.  Please DO NOT EDIT this file
1488    C    unless you are CERTAIN that you know what you are doing.
1489    
1490    #define ALLOW_ADJOINT_RUN
1491    #undef ALLOW_TANGENTLINEAR_RUN
1492    #undef ALLOW_ECCO_OPTIMIZATION
1493    EOF
1494    cat >ftl_config.template <<EOF
1495    C  WARNING: This file is automatically generated by genmake2 and
1496    C    used by the Makefile rules.  Please DO NOT EDIT this file
1497    C    unless you are CERTAIN that you know what you are doing.
1498    
1499    #undef ALLOW_ADJOINT_RUN
1500    #define ALLOW_TANGENTLINEAR_RUN
1501    #undef ALLOW_ECCO_OPTIMIZATION
1502    EOF
1503    cat >svd_config.template <<EOF
1504    C  WARNING: This file is automatically generated by genmake2 and
1505    C    used by the Makefile rules.  Please DO NOT EDIT this file
1506    C    unless you are CERTAIN that you know what you are doing.
1507    
1508    #undef ALLOW_ADJOINT_RUN
1509    #undef ALLOW_TANGENTLINEAR_RUN
1510    #undef ALLOW_ECCO_OPTIMIZATION
1511    EOF
1512    cp AD_CONFIG.template AD_CONFIG.h
1513    
1514    
1515  #  Write the "state" for future records  #  Write the "state" for future records
1516  if test "x$DUMPSTATE" != xf ; then  if test "x$DUMPSTATE" != xf ; then

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.23

  ViewVC Help
Powered by ViewVC 1.1.22