summaryrefslogtreecommitdiff
path: root/Makefile
blob: 6ac3191690a2023de3b7a7229eacf84c5e4af1be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Build ddt180.com from ddt180.z80

PROG	:= ddt180

SRC	:= $(PROG).z80

EXTRA_DIST := autorevision.cache version.inc

OBJ	:= $(SRC:.z80=.rel)

DIST_NAME = $(PROG)_$(VERS).zip
PREFIX = $(PROG)_$(VERS)

ASM	:= zxcc slrz80.com
LINK	:= zxcc link80.com
CP	:= cp
RM	:= rm -f
GIT	:= git
ZIP	:= zip

AS_OPT	:= MFS

.PHONY: all
all: $(PROG).com



$(PROG).com: $(PROG).prl
	@# Remove the PRL header record (256 bytes)
	dd status=none bs=256 skip=1  if=$< of=$@

$(PROG).prl: $(OBJ)
	$(LINK) -'$(PROG)[op,$$SZ]'

$(PROG).rel: version.inc

$(foreach X,$(subst =,:=,$(subst ",,$(filter VCS_%,\
	$(shell autorevision -t sh -o $(CURDIR)/autorevision.cache)))),$(eval $X))

VERS := $(shell echo "$(VCS_TAG)" | sed -e 's/^v//g')

ifneq ($(VCS_TICK),0)
  VERS := $(VERS)-$(VCS_TICK)
endif
ifneq ($(VCS_BRANCH),master)
  VERS := $(VERS)-$(VCS_BRANCH)
endif
ifeq ($(VCS_WC_MODIFIED),1)
  VERS := $(VERS)-dirty
endif



version.inc: autorevision.cache
	@echo update $@ to $(VERS)
	@printf "defvers	macro\r\n\
		db	'$(VERS)'\r\n\
		endm\r\n\032" > $@

.PHONY: dist
dist: $(PROG).com version.inc
	$(GIT) archive --format=zip --prefix=$(PREFIX)/ -9 -o $(DIST_NAME) HEAD^{tree}
	@mkdir -p $(PREFIX)
	@$(CP) -p $(EXTRA_DIST) $(PREFIX)
	$(ZIP) -r -9 $(DIST_NAME) $(PREFIX) $(PROG).com
	@$(RM) -r $(PREFIX)

.PHONY: clean
clean:
	rm -f $(PROG).com *.rel *.lst *.prl

.SUFFIXES:
.SUFFIXES: .z80 .rel .prl


define cpm-asm =
COMMAND="$(ASM) -$(basename $<)/$(AS_OPT)"; \
OUTPUT=$$(mktemp); echo $${COMMAND}; \
$${COMMAND} > $${OUTPUT} < $<; \
grep -q '^ 0 Error(s) Detected' $${OUTPUT}; ERROR=$$? ; \
if [ "$${ERROR}" != "0" ]; then cat $${OUTPUT}; rm -f $@; fi ; \
exit $${ERROR}
endef

%.rel %lst: %.z80
	@$(cpm-asm)