# Makefile
# Author: Matthew Chan
$CC = gcc

.PHONY : all
all : clean flio.native

.PHONY : flio.native
flio.native :
	ocamlbuild -use-ocamlfind -pkgs llvm,llvm.analysis -cflags -w,+a-4 \
		flio.native
	$(CC) -c stdlib.c

.PHONY: clean
clean:
	ocamlbuild -clean
	rm -rf scanner.ml parser.ml parser.mlii flio
	rm -rf *.cmx *.cmi *.cmo *.cmx *.o
	rm -rf testall.log *.diff *.err *.ll
	rm -rf *.exe *s *.out flio.tar.gz

TESTS = binop concat copyfile createfile decl2 fcall fcall2 fdecl fdecl2 \
	for hello hello2 if logic movefile number readfile rmdir string void

FAILS = assign fdecl fdecl2 fdecl3 for hello if return scope types

TESTFILES = $(TESTS:%=test-%.f) $(FAILS:%=fail-%.f)

SOURCEFILES = Makefile scanner.mll parser.mly ast.ml sast.ml semant.ml \
	      testall.sh codegen.ml flio.ml stdlib.c

DEMOFILES = rundemo.sh sample.txt demo.f

TARFILES = ../README.md $(SOURCEFILES) $(TESTFILES:%=../test/%) $(DEMOFILES:%=../demo/%) 

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

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

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

flio.tar.gz : $(TARFILES)
	cd .. && tar zcf src/flio.tar.gz $(TARFILES:%=src/%)

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

# Generated by ocamldep *.ml *.mli
ast.cmo:
ast.cmx:
codegen.cmo: ast.cmo
codegen.cmx: ast.cmx
flio.cmo : semant.cmo scanner.cmo parser.cmi codegen.cmo ast.cmo
flio.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 
