#!/bin/csh -f
#
#  MKSRC -- Make a pure source tree and configure the links for the 
#  current architecture.


unset	noclobber
onintr	cleanup_
unalias cd cp cmp echo ln mv rm sed set grep ls chmod chown pwd touch sort which

setenv	path  "(/sbin /usr/sbin /bin /usr/bin /usr/5bin /usr/ucb /etc /usr/etc $path /usr/local/bin /opt/local/bin /local/bin /home/local/bin /usr/openwin/bin /usr/X11R6/bin /usr/X11/bin)"

# Utility aliases.
alias PUT      "mv -f \!*; chown $user \!$ "                   # [MACHDEP]
alias BOLD_ON  "(tput bold)"
alias BOLD_OFF "(tput sgr0)"
alias SO_ON    "(tput smso)"
alias SO_OFF   "(tput sgr0)"

alias DO_OK    "(echo -n '[ '; BOLD_ON; echo -n ' OK '; BOLD_OFF; echo ' ]')"
alias DO_WARN  "(echo -n '[ '; BOLD_ON; echo -n 'WARN'; BOLD_OFF; echo ' ]')"
alias DO_FAIL  "(echo -n '[ ';   SO_ON; echo -n 'FAIL';   SO_OFF; echo ' ]')"

alias ERRMSG   "(echo -n '   ';BOLD_ON;echo -n 'ERROR: '  ;BOLD_OFF; echo \!*)"
alias WARNING  "(echo -n '   ';BOLD_ON;echo -n 'WARNING: ';BOLD_OFF; echo \!*)"
alias NEWLINE  "(echo '')"



# set echo


if (! $?iraf) then
    echo ""
    echo "Error:  You must have the iraf env variable defined !"
    echo ""
    exit 1
endif


set	exec	= yes
set	arch	= `$iraf/unix/hlib/irafarch.csh`


#=============================================================================
# Process any command line arguments.
#=============================================================================
while ("$1" != "")
    switch ("$1")
    case -n:                            # no execute
        set exec = no
        breaksw
    default:
        ERRMSG  "$0: unknown argument $1"
        breaksw
    endsw

    if ("$2" == "") then
        break
    else
        shift
    endif
end





#----------------------------------
# Determine platform architecture.
#----------------------------------

echo -n "Clean host directories ...."
  if ($exec == "yes") then
    /bin/rm -f unix/bin.*/[agm-z]*.e unix/bin.*/lib[bco]*.a >& /dev/null
  else
    /bin/ls -l unix/bin.*/[agm-z]*.e unix/bin.*/lib[bco]*.a
  endif
echo "		Done"



echo -n "Clean src directories ...."
foreach i (local math pkg sys noao)
  if ($exec == "yes") then
    find $i -type f -name \*.a   -exec /bin/rm -f {} \;		>& /dev/null
    find $i -type f -name \*.e   -exec /bin/rm -f {} \;		>& /dev/null
    find $i -type f -name \*.o   -exec /bin/rm -f {} \;		>& /dev/null
    find $i -type f -name OBJS\* -exec /bin/ls -l {} \;		>& /dev/null
  else
    find $i -type f -name \*.a   -exec /bin/ls -l {} \;
    find $i -type f -name \*.e   -exec /bin/ls -l {} \;
    find $i -type f -name \*.o   -exec /bin/ls -l {} \;
    find $i -type f -name OBJS\* -exec /bin/ls -l {} \;
  endif
end
echo "		Done"


echo -n "Clean bin directories ...."
if ($exec == "yes") then
    /bin/rm -rf bin.*/*.[aeoZ] noao/bin.*/*.[aeoZ] OBJS*	>& /dev/null
else
    /bin/ls -l  bin.*/*.[aeoZ] noao/bin.*/*.[aeoZ] OBJS*
endif
echo "		Done"


echo -n "Cleaning spool files ...."
if ($exec == "yes") then
    find . -name spool\* -print -exec /bin/rm -f {} \;		>& /dev/null
    find . -name _spool\* -print -exec /bin/rm -f {} \;		>& /dev/null
else
    find . -name spool\* -print
    find . -name _spool\* -print
endif
echo "		Done"
