#!/bin/csh -f
#
# Eric A. Brewer  4-17-90
# Version 2.0  -- 8-27-91
#
# $Header: /u/brewer/sim4/RCS/makesim,v 1.7 92/10/28 11:38:15 brewer Exp $
# $Log:	makesim,v $
# Revision 1.7  92/10/28  11:38:15  brewer
# Added onintr cleanup code to remove tmp file.
# 
# Revision 1.6  92/09/24  11:52:47  brewer
# Added cpp args -U and -I
# 
# Revision 1.5  92/09/23  10:59:59  brewer
# Added handling for -f flag
# Added -DUSERMAKE=... to cpp invocation
# swicthed to /bin/csh -f execution shell
# 
# Revision 1.4  92/06/25  13:27:09  brewer
# Added code to exit with a nonzero status if the make has problems
# 
# Revision 1.3  92/04/03  17:22:53  brewer
# removed pipe of SimMake into /bin/make,
# replaced it with a temporary file.  This is a workaround
# for an Ultrix bug.
# 
# Revision 1.2  92/04/02  14:05:01  brewer
# changed "cpp" to "cc -E"
# 
# Revision 1.1  92/02/11  16:08:03  brewer
# Initial revision
# 
#

set cpp = 'cc -E'
set cpp_args = ""
set make_args = "-k"
set usermake = "UserMake"

while ("$1" != "")
	if ("$1" =~ -D*) then
		set cpp_args = ($cpp_args $1)
	else if ("$1" =~ -U*) then
		set cpp_args = ($cpp_args $1)
	else if ("$1" =~ -I*) then
		set cpp_args = ($cpp_args $1)
	else if ("$1" == "-f") then
		if ($#argv > 1) then
			set usermake = $2
			shift
		endif
	else
		set make_args = ($make_args $1)
	endif
	shift
end

#echo CPP: $cpp_args
#echo MAKE: $make_args

set tmp_file = makesim.$$
onintr cleanup

$cpp SimMake $cpp_args -DUSERMAKE='"'$usermake'"' > $tmp_file
if ($status) exit 1

/bin/make $make_args -f $tmp_file
if ($status) then
	/bin/rm $tmp_file
	exit 1
endif

/bin/rm -f $tmp_file
exit $status

cleanup:
echo "cleaning up..."
/bin/rm -f $tmp_file
exit 1

