maintcheck: refactor rules checking '*.am' files
[platform/upstream/automake.git] / Makefile.am
1 ## Process this file with automake to create Makefile.in
2
3 ## Makefile for Automake.
4
5 # Copyright (C) 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004,
6 # 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software
7 # Foundation, Inc.
8
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2, or (at your option)
12 # any later version.
13
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18
19 # You should have received a copy of the GNU General Public License
20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
22 ## lib goes first, because it builds Config.pm, used by aclocal and
23 ## automake (run in doc, tests, and in the rebuild rules.)
24 ## `.' goes before doc and tests, because the latter two directories
25 ## run aclocal and automake.
26 SUBDIRS = lib . contrib doc m4 tests
27
28 bin_SCRIPTS = automake aclocal
29
30 CLEANFILES = $(bin_SCRIPTS)
31 AUTOMAKESOURCES = automake.in aclocal.in
32
33 TAGS_FILES = $(AUTOMAKESOURCES)
34
35 EXTRA_DIST = \
36   HACKING \
37   ChangeLog.96 \
38   ChangeLog.98 \
39   ChangeLog.00 \
40   ChangeLog.01 \
41   ChangeLog.02 \
42   ChangeLog.03 \
43   ChangeLog.04 \
44   ChangeLog.09 \
45   ChangeLog.11 \
46   bootstrap \
47   $(AUTOMAKESOURCES)
48
49 ## Make versioned links.  We only run the transform on the root name;
50 ## then we make a versioned link with the transformed base name.  This
51 ## seemed like the most reasonable approach.
52 install-exec-hook:
53         @$(POST_INSTALL)
54         @for p in $(bin_SCRIPTS); do \
55           f="`echo $$p|sed '$(transform)'`"; \
56           fv="$$f-$(APIVERSION)"; \
57           rm -f $(DESTDIR)$(bindir)/$$fv; \
58           echo " $(LN) $(DESTDIR)$(bindir)/$$f $(DESTDIR)$(bindir)/$$fv"; \
59           $(LN) $(DESTDIR)$(bindir)/$$f $(DESTDIR)$(bindir)/$$fv; \
60         done
61
62 uninstall-hook:
63         @for p in $(bin_SCRIPTS); do \
64           f="`echo $$p|sed '$(transform)'`"; \
65           fv="$$f-$(APIVERSION)"; \
66           rm -f $(DESTDIR)$(bindir)/$$fv; \
67         done
68
69
70 ## We can't use configure to do the substitution here; we must do it
71 ## by hand.  We use a funny notation here to avoid configure
72 ## substitutions in our text.
73 do_subst = sed \
74   -e 's,[@]APIVERSION[@],$(APIVERSION),g' \
75   -e 's,[@]PACKAGE[@],$(PACKAGE),g' \
76   -e 's,[@]PACKAGE_BUGREPORT[@],$(PACKAGE_BUGREPORT),g' \
77   -e 's,[@]PACKAGE_URL[@],$(PACKAGE_URL),g' \
78   -e 's,[@]PATH_SEPARATOR[@],$(PATH_SEPARATOR),g' \
79   -e 's,[@]PERL[@],$(PERL),g' \
80   -e 's,[@]PERL_THREADS[@],$(PERL_THREADS),g' \
81   -e 's,[@]SHELL[@],$(SHELL),g' \
82   -e 's,[@]am_AUTOCONF[@],$(am_AUTOCONF),g' \
83   -e 's,[@]am_AUTOM4TE[@],$(am_AUTOM4TE),g' \
84   -e 's,[@]VERSION[@],$(VERSION),g' \
85   -e 's,[@]configure_input[@],Generated from $@.in; do not edit by hand.,g' \
86   -e 's,[@]datadir[@],$(datadir),g'
87
88 ## These files depend on Makefile so they are rebuilt if $(VERSION),
89 ## $(datadir) or other do_subst'ituted variables change.
90 ## Use chmod a-w to prevent people from editing the wrong file by accident.
91 automake: automake.in
92 aclocal: aclocal.in
93 automake aclocal: Makefile
94         $(AM_V_at)rm -f $@ $@-t
95         $(AM_V_GEN)$(do_subst) $(srcdir)/$@.in >$@-t
96         $(AM_V_at)chmod a+x,a-w $@-t && mv -f $@-t $@
97
98 ## The master location for INSTALL is lib/INSTALL.
99 ## This is where `make fetch' will install new versions.
100 ## Make sure we also update this copy.
101 INSTALL: lib/INSTALL
102         $(AM_V_GEN)cp $(srcdir)/lib/INSTALL $@
103
104 # Run the testsuite with the installed aclocal and automake.
105 installcheck-local:
106         am_running_installcheck=yes $(MAKE) $(AM_MAKEFLAGS) check
107
108 # Convenience proxy target for the test suites.
109 recheck:
110         $(am__cd) tests && $(MAKE) $(AM_MAKEFLAGS) $@
111 .PHONY: recheck
112
113 ################################################################
114 ##
115 ## Everything past here is useful to the maintainer, but probably not
116 ## to anybody else
117 ##
118
119 gitlog_to_changelog_command = $(PERL) $(srcdir)/lib/gitlog-to-changelog
120 gitlog_to_changelog_options = --since='2011-12-28 00:00:00' \
121                               --no-cluster --format '%s%n%n%b'
122
123 # Automatic generation of the ChangeLog from git history.
124 #
125 # When executed from a git checkout, generate the ChangeLog from the git
126 # history.  When executed from an extracted distribution tarball, just
127 # copy the distributed ChangeLog in the build directory (and if this
128 # fails, or if no distributed ChangeLog file is present, complain and
129 # give an error).
130 #
131 # We need the apparently useless dependency from another .PHONY target
132 # `am--changelog-regen-hook' to work around a bug of Solaris make, which
133 # doesn't execute the recipe of a target named as an existing file, even
134 # if such target is declared `.PHONY' (yikes!)
135 #
136 .PHONY: am--changelog-regen-hook
137 am--changelog-regen-hook:
138 ChangeLog: am--changelog-regen-hook
139         $(AM_V_GEN)set -e; set -u; \
140 ## The ChangeLog should be regenerated unconditionally when working from
141 ## checked-out sources; otherwise, if we're working from a distribution
142 ## tarball, we expect the ChangeLog to be distributed, so check that it
143 ## is indeed present in the source directory.
144         if test -d $(srcdir)/.git; then \
145           rm -f $@-t \
146             && $(gitlog_to_changelog_command) \
147                $(gitlog_to_changelog_options) >$@-t \
148             && chmod a-w $@-t \
149             && mv -f $@-t $@ \
150             || exit 1; \
151         elif test ! -f $(srcdir)/$@; then \
152           echo "Source tree is not a git checkout, and no pre-existent" \
153                "$@ file has been found there" >&2; \
154           exit 1; \
155         fi
156
157 # Ensure tests are world-executable
158 dist-hook:
159         $(am__cd) $(distdir)/tests && chmod a+rx *.test
160
161
162 # Perl coverage statistics.
163 PERL_COVERAGE_DB = $(abs_top_builddir)/cover_db
164 PERL_COVERAGE_FLAGS = -MDevel::Cover=-db,$(PERL_COVERAGE_DB),-silent,on,-summary,off
165 PERL_COVER = cover
166
167 check-coverage-run recheck-coverage-run: all
168         $(mkinstalldirs) $(PERL_COVERAGE_DB)
169         PERL5OPT="$$PERL5OPT $(PERL_COVERAGE_FLAGS)"; export PERL5OPT; \
170         WANT_NO_THREADS=yes; export WANT_NO_THREADS; unset AUTOMAKE_JOBS; \
171         $(MAKE) $(AM_MAKEFLAGS) `echo $@ | sed 's/-coverage-run//'`
172
173 check-coverage-report:
174         @if test ! -d "$(PERL_COVERAGE_DB)"; then \
175           echo "No coverage database found in \`$(PERL_COVERAGE_DB)'." >&2; \
176           echo "Please run \`make check-coverage' first" >&2; \
177           exit 1; \
178         fi
179         $(PERL_COVER) $(PERL_COVER_FLAGS) "$(PERL_COVERAGE_DB)"
180
181 # We don't use direct dependencies here because we'd like to be able
182 # to invoke the report even after interrupted check-coverage.
183 check-coverage: check-coverage-run
184         $(MAKE) $(AM_MAKEFLAGS) check-coverage-report
185
186 recheck-coverage: recheck-coverage-run
187         $(MAKE) $(AM_MAKEFLAGS) check-coverage-report
188
189 clean-coverage:
190         rm -rf "$(PERL_COVERAGE_DB)"
191 clean-local: clean-coverage
192
193 .PHONY: check-coverage recheck-coverage check-coverage-run \
194         recheck-coverage-run check-coverage-report clean-coverage
195
196 # We also have to take into account VPATH builds (where some generated
197 # tests might be in `$(builddir)' rather than in `$(srcdir)'), TAP-based
198 # tests script (which have a `.tap' extension) and helper scripts used
199 # by other test cases (which have a `.sh' extension).
200 xtests = \
201   `if test $(srcdir) = .; then \
202      dirs=.; \
203    else \
204      dirs='$(srcdir) .'; \
205    fi; \
206    for d in $$dirs; do \
207      for s in test tap sh; do \
208        ls $$d/tests/*.$$s 2>/dev/null; \
209      done; \
210    done | sort`
211
212 ams = `find $(srcdir) -name '*.am'`
213
214 # Some simple checks, and then ordinary check.  These are only really
215 # guaranteed to work on my machine.
216 syntax_check_rules = \
217 sc_test_names \
218 sc_diff_automake_in_automake \
219 sc_diff_aclocal_in_automake \
220 sc_perl_syntax \
221 sc_no_brace_variable_expansions \
222 sc_rm_minus_f \
223 sc_no_for_variable_in_macro \
224 sc_mkinstalldirs \
225 sc_pre_normal_post_install_uninstall \
226 sc_perl_no_undef \
227 sc_perl_no_split_regex_space \
228 sc_cd_in_backquotes \
229 sc_cd_relative_dir \
230 sc_perl_at_uscore_in_scalar_context \
231 sc_perl_local_no_parens \
232 sc_perl_local \
233 sc_AMDEP_TRUE_in_automake_in \
234 sc_tests_make_without_am_makeflags \
235 sc_tests_obsolete_variables \
236 sc_tests_plain_make \
237 sc_tests_plain_autoconf \
238 sc_tests_plain_autoupdate \
239 sc_tests_plain_automake \
240 sc_tests_plain_autom4te \
241 sc_tests_plain_autoheader \
242 sc_tests_plain_autoreconf \
243 sc_tests_here_document_format \
244 sc_tests_Exit_not_exit \
245 sc_tests_automake_fails \
246 sc_tests_plain_aclocal \
247 sc_tests_plain_perl \
248 sc_tests_required_after_defs \
249 sc_tests_tap_plan \
250 sc_tests_overriding_macros_on_cmdline \
251 sc_tests_plain_sleep \
252 sc_tests_plain_egrep_fgrep \
253 sc_tests_PATH_SEPARATOR \
254 sc_tests_logs_duplicate_prefixes \
255 sc_tests_makefile_variable_order \
256 sc_mkdir_p \
257 sc_perl_at_substs \
258 sc_unquoted_DESTDIR \
259 sc_tabs_in_texi \
260 sc_at_in_texi
261
262 $(syntax_check_rules): automake aclocal
263 maintainer-check: $(syntax_check_rules)
264 .PHONY: maintainer-check $(syntax_check_rules)
265
266 ## Check that the list of tests given in the Makefile is equal to the
267 ## list of all test scripts in the Automake testsuite.
268 .PHONY: maintainer-check-list-of-tests
269 maintainer-check-list-of-tests:
270         $(am__cd) tests && $(MAKE) $(AM_MAKEFLAGS) $@
271 maintainer-check: maintainer-check-list-of-tests
272
273 ## Look for test whose names can cause spurious failures when used as
274 ## first argument to AC_INIT (chiefly because they might contain an
275 ## m4/m4sugar builtin or macro name).
276 m4_builtins = \
277   __gnu__ \
278   __unix__ \
279   bpatsubst \
280   bregexp \
281   builtin \
282   changecom \
283   changequote \
284   changeword \
285   debugfile \
286   debugmode \
287   decr \
288   define \
289   defn \
290   divert \
291   divnum \
292   dnl \
293   dumpdef \
294   errprint \
295   esyscmd \
296   eval \
297   format \
298   ifdef \
299   ifelse \
300   include \
301   incr \
302   index \
303   indir \
304   len \
305   m4exit \
306   m4wrap \
307   maketemp \
308   mkstemp \
309   patsubst \
310   popdef \
311   pushdef \
312   regexp \
313   shift \
314   sinclude \
315   substr \
316   symbols \
317   syscmd \
318   sysval \
319   traceoff \
320   traceon \
321   translit \
322   undefine \
323   undivert
324 sc_test_names:
325         @m4_builtin_rx=`echo $(m4_builtins) | sed 's/ /|/g'`; \
326          m4_macro_rx="\\<($$m4_builtin_rx)\\>|\\<_?(A[CUMHS]|m4)_"; \
327          if { \
328            for t in $(xtests); do echo $$t; done \
329              | LC_ALL=C grep -E "$$m4_macro_rx"; \
330          }; then \
331            echo "the names of the tests above can be problematic" 1>&2; \
332            echo "Avoid test names that contain names of m4 macros" 1>&2; \
333            exit 1; \
334          fi
335
336 ## These check avoids accidental configure substitutions in the source.
337 ## There are exactly 9 lines that should be modified from automake.in to
338 ## automake, and 10 lines that should be modified from aclocal.in to
339 ## aclocal; these wors out to 32 and 34 lines of diffs, respectively.
340 sc_diff_automake_in_automake:
341         @if test `diff $(srcdir)/automake.in automake | wc -l` -ne 32; then \
342           echo "found too many diffs between automake.in and automake" 1>&2; \
343           diff -c $(srcdir)/automake.in automake; \
344           exit 1; \
345         fi
346 sc_diff_aclocal_in_aclocal:
347         @if test `diff $(srcdir)/aclocal.in aclocal | wc -l` -ne 34; then \
348           echo "found too many diffs between aclocal.in and aclocal" 1>&2; \
349           diff -c $(srcdir)/aclocal.in aclocal; \
350           exit 1; \
351         fi
352
353 ## Syntax check with default Perl (on my machine, Perl 5).
354 sc_perl_syntax:
355         @perllibdir="./lib$(PATH_SEPARATOR)$(srcdir)/lib" $(PERL) -c -w automake
356         @perllibdir="./lib$(PATH_SEPARATOR)$(srcdir)/lib" $(PERL) -c -w aclocal
357
358 ## expect no instances of '${...}'.  However, $${...} is ok, since that
359 ## is a shell construct, not a Makefile construct.
360 sc_no_brace_variable_expansions:
361         @if grep -F '$${' $(ams) | grep -F -v '$$$$'; then \
362           echo "Found too many uses of '\$${' in the lines above." 1>&2; \
363           exit 1;                               \
364         else :; fi
365
366 ## Make sure `rm' is called with `-f'.
367 sc_rm_minus_f:
368         @if grep -v '^#' $(ams) $(xtests) \
369            | grep -E '\<rm ([^-]|\-[^f ]*\>)'; \
370         then \
371           echo "Suspicious 'rm' invocation." 1>&2; \
372           exit 1;                               \
373         else :; fi
374
375 ## Never use something like `for file in $(FILES)', this doesn't work
376 ## if FILES is empty or if it contains shell meta characters (e.g. $ is
377 ## commonly used in Java filenames).
378 sc_no_for_variable_in_macro:
379         @if grep 'for .* in \$$(' $(ams); then \
380           echo 'Use "list=$$(mumble); for var in $$$$list".' 1>&2 ; \
381           exit 1; \
382         else :; fi
383
384 ## Make sure all invocations of mkinstalldirs are correct.
385 sc_mkinstalldirs:
386         @if grep -n 'mkinstalldirs' $(ams) | \
387               grep -F -v '$$(mkinstalldirs)'; then \
388           echo "Found incorrect use of mkinstalldirs in the lines above" 1>&2; \
389           exit 1; \
390         else :; fi
391
392 ## Make sure all calls to PRE/NORMAL/POST_INSTALL/UNINSTALL
393 sc_pre_normal_post_install_uninstall:
394         @if grep -E -n '\((PRE|NORMAL|POST)_(|UN)INSTALL\)' $(ams) | \
395               grep -v ':##' | grep -v ':        @\$$('; then \
396           echo "Found incorrect use of PRE/NORMAL/POST_INSTALL/UNINSTALL in the lines above" 1>&2; \
397           exit 1; \
398         else :; fi
399
400 ## We never want to use "undef", only "delete", but for $/.
401 sc_perl_no_undef:
402         @if grep -n -w 'undef ' $(srcdir)/automake.in | \
403               grep -F -v 'undef $$/'; then \
404           echo "Found undef in automake.in; use delete instead" 1>&2; \
405           exit 1; \
406         fi
407
408 ## We never want split (/ /,...), only split (' ', ...).
409 sc_perl_no_split_regex_space:
410         @if grep -n 'split (/ /' $(srcdir)/automake.in; then \
411           echo "Found bad split in the lines above." 1>&2; \
412           exit 1; \
413         fi
414
415 ## Look for cd within backquotes
416 sc_cd_in_backquotes:
417         @if grep -n '^[^#]*` *cd ' $(srcdir)/automake.in $(ams); then \
418           echo "Consider using \$$(am__cd) in the lines above." 1>&2; \
419           exit 1; \
420         fi
421
422 ## Look for cd to a relative directory (may be influenced by CDPATH).
423 ## Skip some known directories that are OK.
424 sc_cd_relative_dir:
425         @if grep -n '^[^#]*cd ' $(srcdir)/automake.in $(ams) | \
426               grep -v 'echo.*cd ' | \
427               grep -v 'am__cd =' | \
428               grep -v '^[^#]*cd [./]' | \
429               grep -v '^[^#]*cd \$$(top_builddir)' | \
430               grep -v '^[^#]*cd "\$$\$$am__cwd' | \
431               grep -v '^[^#]*cd \$$(abs' | \
432               grep -v '^[^#]*cd "\$$(DESTDIR)'; then \
433           echo "Consider using \$$(am__cd) in the lines above." 1>&2; \
434           exit 1; \
435         fi
436
437 ## Using @_ in a scalar context is most probably a programming error.
438 sc_perl_at_uscore_in_scalar_context:
439         @if grep -Hn '[^@_A-Za-z0-9][_A-Za-z0-9]*[^) ] *= *@_' $(srcdir)/automake.in; then \
440           echo "Using @_ in a scalar context in the lines above." 1>&2; \
441           exit 1; \
442         fi
443
444 ## Forbid using parens with `local' to ease counting.
445 sc_perl_local_no_parens:
446         @if grep '^[ \t]*local *(' $(srcdir)/automake.in; then \
447           echo "Don't use \`local' with parens: use several \`local' above." >&2; \
448           exit 1; \
449         fi
450
451 ## Allow only few variables to be localized in Automake.
452 sc_perl_local:
453         @if egrep -v '^[ \t]*local \$$[_~]( *=|;)' $(srcdir)/automake.in | \
454                 grep '^[ \t]*local [^*]'; then \
455           echo "Please avoid \`local'." 1>&2; \
456           exit 1; \
457         fi
458
459 ## Don't let AMDEP_TRUE substitution appear in automake.in.
460 sc_AMDEP_TRUE_in_automake_in:
461         @if grep '@AMDEP''_TRUE@' $(srcdir)/automake.in; then \
462           echo "Don't put AMDEP_TRUE substitution in automake.in" 1>&2; \
463           exit 1; \
464         fi
465
466 ## Recursive make invocations should always pass $(AM_MAKEFLAGS)
467 ## to $(MAKE), for portability to non-GNU make.
468 sc_tests_make_without_am_makeflags:
469         @if grep '^[^#].*(MAKE) ' $(ams) $(srcdir)/automake.in | \
470                 grep -v 'AM_MAKEFLAGS'; then \
471           echo 'Use $$(MAKE) $$(AM_MAKEFLAGS).' 1>&2; \
472           exit 1; \
473         fi
474
475 ## Look out for some obsolete variables.
476 sc_tests_obsolete_variables:
477         @vars=" \
478           using_tap \
479           parallel_tests \
480           test_prefer_config_shell \
481           original_AUTOMAKE \
482           original_ACLOCAL \
483         "; \
484         seen=""; \
485         for v in $$vars; do \
486           if grep -E "\b$$v\b" \
487             $(xtests) $(srcdir)/tests/defs \
488             $(srcdir)/tests/defs-static.in \
489           ; then \
490             seen="$$seen $$v"; \
491           fi; \
492         done; \
493         if test -n "$$seen"; then \
494           for v in $$seen; do \
495             echo "Variable '$$v' is obsolete, use 'am_$$v' instead." 1>&2; \
496           done; \
497           exit 1; \
498         else :; fi
499
500 ## Tests should never call make directly.
501 sc_tests_plain_make:
502         @if grep -v '^#' $(xtests) | $(EGREP) ':[       ]*make( |$$)'; then \
503           echo 'Do not run "make" in the above tests.  Use "$$MAKE" instead.' 1>&2; \
504           exit 1; \
505         fi
506
507 ## Tests should never call autoconf directly.
508 sc_tests_plain_autoconf:
509         @if grep -v '^#' $(xtests) | grep ':[   ]*autoconf\>'; then \
510           echo 'Do not run "autoconf" in the above tests.  Use "$$AUTOCONF" instead.' 1>&2; \
511           exit 1; \
512         fi
513
514 ## Tests should never call autoupdate directly.
515 sc_tests_plain_autoupdate:
516         @if grep -v '^#' $(xtests) | grep ':[   ]*autoupdate\>'; then \
517           echo 'Do not run "autoupdate" in the above tests.  Use "$$AUTOUPDATE" instead.' 1>&2; \
518           exit 1; \
519         fi
520
521 ## Tests should never call automake directly.
522 sc_tests_plain_automake:
523         @if grep -v '^#' $(xtests) | grep -E ':[        ]*automake\>([^:]|$$)'; then \
524           echo 'Do not run "automake" in the above tests.  Use "$$AUTOMAKE" instead.' 1>&2;  \
525           exit 1; \
526         fi
527
528 ## Tests should never call autoheader directly.
529 sc_tests_plain_autoheader:
530         @if grep -v '^#' $(xtests) | grep ':[   ]*autoheader\>'; then \
531           echo 'Do not run "autoheader" in the above tests.  Use "$$AUTOHEADER" instead.' 1>&2;  \
532           exit 1; \
533         fi
534
535 ## Tests should never call autoreconf directly.
536 sc_tests_plain_autoreconf:
537         @if grep -v '^#' $(xtests) | grep ':[   ]*autoreconf\>'; then \
538           echo 'Do not run "autoreconf" in the above tests.  Use "$$AUTORECONF" instead.' 1>&2;  \
539           exit 1; \
540         fi
541
542 ## Tests should never call autom4te directly.
543 sc_tests_plain_autom4te:
544         @if grep -v '^#' $(xtests) | grep ':[   ]*autom4te\>'; then \
545           echo 'Do not run "autom4te" in the above tests.  Use "$$AUTOM4TE" instead.' 1>&2;  \
546           exit 1; \
547         fi
548
549 ## Tests should only use END and EOF for here documents
550 ## (so that the next test is effective).
551 sc_tests_here_document_format:
552         @if grep '<<' $(xtests) | grep -v 'END' | grep -v 'EOF'; then \
553           echo 'Use here documents with "END" and "EOF" only, for greppability.' 1>&2; \
554           exit 1; \
555         fi
556
557 ## Tests should never call exit directly, but use Exit.
558 ## This is so that the exit status is transported correctly across the 0 trap.
559 ## Ignore comments, testsuite self tests, and one perl line in ext2.test.
560 sc_tests_Exit_not_exit:
561         @found=false; for file in $(xtests); do \
562           case $$file in */self-check-*) continue;; esac; \
563           res=`sed -n -e '/^#/d; /^\$$PERL/d' -e '/<<.*END/,/^END/b' \
564                       -e '/<<.*EOF/,/^EOF/b' -e '/exit [$$0-9]/p' $$file`; \
565           if test -n "$$res"; then \
566             echo "$$file:$$res"; \
567             found=true; \
568           fi; \
569         done; \
570         if $$found; then \
571           echo 'Do not call plain "exit", use "Exit" instead, in above tests.' 1>&2; \
572           exit 1; \
573         fi
574
575 ## Use AUTOMAKE_fails when appropriate
576 sc_tests_automake_fails:
577         @if grep -v '^#' $(xtests) | grep '\$$AUTOMAKE.*&&.*[eE]xit'; then \
578           echo 'Use AUTOMAKE_fails + grep to catch automake failures in the above tests.' 1>&2;  \
579           exit 1; \
580         fi
581
582 ## Tests should never call aclocal directly.
583 sc_tests_plain_aclocal:
584         @if grep -v '^#' $(xtests) | grep ':[   ]*aclocal\>'; then \
585           echo 'Do not run "aclocal" in the above tests.  Use "$$ACLOCAL" instead.' 1>&2;  \
586           exit 1; \
587         fi
588
589 ## Tests should never call perl directly.
590 sc_tests_plain_perl:
591         @if grep -v '^#' $(xtests) | grep ':[   ]*perl\>'; then \
592           echo 'Do not run "perl" in the above tests.  Use "$$PERL" instead.' 1>&2; \
593           exit 1; \
594         fi
595
596 ## Setting `required' after sourcing `./defs' is a bug.
597 sc_tests_required_after_defs:
598         @for file in $(xtests); do \
599           if out=`sed -n '/defs/,$${/required=/p;}' $$file`; test -n "$$out"; then \
600             echo 'Do not set "required" after sourcing "defs" in '"$$file: $$out" 1>&2; \
601             exit 1; \
602           fi; \
603         done
604
605 ## TAP-based test scripts should not forget to declare a TAP plan.  In
606 ## case it is not known in advance how many tests will be run, a "lazy"
607 ## plan can be used; but its use should be deliberate, explicitly declared
608 ## with a "plan_ later" call, rather than the result of an oversight.
609 ## This check helps to ensure this is indeed the case.
610 sc_tests_tap_plan:
611         @with_plan=`grep -l '^ *plan_ ' $(srcdir)/tests/*.tap`; \
612          with_plan=`echo $$with_plan`; \
613          ok=:; \
614          for t in $(srcdir)/tests/*.tap; do \
615            case " $$with_plan " in *" $$t "*) continue;; esac; \
616 ## It's ok for an *auto-generated* test sourcing an hand-written one not
617 ## to declare a TAP plan: that will be done by the sourced test.
618            case $$t in \
619              *-w.tap) \
620                t2=`echo $$t | sed -e 's|.*/||' -e 's/-w\.tap$$/.tap/'` \
621                  && grep -E "^ *\\.  *[^        ]*/$$t2\\b" $$t >/dev/null \
622                  && continue || : ;; \
623            esac; \
624            ok=false; echo $$t; \
625          done; \
626          $$ok || { \
627           echo 'The tests above do not declare a TAP plan.' 1>&2; \
628           exit 1; \
629          }
630
631 ## Overriding a Makefile macro on the command line is not portable when
632 ## recursive targets are used.  Better use an envvar.  SHELL is an
633 ## exception, POSIX says it can't come from the environment.  V, DESTDIR,
634 ## DISTCHECK_CONFIGURE_FLAGS and DISABLE_HARD_ERRORS are exceptions, too,
635 ## as package authors are urged not to initialize them anywhere.
636 sc_tests_overriding_macros_on_cmdline:
637         @if grep -E '\$$MAKE .*(SHELL=.*=|=.*SHELL=)' $(xtests); then \
638           echo 'Rewrite "$$MAKE foo=bar SHELL=$$SHELL" as "foo=bar $$MAKE -e SHELL=$$SHELL"' 1>&2; \
639           echo ' in the above lines, it is more portable.' 1>&2; \
640           exit 1; \
641         fi
642 ## Also try to account for usages like "$MAKE || st=$?".
643         @if sed -e 's/ || .*//' -e 's/ && .*//' \
644                 -e 's/ DESTDIR=[^ ]*/ /' -e 's/ SHELL=[^ ]*/ /' \
645                 -e 's/ V=[^ ]*/ /' -e 's/ DISABLE_HARD_ERRORS=[^ ]*/ /' \
646 ## DISTCHECK_CONFIGURE_FLAGS is allowed to contain whitespace in its
647 ## definition, so the more complex substitutions below.
648                 -e "s/ DISTCHECK_CONFIGURE_FLAGS='[^']*'/ /" \
649                 -e 's/ DISTCHECK_CONFIGURE_FLAGS="[^"]*"/ /' \
650                 -e 's/ DISTCHECK_CONFIGURE_FLAGS=[^ ]/ /' \
651               $(xtests) | grep '\$$MAKE .*='; then \
652           echo 'Rewrite "$$MAKE foo=bar" as "foo=bar $$MAKE -e" in the above lines,' 1>&2; \
653           echo 'it is more portable.' 1>&2; \
654           exit 1; \
655         fi
656         @if grep 'SHELL=.*\$$MAKE' $(xtests); then \
657           echo '$$MAKE ignores the SHELL envvar, use "$$MAKE SHELL=$$SHELL" in' 1>&2; \
658           echo 'the above lines.' 1>&2; \
659           exit 1; \
660         fi
661
662 ## Never use `sleep 1' to create files with different timestamps.
663 ## Use `$sleep' instead.  Some filesystems (e.g., Windows') have only
664 ## a 2sec resolution.
665 sc_tests_plain_sleep:
666         @if grep -E '\bsleep +[12345]\b' $(xtests); then \
667           echo 'Do not use "sleep x" in the above tests.  Use "$$sleep" instead.' 1>&2; \
668           exit 1; \
669         fi
670
671 ## fgrep and egrep are not required by POSIX.
672 sc_tests_plain_egrep_fgrep:
673         @if grep -E '\b[ef]grep\b' $(xtests) ; then \
674           echo 'Do not use egrep or fgrep in test cases.  Use $$FGREP or $$EGREP.' 1>&2; \
675           exit 1; \
676         fi
677         @if grep -E '\b[ef]grep\b' $(ams) $(srcdir)/m4/*.m4; then \
678           echo 'Do not use egrep or fgrep in the above files, they are not portable.' 1>&2; \
679           exit 1; \
680         fi
681
682 ## Rule to ensure that the testsuite has been run before.  We don't depend on `check'
683 ## here, because that would be very wasteful in the common case.  We could run
684 ## `make check RECHECK_LOGS=' and avoid toplevel races with AM_RECURSIVE_TARGETS.
685 ## Suggest keeping test directories around for greppability of the Makefile.in files.
686 sc_ensure_testsuite_has_run:
687         @if test ! -f tests/test-suite.log; then \
688           echo "Run \`env keep_testdirs=yes make check' before \`maintainer-check'" >&2; \
689           exit 1; \
690         fi
691 .PHONY: sc_ensure_testsuite_has_run
692
693 ## Ensure our warning and error messages do not contain duplicate 'warning:' prefixes.
694 ## This test actually depends on the testsuite having been run before.
695 sc_tests_logs_duplicate_prefixes: sc_ensure_testsuite_has_run
696         @if grep -E '(warning|error):.*(warning|error):' tests/*.log; then \
697           echo 'Duplicate warning/error message prefixes seen in above tests.' >&2; \
698           exit 1; \
699         fi
700
701 ## Ensure variables are listed before rules in Makefile.in files we generate.
702 sc_tests_makefile_variable_order: sc_ensure_testsuite_has_run
703         @for file in `find tests -name Makefile.in -print`; do \
704           latevars=`sed -n \
705             -e :x -e 's/#.*//' \
706             -e '/\\\\$$/{' -e N -e 'b x' -e '}' \
707 ## Literal TAB.
708             -e '1,/^    /d' \
709 ## Allow @ so we match conditionals.
710             -e '/^ *[a-zA-Z_@]\{1,\} *=/p' $$file`; \
711           if test -n "$$latevars"; then \
712             echo 'Ensure variables are expanded before rules' >&2; \
713             echo "Variables are expanded too late in $$file:" >&2; \
714             echo "$$latevars" | sed 's/^/  /' >&2; \
715             exit 1; \
716           fi; \
717         done
718
719 ## Using `:' as a PATH separator is not portable.
720 sc_tests_PATH_SEPARATOR:
721         @if grep -E '\bPATH=.*:.*' $(xtests) ; then \
722           echo "Use \`\$$PATH_SEPARATOR', not \`:', in PATH definitions above." 1>&2; \
723           exit 1; \
724         fi
725
726 sc_mkdir_p:
727         @if grep 'mkdir_p' $(srcdir)/automake.in $(ams) $(xtests); then \
728           echo 'Do not use mkdir_p in the above files, use MKDIR_P.' 1>&2; \
729           exit 1; \
730         fi
731
732 ## Try to make sure all @...@ substitutions are covered by our
733 ## substitution rule.
734 sc_perl_at_substs:
735         @if test `grep -E '^[^#]*@[A-Za-z_0-9]+@' aclocal | wc -l` -ne 0; then \
736           echo "Unresolved @...@ substitution in aclocal" 1>&2; \
737           exit 1; \
738         fi
739         @if test `grep -E '^[^#]*@[A-Za-z_0-9]+@' automake | wc -l` -ne 0; then \
740           echo "Unresolved @...@ substitution in automake" 1>&2; \
741           exit 1; \
742         fi
743
744 sc_unquoted_DESTDIR:
745         @if grep -E "[^\'\"]\\\$$\(DESTDIR" $(ams); then \
746           echo 'Suspicious unquoted DESTDIR uses.' 1>&2 ; \
747           exit 1; \
748         fi
749
750 sc_tabs_in_texi:
751         @if grep '      ' $(srcdir)/doc/automake.texi; then \
752           echo 'Do not use tabs in the manual.' 1>&2; \
753           exit 1; \
754         fi
755
756 sc_at_in_texi:
757         @if grep -E '([^@]|^)@([         ][^@]|$$)' $(srcdir)/doc/automake.texi; \
758         then \
759           echo 'Unescaped @.' 1>&2; \
760           exit 1; \
761         fi
762
763
764 git-dist: maintainer-check
765 ## Make sure the NEWS file is up-to-date.
766         @if sed 1q $(srcdir)/NEWS | grep -e "$(VERSION)" > /dev/null; then :; else \
767           echo "NEWS not updated; not releasing" 1>&2; \
768           exit 1;                               \
769         fi
770 ## Build the distribution.  We expect the developer to have already run
771 ## "make check" and "make distcheck" on his own (as required in the
772 ## HACKING file, section "Release procedure").
773         $(MAKE) $(AM_MAKEFLAGS) dist
774 ## Finally, if anything was successful, commit the last changes and tag
775 ## the release in the repository.  We don't use RCS keywords so it's OK
776 ## to distribute the files before they were committed.
777         $(am__cd) $(srcdir) && git commit -a -s && \
778            git tag -s "v$(VERSION)" -m "Release $(VERSION)"
779
780 git-release: git-dist
781         case $(VERSION) in \
782           *[a-z]) dest=alpha;; \
783           *)      dest=ftp;; \
784         esac; \
785         $(srcdir)/lib/gnupload $(GNUPLOADFLAGS) \
786           --to $$dest.gnu.org:automake $(DIST_ARCHIVES)
787
788 ## Visually comparing differences between the Makefile.in files in
789 ## automake's own build system as generated in two different branches
790 ## might help to catch bugs and blunders.  This has already happened a
791 ## few times in the past, when we used to version-control Makefile.in.
792 autodiffs:
793         @set -u; \
794          NEW_COMMIT=$${NEW_COMMIT-"HEAD"}; \
795          OLD_COMMIT=$${OLD_COMMIT-"HEAD~1"}; \
796          am_gitdir='$(abs_top_srcdir)/.git'; \
797          get_autofiles_from_rev () \
798          { \
799              rev=$$1 dir=$$2 \
800                && echo "$@: will get files from revision $$rev" \
801                && git clone -q --depth 1 "$$am_gitdir" tmp \
802                && cd tmp \
803                && git checkout -q "$$rev" \
804                && echo "$@: bootstrapping $$rev" \
805                && $(SHELL) ./bootstrap \
806                && echo "$@: copying files from $$rev" \
807                && makefile_ins=`find . -name Makefile.in` \
808                && (tar cf - configure aclocal.m4 $$makefile_ins) | \
809                   (cd .. && cd "$$dir" && tar xf -) \
810                && cd .. \
811                && rm -rf tmp; \
812          }; \
813          outdir=$@.dir \
814 ## Before proceeding, ensure the specified revisions truly exist.
815            && git --git-dir="$$am_gitdir" describe $$OLD_COMMIT >/dev/null \
816            && git --git-dir="$$am_gitdir" describe $$NEW_COMMIT >/dev/null \
817            && rm -rf $$outdir \
818            && mkdir $$outdir \
819            && cd $$outdir \
820            && mkdir new old \
821            && get_autofiles_from_rev $$OLD_COMMIT old \
822            && get_autofiles_from_rev $$NEW_COMMIT new \
823            && exit 0
824 ## With lots of eye candy; we like our developers pampered and spoiled :-)
825 compare-autodiffs: autodiffs
826         @set -u; \
827         : $${COLORDIFF=colordiff} $${DIFF=diff}; \
828         dir=autodiffs.dir; \
829         if test ! -d "$$dir"; then \
830           echo "$@: $$dir: Not a directory" >&2; \
831           exit 1; \
832         fi; \
833         mydiff=false mypager=false; \
834         if test -t 1; then \
835           if ($$COLORDIFF -r . .) </dev/null >/dev/null 2>&1; then \
836             mydiff=$$COLORDIFF; \
837             mypager="less -R"; \
838           else \
839             mypager=less; \
840           fi; \
841         else \
842           mypager=cat; \
843         fi; \
844         if test "$$mydiff" = false; then \
845           if ($$DIFF -r -u . .); then \
846             mydiff=$$DIFF; \
847           else \
848             echo "$@: no good-enough diff program specified" >&2; \
849             exit 1; \
850           fi; \
851         fi; \
852         st=0; $$mydiff -r -u $$dir/old $$dir/new | $$mypager || st=$$?; \
853         rm -rf $$dir; \
854         exit $$st
855 .PHONY: autodiffs compare-autodiffs
856
857 ## Program to use to fetch files.
858 WGET = wget
859 WGET_SV_CVS = $(WGET) http://savannah.gnu.org/cgi-bin/viewcvs/~checkout~/
860 WGET_SV_GIT_CF = $(WGET) 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;hb=HEAD;f='
861 WGET_SV_GIT_AC = $(WGET) 'http://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=blob_plain;hb=HEAD;f='
862 WGET_SV_GIT_GL = $(WGET) 'http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob_plain;hb=HEAD;f='
863
864 ## Files that we fetch and which we compare against.
865 ## FIXME should be a lot more here
866 FETCHFILES = \
867 INSTALL \
868 config.guess \
869 config.sub \
870 gnupload \
871 gitlog-to-changelog \
872 texinfo.tex
873
874 ## Fetch the latest versions of files we care about.
875 fetch:
876         rm -rf Fetchdir > /dev/null 2>&1
877         mkdir Fetchdir
878 ## If a get fails then that is a problem.
879         ($(am__cd) Fetchdir && \
880         $(WGET_SV_GIT_CF)config.guess -O config.guess && \
881         $(WGET_SV_GIT_CF)config.sub -O config.sub && \
882         $(WGET_SV_CVS)texinfo/texinfo/doc/texinfo.tex -O texinfo.tex && \
883         $(WGET_SV_GIT_GL)doc/INSTALL -O INSTALL && \
884         $(WGET_SV_GIT_GL)build-aux/gnupload -O gnupload && \
885         $(WGET_SV_GIT_GL)build-aux/gitlog-to-changelog -O gitlog-to-changelog)
886 ## Don't exit after test because we want to give as many errors as
887 ## possible.
888         @stat=0; for file in $(FETCHFILES); do \
889           if diff -u $(srcdir)/lib/$$file Fetchdir/$$file \
890                   >>Fetchdir/update.patch 2>/dev/null; then :; \
891           else \
892             stat=1; \
893             echo "Updating $(srcdir)/lib/$$file ..."; \
894             cp Fetchdir/$$file $(srcdir)/lib/$$file; \
895           fi; \
896         done; \
897         test $$stat = 0 || \
898           echo "See Fetchdir/update.patch for a log of the changes."; \
899         exit $$stat
900 .PHONY: fetch
901
902 ## Generate release statistics, for the table in automake.texi.
903 ## This has to be run in an up to date build tree, but there must
904 ## be no temp files nor unused other files lying around!
905 release-stats: ps
906         $(AM_V_GEN): && \
907         am=`wc -l < automake` && \
908         acl=`wc -l < aclocal` && \
909         pmfiles="lib/Automake/*.pm" && \
910         if test . != '$(srcdir)'; then pmfiles="$$pmfiles $(srcdir)/lib/Automake/*.pm"; \
911         else :; fi && \
912         pm=`cat $$pmfiles | wc -l` && \
913         dot_am_files=`ls -1 $(srcdir)/lib/am/*.am | grep -v Makefile.am` && \
914         amf=`echo "$$dot_am_files" | wc -l` && \
915         aml=`cat $$dot_am_files | wc -l` && \
916         m4f=`ls -1 $(srcdir)/m4/*.m4 | wc -l` && \
917         m4l=`cat $(srcdir)/m4/*.m4 | wc -l` && \
918         doc_text=`$(am__cd) doc && LC_ALL=C pstops 0 automake.ps unused.ps 2>&1` && \
919         echo "$$doc_text" && \
920         rm -f doc/unused.ps && \
921         doc=`echo "$$doc_text" | sed -n 's/.*Wrote \([1-9][0-9]*\) pages.*/\1/p'` && \
922         tests="tests/*.test"; \
923         if test . != '$(srcdir)'; then tests="$$tests $(srcdir)/tests/*.test"; \
924         else :; fi && \
925         t=`ls -1 $$tests | wc -l` && \
926         tgen=`grep 'GENERATED AUTOMATICALLY' $$tests | wc -l` && \
927         today=`date +%Y-%m-%d` && \
928         echo "add this to the table in doc/automake.texi after verification:" && \
929         printf '@item %s @tab %-6s @tab %4d @tab %4d @tab %4d @tab %4d %-4s @tab %4d %-4s @tab %3d @tab %d %-4s\n' \
930                       $$today $(VERSION) $$am    $$acl    $$pm   $$aml "($$amf)" $$m4l "($$m4f)" $$doc $$t "($$tgen)"
931 .PHONY: release-stats