OBJS = ast.cmo Sast.cmo parser.cmo scanner.cmo translate.cmo analyzer.cmo typeConverter.cmo compile.cmo

TESTS = \
arith1 \
arith2 \
fib \
for1 \
func1 \
func2 \
func3 \
gcd \
gcd2 \
global1 \
hello \
if1 \
if2 \
if3 \
if4 \
ops1 \
var1 \
while1

# Choose one
YACC = ocamlyacc -v
# YACC = menhir --explain

TARFILES = Makefile testall.sh scanner.mll parser.mly \
	ast.ml Sast.ml bytecode.ml interpret.ml compile.ml execute.ml microc.ml \
	$(TESTS:%=tests/test-%.mc) \
	$(TESTS:%=tests/test-%.out)


build: analyzer clib

.PHONY: setup
setup:
	cd clib ; make clean
	cd clib ; make library

clib:
	make -f clib/Makefile

analyzer : str $(OBJS)
	ocamlc -o dotc str.cma $(OBJS)

ast_print : str $(OBJS)
	ocamlc -o dotc str.cma $(OBJS) astPrinter.ml

str : 
	ocamlopt str.cmxa

microc : $(OBJS)
	ocamlc -o microc $(OBJS)

.PHONY : test
test : microc testall.sh
	./testall.sh

scanner.ml : scanner.mll
	ocamllex scanner.mll

parser.ml parser.mli : parser.mly
	$(YACC) parser.mly

%.cmo : %.ml
	ocamlc -c $<

%.cmi : %.mli
	ocamlc -c $<

microc.tar.gz : $(TARFILES)
	cd .. && tar czf microc/microc.tar.gz $(TARFILES:%=microc/%)

.PHONY : clean
clean :
	rm -f dotc microc parser.output parser.automaton parser.ml parser.mli scanner.ml testall.log \
	*.cmo *.cmi *.out *.diff exec compile.c

# Generated by ocamldep *.ml *.mli

analyzer.cmo: sast.cmo ast.cmo
analyzer.cmx: sast.cmx ast.cmx
generator.cmo: sast.cmo
generator.cmx: sast.cmx
parser.cmo: ast.cmo parser.cmi 
parser.cmx: ast.cm parser.cmi 
dot.cmo: scanner.cmo sast.cmo parser.cmi ast.cmo analyzer.cmo
dot.cmx: scanner.cmx sast.cmo parser.cmx ast.cmx analyzer.cmx
sast.cmo: ast.cmo
sast.cmx: ast.cmx
scanner.cmo: parser.cmi 
scanner.cmx: parser.cmx 
parser.cmi: ast.cmo
str.cma: str.cmxa