On Thursday 13 October 2011, Jim Meyering wrote:
> Stefano Lattarini wrote:
> > On my Debian GNU/Linux system:
> >
> >   $ cd ~/src/grep
> >   $ rm -f ChangeLog
> >   $ make dist
> >   make: *** No rule to make target `ChangeLog', needed by `distdir'.  Stop.
> >   $ make
> >     GEN    gen-ChangeLog
> >   /bin/sh: line 2: grep-2.9.63-88b2-dirty/cl-t: No such file or directory
> >   mv: cannot stat `grep-2.9.63-88b2-dirty/cl-t': No such file or directory
> >   make: *** [gen-ChangeLog] Error 1
> >
> > This could all be solved by re-creating the dummy `ChangeLog' file (a simple
> > "touch ChangeLog" is enough), but I dislike the idea that we have to create
> > an empty, dummy file in order to allow the real file to be created at "make
> > dist" time (and only then).  The attached patch tries to improve the
> > situation.  Of course, I understand that you might prefer the current setup
> > over the one my patch implements, so feel free to just reject the patch; I'm
> > sending it over anyway, in the hope you might share my preferences on this
> > matter.
> ...
> 
> Thanks for the patch.
> I like the idea, but would rather have the new rule in a separate,
> "include"d file, which would make it easier to share and keep up to date.
>
Good idea; maybe I could submit such a file to gnulib (project for which I
have a copyright assignement BTW), so that it will be even easier to share
it among the GNU projects...  For now, I will submit a "prototype" here.

> A couple of comments in-line:
> 
> > Subject: [PATCH] dist: better automatic generation of ChangeLog
> >
> > * Makefile.am (gen-ChangeLog): Removed, superseded by ...
> > (ChangeLog): ... this new .PHONY target, that takes care of
> > creating the ChangeLog in the builddir rather than in the
> > distdir.
> > (dist-hook): Don't depend on `gen-ChangeLog' anymore.
> > * bootstrap.conf: Don't generate a dummy ChangeLog file
> > anymore, it's no more needed.
> > ---
> >  Makefile.am    |   29 ++++++++++++++++++++---------
> >  bootstrap.conf |    3 ---
> >  2 files changed, 20 insertions(+), 12 deletions(-)
> >
> > diff --git a/Makefile.am b/Makefile.am
> > index a13f262..24624f3 100644
> > --- a/Makefile.am
> > +++ b/Makefile.am
> > @@ -35,15 +35,26 @@ run-syntax-check:
> >
> >  # Arrange so that .tarball-version appears only in the distribution
> >  # tarball, and never in a checked-out repository.
> > -dist-hook: gen-ChangeLog run-syntax-check
> > +dist-hook: run-syntax-check
> >     $(AM_V_GEN)echo $(VERSION) > $(distdir)/.tarball-version
> >
> >  gen_start_date = 2009-11-27
> > -.PHONY: gen-ChangeLog
> > -gen-ChangeLog:
> > -   $(AM_V_GEN)if test -d .git; then                                \
> > -     $(top_srcdir)/build-aux/gitlog-to-changelog                   \
> > -       --since=$(gen_start_date) > $(distdir)/cl-t;                \
> > -     rm -f $(distdir)/ChangeLog;                                   \
> > -     mv $(distdir)/cl-t $(distdir)/ChangeLog;                      \
> > -   fi
> > +.PHONY: ChangeLog
> > +ChangeLog:
> > +   $(AM_V_GEN)rm -f $@-t || exit 1; \
> > +   if test -d $(srcdir)/.git; then \
> > +     $(top_srcdir)/build-aux/gitlog-to-changelog \
> > +       --since=$(gen_start_date) > $@-t; \
> > +## We want to support "make dist" also from distribution tarballs.  In
> > +## case of a VPATH build, prefer any ChangeLog in the build dir to the
> > +## one in the source dir (in the spirit of VPATH).
> > +   elif test -f $@; then \
> > +     cp -f $@ $@-t; \
> > +   elif test -f $(srcdir)/'$@'; then \
> > +     cp -f $(srcdir)/'$@' $@-t; \
> 
> Why add single quotes above?
>
Leftover from a previous version, where I was "cargo-culting" to cater
for VPATH rewrites.  Anyway, this part has been rewritten in the v2 of
the patch.

> I find it more readable to align the backslashes.
> Also, if one is missing, say on a just-added line, it's far easier to spot.
>
OK, will fix the cosmetics.

> > +   else \
> > +     echo "Source tree is not a git checkout, and no" \
> > +          "pre-existent ChangeLog file has been found" >&2; \
> > +     exit 1; \
> > +   fi; \
> 
> Don't you mean this:
> 
>       fi && \
> 
> so that if any of the above fail we don't end up with
> a corrupted ChangeLog file?
>
You're right; anyway, this part too has been re-written, so this is
moot now.

Also, I've made the recipe more customizable, allowing overrides of the
build-aux directory, and allowing an empty "start date" (which will mean
"give me all the git log entries, from the root commit onwards").  I've
also tried to cater to a bug of Solaris make (the recipe of a .PHONY
target named as an existing file is *not* executed, d'oh!).  My new
attempt is attached; once it has been polished, I'll submit it to the
bug-gnulib list, and then you can start using it in grep.

Thanks,
  Stefano
From ca6d7bda4a8868265861a257d7bb5e06d1adc1c9 Mon Sep 17 00:00:00 2001
Message-Id: <ca6d7bda4a8868265861a257d7bb5e06d1adc1c9.1318521170.git.stefano.lattar...@gmail.com>
From: Stefano Lattarini <[email protected]>
Date: Mon, 10 Oct 2011 17:03:09 +0200
Subject: [PATCH] dist: better automatic generation of ChangeLog

* Makefile.am (gen-ChangeLog): Removed, superseded by ...
(include changelog-gen.mk): ... rules provided by this new
included file, ...
* changelog-gen.mk: ... imported from gnulib.
(dist-hook): Don't depend on `gen-ChangeLog' anymore.
* bootstrap.conf: Don't generate a dummy ChangeLog file
anymore, it's no more needed.
---
 Makefile.am      |   14 +++--------
 bootstrap.conf   |    3 --
 changelog-gen.mk |   64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+), 13 deletions(-)
 create mode 100644 changelog-gen.mk

diff --git a/Makefile.am b/Makefile.am
index a13f262..a35da99 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -35,15 +35,9 @@ run-syntax-check:
 
 # Arrange so that .tarball-version appears only in the distribution
 # tarball, and never in a checked-out repository.
-dist-hook: gen-ChangeLog run-syntax-check
+dist-hook: run-syntax-check
 	$(AM_V_GEN)echo $(VERSION) > $(distdir)/.tarball-version
 
-gen_start_date = 2009-11-27
-.PHONY: gen-ChangeLog
-gen-ChangeLog:
-	$(AM_V_GEN)if test -d .git; then				\
-	  $(top_srcdir)/build-aux/gitlog-to-changelog			\
-	    --since=$(gen_start_date) > $(distdir)/cl-t;		\
-	  rm -f $(distdir)/ChangeLog;					\
-	  mv $(distdir)/cl-t $(distdir)/ChangeLog;			\
-	fi
+## Automatic generation of the ChangeLog from git history.
+changelog_start_date = 2009-11-27
+include changelog-gen.mk
diff --git a/bootstrap.conf b/bootstrap.conf
index c3b7158..9bfd16c 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -98,9 +98,6 @@ XGETTEXT_OPTIONS=$XGETTEXT_OPTIONS'\\\
  --flag=error:3:c-format --flag=error_at_line:5:c-format\\\
 '
 
-# Automake requires that ChangeLog exist.
-test -f ChangeLog || touch ChangeLog || exit 1
-
 gnulib_tool_option_extras="--tests-base=$bt/gnulib-tests --with-tests"
 
 # Build prerequisites
diff --git a/changelog-gen.mk b/changelog-gen.mk
new file mode 100644
index 0000000..fbe1fdb
--- /dev/null
+++ b/changelog-gen.mk
@@ -0,0 +1,64 @@
+# -*- Makefile -*-
+#
+# Copyright 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+#
+# When executed from a git checkout, generate the ChangeLog from the git
+# history.  When executed from an extracted distribution tarball, just
+# copy the distributed ChangeLog in the build directory (and if this
+# fails, or if no distributed ChangeLog file is present, complain and
+# give and error).
+#
+# We need the apparently useless dependency from another .PHONY target
+# `gl--changelog-regen-hook' to work around a bug of Solaris make, which
+# doesn't execute the recipe of a target named as an existing file, even
+# if such target is declared `.PHONY' (yikes!)
+#
+# Variables that can influence the recipe:
+#
+#   - $(changelog_start_date): the date from which the ChangeLog entries
+#     should start (in format `YYYY-MM-DD'); if empty, the entries will
+#     start from the beginning of the git history.
+#
+#   - $(build_auxdir): the directory where the auxiliary scripts for the
+#     project are kept; defaults to `$(top_srcdir)/build-aux'.
+#
+.PHONY: gl--changelog-regen-hook
+gl--changelog-regen-hook:
+.PHONY: ChangeLog
+ChangeLog: gl--changelog-regen-hook
+	$(AM_V_GEN)set -e; set -u;					 \
+	build_auxdir=$(build_auxdir);					 \
+	test -n "$$build_auxdir"					 \
+	  || build_auxdir=$(top_srcdir)/build-aux;			 \
+	log_start_date=$(changelog_start_date);				 \
+	test -z "$$log_start_date"					 \
+	  || log_start_date="--since=$$log_start_date";			 \
+## The ChangeLog should be regenerated unconditionally when working from
+## checked-out sources; otherwise, if we're working from a distribution
+## tarball, we expect the ChangeLog to be distributed, so check that it
+## is indeed present in the source directory.
+	if test -d $(srcdir)/.git; then					 \
+	  rm -f $@-t							 \
+	    && $$build_auxdir/gitlog-to-changelog $$log_start_date >$@-t \
+	    && chmod a-w $@-t						 \
+	    && mv -f $@-t $@						 \
+	    || exit 1;							 \
+	elif test ! -f $(srcdir)/$@; then				 \
+	  echo "Source tree is not a git checkout, and no pre-existent"	 \
+	       "$@ file has been found there" >&2;			 \
+	  exit 1;							 \
+	fi
-- 
1.7.2.3

Reply via email to