TARFILES = Makefile scanner.mll parser.mly ast.ml darn.ml semant.
# Make sure ocamlbuild can find opam-managed packages: first run
#
# eval `opam config env`

# Easiest way to build: using ocamlbuild, which in turn uses ocamlfind

.PHONY : darn.native

darn.native : 
	ocamlbuild -use-ocamlfind -pkgs llvm,llvm.analysis,str -cflags -w,+a-4 \
		darn.native

# "make clean" removes all generated files

.PHONY : clean
clean :
	ocamlbuild -clean
	rm -rf testall.log *.diff darn test_darn scanner.ml parser.ml parser.mli
	rm -rf *.cmx *.cmi *.cmo *.cmx *.o

# More detailed: build using ocamlc/ocamlopt + ocamlfind to locate LLVM
TESTOBJS = parser.cmo scanner.cmo

.PHONY : test
test : darn.native test_parser_scanner

.PHONY : test_parser_scanner

test_parser_scanner : $(TESTOBJS)


OBJS = ast.cmx codegen.cmx parser.cmx scanner.cmx darn.cmx semant.cmx 

darn : $(OBJS)
	ocamlfind ocamlopt -linkpkg -package llvm -package llvm.analysis $(OBJS) -o darn

scanner.ml : scanner.mll
	ocamllex scanner.mll

parser.ml parser.mli : parser.mly
	ocamlyacc parser.mly

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

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

%.cmx : %.ml
	ocamlfind ocamlopt -c -package llvm $<

#.PHONY : clean
#clean :
#	rm -f darn parser.ml parser.mli scanner.ml *.cmo *.cmi

# Generated by ocamldep *.ml *.mli
calc.cmo: scanner.cmo parser.cmi ast.cmo
calc.cmx: scanner.cmx parser.cmx ast.cmx 
parser.cmo: ast.cmo parser.cmi 
parser.cmx: ast.cmx parser.cmi 
scanner.cmo: parser.cmi 
scanner.cmx: parser.cmx 
semant.cmo: ast.cmo
semant.cmx: ast.cmx
parser.cmi: ast.cmo 
