Previous: , Up: Build Infrastructure Modules   [Contents][Index]


19.9 gitlog-to-changelog

Gnulib have a module gitlog-to-changelog to parse git log output and generate ChangeLog files, see https://www.gnu.org/prep/standards/html_node/Change-Logs.html.

You would typically use it by extending the dist-hook in the top-level Makefile.am like this:

dist-hook: gen-ChangeLog
...
.PHONY: gen-ChangeLog
gen-ChangeLog:
        $(AM_V_GEN)if test -e .git; then                               \
                $(top_srcdir)/build-aux/gitlog-to-changelog >          \
                        $(distdir)/cl-t &&                             \
                { rm -f $(distdir)/ChangeLog &&                        \
                  mv $(distdir)/cl-t $(distdir)/ChangeLog; }           \
        fi

See gitlog-to-changelog --help for complete documentation.

The tool prints timestamps using localtime, so its output may be different depending on what locale the developer that runs the tool is using. If your project desire reproducible ChangeLog files that doesn’t depend on locale settings, use something like the following.

gen-ChangeLog:
        $(AM_V_GEN)if test -e .git; then                               \
                env LC_ALL=en_US.UTF-8 TZ=UTC=0                        \
                        $(top_srcdir)/build-aux/gitlog-to-changelog >  \
                        $(distdir)/cl-t &&                             \
                { rm -f $(distdir)/ChangeLog &&                        \
                  mv $(distdir)/cl-t $(distdir)/ChangeLog; }           \
        fi

If you wish to limit the ChangeLog entries (perhaps for size issues) to only contain entries since a particular git tag, use something like the following:

dist-hook: gen-ChangeLog
...
gen_start_ver = 8.31
.PHONY: gen-ChangeLog
gen-ChangeLog:
        $(AM_V_GEN)if test -e .git; then                               \
          log_fix="$(srcdir)/build-aux/git-log-fix";                   \
          test -e "$$log_fix"                                          \
            && amend_git_log="--amend=$$log_fix"                       \
            || amend_git_log=;                                         \
          $(top_srcdir)/build-aux/gitlog-to-changelog $$amend_git_log  \
            -- v$(gen_start_ver)~.. > $(distdir)/cl-t &&               \
            { printf '\n\nSee the source repo for older entries\n'     \
              >> $(distdir)/cl-t &&                                    \
              rm -f $(distdir)/ChangeLog &&                            \
              mv $(distdir)/cl-t $(distdir)/ChangeLog; }               \
        fi