# $Id: Makefile,v 1.21 2001/03/05 17:01:02 si Exp $

##
##help
##	this target

help	:
	@grep ^## Makefile | sed 's|##||'

SRC	= \
	Matrix.hs	\
	Picture.hs	\
	Ppm.hs 		\
	Symbol.hs	\
	Lexer.hs	\
	AbstractSyntax.hs	\
	Parser.hs	\
	BuiltinFunctions.hs	\
	SemanticAnalysis.hs	\
	Instructions.hs \
	GlobalState.hs	\
	CodeGeneration.hs	\
	Assemble.hs	\
	MachineArchitecture.hs	\
	StateTrans.hs	\
	NTree.hs	\
	ShowAbstractSyntaxTree.hs	\
	ShowAttrTree.hs	\
	ShowCode.hs	\
	ShowJavaCode.hs	\
	ShowMS.hs	\
	Error.hs	\
	MicroCode.hs	\
	OPCode.hs	\
	ControlUnit.hs	\
	Loader.hs	\
	Main.hs

SRCtest	= TestNTree.hs NTree.hs

SRCall	= $(SRC) $(SRCtest)

OBJ	= $(SRC:.hs=.o)
OBJtest	= $(SRCtest:.hs=.o)
OBJall	= $(SRCall:.hs=.o)

PGMall	:= $(wildcard *.pgm)
GIFall	= $(PGMall:.pgm=.gif)

PPLCOPT	= +RTS -K2000000 -M150000000 -RTS

PPLC	= pplc

##
##all
##	make pplc compiler, test prog for tree output
##	compile ppl-test programs
##	run some of the test programs
##	and generate java code

all	: $(PPLC) testNTree test run java Parser.info1 gifs

Parser.hs Parser.info	: Parser.y
	happy --info -a $<

%.info1	: %.info
	cat $< | cut -b 1-80 > $@

%.o	: %.hs
	ghc -prof -auto-all -K20m -H100m -O -c $<

%.hi	: %.o
	@: # do nothing

$(PPLC)	: $(OBJ)
	ghc -o $@ $(OBJ)

testNTree	: $(OBJtest)
	ghc -o $@ $(OBJtest)

%.scan	: %.ppl $(PPLC)
	$(PPLC) --scan $< > $@

%.parse	: %.ppl $(PPLC)
	$(PPLC) --parse $< > $@

%.check	: %.ppl $(PPLC)
	$(PPLC) --check $< > $@

%.gencode	: %.ppl $(PPLC)
	$(PPLC) --gencode $< > $@

%.ass	: %.ppl $(PPLC)
	$(PPLC) --ass $< > $@

%.java	: %.ppl $(PPLC)
	$(PPLC) --java $< > $@
	cp $@ ppl/$@

%.res	: %.ppl $(PPLC)
	$(PPLC) $(PPLCOPT) --exec $< 2> $*.trc
	cat $*.trc

%.gif	: %.pgm
	ppmtogif $< > $@

TESTPROGS	= example.ppl stmt.ppl expr.ppl branch.ppl t.ppl ggt.ppl wavelet.ppl

TESTSCAN	= $(TESTPROGS:.ppl=.scan)
TESTPARSE	= $(TESTPROGS:.ppl=.parse)
TESTCHECK	= $(TESTPROGS:.ppl=.check)
TESTGENCODE	= $(TESTPROGS:.ppl=.gencode)
TESTASS		= $(TESTPROGS:.ppl=.ass)
TESTJAVA	= $(TESTPROGS:.ppl=.java)
TESTS		= $(TESTSCAN) $(TESTPARSE) $(TESTCHECK) $(TESTGENCODE) $(TESTASS) $(TESTJAVA)

##
##test
##	compile ppl test programs

test	: $(TESTS)

RUNS		= example.res ggt.res

##
##run
##	run ppl test programs

run	: $(RUNS)

##
##java
##	generate java output from test programs

java	: $(TESTJAVA)
	javac ppl/*.java

##
##gifs
##	make gifs from all pgm files
gifs	: $(GIFall)

##
##cleantest
##	remove all test program compile output

cleantest	:
	rm -f $(TESTS)

##
##clean
##	delete all generated files

clean	:
	rm -rf $(OBJall) $(SRCall:.hs=.hi) $(PPLC) testNTree
	$(MAKE) cleantest

##
##tgz
##	create ppl.tgz file

tgz	:
	( cd .. \
	; tar   --exclude=pl0/ppl.tgz \
		--exclude='*.xvpics*' \
		--exclude='*.cvsignore' \
		--exclude='*CVS*' \
		--exclude='*~' \
		--exclude='*.o' \
		--exclude='*.hi' \
		--exclude='*.class' \
		-cvzf - pl0 \
	) > ppl.tgz

# DO NOT DELETE: Beginning of Haskell dependencies
AbstractSyntax.o : AbstractSyntax.hs
Assemble.o : Assemble.hs
Assemble.o : ./Instructions.hi
BuildinFunctions.o : BuildinFunctions.hs
BuildinFunctions.o : ./AbstractSyntax.hi
BuiltinFunctions.o : BuiltinFunctions.hs
BuiltinFunctions.o : ./AbstractSyntax.hi
CodeGeneration.o : CodeGeneration.hs
CodeGeneration.o : ./AbstractSyntax.hi
CodeGeneration.o : ./Instructions.hi
CodeGeneration.o : ./GlobalState.hi
ControlUnit.o : ControlUnit.hs
ControlUnit.o : ./Instructions.hi
ControlUnit.o : ./MachineArchitecture.hi
ControlUnit.o : ./MicroCode.hi
ControlUnit.o : ./OPCode.hi
ControlUnit.o : ./Error.hi
ControlUnit.o : ./ShowMS.hi
Error.o : Error.hs
GlobalState.o : GlobalState.hs
GlobalState.o : ./Instructions.hi
Instructions.o : Instructions.hs
Lexer.o : Lexer.hs
Lexer.o : ./Symbol.hi
Loader.o : Loader.hs
Loader.o : ./Instructions.hi
Loader.o : ./MachineArchitecture.hi
MachineArchitecture.o : MachineArchitecture.hs
MachineArchitecture.o : ./Instructions.hi
MachineArchitecture.o : ./Picture.hi
MachineStructure.o : MachineStructure.hs
MachineStructure.o : ./Instructions.hi
MachineStructure.o : ./Picture.hi
Main.o : Main.hs
Main.o : ./AbstractSyntax.hi
Main.o : ./Lexer.hi
Main.o : ./Parser.hi
Main.o : ./SemanticAnalysis.hi
Main.o : ./Instructions.hi
Main.o : ./CodeGeneration.hi
Main.o : ./Assemble.hi
Main.o : ./ShowAbstractSyntaxTree.hi
Main.o : ./ShowAttrTree.hi
Main.o : ./ShowCode.hi
Main.o : ./ShowJavaCode.hi
Main.o : ./Loader.hi
Main.o : ./ControlUnit.hi
Matrix.o : Matrix.hs
MicroCode.o : MicroCode.hs
MicroCode.o : ./Instructions.hi
MicroCode.o : ./MachineArchitecture.hi
MicroCode.o : ./StateTrans.hi
MicroCode.o : ./Error.hi
MicroCode.o : ./ShowMS.hi
NTree.o : NTree.hs
OPCode.o : OPCode.hs
OPCode.o : ./MachineArchitecture.hi
OPCode.o : ./MicroCode.hi
OPCode.o : ./Picture.hi
OPCode.o : ./Error.hi
OPCode.o : ./Ppm.hi
PPLInterpreter.o : PPLInterpreter.hs
PPLInterpreter.o : ./Instructions.hi
PPLInterpreter.o : ./MachineArchitecture.hi
PPLInterpreter.o : ./ControlUnit.hi
PPLInterpreter.o : ./Loader.hi
PPLInterpreter.o : ./ShowMS.hi
Parser.o : Parser.hs
Parser.o : ./Symbol.hi
Parser.o : ./AbstractSyntax.hi
Parser.o : ./Lexer.hi
Picture.o : Picture.hs
Picture.o : ./Matrix.hi
Ppm.o : Ppm.hs
Ppm.o : ./Picture.hi
SemanticAnalysis.o : SemanticAnalysis.hs
SemanticAnalysis.o : ./AbstractSyntax.hi
SemanticAnalysis.o : ./BuiltinFunctions.hi
ShowAbstractSyntaxTree.o : ShowAbstractSyntaxTree.hs
ShowAbstractSyntaxTree.o : ./AbstractSyntax.hi
ShowAbstractSyntaxTree.o : ./NTree.hi
ShowAttrTree.o : ShowAttrTree.hs
ShowAttrTree.o : ./AbstractSyntax.hi
ShowAttrTree.o : ./ShowAbstractSyntaxTree.hi
ShowAttrTree.o : ./NTree.hi
ShowCode.o : ShowCode.hs
ShowCode.o : ./Instructions.hi
ShowJavaCode.o : ShowJavaCode.hs
ShowJavaCode.o : ./Instructions.hi
ShowMS.o : ShowMS.hs
ShowMS.o : ./Instructions.hi
ShowMS.o : ./MachineArchitecture.hi
ShowMS.o : ./ShowCode.hi
StateTrans.o : StateTrans.hs
Symbol.o : Symbol.hs
TestNTree.o : TestNTree.hs
TestNTree.o : ./NTree.hi
t.o : t.hs
# DO NOT DELETE: End of Haskell dependencies
