1# Makefile for the regression tests that return an error code on failure
2
3ifneq ($(shell echo),)
4  CMD_EXE = 1
5endif
6
7ifdef CMD_EXE
8  S = $(subst /,\,/)
9  NULLDEV = nul:
10  MKDIR = mkdir $(subst /,\,$1)
11  RMDIR = -rmdir /s /q $(subst /,\,$1)
12  DEL = del /f $(subst /,\,$1)
13else
14  S = /
15  NULLDEV = /dev/null
16  MKDIR = mkdir -p $1
17  RMDIR = $(RM) -r $1
18  DEL = $(RM) $1
19endif
20
21ifdef QUIET
22  .SILENT:
23  NULLOUT = >$(NULLDEV)
24  NULLERR = 2>$(NULLDEV)
25endif
26
27SIM65FLAGS = -x 200000000
28
29CL65 := $(if $(wildcard ../../bin/cl65*),..$S..$Sbin$Scl65,cl65)
30SIM65 := $(if $(wildcard ../../bin/sim65*),..$S..$Sbin$Ssim65,sim65)
31
32WORKDIR = ../../testwrk/val
33
34OPTIONS = g O Os Osi Osir Osr Oi Oir Or
35
36.PHONY: all clean
37
38SOURCES := $(wildcard *.c)
39TESTS  = $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).6502.prg))
40TESTS += $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).65c02.prg))
41
42all: $(TESTS)
43
44$(WORKDIR):
45	$(call MKDIR,$(WORKDIR))
46
47define PRG_template
48
49$(WORKDIR)/%.$1.$2.prg: %.c | $(WORKDIR)
50	$(if $(QUIET),echo val/$$*.$1.$2.prg)
51	$(CL65) -t sim$2 $$(CC65FLAGS) -$1 -o $$@ $$< $(NULLERR)
52	$(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT)
53
54endef # PRG_template
55
56$(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),6502)))
57$(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),65c02)))
58
59clean:
60	@$(call RMDIR,$(WORKDIR))
61	@$(call DEL,$(SOURCES:.c=.o))
62