/[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.96 by edhill, Mon Aug 9 02:28:51 2004 UTC revision 1.252 by jmc, Mon Jul 22 19:11:31 2013 UTC
# Line 1  Line 1 
1  #! /usr/bin/env bash  #! /usr/bin/env bash
2  #  #
3  # $Header$  # $Header$
4    # $Name$
5  #  #
6  # Makefile generator for MITgcm UV codes  # Makefile generator for MITgcm UV codes
7  #   created  by cnh 03/98  #   created  by cnh 03/98
# Line 8  Line 9 
9  #   modified by aja 01/00  #   modified by aja 01/00
10  #   rewritten in bash by eh3 08/03  #   rewritten in bash by eh3 08/03
11    
12    #  Explain usage
13    usage()  {
14    cat <<EOF
15    
16    Usage: "$0" [OPTIONS]
17      where [OPTIONS] can be:
18    
19        -help | --help | -h | --h
20              Print this help message and exit.
21    
22        -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME
23          -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME
24              Use "NAME" as the adoptfile.  By default, the file at
25              "tools/adjoint_options/adjoint_default" will be used.
26    
27        -nooptfile | --nooptfile
28          -optfile NAME | --optfile NAME | -of NAME | --of NAME
29          -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
30              Use "NAME" as the optfile.  By default, an attempt will be
31              made to find an appropriate "standard" optfile in the
32              tools/build_options/ directory.
33    
34        -pdepend NAME | --pdepend NAME
35          -pdepend=NAME | --pdepend=NAME
36              Get package dependency information from "NAME".
37    
38        -pgroups NAME | --pgroups NAME
39          -pgroups=NAME | --pgroups=NAME
40              Get the package groups information from "NAME".
41    
42        -bash NAME
43              Explicitly specify the Bourne or BASH shell to use
44    
45        -make NAME | -m NAME
46          --make=NAME | -m=NAME
47              Use "NAME" for the MAKE program. The default is "make" but
48              many platforms, "gmake" is the preferred choice.
49    
50        -makefile NAME | -mf NAME
51          --makefile=NAME | -mf=NAME
52              Call the makefile "NAME".  The default is "Makefile".
53    
54        -makedepend NAME | -md NAME
55          --makedepend=NAME | -md=NAME
56              Use "NAME" for the MAKEDEPEND program.
57    
58        -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
59          -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
60              Specify the location of the MITgcm ROOTDIR as "NAME".
61              By default, genamke will try to find the location by
62              looking in parent directories (up to the 5th parent).
63    
64        -mods NAME | --mods NAME | -mo NAME | --mo NAME
65          -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
66              Here, "NAME" specifies a list of directories that are
67              used for additional source code.  Files found in the
68              "mods list" are given preference over files of the same
69              name found elsewhere.
70    
71        -disable NAME | --disable NAME
72          -disable=NAME | --disable=NAME
73              Here "NAME" specifies a list of packages that we don't
74              want to use.  If this violates package dependencies,
75              genamke will exit with an error message.
76    
77        -enable NAME | --enable NAME
78          -enable=NAME | --enable=NAME
79              Here "NAME" specifies a list of packages that we wish
80              to specifically enable.  If this violates package
81              dependencies, genamke will exit with an error message.
82    
83        -standarddirs NAME | --standarddirs NAME
84          -standarddirs=NAME | --standarddirs=NAME
85              Here, "NAME" specifies a list of directories to be
86              used as the "standard" code.
87    
88        -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
89          -fc=NAME | --fc=NAME
90              Use "NAME" as the fortran compiler.  By default, genmake
91              will search for a working compiler by trying a list of
92              "usual suspects" such as g77, f77, etc.
93    
94        -cc NAME | --cc NAME | -cc=NAME | --cc=NAME
95              Use "NAME" as the C compiler.  By default, genmake
96              will search for a working compiler by trying a list of
97              "usual suspects" such as gcc, c89, cc, etc.
98    
99        -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4
100              Use "real*4" type for _RS variable (#undef REAL4_IS_SLOW)
101              *only* works if CPP_EEOPTIONS.h allows this.
102    
103        -ignoretime | -ignore_time | --ignoretime | --ignore_time
104              Ignore all the "wall clock" routines entirely.  This will
105              not in any way hurt the model results -- it simply means
106              that the code that checks how long the model spends in
107              various routines will give junk values.
108    
109        -ts | --ts
110              Produce timing information per timestep
111        -papis | --papis
112              Produce summary MFlop/s (and IPC) with PAPI per timestep
113        -pcls | --pcls
114              Produce summary MFlop/s etc. with PCL per timestep
115        -foolad | --foolad
116              Fool the AD code generator
117        -papi | --papi
118              Performance analysis with PAPI
119        -pcl | --pcl
120              Performance analysis with PCL
121        -hpmt | --hpmt
122              Performance analysis with the HPM Toolkit
123    
124        -ieee | --ieee
125              use IEEE numerics.  Note that this option *only* works
126              if it is supported by the OPTFILE that is being used.
127        -devel | --devel
128              Add additional warning and debugging flags for development
129              (if supported by the OPTFILE); also switch to IEEE numerics.
130        -gsl | --gsl
131              Use GSL to control floating point rounding and precision
132    
133        -mpi | --mpi
134              Include MPI header files and link to MPI libraries
135        -mpi=PATH | --mpi=PATH
136              Include MPI header files and link to MPI libraries using MPI_ROOT
137              set to PATH. i.e. Include files from \$PATH/include, link to libraries
138              from \$PATH/lib and use binaries from \$PATH/bin.
139    
140        -omp | --omp
141              Activate OpenMP code + use Compiler option OMPFLAG
142        -omp=OMPFLAG | --omp=OMPFLAG
143              Activate OpenMP code + use Compiler option OMPFLAG
144    
145        -es | --es | -embed-source | --embed-source
146              Embed a tarball containing the full source code
147              (including the Makefile, etc.) used to build the
148              executable [off by default]
149    
150        -ds | --ds
151              Report genmake internal variables status (DUMPSTATE)
152              to file "genmake_state" (for debug purpose)
153    
154      While it is most often a single word, the "NAME" variables specified
155      above can in many cases be a space-delimited string such as:
156    
157        --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'
158        -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'
159        -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
160    
161      which, depending upon your shell, may need to be single-quoted.
162    
163      For more detailed genmake documentation, please see:
164    
165        http://mitgcm.org/public/devel_HOWTO/
166    
167    EOF
168    
169        exit 1
170    }
171    
172  # Search for particular CPP #cmds associated with packages  # Search for particular CPP #cmds associated with packages
173  # usage: test_for_package_in_cpp_options CPP_file package_name  # usage: test_for_package_in_cpp_options CPP_file package_name
174  test_for_package_in_cpp_options() {  test_for_package_in_cpp_options() {
175      cpp_options=$1      cpp_options=$1
176      pkg=$2      pkg=$2
177      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg" || exit 99      test_for_string_in_file $cpp_options "^ *# *define *\<ALLOW_$pkg\>"
178      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg" || exit 99      test_for_string_in_file $cpp_options "^ *# *undef *\<ALLOW_$pkg\>"
179      test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg" || exit 99      test_for_string_in_file $cpp_options "^ *# *define *\<DISABLE_$pkg\>"
180      test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg" || exit 99      test_for_string_in_file $cpp_options "^ *# *undef *\<DISABLE_$pkg\>"
181  }  }
182    
183  # Search for particular CPP #cmds associated with MPI  # Search for particular CPP #cmds associated with MPI
184  # usage: test_for_mpi_in_cpp_eeoptions CPP_file  # usage: test_for_mpi_in_cpp_eeoptions CPP_file
185  test_for_mpi_in_cpp_eeoptions() {  test_for_mpi_in_cpp_eeoptions() {
186      cpp_options=$1      cpp_options=$1
187      test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI" || exit 99      test_for_string_in_file $cpp_options "^ *# *define *\<ALLOW_USE_MPI\>"
188      test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI" || exit 99      test_for_string_in_file $cpp_options "^ *# *undef *\<ALLOW_USE_MPI\>"
     test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI" || exit 99  
     test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI" || exit 99  
189  }  }
190    
191  # Search for particular string in a file. Return 1 if detected, 0 if not  # Search for particular string in a file. Return 1 if detected, 0 if not
# Line 34  test_for_mpi_in_cpp_eeoptions() { Line 193  test_for_mpi_in_cpp_eeoptions() {
193  test_for_string_in_file() {  test_for_string_in_file() {
194      file=$1      file=$1
195      strng=$2      strng=$2
196      grep -i "$strng" $file > /dev/null 2>&1      grep "$strng" $file > /dev/null 2>&1
197      RETVAL=$?      RETVAL=$?
198      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
199          printf "Error: In $file there is an illegal line: "          printf "Error: In $file there is an illegal line: "
200          grep -i "$strng" $file          grep -i "$strng" $file
201          return 1          exit 99
202      fi      fi
203      return 0      return 0
204  }  }
# Line 48  test_for_string_in_file() { Line 207  test_for_string_in_file() {
207  # the package list.  # the package list.
208  expand_pkg_groups() {  expand_pkg_groups() {
209      new_packages=      new_packages=
     PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups"  
210      if test -r $PKG_GROUPS ; then      if test -r $PKG_GROUPS ; then
211          cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp          cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp
212          cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp          cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp
# Line 59  expand_pkg_groups() { Line 217  expand_pkg_groups() {
217              if test "x$RETVAL" = x0 ; then              if test "x$RETVAL" = x0 ; then
218                  matched=1                  matched=1
219                  replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`                  replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`
220                  echo "    replacing \"$i\" with: $replace"                  echo "    replacing \"$i\" with:$replace"
221                  new_packages="$new_packages $replace"                  new_packages="$new_packages $replace"
222              else              else
223                  new_packages="$new_packages $i"                  new_packages="$new_packages $i"
# Line 102  EOF Line 260  EOF
260              check_for_broken_Ff              check_for_broken_Ff
261          else          else
262              cat <<EOF 2>&1              cat <<EOF 2>&1
263  ERROR: Your file system cannot distinguish between *.F and *.f files  ERROR: Your file system cannot distinguish between *.F and *.f files
264    (fails the "cp" test) and this program cannot find a suitable    (fails the "cp" test) and this program cannot find a suitable
265    replacement extension.  Please try a different build environment or    replacement extension.  Please try a different build environment or
266    contact the <MITgcm-support@mitgcm.org> list for help.    contact the <MITgcm-support@mitgcm.org> list for help.
267    
268  EOF  EOF
# Line 122  EOF Line 280  EOF
280        stop        stop
281        end        end
282  EOF  EOF
283      test -f Makefile  &&  mv -f Makefile Makefile.bak      test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
284      cat <<EOF >> Makefile      cat <<EOF >> $MAKEFILE
 %.$tfs : %.F  
285  .SUFFIXES:  .SUFFIXES:
286  genmake_hello.$tfs: genmake_hello.F  .SUFFIXES: .$tfs .F
287          $LN genmake_hello.F genmake_hello.$tfs  .F.$tfs:
288            $LN \$< \$@
289  EOF  EOF
290      $MAKE "genmake_hello."$tfs > /dev/null 2>&1      $MAKE -f $MAKEFILE "genmake_hello."$tfs > /dev/null 2>&1
291      RETVAL=$?      RETVAL=$?
292      if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then      if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then
293          if test "x$FS" = x ; then          if test "x$FS" = x ; then
# Line 137  EOF Line 295  EOF
295              FS90='fr9'              FS90='fr9'
296              check_for_broken_Ff              check_for_broken_Ff
297          else          else
298              cat <<EOF 2>&1              echo "ERROR: test: '$MAKE -f $MAKEFILE genmake_hello.$tfs' Failed"
299  ERROR: Your file system cannot distinguish between *.F and *.f files              echo "       see simple makefile: '$MAKEFILE' (left here)"
300    (fails the "make/ln" test) and this program cannot find a suitable              echo "  Please check (1) your '$MAKE' command, (2) your '$LN' command"
301    replacement extension.  Please try a different build environment or              echo "           and (3) the allowed sufix '.F' and '.$tfs' in makefile"
302    contact the <MITgcm-support@mitgcm.org> list for help.              echo "  or contact the <MITgcm-support@mitgcm.org> list for help."
303                echo ""
 EOF  
304              exit -1              exit -1
305              return              return
306          fi          fi
307      fi      fi
308      rm -f genmake_hello.* Makefile      rm -f genmake_hello.* $MAKEFILE
309      test -f Makefile  &&  mv -f Makefile.bak Makefile      test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
310    
311      #  If we make it here, use the extensions      #  If we make it here, use the extensions
312      FS=$tfs      FS=$tfs
# Line 157  EOF Line 314  EOF
314      return      return
315  }  }
316    
   
317  look_for_makedepend()  {  look_for_makedepend()  {
318    
319      #  The "original" makedepend is part of the Imake system that is      #  The "original" makedepend is part of the Imake system that is
# Line 168  look_for_makedepend()  { Line 324  look_for_makedepend()  {
324      #      #
325      #    1) a makedepend implementation shipped with the cyrus-imapd      #    1) a makedepend implementation shipped with the cyrus-imapd
326      #       package:  ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/      #       package:  ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
327      #      #    2) a local tools/xmakedepend shell script
     #    2) a known-buggy xmakedpend shell script  
328      #      #
329      #  So the choices are, in order:      #  So the choices are, in order:
     #  
330      #    1) use the user-specified program      #    1) use the user-specified program
331      #    2) use a system-wide default      #    2) use the local xmakedepend script (get all dependencies, but slower)
332      #    3) locally build and use the cyrus implementation      #    3) use a system-wide default
333      #    4) fall back to the buggy local xmakedpend script      #    4) locally build and use the cyrus makedepend
334        #             (faster, but can miss some dependencies)
335      #      #
336        echo >> $LOGFILE
337        echo "running: look_for_makedepend()" >> $LOGFILE
338        if test "x${MAKEDEPEND}" != x ; then
339            echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1
340            RETVAL=$?
341            if test x"$RETVAL" = x0 ; then
342                build_cyrus_makedepend
343                RETVAL=$?
344                if test "x$RETVAL" != x0 ; then
345                    echo "WARNING: unable to build cyrus-makedepend. Try other 'makedepend'"
346                    MAKEDEPEND=
347                fi
348            else
349                echo "${MAKEDEPEND}" | grep 'tools.xmakedepend' > /dev/null 2>&1
350                RETVAL=$?
351                if test "x$RETVAL" = x0 ; then
352                    MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
353                fi
354                echo " -->     MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
355            fi
356        fi
357      if test "x${MAKEDEPEND}" = x ; then      if test "x${MAKEDEPEND}" = x ; then
358          which makedepend > /dev/null 2>&1          test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
359          RV0=$?          #  echo 'MAKEFILE="'$MAKEFILE'"'
360            cat <<EOF >> $MAKEFILE
361    #   THIS IS A TEST MAKEFILE GENERATED BY "genmake2"
362    #
363    #   Some "makedepend" implementations will die if they cannot
364    #   find a Makefile -- so this file is here to gives them an
365    #   empty one to find and parse.
366    EOF
367          cat <<EOF >> genmake_tc.f          cat <<EOF >> genmake_tc.f
368        program test        program test
369        write(*,*) 'test'        write(*,*) 'test'
370        stop        stop
371        end        end
372  EOF  EOF
373          makedepend genmake_tc.f > /dev/null 2>&1          $ROOTDIR/tools/xmakedepend -f $MAKEFILE genmake_tc.f > /dev/null 2>&1
374          RV1=$?          RV1=$?
375          if test "x${RV0}${RV1}" = x00 ; then          which makedepend > /dev/null 2>&1
376            RV2=$?
377            if test "x${RV2}" = x0 ; then
378                makedepend -f $MAKEFILE genmake_tc.f > /dev/null 2>&1
379                RV3=$? ; loc_msg='not working.'
380            else RV3=$RV2 ; loc_msg='not found.'
381            fi
382            test -f $MAKEFILE  &&  rm -f $MAKEFILE
383            test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
384            echo "  check makedepend (local: $RV1, system: $RV2, $RV3)"
385            if test "x${RV1}" = x0 ; then
386                MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
387                echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
388            elif test "x${RV3}" = x0 ; then
389                echo "    local tools/xmakedepend not working. Use system-default makedepend"
390              MAKEDEPEND=makedepend              MAKEDEPEND=makedepend
391                echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
392          else          else
393              echo "    a system-default makedepend was not found."              echo "    local tools/xmakedepend not working; system-default makedepend $loc_msg"
394                            echo -n "    Try to build cyrus-makedepend ..."
395              #  Try to build the cyrus implementation              #  Try to build the cyrus implementation
396              build_cyrus_makedepend              build_cyrus_makedepend
397              RETVAL=$?              RETVAL=$?
398              if test "x$RETVAL" != x0 ; then              if test "x$RETVAL" = x0 ; then
399                  MAKEDEPEND='$(TOOLSDIR)/xmakedepend'                  echo "  Works"
400                else
401                    echo "  Fails" ; echo "" >> $LOGFILE
402                    echo "ERROR: no working makedepend found ; look_for_makedepend FAILED" | tee -a $LOGFILE
403                    echo ""
404                    exit -1
405                    return
406              fi              fi
             rm -f ./genmake_cy_md  
         fi  
     else  
         #  echo "MAKEDEPEND=${MAKEDEPEND}"  
         echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1  
         RETVAL=$?  
         if test x"$RETVAL" = x0 ; then  
             build_cyrus_makedepend  
407          fi          fi
408      fi      fi
409  }  }
410    
   
411  build_cyrus_makedepend()  {  build_cyrus_makedepend()  {
412        echo >> $LOGFILE
413        echo "running: build_cyrus_makedepend()" >> $LOGFILE
414      rm -f ./genmake_cy_md      rm -f ./genmake_cy_md
415      (      (
416          cd $ROOTDIR/tools/cyrus-imapd-makedepend  \          cd $ROOTDIR/tools/cyrus-imapd-makedepend  \
417              &&  ./configure > /dev/null 2>&1  \              &&  ./configure > /dev/null 2>&1  \
418              &&  make > /dev/null 2>&1              &&  $MAKE > /dev/null 2>&1
419          if test -x ./makedepend.exe ; then          if test -x ./makedepend.exe ; then
420              $LN ./makedepend.exe ./makedepend              $LN ./makedepend.exe ./makedepend
421          fi          fi
# Line 230  build_cyrus_makedepend()  { Line 427  build_cyrus_makedepend()  {
427      rm -f ./genmake_cy_md      rm -f ./genmake_cy_md
428      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
429          MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'          MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
430            echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
431          return 0          return 0
432      else      else
433          echo "WARNING: unable to build cyrus-imapd-makedepend"          echo "WARNING: fail to build cyrus-imapd-makedepend" >> $LOGFILE
434          return 1          return 1
435      fi      fi
436  }  }
437    
438  # Guess possible config options for this host  build_embed_encode()
439  find_possible_configs()  {  {
440        printf "  building the embed-encode utility...  "
441      tmp1=`uname`"_"`uname -m`      if test ! -e "$ROOTDIR/tools/embed_encode/encode_files" ; then
442      tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`          if test ! -d "$ROOTDIR/tools/embed_encode" ; then
443      tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`              echo
444      tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`              echo "    Error: can't locate \"$ROOTDIR/tools/embed_encode\""
445      tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`              echo
446      tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`              EMBED_SRC=f
447      PLATFORM=$tmp3              return 1
448      echo $PLATFORM | grep cygwin > /dev/null 2>&1  &&  PLATFORM=cygwin_ia32          fi
449      OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`          clist="cc gcc c89 $CC"
450      echo "  The platform appears to be:  $PLATFORM"          for ic in $clist ; do
451                    comm="$ic -o encode_files encode_files.c"
452      echo "test" > test              ( cd $ROOTDIR/tools/embed_encode && $comm ) > /dev/null 2>&1
453      ln -s ./test link              RETVAL=$?
454      RETVAL=$?              if test "x$RETVAL" = x0 ; then
455      if test "x${RETVAL}" = x0 ; then                  echo "OK"
456          LN="ln -s"                  return 0
457      else              fi
458          echo "Error: \"ln -s\" does not appear to work on this system!"          done
459          echo "  For help, please contact <MITgcm-support@mitgcm.org>."          echo
460          exit 1          echo "    Error: unable to build $ROOTDIR/embed_encode/encode_files"
461      fi          echo "      so it has been disabled"
462      rm -f test link          echo
463            EMBED_SRC=f
464      if test "x$CPP" = x ; then          return 1
         CPP="cpp -traditional -P"  
465      fi      fi
466        echo "OK"
467    }
468    
469      look_for_makedepend  #  look for possible C compilers
470    look_for_C_compilers() {
471      #================================================================      echo >> $LOGFILE
472      #  look for possible C compilers      echo "running: look_for_C_compilers()" >> $LOGFILE
473      tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc"      rm -f ./genmake_hello.c  ./genmake_hello
474      p_CC=      cat >> genmake_hello.c << EOF
     for c in $tmp ; do  
         rm -f ./genmake_hello.c  ./genmake_hello  
         cat >> genmake_hello.c << EOF  
475  #include <stdio.h>  #include <stdio.h>
476  int main(int argc, char **argv) {  int main(int argc, char **argv) {
477    printf("Hello!\n");    printf("Hello!\n");
478    return 0;    return 0;
479  }  }
480  EOF  EOF
481          $c -o genmake_hello genmake_hello.c > /dev/null 2>&1      tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc icc"
482        p_CC=
483        for c in $tmp ; do
484            COMM="$c $CFLAGS -o genmake_hello genmake_hello.c"
485            echo $COMM >> $LOGFILE
486            $COMM >> $LOGFILE 2>&1
487          RETVAL=$?          RETVAL=$?
488          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
489                echo " $c test successful" >> $LOGFILE
490              p_CC="$p_CC $c"              p_CC="$p_CC $c"
491          fi          fi
492      done      done
# Line 300  Error: No C compilers were found in your Line 502  Error: No C compilers were found in your
502  EOF  EOF
503          exit 1          exit 1
504      else      else
505          echo "  The possible C compilers found in your path are:"          echo "  The possible C compilers found in your path are: $p_CC" | tee -a $LOGFILE
         echo "   "$p_CC  
506          if test "x$CC" = x ; then          if test "x$CC" = x ; then
507              CC=`echo $p_CC | $AWK '{print $1}'`              CC=`echo $p_CC | $AWK '{print $1}'`
508              echo "  Setting C compiler to: "$CC              echo "  Setting C compiler to: "$CC
509          fi          fi
510      fi      fi
511        echo " --> set CC='$CC'" >> $LOGFILE
512    }
513    
514    # Guess possible config options for this host
515    find_possible_optfile()  {
516    
517        echo >> $LOGFILE
518        echo "running: find_possible_optfile()" >> $LOGFILE
519        tmp1=`uname`"_"`uname -m`
520        tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
521        tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
522        tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
523        tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
524        tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
525        PLATFORM=$tmp3
526        echo $PLATFORM | grep cygwin > /dev/null 2>&1  &&  PLATFORM=cygwin_ia32
527        OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
528        echo "  The platform appears to be:  $PLATFORM" | tee -a $LOGFILE
529    
530      #================================================================      #================================================================
531      #  look for possible FORTRAN compilers      #  look for possible FORTRAN compilers
532      tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"      echo "  look for possible FORTRAN compilers" >> $LOGFILE
533        tmp="$MITGCM_FC $FC efc gfortran g77 f77 pgf77 pgf95 ifc ifort f90 f95 mpif77 mpf77 mpxlf95 g95"
534      p_FC=      p_FC=
535      for c in $tmp ; do      rm -f ./genmake_hello.f
536          rm -f ./hello.f ./hello      cat >> genmake_hello.f <<EOF
         cat >> hello.f <<EOF  
537        program hello        program hello
538        do i=1,3        do i=1,3
539          print *, 'hello world : ', i          print *, 'hello world : ', i
540        enddo        enddo
541        end        end
542  EOF  EOF
543          $c -o hello hello.f > /dev/null 2>&1      for f in $tmp ; do
544            COMM="$f -o genmake_hello genmake_hello.f"
545            echo $COMM >> $LOGFILE
546            $COMM >> $LOGFILE 2>&1
547          RETVAL=$?          RETVAL=$?
548          if test "x${RETVAL}" = x0 ; then          if test "x${RETVAL}" = x0 ; then
549              p_FC="$p_FC $c"              echo " $f test successful" >> $LOGFILE
550                p_FC="$p_FC $f"
551          fi          fi
552      done      done
553      rm -f ./hello.f ./hello      rm -f ./genmake_hello.f ./genmake_hello
554      if test "x${p_FC}" = x ; then      if test "x${p_FC}" = x ; then
555          cat 1>&2 <<EOF          cat 1>&2 <<EOF
556    
# Line 340  Error: No Fortran compilers were found i Line 563  Error: No Fortran compilers were found i
563  EOF  EOF
564          exit 1          exit 1
565      else      else
566          echo "  The possible FORTRAN compilers found in your path are:"          echo "  The possible FORTRAN compilers found in your path are: $p_FC" | tee -a $LOGFILE
567          echo "   "$p_FC      fi
568          if test "x$FC" = x ; then  
569              FC=`echo $p_FC | $AWK '{print $1}'`      #  Use the first of the compilers found in the current PATH
570              echo "  Setting FORTRAN compiler to: "$FC      #  that has a correctly-named optfile
571          fi      if test "x$OPTFILE" = x  -a  "x$FC" = x ; then
572            for i in $p_FC ; do
573                OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
574                if test -r $OPTFILE ; then
575                    echo "  Setting OPTFILE to: "$OPTFILE | tee -a $LOGFILE
576                    break
577                fi
578            done
579      fi      fi
580    
581      if test "x$OPTFILE" = x ; then      if test "x$OPTFILE" = x ; then
582          OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC          OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
583          if test ! -r $OPTFILE ; then          if test ! -r $OPTFILE ; then
584               echo "  I looked for the file "$OPTFILE" but did not find it"               echo "  I looked for the file "$OPTFILE" but did not find it"
585          fi          fi
586      fi      fi
587  #    echo "  The options file:  $p_OF"  
 #    echo "    appears to match so we'll use it."  
 #   for i in $p_FC ; do  
 #p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i  
 #if test -r $p_OF ; then  
 #    OPTFILE=$p_OF  
 #    echo "  The options file:  $p_OF"  
 #    echo "    appears to match so we'll use it."  
 #    break  
 #fi  
 #   done  
588      if test "x$OPTFILE" = x ; then      if test "x$OPTFILE" = x ; then
589          cat 1>&2 <<EOF          cat 1>&2 <<EOF
590    
# Line 380  Error: No options file was found in:  $R Line 600  Error: No options file was found in:  $R
600  EOF  EOF
601          exit 1          exit 1
602      fi      fi
603        }
 #     # 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  
 # EOF  
 #       eval "$mpi_fort -showme test.f > out"  
 #       RETVAL=$?  
 #       if test "x${RETVAL}" = x0 ; then  
 #           a=`cat out`  
 #           for i in $a ; do  
 #               case $i in  
 #                   -*)  
 #                       mpi_libs="$mpi_libs $i" ;;  
 #               esac  
 #           done  
 #           echo "The MPI libs appear to be:"  
 #           echo "  "$mpi_libs  
 #       fi  
 #       rm -f test.f out  
 #     fi  
604    
605    #  Do a local copy of MPI headers files (in local dir ./mpi_headers/) after
606    #  checking for additional included headers (in case of chain of included header)
607    mpi_headers_do_local_copy() {
608    
609        dBug=0
610        #----- check for additional headers (chain of included headers)
611        listIni=$MPI_HEADER_FILES
612        echo $listIni | grep "\<mpif.h\>" > /dev/null 2>&1
613        outp=$?
614        #- always check mpif.h (the only mpi-header included in standard MITgcm code)
615        if test $outp != 0 ; then listIni="mpif.h $listIni" ; fi
616        if test $dBug = 1 ; then echo "listIni='$listIni'" ; fi
617        doCheck=1 ; list2copy='' ; list2check=$listIni
618        while test $doCheck = 1 ; do
619            newList=''
620            for i in $list2check ; do
621             if test -f $MPIINCLUDEDIR/$i ; then
622                newInc=`grep '^ *include ' $MPIINCLUDEDIR/$i | \
623                    sed -e 's/^ *include //' -e 's/\!.*$//' -e "s/'//g"  -e 's/\"//g'`
624               if test $dBug = 1 ; then echo -n "checking $i : newInc='$newInc'" ; fi
625               for j in $newInc ; do
626                 echo $listIni $list2copy $newList | grep "\<$j\>" > /dev/null 2>&1
627                 outp=$?
628                 if test $outp != 0 ; then
629                    if test $dBug = 1 ; then echo -n " ; adding $j" ; fi
630                    newList="$newList $j"
631                 fi
632               done
633               if test $dBug = 1 ; then echo "" ; fi
634             fi
635            done
636            if test "x$newList" = x ; then doCheck=0
637            else list2check=$newList ; list2copy="$list2copy $newList"
638            fi
639        done
640        list2copy="$MPI_HEADER_FILES $list2copy"
641        if test $dBug = 1 ; then echo "list2copy='$list2copy'" ; fi
642        #----- make local copy and update LOCAL_MPI_HEADERS (if not already set)
643        mkListInc=0
644        for i in $list2copy ; do
645            if test -f $MPIINCLUDEDIR/$i ; then
646                cp -p $MPIINCLUDEDIR/$i ./mpi_headers
647                if test $i = 'mpif.h' ; then
648                    perl -i -pe 's/MPI_DISPLACEMENT_CURRENT=-1_8/MPI_DISPLACEMENT_CURRENT=-1/g' mpi_headers/mpif.h
649                fi
650                if test $mkListInc = 1 ; then
651                    LOCAL_MPI_HEADERS="$LOCAL_MPI_HEADERS ./mpi_headers/$i"
652                fi
653                if test "x$LOCAL_MPI_HEADERS" = x ; then
654                    LOCAL_MPI_HEADERS="./mpi_headers/$i" ; mkListInc=1
655                fi
656            fi
657        done
658  }  }
659    
660  #  Parse the package dependency information  #  Parse the package dependency information
# Line 418  get_pdepend_list()  { Line 663  get_pdepend_list()  {
663      #  strip the comments and then convert the dependency file into      #  strip the comments and then convert the dependency file into
664      #  two arrays: PNAME, DNAME      #  two arrays: PNAME, DNAME
665      cat $1 | sed -e 's/#.*$//g' \      cat $1 | sed -e 's/#.*$//g' \
666          | $AWK 'BEGIN{nn=0;} (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}' \
667          > ./.pd_tmp          > ./.pd_tmp
668        RETVAL=$?
669        if test ! "x${RETVAL}" = x0 ; then
670          echo "Error: unable to parse package dependencies -- please check PKG_DEPEND=\"$1\""
671          exit 1
672        fi
673      . ./.pd_tmp      . ./.pd_tmp
674      rm -f ./.pd_tmp      rm -f ./.pd_tmp
   
     printf "PNAME = "${}  
 }  
   
   
 #  Explain usage  
 usage()  {  
 cat <<EOF  
   
 Usage: "$0" [OPTIONS]  
   where [OPTIONS] can be:  
   
     -help | --help | -h | --h  
           Print this help message and exit.  
   
     -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME  
       -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME  
           Use "NAME" as the adoptfile.  By default, the file at  
           "tools/adjoint_options/adjoint_default" will be used.  
   
     -nooptfile | --nooptfile  
       -optfile NAME | --optfile NAME | -of NAME | --of NAME  
       -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME  
           Use "NAME" as the optfile.  By default, an attempt will be  
           made to find an appropriate "standard" optfile in the  
           tools/build_options/ directory.  
   
     -pdepend NAME | --pdepend NAME  
       -pdepend=NAME | --pdepend=NAME  
           Get package dependency information from "NAME".  
   
     -pdefault NAME | --pdefault NAME  
       -pdefault=NAME | --pdefault=NAME  
           Get the default package list from "NAME".  
   
     -make NAME | -m NAME  
       --make=NAME | -m=NAME  
           Use "NAME" for the MAKE program. The default is "make" but  
           many platforms, "gmake" is the preferred choice.  
   
     -makefile NAME | -mf NAME  
       --makefile=NAME | -mf=NAME  
           Call the makefile "NAME".  The default is "Makefile".  
   
     -makedepend NAME | -md NAME  
       --makedepend=NAME | -md=NAME  
           Use "NAME" for the MAKEDEPEND program.  
   
     -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME  
       -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME  
           Specify the location of the MITgcm ROOTDIR as "NAME".  
           By default, genamke will try to find the location by  
           looking in parent directories (up to the 5th parent).  
   
     -mods NAME | --mods NAME | -mo NAME | --mo NAME  
       -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME  
           Here, "NAME" specifies a list of directories that are  
           used for additional source code.  Files found in the  
           "mods list" are given preference over files of the same  
           name found elsewhere.  
   
     -disable NAME | --disable NAME  
       -disable=NAME | --disable=NAME  
           Here "NAME" specifies a list of packages that we don't  
           want to use.  If this violates package dependencies,  
           genamke will exit with an error message.  
   
     -enable NAME | --enable NAME  
       -enable=NAME | --enable=NAME  
           Here "NAME" specifies a list of packages that we wish  
           to specifically enable.  If this violates package  
           dependencies, genamke will exit with an error message.  
   
     -standarddirs NAME | --standarddirs NAME  
       -standarddirs=NAME | --standarddirs=NAME  
           Here, "NAME" specifies a list of directories to be  
           used as the "standard" code.  
   
     -fortran NAME | --fortran NAME | -fc NAME | --fc NAME  
       -fc=NAME | --fc=NAME  
           Use "NAME" as the fortran compiler.  By default, genmake  
           will search for a working compiler by trying a list of  
           "usual suspects" such as g77, f77, etc.  
   
     -cc NAME | --cc NAME | -cc=NAME | --cc=NAME  
           Use "NAME" as the C compiler.  By default, genmake  
           will search for a working compiler by trying a list of  
           "usual suspects" such as gcc, c89, cc, etc.  
   
     -[no]ieee | --[no]ieee  
           Do or don't use IEEE numerics.  Note that this option  
           *only* works if it is supported by the OPTFILE that  
           is being used.  
   
     -mpi | --mpi  
           Include MPI header files and link to MPI libraries  
     -mpi=PATH | --mpi=PATH  
           Include MPI header files and link to MPI libraries using MPI_ROOT  
           set to PATH. i.e. Include files from \$PATH/include, link to libraries  
           from \$PATH/lib and use binaries from \$PATH/bin.  
   
     -bash NAME  
           Explicitly specify the Bourne or BASH shell to use  
   
   While it is most often a single word, the "NAME" variables specified  
   above can in many cases be a space-delimited string such as:  
   
     --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'  
     -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'  
     -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'  
   
   which, depending upon your shell, may need to be single-quoted.  
   
   For more detailed genmake documentation, please see:  
   
     http://mitgcm.org/devel_HOWTO/  
   
 EOF  
   
     exit 1  
675  }  }
676    
677  #  Build a CPP macro to automate calling C routines from FORTRAN  #  Build a CPP macro to automate calling C routines from FORTRAN
# Line 549  get_fortran_c_namemangling()  { Line 679  get_fortran_c_namemangling()  {
679    
680      #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""      #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
681      if test ! "x$FC_NAMEMANGLE" = x ; then      if test ! "x$FC_NAMEMANGLE" = x ; then
682          return 0          return 0
683      fi      fi
684        echo " running: get_fortran_c_namemangling()" >> $LOGFILE
685    
686      default_nm="#define FC_NAMEMANGLE(X) X ## _"      default_nm="#define FC_NAMEMANGLE(X) X ## _"
687        
688      cat > genmake_test.c <<EOF      cat > genmake_test.c <<EOF
689  void tcall( char * string ) { tsub( string ); }  void tcall( char * string ) { tsub( string ); }
690  EOF  EOF
691      $MAKE genmake_test.o >> genmake_warnings 2>&1      COMM="$CC $CFLAGS -c genmake_test.c"
692        echo ' '$COMM >> $LOGFILE
693        $COMM >> $LOGFILE 2>&1
694      RETVAL=$?      RETVAL=$?
695      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
696          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
697          cat <<EOF>> genmake_errors          cat <<EOF>> $LOGFILE
698    
699  WARNING: C test compile fails   WARNING: C test compile fails
700  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
701  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here   WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
702  EOF  EOF
703          return 1          return 1
704      fi      fi
# Line 573  EOF Line 706  EOF
706      RETVAL=$?      RETVAL=$?
707      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
708          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
709          cat <<EOF>> genmake_warnings          cat <<EOF>> $LOGFILE
710    
711  WARNING: The "nm" command failed.   WARNING: The "nm" command failed.
712  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
713  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here   WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
714  EOF  EOF
715          return 1          return 1
716      fi      fi
717      cat > genmake_tcomp.f <<EOF      cat > genmake_tcomp.$FS <<EOF
718        subroutine tcall( string )        subroutine tcall( string )
719        character*(*) string        character*(*) string
720        call tsub( string )        call tsub( string )
721        end        end
722  EOF  EOF
723      $FC $FFLAGS $DEFINES -c genmake_tcomp.f >> genmake_warnings 2>&1      COMM="$FC $FFLAGS -c genmake_tcomp.$FS"
724        echo ' '$COMM >> $LOGFILE
725        $COMM >> $LOGFILE 2>&1
726      RETVAL=$?      RETVAL=$?
727      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
728          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
729          cat <<EOF>> genmake_warnings          cat <<EOF>> $LOGFILE
730    
731  WARNING: FORTRAN test compile fails -- please see "genmake_errors"   WARNING: FORTRAN test compile fails -- please see '$LOGFILE'
732  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
733  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.   WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
734  EOF  EOF
735          return 1          return 1
736      fi      fi
# Line 603  EOF Line 738  EOF
738      RETVAL=$?      RETVAL=$?
739      if test "x$RETVAL" != x0 ; then      if test "x$RETVAL" != x0 ; then
740          FC_NAMEMANGLE=$default_nm          FC_NAMEMANGLE=$default_nm
741          cat <<EOF>> genmake_warnings          cat <<EOF>> $LOGFILE
742    
743  WARNING: The "nm" command failed.   WARNING: The "nm" command failed.
744  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'   WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
745  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.   WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
746  EOF  EOF
747          return 1          return 1
748      fi      fi
# Line 633  EOF Line 768  EOF
768    
769      #  cleanup the testing files      #  cleanup the testing files
770      rm -f genmake_tcomp.* genmake_test.*      rm -f genmake_tcomp.* genmake_test.*
 }  
771    
772        echo " --> set FC_NAMEMANGLE='$FC_NAMEMANGLE'" >> $LOGFILE
773    }
774    
775  check_HAVE_CLOC()  {  check_HAVE_CLOC()  {
776        echo >> $LOGFILE
777        echo "running: check_HAVE_CLOC()" >> $LOGFILE
778      get_fortran_c_namemangling      get_fortran_c_namemangling
779      cat <<EOF > genmake_tc_1.c      cat <<EOF > genmake_tc_1.c
780  $FC_NAMEMANGLE  $FC_NAMEMANGLE
# Line 653  void FC_NAMEMANGLE(cloc) ( double *curti Line 791  void FC_NAMEMANGLE(cloc) ( double *curti
791   *curtim = *curtim/1.E6;   *curtim = *curtim/1.E6;
792  }  }
793  EOF  EOF
794      make genmake_tc_1.o >> genmake_tc.log 2>&1      COMM="$CC $CFLAGS -c genmake_tc_1.c"
795        echo $COMM >> $LOGFILE
796        $COMM >> $LOGFILE 2>&1
797      RET_C=$?      RET_C=$?
798      cat <<EOF > genmake_tc_2.f      cat <<EOF > genmake_tc_2.$FS
799        program hello        program hello
800        Real*8 wtime        REAL*8 wtime
801        external cloc        external cloc
802        call cloc(wtime)        call cloc(wtime)
803        print *," HELLO WORLD", wtime        print *," HELLO WORLD", wtime
804        end program hello        end
805  EOF  EOF
806      $FC $FFLAGS -o genmake_tc genmake_tc_2.f genmake_tc_1.o >> genmake_tc.log 2>&1      COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
807        echo $COMM >> $LOGFILE
808        $COMM >> $LOGFILE 2>&1
809      RET_F=$?      RET_F=$?
810      test -x ./genmake_tc  &&  ./genmake_tc >> genmake_tc.log 2>&1      test -x ./genmake_tc  &&  ./genmake_tc >> $LOGFILE 2>&1
811      RETVAL=$?      RETVAL=$?
812      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" = x0 ; then
813          HAVE_CLOC=t          HAVE_CLOC=t
         DEFINES="$DEFINES -DHAVE_CLOC"  
814      fi      fi
815      rm -f genmake_tc*      rm -f genmake_tc*
816        echo " --> set HAVE_CLOC='$HAVE_CLOC'" >> $LOGFILE
817  }  }
818    
819    check_HAVE_SIGREG()  {
820        if test ! "x$HAVE_SIGREG" = x ; then
821            return
822        fi
823        echo >> $LOGFILE
824        echo "running: check_HAVE_SIGREG()" >> $LOGFILE
825        get_fortran_c_namemangling
826        cat <<EOF > genmake_tc_1.c
827    $FC_NAMEMANGLE
828    #include <stdlib.h>
829    #include <stdio.h>
830    #include <signal.h>
831    #include <errno.h>
832    #include <ucontext.h>
833    
834    int * ip;
835    
836    static void killhandler(
837        unsigned int sn, siginfo_t  si, struct ucontext *sc )
838    {
839        *ip = *ip + 1;
840        return;
841    }
842    
843    void FC_NAMEMANGLE(sigreg) (int * aip)
844    {
845        struct sigaction s;
846        ip = aip;
847        s.sa_flags = SA_SIGINFO;
848        s.sa_sigaction = (void *)killhandler;
849        if(sigaction (SIGTERM,&s,(struct sigaction *)NULL)) {
850            printf("Sigaction returned error = %d\n", errno);
851            exit(0);
852        }
853        return;
854    }
855    EOF
856        COMM="$CC $CFLAGS -c genmake_tc_1.c"
857        echo $COMM >> $LOGFILE
858        $COMM >> $LOGFILE 2>&1
859        RET_C=$?
860        cat <<EOF > genmake_tc_2.$FS
861          program hello
862          integer anint
863          common /iv/ anint
864          external sigreg
865          call sigreg(anint)
866          end
867    EOF
868        cat genmake_tc_2.$FS >> $LOGFILE
869        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
870        echo $COMM >> $LOGFILE
871        $COMM >> $LOGFILE 2>&1
872        RETVAL=$?
873        if test "x$RETVAL" = x0 ; then
874            HAVE_SIGREG=t
875        fi
876        rm -f genmake_tc*
877        echo " --> set HAVE_SIGREG='$HAVE_SIGREG'" >> $LOGFILE
878    }
879    
880    check_HAVE_SETRLSTK()  {
881        if test ! "x$HAVE_SETRLSTK" = x ; then
882            return
883        fi
884        echo >> $LOGFILE
885        echo "running: check_HAVE_SETRLSTK()" >> $LOGFILE
886        get_fortran_c_namemangling
887        cat <<EOF > genmake_tc_1.c
888    $FC_NAMEMANGLE
889    #include <sys/time.h>
890    #include <sys/resource.h>
891    #include <unistd.h>
892    void FC_NAMEMANGLE(setrlstk) ()
893    {
894        struct rlimit rls;
895        rls.rlim_cur = RLIM_INFINITY;
896        rls.rlim_max = RLIM_INFINITY;
897        setrlimit(RLIMIT_STACK, &rls);
898        return;
899    }
900    EOF
901        COMM="$CC $CFLAGS -c genmake_tc_1.c"
902        echo $COMM >> $LOGFILE
903        $COMM >> $LOGFILE 2>&1
904        RET_C=$?
905        cat <<EOF > genmake_tc_2.$FS
906          program hello
907          external setrlstk
908          call setrlstk()
909          end
910    EOF
911        cat genmake_tc_2.$FS >> $LOGFILE
912        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
913        echo $COMM >> $LOGFILE
914        $COMM >> $LOGFILE 2>&1
915        RETVAL=$?
916        if test "x$RETVAL" = x0 ; then
917            HAVE_SETRLSTK=t
918        fi
919        rm -f genmake_tc*
920        echo " --> set HAVE_SETRLSTK='$HAVE_SETRLSTK'" >> $LOGFILE
921    }
922    
923    check_HAVE_STAT()  {
924        echo >> $LOGFILE
925        echo "running: check_HAVE_STAT()" >> $LOGFILE
926        get_fortran_c_namemangling
927        cat <<EOF > genmake_tc_1.c
928    $FC_NAMEMANGLE
929    #include <stdio.h>
930    #include <stdlib.h>
931    #include <unistd.h>
932    #include <sys/stat.h>
933    #include <sys/types.h>
934    void FC_NAMEMANGLE(tfsize) ( int *nbyte )
935    {
936        char name[512];
937        struct stat astat;
938    
939        name[0] = 'a'; name[1] = '\0';
940        if (! stat(name, &astat))
941            *nbyte = (int)(astat.st_size);
942        else
943            *nbyte = -1;
944    }
945    EOF
946        COMM="$CC $CFLAGS -c genmake_tc_1.c"
947        echo $COMM >> $LOGFILE
948        $COMM >> genmake_tc.log 2>&1
949        RET_C=$?
950        cat <<EOF > genmake_tc_2.$FS
951          program hello
952          integer nbyte
953          call tfsize(nbyte)
954          print *," HELLO WORLD", nbyte
955          end
956    EOF
957        cat genmake_tc_2.$FS >> $LOGFILE
958        COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
959        echo $COMM >> $LOGFILE
960        $COMM >> genmake_tc.log 2>&1
961        RETVAL=$?
962        if test "x$RETVAL" = x0 ; then
963            HAVE_STAT=t
964        fi
965        rm -f genmake_tc*
966        echo " --> set HAVE_STAT='$HAVE_STAT'" >> $LOGFILE
967    }
968    
969  check_netcdf_libs()  {  check_netcdf_libs()  {
970      echo "" > genmake_tnc.log      if test ! "x$SKIP_NETCDF_CHECK" = x ; then
971      cat <<EOF > genmake_tnc.for          return
972        fi
973        echo >> $LOGFILE
974        echo "running: check_netcdf_libs()" >> $LOGFILE
975        cat <<EOF > genmake_tnc.F
976        program fgennc        program fgennc
977  #include "netcdf.inc"  #include "netcdf.inc"
978    EOF
979       #if test ! "x$MPI" = x ; then
980       #    echo '#include "mpif.h"' >> genmake_tnc.F
981       #fi
982        cat <<EOF >> genmake_tnc.F
983        integer iret, ncid, xid        integer iret, ncid, xid
984        iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)        iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
985        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
# Line 689  check_netcdf_libs()  { Line 989  check_netcdf_libs()  {
989        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)        IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
990        end        end
991  EOF  EOF
992      #echo "$CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f"      echo "===  genmake_tnc.F  >>>" > genmake_tnc.log
993      #echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.f"      cat genmake_tnc.F >> genmake_tnc.log
994      #echo "$LINK -o genmake_tnc.o $LIBS"      echo "<<<  genmake_tnc.F  ===" >> genmake_tnc.log
995      $CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f 2>/dev/null  \      RET_CPP=f
996          &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.f  \      COMM="cat genmake_tnc.F | $CPP $DEFINES $INCLUDES"
997          &&  $LINK -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1      echo "$COMM" >> genmake_tnc.log
998        eval $COMM > genmake_tnc.$FS 2>/dev/null  &&  RET_CPP=t
999        if test "x$RET_CPP" = xf ; then
1000            echo "  WARNING: CPP failed to pre-process the netcdf test." \
1001                >> genmake_tnc.log
1002            echo "    Please check that \$INCLUDES is properly set." \
1003                >> genmake_tnc.log
1004        fi
1005        echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.$FS  \ " >> genmake_tnc.log
1006        echo "  &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc.o $LIBS" >> genmake_tnc.log
1007        $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
1008            &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
1009      RET_COMPILE=$?      RET_COMPILE=$?
1010      test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1      cat genmake_tnc.log >> $LOGFILE
1011      RETVAL=$?  
1012      if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then      #EH3  Remove test program execution for machines that either disallow
1013        #EH3  execution or cannot support it (eg. cross-compilers)
1014        #EH3
1015        #EH3 test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1
1016        #EH3 RETVAL=$?
1017        #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
1018    
1019        if test "x$RET_COMPILE" = x0 ; then
1020          HAVE_NETCDF=t          HAVE_NETCDF=t
1021            echo "check_netcdf: successful" >> $LOGFILE
1022      else      else
1023          # try again with "-lnetcdf" added to the libs          # try again with "-lnetcdf" added to the libs
1024          $CPP $DEFINES $INCLUDES genmake_tnc.for > genmake_tnc.f 2>/dev/null  \          echo "==> try again with added '-lnetcdf'" > genmake_tnc.log
1025              &&  $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f \          echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log
1026              $LIBS -lnetcdf >> genmake_tnc_2.log 2>&1          echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
1027            echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
1028            cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null  \
1029                &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
1030                &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
1031          RET_COMPILE=$?          RET_COMPILE=$?
1032          test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1          echo >> $LOGFILE
1033          RETVAL=$?          cat genmake_tnc.log >> $LOGFILE
1034          if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then          if test "x$RET_COMPILE" = x0 ; then
1035              LIBS="$LIBS -lnetcdf"              LIBS="$LIBS -lnetcdf"
1036              HAVE_NETCDF=t              HAVE_NETCDF=t
1037                echo "check_netcdf: successful" >> $LOGFILE
1038          else          else
1039              cat genmake_tnc.log >> genmake_warnings          # try again with "-lnetcdff" added to the libs
1040                echo "==> try again with added '-lnetcdff -lnetcdf'" > genmake_tnc.log
1041                echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log
1042                echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
1043                echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
1044                cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null  \
1045                    &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
1046                    &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdff -lnetcdf >> genmake_tnc.log 2>&1
1047                RET_COMPILE=$?
1048                echo >> $LOGFILE
1049                cat genmake_tnc.log >> $LOGFILE
1050                if test "x$RET_COMPILE" = x0 ; then
1051                    LIBS="$LIBS -lnetcdff -lnetcdf"
1052                    HAVE_NETCDF=t
1053                    echo "check_netcdf: successful" >> $LOGFILE
1054                fi
1055          fi          fi
1056      fi      fi
1057      rm -f genmake_tnc*      rm -f genmake_tnc*
1058        echo " --> set HAVE_NETCDF='$HAVE_NETCDF'" >> $LOGFILE
1059    }
1060    
1061    check_lapack_libs()  {
1062        if test ! "x$SKIP_LAPACK_CHECK" = x ; then
1063            return
1064        fi
1065        echo >> $LOGFILE
1066        echo "running: check_lapack_libs()" >> $LOGFILE
1067        cat <<EOF > genmake_tla.F
1068          program fgenla
1069          integer info
1070          integer ipiv( 2 )
1071          double precision ab( 4, 2 ), b( 2 )
1072          data ab / 0., 0., 1., 2., 0., 2., 1., 0. /
1073          data b / 1., 1. /
1074          call dgbsv( 2, 1, 1, 1, ab, 4, ipiv, b, 2, info )
1075          IF (info .NE. 0) write(*,*) 'Error:', info
1076          write(*,*) b
1077          end
1078    EOF
1079        echo "===  genmake_tla.F  >>>" > genmake_tla.log
1080        cat genmake_tla.F >> genmake_tla.log
1081        echo "<<<  genmake_tla.F  ===" >> genmake_tla.log
1082        RET_CPP=f
1083        COMM="cat genmake_tla.F | $CPP $DEFINES $INCLUDES"
1084        echo "$COMM" >> genmake_tla.log
1085        eval $COMM > genmake_tla.$FS 2>/dev/null  &&  RET_CPP=t
1086        if test "x$RET_CPP" = xf ; then
1087            echo "  WARNING: CPP failed to pre-process the lapack test." \
1088                >> genmake_tla.log
1089            echo "    Please check that \$INCLUDES is properly set." \
1090                >> genmake_tla.log
1091        fi
1092        echo "$FC $FFLAGS $FOPTIM -c genmake_tla.$FS  \ " >> genmake_tla.log
1093        echo "  &&  $LINK $FFLAGS $FOPTIM -o genmake_tla.o $LIBS" >> genmake_tla.log
1094        $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
1095            &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS >> genmake_tla.log 2>&1
1096        RET_COMPILE=$?
1097        cat genmake_tla.log >> $LOGFILE
1098    
1099        # test program execution not always possible (see check_netcdf_libs)
1100        #
1101        #test -x ./genmake_tla  &&  ./genmake_tla >> genmake_tla.log 2>&1
1102        #RETVAL=$?
1103        #if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
1104    
1105        if test "x$RET_COMPILE" = x0 ; then
1106            HAVE_LAPACK=t
1107            echo "check_lapack: successful" >> $LOGFILE
1108        else
1109            # try again with "-llapack" added to the libs
1110            echo "==> try again with added '-llapack'" > genmake_tla.log
1111            echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1112            echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1113            echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack" >> genmake_tla.log
1114            cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null  \
1115                &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
1116                &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack >> genmake_tla.log 2>&1
1117            RET_COMPILE=$?
1118            echo >> $LOGFILE
1119            cat genmake_tla.log >> $LOGFILE
1120            if test "x$RET_COMPILE" = x0 ; then
1121                LIBS="$LIBS -llapack"
1122                HAVE_LAPACK=t
1123                echo "check_lapack: successful" >> $LOGFILE
1124            else
1125            # try again with "-lf77blas -lcblas" added to the libs
1126                echo "==> try again with added '-llapack -lf77blas -lcblas'" > genmake_tla.log
1127                echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1128                echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1129                echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas" >> genmake_tla.log
1130                cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null  \
1131                    &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
1132                    &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas >> genmake_tla.log 2>&1
1133                RET_COMPILE=$?
1134                echo >> $LOGFILE
1135                cat genmake_tla.log >> $LOGFILE
1136                if test "x$RET_COMPILE" = x0 ; then
1137                    LIBS="$LIBS -llapack -lf77blas -lcblas"
1138                    HAVE_LAPACK=t
1139                    echo "check_lapack: successful" >> $LOGFILE
1140                else
1141                # try again with "-latlas" added to the libs
1142                    echo "==> try again with added '-llapack -lf77blas -lcblas -latlas'" > genmake_tla.log
1143                    echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1144                    echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1145                    echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas -latlas" >> genmake_tla.log
1146                    cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null  \
1147                        &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
1148                        &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas -latlas >> genmake_tla.log 2>&1
1149                    RET_COMPILE=$?
1150                    echo >> $LOGFILE
1151                    cat genmake_tla.log >> $LOGFILE
1152                    if test "x$RET_COMPILE" = x0 ; then
1153                        LIBS="$LIBS -llapack -lf77blas -lcblas -latlas"
1154                        HAVE_LAPACK=t
1155                        echo "check_lapack: successful" >> $LOGFILE
1156                    fi
1157                fi
1158            fi
1159        fi
1160        rm -f genmake_tla*
1161        echo " --> set HAVE_LAPACK='$HAVE_LAPACK'" >> $LOGFILE
1162  }  }
1163    
1164    check_HAVE_FLUSH()  {
1165        if test ! "x$SKIP_CHECK_FLUSH" = x ; then
1166            return
1167        fi
1168        echo >> $LOGFILE
1169        echo "running: check_HAVE_FLUSH()" >> $LOGFILE
1170        cat <<EOF > genmake_tflsh.$FS
1171          program fgenflsh
1172          integer iounit
1173          character*9 fname
1174          iounit = 26
1175          fname = 'tmp.tflsh'
1176          open(iounit,FILE=fname,STATUS='unknown')
1177          write(iounit,*) 'genmake_tflsh: hello'
1178          call flush(iounit)
1179          close(iounit)
1180          end
1181    EOF
1182        echo "===  genmake_tflsh.$FS  >>>" > genmake_tflsh.log
1183        cat genmake_tflsh.$FS >> genmake_tflsh.log
1184        echo "<<<  genmake_tflsh.$FS  ===" >> genmake_tflsh.log
1185    
1186        echo "$FC $FFLAGS $FOPTIM -c genmake_tflsh.$FS  \ " >> genmake_tflsh.log
1187        echo "  &&  $LINK $FFLAGS $FOPTIM -o genmake_tflsh.o $LIBS" >> genmake_tflsh.log
1188        $FC $FFLAGS $FOPTIM -c genmake_tflsh.$FS >> genmake_tflsh.log 2>&1  \
1189            &&  $LINK $FFLAGS $FOPTIM -o genmake_tflsh genmake_tflsh.o $LIBS >> genmake_tflsh.log 2>&1
1190        RET_COMPILE=$?
1191    
1192        if test "x$RET_COMPILE" = x0 ; then
1193            HAVE_FLUSH=t
1194            #cat genmake_tflsh.log >> $LOGFILE
1195            echo "  check_HAVE_FLUSH: successful" >> $LOGFILE
1196        else
1197            HAVE_FLUSH=f
1198            cat genmake_tflsh.log >> $LOGFILE
1199        fi
1200        rm -f genmake_tflsh*
1201        echo " --> set HAVE_FLUSH='$HAVE_FLUSH'" >> $LOGFILE
1202    }
1203    
1204  ###############################################################################  ###############################################################################
1205  #   Sequential part of script starts here  #   Sequential part of script starts here
# Line 731  PLATFORM= Line 1212  PLATFORM=
1212  LN=  LN=
1213  S64=  S64=
1214  KPP=  KPP=
1215  FC=  #FC=
1216  #CC=gcc  #CC=gcc
1217  CPP=  #CPP=
1218  LINK=  LINK=
1219  DEFINES=  DEFINES=
1220  PACKAGES=  PACKAGES=
1221  ENABLE=  ENABLE=
1222  DISABLE=  DISABLE=
1223  MAKEFILE=  # MAKEFILE=
1224  #MAKEDEPEND=  # MAKEDEPEND=
1225  PDEPEND=  PKG_DEPEND=
1226  DUMPSTATE=t  PKG_GROUPS=
1227  PDEFAULT=  DUMPSTATE=f
1228  OPTFILE=  OPTFILE=
1229  INCLUDES="-I."  INCLUDES="-I. $INCLUDES"
1230  FFLAGS=  FFLAGS=
1231  FOPTIM=  FOPTIM=
1232    FEXTRAFLAGS=
1233    USE_EXTENDED_SRC=
1234    EXTENDED_SRC_FLAG=
1235    GET_FC_VERSION=
1236  CFLAGS=  CFLAGS=
1237  KFLAGS1=  KFLAGS1=
1238  KFLAGS2=  KFLAGS2=
# Line 758  NOOPTFILES= Line 1243  NOOPTFILES=
1243  NOOPTFLAGS=  NOOPTFLAGS=
1244  MPI=  MPI=
1245  MPIPATH=  MPIPATH=
1246    OMP=
1247    OMPFLAG=
1248    USE_R4=
1249    TS=
1250    PAPIS=
1251    PCLS=
1252    FOOLAD=
1253    PAPI=
1254    PCL=
1255    HPMT=
1256    GSL=
1257    DEVEL=
1258    HAVE_TEST_L=
1259    
1260  # DEFINES checked by test compilation  # comment this line out to enable lapack test
1261    SKIP_LAPACK_CHECK=t
1262    
1263    # DEFINES checked by test compilation or command-line
1264  HAVE_SYSTEM=  HAVE_SYSTEM=
1265  HAVE_FDATE=  HAVE_FDATE=
1266  FC_NAMEMANGLE=  FC_NAMEMANGLE=
1267  HAVE_CLOC=  HAVE_CLOC=
1268    # HAVE_SETRLSTK=
1269    HAVE_STAT=
1270  HAVE_NETCDF=  HAVE_NETCDF=
1271  HAVE_ETIME=  HAVE_ETIME=
1272    IGNORE_TIME=
1273    HAVE_LAPACK=
1274    HAVE_FLUSH=
1275    
1276  MODS=  MODS=
1277  TOOLSDIR=  TOOLSDIR=
# Line 773  SOURCEDIRS= Line 1279  SOURCEDIRS=
1279  INCLUDEDIRS=  INCLUDEDIRS=
1280  STANDARDDIRS="USE_THE_DEFAULT"  STANDARDDIRS="USE_THE_DEFAULT"
1281    
1282    #- local config file
1283    gm_local="genmake_local"
1284    
1285  G2ARGS=  G2ARGS=
1286  BASH=  BASH=
1287  PWD=`pwd`  PWD=`pwd`
1288  MAKE=make  test "x$MAKE" = x  &&  MAKE=make
1289  AWK=awk  test "x$AWK" = x   &&  AWK=awk
1290  THISHOSTNAME=`hostname`  EMBED_SRC=
1291    THISHOST=`hostname`
1292  THISCWD=`pwd`  THISCWD=`pwd`
1293  THISDATE=`date`  THISDATE=`date`
1294    THISUSER=`echo $USER`
1295    THISVER=
1296  MACHINE=`uname -a`  MACHINE=`uname -a`
1297  EXECUTABLE=  EXECUTABLE=
1298  EXEHOOK=  EXEHOOK=
1299  EXEDIR=  EXEDIR=
 PACKAGES_CONF=  
1300  IEEE=  IEEE=
1301  if test "x$MITGCM_IEEE" != x ; then  if test "x$MITGCM_IEEE" != x ; then
1302      IEEE=$MITGCM_IEEE      IEEE=$MITGCM_IEEE
# Line 806  FTL_TAF_FLAGS= Line 1317  FTL_TAF_FLAGS=
1317  SVD_TAMC_FLAGS=  SVD_TAMC_FLAGS=
1318  TAMC_EXTRA=  TAMC_EXTRA=
1319    
1320    DIVA=
1321    MPIINCLUDEDIR=
1322    MPI_HEADER_FILES=
1323    LOCAL_MPI_HEADERS=
1324    
1325  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
1326  gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"  gm_s1="ROOTDIR STANDARDDIRS MODS PKG_DEPEND PKG_GROUPS DISABLE ENABLE"
1327  gm_s2="FC CPP IEEE MPI JAM DUMPSTATE STANDARDDIRS"  gm_s2="PLATFORM OPTFILE MAKE MAKEFILE MAKEDEPEND FC CC MPI OMP USE_R4"
1328    gm_s3="FEXTRAFLAGS IEEE DEVEL GSL TS PAPIS PCLS PAPI PCL HPMT DUMPSTATE"
1329    
1330  #  The following state is not directly set by command-line switches  #  The following state is not directly set by command-line switches
1331  gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "  gm_s4="LN S64 LINK PACKAGES INCLUDES FFLAGS FOPTIM"
1332  gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"  gm_s5="CFLAGS LIBS KPP KFLAGS1 KFLAGS2 KPPFILES NOOPTFILES NOOPTFLAGS"
1333  gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"  gm_s6="PWD TOOLSDIR SOURCEDIRS INCLUDEDIRS EXEDIR EXECUTABLE EXEHOOK"
1334  gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"  gm_s7="THISHOST THISUSER THISDATE THISVER MACHINE FC_NAMEMANGLE"
1335  gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME"  gm_s8="HAVE_NETCDF HAVE_SYSTEM HAVE_FDATE HAVE_ETIME HAVE_LAPACK HAVE_FLUSH"
1336    
1337  #  The following are all related to adjoint/tangent-linear stuff  #  The following are all related to adjoint/tangent-linear stuff
1338  gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"  gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
1339  gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"  gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
1340  gm_s12="TAF_EXTRA TAMC_EXTRA"  gm_s12="TAF_EXTRA TAMC_EXTRA DIVA MPIINCLUDEDIR MPI_HEADER_FILES"
1341    
1342  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 $gm_s8"
1343  gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"  gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
1344    
1345  cat <<EOF  cat <<EOF
1346    
1347  GENMAKE :  GENMAKE :
1348    
1349  A program for GENerating MAKEfiles for the MITgcm project.  For a  A program for GENerating MAKEfiles for the MITgcm project.
1350  quick list of options, use "genmake -h" or for more detail see:     For a quick list of options, use "genmake2 -h"
1351    or for more detail see the Developer's HOWTO manual at:
1352    http://mitgcm.org/devel_HOWTO/     http://mitgcm.org/public/docs.html
1353    
1354  EOF  EOF
1355    
1356    LOGFILE="genmake.log"
1357    #- clean-up previous genmake logfiles:
1358    rm -f genmake_state genmake_*optfile $LOGFILE
1359    
1360  echo "===  Processing options files and arguments  ==="  echo "===  Processing options files and arguments  ==="
 gm_local="genmake_local"  
 for i in . $MODS ; do  
     if test -r $i/$gm_local ; then  
         . $i/$gm_local  
         break  
     fi  
 done  
 printf "  getting local config information:  "  
 if test -f $gm_local ; then  
     echo "using $gm_local"  
     . $gm_local  
     # echo "DISABLE=$DISABLE"  
     # echo "ENABLE=$ENABLE"  
 else  
     echo "none found"  
 fi  
1361    
1362  #  echo "$0::$1:$2:$3:$4:$5:$6:$7:"  #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
 #OPTIONS=  
 #n=0  
 #for i ; do  
 #   echo "$i  $n"  
 #   setvar="OPTIONS[$n]='$i'"  
 #   #  echo "  $setvar"  
 #   eval "$setvar"  
 #   n=$(( $n + 1 ))  
 #done  
1363  #parse_options  #parse_options
1364  ac_prev=  ac_prev=
1365  for ac_option in $@ ; do  for ac_option in "$@" ; do
1366    
1367      G2ARGS="$G2ARGS \"$ac_option\""      G2ARGS="$G2ARGS \"$ac_option\""
1368    
# Line 877  for ac_option in $@ ; do Line 1372  for ac_option in $@ ; do
1372          ac_prev=          ac_prev=
1373          continue          continue
1374      fi      fi
1375        
1376      ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`      ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
1377        
1378      case $ac_option in      case $ac_option in
1379            
1380          -help | --help | -h | --h)          -help | --help | -h | --h)
1381              usage ;;              usage ;;
1382            
1383          -nooptfile | --nooptfile)          -nooptfile | --nooptfile)
1384              OPTFILE="NONE" ;;              OPTFILE="NONE" ;;
1385          -optfile | --optfile | -of | --of)          -optfile | --optfile | -of | --of)
1386              ac_prev=OPTFILE ;;              ac_prev=OPTFILE ;;
1387          -optfile=* | --optfile=* | -of=* | --of=*)          -optfile=* | --optfile=* | -of=* | --of=*)
1388              OPTFILE=$ac_optarg ;;              OPTFILE=$ac_optarg ;;
1389            
1390          -adoptfile | --adoptfile | -adof | --adof)          -adoptfile | --adoptfile | -adof | --adof)
1391              ac_prev=AD_OPTFILE ;;              ac_prev=AD_OPTFILE ;;
1392          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
1393              AD_OPTFILE=$ac_optarg ;;              AD_OPTFILE=$ac_optarg ;;
1394            
1395          -pdepend | --pdepend)          -pdepend | --pdepend)
1396              ac_prev=PDEPEND ;;              ac_prev=PKG_DEPEND ;;
1397          -pdepend=* | --pdepend=*)          -pdepend=* | --pdepend=*)
1398              PDEPEND=$ac_optarg ;;              PKG_DEPEND=$ac_optarg ;;
1399            
1400          -pdefault | --pdefault)          -pgroups | --pgroups)
1401              ac_prev=PDEFAULT ;;              ac_prev=PKG_GROUPS ;;
1402          -pdefault=* | --pdefault=*)          -pgroups=* | --pgroups=*)
1403              PDEFAULT=$ac_optarg ;;              PKG_GROUPS=$ac_optarg ;;
1404            
1405          -make | --make | -m | --m)          -make | --make | -m | --m)
1406              ac_prev=MAKE ;;              ac_prev=MAKE ;;
1407          -make=* | --make=* | -m=* | --m=*)          -make=* | --make=* | -m=* | --m=*)
1408              MAKE=$ac_optarg ;;              MAKE=$ac_optarg ;;
1409            
1410          -bash | --bash)          -bash | --bash)
1411              ac_prev=BASH ;;              ac_prev=BASH ;;
1412          -bash=* | --bash=*)          -bash=* | --bash=*)
1413              BASH=$ac_optarg ;;              BASH=$ac_optarg ;;
1414            
1415          -makedepend | --makedepend | -md | --md)          -makedepend | --makedepend | -md | --md)
1416              ac_prev=MAKEDEPEND ;;              ac_prev=MAKEDEPEND ;;
1417          -makedepend=* | --makedepend=* | -md=* | --md=*)          -makedepend=* | --makedepend=* | -md=* | --md=*)
1418              MAKEDEPEND=$ac_optarg ;;              MAKEDEPEND=$ac_optarg ;;
1419            
1420          -makefile | --makefile | -ma | --ma)          -makefile | --makefile | -mf | --mf)
1421              ac_prev=MAKEFILE ;;              ac_prev=MAKEFILE ;;
1422          -makefile=* | --makefile=* | -ma=* | --ma=*)          -makefile=* | --makefile=* | -mf=* | --mf=*)
1423              MAKEFILE=$ac_optarg ;;              MAKEFILE=$ac_optarg ;;
1424            
1425          -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)          -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
1426              echo "ERROR: The platform option has been removed.  Please specify"              echo "ERROR: The platform option has been removed.  Please specify"
1427              echo "  the build options using the \"optfile\" mechanism."              echo "  the build options using the \"optfile\" mechanism."
1428              echo              echo
1429              usage              usage
1430              ;;              ;;
1431            
1432          -rootdir | --rootdir | -rd | --rd)          -rootdir | --rootdir | -rd | --rd)
1433              ac_prev=ROOTDIR ;;              ac_prev=ROOTDIR ;;
1434          -rootdir=* | --rootdir=* | -rd=* | --rd=*)          -rootdir=* | --rootdir=* | -rd=* | --rd=*)
1435              ROOTDIR=$ac_optarg ;;              ROOTDIR=$ac_optarg ;;
1436            
1437          -mods | --mods | -mo | --mo)          -mods | --mods | -mo | --mo)
1438              ac_prev=MODS ;;              ac_prev=MODS ;;
1439          -mods=* | --mods=* | -mo=* | --mo=*)          -mods=* | --mods=* | -mo=* | --mo=*)
1440              MODS=$ac_optarg ;;              MODS=$ac_optarg ;;
1441            
1442          -disable | --disable)          -disable | --disable)
1443              ac_prev=DISABLE ;;              ac_prev=DISABLE ;;
1444          -disable=* | --disable=*)          -disable=* | --disable=*)
1445              DISABLE=$ac_optarg ;;              DISABLE=$ac_optarg ;;
1446            
1447          -enable | --enable)          -enable | --enable)
1448              ac_prev=ENABLE ;;              ac_prev=ENABLE ;;
1449          -enable=* | --enable=*)          -enable=* | --enable=*)
1450              ENABLE=$ac_optarg ;;              ENABLE=$ac_optarg ;;
1451            
1452          -standarddirs | --standarddirs)          -standarddirs | --standarddirs)
1453              ac_prev=STANDARDDIRS ;;              ac_prev=STANDARDDIRS ;;
1454          -standarddirs=* | --standarddirs=*)          -standarddirs=* | --standarddirs=*)
# Line 963  for ac_option in $@ ; do Line 1458  for ac_option in $@ ; do
1458  #               ac_prev=cpp ;;  #               ac_prev=cpp ;;
1459  #           -cpp=* | --cpp=*)  #           -cpp=* | --cpp=*)
1460  #               CPP=$ac_optarg ;;  #               CPP=$ac_optarg ;;
1461            
1462          -cc | --cc)          -cc | --cc)
1463              ac_prev=CC ;;              ac_prev=CC ;;
1464          -cc=* | --cc=*)          -cc=* | --cc=*)
1465              CC=$ac_optarg ;;              CC=$ac_optarg ;;
1466            
1467          -fortran | --fortran | -fc | --fc)          -fortran | --fortran | -fc | --fc)
1468              ac_prev=FC ;;              ac_prev=FC ;;
1469          -fc=* | --fc=*)          -fc=* | --fc=*)
1470              FC=$ac_optarg ;;              FC=$ac_optarg ;;
1471            
1472          -fs | --fs)          -fs | --fs)
1473              ac_prev=FS ;;              ac_prev=FS ;;
1474          -fs=* | --fs=*)          -fs=* | --fs=*)
1475              FS=$ac_optarg ;;              FS=$ac_optarg ;;
1476            
1477          -fs90 | --fs90)          -fs90 | --fs90)
1478              ac_prev=FS90 ;;              ac_prev=FS90 ;;
1479          -fs90=* | --fs90=*)          -fs90=* | --fs90=*)
1480              FS90=$ac_optarg ;;              FS90=$ac_optarg ;;
1481            
1482            -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4 )
1483                USE_R4=true ;;
1484    
1485          -ieee | --ieee)          -ieee | --ieee)
1486              IEEE=true ;;              IEEE=true ;;
1487          -noieee | --noieee)          -noieee | --noieee)
1488              IEEE= ;;              echo "Warning: ignore option '$ac_option' (default is already without '-ieee')" ;;
1489            -devel | --devel)
1490                IEEE=true ; DEVEL=true ;;
1491            -gsl | --gsl)
1492                GSL=true ;;
1493    
1494            -ts | --ts)
1495                TS=true ;;
1496            -papis | --papis)
1497                PAPIS=true ;;
1498            -pcls | --pcls)
1499                PCLS=true ;;
1500            -foolad | --foolad)
1501                FOOLAD=true ;;
1502            -papi | --papi)
1503                PAPI=true ;;
1504            -pcl | --pcl)
1505                PCL=true ;;
1506            -hpmt | --hpmt)
1507                HPMT=true ;;
1508    
1509          -mpi | --mpi)          -mpi | --mpi)
1510              MPI=true ;;              MPI=true ;;
1511          -mpi=* | --mpi=*)          -mpi=* | --mpi=*)
1512              MPIPATH=$ac_optarg              MPIPATH=$ac_optarg
1513              MPI=true ;;              MPI=true ;;
1514            
1515  #       -jam | --jam)          -omp | --omp)
1516  #           JAM=1 ;;              OMP=true ;;
1517  #       -nojam | --nojam)          -omp=* | --omp=*)
1518  #           JAM=0 ;;              OMPFLAG=$ac_optarg
1519                        OMP=true ;;
1520    
1521          -ds | --ds)          -ds | --ds)
1522              DUMPSTATE=t ;;              DUMPSTATE=t ;;
1523            
1524            -extra_flag | --extra_flag)
1525                ac_prev=FEXTRAFLAGS ;;
1526            -extra_flag=* | --extra_flag=*)
1527                FEXTRAFLAGS=$ac_optarg ;;
1528    
1529          -taf_extra | --taf_extra)          -taf_extra | --taf_extra)
1530              ac_prev=TAF_EXTRA ;;              ac_prev=TAF_EXTRA ;;
1531          -taf_extra=* | --taf_extra=*)          -taf_extra=* | --taf_extra=*)
# Line 1013  for ac_option in $@ ; do Line 1536  for ac_option in $@ ; do
1536          -tamc_extra=* | --tamc_extra=*)          -tamc_extra=* | --tamc_extra=*)
1537              TAMC_EXTRA=$ac_optarg ;;              TAMC_EXTRA=$ac_optarg ;;
1538    
1539            -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1540                IGNORE_TIME="-DIGNORE_TIME" ;;
1541    
1542            -es | --es | -embed-source | --embed-source)
1543                EMBED_SRC=t ;;
1544    
1545          -*)          -*)
1546              echo "Error: unrecognized option: "$ac_option              echo "Error: unrecognized option: "$ac_option
1547              usage              usage
1548              ;;              ;;
1549            
1550          *)          *)
1551              echo "Error: unrecognized argument: "$ac_option              echo "Error: unrecognized argument: "$ac_option
1552              usage              usage
1553              ;;              ;;
1554            
1555      esac      esac
1556        
1557  done  done
1558    
1559    printf "  getting local config information:  "
1560    if test -f $gm_local ; then
1561        echo "using $gm_local"
1562        . $gm_local
1563    else
1564        echo "none found"
1565    fi
1566    
1567  if test -f ./.genmakerc ; then  if test -f ./.genmakerc ; then
1568      echo      echo
1569      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""      echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
1570      echo "  file.  This file format is no longer supported.  Please see:"      echo "  file.  This file format is no longer supported.  For directions on"
1571      echo      echo "  how to setup and use the new \"genmake2\" script, please see:"
1572      echo "    http://mitgcm.org/devel_HOWTO/"      echo "    http://mitgcm.org/public/devel_HOWTO/"
1573        echo "  and send an email to MITgcm-support@mitgcm.org if you need help."
1574        echo "WARNING: ignore \"./.genmakerc\" and continue."
1575      echo      echo
     echo "  for directions on how to setup and use the new \"genmake2\" input"  
     echo "  files and send an email to MITgcm-support@mitgcm.org if you want help."  
     echo  
1576  fi  fi
1577    
1578    #  Find the MITgcm ${ROOTDIR}
1579  if test "x${ROOTDIR}" = x ; then  if test "x${ROOTDIR}" = x ; then
1580      tmp=`echo $PWD | sed -e 's/\// /g' | awk '{print $NR}'`      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1581      if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then      if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesupp -a -d ../pkg ; then
1582          ROOTDIR=".."          ROOTDIR=".."
1583      else      else
1584          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do          for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1585              if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then              if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
1586                  ROOTDIR=$d                  ROOTDIR=$d
1587                  printf "Warning:  ROOTDIR was not specified but there appears to be"                  printf "Warning: ROOTDIR was not specified ;"
1588                  echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."                  echo " try using a local copy of MITgcm found at \"$ROOTDIR\""
1589                  break                  break
1590              fi              fi
1591          done          done
# Line 1065  if test ! -d ${ROOTDIR} ; then Line 1602  if test ! -d ${ROOTDIR} ; then
1602      exit 1      exit 1
1603  fi  fi
1604    
1605  echo "  getting OPTFILE information:  "  #  Find the MITgcm ${THISVER}
1606    version_file="${ROOTDIR}/doc/tag-index"
1607    if test -f $version_file ; then
1608        THISVER=`$AWK '/^checkpoint/{print $1; exit}' $version_file`
1609    #-  remove ./BUILD_INFO.h file if older than version_file
1610        if test -f ./BUILD_INFO.h -a ./BUILD_INFO.h -ot $version_file ; then
1611            echo "  remove ./BUILD_INFO.h (older than ${version_file})"
1612            rm -f ./BUILD_INFO.h
1613        fi
1614    fi
1615    
1616    if test "x$MAKEFILE" = x ; then
1617        MAKEFILE="Makefile"
1618    fi
1619    
1620    echo "  getting OPTFILE information:"
1621  if test "x${OPTFILE}" = x ; then  if test "x${OPTFILE}" = x ; then
1622      if test "x$MITGCM_OF" = x ; then      if test "x$MITGCM_OF" = x ; then
1623          echo "Warning: no OPTFILE specified so we'll look for possible settings"          echo "Warning: no OPTFILE specified so we'll look for possible settings"
1624          printf "\n===  Searching for possible settings for OPTFILE  ===\n"          printf "\n===  Searching for possible settings for OPTFILE  ===\n"
1625          find_possible_configs          find_possible_optfile
1626      else      else
1627          OPTFILE=$MITGCM_OF          OPTFILE=$MITGCM_OF
1628      fi      fi
# Line 1085  if test "x$OPTFILE" != xNONE ; then Line 1637  if test "x$OPTFILE" != xNONE ; then
1637              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1638              exit 1              exit 1
1639          fi          fi
1640          if test "x$DUMPSTATE" != xf ; then          if test "x$DUMPSTATE" = xt ; then
1641              cp -f $OPTFILE "genmake_optfile"              cp -f $OPTFILE "genmake_optfile"
1642          fi          fi
1643      else      else
# Line 1094  if test "x$OPTFILE" != xNONE ; then Line 1646  if test "x$OPTFILE" != xNONE ; then
1646      fi      fi
1647  fi  fi
1648    
1649  #  Check for broken systems that cannot correctly distinguish *.F and *.f files  echo "  getting AD_OPTFILE information:"
 # check_for_broken_Ff  
   
 echo "  getting AD_OPTFILE information:  "  
1650  if test "x${AD_OPTFILE}" = x ; then  if test "x${AD_OPTFILE}" = x ; then
1651      if test "x$MITGCM_AD_OF" = x ; then      if test "x$MITGCM_AD_OF" = x ; then
1652          AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default          AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
# Line 1115  if test "x${AD_OPTFILE}" != xNONE ; then Line 1664  if test "x${AD_OPTFILE}" != xNONE ; then
1664              echo "--please check that variable syntax is bash-compatible"              echo "--please check that variable syntax is bash-compatible"
1665              exit 1              exit 1
1666          fi          fi
1667          if test "x$DUMPSTATE" != xf ; then          if test "x$DUMPSTATE" = xt ; then
1668              cp -f $AD_OPTFILE "genmake_ad_optfile"              cp -f $AD_OPTFILE "genmake_ad_optfile"
1669          fi          fi
1670      else      else
# Line 1124  if test "x${AD_OPTFILE}" != xNONE ; then Line 1673  if test "x${AD_OPTFILE}" != xNONE ; then
1673      fi      fi
1674  fi  fi
1675    
1676    #====================================================================
1677    #  Set default values if not set by the optfile
1678    #
1679  #  Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined.  If not,  #  Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
1680  #  either set defaults or complain and abort!  #  either set defaults or complain and abort!
1681  if test ! "x$BASH" = x ; then  if test ! "x$BASH" = x ; then
# Line 1140  Error: no Fortran compiler: please speci Line 1692  Error: no Fortran compiler: please speci
1692  EOF  EOF
1693      exit 1      exit 1
1694  fi  fi
1695    if test "x$GET_FC_VERSION" != x ; then
1696      echo "Get compiler version using: $FC $GET_FC_VERSION" >> $LOGFILE
1697      ff=`echo $FC | sed 's/ .*//'` ; xx=`echo $ff | sed 's/^./& /' | sed 's/ .*//'`
1698      if test $xx != '/' ; then which $ff >> $LOGFILE ; fi
1699      $FC $GET_FC_VERSION > genmake_fc_vers1 2> genmake_fc_vers2
1700      if test -s genmake_fc_vers1 ; then
1701        cat genmake_fc_vers1 >> $LOGFILE
1702      else
1703        cat genmake_fc_vers2 >> $LOGFILE
1704      fi
1705      echo "<-- compiler version ----" >> $LOGFILE
1706      rm -f genmake_fc_vers1 genmake_fc_vers2
1707    fi
1708    
1709  if test "x$CC" = x ; then  if test "x$CC" = x ; then
1710      CC=cc      look_for_C_compilers
 #     cat <<EOF 1>&2  
 # Error: no C compiler: please specify using one of the following:  
 #   1) within the options file ("CC=...") as specified by "-of=OPTFILE"  
 #   2) the "-cc=XXX" command-line option  
 #   3) the "./genmake_local" file  
 # EOF  
 #     exit 1  
1711  fi  fi
1712    
1713  if test "x$LINK" = x ; then  if test "x$LINK" = x ; then
1714      LINK=$FC      LINK=$FC
1715  fi  fi
# Line 1157  if test "x$MAKE" = x ; then Line 1717  if test "x$MAKE" = x ; then
1717      MAKE="make"      MAKE="make"
1718  fi  fi
1719  if test "x$CPP" = x ; then  if test "x$CPP" = x ; then
1720      CPP=cpp      CPP="cpp -traditional -P"
1721  fi  fi
1722  #EH3 === UGLY ===  #EH3 === UGLY ===
1723  #  The following is an ugly little hack to check for $CPP in /lib/ and  #  The following is an ugly little hack to check for $CPP in /lib/ and
# Line 1184  EOF Line 1744  EOF
1744  else  else
1745      rm -f test_cpp      rm -f test_cpp
1746  fi  fi
1747    
1748  look_for_makedepend  look_for_makedepend
1749    
1750    #  Check that soft-link command is set and usable
1751  if test "x$LN" = x ; then  if test "x$LN" = x ; then
1752      LN="ln -s"      LN="ln -s"
1753  fi  fi
# Line 1194  RETVAL=$? Line 1757  RETVAL=$?
1757  if test "x$RETVAL" != x0 ; then  if test "x$RETVAL" != x0 ; then
1758      cat <<EOF 1>&2      cat <<EOF 1>&2
1759    
1760  Error: The command "ln -s" failed -- please specify a working soft-link  Error: The command "$LN" failed -- please specify a working soft-link
1761    command in the optfile.    command in the optfile.
1762    
1763  EOF  EOF
1764      exit 1      exit 1
1765  fi  fi
1766    test -L genmake_tlink > /dev/null 2>&1
1767    RETVAL=$?
1768    if test "x$RETVAL" = x0 ; then
1769        HAVE_TEST_L=t
1770    fi
1771  rm -f genmake_test_ln genmake_tlink  rm -f genmake_test_ln genmake_tlink
1772    
1773  #  Check for broken *.F/*.f handling and fix if possible  #  Check for broken *.F/*.f handling and fix if possible
# Line 1207  check_for_broken_Ff Line 1775  check_for_broken_Ff
1775    
1776  if test ! "x$MPI" = x ; then  if test ! "x$MPI" = x ; then
1777        echo "  Turning on MPI cpp macros"        echo "  Turning on MPI cpp macros"
1778        DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"        DEFINES="$DEFINES -DALLOW_USE_MPI"
1779    #- To compile code older than checkpoint63s (2012/09/05), un-comment the following line:
1780    #     DEFINES="$DEFINES -DALWAYS_USE_MPI"
1781    fi
1782    if test ! "x$OMP" = x ; then
1783          echo "  Add OMPFLAG and turn on OpenMP cpp macros"
1784          FFLAGS="$FFLAGS $OMPFLAG"
1785          F90FLAGS="$F90FLAGS $OMPFLAG"
1786          DEFINES="$DEFINES -DUSE_OMP_THREADING"
1787    fi
1788    
1789    if test ! "x$USE_R4" = x ; then
1790          echo "  Turning on LET_RS_BE_REAL4 cpp flag"
1791          DEFINES="$DEFINES -DLET_RS_BE_REAL4"
1792    fi
1793    
1794    if test ! "x$TS" = x ; then
1795          echo "  Turning on timing per timestep"
1796          if test ! "x$FOOLAD" = x ; then
1797                DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP"
1798          else
1799                DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1800          fi
1801          PACKAGES="$PACKAGES showflops"
1802    fi
1803    if test ! "x$PAPIS" = x ; then
1804          echo "  Turning on PAPI flop summary per timestep"
1805          echo "  Please make sure PAPIINC, PAPILIB are defined"
1806          if test ! "x$FOOLAD" = x ; then
1807                DEFINES="$DEFINES -DUSE_PAPI_FLOPS_SFP"
1808          else
1809                DEFINES="$DEFINES -DUSE_PAPI_FLOPS"
1810          fi
1811          INCLUDES="$INCLUDES $PAPIINC"
1812          LIBS="$LIBS $PAPILIB"
1813          PACKAGES="$PACKAGES showflops"
1814    fi
1815    if test ! "x$PCLS" = x ; then
1816          echo "  Turning on PCL counter summary per timestep"
1817          echo "  Please make sure PCLINC, PCLLIB are defined"
1818          if test ! "x$FOOLAD" = x ; then
1819                DEFINES="$DEFINES -DUSE_PCL_FLOPS_SFP"
1820          else
1821                DEFINES="$DEFINES -DUSE_PCL_FLOPS"
1822          fi
1823          INCLUDES="$INCLUDES $PCLINC"
1824          LIBS="$LIBS $PCLLIB"
1825          PACKAGES="$PACKAGES showflops"
1826    fi
1827    if test ! "x$PAPI" = x ; then
1828          if test ! "x$PAPIS" = x ; then
1829              echo "  PAPI performance analysis and flop summary per timestep cannot co-exist!"
1830              echo "  Sticking with PAPI flop summary per timestep!"
1831          else
1832              echo "  Turning on performance analysis with PAPI"
1833              echo "  Please make sure PAPIINC, PAPILIB are defined"
1834              DEFINES="$DEFINES -DUSE_PAPI"
1835              INCLUDES="$INCLUDES $PAPIINC"
1836              LIBS="$LIBS $PAPILIB"
1837          fi
1838    fi
1839    if test ! "x$PCL" = x ; then
1840          if test ! "x$PCLS" = x ; then
1841              echo "  PCL performance analysis and flop summary per timestep cannot co-exist!"
1842              echo "  Sticking with PCL flop summary per timestep!"
1843          else
1844              echo "  Turning on performance analysis with PCL"
1845              echo "  Please make sure PCLINC, PCLLIB are defined"
1846              DEFINES="$DEFINES -DUSE_PCL"
1847              INCLUDES="$INCLUDES $PCLINC"
1848              LIBS="$LIBS $PCLLIB"
1849          fi
1850    fi
1851    if test ! "x$HPMT" = x ; then
1852          if test ! "x$PAPI" = x ; then
1853              echo "  PAPI and the HPM Toolkit cannot co-exist!"
1854              echo "  Sticking with PAPI!"
1855          else
1856            if test ! "x$PCL" = x ; then
1857              echo "  PCL and the HPM Toolkit cannot co-exist!"
1858              echo "  Sticking with PCL!"
1859            else
1860              echo "  Turning on performance analysis with the HPM Toolkit"
1861              echo "  Please make sure HPMTINC, HPMTLIB are defined"
1862              DEFINES="$DEFINES -DUSE_LIBHPM"
1863              INCLUDES="$INCLUDES $HPMTINC"
1864              LIBS="$LIBS $HPMTLIB"
1865            fi
1866          fi
1867    fi
1868    if test ! "x$GSL" = x ; then
1869          echo "  Turning on use of GSL to control floating point calculations"
1870          echo "  Please make sure GSLINC, GSLLIB are defined"
1871          DEFINES="$DEFINES -DUSE_GSL_IEEE"
1872          INCLUDES="$INCLUDES $GSLINC"
1873          LIBS="$LIBS $GSLLIB"
1874    fi
1875    #- if USE_EXTENDED_SRC is set, add EXTENDED_SRC_FLAG to FFLAGS :
1876    if test ! "x$USE_EXTENDED_SRC" = x ; then
1877          FFLAGS="$FFLAGS $EXTENDED_SRC_FLAG"
1878          F90FIXEDFORMAT="$F90FIXEDFORMAT $EXTENDED_SRC_FLAG"
1879  fi  fi
1880    
1881  printf "\n===  Checking system libraries  ===\n"  printf "\n===  Checking system libraries  ===\n"
1882  printf "  Do we have the system() command using $FC...  "  printf "  Do we have the system() command using $FC...  "
1883  cat > genmake_tcomp.f <<EOF  cat > genmake_tcomp.$FS <<EOF
1884        program hello        program hello
1885        call system('echo hi')        call system('echo hi')
1886        end        end
1887  EOF  EOF
1888  $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1  $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1889  RETVAL=$?  RETVAL=$?
1890  if test "x$RETVAL" = x0 ; then  if test "x$RETVAL" = x0 ; then
1891      HAVE_SYSTEM=t      HAVE_SYSTEM=t
# Line 1230  fi Line 1898  fi
1898  rm -f genmake_tcomp*  rm -f genmake_tcomp*
1899    
1900  printf "  Do we have the fdate() command using $FC...  "  printf "  Do we have the fdate() command using $FC...  "
1901  cat > genmake_tcomp.f <<EOF  cat > genmake_tcomp.$FS <<EOF
1902        program hello        program hello
1903        CHARACTER(128) string        CHARACTER*(128) string
1904        string = ' '        string = ' '
1905        call fdate( string )        call fdate( string )
1906        print *, string        print *, string
1907        end        end
1908  EOF  EOF
1909  $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1  $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1910  RETVAL=$?  RETVAL=$?
1911  if test "x$RETVAL" = x0 ; then  if test "x$RETVAL" = x0 ; then
1912      HAVE_FDATE=t      HAVE_FDATE=t
# Line 1251  fi Line 1919  fi
1919  rm -f genmake_tcomp*  rm -f genmake_tcomp*
1920    
1921  printf "  Do we have the etime() command using $FC...  "  printf "  Do we have the etime() command using $FC...  "
1922  cat > genmake_tcomp.f <<EOF  cat > genmake_tcomp.$FS <<EOF
1923        program hello        program hello
1924        REAL*4 ACTUAL, TARRAY(2)        REAL*4 ACTUAL, TARRAY(2)
1925        EXTERNAL ETIME        EXTERNAL ETIME
# Line 1260  cat > genmake_tcomp.f <<EOF Line 1928  cat > genmake_tcomp.f <<EOF
1928        print *, tarray        print *, tarray
1929        end        end
1930  EOF  EOF
1931  $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1  $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1932  RETVAL=$?  RETVAL=$?
1933  if test "x$RETVAL" = x0 ; then  if test "x$RETVAL" = x0 ; then
1934      HAVE_ETIME=t      HAVE_ETIME=t
# Line 1275  rm -f genmake_tcomp* Line 1943  rm -f genmake_tcomp*
1943  printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "  printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
1944  check_HAVE_CLOC  check_HAVE_CLOC
1945  if test "x$HAVE_CLOC" != x ; then  if test "x$HAVE_CLOC" != x ; then
1946        DEFINES="$DEFINES -DHAVE_CLOC"
1947        echo "yes"
1948    else
1949        echo "no"
1950        if test "x$EMBED_SRC" = xt ; then
1951            echo "    WARNING: you requested file embedding but it has"
1952            echo "      been disabled since C code cannot be called"
1953            EMBED_SRC=
1954        fi
1955    fi
1956    rm -f genmake_t*
1957    
1958    printf "  Can we unlimit the stack size using $FC...  "
1959    check_HAVE_SETRLSTK
1960    if test "x$HAVE_SETRLSTK" = xt ; then
1961        DEFINES="$DEFINES -DHAVE_SETRLSTK"
1962        echo "yes"
1963    else
1964        echo "no"
1965    fi
1966    rm -f genmake_t*
1967    
1968    printf "  Can we register a signal handler using $FC...  "
1969    check_HAVE_SIGREG
1970    if test "x$HAVE_SIGREG" = xt ; then
1971        DEFINES="$DEFINES -DHAVE_SIGREG"
1972        echo "yes"
1973    else
1974        echo "no"
1975    fi
1976    rm -f genmake_t*
1977    
1978    printf "  Can we use stat() through C calls...  "
1979    check_HAVE_STAT
1980    if test "x$HAVE_STAT" != x ; then
1981        DEFINES="$DEFINES -DHAVE_STAT"
1982      echo "yes"      echo "yes"
1983  else  else
1984      echo "no"      echo "no"
# Line 1284  rm -f genmake_t* Line 1988  rm -f genmake_t*
1988  printf "  Can we create NetCDF-enabled binaries...  "  printf "  Can we create NetCDF-enabled binaries...  "
1989  check_netcdf_libs  check_netcdf_libs
1990  if test "x$HAVE_NETCDF" != x ; then  if test "x$HAVE_NETCDF" != x ; then
1991        DEFINES="$DEFINES -DHAVE_NETCDF"
1992        echo "yes"
1993    else
1994        echo "no"
1995    fi
1996    
1997    printf "  Can we create LAPACK-enabled binaries...  "
1998    check_lapack_libs
1999    if test "x$HAVE_LAPACK" != x ; then
2000        DEFINES="$DEFINES -DHAVE_LAPACK"
2001      echo "yes"      echo "yes"
2002  else  else
2003      echo "no"      echo "no"
2004  fi  fi
2005    
2006    printf "  Can we call FLUSH intrinsic subroutine...  "
2007    check_HAVE_FLUSH
2008    if test "x$HAVE_FLUSH" = xt ; then
2009        DEFINES="$DEFINES -DHAVE_FLUSH"
2010        echo "yes"
2011    else
2012        echo "no"
2013    fi
2014    
2015    DEFINES="$DEFINES $IGNORE_TIME"
2016    if test "x$EMBED_SRC" = xt ; then
2017        build_embed_encode
2018    fi
2019    if test "x$EMBED_SRC" = xt ; then
2020        ENABLE="$ENABLE embed_files"
2021    #   DEFINES="$DEFINES -DHAVE_EMBED_SRC"
2022    fi
2023    
2024  printf "\n===  Setting defaults  ===\n"  printf "\n===  Setting defaults  ===\n"
2025  printf "  Adding MODS directories:  "  printf "  Adding MODS directories: "
2026  for d in $MODS ; do  for d in $MODS ; do
2027      if test ! -d $d ; then      if test ! -d $d ; then
2028          echo          echo
2029          echo "Error: MODS directory \"$d\" not found!"          echo "Error: MODS directory \"$d\" not found!"
2030          exit 1          exit 1
2031      else      else
2032          printf " $d"          printf "$d "
2033          SOURCEDIRS="$SOURCEDIRS $d"          SOURCEDIRS="$SOURCEDIRS $d"
2034          INCLUDEDIRS="$INCLUDEDIRS $d"          INCLUDEDIRS="$INCLUDEDIRS $d"
2035      fi      fi
2036  done  done
2037  echo  echo
2038    
2039  if test "x$MAKEFILE" = x ; then  #if test "x${PLATFORM}" = x ; then
2040      MAKEFILE="Makefile"  #    PLATFORM=$p_PLATFORM
2041  fi  #fi
 if test "x${PLATFORM}" = x ; then  
     PLATFORM=$p_PLATFORM  
 fi  
2042    
2043  if test "x${EXEDIR}" = x ; then  if test "x${EXEDIR}" = x ; then
2044      tmp=`echo $PWD | sed -e 's/\// /g' | awk '{print $NR}'`      tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
2045      if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then      if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
2046          EXEDIR=../exe          EXEDIR=../exe
2047      else      else
# Line 1333  if test ! -d ${TOOLSDIR} ; then Line 2061  if test ! -d ${TOOLSDIR} ; then
2061      exit 1      exit 1
2062  fi  fi
2063  if test "x$S64" = x ; then  if test "x$S64" = x ; then
2064      S64='$(TOOLSDIR)/set64bitConst.sh'      echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1
2065        RETVAL=$?
2066        if test "x${RETVAL}" = x0 ; then
2067            S64='$(TOOLSDIR)/set64bitConst.sh'
2068        else
2069            echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1
2070            RETVAL=$?
2071            if test "x${RETVAL}" = x0 ; then
2072                S64='$(TOOLSDIR)/set64bitConst.csh'
2073            else
2074                cat <<EOF
2075    
2076    ERROR: neither of the two default scripts:
2077    
2078        ${TOOLSDIR}/set64bitConst.sh
2079        ${TOOLSDIR}/set64bitConst.csh
2080    
2081      are working so please check paths or specify (with \$S64) a
2082      working version of this script.
2083    
2084    EOF
2085                exit 1
2086            fi
2087        fi
2088  fi  fi
2089  THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`  THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
2090    
2091  EXECUTABLE=${EXECUTABLE:-mitgcmuv}  EXECUTABLE=${EXECUTABLE:-mitgcmuv}
2092    
2093    #  Set Standard Code Directories:
2094    if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
2095        STANDARDDIRS="eesupp model"
2096    fi
2097    #  if model in Standard-Code-Dir, add eesupp (needed to compile model)
2098    echo " $STANDARDDIRS " | grep ' model ' > /dev/null 2>&1
2099    ckM=$?
2100    echo " $STANDARDDIRS " | grep ' eesupp ' > /dev/null 2>&1
2101    ckE=$?
2102    if test $ckM = 0 -a $ckE = 1 ; then
2103        STANDARDDIRS="$STANDARDDIRS eesupp"
2104    fi
2105    
2106  #  We have a special set of source files in eesupp/src which are  #  We have a special set of source files in eesupp/src which are
2107  #  generated from some template source files. We'll make them first so  #  generated from some template source files. We'll make them first so
2108  #  they appear as regular source code  #  they appear as regular source code
2109  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then  if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
2110      echo "  Making source files in eesupp from templates"      echo "  Making source files in eesupp from templates"
2111      ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1      ( cd $ROOTDIR"/eesupp/src/" && $MAKE clean_old && $MAKE \
2112        ) > make_eesupp.errors 2>&1
2113      RETVAL=$?      RETVAL=$?
2114      if test "x${RETVAL}" = x0 ; then      if test "x${RETVAL}" = x0 ; then
2115          rm -f make_eesupp.errors          rm -f make_eesupp.errors
# Line 1355  if test -r $ROOTDIR"/eesupp/src/Makefile Line 2120  if test -r $ROOTDIR"/eesupp/src/Makefile
2120      fi      fi
2121  fi  fi
2122    
2123  #same for exch2  #same for pkg/exch2 and pkg/regrid
2124  if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then  for pdir in exch2 regrid ; do
2125      echo "  Making source files in exch2 from  templates"      if test -r $ROOTDIR"/pkg/${pdir}/Makefile" ; then
2126      ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1          echo "  Making source files in pkg/${pdir} from templates"
2127      RETVAL=$?          ( cd $ROOTDIR"/pkg/"${pdir} && $MAKE clean_old && $MAKE \
2128      if test "x${RETVAL}" = x0 ; then          ) > make_${pdir}.errors 2>&1
2129          rm -f make_exch2.errors          RETVAL=$?
2130      else          if test "x${RETVAL}" = x0 ; then
2131          echo "Error: problem encountered while building source files in exch2:"              rm -f make_${pdir}.errors
2132          cat make_exch2.errors 1>&2          else
2133          exit 1              echo "Error: problem encountered while building source files in pkg/${pdir}:"
2134                cat make_${pdir}.errors 1>&2
2135                exit 1
2136            fi
2137      fi      fi
2138  fi  done
2139    
2140  printf "\n===  Determining package settings  ===\n"  printf "\n===  Determining package settings  ===\n"
2141  if  test "x${PDEPEND}" = x ; then  if  test "x${PKG_DEPEND}" = x ; then
2142      tmp=$ROOTDIR"/pkg/pkg_depend"      tmp=$ROOTDIR"/pkg/pkg_depend"
2143      if test -r $tmp ; then      if test -r $tmp ; then PKG_DEPEND=$tmp ; fi
2144          PDEPEND=$tmp  fi
2145      else  if  test "x${PKG_DEPEND}" = x ; then
2146          echo "Warning:  No package dependency information was specified."          echo "Warning:  No package dependency information was specified."
2147          echo "  Please check that ROOTDIR/pkg/pkg_depend exists."          echo "  Please check that ROOTDIR/pkg/pkg_depend exists."
     fi  
2148  else  else
2149      if test ! -r ${PDEPEND} ; then      if test ! -r ${PKG_DEPEND} ; then
2150          echo "Error:  can't read package dependency info from PDEPEND=\"$PDEPEND\""          echo "Error:  can't read package dependency info from PKG_DEPEND=\"$PKG_DEPEND\""
2151          exit 1          exit 1
2152      fi      fi
2153        echo "  getting package dependency info from  $PKG_DEPEND"
2154    #  Strip the comments and then convert the dependency file into arrays: PNAME, DNAME
2155        get_pdepend_list $PKG_DEPEND
2156  fi  fi
2157  echo "  getting package dependency info from  $PDEPEND"  
2158  #  Strip the comments and then convert the dependency file into  # A default package groups file "$ROOTDIR/pkg/pkg_groups" is provided
2159  #  two arrays: PNAME, DNAME  #  to define the "default_pkg_list" and package groups (for convenience, one
2160  cat $PDEPEND | sed -e 's/#.*$//g' \  #  can specify a group of packages using names like "ocean" and "atmosphere").
2161      | $AWK 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \  if test "x${PKG_GROUPS}" = x ; then
2162      > ./.pd_tmp      tmp=$ROOTDIR"/pkg/pkg_groups"
2163  RETVAL=$?      if test -r $tmp ; then PKG_GROUPS=$tmp ; fi
2164  if test ! "x${RETVAL}" = x0 ; then  fi
2165      echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""  if test "x${PKG_GROUPS}" = x ; then
2166      exit 1          echo "Warning:  No package groups information was specified."
2167            echo "  Please check that ROOTDIR/pkg/pkg_groups exists."
2168    else
2169        if test ! -r ${PKG_GROUPS} ; then
2170            echo "Error:  can't read package groups info from PKG_GROUPS=\"$PKG_GROUPS\""
2171            exit 1
2172        fi
2173        echo "  getting package groups info from      $PKG_GROUPS"
2174  fi  fi
 . ./.pd_tmp  
 rm -f ./.pd_tmp  
2175    
2176  #  Search for default packages.  Note that a "$ROOTDIR/pkg/pkg_groups"  #  Search for packages to compile.
2177  #  file should eventually be added so that, for convenience, one can  echo "  checking list of packages to compile:"
2178  #  specify groups of packages using names like "ocean" and "atmosphere".  PKG_LIST=
2179  echo "  checking default package list:  "  if test "x${PKG_LIST}" = x ; then
 if test "x${PDEFAULT}" = x ; then  
2180      for i in "." $MODS ; do      for i in "." $MODS ; do
2181          if test -r $i"/packages.conf" ; then          if test -r $i"/packages.conf" ; then
2182                  PDEFAULT=$i"/packages.conf"                  PKG_LIST=$i"/packages.conf"
2183                  break                  break
2184          fi          fi
2185      done      done
2186  fi  fi
2187  if test "x${PDEFAULT}" = x ; then  if test "x${PKG_LIST}" = x ; then
2188      PDEFAULT="$ROOTDIR/pkg/pkg_default"      pkg_list='default_pkg_list'
2189  fi      if test "x${PKG_GROUPS}" = x ; then
2190  if test "x${PDEFAULT}" = xNONE ; then          echo "Error:  need package groups info to expand pkg_list=\"$pkg_list\""
2191      echo "    default packages file disabled"          exit 1
2192        fi
2193  else  else
2194      if test ! -r $PDEFAULT ; then      if test ! -r $PKG_LIST ; then
2195          echo "Warning:  can't read default packages from PDEFAULT=\"$PDEFAULT\""          echo "Error:  can't read package list from PKG_LIST=\"$PKG_LIST\""
2196            exit 1
2197      else      else
2198          echo "    using PDEFAULT=\"$PDEFAULT\""          echo "    using PKG_LIST=\"$PKG_LIST\""
2199          #  Strip the comments and add all the names          #  Strip the comments and add all the names
2200          def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`          pkg_list=`cat $PKG_LIST | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
2201          RETVAL=$?          RETVAL=$?
2202          if test "x${RETVAL}" != x0 ; then          if test "x${RETVAL}" != x0 ; then
2203              printf "Error: can't parse default package list "              printf "Error: can't parse package list "
2204              echo "-- please check PDEFAULT=\"$PDEFAULT\""              echo "-- please check PKG_LIST=\"$PKG_LIST\""
2205              exit 1              exit 1
2206          fi          fi
         for i in $def ; do  
             PACKAGES="$PACKAGES $i"  
         done  
         echo "    before group expansion packages are: $PACKAGES"  
         RET=1  
         while test $RET = 1 ; do expand_pkg_groups; RET=$?; done  
         echo "    after group expansion packages are:  $PACKAGES"  
2207      fi      fi
2208  fi  fi
2209    for i in $pkg_list ; do
2210        PACKAGES="$PACKAGES $i"
2211    done
2212    echo     "    before group expansion packages are:$PACKAGES"
2213    if test "x${PKG_GROUPS}" != x ; then
2214        RET=1
2215        while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
2216        echo "    after group expansion packages are: $PACKAGES"
2217    fi
2218    
2219  echo "  applying DISABLE settings"  echo "  applying DISABLE settings"
2220    echo "" > ./.tmp_pack
2221  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2222      echo $i >> ./.tmp_pack      echo $i >> ./.tmp_pack
2223  done  done
# Line 1466  PACKAGES="$PACKAGES $ENABLE" Line 2245  PACKAGES="$PACKAGES $ENABLE"
2245  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2246      j=`echo $i | sed 's/[-+]//'`      j=`echo $i | sed 's/[-+]//'`
2247      if test ! -d "$ROOTDIR/pkg/$j" ; then      if test ! -d "$ROOTDIR/pkg/$j" ; then
2248          echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""          echo "Error: dir '$ROOTDIR/pkg/$i' missing for package '$i'"
2249          exit 1          exit 1
2250      fi      fi
2251      echo $i >> ./.tmp_pack      echo $i >> ./.tmp_pack
2252  done  done
# Line 1476  for i in `grep -v "-" ./.tmp_pack | sort Line 2255  for i in `grep -v "-" ./.tmp_pack | sort
2255      PACKAGES="$PACKAGES $i"      PACKAGES="$PACKAGES $i"
2256  done  done
2257  rm -f ./.tmp_pack  rm -f ./.tmp_pack
2258  echo "    packages are:  $PACKAGES"  echo "    packages are: $PACKAGES"
2259    
2260    #  Check for package MNC: if NetCDF is available, then build the MNC
2261    #  template files ; otherwise, delete mnc from the list of packages.
2262    echo " $PACKAGES " | grep ' mnc ' > /dev/null 2>&1
2263    mnc_in=$?
2264    if test "x$HAVE_NETCDF" != xt ; then
2265        if test "x$mnc_in" = x0 ; then
2266            cat <<EOF
2267    *********************************************************************
2268    WARNING: the "mnc" package was enabled but tests failed to compile
2269      NetCDF applications.  Please check that:
2270    
2271      1) NetCDF is correctly installed for this compiler and
2272      2) the LIBS variable (within the "optfile") specifies the correct
2273           NetCDF library to link against.
2274    
2275      Due to this failure, the "mnc" package is now DISABLED.
2276    *********************************************************************
2277    EOF
2278            PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
2279            DISABLE="$DISABLE mnc"
2280        else
2281        #  this prevent to add mnc (due to pdepend rules) if not available
2282            DISABLE="$DISABLE mnc"
2283        fi
2284    else
2285        # we have NetCDF, we try to build MNC template files
2286        ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
2287        RETVAL=$?
2288        if test "x${RETVAL}" = x0 ; then
2289            rm -f make_mnc.errors
2290        else
2291            echo "Error: problem encountered while building source files in pkg/mnc:"
2292            cat make_mnc.errors 1>&2
2293            if test "x$mnc_in" = x0 ; then
2294                exit 1
2295            else
2296                DISABLE="$DISABLE mnc"
2297            fi
2298        fi
2299    fi
2300    
2301    #  Check for package PROFILES: if NetCDF is not available,
2302    #  then delete profiles from the list of available packages.
2303    if test "x$HAVE_NETCDF" != xt ; then
2304        echo " $PACKAGES " | grep ' profiles ' > /dev/null 2>&1
2305        RETVAL=$?
2306        if test "x$RETVAL" = x0 ; then
2307            cat <<EOF
2308    *********************************************************************
2309    WARNING: the "profiles" package was enabled but tests failed to
2310      compile NetCDF applications.  Please check that:
2311    
2312      1) NetCDF is correctly installed for this compiler and
2313      2) the LIBS variable (within the "optfile") specifies the correct
2314           NetCDF library to link against.
2315    
2316      Due to this failure, the "profiles" package is now DISABLED.
2317    *********************************************************************
2318    EOF
2319            PACKAGES=`echo $PACKAGES | sed -e 's/profiles//g'`
2320            DISABLE="$DISABLE profiles"
2321        else
2322        #  this prevent to add profiles (due to pdepend rules) if not available
2323            DISABLE="$DISABLE profiles"
2324        fi
2325    fi
2326    
2327    #  Check for package RADTRANS: if LAPACK is not available,
2328    #  then issue a warning that the direct radtrans solver is not available.
2329    if test "x$HAVE_LAPACK" != xt ; then
2330        echo " $PACKAGES " | grep ' radtrans ' > /dev/null 2>&1
2331        RETVAL=$?
2332        if test "x$RETVAL" = x0 ; then
2333            cat <<EOF
2334    *********************************************************************
2335    WARNING: the "radtrans" package was enabled but tests failed to
2336      compile LAPACK applications.  This means that the direct radtrans
2337      solver is not available and compilation will fail if it is enabled.
2338      If you want to use the direct solver, please check that:
2339    
2340  echo "  applying package dependency rules"    1) LAPACK is correctly installed for this compiler and
2341  ck=    2) the LIBS variable (within the "optfile") specifies the correct
2342  while test "x$ck" != xtt ; do       LAPACK library to link against.
2343    *********************************************************************
2344    EOF
2345        fi
2346    fi
2347    
2348    if  test "x${PKG_DEPEND}" != x ; then
2349      echo "  applying package dependency rules"
2350      ck=
2351      while test "x$ck" != xtt ; do
2352      i=0      i=0
2353      # rtot=${#PNAME[@]}      # rtot=${#PNAME[@]}
2354      rtot=$nname      rtot=$nname
2355      while test $i -lt $rtot ; do      while test $i -le $rtot ; do
2356    
2357          #  Is $pname in the current $PACKAGES list?          #  Is $pname in the current $PACKAGES list?
2358          #  pname=${PNAME[$i]}          #  pname=${PNAME[$i]}
# Line 1496  while test "x$ck" != xtt ; do Line 2364  while test "x$ck" != xtt ; do
2364                  pin="t"                  pin="t"
2365              fi              fi
2366          done          done
2367            #  or in the current $STANDARDDIRS list?
2368            for p in $STANDARDDIRS ; do
2369                if test "x$p" = "x$pname" ; then pin="t" ; fi
2370            done
2371    
2372          #  Is the DNAME entry a (+) or (-) rule ?          #  Is the DNAME entry a (+) or (-) rule ?
2373          tmp="dname=\"\$DNAME_$i\""          tmp="dname=\"\$DNAME_$i\""
# Line 1518  while test "x$ck" != xtt ; do Line 2390  while test "x$ck" != xtt ; do
2390    
2391          #  Do we need to add $dname according to the dependency rules?          #  Do we need to add $dname according to the dependency rules?
2392          if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then          if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then
2393                #echo "   " $pname ": need to add :" $dname
2394              in_dis="f"              in_dis="f"
2395              for dis in $DISABLE ; do              for dis in $DISABLE ; do
2396                  if test "x$dis" = "x$dname" ; then                  if test "x$dis" = "x$dname" ; then
# Line 1538  while test "x$ck" != xtt ; do Line 2411  while test "x$ck" != xtt ; do
2411          #  Do we need to get rid of $dname according to the dependency rules?          #  Do we need to get rid of $dname according to the dependency rules?
2412          if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then          if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then
2413              echo "Error: can't satisfy package dependencies:"              echo "Error: can't satisfy package dependencies:"
2414              echo "  \"$pname\" was requested but is disallowed by"              echo "  \"$pname\" was requested but is disallowed by"
2415              echo "  the dependency rules for \"$dname\""              echo "  the dependency rules for \"$dname\""
2416              exit 1              exit 1
2417          fi          fi
2418          i=`echo "$i + 1" | bc -l`          i=`echo "$i + 1" | bc -l`
2419          #i=$(( $i + 1 ))          #i=$(( $i + 1 ))
2420      done      done
2421      ck=$ck"t"      ck=$ck"t"
2422  done    done
2423  echo "    packages are:  $PACKAGES"    echo "    packages are: $PACKAGES"
2424    fi
2425  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2426      adr="$ROOTDIR/pkg/$i"      adr="$ROOTDIR/pkg/$i"
2427      if test -d $adr ; then      if test -d $adr ; then
# Line 1562  for i in $PACKAGES ; do Line 2436  for i in $PACKAGES ; do
2436      fi      fi
2437  done  done
2438    
 #  Build MNC templates and check for ability to build and use NetCDF  
 echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1  
 RETVAL=$?  
 if test "x$RETVAL" = x0 ; then  
     ( cd $ROOTDIR"/pkg/mnc" && $MAKE templates ) > make_mnc.errors 2>&1  
     RETVAL=$?  
     if test "x${RETVAL}" = x0 ; then  
         rm -f make_mnc.errors  
     else  
         echo "Error: problem encountered while building source files in pkg/mnc:"  
         cat make_mnc.errors 1>&2  
         exit 1  
     fi  
     if test "x$HAVE_NETCDF" != xt ; then  
         cat <<EOF  
   
 WARNING: the "mnc" package has been enabled but tests failed to  
   compile and/or execute NetCDF applications.  Please check that:  
   
   1) NetCDF is installed for your compiler and  
   2) the LIBS variable (within the 'optfile") specifies the correct  
        NetCDF library to link against.  
     
 EOF  
     fi  
 fi  
   
2439  # Create a list of #define and #undef to enable/disable packages  # Create a list of #define and #undef to enable/disable packages
2440  PACKAGES_DOT_H=PACKAGES_CONFIG.h  PACKAGES_DOT_H=PACKAGES_CONFIG.h
2441  #  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
2442  #  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
2443  #  file would eventually be split up so that all package-related #define  #  file would eventually be split up so that all package-related #define
2444  #  statements could be separated and handled only by genmake.  #  statements could be separated and handled only by genmake.
2445  names=`ls -1 "$ROOTDIR/pkg"`  names=`ls -1 "$ROOTDIR/pkg"`
# Line 1608  for n in $names ; do Line 2455  for n in $names ; do
2455              fi              fi
2456          done          done
2457          if test "x$has_pack" = xf ; then          if test "x$has_pack" = xf ; then
2458              undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`              undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2459              DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"              DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
2460          fi          fi
2461      fi      fi
2462  done  done
2463  ENABLED_PACKAGES=  ENABLED_PACKAGES=
2464  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2465      def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`      def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2466      ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"      ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
2467  #eh3 DEFINES="$DEFINES -D$def"  #eh3 DEFINES="$DEFINES -D$def"
2468    
2469  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!  #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
2470      case $i in      case $i in
2471          aim_v23)          aim_v23)
2472              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"              ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
2473              echo "Warning: ALLOW_AIM is set to enable aim_v23."              echo "Warning: ALLOW_AIM is set to enable aim_v23."
2474              ;;              ;;
2475      esac      esac
# Line 1630  for i in $PACKAGES ; do Line 2477  for i in $PACKAGES ; do
2477    
2478  done  done
2479    
2480  echo "  Adding STANDARDDIRS"  echo "  Adding STANDARDDIRS='$STANDARDDIRS'"
2481  BUILDDIR=${BUILDDIR:-.}  BUILDDIR=${BUILDDIR:-.}
 if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then  
     STANDARDDIRS="eesupp model"  
 fi  
2482  if test "x$STANDARDDIRS" != x ; then  if test "x$STANDARDDIRS" != x ; then
2483      for d in $STANDARDDIRS ; do      for d in $STANDARDDIRS ; do
2484          adr="$ROOTDIR/$d/src"          adr="$ROOTDIR/$d/src"
# Line 1667  for i in $spaths ; do Line 2511  for i in $spaths ; do
2511      if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then      if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
2512          echo "    found CPP_OPTIONS=\"$try\""          echo "    found CPP_OPTIONS=\"$try\""
2513          CPP_OPTIONS="$try"          CPP_OPTIONS="$try"
2514          # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h          # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
2515          for n in $names ; do          for n in $names ; do
2516              test_for_package_in_cpp_options $CPP_OPTIONS $n              test_for_package_in_cpp_options $CPP_OPTIONS $n
2517          done          done
2518      fi      fi
2519      try="$i/CPP_EEOPTIONS.h"      try="$i/CPP_EEOPTIONS.h"
2520      if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then      if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
2521          echo "    found CPP_EEOPTIONS=\"$try\""          echo "    found CPP_EEOPTIONS=\"$try\""
2522          # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h          # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
2523  #**** not yet enabled ****  #**** not yet enabled ****
2524  #        test_for_mpi_in_cpp_eeoptions $try  #        test_for_mpi_in_cpp_eeoptions $try
2525  #**** not yet enabled ****  #**** not yet enabled ****
# Line 1689  fi Line 2533  fi
2533    
2534  #  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
2535  #  compiler.  #  compiler.
2536  if test -f ./ad_files ; then  if test -f ./adSrcFiles.tmp ; then
2537      rm -f ./ad_files      rm -f ./adSrcFiles.tmp
2538  fi  fi
2539  echo "  Creating the list of files for the adjoint compiler."  echo "  Creating the list of files for the adjoint compiler."
2540    touch adSrcFiles.tmp
2541  for i in $SOURCEDIRS ; do  for i in $SOURCEDIRS ; do
2542      list_files=`( cd $i && ls -1 *.list 2>/dev/null )`      list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
2543      for j in $list_files ; do      for j in $list_files ; do
2544          cat $i/$j >> ad_files          cat $i/$j >> adSrcFiles.tmp
2545      done      done
2546  done  done
2547    if test ! "x"$FS = "x.f" ; then
2548        cat adSrcFiles.tmp | sed -e "s/\.f/.$FS/g" > adSrcFiles.tmp_f
2549        mv -f adSrcFiles.tmp_f adSrcFiles.tmp
2550    fi
2551    
2552  echo  echo
2553  echo "===  Creating the Makefile  ==="  echo "===  Creating the Makefile  ==="
# Line 1710  for i in $INCLUDEDIRS ; do Line 2558  for i in $INCLUDEDIRS ; do
2558      fi      fi
2559  done  done
2560    
2561    if test ! "x$DIVA" = x -a ! "x$MPI" = x ; then
2562      if test ! "x$MPIINCLUDEDIR" = x ; then
2563        if test -d $MPIINCLUDEDIR ; then
2564            echo "  Creating the pseudo-MPI include directory"
2565            INCLUDES="-I./mpi_headers $INCLUDES"
2566            rm -rf ./mpi_headers
2567            mkdir -p ./mpi_headers
2568            #  Do a local copy of MPI headers files (in local dir ./mpi_headers/) after
2569            #   checking for additional included headers (in case of chain of included
2570            #   header); also set LOCAL_MPI_HEADERS (if not already set)
2571            mpi_headers_do_local_copy
2572        else
2573            echo "WARNING: MPIINCLUDEDIR='$MPIINCLUDEDIR' is not a dir"
2574            echo "WARNING: ==> cannot create pseudo-MPI include directory"
2575    #       exit -1
2576        fi
2577      fi
2578    fi
2579    
2580  echo "  Determining the list of source and include files"  echo "  Determining the list of source and include files"
2581  rm -rf .links.tmp  rm -rf .links.tmp
2582  mkdir .links.tmp  mkdir .links.tmp
2583    touch .links.tmp/foo
2584    if test ! -r ".links.tmp/foo" ; then
2585        echo
2586        echo "ERROR : something is wrong with your directory permissions or"
2587        echo "   your user file-creation mask (\"umask\") since creating a"
2588        echo "   sub-dir, touch-ing a file within it, and then reading it is"
2589        echo "   not working.  Please try setting your umask to something"
2590        echo "   sane such as:"
2591        echo
2592        echo "      umask 0002"
2593        echo
2594        echo "   and please verify that you have the proper permissions for"
2595        echo "   creating sub-directories and then reading files created"
2596        echo "   within them."
2597        echo
2598        exit 1
2599    fi
2600    rm -f .links.tmp/foo
2601    
2602    if test "x$OPENAD" != x ; then
2603        OAD_DONT_COMPILE="/dev/null"
2604        OAD_DONT_TRANSFORM="/dev/null"
2605        OAD_KEEP_ORIGINAL="/dev/null"
2606        OAD_CB2M_FILES="/dev/null"
2607        OADTOOLS="$TOOLSDIR/OAD_support"
2608        echo "  looking for dontCompile file:  "
2609        for i in "." $MODS ; do
2610            if test -r $i"/dontCompile" ; then
2611                OAD_DONT_COMPILE=$i"/dontCompile"
2612                echo "     found $OAD_DONT_COMPILE"
2613                break
2614            fi
2615        done
2616        echo "  looking for dontTransform file:  "
2617        for i in "." $MODS ; do
2618            if test -r $i"/dontTransform" ; then
2619                OAD_DONT_TRANSFORM=$i"/dontTransform"
2620                echo "     found $OAD_DONT_TRANSFORM"
2621                break
2622            fi
2623        done
2624        echo "  looking for keepOriginal file:  "
2625        for i in "." $MODS ; do
2626            if test -r $i"/keepOriginal" ; then
2627                OAD_KEEP_ORIGINAL=$i"/keepOriginal"
2628                echo "     found $OAD_KEEP_ORIGINAL"
2629                break
2630            fi
2631        done
2632        echo "  looking for cb2mFiles:  "
2633        for i in "." $MODS ; do
2634            if test -r $i"/cb2mFiles" ; then
2635                OAD_CB2M_FILES=$i"/cb2mFiles"
2636                echo "     found $OAD_CB2M_FILES"
2637                break
2638            fi
2639        done
2640        echo "   OpenAD exceptions:  "
2641    fi
2642    
2643  echo "# This section creates symbolic links" > srclinks.tmp  echo "# This section creates symbolic links" > srclinks.tmp
2644  echo "" >> srclinks.tmp  echo "" >> srclinks.tmp
2645  printf 'SRCFILES = '    > srclist.inc  printf 'F77_SRC_FILES = ' > F77srclist.tmp
2646  printf 'CSRCFILES = '   > csrclist.inc  printf 'NON_AD_F77_SRC_FILES = ' > nonADF77srclist.tmp
2647  printf 'F90SRCFILES = ' > f90srclist.inc  printf 'C_SRC_FILES = '   > csrclist.tmp
2648  printf 'HEADERFILES = ' > hlist.inc  printf 'F90_SRC_FILES = ' > F90srclist.tmp
2649  printf 'AD_FLOW_FILES = ' > ad_flow_files.inc  printf 'H_SRC_FILES = '   > hsrclist.tmp
2650    printf 'AD_FLOW_FILES = ' > ad_flow_files.tmp
2651  alldirs="$SOURCEDIRS $INCLUDEDIRS ."  alldirs="$SOURCEDIRS $INCLUDEDIRS ."
2652  for d in $alldirs ; do  for d in $alldirs ; do
2653      deplist=      deplist=
2654      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
2655      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
2656        if test "x$OPENAD" != x ; then
2657            sfiles=`( echo $sfiles | grep -v _cb2m\. )`
2658        fi
2659      for sf in $sfiles ; do      for sf in $sfiles ; do
2660          if test ! -r ".links.tmp/$sf" ; then          if test ! -r ".links.tmp/$sf" ; then
2661              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
2662                  case $d/$sf in                  ignore_f=f
2663                    ./$PACKAGES_DOT_H)                  case $d/$sf in
2664                      ./$PACKAGES_DOT_H)
2665                            ignore_f=t
2666                          ;;                          ;;
2667                    ./AD_CONFIG.h)                    ./AD_CONFIG.h)
2668                            ignore_f=t
2669                          ;;                          ;;
2670                    ./FC_NAMEMANGLE.h)                    ./FC_NAMEMANGLE.h)
2671                            ignore_f=t
2672                          ;;                          ;;
2673                    *)                    ./BUILD_INFO.h)
2674                          touch .links.tmp/$sf                          ignore_f=t
                         deplist="$deplist $sf"  
2675                          ;;                          ;;
2676                  esac                    ./EMBEDDED_FILES.h)
2677                  extn=`echo $sf | $AWK -F '.' '{print $NF}'`                          ignore_f=t
2678                  case $extn in                          ;;
2679                      F)                    *)
2680                          echo    " \\"  >> srclist.inc                          #  For the local directory *ONLY*,
2681                          printf " $sf" >> srclist.inc                          #  ignore all soft-links
2682                            if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then
2683                                ignore_f=t
2684                            else
2685                                touch .links.tmp/$sf
2686                                deplist="$deplist $sf"
2687                            fi
2688                            ;;
2689                    esac
2690                    if test "x$ignore_f" = xf ; then
2691                        extn=`echo $sf | $AWK -F. '{print $NF}'`
2692                        case $extn in
2693                          F)
2694                            echo    " \\"  >> F77srclist.tmp
2695                            printf " $sf" >> F77srclist.tmp
2696                            if test "x$OPENAD" != x ; then
2697                                basename=${sf%%.F}
2698                                isAD=`egrep ^$basename.f'[  ]*' adSrcFiles.tmp`
2699                                if test -z "$isAD" ; then
2700                                    toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE}`
2701                                    if test -z "$toBeIgnored" ; then
2702                                        echo    " \\"  >> nonADF77srclist.tmp
2703                                        printf " $sf" >> nonADF77srclist.tmp
2704                                    else
2705                                        echo "    not to be compiled   :  $sf"
2706                                    fi
2707                                else # file is initially listed as an AD file we want to exclude it
2708                                     # or we want to retain the untransformed version
2709                                    notToBeTransformed=`egrep ^$basename'[      ]*' ${OAD_DONT_TRANSFORM}`
2710                                    untransformedVersionToBeKept=`egrep ^$basename'[      ]*' ${OAD_KEEP_ORIGINAL}`
2711                                    if test -n "$notToBeTransformed"; then
2712                                        echo "    not to be transformed:  $sf"
2713                                    fi
2714                                    if test -n "$untransformedVersionToBeKept" ; then
2715                                        echo "    original to be kept  :  $sf"
2716                                    fi
2717                                    if test -n "$notToBeTransformed" -o -n "$untransformedVersionToBeKept" ; then
2718                                        echo    " \\"  >> nonADF77srclist.tmp
2719                                        printf " $sf" >> nonADF77srclist.tmp
2720                                    fi
2721                                fi
2722                            fi
2723                          ;;                          ;;
2724                      F90)                      F90)
2725                          echo    " \\"  >> f90srclist.inc                          echo    " \\"  >> F90srclist.tmp
2726                          printf " $sf" >> f90srclist.inc                          printf " $sf" >> F90srclist.tmp
2727                          ;;                          ;;
2728                      c)                      c)
2729                          echo    " \\"  >> csrclist.inc                          echo    " \\"  >> csrclist.tmp
2730                          printf " $sf" >> csrclist.inc                          printf " $sf" >> csrclist.tmp
2731                          ;;                          ;;
2732                      h)                      h)
2733                          echo    " \\"  >> hlist.inc                          echo    " \\"  >> hsrclist.tmp
2734                          printf " $sf" >> hlist.inc                          printf " $sf" >> hsrclist.tmp
2735                          ;;                          ;;
2736                      flow)                      flow)
2737                          echo    " \\"  >> ad_flow_files.inc                          echo    " \\"  >> ad_flow_files.tmp
2738                          printf " $sf" >> ad_flow_files.inc                          printf " $sf" >> ad_flow_files.tmp
2739                          ;;                          ;;
2740                  esac                     esac
2741                    fi
2742              fi              fi
2743          fi          fi
2744      done      done
2745      if test "x$deplist" != x ; then      if test "x$deplist" != x ; then
2746          if test "$d" != "." ; then
2747          echo "" >> srclinks.tmp          echo "" >> srclinks.tmp
2748          echo "#  These files are linked from $d" >> srclinks.tmp          echo "#  These files are linked from $d" >> srclinks.tmp
2749          echo "$deplist :" >> srclinks.tmp          echo "$deplist :" >> srclinks.tmp
2750          printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp  # We need to make sure that the link isn't already there.
2751    # This may happen when make thinks that a header file has to be "remade"
2752    # because a module it depends on has changed.  In this case we do nothing.
2753            printf "\tif [ ! -L \$@ ]; then \$(LN) %s/\$@ \$@; fi\n" $d >> srclinks.tmp
2754          fi
2755      fi      fi
2756  done  done
2757  rm -rf .links.tmp  rm -rf .links.tmp
2758  echo "" >> srclist.inc  echo "" >> F77srclist.tmp
2759  echo "" >> csrclist.inc  echo "" >> nonADF77srclist.tmp
2760  echo "" >> f90srclist.inc  echo "" >> csrclist.tmp
2761  echo "" >> hlist.inc  echo "" >> F90srclist.tmp
2762  echo "" >> ad_flow_files.inc  echo "" >> hsrclist.tmp
2763    echo "" >> ad_flow_files.tmp
2764    
2765    CMDLINE=$0
2766    for xx in "$@" ; do nw=`echo $xx | wc -w`
2767        if test $nw = '1' ; then CMDLINE="$CMDLINE $xx"
2768                            else CMDLINE="$CMDLINE '$xx'" ; fi
2769    done
2770    
2771  if test -f $MAKEFILE ; then  if test -f $MAKEFILE ; then
2772      mv -f $MAKEFILE "$MAKEFILE.bak"      mv -f $MAKEFILE "$MAKEFILE.old"
2773  fi  fi
2774  echo "  Writing makefile: $MAKEFILE"  echo "  Writing makefile: $MAKEFILE"
2775  echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE  echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
# Line 1789  echo "#    $MACHINE" >> $MAKEFILE Line 2777  echo "#    $MACHINE" >> $MAKEFILE
2777  echo "# This makefile was generated automatically on" >> $MAKEFILE  echo "# This makefile was generated automatically on" >> $MAKEFILE
2778  echo "#    $THISDATE" >> $MAKEFILE  echo "#    $THISDATE" >> $MAKEFILE
2779  echo "# by the command:" >> $MAKEFILE  echo "# by the command:" >> $MAKEFILE
2780  echo "#    $0 $G2ARGS" >> $MAKEFILE  echo "#    $CMDLINE"  >> $MAKEFILE
2781  echo "# executed by:" >> $MAKEFILE  echo "# executed by:" >> $MAKEFILE
2782  echo "#    $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE  echo "#    ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
2783    
2784  EXE_AD=$EXECUTABLE"_ad"  EXE_AD=$EXECUTABLE"_ad"
2785  EXE_FTL=$EXECUTABLE"_ftl"  EXE_FTL=$EXECUTABLE"_ftl"
# Line 1800  EXE_SVD=$EXECUTABLE"_svd" Line 2788  EXE_SVD=$EXECUTABLE"_svd"
2788  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2789  #  #
2790  # OPTFILE="$OPTFILE"  # OPTFILE="$OPTFILE"
2791  #  #
2792  # BUILDDIR     : Directory where object files are written  # BUILDDIR     : Directory where object files are written
2793  # SOURCEDIRS   : Directories containing the source (.F) files  # SOURCEDIRS   : Directories containing the source (.F) files
2794  # INCLUDEDIRS  : Directories containing the header-source (.h) files  # INCLUDEDIRS  : Directories containing the header-source (.h) files
# Line 1811  cat >>$MAKEFILE <<EOF Line 2799  cat >>$MAKEFILE <<EOF
2799  # INCLUDES     : Directories searched for header files  # INCLUDES     : Directories searched for header files
2800  # DEFINES      : Macro definitions for CPP  # DEFINES      : Macro definitions for CPP
2801  # MAKEDEPEND   : Dependency generator  # MAKEDEPEND   : Dependency generator
 # KPP          : Special preprocessor command (specific to platform)  
 # KFLAGS       : Flags for KPP  
2802  # FC           : Fortran compiler command  # FC           : Fortran compiler command
2803  # FFLAGS       : Configuration/debugging options for FC  # FFLAGS       : Configuration/debugging options for FC
2804  # FOPTIM       : Optimization options for FC  # FOPTIM       : Optimization options for FC
# Line 1820  cat >>$MAKEFILE <<EOF Line 2806  cat >>$MAKEFILE <<EOF
2806  # LIBS         : Library flags /or/ additional optimization/debugging flags  # LIBS         : Library flags /or/ additional optimization/debugging flags
2807    
2808  ROOTDIR     = ${ROOTDIR}  ROOTDIR     = ${ROOTDIR}
2809  BUILDDIR    = ${BUILDDIR}    BUILDDIR    = ${BUILDDIR}
2810  SOURCEDIRS  = ${SOURCEDIRS}  SOURCEDIRS  = ${SOURCEDIRS}
2811  INCLUDEDIRS = ${INCLUDEDIRS}  INCLUDEDIRS = ${INCLUDEDIRS}
2812  EXEDIR      = ${EXEDIR}  EXEDIR      = ${EXEDIR}
2813  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}
2814  TOOLSDIR    = ${TOOLSDIR}  TOOLSDIR    = ${TOOLSDIR}
2815    OADTOOLS    = ${OADTOOLS}
2816    
2817  #eh3  new defines for the adjoint work  #eh3  new defines for the adjoint work
2818  AUTODIFF    = ${ROOTDIR}/pkg/autodiff  AUTODIFF    = ${ROOTDIR}/pkg/autodiff
# Line 1837  ENABLED_PACKAGES = ${ENABLED_PACKAGES} Line 2824  ENABLED_PACKAGES = ${ENABLED_PACKAGES}
2824  DISABLED_PACKAGES = ${DISABLED_PACKAGES}  DISABLED_PACKAGES = ${DISABLED_PACKAGES}
2825    
2826  # These files are created by Makefile  # These files are created by Makefile
2827  SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h  SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h
   
2828  EOF  EOF
2829    
2830  #  Note: figure out some way to add Hyades JAM libraries here  if test "x$EMBED_SRC" = xt ; then
2831        echo "EMBEDDED_FILES = EMBEDDED_FILES.h" >>$MAKEFILE
2832    else
2833        echo "EMBEDDED_FILES = " >>$MAKEFILE
2834    fi
2835    
2836    # extract default cpp search path so we can pass it to makedepend
2837    CPPINCLUDES=`cat /dev/null | $CPP -v 2>&1 | awk '/^End of search/{f=0}!/^\#/{if(f){printf " -I%s", $1;}}/^\#include "..." search start/{f=1}'`
2838    
2839  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2840  # Unix ln (link)  # Unix ln (link)
2841  LN = ${LN}  LN = ${LN}
 # C preprocessor  
 CPP = cat \$< | ${S64} | ${CPP}  
2842  # Dependency generator  # Dependency generator
2843  MAKEDEPEND = ${MAKEDEPEND}  MAKEDEPEND = ${MAKEDEPEND}
2844  # Special preprocessor (KAP on DECs, FPP on Crays)  # Special preprocessor (KAP on DECs, FPP on Crays)
# Line 1865  LINK = ${LINK} ${LDADD} Line 2856  LINK = ${LINK} ${LDADD}
2856  DEFINES = ${DEFINES}  DEFINES = ${DEFINES}
2857  # Includes for CPP  # Includes for CPP
2858  INCLUDES = ${INCLUDES}  INCLUDES = ${INCLUDES}
2859    # default CPP includes for makedepend
2860    CPPINCLUDES = ${CPPINCLUDES}
2861  # Flags for KPP  # Flags for KPP
2862  KFLAGS1 = ${KFLAGS1}  KFLAGS1 = ${KFLAGS1}
2863  KFLAGS2 = ${KFLAGS2}  KFLAGS2 = ${KFLAGS2}
2864  # Optim./debug for FC  # Optim./debug for FC
2865  FFLAGS = ${FFLAGS}  FFLAGS = ${FFLAGS} ${FEXTRAFLAGS}
2866  FOPTIM = ${FOPTIM}  FOPTIM = ${FOPTIM}
2867  # Optim./debug for FC  # Optim./debug for FC
2868  F90FLAGS = ${F90FLAGS}  F90FLAGS = ${F90FLAGS}
2869  F90OPTIM = ${F90OPTIM}  F90OPTIM = ${F90OPTIM}
2870    F90FIXEDFORMAT = ${F90FIXEDFORMAT}
2871  # Flags for CC  # Flags for CC
2872  CFLAGS = ${CFLAGS}  CFLAGS = ${CFLAGS}
2873  # Files that should not be optimized  # Files that should not be optimized
2874  NOOPTFILES = ${NOOPTFILES}  NOOPTFILES = ${NOOPTFILES}
2875  NOOPTFLAGS = ${NOOPTFLAGS}  NOOPTFLAGS = ${NOOPTFLAGS}
2876  # Flags and libraries needed for linking  # Flags and libraries needed for linking
2877  LIBS = ${LIBS} \$(XLIBS)  LIBS = ${LIBS}
2878  # Name of the Mekfile  # Name of the makefile
2879  MAKEFILE=${MAKEFILE}  MAKEFILE = ${MAKEFILE}
2880    # Name of the make program
2881    MAKE = ${MAKE}
2882    
2883  EOF  EOF
2884    
2885  cat srclist.inc       >> $MAKEFILE  cat F77srclist.tmp      >> $MAKEFILE
2886  cat csrclist.inc      >> $MAKEFILE  cat nonADF77srclist.tmp >> $MAKEFILE
2887  cat f90srclist.inc    >> $MAKEFILE  cat csrclist.tmp        >> $MAKEFILE
2888  cat hlist.inc         >> $MAKEFILE  cat F90srclist.tmp      >> $MAKEFILE
2889  cat ad_flow_files.inc >> $MAKEFILE  cat hsrclist.tmp        >> $MAKEFILE
2890    cat ad_flow_files.tmp   >> $MAKEFILE
2891    
2892    rm -f F77srclist.tmp nonADF77srclist.tmp csrclist.tmp F90srclist.tmp hsrclist.tmp ad_flow_files.tmp
2893    
2894  echo >> $MAKEFILE  echo >> $MAKEFILE
2895  echo 'F77FILES =  $(SRCFILES:.F=.'$FS')'      >> $MAKEFILE  
2896  echo 'F90FILES =  $(F90SRCFILES:.F=.'$FS90')' >> $MAKEFILE  # add definitions for preprocessed sources
2897  echo 'OBJFILES =  $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE  # and note that not all systems allow case sensitive extensions
2898    # hence the $FS and $FS90 here.
2899    # for fixed format f90 files we use ff90 or FF90 resp
2900    # but these are not expected to be the original source files
2901    
2902    echo 'F77_PP_SRC_FILES = $(F77_SRC_FILES:.F=.'$FS')'      >> $MAKEFILE
2903    echo 'F90_PP_SRC_FILES = $(F90_SRC_FILES:.F90=.'$FS90')' >> $MAKEFILE
2904    echo 'OBJFILES= $(F77_SRC_FILES:.F=.o) $(C_SRC_FILES:.c=.o) $(F90_SRC_FILES:.F90=.o)' >> $MAKEFILE
2905    echo 'FLOWFILES =  $(AD_FLOW_FILES:.flow=.flowdir)' >> $MAKEFILE
2906  echo >> $MAKEFILE  echo >> $MAKEFILE
2907  echo '.SUFFIXES:' >> $MAKEFILE  echo '.SUFFIXES:' >> $MAKEFILE
2908  echo '.SUFFIXES: .o .'$FS' .p .F .c .'$FS90' .F90' >> $MAKEFILE  echo '.SUFFIXES: .o .'$FS' .p .F .c .f'$FS90' .'$FS90' .FF90 .F90 .flowdir .flow' >> $MAKEFILE
 rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc  
 rm -f ad_flow_files.inc  
2909    
2910  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
2911    
2912  all: \$(EXECUTABLE)  all: fwd_exe_target
2913  \$(EXECUTABLE): \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(OBJFILES)  fwd_exe_target:
2914            @echo Update AD_CONFIG.h and make \$(EXECUTABLE)
2915            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Forward version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
2916            @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
2917            @-rm -f ad_config.template
2918            \$(MAKE) -f \$(MAKEFILE) \$(EXECUTABLE)
2919    
2920    \$(EXECUTABLE): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(OBJFILES) \$(EMBEDDED_FILES)
2921          @echo Creating \$@ ...          @echo Creating \$@ ...
2922          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
2923    
2924  depend:  depend:
2925          @make links          @\$(MAKE) -f \$(MAKEFILE) links
2926          \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(SRCFILES)          \$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(CPPINCLUDES) \$(F77_SRC_FILES)
2927          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)          \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2928          -rm -f makedepend.out          -rm -f makedepend.out
2929    
2930  links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES)  lib: libmitgcmuv.a
2931    
2932  small_f: \$(F77FILES) \$(F90FILES)  libmitgcmuv.a: \$(OBJFILES)
2933            ar rcv libmitgcmuv.a \$(OBJFILES)
2934            ar d   libmitgcmuv.a main.o
2935    
2936    obj: \$(OBJFILES)
2937    
2938    links: \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(SPECIAL_FILES)
2939    
2940    small_f: \$(F77_PP_SRC_FILES) \$(F90_PP_SRC_FILES)
2941    
2942  output.txt: \$(EXECUTABLE)  output.txt: \$(EXECUTABLE)
2943          @printf 'running ... '          @printf 'running ... '
2944          @\$(EXECUTABLE) > \$@          @\$(EXECUTABLE) > \$@
2945    
2946    # remove most of the files that "make" generates
2947  clean:  clean:
2948          -rm -rf *.o *.$FS *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template          -rm -rf *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
2949            -rm -rf *.o
2950            -rm -rf *.$FS *.flowdir
2951            -rm -rf *.f$FS90 \$(AD_CLEAN) ad_input*
2952    
2953    # remove most of the files that "make" and "make depend" generate
2954  Clean:  Clean:
2955          @make clean          @\$(MAKE) -f \$(MAKEFILE) clean
2956          @make cleanlinks          @\$(MAKE) -f \$(MAKEFILE) cleanlinks
2957          -rm -f \$(SPECIAL_FILES)          -rm -f \$(SPECIAL_FILES) f90mkdepend.log $MAKEFILE.old
2958          -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak          -rm -f taf_command taf_output taf_ad.log taf_ad_flow.log taf_ftl.log
2959    
2960    # remove also the executable, files that "genmake2" generates (except Makefile)
2961    #         and output from a run (plus log files from testreport)
2962  CLEAN:  CLEAN:
2963          @make Clean          @\$(MAKE) -f \$(MAKEFILE) Clean
2964            -rm -f \$(EXECUTABLE) \$(EXE_AD) \$(EXE_FTL) *.bak
2965            -rm -f $LOGFILE genmake_state genmake_*optfile
2966            -rm -f SIZE.h.mpi genmake.tr_log make.tr_log
2967            -rm -rf mpi_headers mnc_test_*
2968          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
2969          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
2970          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
2971          -rm -f \$(EXECUTABLE) output.txt STD*          -rm -f *.txt STDOUT.* STDERR.* *diagnostics.log *.[0-9][0-9][0-9][0-9].log
2972            -rm -f datetime costfinal divided.ctrl snapshot* output_adm.txt.diva_*
2973            -rm -f *_MIT_CE_000.opt0000 costfunction*0000
2974            -rm -f oad_cp.000.[0-9][0-9][0-9][0-9][0-9]
2975    
 #eh3 Makefile: makefile  
2976  makefile:  makefile:
2977          $THIS_SCRIPT $G2ARGS          $THIS_SCRIPT $G2ARGS
2978  cleanlinks:  cleanlinks:
2979          -find . -type l -exec rm {} \;          -find . -type l -exec rm {} \;
2980    
2981  # Special targets ($SPECIAL_FILES) which are create by make  # Special targets (SPECIAL_FILES) which are created by make
2982  ${PACKAGES_DOT_H}:  ${PACKAGES_DOT_H}:
2983          @echo Creating \$@ ...          @echo Creating \$@ ...
2984          @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@          @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@
2985  AD_CONFIG.h:  AD_CONFIG.h:
2986          @echo Creating \$@ ...          @echo Creating \$@ ...
2987          @$BASH\$(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 > \$@          @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Default version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > \$@
2988  FC_NAMEMANGLE.h:  FC_NAMEMANGLE.h:
2989          @echo Creating \$@ ...          @echo Creating \$@ ...
2990          echo "$FC_NAMEMANGLE" > \$@          echo "$FC_NAMEMANGLE" > \$@
2991    
2992    BUILD_INFO.h:
2993            @echo Creating \$@ ...
2994    EOF
2995    
2996    test ! "x$THISVER" = x  && echo "       -echo \"#define THISVER '$THISVER'\" > \$@"   >> $MAKEFILE
2997    test ! "x$THISUSER" = x && echo "       -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE
2998    test ! "x$THISDATE" = x && echo "       -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
2999    test ! "x$THISHOST" = x && echo "       -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
3000    
3001    if test "x$EMBED_SRC" = xt ; then
3002        cat >>$MAKEFILE <<EOF
3003    
3004    decode_files.o : EMBEDDED_FILES.h
3005    
3006    ##  \$(F77_PP_SRC_FILES)
3007    all_fF.tar.gz : \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile
3008            @echo Creating \$@ ...
3009            -tar -hcf all_fF.tar \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile
3010            -rm -f all_fF.tar.gz
3011            -gzip all_fF.tar
3012    
3013    EMBEDDED_FILES.h : all_fF.tar.gz
3014            @echo Creating \$@ ...
3015            -\${ROOTDIR}/tools/embed_encode/encode_files EMBEDDED_FILES.h all_fF.tar.gz
3016    
3017    EOF
3018    fi
3019    
3020    cat >>$MAKEFILE <<EOF
3021    
3022  # The normal chain of rules is (  .F - .$FS - .o  )  # The normal chain of rules is (  .F - .$FS - .o  )
3023    
3024  %.o : %.F  ## This nullifies any default implicit rules concerning these two file types:
3025    ## %.o : %.F
3026    
3027    # C preprocessing and replacing the _d in constants:
3028    CPPCMD = cat \$< | ${CPP} \$(DEFINES) \$(INCLUDES) | ${S64}
3029    
3030  .F.$FS:  .F.$FS:
3031          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPPCMD)  > \$@
3032  .$FS.o:  .$FS.o:
3033          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<          \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
3034    .F.o:
3035            \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
3036  .F90.$FS90:  .F90.$FS90:
3037          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPPCMD)  > \$@
3038    .FF90.f$FS90:
3039            \$(CPPCMD)  > \$@
3040  .$FS90.o:  .$FS90.o:
3041          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<          \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
3042    .f$FS90.o:
3043            cp \$< \$(basename  \$<).f90
3044            \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$(F90FIXEDFORMAT) \$(basename  \$<).f90
3045  .c.o:  .c.o:
3046          \$(CC) \$(CFLAGS) -c \$<          \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$<
3047    .flow.flowdir:
3048            \$(CPPCMD) > \$@
3049    
3050  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain  # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
3051  .F.p:  .F.p:
3052          \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@          \$(CPPCMD) > \$@
3053  .p.$FS:  .p.$FS:
3054          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<          \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
3055    
3056    EOF
3057    
3058  #=========================================  #=========================================
3059  #===  Automatic Differentiation Rules  ===  #===  Automatic Differentiation Rules  ===
3060    #===  for TAMC/TAF  ======================
3061    
3062    if test "x$OPENAD" = x ; then
3063    
3064    cat >>$MAKEFILE <<EOF
3065    
3066  TAMC           = ${TAMC}  TAMC           = ${TAMC}
3067  TAF            = ${TAF}  TAF            = ${TAF}
3068    
3069  TAF_EXTRA      = ${TAF_EXTRA}  TAF_EXTRA      = ${TAF_EXTRA}
3070  TAMC_EXTRA     = ${TAMC_EXTRA}  TAMC_EXTRA     = ${TAMC_EXTRA}
3071    LOCAL_MPI_HEADERS    = ${LOCAL_MPI_HEADERS}
3072    
3073  EOF  EOF
3074    
# Line 1989  ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF Line 3077  ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF
3077  ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"  ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
3078  for i in $ad_vars ; do  for i in $ad_vars ; do
3079      name=$i      name=$i
3080      t1="t2=\$"`echo $i`      t1="t2=\$"`echo "$i"`
3081      eval $t1      eval $t1
3082      printf "%-20s = " $name >> $MAKEFILE      printf "%-20s = " $name >> $MAKEFILE
3083      echo $t2 >> $MAKEFILE      echo "$t2" | sed -e 's| \+| |g' >> $MAKEFILE
3084  done  done
3085    
3086  echo "  Add the source list for AD code generation"  echo "  Add the source list for AD code generation"
3087  echo >> $MAKEFILE  echo >> $MAKEFILE
3088  printf "AD_FILES = " >> $MAKEFILE  printf "AD_FILES = " >> $MAKEFILE
3089  AD_FILES=`cat ad_files`  AD_FILES=`cat adSrcFiles.tmp`
3090  for i in $AD_FILES ; do  for i in $AD_FILES ; do
3091      echo    " \\" >> $MAKEFILE      echo    " \\" >> $MAKEFILE
3092      printf " $i" >> $MAKEFILE      printf " $i" >> $MAKEFILE
3093  done  done
3094  echo >> $MAKEFILE  echo >> $MAKEFILE
3095  rm -f ad_files  rm -f adSrcFiles.tmp
3096    
3097  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
3098    
3099  # ... AD ...  # ... AD ...
3100  adall: ad_taf  adall: ad_exe_target
3101  adtaf: ad_taf_output.f  adtaf: ad_taf_output.$FS
3102  adtamc: ad_tamc_output.f  adtamc: ad_tamc_output.$FS
3103    
3104    ad_exe_target:
3105            @echo Update AD_CONFIG.h and make \$(EXE_AD)
3106            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3107            @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3108            @-rm -f ad_config.template
3109            \$(MAKE) -f \$(MAKEFILE) \$(EXE_AD)
3110    
3111  ad_input_code.f: \$(AD_FILES) \$(HEADERFILES)  ad_input_code.$FS: \$(AD_FILES) \$(AD_FLOW_FILES)
3112          @$BASH\$(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          @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3113          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
3114          -rm -f ad_config.template          @-rm -f ad_config.template
3115          @make \$(F77FILES)          @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3116          @make \$(AD_FLOW_FILES)          @\$(MAKE) -f \$(MAKEFILE) \$(FLOWFILES)
3117          cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f          cat \$(FLOWFILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ad_input_code.$FS
3118    
3119  ad_taf_output.f: ad_input_code.f  ad_taf_output.$FS: ad_input_code.$FS
3120          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
3121          cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f          ls -l ad_input_code_ad.$FS
3122            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
3123    
3124  adtafonly:  adtafonly:
3125          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
3126          cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f          ls -l ad_input_code_ad.$FS
3127            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
3128    
3129    \$(EXE_AD): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) ad_taf_output.o \$(OBJFILES) \$(EMBEDDED_FILES)
3130            \$(LINK) -o \${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
3131    
3132    ad_tamc_output.$FS: ad_input_code.$FS
3133            \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
3134            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS
3135    
3136  ad_taf: ad_taf_output.o \$(OBJFILES)  ad_tamc: ad_tamc_output.o \$(OBJFILES)
3137          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
3138    
3139  ad_tamc_output.f: ad_input_code.f  adonlyfwd:
3140          \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f          patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
         cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.f  
3141    
3142  ad_tamc: ad_tamc_output.o \$(OBJFILES)  adtrick:
3143          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)          patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
3144    
3145    adobj: ad_taf_output.o \$(OBJFILES)
3146    
3147  # ... FTL ...  # ... FTL ...
3148  ftlall: ftl_taf  ftlall: ftl_exe_target
3149  ftltaf: ftl_taf_output.f  ftltaf: ftl_taf_output.$FS
3150  ftltamc: ftl_tamc_output.f  ftltamc: ftl_tamc_output.$FS
3151    
3152  ftl_input_code.f: \$(AD_FILES) \$(HEADERFILES)  ftl_exe_target:
3153          @$BASH\$(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          @echo Update AD_CONFIG.h and make \$(EXE_FTL)
3154          cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h          @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
3155          -rm -f ftl_config.template          @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3156          @make \$(F77FILES)          @-rm -f ad_config.template
3157          @make \$(AD_FLOW_FILES)          \$(MAKE) -f \$(MAKEFILE) \$(EXE_FTL)
         cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f  
   
 ftl_taf_output.f: ftl_input_code.f  
         \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f  
         cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f  
   
 ftltafonly:  
         \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f  
         cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f  
3158    
3159  ftl_taf: ftl_taf_output.o \$(OBJFILES)  ftl_input_code.$FS: \$(AD_FILES)
3160          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)          @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
3161            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3162            @-rm -f ad_config.template
3163            @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3164            @\$(MAKE) -f \$(MAKEFILE) \$(AD_FLOW_FILES)
3165            cat \$(AD_FLOW_FILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ftl_input_code.$FS
3166    
3167    ftl_taf_output.$FS: ftl_input_code.$FS
3168            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
3169            ls -l ftl_input_code_ftl.$FS
3170            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
3171    
3172  ftl_tamc_output.f: ftl_input_code.f  ftltafonly:
3173          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
3174          cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.f          ls -l ftl_input_code_ftl.$FS
3175            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
3176    
3177    \$(EXE_FTL): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) ftl_taf_output.o \$(OBJFILES) \$(EMBEDDED_FILES)
3178            \$(LINK) -o \${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
3179    
3180    ftl_tamc_output.$FS: ftl_input_code.$FS
3181            \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
3182            cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS
3183    
3184  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)  ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
3185          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)          \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
   
3186    
3187  # ... SVD ...  # ... SVD ...
3188  svdtaf: ad_taf_output.f ftl_taf_output.f  svdtaf: ad_taf_output.$FS ftl_taf_output.$FS
3189  svdall: svd_taf          @echo "--->>> Only ran TAF to generate SVD code!    <<<---"
3190            @echo "--->>> Do make svdall afterwards to compile. <<<---"
3191    svdall: svd_touch svd_taf
3192    
3193  svd_taf: ad_taf_output.o ftl_taf_output.o \$(OBJFILES)  svd_taf: \$(OBJFILES)
3194          \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)          \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
3195    
3196            @echo "--->>> Only COMPILE svd code! <<<---"
3197            @echo "--->>> Assumes you previously <<<---"
3198            @echo "--->>> did make svdtaf        <<<---"
3199    
3200    svd_touch:
3201            @echo "--->>> Only COMPILE svd code! <<<---"
3202            @echo "--->>> Assumes you previously <<<---"
3203            @echo "--->>> did make svdtaf        <<<---"
3204            touch ad_taf_output.$FS ftl_taf_output.$FS
3205            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS
3206            \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS
3207            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "SVD version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
3208            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3209            @-rm -f ad_config.template
3210    
3211  #=========================================  EOF
3212    
3213    fi
3214    
3215    #===  for OpenAD  ========================
3216    
3217    if test "x$OPENAD" != x ; then
3218    
3219    # ============ begin OpenAD specific section ==============
3220    
3221    cat >>$MAKEFILE <<EOF
3222    
3223    # all the source files linked from the various locations:
3224    ALL_LINKED_FILES= \
3225    \$(F77_SRC_FILES) \
3226    \$(C_SRC_FILES) \
3227    \$(H_SRC_FILES) \
3228    \$(F90_SRC_FILES) \
3229    \$(SPECIAL_FILES)
3230    
3231    ifndef OPENADROOT
3232      \$(error "Error:  environment variable OPENADROOT not defined!")
3233    endif
3234    
3235    ifndef XAIFSCHEMAROOT
3236      \$(error "Error:  environment variable XAIFSCHEMAROOT not defined!")
3237    endif
3238    
3239    ifndef XAIFBOOSTERROOT
3240      \$(error "Error:  environment variable XAIFBOOSTERROOT not defined!")
3241    endif
3242    
3243    EOF
3244    
3245    echo "  Add the source list for common block to module conversion "
3246    echo >> $MAKEFILE
3247    printf "CB2M_F90_SRC_NAMES = " >> $MAKEFILE
3248    for i in `cat ${OAD_CB2M_FILES}` ; do
3249      echo    " \\" >> $MAKEFILE
3250      printf " $i" >> $MAKEFILE
3251    done
3252    echo >> $MAKEFILE
3253    
3254    echo "  Add the source list for AD code generation"
3255    echo >> $MAKEFILE
3256    printf "AD_FILES = " >> $MAKEFILE
3257    for i in `cat ${OAD_CB2M_FILES}` ; do
3258      echo    " \\" >> $MAKEFILE
3259      printf " ${i}_mod.f$FS90" >> $MAKEFILE
3260    done
3261    AD_FILES=`cat adSrcFiles.tmp`
3262    for i in $AD_FILES ; do
3263      basename=${i%%.f}
3264      toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE} ${OAD_DONT_TRANSFORM}`
3265      if test -z "$toBeIgnored" ; then
3266        echo    " \\" >> $MAKEFILE
3267        printf " $i" >> $MAKEFILE
3268      fi
3269    done
3270    echo >> $MAKEFILE
3271    rm -f adSrcFiles.tmp
3272    
3273    cat >>$MAKEFILE <<EOF
3274    
3275    adAll: \$(EXE_AD)
3276    .PHONY: adAll
3277    
3278    CB2M_F90_PP_SRC_FILES=\$(addsuffix _mod.f$FS90, \$(CB2M_F90_SRC_NAMES))
3279    
3280    .PRECIOUS: \$(CB2M_F90_PP_SRC_FILES) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90)
3281    
3282    .PHONY: adDepend
3283    adDepend: \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) \$(addsuffix _mod.FF90, \$(CB2M_F90_SRC_NAMES)) \$(F77_SRC_FILES:.F=_cb2m.FF90)
3284            \$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)
3285            \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
3286            -rm -f makedepend.out
3287    
3288    OPENAD_SUPPORT_F90_SRC_FILES = \
3289    w2f__types.F90 \
3290    OAD_active.F90 \
3291    OAD_cp.F90 \
3292    OAD_rev.F90 \
3293    OAD_tape.F90 \
3294    revolve.F90
3295    
3296    OPENAD_SUPPORT_C_SRC_FILES = \
3297    iaddr.c \
3298    timeRatio.c
3299    
3300    f95_test_mods.f90: \$(OPENAD_SUPPORT_F90_SRC_FILES:F90=$FS90)
3301            cat \$^ > \$@
3302    
3303    f95_test.f90: all_mods.xb.x2w.w2f.pp.f$FS90 \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90) ad_input_code.w2f.pre.xb.x2w.w2f.td.pp.f$FS90
3304            cat \$^ > \$@
3305    
3306    f95_test.out: f95_test_mods.f90 f95_test.f90
3307            f95 -fixed -w=unused -maxcontin=132 -c f95_test_mods.f90 > \$@ 2>&1
3308            f95 -fixed -w=unused -maxcontin=132 -c -fixed f95_test.f90 >> \$@ 2>&1
3309    
3310    CB2M_AD_FILES=\$(AD_FILES:.f=_cb2m.f$FS90)
3311    
3312    AD_OBJ_FILES_S1=\$(OPENAD_SUPPORT_F90_SRC_FILES:.F90=.o) \$(OPENAD_SUPPORT_C_SRC_FILES:.c=.o)  OAD_intrinsics_oad.o \$(CB2M_AD_FILES:.f$FS90=_oad.o)
3313    
3314    AD_OBJ_FILES_S2=\$(AD_OBJ_FILES_S1) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.o) \$(C_SRC_FILES:.c=.o) \$(F90_SRC_FILES:.F90=.o)
3315    
3316    \$(EXE_AD): \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) postProcess.tag \$(AD_OBJ_FILES_S2)
3317            \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(AD_OBJ_FILES_S2) \$(LIBS)
3318    
3319    # create sources files modules from header files containing common blocks
3320    %_mod.FF90 : %.h \${OADTOOLS}/cb2mGetModules.csh \${OADTOOLS}/cb2mGetModules.awk
3321            \${OADTOOLS}/cb2mGetModules.csh $< \${OADTOOLS}/cb2mGetModules.awk
3322    
3323    # create new header files with USE statements for the new modules made above
3324    %_mod.h : %.h \${OADTOOLS}/cb2mGetHeaders.csh \${OADTOOLS}/cb2mGetHeaders.awk
3325            \${OADTOOLS}/cb2mGetHeaders.csh $< \${OADTOOLS}/cb2mGetHeaders.awk \$(CB2M_F90_SRC_NAMES)
3326    
3327    # change the include directives of everybody to refer to  the new header files with the USE statements
3328    %_cb2m.FF90 : %.F \${OADTOOLS}/cb2mUseModules.bash
3329            \${OADTOOLS}/cb2mUseModules.bash $< ${MPI}
3330    
3331    # makefile debug rule
3332    small_f: \$(CB2M_F90_PP_SRC_FILES)
3333    .PHONY: small_f
3334    
3335    ad_output.txt: \$(EXE_AD)
3336            @printf 'linking data files ... '
3337            \$(LN) -f ../input_ad/data* ../input_ad/eedata .
3338            \$(LN) -f ../../global_ocean.90x40x15/input/*.bin .
3339            @printf 'running ... '
3340            @./\$(EXE_AD) > \$@
3341    
3342    ad_input_code.f$FS90:  \$(CB2M_AD_FILES)
3343            cat \$^ > \$@
3344    
3345    # canonicalizer
3346    ad_input_code_sf.pre.f90 : \$(CB2M_AD_FILES)
3347            \${OPENADFORTTK_BASE}/tools/SourceProcessing/preProcess.py --timing --r8 -H -S  -o \$@ \$^
3348    
3349    # replace stop statements (to avoid the implied unstructured control flow)  with print statements
3350    ad_input_code_sf.pre.s2p.f90 : ad_input_code_sf.pre.f90
3351            cat \$< | sed -f \${OADTOOLS}/stop2print.sed > ad_input_code_sf.pre.s2p.f90
3352    
3353    # F -> WHIRL
3354    ad_input_code_sf.pre.s2p.B: ad_input_code_sf.pre.s2p.f90
3355            \${OPEN64ROOT}/crayf90/sgi/mfef90 -r8 -z -F ad_input_code_sf.pre.s2p.f90
3356    
3357    # WHIRL -> XAIF
3358    ad_input_code_sf.pre.s2p.xaif : ad_input_code_sf.pre.s2p.B
3359            \${OPENADFORTTK}/bin/whirl2xaif -s -n --debug 1 -o \$@ \$<
3360    
3361    # XAIF -> XAIF'
3362    ad_input_code_sf.pre.s2p.xb.xaif : ad_input_code_sf.pre.s2p.xaif xaif.xsd xaif_base.xsd xaif_inlinable_intrinsics.xsd xaif_derivative_propagator.xsd xaif_output.xsd
3363            \${XAIFBOOSTERROOT}/xaifBooster/algorithms/BasicBlockPreaccumulationReverse/driver/oadDriver -f -t forward_step -i \$< -c \${XAIFSCHEMAROOT}/schema/examples/inlinable_intrinsics.xaif -o \$@ -I -r
3364    
3365    # XAIF' -> WHIRL'
3366    ad_input_code_sf.pre.s2p.xb.x2w.B : ad_input_code_sf.pre.s2p.xb.xaif
3367            \${OPENADFORTTK}/bin/xaif2whirl --debug 1 ad_input_code_sf.pre.s2p.B \$<
3368    
3369    # WHIRL' -> F'
3370    ad_input_code_sf.pre.s2p.xb.x2w.w2f.f$FS90: ad_input_code_sf.pre.s2p.xb.x2w.B
3371            \${OPEN64ROOT}/whirl2f/whirl2f -FLIST:ftn_file=\$@ -openad \$<
3372    
3373    # insert template directives
3374    ad_input_code_sf.pre.s2p.xb.x2w.w2f.td.f$FS90: ad_input_code_sf.pre.s2p.xb.x2w.w2f.f$FS90 \${OADTOOLS}/insertTemplateDir.bash
3375            \${OADTOOLS}/insertTemplateDir.bash \$< \$@
3376    
3377    PPEXTRAS=\$(wildcard \${OADTOOLS}/ad_template.*.F) \${OADTOOLS}/ad_inline.F
3378    # postprocess F'
3379    postProcess.tag: ad_input_code_sf.pre.s2p.xb.x2w.w2f.td.f$FS90 \$(PPEXTRAS:.F=.f) | w2f__types.f90
3380            \${OPENADFORTTK_BASE}/tools/SourceProcessing/postProcess.py --progress --timing --infoUnitFile w2f__types.f90 --outputFormat=fixed --separateOutput --pathSuffix "" --filenameSuffix "_oad" -m r -i \${OADTOOLS}/ad_inline.f \$<
3381            # the target is a placeholder to trigger a single execution of the rule
3382            touch \$@
3383    # put this so make knows about the postprocessing output
3384    OAD_intrinsics_oad.f \$(CB2M_AD_FILES:.f$FS90=_oad.f): postProcess.tag
3385    
3386    # link the XAIF schema files
3387    %.xsd:
3388            \$(LN) \${XAIFSCHEMAROOT}/schema/\$@ .
3389    
3390    # link the support files:
3391    \$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES):
3392            \$(LN) \${OADTOOLS}/\$@ .
3393    
3394    AD_CLEAN += *_mod.h *_mod.F90 *.FF90 *.mod-whirl temp.sed oad_cp.* postProcess.tag \$(PPEXTRAS:.F=.f)
3395    
3396    # ============ end OpenAD specific section ==============
3397    
3398  EOF  EOF
3399    
3400    fi
3401    
3402    #=========================================
3403    
3404  if test "x$EXEHOOK" != x ; then  if test "x$EXEHOOK" != x ; then
3405      printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE      printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
3406  fi  fi
# Line 2119  printf "\n\n# DO NOT DELETE\n" >> $MAKEF Line 3436  printf "\n\n# DO NOT DELETE\n" >> $MAKEF
3436  printf "\n===  Done  ===\n"  printf "\n===  Done  ===\n"
3437    
3438  # Create special header files  # Create special header files
3439  $BASH $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"  $BASH $TOOLSDIR/convert_cpp_cmd2defines -bPACKAGES_CONFIG_H "Disabled packages:" $DISABLED_PACKAGES " " "Enabled packages:" $ENABLED_PACKAGES > $PACKAGES_DOT_H".tmp"
3440  if test ! -f $PACKAGES_DOT_H ; then  if test ! -f $PACKAGES_DOT_H ; then
3441      mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H      mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
3442  else  else
# Line 2133  else Line 3450  else
3450      fi      fi
3451  fi  fi
3452  if test ! -f AD_CONFIG.h ; then  if test ! -f AD_CONFIG.h ; then
3453      $BASH $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      $BASH $TOOLSDIR/convert_cpp_cmd2defines "Default version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > AD_CONFIG.h
3454  fi  fi
3455    
   
3456  #  Write the "state" for future records  #  Write the "state" for future records
3457  if test "x$DUMPSTATE" != xf ; then  if test "x$DUMPSTATE" = xt ; then
3458      printf "" > genmake_state      printf "" > genmake_state
3459      for i in $gm_state ; do      for i in $gm_state ; do
3460          t1="t2=\$$i"          t1="t2=\$$i"
3461          eval $t1          eval $t1
3462          echo "$i='$t2'" >> genmake_state          echo "$i='$t2'" | sed -e 's/  */ /g' >> genmake_state
3463      done      done
3464  fi  fi

Legend:
Removed from v.1.96  
changed lines
  Added in v.1.252

  ViewVC Help
Powered by ViewVC 1.1.22