# Brain-dead makefile to compile and run all the benchmarks.

# Configuration:
#   USETALC - if defined use the TALC assembler otherwise use MASM

ifdef USETALC
POPFLAGS = --TALC
else
POPFLAGS = --MS
endif

out=test.out
ref=sample.out

POPCORN = popcorn

exes = ast.exe check_array.exe check_big_fact.exe check_exn.exe \
       check_exn2.exe check_globals.exe check_loops.exe check_spill.exe \
       combine.exe fact.exe fib.exe hanoi.exe int_msort.exe int_queue.exe \
       msort.exe

compile: $(exes) 

check_globals.exe: check_globals.pop check_globals2.pop
	$(POPCORN) $(POPFLAGS) -o check_globals.exe \
		check_globals.pop check_globals2.pop

int_msort.exe: int_list.pop int_msort.pop
	$(POPCORN) $(POPFLAGS) -o int_msort.exe int_list.pop int_msort.pop

msort.exe: list.pop msort.pop
	$(POPCORN) --TALC -o msort.exe list.pop msort.pop

combine.exe: list.pop combine.pop
	$(POPCORN) --TALC -o combine.exe list.pop combine.pop

run:
	rm -f $(out)
	./ast.exe >> $(out)
	./check_array.exe >> $(out)
	./check_big_fact.exe >> $(out)
	./check_exn.exe >> $(out)
	./check_exn2.exe >> $(out)
	./check_globals.exe >> $(out)
	./check_loops.exe >> $(out)
	./check_spill.exe >> $(out)
	./combine.exe >> $(out)
	./fact.exe 10 >> $(out)
	./fib.exe 10 >> $(out)
	./hanoi.exe >> $(out)
	./int_msort.exe 5 >> $(out)
	./int_queue.exe  >> $(out)
	./msort.exe 5 >> $(out)

check:
	diff $(out) $(ref)

all: clean compile run check

exe_only:
	rm -f *~ *.o *.obj *.tal* *.lst

clean: exe_only
	rm -f *.exe $(out)

%.exe: %.pop
	$(POPCORN) $(POPFLAGS) -o $@ $<
