[PATCH v2 11/17] build: define RELEASE_YEAR with AC_SUBST

Stefano Lattarini <[email protected]>
Newsgroups gmane.comp.sysutils.autoconf.patches
Message-ID <f8ac780d14229e99d70b46b50e3d026e2c93a6a3.1367846278.git.stefano.lattarini@gmail.com>
Rather than reading it dynamically from the ChangeLog -- that,
remember, is only a dummy in a Git checkout!  To avoid risking
the definition to get out-of-sync, let's enhance the maintainer
target 'update-copyright' to update it automatically (the same
way it's done in the Automake build system).

* configure.ac (RELEASE_YEAR): New AC_SUBST'd variable.
* cfg.mk (update-release-year): New maintainer-specific target
to automatically update the value of that variable.
(update-copyright): Depend on the new target.
* bin/local.mk (RELEASE_YEAR): Drop definition.
(edit): Simplify quoting of $(RELEASE_YEAR).
* lib/Makefile.am (RELEASE_YEAR): Drop definition.
(m4sugar/version.m4): Simplify quoting of $(RELEASE_YEAR).

Signed-off-by: Stefano Lattarini <[email protected]>
---
 bin/local.mk    |  6 +-----
 cfg.mk          | 12 ++++++++++++
 configure.ac    |  5 +++++
 lib/Makefile.am |  6 +-----
 4 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/bin/local.mk b/bin/local.mk
index 57983f8..ff7b2cf 100644
--- a/bin/local.mk
+++ b/bin/local.mk
@@ -38,10 +38,6 @@ EXTRA_DIST += \
 # Files that should be removed, but which Automake does not know.
 MOSTLYCLEANFILES += $(bin_SCRIPTS) bin/autoconf.in bin/*.tmp
 
-# Get the release year from ChangeLog.
-RELEASE_YEAR = \
-  `sed 's/^\([0-9][0-9][0-9][0-9]\).*/\1/;q' $(top_srcdir)/ChangeLog`
-
 ## ------------- ##
 ## The scripts.  ##
 ## ------------- ##
@@ -60,7 +56,7 @@ edit = sed \
 	-e 's|@M4_DEBUGFILE[@]|$(M4_DEBUGFILE)|g' \
 	-e 's|@M4_GNU[@]|$(M4_GNU)|g' \
 	-e 's|@AWK[@]|$(AWK)|g' \
-	-e 's|@RELEASE_YEAR[@]|'$(RELEASE_YEAR)'|g' \
+	-e 's|@RELEASE_YEAR[@]|$(RELEASE_YEAR)|g' \
 	-e 's|@VERSION[@]|$(VERSION)|g' \
 	-e 's|@PACKAGE_NAME[@]|$(PACKAGE_NAME)|g' \
 	-e 's|@configure_input[@]|Generated from [email protected]; do not edit by hand.|g'
diff --git a/cfg.mk b/cfg.mk
index a57196e..980eab9 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -123,6 +123,18 @@ update-copyright-env = \
   UPDATE_COPYRIGHT_USE_INTERVALS=1 \
   UPDATE_COPYRIGHT_MAX_LINE_LENGTH=72
 
+update-copyright: update-release-year
+update-release-year:
+	$(AM_V_GEN):; \
+	if test -n "$$UPDATE_COPYRIGHT_YEAR"; then \
+	   current_year=$$UPDATE_COPYRIGHT_YEAR; \
+	else \
+	  current_year=`date +%Y` && test -n "$$current_year" \
+	    || { echo "$@: cannot get current year" >&2; exit 1; }; \
+	fi; \
+	sed -i "/^RELEASE_YEAR=/s/=.*$$/=$$current_year/" configure.ac
+.PHONY: update-release-year
+
 # Prevent incorrect NEWS edits.
 old_NEWS_hash = 8532b4ed4fb456eb71071a5cf8c258d4
 
diff --git a/configure.ac b/configure.ac
index b3f3fa9..91f6a74 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,6 +27,11 @@ AC_CONFIG_AUX_DIR([build-aux])
 
 AM_INIT_AUTOMAKE([1.11 dist-xz readme-alpha no-texinfo.tex std-options])
 
+# Keep this on a line of its own, since it must be found and processed
+# by the 'update-release-year' rule in our Makefile.
+RELEASE_YEAR=2013
+AC_SUBST([RELEASE_YEAR])
+
 AB_INIT
 
 # We use '/bin/sh -n script' to check that there are no syntax errors
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 1004622..2b4c494 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -162,10 +162,6 @@ nodist_m4sugarlib_DATA = \
 
 CLEANFILES += $(nodist_m4sugarlib_DATA)
 
-# Get the release year from ../ChangeLog.
-RELEASE_YEAR = \
-  `sed 's/^\([0-9][0-9][0-9][0-9]\).*/\1/;q' $(top_srcdir)/ChangeLog`
-
 # The ':;' in the second line of the recipe works around a redirected
 # compound command bash exit status bug.
 m4sugar/version.m4: Makefile
@@ -182,7 +178,7 @@ m4sugar/version.m4: Makefile
 	  echo 'm4_define([m4_PACKAGE_STRING],    [$(PACKAGE_STRING)])' && \
 	  echo 'm4_define([m4_PACKAGE_BUGREPORT], [$(PACKAGE_BUGREPORT)])' && \
 	  echo 'm4_define([m4_PACKAGE_URL],       [$(PACKAGE_URL)])' && \
-	  echo 'm4_define([m4_PACKAGE_YEAR],      ['$(RELEASE_YEAR)'])'; \
+	  echo 'm4_define([m4_PACKAGE_YEAR],      [$(RELEASE_YEAR)])'; \
 	} > $@-t
 	mv $@-t $@
 
-- 
1.8.3.rc0.19.g7e6a0cc
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.