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

# Configuration:
#   NOTALC - if defined use MASM else the TALC assembler 

LIBFILES = core

ifdef NOTALC
ASSEMBLER=--MS
else
ASSEMBLER=--TALC
endif

ifdef WINDIR
O=obj
A=lib
else
O=o
A=a
endif


POPFLAGS = $(ASSEMBLER) $(addprefix $(POPLIB), $(addsuffix .$(O), $(LIBFILES)))

out=test.out
ref=sample.out

POPCORN = popcorn.exe

exes = ast.exe check_array.exe check_array2.exe check_big_fact.exe check_exn.exe\
       check_exn2.exe check_globals.exe check_loops.exe check_spill.exe \
       check_inst.exe check_def_init.exe check_for.exe check_open.exe \
       check_arith.exe \
       combine.exe fact.exe fib.exe hanoi.exe int_msort.exe int_queue.exe \
       msort.exe printf.exe rsa.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) $(POPFLAGS) -o msort.exe list.pop msort.pop

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

run:
	rm -f $(out)
	./ast.exe >> $(out)
	./check_array.exe >> $(out)
	./check_array2.exe >> $(out)
	./check_big_fact.exe >> $(out)
	./check_exn.exe >> $(out) 2>&1 || true
	./check_exn2.exe >> $(out)
	./check_globals.exe >> $(out)
	./check_loops.exe >> $(out)
	./check_spill.exe >> $(out)
	./check_inst.exe >> $(out)
	./check_def_init.exe >> $(out)
	./check_for.exe >> $(out)
	./check_open.exe >> $(out)
	./check_arith.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)
	./printf.exe >> $(out)
	./rsa.exe >> $(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 $@ $<
