# Makefile for MAD examples
MAD = ../mad

.SUFFIXES: .mad

.mad:
	$(MAD) $(MADOPTS) -o $@ $+

# These should compile properly
RUN_TESTS = beer cubic fact hello truthtable \
	newton2 quadratic \
	printcomment testmad dampsine testfmt primes \
	testtape testtape2
COMPILE_TESTS =  gcd wordsearch altpayroll findroot \
	payroll newton1 tschebychev payrolltape
BROKEN = simps

# edc1 was a historical MAD program
# We can't fuly compile it, as it requires lots of runtime support not yet
# available. This production simply uses it as a test for the parser.
EDC_TESTS = edc1 concd typ6 binval

# These rely on array features the compiler has not yet implemented
NONTESTS = matrixmult jordan transfunc

check:
	@make clean
	@make tap | ./tapview
	@make clean

count:
	@echo 1..$(words $(COMPILE_TESTS) $(EDC_TESTS) $(RUN_TESTS))

foo:
	echo $(TESTS)
	echo $(EDCTESTS)

tap: $(RUN_TESTS) count
	@for x in $(EDC_TESTS) $(COMPILE_TESTS); \
	do \
		if $(MAD) -C -S binval.mad; \
		then \
			echo "ok - $${x} compilation"; \
		else \
			echo "not ok - $${x} compilation"; \
		fi \
	done
	@./beer | ./tapdiffer "beer test" beer.chk
	@cat cubic.tst | ./cubic | ./tapdiffer "cubic test" cubic.chk
	@cat fact.tst | ./fact | ./tapdiffer "fact test" fact.chk
	@./hello | ./tapdiffer "hello test" hello.chk
	@./testmad | ./tapdiffer "testmad test" testmad.chk
	@./truthtable | ./tapdiffer "truthtable test" truthtable.chk
	@./printcomment | ./tapdiffer "printcomment test" printcomment.chk
	@./dampsine | ./tapdiffer "dampsine test" dampsine.chk
	@./primes 
	@cat Tape_6.dat | ./tapdiffer "primes test" primes.chk
	@cat testfmt.tst | ./testfmt | ./tapdiffer "testfmt test" testfmt.chk
	@cat quadratic.tst | ./quadratic | ./tapdiffer "quadratic test" quadratic.chk
	@cat newton2.tst | ./newton2 | ./tapdiffer "newton2 test" newton2.chk
	@cat testtape.tst | ./testtape | ./tapdiffer "testtape test" testtape.chk
	@cat testtape2.tst | ./testtape2 | ./tapdiffer "testtape2 test" testtape2.chk

# FIXME: Some of these test programs return an error status.
rebuild:
	./beer >beer.chk
	cat cubic.tst | ./cubic >cubic.chk
	-cat fact.tst | ./fact >fact.chk
	./hello >hello.chk
	./testmad >testmad.chk
	./truthtable >truthtable.chk
	./printcomment >printcomment.chk
	./dampsine >dampsine.chk
	./primes 
	cat Tape_6.dat >primes.chk
	-cat testfmt.tst | ./testfmt >testfmt.chk
	-cat quadratic.tst | ./quadratic >quadratic.chk
	-cat newton2.tst | ./newton2 >newton2.chk
	cat testtape.tst | ./testtape >testtape.chk
	cat testtape2.tst | ./testtape2 >testtape2.chk

fact: factfunc.mad factmain.mad
	$(MAD) $(MADOPTS) -o fact factfunc.mad factmain.mad

gcd: gcdfunc.mad gcdtest.mad
	$(MAD) $(MADOPTS) -o gcd gcdfunc.mad gcdtest.mad

simps: simpsfunc.mad simpsmain.mad
	$(MAD) $(MADOPTS) -o simps simpsfunc.mad simpsmain.mad

tschebychev: tschebfunc.mad tschebmain.mad
	$(MAD) $(MADOPTS) -o tschebychev tschebfunc.mad tschebmain.mad

clean:
	rm -f $(RUN_TESTS) $(COMPILE_TESTS) $(BROKEN) *~ *.c *.o parsetab.py parser.out
	rm -f support/*.o Tape_*.dat
 
