# $Id: Makefile,v 1.33 1992/11/09 11:26:10 grosch rel $

BIN	= $(HOME)/bin
LIB	= $(HOME)/lib

# Modula-2 source modules
SRCM	= AssocTab.md AssocTab.mi Base.md Base.mi DefMods.md DefMods.mi \
	  Errors.md Errors.mi Source.md Source.mi Tokens.md Tokens.mi \
	  UniqueIds.md UniqueIds.mi GenIdents.md GenIdents.mi \
	  Positions.md Positions.mi Values.md Values.mi Types.md Types.mi mtc.mi

# source modules generated by tools
GEN	= Parser.md Parser.mi Scanner.md Scanner.mi Tree.md Tree.mi \
	  Defs.md Defs.mi Semantics.md Semantics.mi Code.md Code.mi

# "runtime system"
RTS	= SYSTEM_.h SYSTEM_.c Arguments.h Arguments.c

all:	mtc_boot

mtc:	$(GEN) mtc_boot

mtc_boot:	$(SRCM)
	echo p mtc | mc -d ../../reuse/src -norange -noindex

Scanner.md Scanner.mi Scanner.Tab:	modula.rex
	rex -d modula.rex;

Parser.md Parser.mi Parser.Tab:	modula.ell
	ell -di modula.ell;

Tree.md Tree.mi:	modula.cg
	cg -mRdiDI0 modula.cg;

Semantics.md Semantics.mi:	modula.cg
	cg -DI0 modula.cg;

Defs.md Defs.mi:	defs.cg
	cg -mdi defs.cg;

Tree.TS:	modula.cg
	echo SELECT Abstract | cat - modula.cg | cg -4

Code.md Code.mi:	code.puma Tree.TS opp opp.sed
	opp code.puma | puma -dis
#	Opp = output pre processor

# swap all byte pairs of the file Scanner.Tab
# reverse all BITSETs (long words) of the file Parser.Tab

bin.conv:	convert
	dd conv=swab < Scanner.Tab > .Scanner.Tab; mv .Scanner.Tab Scanner.Tab
	dd conv=swab < Parser.Tab | convert > .Parser.Tab; mv .Parser.Tab Parser.Tab

convert:	convert.o
	cc -o convert convert.o

install:	mtc mtc.sh $(BIN) $(LIB)/mtc
	if test $(LIB) = $(BIN); then echo error: BIN = LIB; false; else true; fi
	sed 's;LIB;$(LIB);g' < mtc.sh > $(BIN)/mtc
	chmod a+rx $(BIN)/mtc
	install -c -s -m 755 mtc $(LIB)/mtc
	install -c -m 644 Scanner.Tab $(LIB)/mtc
	install -c -m 644 Parser.Tab $(LIB)/mtc
	cp $(RTS) $(LIB)/mtc
	cd $(LIB)/mtc; chmod a+r $(RTS)

# installation directories

$(BIN):
	sh -c "if test ! -d $(BIN); then mkdir $(BIN); else true; fi"

$(LIB):
	sh -c "if test ! -d $(LIB); then mkdir $(LIB); else true; fi"

$(LIB)/mtc:	$(LIB)
	sh -c "if test ! -d $(LIB)/mtc; then mkdir $(LIB)/mtc; else true; fi"

m2c:
	co RCS/*
	make $(GEN)
	cp *Tab ../m2c
	ln *.m[id] ../m2c
	cd ../m2c; make sources M2FLAGS="-c -d../../reuse/src"
	cd ../m2c; rm -f *.m[id]

MTC	= time mtc -tm -d../../reuse/src s.mi

test:	$(GEN) $(SRCM)
	cg -IL modula.cg;
	mv Semantics.mi s.mi
	cg -dimRDI0 modula.cg;
	make mtc
	tcsh -c "$(MTC); $(MTC); $(MTC); $(MTC)"
	wc Semantics.mi
	size Semantics.o mtc
	cg -dimRDI09 modula.cg;
	make mtc
	$(MTC)
	cg -dimRDI modula.cg;
	make mtc
	tcsh -c "$(MTC); $(MTC); $(MTC); $(MTC)"
	wc Semantics.mi
	size Semantics.o mtc
	cg -dimRDI9 modula.cg;
	make mtc
	$(MTC)
	cg -dimRDIL modula.cg;
	make mtc
	tcsh -c "$(MTC); $(MTC); $(MTC); $(MTC)"
	wc Semantics.mi
	size Semantics.o mtc
	cg -dimRDIL9 modula.cg;
	make mtc
	$(MTC)

clean:
	rm -f *.[dimor] core ERRORS LISTING convert *.bak

CLEAN:	clean
	rm -f mtc Scanner.Tab Parser.Tab Scanner.m? Parser.m? Tree.m? Defs.m? Semantics.m? Code.m? Tree.TS
