########################################################################
#                 copyright 2001, Amoco Production Company             #
#                             All Rights Reserved                      #
#                     an affiliate of BP America Inc.                  #
########################################################################

ifeq "${Vendor}" "sgi"
TargetArch :=  ${TargetArch:="-IRIX32"}
endif

include ${DEPTROOT}/usp/etc/gmake.init

IncludeDirs	:=	${strip -I${TArchDir} ${IncludeDirs}}

Libes		:= 	${Libes} -lieeeio -lut
ifneq "${SOLARIS}" ""
Libes		:= 	${Libes} -Bdynamic -ldl -Bstatic
endif

sun4CCFlags	:=	${sun4CCFlags} -DSUN -pipe
crayCCFlags	:=	${crayCCFlags} -DCRAY

YaccFlags 	:=	${YaccFlags} -d
#Yacc		:=	bison -y
Yacc		:=	yacc

CSrcs		:=	ufh.c		init.c				\
			mathfcns.c	symbol.c			\
			support.c	lexer.c		utils.c		\
			opcodes.c	arithops.c	arith2.c	\
			machine.c	datastak.c			\
			tpackage.c	run.c		debug.c	\
			iostuff.c	traceops.c	typestuff.c	\
			sismember.c

HSrcs		:=	ufh.h sismember.h functions.h

YaccSrcs	:=	parser.y

YaccCSrcs	=	${patsubst %.y, ${TArchDir}/%.c, ${YaccSrcs}}

YaccObjs	=	${patsubst %.y, ${TArchDir}/%.o, ${YaccSrcs}}

${TArchDir}/%.c:	%.y
	${Yacc} ${YaccFlags} $<
	mv y.tab.c ${patsubst %.y, %{TArchDir}/%.c, $<}
	mv y.tab.h ${TArchDir}/x_tab.h

${TArchDir}/%.o:	${TArchDir}/%.c
ifeq "${Vendor}" "cray"
	${CompileC} $<
	${MoveObjectToTArchDir}
else
	${CompileC} $< -o $@
endif

ThisDir		:=	${shell pwd}
# TargetName	:=	${shell basename ${ThisDir}} - this quit working
TargetName	:=	$(notdir ${ThisDir})
# Target		:=	${LocalBin}/${TargetName}
PRGM		:=	${LocalBin}/${TargetName}
TestFlags	:=	${TestFlags}

SafeFiles	:=	${wildcard *.h}			\
			ufh.pattern \
			${wildcard *.1}			\
			Makefile ${AllSrcs} ${YaccSrcs}	\
			Comments			\
			V2-Test V2-Test-Stage2 gather	\
			Echo-test


.PHONY: all remotes safe tags targets install v2.0-test

ifeq "${Vendor}" "cray"
OS-error:
	@echo  '**********************************************************'
	@echo  '** The current Cray OS causes fatal problems for ufh !! **'
	@echo  '**         Unable to rebuild ${TArchDir} version        **'
	@echo  '**********************************************************'
	DropThisMake:
endif

targets: v2.0-test

current: v2.0-test

v2.0-test: ${PRGM}
	${PRGM} V2-Test < gather | cat>/dev/null
	${PRGM} Echo-test 1 2 3 "last but not least" < /dev/null

${PRGM}:  ${YaccObjs} ${AllObjs}
	${LinkC} -o $@ $^ ${Libes} -lm

all: safe clean ${PRGM} remotes install tags

tags: TAGS

TAGS: ${CSrcs} ${HSrcs} ${YaccSrcs}
	${DEPTROOT}/lisp/browse/etags -bt ${CSrcs} ${HSrcs} ${YaccSrcs}

CFlow:	${YaccSrcs} ${CSrcs}
	cflow ${IncludeDirs} -Wf"-ix"  ${YaccSrcs} ${CSrcs} > CFlow

x_tab.h: ${TArchDir}/parser.o

parser.y: ufh.h

include	${TArchDir}/included.files

${TArchDir}/included.files: ${AllSrcs} ${YaccSrcs}
	${FindIncludes}

safe:	.safe.${jdate}.Z

.safe.${jdate}.Z:	${SafeFiles}
	${MakeSafe}

remotes:	RemoteCopies RemoteMakes

install:
	mancopy 1 ufh
	execopy  ufh
	shadowexec -v ${MAKE} install

RemoteCopies:	${SafeFiles}
	shadowcopy -v $? && touch RemoteCopies

RemoteMakes:	RemoteCopies ${SafeFiles}
	shadowexec -v ${MAKE} && touch RemoteMakes

clean:
	-rm ${TArchDir}/included.files ${AllObjs} ${PRGM} \
		RemoteCopies RemoteMakes ${wildcard ShdCpy*}
