1# ===============================================================================
2#     http://www.gnu.org/software/autoconf-archive/ax_generate_changelog.html
3# ===============================================================================
4#
5# SYNOPSIS
6#
7#   AX_GENERATE_CHANGELOG()
8#
9# DESCRIPTION
10#
11#   Builds a rule for generating a ChangeLog file from version control system
12#   commit messages.  Currently, the only supported VCS is git, but support
13#   for others could be added in future.
14#
15#   Defines GENERATE_CHANGELOG_RULES which should be substituted in your
16#   Makefile.
17#
18#   Usage example:
19#
20#   configure.ac:
21#
22#     AX_GENERATE_CHANGELOG
23#
24#   Makefile.am:
25#
26#     @GENERATE_CHANGELOG_RULES@
27#     CHANGELOG_START = 0.2.3^
28#     dist-hook: dist-ChangeLog
29#
30#   ChangeLog (stub committed to VCS):
31#
32#     The ChangeLog is auto-generated when releasing.
33#     If you are seeing this, use 'git log' for a detailed list of changes.
34#
35#   This results in a "dist-ChangeLog" rule being added to the Makefile.
36#   When run, "dist-ChangeLog" will generate a ChangeLog in the
37#   $(top_distdir), using $(CHANGELOG_GIT_FLAGS) to format the output from
38#   "git log" being run in $(CHANGELOG_GIT_DIR).
39#
40#   Unless Automake is initialised with the 'foreign' option, a dummy
41#   ChangeLog file must be committed to VCS in $(top_srcdir), containing the
42#   text above (for example).  It will be substituted by the automatically
43#   generated ChangeLog during "make dist".
44#
45# LICENSE
46#
47#   Copyright (c) 2015 David King <amigadave@amigadave.com>
48#   Copyright (c) 2015 Philip Withnall <philip.withnall@collabora.co.uk>
49#
50#   Copying and distribution of this file, with or without modification, are
51#   permitted in any medium without royalty provided the copyright notice
52#   and this notice are preserved.  This file is offered as-is, without any
53#   warranty.
54
55#serial 1
56
57AC_DEFUN([AX_GENERATE_CHANGELOG],[
58	# Find git, defaulting to the 'missing' script so the user gets a nice
59	# message if git is missing, rather than a plain 'command not found'.
60	AC_PATH_PROG([GIT],[git],[${am_missing_run}git])
61	AC_SUBST([GIT])
62
63	# Build the ChangeLog rules.
64	m4_pattern_allow([AM_V_GEN])
65GENERATE_CHANGELOG_RULES='
66# Generate ChangeLog
67#
68# Optional:
69#  - CHANGELOG_START: git commit ID or tag name to output changelogs from
70#    (exclusive). (Default: include all commits)
71#  - CHANGELOG_GIT_FLAGS: General flags to pass to git-log when generating the
72#    ChangeLog. (Default: various)
73#  - CHANGELOG_GIT_DIR: .git directory to use. (Default: $(top_srcdir)/.git)
74
75# git-specific
76CHANGELOG_GIT_FLAGS ?= --stat -M -C --name-status --no-color
77CHANGELOG_GIT_DIR ?= $(top_srcdir)/.git
78
79ifeq ($(CHANGELOG_START),)
80CHANGELOG_GIT_RANGE =
81else
82CHANGELOG_GIT_RANGE = $(CHANGELOG_START)..
83endif
84
85# Generate a ChangeLog in $(top_distdir)
86dist-ChangeLog:
87	$(AM_V_GEN)if $(GIT) \
88		--git-dir=$(CHANGELOG_GIT_DIR) --work-tree=$(top_srcdir) log \
89		$(CHANGELOG_GIT_FLAGS) $(CHANGELOG_GIT_RANGE) \
90		| fmt --split-only >.ChangeLog.tmp; \
91	then mv -f .ChangeLog.tmp "$(top_distdir)/ChangeLog"; \
92	else rm -f .ChangeLog.tmp; exit 1; fi
93
94.PHONY: dist-ChangeLog
95'
96
97	AC_SUBST([GENERATE_CHANGELOG_RULES])
98	m4_ifdef([_AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE([GENERATE_CHANGELOG_RULES])])
99])
100