#!/bin/csh -f

#
# configure must be run first -- configure.upp is output
if ( ! -e configure.upp ) then
	echo "ERR :: No configure.upp file => Do './configure' first"
	exit ( 1 ) 
else if ( -z configure.upp ) then
	echo "ERR :: Empty configure.upp file => Do './configure' first"
	exit ( 2 ) 
endif

#
# NETCDF environment variable must be set
if  ( ( ! $?NETCDF ) && ( -d netcdf_links ) ) then
	setenv NETCDF `pwd`/netcdf_links
	setenv temp_netcdf 1
else
	setenv temp_netcdf 0
endif

#
# Not expecting any arguments
if ( ${#argv} == 0 ) then
	echo "**** Compiling UPP and all libs ****"
   set MAKE = `awk '($1~/^MAKE/) {print substr($0,index($0,"=")+1) }' configure.upp`
   ( ${MAKE} -i -f makefile all )
else
   echo "*****"
   echo " "
	echo "Unrecognized compile target $1."
   echo " "
   echo " Usage:"
   echo " compile"
   echo "   make will be called from this directory
   echo " "
   echo "*****"
   exit(1)
endif

if ( $temp_netcdf == 1 ) then
	unsetenv NETCDF
endif

exit(0)