CXXFLAGS = -pthread
SRC = ./src/

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

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


.PHONY : all
all : gmm.native $(SRC)builtin.o

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

gmm.native :
	opam config exec -- \
	ocamlbuild -use-ocamlfind $(SRC)gmm.native


test-print.native:
	opam config exec -- \
	ocamlbuild -use-ocamlfind $(SRC)test-print.native

# "make clean" removes all generated files

.PHONY : clean
clean :
	ocamlbuild -clean
	rm -rf testall.log ocamlllvm *.diff
	rm -rf *.err *.ll *.s *.out *.exe $(SRC)*.o *.o
	rm -rf gmm.native

.PHONY : sclean
sclean: 
	rm *.ll *.s *.exe


# compile builtin functions

builtin : $(SRC)builtin.c
	cc -o builtin -DBUILD_TEST -pthread $(SRC)builtin.c

# Build tests

TESTS = \
  add1 arith1 arith2 arith3 array-types array  \
  bool fib float float1 float2 float3 for-pp \
  for1 for2 func1 func2 func3 func4 func5 func6 func7 func8 \
  func9 gcd gcd2 global-array global1 global2 \
  global3 goargs gocall-stress gocall-stress2 gofunc1 gofunc2 \
  gofunc3 hello if1 if2 if3 if4 if5 if6 integer local1 local2 \
  ops1 ops2 ppmm printfib simple-channel simple-string \
  str str2 string-channel struct var1 var2 while1 while2 

GOTEST = \
  bool-channel float-channel global-channel struct-channel


FAILS = \
  array-channel array-init array-typ array1 assign1 assign2 assign3 \
  channel-type dead1 dead2 expr1 expr2 expr3 float1 \
  float2 for1 for2 for3 for4 for5 func1 func2 func3 func4 func5 func6 \
  func7 global1 global2 gofunc if1 if2 if3 nomain ppmm print printb \
  return1 return2 void while1 while2 

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

