]> git.sur5r.net Git - cc65/blob - test/ref/Makefile
Run test for the 65C02 code generator / runtime too.
[cc65] / test / ref / Makefile
1 # Makefile for the regression tests that generate output which has to be
2 # compared with reference output
3
4 ifneq ($(shell echo),)
5   CMD_EXE = 1
6 endif
7
8 ifdef CMD_EXE
9   S = $(subst /,\,/)
10   EXE = .exe
11   MKDIR = mkdir $(subst /,\,$1)
12   RMDIR = -rmdir /s /q $(subst /,\,$1)
13   DEL = del /f $(subst /,\,$1)
14 else
15   S = /
16   EXE =
17   MKDIR = mkdir -p $1
18   RMDIR = $(RM) -r $1
19   DEL = $(RM) $1
20 endif
21
22 SIM65FLAGS = -x 200000000
23
24 CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65)
25 SIM65 := $(if $(wildcard ../../bin/sim65*),..$S..$Sbin$Ssim65,sim65)
26
27 WORKDIR = ..$S..$Stestwrk$Sref
28
29 OPTIONS = g O Os Osi Osir Oi Oir Or
30
31 DIFF = $(WORKDIR)$Sbdiff$(EXE)
32
33 CC = gcc
34 CFLAGS = -O2 -Wall -W -Wextra -funsigned-char -fwrapv -fno-strict-overflow
35
36 .PHONY: all clean
37
38 SOURCES := $(wildcard *.c)
39 REFS = $(SOURCES:%.c=$(WORKDIR)/%.ref)
40 TESTS  = $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).6502.prg))
41 TESTS += $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).65c02.prg))
42
43 all: $(REFS) $(TESTS)
44
45 $(WORKDIR):
46         $(call MKDIR,$(WORKDIR))
47
48 $(WORKDIR)/%.ref: %.c | $(WORKDIR)
49         $(CC) $(CFLAGS) -o $(WORKDIR)/$*.host $<
50         $(WORKDIR)$S$*.host > $@
51
52 $(DIFF): ../bdiff.c | $(WORKDIR)
53         $(CC) $(CFLAGS) -o $@ $<
54
55 # Some files have "K & R"-style syntax.  Therefore, some forward
56 # function-declarations don't match the later function definitions.
57 # Those programs fail when fastcall is used; but, the cdecl calling convention
58 # tolerates those conflicts.  Therefore, make their functions default to cdecl.
59 #
60 $(WORKDIR)/init.%.prg   \
61 $(WORKDIR)/switch.%.prg \
62 $(WORKDIR)/yacc.%.prg   \
63 $(WORKDIR)/yaccdbg.%.prg: CC65FLAGS += -Wc --all-cdecl
64
65 # "yaccdbg.c" includes "yacc.c".
66 # yaccdbg's built files must depend on both of them.
67 #
68 $(WORKDIR)/yaccdbg.ref:   yacc.c
69 $(WORKDIR)/yaccdbg.%.prg: yacc.c
70
71 define PRG_template
72
73 $(WORKDIR)/%.$1.$2.prg: %.c $(WORKDIR)/%.ref $(DIFF)
74         $(CL65) -t sim$2 $$(CC65FLAGS) -$1 -o $$@ $$<
75         $(SIM65) $(SIM65FLAGS) $$@ > $(WORKDIR)/$$*.out
76         $(DIFF) $(WORKDIR)/$$*.out $(WORKDIR)/$$*.ref
77
78 endef # PRG_template
79
80 $(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),6502)))
81 $(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),65c02)))
82
83 clean:
84         @$(call RMDIR,$(WORKDIR))
85         @$(call DEL,$(SOURCES:.c=.o))