The previous patch introduced some code duplication.  This patch takes 
care of removing (part of) such duplication, by adding a new *.am 
makefile fragment to be included by the relevant Makefiles.am
From 6dc1a373b889e484d979ce7a1107ec9a26a2ee0e Mon Sep 17 00:00:00 2001
From: Stefano Lattarini <[email protected]>
Date: Sat, 30 Jan 2010 01:57:12 +0100
Subject: [PATCH 2/3] Maint-check: refactoring to avoid code duplication

The recent extension of the `maintainer-check' target (to include
checks on the consistency of the list of test scripts) has
introduced some code duplication.  This commit takes care of
removing (part of) such duplication.

* CheckListOfTests.am: New file.
(maintainer-check-list-of-tests): New target, mostly copied
from the equally-named rule in the previous version of file
`tests/Makefile.am'.
(clean-maintcheck-testslist-tmp): New rule, to clean up the
temporary files that might be left around by the previous rule.
(clean-local): Depend on it.
* tests/Makefile.am: Include `CheckListOfTests.am'.
(maintainer-check-list-of-tests): Removed associated rules,
they're defined in included file `CheckListOfTests.am'.
(TEST_EXTENSIONS): New, define to `.test'.
(MOSTLYCLEANFILES): Definition removed, no more needed.
* lib/Automake/tests/Makefile.am: Include `CheckListOfTests.am'.
Bump copyright years.
(maintainer-check-list-of-tests): Removed, it's defined in
included file `CheckListOfTests.am'.
(MOSTLYCLEANFILES): Definition removed, no more needed.
---
 ChangeLog                      |   25 ++++++++++++++
 CheckListOfTests.am            |   71 ++++++++++++++++++++++++++++++++++++++++
 lib/Automake/tests/Makefile.am |   42 +-----------------------
 lib/Automake/tests/Makefile.in |   52 +++++++++++++++++------------
 tests/Makefile.am              |   43 ++----------------------
 tests/Makefile.in              |   42 +++++++++++++++--------
 6 files changed, 158 insertions(+), 117 deletions(-)
 create mode 100644 CheckListOfTests.am

diff --git a/ChangeLog b/ChangeLog
index 292aff2..b69037b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,30 @@
 2009-01-30  Stefano Lattarini  <[email protected]>
 
+	Maint-check: refactoring in makefiles, to avoid code duplication.
+	The recent extension of the `maintainer-check' target (to include
+	checks on the consistency of the list of test scripts) has
+	introduced some code duplication.  This change takes care of
+	removing (part of) such duplication.
+	* CheckListOfTests.am: New file.
+	(maintainer-check-list-of-tests): New target, mostly copied
+	from the equally-named rule in the previous version of file
+	`tests/Makefile.am'.
+	(clean-maintcheck-testslist-tmp): New rule, to clean up the
+	temporary files that might be left around by the previous rule.
+	(clean-local): Depend on it.
+	* tests/Makefile.am: Include `CheckListOfTests.am'.
+	(maintainer-check-list-of-tests): Removed associated rules,
+	they're defined in included file `CheckListOfTests.am'.
+	(TEST_EXTENSIONS): New, define to `.test'.
+	(MOSTLYCLEANFILES): Definition removed, no more needed.
+	* lib/Automake/tests/Makefile.am: Include `CheckListOfTests.am'.
+	Bump copyright years.
+	(maintainer-check-list-of-tests): Removed, it's defined in
+	included file `CheckListOfTests.am'.
+	(MOSTLYCLEANFILES): Definition removed, no more needed.
+
+2009-01-30  Stefano Lattarini  <[email protected]>
+
 	Maint-check: check consistency of list of test scripts.
 	* Makefile.am (maintainer-check-list-of-tests): New target.
 	(maintainer-check): Added dependency from new target
diff --git a/CheckListOfTests.am b/CheckListOfTests.am
new file mode 100644
index 0000000..40e1e05
--- /dev/null
+++ b/CheckListOfTests.am
@@ -0,0 +1,71 @@
+## -*- Automake -*-
+##
+## Copyright (C) 2010 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 2, 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/>.
+##
+
+## temporary files used in the `check-list-of-tests' target
+tmk = tests-in-makefile-list.tmp
+tfs = tests-on-filesystem-list.tmp
+tdf = diff-in-tests-lists.tmp
+
+## Check that the list of tests given in the Makefile is equal to the
+## list of all test scripts in the Automake testsuite.
+.PHONY: maintainer-check-list-of-tests
+maintainer-check-list-of-tests:
+	 ## prefer unified diffs over plain diffs, for readability
+	 @if diff -u /dev/null /dev/null >/dev/null 2>&1; then \
+	   diff='diff -u'; \
+	 else \
+	   diff='diff'; \
+	 fi; \
+	 ## determine which files are to be considered test scripts
+	 set X $(TEST_EXTENSIONS); shift; \
+	 if test $$# -eq 0; then \
+	   echo '$@: INTERNAL ERROR: $$(TEST_EXTENSIONS) undefined' \
+	        'or empty' >&2; \
+	   exit 255; \
+	 fi; \
+	 shift $$#; \
+	 ## list of tests in Makefile
+	 for t in $(TESTS); do \
+	   echo "$$t"; \
+	 done | sort >$(tmk); \
+	 ## list of tests on filesystem
+	 for suf in $(TEST_EXTENSIONS); do \
+	   glob="$(srcdir)/*$$suf"; \
+	   if test x"$(srcdir)" != x"$(builddir)"; then \
+	     glob="$$glob $(builddir)/*$$suf"; \
+	   fi; \
+	 done; \
+	 for t in $$glob; do \
+	   echo "$$t"; \
+	 done | sed 's,^.*/,,' | sort >$(tfs); \
+	 ## compare the two lists
+	 if $$diff $(tmk) $(tfs) >$(tdf); then \
+	    e=0; \
+	 else \
+	    echo '$@: list of tests in Makefile an on filesystem differ' >&2; \
+	    echo "+ $$diff in-makefile on-filesystem" >&2; \
+	    cat $(tdf) >&2; \
+	    e=1; \
+	 fi; \
+	 rm -f $(tmk) $(tfs) $(tdf); \
+	 exit $$e;
+
+.PHONY: clean-maintcheck-testslist-tmp
+clean-local: clean-maintcheck-testslist-tmp
+clean-maintcheck-testslist-tmp:
+	rm -f $(tmk) $(tfs) $(tdf)
diff --git a/lib/Automake/tests/Makefile.am b/lib/Automake/tests/Makefile.am
index 4597b48..e0f27b4 100644
--- a/lib/Automake/tests/Makefile.am
+++ b/lib/Automake/tests/Makefile.am
@@ -44,44 +44,4 @@ Version3.pl
 
 EXTRA_DIST = $(TESTS)
 
-## temporary files used in the `check-list-of-tests' target
-tmk = tests-in-makefile-list.tmp
-tfs = tests-on-filesystem-list.tmp
-tdf = diff-in-tests-lists.tmp
-
-MOSTLYCLEANFILES = $(tmk) $(tfs) $(tdf)
-
-# Check that the list of tests given in the Makefile is equal to the
-# list of all test scripts in the Automake testsuite.
-maintainer-check-list-of-tests:
-	@:; \
-	 ## prefer unified diffs over plain diffs, for readability
-	 if diff -u /dev/null /dev/null >/dev/null 2>&1; then \
-	   diff='diff -u'; \
-	 else \
-	   diff='diff'; \
-	 fi; \
-	 ## list of tests in Makefile
-	 for t in $(TESTS); do \
-	   echo "$$t"; \
-	 done | sort >$(tmk); \
-	 ## list of tests on filesystem
-	 glob="$(srcdir)/*.pl"; \
-	 if test x"$(srcdir)" != x"$(builddir)"; then \
-	   glob="$$glob $(builddir)/*.pl"; \
-	 fi; \
-	 for t in $$glob; do \
-	   echo "$$t"; \
-	 done | sed 's,^.*/,,' | sort >$(tfs); \
-	 ## compare the two lists
-	 if $$diff $(tmk) $(tfs) >$(tdf); then \
-	    e=0; \
-	 else \
-	    echo '$@: list of tests in Makefile an on filesystem differ' >&2; \
-	    echo "+ $$diff in-makefile on-filesystem" >&2; \
-	    cat $(tdf) >&2; \
-	    e=1; \
-	 fi; \
-	 rm -f $(tmk) $(tfs) $(tdf); \
-	 exit $$e;
-.PHONY: maintainer-check-list-of-tests
+include ../../../CheckListOfTests.am
diff --git a/lib/Automake/tests/Makefile.in b/lib/Automake/tests/Makefile.in
index b1c837f..6a9beae 100644
--- a/lib/Automake/tests/Makefile.in
+++ b/lib/Automake/tests/Makefile.in
@@ -48,8 +48,9 @@ NORMAL_UNINSTALL = :
 PRE_UNINSTALL = :
 POST_UNINSTALL = :
 build_triplet = @build@
+DIST_COMMON = $(srcdir)/../../../CheckListOfTests.am \
+	$(srcdir)/Makefile.am $(srcdir)/Makefile.in
 subdir = lib/Automake/tests
-DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/m4/amversion.m4 \
 	$(top_srcdir)/m4/auxdir.m4 $(top_srcdir)/m4/init.m4 \
@@ -274,12 +275,11 @@ EXTRA_DIST = $(TESTS)
 tmk = tests-in-makefile-list.tmp
 tfs = tests-on-filesystem-list.tmp
 tdf = diff-in-tests-lists.tmp
-MOSTLYCLEANFILES = $(tmk) $(tfs) $(tdf)
 all: all-am
 
 .SUFFIXES:
 .SUFFIXES: .html .log .pl
-$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am $(srcdir)/../../../CheckListOfTests.am $(am__configure_deps)
 	@for dep in $?; do \
 	  case '$(am__configure_deps)' in \
 	    *$$dep*) \
@@ -523,7 +523,6 @@ install-strip:
 	  `test -z '$(STRIP)' || \
 	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
 mostlyclean-generic:
-	-test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES)
 	-test -z "$(TEST_LOGS)" || rm -f $(TEST_LOGS)
 	-test -z "$(TEST_LOGS_TMP)" || rm -f $(TEST_LOGS_TMP)
 	-test -z "$(TEST_SUITE_HTML)" || rm -f $(TEST_SUITE_HTML)
@@ -540,7 +539,7 @@ maintainer-clean-generic:
 	@echo "it deletes files that may require special tools to rebuild."
 clean: clean-am
 
-clean-am: clean-generic mostlyclean-am
+clean-am: clean-generic clean-local mostlyclean-am
 
 distclean: distclean-am
 	-rm -f Makefile
@@ -608,33 +607,40 @@ uninstall-am:
 	recheck-html
 
 .PHONY: all all-am check check-TESTS check-am check-html clean \
-	clean-generic distclean distclean-generic distdir dvi dvi-am \
-	html html-am info info-am install install-am install-data \
-	install-data-am install-dvi install-dvi-am install-exec \
-	install-exec-am install-html install-html-am install-info \
-	install-info-am install-man install-pdf install-pdf-am \
-	install-ps install-ps-am install-strip installcheck \
-	installcheck-am installdirs maintainer-clean \
+	clean-generic clean-local distclean distclean-generic distdir \
+	dvi dvi-am html html-am info info-am install install-am \
+	install-data install-data-am install-dvi install-dvi-am \
+	install-exec install-exec-am install-html install-html-am \
+	install-info install-info-am install-man install-pdf \
+	install-pdf-am install-ps install-ps-am install-strip \
+	installcheck installcheck-am installdirs maintainer-clean \
 	maintainer-clean-generic mostlyclean mostlyclean-generic pdf \
 	pdf-am ps ps-am recheck recheck-html uninstall uninstall-am
 
 
-# Check that the list of tests given in the Makefile is equal to the
-# list of all test scripts in the Automake testsuite.
+.PHONY: maintainer-check-list-of-tests
 maintainer-check-list-of-tests:
-	@:; \
-	 if diff -u /dev/null /dev/null >/dev/null 2>&1; then \
+	 @if diff -u /dev/null /dev/null >/dev/null 2>&1; then \
 	   diff='diff -u'; \
 	 else \
 	   diff='diff'; \
 	 fi; \
+	 set X $(TEST_EXTENSIONS); shift; \
+	 if test $$# -eq 0; then \
+	   echo '$@: INTERNAL ERROR: $$(TEST_EXTENSIONS) undefined' \
+	        'or empty' >&2; \
+	   exit 255; \
+	 fi; \
+	 shift $$#; \
 	 for t in $(TESTS); do \
 	   echo "$$t"; \
 	 done | sort >$(tmk); \
-	 glob="$(srcdir)/*.pl"; \
-	 if test x"$(srcdir)" != x"$(builddir)"; then \
-	   glob="$$glob $(builddir)/*.pl"; \
-	 fi; \
+	 for suf in $(TEST_EXTENSIONS); do \
+	   glob="$(srcdir)/*$$suf"; \
+	   if test x"$(srcdir)" != x"$(builddir)"; then \
+	     glob="$$glob $(builddir)/*$$suf"; \
+	   fi; \
+	 done; \
 	 for t in $$glob; do \
 	   echo "$$t"; \
 	 done | sed 's,^.*/,,' | sort >$(tfs); \
@@ -648,7 +654,11 @@ maintainer-check-list-of-tests:
 	 fi; \
 	 rm -f $(tmk) $(tfs) $(tdf); \
 	 exit $$e;
-.PHONY: maintainer-check-list-of-tests
+
+.PHONY: clean-maintcheck-testslist-tmp
+clean-local: clean-maintcheck-testslist-tmp
+clean-maintcheck-testslist-tmp:
+	rm -f $(tmk) $(tfs) $(tdf)
 
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 30bbe20..4ce9955 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -38,6 +38,8 @@ MAINTAINERCLEANFILES = $(parallel_tests)
 defs-p: defs Makefile.am
 	$(AM_V_GEN)sed 's,^AM_INIT_AUTOMAKE$$,&([parallel-tests]),' < defs >$@
 
+TEST_EXTENSIONS = .test
+
 TESTS =	\
 aclibobj.test \
 aclocal.test \
@@ -772,47 +774,8 @@ $(parallel_tests)
 
 EXTRA_DIST = ChangeLog-old gen-parallel-tests $(TESTS)
 
-## temporary files used in the `check-list-of-tests' target
-tmk = tests-in-makefile-list.tmp
-tfs = tests-on-filesystem-list.tmp
-tdf = diff-in-tests-lists.tmp
-
-MOSTLYCLEANFILES = $(tmk) $(tfs) $(tdf)
-
-# Check that the list of tests given in the Makefile is equal to the
-# list of all test scripts in the Automake testsuite.
+include ../CheckListOfTests.am
 maintainer-check-list-of-tests: $(parallel_tests)
-	@:; \
-	 ## prefer unified diffs over plain diffs, for readability
-	 if diff -u /dev/null /dev/null >/dev/null 2>&1; then \
-	   diff='diff -u'; \
-	 else \
-	   diff='diff'; \
-	 fi; \
-	 ## list of tests in Makefile
-	 for t in $(TESTS); do \
-	   echo "$$t"; \
-	 done | sort >$(tmk); \
-	 ## list of tests on filesystem
-	 glob="$(srcdir)/*.test"; \
-	 if test x"$(srcdir)" != x"$(builddir)"; then \
-	   glob="$$glob $(builddir)/*.test"; \
-	 fi; \
-	 for t in $$glob; do \
-	   echo "$$t"; \
-	 done | sed 's,^.*/,,' | sort >$(tfs); \
-	 ## compare the two lists
-	 if $$diff $(tmk) $(tfs) >$(tdf); then \
-	    e=0; \
-	 else \
-	    echo '$@: list of tests in Makefile an on filesystem differ' >&2; \
-	    echo "+ $$diff in-makefile on-filesystem" >&2; \
-	    cat $(tdf) >&2; \
-	    e=1; \
-	 fi; \
-	 rm -f $(tmk) $(tfs) $(tdf); \
-	 exit $$e;
-.PHONY: maintainer-check-list-of-tests
 
 # Each test case depends on defs, aclocal, and automake.
 check_SCRIPTS = defs defs-p aclocal-$(APIVERSION) automake-$(APIVERSION)
diff --git a/tests/Makefile.in b/tests/Makefile.in
index 301d735..0b8ee7b 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -48,7 +48,8 @@ NORMAL_UNINSTALL = :
 PRE_UNINSTALL = :
 POST_UNINSTALL = :
 build_triplet = @build@
-DIST_COMMON = README $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
+DIST_COMMON = README $(srcdir)/../CheckListOfTests.am \
+	$(srcdir)/Makefile.am $(srcdir)/Makefile.in \
 	$(srcdir)/aclocal.in $(srcdir)/automake.in $(srcdir)/defs.in \
 	$(srcdir)/parallel-tests.am
 subdir = tests
@@ -151,7 +152,6 @@ RECHECK_LOGS = $(TEST_LOGS)
 AM_RECURSIVE_TARGETS = check check-html recheck recheck-html
 TEST_SUITE_LOG = test-suite.log
 TEST_SUITE_HTML = $(TEST_SUITE_LOG:.log=.html)
-TEST_EXTENSIONS = .test
 am__test_logs1 = $(TESTS:=.log)
 TEST_LOGS = $(am__test_logs1:.test.log=.log)
 TEST_LOG_COMPILE = $(TEST_LOG_COMPILER) $(AM_TEST_LOG_FLAGS) \
@@ -279,6 +279,7 @@ pr401b-p.test \
 pr401c-p.test
 
 MAINTAINERCLEANFILES = $(parallel_tests)
+TEST_EXTENSIONS = .test
 TESTS = \
 aclibobj.test \
 aclocal.test \
@@ -1015,7 +1016,6 @@ EXTRA_DIST = ChangeLog-old gen-parallel-tests $(TESTS)
 tmk = tests-in-makefile-list.tmp
 tfs = tests-on-filesystem-list.tmp
 tdf = diff-in-tests-lists.tmp
-MOSTLYCLEANFILES = $(tmk) $(tfs) $(tdf)
 
 # Each test case depends on defs, aclocal, and automake.
 check_SCRIPTS = defs defs-p aclocal-$(APIVERSION) automake-$(APIVERSION)
@@ -1023,7 +1023,7 @@ all: all-am
 
 .SUFFIXES:
 .SUFFIXES: .html .log .test
-$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am $(srcdir)/parallel-tests.am $(am__configure_deps)
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am $(srcdir)/parallel-tests.am $(srcdir)/../CheckListOfTests.am $(am__configure_deps)
 	@for dep in $?; do \
 	  case '$(am__configure_deps)' in \
 	    *$$dep*) \
@@ -1274,7 +1274,6 @@ install-strip:
 	  `test -z '$(STRIP)' || \
 	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
 mostlyclean-generic:
-	-test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES)
 	-test -z "$(TEST_LOGS)" || rm -f $(TEST_LOGS)
 	-test -z "$(TEST_LOGS_TMP)" || rm -f $(TEST_LOGS_TMP)
 	-test -z "$(TEST_SUITE_HTML)" || rm -f $(TEST_SUITE_HTML)
@@ -1382,22 +1381,29 @@ $(parallel_tests): $(parallel_tests:-p.test=.test) Makefile.am
 defs-p: defs Makefile.am
 	$(AM_V_GEN)sed 's,^AM_INIT_AUTOMAKE$$,&([parallel-tests]),' < defs >$@
 
-# Check that the list of tests given in the Makefile is equal to the
-# list of all test scripts in the Automake testsuite.
-maintainer-check-list-of-tests: $(parallel_tests)
-	@:; \
-	 if diff -u /dev/null /dev/null >/dev/null 2>&1; then \
+.PHONY: maintainer-check-list-of-tests
+maintainer-check-list-of-tests:
+	 @if diff -u /dev/null /dev/null >/dev/null 2>&1; then \
 	   diff='diff -u'; \
 	 else \
 	   diff='diff'; \
 	 fi; \
+	 set X $(TEST_EXTENSIONS); shift; \
+	 if test $$# -eq 0; then \
+	   echo '$@: INTERNAL ERROR: $$(TEST_EXTENSIONS) undefined' \
+	        'or empty' >&2; \
+	   exit 255; \
+	 fi; \
+	 shift $$#; \
 	 for t in $(TESTS); do \
 	   echo "$$t"; \
 	 done | sort >$(tmk); \
-	 glob="$(srcdir)/*.test"; \
-	 if test x"$(srcdir)" != x"$(builddir)"; then \
-	   glob="$$glob $(builddir)/*.test"; \
-	 fi; \
+	 for suf in $(TEST_EXTENSIONS); do \
+	   glob="$(srcdir)/*$$suf"; \
+	   if test x"$(srcdir)" != x"$(builddir)"; then \
+	     glob="$$glob $(builddir)/*$$suf"; \
+	   fi; \
+	 done; \
 	 for t in $$glob; do \
 	   echo "$$t"; \
 	 done | sed 's,^.*/,,' | sort >$(tfs); \
@@ -1411,7 +1417,13 @@ maintainer-check-list-of-tests: $(parallel_tests)
 	 fi; \
 	 rm -f $(tmk) $(tfs) $(tdf); \
 	 exit $$e;
-.PHONY: maintainer-check-list-of-tests
+
+.PHONY: clean-maintcheck-testslist-tmp
+clean-local: clean-maintcheck-testslist-tmp
+clean-maintcheck-testslist-tmp:
+	rm -f $(tmk) $(tfs) $(tdf)
+
+maintainer-check-list-of-tests: $(parallel_tests)
 
 clean-local: clean-local-check
 .PHONY: clean-local-check
-- 
1.6.5

Reply via email to