# "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 : printbig.o list.o treebasics.o treeset.o treedict.o stringLibrary.o FFBB.native

# "make FFBB.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

FFBB.native :
	opam config exec -- \
	ocamlbuild -use-ocamlfind -no-hygiene FFBB.native

# "make clean" removes all generated files

.PHONY : clean
clean :
	ocamlbuild -clean
	rm -rf tests/*.ll tests/*.s
	rm -rf testall.log ocamlllvm *.diff
	rm -rf *.o *.exe *.ll *.s *.gz

# Testing the "printbig" example

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

# Testing the "printbig" example

list : list.c
	cc -o list -DBUILD_TEST list.c

treebasics.o : treebasics.c
	cc -c treebasics.c

treeset.o : treeset.c
	cc -c treeset.c

treedict.o : treedict.c
	cc -c treedict.c
# Building the tarball

stringLibrary : stringLibrary.c
	cc -o stringLibrary stringLibrary.c

TESTS = \
  add1 arith1 arith2 arith3 arith4 fib float1 float2 float3 for1 for2 func1 \
  func2 func3 func4 func5 func6 func7 func8 func9 gcd2 gcd global1 \
  global2 global3 hello if1 if2 if3 if4 if5 if6 local1 local2 ops1 \
  ops2 printbig var1 var2 while1 while2 demo1 demo2 demo3 demo4 demo5 \
  dict-list1 dict-list2 dict-list3 dict1 dict2 dict3 dict4 dict5 dict6 dict7 dict8 \
  forin1 hello-world list1 list2 list3 list4 ops3 ops4 \
  set1 set2 set3 set4 set5 string-concat string-len string-slice string1 string2 var3 lambda

FAILS = \
  assign1 assign2 assign3 dead1 dead2 dict1 dict2 dict3 expr1 expr2 expr3 expr4 expr5 \
  float1 float2 for1 for2 for3 for4 for5 func1 func2 func3 func4 func5 func6 func7 \
  func8 func9 global1 global2 if1 if2 if3 list1 list2 list3 ops1 ops2 ops3 nomain printbig printb print \
  return1 return2 while1 while2 set1 set2 

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

TARFILES = ast.ml sast.ml codegen.ml Makefile _tags FFBB.ml FFBBparser.mly \
	scanner.mll semant.ml testall.sh treeset.c stringLibrary.c \
	printbig.c arcade-font.pbm font2c list.c list.h \
	Dockerfile log.txt mytest.sh treebasics.c treebasics.h \
	treedict.c FFBB.README microc.README llvm.sh parsertest.txt parsetexthistory.txt \
	$(TESTFILES:%=tests/%) 

FFBB.tar.gz : $(TARFILES)
	tar czf FFBB.tar.gz \
		$(TARFILES:%=%)
