SRC := $(PROG).z80
+EXTRA_DIST := autorevision.cache version.inc
+
OBJ := $(SRC:.z80=.rel)
-AS_OPT := MFS
+DIST_NAME = $(PROG)_$(VERS).zip
+PREFIX = $(PROG)_$(VERS)
-ASM := zxcc slrz80.com
-LINK := zxcc link80.com
+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).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 $@
+ @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: