/[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.3 by cnh, Fri Aug 22 20:50:40 2003 UTC revision 1.11.2.1 by adcroft, Wed Oct 1 18:44:48 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    
43  # Guess possible config options for this host  # Guess possible config options for this host
44  find_possible_configs()  {  find_possible_configs()  {
45    
46      p_PLATFORM=`uname`"-"`uname -m`      tmp1=`uname`"_"`uname -m`
47      echo "The platform appears to be:"      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
48      echo "  "$p_PLATFORM      PLATFORM=`echo $tmp2 | sed -e 's/i[3-6]86/ia32/'`
49        OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
50      p_LN=      echo "  The platform appears to be:  $PLATFORM"
51    #     if test "x$OFLIST" = x ; then
52    #       echo "  No pre-defined options files were found matching this platform"
53    #       echo "  but examples for other platforms can be found in:"
54    #       echo "    $ROOTDIR/tools/build_options"
55    #     else
56    #       echo "  Options files (located in $ROOTDIR/tools/build_options) that"
57    #       echo "  may work with this machine are:"
58    #       for i in $OFLIST ; do
59    #           echo "    $i"
60    #       done
61    #     fi
62        
63      echo "test" > test      echo "test" > test
64      ln -s ./test link      ln -s ./test link
65      RETVAL=$?      RETVAL=$?
66      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
67          p_LN="ln -s"          LN="ln -s"
68        else
69            echo "Error: \"ln -s\" does not appear to work on this system!"
70            echo "  For help, please contact <MITgcm-support@mitgcm.org>."
71            exit 1
72      fi      fi
73      rm -f test link      rm -f test link
74    
75      p_CPP=`which cpp`      if test "x$CPP" = x ; then
76                CPP="cpp -traditional -P"
     RETVAL=$?  
     if test "x${RETVAL}" = x0 ; then  
         p_LN="ln -s"  
77      fi      fi
     rm -f test link  
78    
79      # look for possible fortran compilers      # look for possible fortran compilers
80        tmp="$MITGCM_FC $FC g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"
81      p_FC=      p_FC=
82      for c in f77 g77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 ; do      for c in $tmp ; do
83          which $c > /dev/null 2>&1          rm -f ./hello.f ./hello
84            cat >> hello.f <<EOF
85          program hello
86          do i=1,3
87            print *, 'hello world : ', i
88          enddo
89          end
90    EOF
91            $c -o hello hello.f > /dev/null 2>&1
92          RETVAL=$?          RETVAL=$?
93          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
94              p_FC="$p_FC $c"              p_FC="$p_FC $c"
95          fi          fi
96      done      done
     echo "Possible FORTRAN compilers appear to be:  "  
97      if test "x${p_FC}" = x ; then      if test "x${p_FC}" = x ; then
98          echo "  None found!!!"          cat 1>&2 <<EOF
99      else  
100          echo "  "$p_FC  Error: No Fortran compilers were found in your path.  Please specify one using:
101      fi  
102        1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
103        2) a command-line option (eg. "-fc NAME"), or
104        3) the MITGCM_FC environment variable.
105    
     # look for possible MPI libraries  
     mpi_libs=  
     mpi_fort=`which mpif77 2>/dev/null`  
     RETVAL=$?  
     if test "x${RETVAL}" = x0 ; then  
         cat >>test.f <<EOF  
       PROGRAM HELLO  
       DO 10, I=1,10  
       PRINT *,'Hello World'  
    10 CONTINUE  
       STOP  
       END  
106  EOF  EOF
107          eval "$mpi_fort -showme test.f > out"          exit 1
108          RETVAL=$?      else
109          if test "x${RETVAL}" = x0 ; then          echo "  The possible FORTRAN compilers found in your path are:"
110              a=`cat out`          echo "   "$p_FC
111              for i in $a ; do          if test "x$FC" = x ; then
112                  case $i in              FC=`echo $p_FC | awk '{print $1}'`
                     -*)  
                         mpi_libs="$mpi_libs $i" ;;  
                 esac  
             done  
             echo "The MPI libs appear to be:"  
             echo "  "$mpi_libs  
113          fi          fi
         rm -f test.f out  
114      fi      fi
115    
116  }      for i in $p_FC ; do
117            p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
118            if test -r $p_OF ; then
119                OPTFILE=$p_OF
120                echo "  The options file:  $p_OF"
121                echo "    appears to match so we'll use it."
122                break
123            fi
124        done
125        if test "x$OPTFILE" = x ; then
126            cat 1>&2 <<EOF
127    
128  parse_options()  {  Error: No options file was found in:  $ROOTDIR/tools/build_options/
129      that matches this platform ("$PLATFORM") and the compilers found in
130      your path.  Please specify an "optfile" using:
131    
132      ac_prev=      1) the command line (eg. "-optfile=path/to/OPTFILE"), or
133      for ac_option in "${OPTIONS[@]}" ; do      2) the MITGCM_OF environment variable.
134    
135      If you need help, please contact the developers at <MITgcm-support@mitgcm.org>.
136    
137    EOF
138            exit 1
139        fi
140        
141    #     # look for possible MPI libraries
142    #     mpi_libs=
143    #     mpi_fort=`which mpif77 2>/dev/null`
144    #     RETVAL=$?
145    #     if test "x${RETVAL}" = x0 ; then
146    #       cat >>test.f <<EOF
147    #       PROGRAM HELLO
148    #       DO 10, I=1,10
149    #       PRINT *,'Hello World'
150    #    10 CONTINUE
151    #       STOP
152    #       END
153    # EOF
154    #       eval "$mpi_fort -showme test.f > out"
155    #       RETVAL=$?
156    #       if test "x${RETVAL}" = x0 ; then
157    #           a=`cat out`
158    #           for i in $a ; do
159    #               case $i in
160    #                   -*)
161    #                       mpi_libs="$mpi_libs $i" ;;
162    #               esac
163    #           done
164    #           echo "The MPI libs appear to be:"
165    #           echo "  "$mpi_libs
166    #       fi
167    #       rm -f test.f out
168    #     fi
169    
         # echo "ac_option = :$ac_option:"  
           
         # If the previous option needs an argument, assign it.  
         if test -n "$ac_prev"; then  
             eval "$ac_prev=\$ac_option"  
             ac_prev=  
             continue  
         fi  
           
         ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`  
           
         case $ac_option in  
               
             -help | --help | -h | --h)  
                 usage ;;  
               
             -nooptfile | --nooptfile)  
                 OPTFILE="NONE" ;;  
             -optfile | --optfile | -of | --of)  
                 ac_prev=optfile ;;  
             -optfile=* | --optfile=* | -of=* | --of=*)  
                 OPTFILE=$ac_optarg ;;  
               
             -pdepend | --pdepend)  
                 ac_prev=pdepend ;;  
             -pdepend=* | --pdepend=*)  
                 PDEPEND=$ac_optarg ;;  
               
             -pdefault | --pdefault)  
                 ac_prev=pdefault ;;  
             -pdefault=* | --pdefault=*)  
                 PDEFAULT=$ac_optarg ;;  
               
             -makefile | -ma)  
                 ac_prev=makefile ;;  
             --makefile=* | -ma=*)  
                 MAKEFILE=$ac_optarg ;;  
               
             -platform | --platform | -pl | --pl)  
                 ac_prev=platform ;;  
             -platform=* | --platform=* | -pl=* | --pl=*)  
                 PLATFORM=$ac_optarg ;;  
   
             -rootdir | --rootdir | -rd | --rd)  
                 ac_prev=rootdir ;;  
             -rootdir=* | --rootdir=* | -rd=* | --rd=*)  
                 ROOTDIR=$ac_optarg ;;  
               
             -mods | --mods | -mo | --mo)  
                 ac_prev=mods ;;  
             -mods=* | --mods=* | -mo=* | --mo=*)  
                 MODS=$ac_optarg ;;  
               
             -disable | --disable)  
                 ac_prev=disable ;;  
             -disable=* | --disable=*)  
                 DISABLE=$ac_optarg ;;  
               
             -enable | --enable)  
                 ac_prev=enable ;;  
             -enable=* | --enable=*)  
                 ENABLE=$ac_optarg ;;  
               
             -noopt | --noopt)  
                 ac_prev=noopt ;;  
             -noopt=* | --noopt=*)  
                 NOOPT=$ac_optarg ;;  
               
 #           -cpp | --cpp)  
 #               ac_prev=cpp ;;  
 #           -cpp=* | --cpp=*)  
 #               CPP=$ac_optarg ;;  
               
             -fortran | --fortran | -fc | --fc)  
                 ac_prev=fc ;;  
             -fc=* | --fc=*)  
                 FC=$ac_optarg ;;  
               
             -ieee | --ieee)  
                 IEEE=1 ;;  
             -noieee | --noieee)  
                 IEEE=0 ;;  
               
             -mpi | --mpi)  
                 MPI=1 ;;  
             -nompi | --nompi)  
                 MPI=0 ;;  
               
             -jam | --jam)  
                 JAM=1 ;;  
             -nojam | --nojam)  
                 JAM=0 ;;  
               
             -*)  
                 echo "Error: unrecognized option: "$ac_option  
                 usage  
                 ;;  
               
             *)  
                 echo "Error: unrecognized argument: "$ac_option  
                 usage  
                 ;;  
               
         esac  
           
     done  
170  }  }
171    
172  #  Parse the package dependency information  #  Parse the package dependency information
# Line 222  usage()  { Line 198  usage()  {
198      echo "      -pdepend=NAME | --pdepend=NAME"      echo "      -pdepend=NAME | --pdepend=NAME"
199      echo "    -pdefault NAME | --pdefault NAME"      echo "    -pdefault NAME | --pdefault NAME"
200      echo "      -pdefault=NAME | --pdefault=NAME"      echo "      -pdefault=NAME | --pdefault=NAME"
201      echo "    -makefile NAME | -ma NAME"      echo "    -make NAME | -m NAME"
202      echo "      --makefile=NAME | -ma=NAME"      echo "      --make=NAME | -m=NAME"
203        echo "    -makefile NAME | -mf NAME"
204        echo "      --makefile=NAME | -mf=NAME"
205      echo "    -platform NAME | --platform NAME | -pl NAME | --pl NAME"      echo "    -platform NAME | --platform NAME | -pl NAME | --pl NAME"
206      echo "      -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"      echo "      -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"
207      echo "    -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"      echo "    -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"
# Line 255  usage()  { Line 233  usage()  {
233      exit 1      exit 1
234  }  }
235    
 # Dump all important state  
 dump_state()  {  
     fname=$1  
     echo " " > $fname  
     RETVAL=$?  
     if test "x${RETVAL}" = x ; then  
         echo "Error: cannot write to $fname"  
         exit 1  
     fi  
     echo "makefile "$makefile > $fname  
 }  
   
   
236  #eh3 # This is the generic configuration.  #eh3 # This is the generic configuration.
237  #eh3 set LN         = ( 'ln -s' )  #eh3 set LN         = ( 'ln -s' )
238  #eh3 set CPP        = ( '/lib/cpp -P' )  #eh3 set CPP        = ( '/lib/cpp -P' )
# Line 288  dump_state()  { Line 253  dump_state()  {
253  #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = (  )  #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = (  )
254    
255  #  Set defaults here  #  Set defaults here
256    COMMANDL="$0 $@"
257    
258  PLATFORM=  PLATFORM=
259  LN=  LN=
260  S64=  S64=
261  KPP=  KPP=
262  FC=  FC=
263  LINK=  LINK=
264    DEFINES="-DWORDLENGTH=4"
265  PACKAGES=  PACKAGES=
266  ENABLE=  ENABLE=
267  DISABLE=  DISABLE=
268  MAKEFILE=  MAKEFILE=
269  MAKEDEPEND=  MAKEDEPEND=
270  PDEPEND=  PDEPEND=
271    DUMPSTATE=t
272  PDEFAULT=  PDEFAULT=
273  OPTFILE=  OPTFILE=
274  INCLUDES="-I."  INCLUDES="-I."
# Line 324  THISHOSTNAME=`hostname` Line 293  THISHOSTNAME=`hostname`
293  THISCWD=`pwd`  THISCWD=`pwd`
294  THISDATE=`date`  THISDATE=`date`
295  MACHINE=`uname -a`  MACHINE=`uname -a`
296    EXECUTABLE=
297    EXEHOOK=
298    EXEDIR=
299    
300    #  The following state can be set directly by command-line switches
301    gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"
302    gm_s2="FC IEEE MPI JAM DUMPSTATE"
303    
304    #  The following state is not directly set by command-line switches
305    gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
306    gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
307    gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"
308    gm_s6="EXECUTABLE EXEHOOK EXEDIR"
309    
310    gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6"
311    
312    
313  echo  echo
314  echo "===  Processing options files and arguments  ==="  echo "===  Processing options files and arguments  ==="
# Line 370  for ac_option ; do Line 355  for ac_option ; do
355          -nooptfile | --nooptfile)          -nooptfile | --nooptfile)
356              OPTFILE="NONE" ;;              OPTFILE="NONE" ;;
357          -optfile | --optfile | -of | --of)          -optfile | --optfile | -of | --of)
358              ac_prev=optfile ;;              ac_prev=OPTFILE ;;
359          -optfile=* | --optfile=* | -of=* | --of=*)          -optfile=* | --optfile=* | -of=* | --of=*)
360              OPTFILE=$ac_optarg ;;              OPTFILE=$ac_optarg ;;
361                    
362          -pdepend | --pdepend)          -pdepend | --pdepend)
363              ac_prev=pdepend ;;              ac_prev=PDEPEND ;;
364          -pdepend=* | --pdepend=*)          -pdepend=* | --pdepend=*)
365              PDEPEND=$ac_optarg ;;              PDEPEND=$ac_optarg ;;
366                    
367          -pdefault | --pdefault)          -pdefault | --pdefault)
368              ac_prev=pdefault ;;              ac_prev=PDEFAULT ;;
369          -pdefault=* | --pdefault=*)          -pdefault=* | --pdefault=*)
370              PDEFAULT=$ac_optarg ;;              PDEFAULT=$ac_optarg ;;
371                    
372          -makefile | -ma)          -make | --make | -m | --m)
373              ac_prev=makefile ;;              ac_prev=MAKE ;;
374          --makefile=* | -ma=*)          -make=* | --make=* | -m=* | --m=*)
375                MAKE=$ac_optarg ;;
376            
377            -makefile | --makefile | -ma | --ma)
378                ac_prev=MAKEFILE ;;
379            -makefile=* | --makefile=* | -ma=* | --ma=*)
380              MAKEFILE=$ac_optarg ;;              MAKEFILE=$ac_optarg ;;
381                    
382          -platform | --platform | -pl | --pl)          -platform | --platform | -pl | --pl)
383              ac_prev=platform ;;              ac_prev=PLATFORM ;;
384          -platform=* | --platform=* | -pl=* | --pl=*)          -platform=* | --platform=* | -pl=* | --pl=*)
385              PLATFORM=$ac_optarg ;;              PLATFORM=$ac_optarg ;;
386                    
387          -rootdir | --rootdir | -rd | --rd)          -rootdir | --rootdir | -rd | --rd)
388              ac_prev=rootdir ;;              ac_prev=ROOTDIR ;;
389          -rootdir=* | --rootdir=* | -rd=* | --rd=*)          -rootdir=* | --rootdir=* | -rd=* | --rd=*)
390              ROOTDIR=$ac_optarg ;;              ROOTDIR=$ac_optarg ;;
391                    
392          -mods | --mods | -mo | --mo)          -mods | --mods | -mo | --mo)
393              ac_prev=mods ;;              ac_prev=MODS ;;
394          -mods=* | --mods=* | -mo=* | --mo=*)          -mods=* | --mods=* | -mo=* | --mo=*)
395              MODS=$ac_optarg ;;              MODS=$ac_optarg ;;
396                    
397          -disable | --disable)          -disable | --disable)
398              ac_prev=disable ;;              ac_prev=DISABLE ;;
399          -disable=* | --disable=*)          -disable=* | --disable=*)
400              DISABLE=$ac_optarg ;;              DISABLE=$ac_optarg ;;
401                    
402          -enable | --enable)          -enable | --enable)
403              ac_prev=enable ;;              ac_prev=ENABLE ;;
404          -enable=* | --enable=*)          -enable=* | --enable=*)
405              ENABLE=$ac_optarg ;;              ENABLE=$ac_optarg ;;
406                    
407          -noopt | --noopt)          -noopt | --noopt)
408              ac_prev=noopt ;;              ac_prev=NOOPT ;;
409          -noopt=* | --noopt=*)          -noopt=* | --noopt=*)
410              NOOPT=$ac_optarg ;;              NOOPT=$ac_optarg ;;
411                    
# Line 425  for ac_option ; do Line 415  for ac_option ; do
415  #               CPP=$ac_optarg ;;  #               CPP=$ac_optarg ;;
416                            
417          -fortran | --fortran | -fc | --fc)          -fortran | --fortran | -fc | --fc)
418              ac_prev=fc ;;              ac_prev=FC ;;
419          -fc=* | --fc=*)          -fc=* | --fc=*)
420              FC=$ac_optarg ;;              FC=$ac_optarg ;;
421                    
# Line 444  for ac_option ; do Line 434  for ac_option ; do
434          -nojam | --nojam)          -nojam | --nojam)
435              JAM=0 ;;              JAM=0 ;;
436                    
437            -ds | --ds)
438                DUMPSTATE=t ;;
439            
440          -*)          -*)
441              echo "Error: unrecognized option: "$ac_option              echo "Error: unrecognized option: "$ac_option
442              usage              usage
# Line 458  for ac_option ; do Line 451  for ac_option ; do
451            
452  done  done
453    
454    if test "x${ROOTDIR}" = x ; then
455        if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
456            ROOTDIR=".."
457        else
458            for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
459                if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
460                    ROOTDIR=$d
461                    echo -n "Warning:  ROOTDIR was not specified but there appears to be"
462                    echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
463                    break
464                fi
465            done
466        fi
467    fi
468    if test "x${ROOTDIR}" = x ; then
469        echo "Error: Cannot determine ROOTDIR for MITgcm code."
470        echo "  Please specify a ROOTDIR using either an options "
471        echo "  file or a command-line option."
472        exit 1
473    fi
474    if test ! -d ${ROOTDIR} ; then
475        echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
476        exit 1
477    fi
478    
479  echo "  getting OPTFILE information:  "  echo "  getting OPTFILE information:  "
480  if test "x${OPTFILE}" = x ; then  if test "x${OPTFILE}" = x ; then
481      echo "Warning: no OPTFILE specified so we'll look for possible settings"      if test "x$MITGCM_OF" = x ; then
482      printf "\n===  Searching for possible settings for OPTFILE  ===\n"          echo "Warning: no OPTFILE specified so we'll look for possible settings"
483      find_possible_configs          printf "\n===  Searching for possible settings for OPTFILE  ===\n"
484  else          find_possible_configs
     if test "x$OPTFILE" = xNONE ; then  
         echo "    OPTFILE=NONE so we'll try to use default settings"  
485      else      else
486          if test -f "$OPTFILE" -a -r "$OPTFILE" ; then          OPTFILE=$MITGCM_OF
487              echo "    using OPTFILE=\"$OPTFILE\""      fi
488              source "$OPTFILE"  fi
489              RETVAL=$?  if test "x$OPTFILE" != xNONE ; then
490              if test "x$RETVAL" != x0 ; then      if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
491                  echo -n "Error: failed to source OPTFILE \"$OPTFILE\""          echo "    using OPTFILE=\"$OPTFILE\""
492                  echo "--please check that variable syntax is bash-compatible"          source "$OPTFILE"
493                  exit 1          RETVAL=$?
494              fi          if test "x$RETVAL" != x0 ; then
495          else              echo -n "Error: failed to source OPTFILE \"$OPTFILE\""
496              echo "Error: can't read OPTFILE=\"$OPTFILE\""              echo "--please check that variable syntax is bash-compatible"
497              exit 1              exit 1
498          fi          fi
499            if test "x$DUMPSTATE" != xf ; then
500                cp -f $OPTFILE "gm_optfile"
501            fi
502        else
503            echo "Error: can't read OPTFILE=\"$OPTFILE\""
504            exit 1
505      fi      fi
506  fi  fi
507    
508    #  Check that FC, LINK, CPP, and S64 are defined.  If not, complain
509    #  and abort!
510    if test "x$FC" = x ; then
511        cat <<EOF 1>&2
512    
513    Error: no Fortran compiler: please specify using one of the following:
514      1) within the options file ("FC=...") as specified by "-of=OPTFILE"
515      2) the "-fc=XXX" command-line option
516      3) the "./gm_local" file
517    EOF
518        exit 1
519    fi
520    if test "x$LINK" = x ; then
521        LINK=$FC
522    fi
523    if test "x$CPP" = x ; then
524        CPP="cpp"
525    fi
526    echo "#define A a" | cpp > test_cpp 2>&1
527    RETVAL=$?
528    if test "x$RETVAL" != x0 ; then
529        cat <<EOF 1>&2
530    
531    Error: C pre-processor "$CPP" failed the test case: please specify using:
532    
533      1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
534      2) the "./gm_local" file
535    
536    EOF
537        exit 1
538    else
539        rm -f test_cpp
540    fi
541    if test "x$MAKEDEPEND" = x ; then
542        MAKEDEPEND=makedepend
543    fi
544    
545  printf "\n===  Setting defaults  ===\n"  printf "\n===  Setting defaults  ===\n"
546  echo -n "  Adding MODS directories:  "  echo -n "  Adding MODS directories:  "
547  for d in $MODS ; do  for d in $MODS ; do
# Line 505  if test "x${PLATFORM}" = x ; then Line 564  if test "x${PLATFORM}" = x ; then
564      PLATFORM=$p_PLATFORM      PLATFORM=$p_PLATFORM
565  fi  fi
566    
 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  
   
567  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
568      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then
569          EXEDIR=../exe          EXEDIR=../exe
# Line 549  if test ! -d ${TOOLSDIR} ; then Line 583  if test ! -d ${TOOLSDIR} ; then
583      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"
584      exit 1      exit 1
585  fi  fi
586    if test "x$S64" = x ; then
587        S64='$(TOOLSDIR)/set64bitConst.sh'
588    fi
589    
590  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
591    
# Line 639  for p in $PACKAGES ; do Line 676  for p in $PACKAGES ; do
676  done  done
677  PACKAGES="$pack"  PACKAGES="$pack"
678  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
679  rm -f ./.tmp_pack  echo "" > ./.tmp_pack
680  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
681  for i in $PACKAGES ; do  for i in $PACKAGES ; do
682      if test ! -d "$ROOTDIR/pkg/$i" ; then      if test ! -d "$ROOTDIR/pkg/$i" ; then
# Line 755  done Line 792  done
792  # done  # done
793  # echo  # echo
794    
795  echo "  Setting package-specific CPP flags in CPP_OPTIONS.h:"  # Create a list of #define and #undef to enable/disable packages
796  CPP_OPTIONS=  PACKAGES_DOT_H=PACKAGES.h
797  spaths="$SOURCEDIRS"  if test -e $PACKAGES_DOT_H ; then
798  for i in $spaths ; do      if test ! -e $PACKAGES_DOT_H.bak ; then
799      try="$i/CPP_OPTIONS.h"          cp -f $PACKAGES_DOT_H $PACKAGES_DOT_H.bak
     #  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  
800      fi      fi
801      cat CPP_OPTIONS.h \      cat $PACKAGES_DOT_H \
802          | awk 'BEGIN{p=1;} ($1=="C===" && $2=="GENMAKE"){p=0;} {if (p==1) print $0}' \          | awk 'BEGIN{p=1;} ($1=="C===" && $2=="GENMAKE"){p=0;} {if (p==1) print $0}' \
803          > CPP_OPTIONS.h.tmp          > $PACKAGES_DOT_H.tmp
804  fi  fi
805  cat <<EOF >>CPP_OPTIONS.h.tmp  cat <<EOF >>$PACKAGES_DOT_H.tmp
806  C=== GENMAKE v2 ===  C=== GENMAKE v2 ===
807  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
808  C  them only if you know what you're doing.  In general, you should  C  edit anything below these comments.  In general, you should
809  C  add or remove packages by re-running genmake with different  C  add or remove packages by re-running genmake with different
810  C  "-enable" and/or "-disable" options.  C  "-enable" and/or "-disable" options.
811    
# Line 808  for n in $names ; do Line 828  for n in $names ; do
828          done          done
829          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
830              undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`
831              echo "#undef $undef" >> CPP_OPTIONS.h.tmp              echo "#undef $undef" >> $PACKAGES_DOT_H.tmp
832    #           DEFINES="$DEFINES -U$undef"
833    
834  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
835              case $n in              case $n in
# Line 818  for n in $names ; do Line 839  for n in $names ; do
839                  mom_vecinv)                  mom_vecinv)
840                      DEFINES="$DEFINES -DDISABLE_MOM_VECINV"                      DEFINES="$DEFINES -DDISABLE_MOM_VECINV"
841                      ;;                      ;;
                 generic_advdiff)  
                     DEFINES="$DEFINES -DDISABLE_GENERIC_ADVDIFF"  
                     ;;  
842                  debug)                  debug)
843                      DEFINES="$DEFINES -DDISABLE_DEBUGMODE"                      DEFINES="$DEFINES -DDISABLE_DEBUGMODE"
844                      ;;                      ;;
# Line 830  for n in $names ; do Line 848  for n in $names ; do
848          fi          fi
849      fi      fi
850  done  done
851  cat <<EOF >>CPP_OPTIONS.h.tmp  cat <<EOF >>$PACKAGES_DOT_H.tmp
852    
853  C  Packages enabled by genmake:  C  Packages enabled by genmake:
854  EOF  EOF
855  for i in $PACKAGES ; do  for i in $PACKAGES ; do
856      def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`      def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`
857      echo "#define $def" >> CPP_OPTIONS.h.tmp      echo "#define $def" >> $PACKAGES_DOT_H.tmp
858        DEFINES="$DEFINES -D$def"
859    
860  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
861      case $i in      case $i in
862          aim_v23)          aim_v23)
863              echo "#define   ALLOW_AIM" >> CPP_OPTIONS.h.tmp              echo "#define   ALLOW_AIM" >> $PACKAGES_DOT_H.tmp
864                DEFINES="$DEFINES -DALLOW_AIM"
865                echo "Warning: ALLOW_AIM is set to enable aim_v23. This is REALLY ugly Jean-Michel :-)"
866              ;;              ;;
867      esac      esac
868  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
869    
870  done  done
871  mv -f CPP_OPTIONS.h.tmp CPP_OPTIONS.h  mv -f $PACKAGES_DOT_H.tmp $PACKAGES_DOT_H
872    
873  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS"
874  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
# Line 871  for d in $STANDARDDIRS ; do Line 892  for d in $STANDARDDIRS ; do
892      fi      fi
893  done  done
894    
895    echo "  Searching for CPP_OPTIONS.h (macros and flags for configuring the model):"
896    CPP_OPTIONS=
897    spaths=". $INCLUDEDIRS"
898    for i in $spaths ; do
899        try="$i/CPP_OPTIONS.h"
900        #  echo -n "    trying $try : "
901        if test -f $try -a -r $try ; then
902            echo "    found CPP_OPTIONS=\"$try\""
903            CPP_OPTIONS="$try"
904    #aja    if test "x$i" != "x." ; then
905    #aja        cp -f $CPP_OPTIONS .
906    #aja    fi
907            break
908        fi
909    done
910    if test "x$CPP_OPTIONS" = x ; then
911        echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
912        exit 1
913    fi
914    # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
915    names=`ls -1 "$ROOTDIR/pkg"`
916    for n in $names ; do
917        test_for_package_in_cpp_options $CPP_OPTIONS $n
918    done
919    
920    
921  echo  echo
922  echo "===  Creating the Makefile  ==="  echo "===  Creating the Makefile  ==="
923  echo "  setting INCLUDES"  echo "  setting INCLUDES"
924  for i in $INCLUDEDIRS ; do  for i in $INCLUDEDIRS ; do
925      if test -d $i ; then      if ! test -d $i ; then
926          INCLUDES="$INCLUDES -I$i"  #       INCLUDES="$INCLUDES -I$i"
927      else  #   else
928          echo "Warning: can't find INCLUDEDIRS=\"$i\""          echo "Warning: can't find INCLUDEDIRS=\"$i\""
929      fi      fi
930  done  done
# Line 892  echo -n 'SRCFILES = '    > srclist.inc Line 938  echo -n 'SRCFILES = '    > srclist.inc
938  echo -n 'CSRCFILES = '   > csrclist.inc  echo -n 'CSRCFILES = '   > csrclist.inc
939  echo -n 'F90SRCFILES = ' > f90srclist.inc  echo -n 'F90SRCFILES = ' > f90srclist.inc
940  echo -n 'HEADERFILES = ' > hlist.inc  echo -n 'HEADERFILES = ' > hlist.inc
941  alldirs=". $SOURCEDIRS $INCLUDEDIRS"  alldirs="$SOURCEDIRS $INCLUDEDIRS ."
942  for d in $alldirs ; do  for d in $alldirs ; do
943      deplist=      deplist=
944      sfiles=`( cd $d; echo *.[h,c,F] )`      sfiles=`( cd $d; echo *.[h,c,F] )`
# Line 937  echo "" >> csrclist.inc Line 983  echo "" >> csrclist.inc
983  echo "" >> f90srclist.inc  echo "" >> f90srclist.inc
984  echo "" >> hlist.inc  echo "" >> hlist.inc
985    
986    echo $DEFINES
987    
988  if test -e $MAKEFILE ; then  if test -e $MAKEFILE ; then
989      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.bak"
990  fi  fi
# Line 1043  all: \$(EXECUTABLE) Line 1091  all: \$(EXECUTABLE)
1091  depend:  depend:
1092          @make links          @make links
1093          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
1094          ../../../tools/f90mkdepend >> \$(MAKEFILE)          ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE)
1095    
1096  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)
1097    
# Line 1058  clean: Line 1106  clean:
1106  Clean:  Clean:
1107          @make clean          @make clean
1108          @make cleanlinks          @make cleanlinks
1109          -rm -f Makefile.bak          -rm -f Makefile.bak gm_state gm_optfile make.log PACKAGES.h*
1110  CLEAN:  CLEAN:
1111          @make Clean          @make Clean
1112          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
1113          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
1114          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
1115          -rm -f \$(EXECUTABLE)          -rm -f \$(EXECUTABLE) output.txt
1116    
1117  makefile:  makefile:
1118          ${0} $@          ${0} $@
# Line 1091  cleanlinks: Line 1139  cleanlinks:
1139    
1140  EOF  EOF
1141    
1142    if test "x$EXEHOOK" != x ; then
1143        printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
1144    fi
1145    
1146  echo "  Making list of \"exceptions\" that need \".p\" files"  echo "  Making list of \"exceptions\" that need \".p\" files"
1147  for i in $KPPFILES ; do  for i in $KPPFILES ; do
1148      base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`      base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
# Line 1120  echo "  Adding makedepend marker" Line 1172  echo "  Adding makedepend marker"
1172  printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE  printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
1173    
1174  printf "\n===  Done  ===\n"  printf "\n===  Done  ===\n"
1175    
1176    
1177    #  Write the "state" for future records
1178    if test "x$DUMPSTATE" != xf ; then
1179        echo -n "" > gm_state
1180        for i in $gm_state ; do
1181            t1="t2=\$$i"
1182            eval $t1
1183            echo "$i='$t2'" >> gm_state
1184        done
1185    fi

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.11.2.1

  ViewVC Help
Powered by ViewVC 1.1.22