/[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.10 by edhill, Fri Oct 3 19:49:06 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      p_PLATFORM=`uname`"-"`uname -m`      tmp1=`uname`"_"`uname -m`
74      echo "The platform appears to be:"      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
75      echo "  "$p_PLATFORM      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")`
77      p_LN=      echo "  The platform appears to be:  $PLATFORM"
78    #     if test "x$OFLIST" = x ; then
79    #       echo "  No pre-defined options files were found matching this platform"
80    #       echo "  but examples for other platforms can be found in:"
81    #       echo "    $ROOTDIR/tools/build_options"
82    #     else
83    #       echo "  Options files (located in $ROOTDIR/tools/build_options) that"
84    #       echo "  may work with this machine are:"
85    #       for i in $OFLIST ; do
86    #           echo "    $i"
87    #       done
88    #     fi
89        
90      echo "test" > test      echo "test" > test
91      ln -s ./test link      ln -s ./test link
92      RETVAL=$?      RETVAL=$?
93      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
94          p_LN="ln -s"          LN="ln -s"
95        else
96            echo "Error: \"ln -s\" does not appear to work on this system!"
97            echo "  For help, please contact <MITgcm-support@mitgcm.org>."
98            exit 1
99      fi      fi
100      rm -f test link      rm -f test link
101    
102      p_CPP=`which cpp`      if test "x$CPP" = x ; then
103                CPP="cpp -traditional -P"
     RETVAL=$?  
     if test "x${RETVAL}" = x0 ; then  
         p_LN="ln -s"  
104      fi      fi
     rm -f test link  
105    
106      # look for possible fortran compilers      # look for possible fortran compilers
107        tmp="$MITGCM_FC $FC g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"
108      p_FC=      p_FC=
109      for c in f77 g77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 ; do      for c in $tmp ; do
110          which $c > /dev/null 2>&1          rm -f ./hello.f ./hello
111            cat >> hello.f <<EOF
112          program hello
113          do i=1,3
114            print *, 'hello world : ', i
115          enddo
116          end
117    EOF
118            $c -o hello hello.f > /dev/null 2>&1
119          RETVAL=$?          RETVAL=$?
120          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
121              p_FC="$p_FC $c"              p_FC="$p_FC $c"
122          fi          fi
123      done      done
     echo "Possible FORTRAN compilers appear to be:  "  
124      if test "x${p_FC}" = x ; then      if test "x${p_FC}" = x ; then
125          echo "  None found!!!"          cat 1>&2 <<EOF
126      else  
127          echo "  "$p_FC  Error: No Fortran compilers were found in your path.  Please specify one using:
128      fi  
129        1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
130        2) a command-line option (eg. "-fc NAME"), or
131        3) the MITGCM_FC environment variable.
132    
     # 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  
133  EOF  EOF
134          eval "$mpi_fort -showme test.f > out"          exit 1
135          RETVAL=$?      else
136          if test "x${RETVAL}" = x0 ; then          echo "  The possible FORTRAN compilers found in your path are:"
137              a=`cat out`          echo "   "$p_FC
138              for i in $a ; do          if test "x$FC" = x ; then
139                  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  
140          fi          fi
         rm -f test.f out  
141      fi      fi
142    
143  }      for i in $p_FC ; do
144            p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
145            if test -r $p_OF ; then
146                OPTFILE=$p_OF
147                echo "  The options file:  $p_OF"
148                echo "    appears to match so we'll use it."
149                break
150            fi
151        done
152        if test "x$OPTFILE" = x ; then
153            cat 1>&2 <<EOF
154    
155  parse_options()  {  Error: No options file was found in:  $ROOTDIR/tools/build_options/
156      that matches this platform ("$PLATFORM") and the compilers found in
157      your path.  Please specify an "optfile" using:
158    
159      ac_prev=      1) the command line (eg. "-optfile=path/to/OPTFILE"), or
160      for ac_option in "${OPTIONS[@]}" ; do      2) the MITGCM_OF environment variable.
161    
162      If you need help, please contact the developers at <MITgcm-support@mitgcm.org>.
163    
164    EOF
165            exit 1
166        fi
167        
168    #     # look for possible MPI libraries
169    #     mpi_libs=
170    #     mpi_fort=`which mpif77 2>/dev/null`
171    #     RETVAL=$?
172    #     if test "x${RETVAL}" = x0 ; then
173    #       cat >>test.f <<EOF
174    #       PROGRAM HELLO
175    #       DO 10, I=1,10
176    #       PRINT *,'Hello World'
177    #    10 CONTINUE
178    #       STOP
179    #       END
180    # EOF
181    #       eval "$mpi_fort -showme test.f > out"
182    #       RETVAL=$?
183    #       if test "x${RETVAL}" = x0 ; then
184    #           a=`cat out`
185    #           for i in $a ; do
186    #               case $i in
187    #                   -*)
188    #                       mpi_libs="$mpi_libs $i" ;;
189    #               esac
190    #           done
191    #           echo "The MPI libs appear to be:"
192    #           echo "  "$mpi_libs
193    #       fi
194    #       rm -f test.f out
195    #     fi
196    
         # 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  
197  }  }
198    
199  #  Parse the package dependency information  #  Parse the package dependency information
# Line 222  usage()  { Line 225  usage()  {
225      echo "      -pdepend=NAME | --pdepend=NAME"      echo "      -pdepend=NAME | --pdepend=NAME"
226      echo "    -pdefault NAME | --pdefault NAME"      echo "    -pdefault NAME | --pdefault NAME"
227      echo "      -pdefault=NAME | --pdefault=NAME"      echo "      -pdefault=NAME | --pdefault=NAME"
228      echo "    -makefile NAME | -ma NAME"      echo "    -make NAME | -m NAME"
229      echo "      --makefile=NAME | -ma=NAME"      echo "      --make=NAME | -m=NAME"
230        echo "    -makefile NAME | -mf NAME"
231        echo "      --makefile=NAME | -mf=NAME"
232      echo "    -platform NAME | --platform NAME | -pl NAME | --pl NAME"      echo "    -platform NAME | --platform NAME | -pl NAME | --pl NAME"
233      echo "      -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"      echo "      -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"
234      echo "    -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"      echo "    -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"
# Line 234  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  usage()  { Line 262  usage()  {
262      exit 1      exit 1
263  }  }
264    
 # 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  
 }  
   
   
265  #eh3 # This is the generic configuration.  #eh3 # This is the generic configuration.
266  #eh3 set LN         = ( 'ln -s' )  #eh3 set LN         = ( 'ln -s' )
267  #eh3 set CPP        = ( '/lib/cpp -P' )  #eh3 set CPP        = ( '/lib/cpp -P' )
# Line 288  dump_state()  { Line 282  dump_state()  {
282  #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = (  )  #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = (  )
283    
284  #  Set defaults here  #  Set defaults here
285    COMMANDL="$0 $@"
286    
287  PLATFORM=  PLATFORM=
288  LN=  LN=
289  S64=  S64=
290  KPP=  KPP=
291  FC=  FC=
292  LINK=  LINK=
293    DEFINES="-DWORDLENGTH=4"
294  PACKAGES=  PACKAGES=
295  ENABLE=  ENABLE=
296  DISABLE=  DISABLE=
297  MAKEFILE=  MAKEFILE=
298  MAKEDEPEND=  MAKEDEPEND=
299  PDEPEND=  PDEPEND=
300    DUMPSTATE=t
301  PDEFAULT=  PDEFAULT=
302  OPTFILE=  OPTFILE=
303  INCLUDES="-I."  INCLUDES="-I."
# Line 317  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 324  THISHOSTNAME=`hostname` Line 323  THISHOSTNAME=`hostname`
323  THISCWD=`pwd`  THISCWD=`pwd`
324  THISDATE=`date`  THISDATE=`date`
325  MACHINE=`uname -a`  MACHINE=`uname -a`
326    EXECUTABLE=
327    EXEHOOK=
328    EXEDIR=
329    PACKAGES_CONF=
330    
331    #  The following state can be set directly by command-line switches
332    gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"
333    gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS"
334    
335    #  The following state is not directly set by command-line switches
336    gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
337    gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
338    gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"
339    gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
340    
341    gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6"
342    
343    
344  echo  echo
345  echo "===  Processing options files and arguments  ==="  echo "===  Processing options files and arguments  ==="
346  gm_local="./gm_local"  gm_local="genmake_local"
347    for i in . $MODS ; do
348        if test -r $i/$gm_local ; then
349            source $i/$gm_local
350            break
351        fi
352    done
353  echo -n "  getting local config information:  "  echo -n "  getting local config information:  "
354  if test -e $gm_local ; then  if test -e $gm_local ; then
355      echo "using $gm_local"      echo "using $gm_local"
# Line 370  for ac_option ; do Line 392  for ac_option ; do
392          -nooptfile | --nooptfile)          -nooptfile | --nooptfile)
393              OPTFILE="NONE" ;;              OPTFILE="NONE" ;;
394          -optfile | --optfile | -of | --of)          -optfile | --optfile | -of | --of)
395              ac_prev=optfile ;;              ac_prev=OPTFILE ;;
396          -optfile=* | --optfile=* | -of=* | --of=*)          -optfile=* | --optfile=* | -of=* | --of=*)
397              OPTFILE=$ac_optarg ;;              OPTFILE=$ac_optarg ;;
398                    
399          -pdepend | --pdepend)          -pdepend | --pdepend)
400              ac_prev=pdepend ;;              ac_prev=PDEPEND ;;
401          -pdepend=* | --pdepend=*)          -pdepend=* | --pdepend=*)
402              PDEPEND=$ac_optarg ;;              PDEPEND=$ac_optarg ;;
403                    
404          -pdefault | --pdefault)          -pdefault | --pdefault)
405              ac_prev=pdefault ;;              ac_prev=PDEFAULT ;;
406          -pdefault=* | --pdefault=*)          -pdefault=* | --pdefault=*)
407              PDEFAULT=$ac_optarg ;;              PDEFAULT=$ac_optarg ;;
408                    
409          -makefile | -ma)          -make | --make | -m | --m)
410              ac_prev=makefile ;;              ac_prev=MAKE ;;
411          --makefile=* | -ma=*)          -make=* | --make=* | -m=* | --m=*)
412                MAKE=$ac_optarg ;;
413            
414            -makefile | --makefile | -ma | --ma)
415                ac_prev=MAKEFILE ;;
416            -makefile=* | --makefile=* | -ma=* | --ma=*)
417              MAKEFILE=$ac_optarg ;;              MAKEFILE=$ac_optarg ;;
418                    
419          -platform | --platform | -pl | --pl)          -platform | --platform | -pl | --pl)
420              ac_prev=platform ;;              ac_prev=PLATFORM ;;
421          -platform=* | --platform=* | -pl=* | --pl=*)          -platform=* | --platform=* | -pl=* | --pl=*)
422              PLATFORM=$ac_optarg ;;              PLATFORM=$ac_optarg ;;
423                    
424          -rootdir | --rootdir | -rd | --rd)          -rootdir | --rootdir | -rd | --rd)
425              ac_prev=rootdir ;;              ac_prev=ROOTDIR ;;
426          -rootdir=* | --rootdir=* | -rd=* | --rd=*)          -rootdir=* | --rootdir=* | -rd=* | --rd=*)
427              ROOTDIR=$ac_optarg ;;              ROOTDIR=$ac_optarg ;;
428                    
429          -mods | --mods | -mo | --mo)          -mods | --mods | -mo | --mo)
430              ac_prev=mods ;;              ac_prev=MODS ;;
431          -mods=* | --mods=* | -mo=* | --mo=*)          -mods=* | --mods=* | -mo=* | --mo=*)
432              MODS=$ac_optarg ;;              MODS=$ac_optarg ;;
433                    
434          -disable | --disable)          -disable | --disable)
435              ac_prev=disable ;;              ac_prev=DISABLE ;;
436          -disable=* | --disable=*)          -disable=* | --disable=*)
437              DISABLE=$ac_optarg ;;              DISABLE=$ac_optarg ;;
438                    
439          -enable | --enable)          -enable | --enable)
440              ac_prev=enable ;;              ac_prev=ENABLE ;;
441          -enable=* | --enable=*)          -enable=* | --enable=*)
442              ENABLE=$ac_optarg ;;              ENABLE=$ac_optarg ;;
443                    
444            -standarddirs | --standarddirs)
445                ac_prev=STANDARDDIRS ;;
446            -standarddirs=* | --standarddirs=*)
447                STANDARDDIRS=$ac_optarg ;;
448    
449          -noopt | --noopt)          -noopt | --noopt)
450              ac_prev=noopt ;;              ac_prev=NOOPT ;;
451          -noopt=* | --noopt=*)          -noopt=* | --noopt=*)
452              NOOPT=$ac_optarg ;;              NOOPT=$ac_optarg ;;
453                    
# Line 425  for ac_option ; do Line 457  for ac_option ; do
457  #               CPP=$ac_optarg ;;  #               CPP=$ac_optarg ;;
458                            
459          -fortran | --fortran | -fc | --fc)          -fortran | --fortran | -fc | --fc)
460              ac_prev=fc ;;              ac_prev=FC ;;
461          -fc=* | --fc=*)          -fc=* | --fc=*)
462              FC=$ac_optarg ;;              FC=$ac_optarg ;;
463                    
# Line 444  for ac_option ; do Line 476  for ac_option ; do
476          -nojam | --nojam)          -nojam | --nojam)
477              JAM=0 ;;              JAM=0 ;;
478                    
479            -ds | --ds)
480                DUMPSTATE=t ;;
481            
482          -*)          -*)
483              echo "Error: unrecognized option: "$ac_option              echo "Error: unrecognized option: "$ac_option
484              usage              usage
# Line 458  for ac_option ; do Line 493  for ac_option ; do
493            
494  done  done
495    
496    if test "x${ROOTDIR}" = x ; then
497        if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
498            ROOTDIR=".."
499        else
500            for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
501                if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
502                    ROOTDIR=$d
503                    echo -n "Warning:  ROOTDIR was not specified but there appears to be"
504                    echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
505                    break
506                fi
507            done
508        fi
509    fi
510    if test "x${ROOTDIR}" = x ; then
511        echo "Error: Cannot determine ROOTDIR for MITgcm code."
512        echo "  Please specify a ROOTDIR using either an options "
513        echo "  file or a command-line option."
514        exit 1
515    fi
516    if test ! -d ${ROOTDIR} ; then
517        echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
518        exit 1
519    fi
520    
521  echo "  getting OPTFILE information:  "  echo "  getting OPTFILE information:  "
522  if test "x${OPTFILE}" = x ; then  if test "x${OPTFILE}" = x ; then
523      echo "Warning: no OPTFILE specified so we'll look for possible settings"      if test "x$MITGCM_OF" = x ; then
524      printf "\n===  Searching for possible settings for OPTFILE  ===\n"          echo "Warning: no OPTFILE specified so we'll look for possible settings"
525      find_possible_configs          printf "\n===  Searching for possible settings for OPTFILE  ===\n"
526  else          find_possible_configs
     if test "x$OPTFILE" = xNONE ; then  
         echo "    OPTFILE=NONE so we'll try to use default settings"  
527      else      else
528          if test -f "$OPTFILE" -a -r "$OPTFILE" ; then          OPTFILE=$MITGCM_OF
529              echo "    using OPTFILE=\"$OPTFILE\""      fi
530              source "$OPTFILE"  fi
531              RETVAL=$?  if test "x$OPTFILE" != xNONE ; then
532              if test "x$RETVAL" != x0 ; then      if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
533                  echo -n "Error: failed to source OPTFILE \"$OPTFILE\""          echo "    using OPTFILE=\"$OPTFILE\""
534                  echo "--please check that variable syntax is bash-compatible"          source "$OPTFILE"
535                  exit 1          RETVAL=$?
536              fi          if test "x$RETVAL" != x0 ; then
537          else              echo -n "Error: failed to source OPTFILE \"$OPTFILE\""
538              echo "Error: can't read OPTFILE=\"$OPTFILE\""              echo "--please check that variable syntax is bash-compatible"
539              exit 1              exit 1
540          fi          fi
541            if test "x$DUMPSTATE" != xf ; then
542                cp -f $OPTFILE "genmake_optfile"
543            fi
544        else
545            echo "Error: can't read OPTFILE=\"$OPTFILE\""
546            exit 1
547      fi      fi
548  fi  fi
549    
550    #  Check that FC, LINK, CPP, and S64 are defined.  If not, complain
551    #  and abort!
552    if test "x$FC" = x ; then
553        cat <<EOF 1>&2
554    
555    Error: no Fortran compiler: please specify using one of the following:
556      1) within the options file ("FC=...") as specified by "-of=OPTFILE"
557      2) the "-fc=XXX" command-line option
558      3) the "./genmake_local" file
559    EOF
560        exit 1
561    fi
562    if test "x$LINK" = x ; then
563        LINK=$FC
564    fi
565    if test "x$CPP" = x ; then
566        CPP="cpp"
567    fi
568    echo "#define A a" | cpp > test_cpp 2>&1
569    RETVAL=$?
570    if test "x$RETVAL" != x0 ; then
571        cat <<EOF 1>&2
572    
573    Error: C pre-processor "$CPP" failed the test case: please specify using:
574    
575      1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
576      2) the "./genmake_local" file
577    
578    EOF
579        exit 1
580    else
581        rm -f test_cpp
582    fi
583    if test "x$MAKEDEPEND" = x ; then
584        MAKEDEPEND=makedepend
585    fi
586    
587  printf "\n===  Setting defaults  ===\n"  printf "\n===  Setting defaults  ===\n"
588  echo -n "  Adding MODS directories:  "  echo -n "  Adding MODS directories:  "
589  for d in $MODS ; do  for d in $MODS ; do
# Line 505  if test "x${PLATFORM}" = x ; then Line 606  if test "x${PLATFORM}" = x ; then
606      PLATFORM=$p_PLATFORM      PLATFORM=$p_PLATFORM
607  fi  fi
608    
 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  
   
609  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
610      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then
611          EXEDIR=../exe          EXEDIR=../exe
# Line 549  if test ! -d ${TOOLSDIR} ; then Line 625  if test ! -d ${TOOLSDIR} ; then
625      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"
626      exit 1      exit 1
627  fi  fi
628    if test "x$S64" = x ; then
629        S64='$(TOOLSDIR)/set64bitConst.sh'
630    fi
631    
632  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
633    
# Line 597  fi Line 676  fi
676  source ./.pd_tmp  source ./.pd_tmp
677  rm -f ./.pd_tmp  rm -f ./.pd_tmp
678    
679    #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"
680    #  file should eventually be added so that, for convenience, one can
681    #  specify groups of packages using names like "ocean" and "atmosphere".
682  echo  -n "  checking default package list:  "  echo  -n "  checking default package list:  "
683  if test "x${PDEFAULT}" = x ; then  if test "x${PDEFAULT}" = x ; then
684        for i in "." $MODS ; do
685            if test -r $i"/packages.conf" ; then
686                    PDEFAULT=$i"/packages.conf"
687                    break
688            fi
689        done
690    fi
691    if test "x${PDEFAULT}" = x ; then
692      PDEFAULT="$ROOTDIR/pkg/pkg_default"      PDEFAULT="$ROOTDIR/pkg/pkg_default"
693  fi  fi
694  if test "x${PDEFAULT}" = xNONE ; then  if test "x${PDEFAULT}" = xNONE ; then
# Line 620  else Line 710  else
710          for i in $def ; do          for i in $def ; do
711              PACKAGES="$PACKAGES $i"              PACKAGES="$PACKAGES $i"
712          done          done
713          echo "    packages are:  $PACKAGES"          echo "    before group expansion packages are: $PACKAGES"
714            expand_pkg_groups
715            echo "    after group expansion packages are:  $PACKAGES"
716      fi      fi
717  fi  fi
718    
# Line 639  for p in $PACKAGES ; do Line 731  for p in $PACKAGES ; do
731  done  done
732  PACKAGES="$pack"  PACKAGES="$pack"
733  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
734  rm -f ./.tmp_pack  echo "" > ./.tmp_pack
735  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
736  for i in $PACKAGES ; do  for i in $PACKAGES ; do
737      if test ! -d "$ROOTDIR/pkg/$i" ; then      if test ! -d "$ROOTDIR/pkg/$i" ; then
# Line 755  done Line 847  done
847  # done  # done
848  # echo  # echo
849    
850  echo "  Setting package-specific CPP flags in CPP_OPTIONS.h:"  # Create a list of #define and #undef to enable/disable packages
851  CPP_OPTIONS=  PACKAGES_DOT_H=PACKAGES_CONFIG.h
852  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  
853  C=== GENMAKE v2 ===  C=== GENMAKE v2 ===
854  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
855  C  them only if you know what you're doing.  In general, you should  C  edit anything below these comments.  In general, you should
856  C  add or remove packages by re-running genmake with different  C  add or remove packages by re-running genmake with different
857  C  "-enable" and/or "-disable" options.  C  "-enable" and/or "-disable" options.
858    
859    #ifndef PACKAGES_H
860    #define PACKAGES_H
861    
862  C  Packages disabled by genmake:  C  Packages disabled by genmake:
863  EOF  EOF
864  #  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 808  for n in $names ; do Line 878  for n in $names ; do
878          done          done
879          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
880              undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`
881              echo "#undef $undef" >> CPP_OPTIONS.h.tmp              echo "#undef $undef" >> $PACKAGES_DOT_H".tmp"
882    #           DEFINES="$DEFINES -U$undef"
883    
884  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
885              case $n in              case $n in
# Line 818  for n in $names ; do Line 889  for n in $names ; do
889                  mom_vecinv)                  mom_vecinv)
890                      DEFINES="$DEFINES -DDISABLE_MOM_VECINV"                      DEFINES="$DEFINES -DDISABLE_MOM_VECINV"
891                      ;;                      ;;
                 generic_advdiff)  
                     DEFINES="$DEFINES -DDISABLE_GENERIC_ADVDIFF"  
                     ;;  
892                  debug)                  debug)
893                      DEFINES="$DEFINES -DDISABLE_DEBUGMODE"                      DEFINES="$DEFINES -DDISABLE_DEBUGMODE"
894                      ;;                      ;;
# Line 830  for n in $names ; do Line 898  for n in $names ; do
898          fi          fi
899      fi      fi
900  done  done
901  cat <<EOF >>CPP_OPTIONS.h.tmp  cat <<EOF >>$PACKAGES_DOT_H".tmp"
902    
903  C  Packages enabled by genmake:  C  Packages enabled by genmake:
904  EOF  EOF
905  for i in $PACKAGES ; do  for i in $PACKAGES ; do
906      def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`      def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`
907      echo "#define $def" >> CPP_OPTIONS.h.tmp      echo "#define $def" >> $PACKAGES_DOT_H".tmp"
908    #eh3 DEFINES="$DEFINES -D$def"
909    
910  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
911      case $i in      case $i in
912          aim_v23)          aim_v23)
913              echo "#define   ALLOW_AIM" >> CPP_OPTIONS.h.tmp              echo "#define   ALLOW_AIM" >> $PACKAGES_DOT_H".tmp"
914                DEFINES="$DEFINES -DALLOW_AIM"
915                echo "Warning: ALLOW_AIM is set to enable aim_v23. This is REALLY ugly Jean-Michel :-)"
916              ;;              ;;
917      esac      esac
918  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
919    
920  done  done
921  mv -f CPP_OPTIONS.h.tmp CPP_OPTIONS.h  cat <<EOF >>$PACKAGES_DOT_H".tmp"
922    
923    #endif /* PACKAGES_H */
924    EOF
925    
926    if test ! -f $PACKAGES_DOT_H ; then
927        mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
928    else
929        cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
930        RETVAL=$?
931        if test "x$RETVAL" = x0 ; then
932            rm -f $PACKAGES_DOT_H".tmp"
933        else
934            mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
935            mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
936        fi
937    fi
938    
939  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS"
940  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
941  STANDARDDIRS=${STANDARDDIRS:-"eesupp model"}  if test "x$STANDARDDIRS" = x ; then
942        STANDARDDIRS="eesupp model"
943    fi
944  for d in $STANDARDDIRS ; do  for d in $STANDARDDIRS ; do
945      adr="$ROOTDIR/$d/src"      adr="$ROOTDIR/$d/src"
946      if test ! -d $adr ; then      if test ! -d $adr ; then
# Line 871  for d in $STANDARDDIRS ; do Line 960  for d in $STANDARDDIRS ; do
960      fi      fi
961  done  done
962    
963    echo " Searching for CPP_OPTIONS.h in order to warn about the presence"
964    echo " of \"#define ALLOW_PKGNAME\"-type statements:"
965    CPP_OPTIONS=
966    spaths=". $INCLUDEDIRS"
967    for i in $spaths ; do
968        try="$i/CPP_OPTIONS.h"
969        #  echo -n "    trying $try : "
970        if test -f $try -a -r $try ; then
971            echo "    found CPP_OPTIONS=\"$try\""
972            CPP_OPTIONS="$try"
973            break
974        fi
975    done
976    if test "x$CPP_OPTIONS" = x ; then
977        echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
978        exit 1
979    fi
980    # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
981    names=`ls -1 "$ROOTDIR/pkg"`
982    for n in $names ; do
983        test_for_package_in_cpp_options $CPP_OPTIONS $n
984    done
985    
986    
987  echo  echo
988  echo "===  Creating the Makefile  ==="  echo "===  Creating the Makefile  ==="
989  echo "  setting INCLUDES"  echo "  setting INCLUDES"
990  for i in $INCLUDEDIRS ; do  for i in $INCLUDEDIRS ; do
991      if test -d $i ; then      if ! test -d $i ; then
992          INCLUDES="$INCLUDES -I$i"  #       INCLUDES="$INCLUDES -I$i"
993      else  #   else
994          echo "Warning: can't find INCLUDEDIRS=\"$i\""          echo "Warning: can't find INCLUDEDIRS=\"$i\""
995      fi      fi
996  done  done
# Line 892  echo -n 'SRCFILES = '    > srclist.inc Line 1004  echo -n 'SRCFILES = '    > srclist.inc
1004  echo -n 'CSRCFILES = '   > csrclist.inc  echo -n 'CSRCFILES = '   > csrclist.inc
1005  echo -n 'F90SRCFILES = ' > f90srclist.inc  echo -n 'F90SRCFILES = ' > f90srclist.inc
1006  echo -n 'HEADERFILES = ' > hlist.inc  echo -n 'HEADERFILES = ' > hlist.inc
1007  alldirs=". $SOURCEDIRS $INCLUDEDIRS"  alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1008  for d in $alldirs ; do  for d in $alldirs ; do
1009      deplist=      deplist=
1010      sfiles=`( cd $d; echo *.[h,c,F] )`      sfiles=`( cd $d; echo *.[h,c,F] )`
# Line 1043  all: \$(EXECUTABLE) Line 1155  all: \$(EXECUTABLE)
1155  depend:  depend:
1156          @make links          @make links
1157          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
1158          ../../../tools/f90mkdepend >> \$(MAKEFILE)          ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE)
1159    
1160  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)
1161    
# Line 1058  clean: Line 1170  clean:
1170  Clean:  Clean:
1171          @make clean          @make clean
1172          @make cleanlinks          @make cleanlinks
1173          -rm -f Makefile.bak          -rm -f Makefile.bak genmake_state genmake_optfile make.log
1174  CLEAN:  CLEAN:
1175          @make Clean          @make Clean
1176          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
1177          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
1178          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
1179          -rm -f \$(EXECUTABLE)          -rm -f \$(EXECUTABLE) output.txt
1180    
1181  makefile:  makefile:
1182          ${0} $@          ${0} $@
# Line 1091  cleanlinks: Line 1203  cleanlinks:
1203    
1204  EOF  EOF
1205    
1206    if test "x$EXEHOOK" != x ; then
1207        printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
1208    fi
1209    
1210  echo "  Making list of \"exceptions\" that need \".p\" files"  echo "  Making list of \"exceptions\" that need \".p\" files"
1211  for i in $KPPFILES ; do  for i in $KPPFILES ; do
1212      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 1236  echo "  Adding makedepend marker"
1236  printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE  printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
1237    
1238  printf "\n===  Done  ===\n"  printf "\n===  Done  ===\n"
1239    
1240    
1241    #  Write the "state" for future records
1242    if test "x$DUMPSTATE" != xf ; then
1243        echo -n "" > genmake_state
1244        for i in $gm_state ; do
1245            t1="t2=\$$i"
1246            eval $t1
1247            echo "$i='$t2'" >> genmake_state
1248        done
1249    fi

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

  ViewVC Help
Powered by ViewVC 1.1.22