/[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.11 by edhill, Sat Oct 4 13:56:40 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 181  usage()  { Line 239  usage()  {
239      echo "      -disable=NAME | --disable=NAME"      echo "      -disable=NAME | --disable=NAME"
240      echo "    -enable NAME | --enable NAME"      echo "    -enable NAME | --enable NAME"
241      echo "      -enable=NAME | --enable=NAME"      echo "      -enable=NAME | --enable=NAME"
242        echo "    -standarddirs NAME | --standarddirs NAME"
243        echo "      -standarddirs=NAME | --standarddirs=NAME"
244      echo "    -noopt NAME | --noopt NAME"      echo "    -noopt NAME | --noopt NAME"
245      echo "      -noopt=NAME | --noopt=NAME"      echo "      -noopt=NAME | --noopt=NAME"
246  #    echo "    -cpp NAME | --cpp NAME"  #    echo "    -cpp NAME | --cpp NAME"
# Line 255  MODS= Line 315  MODS=
315  TOOLSDIR=  TOOLSDIR=
316  SOURCEDIRS=  SOURCEDIRS=
317  INCLUDEDIRS=  INCLUDEDIRS=
318    STANDARDDIRS=
319    
320  PWD=`pwd`  PWD=`pwd`
321  MAKE=make  MAKE=make
# Line 265  MACHINE=`uname -a` Line 326  MACHINE=`uname -a`
326  EXECUTABLE=  EXECUTABLE=
327  EXEHOOK=  EXEHOOK=
328  EXEDIR=  EXEDIR=
329    PACKAGES_CONF=
330    if test "x$MITGCM_IEEE" != x ; then
331        IEEE=$MITGCM_IEEE
332    fi
333    
334  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
335  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"
336  gm_s2="FC IEEE MPI JAM DUMPSTATE"  gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS"
337    
338  #  The following state is not directly set by command-line switches  #  The following state is not directly set by command-line switches
339  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 "
340  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
341  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"
342  gm_s6="EXECUTABLE EXEHOOK EXEDIR"  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
343    
344  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"
345    
346    
347  echo  echo
348  echo "===  Processing options files and arguments  ==="  echo "===  Processing options files and arguments  ==="
349  gm_local="./gm_local"  gm_local="genmake_local"
350    for i in . $MODS ; do
351        if test -r $i/$gm_local ; then
352            source $i/$gm_local
353            break
354        fi
355    done
356  echo -n "  getting local config information:  "  echo -n "  getting local config information:  "
357  if test -e $gm_local ; then  if test -e $gm_local ; then
358      echo "using $gm_local"      echo "using $gm_local"
# Line 373  for ac_option ; do Line 444  for ac_option ; do
444          -enable=* | --enable=*)          -enable=* | --enable=*)
445              ENABLE=$ac_optarg ;;              ENABLE=$ac_optarg ;;
446                    
447            -standarddirs | --standarddirs)
448                ac_prev=STANDARDDIRS ;;
449            -standarddirs=* | --standarddirs=*)
450                STANDARDDIRS=$ac_optarg ;;
451    
452          -noopt | --noopt)          -noopt | --noopt)
453              ac_prev=NOOPT ;;              ac_prev=NOOPT ;;
454          -noopt=* | --noopt=*)          -noopt=* | --noopt=*)
# Line 389  for ac_option ; do Line 465  for ac_option ; do
465              FC=$ac_optarg ;;              FC=$ac_optarg ;;
466                    
467          -ieee | --ieee)          -ieee | --ieee)
468              IEEE=1 ;;              IEEE=true ;;
469          -noieee | --noieee)          -noieee | --noieee)
470              IEEE=0 ;;              IEEE= ;;
471                    
472          -mpi | --mpi)          -mpi | --mpi)
473              MPI=1 ;;              MPI=true ;;
474          -nompi | --nompi)          -nompi | --nompi)
475              MPI=0 ;;              MPI= ;;
476                    
477          -jam | --jam)          -jam | --jam)
478              JAM=1 ;;              JAM=1 ;;
# Line 466  if test "x$OPTFILE" != xNONE ; then Line 542  if test "x$OPTFILE" != xNONE ; then
542              exit 1              exit 1
543          fi          fi
544          if test "x$DUMPSTATE" != xf ; then          if test "x$DUMPSTATE" != xf ; then
545              cp -f $OPTFILE "gm_optfile"              cp -f $OPTFILE "genmake_optfile"
546          fi          fi
547      else      else
548          echo "Error: can't read OPTFILE=\"$OPTFILE\""          echo "Error: can't read OPTFILE=\"$OPTFILE\""
# Line 482  if test "x$FC" = x ; then Line 558  if test "x$FC" = x ; then
558  Error: no Fortran compiler: please specify using one of the following:  Error: no Fortran compiler: please specify using one of the following:
559    1) within the options file ("FC=...") as specified by "-of=OPTFILE"    1) within the options file ("FC=...") as specified by "-of=OPTFILE"
560    2) the "-fc=XXX" command-line option    2) the "-fc=XXX" command-line option
561    3) the "./gm_local" file    3) the "./genmake_local" file
562  EOF  EOF
563      exit 1      exit 1
564  fi  fi
# Line 500  if test "x$RETVAL" != x0 ; then Line 576  if test "x$RETVAL" != x0 ; then
576  Error: C pre-processor "$CPP" failed the test case: please specify using:  Error: C pre-processor "$CPP" failed the test case: please specify using:
577    
578    1) within the options file ("CPP=...") as specified by "-of=OPTFILE"    1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
579    2) the "./gm_local" file    2) the "./genmake_local" file
580    
581  EOF  EOF
582      exit 1      exit 1
# Line 603  fi Line 679  fi
679  source ./.pd_tmp  source ./.pd_tmp
680  rm -f ./.pd_tmp  rm -f ./.pd_tmp
681    
682    #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"
683    #  file should eventually be added so that, for convenience, one can
684    #  specify groups of packages using names like "ocean" and "atmosphere".
685  echo  -n "  checking default package list:  "  echo  -n "  checking default package list:  "
686  if test "x${PDEFAULT}" = x ; then  if test "x${PDEFAULT}" = x ; then
687        for i in "." $MODS ; do
688            if test -r $i"/packages.conf" ; then
689                    PDEFAULT=$i"/packages.conf"
690                    break
691            fi
692        done
693    fi
694    if test "x${PDEFAULT}" = x ; then
695      PDEFAULT="$ROOTDIR/pkg/pkg_default"      PDEFAULT="$ROOTDIR/pkg/pkg_default"
696  fi  fi
697  if test "x${PDEFAULT}" = xNONE ; then  if test "x${PDEFAULT}" = xNONE ; then
# Line 626  else Line 713  else
713          for i in $def ; do          for i in $def ; do
714              PACKAGES="$PACKAGES $i"              PACKAGES="$PACKAGES $i"
715          done          done
716          echo "    packages are:  $PACKAGES"          echo "    before group expansion packages are: $PACKAGES"
717            expand_pkg_groups
718            echo "    after group expansion packages are:  $PACKAGES"
719      fi      fi
720  fi  fi
721    
# Line 645  for p in $PACKAGES ; do Line 734  for p in $PACKAGES ; do
734  done  done
735  PACKAGES="$pack"  PACKAGES="$pack"
736  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
737  rm -f ./.tmp_pack  echo "" > ./.tmp_pack
738  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
739  for i in $PACKAGES ; do  for i in $PACKAGES ; do
740      if test ! -d "$ROOTDIR/pkg/$i" ; then      if test ! -d "$ROOTDIR/pkg/$i" ; then
# Line 761  done Line 850  done
850  # done  # done
851  # echo  # echo
852    
853  echo "  Searching for CPP_OPTIONS.h (macros and flags for configuring the model):"  # Create a list of #define and #undef to enable/disable packages
854  CPP_OPTIONS=  PACKAGES_DOT_H=PACKAGES_CONFIG.h
855  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  
856  C=== GENMAKE v2 ===  C=== GENMAKE v2 ===
857  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
858  C  edit anything below these comments.  In general, you should  C  edit anything below these comments.  In general, you should
859  C  add or remove packages by re-running genmake with different  C  add or remove packages by re-running genmake with different
860  C  "-enable" and/or "-disable" options.  C  "-enable" and/or "-disable" options.
861    
862    #ifndef PACKAGES_H
863    #define PACKAGES_H
864    
865  C  Packages disabled by genmake:  C  Packages disabled by genmake:
866  EOF  EOF
867  #  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 881  for n in $names ; do
881          done          done
882          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
883              undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`
884              echo "#undef $undef" >> CPP_OPTIONS.h.tmp              echo "#undef $undef" >> $PACKAGES_DOT_H".tmp"
885    #           DEFINES="$DEFINES -U$undef"
886    
887  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
888              case $n in              case $n in
# Line 824  for n in $names ; do Line 892  for n in $names ; do
892                  mom_vecinv)                  mom_vecinv)
893                      DEFINES="$DEFINES -DDISABLE_MOM_VECINV"                      DEFINES="$DEFINES -DDISABLE_MOM_VECINV"
894                      ;;                      ;;
                 generic_advdiff)  
                     DEFINES="$DEFINES -DDISABLE_GENERIC_ADVDIFF"  
                     ;;  
895                  debug)                  debug)
896                      DEFINES="$DEFINES -DDISABLE_DEBUGMODE"                      DEFINES="$DEFINES -DDISABLE_DEBUGMODE"
897                      ;;                      ;;
# Line 836  for n in $names ; do Line 901  for n in $names ; do
901          fi          fi
902      fi      fi
903  done  done
904  cat <<EOF >>CPP_OPTIONS.h.tmp  cat <<EOF >>$PACKAGES_DOT_H".tmp"
905    
906  C  Packages enabled by genmake:  C  Packages enabled by genmake:
907  EOF  EOF
908  for i in $PACKAGES ; do  for i in $PACKAGES ; do
909      def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`      def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`
910      echo "#define $def" >> CPP_OPTIONS.h.tmp      echo "#define $def" >> $PACKAGES_DOT_H".tmp"
911    #eh3 DEFINES="$DEFINES -D$def"
912    
913  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
914      case $i in      case $i in
915          aim_v23)          aim_v23)
916              echo "#define   ALLOW_AIM" >> CPP_OPTIONS.h.tmp              echo "#define   ALLOW_AIM" >> $PACKAGES_DOT_H".tmp"
917                DEFINES="$DEFINES -DALLOW_AIM"
918                echo "Warning: ALLOW_AIM is set to enable aim_v23. This is REALLY ugly Jean-Michel :-)"
919              ;;              ;;
920      esac      esac
921  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
922    
923  done  done
924  mv -f CPP_OPTIONS.h.tmp CPP_OPTIONS.h  cat <<EOF >>$PACKAGES_DOT_H".tmp"
925    
926    #endif /* PACKAGES_H */
927    EOF
928    
929    if test ! -f $PACKAGES_DOT_H ; then
930        mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
931    else
932        cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
933        RETVAL=$?
934        if test "x$RETVAL" = x0 ; then
935            rm -f $PACKAGES_DOT_H".tmp"
936        else
937            mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
938            mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
939        fi
940    fi
941    
942  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS"
943  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
944  STANDARDDIRS=${STANDARDDIRS:-"eesupp model"}  if test "x$STANDARDDIRS" = x ; then
945        STANDARDDIRS="eesupp model"
946    fi
947  for d in $STANDARDDIRS ; do  for d in $STANDARDDIRS ; do
948      adr="$ROOTDIR/$d/src"      adr="$ROOTDIR/$d/src"
949      if test ! -d $adr ; then      if test ! -d $adr ; then
# Line 877  for d in $STANDARDDIRS ; do Line 963  for d in $STANDARDDIRS ; do
963      fi      fi
964  done  done
965    
966    echo " Searching for CPP_OPTIONS.h in order to warn about the presence"
967    echo " of \"#define ALLOW_PKGNAME\"-type statements:"
968    CPP_OPTIONS=
969    spaths=". $INCLUDEDIRS"
970    for i in $spaths ; do
971        try="$i/CPP_OPTIONS.h"
972        #  echo -n "    trying $try : "
973        if test -f $try -a -r $try ; then
974            echo "    found CPP_OPTIONS=\"$try\""
975            CPP_OPTIONS="$try"
976            break
977        fi
978    done
979    if test "x$CPP_OPTIONS" = x ; then
980        echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
981        exit 1
982    fi
983    # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
984    names=`ls -1 "$ROOTDIR/pkg"`
985    for n in $names ; do
986        test_for_package_in_cpp_options $CPP_OPTIONS $n
987    done
988    
989    
990  echo  echo
991  echo "===  Creating the Makefile  ==="  echo "===  Creating the Makefile  ==="
992  echo "  setting INCLUDES"  echo "  setting INCLUDES"
993  for i in $INCLUDEDIRS ; do  for i in $INCLUDEDIRS ; do
994      if test -d $i ; then      if ! test -d $i ; then
995          INCLUDES="$INCLUDES -I$i"  #       INCLUDES="$INCLUDES -I$i"
996      else  #   else
997          echo "Warning: can't find INCLUDEDIRS=\"$i\""          echo "Warning: can't find INCLUDEDIRS=\"$i\""
998      fi      fi
999  done  done
# Line 1064  clean: Line 1173  clean:
1173  Clean:  Clean:
1174          @make clean          @make clean
1175          @make cleanlinks          @make cleanlinks
1176          -rm -f Makefile.bak          -rm -f Makefile.bak genmake_state genmake_optfile make.log
1177  CLEAN:  CLEAN:
1178          @make Clean          @make Clean
1179          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
1180          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
1181          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
1182          -rm -f \$(EXECUTABLE)          -rm -f \$(EXECUTABLE) output.txt
1183    
1184  makefile:  makefile:
1185          ${0} $@          ${0} $@
# Line 1134  printf "\n===  Done  ===\n" Line 1243  printf "\n===  Done  ===\n"
1243    
1244  #  Write the "state" for future records  #  Write the "state" for future records
1245  if test "x$DUMPSTATE" != xf ; then  if test "x$DUMPSTATE" != xf ; then
1246      echo -n "" > gm_state      echo -n "" > genmake_state
1247      for i in $gm_state ; do      for i in $gm_state ; do
1248          t1="t2=\$$i"          t1="t2=\$$i"
1249          eval $t1          eval $t1
1250          echo "$i='$t2'" >> gm_state          echo "$i='$t2'" >> genmake_state
1251      done      done
1252  fi  fi

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

  ViewVC Help
Powered by ViewVC 1.1.22