From 8394dc6b446e745b430f880dd08fb664379cdbe0 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@redhat.com>
Date: Fri, 27 Jul 2012 12:12:42 +0200
Subject: [PATCH] maint.mk: new rule: refresh-gnulib-patches

I noticed that 8 of coreutils' 9 gl/**/*.diff files was stale.
Use this rule to refresh them.
* top/maint.mk (refresh-gnulib-patches): New rule.
---
 ChangeLog    |  7 +++++++
 top/maint.mk | 25 +++++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index c41549fdfa..22dedf407b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2012-07-27  Jim Meyering  <meyering@redhat.com>
+
+	maint.mk: new rule: refresh-gnulib-patches
+	I noticed that 8 of coreutils' 9 gl/**/*.diff files was stale.
+	Use this rule to refresh them.
+	* top/maint.mk (refresh-gnulib-patches): New rule.
+
 2012-07-24  Bruno Haible  <bruno@clisp.org>
 
 	gnulib-tool: Fix handling of inctests variable.
diff --git a/top/maint.mk b/top/maint.mk
index b39e9ae5a2..baff0e9890 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -1429,6 +1429,31 @@ gen-coverage:
 
 coverage: init-coverage build-coverage gen-coverage
 
+# Some projects carry local adjustments for gnulib modules via patches in
+# a gnulib patch directory whose default name is gl/ (defined in bootstrap
+# via local_gl_dir=gl).  Those patches become stale as the originals evolve
+# in gnulib.  Use this rule to refresh any stale patches.  It applies each
+# patch to the original in $(gnulib_dir) and uses the temporary result to
+# generate a fuzz-free .diff file.  If you customize the name of your local
+# gnulib patch directory via bootstrap.conf, this rule detects that name.
+# Run this from a non-VPATH (i.e., srcdir) build directory.
+.PHONY: refresh-gnulib-patches
+refresh-gnulib-patches:
+	gl=gl;								\
+	if test -f bootstrap.conf; then					\
+	  t=$$(perl -lne '/^\s*local_gl_dir=(\S+)/ and $$d=$$1;'	\
+	       -e 'END{defined $$d and print $$d}' bootstrap.conf);	\
+	  test -n "$$t" && gl=$$t;					\
+	fi;								\
+	for diff in $$(cd $$gl; git ls-files | grep '\.diff$$'); do	\
+	  b=$$(printf %s "$$diff"|sed 's/\.diff$$//');			\
+	  VERSION_CONTROL=none						\
+	    patch "$(gnulib_dir)/$$b" "$$gl/$$diff" || exit 1;		\
+	  ( cd $(gnulib_dir) || exit 1;					\
+	    git diff "$$b" > "../$$gl/$$diff";				\
+	    git checkout $$b ) || exit 1;				\
+	done
+
 # Update gettext files.
 PACKAGE ?= $(shell basename $(PWD))
 PO_DOMAIN ?= $(PACKAGE)
-- 
2.39.5