1# Makefile for the regression tests that generate output which has to be 2# compared with reference output 3 4ifneq ($(shell echo),) 5 CMD_EXE = 1 6endif 7 8ifdef CMD_EXE 9 S = $(subst /,\,/) 10 EXE = .exe 11 NULLDEV = nul: 12 MKDIR = mkdir $(subst /,\,$1) 13 RMDIR = -rmdir /s /q $(subst /,\,$1) 14 DEL = del /f $(subst /,\,$1) 15else 16 S = / 17 EXE = 18 NULLDEV = /dev/null 19 MKDIR = mkdir -p $1 20 RMDIR = $(RM) -r $1 21 DEL = $(RM) $1 22endif 23 24ifdef QUIET 25 .SILENT: 26 NULLERR = 2>$(NULLDEV) 27endif 28 29SIM65FLAGS = -x 200000000 30 31CL65 := $(if $(wildcard ../../bin/cl65*),..$S..$Sbin$Scl65,cl65) 32SIM65 := $(if $(wildcard ../../bin/sim65*),..$S..$Sbin$Ssim65,sim65) 33 34WORKDIR = ..$S..$Stestwrk$Sref 35 36OPTIONS = g O Os Osi Osir Osr Oi Oir Or 37 38DIFF = $(WORKDIR)$Sbdiff$(EXE) 39 40#CC = gcc 41#CFLAGS = -O2 -Wall -W -Wextra -funsigned-char -fwrapv -fno-strict-overflow 42 43.PHONY: all clean 44 45SOURCES := $(wildcard *.c) 46REFS = $(SOURCES:%.c=$(WORKDIR)/%.ref) 47TESTS = $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).6502.prg)) 48TESTS += $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).65c02.prg)) 49 50all: $(REFS) $(TESTS) 51 52$(WORKDIR): 53 $(call MKDIR,$(WORKDIR)) 54 55$(WORKDIR)/%.ref: %.c | $(WORKDIR) 56 $(if $(QUIET),echo ref/$*.host) 57 $(CC) $(CFLAGS) -o $(WORKDIR)/$*.host $< $(NULLERR) 58 $(WORKDIR)$S$*.host > $@ 59 60$(DIFF): ../bdiff.c | $(WORKDIR) 61 $(CC) $(CFLAGS) -o $@ $< 62 63# "yaccdbg.c" includes "yacc.c". 64# yaccdbg's built files must depend on both of them. 65# 66$(WORKDIR)/yaccdbg.ref: yacc.c 67$(WORKDIR)/yaccdbg.%.prg: yacc.c 68 69define PRG_template 70 71$(WORKDIR)/%.$1.$2.prg: %.c $(WORKDIR)/%.ref $(DIFF) 72 $(if $(QUIET),echo ref/$$*.$1.$2.prg) 73 $(CL65) -t sim$2 $$(CC65FLAGS) -$1 -o $$@ $$< $(NULLERR) 74 $(SIM65) $(SIM65FLAGS) $$@ > $(WORKDIR)/$$*.out 75 $(DIFF) $(WORKDIR)/$$*.out $(WORKDIR)/$$*.ref 76 77endef # PRG_template 78 79$(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),6502))) 80$(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),65c02))) 81 82clean: 83 @$(call RMDIR,$(WORKDIR)) 84 @$(call DEL,$(SOURCES:.c=.o)) 85