Back to home page

MITgcm

 
 

    


Warning, /tools/genmake2 is written in an unsupported language. File is not indexed.

view on githubraw file Latest commit 71b7a3e5 on 2024-10-29 20:15:15 UTC
3185ed66f0 Ed H*0001 #! /usr/bin/env bash
6aec5d9846 Ed H*0002 #
                0003 # Makefile generator for MITgcm UV codes
                0004 #   created  by cnh 03/98
                0005 #   adapted  by aja 06/98
                0006 #   modified by aja 01/00
                0007 #   rewritten in bash by eh3 08/03
                0008 
23f21461eb Jean*0009 #  Explain usage
                0010 usage()  {
                0011 cat <<EOF
                0012 
                0013 Usage: "$0" [OPTIONS]
                0014   where [OPTIONS] can be:
                0015 
                0016     -help | --help | -h | --h
36e14999eb Jean*0017           Print this help message and exit.
23f21461eb Jean*0018 
b4daa24319 Shre*0019     -tap | --tap
                0020           Generate a Makefile for a Tapenade build
                0021 
16cc6e2b59 Jean*0022     -oad | --oad
                0023           Generate a Makefile for an OpenAD built
                0024 
9d0c386f0c dngo*0025     -oadsingularity NAME | --oadsingularity NAME | -oadsngl NAME | --oadsngl NAME
                0026       -oadsingularity=NAME | --oadsingularity=NAME | -oadsngl=NAME | --oadsngl=NAME
                0027           Here, "NAME" specifies the singularity file
                0028           that contains the OpenAD execulable.
                0029 
44f4a23ebb Jean*0030     -nocat4ad | -dog4ad | -ncad | -dad
                0031           do not concatenate (cat) source code sent to TAF
                0032           resulting in compilation of multiple files
                0033 
23f21461eb Jean*0034     -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME
                0035       -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME
36e14999eb Jean*0036           Use "NAME" as the adoptfile.  By default, the file at
16cc6e2b59 Jean*0037           "tools/adjoint_options/adjoint_oad" (for OpenAD built) or
36e14999eb Jean*0038           "tools/adjoint_options/adjoint_default" will be used.
23f21461eb Jean*0039 
bdd2b3a476 Jean*0040     -optfile NAME | --optfile NAME | -of NAME | --of NAME
23f21461eb Jean*0041       -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
36e14999eb Jean*0042           Use "NAME" as the optfile.  By default, an attempt will be
                0043           made to find an appropriate "standard" optfile in the
                0044           tools/build_options/ directory.
23f21461eb Jean*0045 
                0046     -pdepend NAME | --pdepend NAME
                0047       -pdepend=NAME | --pdepend=NAME
36e14999eb Jean*0048           Get package dependency information from "NAME".
23f21461eb Jean*0049 
                0050     -pgroups NAME | --pgroups NAME
                0051       -pgroups=NAME | --pgroups=NAME
36e14999eb Jean*0052           Get the package groups information from "NAME".
23f21461eb Jean*0053 
                0054     -bash NAME
36e14999eb Jean*0055           Explicitly specify the Bourne or BASH shell to use
23f21461eb Jean*0056 
                0057     -make NAME | -m NAME
                0058       --make=NAME | -m=NAME
36e14999eb Jean*0059           Use "NAME" for the MAKE program. The default is "make" but
                0060           many platforms, "gmake" is the preferred choice.
23f21461eb Jean*0061 
                0062     -makefile NAME | -mf NAME
                0063       --makefile=NAME | -mf=NAME
36e14999eb Jean*0064           Call the makefile "NAME".  The default is "Makefile".
23f21461eb Jean*0065 
                0066     -makedepend NAME | -md NAME
                0067       --makedepend=NAME | -md=NAME
36e14999eb Jean*0068           Use "NAME" for the MAKEDEPEND program.
23f21461eb Jean*0069 
                0070     -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
                0071       -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
36e14999eb Jean*0072           Specify the location of the MITgcm ROOTDIR as "NAME".
                0073           By default, genamke will try to find the location by
                0074           looking in parent directories (up to the 5th parent).
23f21461eb Jean*0075 
                0076     -mods NAME | --mods NAME | -mo NAME | --mo NAME
                0077       -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
36e14999eb Jean*0078           Here, "NAME" specifies a list of directories that are
                0079           used for additional source code.  Files found in the
                0080           "mods list" are given preference over files of the same
                0081           name found elsewhere.
23f21461eb Jean*0082 
                0083     -disable NAME | --disable NAME
                0084       -disable=NAME | --disable=NAME
36e14999eb Jean*0085           Here "NAME" specifies a list of packages that we don't
                0086           want to use.  If this violates package dependencies,
                0087           genamke will exit with an error message.
23f21461eb Jean*0088 
                0089     -enable NAME | --enable NAME
                0090       -enable=NAME | --enable=NAME
36e14999eb Jean*0091           Here "NAME" specifies a list of packages that we wish
                0092           to specifically enable.  If this violates package
                0093           dependencies, genamke will exit with an error message.
23f21461eb Jean*0094 
                0095     -standarddirs NAME | --standarddirs NAME
                0096       -standarddirs=NAME | --standarddirs=NAME
36e14999eb Jean*0097           Here, "NAME" specifies a list of directories to be
                0098           used as the "standard" code.
23f21461eb Jean*0099 
                0100     -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
                0101       -fc=NAME | --fc=NAME
36e14999eb Jean*0102           Use "NAME" as the fortran compiler.  By default, genmake
                0103           will search for a working compiler by trying a list of
                0104           "usual suspects" such as g77, f77, etc.
23f21461eb Jean*0105 
                0106     -cc NAME | --cc NAME | -cc=NAME | --cc=NAME
36e14999eb Jean*0107           Use "NAME" as the C compiler.  By default, genmake
                0108           will search for a working compiler by trying a list of
                0109           "usual suspects" such as gcc, c89, cc, etc.
23f21461eb Jean*0110 
                0111     -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4
36e14999eb Jean*0112           Use "real*4" type for _RS variable (#undef REAL4_IS_SLOW)
                0113           *only* works if CPP_EEOPTIONS.h allows this.
23f21461eb Jean*0114 
                0115     -ignoretime | -ignore_time | --ignoretime | --ignore_time
36e14999eb Jean*0116           Ignore all the "wall clock" routines entirely.  This will
                0117           not in any way hurt the model results -- it simply means
                0118           that the code that checks how long the model spends in
                0119           various routines will give junk values.
23f21461eb Jean*0120 
                0121     -ts | --ts
36e14999eb Jean*0122           Produce timing information per timestep
23f21461eb Jean*0123     -papis | --papis
36e14999eb Jean*0124           Produce summary MFlop/s (and IPC) with PAPI per timestep
23f21461eb Jean*0125     -pcls | --pcls
36e14999eb Jean*0126           Produce summary MFlop/s etc. with PCL per timestep
23f21461eb Jean*0127     -foolad | --foolad
36e14999eb Jean*0128           Fool the AD code generator
23f21461eb Jean*0129     -papi | --papi
36e14999eb Jean*0130           Performance analysis with PAPI
23f21461eb Jean*0131     -pcl | --pcl
36e14999eb Jean*0132           Performance analysis with PCL
23f21461eb Jean*0133     -hpmt | --hpmt
36e14999eb Jean*0134           Performance analysis with the HPM Toolkit
23f21461eb Jean*0135 
4d1f7e1a03 Jean*0136     -ieee | --ieee
36e14999eb Jean*0137           use IEEE numerics.  Note that this option *only* works
                0138           if it is supported by the OPTFILE that is being used.
23f21461eb Jean*0139     -devel | --devel
36e14999eb Jean*0140           Add additional warning and debugging flags for development
                0141           (if supported by the OPTFILE); also switch to IEEE numerics.
4d1f7e1a03 Jean*0142     -gsl | --gsl
36e14999eb Jean*0143           Use GSL to control floating point rounding and precision
23f21461eb Jean*0144 
                0145     -mpi | --mpi
36e14999eb Jean*0146           Include MPI header files and link to MPI libraries
23f21461eb Jean*0147     -mpi=PATH | --mpi=PATH
36e14999eb Jean*0148           Include MPI header files and link to MPI libraries using MPI_ROOT
                0149           set to PATH. i.e. Include files from \$PATH/include, link to libraries
                0150           from \$PATH/lib and use binaries from \$PATH/bin.
23f21461eb Jean*0151 
                0152     -omp | --omp
fb8a3f8f0e Jean*0153           Activate OpenMP code
23f21461eb Jean*0154     -omp=OMPFLAG | --omp=OMPFLAG
36e14999eb Jean*0155           Activate OpenMP code + use Compiler option OMPFLAG
23f21461eb Jean*0156 
                0157     -es | --es | -embed-source | --embed-source
36e14999eb Jean*0158           Embed a tarball containing the full source code
                0159           (including the Makefile, etc.) used to build the
                0160           executable [off by default]
23f21461eb Jean*0161 
                0162     -ds | --ds
36e14999eb Jean*0163           Report genmake internal variables status (DUMPSTATE)
                0164           to file "genmake_state" (for debug purpose)
23f21461eb Jean*0165 
                0166   While it is most often a single word, the "NAME" variables specified
                0167   above can in many cases be a space-delimited string such as:
                0168 
                0169     --enable pkg1   --enable 'pkg1 pkg2'   --enable 'pkg1 pkg2 pkg3'
                0170     -mods=dir1   -mods='dir1'   -mods='dir1 dir2 dir3'
                0171     -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
                0172 
                0173   which, depending upon your shell, may need to be single-quoted.
                0174 
516b08a580 jm-c 0175   For more detailed genmake documentation, please see section "Building the model"
                0176     (under "Getting Started") at:  https://mitgcm.readthedocs.io/
23f21461eb Jean*0177 
                0178 EOF
516b08a580 jm-c 0179 #- full link directly to section 3.5:
                0180 #https://mitgcm.readthedocs.io/en/latest/getting_started/getting_started.html#building-the-model
23f21461eb Jean*0181 
                0182     exit 1
                0183 }
                0184 
6d54cf9ca1 Ed H*0185 # Search for particular CPP #cmds associated with packages
                0186 # usage: test_for_package_in_cpp_options CPP_file package_name
                0187 test_for_package_in_cpp_options() {
                0188     cpp_options=$1
                0189     pkg=$2
e8e03c465c Jean*0190     test_for_string_in_file $cpp_options "^ *# *define *\<ALLOW_$pkg\>"
                0191     test_for_string_in_file $cpp_options "^ *# *undef *\<ALLOW_$pkg\>"
                0192     test_for_string_in_file $cpp_options "^ *# *define *\<DISABLE_$pkg\>"
                0193     test_for_string_in_file $cpp_options "^ *# *undef *\<DISABLE_$pkg\>"
40f7a33215 Alis*0194 }
                0195 
                0196 # Search for particular CPP #cmds associated with MPI
                0197 # usage: test_for_mpi_in_cpp_eeoptions CPP_file
                0198 test_for_mpi_in_cpp_eeoptions() {
                0199     cpp_options=$1
e8e03c465c Jean*0200     test_for_string_in_file $cpp_options "^ *# *define *\<ALLOW_USE_MPI\>"
                0201     test_for_string_in_file $cpp_options "^ *# *undef *\<ALLOW_USE_MPI\>"
40f7a33215 Alis*0202 }
                0203 
                0204 # Search for particular string in a file. Return 1 if detected, 0 if not
                0205 # usage: test_for_string_in_file file string
                0206 test_for_string_in_file() {
                0207     file=$1
                0208     strng=$2
e8e03c465c Jean*0209     grep "$strng" $file > /dev/null 2>&1
6d54cf9ca1 Ed H*0210     RETVAL=$?
                0211     if test "x${RETVAL}" = x0 ; then
13fa7032ba Ed H*0212         printf "Error: In $file there is an illegal line: "
36e14999eb Jean*0213         grep -i "$strng" $file
d54f5b7a0d Ed H*0214         exit 99
6d54cf9ca1 Ed H*0215     fi
40f7a33215 Alis*0216     return 0
6d54cf9ca1 Ed H*0217 }
                0218 
                0219 # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to
                0220 # the package list.
                0221 expand_pkg_groups() {
                0222     new_packages=
                0223     if test -r $PKG_GROUPS ; then
7deef35259 Jean*0224         cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > $TMP.p1
                0225         cat $TMP.p1 | $AWK '(NF>2 && $2==":"){ print $0 }' > $TMP.p2
6d54cf9ca1 Ed H*0226         matched=0
                0227         for i in $PACKAGES ; do
7deef35259 Jean*0228             line=`grep "^ *$i" $TMP.p2`
6d54cf9ca1 Ed H*0229             RETVAL=$?
                0230             if test "x$RETVAL" = x0 ; then
                0231                 matched=1
3e661b1a92 Ed H*0232                 replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`
a5a3c4e100 Jean*0233                 echo "    replacing \"$i\" with:$replace"
6d54cf9ca1 Ed H*0234                 new_packages="$new_packages $replace"
                0235             else
                0236                 new_packages="$new_packages $i"
                0237             fi
                0238         done
                0239         PACKAGES=$new_packages
7deef35259 Jean*0240         rm -f $TMP.p[1,2]
d3d6cca041 Alis*0241         return $matched
6d54cf9ca1 Ed H*0242     else
                0243         echo "Warning: can't read package groups definition file: $PKG_GROUPS"
                0244     fi
                0245 }
6aec5d9846 Ed H*0246 
5bb11ad8a0 Ed H*0247 #  Check for broken environments (eg. cygwin, MacOSX w/HFS+) that
                0248 #  cannot distinguish [*.F/*.F90] from [*.f/*.f90] files.
                0249 check_for_broken_Ff()  {
3eb03232c2 Ed H*0250     #  Do we have defaults for $FS and/or $FS90 ?
                0251     tfs=f
                0252     tfs9=f90
                0253     if test "x$FS" != x ; then
                0254         tfs="$FS"
                0255     fi
                0256     if test "x$FS90" != x ; then
                0257         tfs9="$FS90"
                0258     fi
                0259 
5bb11ad8a0 Ed H*0260     #  First check the ability to create a *.F/.f pair.
3eb03232c2 Ed H*0261     cat <<EOF >> genmake_hello.F
5bb11ad8a0 Ed H*0262       program hello
                0263       write(*,*) 'hi'
                0264       stop
                0265       end
                0266 EOF
3eb03232c2 Ed H*0267     cp genmake_hello.F "genmake_hello."$tfs > /dev/null 2>&1
5bb11ad8a0 Ed H*0268     RETVAL=$?
                0269     if test "x$RETVAL" != x0 ; then
3eb03232c2 Ed H*0270         if test "x$FS" = x ; then
a4cdb0c6f0 Ed H*0271             FS='for'
                0272             FS90='fr9'
3eb03232c2 Ed H*0273             check_for_broken_Ff
                0274         else
                0275             cat <<EOF 2>&1
5be35a17af Jean*0276 ERROR: Your file system cannot distinguish between *.F and *.f files
                0277   (fails the "cp" test) and this program cannot find a suitable
                0278   replacement extension.  Please try a different build environment or
3eb03232c2 Ed H*0279   contact the <MITgcm-support@mitgcm.org> list for help.
                0280 
                0281 EOF
                0282             exit -1
                0283         fi
5bb11ad8a0 Ed H*0284         return
                0285     fi
3eb03232c2 Ed H*0286     rm -f genmake_hello.*
5bb11ad8a0 Ed H*0287 
3eb03232c2 Ed H*0288     #  Check the ability of ${MAKE} and ${LN} to use the current set
                0289     #  of extensions.
                0290     cat <<EOF >> genmake_hello.F
                0291       program hello
                0292       write(*,*) 'hi'
                0293       stop
                0294       end
                0295 EOF
3ce2ed8dc5 Ed H*0296     test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
                0297     cat <<EOF >> $MAKEFILE
5bb11ad8a0 Ed H*0298 .SUFFIXES:
7a76cc695e Ed H*0299 .SUFFIXES: .$tfs .F
                0300 .F.$tfs:
                0301         $LN \$< \$@
5bb11ad8a0 Ed H*0302 EOF
18371f2c52 Jean*0303     $MAKE -f $MAKEFILE "genmake_hello."$tfs > /dev/null 2>&1
5bb11ad8a0 Ed H*0304     RETVAL=$?
355771feeb Ed H*0305     if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then
3eb03232c2 Ed H*0306         if test "x$FS" = x ; then
a4cdb0c6f0 Ed H*0307             FS='for'
                0308             FS90='fr9'
3eb03232c2 Ed H*0309             check_for_broken_Ff
                0310         else
776d1c0efd Jean*0311             echo "ERROR: test: '$MAKE -f $MAKEFILE genmake_hello.$tfs' Failed"
                0312             echo "       see simple makefile: '$MAKEFILE' (left here)"
                0313             echo "  Please check (1) your '$MAKE' command, (2) your '$LN' command"
                0314             echo "           and (3) the allowed sufix '.F' and '.$tfs' in makefile"
                0315             echo "  or contact the <MITgcm-support@mitgcm.org> list for help."
                0316             echo ""
3eb03232c2 Ed H*0317             exit -1
                0318             return
                0319         fi
5bb11ad8a0 Ed H*0320     fi
3ce2ed8dc5 Ed H*0321     rm -f genmake_hello.* $MAKEFILE
                0322     test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
5bb11ad8a0 Ed H*0323 
3eb03232c2 Ed H*0324     #  If we make it here, use the extensions
                0325     FS=$tfs
                0326     FS90=$tfs9
                0327     return
5bb11ad8a0 Ed H*0328 }
                0329 
072ddee95c Ed H*0330 look_for_makedepend()  {
6aec5d9846 Ed H*0331 
b0867682b1 Ed H*0332     #  The "original" makedepend is part of the Imake system that is
                0333     #  most often distributed with XFree86 or with an XFree86 source
                0334     #  package.  As a result, many machines (eg. generic Linux) do not
                0335     #  have a system-default "makedepend" available.  For those
                0336     #  systems, we have two fall-back options:
                0337     #
                0338     #    1) a makedepend implementation shipped with the cyrus-imapd
                0339     #       package:  ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
88a755a5b2 Jean*0340     #    2) a local tools/xmakedepend shell script
b0867682b1 Ed H*0341     #
                0342     #  So the choices are, in order:
                0343     #    1) use the user-specified program
88a755a5b2 Jean*0344     #    2) use the local xmakedepend script (get all dependencies, but slower)
                0345     #    3) use a system-wide default
                0346     #    4) locally build and use the cyrus makedepend
                0347     #             (faster, but can miss some dependencies)
b0867682b1 Ed H*0348     #
b353a7c6c6 Jean*0349     echo >> $LOGFILE
                0350     echo "running: look_for_makedepend()" >> $LOGFILE
                0351     if test "x${MAKEDEPEND}" != x ; then
                0352         echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1
                0353         RETVAL=$?
                0354         if test x"$RETVAL" = x0 ; then
                0355             build_cyrus_makedepend
                0356             RETVAL=$?
                0357             if test "x$RETVAL" != x0 ; then
88a755a5b2 Jean*0358                 echo "WARNING: unable to build cyrus-makedepend. Try other 'makedepend'"
b353a7c6c6 Jean*0359                 MAKEDEPEND=
                0360             fi
                0361         else
9131c4d333 Jean*0362             echo "${MAKEDEPEND}" | grep 'tools.xmakedepend' > /dev/null 2>&1
                0363             RETVAL=$?
                0364             if test "x$RETVAL" = x0 ; then
                0365                 MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
                0366             fi
b353a7c6c6 Jean*0367             echo " -->     MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
                0368         fi
                0369     fi
19d7e59ef3 Alis*0370     if test "x${MAKEDEPEND}" = x ; then
3ce2ed8dc5 Ed H*0371         test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
                0372         #  echo 'MAKEFILE="'$MAKEFILE'"'
                0373         cat <<EOF >> $MAKEFILE
                0374 #   THIS IS A TEST MAKEFILE GENERATED BY "genmake2"
                0375 #
5be35a17af Jean*0376 #   Some "makedepend" implementations will die if they cannot
                0377 #   find a Makefile -- so this file is here to gives them an
3ce2ed8dc5 Ed H*0378 #   empty one to find and parse.
                0379 EOF
925891ca7b Ed H*0380         cat <<EOF >> genmake_tc.f
a4cdb0c6f0 Ed H*0381       program test
                0382       write(*,*) 'test'
                0383       stop
                0384       end
                0385 EOF
88a755a5b2 Jean*0386         $ROOTDIR/tools/xmakedepend -f $MAKEFILE genmake_tc.f > /dev/null 2>&1
b681e6be2e Mart*0387         RV1=$?
88a755a5b2 Jean*0388         which makedepend > /dev/null 2>&1
                0389         RV2=$?
                0390         if test "x${RV2}" = x0 ; then
                0391             makedepend -f $MAKEFILE genmake_tc.f > /dev/null 2>&1
                0392             RV3=$? ; loc_msg='not working.'
                0393         else RV3=$RV2 ; loc_msg='not found.'
                0394         fi
3ce2ed8dc5 Ed H*0395         test -f $MAKEFILE  &&  rm -f $MAKEFILE
                0396         test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
88a755a5b2 Jean*0397         echo "  check makedepend (local: $RV1, system: $RV2, $RV3)"
                0398         if test "x${RV1}" = x0 ; then
                0399             MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
                0400             echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
                0401         elif test "x${RV3}" = x0 ; then
                0402             echo "    local tools/xmakedepend not working. Use system-default makedepend"
925891ca7b Ed H*0403             MAKEDEPEND=makedepend
b353a7c6c6 Jean*0404             echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
925891ca7b Ed H*0405         else
88a755a5b2 Jean*0406             echo "    local tools/xmakedepend not working; system-default makedepend $loc_msg"
                0407             echo -n "    Try to build cyrus-makedepend ..."
925891ca7b Ed H*0408             #  Try to build the cyrus implementation
b0dc3e31a0 Ed H*0409             build_cyrus_makedepend
925891ca7b Ed H*0410             RETVAL=$?
88a755a5b2 Jean*0411             if test "x$RETVAL" = x0 ; then
                0412                 echo "  Works"
                0413             else
                0414                 echo "  Fails" ; echo "" >> $LOGFILE
                0415                 echo "ERROR: no working makedepend found ; look_for_makedepend FAILED" | tee -a $LOGFILE
                0416                 echo ""
                0417                 exit -1
                0418                 return
925891ca7b Ed H*0419             fi
b0dc3e31a0 Ed H*0420         fi
19d7e59ef3 Alis*0421     fi
072ddee95c Ed H*0422 }
                0423 
b0dc3e31a0 Ed H*0424 build_cyrus_makedepend()  {
b353a7c6c6 Jean*0425     echo >> $LOGFILE
                0426     echo "running: build_cyrus_makedepend()" >> $LOGFILE
b0dc3e31a0 Ed H*0427     rm -f ./genmake_cy_md
                0428     (
                0429         cd $ROOTDIR/tools/cyrus-imapd-makedepend  \
                0430             &&  ./configure > /dev/null 2>&1  \
621623385c Jean*0431             &&  $MAKE > /dev/null 2>&1
b0dc3e31a0 Ed H*0432         if test -x ./makedepend.exe ; then
                0433             $LN ./makedepend.exe ./makedepend
                0434         fi
                0435         ./makedepend ifparser.c > /dev/null 2>&1  \
                0436             &&  echo "true"
                0437     ) > ./genmake_cy_md
                0438     grep true ./genmake_cy_md > /dev/null 2>&1
                0439     RETVAL=$?
                0440     rm -f ./genmake_cy_md
                0441     if test "x$RETVAL" = x0 ; then
                0442         MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
b353a7c6c6 Jean*0443         echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
b0dc3e31a0 Ed H*0444         return 0
                0445     else
b353a7c6c6 Jean*0446         echo "WARNING: fail to build cyrus-imapd-makedepend" >> $LOGFILE
b0dc3e31a0 Ed H*0447         return 1
                0448     fi
                0449 }
                0450 
ab504a3a96 Ed H*0451 build_embed_encode()
                0452 {
                0453     printf "  building the embed-encode utility...  "
                0454     if test ! -e "$ROOTDIR/tools/embed_encode/encode_files" ; then
36e14999eb Jean*0455         if test ! -d "$ROOTDIR/tools/embed_encode" ; then
                0456             echo
                0457             echo "    Error: can't locate \"$ROOTDIR/tools/embed_encode\""
                0458             echo
                0459             EMBED_SRC=f
ab504a3a96 Ed H*0460             return 1
36e14999eb Jean*0461         fi
ab504a3a96 Ed H*0462         clist="cc gcc c89 $CC"
5be35a17af Jean*0463         for ic in $clist ; do
ab504a3a96 Ed H*0464             comm="$ic -o encode_files encode_files.c"
                0465             ( cd $ROOTDIR/tools/embed_encode && $comm ) > /dev/null 2>&1
                0466             RETVAL=$?
                0467             if test "x$RETVAL" = x0 ; then
                0468                 echo "OK"
                0469                 return 0
                0470             fi
                0471         done
                0472         echo
                0473         echo "    Error: unable to build $ROOTDIR/embed_encode/encode_files"
                0474         echo "      so it has been disabled"
                0475         echo
                0476         EMBED_SRC=f
                0477         return 1
                0478     fi
                0479     echo "OK"
                0480 }
                0481 
0e2704be3d Jean*0482 #  look for possible C compilers
                0483 look_for_C_compilers() {
65377ddbcb Jean*0484     echo >> $LOGFILE
                0485     echo "running: look_for_C_compilers()" >> $LOGFILE
                0486     rm -f ./genmake_hello.c  ./genmake_hello
                0487     cat >> genmake_hello.c << EOF
e8a04cb645 Ed H*0488 #include <stdio.h>
                0489 int main(int argc, char **argv) {
                0490   printf("Hello!\n");
                0491   return 0;
                0492 }
                0493 EOF
65377ddbcb Jean*0494     tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc icc"
                0495     p_CC=
                0496     for c in $tmp ; do
                0497         COMM="$c $CFLAGS -o genmake_hello genmake_hello.c"
                0498         echo $COMM >> $LOGFILE
                0499         $COMM >> $LOGFILE 2>&1
e8a04cb645 Ed H*0500         RETVAL=$?
                0501         if test "x${RETVAL}" = x0 ; then
65377ddbcb Jean*0502             echo " $c test successful" >> $LOGFILE
e8a04cb645 Ed H*0503             p_CC="$p_CC $c"
                0504         fi
                0505     done
                0506     rm -f ./genmake_hello.c ./genmake_hello
                0507     if test "x${p_CC}" = x ; then
                0508         cat 1>&2 <<EOF
                0509 
                0510 Error: No C compilers were found in your path.  Please specify one using:
                0511 
                0512     1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
                0513     2) the CC or MITGCM_CC environment variables.
                0514 
                0515 EOF
                0516         exit 1
                0517     else
65377ddbcb Jean*0518         echo "  The possible C compilers found in your path are: $p_CC" | tee -a $LOGFILE
e8a04cb645 Ed H*0519         if test "x$CC" = x ; then
                0520             CC=`echo $p_CC | $AWK '{print $1}'`
                0521             echo "  Setting C compiler to: "$CC
                0522         fi
                0523     fi
65377ddbcb Jean*0524     echo " --> set CC='$CC'" >> $LOGFILE
0e2704be3d Jean*0525 }
                0526 
                0527 # Guess possible config options for this host
                0528 find_possible_optfile()  {
                0529 
23f21461eb Jean*0530     echo >> $LOGFILE
                0531     echo "running: find_possible_optfile()" >> $LOGFILE
0e2704be3d Jean*0532     tmp1=`uname`"_"`uname -m`
                0533     tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
                0534     tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
726aa03a13 Gael*0535     tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|' | sed -e 's|aarch64|arm64|'`
0e2704be3d Jean*0536     tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
                0537     tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
                0538     PLATFORM=$tmp3
                0539     echo $PLATFORM | grep cygwin > /dev/null 2>&1  &&  PLATFORM=cygwin_ia32
                0540     OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
23f21461eb Jean*0541     echo "  The platform appears to be:  $PLATFORM" | tee -a $LOGFILE
e8a04cb645 Ed H*0542 
                0543     #================================================================
                0544     #  look for possible FORTRAN compilers
23f21461eb Jean*0545     echo "  look for possible FORTRAN compilers" >> $LOGFILE
                0546     tmp="$MITGCM_FC $FC efc gfortran g77 f77 pgf77 pgf95 ifc ifort f90 f95 mpif77 mpf77 mpxlf95 g95"
6aec5d9846 Ed H*0547     p_FC=
23f21461eb Jean*0548     rm -f ./genmake_hello.f
                0549     cat >> genmake_hello.f <<EOF
f10e3a8bdd Ed H*0550       program hello
                0551       do i=1,3
                0552         print *, 'hello world : ', i
                0553       enddo
                0554       end
                0555 EOF
23f21461eb Jean*0556     for f in $tmp ; do
                0557         COMM="$f -o genmake_hello genmake_hello.f"
                0558         echo $COMM >> $LOGFILE
                0559         $COMM >> $LOGFILE 2>&1
6aec5d9846 Ed H*0560         RETVAL=$?
                0561         if test "x${RETVAL}" = x0 ; then
23f21461eb Jean*0562             echo " $f test successful" >> $LOGFILE
                0563             p_FC="$p_FC $f"
6aec5d9846 Ed H*0564         fi
                0565     done
23f21461eb Jean*0566     rm -f ./genmake_hello.f ./genmake_hello
6aec5d9846 Ed H*0567     if test "x${p_FC}" = x ; then
f10e3a8bdd Ed H*0568         cat 1>&2 <<EOF
                0569 
                0570 Error: No Fortran compilers were found in your path.  Please specify one using:
                0571 
                0572     1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
                0573     2) a command-line option (eg. "-fc NAME"), or
e8a04cb645 Ed H*0574     3) the FC or MITGCM_FC environment variables.
f10e3a8bdd Ed H*0575 
                0576 EOF
                0577         exit 1
6aec5d9846 Ed H*0578     else
23f21461eb Jean*0579         echo "  The possible FORTRAN compilers found in your path are: $p_FC" | tee -a $LOGFILE
611257dd1a Ed H*0580     fi
                0581 
                0582     #  Use the first of the compilers found in the current PATH
                0583     #  that has a correctly-named optfile
                0584     if test "x$OPTFILE" = x  -a  "x$FC" = x ; then
                0585         for i in $p_FC ; do
                0586             OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
                0587             if test -r $OPTFILE ; then
23f21461eb Jean*0588                 echo "  Setting OPTFILE to: "$OPTFILE | tee -a $LOGFILE
611257dd1a Ed H*0589                 break
                0590             fi
                0591         done
6aec5d9846 Ed H*0592     fi
                0593 
c1324e0980 Alis*0594     if test "x$OPTFILE" = x ; then
                0595         OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
                0596         if test ! -r $OPTFILE ; then
776d1c0efd Jean*0597              echo "  I looked for the file "$OPTFILE" but did not find it"
                0598         fi
c1324e0980 Alis*0599     fi
0e2704be3d Jean*0600 
f10e3a8bdd Ed H*0601     if test "x$OPTFILE" = x ; then
                0602         cat 1>&2 <<EOF
                0603 
                0604 Error: No options file was found in:  $ROOTDIR/tools/build_options/
                0605   that matches this platform ("$PLATFORM") and the compilers found in
                0606   your path.  Please specify an "optfile" using:
                0607 
                0608     1) the command line (eg. "-optfile=path/to/OPTFILE"), or
                0609     2) the MITGCM_OF environment variable.
                0610 
516b08a580 jm-c 0611   If you need help, please contact the <MITgcm-support@mitgcm.org> list.
f10e3a8bdd Ed H*0612 
                0613 EOF
                0614         exit 1
6aec5d9846 Ed H*0615     fi
                0616 }
                0617 
f7aaac66f3 jm-c 0618 #  Just try to use FC, report failed attempt as a Warning
                0619 check_fortran_compiler() {
                0620     echo -n "  check Fortran Compiler... "
                0621     echo "" >> $LOGFILE
                0622     echo "running: check_fortran_compiler" >> $LOGFILE
                0623     FC_CHECK=-1
                0624     rm -f ./genmake_tcomp.f
                0625     cat >> genmake_tcomp.f <<EOF
                0626       program hello
                0627       integer i
                0628       do i=1,3
                0629         print *, 'hello world : ', i
                0630       enddo
                0631       end
                0632 EOF
                0633     COMM="$FC $FFLAGS $FOPTIM -c genmake_tcomp.f"
                0634     echo ' '$COMM >> $LOGFILE
                0635     $COMM >> $LOGFILE 2>&1
                0636     RETVAL=$?
                0637     if test "x$RETVAL" != x0 ; then
                0638         FC_CHECK=0
                0639         echo "" >> $LOGFILE
                0640         echo " Warning: FORTRAN compiler test fails to compile" >> $LOGFILE
                0641         echo -n " fail to compile"
                0642     fi
                0643     if test $FC_CHECK = '-1' ; then
                0644         COMM="$LINK $FFLAGS $FOPTIM -o genmake_tcomp genmake_tcomp.o $LIBS"
                0645         echo ' '$COMM >> $LOGFILE
                0646         $COMM >> $LOGFILE 2>&1
                0647         RETVAL=$?
                0648     else RETVAL=0 ; fi
                0649     if test "x$RETVAL" != x0 ; then
                0650         FC_CHECK=1
                0651         echo "" >> $LOGFILE
                0652         echo " Warning: FORTRAN compiler test fails to link" >> $LOGFILE
                0653         echo -n " fail to generate executable"
                0654     fi
                0655     if test $FC_CHECK = '-1' -a -x genmake_tcomp ; then
                0656         if test "x$MPI" = 'xtrue' ; then
516b08a580 jm-c 0657           which mpirun > /dev/null 2>&1
                0658           RETVAL=$?
                0659           if test "x${RETVAL}" = x0 ; then
6c0f1b57d6 Oliv*0660             COMM="mpirun -np 1 ./genmake_tcomp"
516b08a580 jm-c 0661           else
                0662             which mpiexec > /dev/null 2>&1
                0663             RETVAL=$?
                0664             if test "x${RETVAL}" = x0 ; then
                0665               COMM="mpiexec -np 1 ./genmake_tcomp"
                0666             else
                0667               FC_CHECK=4
                0668               echo "" >> $LOGFILE
                0669               echo " warning: MPI run command not found ==> skip run-test check" >> $LOGFILE
                0670              #echo -n " fail to generate executable"
                0671             fi
                0672           fi
f7aaac66f3 jm-c 0673         else
                0674             COMM="./genmake_tcomp"
                0675         fi
516b08a580 jm-c 0676     elif test $FC_CHECK = '-1' ; then
                0677         FC_CHECK=2
                0678         echo 'WARNING: missing executable from FORTRAN compiler test' >> $LOGFILE
                0679         echo -n " fail to generate executable"
                0680     fi
                0681     if test $FC_CHECK = '-1' ; then
f7aaac66f3 jm-c 0682         echo ' '$COMM >> $LOGFILE
                0683         $COMM >> $LOGFILE 2>&1
                0684         RETVAL=$?
                0685         if test "x$RETVAL" != x0 ; then
                0686            FC_CHECK=3
                0687           #echo -n " fail to run"
                0688         else
516b08a580 jm-c 0689            FC_CHECK=5
f7aaac66f3 jm-c 0690            echo -n " pass"
                0691         fi
                0692     fi
                0693     rm -f genmake_tcomp.* genmake_tcomp
516b08a580 jm-c 0694     echo " --> set FC_CHECK= $FC_CHECK /5" >> $LOGFILE
                0695     echo "  (set FC_CHECK=${FC_CHECK}/5)"
f7aaac66f3 jm-c 0696 }
                0697 
fea3e7d209 Jean*0698 #  Do a local copy of MPI headers files (in local dir ./mpi_headers/) after
                0699 #  checking for additional included headers (in case of chain of included header)
                0700 mpi_headers_do_local_copy() {
                0701 
                0702     dBug=0
cd15dc9a7a Jean*0703     rm -rf ./mpi_headers
                0704     if test -d $MPIINCLUDEDIR ; then
                0705 
                0706         #----- check for additional headers (chain of included headers)
                0707         echo -n '  Check MPI headers ... '
                0708         listIni=$MPI_HEADER_FILES
                0709         echo $listIni | grep "\<mpif.h\>" > /dev/null 2>&1
                0710         outp=$?
                0711         #- always check mpif.h (the only mpi-header included in standard MITgcm code)
                0712         if test $outp != 0 ; then listIni="mpif.h $listIni" ; fi
                0713         if test $dBug = 1 ; then echo "listIni='$listIni'" ; fi
                0714 
                0715         doCheck=1 ; list2copy='' ; list2check=$listIni
                0716         while test $doCheck = 1 ; do
                0717           newList=''
                0718           for i in $list2check ; do
                0719             if test -f $MPIINCLUDEDIR/$i ; then
                0720               newInc=`grep '^ *include ' $MPIINCLUDEDIR/$i | \
fea3e7d209 Jean*0721                 sed -e 's/^ *include //' -e 's/\!.*$//' -e "s/'//g"  -e 's/\"//g'`
cd15dc9a7a Jean*0722               if test $dBug = 1 ; then echo -n "checking $i : newInc='$newInc'" ; fi
                0723               for j in $newInc ; do
                0724                 echo $listIni $list2copy $newList | grep "\<$j\>" > /dev/null 2>&1
                0725                 outp=$?
                0726                 if test $outp != 0 ; then
                0727                   if test $dBug = 1 ; then echo -n " ; adding $j" ; fi
                0728                   newList="$newList $j"
                0729                 fi
                0730               done
                0731               if test $dBug = 1 ; then echo "" ; fi
                0732             fi
                0733           done
                0734           if test "x$newList" = x ; then doCheck=0
                0735           else list2check=$newList ; list2copy="$list2copy $newList"
                0736           fi
fea3e7d209 Jean*0737         done
cd15dc9a7a Jean*0738         list2copy="$MPI_HEADER_FILES $list2copy"
                0739         if test $dBug = 1 ; then echo "list2copy='$list2copy'" ; fi
                0740 
                0741         #----- create local mpi_headers dir if we have files to copy
                0742         mkListInc=`echo $list2copy | wc -w`
                0743         if test $mkListInc != 0 ; then
                0744           echo 'create local "./mpi_headers" dir'
                0745           mkdir -p ./mpi_headers
                0746           INCLUDES="-I./mpi_headers $INCLUDES"
                0747           mkListInc=1
fea3e7d209 Jean*0748         fi
cd15dc9a7a Jean*0749         if test "x$LOCAL_MPI_HEADERS" != x ; then mkListInc=0 ; fi
                0750 
                0751         #----- make local copy and update LOCAL_MPI_HEADERS (if not already set)
                0752         for i in $list2copy ; do
                0753           if test -f $MPIINCLUDEDIR/$i ; then
fea3e7d209 Jean*0754             cp -p $MPIINCLUDEDIR/$i ./mpi_headers
                0755             if test $i = 'mpif.h' ; then
                0756                 perl -i -pe 's/MPI_DISPLACEMENT_CURRENT=-1_8/MPI_DISPLACEMENT_CURRENT=-1/g' mpi_headers/mpif.h
                0757             fi
cd15dc9a7a Jean*0758             if test $mkListInc = 2 ; then
fea3e7d209 Jean*0759                 LOCAL_MPI_HEADERS="$LOCAL_MPI_HEADERS ./mpi_headers/$i"
                0760             fi
cd15dc9a7a Jean*0761             if test $mkListInc = 1 ; then
                0762                 LOCAL_MPI_HEADERS="./mpi_headers/$i" ; mkListInc=2
fea3e7d209 Jean*0763             fi
cd15dc9a7a Jean*0764           fi
                0765         done
                0766     else
                0767         echo "WARNING: MPIINCLUDEDIR='$MPIINCLUDEDIR' is not a directory"
                0768         echo "WARNING: => skip checking for MPI headers (no ./mpi_headers dir)"
                0769 #       exit -1
                0770     fi
fea3e7d209 Jean*0771 }
                0772 
6aec5d9846 Ed H*0773 #  Parse the package dependency information
                0774 get_pdepend_list()  {
                0775 
                0776     #  strip the comments and then convert the dependency file into
                0777     #  two arrays: PNAME, DNAME
                0778     cat $1 | sed -e 's/#.*$//g' \
bf318dd62d Jean*0779         | $AWK 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \
6aec5d9846 Ed H*0780         > ./.pd_tmp
bf318dd62d Jean*0781     RETVAL=$?
                0782     if test ! "x${RETVAL}" = x0 ; then
a5a3c4e100 Jean*0783       echo "Error: unable to parse package dependencies -- please check PKG_DEPEND=\"$1\""
bf318dd62d Jean*0784       exit 1
                0785     fi
12417e3119 Jean*0786     #echo "---- content of tmp file '.pd_tmp' :" ; cat .pd_tmp ; echo "---- end of file"
3021a6b819 Ed H*0787     . ./.pd_tmp
6aec5d9846 Ed H*0788     rm -f ./.pd_tmp
                0789 }
                0790 
8636935175 Ed H*0791 #  Build a CPP macro to automate calling C routines from FORTRAN
                0792 get_fortran_c_namemangling()  {
353dc202ae Ed H*0793 
                0794     #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
                0795     if test ! "x$FC_NAMEMANGLE" = x ; then
776d1c0efd Jean*0796         return 0
353dc202ae Ed H*0797     fi
0e2704be3d Jean*0798     echo " running: get_fortran_c_namemangling()" >> $LOGFILE
353dc202ae Ed H*0799 
8636935175 Ed H*0800     default_nm="#define FC_NAMEMANGLE(X) X ## _"
5be35a17af Jean*0801 
8636935175 Ed H*0802     cat > genmake_test.c <<EOF
                0803 void tcall( char * string ) { tsub( string ); }
                0804 EOF
0e2704be3d Jean*0805     COMM="$CC $CFLAGS -c genmake_test.c"
                0806     echo ' '$COMM >> $LOGFILE
                0807     $COMM >> $LOGFILE 2>&1
8636935175 Ed H*0808     RETVAL=$?
                0809     if test "x$RETVAL" != x0 ; then
                0810         FC_NAMEMANGLE=$default_nm
683b8f029b Jean*0811         cat <<EOF>> $LOGFILE
06c46c472d Ed H*0812 
0e2704be3d Jean*0813  WARNING: C test compile fails
                0814  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
                0815  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
06c46c472d Ed H*0816 EOF
8636935175 Ed H*0817         return 1
                0818     fi
e8a04cb645 Ed H*0819     c_tcall=`nm genmake_test.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
8636935175 Ed H*0820     RETVAL=$?
                0821     if test "x$RETVAL" != x0 ; then
                0822         FC_NAMEMANGLE=$default_nm
683b8f029b Jean*0823         cat <<EOF>> $LOGFILE
06c46c472d Ed H*0824 
0e2704be3d Jean*0825  WARNING: The "nm" command failed.
                0826  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
                0827  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
06c46c472d Ed H*0828 EOF
8636935175 Ed H*0829         return 1
                0830     fi
6554790d1c Ed H*0831     cat > genmake_tcomp.$FS <<EOF
8636935175 Ed H*0832       subroutine tcall( string )
                0833       character*(*) string
                0834       call tsub( string )
                0835       end
                0836 EOF
0e2704be3d Jean*0837     COMM="$FC $FFLAGS -c genmake_tcomp.$FS"
                0838     echo ' '$COMM >> $LOGFILE
                0839     $COMM >> $LOGFILE 2>&1
8636935175 Ed H*0840     RETVAL=$?
                0841     if test "x$RETVAL" != x0 ; then
                0842         FC_NAMEMANGLE=$default_nm
683b8f029b Jean*0843         cat <<EOF>> $LOGFILE
06c46c472d Ed H*0844 
0e2704be3d Jean*0845  WARNING: FORTRAN test compile fails -- please see '$LOGFILE'
                0846  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
                0847  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
06c46c472d Ed H*0848 EOF
8636935175 Ed H*0849         return 1
                0850     fi
e8a04cb645 Ed H*0851     f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
8636935175 Ed H*0852     RETVAL=$?
                0853     if test "x$RETVAL" != x0 ; then
                0854         FC_NAMEMANGLE=$default_nm
683b8f029b Jean*0855         cat <<EOF>> $LOGFILE
06c46c472d Ed H*0856 
0e2704be3d Jean*0857  WARNING: The "nm" command failed.
                0858  WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
                0859  WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
06c46c472d Ed H*0860 EOF
8636935175 Ed H*0861         return 1
                0862     fi
                0863 
                0864     c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
                0865     f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
                0866     c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
                0867     f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
                0868 
                0869     nmangle="X"
                0870     if test "x$c_a" != "x$f_a" ; then
                0871         comm="echo x$f_a | sed -e 's|x$c_a||'"
                0872         a=`eval $comm`
                0873         nmangle="$a ## $nmangle"
                0874     fi
                0875     if test "x$c_b" != "x$f_b" ; then
                0876         comm="echo x$f_b | sed -e 's|x$c_b||'"
                0877         b=`eval $comm`
                0878         nmangle="$nmangle ## $b"
                0879     fi
                0880 
                0881     FC_NAMEMANGLE="#define FC_NAMEMANGLE(X)  $nmangle"
63e5b59462 Ed H*0882 
                0883     #  cleanup the testing files
                0884     rm -f genmake_tcomp.* genmake_test.*
0e2704be3d Jean*0885 
                0886     echo " --> set FC_NAMEMANGLE='$FC_NAMEMANGLE'" >> $LOGFILE
8636935175 Ed H*0887 }
6aec5d9846 Ed H*0888 
06c46c472d Ed H*0889 check_HAVE_CLOC()  {
683b8f029b Jean*0890     echo >> $LOGFILE
                0891     echo "running: check_HAVE_CLOC()" >> $LOGFILE
06c46c472d Ed H*0892     get_fortran_c_namemangling
                0893     cat <<EOF > genmake_tc_1.c
                0894 $FC_NAMEMANGLE
                0895 #include <stdio.h>
                0896 #include <stdlib.h>
                0897 #include <unistd.h>
                0898 #include <assert.h>
                0899 #include <sys/time.h>
                0900 void FC_NAMEMANGLE(cloc) ( double *curtim )
                0901 {
                0902  struct timeval tv1;
                0903  gettimeofday(&tv1 , (void *)NULL );
                0904  *curtim =  (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
                0905  *curtim = *curtim/1.E6;
                0906 }
                0907 EOF
e89c0084d6 Mart*0908     COMM="$CC $CFLAGS -c genmake_tc_1.c"
683b8f029b Jean*0909     echo $COMM >> $LOGFILE
                0910     $COMM >> $LOGFILE 2>&1
06c46c472d Ed H*0911     RET_C=$?
6554790d1c Ed H*0912     cat <<EOF > genmake_tc_2.$FS
06c46c472d Ed H*0913       program hello
c899631d80 Ed H*0914       REAL*8 wtime
06c46c472d Ed H*0915       external cloc
                0916       call cloc(wtime)
                0917       print *," HELLO WORLD", wtime
f745933813 Ed H*0918       end
06c46c472d Ed H*0919 EOF
5e91cc7226 Mart*0920     COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
683b8f029b Jean*0921     echo $COMM >> $LOGFILE
                0922     $COMM >> $LOGFILE 2>&1
06c46c472d Ed H*0923     RET_F=$?
683b8f029b Jean*0924     test -x ./genmake_tc  &&  ./genmake_tc >> $LOGFILE 2>&1
06c46c472d Ed H*0925     RETVAL=$?
                0926     if test "x$RETVAL" = x0 ; then
                0927         HAVE_CLOC=t
                0928     fi
                0929     rm -f genmake_tc*
0e2704be3d Jean*0930     echo " --> set HAVE_CLOC='$HAVE_CLOC'" >> $LOGFILE
06c46c472d Ed H*0931 }
                0932 
b81731e160 Ed H*0933 check_HAVE_SIGREG()  {
1c82e4d566 Ed H*0934     if test ! "x$HAVE_SIGREG" = x ; then
                0935         return
                0936     fi
683b8f029b Jean*0937     echo >> $LOGFILE
                0938     echo "running: check_HAVE_SIGREG()" >> $LOGFILE
b81731e160 Ed H*0939     get_fortran_c_namemangling
                0940     cat <<EOF > genmake_tc_1.c
                0941 $FC_NAMEMANGLE
                0942 #include <stdlib.h>
                0943 #include <stdio.h>
                0944 #include <signal.h>
                0945 #include <errno.h>
                0946 #include <ucontext.h>
                0947 
                0948 int * ip;
                0949 
                0950 static void killhandler(
                0951     unsigned int sn, siginfo_t  si, struct ucontext *sc )
                0952 {
                0953     *ip = *ip + 1;
                0954     return;
                0955 }
                0956 
                0957 void FC_NAMEMANGLE(sigreg) (int * aip)
                0958 {
                0959     struct sigaction s;
b696d1568c Ed H*0960     ip = aip;
b81731e160 Ed H*0961     s.sa_flags = SA_SIGINFO;
                0962     s.sa_sigaction = (void *)killhandler;
                0963     if(sigaction (SIGTERM,&s,(struct sigaction *)NULL)) {
                0964         printf("Sigaction returned error = %d\n", errno);
                0965         exit(0);
                0966     }
                0967     return;
                0968 }
                0969 EOF
e89c0084d6 Mart*0970     COMM="$CC $CFLAGS -c genmake_tc_1.c"
683b8f029b Jean*0971     echo $COMM >> $LOGFILE
                0972     $COMM >> $LOGFILE 2>&1
b81731e160 Ed H*0973     RET_C=$?
                0974     cat <<EOF > genmake_tc_2.$FS
                0975       program hello
                0976       integer anint
                0977       common /iv/ anint
                0978       external sigreg
                0979       call sigreg(anint)
                0980       end
                0981 EOF
683b8f029b Jean*0982     cat genmake_tc_2.$FS >> $LOGFILE
b81731e160 Ed H*0983     COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
683b8f029b Jean*0984     echo $COMM >> $LOGFILE
                0985     $COMM >> $LOGFILE 2>&1
b81731e160 Ed H*0986     RETVAL=$?
                0987     if test "x$RETVAL" = x0 ; then
                0988         HAVE_SIGREG=t
                0989     fi
                0990     rm -f genmake_tc*
0e2704be3d Jean*0991     echo " --> set HAVE_SIGREG='$HAVE_SIGREG'" >> $LOGFILE
b81731e160 Ed H*0992 }
                0993 
df91541502 Ed H*0994 check_HAVE_SETRLSTK()  {
36459526ba Ed H*0995     if test ! "x$HAVE_SETRLSTK" = x ; then
                0996         return
                0997     fi
683b8f029b Jean*0998     echo >> $LOGFILE
                0999     echo "running: check_HAVE_SETRLSTK()" >> $LOGFILE
df91541502 Ed H*1000     get_fortran_c_namemangling
                1001     cat <<EOF > genmake_tc_1.c
                1002 $FC_NAMEMANGLE
                1003 #include <sys/time.h>
                1004 #include <sys/resource.h>
                1005 #include <unistd.h>
                1006 void FC_NAMEMANGLE(setrlstk) ()
                1007 {
                1008     struct rlimit rls;
                1009     rls.rlim_cur = RLIM_INFINITY;
                1010     rls.rlim_max = RLIM_INFINITY;
                1011     setrlimit(RLIMIT_STACK, &rls);
                1012     return;
                1013 }
                1014 EOF
e89c0084d6 Mart*1015     COMM="$CC $CFLAGS -c genmake_tc_1.c"
683b8f029b Jean*1016     echo $COMM >> $LOGFILE
                1017     $COMM >> $LOGFILE 2>&1
df91541502 Ed H*1018     RET_C=$?
                1019     cat <<EOF > genmake_tc_2.$FS
                1020       program hello
                1021       external setrlstk
                1022       call setrlstk()
                1023       end
                1024 EOF
683b8f029b Jean*1025     cat genmake_tc_2.$FS >> $LOGFILE
b566c11b33 Ed H*1026     COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
683b8f029b Jean*1027     echo $COMM >> $LOGFILE
                1028     $COMM >> $LOGFILE 2>&1
df91541502 Ed H*1029     RETVAL=$?
                1030     if test "x$RETVAL" = x0 ; then
                1031         HAVE_SETRLSTK=t
                1032     fi
                1033     rm -f genmake_tc*
0e2704be3d Jean*1034     echo " --> set HAVE_SETRLSTK='$HAVE_SETRLSTK'" >> $LOGFILE
df91541502 Ed H*1035 }
                1036 
ab11ba1276 Ed H*1037 check_HAVE_STAT()  {
683b8f029b Jean*1038     echo >> $LOGFILE
                1039     echo "running: check_HAVE_STAT()" >> $LOGFILE
ab11ba1276 Ed H*1040     get_fortran_c_namemangling
                1041     cat <<EOF > genmake_tc_1.c
                1042 $FC_NAMEMANGLE
                1043 #include <stdio.h>
                1044 #include <stdlib.h>
                1045 #include <unistd.h>
                1046 #include <sys/stat.h>
                1047 #include <sys/types.h>
                1048 void FC_NAMEMANGLE(tfsize) ( int *nbyte )
                1049 {
                1050     char name[512];
                1051     struct stat astat;
                1052 
                1053     name[0] = 'a'; name[1] = '\0';
                1054     if (! stat(name, &astat))
                1055         *nbyte = (int)(astat.st_size);
                1056     else
                1057         *nbyte = -1;
                1058 }
                1059 EOF
e89c0084d6 Mart*1060     COMM="$CC $CFLAGS -c genmake_tc_1.c"
683b8f029b Jean*1061     echo $COMM >> $LOGFILE
e89c0084d6 Mart*1062     $COMM >> genmake_tc.log 2>&1
ab11ba1276 Ed H*1063     RET_C=$?
6554790d1c Ed H*1064     cat <<EOF > genmake_tc_2.$FS
ab11ba1276 Ed H*1065       program hello
                1066       integer nbyte
                1067       call tfsize(nbyte)
                1068       print *," HELLO WORLD", nbyte
f745933813 Ed H*1069       end
ab11ba1276 Ed H*1070 EOF
683b8f029b Jean*1071     cat genmake_tc_2.$FS >> $LOGFILE
b566c11b33 Ed H*1072     COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
683b8f029b Jean*1073     echo $COMM >> $LOGFILE
b566c11b33 Ed H*1074     $COMM >> genmake_tc.log 2>&1
ab11ba1276 Ed H*1075     RETVAL=$?
                1076     if test "x$RETVAL" = x0 ; then
                1077         HAVE_STAT=t
                1078     fi
                1079     rm -f genmake_tc*
0e2704be3d Jean*1080     echo " --> set HAVE_STAT='$HAVE_STAT'" >> $LOGFILE
ab11ba1276 Ed H*1081 }
                1082 
4b2baec0be Ed H*1083 check_netcdf_libs()  {
92d9fec357 Ed H*1084     if test ! "x$SKIP_NETCDF_CHECK" = x ; then
                1085         return
                1086     fi
683b8f029b Jean*1087     echo >> $LOGFILE
                1088     echo "running: check_netcdf_libs()" >> $LOGFILE
54fd2d570d Ed H*1089     cat <<EOF > genmake_tnc.F
4b2baec0be Ed H*1090       program fgennc
                1091 #include "netcdf.inc"
92d9fec357 Ed H*1092 EOF
14693852dd Jean*1093    #if test ! "x$MPI" = x ; then
                1094    #    echo '#include "mpif.h"' >> genmake_tnc.F
                1095    #fi
54fd2d570d Ed H*1096     cat <<EOF >> genmake_tnc.F
4b2baec0be Ed H*1097       integer iret, ncid, xid
                1098       iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
                1099       IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
                1100       iret = nf_def_dim(ncid, 'X', 11, xid)
                1101       IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
                1102       iret = nf_close(ncid)
                1103       IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
                1104       end
                1105 EOF
6206da1394 Jean*1106     echo "===  genmake_tnc.F  >>>" > genmake_tnc.log
b566c11b33 Ed H*1107     cat genmake_tnc.F >> genmake_tnc.log
6206da1394 Jean*1108     echo "<<<  genmake_tnc.F  ===" >> genmake_tnc.log
4647ba122e Ed H*1109     RET_CPP=f
527acd427b Ed H*1110     COMM="cat genmake_tnc.F | $CPP $DEFINES $INCLUDES"
b566c11b33 Ed H*1111     echo "$COMM" >> genmake_tnc.log
1fa3d1c640 Davi*1112     eval $COMM > genmake_tnc.$FS 2>/dev/null  &&  RET_CPP=t
4647ba122e Ed H*1113     if test "x$RET_CPP" = xf ; then
                1114         echo "  WARNING: CPP failed to pre-process the netcdf test." \
d3c49ba21e Ed H*1115             >> genmake_tnc.log
4647ba122e Ed H*1116         echo "    Please check that \$INCLUDES is properly set." \
d3c49ba21e Ed H*1117             >> genmake_tnc.log
4647ba122e Ed H*1118     fi
b566c11b33 Ed H*1119     echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.$FS  \ " >> genmake_tnc.log
56758c9c48 Greg*1120     echo "  &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS" >> genmake_tnc.log
54fd2d570d Ed H*1121     $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
f49dfe24c3 Ed H*1122         &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
4b2baec0be Ed H*1123     RET_COMPILE=$?
683b8f029b Jean*1124     cat genmake_tnc.log >> $LOGFILE
2fc7466b7d Ed H*1125 
                1126     #EH3  Remove test program execution for machines that either disallow
                1127     #EH3  execution or cannot support it (eg. cross-compilers)
                1128     #EH3
                1129     #EH3 test -x ./genmake_tnc  &&  ./genmake_tnc >> genmake_tnc.log 2>&1
                1130     #EH3 RETVAL=$?
                1131     #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
                1132 
                1133     if test "x$RET_COMPILE" = x0 ; then
4b2baec0be Ed H*1134         HAVE_NETCDF=t
683b8f029b Jean*1135         echo "check_netcdf: successful" >> $LOGFILE
4b2baec0be Ed H*1136     else
2978624509 Ed H*1137         # try again with "-lnetcdf" added to the libs
6206da1394 Jean*1138         echo "==> try again with added '-lnetcdf'" > genmake_tnc.log
527acd427b Ed H*1139         echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log
d3c49ba21e Ed H*1140         echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
f49dfe24c3 Ed H*1141         echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
527acd427b Ed H*1142         cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null  \
54fd2d570d Ed H*1143             &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
f49dfe24c3 Ed H*1144             &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
2978624509 Ed H*1145         RET_COMPILE=$?
683b8f029b Jean*1146         echo >> $LOGFILE
                1147         cat genmake_tnc.log >> $LOGFILE
2fc7466b7d Ed H*1148         if test "x$RET_COMPILE" = x0 ; then
2978624509 Ed H*1149             LIBS="$LIBS -lnetcdf"
                1150             HAVE_NETCDF=t
683b8f029b Jean*1151             echo "check_netcdf: successful" >> $LOGFILE
979d83c92d Cons*1152         else
56758c9c48 Greg*1153         # try again with "-lnetcdff -lnetcdf" added to the libs
6206da1394 Jean*1154             echo "==> try again with added '-lnetcdff -lnetcdf'" > genmake_tnc.log
979d83c92d Cons*1155             echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log
                1156             echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
56758c9c48 Greg*1157             echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdff -lnetcdf" >> genmake_tnc.log
979d83c92d Cons*1158             cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null  \
                1159                 &&  $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1  \
                1160                 &&  $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdff -lnetcdf >> genmake_tnc.log 2>&1
                1161             RET_COMPILE=$?
683b8f029b Jean*1162             echo >> $LOGFILE
                1163             cat genmake_tnc.log >> $LOGFILE
979d83c92d Cons*1164             if test "x$RET_COMPILE" = x0 ; then
                1165                 LIBS="$LIBS -lnetcdff -lnetcdf"
                1166                 HAVE_NETCDF=t
683b8f029b Jean*1167                 echo "check_netcdf: successful" >> $LOGFILE
979d83c92d Cons*1168             fi
2978624509 Ed H*1169         fi
4b2baec0be Ed H*1170     fi
                1171     rm -f genmake_tnc*
0e2704be3d Jean*1172     echo " --> set HAVE_NETCDF='$HAVE_NETCDF'" >> $LOGFILE
4b2baec0be Ed H*1173 }
                1174 
991445cec7 Oliv*1175 check_lapack_libs()  {
516b08a580 jm-c 1176     HAVE_LAPACK=f
991445cec7 Oliv*1177     echo >> $LOGFILE
                1178     echo "running: check_lapack_libs()" >> $LOGFILE
                1179     cat <<EOF > genmake_tla.F
                1180       program fgenla
776d1c0efd Jean*1181       integer info
991445cec7 Oliv*1182       integer ipiv( 2 )
                1183       double precision ab( 4, 2 ), b( 2 )
                1184       data ab / 0., 0., 1., 2., 0., 2., 1., 0. /
                1185       data b / 1., 1. /
                1186       call dgbsv( 2, 1, 1, 1, ab, 4, ipiv, b, 2, info )
                1187       IF (info .NE. 0) write(*,*) 'Error:', info
                1188       write(*,*) b
                1189       end
                1190 EOF
                1191     echo "===  genmake_tla.F  >>>" > genmake_tla.log
                1192     cat genmake_tla.F >> genmake_tla.log
                1193     echo "<<<  genmake_tla.F  ===" >> genmake_tla.log
                1194     RET_CPP=f
                1195     COMM="cat genmake_tla.F | $CPP $DEFINES $INCLUDES"
                1196     echo "$COMM" >> genmake_tla.log
                1197     eval $COMM > genmake_tla.$FS 2>/dev/null  &&  RET_CPP=t
                1198     if test "x$RET_CPP" = xf ; then
                1199         echo "  WARNING: CPP failed to pre-process the lapack test." \
                1200             >> genmake_tla.log
                1201         echo "    Please check that \$INCLUDES is properly set." \
                1202             >> genmake_tla.log
                1203     fi
                1204     echo "$FC $FFLAGS $FOPTIM -c genmake_tla.$FS  \ " >> genmake_tla.log
                1205     echo "  &&  $LINK $FFLAGS $FOPTIM -o genmake_tla.o $LIBS" >> genmake_tla.log
                1206     $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
                1207         &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS >> genmake_tla.log 2>&1
                1208     RET_COMPILE=$?
                1209     cat genmake_tla.log >> $LOGFILE
                1210 
                1211     # test program execution not always possible (see check_netcdf_libs)
                1212     #
                1213     #test -x ./genmake_tla  &&  ./genmake_tla >> genmake_tla.log 2>&1
                1214     #RETVAL=$?
                1215     #if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
                1216 
                1217     if test "x$RET_COMPILE" = x0 ; then
                1218         HAVE_LAPACK=t
                1219         echo "check_lapack: successful" >> $LOGFILE
                1220     else
                1221         # try again with "-llapack" added to the libs
                1222         echo "==> try again with added '-llapack'" > genmake_tla.log
                1223         echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
                1224         echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
                1225         echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack" >> genmake_tla.log
                1226         cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null  \
                1227             &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
                1228             &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack >> genmake_tla.log 2>&1
                1229         RET_COMPILE=$?
                1230         echo >> $LOGFILE
                1231         cat genmake_tla.log >> $LOGFILE
                1232         if test "x$RET_COMPILE" = x0 ; then
                1233             LIBS="$LIBS -llapack"
                1234             HAVE_LAPACK=t
                1235             echo "check_lapack: successful" >> $LOGFILE
                1236         else
                1237         # try again with "-lf77blas -lcblas" added to the libs
                1238             echo "==> try again with added '-llapack -lf77blas -lcblas'" > genmake_tla.log
                1239             echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
                1240             echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
                1241             echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas" >> genmake_tla.log
                1242             cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null  \
                1243                 &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
                1244                 &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas >> genmake_tla.log 2>&1
                1245             RET_COMPILE=$?
                1246             echo >> $LOGFILE
                1247             cat genmake_tla.log >> $LOGFILE
                1248             if test "x$RET_COMPILE" = x0 ; then
                1249                 LIBS="$LIBS -llapack -lf77blas -lcblas"
                1250                 HAVE_LAPACK=t
                1251                 echo "check_lapack: successful" >> $LOGFILE
776d1c0efd Jean*1252             else
                1253             # try again with "-latlas" added to the libs
                1254                 echo "==> try again with added '-llapack -lf77blas -lcblas -latlas'" > genmake_tla.log
                1255                 echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
                1256                 echo " &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
                1257                 echo " &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas -latlas" >> genmake_tla.log
                1258                 cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null  \
                1259                     &&  $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1  \
                1260                     &&  $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas -latlas >> genmake_tla.log 2>&1
                1261                 RET_COMPILE=$?
                1262                 echo >> $LOGFILE
                1263                 cat genmake_tla.log >> $LOGFILE
                1264                 if test "x$RET_COMPILE" = x0 ; then
                1265                     LIBS="$LIBS -llapack -lf77blas -lcblas -latlas"
                1266                     HAVE_LAPACK=t
                1267                     echo "check_lapack: successful" >> $LOGFILE
                1268                 fi
991445cec7 Oliv*1269             fi
                1270         fi
                1271     fi
                1272     rm -f genmake_tla*
                1273     echo " --> set HAVE_LAPACK='$HAVE_LAPACK'" >> $LOGFILE
                1274 }
                1275 
7d5fc6b559 Jean*1276 check_HAVE_FLUSH()  {
                1277     if test ! "x$SKIP_CHECK_FLUSH" = x ; then
                1278         return
                1279     fi
                1280     echo >> $LOGFILE
                1281     echo "running: check_HAVE_FLUSH()" >> $LOGFILE
                1282     cat <<EOF > genmake_tflsh.$FS
                1283       program fgenflsh
                1284       integer iounit
                1285       character*9 fname
                1286       iounit = 26
                1287       fname = 'tmp.tflsh'
                1288       open(iounit,FILE=fname,STATUS='unknown')
                1289       write(iounit,*) 'genmake_tflsh: hello'
                1290       call flush(iounit)
                1291       close(iounit)
                1292       end
                1293 EOF
                1294     echo "===  genmake_tflsh.$FS  >>>" > genmake_tflsh.log
                1295     cat genmake_tflsh.$FS >> genmake_tflsh.log
                1296     echo "<<<  genmake_tflsh.$FS  ===" >> genmake_tflsh.log
                1297 
                1298     echo "$FC $FFLAGS $FOPTIM -c genmake_tflsh.$FS  \ " >> genmake_tflsh.log
                1299     echo "  &&  $LINK $FFLAGS $FOPTIM -o genmake_tflsh.o $LIBS" >> genmake_tflsh.log
                1300     $FC $FFLAGS $FOPTIM -c genmake_tflsh.$FS >> genmake_tflsh.log 2>&1  \
                1301         &&  $LINK $FFLAGS $FOPTIM -o genmake_tflsh genmake_tflsh.o $LIBS >> genmake_tflsh.log 2>&1
                1302     RET_COMPILE=$?
                1303 
                1304     if test "x$RET_COMPILE" = x0 ; then
                1305         HAVE_FLUSH=t
                1306         #cat genmake_tflsh.log >> $LOGFILE
                1307         echo "  check_HAVE_FLUSH: successful" >> $LOGFILE
                1308     else
                1309         HAVE_FLUSH=f
                1310         cat genmake_tflsh.log >> $LOGFILE
                1311     fi
                1312     rm -f genmake_tflsh*
                1313     echo " --> set HAVE_FLUSH='$HAVE_FLUSH'" >> $LOGFILE
                1314 }
4b2baec0be Ed H*1315 
c1324e0980 Alis*1316 ###############################################################################
                1317 #   Sequential part of script starts here
                1318 ###############################################################################
                1319 
6aec5d9846 Ed H*1320 #  Set defaults here
2ff82eb834 Ed H*1321 COMMANDL="$0 $@"
                1322 
6aec5d9846 Ed H*1323 PLATFORM=
                1324 LN=
                1325 S64=
                1326 KPP=
6e9c5fd628 Ed H*1327 #FC=
9d6ad94e1e Ed H*1328 #CC=gcc
6e9c5fd628 Ed H*1329 #CPP=
6aec5d9846 Ed H*1330 LINK=
8636935175 Ed H*1331 DEFINES=
6aec5d9846 Ed H*1332 PACKAGES=
                1333 ENABLE=
                1334 DISABLE=
3ce2ed8dc5 Ed H*1335 # MAKEFILE=
                1336 # MAKEDEPEND=
a5a3c4e100 Jean*1337 PKG_DEPEND=
                1338 PKG_GROUPS=
683b8f029b Jean*1339 DUMPSTATE=f
6aec5d9846 Ed H*1340 OPTFILE=
4647ba122e Ed H*1341 INCLUDES="-I. $INCLUDES"
6aec5d9846 Ed H*1342 FFLAGS=
                1343 FOPTIM=
780fea06ba Mart*1344 FEXTRAFLAGS=
ebe06b86a4 Jean*1345 USE_EXTENDED_SRC=
                1346 EXTENDED_SRC_FLAG=
40958e8f52 Jean*1347 GET_FC_VERSION=
6aec5d9846 Ed H*1348 CFLAGS=
                1349 KFLAGS1=
                1350 KFLAGS2=
e129bec2de Ed H*1351 #LDADD=
6aec5d9846 Ed H*1352 LIBS=
                1353 KPPFILES=
                1354 NOOPTFILES=
                1355 NOOPTFLAGS=
c1324e0980 Alis*1356 MPI=
                1357 MPIPATH=
e9e6f33093 Jean*1358 OMP=
                1359 OMPFLAG=
b3a27c6152 Jean*1360 USE_R4=
a66d6f811f Cons*1361 TS=
29eb399fd0 Cons*1362 PAPIS=
008ba3ca0d Cons*1363 PCLS=
29eb399fd0 Cons*1364 FOOLAD=
                1365 PAPI=
008ba3ca0d Cons*1366 PCL=
29eb399fd0 Cons*1367 HPMT=
                1368 GSL=
979d83c92d Cons*1369 DEVEL=
f7f6e70984 Ed H*1370 HAVE_TEST_L=
6aec5d9846 Ed H*1371 
937e30e5d7 Jean*1372 # set this to "t" to enable lapack test
                1373 CHECK_FOR_LAPACK=f
1c6c4d23f7 Oliv*1374 
4b08b6ee66 Ed H*1375 # DEFINES checked by test compilation or command-line
e51ecc3fef Ed H*1376 HAVE_SYSTEM=
                1377 HAVE_FDATE=
f7aaac66f3 jm-c 1378 FC_CHECK=
e51ecc3fef Ed H*1379 FC_NAMEMANGLE=
06c46c472d Ed H*1380 HAVE_CLOC=
36459526ba Ed H*1381 # HAVE_SETRLSTK=
ab11ba1276 Ed H*1382 HAVE_STAT=
4b2baec0be Ed H*1383 HAVE_NETCDF=
9698b7effe Chri*1384 HAVE_ETIME=
4b08b6ee66 Ed H*1385 IGNORE_TIME=
991445cec7 Oliv*1386 HAVE_LAPACK=
7d5fc6b559 Jean*1387 HAVE_FLUSH=
e51ecc3fef Ed H*1388 
6aec5d9846 Ed H*1389 MODS=
                1390 TOOLSDIR=
                1391 SOURCEDIRS=
                1392 INCLUDEDIRS=
57ace0c46a Ed H*1393 STANDARDDIRS="USE_THE_DEFAULT"
9d0c386f0c dngo*1394 SINGULARITYFILE=
6aec5d9846 Ed H*1395 
36e14999eb Jean*1396 #- local config file
                1397 gm_local="genmake_local"
                1398 
6aefb07181 Ed H*1399 G2ARGS=
13fa7032ba Ed H*1400 BASH=
6aec5d9846 Ed H*1401 PWD=`pwd`
6e9c5fd628 Ed H*1402 test "x$MAKE" = x  &&  MAKE=make
                1403 test "x$AWK" = x   &&  AWK=awk
ab504a3a96 Ed H*1404 EMBED_SRC=
9a263a84a8 Ed H*1405 THISHOST=`hostname`
6aec5d9846 Ed H*1406 THISCWD=`pwd`
                1407 THISDATE=`date`
9a263a84a8 Ed H*1408 THISUSER=`echo $USER`
                1409 THISVER=
6aec5d9846 Ed H*1410 MACHINE=`uname -a`
6c90987a77 Ed H*1411 EXECUTABLE=
                1412 EXEHOOK=
                1413 EXEDIR=
6d54cf9ca1 Ed H*1414 IEEE=
                1415 if test "x$MITGCM_IEEE" != x ; then
                1416     IEEE=$MITGCM_IEEE
                1417 fi
3eb03232c2 Ed H*1418 FS=
                1419 FS90=
6aec5d9846 Ed H*1420 
668b211e58 Ed H*1421 AUTODIFF_PKG_USED=f
b4daa24319 Shre*1422 TAPENADE=
                1423 TAPENADECMD=tapenade
16cc6e2b59 Jean*1424 OPENAD=
668b211e58 Ed H*1425 AD_OPTFILE=
44f4a23ebb Jean*1426 CAT_SRC_FOR_TAF=1
0c0e61146f Ed H*1427 TAF=
                1428 AD_TAF_FLAGS=
                1429 FTL_TAF_FLAGS=
                1430 SVD_TAF_FLAGS=
                1431 TAF_EXTRA=
                1432 TAMC=
                1433 AD_TAMC_FLAGS=
                1434 FTL_TAF_FLAGS=
                1435 SVD_TAMC_FLAGS=
                1436 TAMC_EXTRA=
                1437 
fea3e7d209 Jean*1438 DIVA=
                1439 MPIINCLUDEDIR=
                1440 MPI_HEADER_FILES=
                1441 LOCAL_MPI_HEADERS=
                1442 
2ff82eb834 Ed H*1443 #  The following state can be set directly by command-line switches
621623385c Jean*1444 gm_s1="ROOTDIR STANDARDDIRS MODS PKG_DEPEND PKG_GROUPS DISABLE ENABLE"
                1445 gm_s2="PLATFORM OPTFILE MAKE MAKEFILE MAKEDEPEND FC CC MPI OMP USE_R4"
                1446 gm_s3="FEXTRAFLAGS IEEE DEVEL GSL TS PAPIS PCLS PAPI PCL HPMT DUMPSTATE"
2ff82eb834 Ed H*1447 
                1448 #  The following state is not directly set by command-line switches
621623385c Jean*1449 gm_s4="LN S64 LINK PACKAGES INCLUDES FFLAGS FOPTIM"
dd9f72a48c Jean*1450 gm_s5="CFLAGS LIBS KPP KFLAGS1 KFLAGS2 KPPFILES NOOPTFILES NOOPTFLAGS"
7d5fc6b559 Jean*1451 gm_s6="PWD TOOLSDIR SOURCEDIRS INCLUDEDIRS EXEDIR EXECUTABLE EXEHOOK"
f7aaac66f3 jm-c 1452 gm_s7="TMP THISHOST THISUSER THISDATE THISVER MACHINE FC_CHECK FC_NAMEMANGLE"
7d5fc6b559 Jean*1453 gm_s8="HAVE_NETCDF HAVE_SYSTEM HAVE_FDATE HAVE_ETIME HAVE_LAPACK HAVE_FLUSH"
2ff82eb834 Ed H*1454 
668b211e58 Ed H*1455 #  The following are all related to adjoint/tangent-linear stuff
b4daa24319 Shre*1456 gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAPENADE TAPENADECMD OPENAD TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
e51ecc3fef Ed H*1457 gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
fea3e7d209 Jean*1458 gm_s12="TAF_EXTRA TAMC_EXTRA DIVA MPIINCLUDEDIR MPI_HEADER_FILES"
668b211e58 Ed H*1459 
dd9f72a48c Jean*1460 gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7 $gm_s8"
e51ecc3fef Ed H*1461 gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
2ff82eb834 Ed H*1462 
06a58fb2fc Ed H*1463 cat <<EOF
                1464 
                1465 GENMAKE :
                1466 
683b8f029b Jean*1467 A program for GENerating MAKEfiles for the MITgcm project.
                1468    For a quick list of options, use "genmake2 -h"
516b08a580 jm-c 1469 or for more detail see the documentation, section "Building the model"
                1470    (under "Getting Started") at:  https://mitgcm.readthedocs.io/
06a58fb2fc Ed H*1471 
                1472 EOF
2ff82eb834 Ed H*1473 
309b5c610e Jean*1474 if test "x$MITGCM_ROOTDIR" = x ; then
                1475   if test "x$ROOTDIR" != x ; then
51a1c30199 Jean*1476     echo "WARNING: Environment Variable 'ROOTDIR' getting retired soon ;"
309b5c610e Jean*1477     echo "WARNING:  ==> has been replaced by Env. Var. 'MITGCM_ROOTDIR'"
51a1c30199 Jean*1478   # echo "WARNING: Environment Variable 'ROOTDIR' no longer recognized"
309b5c610e Jean*1479   # echo "WARNING:  use instead 'MITGCM_ROOTDIR'" ; ROOTDIR=
                1480     echo ''
                1481   fi
                1482 else
                1483   ROOTDIR=$MITGCM_ROOTDIR
                1484 fi
                1485 
683b8f029b Jean*1486 LOGFILE="genmake.log"
6206da1394 Jean*1487 #- clean-up previous genmake logfiles:
683b8f029b Jean*1488 rm -f genmake_state genmake_*optfile $LOGFILE
67fd6ce146 Jean*1489 
76c1b0ef61 Ed H*1490 echo "===  Processing options files and arguments  ==="
6aec5d9846 Ed H*1491 
a674d19f61 Ed H*1492 #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
76c1b0ef61 Ed H*1493 #parse_options
                1494 ac_prev=
405899ca27 Ed H*1495 for ac_option in "$@" ; do
76c1b0ef61 Ed H*1496 
6aefb07181 Ed H*1497     G2ARGS="$G2ARGS \"$ac_option\""
                1498 
76c1b0ef61 Ed H*1499     # If the previous option needs an argument, assign it.
                1500     if test -n "$ac_prev"; then
                1501         eval "$ac_prev=\$ac_option"
                1502         ac_prev=
                1503         continue
                1504     fi
5be35a17af Jean*1505 
76c1b0ef61 Ed H*1506     ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
5be35a17af Jean*1507 
76c1b0ef61 Ed H*1508     case $ac_option in
776d1c0efd Jean*1509 
76c1b0ef61 Ed H*1510         -help | --help | -h | --h)
                1511             usage ;;
776d1c0efd Jean*1512 
76c1b0ef61 Ed H*1513         -optfile | --optfile | -of | --of)
c53a297da3 Ed H*1514             ac_prev=OPTFILE ;;
76c1b0ef61 Ed H*1515         -optfile=* | --optfile=* | -of=* | --of=*)
                1516             OPTFILE=$ac_optarg ;;
776d1c0efd Jean*1517 
b4daa24319 Shre*1518         -tap | --tap)
                1519             TAPENADE="true" ; ALWAYS_USE_F90=1 ;;
                1520 
16cc6e2b59 Jean*1521         -oad | --oad)
9bf5db3002 Jean*1522             OPENAD="true" ; ALWAYS_USE_F90=1 ;;
9d0c386f0c dngo*1523         -oadsingularity | --oadsingularity | -oadsngl | --oadsngl)
                1524             ac_prev=SINGULARITYFILE ;;
                1525         -oadsingularity=* | --oadsingularity=* | -oadsngl=* | --oadsngl=*)
                1526             SINGULARITYFILE=$ac_optarg ;;
44f4a23ebb Jean*1527         -nocat4ad | -dog4ad | -ncad | -dad)
                1528             CAT_SRC_FOR_TAF=0 ;;
b34430ea9b Ed H*1529         -adoptfile | --adoptfile | -adof | --adof)
668b211e58 Ed H*1530             ac_prev=AD_OPTFILE ;;
                1531         -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
                1532             AD_OPTFILE=$ac_optarg ;;
776d1c0efd Jean*1533 
76c1b0ef61 Ed H*1534         -pdepend | --pdepend)
a5a3c4e100 Jean*1535             ac_prev=PKG_DEPEND ;;
76c1b0ef61 Ed H*1536         -pdepend=* | --pdepend=*)
a5a3c4e100 Jean*1537             PKG_DEPEND=$ac_optarg ;;
776d1c0efd Jean*1538 
a5a3c4e100 Jean*1539         -pgroups | --pgroups)
                1540             ac_prev=PKG_GROUPS ;;
                1541         -pgroups=* | --pgroups=*)
                1542             PKG_GROUPS=$ac_optarg ;;
776d1c0efd Jean*1543 
b34aa4cc66 Ed H*1544         -make | --make | -m | --m)
                1545             ac_prev=MAKE ;;
                1546         -make=* | --make=* | -m=* | --m=*)
                1547             MAKE=$ac_optarg ;;
776d1c0efd Jean*1548 
13fa7032ba Ed H*1549         -bash | --bash)
                1550             ac_prev=BASH ;;
                1551         -bash=* | --bash=*)
                1552             BASH=$ac_optarg ;;
776d1c0efd Jean*1553 
b0867682b1 Ed H*1554         -makedepend | --makedepend | -md | --md)
                1555             ac_prev=MAKEDEPEND ;;
                1556         -makedepend=* | --makedepend=* | -md=* | --md=*)
                1557             MAKEDEPEND=$ac_optarg ;;
776d1c0efd Jean*1558 
36e14999eb Jean*1559         -makefile | --makefile | -mf | --mf)
c53a297da3 Ed H*1560             ac_prev=MAKEFILE ;;
36e14999eb Jean*1561         -makefile=* | --makefile=* | -mf=* | --mf=*)
76c1b0ef61 Ed H*1562             MAKEFILE=$ac_optarg ;;
776d1c0efd Jean*1563 
06a58fb2fc Ed H*1564         -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
                1565             echo "ERROR: The platform option has been removed.  Please specify"
                1566             echo "  the build options using the \"optfile\" mechanism."
                1567             echo
                1568             usage
                1569             ;;
776d1c0efd Jean*1570 
76c1b0ef61 Ed H*1571         -rootdir | --rootdir | -rd | --rd)
c53a297da3 Ed H*1572             ac_prev=ROOTDIR ;;
76c1b0ef61 Ed H*1573         -rootdir=* | --rootdir=* | -rd=* | --rd=*)
                1574             ROOTDIR=$ac_optarg ;;
776d1c0efd Jean*1575 
76c1b0ef61 Ed H*1576         -mods | --mods | -mo | --mo)
c53a297da3 Ed H*1577             ac_prev=MODS ;;
76c1b0ef61 Ed H*1578         -mods=* | --mods=* | -mo=* | --mo=*)
                1579             MODS=$ac_optarg ;;
776d1c0efd Jean*1580 
76c1b0ef61 Ed H*1581         -disable | --disable)
c53a297da3 Ed H*1582             ac_prev=DISABLE ;;
76c1b0ef61 Ed H*1583         -disable=* | --disable=*)
                1584             DISABLE=$ac_optarg ;;
776d1c0efd Jean*1585 
76c1b0ef61 Ed H*1586         -enable | --enable)
c53a297da3 Ed H*1587             ac_prev=ENABLE ;;
76c1b0ef61 Ed H*1588         -enable=* | --enable=*)
                1589             ENABLE=$ac_optarg ;;
776d1c0efd Jean*1590 
6d54cf9ca1 Ed H*1591         -standarddirs | --standarddirs)
                1592             ac_prev=STANDARDDIRS ;;
                1593         -standarddirs=* | --standarddirs=*)
                1594             STANDARDDIRS=$ac_optarg ;;
                1595 
76c1b0ef61 Ed H*1596 #           -cpp | --cpp)
                1597 #               ac_prev=cpp ;;
                1598 #           -cpp=* | --cpp=*)
                1599 #               CPP=$ac_optarg ;;
776d1c0efd Jean*1600 
e8a04cb645 Ed H*1601         -cc | --cc)
                1602             ac_prev=CC ;;
                1603         -cc=* | --cc=*)
                1604             CC=$ac_optarg ;;
776d1c0efd Jean*1605 
76c1b0ef61 Ed H*1606         -fortran | --fortran | -fc | --fc)
c53a297da3 Ed H*1607             ac_prev=FC ;;
76c1b0ef61 Ed H*1608         -fc=* | --fc=*)
                1609             FC=$ac_optarg ;;
776d1c0efd Jean*1610 
3eb03232c2 Ed H*1611         -fs | --fs)
                1612             ac_prev=FS ;;
                1613         -fs=* | --fs=*)
                1614             FS=$ac_optarg ;;
776d1c0efd Jean*1615 
3eb03232c2 Ed H*1616         -fs90 | --fs90)
                1617             ac_prev=FS90 ;;
                1618         -fs90=* | --fs90=*)
                1619             FS90=$ac_optarg ;;
776d1c0efd Jean*1620 
4d1f7e1a03 Jean*1621         -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4 )
                1622             USE_R4=true ;;
                1623 
76c1b0ef61 Ed H*1624         -ieee | --ieee)
6d54cf9ca1 Ed H*1625             IEEE=true ;;
76c1b0ef61 Ed H*1626         -noieee | --noieee)
4d1f7e1a03 Jean*1627             echo "Warning: ignore option '$ac_option' (default is already without '-ieee')" ;;
36e14999eb Jean*1628         -devel | --devel)
4d1f7e1a03 Jean*1629             IEEE=true ; DEVEL=true ;;
36e14999eb Jean*1630         -gsl | --gsl)
4d1f7e1a03 Jean*1631             GSL=true ;;
b3a27c6152 Jean*1632 
a66d6f811f Cons*1633         -ts | --ts)
                1634             TS=true ;;
29eb399fd0 Cons*1635         -papis | --papis)
                1636             PAPIS=true ;;
008ba3ca0d Cons*1637         -pcls | --pcls)
                1638             PCLS=true ;;
29eb399fd0 Cons*1639         -foolad | --foolad)
                1640             FOOLAD=true ;;
                1641         -papi | --papi)
                1642             PAPI=true ;;
008ba3ca0d Cons*1643         -pcl | --pcl)
                1644             PCL=true ;;
29eb399fd0 Cons*1645         -hpmt | --hpmt)
                1646             HPMT=true ;;
                1647 
c1324e0980 Alis*1648         -mpi | --mpi)
                1649             MPI=true ;;
                1650         -mpi=* | --mpi=*)
                1651             MPIPATH=$ac_optarg
                1652             MPI=true ;;
776d1c0efd Jean*1653 
                1654         -omp | --omp)
                1655             OMP=true ;;
e9e6f33093 Jean*1656         -omp=* | --omp=*)
                1657             OMPFLAG=$ac_optarg
                1658             OMP=true ;;
776d1c0efd Jean*1659 
2ff82eb834 Ed H*1660         -ds | --ds)
                1661             DUMPSTATE=t ;;
776d1c0efd Jean*1662 
dd9f72a48c Jean*1663         -extra_flag | --extra_flag)
                1664             ac_prev=FEXTRAFLAGS ;;
                1665         -extra_flag=* | --extra_flag=*)
                1666             FEXTRAFLAGS=$ac_optarg ;;
776d1c0efd Jean*1667 
0c0e61146f Ed H*1668         -taf_extra | --taf_extra)
                1669             ac_prev=TAF_EXTRA ;;
                1670         -taf_extra=* | --taf_extra=*)
                1671             TAF_EXTRA=$ac_optarg ;;
                1672 
                1673         -tamc_extra | --tamc_extra)
                1674             ac_prev=TAMC_EXTRA ;;
                1675         -tamc_extra=* | --tamc_extra=*)
                1676             TAMC_EXTRA=$ac_optarg ;;
776d1c0efd Jean*1677 
4b08b6ee66 Ed H*1678         -ignoretime | -ignore_time | --ignoretime | --ignore_time)
                1679             IGNORE_TIME="-DIGNORE_TIME" ;;
0c0e61146f Ed H*1680 
ab504a3a96 Ed H*1681         -es | --es | -embed-source | --embed-source)
                1682             EMBED_SRC=t ;;
                1683 
76c1b0ef61 Ed H*1684         -*)
                1685             echo "Error: unrecognized option: "$ac_option
                1686             usage
                1687             ;;
776d1c0efd Jean*1688 
76c1b0ef61 Ed H*1689         *)
                1690             echo "Error: unrecognized argument: "$ac_option
                1691             usage
                1692             ;;
776d1c0efd Jean*1693 
76c1b0ef61 Ed H*1694     esac
5be35a17af Jean*1695 
6aec5d9846 Ed H*1696 done
                1697 
4965aa2630 Jean*1698 #TMP=./genmk_$$
7deef35259 Jean*1699 #- try to put temporary files in system-local /tmp dir
b3a874fe30 Jean*1700 TMP=/tmp/genmk_${USER}_$$
4965aa2630 Jean*1701 touch $TMP ; retVal=$?
                1702 if [ $retVal -eq 0 ] ; then
                1703   if test ! -r $TMP ; then TMP=./genmk_$$ ; fi
                1704 else
                1705   TMP=./genmk_$$
                1706 fi
                1707 rm -f $TMP
                1708 #echo "  temp files: $TMP.*"
7deef35259 Jean*1709 
36e14999eb Jean*1710 printf "  getting local config information:  "
                1711 if test -f $gm_local ; then
                1712     echo "using $gm_local"
                1713     . $gm_local
                1714 else
                1715     echo "none found"
                1716 fi
                1717 
6d54cf9ca1 Ed H*1718 if test -f ./.genmakerc ; then
                1719     echo
                1720     echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
516b08a580 jm-c 1721     echo "  file.  This file format is no longer supported."
                1722     echo "  For directions on how to setup and use the new \"genmake2\" script,"
                1723     echo "  please see the User Manual at:  https://mitgcm.readthedocs.io/"
55252a5af3 Jean*1724     echo "WARNING: ignore \"./.genmakerc\" and continue."
5be35a17af Jean*1725     echo
6d54cf9ca1 Ed H*1726 fi
                1727 
9a263a84a8 Ed H*1728 #  Find the MITgcm ${ROOTDIR}
f10e3a8bdd Ed H*1729 if test "x${ROOTDIR}" = x ; then
87042bad2c Ed H*1730     tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
822f69f065 Ed H*1731     if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesupp -a -d ../pkg ; then
f10e3a8bdd Ed H*1732         ROOTDIR=".."
                1733     else
                1734         for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
                1735             if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
                1736                 ROOTDIR=$d
b353a7c6c6 Jean*1737                 printf "Warning: ROOTDIR was not specified ;"
                1738                 echo " try using a local copy of MITgcm found at \"$ROOTDIR\""
f10e3a8bdd Ed H*1739                 break
                1740             fi
                1741         done
                1742     fi
                1743 fi
                1744 if test "x${ROOTDIR}" = x ; then
                1745     echo "Error: Cannot determine ROOTDIR for MITgcm code."
309b5c610e Jean*1746     echo "  Please specify a ROOTDIR using either the command line"
                1747     echo "   option '-rootdir' or the Env.Var. 'MITGCM_ROOTDIR'."
f10e3a8bdd Ed H*1748     exit 1
                1749 fi
                1750 if test ! -d ${ROOTDIR} ; then
                1751     echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
                1752     exit 1
                1753 fi
                1754 
9a263a84a8 Ed H*1755 #  Find the MITgcm ${THISVER}
dbad7fe471 Jean*1756 version_file="${ROOTDIR}/doc/tag-index"
                1757 if test -f $version_file ; then
8a81a79ea3 Jean*1758     THISVER=`$AWK '/^checkpoint/{print $1; exit}' $version_file`
dbad7fe471 Jean*1759 #-  remove ./BUILD_INFO.h file if older than version_file
                1760     if test -f ./BUILD_INFO.h -a ./BUILD_INFO.h -ot $version_file ; then
                1761         echo "  remove ./BUILD_INFO.h (older than ${version_file})"
                1762         rm -f ./BUILD_INFO.h
                1763     fi
9a263a84a8 Ed H*1764 fi
                1765 
3ce2ed8dc5 Ed H*1766 if test "x$MAKEFILE" = x ; then
                1767     MAKEFILE="Makefile"
                1768 fi
                1769 
dd9f72a48c Jean*1770 echo "  getting OPTFILE information:"
6aec5d9846 Ed H*1771 if test "x${OPTFILE}" = x ; then
f10e3a8bdd Ed H*1772     if test "x$MITGCM_OF" = x ; then
                1773         echo "Warning: no OPTFILE specified so we'll look for possible settings"
                1774         printf "\n===  Searching for possible settings for OPTFILE  ===\n"
0e2704be3d Jean*1775         find_possible_optfile
6aec5d9846 Ed H*1776     else
f10e3a8bdd Ed H*1777         OPTFILE=$MITGCM_OF
                1778     fi
                1779 fi
                1780 if test "x$OPTFILE" != xNONE ; then
                1781     if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
                1782         echo "    using OPTFILE=\"$OPTFILE\""
3021a6b819 Ed H*1783         . "$OPTFILE"
f10e3a8bdd Ed H*1784         RETVAL=$?
                1785         if test "x$RETVAL" != x0 ; then
13fa7032ba Ed H*1786             printf "Error: failed to source OPTFILE \"$OPTFILE\""
f10e3a8bdd Ed H*1787             echo "--please check that variable syntax is bash-compatible"
6aec5d9846 Ed H*1788             exit 1
                1789         fi
683b8f029b Jean*1790         if test "x$DUMPSTATE" = xt ; then
6d54cf9ca1 Ed H*1791             cp -f $OPTFILE "genmake_optfile"
f10e3a8bdd Ed H*1792         fi
                1793     else
                1794         echo "Error: can't read OPTFILE=\"$OPTFILE\""
                1795         exit 1
6aec5d9846 Ed H*1796     fi
                1797 fi
                1798 
dd9f72a48c Jean*1799 echo "  getting AD_OPTFILE information:"
668b211e58 Ed H*1800 if test "x${AD_OPTFILE}" = x ; then
16cc6e2b59 Jean*1801     if test "x$MITGCM_AD_OF" != x ; then
                1802         AD_OPTFILE=$MITGCM_AD_OF
b4daa24319 Shre*1803     elif test "x$TAPENADE" != x ; then
                1804         AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_tap
                1805     elif test "x$OPENAD" != x ; then
16cc6e2b59 Jean*1806         AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_oad
b4daa24319 Shre*1807     else
                1808         AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
668b211e58 Ed H*1809     fi
                1810 fi
                1811 if test "x${AD_OPTFILE}" != xNONE ; then
                1812     if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
                1813         echo "    using AD_OPTFILE=\"$AD_OPTFILE\""
3021a6b819 Ed H*1814         . "$AD_OPTFILE"
668b211e58 Ed H*1815         RETVAL=$?
                1816         if test "x$RETVAL" != x0 ; then
13fa7032ba Ed H*1817             printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
668b211e58 Ed H*1818             echo "--please check that variable syntax is bash-compatible"
                1819             exit 1
                1820         fi
683b8f029b Jean*1821         if test "x$DUMPSTATE" = xt ; then
668b211e58 Ed H*1822             cp -f $AD_OPTFILE "genmake_ad_optfile"
                1823         fi
                1824     else
                1825         echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
                1826         exit 1
                1827     fi
                1828 fi
                1829 
3ce2ed8dc5 Ed H*1830 #====================================================================
25bb252094 Jean*1831 # Initialize INCLUDEDIRSMK from and optfile INCLUDEDIRS
                1832 if test "x${INCLUDEDIRS}" != "x" ; then
                1833  INCLUDEDIRSMK=${INCLUDEDIRS}
                1834 fi
                1835 
                1836 #====================================================================
3ce2ed8dc5 Ed H*1837 #  Set default values if not set by the optfile
                1838 #
e8a04cb645 Ed H*1839 #  Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
06c46c472d Ed H*1840 #  either set defaults or complain and abort!
13fa7032ba Ed H*1841 if test ! "x$BASH" = x ; then
                1842     # add a trailing space so that it works within the Makefile syntax (see below)
                1843     BASH="$BASH "
                1844 fi
61e39758c3 Ed H*1845 if test "x$FC" = x ; then
                1846     cat <<EOF 1>&2
                1847 
                1848 Error: no Fortran compiler: please specify using one of the following:
                1849   1) within the options file ("FC=...") as specified by "-of=OPTFILE"
                1850   2) the "-fc=XXX" command-line option
6d54cf9ca1 Ed H*1851   3) the "./genmake_local" file
61e39758c3 Ed H*1852 EOF
                1853     exit 1
                1854 fi
40958e8f52 Jean*1855 if test "x$GET_FC_VERSION" != x ; then
                1856   echo "Get compiler version using: $FC $GET_FC_VERSION" >> $LOGFILE
db3ae3fff3 Jean*1857   ff=`echo $FC | sed 's/ .*//'` ; xx=`echo $ff | sed 's/^./& /' | sed 's/ .*//'`
                1858   if test $xx != '/' ; then which $ff >> $LOGFILE ; fi
bb9d8ba6da Jean*1859   $FC $GET_FC_VERSION > genmake_fc_vers1 2> genmake_fc_vers2
                1860   if test -s genmake_fc_vers1 ; then
                1861     cat genmake_fc_vers1 >> $LOGFILE
                1862   else
                1863     cat genmake_fc_vers2 >> $LOGFILE
                1864   fi
5c9316216b Jean*1865   echo "<-- compiler version ----" >> $LOGFILE
bb9d8ba6da Jean*1866   rm -f genmake_fc_vers1 genmake_fc_vers2
40958e8f52 Jean*1867 fi
0e2704be3d Jean*1868 
e8a04cb645 Ed H*1869 if test "x$CC" = x ; then
0e2704be3d Jean*1870     look_for_C_compilers
e8a04cb645 Ed H*1871 fi
0e2704be3d Jean*1872 
61e39758c3 Ed H*1873 if test "x$LINK" = x ; then
                1874     LINK=$FC
                1875 fi
06c46c472d Ed H*1876 if test "x$MAKE" = x ; then
                1877     MAKE="make"
                1878 fi
f7aaac66f3 jm-c 1879 
                1880 #- check for fortran compiler (for now, just for information, no consequence)
bcbb675387 jm-c 1881 if test "x$FC_CHECK" = x -o "x$FC_CHECK" = xt ; then
                1882     check_fortran_compiler
                1883 else FC_CHECK=-2 ; fi
f7aaac66f3 jm-c 1884 
4fbb3ff84d Ed H*1885 if test "x$CPP" = x ; then
0e2704be3d Jean*1886     CPP="cpp -traditional -P"
4fbb3ff84d Ed H*1887 fi
                1888 #EH3 === UGLY ===
3eb03232c2 Ed H*1889 #  The following is an ugly little hack to check for $CPP in /lib/ and
                1890 #  it should eventually be replaced with a more general function that
4fbb3ff84d Ed H*1891 #  searches a combo of the user's path and a list of "usual suspects"
                1892 #  to find the correct location for binaries such as $CPP.
                1893 for i in " " "/lib/" ; do
                1894     echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
                1895 done
                1896 #EH3 === UGLY ===
7f196e2d92 Ed H*1897 echo "#define A a" | $CPP > test_cpp 2>&1
f10e3a8bdd Ed H*1898 RETVAL=$?
                1899 if test "x$RETVAL" != x0 ; then
61e39758c3 Ed H*1900     cat <<EOF 1>&2
                1901 
f10e3a8bdd Ed H*1902 Error: C pre-processor "$CPP" failed the test case: please specify using:
                1903 
61e39758c3 Ed H*1904   1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
6d54cf9ca1 Ed H*1905   2) the "./genmake_local" file
c419bc9ed8 Ed H*1906   3) with the CPP environment variable
61e39758c3 Ed H*1907 
                1908 EOF
                1909     exit 1
f10e3a8bdd Ed H*1910 else
                1911     rm -f test_cpp
                1912 fi
0e2704be3d Jean*1913 
072ddee95c Ed H*1914 look_for_makedepend
0e2704be3d Jean*1915 
                1916 #  Check that soft-link command is set and usable
48cf0b55dd Ed H*1917 if test "x$LN" = x ; then
                1918     LN="ln -s"
                1919 fi
                1920 echo "test" > genmake_test_ln
                1921 $LN genmake_test_ln genmake_tlink
                1922 RETVAL=$?
                1923 if test "x$RETVAL" != x0 ; then
                1924     cat <<EOF 1>&2
61e39758c3 Ed H*1925 
0e2704be3d Jean*1926 Error: The command "$LN" failed -- please specify a working soft-link
48cf0b55dd Ed H*1927   command in the optfile.
                1928 
                1929 EOF
                1930     exit 1
                1931 fi
f7f6e70984 Ed H*1932 test -L genmake_tlink > /dev/null 2>&1
                1933 RETVAL=$?
                1934 if test "x$RETVAL" = x0 ; then
                1935     HAVE_TEST_L=t
                1936 fi
48cf0b55dd Ed H*1937 rm -f genmake_test_ln genmake_tlink
e51ecc3fef Ed H*1938 
a4cdb0c6f0 Ed H*1939 #  Check for broken *.F/*.f handling and fix if possible
                1940 check_for_broken_Ff
                1941 
c1324e0980 Alis*1942 if test ! "x$MPI" = x ; then
                1943       echo "  Turning on MPI cpp macros"
e8e03c465c Jean*1944       DEFINES="$DEFINES -DALLOW_USE_MPI"
fb0eed0ba5 Jean*1945 #- To compile code older than checkpoint63s (2012/09/05), un-comment the following line:
                1946 #     DEFINES="$DEFINES -DALWAYS_USE_MPI"
c1324e0980 Alis*1947 fi
e9e6f33093 Jean*1948 if test ! "x$OMP" = x ; then
                1949       echo "  Add OMPFLAG and turn on OpenMP cpp macros"
                1950       FFLAGS="$FFLAGS $OMPFLAG"
                1951       F90FLAGS="$F90FLAGS $OMPFLAG"
                1952       DEFINES="$DEFINES -DUSE_OMP_THREADING"
                1953 fi
06c46c472d Ed H*1954 
b3a27c6152 Jean*1955 if test ! "x$USE_R4" = x ; then
                1956       echo "  Turning on LET_RS_BE_REAL4 cpp flag"
                1957       DEFINES="$DEFINES -DLET_RS_BE_REAL4"
                1958 fi
                1959 
a66d6f811f Cons*1960 if test ! "x$TS" = x ; then
                1961       echo "  Turning on timing per timestep"
29eb399fd0 Cons*1962       if test ! "x$FOOLAD" = x ; then
776d1c0efd Jean*1963             DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP"
29eb399fd0 Cons*1964       else
                1965             DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
                1966       fi
35f9e7450d Cons*1967       PACKAGES="$PACKAGES showflops"
29eb399fd0 Cons*1968 fi
                1969 if test ! "x$PAPIS" = x ; then
                1970       echo "  Turning on PAPI flop summary per timestep"
                1971       echo "  Please make sure PAPIINC, PAPILIB are defined"
                1972       if test ! "x$FOOLAD" = x ; then
                1973             DEFINES="$DEFINES -DUSE_PAPI_FLOPS_SFP"
                1974       else
                1975             DEFINES="$DEFINES -DUSE_PAPI_FLOPS"
                1976       fi
                1977       INCLUDES="$INCLUDES $PAPIINC"
                1978       LIBS="$LIBS $PAPILIB"
35f9e7450d Cons*1979       PACKAGES="$PACKAGES showflops"
29eb399fd0 Cons*1980 fi
008ba3ca0d Cons*1981 if test ! "x$PCLS" = x ; then
                1982       echo "  Turning on PCL counter summary per timestep"
                1983       echo "  Please make sure PCLINC, PCLLIB are defined"
                1984       if test ! "x$FOOLAD" = x ; then
                1985             DEFINES="$DEFINES -DUSE_PCL_FLOPS_SFP"
                1986       else
                1987             DEFINES="$DEFINES -DUSE_PCL_FLOPS"
                1988       fi
                1989       INCLUDES="$INCLUDES $PCLINC"
                1990       LIBS="$LIBS $PCLLIB"
35f9e7450d Cons*1991       PACKAGES="$PACKAGES showflops"
008ba3ca0d Cons*1992 fi
29eb399fd0 Cons*1993 if test ! "x$PAPI" = x ; then
                1994       if test ! "x$PAPIS" = x ; then
                1995           echo "  PAPI performance analysis and flop summary per timestep cannot co-exist!"
                1996           echo "  Sticking with PAPI flop summary per timestep!"
                1997       else
                1998           echo "  Turning on performance analysis with PAPI"
776d1c0efd Jean*1999           echo "  Please make sure PAPIINC, PAPILIB are defined"
29eb399fd0 Cons*2000           DEFINES="$DEFINES -DUSE_PAPI"
                2001           INCLUDES="$INCLUDES $PAPIINC"
                2002           LIBS="$LIBS $PAPILIB"
                2003       fi
                2004 fi
008ba3ca0d Cons*2005 if test ! "x$PCL" = x ; then
                2006       if test ! "x$PCLS" = x ; then
                2007           echo "  PCL performance analysis and flop summary per timestep cannot co-exist!"
                2008           echo "  Sticking with PCL flop summary per timestep!"
                2009       else
                2010           echo "  Turning on performance analysis with PCL"
776d1c0efd Jean*2011           echo "  Please make sure PCLINC, PCLLIB are defined"
008ba3ca0d Cons*2012           DEFINES="$DEFINES -DUSE_PCL"
                2013           INCLUDES="$INCLUDES $PCLINC"
                2014           LIBS="$LIBS $PCLLIB"
                2015       fi
                2016 fi
29eb399fd0 Cons*2017 if test ! "x$HPMT" = x ; then
                2018       if test ! "x$PAPI" = x ; then
                2019           echo "  PAPI and the HPM Toolkit cannot co-exist!"
                2020           echo "  Sticking with PAPI!"
36e14999eb Jean*2021       else
                2022         if test ! "x$PCL" = x ; then
008ba3ca0d Cons*2023           echo "  PCL and the HPM Toolkit cannot co-exist!"
                2024           echo "  Sticking with PCL!"
36e14999eb Jean*2025         else
29eb399fd0 Cons*2026           echo "  Turning on performance analysis with the HPM Toolkit"
776d1c0efd Jean*2027           echo "  Please make sure HPMTINC, HPMTLIB are defined"
29eb399fd0 Cons*2028           DEFINES="$DEFINES -DUSE_LIBHPM"
776d1c0efd Jean*2029           INCLUDES="$INCLUDES $HPMTINC"
29eb399fd0 Cons*2030           LIBS="$LIBS $HPMTLIB"
36e14999eb Jean*2031         fi
de1771f913 Cons*2032       fi
29eb399fd0 Cons*2033 fi
                2034 if test ! "x$GSL" = x ; then
                2035       echo "  Turning on use of GSL to control floating point calculations"
                2036       echo "  Please make sure GSLINC, GSLLIB are defined"
                2037       DEFINES="$DEFINES -DUSE_GSL_IEEE"
                2038       INCLUDES="$INCLUDES $GSLINC"
                2039       LIBS="$LIBS $GSLLIB"
a66d6f811f Cons*2040 fi
ebe06b86a4 Jean*2041 #- if USE_EXTENDED_SRC is set, add EXTENDED_SRC_FLAG to FFLAGS :
                2042 if test ! "x$USE_EXTENDED_SRC" = x ; then
                2043       FFLAGS="$FFLAGS $EXTENDED_SRC_FLAG"
                2044       F90FIXEDFORMAT="$F90FIXEDFORMAT $EXTENDED_SRC_FLAG"
                2045 fi
a66d6f811f Cons*2046 
e51ecc3fef Ed H*2047 printf "\n===  Checking system libraries  ===\n"
13fa7032ba Ed H*2048 printf "  Do we have the system() command using $FC...  "
6554790d1c Ed H*2049 cat > genmake_tcomp.$FS <<EOF
e51ecc3fef Ed H*2050       program hello
                2051       call system('echo hi')
                2052       end
                2053 EOF
64947e6405 Ed H*2054 $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
e51ecc3fef Ed H*2055 RETVAL=$?
                2056 if test "x$RETVAL" = x0 ; then
                2057     HAVE_SYSTEM=t
                2058     DEFINES="$DEFINES -DHAVE_SYSTEM"
                2059     echo "yes"
                2060 else
                2061     HAVE_SYSTEM=
                2062     echo "no"
                2063 fi
                2064 rm -f genmake_tcomp*
                2065 
13fa7032ba Ed H*2066 printf "  Do we have the fdate() command using $FC...  "
6554790d1c Ed H*2067 cat > genmake_tcomp.$FS <<EOF
e51ecc3fef Ed H*2068       program hello
c899631d80 Ed H*2069       CHARACTER*(128) string
e51ecc3fef Ed H*2070       string = ' '
                2071       call fdate( string )
                2072       print *, string
                2073       end
                2074 EOF
64947e6405 Ed H*2075 $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
e51ecc3fef Ed H*2076 RETVAL=$?
                2077 if test "x$RETVAL" = x0 ; then
                2078     HAVE_FDATE=t
                2079     DEFINES="$DEFINES -DHAVE_FDATE"
                2080     echo "yes"
                2081 else
                2082     HAVE_FDATE=
                2083     echo "no"
                2084 fi
                2085 rm -f genmake_tcomp*
                2086 
7c83a0f18d Jean*2087 printf "  Do we have the etime() command using $FC... "
f9872c5276 Jean*2088 cat > genmake_tcomp_1.$FS <<EOF
                2089       program hello
                2090       REAL*4 actual, tarray(2)
                2091       EXTERNAL ETIME
                2092       REAL*4 ETIME
                2093       actual = ETIME( tarray )
                2094       print *, tarray
                2095       end
                2096 EOF
                2097 $FC $FFLAGS -o genmake_tcomp_1 genmake_tcomp_1.$FS > genmake_tcomp.log 2>&1
                2098 RETVAL=$?
                2099 if test "x$RETVAL" = x0 ; then
                2100     HAVE_ETIME='Fct'
                2101     DEFINES="$DEFINES -DHAVE_ETIME_FCT"
                2102     echo " yes (${HAVE_ETIME})"
                2103 else
                2104   cat > genmake_tcomp_2.$FS <<EOF
9698b7effe Chri*2105       program hello
7c83a0f18d Jean*2106       REAL*4 actual, tarray(2)
                2107       actual = -999.
                2108       call ETIME( tarray, actual )
                2109       if ( actual.ge.0. ) then
                2110         print *, 0, tarray, actual
                2111       else
                2112         print *, 1, tarray, actual
                2113       endif
9698b7effe Chri*2114       end
                2115 EOF
f9872c5276 Jean*2116   $FC $FFLAGS -o genmake_tcomp_2 genmake_tcomp_2.$FS >> genmake_tcomp.log 2>&1
                2117   RETVAL=$?
                2118   if test "x$RETVAL" = x0 ; then
7c83a0f18d Jean*2119     echo -n 'c,'
f9872c5276 Jean*2120     ./genmake_tcomp_2 > genmake_tcomp_2.out 2>&1
7c83a0f18d Jean*2121     RETVAL=$?
f9872c5276 Jean*2122   fi
                2123   if test "x$RETVAL" = x0 ; then
7c83a0f18d Jean*2124     echo -n 'r:'
f9872c5276 Jean*2125     RETVAL=`cat genmake_tcomp_2.out | $AWK '{print $1}'`
                2126   fi
                2127   if test "x$RETVAL" = x0 ; then
                2128     HAVE_ETIME='SbR'
                2129     DEFINES="$DEFINES -DHAVE_ETIME_SBR"
                2130     echo " yes (${HAVE_ETIME})"
                2131   else
9698b7effe Chri*2132     HAVE_ETIME=
7c83a0f18d Jean*2133     echo " no"
f9872c5276 Jean*2134   fi
9698b7effe Chri*2135 fi
7c83a0f18d Jean*2136 #mkdir chk_etime ; cp -p -f genmake_tcomp* chk_etime
9698b7effe Chri*2137 rm -f genmake_tcomp*
                2138 
13fa7032ba Ed H*2139 printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
06c46c472d Ed H*2140 check_HAVE_CLOC
                2141 if test "x$HAVE_CLOC" != x ; then
b5e03e7d0e Jean*2142     DEFINES="$DEFINES -DHAVE_CLOC"
06c46c472d Ed H*2143     echo "yes"
                2144 else
df91541502 Ed H*2145     echo "no"
ab504a3a96 Ed H*2146     if test "x$EMBED_SRC" = xt ; then
                2147         echo "    WARNING: you requested file embedding but it has"
                2148         echo "      been disabled since C code cannot be called"
                2149         EMBED_SRC=
                2150     fi
df91541502 Ed H*2151 fi
                2152 rm -f genmake_t*
                2153 
                2154 printf "  Can we unlimit the stack size using $FC...  "
                2155 check_HAVE_SETRLSTK
36459526ba Ed H*2156 if test "x$HAVE_SETRLSTK" = xt ; then
b5e03e7d0e Jean*2157     DEFINES="$DEFINES -DHAVE_SETRLSTK"
df91541502 Ed H*2158     echo "yes"
                2159 else
06c46c472d Ed H*2160     echo "no"
e51ecc3fef Ed H*2161 fi
06c46c472d Ed H*2162 rm -f genmake_t*
e51ecc3fef Ed H*2163 
b81731e160 Ed H*2164 printf "  Can we register a signal handler using $FC...  "
                2165 check_HAVE_SIGREG
1c82e4d566 Ed H*2166 if test "x$HAVE_SIGREG" = xt ; then
b5e03e7d0e Jean*2167     DEFINES="$DEFINES -DHAVE_SIGREG"
b81731e160 Ed H*2168     echo "yes"
                2169 else
                2170     echo "no"
                2171 fi
                2172 rm -f genmake_t*
                2173 
ab11ba1276 Ed H*2174 printf "  Can we use stat() through C calls...  "
                2175 check_HAVE_STAT
                2176 if test "x$HAVE_STAT" != x ; then
b5e03e7d0e Jean*2177     DEFINES="$DEFINES -DHAVE_STAT"
ab11ba1276 Ed H*2178     echo "yes"
                2179 else
                2180     echo "no"
                2181 fi
                2182 rm -f genmake_t*
                2183 
13fa7032ba Ed H*2184 printf "  Can we create NetCDF-enabled binaries...  "
4b2baec0be Ed H*2185 check_netcdf_libs
                2186 if test "x$HAVE_NETCDF" != x ; then
b5e03e7d0e Jean*2187     DEFINES="$DEFINES -DHAVE_NETCDF"
4b2baec0be Ed H*2188     echo "yes"
                2189 else
                2190     echo "no"
                2191 fi
991445cec7 Oliv*2192 
516b08a580 jm-c 2193 if test "x$CHECK_FOR_LAPACK" = xf ; then
                2194     echo   "    skip check for LAPACK Libs"
991445cec7 Oliv*2195 else
516b08a580 jm-c 2196     printf "  Can we create LAPACK-enabled binaries...  "
                2197     check_lapack_libs
                2198     if test "x$HAVE_LAPACK" = xt ; then
                2199         echo "yes"
                2200     else
                2201         echo "no"
                2202     fi
                2203 fi
                2204 if test "x$HAVE_LAPACK" = xt ; then
                2205     DEFINES="$DEFINES -DHAVE_LAPACK"
                2206 elif test "x$HAVE_LAPACK" = x ; then
                2207    #- do not report if unset and unchecked:
                2208     gm_state=`echo $gm_state | sed 's/HAVE_LAPACK//'`
991445cec7 Oliv*2209 fi
e51ecc3fef Ed H*2210 
7d5fc6b559 Jean*2211 printf "  Can we call FLUSH intrinsic subroutine...  "
                2212 check_HAVE_FLUSH
                2213 if test "x$HAVE_FLUSH" = xt ; then
                2214     DEFINES="$DEFINES -DHAVE_FLUSH"
                2215     echo "yes"
                2216 else
                2217     echo "no"
                2218 fi
                2219 
                2220 DEFINES="$DEFINES $IGNORE_TIME"
ab504a3a96 Ed H*2221 if test "x$EMBED_SRC" = xt ; then
                2222     build_embed_encode
                2223 fi
                2224 if test "x$EMBED_SRC" = xt ; then
                2225     ENABLE="$ENABLE embed_files"
b5e03e7d0e Jean*2226 #   DEFINES="$DEFINES -DHAVE_EMBED_SRC"
ab504a3a96 Ed H*2227 fi
                2228 
76c1b0ef61 Ed H*2229 printf "\n===  Setting defaults  ===\n"
ab728c5fe9 Jean*2230 printf "  Adding MODS directories: "
6aec5d9846 Ed H*2231 for d in $MODS ; do
                2232     if test ! -d $d ; then
76c1b0ef61 Ed H*2233         echo
                2234         echo "Error: MODS directory \"$d\" not found!"
6aec5d9846 Ed H*2235         exit 1
                2236     else
ab728c5fe9 Jean*2237         printf "$d "
6aec5d9846 Ed H*2238         SOURCEDIRS="$SOURCEDIRS $d"
                2239         INCLUDEDIRS="$INCLUDEDIRS $d"
25bb252094 Jean*2240         SOURCEDIRSMK="$SOURCEDIRSMK $d"
                2241         INCLUDEDIRSMK="$INCLUDEDIRSMK $d"
6aec5d9846 Ed H*2242     fi
                2243 done
                2244 echo
                2245 
0e2704be3d Jean*2246 #if test "x${PLATFORM}" = x ; then
                2247 #    PLATFORM=$p_PLATFORM
                2248 #fi
6aec5d9846 Ed H*2249 
                2250 if test "x${EXEDIR}" = x ; then
87042bad2c Ed H*2251     tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1d6dde53d4 Ed H*2252     if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
6aec5d9846 Ed H*2253         EXEDIR=../exe
                2254     else
                2255         EXEDIR=.
                2256     fi
                2257 fi
                2258 if test ! -d ${EXEDIR} ; then
                2259     echo "Error:  the specified EXEDIR (\"$EXEDIR\") does not exist!"
                2260     exit 1
                2261 fi
                2262 
                2263 if test "x${TOOLSDIR}" = x ; then
                2264     TOOLSDIR="$ROOTDIR/tools"
25bb252094 Jean*2265     TOOLSDIRMK='$(ROOTDIR)'"/tools"
                2266 else
                2267     TOOLSDIRMK=${TOOLSDIR}
6aec5d9846 Ed H*2268 fi
                2269 if test ! -d ${TOOLSDIR} ; then
50c201310d Chri*2270     echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
6aec5d9846 Ed H*2271     exit 1
                2272 fi
f10e3a8bdd Ed H*2273 if test "x$S64" = x ; then
a82b95c41f Ed H*2274     echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1
                2275     RETVAL=$?
                2276     if test "x${RETVAL}" = x0 ; then
                2277         S64='$(TOOLSDIR)/set64bitConst.sh'
                2278     else
                2279         echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1
                2280         RETVAL=$?
                2281         if test "x${RETVAL}" = x0 ; then
                2282             S64='$(TOOLSDIR)/set64bitConst.csh'
                2283         else
                2284             cat <<EOF
                2285 
                2286 ERROR: neither of the two default scripts:
                2287 
                2288     ${TOOLSDIR}/set64bitConst.sh
                2289     ${TOOLSDIR}/set64bitConst.csh
                2290 
5be35a17af Jean*2291   are working so please check paths or specify (with \$S64) a
a82b95c41f Ed H*2292   working version of this script.
                2293 
                2294 EOF
                2295             exit 1
                2296         fi
                2297     fi
f10e3a8bdd Ed H*2298 fi
0c83fc374c Alis*2299 THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
6aec5d9846 Ed H*2300 
                2301 EXECUTABLE=${EXECUTABLE:-mitgcmuv}
                2302 
bf318dd62d Jean*2303 #  Set Standard Code Directories:
                2304 if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
                2305     STANDARDDIRS="eesupp model"
                2306 fi
                2307 #  if model in Standard-Code-Dir, add eesupp (needed to compile model)
                2308 echo " $STANDARDDIRS " | grep ' model ' > /dev/null 2>&1
                2309 ckM=$?
                2310 echo " $STANDARDDIRS " | grep ' eesupp ' > /dev/null 2>&1
                2311 ckE=$?
5be35a17af Jean*2312 if test $ckM = 0 -a $ckE = 1 ; then
bf318dd62d Jean*2313     STANDARDDIRS="$STANDARDDIRS eesupp"
                2314 fi
                2315 
6aec5d9846 Ed H*2316 #  We have a special set of source files in eesupp/src which are
                2317 #  generated from some template source files. We'll make them first so
                2318 #  they appear as regular source code
                2319 if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
                2320     echo "  Making source files in eesupp from templates"
149a2bf4b6 Jean*2321     ( cd $ROOTDIR"/eesupp/src/" && $MAKE clean_old && $MAKE \
                2322     ) > make_eesupp.errors 2>&1
6aec5d9846 Ed H*2323     RETVAL=$?
76c1b0ef61 Ed H*2324     if test "x${RETVAL}" = x0 ; then
6aec5d9846 Ed H*2325         rm -f make_eesupp.errors
                2326     else
                2327         echo "Error: problem encountered while building source files in eesupp:"
4666a7f4f2 Ed H*2328         cat make_eesupp.errors 1>&2
6aec5d9846 Ed H*2329         exit 1
                2330     fi
                2331 fi
                2332 
822f69f065 Ed H*2333 #same for pkg/exch2 and pkg/regrid
                2334 for pdir in exch2 regrid ; do
                2335     if test -r $ROOTDIR"/pkg/${pdir}/Makefile" ; then
                2336         echo "  Making source files in pkg/${pdir} from templates"
149a2bf4b6 Jean*2337         ( cd $ROOTDIR"/pkg/"${pdir} && $MAKE clean_old && $MAKE \
                2338         ) > make_${pdir}.errors 2>&1
822f69f065 Ed H*2339         RETVAL=$?
                2340         if test "x${RETVAL}" = x0 ; then
                2341             rm -f make_${pdir}.errors
                2342         else
                2343             echo "Error: problem encountered while building source files in pkg/${pdir}:"
                2344             cat make_${pdir}.errors 1>&2
                2345             exit 1
                2346         fi
73aeb7d4dc Andr*2347     fi
822f69f065 Ed H*2348 done
73aeb7d4dc Andr*2349 
76c1b0ef61 Ed H*2350 printf "\n===  Determining package settings  ===\n"
a5a3c4e100 Jean*2351 if  test "x${PKG_DEPEND}" = x ; then
6aec5d9846 Ed H*2352     tmp=$ROOTDIR"/pkg/pkg_depend"
a5a3c4e100 Jean*2353     if test -r $tmp ; then PKG_DEPEND=$tmp ; fi
                2354 fi
                2355 if  test "x${PKG_DEPEND}" = x ; then
6aec5d9846 Ed H*2356         echo "Warning:  No package dependency information was specified."
                2357         echo "  Please check that ROOTDIR/pkg/pkg_depend exists."
a5a3c4e100 Jean*2358 else
                2359     if test ! -r ${PKG_DEPEND} ; then
                2360         echo "Error:  can't read package dependency info from PKG_DEPEND=\"$PKG_DEPEND\""
                2361         exit 1
6aec5d9846 Ed H*2362     fi
a5a3c4e100 Jean*2363     echo "  getting package dependency info from  $PKG_DEPEND"
                2364 #  Strip the comments and then convert the dependency file into arrays: PNAME, DNAME
                2365     get_pdepend_list $PKG_DEPEND
                2366 fi
                2367 
                2368 # A default package groups file "$ROOTDIR/pkg/pkg_groups" is provided
                2369 #  to define the "default_pkg_list" and package groups (for convenience, one
                2370 #  can specify a group of packages using names like "ocean" and "atmosphere").
                2371 if test "x${PKG_GROUPS}" = x ; then
                2372     tmp=$ROOTDIR"/pkg/pkg_groups"
                2373     if test -r $tmp ; then PKG_GROUPS=$tmp ; fi
                2374 fi
                2375 if test "x${PKG_GROUPS}" = x ; then
                2376         echo "Warning:  No package groups information was specified."
                2377         echo "  Please check that ROOTDIR/pkg/pkg_groups exists."
6aec5d9846 Ed H*2378 else
a5a3c4e100 Jean*2379     if test ! -r ${PKG_GROUPS} ; then
                2380         echo "Error:  can't read package groups info from PKG_GROUPS=\"$PKG_GROUPS\""
6aec5d9846 Ed H*2381         exit 1
                2382     fi
a5a3c4e100 Jean*2383     echo "  getting package groups info from      $PKG_GROUPS"
6aec5d9846 Ed H*2384 fi
a5a3c4e100 Jean*2385 
                2386 #  Search for packages to compile.
                2387 echo "  checking list of packages to compile:"
                2388 PKG_LIST=
                2389 if test "x${PKG_LIST}" = x ; then
6d54cf9ca1 Ed H*2390     for i in "." $MODS ; do
                2391         if test -r $i"/packages.conf" ; then
a5a3c4e100 Jean*2392                 PKG_LIST=$i"/packages.conf"
6d54cf9ca1 Ed H*2393                 break
                2394         fi
                2395     done
                2396 fi
a5a3c4e100 Jean*2397 if test "x${PKG_LIST}" = x ; then
                2398     pkg_list='default_pkg_list'
                2399     if test "x${PKG_GROUPS}" = x ; then
                2400         echo "Error:  need package groups info to expand pkg_list=\"$pkg_list\""
                2401         exit 1
                2402     fi
6aec5d9846 Ed H*2403 else
a5a3c4e100 Jean*2404     if test ! -r $PKG_LIST ; then
                2405         echo "Error:  can't read package list from PKG_LIST=\"$PKG_LIST\""
                2406         exit 1
6aec5d9846 Ed H*2407     else
a5a3c4e100 Jean*2408         echo "    using PKG_LIST=\"$PKG_LIST\""
36e14999eb Jean*2409         #  Strip the comments and add all the names
a5a3c4e100 Jean*2410         pkg_list=`cat $PKG_LIST | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
6aec5d9846 Ed H*2411         RETVAL=$?
                2412         if test "x${RETVAL}" != x0 ; then
a5a3c4e100 Jean*2413             printf "Error: can't parse package list "
                2414             echo "-- please check PKG_LIST=\"$PKG_LIST\""
6aec5d9846 Ed H*2415             exit 1
                2416         fi
                2417     fi
                2418 fi
a5a3c4e100 Jean*2419 for i in $pkg_list ; do
                2420     PACKAGES="$PACKAGES $i"
                2421 done
                2422 echo     "    before group expansion packages are:$PACKAGES"
                2423 if test "x${PKG_GROUPS}" != x ; then
                2424     RET=1
                2425     while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
                2426     echo "    after group expansion packages are: $PACKAGES"
                2427 fi
6aec5d9846 Ed H*2428 
                2429 echo "  applying DISABLE settings"
7deef35259 Jean*2430 echo "" > $TMP.pack
d3d6cca041 Alis*2431 for i in $PACKAGES ; do
7deef35259 Jean*2432     echo $i >> $TMP.pack
d3d6cca041 Alis*2433 done
7deef35259 Jean*2434 for i in `grep  "-" $TMP.pack` ; do
d3d6cca041 Alis*2435     j=`echo $i | sed 's/[-]//'`
                2436     DISABLE="$DISABLE $j"
                2437 done
6aec5d9846 Ed H*2438 pack=
                2439 for p in $PACKAGES ; do
                2440     addit="t"
                2441     for d in $DISABLE ; do
                2442         if test "x$p" = "x$d" ; then
                2443             addit="f"
                2444         fi
                2445     done
                2446     if test "x$addit" = xt ; then
                2447         pack="$pack $p"
                2448     fi
                2449 done
                2450 PACKAGES="$pack"
                2451 echo "  applying ENABLE settings"
7deef35259 Jean*2452 echo "" > $TMP.pack
6aec5d9846 Ed H*2453 PACKAGES="$PACKAGES $ENABLE"
d3d6cca041 Alis*2454 # Test if each explicitly referenced package exists
6aec5d9846 Ed H*2455 for i in $PACKAGES ; do
d3d6cca041 Alis*2456     j=`echo $i | sed 's/[-+]//'`
                2457     if test ! -d "$ROOTDIR/pkg/$j" ; then
a5a3c4e100 Jean*2458         echo "Error: dir '$ROOTDIR/pkg/$i' missing for package '$i'"
776d1c0efd Jean*2459         exit 1
6aec5d9846 Ed H*2460     fi
7deef35259 Jean*2461     echo $i >> $TMP.pack
6aec5d9846 Ed H*2462 done
                2463 PACKAGES=
7deef35259 Jean*2464 for i in `grep -v "-" $TMP.pack | sort | uniq` ; do
6aec5d9846 Ed H*2465     PACKAGES="$PACKAGES $i"
                2466 done
7deef35259 Jean*2467 rm -f $TMP.pack
bf318dd62d Jean*2468 echo "    packages are: $PACKAGES"
6aec5d9846 Ed H*2469 
5be35a17af Jean*2470 #  Check for package MNC: if NetCDF is available, then build the MNC
55252a5af3 Jean*2471 #  template files ; otherwise, delete mnc from the list of packages.
bf318dd62d Jean*2472 echo " $PACKAGES " | grep ' mnc ' > /dev/null 2>&1
5be35a17af Jean*2473 mnc_in=$?
                2474 if test "x$HAVE_NETCDF" != xt ; then
                2475     if test "x$mnc_in" = x0 ; then
bee85d1689 Ed H*2476         cat <<EOF
                2477 *********************************************************************
                2478 WARNING: the "mnc" package was enabled but tests failed to compile
                2479   NetCDF applications.  Please check that:
                2480 
                2481   1) NetCDF is correctly installed for this compiler and
5be35a17af Jean*2482   2) the LIBS variable (within the "optfile") specifies the correct
bee85d1689 Ed H*2483        NetCDF library to link against.
                2484 
                2485   Due to this failure, the "mnc" package is now DISABLED.
                2486 *********************************************************************
                2487 EOF
                2488         PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
                2489         DISABLE="$DISABLE mnc"
                2490     else
5be35a17af Jean*2491     #  this prevent to add mnc (due to pdepend rules) if not available
                2492         DISABLE="$DISABLE mnc"
                2493     fi
                2494 else
                2495     # we have NetCDF, we try to build MNC template files
                2496     ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
                2497     RETVAL=$?
                2498     if test "x${RETVAL}" = x0 ; then
                2499         rm -f make_mnc.errors
                2500     else
                2501         echo "Error: problem encountered while building source files in pkg/mnc:"
                2502         cat make_mnc.errors 1>&2
                2503         if test "x$mnc_in" = x0 ; then
36e14999eb Jean*2504             exit 1
bee85d1689 Ed H*2505         else
5be35a17af Jean*2506             DISABLE="$DISABLE mnc"
bee85d1689 Ed H*2507         fi
                2508     fi
                2509 fi
                2510 
55252a5af3 Jean*2511 #  Check for package PROFILES: if NetCDF is not available,
                2512 #  then delete profiles from the list of available packages.
5be35a17af Jean*2513 if test "x$HAVE_NETCDF" != xt ; then
                2514     echo " $PACKAGES " | grep ' profiles ' > /dev/null 2>&1
                2515     RETVAL=$?
                2516     if test "x$RETVAL" = x0 ; then
55252a5af3 Jean*2517         cat <<EOF
                2518 *********************************************************************
                2519 WARNING: the "profiles" package was enabled but tests failed to
                2520   compile NetCDF applications.  Please check that:
                2521 
                2522   1) NetCDF is correctly installed for this compiler and
5be35a17af Jean*2523   2) the LIBS variable (within the "optfile") specifies the correct
55252a5af3 Jean*2524        NetCDF library to link against.
                2525 
                2526   Due to this failure, the "profiles" package is now DISABLED.
                2527 *********************************************************************
                2528 EOF
                2529         PACKAGES=`echo $PACKAGES | sed -e 's/profiles//g'`
                2530         DISABLE="$DISABLE profiles"
5be35a17af Jean*2531     else
                2532     #  this prevent to add profiles (due to pdepend rules) if not available
                2533         DISABLE="$DISABLE profiles"
55252a5af3 Jean*2534     fi
                2535 fi
                2536 
b4daa24319 Shre*2537 #  Make sure the tapenade package is enabled if using TAPENADE
                2538 if test "x$TAPENADE" != x ; then
                2539     echo " $PACKAGES " | grep ' tapenade ' > /dev/null 2>&1
                2540     RETVAL=$?
                2541     if test "x$RETVAL" != x0 ; then
                2542         cat <<EOF
                2543 
                2544 *********************************************************************
                2545 ERROR: when generating an adjoint with TAPENADE, the tapenade package
                2546   must be enabled.  Please add it to packages.conf.
                2547 *********************************************************************
                2548 
                2549 EOF
                2550         exit 1
                2551     fi
                2552 fi
                2553 
c5032d3931 Oliv*2554 #  Make sure the openad package is enabled if using OpenAD
                2555 if test "x$OPENAD" != x ; then
                2556     echo " $PACKAGES " | grep ' openad ' > /dev/null 2>&1
                2557     RETVAL=$?
                2558     if test "x$RETVAL" != x0 ; then
                2559         cat <<EOF
                2560 
                2561 *********************************************************************
                2562 ERROR: when generating an adjoint with OpenAD, the openad package
                2563   must be enabled.  Please add it to packages.conf.
                2564 *********************************************************************
                2565 
                2566 EOF
                2567         exit 1
                2568     fi
                2569 fi
                2570 
a5a3c4e100 Jean*2571 if  test "x${PKG_DEPEND}" != x ; then
                2572   echo "  applying package dependency rules"
                2573   ck=
                2574   while test "x$ck" != xtt ; do
6aec5d9846 Ed H*2575     i=0
76c1b0ef61 Ed H*2576     # rtot=${#PNAME[@]}
                2577     rtot=$nname
553241f6b0 Jean*2578     while test $i -le $rtot ; do
6aec5d9846 Ed H*2579 
                2580         #  Is $pname in the current $PACKAGES list?
76c1b0ef61 Ed H*2581         #  pname=${PNAME[$i]}
                2582         tmp="pname=\"\$PNAME_$i\""
                2583         eval $tmp
6aec5d9846 Ed H*2584         pin="f"
                2585         for p in $PACKAGES ; do
                2586             if test "x$p" = "x$pname" ; then
                2587                 pin="t"
                2588             fi
                2589         done
bf318dd62d Jean*2590         #  or in the current $STANDARDDIRS list?
                2591         for p in $STANDARDDIRS ; do
                2592             if test "x$p" = "x$pname" ; then pin="t" ; fi
                2593         done
6aec5d9846 Ed H*2594 
12417e3119 Jean*2595         #  Is the DNAME entry a (=), (+) or (-) rule ?
76c1b0ef61 Ed H*2596         tmp="dname=\"\$DNAME_$i\""
                2597         eval $tmp
12417e3119 Jean*2598         plus="a"
76c1b0ef61 Ed H*2599         echo $dname | grep '^+' > /dev/null 2>&1
6aec5d9846 Ed H*2600         RETVAL=$?
12417e3119 Jean*2601         if test "x$RETVAL" = x0 ; then plus="+" ; fi
                2602         echo $dname | grep '^-' > /dev/null 2>&1
                2603         RETVAL=$?
                2604         if test "x$RETVAL" = x0 ; then plus="-" ; fi
6aec5d9846 Ed H*2605 
                2606         #  Is $dname in the current $PACKAGES list?
12417e3119 Jean*2607         dname=`echo $dname | sed -e 's/^[=+-]//'`
6aec5d9846 Ed H*2608         din="f"
                2609         for p in $PACKAGES ; do
                2610             if test "x$p" = "x$dname" ; then
                2611                 din="t"
                2612             fi
                2613         done
                2614 
                2615         #  Do we need to add $dname according to the dependency rules?
12417e3119 Jean*2616         if test "x$pin" = xt -a "x$plus" != "x-" -a "x$din" = xf ; then
776d1c0efd Jean*2617             #echo "   " $pname ": need to add :" $dname
6aec5d9846 Ed H*2618             in_dis="f"
                2619             for dis in $DISABLE ; do
                2620                 if test "x$dis" = "x$dname" ; then
                2621                     in_dis="t"
                2622                 fi
                2623             done
                2624             if test "x$in_dis" = xt ; then
12417e3119 Jean*2625                 if test "x$plus" = "x+" ; then
                2626                     echo "Error: can't satisfy package dependencies:"
                2627                     echo "  \"$dname\" is required with pkg \"$pname\" (dependency rules)"
                2628                     echo "  but is disallowed by the DISABLE settings"
                2629                     exit 1
                2630                 elif test "x$ck" = xt ; then
                2631                 #- (=) is a weaker dependency rule: warning but no stop
                2632                     echo    "Warning: pkg \"$dname\" is set DISABLE (from: \"$PKG_LIST\")"
                2633                     echo -n "     but is recommended with pkg \"$pname\" (dependency rules)"
                2634                     echo " <- ignores recommendation"
                2635                 fi
6aec5d9846 Ed H*2636             else
                2637                 PACKAGES="$PACKAGES $dname"
                2638                 ck=
                2639             fi
                2640         fi
                2641 
                2642         #  Do we need to get rid of $dname according to the dependency rules?
                2643         if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then
                2644             echo "Error: can't satisfy package dependencies:"
12417e3119 Jean*2645             echo "  \"$dname\" was requested but is disallowed by"
                2646             echo "  the dependency rules for \"$pname\""
6aec5d9846 Ed H*2647             exit 1
                2648         fi
ef774c4a3e Jean*2649         i=`expr $i + 1`
                2650         #i=`echo "$i + 1" | bc -l`
6aec5d9846 Ed H*2651     done
                2652     ck=$ck"t"
a5a3c4e100 Jean*2653   done
                2654   echo "    packages are: $PACKAGES"
                2655 fi
6aec5d9846 Ed H*2656 for i in $PACKAGES ; do
                2657     adr="$ROOTDIR/pkg/$i"
25bb252094 Jean*2658     adrmk='$(ROOTDIR)'"/pkg/$i"
6aec5d9846 Ed H*2659     if test -d $adr ; then
                2660         SOURCEDIRS="$SOURCEDIRS $adr"
                2661         INCLUDEDIRS="$INCLUDEDIRS $adr"
25bb252094 Jean*2662         SOURCEDIRSMK="$SOURCEDIRSMK $adrmk"
                2663         INCLUDEDIRSMK="$INCLUDEDIRSMK $adrmk"
668b211e58 Ed H*2664         if test "x$i" = xautodiff ; then
                2665             AUTODIFF_PKG_USED=t
                2666         fi
6aec5d9846 Ed H*2667     else
                2668         echo "Error: the directory \"$adr\" for package $i doesn't exist"
                2669         exit 1
                2670     fi
                2671 done
                2672 
6d54cf9ca1 Ed H*2673 # Create a list of #define and #undef to enable/disable packages
                2674 PACKAGES_DOT_H=PACKAGES_CONFIG.h
5be35a17af Jean*2675 #  The following UGLY HACK sets multiple "#undef"s and it needs to go
                2676 #  away.  On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
6aec5d9846 Ed H*2677 #  file would eventually be split up so that all package-related #define
                2678 #  statements could be separated and handled only by genmake.
                2679 names=`ls -1 "$ROOTDIR/pkg"`
                2680 all_pack=
0c83fc374c Alis*2681 DISABLED_PACKAGES=
6aec5d9846 Ed H*2682 for n in $names ; do
                2683     if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
                2684         has_pack="f"
                2685         for pack in $PACKAGES ; do
                2686             if test "x$pack" = "x$n" ; then
                2687                 has_pack="t"
                2688                 break
                2689             fi
                2690         done
                2691         if test "x$has_pack" = xf ; then
523cb1423f Ed H*2692             undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
776d1c0efd Jean*2693             DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
6aec5d9846 Ed H*2694         fi
                2695     fi
                2696 done
0c83fc374c Alis*2697 ENABLED_PACKAGES=
6aec5d9846 Ed H*2698 for i in $PACKAGES ; do
523cb1423f Ed H*2699     def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
0c83fc374c Alis*2700     ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
6d54cf9ca1 Ed H*2701 #eh3 DEFINES="$DEFINES -D$def"
6aec5d9846 Ed H*2702 
                2703 #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
5be35a17af Jean*2704     case $i in
6aec5d9846 Ed H*2705         aim_v23)
776d1c0efd Jean*2706             ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
a1c0f64028 Jean*2707             echo "Warning: ALLOW_AIM is set to enable aim_v23."
6aec5d9846 Ed H*2708             ;;
                2709     esac
                2710 #EH3  WARNING :  This is an UGLY HACK that needs to be removed!!!
                2711 
                2712 done
                2713 
bf318dd62d Jean*2714 echo "  Adding STANDARDDIRS='$STANDARDDIRS'"
6aec5d9846 Ed H*2715 BUILDDIR=${BUILDDIR:-.}
57ace0c46a Ed H*2716 if test "x$STANDARDDIRS" != x ; then
                2717     for d in $STANDARDDIRS ; do
                2718         adr="$ROOTDIR/$d/src"
25bb252094 Jean*2719         adrmk='$(ROOTDIR)/'"$d/src"
57ace0c46a Ed H*2720         if test ! -d $adr ; then
                2721             echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
                2722             echo "  is correct and that you correctly specified the STANDARDDIRS option"
                2723             exit 1
                2724         else
                2725             SOURCEDIRS="$SOURCEDIRS $adr"
25bb252094 Jean*2726             SOURCEDIRSMK="$SOURCEDIRSMK $adrmk"
57ace0c46a Ed H*2727         fi
                2728         adr="$ROOTDIR/$d/inc"
25bb252094 Jean*2729         adrmk='$(ROOTDIR)/'"$d/inc"
57ace0c46a Ed H*2730         if test ! -d $adr ; then
                2731             echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
                2732             echo "  is correct and that you correctly specified the STANDARDDIRS option"
                2733             exit 1
                2734         else
                2735             INCLUDEDIRS="$INCLUDEDIRS $adr"
25bb252094 Jean*2736             INCLUDEDIRSMK="$INCLUDEDIRSMK $adrmk"
57ace0c46a Ed H*2737         fi
                2738     done
                2739 fi
6aec5d9846 Ed H*2740 
40f7a33215 Alis*2741 echo "  Searching for *OPTIONS.h files in order to warn about the presence"
                2742 echo "    of \"#define \"-type statements that are no longer allowed:"
6d54cf9ca1 Ed H*2743 CPP_OPTIONS=
40f7a33215 Alis*2744 CPP_EEOPTIONS=
6d54cf9ca1 Ed H*2745 spaths=". $INCLUDEDIRS"
40f7a33215 Alis*2746 names=`ls -1 "$ROOTDIR/pkg"`
6d54cf9ca1 Ed H*2747 for i in $spaths ; do
                2748     try="$i/CPP_OPTIONS.h"
5e1b06e200 Ed H*2749     if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
6d54cf9ca1 Ed H*2750         echo "    found CPP_OPTIONS=\"$try\""
                2751         CPP_OPTIONS="$try"
776d1c0efd Jean*2752         # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
                2753         for n in $names ; do
                2754             test_for_package_in_cpp_options $CPP_OPTIONS $n
                2755         done
40f7a33215 Alis*2756     fi
                2757     try="$i/CPP_EEOPTIONS.h"
5e1b06e200 Ed H*2758     if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
40f7a33215 Alis*2759         echo "    found CPP_EEOPTIONS=\"$try\""
776d1c0efd Jean*2760         # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
40f7a33215 Alis*2761 #**** not yet enabled ****
                2762 #        test_for_mpi_in_cpp_eeoptions $try
                2763 #**** not yet enabled ****
                2764         CPP_EEOPTIONS="$try"
6d54cf9ca1 Ed H*2765     fi
                2766 done
                2767 if test "x$CPP_OPTIONS" = x ; then
                2768     echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
                2769     exit 1
                2770 fi
6aec5d9846 Ed H*2771 
ea893758ea Patr*2772 #  Here, we build the list of files to be "run through" the adjoint compiler.
                2773 #  split this list between F77 and F90 src code:
668b211e58 Ed H*2774 echo "  Creating the list of files for the adjoint compiler."
ea893758ea Patr*2775 test -f $TMP.adSrcFiles && rm -f $TMP.adSrcFiles
                2776 test -f $TMP.adF90Files && rm -f $TMP.adF90Files
7deef35259 Jean*2777 touch $TMP.adSrcFiles
ea893758ea Patr*2778 touch $TMP.adF90Files
668b211e58 Ed H*2779 for i in $SOURCEDIRS ; do
0524b7d1ff Mart*2780     list_files=`( cd $i && ls -1 *_ad_diff.list 2>/dev/null )`
668b211e58 Ed H*2781     for j in $list_files ; do
ea893758ea Patr*2782         grep '\.f\>'   $i/$j >> $TMP.adSrcFiles
                2783         grep '\.f90\>' $i/$j >> $TMP.adF90Files
668b211e58 Ed H*2784     done
                2785 done
4b2baec0be Ed H*2786 
76c1b0ef61 Ed H*2787 echo
                2788 echo "===  Creating the Makefile  ==="
6aec5d9846 Ed H*2789 echo "  setting INCLUDES"
                2790 for i in $INCLUDEDIRS ; do
1d6dde53d4 Ed H*2791     if test ! -d $i ; then
6aec5d9846 Ed H*2792         echo "Warning: can't find INCLUDEDIRS=\"$i\""
                2793     fi
                2794 done
                2795 
7783960e4d Jean*2796 if test ! "x$DIVA" = x -a ! "x$MPI" = x ; then
cd15dc9a7a Jean*2797     if test ! "x$MPIINCLUDEDIR" = x ; then
fea3e7d209 Jean*2798         #  Do a local copy of MPI headers files (in local dir ./mpi_headers/) after
                2799         #   checking for additional included headers (in case of chain of included
                2800         #   header); also set LOCAL_MPI_HEADERS (if not already set)
                2801         mpi_headers_do_local_copy
29eb399fd0 Cons*2802     fi
                2803 fi
                2804 
6aec5d9846 Ed H*2805 echo "  Determining the list of source and include files"
7deef35259 Jean*2806 rm -rf $TMP.links
                2807 mkdir $TMP.links
                2808 touch $TMP.links/foo
                2809 if test ! -r "$TMP.links/foo" ; then
5709a39825 Ed H*2810     echo
                2811     echo "ERROR : something is wrong with your directory permissions or"
                2812     echo "   your user file-creation mask (\"umask\") since creating a"
                2813     echo "   sub-dir, touch-ing a file within it, and then reading it is"
                2814     echo "   not working.  Please try setting your umask to something"
                2815     echo "   sane such as:"
                2816     echo
                2817     echo "      umask 0002"
                2818     echo
                2819     echo "   and please verify that you have the proper permissions for"
                2820     echo "   creating sub-directories and then reading files created"
                2821     echo "   within them."
                2822     echo
                2823     exit 1
                2824 fi
7deef35259 Jean*2825 rm -f $TMP.links/foo
5bd7f28048 Jean*2826 
b4daa24319 Shre*2827 if test "x$TAPENADE" != x ; then
                2828     TAP_DONT_COMPILE="/dev/null"
                2829     TAP_DONT_TRANSFORM="/dev/null"
                2830     TAP_KEEP_ORIGINAL="/dev/null"
                2831     TAP_CB2M_FILES="/dev/null"
                2832     TAPTOOLS="$TOOLSDIR/TAP_support"
                2833     TAPTOOLSMK='$(TOOLSDIR)/TAP_support'
                2834     echo "  looking for dontCompile file:  "
                2835     for i in "." $MODS $TAPTOOLS ; do
                2836         if test -r $i"/dontCompile" ; then
                2837             TAP_DONT_COMPILE=$i"/dontCompile"
                2838             echo "     found $TAP_DONT_COMPILE"
                2839             break
                2840         fi
                2841     done
                2842     echo "  looking for dontTransform file:  "
                2843     for i in "." $MODS $TAPTOOLS ; do
                2844         if test -r $i"/dontTransform" ; then
                2845             TAP_DONT_TRANSFORM=$i"/dontTransform"
                2846             echo "     found $TAP_DONT_TRANSFORM"
                2847             break
                2848         fi
                2849     done
                2850     echo "  looking for keepOriginal file:  "
                2851     for i in "." $MODS $TAPTOOLS ; do
                2852         if test -r $i"/keepOriginal" ; then
                2853             TAP_KEEP_ORIGINAL=$i"/keepOriginal"
                2854             echo "     found $TAP_KEEP_ORIGINAL"
                2855             break
                2856         fi
                2857     done
                2858     echo "  looking for cb2mFiles:  "
                2859     for i in "." $MODS $TAPTOOLS ; do
                2860         if test -r $i"/cb2mFiles" ; then
                2861             TAP_CB2M_FILES=$i"/cb2mFiles"
                2862             echo "     found $TAP_CB2M_FILES"
                2863             break
                2864         fi
                2865     done
                2866     echo "   TAPENADE exceptions:  "
                2867 fi
                2868 
5be35a17af Jean*2869 if test "x$OPENAD" != x ; then
5bd7f28048 Jean*2870     OAD_DONT_COMPILE="/dev/null"
                2871     OAD_DONT_TRANSFORM="/dev/null"
                2872     OAD_KEEP_ORIGINAL="/dev/null"
                2873     OAD_CB2M_FILES="/dev/null"
8702af1f36 Patr*2874     OADTOOLS="$TOOLSDIR/OAD_support"
25bb252094 Jean*2875     OADTOOLSMK='$(TOOLSDIR)/OAD_support'
5bd7f28048 Jean*2876     echo "  looking for dontCompile file:  "
595aad8523 Patr*2877     for i in "." $MODS $OADTOOLS ; do
5bd7f28048 Jean*2878         if test -r $i"/dontCompile" ; then
                2879             OAD_DONT_COMPILE=$i"/dontCompile"
                2880             echo "     found $OAD_DONT_COMPILE"
                2881             break
                2882         fi
                2883     done
                2884     echo "  looking for dontTransform file:  "
595aad8523 Patr*2885     for i in "." $MODS $OADTOOLS ; do
5bd7f28048 Jean*2886         if test -r $i"/dontTransform" ; then
                2887             OAD_DONT_TRANSFORM=$i"/dontTransform"
                2888             echo "     found $OAD_DONT_TRANSFORM"
                2889             break
                2890         fi
                2891     done
                2892     echo "  looking for keepOriginal file:  "
595aad8523 Patr*2893     for i in "." $MODS $OADTOOLS ; do
5bd7f28048 Jean*2894         if test -r $i"/keepOriginal" ; then
                2895             OAD_KEEP_ORIGINAL=$i"/keepOriginal"
                2896             echo "     found $OAD_KEEP_ORIGINAL"
                2897             break
                2898         fi
                2899     done
                2900     echo "  looking for cb2mFiles:  "
595aad8523 Patr*2901     for i in "." $MODS $OADTOOLS ; do
5bd7f28048 Jean*2902         if test -r $i"/cb2mFiles" ; then
                2903             OAD_CB2M_FILES=$i"/cb2mFiles"
                2904             echo "     found $OAD_CB2M_FILES"
                2905             break
                2906         fi
                2907     done
                2908     echo "   OpenAD exceptions:  "
                2909 fi
                2910 
7deef35259 Jean*2911 echo "# This section creates symbolic links" > $TMP.srclinks
                2912 echo "" >> $TMP.srclinks
                2913 printf 'F77_SRC_FILES = ' > $TMP.F77srclist
                2914 printf 'NON_AD_F77_SRC_FILES = ' > $TMP.nonADF77srclist
                2915 printf 'C_SRC_FILES = '   > $TMP.csrclist
                2916 printf 'F90_SRC_FILES = ' > $TMP.F90srclist
ea893758ea Patr*2917 printf 'NON_AD_F90_SRC_FILES = ' > $TMP.nonADF90srclist
7deef35259 Jean*2918 printf 'H_SRC_FILES = '   > $TMP.hsrclist
                2919 printf 'AD_FLOW_FILES = ' > $TMP.ad_flow_files
d119ddb592 Alis*2920 alldirs="$SOURCEDIRS $INCLUDEDIRS ."
25bb252094 Jean*2921 alldirsmk=(${SOURCEDIRSMK} ${INCLUDEDIRSMK} ".")
                2922 nd=0
6aec5d9846 Ed H*2923 for d in $alldirs ; do
25bb252094 Jean*2924     dmk=${alldirsmk[${nd}]}
                2925     nd=$((${nd}+1))
6aec5d9846 Ed H*2926     deplist=
668b211e58 Ed H*2927     sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
27c9249c85 Chri*2928     sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
b4daa24319 Shre*2929     if test "x$TAPENADE" != x ; then
                2930         sfiles=`( echo $sfiles | grep -v _cb2m\. )`
                2931     fi
5be35a17af Jean*2932     if test "x$OPENAD" != x ; then
5bd7f28048 Jean*2933         sfiles=`( echo $sfiles | grep -v _cb2m\. )`
                2934     fi
6aec5d9846 Ed H*2935     for sf in $sfiles ; do
7deef35259 Jean*2936         if test ! -r "$TMP.links/$sf" ; then
6aec5d9846 Ed H*2937             if test -f "$d/$sf" ; then
f7f6e70984 Ed H*2938                 ignore_f=f
776d1c0efd Jean*2939                 case $d/$sf in
                2940                   ./$PACKAGES_DOT_H)
ab504a3a96 Ed H*2941                         ignore_f=t
0c83fc374c Alis*2942                         ;;
776d1c0efd Jean*2943                   ./AD_CONFIG.h)
ab504a3a96 Ed H*2944                         ignore_f=t
0c83fc374c Alis*2945                         ;;
776d1c0efd Jean*2946                   ./FC_NAMEMANGLE.h)
ab504a3a96 Ed H*2947                         ignore_f=t
0c83fc374c Alis*2948                         ;;
776d1c0efd Jean*2949                   ./BUILD_INFO.h)
ab504a3a96 Ed H*2950                         ignore_f=t
                2951                         ;;
776d1c0efd Jean*2952                   ./EMBEDDED_FILES.h)
ab504a3a96 Ed H*2953                         ignore_f=t
f79257694d Ed H*2954                         ;;
776d1c0efd Jean*2955                   *)
f7f6e70984 Ed H*2956                         #  For the local directory *ONLY*,
                2957                         #  ignore all soft-links
                2958                         if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then
                2959                             ignore_f=t
                2960                         else
7deef35259 Jean*2961                             touch $TMP.links/$sf
f7f6e70984 Ed H*2962                             deplist="$deplist $sf"
                2963                         fi
0c83fc374c Alis*2964                         ;;
776d1c0efd Jean*2965                 esac
f7f6e70984 Ed H*2966                 if test "x$ignore_f" = xf ; then
                2967                     extn=`echo $sf | $AWK -F. '{print $NF}'`
ea893758ea Patr*2968                     # this is built-in bash and does not rely on $AWK :
                2969                     # extn=${sf##*.}
f7f6e70984 Ed H*2970                     case $extn in
5bd7f28048 Jean*2971                       F)
7deef35259 Jean*2972                         echo    " \\"  >> $TMP.F77srclist
                2973                         printf " $sf" >> $TMP.F77srclist
b4daa24319 Shre*2974 
                2975                         if test "x$TAPENADE" != x ; then
                2976                             basename=${sf%%.F}
                2977                             isAD=`egrep ^$basename.f'[  ]*' $TMP.adSrcFiles`
                2978                             if test -z "$isAD" ; then
                2979                                 toBeIgnored=`egrep ^$basename'[      ]*' ${TAP_DONT_COMPILE}`
                2980                                 if test -z "$toBeIgnored" ; then
                2981                                     echo    " \\"  >> $TMP.nonADF77srclist
                2982                                     printf " $sf" >> $TMP.nonADF77srclist
                2983                                 else
                2984                                     echo "    not to be compiled   :  $sf"
                2985                                 fi
                2986                             else # file is initially listed as an AD file we want to exclude it
                2987                                  # or we want to retain the untransformed version
                2988                                 notToBeTransformed=`egrep ^$basename'[      ]*' ${TAP_DONT_TRANSFORM}`
                2989                                 untransformedVersionToBeKept=`egrep ^$basename'[      ]*' ${TAP_KEEP_ORIGINAL}`
                2990                                 if test -n "$notToBeTransformed"; then
                2991                                     echo "    not to be transformed:  $sf"
                2992                                 fi
                2993                                 if test -n "$untransformedVersionToBeKept" ; then
                2994                                     echo "    original to be kept  :  $sf"
                2995                                 fi
                2996                                 if test -n "$notToBeTransformed" -o -n "$untransformedVersionToBeKept" ; then
                2997                                     echo    " \\"  >> $TMP.nonADF77srclist
                2998                                     printf " $sf" >> $TMP.nonADF77srclist
                2999                                 fi
                3000                             fi
                3001                         fi
                3002 
7783960e4d Jean*3003                         if test "x$OPENAD" = x ; then
                3004                             basename=${sf%%.F}
7deef35259 Jean*3005                             isAD=`egrep ^$basename.f'[  ]*' $TMP.adSrcFiles`
7783960e4d Jean*3006                             if test -z "$isAD" ; then
7deef35259 Jean*3007                                 echo    " \\"  >> $TMP.nonADF77srclist
                3008                                 printf " $sf" >> $TMP.nonADF77srclist
7783960e4d Jean*3009                             fi
                3010                         else #- OpenAD case:
5bd7f28048 Jean*3011                             basename=${sf%%.F}
7deef35259 Jean*3012                             isAD=`egrep ^$basename.f'[  ]*' $TMP.adSrcFiles`
5be35a17af Jean*3013                             if test -z "$isAD" ; then
5bd7f28048 Jean*3014                                 toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE}`
5be35a17af Jean*3015                                 if test -z "$toBeIgnored" ; then
7deef35259 Jean*3016                                     echo    " \\"  >> $TMP.nonADF77srclist
                3017                                     printf " $sf" >> $TMP.nonADF77srclist
5be35a17af Jean*3018                                 else
5bd7f28048 Jean*3019                                     echo "    not to be compiled   :  $sf"
                3020                                 fi
5be35a17af Jean*3021                             else # file is initially listed as an AD file we want to exclude it
5bd7f28048 Jean*3022                                  # or we want to retain the untransformed version
                3023                                 notToBeTransformed=`egrep ^$basename'[      ]*' ${OAD_DONT_TRANSFORM}`
                3024                                 untransformedVersionToBeKept=`egrep ^$basename'[      ]*' ${OAD_KEEP_ORIGINAL}`
5be35a17af Jean*3025                                 if test -n "$notToBeTransformed"; then
5bd7f28048 Jean*3026                                     echo "    not to be transformed:  $sf"
                3027                                 fi
                3028                                 if test -n "$untransformedVersionToBeKept" ; then
                3029                                     echo "    original to be kept  :  $sf"
5be35a17af Jean*3030                                 fi
5bd7f28048 Jean*3031                                 if test -n "$notToBeTransformed" -o -n "$untransformedVersionToBeKept" ; then
7deef35259 Jean*3032                                     echo    " \\"  >> $TMP.nonADF77srclist
                3033                                     printf " $sf" >> $TMP.nonADF77srclist
5bd7f28048 Jean*3034                                 fi
                3035                             fi
                3036                         fi
                3037                         ;;
                3038                     F90)
ea893758ea Patr*3039                         echo    " \\" >> $TMP.F90srclist
7deef35259 Jean*3040                         printf " $sf" >> $TMP.F90srclist
ea893758ea Patr*3041                         if ( test "x$OPENAD" = x && test "x$TAPENADE" = x ) ; then
                3042                             basename=${sf%%.F90}
                3043                             isAD=`egrep ^$basename.f90'[        ]*' $TMP.adF90Files`
                3044                             if test -z "$isAD" ; then
                3045                                 echo    " \\" >> $TMP.nonADF90srclist
                3046                                 printf " $sf" >> $TMP.nonADF90srclist
                3047                             fi
                3048                         fi
5bd7f28048 Jean*3049                         ;;
                3050                     c)
7deef35259 Jean*3051                         echo    " \\"  >> $TMP.csrclist
                3052                         printf " $sf" >> $TMP.csrclist
5bd7f28048 Jean*3053                         ;;
                3054                     h)
7deef35259 Jean*3055                         echo    " \\"  >> $TMP.hsrclist
                3056                         printf " $sf" >> $TMP.hsrclist
5bd7f28048 Jean*3057                         ;;
776d1c0efd Jean*3058                     flow)
7deef35259 Jean*3059                         echo    " \\"  >> $TMP.ad_flow_files
                3060                         printf " $sf" >> $TMP.ad_flow_files
5bd7f28048 Jean*3061                         ;;
                3062                    esac
                3063                 fi
6aec5d9846 Ed H*3064             fi
                3065         fi
                3066     done
                3067     if test "x$deplist" != x ; then
5bd7f28048 Jean*3068       if test "$d" != "." ; then
7deef35259 Jean*3069         echo "" >> $TMP.srclinks
25bb252094 Jean*3070         echo "#  These files are linked from $dmk ( aka $d )" >> $TMP.srclinks
7deef35259 Jean*3071         echo "$deplist :" >> $TMP.srclinks
097ea4d955 Oliv*3072 # We need to make sure that the link isn't already there.
                3073 # This may happen when make thinks that a header file has to be "remade"
                3074 # because a module it depends on has changed.  In this case we do nothing.
25bb252094 Jean*3075         printf "\tif [ ! -L \$@ ]; then \$(LN) %s/\$@ \$@; fi\n" $dmk >> $TMP.srclinks
5bd7f28048 Jean*3076       fi
6aec5d9846 Ed H*3077     fi
                3078 done
7deef35259 Jean*3079 rm -rf $TMP.links
                3080 echo "" >> $TMP.F77srclist
                3081 echo "" >> $TMP.nonADF77srclist
ea893758ea Patr*3082 echo "" >> $TMP.nonADF90srclist
7deef35259 Jean*3083 echo "" >> $TMP.csrclist
                3084 echo "" >> $TMP.F90srclist
                3085 echo "" >> $TMP.hsrclist
                3086 echo "" >> $TMP.ad_flow_files
6aec5d9846 Ed H*3087 
0ec5c8a391 Jean*3088 CMDLINE=$0
                3089 for xx in "$@" ; do nw=`echo $xx | wc -w`
                3090     if test $nw = '1' ; then CMDLINE="$CMDLINE $xx"
36e14999eb Jean*3091                         else CMDLINE="$CMDLINE '$xx'" ; fi
0ec5c8a391 Jean*3092 done
                3093 
355771feeb Ed H*3094 if test -f $MAKEFILE ; then
bf318dd62d Jean*3095     mv -f $MAKEFILE "$MAKEFILE.old"
6aec5d9846 Ed H*3096 fi
                3097 echo "  Writing makefile: $MAKEFILE"
                3098 echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
                3099 echo "#    $MACHINE" >> $MAKEFILE
                3100 echo "# This makefile was generated automatically on" >> $MAKEFILE
                3101 echo "#    $THISDATE" >> $MAKEFILE
                3102 echo "# by the command:" >> $MAKEFILE
0ec5c8a391 Jean*3103 echo "#    $CMDLINE"  >> $MAKEFILE
6aec5d9846 Ed H*3104 echo "# executed by:" >> $MAKEFILE
9a263a84a8 Ed H*3105 echo "#    ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
74d4132da5 Ed H*3106 
b4daa24319 Shre*3107 if test "x$TAPENADE" = x ; then
                3108     EXE_ADJ=$EXECUTABLE"_ad"
                3109     EXE_TLM=$EXECUTABLE"_ftl"
                3110 else
                3111     EXE_ADJ=$EXECUTABLE"_tap_adj"
                3112     EXE_TLM=$EXECUTABLE"_tap_tlm"
                3113 fi
74d4132da5 Ed H*3114 EXE_SVD=$EXECUTABLE"_svd"
                3115 
6aec5d9846 Ed H*3116 cat >>$MAKEFILE <<EOF
0058ae90fe Ed H*3117 #
                3118 # OPTFILE="$OPTFILE"
bf318dd62d Jean*3119 #
6aec5d9846 Ed H*3120 # BUILDDIR     : Directory where object files are written
                3121 # SOURCEDIRS   : Directories containing the source (.F) files
                3122 # INCLUDEDIRS  : Directories containing the header-source (.h) files
                3123 # EXEDIR       : Directory where executable that is generated is written
                3124 # EXECUTABLE   : Full path of executable binary
                3125 #
                3126 # CPP          : C-preprocessor command
                3127 # INCLUDES     : Directories searched for header files
                3128 # DEFINES      : Macro definitions for CPP
                3129 # MAKEDEPEND   : Dependency generator
                3130 # FC           : Fortran compiler command
                3131 # FFLAGS       : Configuration/debugging options for FC
                3132 # FOPTIM       : Optimization options for FC
                3133 # LINK         : Command for link editor program
                3134 # LIBS         : Library flags /or/ additional optimization/debugging flags
                3135 
                3136 ROOTDIR     = ${ROOTDIR}
bf318dd62d Jean*3137 BUILDDIR    = ${BUILDDIR}
25bb252094 Jean*3138 SOURCEDIRS  = ${SOURCEDIRSMK}
                3139 INCLUDEDIRS = ${INCLUDEDIRSMK}
6aec5d9846 Ed H*3140 EXEDIR      = ${EXEDIR}
                3141 EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}
25bb252094 Jean*3142 TOOLSDIR    = ${TOOLSDIRMK}
                3143 OADTOOLS    = ${OADTOOLSMK}
6aec5d9846 Ed H*3144 
668b211e58 Ed H*3145 #eh3  new defines for the adjoint work
25bb252094 Jean*3146 AUTODIFF    = \$(ROOTDIR)/pkg/autodiff
b4daa24319 Shre*3147 EXE_ADJ     = ${EXE_ADJ}
                3148 EXE_TLM     = ${EXE_TLM}
74d4132da5 Ed H*3149 EXE_SVD     = ${EXE_SVD}
668b211e58 Ed H*3150 
0c83fc374c Alis*3151 ENABLED_PACKAGES = ${ENABLED_PACKAGES}
                3152 DISABLED_PACKAGES = ${DISABLED_PACKAGES}
                3153 
40f7a33215 Alis*3154 # These files are created by Makefile
9a263a84a8 Ed H*3155 SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h
6aec5d9846 Ed H*3156 EOF
                3157 
ab504a3a96 Ed H*3158 if test "x$EMBED_SRC" = xt ; then
                3159     echo "EMBEDDED_FILES = EMBEDDED_FILES.h" >>$MAKEFILE
                3160 else
                3161     echo "EMBEDDED_FILES = " >>$MAKEFILE
                3162 fi
                3163 
bc2c9aac73 Oliv*3164 # extract default cpp search path so we can pass it to makedepend
d220271442 Oliv*3165 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}'`
bc2c9aac73 Oliv*3166 
6aec5d9846 Ed H*3167 cat >>$MAKEFILE <<EOF
                3168 # Unix ln (link)
                3169 LN = ${LN}
                3170 # Dependency generator
                3171 MAKEDEPEND = ${MAKEDEPEND}
                3172 # Special preprocessor (KAP on DECs, FPP on Crays)
                3173 KPP = ${KPP}
                3174 # Fortran compiler
89c0a4365c Ed H*3175 FC = ${FC}
27c9249c85 Chri*3176 # Fortran compiler
                3177 F90C = ${F90C}
dec9692aba Ed H*3178 # C compiler
                3179 CC = ${CC}
6aec5d9846 Ed H*3180 # Link editor
e129bec2de Ed H*3181 LINK = ${LINK} ${LDADD}
6aec5d9846 Ed H*3182 
                3183 # Defines for CPP
                3184 DEFINES = ${DEFINES}
                3185 # Includes for CPP
                3186 INCLUDES = ${INCLUDES}
bc2c9aac73 Oliv*3187 # default CPP includes for makedepend
                3188 CPPINCLUDES = ${CPPINCLUDES}
6aec5d9846 Ed H*3189 # Flags for KPP
                3190 KFLAGS1 = ${KFLAGS1}
                3191 KFLAGS2 = ${KFLAGS2}
                3192 # Optim./debug for FC
052caf96de Mart*3193 FFLAGS = ${FFLAGS}
                3194 FOPTIM = ${FOPTIM} ${FEXTRAFLAGS}
27c9249c85 Chri*3195 # Optim./debug for FC
                3196 F90FLAGS = ${F90FLAGS}
                3197 F90OPTIM = ${F90OPTIM}
5bd7f28048 Jean*3198 F90FIXEDFORMAT = ${F90FIXEDFORMAT}
6aec5d9846 Ed H*3199 # Flags for CC
                3200 CFLAGS = ${CFLAGS}
                3201 # Files that should not be optimized
                3202 NOOPTFILES = ${NOOPTFILES}
                3203 NOOPTFLAGS = ${NOOPTFLAGS}
                3204 # Flags and libraries needed for linking
395713ae01 Ed H*3205 LIBS = ${LIBS}
18371f2c52 Jean*3206 # Name of the makefile
621623385c Jean*3207 MAKEFILE = ${MAKEFILE}
                3208 # Name of the make program
                3209 MAKE = ${MAKE}
6aec5d9846 Ed H*3210 
                3211 EOF
                3212 
7deef35259 Jean*3213 cat $TMP.F77srclist      >> $MAKEFILE
                3214 cat $TMP.nonADF77srclist >> $MAKEFILE
ea893758ea Patr*3215 cat $TMP.nonADF90srclist >> $MAKEFILE
7deef35259 Jean*3216 cat $TMP.csrclist        >> $MAKEFILE
                3217 cat $TMP.F90srclist      >> $MAKEFILE
                3218 cat $TMP.hsrclist        >> $MAKEFILE
                3219 cat $TMP.ad_flow_files   >> $MAKEFILE
5bd7f28048 Jean*3220 
ea893758ea Patr*3221 rm -f $TMP.F77srclist $TMP.nonADF77srclist $TMP.nonADF90srclist $TMP.csrclist $TMP.F90srclist $TMP.hsrclist $TMP.ad_flow_files
5bd7f28048 Jean*3222 
5bb11ad8a0 Ed H*3223 echo >> $MAKEFILE
5bd7f28048 Jean*3224 
bf318dd62d Jean*3225 # add definitions for preprocessed sources
                3226 # and note that not all systems allow case sensitive extensions
                3227 # hence the $FS and $FS90 here.
                3228 # for fixed format f90 files we use ff90 or FF90 resp
5bd7f28048 Jean*3229 # but these are not expected to be the original source files
                3230 
                3231 echo 'F77_PP_SRC_FILES = $(F77_SRC_FILES:.F=.'$FS')'      >> $MAKEFILE
                3232 echo 'F90_PP_SRC_FILES = $(F90_SRC_FILES:.F90=.'$FS90')' >> $MAKEFILE
                3233 echo 'OBJFILES= $(F77_SRC_FILES:.F=.o) $(C_SRC_FILES:.c=.o) $(F90_SRC_FILES:.F90=.o)' >> $MAKEFILE
b4daa24319 Shre*3234 
                3235 if test "x$TAPENADE" != x ; then
                3236 cat >>$MAKEFILE <<EOF
                3237 TAPENADE_SUPPORT_C_SRC_FILES = \
                3238 ${TAPTOOLS}/ADFirstAidKit/adStack.c \
                3239 ${TAPTOOLS}/ADFirstAidKit/adBinomial.c
                3240 EOF
                3241 echo 'TAP_SUPPORT_OBJFILES = $(TAPENADE_SUPPORT_C_SRC_FILES:.c=.o)' >> $MAKEFILE
                3242 fi
                3243 
5bb11ad8a0 Ed H*3244 echo >> $MAKEFILE
                3245 echo '.SUFFIXES:' >> $MAKEFILE
71b7a3e5ac Mart*3246 echo '.SUFFIXES: .o .'$FS' .p .F .c .f'$FS90' .'$FS90' .FF90 .F90 .flow' >> $MAKEFILE
6aec5d9846 Ed H*3247 
                3248 cat >>$MAKEFILE <<EOF
                3249 
621623385c Jean*3250 all: fwd_exe_target
                3251 fwd_exe_target:
                3252         @echo Update AD_CONFIG.h and make \$(EXECUTABLE)
                3253         @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Forward version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
                3254         @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
                3255         @-rm -f ad_config.template
                3256         \$(MAKE) -f \$(MAKEFILE) \$(EXECUTABLE)
                3257 
5bd7f28048 Jean*3258 \$(EXECUTABLE): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(OBJFILES) \$(EMBEDDED_FILES)
0c83fc374c Alis*3259         @echo Creating \$@ ...
6aec5d9846 Ed H*3260         \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
dd9f72a48c Jean*3261 
6aec5d9846 Ed H*3262 depend:
621623385c Jean*3263         @\$(MAKE) -f \$(MAKEFILE) links
bc2c9aac73 Oliv*3264         \$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(CPPINCLUDES) \$(F77_SRC_FILES)
f79ba37af1 Mart*3265         \$(MAKEDEPEND) -f \$(MAKEFILE) -a -o .$FS90 \$(DEFINES) \$(INCLUDES) \$(CPPINCLUDES) \$(F90_SRC_FILES)
95cd2dedde Ivan*3266         \$(TOOLSDIR)/f90mkdepend -fs $FS -fs90 $FS90 >> \$(MAKEFILE)
c55c6693ee Ed H*3267         -rm -f makedepend.out
6aec5d9846 Ed H*3268 
04be54cff9 Chri*3269 lib: libmitgcmuv.a
                3270 
25bb252094 Jean*3271 libmitgcmuv.a: \$(SPECIAL_FILES) \$(OBJFILES)
04be54cff9 Chri*3272         ar rcv libmitgcmuv.a \$(OBJFILES)
3a8b237fcd Chri*3273         ar d   libmitgcmuv.a main.o
04be54cff9 Chri*3274 
dd9f72a48c Jean*3275 obj: \$(OBJFILES)
                3276 
5bd7f28048 Jean*3277 links: \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(SPECIAL_FILES)
6aec5d9846 Ed H*3278 
5bd7f28048 Jean*3279 small_f: \$(F77_PP_SRC_FILES) \$(F90_PP_SRC_FILES)
6aec5d9846 Ed H*3280 
6206da1394 Jean*3281 # remove most of the files that "make" generates
6aec5d9846 Ed H*3282 clean:
f68e8310e6 Patr*3283         -rm -rf *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
                3284         -rm -rf *.o
71b7a3e5ac Mart*3285         -rm -rf *.$FS
45de16ddcf Jean*3286         -rm -rf *.f$FS90 \$(AD_CLEAN) ad_input*
6206da1394 Jean*3287 
                3288 # remove most of the files that "make" and "make depend" generate
6aec5d9846 Ed H*3289 Clean:
621623385c Jean*3290         @\$(MAKE) -f \$(MAKEFILE) clean
                3291         @\$(MAKE) -f \$(MAKEFILE) cleanlinks
71b7a3e5ac Mart*3292         -rm -rf *.flowdir
fa507bf6a3 Jean*3293         -rm -f \$(SPECIAL_FILES) f90mkdepend.log $MAKEFILE.old
b9626ac20f Jean*3294         -rm -f taf_command taf_output taf_ad.log taf_ad_flow.log taf_ftl.log
6206da1394 Jean*3295 
                3296 # remove also the executable, files that "genmake2" generates (except Makefile)
683b8f029b Jean*3297 #         and output from a run (plus log files from testreport)
6aec5d9846 Ed H*3298 CLEAN:
621623385c Jean*3299         @\$(MAKE) -f \$(MAKEFILE) Clean
b4daa24319 Shre*3300         -rm -f \$(EXECUTABLE) \$(EXE_ADJ) \$(EXE_TLM) *.bak
8d24b8817c Jean*3301         -rm -f $LOGFILE genmake_state genmake_*optfile
                3302         -rm -f SIZE.h.mpi genmake.tr_log make.tr_log
fea3e7d209 Jean*3303         -rm -rf mpi_headers mnc_test_*
6aec5d9846 Ed H*3304         -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
                3305         -find \$(EXEDIR) -name "*.data" -exec rm {} \;
                3306         -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
bafb387432 Jean*3307         -rm -f *.txt STDOUT.* STDERR.* *diagnostics.log *.[0-9][0-9][0-9][0-9].log
                3308         -rm -f datetime costfinal divided.ctrl snapshot* output_adm.txt.diva_*
                3309         -rm -f *_MIT_CE_000.opt0000 costfunction*0000
cd15dc9a7a Jean*3310         -rm -f oad_cp.[0-9][0-9][0-9].?????
6aec5d9846 Ed H*3311 
                3312 makefile:
6aefb07181 Ed H*3313         $THIS_SCRIPT $G2ARGS
6aec5d9846 Ed H*3314 cleanlinks:
                3315         -find . -type l -exec rm {} \;
                3316 
5bd7f28048 Jean*3317 # Special targets (SPECIAL_FILES) which are created by make
0c83fc374c Alis*3318 ${PACKAGES_DOT_H}:
                3319         @echo Creating \$@ ...
621623385c Jean*3320         @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@
0c83fc374c Alis*3321 AD_CONFIG.h:
                3322         @echo Creating \$@ ...
621623385c Jean*3323         @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Default version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > \$@
40f7a33215 Alis*3324 FC_NAMEMANGLE.h:
                3325         @echo Creating \$@ ...
                3326         echo "$FC_NAMEMANGLE" > \$@
0c83fc374c Alis*3327 
9a263a84a8 Ed H*3328 BUILD_INFO.h:
                3329         @echo Creating \$@ ...
                3330 EOF
                3331 
                3332 test ! "x$THISVER" = x  && echo "       -echo \"#define THISVER '$THISVER'\" > \$@"   >> $MAKEFILE
                3333 test ! "x$THISUSER" = x && echo "       -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE
                3334 test ! "x$THISDATE" = x && echo "       -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
                3335 test ! "x$THISHOST" = x && echo "       -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
                3336 
ab504a3a96 Ed H*3337 if test "x$EMBED_SRC" = xt ; then
                3338     cat >>$MAKEFILE <<EOF
                3339 
                3340 decode_files.o : EMBEDDED_FILES.h
                3341 
bf318dd62d Jean*3342 ##  \$(F77_PP_SRC_FILES)
5bd7f28048 Jean*3343 all_fF.tar.gz : \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile
ab504a3a96 Ed H*3344         @echo Creating \$@ ...
5bd7f28048 Jean*3345         -tar -hcf all_fF.tar \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile
ab504a3a96 Ed H*3346         -rm -f all_fF.tar.gz
                3347         -gzip all_fF.tar
                3348 
                3349 EMBEDDED_FILES.h : all_fF.tar.gz
                3350         @echo Creating \$@ ...
                3351         -\${ROOTDIR}/tools/embed_encode/encode_files EMBEDDED_FILES.h all_fF.tar.gz
                3352 
                3353 EOF
                3354 fi
                3355 
9a263a84a8 Ed H*3356 cat >>$MAKEFILE <<EOF
                3357 
3eb03232c2 Ed H*3358 # The normal chain of rules is (  .F - .$FS - .o  )
                3359 
7a76cc695e Ed H*3360 ## This nullifies any default implicit rules concerning these two file types:
3af519cc10 Jean*3361 ## %.o : %.F
3eb03232c2 Ed H*3362 
7d5fc6b559 Jean*3363 # C preprocessing and replacing the _d in constants:
5158aa0815 Jean*3364 CPPCMD = cat \$< | ${CPP} \$(DEFINES) \$(INCLUDES) | ${S64}
                3365 
3eb03232c2 Ed H*3366 .F.$FS:
5158aa0815 Jean*3367         \$(CPPCMD)  > \$@
3eb03232c2 Ed H*3368 .$FS.o:
6aec5d9846 Ed H*3369         \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
23f21461eb Jean*3370 .F.o:
                3371         \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
5bd7f28048 Jean*3372 .F90.$FS90:
5158aa0815 Jean*3373         \$(CPPCMD)  > \$@
5bd7f28048 Jean*3374 .FF90.f$FS90:
5158aa0815 Jean*3375         \$(CPPCMD)  > \$@
5bd7f28048 Jean*3376 .$FS90.o:
27c9249c85 Chri*3377         \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
5bd7f28048 Jean*3378 .f$FS90.o:
                3379         cp \$< \$(basename  \$<).f90
                3380         \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$(F90FIXEDFORMAT) \$(basename  \$<).f90
6aec5d9846 Ed H*3381 .c.o:
29eb399fd0 Cons*3382         \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$<
6aec5d9846 Ed H*3383 
3eb03232c2 Ed H*3384 # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
                3385 .F.p:
5158aa0815 Jean*3386         \$(CPPCMD) > \$@
3eb03232c2 Ed H*3387 .p.$FS:
6aec5d9846 Ed H*3388         \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
                3389 
5bd7f28048 Jean*3390 EOF
                3391 
668b211e58 Ed H*3392 #=========================================
                3393 #===  Automatic Differentiation Rules  ===
5bd7f28048 Jean*3394 #===  for TAMC/TAF  ======================
                3395 
b4daa24319 Shre*3396 if test "x$TAPENADE" = x ; then
5be35a17af Jean*3397 if test "x$OPENAD" = x ; then
5bd7f28048 Jean*3398 
                3399 cat >>$MAKEFILE <<EOF
668b211e58 Ed H*3400 
                3401 TAMC           = ${TAMC}
                3402 TAF            = ${TAF}
                3403 
0c0e61146f Ed H*3404 TAF_EXTRA      = ${TAF_EXTRA}
                3405 TAMC_EXTRA     = ${TAMC_EXTRA}
fea3e7d209 Jean*3406 LOCAL_MPI_HEADERS    = ${LOCAL_MPI_HEADERS}
0c0e61146f Ed H*3407 
668b211e58 Ed H*3408 EOF
                3409 
                3410 ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
                3411 ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF_FLAGS"
                3412 ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
                3413 for i in $ad_vars ; do
                3414     name=$i
36459526ba Ed H*3415     t1="t2=\$"`echo "$i"`
668b211e58 Ed H*3416     eval $t1
                3417     printf "%-20s = " $name >> $MAKEFILE
36459526ba Ed H*3418     echo "$t2" | sed -e 's| \+| |g' >> $MAKEFILE
668b211e58 Ed H*3419 done
                3420 
                3421 echo "  Add the source list for AD code generation"
                3422 echo >> $MAKEFILE
13fa7032ba Ed H*3423 printf "AD_FILES = " >> $MAKEFILE
ea893758ea Patr*3424 AD_FILES=`cat $TMP.adSrcFiles | sed -e "s/\.f/.$FS/g"`
668b211e58 Ed H*3425 for i in $AD_FILES ; do
0524b7d1ff Mart*3426     echo   " \\" >> $MAKEFILE
13fa7032ba Ed H*3427     printf " $i" >> $MAKEFILE
668b211e58 Ed H*3428 done
                3429 echo >> $MAKEFILE
7deef35259 Jean*3430 rm -f $TMP.adSrcFiles
ea893758ea Patr*3431 printf "AD_F90FILES = " >> $MAKEFILE
                3432 AD_F90FILES=`cat $TMP.adF90Files | sed -e "s/\.f90/.$FS90/g"`
                3433 for i in $AD_F90FILES ; do
0524b7d1ff Mart*3434     echo   " \\" >> $MAKEFILE
ea893758ea Patr*3435     printf " $i" >> $MAKEFILE
                3436 done
                3437 echo >> $MAKEFILE
                3438 rm -f $TMP.adF90Files
668b211e58 Ed H*3439 
44f4a23ebb Jean*3440 if test $CAT_SRC_FOR_TAF = 0 ; then
                3441 cat >>$MAKEFILE <<EOF
                3442 
                3443 # ... Utilities ...
                3444 remove_comments:
                3445         sed -i.bak -f \$(TOOLSDIR)/remove_comments_sed \$(AD_FILES)
                3446         @-rm -f \$(AD_FILES:.$FS=.$FS.bak)
                3447 adj_sed:
                3448         sed -i.bak -f \$(TOOLSDIR)/adjoint_sed \$(AD_FILES:.$FS=_ad.$FS)
                3449         @-rm -f \$(AD_FILES:.$FS=_ad.$FS.bak)
                3450 ftl_sed:
                3451         sed -i.bak -f \$(TOOLSDIR)/adjoint_sed \$(AD_FILES:.$FS=_tl.$FS)
                3452         @-rm -f \$(AD_FILES:.$FS=_tl.$FS.bak)
ea893758ea Patr*3453 adobjfiles: \$(AD_FILES:.$FS=_ad.o) \$(AD_F90FILES:.$FS90=_ad.o)
0524b7d1ff Mart*3454 ftlobjfiles: \$(AD_FILES:.$FS=_tl.o) \$(AD_F90FILES:.$FS90=_tl.o)
44f4a23ebb Jean*3455 EOF
                3456 fi
                3457 
668b211e58 Ed H*3458 cat >>$MAKEFILE <<EOF
                3459 
eb2bbeeb07 Ed H*3460 # ... AD ...
621623385c Jean*3461 adall: ad_exe_target
e1583c94d9 Ed H*3462 adtaf: ad_taf_output.$FS
                3463 adtamc: ad_tamc_output.$FS
74d4132da5 Ed H*3464 
621623385c Jean*3465 ad_exe_target:
b4daa24319 Shre*3466         @echo Update AD_CONFIG.h and make \$(EXE_ADJ)
621623385c Jean*3467         @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
                3468         @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
                3469         @-rm -f ad_config.template
b4daa24319 Shre*3470         \$(MAKE) -f \$(MAKEFILE) \$(EXE_ADJ)
621623385c Jean*3471 
7783960e4d Jean*3472 ad_input_code.$FS: \$(AD_FILES) \$(AD_FLOW_FILES)
621623385c Jean*3473         @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
577a31280a Ed H*3474         cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
621623385c Jean*3475         @-rm -f ad_config.template
                3476         @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
71b7a3e5ac Mart*3477         cat \$(AD_FLOW_FILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ad_input_code.$FS
4a967b9107 Ed H*3478 
ea893758ea Patr*3479 EOF
                3480 if test -n "$AD_F90FILES" ; then
                3481 cat >>$MAKEFILE <<EOF
                3482 ad_inpF90_code.$FS90: \$(AD_F90FILES) \$(AD_FLOW_FILES)
                3483         @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
                3484         cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
                3485         @-rm -f ad_config.template
                3486         @\$(MAKE) -f \$(MAKEFILE) \$(F90_PP_SRC_FILES)
                3487         cat \$(AD_F90FILES) > ad_inpF90_code.$FS90
                3488 
                3489 EOF
                3490 fi
                3491 cat >>$MAKEFILE <<EOF
                3492 # this is an unused target and could be removed
                3493 adtafonly: ad_input_code.$FS
                3494         \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) -fixed ad_input_code.$FS
20ef1172ff Jean*3495         ls -l ad_input_code_ad.$FS
e1583c94d9 Ed H*3496         cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
668b211e58 Ed H*3497 
44f4a23ebb Jean*3498 EOF
                3499 
                3500 if test $CAT_SRC_FOR_TAF = 1 ; then
ea893758ea Patr*3501 if test -z "$AD_F90FILES" ; then
44f4a23ebb Jean*3502 cat >>$MAKEFILE <<EOF
                3503 # ... send 1 file to TAF ...
                3504 ad_taf_output.$FS: ad_input_code.$FS
                3505         @-rm -f ad_input_code_ad.$FS ; echo ''
ea893758ea Patr*3506         \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) -fixed ad_input_code.$FS
20ef1172ff Jean*3507         ls -l ad_input_code_ad.$FS
e1583c94d9 Ed H*3508         cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
405822b4f9 Patr*3509 
ea893758ea Patr*3510 \$(EXE_ADJ): \$(SPECIAL_FILES) \$(H_SRC_FILES) ad_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(NON_AD_F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(EMBEDDED_FILES)
                3511         \$(LINK) -o \${EXE_ADJ} \$(FFLAGS) \$(FOPTIM) ad_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(NON_AD_F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(LIBS)
668b211e58 Ed H*3512 
ea893758ea Patr*3513 adobj: ad_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(NON_AD_F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o)
668b211e58 Ed H*3514 
44f4a23ebb Jean*3515 EOF
ea893758ea Patr*3516 else
                3517 cat >>$MAKEFILE <<EOF
                3518 # ... send 1 fixed format file and 1 free format file to TAF ...
                3519 ad_taf_output.$FS: ad_input_code.$FS ad_inpF90_code.$FS90
                3520         @-rm -f ad_input_code_ad.$FS ad_inpF90_code_ad.$FS90 ; echo ''
                3521         \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) -fixed ad_input_code.$FS -free ad_inpF90_code.$FS90
                3522         ls -l ad_input_code_ad.$FS ad_inpF90_code_ad.$FS90
                3523         cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
                3524 
                3525 # We need the extra target for ad_taf_outpF90.$FS90, because the file is
                3526 # generated together with ad_taf_output.$FS.
                3527 ad_taf_outpF90.$FS90: ad_taf_output.$FS
                3528         cat ad_inpF90_code_ad.$FS90 > ad_taf_outpF90.$FS90
                3529 
                3530 \$(EXE_ADJ): \$(SPECIAL_FILES) \$(H_SRC_FILES) ad_taf_output.o ad_taf_outpF90.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(NON_AD_F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(EMBEDDED_FILES)
                3531         \$(LINK) -o \${EXE_ADJ} \$(FFLAGS) \$(FOPTIM) ad_taf_output.o ad_taf_outpF90.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(NON_AD_F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(LIBS)
                3532 
                3533 adobj: ad_taf_output.o ad_taf_outpF90.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(NON_AD_F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o)
                3534 
                3535 EOF
                3536 fi
668b211e58 Ed H*3537 
44f4a23ebb Jean*3538 else
                3539 cat >>$MAKEFILE <<EOF
                3540 # ... send multiple files to TAF ...
ea893758ea Patr*3541 ad_taf_output.$FS: \$(AD_FLOW_FILES) \$(AD_FILES) \$(AD_F90FILES)
44f4a23ebb Jean*3542         @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
                3543         cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
                3544         @-rm -f ad_config.template
ea893758ea Patr*3545         @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES) \$(F90_PP_SRC_FILES)
44f4a23ebb Jean*3546         @-rm -f \$(AD_FILES:.$FS=_ad.$FS) \$(AD_FILES:.$FS=_ad.o); echo ''
ea893758ea Patr*3547         @-rm -f \$(AD_F90FILES:.$FS90=_ad.$FS90) \$(AD_F90FILES:.$FS90=_ad.o); echo ''
44f4a23ebb Jean*3548         \$(MAKE) -f \$(MAKEFILE) remove_comments
71b7a3e5ac Mart*3549         \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) -fixed \$(AD_FLOW_FILES) \$(AD_FILES) -free \$(AD_F90FILES)
44f4a23ebb Jean*3550         \$(MAKE) -f \$(MAKEFILE) adj_sed
                3551         cat \$(AD_FILES:.$FS=_ad.$FS) > ad_taf_output.$FS
                3552 
ea893758ea Patr*3553 \$(EXE_ADJ): \$(SPECIAL_FILES) \$(H_SRC_FILES) ad_taf_output.$FS \$(NON_AD_F77_SRC_FILES:.F=.o) \$(NON_AD_F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(EMBEDDED_FILES)
b3a874fe30 Jean*3554         \$(MAKE) -f \$(MAKEFILE) adobjfiles
ea893758ea Patr*3555         \$(LINK) -o \${EXE_ADJ} \$(FFLAGS) \$(FOPTIM) \$(AD_FILES:.$FS=_ad.o) \$(AD_F90FILES:.$FS90=_ad.o) \$(NON_AD_F77_SRC_FILES:.F=.o) \$(NON_AD_F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(LIBS)
44f4a23ebb Jean*3556 
ea893758ea Patr*3557 adobj: ad_taf_output.$FS \$(NON_AD_F77_SRC_FILES:.F=.o) \$(NON_AD_F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o)
b3a874fe30 Jean*3558         \$(MAKE) -f \$(MAKEFILE) adobjfiles
44f4a23ebb Jean*3559 
                3560 EOF
                3561 fi
                3562 
3924ebfa1b Mart*3563 #adonlyfwd:
                3564 #       patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
                3565 #adtrick:
                3566 #       patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
668b211e58 Ed H*3567 
3924ebfa1b Mart*3568 cat >>$MAKEFILE <<EOF
44f4a23ebb Jean*3569 ad_tamc_output.$FS: ad_input_code.$FS
                3570         \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
                3571         cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS
                3572 
                3573 ad_tamc: ad_tamc_output.o \$(OBJFILES)
b4daa24319 Shre*3574         \$(LINK) -o ${EXE_ADJ} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
863253e995 Jean*3575 
0f20d21780 Ed H*3576 # ... FTL ...
621623385c Jean*3577 ftlall: ftl_exe_target
e1583c94d9 Ed H*3578 ftltaf: ftl_taf_output.$FS
                3579 ftltamc: ftl_tamc_output.$FS
74d4132da5 Ed H*3580 
621623385c Jean*3581 ftl_exe_target:
b4daa24319 Shre*3582         @echo Update AD_CONFIG.h and make \$(EXE_TLM)
621623385c Jean*3583         @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
                3584         @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
                3585         @-rm -f ad_config.template
b4daa24319 Shre*3586         \$(MAKE) -f \$(MAKEFILE) \$(EXE_TLM)
621623385c Jean*3587 
0524b7d1ff Mart*3588 ftl_input_code.$FS: \$(AD_FILES) \$(AD_FLOW_FILES)
621623385c Jean*3589         @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
                3590         cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
                3591         @-rm -f ad_config.template
                3592         @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
7783960e4d Jean*3593         cat \$(AD_FLOW_FILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ftl_input_code.$FS
4a967b9107 Ed H*3594 
0524b7d1ff Mart*3595 EOF
                3596 if test -n "$AD_F90FILES" ; then
                3597 cat >>$MAKEFILE <<EOF
                3598 ftl_inpF90_code.$FS90: \$(AD_F90FILES) \$(AD_FLOW_FILES)
                3599         @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
                3600         cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
                3601         @-rm -f ad_config.template
                3602         @\$(MAKE) -f \$(MAKEFILE) \$(F90_PP_SRC_FILES)
                3603         cat \$(AD_F90FILES) > ftl_inpF90_code.$FS90
                3604 
                3605 EOF
                3606 fi
                3607 cat >>$MAKEFILE <<EOF
ea893758ea Patr*3608 # this is an unused target and could be removed
44f4a23ebb Jean*3609 ftltafonly:
ea893758ea Patr*3610         \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) -fixed ftl_input_code.$FS
09f59bbc00 Patr*3611         ls -l ftl_input_code_tl.$FS
                3612         cat ftl_input_code_tl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
668b211e58 Ed H*3613 
44f4a23ebb Jean*3614 EOF
                3615 
                3616 if test $CAT_SRC_FOR_TAF = 1 ; then
0524b7d1ff Mart*3617 if test -z "$AD_F90FILES" ; then
44f4a23ebb Jean*3618 cat >>$MAKEFILE <<EOF
                3619 # ... send 1 file to TAF ...
                3620 ftl_taf_output.$FS: ftl_input_code.$FS
                3621         @-rm -f ftl_input_code_tl.$FS ; echo ''
ea893758ea Patr*3622         \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) -fixed ftl_input_code.$FS
09f59bbc00 Patr*3623         ls -l ftl_input_code_tl.$FS
                3624         cat ftl_input_code_tl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
0b6ffb4e9b Patr*3625 
0524b7d1ff Mart*3626 \$(EXE_TLM): \$(SPECIAL_FILES) \$(H_SRC_FILES) ftl_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(NON_AD_F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(EMBEDDED_FILES)
                3627         \$(LINK) -o \${EXE_TLM} \$(FFLAGS) \$(FOPTIM) ftl_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(NON_AD_F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(LIBS)
668b211e58 Ed H*3628 
0524b7d1ff Mart*3629 ftlobj: ftl_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(NON_AD_F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o)
c59dd234b1 Jean*3630 
44f4a23ebb Jean*3631 EOF
0524b7d1ff Mart*3632 else
                3633 cat >>$MAKEFILE <<EOF
                3634 # ... send 1 fixed format file and 1 free format file to TAF ...
                3635 ftl_taf_output.$FS: ftl_input_code.$FS ftl_inpF90_code.$FS90
                3636         @-rm -f ftl_input_code_tl.$FS ftl_inpF90_code_tl.$FS90 ; echo ''
                3637         \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) -fixed ftl_input_code.$FS -free ftl_inpF90_code.$FS90
                3638         ls -l ftl_input_code_tl.$FS ftl_inpF90_code_tl.$FS90
                3639         cat ftl_input_code_tl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
                3640 
                3641 # We need the extra target for ftl_taf_outpF90.$FS90, because the file is
                3642 # generated together with ftl_taf_output.$FS.
                3643 ftl_taf_outpF90.$FS90: ftl_taf_output.$FS
                3644         cat ftl_inpF90_code_tl.$FS90 > ftl_taf_outpF90.$FS90
                3645 
                3646 \$(EXE_TLM): \$(SPECIAL_FILES) \$(H_SRC_FILES) ftl_taf_output.o ftl_taf_outpF90.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(NON_AD_F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(EMBEDDED_FILES)
                3647         \$(LINK) -o \${EXE_TLM} \$(FFLAGS) \$(FOPTIM) ftl_taf_output.o ftl_taf_outpF90.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(NON_AD_F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(LIBS)
                3648 
                3649 ftlobj: ftl_taf_output.o ftl_taf_outpF90.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(NON_AD_F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o)
                3650 
                3651 EOF
                3652 fi
44f4a23ebb Jean*3653 
                3654 else
                3655 cat >>$MAKEFILE <<EOF
                3656 # ... send multiple files to TAF ...
0524b7d1ff Mart*3657 ftl_taf_output.$FS: \$(AD_FLOW_FILES) \$(AD_FILES) \$(AD_F90FILES)
44f4a23ebb Jean*3658         @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
                3659         cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
                3660         @-rm -f ad_config.template
0524b7d1ff Mart*3661         @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES) \$(F90_PP_SRC_FILES)
44f4a23ebb Jean*3662         @\$(MAKE) -f \$(MAKEFILE) \$(AD_FLOW_FILES)
                3663         @-rm -f \$(AD_FILES:.$FS=_tl.$FS) \$(AD_FILES:.$FS=_tl.o); echo ''
0524b7d1ff Mart*3664         @-rm -f \$(AD_F90FILES:.$FS90=_tl.$FS90) \$(AD_F90FILES:.$FS90=_tl.o); echo ''
44f4a23ebb Jean*3665         \$(MAKE) -f \$(MAKEFILE) remove_comments
0524b7d1ff Mart*3666         \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) -fixed \$(AD_FLOW_FILES) \$(AD_FILES) -free \$(AD_F90FILES)
44f4a23ebb Jean*3667         \$(MAKE) -f \$(MAKEFILE) ftl_sed
                3668         cat \$(AD_FILES:.$FS=_tl.$FS) > ftl_taf_output.$FS
                3669 
0524b7d1ff Mart*3670 \$(EXE_TLM): \$(SPECIAL_FILES) \$(H_SRC_FILES) ftl_taf_output.$FS \$(NON_AD_F77_SRC_FILES:.F=.o) \$(NON_AD_F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(EMBEDDED_FILES)
b3a874fe30 Jean*3671         \$(MAKE) -f \$(MAKEFILE) ftlobjfiles
0524b7d1ff Mart*3672         \$(LINK) -o \${EXE_TLM} \$(FFLAGS) \$(FOPTIM) \$(AD_FILES:.$FS=_tl.o) \$(AD_F90FILES:.$FS90=_tl.o) \$(NON_AD_F77_SRC_FILES:.F=.o) \$(NON_AD_F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(LIBS)
44f4a23ebb Jean*3673 
0524b7d1ff Mart*3674 ftlobj: ftl_taf_output.$FS \$(NON_AD_F77_SRC_FILES:.F=.o) \$(NON_AD_F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o)
c59dd234b1 Jean*3675         \$(MAKE) -f \$(MAKEFILE) ftlobjfiles
                3676 
44f4a23ebb Jean*3677 EOF
                3678 fi
                3679 
                3680 cat >>$MAKEFILE <<EOF
e1583c94d9 Ed H*3681 ftl_tamc_output.$FS: ftl_input_code.$FS
                3682         \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
                3683         cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS
eb2bbeeb07 Ed H*3684 
0f20d21780 Ed H*3685 ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
b4daa24319 Shre*3686         \$(LINK) -o ${EXE_TLM} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
eb2bbeeb07 Ed H*3687 
                3688 # ... SVD ...
e1583c94d9 Ed H*3689 svdtaf: ad_taf_output.$FS ftl_taf_output.$FS
fdbd521b91 Patr*3690         @echo "--->>> Only ran TAF to generate SVD code!    <<<---"
                3691         @echo "--->>> Do make svdall afterwards to compile. <<<---"
                3692 svdall: svd_touch svd_taf
eb2bbeeb07 Ed H*3693 
fdbd521b91 Patr*3694 svd_taf: \$(OBJFILES)
0b6ffb4e9b Patr*3695         \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
668b211e58 Ed H*3696 
fdbd521b91 Patr*3697         @echo "--->>> Only COMPILE svd code! <<<---"
                3698         @echo "--->>> Assumes you previously <<<---"
                3699         @echo "--->>> did make svdtaf        <<<---"
                3700 
                3701 svd_touch:
                3702         @echo "--->>> Only COMPILE svd code! <<<---"
                3703         @echo "--->>> Assumes you previously <<<---"
                3704         @echo "--->>> did make svdtaf        <<<---"
e1583c94d9 Ed H*3705         touch ad_taf_output.$FS ftl_taf_output.$FS
                3706         \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS
                3707         \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS
621623385c Jean*3708         @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "SVD version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
                3709         cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
                3710         @-rm -f ad_config.template
668b211e58 Ed H*3711 
5bd7f28048 Jean*3712 EOF
                3713 
5be35a17af Jean*3714 fi
b4daa24319 Shre*3715 fi
                3716 
                3717 #===  for TAPENADE  ========================
                3718 
                3719 if test "x$TAPENADE" != x ; then
                3720 
                3721 # ============ begin TAPENADE specific section ==============
                3722 
                3723 cat >>$MAKEFILE <<EOF
                3724 # ========== begin TAPENADE specific section ==============
                3725 EOF
                3726 
                3727 echo "  Add the source list for AD code generation"
                3728 echo >> $MAKEFILE
                3729 printf "AD_FILES = " >> $MAKEFILE
                3730 AD_FILES=`cat $TMP.adSrcFiles`
                3731 for i in $AD_FILES ; do
                3732   basename=${i%%.f}
                3733   toBeIgnored=`egrep ^$basename'[      ]*' ${TAP_DONT_COMPILE} ${TAP_DONT_TRANSFORM}`
                3734   if test -z "$toBeIgnored" ; then
                3735     echo    " \\" >> $MAKEFILE
                3736     printf " $i" >> $MAKEFILE
                3737   fi
                3738 done
                3739 echo >> $MAKEFILE
                3740 rm -f $TMP.adSrcFiles
ea893758ea Patr*3741 rm -f $TMP.adF90Files
b4daa24319 Shre*3742 
                3743 cat >>$MAKEFILE <<EOF
                3744 
                3745 TAPENADECMD = ${TAPENADECMD}
                3746 
                3747 TAPENADE_SUPPORT_F90_SRC_FILES = \
                3748 ${TAPTOOLS}/diffsizes.F90
                3749 AD_CLEAN = *_b.f *_d.f *.f~ *.msg *.msg~ f95_test_mods.f90
                3750 
                3751 f95_test_mods.f90: \$(TAPENADE_SUPPORT_F90_SRC_FILES)
                3752         cat \$^ > \$@
                3753 #
                3754 AD_FILES_ADJ=\$(AD_FILES:.$FS=_b.f)
                3755 AD_FILES_TLM=\$(AD_FILES:.$FS=_d.f)
                3756 #
                3757 .PHONY: TAP_TLM_FILES
                3758 TAP_TLM_FILES: \$(AD_FILES) f95_test_mods.f90
                3759         touch \$(AD_FILES_TLM)
                3760         \$(TAPENADECMD) -d -ext "${TAPTOOLS}/flow_tap" -head "the_main_loop(fc)/(xx_genarr3d_dummy, xx_genarr2d_dummy, xx_gentim2d_dummy)" \$(AD_FILES) f95_test_mods.f90
                3761 #
                3762 .PHONY: TAP_ADJ_FILES
                3763 TAP_ADJ_FILES: \$(AD_FILES) f95_test_mods.f90
                3764         touch \$(AD_FILES_ADJ)
                3765         \$(TAPENADECMD) -b -ext "${TAPTOOLS}/flow_tap" -head "the_main_loop(fc)/(xx_genarr3d_dummy, xx_genarr2d_dummy, xx_gentim2d_dummy)" \$(AD_FILES) f95_test_mods.f90
                3766 
                3767 tap_adj: ad_exe_target
                3768 ad_exe_target:
                3769         @echo Update AD_CONFIG.h and make \$(EXE_ADJ)
                3770         @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
                3771         @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
                3772         @-rm -f ad_config.template
                3773         \$(MAKE) -f \$(MAKEFILE) \$(EXE_ADJ)
                3774 
                3775 tap_tlm: tlm_exe_target
                3776 tlm_exe_target:
                3777         @echo Update AD_CONFIG.h and make \$(EXE_TLM)
                3778         @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Tangent linear version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
                3779         @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
                3780         @-rm -f ad_config.template
                3781         \$(MAKE) -f \$(MAKEFILE) \$(EXE_TLM)
                3782 
                3783 \$(EXE_ADJ): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(OBJFILES) \$(TAP_SUPPORT_OBJFILES) \$(EMBEDDED_FILES) TAP_ADJ_FILES
                3784         @echo Creating \$@ ...
                3785         \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(AD_FILES_ADJ) \$(TAP_SUPPORT_OBJFILES:${TAPTOOLS}/ADFirstAidKit/%=%) \$(LIBS)
                3786 \$(EXE_TLM): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(OBJFILES) \$(TAP_SUPPORT_OBJFILES) \$(EMBEDDED_FILES) TAP_TLM_FILES
                3787         @echo Creating \$@ ...
                3788         \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(AD_FILES_TLM) \$(TAP_SUPPORT_OBJFILES:${TAPTOOLS}/ADFirstAidKit/%=%) \$(LIBS)
                3789 
                3790 # ============ end TAPENADE specific section ==============
                3791 
                3792 EOF
                3793 
                3794 fi
5bd7f28048 Jean*3795 
                3796 #===  for OpenAD  ========================
                3797 
5be35a17af Jean*3798 if test "x$OPENAD" != x ; then
5bd7f28048 Jean*3799 
                3800 # ============ begin OpenAD specific section ==============
                3801 
                3802 cat >>$MAKEFILE <<EOF
fc13640ec0 Jean*3803 # ... OpenAD ...
5bd7f28048 Jean*3804 
5be35a17af Jean*3805 # all the source files linked from the various locations:
5bd7f28048 Jean*3806 ALL_LINKED_FILES= \
                3807 \$(F77_SRC_FILES) \
                3808 \$(C_SRC_FILES) \
                3809 \$(H_SRC_FILES) \
                3810 \$(F90_SRC_FILES) \
                3811 \$(SPECIAL_FILES)
                3812 
9d0c386f0c dngo*3813 EOF
                3814 
                3815 if test "x$SINGULARITYFILE" != x ; then
                3816 # run OpenAD commands in singularity container with standard paths
                3817 cat >>$MAKEFILE <<EOF
                3818 SINGULARITYCMD = singularity exec ${SINGULARITYFILE}
                3819 export SINGULARITYENV_LD_LIBRARY_PATH=/OpenAD//Open64/osprey1.0/targ_ia64_ia64_linux/whirl2f/
                3820 export OPENADROOT=/OpenAD
                3821 export XAIFBOOSTERROOT=/OpenAD/xaifBooster/..
                3822 export XAIFSCHEMAROOT=/OpenAD/xaif
                3823 export OPENADFORTTK_BASE=/OpenAD/OpenADFortTk
                3824 export OPEN64ROOT=/OpenAD/Open64/osprey1.0/targ_ia64_ia64_linux
                3825 export OPENADFORTTK=/OpenAD/OpenADFortTk/OpenADFortTk-x86_64-Linux
                3826 
                3827 EOF
                3828 else
                3829 # run OpenAD directly
                3830 cat >>$MAKEFILE <<EOF
                3831 SINGULARITYCMD =
                3832 
                3833 EOF
                3834 fi
                3835 
                3836 cat >>$MAKEFILE <<EOF
5bd7f28048 Jean*3837 ifndef OPENADROOT
                3838   \$(error "Error:  environment variable OPENADROOT not defined!")
                3839 endif
                3840 
                3841 ifndef XAIFSCHEMAROOT
                3842   \$(error "Error:  environment variable XAIFSCHEMAROOT not defined!")
                3843 endif
                3844 
                3845 ifndef XAIFBOOSTERROOT
                3846   \$(error "Error:  environment variable XAIFBOOSTERROOT not defined!")
                3847 endif
71a0839232 Chri*3848 
                3849 EOF
                3850 
5bd7f28048 Jean*3851 echo "  Add the source list for common block to module conversion "
                3852 echo >> $MAKEFILE
                3853 printf "CB2M_F90_SRC_NAMES = " >> $MAKEFILE
                3854 for i in `cat ${OAD_CB2M_FILES}` ; do
                3855   echo    " \\" >> $MAKEFILE
                3856   printf " $i" >> $MAKEFILE
                3857 done
                3858 echo >> $MAKEFILE
                3859 
                3860 echo "  Add the source list for AD code generation"
                3861 echo >> $MAKEFILE
                3862 printf "AD_FILES = " >> $MAKEFILE
                3863 for i in `cat ${OAD_CB2M_FILES}` ; do
                3864   echo    " \\" >> $MAKEFILE
                3865   printf " ${i}_mod.f$FS90" >> $MAKEFILE
                3866 done
7deef35259 Jean*3867 AD_FILES=`cat $TMP.adSrcFiles`
5bd7f28048 Jean*3868 for i in $AD_FILES ; do
                3869   basename=${i%%.f}
                3870   toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE} ${OAD_DONT_TRANSFORM}`
                3871   if test -z "$toBeIgnored" ; then
                3872     echo    " \\" >> $MAKEFILE
                3873     printf " $i" >> $MAKEFILE
                3874   fi
                3875 done
                3876 echo >> $MAKEFILE
7deef35259 Jean*3877 rm -f $TMP.adSrcFiles
ea893758ea Patr*3878 rm -f $TMP.adF90Files
5bd7f28048 Jean*3879 
                3880 cat >>$MAKEFILE <<EOF
                3881 
fc13640ec0 Jean*3882 adAll: ad_exe_target
5bd7f28048 Jean*3883 .PHONY: adAll
                3884 
fc13640ec0 Jean*3885 ad_exe_target:
b4daa24319 Shre*3886         @echo Update AD_CONFIG.h and make \$(EXE_ADJ)
fc13640ec0 Jean*3887         @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
                3888         @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
                3889         @-rm -f ad_config.template
b4daa24319 Shre*3890         \$(MAKE) -f \$(MAKEFILE) \$(EXE_ADJ)
fc13640ec0 Jean*3891 
5bd7f28048 Jean*3892 CB2M_F90_PP_SRC_FILES=\$(addsuffix _mod.f$FS90, \$(CB2M_F90_SRC_NAMES))
                3893 
                3894 .PRECIOUS: \$(CB2M_F90_PP_SRC_FILES) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90)
                3895 
                3896 .PHONY: adDepend
                3897 adDepend: \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) \$(addsuffix _mod.FF90, \$(CB2M_F90_SRC_NAMES)) \$(F77_SRC_FILES:.F=_cb2m.FF90)
c62d6c2ba9 Jean*3898         \$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)
95cd2dedde Ivan*3899         \$(TOOLSDIR)/f90mkdepend -fs $FS -fs90 $FS90 >> \$(MAKEFILE)
5bd7f28048 Jean*3900         -rm -f makedepend.out
                3901 
                3902 OPENAD_SUPPORT_F90_SRC_FILES = \
                3903 w2f__types.F90 \
                3904 OAD_active.F90 \
                3905 OAD_cp.F90 \
                3906 OAD_rev.F90 \
b6f3d01b24 Jean*3907 OAD_tape.F90 \
279dc77b07 Patr*3908 OAD_regular_cp.F90 \
b6f3d01b24 Jean*3909 revolve.F90
5bd7f28048 Jean*3910 
                3911 OPENAD_SUPPORT_C_SRC_FILES = \
                3912 iaddr.c \
                3913 timeRatio.c
                3914 
                3915 f95_test_mods.f90: \$(OPENAD_SUPPORT_F90_SRC_FILES:F90=$FS90)
                3916         cat \$^ > \$@
                3917 
5be35a17af Jean*3918 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
5bd7f28048 Jean*3919         cat \$^ > \$@
                3920 
                3921 f95_test.out: f95_test_mods.f90 f95_test.f90
                3922         f95 -fixed -w=unused -maxcontin=132 -c f95_test_mods.f90 > \$@ 2>&1
                3923         f95 -fixed -w=unused -maxcontin=132 -c -fixed f95_test.f90 >> \$@ 2>&1
                3924 
0e81c91d99 Jean*3925 CB2M_AD_FILES=\$(AD_FILES:.f=_cb2m.f$FS90)
5bd7f28048 Jean*3926 
0e81c91d99 Jean*3927 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)
45de16ddcf Jean*3928 
                3929 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)
                3930 
b4daa24319 Shre*3931 \$(EXE_ADJ): \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) postProcess.tag \$(AD_OBJ_FILES_S2)
45de16ddcf Jean*3932         \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(AD_OBJ_FILES_S2) \$(LIBS)
5bd7f28048 Jean*3933 
0e81c91d99 Jean*3934 # create sources files modules from header files containing common blocks
25bb252094 Jean*3935 %_mod.FF90 : %.h \$(OADTOOLS)/cb2mGetModules.csh \$(OADTOOLS)/cb2mGetModules.awk
                3936         \$(OADTOOLS)/cb2mGetModules.csh $< \$(OADTOOLS)/cb2mGetModules.awk
5bd7f28048 Jean*3937 
776d1c0efd Jean*3938 # create new header files with USE statements for the new modules made above
25bb252094 Jean*3939 %_mod.h : %.h \$(OADTOOLS)/cb2mGetHeaders.csh \$(OADTOOLS)/cb2mGetHeaders.awk
                3940         \$(OADTOOLS)/cb2mGetHeaders.csh $< \$(OADTOOLS)/cb2mGetHeaders.awk \$(CB2M_F90_SRC_NAMES)
5bd7f28048 Jean*3941 
0e81c91d99 Jean*3942 # change the include directives of everybody to refer to  the new header files with the USE statements
25bb252094 Jean*3943 %_cb2m.FF90 : %.F \$(OADTOOLS)/cb2mUseModules.bash
                3944         \$(OADTOOLS)/cb2mUseModules.bash $< ${MPI}
5bd7f28048 Jean*3945 
                3946 # makefile debug rule
                3947 small_f: \$(CB2M_F90_PP_SRC_FILES)
                3948 .PHONY: small_f
                3949 
0684e64a42 Jean*3950 ad_input_code.f$FS90:  \$(CB2M_AD_FILES)
5bd7f28048 Jean*3951         cat \$^ > \$@
                3952 
                3953 # canonicalizer
776d1c0efd Jean*3954 ad_input_code_sf.pre.f90 : \$(CB2M_AD_FILES)
9d0c386f0c dngo*3955         \${SINGULARITYCMD} \${OPENADFORTTK_BASE}/tools/SourceProcessing/preProcess.py --timing --r8 -H -S  -o \$@ \$^
0e81c91d99 Jean*3956 
                3957 # replace stop statements (to avoid the implied unstructured control flow)  with print statements
                3958 ad_input_code_sf.pre.s2p.f90 : ad_input_code_sf.pre.f90
25bb252094 Jean*3959         cat \$< | sed -f \$(OADTOOLS)/stop2print.sed > ad_input_code_sf.pre.s2p.f90
5bd7f28048 Jean*3960 
                3961 # F -> WHIRL
0e81c91d99 Jean*3962 ad_input_code_sf.pre.s2p.B: ad_input_code_sf.pre.s2p.f90
9d0c386f0c dngo*3963         \${SINGULARITYCMD} \${OPEN64ROOT}/crayf90/sgi/mfef90 -r8 -z -F ad_input_code_sf.pre.s2p.f90
5bd7f28048 Jean*3964 
                3965 # WHIRL -> XAIF
776d1c0efd Jean*3966 ad_input_code_sf.pre.s2p.xaif : ad_input_code_sf.pre.s2p.B
9d0c386f0c dngo*3967         \${SINGULARITYCMD} \${OPENADFORTTK}/bin/whirl2xaif -s -n --debug 1 -o \$@ \$<
5bd7f28048 Jean*3968 
                3969 # XAIF -> XAIF'
776d1c0efd Jean*3970 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
9d0c386f0c dngo*3971         \${SINGULARITYCMD} \${XAIFBOOSTERROOT}/xaifBooster/algorithms/BasicBlockPreaccumulationReverse/driver/oadDriver -f -t forward_step -i \$< -c \${XAIFSCHEMAROOT}/schema/examples/inlinable_intrinsics.xaif -o \$@ -I -r
5bd7f28048 Jean*3972 
                3973 # XAIF' -> WHIRL'
776d1c0efd Jean*3974 ad_input_code_sf.pre.s2p.xb.x2w.B : ad_input_code_sf.pre.s2p.xb.xaif
9d0c386f0c dngo*3975         \${SINGULARITYCMD} \${OPENADFORTTK}/bin/xaif2whirl --debug 1 ad_input_code_sf.pre.s2p.B \$<
5bd7f28048 Jean*3976 
                3977 # WHIRL' -> F'
776d1c0efd Jean*3978 ad_input_code_sf.pre.s2p.xb.x2w.w2f.f$FS90: ad_input_code_sf.pre.s2p.xb.x2w.B
9d0c386f0c dngo*3979         \${SINGULARITYCMD} \${OPEN64ROOT}/whirl2f/whirl2f -FLIST:ftn_file=\$@ -openad \$<
5bd7f28048 Jean*3980 
                3981 # insert template directives
25bb252094 Jean*3982 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
                3983         \$(OADTOOLS)/insertTemplateDir.bash \$< \$@
5bd7f28048 Jean*3984 
25bb252094 Jean*3985 PPEXTRAS=\$(notdir \$(wildcard \$(OADTOOLS)/ad_template.*.F)) ad_inline.F
5bd7f28048 Jean*3986 # postprocess F'
0e81c91d99 Jean*3987 postProcess.tag: ad_input_code_sf.pre.s2p.xb.x2w.w2f.td.f$FS90 \$(PPEXTRAS:.F=.f) | w2f__types.f90
9d0c386f0c dngo*3988         \${SINGULARITYCMD} \${OPENADFORTTK_BASE}/tools/SourceProcessing/postProcess.py --progress --timing --infoUnitFile w2f__types.f90 --outputFormat=fixed --separateOutput --pathSuffix "" --filenameSuffix "_oad" -m r -i ad_inline.f \$<
0e81c91d99 Jean*3989         # the target is a placeholder to trigger a single execution of the rule
45de16ddcf Jean*3990         touch \$@
776d1c0efd Jean*3991 # put this so make knows about the postprocessing output
0e81c91d99 Jean*3992 OAD_intrinsics_oad.f \$(CB2M_AD_FILES:.f$FS90=_oad.f): postProcess.tag
5bd7f28048 Jean*3993 
0e81c91d99 Jean*3994 # link the XAIF schema files
5bd7f28048 Jean*3995 %.xsd:
                3996         \$(LN) \${XAIFSCHEMAROOT}/schema/\$@ .
                3997 
                3998 # link the support files:
01e0754d66 Oliv*3999 \$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES) \$(PPEXTRAS):
25bb252094 Jean*4000         \$(LN) \$(OADTOOLS)/\$@ .
5bd7f28048 Jean*4001 
01e0754d66 Oliv*4002 AD_CLEAN += *_mod.h *_mod.F90 *.FF90 *.mod-whirl temp.sed oad_cp.* postProcess.tag
45de16ddcf Jean*4003 
5bd7f28048 Jean*4004 # ============ end OpenAD specific section ==============
                4005 
                4006 EOF
                4007 
                4008 fi
                4009 
                4010 #=========================================
                4011 
6c90987a77 Ed H*4012 if test "x$EXEHOOK" != x ; then
                4013     printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
                4014 fi
                4015 
6aec5d9846 Ed H*4016 echo "  Making list of \"exceptions\" that need \".p\" files"
                4017 for i in $KPPFILES ; do
                4018     base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
                4019     RETVAL=$?
                4020     if test "x$RETVAL" != x0 ; then
                4021         echo "Error: unable to add file \"$i\" to the exceptions list"
                4022     fi
3eb03232c2 Ed H*4023     echo "$base.$FS: $base.p" >> $MAKEFILE
6aec5d9846 Ed H*4024 done
                4025 
                4026 echo "  Making list of NOOPTFILES"
                4027 for i in $NOOPTFILES ; do
                4028     base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
                4029     RETVAL=$?
                4030     if test "x$RETVAL" != x0 ; then
                4031         echo "Error: unable to add file \"$i\" to the exceptions list"
                4032     fi
3eb03232c2 Ed H*4033     echo "$base.o: $base.$FS" >> $MAKEFILE
76c1b0ef61 Ed H*4034     printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
6aec5d9846 Ed H*4035 done
                4036 
                4037 echo "  Add rules for links"
7deef35259 Jean*4038 cat $TMP.srclinks >> $MAKEFILE
                4039 rm -f $TMP.srclinks
6aec5d9846 Ed H*4040 
                4041 echo "  Adding makedepend marker"
76c1b0ef61 Ed H*4042 printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
6aec5d9846 Ed H*4043 
76c1b0ef61 Ed H*4044 printf "\n===  Done  ===\n"
2ff82eb834 Ed H*4045 
1f2ed3565b Alis*4046 # Create special header files
621623385c Jean*4047 $BASH $TOOLSDIR/convert_cpp_cmd2defines -bPACKAGES_CONFIG_H "Disabled packages:" $DISABLED_PACKAGES " " "Enabled packages:" $ENABLED_PACKAGES > $PACKAGES_DOT_H".tmp"
1f2ed3565b Alis*4048 if test ! -f $PACKAGES_DOT_H ; then
                4049     mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
                4050 else
a29e11f9ee Ed H*4051     cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
1f2ed3565b Alis*4052     RETVAL=$?
                4053     if test "x$RETVAL" = x0 ; then
                4054         rm -f $PACKAGES_DOT_H".tmp"
                4055     else
                4056         mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
                4057         mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
                4058     fi
                4059 fi
                4060 if test ! -f AD_CONFIG.h ; then
621623385c Jean*4061     $BASH $TOOLSDIR/convert_cpp_cmd2defines "Default version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > AD_CONFIG.h
1f2ed3565b Alis*4062 fi
                4063 
2ff82eb834 Ed H*4064 #  Write the "state" for future records
683b8f029b Jean*4065 if test "x$DUMPSTATE" = xt ; then
13fa7032ba Ed H*4066     printf "" > genmake_state
2ff82eb834 Ed H*4067     for i in $gm_state ; do
                4068         t1="t2=\$$i"
                4069         eval $t1
dd9f72a48c Jean*4070         echo "$i='$t2'" | sed -e 's/  */ /g' >> genmake_state
2ff82eb834 Ed H*4071     done
                4072 fi
f7aaac66f3 jm-c 4073 
                4074 #  Conclude
516b08a580 jm-c 4075 if test $FC_CHECK = 5 ; then
f7aaac66f3 jm-c 4076     echo "  original 'Makefile' generated successfully"
                4077     echo "=> next steps:"
                4078     ad=`echo $PACKAGES | grep -c autodiff`
                4079     if test "x$OPENAD" != x ; then
                4080         echo "  > make adAll    (<-- adjoint executable)"
                4081     elif test $ad != 0 ; then
                4082         echo "  > make depend"
b4daa24319 Shre*4083       if test "x$TAPENADE" = x ; then
                4084         echo "    > make adall  (<-- adjoint  executable with TAF)"
                4085         echo " or > make ftlall (<-- tang-lin executable with TAF)"
                4086       else
                4087         echo "    > make tap_adj  (<-- adjoint executable with Tapenade)"
                4088         echo " or > make tap_tlm (<-- tang-lin executable with Tapenade)"
                4089       fi
f7aaac66f3 jm-c 4090         echo " or > make        (<-- forward executable)"
                4091     else
                4092 #       echo "  > make depend   (add dependencies to Makefile)"
                4093         echo "  > make depend"
                4094         echo "  > make       (<-- to generate executable)"
                4095     fi
516b08a580 jm-c 4096 elif [ $FC_CHECK -ge 3 ] ; then
                4097     echo "  original 'Makefile' generated but was unable to"
                4098     echo "   run compiled test-program (please see '$LOGFILE')"
bcbb675387 jm-c 4099 elif [ $FC_CHECK -ge 0 ] ; then
516b08a580 jm-c 4100     echo "Warning: FORTRAN compiler test failed (please see '$LOGFILE')"
                4101     echo "Warning: 'Makefile' might be unusable (check your optfile)"
f7aaac66f3 jm-c 4102 fi