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

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

.PHONY : draw
draw : all scripts/draw.sh testdrawchessboard.o
	./scripts/draw.sh

.PHONY : setupdraw
setupdraw : all scripts/setupdraw.sh 
	./scripts/setupdraw.sh

.PHONY : color
color : all scripts/color.sh 
	./scripts/color.sh

.PHONY : drawline
drawline : all scripts/drawline.sh 
	./scripts/drawline.sh

.PHONY : gfxcircle
gfxcircle : all scripts/gfxcircle.sh 
	./scripts/gfxcircle.sh

.PHONY : movingball
movingball : all scripts/movingball.sh 
	./scripts/movingball.sh

.PHONY : movingball-background
movingball-background : all scripts/movingball-background.sh 
	./scripts/movingball-background.sh

.PHONY : movingball-color
movingball-color : all scripts/movingball-color.sh 
	./scripts/movingball-color.sh

.PHONY : movingball-opacity
movingball-opacity : all scripts/movingball-opacity.sh 
	./scripts/movingball-opacity.sh

.PHONY : mouse
mouse : all scripts/mouse.sh 
	./scripts/mouse.sh

.PHONY : compArtLogo
compArtLogo : all scripts/compArtLogo.sh 
	./scripts/compArtLogo.sh

.PHONY : multipleMovingBalls
multipleMovingBalls : all scripts/multipleMovingBalls.sh 
	./scripts/multipleMovingBalls.sh

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

.PHONY : all
all : compArt.native printbig.o compArtHelper.o

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

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

# "make clean" removes all generated files

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

# Testing the "printbig" example

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



# Building the tarball

TESTS = \
  add1 arith1 arith2 arith3 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 array1 array2 array3 array4 hello

FAILS = \
  assign1 assign2 assign3 dead1 dead2 expr1 expr2 expr3 float1 float2 \
  for1 for2 for3 for4 for5 func1 func2 func3 func4 func5 func6 func7 \
  func8 func9 global1 global2 if1 if2 if3 nomain printbig printb print \
  return1 return2 while1 while2

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

TARFILES = ast.ml sast.ml codegen.ml Makefile _tags compArt.ml compArtParse.mly \
	README scanner.mll semant.ml testall.sh \
	printbig.c arcade-font.pbm font2c \
	Dockerfile \
	compArtHelper.c run.sh arraystruct.c SDL2_gfxPrimitives.h \
	tests/test-color.ca tests/test-compArtLogo.ca tests/test-drawfunc.ca \
	tests/test-drawline.ca tests/test-gfxcircle.ca tests/test-mouse.ca \
	tests/test-movingball-background.ca tests/test-movingball-color.ca \
	tests/test-movingball-opacity.ca tests/test-movingball.ca \
	tests/test-multipleMovingBalls.ca \
	scripts/color.sh scripts/gfxcircle.sh scripts/movingball-opacity.sh \
	scripts/compArtLogo.sh scripts/mouse.sh scripts/movingball.sh \
	scripts/draw.sh scripts/movingball-background.sh scripts/multipleMovingBalls.sh \
	scripts/drawline.sh scripts/movingball-color.sh scripts/setupdraw.sh \
	$(TESTFILES:%=tests/%) 

compArt.tar.gz : $(TARFILES)
	cd .. && tar czf CompArt2.0/compArt.tar.gz \
		$(TARFILES:%=CompArt2.0/%)
