# Makefile for PLT

# VARIOUS VARIABLES
LEX = ocamllex
YACC = ocamlyacc

CC = ocamlc


OUTPUTS_TO_CLEAN = compiler *.cmi *.cmo bisect*.out *.cmp test/*.tree test/*.html scanner.ml parser.ml parser.mli parser.output


test: compiler ./test/*.cl test/test.sh
	test/test.sh
	bisect-report -html report bisect*.out

.PHONY : test

all: compiler

compiler: parser.cmo scanner.cmo compiler.cmo semantic.cmo astprinter.cmo generator.cmo header.cmo
	$(CC) -o compiler -I +bisect bisect.cma header.cmo ast.cmo astprinter.cmo parser.cmo scanner.cmo semantic.cmo generator.cmo compiler.cmo

header.cmo: header.ml
	$(CC) -c -I +bisect -pp 'camlp4o str.cma ./bisect_pp.cmo' header.ml

scanner.ml: scanner.mll header.cmo
	$(LEX) scanner.mll

scanner.cmo: scanner.ml parser.cmo ast.cmo
	$(CC) -c -I +bisect -pp 'camlp4o str.cma ./bisect_pp.cmo' scanner.ml

parser.mli parser.ml: parser.mly scanner.ml
	$(YACC) -v parser.mly

ast.cmo: ast.ml
	$(CC) -c -I +bisect -pp 'camlp4o str.cma ./bisect_pp.cmo' ast.ml

parser.cmo: parser.cmi parser.ml
	$(CC) -c -I +bisect -pp 'camlp4o str.cma ./bisect_pp.cmo' parser.ml

parser.cmi: parser.mli ast.cmo
	$(CC) -c parser.mli

semantic.cmo: semantic.ml semantic.cmi
	$(CC) -c -I +bisect -pp 'camlp4o str.cma ./bisect_pp.cmo' semantic.ml

semantic.cmi: semantic.mli ast.cmo
	$(CC) -c semantic.mli

compiler.cmo: compiler.ml astprinter.cmo semantic.cmo ast.cmo generator.cmo
	$(CC) -c -I +bisect -pp 'camlp4o str.cma ./bisect_pp.cmo' compiler.ml

astprinter.cmo: astprinter.cmi astprinter.ml
	$(CC) -c -I +bisect -pp 'camlp4o str.cma ./bisect_pp.cmo' astprinter.ml

astprinter.cmi: astprinter.mli ast.cmo
	$(CC) -c -I +bisect -pp 'camlp4o str.cma ./bisect_pp.cmo' astprinter.mli

generator.cmi: generator.mli ast.cmo
	$(CC) -c generator.mli

generator.cmo: generator.ml generator.cmi
	$(CC) -c -I +bisect -pp 'camlp4o str.cma ./bisect_pp.cmo' generator.ml

	
# 'make clean' removes all output and temporary files
clean:
	mv bisect_pp.cmo bisect_pp.cmo_save
	-rm -f $(OUTPUTS_TO_CLEAN)
	mv bisect_pp.cmo_save bisect_pp.cmo
	-rm -rf report
