# Makefile.in for LCC, Amiga port 26-Aug-1996; Joop van de Wege
# email: Joop.vandeWege@medew.ento.wau.nl
# TODO: make install rule
#       add rule for building with lcc/rcc (path problems!)
#       the old one is there but don't know if it works!
#       make the number of code-generators configurable

srcdir = @srcdir@
VPATH = @srcdir@
SHELL=/bin/sh
CC=@CXX@
CFLAGS = @CFLAGS@
GNUFLAGS = @GNUFLAGS@
INTERLNAL_CFLAGS= $(CFLAGS) $(GNUFLAGS) $(INTERNAL_INCLUDE)
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
INTERNAL_INCLUDE=-I$(srcdir)

OBJS=alloc.o bind.o dag.o decl.o enode.o error.o expr.o event.o \
	init.o input.o lex.o list.o main.o output.o prof.o profio.o simp.o \
	stmt.o string.o sym.o trace.o tree.o types.o \
	null.o symbolic.o gen.o mips.o sparc.o x86.o mc68030.o

all:	rcc

rcc:	$(OBJS)
		$(CC) -o $@ $(OBJS) $(LDFLAGS) -lm

alloc.o: alloc.c
	$(CC) $(CFLAGS) -c $(srcdir)/alloc.c
bind.o: bind.c
	$(CC) $(CFLAGS) -c $(srcdir)/bind.c
dag.o: dag.c
	$(CC) $(CFLAGS) -c $(srcdir)/dag.c
decl.o: decl.c
	$(CC) $(CFLAGS) -c $(srcdir)/decl.c
enode.o:	enode.c
	$(CC) $(CFLAGS) -c $(srcdir)/enode.c
error.o:	error.c
	$(CC) $(CFLAGS) -c $(srcdir)/error.c
event.o:	event.c
	$(CC) $(CFLAGS) -c $(srcdir)/event.c
expr.o:		expr.c
	$(CC) $(CFLAGS) -c $(srcdir)/expr.c
gen.o:		gen.c
	$(CC) $(CFLAGS) -c $(srcdir)/gen.c
init.o:		init.c
	$(CC) $(CFLAGS) -c $(srcdir)/init.c
input.o:	input.c
	$(CC) $(CFLAGS) -c $(srcdir)/input.c
lex.o:		lex.c
	$(CC) $(CFLAGS) -c $(srcdir)/lex.c
list.o:		list.c
	$(CC) $(CFLAGS) -c $(srcdir)/list.c
main.o:		main.c
	$(CC) $(CFLAGS) -c $(srcdir)/main.c
null.o:		null.c
	$(CC) $(CFLAGS) -c $(srcdir)/null.c
output.o:	output.c
	$(CC) $(CFLAGS) -c $(srcdir)/output.c
prof.o:		prof.c
	$(CC) $(CFLAGS) -c $(srcdir)/prof.c
profio.o:	profio.c
	$(CC) $(CFLAGS) -c $(srcdir)/profio.c
simp.o:		simp.c
	$(CC) $(CFLAGS) -c $(srcdir)/simp.c
stmt.o:		stmt.c
	$(CC) $(CFLAGS) -c $(srcdir)/stmt.c
string.o:	string.c
	$(CC) $(CFLAGS) -c $(srcdir)/string.c
sym.o:		sym.c
	$(CC) $(CFLAGS) -c $(srcdir)/sym.c
symbolic.o:	symbolic.c
	$(CC) $(CFLAGS) -c $(srcdir)/symbolic.c
trace.o:	trace.c
	$(CC) $(CFLAGS) -c $(srcdir)/trace.c
tree.o:		tree.c
	$(CC) $(CFLAGS) -c $(srcdir)/tree.c
types.o:	types.c
	$(CC) $(CFLAGS) -c $(srcdir)/types.c
mips.o:		mips.c
	$(CC) $(CFLAGS) $(INTERNAL_INCLUDE) -c mips.c
sparc.o:	sparc.c
	$(CC) $(CFLAGS) $(INTERNAL_INCLUDE) -c sparc.c
x86.o:		x86.c
	$(CC) $(CFLAGS) $(INTERNAL_INCLUDE) -c x86.c
mc68030.o:	mc68030.c
	$(CC) $(CFLAGS) $(INTERNAL_INCLUDE) -c mc68030.c

$(OBJS):	$(srcdir)/c.h $(srcdir)/token.h $(srcdir)/config.h

mips.c:		$(srcdir)/mips.md
	 ../lburg/lburg <$(srcdir)/mips.md  >mips.c
sparc.c:	$(srcdir)/sparc.md
	 ../lburg/lburg <$(srcdir)/sparc.md >sparc.c
x86.c:		$(srcdir)/x86.md
	 ../lburg/lburg <$(srcdir)/x86.md   >x86.c
mc68030.c:	$(srcdir)/mc68030.md
	../lburg/lburg <$(srcdir)/mc68030.md   >mc68030.c

test:	tst/8q.s tst/array.s tst/cf.s tst/cq.s tst/cvt.s tst/fields.s \
	tst/front.s tst/incr.s tst/init.s tst/limits.s tst/paranoia.s \
	tst/sort.s tst/spill.s tst/stdarg.s tst/struct.s tst/switch.s \
	tst/wf1.s tst/yacc.s

T=$(SRC)/../tst
RUN=$(SRC)/run
RCC=rcc
LCC=gcc
CMD=@$(RUN) $(TARGET)

tst/8q.s:	$(RUN) $(RCC) $(T)/8q.c		$(T)/8q.0;	$(CMD) 8q
tst/array.s:	$(RUN) $(RCC) $(T)/array.c	$(T)/array.0;	$(CMD) array
tst/cf.s:	$(RUN) $(RCC) $(T)/cf.c		$(T)/cf.0;	$(CMD) cf
tst/cq.s:	$(RUN) $(RCC) $(T)/cq.c		$(T)/cq.0;	$(CMD) cq
tst/cvt.s:	$(RUN) $(RCC) $(T)/cvt.c	$(T)/cvt.0;	$(CMD) cvt
tst/fields.s:	$(RUN) $(RCC) $(T)/fields.c	$(T)/fields.0;	$(CMD) fields
tst/front.s:	$(RUN) $(RCC) $(T)/front.c	$(T)/front.0;	$(CMD) front
tst/incr.s:	$(RUN) $(RCC) $(T)/incr.c	$(T)/incr.0;	$(CMD) incr
tst/init.s:	$(RUN) $(RCC) $(T)/init.c	$(T)/init.0;	$(CMD) init
tst/limits.s:	$(RUN) $(RCC) $(T)/limits.c	$(T)/limits.0;	$(CMD) limits
tst/paranoia.s:	$(RUN) $(RCC) $(T)/paranoia.c	$(T)/paranoia.0;$(CMD) paranoia
tst/sort.s:	$(RUN) $(RCC) $(T)/sort.c	$(T)/sort.0;	$(CMD) sort
tst/spill.s:	$(RUN) $(RCC) $(T)/spill.c	$(T)/spill.0;	$(CMD) spill
tst/stdarg.s:	$(RUN) $(RCC) $(T)/stdarg.c	$(T)/stdarg.0;	$(CMD) stdarg
tst/struct.s:	$(RUN) $(RCC) $(T)/struct.c	$(T)/struct.0;	$(CMD) struct
tst/switch.s:	$(RUN) $(RCC) $(T)/switch.c	$(T)/switch.0;	$(CMD) switch
tst/wf1.s:	$(RUN) $(RCC) $(T)/wf1.c      	$(T)/wf1.0;	$(CMD) wf1
tst/yacc.s:	$(RUN) $(RCC) $(T)/yacc.c     	$(T)/yacc.0;	$(CMD) yacc

OPTS=CC='$(LCC) -B./ -d0.1 -A' \
	CFLAGS='-Wf-target=$(TARGET) -I$(SRC)/../include/`echo $(TARGET)|tr - /` \
	-I$(SRC)' LDFLAGS='$(LDFLAGS)'

triple:	rcc
	rm -f *.o
	make -f $(SRC)/makefile $(OPTS)
	-strip rcc
	-od rcc +8 >od2
	rm -f *.o
	make -f $(SRC)/makefile $(OPTS)
	-strip rcc
	-od rcc +8 >od3
	cmp od[23] && rm od[23]

testclean:
	-rm -f tst/*.[12so]
	-cd tst; rm -f 8q array cf cq cvt fields front incr init \
		limits paranoia sort spill stdarg struct switch wf1 yacc
	
clean:		testclean
		-rm -f *.o

clobber:	clean
		rm -f rcc lburg
#		rm -f $(SRC)/mips.c $(SRC)/sparc.c $(SRC)/x86.c
