# Make sure ocamlbuild can find opam-managed packages: first run
#

.PHONY: rusty.native

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

# "make clean" removes all generated files

.PHONY : clean
clean :
	ocamlbuild -clean
	rm -rf testall.log *.diff rusty scanner.ml parser.ml parser.mli
	rm -rf *.cmx *.cmi *.cmo *.cmx *.o *.ll *.err *.diff *.out

# More detailed: build using ocamlc/ocamlopt + ocamlfind to locate LLVM

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

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

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 $<

### Generated by "ocamldep *.ml *.mli" after building scanner.ml and parser.ml


codegen.cmo : ast.cmo 
codegen.cmx : ast.cmx 
rusty.cmo : semant.cmo scanner.cmo parser.cmi codegen.cmo ast.cmo 
rusty.cmx : semant.cmx scanner.cmx parser.cmx codegen.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 

# Building the tarball

TESTS = 

FAILS = 

TESTFILES = $(TESTS:%=test_%.rusty) $(TESTS:%=test_%.out) \
		$(FAILS:%=fail_%.rusty) $(FAILS:%=fail_%.err)

TARFILES = ast.ml  codegen.ml Makefile rusty.ml parser.mly README scanner.mll \
	semant.ml testall.sh $(TESTFILES:%=tests/%)

rusty-llvm.tar.gz : $(TARFILES)
	cd .. && tar czf rusty-llvm/rusty-llvm.tar.gz \
		$(TARFILES:%=rusty-llvm/%)
