19.9 gitlog-to-changelog

Gnulib has 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 can use it by extending the dist-hook rule in the top-level Makefile.am like this:

dist-hook: gen-ChangeLog
.PHONY: gen-ChangeLog
gen-ChangeLog:
        $(AM_V_GEN)if test -e $(srcdir)/.git; then             \
          LC_ALL=en_US.UTF-8 TZ=UTC0                           \
            $(top_srcdir)/build-aux/gitlog-to-changelog        \
              --srcdir=$(srcdir) > $(distdir)/ChangeLog.tmp && \
          mv -f $(distdir)/ChangeLog.tmp $(distdir)/ChangeLog; \
        fi

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

The LC_ALL=en_US.UTF-8 TZ=UTC0 line in this recipe assumes that you want to generate reproducible ChangeLog files that do not depend on the developer’s locale and time zone. Omit this line if you prefer ChangeLog files that depend on these developer settings.

If you wish to output the ChangeLog with dates respecting the time zone each individual commit was made in you can use the --commit-timezone option. For example:

dist-hook: gen-ChangeLog
.PHONY: gen-ChangeLog
gen-ChangeLog:
        $(AM_V_GEN)if test -e $(srcdir)/.git; then             \
          $(top_srcdir)/build-aux/gitlog-to-changelog          \
              --srcdir=$(srcdir) --commit-timezone             \
              > $(distdir)/ChangeLog.tmp &&                    \
          mv -f $(distdir)/ChangeLog.tmp $(distdir)/ChangeLog; \
        fi

The use of --commit-timezone means that ChangeLog dates correctly represent when a committer pushed a change according to their time zone. However, as a consequence ChangeLog dates will no longer be monotonically increasing, if the developers are spread across different time zones. For example, the following three commits were made in a short period of time across two different time zones. This behavior may be undesired.

2024-06-19  Bruno Haible  <bruno@clisp.org>

	...

2024-06-18  Collin Funk  <collin.funk1@gmail.com>

	...

2024-06-19  Bruno Haible  <bruno@clisp.org>

	...

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

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