/[MITgcm]/MITgcm/tools/genmake2
ViewVC logotype

Diff of /MITgcm/tools/genmake2

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.249 by utke, Sat Feb 23 04:24:42 2013 UTC revision 1.280 by jmc, Wed Feb 8 22:31:33 2017 UTC
# Line 19  Usage: "$0" [OPTIONS] Line 19  Usage: "$0" [OPTIONS]
19      -help | --help | -h | --h      -help | --help | -h | --h
20            Print this help message and exit.            Print this help message and exit.
21    
22        -oad | --oad
23              Generate a Makefile for an OpenAD built
24    
25        -nocat4ad | -dog4ad | -ncad | -dad
26              do not concatenate (cat) source code sent to TAF
27              resulting in compilation of multiple files
28    
29      -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME      -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME
30        -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME        -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME
31            Use "NAME" as the adoptfile.  By default, the file at            Use "NAME" as the adoptfile.  By default, the file at
32              "tools/adjoint_options/adjoint_oad" (for OpenAD built) or
33            "tools/adjoint_options/adjoint_default" will be used.            "tools/adjoint_options/adjoint_default" will be used.
34    
35      -nooptfile | --nooptfile      -optfile NAME | --optfile NAME | -of NAME | --of NAME
       -optfile NAME | --optfile NAME | -of NAME | --of NAME  
36        -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME        -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
37            Use "NAME" as the optfile.  By default, an attempt will be            Use "NAME" as the optfile.  By default, an attempt will be
38            made to find an appropriate "standard" optfile in the            made to find an appropriate "standard" optfile in the
# Line 208  test_for_string_in_file() { Line 215  test_for_string_in_file() {
215  expand_pkg_groups() {  expand_pkg_groups() {
216      new_packages=      new_packages=
217      if test -r $PKG_GROUPS ; then      if test -r $PKG_GROUPS ; then
218          cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp          cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > $TMP.p1
219          cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp          cat $TMP.p1 | $AWK '(NF>2 && $2==":"){ print $0 }' > $TMP.p2
220          matched=0          matched=0
221          for i in $PACKAGES ; do          for i in $PACKAGES ; do
222              line=`grep "^ *$i" ./p2.tmp`              line=`grep "^ *$i" $TMP.p2`
223              RETVAL=$?              RETVAL=$?
224              if test "x$RETVAL" = x0 ; then              if test "x$RETVAL" = x0 ; then
225                  matched=1                  matched=1
# Line 224  expand_pkg_groups() { Line 231  expand_pkg_groups() {
231              fi              fi
232          done          done
233          PACKAGES=$new_packages          PACKAGES=$new_packages
234          rm -f ./p[1,2].tmp          rm -f $TMP.p[1,2]
235          return $matched          return $matched
236      else      else
237          echo "Warning: can't read package groups definition file: $PKG_GROUPS"          echo "Warning: can't read package groups definition file: $PKG_GROUPS"
# Line 324  look_for_makedepend()  { Line 331  look_for_makedepend()  {
331      #      #
332      #    1) a makedepend implementation shipped with the cyrus-imapd      #    1) a makedepend implementation shipped with the cyrus-imapd
333      #       package:  ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/      #       package:  ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
334      #      #    2) a local tools/xmakedepend shell script
     #    2) a known-buggy xmakedpend shell script  
335      #      #
336      #  So the choices are, in order:      #  So the choices are, in order:
     #  
337      #    1) use the user-specified program      #    1) use the user-specified program
338      #    2) use a system-wide default      #    2) use the local xmakedepend script (get all dependencies, but slower)
339      #    3) locally build and use the cyrus implementation      #    3) use a system-wide default
340      #    4) fall back to the buggy local xmakedpend script      #    4) locally build and use the cyrus makedepend
341        #             (faster, but can miss some dependencies)
342      #      #
343      echo >> $LOGFILE      echo >> $LOGFILE
344      echo "running: look_for_makedepend()" >> $LOGFILE      echo "running: look_for_makedepend()" >> $LOGFILE
# Line 343  look_for_makedepend()  { Line 349  look_for_makedepend()  {
349              build_cyrus_makedepend              build_cyrus_makedepend
350              RETVAL=$?              RETVAL=$?
351              if test "x$RETVAL" != x0 ; then              if test "x$RETVAL" != x0 ; then
352                  echo "WARNING: unable to build cyrus-makedepend. Try 'makedepend'"                  echo "WARNING: unable to build cyrus-makedepend. Try other 'makedepend'"
353                  MAKEDEPEND=                  MAKEDEPEND=
354              fi              fi
355          else          else
# Line 356  look_for_makedepend()  { Line 362  look_for_makedepend()  {
362          fi          fi
363      fi      fi
364      if test "x${MAKEDEPEND}" = x ; then      if test "x${MAKEDEPEND}" = x ; then
         which makedepend > /dev/null 2>&1  
         RV0=$?  
365          test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"          test -f $MAKEFILE  &&  mv -f $MAKEFILE $MAKEFILE".tst"
366          #  echo 'MAKEFILE="'$MAKEFILE'"'          #  echo 'MAKEFILE="'$MAKEFILE'"'
367          cat <<EOF >> $MAKEFILE          cat <<EOF >> $MAKEFILE
# Line 373  EOF Line 377  EOF
377        stop        stop
378        end        end
379  EOF  EOF
380          makedepend -f $MAKEFILE genmake_tc.f > /dev/null 2>&1          $ROOTDIR/tools/xmakedepend -f $MAKEFILE genmake_tc.f > /dev/null 2>&1
381          RV1=$?          RV1=$?
382            which makedepend > /dev/null 2>&1
383            RV2=$?
384            if test "x${RV2}" = x0 ; then
385                makedepend -f $MAKEFILE genmake_tc.f > /dev/null 2>&1
386                RV3=$? ; loc_msg='not working.'
387            else RV3=$RV2 ; loc_msg='not found.'
388            fi
389          test -f $MAKEFILE  &&  rm -f $MAKEFILE          test -f $MAKEFILE  &&  rm -f $MAKEFILE
390          test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE          test -f $MAKEFILE".tst"  &&  mv -f $MAKEFILE".tst" $MAKEFILE
391          if test "x${RV0}${RV1}" = x00 ; then          echo "  check makedepend (local: $RV1, system: $RV2, $RV3)"
392            if test "x${RV1}" = x0 ; then
393                MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
394                echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
395            elif test "x${RV3}" = x0 ; then
396                echo "    local tools/xmakedepend not working. Use system-default makedepend"
397              MAKEDEPEND=makedepend              MAKEDEPEND=makedepend
398              echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE              echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
399          else          else
400              echo "    system-default makedepend not found. Try to build cyrus-makedepend"              echo "    local tools/xmakedepend not working; system-default makedepend $loc_msg"
401                echo -n "    Try to build cyrus-makedepend ..."
402              #  Try to build the cyrus implementation              #  Try to build the cyrus implementation
403              build_cyrus_makedepend              build_cyrus_makedepend
404              RETVAL=$?              RETVAL=$?
405              if test "x$RETVAL" != x0 ; then              if test "x$RETVAL" = x0 ; then
406                  echo "WARNING: unable to build cyrus-makedepend. Use local xmakedepend"                  echo "  Works"
407                  MAKEDEPEND='$(TOOLSDIR)/xmakedepend'              else
408                  echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE                  echo "  Fails" ; echo "" >> $LOGFILE
409                    echo "ERROR: no working makedepend found ; look_for_makedepend FAILED" | tee -a $LOGFILE
410                    echo ""
411                    exit -1
412                    return
413              fi              fi
414          fi          fi
415      fi      fi
# Line 588  EOF Line 609  EOF
609      fi      fi
610  }  }
611    
612    #  Do a local copy of MPI headers files (in local dir ./mpi_headers/) after
613    #  checking for additional included headers (in case of chain of included header)
614    mpi_headers_do_local_copy() {
615    
616        dBug=0
617        rm -rf ./mpi_headers
618        if test -d $MPIINCLUDEDIR ; then
619    
620            #----- check for additional headers (chain of included headers)
621            echo -n '  Check MPI headers ... '
622            listIni=$MPI_HEADER_FILES
623            echo $listIni | grep "\<mpif.h\>" > /dev/null 2>&1
624            outp=$?
625            #- always check mpif.h (the only mpi-header included in standard MITgcm code)
626            if test $outp != 0 ; then listIni="mpif.h $listIni" ; fi
627            if test $dBug = 1 ; then echo "listIni='$listIni'" ; fi
628    
629            doCheck=1 ; list2copy='' ; list2check=$listIni
630            while test $doCheck = 1 ; do
631              newList=''
632              for i in $list2check ; do
633                if test -f $MPIINCLUDEDIR/$i ; then
634                  newInc=`grep '^ *include ' $MPIINCLUDEDIR/$i | \
635                    sed -e 's/^ *include //' -e 's/\!.*$//' -e "s/'//g"  -e 's/\"//g'`
636                  if test $dBug = 1 ; then echo -n "checking $i : newInc='$newInc'" ; fi
637                  for j in $newInc ; do
638                    echo $listIni $list2copy $newList | grep "\<$j\>" > /dev/null 2>&1
639                    outp=$?
640                    if test $outp != 0 ; then
641                      if test $dBug = 1 ; then echo -n " ; adding $j" ; fi
642                      newList="$newList $j"
643                    fi
644                  done
645                  if test $dBug = 1 ; then echo "" ; fi
646                fi
647              done
648              if test "x$newList" = x ; then doCheck=0
649              else list2check=$newList ; list2copy="$list2copy $newList"
650              fi
651            done
652            list2copy="$MPI_HEADER_FILES $list2copy"
653            if test $dBug = 1 ; then echo "list2copy='$list2copy'" ; fi
654    
655            #----- create local mpi_headers dir if we have files to copy
656            mkListInc=`echo $list2copy | wc -w`
657            if test $mkListInc != 0 ; then
658              echo 'create local "./mpi_headers" dir'
659              mkdir -p ./mpi_headers
660              INCLUDES="-I./mpi_headers $INCLUDES"
661              mkListInc=1
662            fi
663            if test "x$LOCAL_MPI_HEADERS" != x ; then mkListInc=0 ; fi
664    
665            #----- make local copy and update LOCAL_MPI_HEADERS (if not already set)
666            for i in $list2copy ; do
667              if test -f $MPIINCLUDEDIR/$i ; then
668                cp -p $MPIINCLUDEDIR/$i ./mpi_headers
669                if test $i = 'mpif.h' ; then
670                    perl -i -pe 's/MPI_DISPLACEMENT_CURRENT=-1_8/MPI_DISPLACEMENT_CURRENT=-1/g' mpi_headers/mpif.h
671                fi
672                if test $mkListInc = 2 ; then
673                    LOCAL_MPI_HEADERS="$LOCAL_MPI_HEADERS ./mpi_headers/$i"
674                fi
675                if test $mkListInc = 1 ; then
676                    LOCAL_MPI_HEADERS="./mpi_headers/$i" ; mkListInc=2
677                fi
678              fi
679            done
680        else
681            echo "WARNING: MPIINCLUDEDIR='$MPIINCLUDEDIR' is not a directory"
682            echo "WARNING: => skip checking for MPI headers (no ./mpi_headers dir)"
683    #       exit -1
684        fi
685    }
686    
687  #  Parse the package dependency information  #  Parse the package dependency information
688  get_pdepend_list()  {  get_pdepend_list()  {
689    
# Line 601  get_pdepend_list()  { Line 697  get_pdepend_list()  {
697        echo "Error: unable to parse package dependencies -- please check PKG_DEPEND=\"$1\""        echo "Error: unable to parse package dependencies -- please check PKG_DEPEND=\"$1\""
698        exit 1        exit 1
699      fi      fi
700        #echo "---- content of tmp file '.pd_tmp' :" ; cat .pd_tmp ; echo "---- end of file"
701      . ./.pd_tmp      . ./.pd_tmp
702      rm -f ./.pd_tmp      rm -f ./.pd_tmp
703  }  }
# Line 990  EOF Line 1087  EOF
1087  }  }
1088    
1089  check_lapack_libs()  {  check_lapack_libs()  {
1090      if test ! "x$SKIP_LAPACK_CHECK" = x ; then      if test "x$CHECK_FOR_LAPACK" = xf ; then return ; fi
         return  
     fi  
1091      echo >> $LOGFILE      echo >> $LOGFILE
1092      echo "running: check_lapack_libs()" >> $LOGFILE      echo "running: check_lapack_libs()" >> $LOGFILE
1093      cat <<EOF > genmake_tla.F      cat <<EOF > genmake_tla.F
# Line 1188  GSL= Line 1283  GSL=
1283  DEVEL=  DEVEL=
1284  HAVE_TEST_L=  HAVE_TEST_L=
1285    
1286  # comment this line out to enable lapack test  # set this to "t" to enable lapack test
1287  SKIP_LAPACK_CHECK=t  CHECK_FOR_LAPACK=f
1288    
1289  # DEFINES checked by test compilation or command-line  # DEFINES checked by test compilation or command-line
1290  HAVE_SYSTEM=  HAVE_SYSTEM=
# Line 1236  FS= Line 1331  FS=
1331  FS90=  FS90=
1332    
1333  AUTODIFF_PKG_USED=f  AUTODIFF_PKG_USED=f
1334    OPENAD=
1335  AD_OPTFILE=  AD_OPTFILE=
1336    CAT_SRC_FOR_TAF=1
1337  TAF=  TAF=
1338  AD_TAF_FLAGS=  AD_TAF_FLAGS=
1339  FTL_TAF_FLAGS=  FTL_TAF_FLAGS=
# Line 1248  FTL_TAF_FLAGS= Line 1345  FTL_TAF_FLAGS=
1345  SVD_TAMC_FLAGS=  SVD_TAMC_FLAGS=
1346  TAMC_EXTRA=  TAMC_EXTRA=
1347    
1348    DIVA=
1349    MPIINCLUDEDIR=
1350    MPI_HEADER_FILES=
1351    LOCAL_MPI_HEADERS=
1352    
1353  #  The following state can be set directly by command-line switches  #  The following state can be set directly by command-line switches
1354  gm_s1="ROOTDIR STANDARDDIRS MODS PKG_DEPEND PKG_GROUPS DISABLE ENABLE"  gm_s1="ROOTDIR STANDARDDIRS MODS PKG_DEPEND PKG_GROUPS DISABLE ENABLE"
1355  gm_s2="PLATFORM OPTFILE MAKE MAKEFILE MAKEDEPEND FC CC MPI OMP USE_R4"  gm_s2="PLATFORM OPTFILE MAKE MAKEFILE MAKEDEPEND FC CC MPI OMP USE_R4"
# Line 1257  gm_s3="FEXTRAFLAGS IEEE DEVEL GSL TS PAP Line 1359  gm_s3="FEXTRAFLAGS IEEE DEVEL GSL TS PAP
1359  gm_s4="LN S64 LINK PACKAGES INCLUDES FFLAGS FOPTIM"  gm_s4="LN S64 LINK PACKAGES INCLUDES FFLAGS FOPTIM"
1360  gm_s5="CFLAGS LIBS KPP KFLAGS1 KFLAGS2 KPPFILES NOOPTFILES NOOPTFLAGS"  gm_s5="CFLAGS LIBS KPP KFLAGS1 KFLAGS2 KPPFILES NOOPTFILES NOOPTFLAGS"
1361  gm_s6="PWD TOOLSDIR SOURCEDIRS INCLUDEDIRS EXEDIR EXECUTABLE EXEHOOK"  gm_s6="PWD TOOLSDIR SOURCEDIRS INCLUDEDIRS EXEDIR EXECUTABLE EXEHOOK"
1362  gm_s7="THISHOST THISUSER THISDATE THISVER MACHINE FC_NAMEMANGLE"  gm_s7="TMP THISHOST THISUSER THISDATE THISVER MACHINE FC_NAMEMANGLE"
1363  gm_s8="HAVE_NETCDF HAVE_SYSTEM HAVE_FDATE HAVE_ETIME HAVE_LAPACK HAVE_FLUSH"  gm_s8="HAVE_NETCDF HAVE_SYSTEM HAVE_FDATE HAVE_ETIME HAVE_LAPACK HAVE_FLUSH"
1364    
1365  #  The following are all related to adjoint/tangent-linear stuff  #  The following are all related to adjoint/tangent-linear stuff
1366  gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"  gm_s10="AUTODIFF_PKG_USED AD_OPTFILE OPENAD TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
1367  gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"  gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
1368  gm_s12="TAF_EXTRA TAMC_EXTRA"  gm_s12="TAF_EXTRA TAMC_EXTRA DIVA MPIINCLUDEDIR MPI_HEADER_FILES"
1369    
1370  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7 $gm_s8"  gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7 $gm_s8"
1371  gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"  gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
# Line 1306  for ac_option in "$@" ; do Line 1408  for ac_option in "$@" ; do
1408          -help | --help | -h | --h)          -help | --help | -h | --h)
1409              usage ;;              usage ;;
1410    
         -nooptfile | --nooptfile)  
             OPTFILE="NONE" ;;  
1411          -optfile | --optfile | -of | --of)          -optfile | --optfile | -of | --of)
1412              ac_prev=OPTFILE ;;              ac_prev=OPTFILE ;;
1413          -optfile=* | --optfile=* | -of=* | --of=*)          -optfile=* | --optfile=* | -of=* | --of=*)
1414              OPTFILE=$ac_optarg ;;              OPTFILE=$ac_optarg ;;
1415    
1416            -oad | --oad)
1417                OPENAD="true" ; ALWAYS_USE_F90=1 ;;
1418            -nocat4ad | -dog4ad | -ncad | -dad)
1419                CAT_SRC_FOR_TAF=0 ;;
1420          -adoptfile | --adoptfile | -adof | --adof)          -adoptfile | --adoptfile | -adof | --adof)
1421              ac_prev=AD_OPTFILE ;;              ac_prev=AD_OPTFILE ;;
1422          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)          -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
# Line 1482  for ac_option in "$@" ; do Line 1586  for ac_option in "$@" ; do
1586    
1587  done  done
1588    
1589    #TMP=./genmk_$$
1590    #- try to put temporary files in system-local /tmp dir
1591    TMP=/tmp/genmk_${USER}_$$
1592    touch $TMP ; retVal=$?
1593    if [ $retVal -eq 0 ] ; then
1594      if test ! -r $TMP ; then TMP=./genmk_$$ ; fi
1595    else
1596      TMP=./genmk_$$
1597    fi
1598    rm -f $TMP
1599    #echo "  temp files: $TMP.*"
1600    
1601  printf "  getting local config information:  "  printf "  getting local config information:  "
1602  if test -f $gm_local ; then  if test -f $gm_local ; then
1603      echo "using $gm_local"      echo "using $gm_local"
# Line 1574  fi Line 1690  fi
1690    
1691  echo "  getting AD_OPTFILE information:"  echo "  getting AD_OPTFILE information:"
1692  if test "x${AD_OPTFILE}" = x ; then  if test "x${AD_OPTFILE}" = x ; then
1693      if test "x$MITGCM_AD_OF" = x ; then      if test "x$MITGCM_AD_OF" != x ; then
1694            AD_OPTFILE=$MITGCM_AD_OF
1695        elif test "x$OPENAD" = x ; then
1696          AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default          AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
1697      else      else
1698          AD_OPTFILE=$MITGCM_AD_OF          AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_oad
1699      fi      fi
1700  fi  fi
1701  if test "x${AD_OPTFILE}" != xNONE ; then  if test "x${AD_OPTFILE}" != xNONE ; then
# Line 1600  if test "x${AD_OPTFILE}" != xNONE ; then Line 1718  if test "x${AD_OPTFILE}" != xNONE ; then
1718  fi  fi
1719    
1720  #====================================================================  #====================================================================
1721    # Initialize INCLUDEDIRSMK from and optfile INCLUDEDIRS
1722    if test "x${INCLUDEDIRS}" != "x" ; then
1723     INCLUDEDIRSMK=${INCLUDEDIRS}
1724    fi
1725    
1726    #====================================================================
1727  #  Set default values if not set by the optfile  #  Set default values if not set by the optfile
1728  #  #
1729  #  Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined.  If not,  #  Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined.  If not,
# Line 1844  else Line 1968  else
1968  fi  fi
1969  rm -f genmake_tcomp*  rm -f genmake_tcomp*
1970    
1971  printf "  Do we have the etime() command using $FC...  "  printf "  Do we have the etime() command using $FC... "
1972  cat > genmake_tcomp.$FS <<EOF  cat > genmake_tcomp_1.$FS <<EOF
1973        program hello        program hello
1974        REAL*4 ACTUAL, TARRAY(2)        REAL*4 actual, tarray(2)
1975        EXTERNAL ETIME        EXTERNAL ETIME
1976        REAL*4 ETIME        REAL*4 ETIME
1977        actual = etime( tarray )        actual = ETIME( tarray )
1978        print *, tarray        print *, tarray
1979        end        end
1980  EOF  EOF
1981  $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1  $FC $FFLAGS -o genmake_tcomp_1 genmake_tcomp_1.$FS > genmake_tcomp.log 2>&1
1982  RETVAL=$?  RETVAL=$?
1983  if test "x$RETVAL" = x0 ; then  if test "x$RETVAL" = x0 ; then
1984      HAVE_ETIME=t      HAVE_ETIME='Fct'
1985      DEFINES="$DEFINES -DHAVE_ETIME"      DEFINES="$DEFINES -DHAVE_ETIME_FCT"
1986      echo "yes"      echo " yes (${HAVE_ETIME})"
1987  else  else
1988      cat > genmake_tcomp_2.$FS <<EOF
1989          program hello
1990          REAL*4 actual, tarray(2)
1991          actual = -999.
1992          call ETIME( tarray, actual )
1993          if ( actual.ge.0. ) then
1994            print *, 0, tarray, actual
1995          else
1996            print *, 1, tarray, actual
1997          endif
1998          end
1999    EOF
2000      $FC $FFLAGS -o genmake_tcomp_2 genmake_tcomp_2.$FS >> genmake_tcomp.log 2>&1
2001      RETVAL=$?
2002      if test "x$RETVAL" = x0 ; then
2003        echo -n 'c,'
2004        ./genmake_tcomp_2 > genmake_tcomp_2.out 2>&1
2005        RETVAL=$?
2006      fi
2007      if test "x$RETVAL" = x0 ; then
2008        echo -n 'r:'
2009        RETVAL=`cat genmake_tcomp_2.out | $AWK '{print $1}'`
2010      fi
2011      if test "x$RETVAL" = x0 ; then
2012        HAVE_ETIME='SbR'
2013        DEFINES="$DEFINES -DHAVE_ETIME_SBR"
2014        echo " yes (${HAVE_ETIME})"
2015      else
2016      HAVE_ETIME=      HAVE_ETIME=
2017      echo "no"      echo " no"
2018      fi
2019  fi  fi
2020    #mkdir chk_etime ; cp -p -f genmake_tcomp* chk_etime
2021  rm -f genmake_tcomp*  rm -f genmake_tcomp*
2022    
2023  printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "  printf "  Can we call simple C routines (here, \"cloc()\") using $FC...  "
# Line 1958  for d in $MODS ; do Line 2112  for d in $MODS ; do
2112          printf "$d "          printf "$d "
2113          SOURCEDIRS="$SOURCEDIRS $d"          SOURCEDIRS="$SOURCEDIRS $d"
2114          INCLUDEDIRS="$INCLUDEDIRS $d"          INCLUDEDIRS="$INCLUDEDIRS $d"
2115            SOURCEDIRSMK="$SOURCEDIRSMK $d"
2116            INCLUDEDIRSMK="$INCLUDEDIRSMK $d"
2117      fi      fi
2118  done  done
2119  echo  echo
# Line 1981  fi Line 2137  fi
2137    
2138  if test "x${TOOLSDIR}" = x ; then  if test "x${TOOLSDIR}" = x ; then
2139      TOOLSDIR="$ROOTDIR/tools"      TOOLSDIR="$ROOTDIR/tools"
2140        TOOLSDIRMK='$(ROOTDIR)'"/tools"
2141    else
2142        TOOLSDIRMK=${TOOLSDIR}
2143  fi  fi
2144  if test ! -d ${TOOLSDIR} ; then  if test ! -d ${TOOLSDIR} ; then
2145      echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"      echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
# Line 2143  if test "x${PKG_GROUPS}" != x ; then Line 2302  if test "x${PKG_GROUPS}" != x ; then
2302  fi  fi
2303    
2304  echo "  applying DISABLE settings"  echo "  applying DISABLE settings"
2305  echo "" > ./.tmp_pack  echo "" > $TMP.pack
2306  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2307      echo $i >> ./.tmp_pack      echo $i >> $TMP.pack
2308  done  done
2309  for i in `grep  "-" ./.tmp_pack` ; do  for i in `grep  "-" $TMP.pack` ; do
2310      j=`echo $i | sed 's/[-]//'`      j=`echo $i | sed 's/[-]//'`
2311      DISABLE="$DISABLE $j"      DISABLE="$DISABLE $j"
2312  done  done
# Line 2165  for p in $PACKAGES ; do Line 2324  for p in $PACKAGES ; do
2324  done  done
2325  PACKAGES="$pack"  PACKAGES="$pack"
2326  echo "  applying ENABLE settings"  echo "  applying ENABLE settings"
2327  echo "" > ./.tmp_pack  echo "" > $TMP.pack
2328  PACKAGES="$PACKAGES $ENABLE"  PACKAGES="$PACKAGES $ENABLE"
2329  # Test if each explicitly referenced package exists  # Test if each explicitly referenced package exists
2330  for i in $PACKAGES ; do  for i in $PACKAGES ; do
# Line 2174  for i in $PACKAGES ; do Line 2333  for i in $PACKAGES ; do
2333          echo "Error: dir '$ROOTDIR/pkg/$i' missing for package '$i'"          echo "Error: dir '$ROOTDIR/pkg/$i' missing for package '$i'"
2334          exit 1          exit 1
2335      fi      fi
2336      echo $i >> ./.tmp_pack      echo $i >> $TMP.pack
2337  done  done
2338  PACKAGES=  PACKAGES=
2339  for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do  for i in `grep -v "-" $TMP.pack | sort | uniq` ; do
2340      PACKAGES="$PACKAGES $i"      PACKAGES="$PACKAGES $i"
2341  done  done
2342  rm -f ./.tmp_pack  rm -f $TMP.pack
2343  echo "    packages are: $PACKAGES"  echo "    packages are: $PACKAGES"
2344    
2345  #  Check for package MNC: if NetCDF is available, then build the MNC  #  Check for package MNC: if NetCDF is available, then build the MNC
# Line 2250  EOF Line 2409  EOF
2409      fi      fi
2410  fi  fi
2411    
2412  #  Check for package RADTRANS: if LAPACK is not available,  #  Make sure the openad package is enabled if using OpenAD
2413  #  then issue a warning that the direct radtrans solver is not available.  if test "x$OPENAD" != x ; then
2414  if test "x$HAVE_LAPACK" != xt ; then      echo " $PACKAGES " | grep ' openad ' > /dev/null 2>&1
     echo " $PACKAGES " | grep ' radtrans ' > /dev/null 2>&1  
2415      RETVAL=$?      RETVAL=$?
2416      if test "x$RETVAL" = x0 ; then      if test "x$RETVAL" != x0 ; then
2417          cat <<EOF          cat <<EOF
 *********************************************************************  
 WARNING: the "radtrans" package was enabled but tests failed to  
   compile LAPACK applications.  This means that the direct radtrans  
   solver is not available and compilation will fail if it is enabled.  
   If you want to use the direct solver, please check that:  
2418    
   1) LAPACK is correctly installed for this compiler and  
   2) the LIBS variable (within the "optfile") specifies the correct  
      LAPACK library to link against.  
2419  *********************************************************************  *********************************************************************
2420    ERROR: when generating an adjoint with OpenAD, the openad package
2421      must be enabled.  Please add it to packages.conf.
2422    *********************************************************************
2423    
2424  EOF  EOF
2425            exit 1
2426      fi      fi
2427  fi  fi
2428    
# Line 2295  if  test "x${PKG_DEPEND}" != x ; then Line 2450  if  test "x${PKG_DEPEND}" != x ; then
2450              if test "x$p" = "x$pname" ; then pin="t" ; fi              if test "x$p" = "x$pname" ; then pin="t" ; fi
2451          done          done
2452    
2453          #  Is the DNAME entry a (+) or (-) rule ?          #  Is the DNAME entry a (=), (+) or (-) rule ?
2454          tmp="dname=\"\$DNAME_$i\""          tmp="dname=\"\$DNAME_$i\""
2455          eval $tmp          eval $tmp
2456          plus="-"          plus="a"
2457          echo $dname | grep '^+' > /dev/null 2>&1          echo $dname | grep '^+' > /dev/null 2>&1
2458          RETVAL=$?          RETVAL=$?
2459          if test "x$RETVAL" = x0 ; then          if test "x$RETVAL" = x0 ; then plus="+" ; fi
2460              plus="+"          echo $dname | grep '^-' > /dev/null 2>&1
2461          fi          RETVAL=$?
2462            if test "x$RETVAL" = x0 ; then plus="-" ; fi
2463    
2464          #  Is $dname in the current $PACKAGES list?          #  Is $dname in the current $PACKAGES list?
2465          dname=`echo $dname | sed -e 's/^[+-]//'`          dname=`echo $dname | sed -e 's/^[=+-]//'`
2466          din="f"          din="f"
2467          for p in $PACKAGES ; do          for p in $PACKAGES ; do
2468              if test "x$p" = "x$dname" ; then              if test "x$p" = "x$dname" ; then
# Line 2315  if  test "x${PKG_DEPEND}" != x ; then Line 2471  if  test "x${PKG_DEPEND}" != x ; then
2471          done          done
2472    
2473          #  Do we need to add $dname according to the dependency rules?          #  Do we need to add $dname according to the dependency rules?
2474          if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then          if test "x$pin" = xt -a "x$plus" != "x-" -a "x$din" = xf ; then
2475              #echo "   " $pname ": need to add :" $dname              #echo "   " $pname ": need to add :" $dname
2476              in_dis="f"              in_dis="f"
2477              for dis in $DISABLE ; do              for dis in $DISABLE ; do
# Line 2324  if  test "x${PKG_DEPEND}" != x ; then Line 2480  if  test "x${PKG_DEPEND}" != x ; then
2480                  fi                  fi
2481              done              done
2482              if test "x$in_dis" = xt ; then              if test "x$in_dis" = xt ; then
2483                  echo "Error: can't satisfy package dependencies:"                  if test "x$plus" = "x+" ; then
2484                  echo "  \"$dname\" is required by the dependency rules"                      echo "Error: can't satisfy package dependencies:"
2485                  echo "  but is disallowed by the DISABLE settings"                      echo "  \"$dname\" is required with pkg \"$pname\" (dependency rules)"
2486                  exit 1                      echo "  but is disallowed by the DISABLE settings"
2487                        exit 1
2488                    elif test "x$ck" = xt ; then
2489                    #- (=) is a weaker dependency rule: warning but no stop
2490                        echo    "Warning: pkg \"$dname\" is set DISABLE (from: \"$PKG_LIST\")"
2491                        echo -n "     but is recommended with pkg \"$pname\" (dependency rules)"
2492                        echo " <- ignores recommendation"
2493                    fi
2494              else              else
2495                  PACKAGES="$PACKAGES $dname"                  PACKAGES="$PACKAGES $dname"
2496                  ck=                  ck=
# Line 2337  if  test "x${PKG_DEPEND}" != x ; then Line 2500  if  test "x${PKG_DEPEND}" != x ; then
2500          #  Do we need to get rid of $dname according to the dependency rules?          #  Do we need to get rid of $dname according to the dependency rules?
2501          if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then          if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then
2502              echo "Error: can't satisfy package dependencies:"              echo "Error: can't satisfy package dependencies:"
2503              echo "  \"$pname\" was requested but is disallowed by"              echo "  \"$dname\" was requested but is disallowed by"
2504              echo "  the dependency rules for \"$dname\""              echo "  the dependency rules for \"$pname\""
2505              exit 1              exit 1
2506          fi          fi
2507          i=`echo "$i + 1" | bc -l`          i=`echo "$i + 1" | bc -l`
# Line 2350  if  test "x${PKG_DEPEND}" != x ; then Line 2513  if  test "x${PKG_DEPEND}" != x ; then
2513  fi  fi
2514  for i in $PACKAGES ; do  for i in $PACKAGES ; do
2515      adr="$ROOTDIR/pkg/$i"      adr="$ROOTDIR/pkg/$i"
2516        adrmk='$(ROOTDIR)'"/pkg/$i"
2517      if test -d $adr ; then      if test -d $adr ; then
2518          SOURCEDIRS="$SOURCEDIRS $adr"          SOURCEDIRS="$SOURCEDIRS $adr"
2519          INCLUDEDIRS="$INCLUDEDIRS $adr"          INCLUDEDIRS="$INCLUDEDIRS $adr"
2520            SOURCEDIRSMK="$SOURCEDIRSMK $adrmk"
2521            INCLUDEDIRSMK="$INCLUDEDIRSMK $adrmk"
2522          if test "x$i" = xautodiff ; then          if test "x$i" = xautodiff ; then
2523              AUTODIFF_PKG_USED=t              AUTODIFF_PKG_USED=t
2524          fi          fi
# Line 2408  BUILDDIR=${BUILDDIR:-.} Line 2574  BUILDDIR=${BUILDDIR:-.}
2574  if test "x$STANDARDDIRS" != x ; then  if test "x$STANDARDDIRS" != x ; then
2575      for d in $STANDARDDIRS ; do      for d in $STANDARDDIRS ; do
2576          adr="$ROOTDIR/$d/src"          adr="$ROOTDIR/$d/src"
2577            adrmk='$(ROOTDIR)/'"$d/src"
2578          if test ! -d $adr ; then          if test ! -d $adr ; then
2579              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
2580              echo "  is correct and that you correctly specified the STANDARDDIRS option"              echo "  is correct and that you correctly specified the STANDARDDIRS option"
2581              exit 1              exit 1
2582          else          else
2583              SOURCEDIRS="$SOURCEDIRS $adr"              SOURCEDIRS="$SOURCEDIRS $adr"
2584                SOURCEDIRSMK="$SOURCEDIRSMK $adrmk"
2585          fi          fi
2586          adr="$ROOTDIR/$d/inc"          adr="$ROOTDIR/$d/inc"
2587            adrmk='$(ROOTDIR)/'"$d/inc"
2588          if test ! -d $adr ; then          if test ! -d $adr ; then
2589              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""              echo "Error:  directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
2590              echo "  is correct and that you correctly specified the STANDARDDIRS option"              echo "  is correct and that you correctly specified the STANDARDDIRS option"
2591              exit 1              exit 1
2592          else          else
2593              INCLUDEDIRS="$INCLUDEDIRS $adr"              INCLUDEDIRS="$INCLUDEDIRS $adr"
2594                INCLUDEDIRSMK="$INCLUDEDIRSMK $adrmk"
2595          fi          fi
2596      done      done
2597  fi  fi
# Line 2459  fi Line 2629  fi
2629    
2630  #  Here, we build the list of files to be "run through" the adjoint  #  Here, we build the list of files to be "run through" the adjoint
2631  #  compiler.  #  compiler.
2632  if test -f ./adSrcFiles.tmp ; then  if test -f $TMP.adSrcFiles ; then
2633      rm -f ./adSrcFiles.tmp      rm -f $TMP.adSrcFiles
2634  fi  fi
2635  echo "  Creating the list of files for the adjoint compiler."  echo "  Creating the list of files for the adjoint compiler."
2636  touch adSrcFiles.tmp  touch $TMP.adSrcFiles
2637  for i in $SOURCEDIRS ; do  for i in $SOURCEDIRS ; do
2638      list_files=`( cd $i && ls -1 *.list 2>/dev/null )`      list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
2639      for j in $list_files ; do      for j in $list_files ; do
2640          cat $i/$j >> adSrcFiles.tmp          cat $i/$j >> $TMP.adSrcFiles
2641      done      done
2642  done  done
2643  if test ! "x"$FS = "x.f" ; then  if test ! "x"$FS = "x.f" ; then
2644      cat adSrcFiles.tmp | sed -e "s/\.f/.$FS/g" > adSrcFiles.tmp_f      cat $TMP.adSrcFiles | sed -e "s/\.f/.$FS/g" > $TMP.adSrcFiles_f
2645      mv -f adSrcFiles.tmp_f adSrcFiles.tmp      mv -f $TMP.adSrcFiles_f $TMP.adSrcFiles
2646  fi  fi
2647    
2648  echo  echo
# Line 2484  for i in $INCLUDEDIRS ; do Line 2654  for i in $INCLUDEDIRS ; do
2654      fi      fi
2655  done  done
2656    
2657  if test ! "x$DIVA" = x ; then  if test ! "x$DIVA" = x -a ! "x$MPI" = x ; then
2658      echo "  Creating the pseudo-MPI include directory"      if test ! "x$MPIINCLUDEDIR" = x ; then
2659      INCLUDES="-I./mpi_headers $INCLUDES"          #  Do a local copy of MPI headers files (in local dir ./mpi_headers/) after
2660      rm -rf ./mpi_headers          #   checking for additional included headers (in case of chain of included
2661      mkdir -p ./mpi_headers          #   header); also set LOCAL_MPI_HEADERS (if not already set)
2662            mpi_headers_do_local_copy
     if test "x$MPIINCLUDEDIR" = x ; then  
         if test "x$MPIHOME" = x ; then  
             MPIHOME='/usr'  
         fi  
         MPIINCLUDEDIR='$MPIHOME/include'  
     fi  
   
     if test -r $MPIINCLUDEDIR/mpif.h ; then  
         for i in $MPI_HEADER_FILES; do  
             cp -p $MPIINCLUDEDIR/$i ./mpi_headers  
         done  
   
         perl -i -pe 's/MPI_DISPLACEMENT_CURRENT=-1_8/MPI_DISPLACEMENT_CURRENT=-1/g' mpi_headers/mpif.h  
     else  
         echo " We cannot create a copy of mpif.h!"  
 #       exit -1  
2663      fi      fi
2664  fi  fi
2665    
2666  echo "  Determining the list of source and include files"  echo "  Determining the list of source and include files"
2667  rm -rf .links.tmp  rm -rf $TMP.links
2668  mkdir .links.tmp  mkdir $TMP.links
2669  touch .links.tmp/foo  touch $TMP.links/foo
2670  if test ! -r ".links.tmp/foo" ; then  if test ! -r "$TMP.links/foo" ; then
2671      echo      echo
2672      echo "ERROR : something is wrong with your directory permissions or"      echo "ERROR : something is wrong with your directory permissions or"
2673      echo "   your user file-creation mask (\"umask\") since creating a"      echo "   your user file-creation mask (\"umask\") since creating a"
# Line 2529  if test ! -r ".links.tmp/foo" ; then Line 2683  if test ! -r ".links.tmp/foo" ; then
2683      echo      echo
2684      exit 1      exit 1
2685  fi  fi
2686  rm -f .links.tmp/foo  rm -f $TMP.links/foo
2687    
2688  if test "x$OPENAD" != x ; then  if test "x$OPENAD" != x ; then
2689      OAD_DONT_COMPILE="/dev/null"      OAD_DONT_COMPILE="/dev/null"
# Line 2537  if test "x$OPENAD" != x ; then Line 2691  if test "x$OPENAD" != x ; then
2691      OAD_KEEP_ORIGINAL="/dev/null"      OAD_KEEP_ORIGINAL="/dev/null"
2692      OAD_CB2M_FILES="/dev/null"      OAD_CB2M_FILES="/dev/null"
2693      OADTOOLS="$TOOLSDIR/OAD_support"      OADTOOLS="$TOOLSDIR/OAD_support"
2694      test -f "oadtempflile"  &&  \rm -f "oadtempflile"      OADTOOLSMK='$(TOOLSDIR)/OAD_support'
 cat >> "oadtempflile" <<EOF  
 $OADTOOLS  
 EOF  
2695      echo "  looking for dontCompile file:  "      echo "  looking for dontCompile file:  "
2696      for i in "." $MODS ; do      for i in "." $MODS $OADTOOLS ; do
2697          if test -r $i"/dontCompile" ; then          if test -r $i"/dontCompile" ; then
2698              OAD_DONT_COMPILE=$i"/dontCompile"              OAD_DONT_COMPILE=$i"/dontCompile"
2699              echo "     found $OAD_DONT_COMPILE"              echo "     found $OAD_DONT_COMPILE"
# Line 2550  EOF Line 2701  EOF
2701          fi          fi
2702      done      done
2703      echo "  looking for dontTransform file:  "      echo "  looking for dontTransform file:  "
2704      for i in "." $MODS ; do      for i in "." $MODS $OADTOOLS ; do
2705          if test -r $i"/dontTransform" ; then          if test -r $i"/dontTransform" ; then
2706              OAD_DONT_TRANSFORM=$i"/dontTransform"              OAD_DONT_TRANSFORM=$i"/dontTransform"
2707              echo "     found $OAD_DONT_TRANSFORM"              echo "     found $OAD_DONT_TRANSFORM"
# Line 2558  EOF Line 2709  EOF
2709          fi          fi
2710      done      done
2711      echo "  looking for keepOriginal file:  "      echo "  looking for keepOriginal file:  "
2712      for i in "." $MODS ; do      for i in "." $MODS $OADTOOLS ; do
2713          if test -r $i"/keepOriginal" ; then          if test -r $i"/keepOriginal" ; then
2714              OAD_KEEP_ORIGINAL=$i"/keepOriginal"              OAD_KEEP_ORIGINAL=$i"/keepOriginal"
2715              echo "     found $OAD_KEEP_ORIGINAL"              echo "     found $OAD_KEEP_ORIGINAL"
# Line 2566  EOF Line 2717  EOF
2717          fi          fi
2718      done      done
2719      echo "  looking for cb2mFiles:  "      echo "  looking for cb2mFiles:  "
2720      for i in "." $MODS ; do      for i in "." $MODS $OADTOOLS ; do
2721          if test -r $i"/cb2mFiles" ; then          if test -r $i"/cb2mFiles" ; then
2722              OAD_CB2M_FILES=$i"/cb2mFiles"              OAD_CB2M_FILES=$i"/cb2mFiles"
2723              echo "     found $OAD_CB2M_FILES"              echo "     found $OAD_CB2M_FILES"
# Line 2576  EOF Line 2727  EOF
2727      echo "   OpenAD exceptions:  "      echo "   OpenAD exceptions:  "
2728  fi  fi
2729    
2730  echo "# This section creates symbolic links" > srclinks.tmp  echo "# This section creates symbolic links" > $TMP.srclinks
2731  echo "" >> srclinks.tmp  echo "" >> $TMP.srclinks
2732  printf 'F77_SRC_FILES = ' > F77srclist.tmp  printf 'F77_SRC_FILES = ' > $TMP.F77srclist
2733  printf 'NON_AD_F77_SRC_FILES = ' > nonADF77srclist.tmp  printf 'NON_AD_F77_SRC_FILES = ' > $TMP.nonADF77srclist
2734  printf 'C_SRC_FILES = '   > csrclist.tmp  printf 'C_SRC_FILES = '   > $TMP.csrclist
2735  printf 'F90_SRC_FILES = ' > F90srclist.tmp  printf 'F90_SRC_FILES = ' > $TMP.F90srclist
2736  printf 'H_SRC_FILES = '   > hsrclist.tmp  printf 'H_SRC_FILES = '   > $TMP.hsrclist
2737  printf 'AD_FLOW_FILES = ' > ad_flow_files.tmp  printf 'AD_FLOW_FILES = ' > $TMP.ad_flow_files
2738  alldirs="$SOURCEDIRS $INCLUDEDIRS ."  alldirs="$SOURCEDIRS $INCLUDEDIRS ."
2739    alldirsmk=(${SOURCEDIRSMK} ${INCLUDEDIRSMK} ".")
2740    nd=0
2741  for d in $alldirs ; do  for d in $alldirs ; do
2742        dmk=${alldirsmk[${nd}]}
2743        nd=$((${nd}+1))
2744      deplist=      deplist=
2745      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`      sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
2746      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`      sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
# Line 2593  for d in $alldirs ; do Line 2748  for d in $alldirs ; do
2748          sfiles=`( echo $sfiles | grep -v _cb2m\. )`          sfiles=`( echo $sfiles | grep -v _cb2m\. )`
2749      fi      fi
2750      for sf in $sfiles ; do      for sf in $sfiles ; do
2751          if test ! -r ".links.tmp/$sf" ; then          if test ! -r "$TMP.links/$sf" ; then
2752              if test -f "$d/$sf" ; then              if test -f "$d/$sf" ; then
2753                  ignore_f=f                  ignore_f=f
2754                  case $d/$sf in                  case $d/$sf in
# Line 2618  for d in $alldirs ; do Line 2773  for d in $alldirs ; do
2773                          if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then                          if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then
2774                              ignore_f=t                              ignore_f=t
2775                          else                          else
2776                              touch .links.tmp/$sf                              touch $TMP.links/$sf
2777                              deplist="$deplist $sf"                              deplist="$deplist $sf"
2778                          fi                          fi
2779                          ;;                          ;;
# Line 2627  for d in $alldirs ; do Line 2782  for d in $alldirs ; do
2782                      extn=`echo $sf | $AWK -F. '{print $NF}'`                      extn=`echo $sf | $AWK -F. '{print $NF}'`
2783                      case $extn in                      case $extn in
2784                        F)                        F)
2785                          echo    " \\"  >> F77srclist.tmp                          echo    " \\"  >> $TMP.F77srclist
2786                          printf " $sf" >> F77srclist.tmp                          printf " $sf" >> $TMP.F77srclist
2787                          if test "x$OPENAD" != x ; then                          if test "x$OPENAD" = x ; then
2788                                basename=${sf%%.F}
2789                                isAD=`egrep ^$basename.f'[  ]*' $TMP.adSrcFiles`
2790                                if test -z "$isAD" ; then
2791                                    echo    " \\"  >> $TMP.nonADF77srclist
2792                                    printf " $sf" >> $TMP.nonADF77srclist
2793                                fi
2794                            else #- OpenAD case:
2795                              basename=${sf%%.F}                              basename=${sf%%.F}
2796                              isAD=`egrep ^$basename.f'[  ]*' adSrcFiles.tmp`                              isAD=`egrep ^$basename.f'[  ]*' $TMP.adSrcFiles`
2797                              if test -z "$isAD" ; then                              if test -z "$isAD" ; then
2798                                  toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE}`                                  toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE}`
2799                                  if test -z "$toBeIgnored" ; then                                  if test -z "$toBeIgnored" ; then
2800                                      echo    " \\"  >> nonADF77srclist.tmp                                      echo    " \\"  >> $TMP.nonADF77srclist
2801                                      printf " $sf" >> nonADF77srclist.tmp                                      printf " $sf" >> $TMP.nonADF77srclist
2802                                  else                                  else
2803                                      echo "    not to be compiled   :  $sf"                                      echo "    not to be compiled   :  $sf"
2804                                  fi                                  fi
# Line 2651  for d in $alldirs ; do Line 2813  for d in $alldirs ; do
2813                                      echo "    original to be kept  :  $sf"                                      echo "    original to be kept  :  $sf"
2814                                  fi                                  fi
2815                                  if test -n "$notToBeTransformed" -o -n "$untransformedVersionToBeKept" ; then                                  if test -n "$notToBeTransformed" -o -n "$untransformedVersionToBeKept" ; then
2816                                      echo    " \\"  >> nonADF77srclist.tmp                                      echo    " \\"  >> $TMP.nonADF77srclist
2817                                      printf " $sf" >> nonADF77srclist.tmp                                      printf " $sf" >> $TMP.nonADF77srclist
2818                                  fi                                  fi
2819                              fi                              fi
2820                          fi                          fi
2821                          ;;                          ;;
2822                      F90)                      F90)
2823                          echo    " \\"  >> F90srclist.tmp                          echo    " \\"  >> $TMP.F90srclist
2824                          printf " $sf" >> F90srclist.tmp                          printf " $sf" >> $TMP.F90srclist
2825                          ;;                          ;;
2826                      c)                      c)
2827                          echo    " \\"  >> csrclist.tmp                          echo    " \\"  >> $TMP.csrclist
2828                          printf " $sf" >> csrclist.tmp                          printf " $sf" >> $TMP.csrclist
2829                          ;;                          ;;
2830                      h)                      h)
2831                          echo    " \\"  >> hsrclist.tmp                          echo    " \\"  >> $TMP.hsrclist
2832                          printf " $sf" >> hsrclist.tmp                          printf " $sf" >> $TMP.hsrclist
2833                          ;;                          ;;
2834                      flow)                      flow)
2835                          echo    " \\"  >> ad_flow_files.tmp                          echo    " \\"  >> $TMP.ad_flow_files
2836                          printf " $sf" >> ad_flow_files.tmp                          printf " $sf" >> $TMP.ad_flow_files
2837                          ;;                          ;;
2838                     esac                     esac
2839                  fi                  fi
# Line 2680  for d in $alldirs ; do Line 2842  for d in $alldirs ; do
2842      done      done
2843      if test "x$deplist" != x ; then      if test "x$deplist" != x ; then
2844        if test "$d" != "." ; then        if test "$d" != "." ; then
2845          echo "" >> srclinks.tmp          echo "" >> $TMP.srclinks
2846          echo "#  These files are linked from $d" >> srclinks.tmp          echo "#  These files are linked from $dmk ( aka $d )" >> $TMP.srclinks
2847          echo "$deplist :" >> srclinks.tmp          echo "$deplist :" >> $TMP.srclinks
2848  # We need to make sure that the link isn't already there.  # We need to make sure that the link isn't already there.
2849  # This may happen when make thinks that a header file has to be "remade"  # This may happen when make thinks that a header file has to be "remade"
2850  # because a module it depends on has changed.  In this case we do nothing.  # because a module it depends on has changed.  In this case we do nothing.
2851          printf "\tif [ ! -L \$@ ]; then \$(LN) %s/\$@ \$@; fi\n" $d >> srclinks.tmp          printf "\tif [ ! -L \$@ ]; then \$(LN) %s/\$@ \$@; fi\n" $dmk >> $TMP.srclinks
2852        fi        fi
2853      fi      fi
2854  done  done
2855  rm -rf .links.tmp  rm -rf $TMP.links
2856  echo "" >> F77srclist.tmp  echo "" >> $TMP.F77srclist
2857  echo "" >> nonADF77srclist.tmp  echo "" >> $TMP.nonADF77srclist
2858  echo "" >> csrclist.tmp  echo "" >> $TMP.csrclist
2859  echo "" >> F90srclist.tmp  echo "" >> $TMP.F90srclist
2860  echo "" >> hsrclist.tmp  echo "" >> $TMP.hsrclist
2861  echo "" >> ad_flow_files.tmp  echo "" >> $TMP.ad_flow_files
2862    
2863  CMDLINE=$0  CMDLINE=$0
2864  for xx in "$@" ; do nw=`echo $xx | wc -w`  for xx in "$@" ; do nw=`echo $xx | wc -w`
# Line 2743  cat >>$MAKEFILE <<EOF Line 2905  cat >>$MAKEFILE <<EOF
2905    
2906  ROOTDIR     = ${ROOTDIR}  ROOTDIR     = ${ROOTDIR}
2907  BUILDDIR    = ${BUILDDIR}  BUILDDIR    = ${BUILDDIR}
2908  SOURCEDIRS  = ${SOURCEDIRS}  SOURCEDIRS  = ${SOURCEDIRSMK}
2909  INCLUDEDIRS = ${INCLUDEDIRS}  INCLUDEDIRS = ${INCLUDEDIRSMK}
2910  EXEDIR      = ${EXEDIR}  EXEDIR      = ${EXEDIR}
2911  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}  EXECUTABLE  = \$(EXEDIR)/${EXECUTABLE}
2912  TOOLSDIR    = ${TOOLSDIR}  TOOLSDIR    = ${TOOLSDIRMK}
2913  OADTOOLS    = ${OADTOOLS}  OADTOOLS    = ${OADTOOLSMK}
2914    
2915  #eh3  new defines for the adjoint work  #eh3  new defines for the adjoint work
2916  AUTODIFF    = ${ROOTDIR}/pkg/autodiff  AUTODIFF    = \$(ROOTDIR)/pkg/autodiff
2917  EXE_AD      = ${EXE_AD}  EXE_AD      = ${EXE_AD}
2918  EXE_FTL     = ${EXE_FTL}  EXE_FTL     = ${EXE_FTL}
2919  EXE_SVD     = ${EXE_SVD}  EXE_SVD     = ${EXE_SVD}
# Line 2798  CPPINCLUDES = ${CPPINCLUDES} Line 2960  CPPINCLUDES = ${CPPINCLUDES}
2960  KFLAGS1 = ${KFLAGS1}  KFLAGS1 = ${KFLAGS1}
2961  KFLAGS2 = ${KFLAGS2}  KFLAGS2 = ${KFLAGS2}
2962  # Optim./debug for FC  # Optim./debug for FC
2963  FFLAGS = ${FFLAGS} ${FEXTRAFLAGS}  FFLAGS = ${FFLAGS}
2964  FOPTIM = ${FOPTIM}  FOPTIM = ${FOPTIM} ${FEXTRAFLAGS}
2965  # Optim./debug for FC  # Optim./debug for FC
2966  F90FLAGS = ${F90FLAGS}  F90FLAGS = ${F90FLAGS}
2967  F90OPTIM = ${F90OPTIM}  F90OPTIM = ${F90OPTIM}
# Line 2818  MAKE = ${MAKE} Line 2980  MAKE = ${MAKE}
2980    
2981  EOF  EOF
2982    
2983  cat F77srclist.tmp      >> $MAKEFILE  cat $TMP.F77srclist      >> $MAKEFILE
2984  cat nonADF77srclist.tmp >> $MAKEFILE  cat $TMP.nonADF77srclist >> $MAKEFILE
2985  cat csrclist.tmp        >> $MAKEFILE  cat $TMP.csrclist        >> $MAKEFILE
2986  cat F90srclist.tmp      >> $MAKEFILE  cat $TMP.F90srclist      >> $MAKEFILE
2987  cat hsrclist.tmp        >> $MAKEFILE  cat $TMP.hsrclist        >> $MAKEFILE
2988  cat ad_flow_files.tmp   >> $MAKEFILE  cat $TMP.ad_flow_files   >> $MAKEFILE
2989    
2990  rm -f F77srclist.tmp nonADF77srclist.tmp csrclist.tmp F90srclist.tmp hsrclist.tmp ad_flow_files.tmp  rm -f $TMP.F77srclist $TMP.nonADF77srclist $TMP.csrclist $TMP.F90srclist $TMP.hsrclist $TMP.ad_flow_files
2991    
2992  echo >> $MAKEFILE  echo >> $MAKEFILE
2993    
# Line 2865  depend: Line 3027  depend:
3027    
3028  lib: libmitgcmuv.a  lib: libmitgcmuv.a
3029    
3030  libmitgcmuv.a: \$(OBJFILES)  libmitgcmuv.a: \$(SPECIAL_FILES) \$(OBJFILES)
3031          ar rcv libmitgcmuv.a \$(OBJFILES)          ar rcv libmitgcmuv.a \$(OBJFILES)
3032          ar d   libmitgcmuv.a main.o          ar d   libmitgcmuv.a main.o
3033    
# Line 2875  links: \$(F77_SRC_FILES) \$(C_SRC_FILES) Line 3037  links: \$(F77_SRC_FILES) \$(C_SRC_FILES)
3037    
3038  small_f: \$(F77_PP_SRC_FILES) \$(F90_PP_SRC_FILES)  small_f: \$(F77_PP_SRC_FILES) \$(F90_PP_SRC_FILES)
3039    
 output.txt: \$(EXECUTABLE)  
         @printf 'running ... '  
         @\$(EXECUTABLE) > \$@  
   
3040  # remove most of the files that "make" generates  # remove most of the files that "make" generates
3041  clean:  clean:
3042          -rm -rf *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template          -rm -rf *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
# Line 2892  Clean: Line 3050  Clean:
3050          @\$(MAKE) -f \$(MAKEFILE) cleanlinks          @\$(MAKE) -f \$(MAKEFILE) cleanlinks
3051          -rm -f \$(SPECIAL_FILES) f90mkdepend.log $MAKEFILE.old          -rm -f \$(SPECIAL_FILES) f90mkdepend.log $MAKEFILE.old
3052          -rm -f taf_command taf_output taf_ad.log taf_ad_flow.log taf_ftl.log          -rm -f taf_command taf_output taf_ad.log taf_ad_flow.log taf_ftl.log
         -rm -f genmake_warnings genmake_errors make.log  
3053    
3054  # remove also the executable, files that "genmake2" generates (except Makefile)  # remove also the executable, files that "genmake2" generates (except Makefile)
3055  #         and output from a run (plus log files from testreport)  #         and output from a run (plus log files from testreport)
# Line 2901  CLEAN: Line 3058  CLEAN:
3058          -rm -f \$(EXECUTABLE) \$(EXE_AD) \$(EXE_FTL) *.bak          -rm -f \$(EXECUTABLE) \$(EXE_AD) \$(EXE_FTL) *.bak
3059          -rm -f $LOGFILE genmake_state genmake_*optfile          -rm -f $LOGFILE genmake_state genmake_*optfile
3060          -rm -f SIZE.h.mpi genmake.tr_log make.tr_log          -rm -f SIZE.h.mpi genmake.tr_log make.tr_log
3061            -rm -rf mpi_headers mnc_test_*
3062          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;          -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
3063          -find \$(EXEDIR) -name "*.data" -exec rm {} \;          -find \$(EXEDIR) -name "*.data" -exec rm {} \;
3064          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;          -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
3065          -rm -f *.txt STD* *diagnostics.log datetime          -rm -f *.txt STDOUT.* STDERR.* *diagnostics.log *.[0-9][0-9][0-9][0-9].log
3066            -rm -f datetime costfinal divided.ctrl snapshot* output_adm.txt.diva_*
3067          -rm -f *_MIT_CE_000.opt0000 costfunction*0000          -rm -f *_MIT_CE_000.opt0000 costfunction*0000
3068          -rm -rf mnc_test_*          -rm -f oad_cp.[0-9][0-9][0-9].?????
3069    
3070  makefile:  makefile:
3071          $THIS_SCRIPT $G2ARGS          $THIS_SCRIPT $G2ARGS
# Line 3003  TAF            = ${TAF} Line 3162  TAF            = ${TAF}
3162    
3163  TAF_EXTRA      = ${TAF_EXTRA}  TAF_EXTRA      = ${TAF_EXTRA}
3164  TAMC_EXTRA     = ${TAMC_EXTRA}  TAMC_EXTRA     = ${TAMC_EXTRA}
3165    LOCAL_MPI_HEADERS    = ${LOCAL_MPI_HEADERS}
3166    
3167  EOF  EOF
3168    
# Line 3020  done Line 3180  done
3180  echo "  Add the source list for AD code generation"  echo "  Add the source list for AD code generation"
3181  echo >> $MAKEFILE  echo >> $MAKEFILE
3182  printf "AD_FILES = " >> $MAKEFILE  printf "AD_FILES = " >> $MAKEFILE
3183  AD_FILES=`cat adSrcFiles.tmp`  AD_FILES=`cat $TMP.adSrcFiles`
3184  for i in $AD_FILES ; do  for i in $AD_FILES ; do
3185      echo    " \\" >> $MAKEFILE      echo    " \\" >> $MAKEFILE
3186      printf " $i" >> $MAKEFILE      printf " $i" >> $MAKEFILE
3187  done  done
3188  echo >> $MAKEFILE  echo >> $MAKEFILE
3189  rm -f adSrcFiles.tmp  rm -f $TMP.adSrcFiles
3190    
3191    if test $CAT_SRC_FOR_TAF = 0 ; then
3192    cat >>$MAKEFILE <<EOF
3193    
3194    # ... Utilities ...
3195    remove_comments:
3196            sed -i.bak -f \$(TOOLSDIR)/remove_comments_sed \$(AD_FILES)
3197            @-rm -f \$(AD_FILES:.$FS=.$FS.bak)
3198    adj_sed:
3199            sed -i.bak -f \$(TOOLSDIR)/adjoint_sed \$(AD_FILES:.$FS=_ad.$FS)
3200            @-rm -f \$(AD_FILES:.$FS=_ad.$FS.bak)
3201    ftl_sed:
3202            sed -i.bak -f \$(TOOLSDIR)/adjoint_sed \$(AD_FILES:.$FS=_tl.$FS)
3203            @-rm -f \$(AD_FILES:.$FS=_tl.$FS.bak)
3204    adobjfiles: \$(AD_FILES:.$FS=_ad.o)
3205    ftlobjfiles: \$(AD_FILES:.$FS=_tl.o)
3206    EOF
3207    fi
3208    
3209  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
3210    
# Line 3050  ad_input_code.$FS: \$(AD_FILES) \$(AD_FL Line 3228  ad_input_code.$FS: \$(AD_FILES) \$(AD_FL
3228          @\$(MAKE) -f \$(MAKEFILE) \$(FLOWFILES)          @\$(MAKE) -f \$(MAKEFILE) \$(FLOWFILES)
3229          cat \$(FLOWFILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ad_input_code.$FS          cat \$(FLOWFILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ad_input_code.$FS
3230    
3231  ad_taf_output.$FS: ad_input_code.$FS  adtafonly:
3232          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
3233          ls -l ad_input_code_ad.$FS          ls -l ad_input_code_ad.$FS
3234          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
3235    
3236  adtafonly:  EOF
3237    
3238    if test $CAT_SRC_FOR_TAF = 1 ; then
3239    cat >>$MAKEFILE <<EOF
3240    # ... send 1 file to TAF ...
3241    ad_taf_output.$FS: ad_input_code.$FS
3242            @-rm -f ad_input_code_ad.$FS ; echo ''
3243          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS          \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
3244          ls -l ad_input_code_ad.$FS          ls -l ad_input_code_ad.$FS
3245          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS          cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
3246    
3247  \$(EXE_AD): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) ad_taf_output.o \$(OBJFILES) \$(EMBEDDED_FILES)  \$(EXE_AD): \$(SPECIAL_FILES) \$(H_SRC_FILES) ad_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(EMBEDDED_FILES)
3248          \$(LINK) -o \${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)          \$(LINK) -o \${EXE_AD} \$(FFLAGS) \$(FOPTIM) ad_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(LIBS)
3249    
3250  ad_tamc_output.$FS: ad_input_code.$FS  adobj: ad_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o)
         \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS  
         cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS  
3251    
3252  ad_tamc: ad_tamc_output.o \$(OBJFILES)  EOF
3253          \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)  
3254    else
3255    cat >>$MAKEFILE <<EOF
3256    # ... send multiple files to TAF ...
3257    ad_taf_output.$FS: \$(AD_FLOW_FILES) \$(AD_FILES)
3258            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3259            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3260            @-rm -f ad_config.template
3261            @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3262            @\$(MAKE) -f \$(MAKEFILE) \$(FLOWFILES)
3263            @-rm -f \$(AD_FILES:.$FS=_ad.$FS) \$(AD_FILES:.$FS=_ad.o); echo ''
3264            \$(MAKE) -f \$(MAKEFILE) remove_comments
3265            \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) \$(FLOWFILES) \$(AD_FILES)
3266            \$(MAKE) -f \$(MAKEFILE) adj_sed
3267            cat \$(AD_FILES:.$FS=_ad.$FS) > ad_taf_output.$FS
3268    
3269    \$(EXE_AD): \$(SPECIAL_FILES) \$(H_SRC_FILES) ad_taf_output.$FS \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(EMBEDDED_FILES)
3270            \$(MAKE) -f \$(MAKEFILE) adobjfiles
3271            \$(LINK) -o \${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(AD_FILES:.$FS=_ad.o) \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(LIBS)
3272    
3273    adobj: ad_taf_output.$FS \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o)
3274            \$(MAKE) -f \$(MAKEFILE) adobjfiles
3275    
3276    EOF
3277    fi
3278    
3279    cat >>$MAKEFILE <<EOF
3280  adonlyfwd:  adonlyfwd:
3281          patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff          patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
3282    
3283  adtrick:  adtrick:
3284          patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff          patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
3285    
3286  adobj: ad_taf_output.o \$(OBJFILES)  ad_tamc_output.$FS: ad_input_code.$FS
3287            \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
3288            cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS
3289    
3290    ad_tamc: ad_tamc_output.o \$(OBJFILES)
3291            \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
3292    
3293  # ... FTL ...  # ... FTL ...
3294  ftlall: ftl_exe_target  ftlall: ftl_exe_target
# Line 3098  ftl_input_code.$FS: \$(AD_FILES) Line 3310  ftl_input_code.$FS: \$(AD_FILES)
3310          @\$(MAKE) -f \$(MAKEFILE) \$(AD_FLOW_FILES)          @\$(MAKE) -f \$(MAKEFILE) \$(AD_FLOW_FILES)
3311          cat \$(AD_FLOW_FILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ftl_input_code.$FS          cat \$(AD_FLOW_FILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ftl_input_code.$FS
3312    
3313  ftl_taf_output.$FS: ftl_input_code.$FS  ftltafonly:
3314          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
3315          ls -l ftl_input_code_ftl.$FS          ls -l ftl_input_code_tl.$FS
3316          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS          cat ftl_input_code_tl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
3317    
3318  ftltafonly:  EOF
3319    
3320    if test $CAT_SRC_FOR_TAF = 1 ; then
3321    cat >>$MAKEFILE <<EOF
3322    # ... send 1 file to TAF ...
3323    ftl_taf_output.$FS: ftl_input_code.$FS
3324            @-rm -f ftl_input_code_tl.$FS ; echo ''
3325          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS          \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
3326          ls -l ftl_input_code_ftl.$FS          ls -l ftl_input_code_tl.$FS
3327          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS          cat ftl_input_code_tl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
3328    
3329  \$(EXE_FTL): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) ftl_taf_output.o \$(OBJFILES) \$(EMBEDDED_FILES)  \$(EXE_FTL): \$(SPECIAL_FILES) \$(H_SRC_FILES) ftl_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(EMBEDDED_FILES)
3330          \$(LINK) -o \${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)          \$(LINK) -o \${EXE_FTL} \$(FFLAGS) \$(FOPTIM) ftl_taf_output.o \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(LIBS)
3331    
3332    EOF
3333    
3334    else
3335    cat >>$MAKEFILE <<EOF
3336    # ... send multiple files to TAF ...
3337    ftl_taf_output.$FS: \$(AD_FLOW_FILES) \$(AD_FILES)
3338            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
3339            cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3340            @-rm -f ad_config.template
3341            @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3342            @\$(MAKE) -f \$(MAKEFILE) \$(AD_FLOW_FILES)
3343            @-rm -f \$(AD_FILES:.$FS=_tl.$FS) \$(AD_FILES:.$FS=_tl.o); echo ''
3344            \$(MAKE) -f \$(MAKEFILE) remove_comments
3345            \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) \$(AD_FLOW_FILES) \$(AD_FILES)
3346            \$(MAKE) -f \$(MAKEFILE) ftl_sed
3347            cat \$(AD_FILES:.$FS=_tl.$FS) > ftl_taf_output.$FS
3348    
3349    \$(EXE_FTL): \$(SPECIAL_FILES) \$(H_SRC_FILES) ftl_taf_output.$FS \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(EMBEDDED_FILES)
3350            \$(MAKE) -f \$(MAKEFILE) ftlobjfiles
3351            \$(LINK) -o \${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(AD_FILES:.$FS=_tl.o) \$(NON_AD_F77_SRC_FILES:.F=.o) \$(F90_SRC_FILES:.F90=.o) \$(C_SRC_FILES:.c=.o) \$(LIBS)
3352    
3353    EOF
3354    fi
3355    
3356    cat >>$MAKEFILE <<EOF
3357  ftl_tamc_output.$FS: ftl_input_code.$FS  ftl_tamc_output.$FS: ftl_input_code.$FS
3358          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS          \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
3359          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS          cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS
# Line 3153  if test "x$OPENAD" != x ; then Line 3396  if test "x$OPENAD" != x ; then
3396  # ============ begin OpenAD specific section ==============  # ============ begin OpenAD specific section ==============
3397    
3398  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
3399    # ... OpenAD ...
3400    
3401  # all the source files linked from the various locations:  # all the source files linked from the various locations:
3402  ALL_LINKED_FILES= \  ALL_LINKED_FILES= \
# Line 3192  for i in `cat ${OAD_CB2M_FILES}` ; do Line 3436  for i in `cat ${OAD_CB2M_FILES}` ; do
3436    echo    " \\" >> $MAKEFILE    echo    " \\" >> $MAKEFILE
3437    printf " ${i}_mod.f$FS90" >> $MAKEFILE    printf " ${i}_mod.f$FS90" >> $MAKEFILE
3438  done  done
3439  AD_FILES=`cat adSrcFiles.tmp`  AD_FILES=`cat $TMP.adSrcFiles`
3440  for i in $AD_FILES ; do  for i in $AD_FILES ; do
3441    basename=${i%%.f}    basename=${i%%.f}
3442    toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE} ${OAD_DONT_TRANSFORM}`    toBeIgnored=`egrep ^$basename'[      ]*' ${OAD_DONT_COMPILE} ${OAD_DONT_TRANSFORM}`
# Line 3202  for i in $AD_FILES ; do Line 3446  for i in $AD_FILES ; do
3446    fi    fi
3447  done  done
3448  echo >> $MAKEFILE  echo >> $MAKEFILE
3449  rm -f adSrcFiles.tmp  rm -f $TMP.adSrcFiles
3450    
3451  cat >>$MAKEFILE <<EOF  cat >>$MAKEFILE <<EOF
3452    
3453  adAll: \$(EXE_AD)  adAll: ad_exe_target
3454  .PHONY: adAll  .PHONY: adAll
3455    
3456    ad_exe_target:
3457            @echo Update AD_CONFIG.h and make \$(EXE_AD)
3458            @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3459            @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3460            @-rm -f ad_config.template
3461            \$(MAKE) -f \$(MAKEFILE) \$(EXE_AD)
3462    
3463  CB2M_F90_PP_SRC_FILES=\$(addsuffix _mod.f$FS90, \$(CB2M_F90_SRC_NAMES))  CB2M_F90_PP_SRC_FILES=\$(addsuffix _mod.f$FS90, \$(CB2M_F90_SRC_NAMES))
3464    
3465  .PRECIOUS: \$(CB2M_F90_PP_SRC_FILES) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90)  .PRECIOUS: \$(CB2M_F90_PP_SRC_FILES) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90)
# Line 3225  OAD_active.F90 \ Line 3476  OAD_active.F90 \
3476  OAD_cp.F90 \  OAD_cp.F90 \
3477  OAD_rev.F90 \  OAD_rev.F90 \
3478  OAD_tape.F90 \  OAD_tape.F90 \
3479    OAD_regular_cp.F90 \
3480  revolve.F90  revolve.F90
3481    
3482  OPENAD_SUPPORT_C_SRC_FILES = \  OPENAD_SUPPORT_C_SRC_FILES = \
# Line 3251  AD_OBJ_FILES_S2=\$(AD_OBJ_FILES_S1) \$(N Line 3503  AD_OBJ_FILES_S2=\$(AD_OBJ_FILES_S1) \$(N
3503          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(AD_OBJ_FILES_S2) \$(LIBS)          \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(AD_OBJ_FILES_S2) \$(LIBS)
3504    
3505  # create sources files modules from header files containing common blocks  # create sources files modules from header files containing common blocks
3506  %_mod.FF90 : %.h \${OADTOOLS}/cb2mGetModules.csh \${OADTOOLS}/cb2mGetModules.awk  %_mod.FF90 : %.h \$(OADTOOLS)/cb2mGetModules.csh \$(OADTOOLS)/cb2mGetModules.awk
3507          \${OADTOOLS}/cb2mGetModules.csh $< \${OADTOOLS}/cb2mGetModules.awk          \$(OADTOOLS)/cb2mGetModules.csh $< \$(OADTOOLS)/cb2mGetModules.awk
3508    
3509  # create new header files with USE statements for the new modules made above  # create new header files with USE statements for the new modules made above
3510  %_mod.h : %.h \${OADTOOLS}/cb2mGetHeaders.csh \${OADTOOLS}/cb2mGetHeaders.awk  %_mod.h : %.h \$(OADTOOLS)/cb2mGetHeaders.csh \$(OADTOOLS)/cb2mGetHeaders.awk
3511          \${OADTOOLS}/cb2mGetHeaders.csh $< \${OADTOOLS}/cb2mGetHeaders.awk \$(CB2M_F90_SRC_NAMES)          \$(OADTOOLS)/cb2mGetHeaders.csh $< \$(OADTOOLS)/cb2mGetHeaders.awk \$(CB2M_F90_SRC_NAMES)
3512    
3513  # change the include directives of everybody to refer to  the new header files with the USE statements  # change the include directives of everybody to refer to  the new header files with the USE statements
3514  %_cb2m.FF90 : %.F \${OADTOOLS}/cb2mUseModules.bash  %_cb2m.FF90 : %.F \$(OADTOOLS)/cb2mUseModules.bash
3515          \${OADTOOLS}/cb2mUseModules.bash $< ${MPI}          \$(OADTOOLS)/cb2mUseModules.bash $< ${MPI}
3516    
3517  # makefile debug rule  # makefile debug rule
3518  small_f: \$(CB2M_F90_PP_SRC_FILES)  small_f: \$(CB2M_F90_PP_SRC_FILES)
3519  .PHONY: small_f  .PHONY: small_f
3520    
 ad_output.txt: \$(EXE_AD)  
         @printf 'linking data files ... '  
         \$(LN) -f ../input_ad/data* ../input_ad/eedata .  
         \$(LN) -f ../../global_ocean.90x40x15/input/*.bin .  
         @printf 'running ... '  
         @./\$(EXE_AD) > \$@  
   
3521  ad_input_code.f$FS90:  \$(CB2M_AD_FILES)  ad_input_code.f$FS90:  \$(CB2M_AD_FILES)
3522          cat \$^ > \$@          cat \$^ > \$@
3523    
# Line 3282  ad_input_code_sf.pre.f90 : \$(CB2M_AD_FI Line 3527  ad_input_code_sf.pre.f90 : \$(CB2M_AD_FI
3527    
3528  # replace stop statements (to avoid the implied unstructured control flow)  with print statements  # replace stop statements (to avoid the implied unstructured control flow)  with print statements
3529  ad_input_code_sf.pre.s2p.f90 : ad_input_code_sf.pre.f90  ad_input_code_sf.pre.s2p.f90 : ad_input_code_sf.pre.f90
3530          cat \$< | sed -f \${OADTOOLS}/stop2print.sed > ad_input_code_sf.pre.s2p.f90          cat \$< | sed -f \$(OADTOOLS)/stop2print.sed > ad_input_code_sf.pre.s2p.f90
3531    
3532  # F -> WHIRL  # F -> WHIRL
3533  ad_input_code_sf.pre.s2p.B: ad_input_code_sf.pre.s2p.f90  ad_input_code_sf.pre.s2p.B: ad_input_code_sf.pre.s2p.f90
# Line 3305  ad_input_code_sf.pre.s2p.xb.x2w.w2f.f$FS Line 3550  ad_input_code_sf.pre.s2p.xb.x2w.w2f.f$FS
3550          \${OPEN64ROOT}/whirl2f/whirl2f -FLIST:ftn_file=\$@ -openad \$<          \${OPEN64ROOT}/whirl2f/whirl2f -FLIST:ftn_file=\$@ -openad \$<
3551    
3552  # insert template directives  # insert template directives
3553  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  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
3554          \${OADTOOLS}/insertTemplateDir.bash \$< \$@          \$(OADTOOLS)/insertTemplateDir.bash \$< \$@
3555    
3556  PPEXTRAS=\$(wildcard \${OADTOOLS}/ad_template.*.F) \${OADTOOLS}/ad_inline.F  PPEXTRAS=\$(notdir \$(wildcard \$(OADTOOLS)/ad_template.*.F)) ad_inline.F
3557  # postprocess F'  # postprocess F'
3558  postProcess.tag: ad_input_code_sf.pre.s2p.xb.x2w.w2f.td.f$FS90 \$(PPEXTRAS:.F=.f) | w2f__types.f90  postProcess.tag: ad_input_code_sf.pre.s2p.xb.x2w.w2f.td.f$FS90 \$(PPEXTRAS:.F=.f) | w2f__types.f90
3559          \${OPENADFORTTK_BASE}/tools/SourceProcessing/postProcess.py --progress --timing --infoUnitFile w2f__types.f90 --outputFormat=fixed --separateOutput --pathSuffix "" --filenameSuffix "_oad" -m r -i \${OADTOOLS}/ad_inline.f \$<          \${OPENADFORTTK_BASE}/tools/SourceProcessing/postProcess.py --progress --timing --infoUnitFile w2f__types.f90 --outputFormat=fixed --separateOutput --pathSuffix "" --filenameSuffix "_oad" -m r -i ad_inline.f \$<
3560          # the target is a placeholder to trigger a single execution of the rule          # the target is a placeholder to trigger a single execution of the rule
3561          touch \$@          touch \$@
3562  # put this so make knows about the postprocessing output  # put this so make knows about the postprocessing output
# Line 3322  OAD_intrinsics_oad.f \$(CB2M_AD_FILES:.f Line 3567  OAD_intrinsics_oad.f \$(CB2M_AD_FILES:.f
3567          \$(LN) \${XAIFSCHEMAROOT}/schema/\$@ .          \$(LN) \${XAIFSCHEMAROOT}/schema/\$@ .
3568    
3569  # link the support files:  # link the support files:
3570  \$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES):  \$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES) \$(PPEXTRAS):
3571          \$(LN) \${OADTOOLS}/\$@ .          \$(LN) \$(OADTOOLS)/\$@ .
3572    
3573  AD_CLEAN += *_mod.h *_mod.F90 *.FF90 *.mod-whirl temp.sed oad_cp.* postProcess.tag \$(PPEXTRAS:.F=.f)  AD_CLEAN += *_mod.h *_mod.F90 *.FF90 *.mod-whirl temp.sed oad_cp.* postProcess.tag
3574    
3575  # ============ end OpenAD specific section ==============  # ============ end OpenAD specific section ==============
3576    
# Line 3361  for i in $NOOPTFILES ; do Line 3606  for i in $NOOPTFILES ; do
3606  done  done
3607    
3608  echo "  Add rules for links"  echo "  Add rules for links"
3609  cat srclinks.tmp >> $MAKEFILE  cat $TMP.srclinks >> $MAKEFILE
3610  rm -f srclinks.tmp  rm -f $TMP.srclinks
3611    
3612  echo "  Adding makedepend marker"  echo "  Adding makedepend marker"
3613  printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE  printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE

Legend:
Removed from v.1.249  
changed lines
  Added in v.1.280

  ViewVC Help
Powered by ViewVC 1.1.22