# (C) Copyright International Business Machines Corporation 23 January 
# 1990.  All Rights Reserved. 
#  
# See the file USERAGREEMENT distributed with this software for full 
# terms and conditions of use. 
# File: Makefile
# Author: David F. Bacon
# SCCS Info: @(#)Makefile	1.18 5/25/90

include ../make/includefile

# redefine default lex to binary rule so that it keeps the lex source
#   around just in case we fall into it while debugging.
.l.o:
	$(LEX) $<
	$(CC) $(CFLAGS) -c lex.yy.c
	mv lex.yy.o $@

LIBDIRS	=	-L../li -L../lib -L../cherm -L../cfunc -L.
# Set following to "/usr/lib/debug/malloc.o" to load in malloc_debug support
MALLOCDEBUG =
LIBS	=	$(MALLOCDEBUG) -lfe -lhermi -lcherm -ll -lhaux $(IRISLIBS)

CHLIBS	=	-ll

LINTLIBS =	-lhaux -lhasm -lhermi -lcherm

YACC	=	yacc -Nm50000
YFLAGS	=	-v
#YACC	=	bison
#YFLAGS	=	-v -y -t

LIBOBJS	=	main.o resolve.o definition.o module.o decl.o \
		process.o unqualname.o typestate.o \
		printmap.o main.o backpatch.o objname.o lookup.o \
		fegram.o felex.o stack.o tempstore.o links.o

IOOBJS	=	standalone.o integrated.o

OBJECTS	=	$(LIBOBJS) $(IOOBJS)

all:		fe integrated.o chgram

install:	all install-chgram
	cp fe $(HERMES)

install-chgram:	chgram
	cp chgram $(CHGRAM)

libfe.a: $(LIBOBJS)
	ar r libfe.a $?
	$(RANLIB) libfe.a

fe: standalone.o libfe.a
	$(CC) $(CFLAGS) -o fe standalone.o $(LIBS)

# yacc-ity yacc, don't talk back....

tokens.yacc: keywords othertokens
	cat othertokens keywords | awk -f tokens.awk >tokens.yacc

keywords.lex: keywords
	awk -f keywords.awk keywords >keywords.lex

ident.yacc: keywords reswords
	egrep -v `awk -f reswords.awk reswords` keywords | \
	  awk -f ident.awk >ident.yacc
 
felex.l: felex.lex felex.h keywords.lex othertokens
	m4 felex.lex >felex.l
	
felex.c: felex.l
	lex -t felex.l >felex.c

#
# automatically generated yacc productions
#
#kleene.yacc: kleene.gram
#	awk -f kleene.awk kleene.gram >kleene.yacc
#opt.yacc: opt.gram
#	awk -f opt.awk opt.gram >opt.yacc
#list.yacc: list.gram
#	awk -f list.awk list.gram >list.yacc
#series.yacc: series.gram
#	awk -f series.awk series.gram >series.yacc

#
# the grammar
#
fegram.y: fegram.yacc ident.yacc opt.yacc series.yacc kleene.yacc \
    list.yacc tokens.yacc 
	m4 fegram.yacc >fegram.y

fegram.c tokens.h: fegram.y
	$(YACC) -d $(YFLAGS) fegram.y
	mv y.tab.c fegram.c
	mv y.tab.h tokens.h

#
# resolution
#
printmap.c: printmap.ch resolve.h resproc.cd stack.o
objname.c: objname.ch resolve.h
definition.c: definition.ch resolve.h
module.c: module.ch resolve.h 
decl.c: decl.ch resolve.h backpatch.cd
typestate.c: typestate.ch resolve.h
process.c: process.ch resolve.h stack.o resproc.cd
backpatch.c: backpatch.ch resolve.h backpatch.cd
lookup.c: lookup.ch resolve.h 
unqualname.c: unqualname.ch unqualname.cd resolve.h
links.c: links.ch

integrated.c: integrated.ch unixenv.h
standalone.c: standalone.ch unixenv.h

#
# chgram'd local defintions
#
backpatch.cd: backpatch.d
resproc.cd: resproc.d
unqualname.cd: unqualname.d


# test for true correctness
lint: fegram.o felex.o $(RESOBJS)
	$(LINT) $(LFLAGS) *.c

# cleanup
clean cln:
	rm -f *.o core a.out lex.yy.c y.tab.c *~*~ .*~*~ *~ *.cd \
	felex.l keywords.lex fe y.output tokens.h \
	tokens.yacc tokens.include ident.yacc fegram.y felex.c fegram.c \
	printmap.c objname.c definition.c name.c module.c \
	decl.c typestate.c process.c backpatch.c lookup.c links.c \
	unqualname.c integrated.c standalone.c \
	libfe.a \
	chgram chgram.c chgram.y fast fegram.tex

#
# the version of the front end which builds definitions for the assembler
#

chgram.y: chgram.yacc ident.yacc opt.yacc series.yacc kleene.yacc \
    list.yacc tokens.yacc 
	m4 chgram.yacc >chgram.y

chgram.c: chgram.y
	$(YACC) -d $(YFLAGS) chgram.y
	mv y.tab.c chgram.c
	mv y.tab.h tokens.h

chgram: chgram.o felex.o chmain.o 
	$(CC) $(CFLAGS) -o chgram chmain.o chgram.o felex.o $(CHLIBS)

#
# old debugging stuff
#
readstamp: readstamp.o
	$(CC) $(CFLAGS) -o readstamp readstamp.o -lhermi -lcherm -lhaux-f

readstamp.c: readstamp.ch

