1EXTRA_DIST=$(GENERATED_EXTRA_DIST)
2
3# === Release Configuration ===
4# RELEASE_VERSION   # defaults to, default: $(VERSION)
5# RELEASE_REVNAME   # micro revision variable name, default: VERSION_PATCHLEVEL
6# RELEASE_TARBALL   # release tarball name, default: $(distdir).tar.?z*
7# RELEASE_DESTHOST  # destination host for tarball uploads
8# RELEASE_DESTPATH  # destination host path for tarball uploads
9# RELEASE_REVISION  # micro revision, defaults to expanding $(RELEASE_REVNAME)
10# RELEASE_REVNEXT   # next micro revision, defaults to incrementing $(RELEASE_REVISION)
11# RELEASE_CHANGELOG # generated ChangeLog file name, if generation desired
12# RELEASE_CHL_RANGE # ChangeLog revision range for git log, default: HEAD
13# RELEASE_CHL_ADD   # plaint text file to be appended to generated ChangeLog
14# === Release auxillary rule defaults ===
15RELAUX_VERSION   = $(strip $(or $(RELEASE_VERSION), $(VERSION)))
16RELAUX_REVNAME   = $(strip $(or $(RELEASE_REVNAME), VERSION_PATCHLEVEL))
17RELAUX_FILE      = $(strip $(or $(RELEASE_TARBALL), $(word 1, $(shell echo $(distdir).tar.?z*))))
18RELAUX_DESTHOST  = $(strip $(or $(RELEASE_DESTHOST), example.com))
19RELAUX_DESTPATH  = $(strip $(or $(RELEASE_DESTPATH), distpath/projectname))
20RELAUX_REVISION  = $($(RELAUX_REVNAME))
21RELAUX_REVNEXT   = $(strip $(or $(RELEASE_REVNEXT), $(shell echo '1 + $(RELAUX_REVISION)' | bc)))
22RELAUX_CHANGELOG = $(strip $(RELEASE_CHANGELOG))
23RELAUX_CHL_RANGE = $(strip $(or $(RELEASE_CHL_RANGE), HEAD))
24RELAUX_CHL_ADD   = $(strip $(RELEASE_CHL_ADD))
25# --- ChangeLog ---
26RELAUX_GITSTAMPS = $(shell ls "$${GIT_DIR:-.git}/`git symbolic-ref -q HEAD || echo HEAD`" \
27			   "$${GIT_DIR:-.git}/packed-refs"  "$${GIT_DIR:-.git}/HEAD" 2>/dev/null )
28${RELAUX_CHANGELOG}:	${RELAUX_CHL_ADD} ${RELAUX_GITSTAMPS} Makefile.am
29	@ # Generate ChangeLog with -prefixed records
30	git log ${RELAUX_CHL_RANGE} > xgen-0$(@F) \
31	   --pretty='tformat:%ai  %an 	# %h%n%n%s%n%n%b'
32	@ # Append old style ChangeLog
33	cat xgen-0$(@F) ${RELAUX_CHL_ADD} > xgen-1$(@F)
34	@ # Tab-indent ChangeLog, except for record start
35	sed 's/^/	/; s/^	//; /^[ 	]*<unknown>$$/d' < xgen-1$(@F) > xgen-0$(@F)
36	@ # Kill trailing whitespaces
37	sed 's/[[:space:]]\+$$//' < xgen-0$(@F) > xgen-1$(@F)
38	@ # Compress multiple newlines
39	sed '/^\s*$$/{ N; /^\s*\n\s*$$/D }' < xgen-1$(@F) > xgen-0$(@F)
40	@ # Cleanup, replace atomically
41	rm -f xgen-1$(@F)
42	mv xgen-0$(@F) $@
43all-am: ${RELAUX_CHANGELOG}
44EXTRA_DIST  += ${RELAUX_CHANGELOG}
45# --- release-upload ---
46release-upload: $(RELAUX_CHANGELOG) # serialized steps, for parallel invocation
47	@echo -n "  Checking for a clean $(RELAUX_VERSION) working tree...                    "
48	@test 0 = `git diff HEAD | wc -l` \
49	|| (echo FAIL && echo "note: use 'git diff HEAD' to view working tree changes" && false)
50	@echo "OK"
51	@echo -n "  Checking untagged revision $(RELAUX_VERSION)...                           "
52	@! git rev-parse --verify -q "$(RELAUX_VERSION)" > /dev/null \
53	|| (echo FAIL && echo -n "note: tag $(RELAUX_VERSION) exists: " \
54            && git rev-parse $(RELAUX_VERSION) && false)
55	@echo "OK"
56	@echo -n "  Checking release file $(RELAUX_FILE)...                  "
57	@test -e "$(RELAUX_FILE)" || (echo "FAIL" && false)
58	@echo "OK"
59	@echo -n "  Checking age of release file $(RELAUX_FILE)...           "
60	@test "$(RELAUX_FILE)" -nt $(RELAUX_CHANGELOG) \
61	|| (echo FAIL && echo "note: $(RELAUX_CHANGELOG) appears to be newer; make distcheck" && false)
62	@echo "OK"
63	@echo -n "  Checking uniqueness of release tarball $(RELAUX_FILE)... "
64	@ssh $(RELAUX_DESTHOST) test ! -e "$(RELAUX_DESTPATH)/$(RELAUX_FILE)" \
65	|| ( echo "FAIL (already existing)" && false )
66	@echo "OK"
67	@echo -n "  Checking version $(RELAUX_VERSION) for even revision...                   "
68	@test "$(RELAUX_REVISION)" = "`echo '$(RELAUX_REVISION) / 2 * 2' | bc`" \
69	|| (echo FAIL && echo "note: not uploading an odd revision, see configure.ac:$(RELAUX_REVNAME)" && false)
70	@echo "OK"
71	@echo -n "  Uploading release tarball $(RELAUX_FILE)...              "
72	@rsync -lpt --delay-updates "$(RELAUX_FILE)" "$(RELAUX_DESTHOST):$(RELAUX_DESTPATH)"
73	@echo "OK" && echo -n "    "
74	@ssh $(RELAUX_DESTHOST) ls -l \`readlink -f "$(RELAUX_DESTPATH)/$(RELAUX_FILE)"\`
75	@echo -n "  Tagging HEAD as '$(RELAUX_VERSION)' release...                            "
76	@git tag -m "Released $(distdir)" "$(RELAUX_VERSION)"
77	@echo "OK" && echo -n "    "
78	@git tag -n1 -l "$(RELAUX_VERSION)"
79	@echo "  Bump configure.ac:$(RELAUX_REVNAME)... "
80	@sed '0,/^\($(RELAUX_REVNAME)\)=[0-9]\+/s//\1=$(RELAUX_REVNEXT)/' \
81	    < $(top_srcdir)/configure.ac > xgen_$$$$Z-configure.ac \
82	&& diff -uU2 $(top_srcdir)/configure.ac xgen_$$$$Z-configure.ac | sed "s/xgen_$$$$Z-//" \
83	&& mv -iv xgen_$$$$Z-configure.ac $(top_srcdir)/configure.ac \
84	&& rm -f xgen_$$$$Z-configure.ac
85.PHONY: release-upload
86