/[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.36 by edhill, Fri Nov 14 02:48:18 2003 UTC revision 1.70 by edhill, Sat Feb 28 05:01:12 2004 UTC
# Line 1  Line 1 
1  #!/bin/sh  #! /usr/bin/env bash
2  #  #
3  # $Header$  # $Header$
4  #  #
# Line 13  Line 13 
13  test_for_package_in_cpp_options() {  test_for_package_in_cpp_options() {
14      cpp_options=$1      cpp_options=$1
15      pkg=$2      pkg=$2
16      grep -i "#define.*ALLOW_$pkg" $cpp_options > /dev/null 2>&1      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg" || exit 99
17      RETVAL=$?      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg" || exit 99
18      if test "x${RETVAL}" = x0 ; then      test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg" || exit 99
19          echo "Error: In $cpp_options there is an illegal line: #define ALLOW_$pkg"      test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg" || exit 99
20          exit 99  }
21      fi  
22      grep -i "#undef.*ALLOW_$pkg" $cpp_options > /dev/null 2>&1  # Search for particular CPP #cmds associated with MPI
23      RETVAL=$?  # usage: test_for_mpi_in_cpp_eeoptions CPP_file
24      if test "x${RETVAL}" = x0 ; then  test_for_mpi_in_cpp_eeoptions() {
25          echo "Error: In $cpp_options there is an illegal line: #undef ALLOW_$pkg"      cpp_options=$1
26          exit 99      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI" || exit 99
27      fi      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI" || exit 99
28      grep -i "#define.*DISABLE_$pkg" $cpp_options > /dev/null 2>&1      test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI" || exit 99
29        test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI" || exit 99
30    }
31    
32    # Search for particular string in a file. Return 1 if detected, 0 if not
33    # usage: test_for_string_in_file file string
34    test_for_string_in_file() {
35        file=$1
36        strng=$2
37        grep -i "$strng" $file > /dev/null 2>&1
38      RETVAL=$?      RETVAL=$?
39      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
40          echo "Error: In $cpp_options there is an illegal line: #define DISABLE_$pkg"          echo -n "Error: In $file there is an illegal line: "
41          exit 99          grep -i "$strng" $file
42            return 1
43      fi      fi
44      grep -i "#undef.*DISABLE_$pkg" $cpp_options > /dev/null 2>&1      return 0
     RETVAL=$?  
     if test "x${RETVAL}" = x0 ; then  
         echo "Error: In $cpp_options there is an illegal line: #undef DISABLE_$pkg"  
         exit 99  
    fi  
45  }  }
46    
47  # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to  # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to
# Line 73  find_possible_configs()  { Line 78  find_possible_configs()  {
78      tmp1=`uname`"_"`uname -m`      tmp1=`uname`"_"`uname -m`
79      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
80      tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`      tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
81      PLATFORM=`echo $tmp3 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`      tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
82        tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
83        PLATFORM=$tmp2
84      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
85      echo "  The platform appears to be:  $PLATFORM"      echo "  The platform appears to be:  $PLATFORM"
 #     if test "x$OFLIST" = x ; then  
 #       echo "  No pre-defined options files were found matching this platform"  
 #       echo "  but examples for other platforms can be found in:"  
 #       echo "    $ROOTDIR/tools/build_options"  
 #     else  
 #       echo "  Options files (located in $ROOTDIR/tools/build_options) that"  
 #       echo "  may work with this machine are:"  
 #       for i in $OFLIST ; do  
 #           echo "    $i"  
 #       done  
 #     fi  
86            
87      echo "test" > test      echo "test" > test
88      ln -s ./test link      ln -s ./test link
# Line 104  find_possible_configs()  { Line 100  find_possible_configs()  {
100          CPP="cpp -traditional -P"          CPP="cpp -traditional -P"
101      fi      fi
102    
103      # makedepend is not always available      #  The "original" makedepend is part of the Imake system that is
104        #  most often distributed with XFree86 or with an XFree86 source
105        #  package.  As a result, many machines (eg. generic Linux) do not
106        #  have a system-default "makedepend" available.  For those
107        #  systems, we have two fall-back options:
108        #
109        #    1) a makedepend implementation shipped with the cyrus-imapd
110        #       package:  ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
111        #
112        #    2) a known-buggy xmakedpend shell script
113        #
114        #  So the choices are, in order:
115        #
116        #    1) use the user-specified program
117        #    2) use a system-wide default
118        #    3) locally build and use the cyrus implementation
119        #    4) fall back to the buggy local xmakedpend script
120        #
121      if test "x${MAKEDEPEND}" = x ; then      if test "x${MAKEDEPEND}" = x ; then
122        which makedepend >& /dev/null        which makedepend >& /dev/null
123        RETVAL=$?        RETVAL=$?
124        if test "x${RETVAL}" = x1 ; then        if test ! "x${RETVAL}" = x0 ; then
125           echo "    makedepend was not found. Using xmakedpend instead."           echo "    a system-default makedepend was not found."
126           MAKEDEPEND='$(TOOLSDIR)/xmakedepend'  
127             #  Try to build the cyrus impl
128             rm -f ./genmake_cy_md
129             (
130                 cd $ROOTDIR/tools/cyrus-imapd-makedepend  \
131                     &&  ./configure > /dev/null 2>&1  \
132                     &&  make > /dev/null 2>&1  \
133                     &&  ./makedepend ifparser.c > /dev/null 2>&1  \
134                     &&  echo "true"
135             ) > ./genmake_cy_md
136             grep true ./genmake_cy_md > /dev/null 2>&1
137             RETVAL=$?
138             if test "x$RETVAL" = x0 ; then
139                 MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
140             else
141                 MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
142             fi
143             rm -f ./genmake_cy_md
144        fi        fi
145      fi      fi
146    
# Line 149  EOF Line 179  EOF
179          echo "   "$p_FC          echo "   "$p_FC
180          if test "x$FC" = x ; then          if test "x$FC" = x ; then
181              FC=`echo $p_FC | $AWK '{print $1}'`              FC=`echo $p_FC | $AWK '{print $1}'`
182                echo "  Setting FORTRAN compiler to: "$FC
183          fi          fi
184      fi      fi
185    
186      for i in $p_FC ; do      if test "x$OPTFILE" = x ; then
187          p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i          OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
188          if test -r $p_OF ; then          if test ! -r $OPTFILE ; then
189              OPTFILE=$p_OF               echo "  I looked for the file "$OPTFILE" but did not find it"
190              echo "  The options file:  $p_OF"          fi
191              echo "    appears to match so we'll use it."      fi
192              break  #    echo "  The options file:  $p_OF"
193          fi  #    echo "    appears to match so we'll use it."
194      done  #   for i in $p_FC ; do
195    #p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
196    #if test -r $p_OF ; then
197    #    OPTFILE=$p_OF
198    #    echo "  The options file:  $p_OF"
199    #    echo "    appears to match so we'll use it."
200    #    break
201    #fi
202    #   done
203      if test "x$OPTFILE" = x ; then      if test "x$OPTFILE" = x ; then
204          cat 1>&2 <<EOF          cat 1>&2 <<EOF
205    
# Line 225  get_pdepend_list()  { Line 264  get_pdepend_list()  {
264    
265  #  Explain usage  #  Explain usage
266  usage()  {  usage()  {
267      echo  cat <<EOF
268      echo "Usage: "$0" [OPTIONS]"  
269      echo "  where [OPTIONS] can be:"  Usage: "$0" [OPTIONS]
270      echo    where [OPTIONS] can be:
271      echo "    -help | --help | -h | --h"  
272      echo "    -nooptfile | --nooptfile"      -help | --help | -h | --h
273      echo "      -optfile NAME | --optfile NAME | -of NAME | --of NAME"            Print this help message and exit.
274      echo "      -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME"  
275      echo "    -pdepend NAME | --pdepend NAME"      -nooptfile | --nooptfile
276      echo "      -pdepend=NAME | --pdepend=NAME"        -optfile NAME | --optfile NAME | -of NAME | --of NAME
277      echo "    -pdefault NAME | --pdefault NAME"        -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
278      echo "      -pdefault=NAME | --pdefault=NAME"            Use "NAME" as the optfile.  By default, an attempt will be
279      echo "    -make NAME | -m NAME"            made to find an appropriate "standard" optfile in the
280      echo "      --make=NAME | -m=NAME"            tools/build_options/ directory.
281      echo "    -makefile NAME | -mf NAME"  
282      echo "      --makefile=NAME | -mf=NAME"      -pdepend NAME | --pdepend NAME
283      echo "    -platform NAME | --platform NAME | -pl NAME | --pl NAME"        -pdepend=NAME | --pdepend=NAME
284      echo "      -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"            Get package dependency information from "NAME".
285      echo "    -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"  
286      echo "      -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME"      -pdefault NAME | --pdefault NAME
287      echo "    -mods NAME | --mods NAME | -mo NAME | --mo NAME"        -pdefault=NAME | --pdefault=NAME
288      echo "      -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME"            Get the default package list from "NAME".
289      echo "    -disable NAME | --disable NAME"  
290      echo "      -disable=NAME | --disable=NAME"      -make NAME | -m NAME
291      echo "    -enable NAME | --enable NAME"        --make=NAME | -m=NAME
292      echo "      -enable=NAME | --enable=NAME"            Use "NAME" for the MAKE program. The default is "make" but
293      echo "    -standarddirs NAME | --standarddirs NAME"            many platforms, "gmake" is the preferred choice.
294      echo "      -standarddirs=NAME | --standarddirs=NAME"  
295      echo "    -noopt NAME | --noopt NAME"      -makefile NAME | -mf NAME
296      echo "      -noopt=NAME | --noopt=NAME"        --makefile=NAME | -mf=NAME
297  #    echo "    -cpp NAME | --cpp NAME"            Call the makefile "NAME".  The default is "Makefile".
298  #    echo "      -cpp=NAME | --cpp=NAME"  
299      echo "    -fortran NAME | --fortran NAME | -fc NAME | --fc NAME"      -makedepend NAME | -md NAME
300      echo "      -fc=NAME | --fc=NAME"        --makedepend=NAME | -md=NAME
301      echo "    -[no]ieee | --[no]ieee"            Use "NAME" for the MAKEDEPEND program.
302      echo "    -[no]mpi | --[no]mpi"  
303      echo "    -[no]jam | --[no]jam"      -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
304      echo        -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
305      echo "  and NAME is a string such as:"            Specify the location of the MITgcm ROOTDIR as "NAME".
306      echo            By default, genamke will try to find the location by
307      echo "    --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'"            looking in parent directories (up to the 5th parent).
308      echo "    -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'"  
309      echo "    -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"      -mods NAME | --mods NAME | -mo NAME | --mo NAME
310      echo        -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
311      echo "  which, depending upon your shell, may need to be single-quoted"            Here, "NAME" specifies a list of directories that are
312      echo "  if it contains spaces, dashes, or other special characters."            used for additional source code.  Files found in the
313              "mods list" are given preference over files of the same
314              name found elsewhere.
315    
316        -disable NAME | --disable NAME
317          -disable=NAME | --disable=NAME
318              Here "NAME" specifies a list of packages that we don't
319              want to use.  If this violates package dependencies,
320              genamke will exit with an error message.
321    
322        -enable NAME | --enable NAME
323          -enable=NAME | --enable=NAME
324              Here "NAME" specifies a list of packages that we wish
325              to specifically enable.  If this violates package
326              dependencies, genamke will exit with an error message.
327    
328        -standarddirs NAME | --standarddirs NAME
329          -standarddirs=NAME | --standarddirs=NAME
330              Here, "NAME" specifies a list of directories to be
331              used as the "standard" code.
332    
333        -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
334          -fc=NAME | --fc=NAME
335              Use "NAME" as the fortran compiler.  By default, genmake
336              will search for a working compiler by trying a list of
337              "usual suspects" such as g77, f77, etc.
338    
339        -[no]ieee | --[no]ieee
340              Do or don't use IEEE numerics.  Note that this option
341              *only* works if it is supported by the OPTFILE that
342              is being used.
343    
344        -mpi | --mpi
345              Include MPI header files and link to MPI libraries
346        -mpi=PATH | --mpi=PATH
347              Include MPI header files and link to MPI libraries using MPI_ROOT
348              set to PATH. i.e. Include files from $PATH/include, link to libraries
349              from $PATH/lib and use binaries from $PATH/bin.
350    
351      While it is most often a single word, the "NAME" variables specified
352      above can in many cases be a space-delimited string such as:
353    
354        --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'
355        -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'
356        -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
357    
358      which, depending upon your shell, may need to be single-quoted.
359    
360      For more detailed genmake documentation, please see:
361    
362        http://mitgcm.org/devel_HOWTO/
363    
364    EOF
365    
366      exit 1      exit 1
367  }  }
368    
# Line 281  get_fortran_c_namemangling()  { Line 373  get_fortran_c_namemangling()  {
373      cat > genmake_test.c <<EOF      cat > genmake_test.c <<EOF
374  void tcall( char * string ) { tsub( string ); }  void tcall( char * string ) { tsub( string ); }
375  EOF  EOF
376      $MAKE genmake_test.o > genmake_test.log 2>&1      $MAKE genmake_test.o >> genmake_warnings 2>&1
377      RETVAL=$?      RETVAL=$?
378      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
         cat genmake_test.log >> genmake_errors  
379          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
380          echo          cat <<EOF>> genmake_errors
381          echo "WARNING: C test compile fails -- please see \"genmake_errors\""  
382          echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"  WARNING: C test compile fails
383          echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
384    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
385    EOF
386          return 1          return 1
387      fi      fi
388      c_tcall=`nm genmake_test.o | grep tcall | cut -d ' ' -f 3`      c_tcall=`nm genmake_test.o | grep 'T ' | grep tcall | cut -d ' ' -f 3`
389      RETVAL=$?      RETVAL=$?
390      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
391          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
392          echo          cat <<EOF>> genmake_warnings
393          echo "WARNING: The \"nm\" command failed."  
394          echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"  WARNING: The "nm" command failed.
395          echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
396    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
397    EOF
398          return 1          return 1
399      fi      fi
400      cat > genmake_tcomp.f <<EOF      cat > genmake_tcomp.f <<EOF
# Line 308  EOF Line 403  EOF
403        call tsub( string )        call tsub( string )
404        end        end
405  EOF  EOF
406      $FC $FFLAGS $DEFINES -c genmake_tcomp.f > genmake_tcomp.log 2>&1      $FC $FFLAGS $DEFINES -c genmake_tcomp.f >> genmake_warnings 2>&1
407      RETVAL=$?      RETVAL=$?
408      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
         cat genmake_tcomp.log >> genmake_errors  
409          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
410          echo          cat <<EOF>> genmake_warnings
411          echo "WARNING: FORTRAN test compile fails -- please see \"genmake_errors\""  
412          echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"  WARNING: FORTRAN test compile fails -- please see "genmake_errors"
413          echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
414    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
415    EOF
416          return 1          return 1
417      fi      fi
418      f_tcall=`nm genmake_tcomp.o | grep tcall | cut -d ' ' -f 3`      f_tcall=`nm genmake_tcomp.o | grep 'T ' | grep tcall | cut -d ' ' -f 3`
419      RETVAL=$?      RETVAL=$?
420      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
421          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
422          echo          cat <<EOF>> genmake_warnings
423          echo "WARNING: The \"nm\" command failed."  
424          echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'"  WARNING: The "nm" command failed.
425          echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here."  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
426    WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
427    EOF
428          return 1          return 1
429      fi      fi
430    
# Line 353  EOF Line 451  EOF
451      rm -f genmake_tcomp.* genmake_test.*      rm -f genmake_tcomp.* genmake_test.*
452  }  }
453    
454    
455    check_HAVE_CLOC()  {
456        get_fortran_c_namemangling
457        cat <<EOF > genmake_tc_1.c
458    $FC_NAMEMANGLE
459    #include <stdio.h>
460    #include <stdlib.h>
461    #include <unistd.h>
462    #include <assert.h>
463    #include <sys/time.h>
464    void FC_NAMEMANGLE(cloc) ( double *curtim )
465    {
466     struct timeval tv1;
467     gettimeofday(&tv1 , (void *)NULL );
468     *curtim =  (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
469     *curtim = *curtim/1.E6;
470    }
471    EOF
472        make genmake_tc_1.o >> genmake_tc.log 2>&1
473        RET_C=$?
474        cat <<EOF > genmake_tc_2.f
475          program hello
476          Real*8 wtime
477          external cloc
478          call cloc(wtime)
479          print *," HELLO WORLD", wtime
480          end program hello
481    EOF
482        $FC $FFLAGS -o genmake_tc genmake_tc_2.f genmake_tc_1.o >> genmake_tc.log 2>&1
483        RET_F=$?
484        test -x ./genmake_tc  &&  ./genmake_tc >> genmake_tc.log 2>&1
485        RETVAL=$?
486        if test "x$RETVAL" = x0 ; then
487            HAVE_CLOC=t
488            DEFINES="$DEFINES -DHAVE_CLOC"
489        fi
490        rm -f genmake_tc*
491    }
492    
493    
494    check_netcdf_libs()  {
495        cat <<EOF > genmake_tnc.F
496          program fgennc
497    #include "netcdf.inc"
498          integer iret, ncid, xid
499          iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
500          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
501          iret = nf_def_dim(ncid, 'X', 11, xid)
502          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
503          iret = nf_close(ncid)
504          IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
505          end
506    EOF
507        $CPP genmake_tnc.F > genmake_tnc.f  \
508            &&  $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f $LIBS >> genmake_tnc.log 2>&1
509        RET_COMPILE=$?
510        test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1
511        RETVAL=$?
512        if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
513            HAVE_NETCDF=t
514        else
515            # try again with "-lnetcdf" added to the libs
516            $CPP genmake_tnc.F > genmake_tnc.f  \
517                &&  $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f \
518                $LIBS -lnetcdf >> genmake_tnc_2.log 2>&1
519            RET_COMPILE=$?
520            test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1
521            RETVAL=$?
522            if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
523                LIBS="$LIBS -lnetcdf"
524                HAVE_NETCDF=t
525            else
526                cat genmake_tnc.log >> genmake_warnings
527            fi
528        fi
529        rm -f genmake_tnc*
530    }
531    
532    
533    
534    ###############################################################################
535    #   Sequential part of script starts here
536    ###############################################################################
537    
538  #  Set defaults here  #  Set defaults here
539  COMMANDL="$0 $@"  COMMANDL="$0 $@"
540    
# Line 361  LN= Line 543  LN=
543  S64=  S64=
544  KPP=  KPP=
545  FC=  FC=
546    CPP=
547  LINK=  LINK=
 # DEFINES="-DWORDLENGTH=4"  
548  DEFINES=  DEFINES=
549  PACKAGES=  PACKAGES=
550  ENABLE=  ENABLE=
# Line 379  FOPTIM= Line 561  FOPTIM=
561  CFLAGS=  CFLAGS=
562  KFLAGS1=  KFLAGS1=
563  KFLAGS2=  KFLAGS2=
564    #LDADD=
565  LIBS=  LIBS=
566  KPPFILES=  KPPFILES=
567  NOOPTFILES=  NOOPTFILES=
568  NOOPTFLAGS=  NOOPTFLAGS=
569    MPI=
570    MPIPATH=
571    
572  # DEFINES checked by test compilation  # DEFINES checked by test compilation
573  HAVE_SYSTEM=  HAVE_SYSTEM=
574  HAVE_FDATE=  HAVE_FDATE=
575  FC_NAMEMANGLE=  FC_NAMEMANGLE=
576    HAVE_CLOC=
577    HAVE_NETCDF=
578    
579  MODS=  MODS=
580  TOOLSDIR=  TOOLSDIR=
581  SOURCEDIRS=  SOURCEDIRS=
582  INCLUDEDIRS=  INCLUDEDIRS=
583  STANDARDDIRS=  STANDARDDIRS="USE_THE_DEFAULT"
584    
585  PWD=`pwd`  PWD=`pwd`
586  MAKE=make  MAKE=make
# Line 426  TAMC_EXTRA= Line 613  TAMC_EXTRA=
613    
614    
615  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
616  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"
617  gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS"  gm_s2="FC CPP IEEE MPI JAM DUMPSTATE STANDARDDIRS"
618    
619  #  The following state is not directly set by command-line switches  #  The following state is not directly set by command-line switches
620  gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "  gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
# Line 444  gm_s12="TAF_EXTRA TAMC_EXTRA" Line 631  gm_s12="TAF_EXTRA TAMC_EXTRA"
631  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"
632  gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"  gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
633    
634    cat <<EOF
635    
636    GENMAKE :
637    
638    A program for GENerating MAKEfiles for the MITgcm project.  For a
639    quick list of options, use "genmake -h" or for more detail see:
640    
641      http://mitgcm.org/devel_HOWTO/
642    
643    EOF
644    
 echo  
645  echo "===  Processing options files and arguments  ==="  echo "===  Processing options files and arguments  ==="
646  gm_local="genmake_local"  gm_local="genmake_local"
647  for i in . $MODS ; do  for i in . $MODS ; do
# Line 499  for ac_option ; do Line 695  for ac_option ; do
695          -optfile=* | --optfile=* | -of=* | --of=*)          -optfile=* | --optfile=* | -of=* | --of=*)
696              OPTFILE=$ac_optarg ;;              OPTFILE=$ac_optarg ;;
697                    
698          -adoptfile | --adoptfile | -ad | --ad)          -adoptfile | --adoptfile | -adof | --adof)
699              ac_prev=AD_OPTFILE ;;              ac_prev=AD_OPTFILE ;;
700          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
701              AD_OPTFILE=$ac_optarg ;;              AD_OPTFILE=$ac_optarg ;;
# Line 519  for ac_option ; do Line 715  for ac_option ; do
715          -make=* | --make=* | -m=* | --m=*)          -make=* | --make=* | -m=* | --m=*)
716              MAKE=$ac_optarg ;;              MAKE=$ac_optarg ;;
717                    
718            -makedepend | --makedepend | -md | --md)
719                ac_prev=MAKEDEPEND ;;
720            -makedepend=* | --makedepend=* | -md=* | --md=*)
721                MAKEDEPEND=$ac_optarg ;;
722            
723          -makefile | --makefile | -ma | --ma)          -makefile | --makefile | -ma | --ma)
724              ac_prev=MAKEFILE ;;              ac_prev=MAKEFILE ;;
725          -makefile=* | --makefile=* | -ma=* | --ma=*)          -makefile=* | --makefile=* | -ma=* | --ma=*)
726              MAKEFILE=$ac_optarg ;;              MAKEFILE=$ac_optarg ;;
727                    
728          -platform | --platform | -pl | --pl)          -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
729              ac_prev=PLATFORM ;;              echo "ERROR: The platform option has been removed.  Please specify"
730          -platform=* | --platform=* | -pl=* | --pl=*)              echo "  the build options using the \"optfile\" mechanism."
731              PLATFORM=$ac_optarg ;;              echo
732                usage
733                ;;
734                    
735          -rootdir | --rootdir | -rd | --rd)          -rootdir | --rootdir | -rd | --rd)
736              ac_prev=ROOTDIR ;;              ac_prev=ROOTDIR ;;
# Line 554  for ac_option ; do Line 757  for ac_option ; do
757          -standarddirs=* | --standarddirs=*)          -standarddirs=* | --standarddirs=*)
758              STANDARDDIRS=$ac_optarg ;;              STANDARDDIRS=$ac_optarg ;;
759    
         -noopt | --noopt)  
             ac_prev=NOOPT ;;  
         -noopt=* | --noopt=*)  
             NOOPT=$ac_optarg ;;  
           
760  #           -cpp | --cpp)  #           -cpp | --cpp)
761  #               ac_prev=cpp ;;  #               ac_prev=cpp ;;
762  #           -cpp=* | --cpp=*)  #           -cpp=* | --cpp=*)
# Line 573  for ac_option ; do Line 771  for ac_option ; do
771              IEEE=true ;;              IEEE=true ;;
772          -noieee | --noieee)          -noieee | --noieee)
773              IEEE= ;;              IEEE= ;;
774            
775          -mpi | --mpi)          -mpi | --mpi)
776              MPI=true ;;              MPI=true ;;
777          -nompi | --nompi)          -mpi=* | --mpi=*)
778              MPI= ;;              MPIPATH=$ac_optarg
779                MPI=true ;;
780                    
781          -jam | --jam)  #       -jam | --jam)
782              JAM=1 ;;  #           JAM=1 ;;
783          -nojam | --nojam)  #       -nojam | --nojam)
784              JAM=0 ;;  #           JAM=0 ;;
785                    
786          -ds | --ds)          -ds | --ds)
787              DUMPSTATE=t ;;              DUMPSTATE=t ;;
# Line 704  if test "x${AD_OPTFILE}" != xNONE ; then Line 903  if test "x${AD_OPTFILE}" != xNONE ; then
903      fi      fi
904  fi  fi
905    
906  #  Check that FC, LINK, CPP, S64, and LN are defined.  If not,  #  Check that FC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
907  #  complain and abort!  #  either set defaults or complain and abort!
908  if test "x$FC" = x ; then  if test "x$FC" = x ; then
909      cat <<EOF 1>&2      cat <<EOF 1>&2
910    
# Line 719  fi Line 918  fi
918  if test "x$LINK" = x ; then  if test "x$LINK" = x ; then
919      LINK=$FC      LINK=$FC
920  fi  fi
921    if test "x$MAKE" = x ; then
922        MAKE="make"
923    fi
924  if test "x$CPP" = x ; then  if test "x$CPP" = x ; then
925      CPP="cpp"      CPP=cpp
926  fi  fi
927    #EH3 === UGLY ===
928    #  The following an ugly little hack to check for $CPP in /lib/ and it
929    #  should eventually be replaced with a more general function that
930    #  searches a combo of the user's path and a list of "usual suspects"
931    #  to find the correct location for binaries such as $CPP.
932    for i in " " "/lib/" ; do
933        echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
934    done
935    #EH3 === UGLY ===
936  echo "#define A a" | $CPP > test_cpp 2>&1  echo "#define A a" | $CPP > test_cpp 2>&1
937  RETVAL=$?  RETVAL=$?
938  if test "x$RETVAL" != x0 ; then  if test "x$RETVAL" != x0 ; then
# Line 758  EOF Line 969  EOF
969  fi  fi
970  rm -f genmake_test_ln genmake_tlink  rm -f genmake_test_ln genmake_tlink
971    
972    if test ! "x$MPI" = x ; then
973          echo "  Turning on MPI cpp macros"
974          DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
975    fi
976    
977  printf "\n===  Checking system libraries  ===\n"  printf "\n===  Checking system libraries  ===\n"
978  echo -n "  Do we have the system() command using $FC...  "  echo -n "  Do we have the system() command using $FC...  "
979  cat > genmake_tcomp.f <<EOF  cat > genmake_tcomp.f <<EOF
# Line 798  else Line 1014  else
1014  fi  fi
1015  rm -f genmake_tcomp*  rm -f genmake_tcomp*
1016    
1017  echo "  The name mangling convention for $FC is...  "  echo -n "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
1018  #FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) X ## _"  check_HAVE_CLOC
1019  if test "x$FC_NAMEMANGLE" = x ; then  if test "x$HAVE_CLOC" != x ; then
1020      get_fortran_c_namemangling      echo "yes"
1021    else
1022        echo "no"
1023  fi  fi
1024  echo "    '$FC_NAMEMANGLE'"  rm -f genmake_t*
1025  echo "$FC_NAMEMANGLE" > FC_NAMEMANGLE.h.template  
1026  cmp FC_NAMEMANGLE.h FC_NAMEMANGLE.h.template > /dev/null 2>&1  echo -n "  Can we create NetCDF-enabled binaries...  "
1027  RETVAL=$?  check_netcdf_libs
1028  if test "x$RETVAL" != x0 ; then  if test "x$HAVE_NETCDF" != x ; then
1029      mv -f FC_NAMEMANGLE.h.template FC_NAMEMANGLE.h      echo "yes"
1030    else
1031        echo "no"
1032  fi  fi
1033    
1034    
# Line 850  if test "x${TOOLSDIR}" = x ; then Line 1070  if test "x${TOOLSDIR}" = x ; then
1070      TOOLSDIR="$ROOTDIR/tools"      TOOLSDIR="$ROOTDIR/tools"
1071  fi  fi
1072  if test ! -d ${TOOLSDIR} ; then  if test ! -d ${TOOLSDIR} ; then
1073      echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
1074      exit 1      exit 1
1075  fi  fi
1076  if test "x$S64" = x ; then  if test "x$S64" = x ; then
1077      S64='$(TOOLSDIR)/set64bitConst.sh'      S64='$(TOOLSDIR)/set64bitConst.sh'
1078  fi  fi
1079    THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
1080    
1081  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1082    
# Line 870  if test -r $ROOTDIR"/eesupp/src/Makefile Line 1091  if test -r $ROOTDIR"/eesupp/src/Makefile
1091          rm -f make_eesupp.errors          rm -f make_eesupp.errors
1092      else      else
1093          echo "Error: problem encountered while building source files in eesupp:"          echo "Error: problem encountered while building source files in eesupp:"
1094          cat make_eesupp.errors          cat make_eesupp.errors 1>&2
1095          exit 1          exit 1
1096      fi      fi
1097  fi  fi
1098    
1099    #same for exch2
1100    if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then
1101        echo "  Making source files in exch2 from  templates"
1102        ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1
1103        RETVAL=$?
1104        if test "x${RETVAL}" = x0 ; then
1105            rm -f make_exch2.errors
1106        else
1107            echo "Error: problem encountered while building source files in exch2:"
1108            cat make_exch2.errors 1>&2
1109            exit 1
1110        fi
1111    fi
1112    
1113  printf "\n===  Determining package settings  ===\n"  printf "\n===  Determining package settings  ===\n"
1114  if  test "x${PDEPEND}" = x ; then  if  test "x${PDEPEND}" = x ; then
1115      tmp=$ROOTDIR"/pkg/pkg_depend"      tmp=$ROOTDIR"/pkg/pkg_depend"
# Line 907  rm -f ./.pd_tmp Line 1142  rm -f ./.pd_tmp
1142  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"
1143  #  file should eventually be added so that, for convenience, one can  #  file should eventually be added so that, for convenience, one can
1144  #  specify groups of packages using names like "ocean" and "atmosphere".  #  specify groups of packages using names like "ocean" and "atmosphere".
1145  echo  -n "  checking default package list:  "  echo "  checking default package list:  "
1146  if test "x${PDEFAULT}" = x ; then  if test "x${PDEFAULT}" = x ; then
1147      for i in "." $MODS ; do      for i in "." $MODS ; do
1148          if test -r $i"/packages.conf" ; then          if test -r $i"/packages.conf" ; then
# Line 920  if test "x${PDEFAULT}" = x ; then Line 1155  if test "x${PDEFAULT}" = x ; then
1155      PDEFAULT="$ROOTDIR/pkg/pkg_default"      PDEFAULT="$ROOTDIR/pkg/pkg_default"
1156  fi  fi
1157  if test "x${PDEFAULT}" = xNONE ; then  if test "x${PDEFAULT}" = xNONE ; then
1158      echo "default packages file disabled"      echo "    default packages file disabled"
1159  else  else
1160      if test ! -r $PDEFAULT ; then      if test ! -r $PDEFAULT ; then
         echo ""  
1161          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""
1162      else      else
1163          echo "  using PDEFAULT=\"$PDEFAULT\""          echo "    using PDEFAULT=\"$PDEFAULT\""
1164          #  Strip the comments and add all the names          #  Strip the comments and add all the names
1165          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
1166          RETVAL=$?          RETVAL=$?
# Line 1059  for i in $PACKAGES ; do Line 1293  for i in $PACKAGES ; do
1293      fi      fi
1294  done  done
1295    
1296    #  Build MNC templates and check for ability to build and use NetCDF
1297    echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1
1298    RETVAL=$?
1299    if test "x$RETVAL" = x0 ; then
1300        ( cd $ROOTDIR"/pkg/mnc" && $MAKE templates ) > make_mnc.errors 2>&1
1301        RETVAL=$?
1302        if test "x${RETVAL}" = x0 ; then
1303            rm -f make_mnc.errors
1304        else
1305            echo "Error: problem encountered while building source files in pkg/mnc:"
1306            cat make_mnc.errors 1>&2
1307            exit 1
1308        fi
1309        if test "x$HAVE_NETCDF" != xt ; then
1310            cat <<EOF
1311    
1312  # Create a list of #define and #undef to enable/disable packages  WARNING: the "mnc" package has been enabled but tests failed to
1313  PACKAGES_DOT_H=PACKAGES_CONFIG.h    compile and/or execute NetCDF applications.  Please check that:
 cat <<EOF >$PACKAGES_DOT_H".tmp"  
 C=== GENMAKE v2 ===  
 C  The following defines have been set by GENMAKE, so please do not  
 C  edit anything below these comments.  In general, you should  
 C  add or remove packages by re-running genmake with different  
 C  "-enable" and/or "-disable" options.  
   
 #ifndef PACKAGES_H  
 #define PACKAGES_H  
1314    
1315  C  Packages disabled by genmake:    1) NetCDF is installed for your compiler and
1316      2) the LIBS variable (within the 'optfile") specifies the correct
1317           NetCDF library to link against.
1318      
1319  EOF  EOF
1320        fi
1321    fi
1322    
1323    # Create a list of #define and #undef to enable/disable packages
1324    PACKAGES_DOT_H=PACKAGES_CONFIG.h
1325  #  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
1326  #  away.  On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h  #  away.  On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
1327  #  file would eventually be split up so that all package-related #define  #  file would eventually be split up so that all package-related #define
1328  #  statements could be separated and handled only by genmake.  #  statements could be separated and handled only by genmake.
1329  names=`ls -1 "$ROOTDIR/pkg"`  names=`ls -1 "$ROOTDIR/pkg"`
1330  all_pack=  all_pack=
1331    DISABLED_PACKAGES=
1332  for n in $names ; do  for n in $names ; do
1333      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then      if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
1334          has_pack="f"          has_pack="f"
# Line 1091  for n in $names ; do Line 1340  for n in $names ; do
1340          done          done
1341          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
1342              undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`
1343              echo "#undef $undef" >> $PACKAGES_DOT_H".tmp"              DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
1344          fi          fi
1345      fi      fi
1346  done  done
1347  cat <<EOF >>$PACKAGES_DOT_H".tmp"  ENABLED_PACKAGES=
   
 C  Packages enabled by genmake:  
 EOF  
1348  for i in $PACKAGES ; do  for i in $PACKAGES ; do
1349      def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`      def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`
1350      echo "#define $def" >> $PACKAGES_DOT_H".tmp"      ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
1351  #eh3 DEFINES="$DEFINES -D$def"  #eh3 DEFINES="$DEFINES -D$def"
1352    
1353  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1354      case $i in      case $i in
1355          aim_v23)          aim_v23)
1356              echo "#define   ALLOW_AIM" >> $PACKAGES_DOT_H".tmp"              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
1357              DEFINES="$DEFINES -DALLOW_AIM"              echo "Warning: ALLOW_AIM is set to enable aim_v23."
             echo "Warning: ALLOW_AIM is set to enable aim_v23. This is REALLY ugly Jean-Michel :-)"  
1358              ;;              ;;
1359      esac      esac
1360  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
1361    
1362  done  done
 cat <<EOF >>$PACKAGES_DOT_H".tmp"  
   
 #endif /* PACKAGES_H */  
 EOF  
   
 if test ! -f $PACKAGES_DOT_H ; then  
     mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H  
 else  
     cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H  
     RETVAL=$?  
     if test "x$RETVAL" = x0 ; then  
         rm -f $PACKAGES_DOT_H".tmp"  
     else  
         mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"  
         mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H  
     fi  
 fi  
1363    
1364  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS"
1365  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
1366  if test "x$STANDARDDIRS" = x ; then  if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
1367      STANDARDDIRS="eesupp model"      STANDARDDIRS="eesupp model"
1368  fi  fi
1369  for d in $STANDARDDIRS ; do  if test "x$STANDARDDIRS" != x ; then
1370      adr="$ROOTDIR/$d/src"      for d in $STANDARDDIRS ; do
1371      if test ! -d $adr ; then          adr="$ROOTDIR/$d/src"
1372          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""          if test ! -d $adr ; then
1373          echo "  is correct and that you correctly specified the STANDARDDIRS option"              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1374          exit 1              echo "  is correct and that you correctly specified the STANDARDDIRS option"
1375      else              exit 1
1376          SOURCEDIRS="$SOURCEDIRS $adr"          else
1377      fi              SOURCEDIRS="$SOURCEDIRS $adr"
1378      adr="$ROOTDIR/$d/inc"          fi
1379      if test ! -d $adr ; then          adr="$ROOTDIR/$d/inc"
1380          echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""          if test ! -d $adr ; then
1381          echo "  is correct and that you correctly specified the STANDARDDIRS option"              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1382          exit 1              echo "  is correct and that you correctly specified the STANDARDDIRS option"
1383      else              exit 1
1384          INCLUDEDIRS="$INCLUDEDIRS $adr"          else
1385      fi              INCLUDEDIRS="$INCLUDEDIRS $adr"
1386  done          fi
1387        done
1388    fi
1389    
1390  echo "  Searching for CPP_OPTIONS.h in order to warn about the presence"  echo "  Searching for *OPTIONS.h files in order to warn about the presence"
1391  echo "    of \"#define ALLOW_PKGNAME\"-type statements:"  echo "    of \"#define \"-type statements that are no longer allowed:"
1392  CPP_OPTIONS=  CPP_OPTIONS=
1393    CPP_EEOPTIONS=
1394  spaths=". $INCLUDEDIRS"  spaths=". $INCLUDEDIRS"
1395    names=`ls -1 "$ROOTDIR/pkg"`
1396  for i in $spaths ; do  for i in $spaths ; do
1397      try="$i/CPP_OPTIONS.h"      try="$i/CPP_OPTIONS.h"
1398      #  echo -n "    trying $try : "      if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
     if test -f $try -a -r $try ; then  
1399          echo "    found CPP_OPTIONS=\"$try\""          echo "    found CPP_OPTIONS=\"$try\""
1400          CPP_OPTIONS="$try"          CPP_OPTIONS="$try"
1401          break          # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
1402            for n in $names ; do
1403                test_for_package_in_cpp_options $CPP_OPTIONS $n
1404            done
1405        fi
1406        try="$i/CPP_EEOPTIONS.h"
1407        if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
1408            echo "    found CPP_EEOPTIONS=\"$try\""
1409            # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
1410    #**** not yet enabled ****
1411    #        test_for_mpi_in_cpp_eeoptions $try
1412    #**** not yet enabled ****
1413            CPP_EEOPTIONS="$try"
1414      fi      fi
1415  done  done
1416  if test "x$CPP_OPTIONS" = x ; then  if test "x$CPP_OPTIONS" = x ; then
1417      echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"      echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
1418      exit 1      exit 1
1419  fi  fi
 # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h  
 names=`ls -1 "$ROOTDIR/pkg"`  
 for n in $names ; do  
     test_for_package_in_cpp_options $CPP_OPTIONS $n  
 done  
   
1420    
1421  #  Here, we build the list of files to be "run through" the adjoint  #  Here, we build the list of files to be "run through" the adjoint
1422  #  compiler.  #  compiler.
# Line 1194  for i in $SOURCEDIRS ; do Line 1431  for i in $SOURCEDIRS ; do
1431      done      done
1432  done  done
1433    
 cat <<EOF > adjoint_sed  
 s/call adopen(/call adopen ( mythid,\\  
      \&           /g  
 s/call adclose(/call adclose( mythid,\\  
      \&           /g  
 s/call adread(/call adread ( mythid,\\  
      \&           /g  
 s/call adwrite(/call adwrite( mythid,\\  
      \&           /g  
   
 EOF  
1434    
1435  echo  echo
1436  echo "===  Creating the Makefile  ==="  echo "===  Creating the Makefile  ==="
# Line 1235  for d in $alldirs ; do Line 1461  for d in $alldirs ; do
1461      for sf in $sfiles ; do      for sf in $sfiles ; do
1462          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
1463              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
1464                    case $d/$sf in
1465                      ./$PACKAGES_DOT_H)
1466                            ;;
1467                      ./AD_CONFIG.h)
1468                            ;;
1469                      ./FC_NAMEMANGLE.h)
1470                            ;;
1471                      *)
1472                            touch .links.tmp/$sf
1473                            deplist="$deplist $sf"
1474                            ;;
1475                    esac
1476                  extn=`echo $sf | $AWK -F '.' '{print $NF}'`                  extn=`echo $sf | $AWK -F '.' '{print $NF}'`
                 touch .links.tmp/$sf  
                 deplist="$deplist $sf"  
1477                  case $extn in                  case $extn in
1478                      F)                      F)
1479                          echo    " \\"  >> srclist.inc                          echo    " \\"  >> srclist.inc
# Line 1295  EXE_FTL=$EXECUTABLE"_ftl" Line 1531  EXE_FTL=$EXECUTABLE"_ftl"
1531  EXE_SVD=$EXECUTABLE"_svd"  EXE_SVD=$EXECUTABLE"_svd"
1532    
1533  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
1534    #
1535    # OPTFILE="$OPTFILE"
1536  #  #
1537  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
1538  # SOURCEDIRS   : Directories containing the source (.F) files  # SOURCEDIRS   : Directories containing the source (.F) files
# Line 1328  EXE_AD      = ${EXE_AD} Line 1566  EXE_AD      = ${EXE_AD}
1566  EXE_FTL     = ${EXE_FTL}  EXE_FTL     = ${EXE_FTL}
1567  EXE_SVD     = ${EXE_SVD}  EXE_SVD     = ${EXE_SVD}
1568    
1569    ENABLED_PACKAGES = ${ENABLED_PACKAGES}
1570    DISABLED_PACKAGES = ${DISABLED_PACKAGES}
1571    
1572    # These files are created by Makefile
1573    SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h
1574    
1575  EOF  EOF
1576    
1577  #  Note: figure out some way to add Hyades JAM libraries here  #  Note: figure out some way to add Hyades JAM libraries here
# Line 1346  FC = ${FC} Line 1590  FC = ${FC}
1590  # Fortran compiler  # Fortran compiler
1591  F90C = ${F90C}  F90C = ${F90C}
1592  # Link editor  # Link editor
1593  LINK = ${LINK}  LINK = ${LINK} ${LDADD}
1594    
1595  # Defines for CPP  # Defines for CPP
1596  DEFINES = ${DEFINES}  DEFINES = ${DEFINES}
# Line 1392  cat >>$MAKEFILE <<EOF Line 1636  cat >>$MAKEFILE <<EOF
1636  .SUFFIXES: .o .f .p .F .c .F90 .f90  .SUFFIXES: .o .f .p .F .c .F90 .f90
1637    
1638  all: \$(EXECUTABLE)  all: \$(EXECUTABLE)
1639  \$(EXECUTABLE): \$(OBJFILES)  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(OBJFILES)
1640            @echo Creating \$@ ...
1641          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
1642  depend:  depend:
1643          @make links          @make links
1644          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
1645          ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE)          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
1646    
1647  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES)
1648    
1649  small_f: \$(F77FILES) \$(F90FILES)  small_f: \$(F77FILES) \$(F90FILES)
1650    
# Line 1408  output.txt: \$(EXECUTABLE) Line 1653  output.txt: \$(EXECUTABLE)
1653          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
1654    
1655  clean:  clean:
1656          -cat AD_CONFIG.template > AD_CONFIG.h          -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl} *.template
         -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}  
1657  Clean:  Clean:
1658          @make clean          @make clean
1659          @make cleanlinks          @make cleanlinks
1660          -rm -f Makefile.bak genmake_state genmake_*optfile make.log          -rm -f \$(SPECIAL_FILES)
1661            -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak
1662  CLEAN:  CLEAN:
1663          @make Clean          @make Clean
1664          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
# Line 1423  CLEAN: Line 1668  CLEAN:
1668    
1669  #eh3 Makefile: makefile  #eh3 Makefile: makefile
1670  makefile:  makefile:
1671          ${0} $@          $THIS_SCRIPT $@
1672  cleanlinks:  cleanlinks:
1673          -find . -type l -exec rm {} \;          -find . -type l -exec rm {} \;
1674    
1675    # Special targets ($SPECIAL_FILES) which are create by make
1676    ${PACKAGES_DOT_H}:
1677            @echo Creating \$@ ...
1678            @\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@
1679    AD_CONFIG.h:
1680            @echo Creating \$@ ...
1681            @\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > \$@
1682    FC_NAMEMANGLE.h:
1683            @echo Creating \$@ ...
1684            echo "$FC_NAMEMANGLE" > \$@
1685    
1686  # The normal chain of rules is (  .F - .f - .o  )  # The normal chain of rules is (  .F - .f - .o  )
1687  .F.f:  .F.f:
1688          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
# Line 1486  adtaf: ad_taf_output.f Line 1742  adtaf: ad_taf_output.f
1742  adtamc: ad_tamc_output.f  adtamc: ad_tamc_output.f
1743    
1744  ad_input_code.f: \$(AD_FILES) \$(HEADERFILES)  ad_input_code.f: \$(AD_FILES) \$(HEADERFILES)
1745            @\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > ad_config.template
1746          cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h          cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
1747            -rm -f ad_config.template
1748          @make \$(F77FILES)          @make \$(F77FILES)
1749          @make \$(AD_FLOW_FILES)          @make \$(AD_FLOW_FILES)
1750          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f
1751    
1752  ad_taf_output.f: ad_input_code.f  ad_taf_output.f: ad_input_code.f
1753          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1754          cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f          cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f
1755    
1756    adtafonly:
1757            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1758            cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f
1759    
1760  ad_taf: ad_taf_output.o \$(OBJFILES)  ad_taf: ad_taf_output.o \$(OBJFILES)
1761          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
1762    
1763  ad_tamc_output.f: ad_input_code.f  ad_tamc_output.f: ad_input_code.f
1764          \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f          \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f
1765          cat ad_input_code_ad.f | sed -f adjoint_sed > ad_tamc_output.f          cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.f
1766    
1767  ad_tamc: ad_tamc_output.o \$(OBJFILES)  ad_tamc: ad_tamc_output.o \$(OBJFILES)
1768          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
# Line 1512  ftltaf: ftl_taf_output.f Line 1774  ftltaf: ftl_taf_output.f
1774  ftltamc: ftl_tamc_output.f  ftltamc: ftl_tamc_output.f
1775    
1776  ftl_input_code.f: \$(AD_FILES) \$(HEADERFILES)  ftl_input_code.f: \$(AD_FILES) \$(HEADERFILES)
1777            @\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > ftl_config.template
1778          cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h          cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
1779            -rm -f ftl_config.template
1780          @make \$(F77FILES)          @make \$(F77FILES)
1781          @make \$(AD_FLOW_FILES)          @make \$(AD_FLOW_FILES)
1782          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f
1783    
1784  ftl_taf_output.f: ftl_input_code.f  ftl_taf_output.f: ftl_input_code.f
1785          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f
1786          cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_taf_output.f          cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f
1787    
1788    ftltafonly:
1789            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f
1790            cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f
1791    
1792  ftl_taf: ftl_taf_output.o \$(OBJFILES)  ftl_taf: ftl_taf_output.o \$(OBJFILES)
1793          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
1794    
1795  ftl_tamc_output.f: ftl_input_code.f  ftl_tamc_output.f: ftl_input_code.f
1796          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f
1797          cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_tamc_output.f          cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.f
1798    
1799  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
1800          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
1801    
1802    
1803  # ... SVD ...  # ... SVD ...
1804  svd: svd_taf  svdtaf: ad_taf_output.f ftl_taf_output.f
1805  svd_taf_f: svd_taf_output.f  svdall: svd_taf
1806    
1807  svd_input_code.f: \$(SRCFILES)  svd_taf: ad_taf_output.o ftl_taf_output.o \$(OBJFILES)
1808          cmp svd_config.template AD_CONFIG.h || cat svd_config.template > AD_CONFIG.h          \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
         @make \$(F77FILES)  
         @make \$(AD_FLOW_FILES)  
         cat \$(AD_FLOW_FILES) \$(AD_FILES) > svd_input_code.f  
   
 svd_taf_output.f: svd_input_code.f  
         \$(TAF) \$(SVD_TAF_FLAGS) \$(TAF_EXTRA) svd_input_code.f  
         cat svd_input_code_ad.f | sed -f adjoint_sed > svd_taf_output.f  
   
 svd_taf: svd_taf_output.o \$(OBJFILES)  
         \$(LINK) -o ${EXE_SVD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) svd_taf_output.o \$(LIBS)  
1809    
1810    
1811  #=========================================  #=========================================
# Line 1588  printf "\n\n# DO NOT DELETE\n" >> $MAKEF Line 1846  printf "\n\n# DO NOT DELETE\n" >> $MAKEF
1846    
1847  printf "\n===  Done  ===\n"  printf "\n===  Done  ===\n"
1848    
1849  #  Write the "template" files for the adjoint builds  # Create special header files
1850  cat >AD_CONFIG.template <<EOF  $TOOLSDIR/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" $DISABLED_PACKAGES " " "Enabled packages:" $ENABLED_PACKAGES > $PACKAGES_DOT_H".tmp"
1851  C  WARNING: This file is automatically generated by genmake2 and  if test ! -f $PACKAGES_DOT_H ; then
1852  C    used by the Makefile rules.  Please DO NOT EDIT this file      mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
1853  C    unless you are CERTAIN that you know what you are doing.  else
1854        cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
1855  #undef ALLOW_ADJOINT_RUN      RETVAL=$?
1856  #undef ALLOW_TANGENTLINEAR_RUN      if test "x$RETVAL" = x0 ; then
1857  #undef ALLOW_ECCO_OPTIMIZATION          rm -f $PACKAGES_DOT_H".tmp"
1858  EOF      else
1859  cat >ad_config.template <<EOF          mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
1860  C  WARNING: This file is automatically generated by genmake2 and          mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
1861  C    used by the Makefile rules.  Please DO NOT EDIT this file      fi
1862  C    unless you are CERTAIN that you know what you are doing.  fi
1863    if test ! -f AD_CONFIG.h ; then
1864  #define ALLOW_ADJOINT_RUN      $TOOLSDIR/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > AD_CONFIG.h
1865  #undef ALLOW_TANGENTLINEAR_RUN  fi
 #undef ALLOW_ECCO_OPTIMIZATION  
 EOF  
 cat >ftl_config.template <<EOF  
 C  WARNING: This file is automatically generated by genmake2 and  
 C    used by the Makefile rules.  Please DO NOT EDIT this file  
 C    unless you are CERTAIN that you know what you are doing.  
   
 #undef ALLOW_ADJOINT_RUN  
 #define ALLOW_TANGENTLINEAR_RUN  
 #undef ALLOW_ECCO_OPTIMIZATION  
 EOF  
 cat >svd_config.template <<EOF  
 C  WARNING: This file is automatically generated by genmake2 and  
 C    used by the Makefile rules.  Please DO NOT EDIT this file  
 C    unless you are CERTAIN that you know what you are doing.  
   
 #undef ALLOW_ADJOINT_RUN  
 #undef ALLOW_TANGENTLINEAR_RUN  
 #undef ALLOW_ECCO_OPTIMIZATION  
 EOF  
 cp AD_CONFIG.template AD_CONFIG.h  
1866    
1867    
1868  #  Write the "state" for future records  #  Write the "state" for future records

Legend:
Removed from v.1.36  
changed lines
  Added in v.1.70

  ViewVC Help
Powered by ViewVC 1.1.22