# 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

all : setc.native strcmp.o stdlib.o

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

# "make clean" removes all generated files

.PHONY : clean
clean :
	ocamlbuild -clean
	rm -rf testall.log *.diff setc scanner.ml parser.ml parser.mli
	rm -rf strcmp
	rm -rf stdlib
	rm -rf *.cmx *.cmi *.cmo *.cmx *.o *.s *.ll *.out *.exe

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

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

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

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

strcmp : strcmp.c
	cc -o strcmp -DBUILD_TEST strcmp.c
# Testing the "printbig" example
stdlib : stdlib.c
	cc -o stdlib -DBUILD_TEST stdlib.c




### Generated by "ocamldep *.ml *.mli" after building scanner.ml and parser.ml
ast.cmo :
ast.cmx :
codegen.cmo : ast.cmo
codegen.cmx : ast.cmx
setc.cmo : semant.cmo scanner.cmo parser.cmi codegen.cmo ast.cmo
setc.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-%.sc) $(TESTS:%=test-%.out) \
	    $(FAILS:%=fail-%.sc) $(FAILS:%=fail-%.err)

TARFILES = ast.ml codegen.ml Makefile setc.ml parser.mly README scanner.mll \
	semant.ml testall.sh $(TESTFILES:%=tests/%) strcmp.c stdlib.c arcade-font.pbm \
	font2c

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