# "make casper.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
casper.native :
	opam config exec -- \
	ocamlbuild -use-ocamlfind casper.native

# Compile the standard library
stdlib : stdlib.c
	cc -o stdlib -DBUILD_TEST stdlib.c

.PHONY : help
help:
	./makesupport/help.sh

# "make testS" loads a version of the scanner that prints out the tokens instead of
# feeding to parser and then scans a program
.PHONY : testS
testS:
	./makesupport/testscanner.sh

# "make testP" uses menhir to evaluate some token strings with the parser
.PHONY: testP
testP:
	./makesupport/testparser.sh

# "make test" Compiles everything and runs the regression tests
.PHONY : test
test : all
	./makesupport/testall.sh

# "make all" builds the executable and standard library
.PHONY : all
all : casper.native stdlib.o

# "make clean" removes all generated files
.PHONY : clean
clean :
	ocamlbuild -clean
	./makesupport/clean.sh

# "make cleang" leaves compiler removes other generated files
.PHONY : cleang
cleang :
	./makesupport/clean.sh

# Building the tarball
TESTS = \
  add1 addassign arith1 arith2 arith3 assign break1 break2 conassign1 conassign2 \
  cont1 dec dountil1 dountil2 dountil3 dowhile1 dowhile2 dowhile3 dup fib float1 \
  float2 float3 for1 for2 for3 func1 func2 func3 func4 func5 func6 func7 func8 func9 \
  gcd2 gcd global1 global2 global3 global5 global6 hello helloworld if1 if2 if3 \
  if4 if5 if6 if7 inc1 inc2 int1 int2 int3 itof local1 local2 local3 negation \
  not ops1 ops2 pow printb1 printb printbig print stdlib str1 str3 str4 str5 \
  subassign var1 var2 while1 while2 while3 while4

FAILS = \
  addassign1 addassign1 addassign2 addassign3 addassign4 addassign5 addassign6 assign10 \
  assign11 assign12 assign13 assign14 assign1 assign2 assign3 assign4 assign5 assign6 assign7 \
  assign8 assign9 break1 continue1 dead1 dead2 dead3 dec1 dec2 dec3 dec4 dec5 dec6 dup1 dup2 \
  dup3 dup4 expr1 expr2 expr3 float1 float2 float3 fmod for1 for2 for3 for4 for5 func10 \
  func1 func2 func3 func4 func5 func6 func7 func8 func9 global1 global2 if1 if2 if3 \
  inc1 inc2 inc3 inc4 inc5 inc6 local1 negation1 negation2 negation3 negation4 nomain \
  not1 not2 not3 not4 not5 not6 printb printc printbig printf printi prints printsnl rand \
  return1 return2 str1 str3 str4 str7 subassign1 subassign2 subassign3 subassign4 \
  subassign5 subassign6 while1 while2

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

CLANG = clangviz.sh xxx.c binarysearch.c
DOCS = Proposal.pdf LRM.pdf Log.xlsx CasperFinalReport.pdf
EXAMPLES = bsearch.goo fib.goo sieve.goo temperaturetable.goo
MAKESUPPORT = clean.sh help.sh testall.sh testparser.sh testscanner.sh
TESTFRONT = menhirTestInput.txt CasperScannerValidationWithLinenumbers.mll \
            CasperScannerValidationInput.txt CasperScannerValidation.mll

TARFILES = casper.ml scanner.mll parser.mly ast.ml sast.ml semant.ml codegen.ml \
	Makefile _tags casper.sh casperc.sh casperll.sh stdlib.c README README.md \
	$(CLANG:%=clang/%) \
	$(DOCS:%=docs/%) \
	$(EXAMPLES:%=examples/%) \
	$(MAKESUPPORT:%=makesupport/%) \
	$(TESTFILES:%=tests/%) \
	$(TESTFRONT:%=X/%)
    
casper.tar.gz : $(TARFILES)
	cd .. && tar czf Casper/casper.tar.gz \
		$(TARFILES:%=Casper/%)
