# 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 : scolkam.native

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

# "make clean" removes all generated files

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

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

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

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

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
ast.cmo :
ast.cmx :
codegen.cmo : ast.cmo
codegen.cmx : ast.cmx
scolkam.cmo : semant.cmo scanner.cmo parser.cmi codegen.cmo ast.cmo
scolkam.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 = add arith arith_2 arith_3 arith_4 arith_5 augment augment2 augment3 augment4 avl_tree bst calc fibonacci float_add float_div	\
    float_multi float_sub for funct funct1 funct2 global hello_world if linked_list	\
    misc_test modulus print print-string tuple_access tuple_slice unary	\

FAILS = x_funct x_funct print \

TESTFILES = $(TESTS:%=test-%.sco) $(TESTS:%=test-%.out) \
        $(FAILS:%=fail-%.sco) $(FAILS:%=fail-%.err)

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

