]> git.sur5r.net Git - cc65/blob - test/ref/Makefile
Cleaned up test Makefiles.
[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 CC65FLAGS = -t sim6502
23 SIM65FLAGS = -x 200000000
24
25 CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65)
26 SIM65 := $(if $(wildcard ../../bin/sim65*),..$S..$Sbin$Ssim65,sim65)
27
28 WORKDIR = ..$S..$Stestwrk$Sref
29
30 OPTIONS = g O Os Osi Osir Oi Oir Or
31
32 DIFF = $(WORKDIR)$Sbdiff$(EXE)
33
34 CC = gcc
35 CFLAGS = -O2 -Wall -W -Wextra -funsigned-char -fwrapv -fno-strict-overflow
36
37 .PHONY: all clean
38
39 SOURCES := $(wildcard *.c)
40 REFS = $(SOURCES:%.c=$(WORKDIR)/%.ref)
41 TESTS = $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).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.prg: %.c $(WORKDIR)/%.ref $(DIFF)
74         $(CL65) $$(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))))
81
82 clean:
83         @$(call RMDIR,$(WORKDIR))
84         @$(call DEL,$(SOURCES:.c=.o))