#!/bin/csh -f

set nonomatch

#
# execute all make clean in subshell to retain PWD
# we don't care about failures to ignore 'em
printf  "\n\n<><><><><><><><> CLEAN BEGIN <><><><><><><><>\n\n"
make clean
printf  "\n\n<><><><><><><> CLEAN COMPLETE <><><><><><><><>\n\n"

#
# clear configuration file to force a reconfigure after a clean
# Configuration file exists
if ( -e configure.upp ) then
  #
  # Configuration file is empty - don't overwrite backup
  if ( ! -z configure.upp ) then
	/bin/mv configure.upp configure.upp.backup
  endif
endif

# empty file for clean op
touch configure.upp

# Now remove this to force a reconfigure

#
# clean -a -- look for anything that may not have been cleaned up and
#   remove it 
if ( "$1" == '-a' ) then
   printf  "\n\n<><><><><><><>   CLEAN ALL    <><><><><><><><>\n\n"
	/bin/rm -rf ./netcdf_links
	find . -name \*.exe -exec \rm {} \; 
	find . -name \*.o -exec \rm {} \; 
	find . -name \*.a -exec \rm {} \; 
   find . -name \*.mod -exec \rm {} \;

   rm -rf bin
   rm -rf lib
   rm -rf include
   printf  "\n\n<><><><><><> CLEAN ALL COMPLETE <><><><><><><><>\n\n"
endif