# 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 : musicmike.native synth.o make_midi.o

musicmike.native :
	ocamlbuild -ocamlyacc "ocamlyacc -v" -use-ocamlfind -pkgs llvm,llvm.analysis -cflags -w,+a-4 \
		musicmike.native

# "make clean" removes all generated files

.PHONY : clean
clean :
	ocamlbuild -no-log -clean
	rm -rf testall.log *.diff musicmike scanner.ml parser.ml parser.mli
	rm -rf synth make_midi
	rm -rf *.cmx *.cmi *.cmo *.cmx *.o *.s *.ll *.out *.exe *.output

parser:
	ocamlyacc -v parser.mly

scanner:
	ocamllex scanner.mll

frontend:
	ocamllex scanner.mll
	ocamlc -c ast.ml
	ocamlyacc -v parser.mly
	ocamlc -c parser.mli
	ocamlc -c lib.ml


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

OBJS = ast.cmx codegen.cmx infer.cmx lib.cmx parser.cmx scanner.cmx semant.cmx musicmike.cmx

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

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

# Synth from microC
synth : synth.c
			cc -o synth -DBUILD_TEST synth.c
make_midi : make_midi.c
			cc -o make_midi -DBUILD_TEST make_midi.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
musicmike.cmo : semant.cmo scanner.cmo parser.cmi codegen.cmo ast.cmo infer.cmo
musicmike.cmx : semant.cmx scanner.cmx parser.cmx codegen.cmx ast.cmx infer.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
infer.cmo : ast.cmo lib.cmo
infer.cmx : ast.cmx lib.cmx
lib.cmo: ast.cmo
lib.cmx: ast.cmx
parser.cmi : ast.cmo

