#!/bin/csh -f
#	$Id$
#
#			Copyright (c) 1995 by
#			Kubota Graphics Technology Inc.
#			All Rights Reserved
#	
#	This software comprises unpublished confidential information of
#	Kubota Graphics Technology Inc. and may not be used, copied or
#	made available to anyone, except in accordance with the license
#	under which it is furnished.
#	
#	This file is under rcs control at KGT in:
#	$Source$
#
#
# Fortran compile & link script is
#	supported cpp process & library link process
#
#	initialize variables
#
set FC       = /bin/f77
set CPP      = '/usr/ccs/lib/cpp -P'
set lists    = ''
set cppsw    = 0
set srcs     = ''
set incpath  = '/usr/avs/include'

#
#	check arguments
#
foreach i ($argv)
	switch ($i)
	case -usage*:
		echo "Usage: $0 [ options ] [ files ]"
		echo "options:"
		echo "   -usage  Print this messages."
		echo "   -cpp    Invoke the C preprocessor on the source file before compiling."
		echo " Others See $FC"
		exit 0
	case -cpp:
		set cppsw = 1
		breaksw
	case -DOSF1:
		set CPP = '/usr/ccs/lib/cpp -DOSF1 -P'
		breaksw
	case *.f:
		set srcs = ($srcs $i)
		breaksw
	default:
		set lists = ($lists $i)
		breaksw
	endsw
end

#
#	cpp process
#
if ($cppsw == 1) then
	foreach i ($srcs)
		grep '^#' $i >& /dev/null
		if ($status != 0) then
			set lists = ($lists $i)
		else
			$CPP $i > /tmp/$i
			set lists = ($lists /tmp/$i)
			\rm -f /tmp/avs
			ln -s $incpath /tmp/avs
		endif
	end
else
	set lists = ($lists $srcs)
endif

#
#	compile & link process
#
$FC $lists
set result = $status

#
#	delete temorary file (/tmp/$srcs)
#
if ($cppsw == 1) then
	foreach i ($srcs)
##		(cd /tmp; \rm -f $i; \rm -r avs)
		(cd /tmp; \rm -f $i)
	end
endif
exit $result
