#echo#######################################################################
# Makefile for   Fortran DVM front-end
#
#	HDR	traditional header files.
#	HDRg	header files generated by programs.
#	SRC	traditional  source files.
#	SRCg	source files generated by programs.
#	OBJS	object files required to load the program.
#

#PATH=$PATH/usr/freeware/lib:
SHELL = /bin/sh
CONFIG_ARCH=iris4d
#!!
SAGEROOT=../Sage
LIBDIR = ../libsage
#LIBDIR = $(SAGEROOT)/lib/$(CONFIG_ARCH)
#LIBDIR = /usr/people/podd/oldsrc
LIBINCLUDE = $(SAGEROOT)/lib/include
HINCLUDE =$(SAGEROOT)/h
DVMINCLUDE = ../include
#INSTALLDEST = $(SAGEROOT)/bin/$(CONFIG_ARCH)
INSTALLDEST = ../bin
INSTALL = /bin/cp
#!!

CC = gcc
#USE_CC#CC=cc#ENDIF#

CXX = /usr/WorkShop/usr/DCC

LINKER = $(CC)



LINTFLAGS = -azhx -I$(HINCLUDE)

#C90#EXTRAOBJS=../lib/c90/alloca-c90.o#ENDIF#
#MIPS_CC#CEXTRA = -Wf,-XNg800#ENDIF#
#HP-ALLOCA#LDLIBS = -lPW#ENDIF#
#HP_CFLAGS#CEXTRA = -Aa#ENDIF#

CFLAGS = -g -Wall -I$(DVMINCLUDE) -I$(HINCLUDE) -I$(LIBINCLUDE) $(CFEXTRA) $(CEXTRA) -DSYS5

LIBS	= $(LIBDIR)/libdb.a
#HP_CFLAGS#LIBS	= $(LIBDIR)/libdb.sl#ENDIF#

# Comment the following line out if you don't use bison
#YACC	= /usr/local/bin/bison
YACC	= bison
#YACC = yacc
# Tells bison to be yacc-compatible and generates y.tab.h and y.tab.c
YFLAGS	= -vd
#!!
EXECUTABLES =	parse

# Directory in which include file can be found
TOOLBOX_HDR     =  $(LIBINCLUDE)/macro.h $(LIBINCLUDE)/bif_node.def  $(LIBINCLUDE)/type.def  $(LIBINCLUDE)/symb.def 
FDVM		=  $(DVMINCLUDE)/dvm_tag.h


HDR	= $(DVMINCLUDE)/inc.h $(HINCLUDE)/defs.h $(DVMINCLUDE)/fdvm.h $(HINCLUDE)/bif.h  \
          $(HINCLUDE)/ll.h $(HINCLUDE)/symb.h $(HINCLUDE)/defines.h  \
	  $(DVMINCLUDE)/extern.h $(HINCLUDE)/sets.h tag tokens

HDRg	= tag.h tokdefs.h

HDRS	= $(HDR) $(HDRg)
# !!
SRC	= cftn.c init.c hash.c lexfdvm.c lists.c\
	  misc.c stat.c  errors.c types.c sym.c\
	  low_hpf.c unparse_hpf.c
#!!
SRCg	= gram.tab.c

SRCS	= $(SRC) $(SRCg)
#!! 
OBJS	= cftn.o errors.o hash.o init.o lexfdvm.o lists.o\
	  misc.o stat.o types.o gram1.tab.o sym.o\
	  low_hpf.o unparse_hpf.o

all:	$(EXECUTABLES)

install: $(INSTALLDEST)/parse
 
$(INSTALLDEST)/parse: parse
		@echo Installing $? in $(INSTALLDEST)
		if [ -d $(INSTALLDEST) ] ; then true; \
		else mkdir $(INSTALLDEST) ;fi
		@$(INSTALL) $? $(INSTALLDEST)


$(EXECUTABLES) : $(OBJS) $(LIBS)
	@echo -n "Loading $(EXECUTABLES) ... "
	$(LINKER) $(LDFLAGS) $(OBJS) $(EXTRAOBJS) $(LIBS) \
		-o $(EXECUTABLES) $(LDLIBS)
	@echo "done"
# !!
gram1.tab.o:	gram1.tab.c
	$(CC) $(CFLAGS) -DYYDEBUG -c gram1.tab.c
#!!
gram1.tab.c:	tokdefs.h ftn.gram fdvm.gram fomp.gram facc.gram fspf.gram
	( sed < tokdefs.h "s/#define/%token/"; cat ftn.gram fdvm.gram fomp.gram facc.gram fspf.gram) > gram1.y
	$(YACC) $(YFLAGS) gram1.y

tokdefs.h: tokens
	grep -n . <tokens | sed "s/\([^:]*\):\(.*\)/#define \2 \1/" >tokdefs.h

tag.h:	head tag
	( cat head; \
	  sed < tag \
	    '/#defin/s/\([^ ]*\) \([^ 	]*\)\(.*\)/  tag \[ \2 \] = \"\2\";/')\
	  > tag.h

lint:
	lint $(LINTFLAGS) $(SRCS) $(SAGEROOT)/lib/llib-llibdb.ln

clean:
		@rm -f $(OBJS)
		@rm -f $(EXECUTABLES)
		@rm -f *.dep
cleaninstall:
		/bin/rm -f $(OBJS)
		/bin/rm -f $(EXECUTABLES)
		/bin/rm -f *.dep

realclean:
	@rm -f $(HDRg) gram1.tab.c

ci:
	ci -u -f $(SRC) $(HDR) ftn.gram

tags:	$(HDRS) $(SRC) ftn.gram; @etags $(HDRS) $(SRC) ftn.gram

update:	$(HDR) $(SRC) ftn.gram
	@update $?
	@touch update
###
cftn.o: $(HINCLUDE)/db.h $(HINCLUDE)/defs.h $(HINCLUDE)/tag $(HINCLUDE)/bif.h \
	$(HINCLUDE)/ll.h $(HINCLUDE)/symb.h $(HINCLUDE)/sets.h
ftn.gram: $(DVMINCLUDE)/extern.h $(HINCLUDE)/defines.h $(HINCLUDE)/defs.h \
        $(DVMINCLUDE)/fdvm.h $(HINCLUDE)/bif.h $(HINCLUDE)/ll.h $(HINCLUDE)/symb.h \
	$(HINCLUDE)/sets.h
commsym.o: $(HINCLUDE)/defs.h $(HINCLUDE)/tag $(HINCLUDE)/symb.h $(HINCLUDE)/defines.h \
	$(HINCLUDE)/bif.h $(DVMINCLUDE)/extern.h $(HINCLUDE)/db.h $(HINCLUDE)/ll.h \
	$(HINCLUDE)/sets.h
errors.o: $(HINCLUDE)/defs.h $(HINCLUDE)/tag $(HINCLUDE)/symb.h  $(DVMINCLUDE)/extern.h \
	$(HINCLUDE)/db.h $(HINCLUDE)/bif.h $(HINCLUDE)/ll.h $(HINCLUDE)/sets.h
exec.o: $(HINCLUDE)/defs.h $(HINCLUDE)/tag
gram.o: $(HINCLUDE)/defs.h \
	$(HINCLUDE)/tag $(HINCLUDE)/bif.h $(HINCLUDE)/ll.h $(HINCLUDE)/symb.h \
	$(HINCLUDE)/sets.h  $(DVMINCLUDE)/extern.h $(HINCLUDE)/db.h $(HINCLUDE)/defines.h 
hash.o: $(HINCLUDE)/defs.h $(HINCLUDE)/symb.h $(HINCLUDE)/defines.h $(DVMINCLUDE)/extern.h \
	$(HINCLUDE)/db.h $(HINCLUDE)/bif.h  $(HINCLUDE)/ll.h $(HINCLUDE)/sets.h $(HINCLUDE)/tag
init.o:  $(DVMINCLUDE)/inc.h $(HINCLUDE)/defs.h $(HINCLUDE)/bif.h  $(HINCLUDE)/defines.h \
	$(HINCLUDE)/ll.h $(HINCLUDE)/symb.h $(HINCLUDE)/sets.h $(HINCLUDE)/db.h $(HINCLUDE)/tag
# !!
lexfdvm.o: $(DVMINCLUDE)/extern.h
lists.o:$(HINCLUDE)/defs.h $(HINCLUDE)/ll.h $(HINCLUDE)/symb.h $(HINCLUDE)/bif.h
misc.o: $(HINCLUDE)/defs.h $(HINCLUDE)/tag $(HINCLUDE)/defines.h $(HINCLUDE)/db.h \
	$(HINCLUDE)/bif.h $(HINCLUDE)/ll.h $(HINCLUDE)/symb.h $(HINCLUDE)/sets.h
stat.o:	$(HINCLUDE)/defs.h $(HINCLUDE)/bif.h $(HINCLUDE)/ll.h $(HINCLUDE)/symb.h\
        $(HINCLUDE)/sets.h $(HINCLUDE)/defines.h $(DVMINCLUDE)/extern.h
sym.o:  $(HINCLUDE)/defs.h $(HINCLUDE)/tag $(HINCLUDE)/symb.h $(HINCLUDE)/defines.h \
	$(HINCLUDE)/bif.h $(DVMINCLUDE)/extern.h $(HINCLUDE)/db.h $(HINCLUDE)/ll.h \
	$(HINCLUDE)/sets.h $(DVMINCLUDE)/fdvm.h
types.o:$(HINCLUDE)/defs.h $(HINCLUDE)/ll.h $(HINCLUDE)/symb.h

low_hpf.o: low_hpf.c $(FDVM) $(TOOLBOX_HDR)         
unparse_hpf.o:   unparse_hpf.c   $(FDVM) $(TOOLBOX_HDR) $(DVMINCLUDE)/unparse.hpf


























