# "make test" Compiles everything and runs the regression tests

.PHONY : test
test : all testall.sh
	./testall.sh

# "make all" builds the executable as well as the "printbig" library designed
# to test linking external code

.PHONY : all
all : CGC.native printbig.o

# "make microc.native" compiles the compiler
#
# The _tags file controls the operation of ocamlbuild, e.g., by including
# packages, enabling warnings
#
# See https://github.com/ocaml/ocamlbuild/blob/master/manual/manual.adoc

CGC.native :
	opam config exec -- \
	ocamlbuild -use-ocamlfind CGC.native

# "make clean" removes all generated files

.PHONY : clean
clean :
	ocamlbuild -clean
	rm -rf testall.log ocamlllvm *.diff

# Testing the "printbig" example

printbig : printbig.c
	cc -o printbig -DBUILD_TEST printbig.c

# Building the tarball

TESTS = \
demo-array test-class1 test-class2 test-recur\
add1 arith1 arith2 arith3 fib float1 float2 float3 for1 for2 func1 \
func2 func3 func4 func5 func6 func7 func8 func9 gcd2 gcd global1 \
lobal2 global3 hello if1 if2 if3 if4 if5 if6 local1 local2 ops1 \
var1 var2 while1 while2 arith_mulAndDiv float_arith_cmp1 float_arith_cmp2 float_arith_cmp3\
float_arith_cmp4 float_arith_cmp5 float_arith_cmp6 float_arith1  float_arith2 float_arith3\
float_arith4 float_arith5  array1 array2 array3 array4 array5  assign_float1 assign_float2\
expr1 class_func class_funcWithThis \
class_inClassFor class_inClassIf class_inClassWhile\
class_nestedAccess class_nestedObj class_noParamConstructor class_objArrayField class_objAsParam\
class_printObjAccess class_recursi\
  


FAILS = \


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

TARFILES = ast.ml sast.ml codegen.ml Makefile _tags microc.ml microcparse.mly \
	README scanner.mll semant.ml testall.sh \
	printbig.c arcade-font.pbm font2c \
	Dockerfile \
	$(TESTFILES:%=tests/%) 

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