From f78dde64c011f95274eee188a09495c0f67ed81c Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Tue, 23 Feb 2021 00:39:30 -0500 Subject: [PATCH] Generate ChangeLog from git at packaging time. Import the gitlog-to-changelog script from gnulib and add rules to generate an up-to-date changelog from the git history, if available, when running 'make dist'. The ChangeLog is otherwise taken from srcdir as usual, so that modified versions can be prepared from a release tarball without requiring the full git history. In this scenario, the ChangeLog would have to be manually edited. In case the ChangeLog generation fails, a distcheck-hook is added to hopefully catch issues before releasing tarballs with a broken ChangeLog. --- .gitignore | 1 + ChangeLog | 1 + Makefile.am | 33 +++++++++++++++++++++++++++++++++ m4/gnulib-cache.m4 | 2 ++ 4 files changed, 37 insertions(+) create mode 100644 ChangeLog diff --git a/.gitignore b/.gitignore index 735368e..dafb638 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ /configure /depcomp /exported.sh +/gitlog-to-changelog /install-sh /lib /libtool diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..4e0b7e7 --- /dev/null +++ b/ChangeLog @@ -0,0 +1 @@ +Stub changelog, see the git history for changes. diff --git a/Makefile.am b/Makefile.am index 01ff0a6..4bdc88c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -149,6 +149,39 @@ unfuck-distdir: find '$(distdir)' -type f -exec chmod u+w {} + .PHONY: unfuck-distdir +GITLOG_FLAGS = --format='%s%n%n%b%n' + +dist-hook: generate-changelog +generate-changelog: unfuck-distdir + -: "$${GIT_DIR=$(top_srcdir)/.git}"; \ + export GIT_DIR; test -d "$$GIT_DIR" || exit 0; \ + $(top_srcdir)/gitlog-to-changelog $(GITLOG_FLAGS) \ + >'$(distdir)/ChangeLog.gen' && \ + mv -f '$(distdir)/ChangeLog.gen' '$(distdir)/ChangeLog' + rm -f '$(distdir)/ChangeLog.gen' +.PHONY: generate-changelog + +GENERIC_V = $(GENERIC_V_@AM_V@) +GENERIC_V_ = $(GENERIC_V_@AM_DEFAULT_V@) +GENERIC_V_0 = @printf '%2.0s%$(DX_ALIGN_V)s %s\n' + +TEST_DISTRIBUTION = false +TEST_DISTRIBUTION_OR_ERROR = if $(TEST_DISTRIBUTION); \ + then echo 'Proceeding anyway...'; \ + else echo 'Run $(MAKE) TEST_DISTRIBUTION=true to ignore this failure.'; \ + false; \ + fi + +distcheck-hook: + $(GENERIC_V) : 'CHECK ' ChangeLog; \ + $(AWK) '/^Stub/ { print FILENAME ":" NR ":", $$0; exit 1 }' \ + $(distdir)/ChangeLog || { \ + echo 'ERROR: *** Packaged ChangeLog was not properly generated from git log.'; \ + echo ' *** The source version was used instead, but this appears to'; \ + echo ' *** be the stub from a git checkout. The "git" and "perl"'; \ + echo ' *** programs are required for ChangeLog generation to work.'; \ + $(TEST_DISTRIBUTION_OR_ERROR); } >&2 + # Supporting rules for bison/flex. BISON_V = $(BISON_V_@AM_V@) diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4 index 5faa6b6..5223b7d 100644 --- a/m4/gnulib-cache.m4 +++ b/m4/gnulib-cache.m4 @@ -41,6 +41,7 @@ # --no-vc-files \ # getopt-gnu \ # gettext-h \ +# gitlog-to-changelog \ # localcharset \ # lock \ # readline \ @@ -52,6 +53,7 @@ gl_LOCAL_DIR([]) gl_MODULES([ getopt-gnu gettext-h + gitlog-to-changelog localcharset lock readline -- 2.43.2