OCAMLLEX=/usr/bin/ocamllex
OCAMLYACC=/usr/bin/ocamlyacc
OCAMLC=/usr/bin/ocamlc

TEST_DRIVER=./run_tests.sh
TEST_LOG=./tests.log
TEST_FILES=$(wildcard tests/*.pls) $(wildcard tests/*.out) $(wildcard tests/*.in)

MAIN=pls

OBJS=scanner.cmo\
     stdin_scanner.cmo\
     parser.cmo\
     ast.cmo\
     bytecode.cmo\
     compiler.cmo\
     vm.cmo\
     pls.cmo

all : pls tests

.PHONY : tests
tests: $(TEST_DRIVER) $(TEST_FILES) pls
	$(TEST_DRIVER)

pls : scanner.ml parser.ml parser.mli $(OBJS)
	$(OCAMLC) -o $(MAIN) $(OBJS)

scanner.ml : scanner.mll parser.ml parser.mli
	$(OCAMLLEX) scanner.mll

stdin_scanner.ml : scanner.mll bytecode.ml
	$(OCAMLLEX) stdin_scanner.mll

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

%.cmo : %.ml
	$(OCAMLC) -c $<

%.cmi : %.mli
	$(OCAMLC) -c $<

.PHONY : clean
clean :
	rm -f $(MAIN) *.cmi *.cmo
	rm -f parser.mli parser.ml scanner.ml stdin_scanner.ml parser.output
	rm -f testlog.log

ast.cmo :
ast.cmx :
bytecode.cmo : ast.cmo
bytecode.cmx : ast.cmx
compiler.cmo : bytecode.cmo ast.cmo
compiler.cmx : bytecode.cmx ast.cmx
parser.cmo : ast.cmo parser.cmi
parser.cmx : ast.cmx parser.cmi
pls.cmo : vm.cmo scanner.cmo parser.cmi compiler.cmo bytecode.cmo ast.cmo
pls.cmx : vm.cmx scanner.cmx parser.cmx compiler.cmx bytecode.cmx ast.cmx
scanner.cmo : parser.cmi
scanner.cmx : parser.cmx
stdin_scanner.cmo : bytecode.cmo
stdin_scanner.cmx : bytecode.cmx
vm.cmo : stdin_scanner.cmo bytecode.cmo
vm.cmx : stdin_scanner.cmx bytecode.cmx
parser.cmi : ast.cmo
