From: Oliver Schmidt 
Date: Sun, 19 Mar 2017 16:48:12 +0000 (+0100)
Subject: Cleaned up test Makefiles.
X-Git-Tag: V2.16~24
X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=66634ef6834438324104d6f1708a0358bd3e31ae;p=cc65
Cleaned up test Makefiles.
---
diff --git a/test/Makefile b/test/Makefile
index 4817e70e0..a02bd91fb 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,43 +1,30 @@
-
-# top-level makefile for the regression tests
+# top-level Makefile for the regression tests
 
 # You can comment this special target when you debug the regression tests.
 # Then, make will give you more progress reports.
 .SILENT:
 
 ifneq ($(shell echo),)
-  CMD_EXE := 1
+  CMD_EXE = 1
 endif
 
 ifdef CMD_EXE
-  EXE := .exe
-  MKDIR = mkdir $(subst /,\,$1)
   RMDIR = -rmdir /s /q $(subst /,\,$1)
 else
-  EXE :=
-  MKDIR = mkdir $1
   RMDIR = $(RM) -r $1
 endif
 
-WORKDIR := ../testwrk
-
-CC := gcc
+WORKDIR = ../testwrk
 
 .PHONY: all dotests continue mostlyclean clean
 
 all: dotests
 
-$(WORKDIR):
-	$(call MKDIR,$(WORKDIR))
-
-$(WORKDIR)/bdiff$(EXE): bdiff.c | $(WORKDIR)
-	$(CC) -O2 -o $@ $<
-
 .NOTPARALLEL:
 
 dotests: mostlyclean continue
 
-continue: $(WORKDIR)/bdiff$(EXE)
+continue:
 	@$(MAKE) -C assembler all
 	@$(MAKE) -C disassembler all
 	@$(MAKE) -C val all
@@ -46,6 +33,8 @@ continue: $(WORKDIR)/bdiff$(EXE)
 	@$(MAKE) -C misc all
 
 mostlyclean:
+	@$(MAKE) -C assembler clean
+	@$(MAKE) -C disassembler clean
 	@$(MAKE) -C val clean
 	@$(MAKE) -C ref clean
 	@$(MAKE) -C err clean
diff --git a/test/assembler/.gitignore b/test/assembler/.gitignore
deleted file mode 100644
index c0c74a35e..000000000
--- a/test/assembler/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-*.o
-*.bin
-*.lst
diff --git a/test/assembler/Makefile b/test/assembler/Makefile
index 5d38847f5..fb840446c 100644
--- a/test/assembler/Makefile
+++ b/test/assembler/Makefile
@@ -1,45 +1,68 @@
+# Makefile for the assembler regression tests
 
-# makefile for the assembler regression tests
+ifneq ($(shell echo),)
+  CMD_EXE = 1
+endif
 
-BINDIR = ../../bin
-WORKDIR := ../../testwrk
+ifdef CMD_EXE
+  EXE = .exe
+  MKDIR = mkdir $(subst /,\,$1)
+  RMDIR = -rmdir /s /q $(subst /,\,$1)
+  DEL = del /f $(subst /,\,$1)
+else
+  EXE =
+  MKDIR = mkdir -p $1
+  RMDIR = $(RM) -r $1
+  DEL = $(RM) $1
+endif
 
-BASE_TARGETS  = 6502 6502x 65sc02 65c02
-BASE_TARGETS += 4510 huc6280
+CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65)
 
-OPCODE_TARGETS = $(BASE_TARGETS)
-CPUDETECT_TARGETS = $(BASE_TARGETS)
+WORKDIR = ../../testwrk/asm
 
-CPUDETECT_TARGETS += 65816
+DIFF = $(WORKDIR)/bdiff$(EXE)
 
-# default target defined later
-all:
+CC = gcc
+CFLAGS = -O2
 
-# generate opcode targets and expand target list
-define opcode
-OPCODE_TARGETLIST += $$(WORKDIR)/$(1)-opcodes.bin
-$$(WORKDIR)/$(1)-opcodes.bin: $(1)-opcodes.s
-	@$$(BINDIR)/cl65 --cpu $(1) -t none -l $$(WORKDIR)/$(1)-opcodes.lst --obj-path $$(WORKDIR) -o $$@ $$<
-	@diff -q $(1)-opcodes.ref $$@ || (cat $$(WORKDIR)/$(1)-opcodes.lst ; exit 1)
-	@echo ca65 --cpu $(1) opcodes ok
-	@rm -f $(1)-opcodes.o #workaround for #168
-endef
-$(foreach target,$(OPCODE_TARGETS),$(eval $(call opcode,$(target))))
+.PHONY: all clean
 
-# generate cpudetect targets and expand target list
-define cpudetect
-CPUDETECT_TARGETLIST += $$(WORKDIR)/$(1)-cpudetect.bin
-$$(WORKDIR)/$(1)-cpudetect.bin: cpudetect.s
-	@$$(BINDIR)/cl65 --cpu $(1) -t none -l $$(WORKDIR)/$(1)-cpudetect.lst --obj-path $$(WORKDIR) -o $$@ $$<
-	@diff -q $(1)-cpudetect.ref $$@ || (cat $$(WORKDIR)/$(1)-cpudetect.lst ; exit 1)
-	@echo ca65 --cpu $(1) cpudetect ok
-	@rm -f cpudetect.o #workaround for #168
-endef
-$(foreach target,$(CPUDETECT_TARGETS),$(eval $(call cpudetect,$(target))))
+OPCODE_REFS := $(wildcard *-opcodes.ref)
+OPCODE_CPUS = $(foreach ref,$(OPCODE_REFS),$(ref:%-opcodes.ref=%))
+OPCODE_BINS = $(foreach cpu,$(OPCODE_CPUS),$(WORKDIR)/$(cpu)-opcodes.bin)
 
-# now that all targets have been generated, get to the manual ones
-all: $(OPCODE_TARGETLIST) $(CPUDETECT_TARGETLIST)
-	@#
+CPUDETECT_REFS := $(wildcard *-cpudetect.ref)
+CPUDETECT_CPUS = $(foreach ref,$(CPUDETECT_REFS),$(ref:%-cpudetect.ref=%))
+CPUDETECT_BINS = $(foreach cpu,$(CPUDETECT_CPUS),$(WORKDIR)/$(cpu)-cpudetect.bin)
 
-.PHONY: all $(OPCODE_TARGETLIST) $(CPUDETECT_TARGETLIST)
+all: $(OPCODE_BINS) $(CPUDETECT_BINS)
 
+$(WORKDIR):
+	$(call MKDIR,$(WORKDIR))
+
+$(DIFF): ../bdiff.c | $(WORKDIR)
+	$(CC) $(CFLAGS) -o $@ $<
+
+define OPCODE_template
+
+$(WORKDIR)/$1-opcodes.bin: $1-opcodes.s $(DIFF)
+	$(CL65) --cpu $1 -t none -l $(WORKDIR)/$1-opcodes.lst -o $$@ $$<
+	$(DIFF) $$@ $1-opcodes.ref
+
+endef # OPCODE_template
+
+$(foreach cpu,$(OPCODE_CPUS),$(eval $(call OPCODE_template,$(cpu))))
+
+define CPUDETECT_template
+
+$(WORKDIR)/$1-cpudetect.bin: cpudetect.s $(DIFF)
+	$(CL65) --cpu $1 -t none -l $(WORKDIR)/$1-cpudetect.lst -o $$@ $$<
+	$(DIFF) $$@ $1-cpudetect.ref
+
+endef # CPUDETECT_template
+
+$(foreach cpu,$(CPUDETECT_CPUS),$(eval $(call CPUDETECT_template,$(cpu))))
+
+clean:
+	@$(call RMDIR,$(WORKDIR))
+	@$(call DEL,$(OPCODE_REFS:.ref=.o) cpudetect.o)
diff --git a/test/disassembler/Makefile b/test/disassembler/Makefile
index 2621b0c20..f8942ef73 100644
--- a/test/disassembler/Makefile
+++ b/test/disassembler/Makefile
@@ -1,42 +1,64 @@
+# Makefile for the disassembler regression tests
 
-# makefile for the disassembler regression tests
+ifneq ($(shell echo),)
+  CMD_EXE = 1
+endif
 
-BINDIR = ../../bin
-WORKDIR := ../../testwrk
+ifdef CMD_EXE
+  EXE = .exe
+  MKDIR = mkdir $(subst /,\,$1)
+  RMDIR = -rmdir /s /q $(subst /,\,$1)
+  DEL = del /f $(subst /,\,$1)
+else
+  EXE =
+  MKDIR = mkdir -p $1
+  RMDIR = $(RM) -r $1
+  DEL = $(RM) $1
+endif
 
-#BASE_TARGETS  = 6502 6502x 65sc02 65c02
-#BASE_TARGETS += 4510 huc6280
-BASE_TARGETS  = 4510
+CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65)
+DA65 := $(if $(wildcard ../../bin/da65*),../../bin/da65,da65)
+
+WORKDIR = ../../testwrk/dasm
+
+DIFF = $(WORKDIR)/bdiff$(EXE)
+
+CC = gcc
+CFLAGS = -O2
 
 START = --start-addr 0x8000
 
-DISASS_TARGETS = $(BASE_TARGETS)
+.PHONY: all clean
+
+SOURCES := $(wildcard *.s)
+CPUS = $(foreach src,$(SOURCES),$(src:%-disass.s=%))
+BINS = $(foreach cpu,$(CPUS),$(WORKDIR)/$(cpu)-reass.bin)
 
 # default target defined later
-all:
+all: $(BINS)
+
+$(WORKDIR):
+	$(call MKDIR,$(WORKDIR))
+
+$(DIFF): ../bdiff.c | $(WORKDIR)
+	$(CC) $(CFLAGS) -o $@ $<
 
-# generate opcode targets and expand target list
-define disass
-DISASS_TARGETLIST += $$(WORKDIR)/$(1)-reass.bin $$(WORKDIR)/$(1)-reass.s $$(WORKDIR)/$(1)-disass.bin
+define DISASS_template
 
-$$(WORKDIR)/$(1)-disass.bin: $(1)-disass.s
-	@$$(BINDIR)/cl65 --cpu $(1) -t none $(START) --obj-path $$(WORKDIR) -o $$@ $$<
-	@rm -f $(1)-disass.o #workaround for #168
+$(WORKDIR)/$1-disass.bin: $1-disass.s | $(WORKDIR)
+	$(CL65) --cpu $1 -t none $(START) -o $$@ $$<
 
-$$(WORKDIR)/$(1)-reass.s: $$(WORKDIR)/$(1)-disass.bin
-	@$$(BINDIR)/da65 --cpu $(1) $(START) -o $$@ $$<
+$(WORKDIR)/$1-reass.s: $(WORKDIR)/$1-disass.bin
+	$(DA65) --cpu $1 $(START) -o $$@ $$<
 
-$$(WORKDIR)/$(1)-reass.bin: $$(WORKDIR)/$(1)-reass.s
-	@$$(BINDIR)/cl65 --cpu $(1) -t none $(START) --obj-path $$(WORKDIR) -o $$@ $$<
-	@rm -f $(1)-reass.o #workaround for #168
-	@cmp $$@ $$(WORKDIR)/$(1)-disass.bin
-	@echo da65 --cpu $(1) ok
-endef
-$(foreach target,$(DISASS_TARGETS),$(eval $(call disass,$(target))))
+$(WORKDIR)/$1-reass.bin: $(WORKDIR)/$1-reass.s $(DIFF)
+	$(CL65) --cpu $1 -t none $(START) -o $$@ $$<
+	$(DIFF) $$@ $(WORKDIR)/$1-disass.bin
 
-# now that all targets have been generated, get to the manual ones
-all: $(DISASS_TARGETLIST)
-	@#
+endef # DISASS_template
 
-.PHONY: all $(DISASS_TARGETLIST)
+$(foreach cpu,$(CPUS),$(eval $(call DISASS_template,$(cpu))))
 
+clean:
+	@$(call RMDIR,$(WORKDIR))
+	@$(call DEL,$(SOURCES:.s=.o))
diff --git a/test/err/Makefile b/test/err/Makefile
index bc4226acb..2bcc1d264 100644
--- a/test/err/Makefile
+++ b/test/err/Makefile
@@ -1,24 +1,27 @@
-# makefile for the tests that MUST NOT compile
+# Makefile for the tests that MUST NOT compile
 
 ifneq ($(shell echo),)
-  CMD_EXE := 1
+  CMD_EXE = 1
 endif
 
 ifdef CMD_EXE
-  NOT := - # Hack
-  DEL = -del /f $(subst /,\,$1)
+  NOT = - # Hack
+  MKDIR = mkdir $(subst /,\,$1)
+  RMDIR = -rmdir /s /q $(subst /,\,$1)
 else
-  NOT := !
-  DEL = $(RM) $1
+  NOT = !
+  MKDIR = mkdir -p $1
+  RMDIR = $(RM) -r $1
 endif
 
 CC65 := $(if $(wildcard ../../bin/cc65*),../../bin/cc65,cc65)
 
-WORKDIR := ../../testwrk
+WORKDIR = ../../testwrk/err
 
 .PHONY: all clean
 
-TESTS := $(patsubst %.c,$(WORKDIR)/%.s,$(wildcard *.c))
+SOURCES := $(wildcard *.c)
+TESTS = $(patsubst %.c,$(WORKDIR)/%.s,$(SOURCES))
 
 all: $(TESTS)
 
@@ -26,4 +29,4 @@ $(WORKDIR)/%.s: %.c
 	$(NOT) $(CC65) -o $@ $<
 
 clean:
-	@$(call DEL,$(TESTS))
+	@$(call RMDIR,$(WORKDIR))
diff --git a/test/misc/Makefile b/test/misc/Makefile
index 918316c6c..6512a9fd9 100644
--- a/test/misc/Makefile
+++ b/test/misc/Makefile
@@ -1,63 +1,85 @@
-
-# makefile for the remaining tests that need special care in one way or another
+# Makefile for the remaining tests that need special care in one way or another
 
 ifneq ($(shell echo),)
-  CMD_EXE := 1
+  CMD_EXE = 1
 endif
 
 ifdef CMD_EXE
-  S := $(subst /,\,/)
-  NOT := - # Hack
-  DEL = -del /f $(subst /,\,$1)
+  S = $(subst /,\,/)
+  NOT = - # Hack
+  EXE = .exe
+  MKDIR = mkdir $(subst /,\,$1)
+  RMDIR = -rmdir /s /q $(subst /,\,$1)
+  DEL = del /f $(subst /,\,$1)
 else
-  S := /
-  NOT := !
+  S = /
+  NOT = !
+  EXE =
+  MKDIR = mkdir -p $1
+  RMDIR = $(RM) -r $1
   DEL = $(RM) $1
 endif
 
-CC65FLAGS := -t sim6502
-SIM65FLAGS := -x 200000000
+CC65FLAGS = -t sim6502
+SIM65FLAGS = -x 200000000
 
 CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65)
 SIM65 := $(if $(wildcard ../../bin/sim65*),..$S..$Sbin$Ssim65,sim65)
 
-WORKDIR := ..$S..$Stestwrk
-DIFF := $(WORKDIR)/bdiff
+WORKDIR = ..$S..$Stestwrk$Smisc
+
+OPTIONS = g O Os Osi Osir Oi Oir Or
+
+DIFF = $(WORKDIR)$Sbdiff$(EXE)
+
+CC = gcc
+CFLAGS = -O2
 
 .PHONY: all clean
 
 SOURCES := $(wildcard *.c)
-TESTS := $(foreach option,. .o. .os. .osi. .osir. .oi. .oir. .or.,$(SOURCES:%.c=$(WORKDIR)/%$(option)prg))
+TESTS = $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).prg))
 
 all: $(TESTS)
 
+$(WORKDIR):
+	$(call MKDIR,$(WORKDIR))
+
+$(DIFF): ../bdiff.c | $(WORKDIR)
+	$(CC) $(CFLAGS) -o $@ $<
+
+define PRG_template
+
 # should compile, but then hangs in an endless loop
-$(WORKDIR)/endless%prg: endless.c
-	$(CL65) $(subst .,,$(*:.o%=-O%)) $(CC65FLAGS) $< -o $@
-	$(NOT) $(SIM65) $(SIM65FLAGS) $@
+$(WORKDIR)/endless.$1.prg: endless.c | $(WORKDIR)
+	$(CL65) $(CC65FLAGS) -$1 -o $$@ $$<
+	$(NOT) $(SIM65) $(SIM65FLAGS) $$@
 
 # these need reference data that can't be generated by a host-compiled program,
 # in a useful way
-$(WORKDIR)/limits%prg: limits.c
-	$(CL65) $(subst .,,$(*:.o%=-O%)) $(CC65FLAGS) $< -o $@
-	$(SIM65) $(SIM65FLAGS) $@ > $(WORKDIR)/limits.out
-	$(DIFF) $(WORKDIR)/limits.out limits.ref
+$(WORKDIR)/limits.$1.prg: limits.c $(DIFF)
+	$(CL65) $(CC65FLAGS) -$1 -o $$@ $$<
+	$(SIM65) $(SIM65FLAGS) $$@ > $(WORKDIR)/limits.$1.out
+	$(DIFF) $(WORKDIR)/limits.$1.out limits.ref
 
 # the rest are tests that fail currently for one reason or another
-$(WORKDIR)/fields%prg: fields.c
-	@echo "FIXME: " $@ "currently will fail."
-	$(CL65) $(subst .,,$(*:.o%=-O%)) $(CC65FLAGS) $< -o $@
-	-$(SIM65) $(SIM65FLAGS) $@
-$(WORKDIR)/sitest%prg: sitest.c
-	@echo "FIXME: " $@ "currently will fail."
-	-$(CL65) $(subst .,,$(*:.o%=-O%)) $(CC65FLAGS) $< -o $@
-#	-$(SIM65) $(SIM65FLAGS) $@
-$(WORKDIR)/cc65141011%prg: cc65141011.c
-	@echo "FIXME: " $@ "currently can fail."
-	$(CL65) $(subst .,,$(*:.o%=-O%)) $(CC65FLAGS) $< -o $@
-	-$(SIM65) $(SIM65FLAGS) $@
+$(WORKDIR)/fields.$1.prg: fields.c | $(WORKDIR)
+	@echo "FIXME: " $$@ "currently will fail."
+	$(CL65) $(CC65FLAGS) -$1 -o $$@ $$<
+	-$(SIM65) $(SIM65FLAGS) $$@
+$(WORKDIR)/sitest.$1.prg: sitest.c | $(WORKDIR)
+	@echo "FIXME: " $$@ "currently will fail."
+	-$(CL65) $(CC65FLAGS) -$1 -o $$@ $$<
+#	-$(SIM65) $(SIM65FLAGS) $$@
+$(WORKDIR)/cc65141011.$1.prg: cc65141011.c | $(WORKDIR)
+	@echo "FIXME: " $$@ "currently can fail."
+	$(CL65) $(CC65FLAGS) -$1 -o $$@ $$<
+	-$(SIM65) $(SIM65FLAGS) $$@
+
+endef # PRG_template
+
+$(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option))))
 
 clean:
-	@$(call DEL,$(TESTS))
+	@$(call RMDIR,$(WORKDIR))
 	@$(call DEL,$(SOURCES:.c=.o))
-	@$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.out))
diff --git a/test/ref/Makefile b/test/ref/Makefile
index 6f0bd1bc1..7bd10cf14 100644
--- a/test/ref/Makefile
+++ b/test/ref/Makefile
@@ -1,102 +1,84 @@
-# makefile for the regression tests that generate output which has to be
+# Makefile for the regression tests that generate output which has to be
 # compared with reference output
 
 ifneq ($(shell echo),)
-  CMD_EXE := 1
+  CMD_EXE = 1
 endif
 
 ifdef CMD_EXE
-  S := $(subst /,\,/)
-  DEL = -del /f $(subst /,\,$1)
+  S = $(subst /,\,/)
+  EXE = .exe
+  MKDIR = mkdir $(subst /,\,$1)
+  RMDIR = -rmdir /s /q $(subst /,\,$1)
+  DEL = del /f $(subst /,\,$1)
 else
-  S := /
+  S = /
+  EXE =
+  MKDIR = mkdir -p $1
+  RMDIR = $(RM) -r $1
   DEL = $(RM) $1
 endif
 
-CC65FLAGS := -t sim6502
-SIM65FLAGS := -x 200000000
+CC65FLAGS = -t sim6502
+SIM65FLAGS = -x 200000000
 
 CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65)
 SIM65 := $(if $(wildcard ../../bin/sim65*),..$S..$Sbin$Ssim65,sim65)
 
-WORKDIR := ..$S..$Stestwrk
-DIFF := $(WORKDIR)/bdiff
+WORKDIR = ..$S..$Stestwrk$Sref
 
-CC := gcc
-CFLAGS := -O2 -Wall -W -Wextra -funsigned-char -fwrapv -fno-strict-overflow
+OPTIONS = g O Os Osi Osir Oi Oir Or
+
+DIFF = $(WORKDIR)$Sbdiff$(EXE)
+
+CC = gcc
+CFLAGS = -O2 -Wall -W -Wextra -funsigned-char -fwrapv -fno-strict-overflow
 
 .PHONY: all clean
 
 SOURCES := $(wildcard *.c)
-REFS := $(SOURCES:%.c=$(WORKDIR)/%.ref)
-TESTS := $(foreach option,. .o. .os. .osi. .osir. .oi. .oir. .or.,$(SOURCES:%.c=$(WORKDIR)/%$(option)prg))
+REFS = $(SOURCES:%.c=$(WORKDIR)/%.ref)
+TESTS = $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).prg))
 
 all: $(REFS) $(TESTS)
 
-# "yaccdbg.c" includes "yacc.c".
-# yaccdbg's built files must depend on both of them.
+$(WORKDIR):
+	$(call MKDIR,$(WORKDIR))
 
-$(WORKDIR)/yaccdbg.ref: yacc.c
-
-$(WORKDIR)/%.ref: %.c
-	$(CC) $(CFLAGS) $< -o $(WORKDIR)/$*.host
+$(WORKDIR)/%.ref: %.c | $(WORKDIR)
+	$(CC) $(CFLAGS) -o $(WORKDIR)/$*.host $<
 	$(WORKDIR)$S$*.host > $@
 
+$(DIFF): ../bdiff.c | $(WORKDIR)
+	$(CC) $(CFLAGS) -o $@ $<
+
 # Some files have "K & R"-style syntax.  Therefore, some forward
 # function-declarations don't match the later function definitions.
 # Those programs fail when fastcall is used; but, the cdecl calling convention
 # tolerates those conflicts.  Therefore, make their functions default to cdecl.
 #
-$(WORKDIR)/init%prg: CC65FLAGS += -Wc --all-cdecl
-$(WORKDIR)/switch.%rg: CC65FLAGS += -Wc --all-cdecl
-$(WORKDIR)/yacc.%rg: CC65FLAGS += -Wc --all-cdecl
-$(WORKDIR)/yaccdbg%prg: CC65FLAGS += -Wc --all-cdecl
-
-$(WORKDIR)/yaccdbg%prg: yacc.c
-
-$(WORKDIR)/%.prg: %.c $(WORKDIR)/%.ref
-	$(CL65) $(CC65FLAGS) $< -o $@
-	$(SIM65) $(SIM65FLAGS) $@ > $(WORKDIR)/$*.out
-	$(DIFF) $(WORKDIR)/$*.out $(WORKDIR)/$*.ref
-
-$(WORKDIR)/%.o.prg: %.c $(WORKDIR)/%.ref
-	$(CL65) -O $(CC65FLAGS) $< -o $@
-	$(SIM65) $(SIM65FLAGS) $@ > $(WORKDIR)/$*.out
-	$(DIFF) $(WORKDIR)/$*.out $(WORKDIR)/$*.ref
-
-$(WORKDIR)/%.os.prg: %.c $(WORKDIR)/%.ref
-	$(CL65) -Os $(CC65FLAGS) $< -o $@
-	$(SIM65) $(SIM65FLAGS) $@ > $(WORKDIR)/$*.out
-	$(DIFF) $(WORKDIR)/$*.out $(WORKDIR)/$*.ref
-
-$(WORKDIR)/%.osi.prg: %.c $(WORKDIR)/%.ref
-	$(CL65) -Osi $(CC65FLAGS) $< -o $@
-	$(SIM65) $(SIM65FLAGS) $@ > $(WORKDIR)/$*.out
-	$(DIFF) $(WORKDIR)/$*.out $(WORKDIR)/$*.ref
-
-$(WORKDIR)/%.osir.prg: %.c $(WORKDIR)/%.ref
-	$(CL65) -Osir $(CC65FLAGS) $< -o $@
-	$(SIM65) $(SIM65FLAGS) $@ > $(WORKDIR)/$*.out
-	$(DIFF) $(WORKDIR)/$*.out $(WORKDIR)/$*.ref
-
-$(WORKDIR)/%.oi.prg: %.c $(WORKDIR)/%.ref
-	$(CL65) -Oi $(CC65FLAGS) $< -o $@
-	$(SIM65) $(SIM65FLAGS) $@ > $(WORKDIR)/$*.out
-	$(DIFF) $(WORKDIR)/$*.out $(WORKDIR)/$*.ref
-
-$(WORKDIR)/%.oir.prg: %.c $(WORKDIR)/%.ref
-	$(CL65) -Oir $(CC65FLAGS) $< -o $@
-	$(SIM65) $(SIM65FLAGS) $@ > $(WORKDIR)/$*.out
-	$(DIFF) $(WORKDIR)/$*.out $(WORKDIR)/$*.ref
-
-$(WORKDIR)/%.or.prg: %.c $(WORKDIR)/%.ref
-	$(CL65) -Or $(CC65FLAGS) $< -o $@
-	$(SIM65) $(SIM65FLAGS) $@ > $(WORKDIR)/$*.out
-	$(DIFF) $(WORKDIR)/$*.out $(WORKDIR)/$*.ref
+$(WORKDIR)/init.%.prg   \
+$(WORKDIR)/switch.%.prg \
+$(WORKDIR)/yacc.%.prg   \
+$(WORKDIR)/yaccdbg.%.prg: CC65FLAGS += -Wc --all-cdecl
+
+# "yaccdbg.c" includes "yacc.c".
+# yaccdbg's built files must depend on both of them.
+#
+$(WORKDIR)/yaccdbg.ref:   yacc.c
+$(WORKDIR)/yaccdbg.%.prg: yacc.c
+
+define PRG_template
+
+$(WORKDIR)/%.$1.prg: %.c $(WORKDIR)/%.ref $(DIFF)
+	$(CL65) $$(CC65FLAGS) -$1 -o $$@ $$<
+	$(SIM65) $(SIM65FLAGS) $$@ > $(WORKDIR)/$$*.out
+	$(DIFF) $(WORKDIR)/$$*.out $(WORKDIR)/$$*.ref
+
+endef # PRG_template
+
+$(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option))))
 
 clean:
-	@$(call DEL,$(TESTS))
+	@$(call RMDIR,$(WORKDIR))
 	@$(call DEL,$(SOURCES:.c=.o))
-	@$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.out))
-	@$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.ref))
-	@$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.host))
diff --git a/test/val/Makefile b/test/val/Makefile
index 4ad8160ef..8a07045ee 100644
--- a/test/val/Makefile
+++ b/test/val/Makefile
@@ -1,70 +1,59 @@
-
-# makefile for the regression tests that return an error code on failure
+# Makefile for the regression tests that return an error code on failure
 
 ifneq ($(shell echo),)
-  CMD_EXE := 1
+  CMD_EXE = 1
 endif
 
 ifdef CMD_EXE
-  DEL = -del /f $(subst /,\,$1)
+  MKDIR = mkdir $(subst /,\,$1)
+  RMDIR = -rmdir /s /q $(subst /,\,$1)
+  DEL = del /f $(subst /,\,$1)
 else
+  MKDIR = mkdir -p $1
+  RMDIR = $(RM) -r $1
   DEL = $(RM) $1
 endif
 
-CC65FLAGS := -t sim6502
-SIM65FLAGS := -x 200000000
+CC65FLAGS = -t sim6502
+SIM65FLAGS = -x 200000000
 
 CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65)
 SIM65 := $(if $(wildcard ../../bin/sim65*),../../bin/sim65,sim65)
 
-WORKDIR := ../../testwrk
+WORKDIR = ../../testwrk/val
+
+OPTIONS = g O Os Osi Osir Oi Oir Or
 
 .PHONY: all clean
 
 SOURCES := $(wildcard *.c)
-TESTS := $(foreach option,. .o. .os. .osi. .osir. .oi. .oir. .or.,$(SOURCES:%.c=$(WORKDIR)/%$(option)prg))
+TESTS = $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).prg))
 
 all: $(TESTS)
 
+$(WORKDIR):
+	$(call MKDIR,$(WORKDIR))
+
 # Some files have "K & R"-style syntax.  Therefore, some forward
 # function-declarations don't match the later function definitions.
 # Those programs fail when fastcall is used; but, the cdecl calling convention
 # tolerates those conflicts.  Therefore, make their functions default to cdecl.
 #
-$(WORKDIR)/cq4%prg $(WORKDIR)/cq71.%rg $(WORKDIR)/cq81%prg $(WORKDIR)/cq84%prg: CC65FLAGS += -Wc --all-cdecl
-
-$(WORKDIR)/%.prg: %.c
-	$(CL65) $(CC65FLAGS) $< -o $@
-	$(SIM65) $(SIM65FLAGS) $@
-
-$(WORKDIR)/%.o.prg: %.c
-	$(CL65) -O $(CC65FLAGS) $< -o $@
-	$(SIM65) $(SIM65FLAGS) $@
-
-$(WORKDIR)/%.os.prg: %.c
-	$(CL65) -Os $(CC65FLAGS) $< -o $@
-	$(SIM65) $(SIM65FLAGS) $@
-
-$(WORKDIR)/%.osi.prg: %.c
-	$(CL65) -Osi $(CC65FLAGS) $< -o $@
-	$(SIM65) $(SIM65FLAGS) $@
+$(WORKDIR)/cq4.%.prg  \
+$(WORKDIR)/cq71.%.prg \
+$(WORKDIR)/cq81.%.prg \
+$(WORKDIR)/cq84.%.prg: CC65FLAGS += -Wc --all-cdecl
 
-$(WORKDIR)/%.osir.prg: %.c
-	$(CL65) -Osir $(CC65FLAGS) $< -o $@
-	$(SIM65) $(SIM65FLAGS) $@
+define PRG_template
 
-$(WORKDIR)/%.oi.prg: %.c
-	$(CL65) -Oi $(CC65FLAGS) $< -o $@
-	$(SIM65) $(SIM65FLAGS) $@
+$(WORKDIR)/%.$1.prg: %.c | $(WORKDIR)
+	$(CL65) $$(CC65FLAGS) -$1 -o $$@ $$<
+	$(SIM65) $(SIM65FLAGS) $$@
 
-$(WORKDIR)/%.oir.prg: %.c
-	$(CL65) -Oir $(CC65FLAGS) $< -o $@
-	$(SIM65) $(SIM65FLAGS) $@
+endef # PRG_template
 
-$(WORKDIR)/%.or.prg: %.c
-	$(CL65) -Or $(CC65FLAGS) $< -o $@
-	$(SIM65) $(SIM65FLAGS) $@
+$(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option))))
 
 clean:
-	@$(call DEL,$(TESTS))
+	@$(call RMDIR,$(WORKDIR))
 	@$(call DEL,$(SOURCES:.c=.o))