#! /bin/csh -f 

source $CASEROOT/env_conf         || exit -1
source $CASEROOT/env_run          || exit -1
source $CASEROOT/env_mach.$MACH  || exit -1
source $CASEROOT/env_pes.$MACH  || exit -1

set exedir = $EXEROOT/atm
set objdir = $OBJROOT/atm/obj

cd $objdir

#------------------------------------------------------------------------------
# Filepath: List of source code directories (in order of importance).
#------------------------------------------------------------------------------

\cat >! Filepath << EOF1
$CASEROOT/SourceMods/src.datm
$CODEROOT/atm/datm7
$SHAREROOT/dshr
$SHAREROOT/shr
$SHAREROOT/cpl
EOF1

#------------------------------------------------------------------------------
# run make
#------------------------------------------------------------------------------

if ($BLDTYPE == 'TRUE') then
if ($OS == 'UNICOS') then
  if (`uname` == 'Linux') then
    # cross compiler needs to run dependency program locally
    module purge
    gcc -o makdep $BLDROOT/makdep.c || exit 2
    source $CASEROOT/env_mach.$MACH  || exit -1
  else
    # makes the build run faster on the Cray X1
    cc -h command -o makdep $BLDROOT/makdep.c || exit 2
  endif
else
  cc -o makdep $BLDROOT/makdep.c || exit 2
endif
  set THREAD = FALSE ;  if ($NTHRDS_ATM > 1) set THREAD = TRUE
  gmake VPFILE=Filepath MODEL=datm EXEC=$exedir/datm \
             THREAD=$THREAD \
             -f  $BLDROOT/Makefile MACFILE=$CASEROOT/Macros.$MACH deps   || exit 2
  gmake -j $GMAKE_J VPFILE=Filepath MODEL=datm EXEC=$exedir/datm \
             THREAD=$THREAD \
             -f  $BLDROOT/Makefile MACFILE=$CASEROOT/Macros.$MACH    || exit 2
endif

if !(-f $exedir/datm) then
  echo "ERROR: datm executable not available, check SETBLD"
  exit -1
endif

