/[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.11 by edhill, Mon Sep 29 16:15:23 2003 UTC revision 1.11.2.9 by edhill, Fri Oct 3 18:54:16 2003 UTC
# 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      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/'`      PLATFORM=`echo $tmp2 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
76      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
77      echo "  The platform appears to be:  $PLATFORM"      echo "  The platform appears to be:  $PLATFORM"
78  #     if test "x$OFLIST" = x ; then  #     if test "x$OFLIST" = x ; then
# Line 603  fi Line 661  fi
661  source ./.pd_tmp  source ./.pd_tmp
662  rm -f ./.pd_tmp  rm -f ./.pd_tmp
663    
664    #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"
665    #  file should eventually be added so that, for convenience, one can
666    #  specify groups of packages using names like "ocean" and "atmosphere".
667  echo  -n "  checking default package list:  "  echo  -n "  checking default package list:  "
668  if test "x${PDEFAULT}" = x ; then  if test "x${PDEFAULT}" = x ; then
669        for i in "." $MODS ; do
670            if test -r $i"/packages.conf" ; then
671                    PDEFAULT=$i"/packages.conf"
672                    break
673            fi
674        done
675    fi
676    if test "x${PDEFAULT}" = x ; then
677      PDEFAULT="$ROOTDIR/pkg/pkg_default"      PDEFAULT="$ROOTDIR/pkg/pkg_default"
678  fi  fi
679  if test "x${PDEFAULT}" = xNONE ; then  if test "x${PDEFAULT}" = xNONE ; then
# Line 626  else Line 695  else
695          for i in $def ; do          for i in $def ; do
696              PACKAGES="$PACKAGES $i"              PACKAGES="$PACKAGES $i"
697          done          done
698          echo "    packages are:  $PACKAGES"          echo "    before group expansion packages are: $PACKAGES"
699            expand_pkg_groups
700            echo "    after group expansion packages are:  $PACKAGES"
701      fi      fi
702  fi  fi
703    
# Line 645  for p in $PACKAGES ; do Line 716  for p in $PACKAGES ; do
716  done  done
717  PACKAGES="$pack"  PACKAGES="$pack"
718  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
719  rm -f ./.tmp_pack  echo "" > ./.tmp_pack
720  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
721  for i in $PACKAGES ; do  for i in $PACKAGES ; do
722      if test ! -d "$ROOTDIR/pkg/$i" ; then      if test ! -d "$ROOTDIR/pkg/$i" ; then
# Line 761  done Line 832  done
832  # done  # done
833  # echo  # echo
834    
835  echo "  Searching for CPP_OPTIONS.h (macros and flags for configuring the model):"  # Create a list of #define and #undef to enable/disable packages
836  CPP_OPTIONS=  PACKAGES_DOT_H=PACKAGES_CONFIG.h
837  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  
838  C=== GENMAKE v2 ===  C=== GENMAKE v2 ===
839  C  The following defines have been set by GENMAKE, so please do not  C  The following defines have been set by GENMAKE, so please do not
840  C  edit anything below these comments.  In general, you should  C  edit anything below these comments.  In general, you should
841  C  add or remove packages by re-running genmake with different  C  add or remove packages by re-running genmake with different
842  C  "-enable" and/or "-disable" options.  C  "-enable" and/or "-disable" options.
843    
844    #ifndef PACKAGES_H
845    #define PACKAGES_H
846    
847  C  Packages disabled by genmake:  C  Packages disabled by genmake:
848  EOF  EOF
849  #  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 814  for n in $names ; do Line 863  for n in $names ; do
863          done          done
864          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
865              undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`
866              echo "#undef $undef" >> CPP_OPTIONS.h.tmp              echo "#undef $undef" >> $PACKAGES_DOT_H".tmp"
867    #           DEFINES="$DEFINES -U$undef"
868    
869  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
870              case $n in              case $n in
# Line 824  for n in $names ; do Line 874  for n in $names ; do
874                  mom_vecinv)                  mom_vecinv)
875                      DEFINES="$DEFINES -DDISABLE_MOM_VECINV"                      DEFINES="$DEFINES -DDISABLE_MOM_VECINV"
876                      ;;                      ;;
                 generic_advdiff)  
                     DEFINES="$DEFINES -DDISABLE_GENERIC_ADVDIFF"  
                     ;;  
877                  debug)                  debug)
878                      DEFINES="$DEFINES -DDISABLE_DEBUGMODE"                      DEFINES="$DEFINES -DDISABLE_DEBUGMODE"
879                      ;;                      ;;
# Line 836  for n in $names ; do Line 883  for n in $names ; do
883          fi          fi
884      fi      fi
885  done  done
886  cat <<EOF >>CPP_OPTIONS.h.tmp  cat <<EOF >>$PACKAGES_DOT_H".tmp"
887    
888  C  Packages enabled by genmake:  C  Packages enabled by genmake:
889  EOF  EOF
890  for i in $PACKAGES ; do  for i in $PACKAGES ; do
891      def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`      def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`
892      echo "#define $def" >> CPP_OPTIONS.h.tmp      echo "#define $def" >> $PACKAGES_DOT_H".tmp"
893    #eh3 DEFINES="$DEFINES -D$def"
894    
895  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
896      case $i in      case $i in
897          aim_v23)          aim_v23)
898              echo "#define   ALLOW_AIM" >> CPP_OPTIONS.h.tmp              echo "#define   ALLOW_AIM" >> $PACKAGES_DOT_H".tmp"
899                DEFINES="$DEFINES -DALLOW_AIM"
900                echo "Warning: ALLOW_AIM is set to enable aim_v23. This is REALLY ugly Jean-Michel :-)"
901              ;;              ;;
902      esac      esac
903  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
904    
905  done  done
906  mv -f CPP_OPTIONS.h.tmp CPP_OPTIONS.h  cat <<EOF >>$PACKAGES_DOT_H".tmp"
907    
908    #endif /* PACKAGES_H */
909    EOF
910    
911    if test ! -f $PACKAGES_DOT_H ; then
912        mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
913    else
914        cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
915        RETVAL=$?
916        if test "x$RETVAL" = x0 ; then
917            rm -f $PACKAGES_DOT_H".tmp"
918        else
919            mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
920            mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
921        fi
922    fi
923    
924  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS"
925  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
# Line 877  for d in $STANDARDDIRS ; do Line 943  for d in $STANDARDDIRS ; do
943      fi      fi
944  done  done
945    
946    echo " Searching for CPP_OPTIONS.h in order to warn about the presence"
947    echo " of \"#define ALLOW_PKGNAME\"-type statements:"
948    CPP_OPTIONS=
949    spaths=". $INCLUDEDIRS"
950    for i in $spaths ; do
951        try="$i/CPP_OPTIONS.h"
952        #  echo -n "    trying $try : "
953        if test -f $try -a -r $try ; then
954            echo "    found CPP_OPTIONS=\"$try\""
955            CPP_OPTIONS="$try"
956            break
957        fi
958    done
959    if test "x$CPP_OPTIONS" = x ; then
960        echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
961        exit 1
962    fi
963    # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
964    names=`ls -1 "$ROOTDIR/pkg"`
965    for n in $names ; do
966        test_for_package_in_cpp_options $CPP_OPTIONS $n
967    done
968    
969    
970  echo  echo
971  echo "===  Creating the Makefile  ==="  echo "===  Creating the Makefile  ==="
972  echo "  setting INCLUDES"  echo "  setting INCLUDES"
973  for i in $INCLUDEDIRS ; do  for i in $INCLUDEDIRS ; do
974      if test -d $i ; then      if ! test -d $i ; then
975          INCLUDES="$INCLUDES -I$i"  #       INCLUDES="$INCLUDES -I$i"
976      else  #   else
977          echo "Warning: can't find INCLUDEDIRS=\"$i\""          echo "Warning: can't find INCLUDEDIRS=\"$i\""
978      fi      fi
979  done  done
# Line 1064  clean: Line 1153  clean:
1153  Clean:  Clean:
1154          @make clean          @make clean
1155          @make cleanlinks          @make cleanlinks
1156          -rm -f Makefile.bak          -rm -f Makefile.bak gm_state gm_optfile make.log
1157  CLEAN:  CLEAN:
1158          @make Clean          @make Clean
1159          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
1160          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
1161          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
1162          -rm -f \$(EXECUTABLE)          -rm -f \$(EXECUTABLE) output.txt
1163    
1164  makefile:  makefile:
1165          ${0} $@          ${0} $@

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.11.2.9

  ViewVC Help
Powered by ViewVC 1.1.22