/[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.1 by edhill, Sat Aug 16 14:01:08 2003 UTC revision 1.11 by edhill, Mon Sep 29 16:15:23 2003 UTC
# Line 12  Line 12 
12  # Guess possible config options for this host  # Guess possible config options for this host
13  find_possible_configs()  {  find_possible_configs()  {
14    
15      p_PLATFORM=`uname`"-"`uname -m`      tmp1=`uname`"_"`uname -m`
16      echo "The platform appears to be:"      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
17      echo "  "$p_PLATFORM      PLATFORM=`echo $tmp2 | sed -e 's/i[3-6]86/ia32/'`
18        OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
19      p_LN=      echo "  The platform appears to be:  $PLATFORM"
20    #     if test "x$OFLIST" = x ; then
21    #       echo "  No pre-defined options files were found matching this platform"
22    #       echo "  but examples for other platforms can be found in:"
23    #       echo "    $ROOTDIR/tools/build_options"
24    #     else
25    #       echo "  Options files (located in $ROOTDIR/tools/build_options) that"
26    #       echo "  may work with this machine are:"
27    #       for i in $OFLIST ; do
28    #           echo "    $i"
29    #       done
30    #     fi
31        
32      echo "test" > test      echo "test" > test
33      ln -s ./test link      ln -s ./test link
34      RETVAL=$?      RETVAL=$?
35      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
36          p_LN="ln -s"          LN="ln -s"
37        else
38            echo "Error: \"ln -s\" does not appear to work on this system!"
39            echo "  For help, please contact <MITgcm-support@mitgcm.org>."
40            exit 1
41      fi      fi
42      rm -f test link      rm -f test link
43    
44      p_CPP=`which cpp`      if test "x$CPP" = x ; then
45                CPP="cpp -traditional -P"
     RETVAL=$?  
     if test "x${RETVAL}" = x0 ; then  
         p_LN="ln -s"  
46      fi      fi
     rm -f test link  
47    
48      # look for possible fortran compilers      # look for possible fortran compilers
49        tmp="$MITGCM_FC $FC g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"
50      p_FC=      p_FC=
51      for c in f77 g77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 ; do      for c in $tmp ; do
52          which $c > /dev/null 2>&1          rm -f ./hello.f ./hello
53            cat >> hello.f <<EOF
54          program hello
55          do i=1,3
56            print *, 'hello world : ', i
57          enddo
58          end
59    EOF
60            $c -o hello hello.f > /dev/null 2>&1
61          RETVAL=$?          RETVAL=$?
62          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
63              p_FC="$p_FC $c"              p_FC="$p_FC $c"
64          fi          fi
65      done      done
     echo "Possible FORTRAN compilers appear to be:  "  
66      if test "x${p_FC}" = x ; then      if test "x${p_FC}" = x ; then
67          echo "  None found!!!"          cat 1>&2 <<EOF
68      else  
69          echo "  "$p_FC  Error: No Fortran compilers were found in your path.  Please specify one using:
70      fi  
71        1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
72        2) a command-line option (eg. "-fc NAME"), or
73        3) the MITGCM_FC environment variable.
74    
     # 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  
75  EOF  EOF
76          eval "$mpi_fort -showme test.f > out"          exit 1
77          RETVAL=$?      else
78          if test "x${RETVAL}" = x0 ; then          echo "  The possible FORTRAN compilers found in your path are:"
79              a=`cat out`          echo "   "$p_FC
80              for i in $a ; do          if test "x$FC" = x ; then
81                  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  
82          fi          fi
         rm -f test.f out  
83      fi      fi
84    
85  }      for i in $p_FC ; do
86            p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
87            if test -r $p_OF ; then
88                OPTFILE=$p_OF
89                echo "  The options file:  $p_OF"
90                echo "    appears to match so we'll use it."
91                break
92            fi
93        done
94        if test "x$OPTFILE" = x ; then
95            cat 1>&2 <<EOF
96    
97  parse_options()  {  Error: No options file was found in:  $ROOTDIR/tools/build_options/
98      that matches this platform ("$PLATFORM") and the compilers found in
99      your path.  Please specify an "optfile" using:
100    
101      ac_prev=      1) the command line (eg. "-optfile=path/to/OPTFILE"), or
102      for ac_option in "${OPTIONS[@]}" ; do      2) the MITGCM_OF environment variable.
103    
104      If you need help, please contact the developers at <MITgcm-support@mitgcm.org>.
105    
106    EOF
107            exit 1
108        fi
109        
110    #     # look for possible MPI libraries
111    #     mpi_libs=
112    #     mpi_fort=`which mpif77 2>/dev/null`
113    #     RETVAL=$?
114    #     if test "x${RETVAL}" = x0 ; then
115    #       cat >>test.f <<EOF
116    #       PROGRAM HELLO
117    #       DO 10, I=1,10
118    #       PRINT *,'Hello World'
119    #    10 CONTINUE
120    #       STOP
121    #       END
122    # EOF
123    #       eval "$mpi_fort -showme test.f > out"
124    #       RETVAL=$?
125    #       if test "x${RETVAL}" = x0 ; then
126    #           a=`cat out`
127    #           for i in $a ; do
128    #               case $i in
129    #                   -*)
130    #                       mpi_libs="$mpi_libs $i" ;;
131    #               esac
132    #           done
133    #           echo "The MPI libs appear to be:"
134    #           echo "  "$mpi_libs
135    #       fi
136    #       rm -f test.f out
137    #     fi
138    
         # 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  
139  }  }
140    
141  #  Parse the package dependency information  #  Parse the package dependency information
# Line 210  get_pdepend_list()  { Line 155  get_pdepend_list()  {
155    
156  #  Explain usage  #  Explain usage
157  usage()  {  usage()  {
158      echo ""      echo
159      echo "Usage: "$0" [OPTIONS]"      echo "Usage: "$0" [OPTIONS]"
160      echo "  where [OPTIONS] can be:"$'\n'      echo "  where [OPTIONS] can be:"
161        echo
162      echo "    -help | --help | -h | --h"      echo "    -help | --help | -h | --h"
163      echo "    -nooptfile | --nooptfile"      echo "    -nooptfile | --nooptfile"
164      echo "      -optfile NAME | --optfile NAME | -of NAME | --of NAME"      echo "      -optfile NAME | --optfile NAME | -of NAME | --of NAME"
# Line 221  usage()  { Line 167  usage()  {
167      echo "      -pdepend=NAME | --pdepend=NAME"      echo "      -pdepend=NAME | --pdepend=NAME"
168      echo "    -pdefault NAME | --pdefault NAME"      echo "    -pdefault NAME | --pdefault NAME"
169      echo "      -pdefault=NAME | --pdefault=NAME"      echo "      -pdefault=NAME | --pdefault=NAME"
170      echo "    -makefile NAME | -ma NAME"      echo "    -make NAME | -m NAME"
171      echo "      --makefile=NAME | -ma=NAME"      echo "      --make=NAME | -m=NAME"
172        echo "    -makefile NAME | -mf NAME"
173        echo "      --makefile=NAME | -mf=NAME"
174      echo "    -platform NAME | --platform NAME | -pl NAME | --pl NAME"      echo "    -platform NAME | --platform NAME | -pl NAME | --pl NAME"
175      echo "      -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"      echo "      -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"
176      echo "    -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"      echo "    -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"
# Line 241  usage()  { Line 189  usage()  {
189      echo "      -fc=NAME | --fc=NAME"      echo "      -fc=NAME | --fc=NAME"
190      echo "    -[no]ieee | --[no]ieee"      echo "    -[no]ieee | --[no]ieee"
191      echo "    -[no]mpi | --[no]mpi"      echo "    -[no]mpi | --[no]mpi"
192      echo "    -[no]jam | --[no]jam"$'\n'      echo "    -[no]jam | --[no]jam"
193      echo "  and NAME is a string such as:"$'\n'      echo
194        echo "  and NAME is a string such as:"
195        echo
196      echo "    --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'"      echo "    --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'"
197      echo "    -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'"      echo "    -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'"
198      echo "    -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"$'\n'      echo "    -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"
199        echo
200      echo "  which, depending upon your shell, may need to be single-quoted"      echo "  which, depending upon your shell, may need to be single-quoted"
201      echo "  if it contains spaces, dashes, or other special characters."      echo "  if it contains spaces, dashes, or other special characters."
202      exit 1      exit 1
203  }  }
204    
 # 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  
 }  
   
   
205  #eh3 # This is the generic configuration.  #eh3 # This is the generic configuration.
206  #eh3 set LN         = ( 'ln -s' )  #eh3 set LN         = ( 'ln -s' )
207  #eh3 set CPP        = ( '/lib/cpp -P' )  #eh3 set CPP        = ( '/lib/cpp -P' )
# Line 284  dump_state()  { Line 222  dump_state()  {
222  #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = (  )  #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = (  )
223    
224  #  Set defaults here  #  Set defaults here
225    COMMANDL="$0 $@"
226    
227  PLATFORM=  PLATFORM=
228  LN=  LN=
229  S64=  S64=
230  KPP=  KPP=
231  FC=  FC=
232  LINK=  LINK=
233    DEFINES="-DWORDLENGTH=4"
234  PACKAGES=  PACKAGES=
235  ENABLE=  ENABLE=
236  DISABLE=  DISABLE=
237  MAKEFILE=  MAKEFILE=
238  MAKEDEPEND=  MAKEDEPEND=
239  PDEPEND=  PDEPEND=
240    DUMPSTATE=t
241  PDEFAULT=  PDEFAULT=
242  OPTFILE=  OPTFILE=
243  INCLUDES=-I.  INCLUDES="-I."
244  FFLAGS=  FFLAGS=
245  FOPTIM=  FOPTIM=
246  CFLAGS=  CFLAGS=
# Line 320  THISHOSTNAME=`hostname` Line 262  THISHOSTNAME=`hostname`
262  THISCWD=`pwd`  THISCWD=`pwd`
263  THISDATE=`date`  THISDATE=`date`
264  MACHINE=`uname -a`  MACHINE=`uname -a`
265    EXECUTABLE=
266    EXEHOOK=
267    EXEDIR=
268    
269    #  The following state can be set directly by command-line switches
270    gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"
271    gm_s2="FC IEEE MPI JAM DUMPSTATE"
272    
273    #  The following state is not directly set by command-line switches
274    gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
275    gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
276    gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"
277    gm_s6="EXECUTABLE EXEHOOK EXEDIR"
278    
279    gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6"
280    
281  echo $'\n'"===  Processing options files and arguments  ==="  
282    echo
283    echo "===  Processing options files and arguments  ==="
284  gm_local="./gm_local"  gm_local="./gm_local"
285  echo -n "  getting local config information:  "  echo -n "  getting local config information:  "
286  if test -e $gm_local ; then  if test -e $gm_local ; then
287      echo "using $gm_local"      echo "using $gm_local"
288      source $gm_local      source $gm_local
289      echo "DISABLE=$DISABLE"$'\n'"ENABLE=$ENABLE"      # echo "DISABLE=$DISABLE"
290        # echo "ENABLE=$ENABLE"
291  else  else
292      echo "none found"      echo "none found"
293  fi  fi
294    
295  #  echo "$0::$1:$2:$3:$4:$5:$6:$7:"  #  echo "$0::$1:$2:$3:$4:$5:$6:$7:"
296  OPTIONS=()  #OPTIONS=
297  n=0  #n=0
298  for i ; do  #for i ; do
299     setvar="OPTIONS[$n]='$i'"  #   echo "$i  $n"
300     #  echo "  $setvar"  #   setvar="OPTIONS[$n]='$i'"
301     eval "$setvar"  #   #  echo "  $setvar"
302     n=$(( $n + 1 ))  #   eval "$setvar"
303    #   n=$(( $n + 1 ))
304    #done
305    #parse_options
306    
307    ac_prev=
308    for ac_option ; do
309    
310        # If the previous option needs an argument, assign it.
311        if test -n "$ac_prev"; then
312            eval "$ac_prev=\$ac_option"
313            ac_prev=
314            continue
315        fi
316        
317        ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
318        
319        case $ac_option in
320            
321            -help | --help | -h | --h)
322                usage ;;
323            
324            -nooptfile | --nooptfile)
325                OPTFILE="NONE" ;;
326            -optfile | --optfile | -of | --of)
327                ac_prev=OPTFILE ;;
328            -optfile=* | --optfile=* | -of=* | --of=*)
329                OPTFILE=$ac_optarg ;;
330            
331            -pdepend | --pdepend)
332                ac_prev=PDEPEND ;;
333            -pdepend=* | --pdepend=*)
334                PDEPEND=$ac_optarg ;;
335            
336            -pdefault | --pdefault)
337                ac_prev=PDEFAULT ;;
338            -pdefault=* | --pdefault=*)
339                PDEFAULT=$ac_optarg ;;
340            
341            -make | --make | -m | --m)
342                ac_prev=MAKE ;;
343            -make=* | --make=* | -m=* | --m=*)
344                MAKE=$ac_optarg ;;
345            
346            -makefile | --makefile | -ma | --ma)
347                ac_prev=MAKEFILE ;;
348            -makefile=* | --makefile=* | -ma=* | --ma=*)
349                MAKEFILE=$ac_optarg ;;
350            
351            -platform | --platform | -pl | --pl)
352                ac_prev=PLATFORM ;;
353            -platform=* | --platform=* | -pl=* | --pl=*)
354                PLATFORM=$ac_optarg ;;
355            
356            -rootdir | --rootdir | -rd | --rd)
357                ac_prev=ROOTDIR ;;
358            -rootdir=* | --rootdir=* | -rd=* | --rd=*)
359                ROOTDIR=$ac_optarg ;;
360            
361            -mods | --mods | -mo | --mo)
362                ac_prev=MODS ;;
363            -mods=* | --mods=* | -mo=* | --mo=*)
364                MODS=$ac_optarg ;;
365            
366            -disable | --disable)
367                ac_prev=DISABLE ;;
368            -disable=* | --disable=*)
369                DISABLE=$ac_optarg ;;
370            
371            -enable | --enable)
372                ac_prev=ENABLE ;;
373            -enable=* | --enable=*)
374                ENABLE=$ac_optarg ;;
375            
376            -noopt | --noopt)
377                ac_prev=NOOPT ;;
378            -noopt=* | --noopt=*)
379                NOOPT=$ac_optarg ;;
380            
381    #           -cpp | --cpp)
382    #               ac_prev=cpp ;;
383    #           -cpp=* | --cpp=*)
384    #               CPP=$ac_optarg ;;
385                
386            -fortran | --fortran | -fc | --fc)
387                ac_prev=FC ;;
388            -fc=* | --fc=*)
389                FC=$ac_optarg ;;
390            
391            -ieee | --ieee)
392                IEEE=1 ;;
393            -noieee | --noieee)
394                IEEE=0 ;;
395            
396            -mpi | --mpi)
397                MPI=1 ;;
398            -nompi | --nompi)
399                MPI=0 ;;
400            
401            -jam | --jam)
402                JAM=1 ;;
403            -nojam | --nojam)
404                JAM=0 ;;
405            
406            -ds | --ds)
407                DUMPSTATE=t ;;
408            
409            -*)
410                echo "Error: unrecognized option: "$ac_option
411                usage
412                ;;
413            
414            *)
415                echo "Error: unrecognized argument: "$ac_option
416                usage
417                ;;
418            
419        esac
420        
421  done  done
422  parse_options  
423    if test "x${ROOTDIR}" = x ; then
424        if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
425            ROOTDIR=".."
426        else
427            for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
428                if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
429                    ROOTDIR=$d
430                    echo -n "Warning:  ROOTDIR was not specified but there appears to be"
431                    echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
432                    break
433                fi
434            done
435        fi
436    fi
437    if test "x${ROOTDIR}" = x ; then
438        echo "Error: Cannot determine ROOTDIR for MITgcm code."
439        echo "  Please specify a ROOTDIR using either an options "
440        echo "  file or a command-line option."
441        exit 1
442    fi
443    if test ! -d ${ROOTDIR} ; then
444        echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
445        exit 1
446    fi
447    
448  echo "  getting OPTFILE information:  "  echo "  getting OPTFILE information:  "
449  if test "x${OPTFILE}" = x ; then  if test "x${OPTFILE}" = x ; then
450      echo "Warning: no OPTFILE specified so we'll look for possible settings"      if test "x$MITGCM_OF" = x ; then
451      echo $'\n'"===  Searching for possible settings for OPTFILE  ==="          echo "Warning: no OPTFILE specified so we'll look for possible settings"
452      find_possible_configs          printf "\n===  Searching for possible settings for OPTFILE  ===\n"
453  else          find_possible_configs
     if test "x$OPTFILE" = xNONE ; then  
         echo "    OPTFILE=NONE so we'll try to use default settings"  
454      else      else
455          if test -f "$OPTFILE" -a -r "$OPTFILE" ; then          OPTFILE=$MITGCM_OF
456              echo "    using OPTFILE=\"$OPTFILE\""      fi
457              source "$OPTFILE"  fi
458              RETVAL=$?  if test "x$OPTFILE" != xNONE ; then
459              if test "x$RETVAL" != x0 ; then      if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
460                  echo -n "Error: failed to source OPTFILE \"$OPTFILE\""          echo "    using OPTFILE=\"$OPTFILE\""
461                  echo "--please check that variable syntax is bash-compatible"          source "$OPTFILE"
462                  exit 1          RETVAL=$?
463              fi          if test "x$RETVAL" != x0 ; then
464          else              echo -n "Error: failed to source OPTFILE \"$OPTFILE\""
465              echo "Error: can't read OPTFILE=\"$OPTFILE\""              echo "--please check that variable syntax is bash-compatible"
466              exit 1              exit 1
467          fi          fi
468            if test "x$DUMPSTATE" != xf ; then
469                cp -f $OPTFILE "gm_optfile"
470            fi
471        else
472            echo "Error: can't read OPTFILE=\"$OPTFILE\""
473            exit 1
474      fi      fi
475  fi  fi
476    
477  echo $'\n'"===  Setting defaults  ==="  #  Check that FC, LINK, CPP, and S64 are defined.  If not, complain
478    #  and abort!
479    if test "x$FC" = x ; then
480        cat <<EOF 1>&2
481    
482    Error: no Fortran compiler: please specify using one of the following:
483      1) within the options file ("FC=...") as specified by "-of=OPTFILE"
484      2) the "-fc=XXX" command-line option
485      3) the "./gm_local" file
486    EOF
487        exit 1
488    fi
489    if test "x$LINK" = x ; then
490        LINK=$FC
491    fi
492    if test "x$CPP" = x ; then
493        CPP="cpp"
494    fi
495    echo "#define A a" | cpp > test_cpp 2>&1
496    RETVAL=$?
497    if test "x$RETVAL" != x0 ; then
498        cat <<EOF 1>&2
499    
500    Error: C pre-processor "$CPP" failed the test case: please specify using:
501    
502      1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
503      2) the "./gm_local" file
504    
505    EOF
506        exit 1
507    else
508        rm -f test_cpp
509    fi
510    if test "x$MAKEDEPEND" = x ; then
511        MAKEDEPEND=makedepend
512    fi
513    
514    printf "\n===  Setting defaults  ===\n"
515  echo -n "  Adding MODS directories:  "  echo -n "  Adding MODS directories:  "
516  for d in $MODS ; do  for d in $MODS ; do
517      if test ! -d $d ; then      if test ! -d $d ; then
518          echo $'\n\n'"Error: MODS directory \"$d\" not found!"          echo
519            echo "Error: MODS directory \"$d\" not found!"
520          exit 1          exit 1
521      else      else
522          echo -n " $d"          echo -n " $d"
# Line 389  if test "x${PLATFORM}" = x ; then Line 533  if test "x${PLATFORM}" = x ; then
533      PLATFORM=$p_PLATFORM      PLATFORM=$p_PLATFORM
534  fi  fi
535    
 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  
   
536  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
537      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then      if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then
538          EXEDIR=../exe          EXEDIR=../exe
# Line 433  if test ! -d ${TOOLSDIR} ; then Line 552  if test ! -d ${TOOLSDIR} ; then
552      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"
553      exit 1      exit 1
554  fi  fi
555    if test "x$S64" = x ; then
556        S64='$(TOOLSDIR)/set64bitConst.sh'
557    fi
558    
559  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
560    
# Line 443  if test -r $ROOTDIR"/eesupp/src/Makefile Line 565  if test -r $ROOTDIR"/eesupp/src/Makefile
565      echo "  Making source files in eesupp from templates"      echo "  Making source files in eesupp from templates"
566      $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1      $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1
567      RETVAL=$?      RETVAL=$?
568      if test "x${RETVAL}" == "x0" ; then      if test "x${RETVAL}" = x0 ; then
569          rm -f make_eesupp.errors          rm -f make_eesupp.errors
570      else      else
571          echo "Error: problem encountered while building source files in eesupp:"          echo "Error: problem encountered while building source files in eesupp:"
# Line 452  if test -r $ROOTDIR"/eesupp/src/Makefile Line 574  if test -r $ROOTDIR"/eesupp/src/Makefile
574      fi      fi
575  fi  fi
576    
577  echo $'\n'"===  Determining package settings  ==="  printf "\n===  Determining package settings  ===\n"
578  if  test "x${PDEPEND}" = x ; then  if  test "x${PDEPEND}" = x ; then
579      tmp=$ROOTDIR"/pkg/pkg_depend"      tmp=$ROOTDIR"/pkg/pkg_depend"
580      if test -r $tmp ; then      if test -r $tmp ; then
# Line 471  echo "  getting package dependency info Line 593  echo "  getting package dependency info
593  #  Strip the comments and then convert the dependency file into  #  Strip the comments and then convert the dependency file into
594  #  two arrays: PNAME, DNAME  #  two arrays: PNAME, DNAME
595  cat $PDEPEND | sed -e 's/#.*$//g' \  cat $PDEPEND | sed -e 's/#.*$//g' \
596      | awk 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \      | awk 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \
597      > ./.pd_tmp      > ./.pd_tmp
598  RETVAL=$?  RETVAL=$?
599  if test ! "x${RETVAL}" = x0 ; then  if test ! "x${RETVAL}" = x0 ; then
# Line 544  echo "  applying package dependency rule Line 666  echo "  applying package dependency rule
666  ck=  ck=
667  while test "x$ck" != xtt ; do  while test "x$ck" != xtt ; do
668      i=0      i=0
669      rtot=${#PNAME[@]}      # rtot=${#PNAME[@]}
670        rtot=$nname
671      while test $i -lt $rtot ; do      while test $i -lt $rtot ; do
672    
673          #  Is $pname in the current $PACKAGES list?          #  Is $pname in the current $PACKAGES list?
674          pname=${PNAME[$i]}          #  pname=${PNAME[$i]}
675            tmp="pname=\"\$PNAME_$i\""
676            eval $tmp
677          pin="f"          pin="f"
678          for p in $PACKAGES ; do          for p in $PACKAGES ; do
679              if test "x$p" = "x$pname" ; then              if test "x$p" = "x$pname" ; then
# Line 557  while test "x$ck" != xtt ; do Line 682  while test "x$ck" != xtt ; do
682          done          done
683    
684          #  Is the DNAME entry a (+) or (-) rule ?          #  Is the DNAME entry a (+) or (-) rule ?
685            tmp="dname=\"\$DNAME_$i\""
686            eval $tmp
687          plus="-"          plus="-"
688          echo "${DNAME[$i]}" | grep '^+' > /dev/null 2>&1          echo $dname | grep '^+' > /dev/null 2>&1
689          RETVAL=$?          RETVAL=$?
690          if test "x$RETVAL" = x0 ; then          if test "x$RETVAL" = x0 ; then
691              plus="+"              plus="+"
692          fi          fi
693    
694          #  Is $dname in the current $PACKAGES list?          #  Is $dname in the current $PACKAGES list?
695          dname=`echo ${DNAME[$i]} | sed -e 's/^[+-]//'`          dname=`echo $dname | sed -e 's/^[+-]//'`
696          din="f"          din="f"
697          for p in $PACKAGES ; do          for p in $PACKAGES ; do
698              if test "x$p" = "x$dname" ; then              if test "x$p" = "x$dname" ; then
# Line 634  done Line 761  done
761  # done  # done
762  # echo  # echo
763    
764  echo "  Setting package-specific CPP flags in CPP_OPTIONS.h:"  echo "  Searching for CPP_OPTIONS.h (macros and flags for configuring the model):"
765  CPP_OPTIONS=  CPP_OPTIONS=
766  spaths=". $SOURCEDIRS"  spaths=". $SOURCEDIRS"
767  for i in $spaths ; do  for i in $spaths ; do
# Line 663  if test -e CPP_OPTIONS.h ; then Line 790  if test -e CPP_OPTIONS.h ; then
790  fi  fi
791  cat <<EOF >>CPP_OPTIONS.h.tmp  cat <<EOF >>CPP_OPTIONS.h.tmp
792  C=== GENMAKE v2 ===  C=== GENMAKE v2 ===
793  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
794  C  them only if you know what you're doing.  In general, you should  C  edit anything below these comments.  In general, you should
795  C  add or remove packages by re-running genmake with different  C  add or remove packages by re-running genmake with different
796  C  "-enable" and/or "-disable" options.  C  "-enable" and/or "-disable" options.
797    
# Line 751  for d in $STANDARDDIRS ; do Line 878  for d in $STANDARDDIRS ; do
878  done  done
879    
880    
881  echo $'\n'"===  Creating the Makefile  ==="  echo
882    echo "===  Creating the Makefile  ==="
883  echo "  setting INCLUDES"  echo "  setting INCLUDES"
884  for i in $INCLUDEDIRS ; do  for i in $INCLUDEDIRS ; do
885      if test -d $i ; then      if test -d $i ; then
# Line 766  rm -rf .links.tmp Line 894  rm -rf .links.tmp
894  mkdir .links.tmp  mkdir .links.tmp
895  echo "# This section creates symbolic links" > srclinks.tmp  echo "# This section creates symbolic links" > srclinks.tmp
896  echo "" >> srclinks.tmp  echo "" >> srclinks.tmp
897  echo -n 'SRCFILES = ' > srclist.inc  echo -n 'SRCFILES = '    > srclist.inc
898  echo -n 'CSRCFILES = ' > csrclist.inc  echo -n 'CSRCFILES = '   > csrclist.inc
899    echo -n 'F90SRCFILES = ' > f90srclist.inc
900  echo -n 'HEADERFILES = ' > hlist.inc  echo -n 'HEADERFILES = ' > hlist.inc
901  alldirs=". $SOURCEDIRS $INCLUDEDIRS"  alldirs="$SOURCEDIRS $INCLUDEDIRS ."
902  for d in $alldirs ; do  for d in $alldirs ; do
903      deplist=      deplist=
904      sfiles=`( cd $d; echo *.[h,c,F] )`      sfiles=`( cd $d; echo *.[h,c,F] )`
905        sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
906      for sf in $sfiles ; do      for sf in $sfiles ; do
907          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
908              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
# Line 784  for d in $alldirs ; do Line 914  for d in $alldirs ; do
914                          echo    " \\"  >> srclist.inc                          echo    " \\"  >> srclist.inc
915                          echo -n " $sf" >> srclist.inc                          echo -n " $sf" >> srclist.inc
916                          ;;                          ;;
917                        F90)
918                            echo    " \\"  >> f90srclist.inc
919                            echo -n " $sf" >> f90srclist.inc
920                            ;;
921                      c)                      c)
922                          echo    " \\"  >> csrclist.inc                          echo    " \\"  >> csrclist.inc
923                          echo -n " $sf" >> csrclist.inc                          echo -n " $sf" >> csrclist.inc
# Line 797  for d in $alldirs ; do Line 931  for d in $alldirs ; do
931          fi          fi
932      done      done
933      if test "x$deplist" != x ; then      if test "x$deplist" != x ; then
934          echo $'\n'"#  These files are linked from $d" >> srclinks.tmp          echo "" >> srclinks.tmp
935            echo "#  These files are linked from $d" >> srclinks.tmp
936          echo "$deplist :" >> srclinks.tmp          echo "$deplist :" >> srclinks.tmp
937          echo $'\t$(LN) '$d'/$@ $@' >> srclinks.tmp          printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp
938      fi      fi
939  done  done
940  rm -rf .links.tmp  rm -rf .links.tmp
941  echo "" >> srclist.inc  echo "" >> srclist.inc
942  echo "" >> csrclist.inc  echo "" >> csrclist.inc
943    echo "" >> f90srclist.inc
944  echo "" >> hlist.inc  echo "" >> hlist.inc
945    
946  if test -e $MAKEFILE ; then  if test -e $MAKEFILE ; then
# Line 862  MAKEDEPEND = ${MAKEDEPEND} Line 998  MAKEDEPEND = ${MAKEDEPEND}
998  KPP = ${KPP}  KPP = ${KPP}
999  # Fortran compiler  # Fortran compiler
1000  FC = ${FC}  FC = ${FC}
1001    # Fortran compiler
1002    F90C = ${F90C}
1003  # Link editor  # Link editor
1004  LINK = ${LINK}  LINK = ${LINK}
1005    
# Line 875  KFLAGS2 = ${KFLAGS2} Line 1013  KFLAGS2 = ${KFLAGS2}
1013  # Optim./debug for FC  # Optim./debug for FC
1014  FFLAGS = ${FFLAGS}  FFLAGS = ${FFLAGS}
1015  FOPTIM = ${FOPTIM}  FOPTIM = ${FOPTIM}
1016    # Optim./debug for FC
1017    F90FLAGS = ${F90FLAGS}
1018    F90OPTIM = ${F90OPTIM}
1019  # Flags for CC  # Flags for CC
1020  CFLAGS = ${CFLAGS}  CFLAGS = ${CFLAGS}
1021  # Files that should not be optimized  # Files that should not be optimized
# Line 882  NOOPTFILES = ${NOOPTFILES} Line 1023  NOOPTFILES = ${NOOPTFILES}
1023  NOOPTFLAGS = ${NOOPTFLAGS}  NOOPTFLAGS = ${NOOPTFLAGS}
1024  # Flags and libraries needed for linking  # Flags and libraries needed for linking
1025  LIBS = ${LIBS} \$(XLIBS)  LIBS = ${LIBS} \$(XLIBS)
1026    # Name of the Mekfile
1027    MAKEFILE=${MAKEFILE}
1028    
1029  EOF  EOF
1030    
1031  cat srclist.inc  >> $MAKEFILE  cat srclist.inc    >> $MAKEFILE
1032  cat csrclist.inc >> $MAKEFILE  cat csrclist.inc   >> $MAKEFILE
1033  cat hlist.inc >> $MAKEFILE  cat f90srclist.inc >> $MAKEFILE
1034  echo 'F77FILES =  $(SRCFILES:.F=.f)'                    >> $MAKEFILE  cat hlist.inc      >> $MAKEFILE
1035  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o)' >> $MAKEFILE  echo 'F77FILES =  $(SRCFILES:.F=.f)'                                           >> $MAKEFILE
1036    echo 'F90FILES =  $(F90SRCFILES:.F90=.f90)'                                    >> $MAKEFILE
1037    echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
1038    
1039  rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp  rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc
1040    
1041  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
1042    
1043  .SUFFIXES:  .SUFFIXES:
1044  .SUFFIXES: .o .f .p .F .c  .SUFFIXES: .o .f .p .F .c .F90 .f90
1045    
1046  all: \$(EXECUTABLE)  all: \$(EXECUTABLE)
1047  \$(EXECUTABLE): \$(OBJFILES)  \$(EXECUTABLE): \$(OBJFILES)
# Line 904  all: \$(EXECUTABLE) Line 1049  all: \$(EXECUTABLE)
1049  depend:  depend:
1050          @make links          @make links
1051          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
1052            ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE)
1053    
1054  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES)  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)
1055    
1056  small_f: \$(F77FILES)  small_f: \$(F77FILES) \$(F90FILES)
1057    
1058  output.txt: \$(EXECUTABLE)  output.txt: \$(EXECUTABLE)
1059          @printf 'running ... '          @printf 'running ... '
1060          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
1061    
1062  clean:  clean:
1063          -rm -rf *.o *.f *.p ${RMFILES} work.{pc,pcl}          -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}
1064  Clean:  Clean:
1065          @make clean          @make clean
1066          @make cleanlinks          @make cleanlinks
# Line 936  cleanlinks: Line 1082  cleanlinks:
1082          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1083  .f.o:  .f.o:
1084          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
1085    .F90.f90:
1086            \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1087    .f90.o:
1088            \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
1089  .c.o:  .c.o:
1090          \$(CC) \$(CFLAGS) -c \$<          \$(CC) \$(CFLAGS) -c \$<
1091    
# Line 947  cleanlinks: Line 1097  cleanlinks:
1097    
1098  EOF  EOF
1099    
1100    if test "x$EXEHOOK" != x ; then
1101        printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
1102    fi
1103    
1104  echo "  Making list of \"exceptions\" that need \".p\" files"  echo "  Making list of \"exceptions\" that need \".p\" files"
1105  for i in $KPPFILES ; do  for i in $KPPFILES ; do
1106      base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`      base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
# Line 965  for i in $NOOPTFILES ; do Line 1119  for i in $NOOPTFILES ; do
1119          echo "Error: unable to add file \"$i\" to the exceptions list"          echo "Error: unable to add file \"$i\" to the exceptions list"
1120      fi      fi
1121      echo "$base.o: $base.f" >> $MAKEFILE      echo "$base.o: $base.f" >> $MAKEFILE
1122      echo $'\t$(FC) $(FFLAGS) $(NOOPTFLAGS) -c $<' >> $MAKEFILE      printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
1123  done  done
1124    
1125  echo "  Add rules for links"  echo "  Add rules for links"
# Line 973  cat srclinks.tmp >> $MAKEFILE Line 1127  cat srclinks.tmp >> $MAKEFILE
1127  rm -f srclinks.tmp  rm -f srclinks.tmp
1128    
1129  echo "  Adding makedepend marker"  echo "  Adding makedepend marker"
1130  echo $'\n\n'"# DO NOT DELETE" >> $MAKEFILE  printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
1131    
1132    printf "\n===  Done  ===\n"
1133    
1134    
1135  echo $'\n'"===  Done  ==="  #  Write the "state" for future records
1136    if test "x$DUMPSTATE" != xf ; then
1137        echo -n "" > gm_state
1138        for i in $gm_state ; do
1139            t1="t2=\$$i"
1140            eval $t1
1141            echo "$i='$t2'" >> gm_state
1142        done
1143    fi

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

  ViewVC Help
Powered by ViewVC 1.1.22