1 # Maintainer checks for Automake. Requires GNU make.
3 # Copyright (C) 2012 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # We also have to take into account VPATH builds (where some generated
19 # tests might be in '$(builddir)' rather than in '$(srcdir)'), TAP-based
20 # tests script (which have a '.tap' extension) and helper scripts used
21 # by other test cases (which have a '.sh' extension).
23 if test $(srcdir) = .; then \
29 for s in test tap sh; do \
30 ls $$d/tests/*.$$s 2>/dev/null; \
32 ls $$d/tests/ax/*.sh 2>/dev/null; \
35 ams := $(shell find $(srcdir) -name '*.am')
37 # Some simple checks, and then ordinary check. These are only really
38 # guaranteed to work on my machine.
39 syntax_check_rules = \
41 sc_diff_automake_in_automake \
42 sc_diff_aclocal_in_automake \
44 sc_no_brace_variable_expansions \
46 sc_no_for_variable_in_macro \
48 sc_pre_normal_post_install_uninstall \
50 sc_perl_no_split_regex_space \
53 sc_perl_at_uscore_in_scalar_context \
55 sc_AMDEP_TRUE_in_automake_in \
56 sc_tests_make_without_am_makeflags \
57 sc_tests_obsolete_variables \
59 sc_tests_plain_autoconf \
60 sc_tests_plain_autoupdate \
61 sc_tests_plain_automake \
62 sc_tests_plain_autom4te \
63 sc_tests_plain_autoheader \
64 sc_tests_plain_autoreconf \
65 sc_tests_here_document_format \
66 sc_tests_Exit_not_exit \
67 sc_tests_automake_fails \
68 sc_tests_plain_aclocal \
70 sc_tests_required_after_defs \
71 sc_tests_overriding_macros_on_cmdline \
72 sc_tests_plain_sleep \
73 sc_tests_plain_egrep_fgrep \
74 sc_tests_no_configure_in \
75 sc_tests_PATH_SEPARATOR \
76 sc_tests_logs_duplicate_prefixes \
77 sc_tests_makefile_variable_order \
84 $(syntax_check_rules): automake aclocal
85 maintainer-check: $(syntax_check_rules)
86 .PHONY: maintainer-check $(syntax_check_rules)
88 ## Check that the list of tests given in the Makefile is equal to the
89 ## list of all test scripts in the Automake testsuite.
90 .PHONY: maintainer-check-list-of-tests
91 maintainer-check-list-of-tests:
93 maintainer-check: maintainer-check-list-of-tests
95 ## Look for test whose names can cause spurious failures when used as
96 ## first argument to AC_INIT (chiefly because they might contain an
97 ## m4/m4sugar builtin or macro name).
147 @m4_builtin_rx=`echo $(m4_builtins) | sed 's/ /|/g'`; \
148 m4_macro_rx="\\<($$m4_builtin_rx)\\>|\\<_?(A[CUMHS]|m4)_"; \
150 for t in $(xtests); do echo $$t; done \
151 | LC_ALL=C grep -E "$$m4_macro_rx"; \
153 echo "the names of the tests above can be problematic" 1>&2; \
154 echo "Avoid test names that contain names of m4 macros" 1>&2; \
158 ## These check avoids accidental configure substitutions in the source.
159 ## There are exactly 9 lines that should be modified from automake.in to
160 ## automake, and 10 lines that should be modified from aclocal.in to
161 ## aclocal; these wors out to 32 and 34 lines of diffs, respectively.
162 sc_diff_automake_in_automake:
163 @if test `diff $(srcdir)/automake.in automake | wc -l` -ne 32; then \
164 echo "found too many diffs between automake.in and automake" 1>&2; \
165 diff -c $(srcdir)/automake.in automake; \
168 sc_diff_aclocal_in_aclocal:
169 @if test `diff $(srcdir)/aclocal.in aclocal | wc -l` -ne 34; then \
170 echo "found too many diffs between aclocal.in and aclocal" 1>&2; \
171 diff -c $(srcdir)/aclocal.in aclocal; \
175 ## Syntax check with default Perl (on my machine, Perl 5).
177 @perllibdir="./lib$(PATH_SEPARATOR)$(srcdir)/lib" $(PERL) -c -w automake
178 @perllibdir="./lib$(PATH_SEPARATOR)$(srcdir)/lib" $(PERL) -c -w aclocal
180 ## expect no instances of '${...}'. However, $${...} is ok, since that
181 ## is a shell construct, not a Makefile construct.
182 sc_no_brace_variable_expansions:
183 @if grep -F '$${' $(ams) | grep -F -v '$$$$'; then \
184 echo "Found too many uses of '\$${' in the lines above." 1>&2; \
188 ## Make sure 'rm' is called with '-f'.
190 @if grep -v '^#' $(ams) $(xtests) \
191 | grep -v '/spy-rm\.tap:' \
192 | grep -E '\<rm ([^-]|\-[^f ]*\>)'; \
194 echo "Suspicious 'rm' invocation." 1>&2; \
198 ## Never use something like "for file in $(FILES)", this doesn't work
199 ## if FILES is empty or if it contains shell meta characters (e.g. $ is
200 ## commonly used in Java filenames).
201 sc_no_for_variable_in_macro:
202 @if grep 'for .* in \$$(' $(ams) | grep -v '/Makefile\.am:'; then \
203 echo 'Use "list=$$(mumble); for var in $$$$list".' 1>&2 ; \
207 ## Make sure all invocations of mkinstalldirs are correct.
209 @if grep -n 'mkinstalldirs' $(ams) \
210 | grep -F -v '$$(mkinstalldirs)' \
211 | grep -v '^\./lib/Makefile.am:[0-9][0-9]*: *mkinstalldirs \\$$'; \
213 echo "Found incorrect use of mkinstalldirs in the lines above" 1>&2; \
217 ## Make sure all calls to PRE/NORMAL/POST_INSTALL/UNINSTALL
218 sc_pre_normal_post_install_uninstall:
219 @if grep -E -n '\((PRE|NORMAL|POST)_(|UN)INSTALL\)' $(ams) | \
220 grep -v ':##' | grep -v ': @\$$('; then \
221 echo "Found incorrect use of PRE/NORMAL/POST_INSTALL/UNINSTALL in the lines above" 1>&2; \
225 ## We never want to use "undef", only "delete", but for $/.
227 @if grep -n -w 'undef ' $(srcdir)/automake.in | \
228 grep -F -v 'undef $$/'; then \
229 echo "Found undef in automake.in; use delete instead" 1>&2; \
233 ## We never want split (/ /,...), only split (' ', ...).
234 sc_perl_no_split_regex_space:
235 @if grep -n 'split (/ /' $(srcdir)/automake.in; then \
236 echo "Found bad split in the lines above." 1>&2; \
240 ## Look for cd within backquotes
242 @if grep -n '^[^#]*` *cd ' $(srcdir)/automake.in $(ams); then \
243 echo "Consider using \$$(am__cd) in the lines above." 1>&2; \
247 ## Look for cd to a relative directory (may be influenced by CDPATH).
248 ## Skip some known directories that are OK.
250 @if grep -n '^[^#]*cd ' $(srcdir)/automake.in $(ams) | \
251 grep -v 'echo.*cd ' | \
252 grep -v 'am__cd =' | \
253 grep -v '^[^#]*cd [./]' | \
254 grep -v '^[^#]*cd \$$(top_builddir)' | \
255 grep -v '^[^#]*cd "\$$\$$am__cwd' | \
256 grep -v '^[^#]*cd \$$(abs' | \
257 grep -v '^[^#]*cd "\$$(DESTDIR)'; then \
258 echo "Consider using \$$(am__cd) in the lines above." 1>&2; \
262 ## Using @_ in a scalar context is most probably a programming error.
263 sc_perl_at_uscore_in_scalar_context:
264 @if grep -Hn '[^@_A-Za-z0-9][_A-Za-z0-9]*[^) ] *= *@_' $(srcdir)/automake.in; then \
265 echo "Using @_ in a scalar context in the lines above." 1>&2; \
269 ## Allow only few variables to be localized in Automake.
271 @if egrep -v '^[ \t]*local \$$[_~]( *=|;)' $(srcdir)/automake.in | \
272 grep '^[ \t]*local [^*]'; then \
273 echo "Please avoid 'local'." 1>&2; \
277 ## Don't let AMDEP_TRUE substitution appear in automake.in.
278 sc_AMDEP_TRUE_in_automake_in:
279 @if grep '@AMDEP''_TRUE@' $(srcdir)/automake.in; then \
280 echo "Don't put AMDEP_TRUE substitution in automake.in" 1>&2; \
284 ## Recursive make invocations should always pass $(AM_MAKEFLAGS)
285 ## to $(MAKE), for portability to non-GNU make.
286 sc_tests_make_without_am_makeflags:
287 @if grep '^[^#].*(MAKE) ' $(ams) $(srcdir)/automake.in \
288 | grep -v 'AM_MAKEFLAGS' \
289 | grep -v '/am/header-vars\.am:.*am--echo.*| $$(MAKE) -f *-'; \
291 echo 'Use $$(MAKE) $$(AM_MAKEFLAGS).' 1>&2; \
295 ## Look out for some obsolete variables.
296 sc_tests_obsolete_variables:
300 test_prefer_config_shell \
305 for v in $$vars; do \
306 if grep -E "\b$$v\b" \
307 $(xtests) $(srcdir)/tests/defs \
308 $(srcdir)/tests/defs-static.in \
313 if test -n "$$seen"; then \
314 for v in $$seen; do \
315 echo "Variable '$$v' is obsolete, use 'am_$$v' instead." 1>&2; \
320 ## Tests should never call make directly.
322 @if grep -v '^#' $(xtests) | $(EGREP) ':[ ]*make( |$$)'; then \
323 echo 'Do not run "make" in the above tests. Use "$$MAKE" instead.' 1>&2; \
327 ## Tests should never call autoconf directly.
328 sc_tests_plain_autoconf:
329 @if grep -v '^#' $(xtests) | grep ':[ ]*autoconf\>'; then \
330 echo 'Do not run "autoconf" in the above tests. Use "$$AUTOCONF" instead.' 1>&2; \
334 ## Tests should never call autoupdate directly.
335 sc_tests_plain_autoupdate:
336 @if grep -v '^#' $(xtests) | grep ':[ ]*autoupdate\>'; then \
337 echo 'Do not run "autoupdate" in the above tests. Use "$$AUTOUPDATE" instead.' 1>&2; \
341 ## Tests should never call automake directly.
342 sc_tests_plain_automake:
343 @if grep -v '^#' $(xtests) | grep -E ':[ ]*automake\>([^:]|$$)'; then \
344 echo 'Do not run "automake" in the above tests. Use "$$AUTOMAKE" instead.' 1>&2; \
348 ## Tests should never call autoheader directly.
349 sc_tests_plain_autoheader:
350 @if grep -v '^#' $(xtests) | grep ':[ ]*autoheader\>'; then \
351 echo 'Do not run "autoheader" in the above tests. Use "$$AUTOHEADER" instead.' 1>&2; \
355 ## Tests should never call autoreconf directly.
356 sc_tests_plain_autoreconf:
357 @if grep -v '^#' $(xtests) | grep ':[ ]*autoreconf\>'; then \
358 echo 'Do not run "autoreconf" in the above tests. Use "$$AUTORECONF" instead.' 1>&2; \
362 ## Tests should never call autom4te directly.
363 sc_tests_plain_autom4te:
364 @if grep -v '^#' $(xtests) | grep ':[ ]*autom4te\>'; then \
365 echo 'Do not run "autom4te" in the above tests. Use "$$AUTOM4TE" instead.' 1>&2; \
369 ## Tests should only use END and EOF for here documents
370 ## (so that the next test is effective).
371 sc_tests_here_document_format:
372 @if grep '<<' $(xtests) | grep -Ev '\b(END|EOF)\b|\bstd::cout <<'; then \
373 echo 'Use here documents with "END" and "EOF" only, for greppability.' 1>&2; \
377 ## Tests should never call exit directly, but use Exit.
378 ## This is so that the exit status is transported correctly across the 0 trap.
379 ## Ignore comments, testsuite self tests, and one perl line in ext2.test.
380 sc_tests_Exit_not_exit:
381 @found=false; for file in $(xtests); do \
382 case $$file in */self-check-*) continue;; esac; \
383 res=`sed -n -e '/^#/d; /^\$$PERL/d' -e '/<<.*END/,/^END/b' \
384 -e '/<<.*EOF/,/^EOF/b' -e '/exit [$$0-9]/p' $$file`; \
385 if test -n "$$res"; then \
386 echo "$$file:$$res"; \
391 echo 'Do not call plain "exit", use "Exit" instead, in above tests.' 1>&2; \
395 ## Use AUTOMAKE_fails when appropriate
396 sc_tests_automake_fails:
397 @if grep -v '^#' $(xtests) | grep '\$$AUTOMAKE.*&&.*[eE]xit'; then \
398 echo 'Use AUTOMAKE_fails + grep to catch automake failures in the above tests.' 1>&2; \
402 ## Tests should never call aclocal directly.
403 sc_tests_plain_aclocal:
404 @if grep -v '^#' $(xtests) | grep ':[ ]*aclocal\>'; then \
405 echo 'Do not run "aclocal" in the above tests. Use "$$ACLOCAL" instead.' 1>&2; \
409 ## Tests should never call perl directly.
411 @if grep -v '^#' $(xtests) | grep ':[ ]*perl\>'; then \
412 echo 'Do not run "perl" in the above tests. Use "$$PERL" instead.' 1>&2; \
416 ## Setting 'required' after sourcing './defs' is a bug.
417 sc_tests_required_after_defs:
418 @for file in $(xtests); do \
419 if out=`sed -n '/defs/,$${/required=/p;}' $$file`; test -n "$$out"; then \
420 echo 'Do not set "required" after sourcing "defs" in '"$$file: $$out" 1>&2; \
425 ## Overriding a Makefile macro on the command line is not portable when
426 ## recursive targets are used. Better use an envvar. SHELL is an
427 ## exception, POSIX says it can't come from the environment. V, DESTDIR,
428 ## DISTCHECK_CONFIGURE_FLAGS and DISABLE_HARD_ERRORS are exceptions, too,
429 ## as package authors are urged not to initialize them anywhere.
430 ## Finally, 'exp' is used by some ad-hoc checks, where we ensure it's
431 ## ok to override it from the command line.
432 sc_tests_overriding_macros_on_cmdline:
433 @if grep -E '\$$MAKE .*(SHELL=.*=|=.*SHELL=)' $(xtests); then \
434 echo 'Rewrite "$$MAKE foo=bar SHELL=$$SHELL" as "foo=bar $$MAKE -e SHELL=$$SHELL"' 1>&2; \
435 echo ' in the above lines, it is more portable.' 1>&2; \
438 # The first s/// tries to account for usages like "$MAKE || st=$?".
439 # 'DISTCHECK_CONFIGURE_FLAGS' and 'exp' are allowed to contain whitespace in
440 # their definitions, hence the more complex last three substitutions below.
441 # Also, the 'make-dryrun.test' is whitelisted, since there we need to
442 # override variables from the command line in order to cover the expected
444 @tests=`for t in $(xtests); do \
445 case $$t in */make-dryrun.test);; *) echo $$t;; esac; \
447 if sed -e 's/ || .*//' -e 's/ && .*//' \
448 -e 's/ DESTDIR=[^ ]*/ /' -e 's/ SHELL=[^ ]*/ /' \
449 -e 's/ V=[^ ]*/ /' -e 's/ DISABLE_HARD_ERRORS=[^ ]*/ /' \
450 -e "s/ DISTCHECK_CONFIGURE_FLAGS='[^']*'/ /" \
451 -e 's/ DISTCHECK_CONFIGURE_FLAGS="[^"]*"/ /' \
452 -e 's/ DISTCHECK_CONFIGURE_FLAGS=[^ ]/ /' \
453 -e "s/ exp='[^']*'/ /" \
454 -e 's/ exp="[^"]*"/ /' \
455 -e 's/ exp=[^ ]/ /' \
456 $$tests | grep '\$$MAKE .*='; then \
457 echo 'Rewrite "$$MAKE foo=bar" as "foo=bar $$MAKE -e" in the above lines,' 1>&2; \
458 echo 'it is more portable.' 1>&2; \
461 @if grep 'SHELL=.*\$$MAKE' $(xtests); then \
462 echo '$$MAKE ignores the SHELL envvar, use "$$MAKE SHELL=$$SHELL" in' 1>&2; \
463 echo 'the above lines.' 1>&2; \
467 ## Never use 'sleep 1' to create files with different timestamps.
468 ## Use '$sleep' instead. Some filesystems (e.g., Windows) have only
469 ## a 2sec resolution.
470 sc_tests_plain_sleep:
471 @if grep -E '\bsleep +[12345]\b' $(xtests); then \
472 echo 'Do not use "sleep x" in the above tests. Use "$$sleep" instead.' 1>&2; \
476 ## fgrep and egrep are not required by POSIX.
477 sc_tests_plain_egrep_fgrep:
478 @if grep -E '\b[ef]grep\b' $(xtests) ; then \
479 echo 'Do not use egrep or fgrep in test cases. Use $$FGREP or $$EGREP.' 1>&2; \
482 @if grep -E '\b[ef]grep\b' $(ams) $(srcdir)/m4/*.m4; then \
483 echo 'Do not use egrep or fgrep in the above files, they are not portable.' 1>&2; \
487 ## Prefer 'configure.ac' over the obsolescent 'configure.in' as the name
488 ## for configure input files in our testsuite. The latter has been
489 ## deprecated for several years (at least since autoconf 2.50).
490 sc_tests_no_configure_in:
491 @if grep -E '\bconfigure\\*\.in\b' $(xtests) $(srcdir)/tests/defs \
492 | grep -Ev '/backcompat.*\.(test|tap):' \
493 | grep -Ev '/autodist-configure-no-subdir\.test:' \
494 | grep -Ev '/(configure|help)\.test:' \
497 echo "Use 'configure.ac', not 'configure.in', as the name" >&2; \
498 echo "for configure input files in the test cases above." >&2; \
502 ## Rule to ensure that the testsuite has been run before. We don't depend
503 ## on 'check' here, because that would be very wasteful in the common case.
504 ## We could run "make check RECHECK_LOGS=" and avoid toplevel races with
505 ## AM_RECURSIVE_TARGETS. Suggest keeping test directories around for
506 ## greppability of the Makefile.in files.
507 sc_ensure_testsuite_has_run:
508 @if test ! -f tests/test-suite.log; then \
509 echo 'Run "env keep_testdirs=yes make check" before' \
510 'running "make maintainer-check"' >&2; \
513 .PHONY: sc_ensure_testsuite_has_run
515 ## Ensure our warning and error messages do not contain duplicate 'warning:' prefixes.
516 ## This test actually depends on the testsuite having been run before.
517 sc_tests_logs_duplicate_prefixes: sc_ensure_testsuite_has_run
518 @if grep -E '(warning|error):.*(warning|error):' tests/*.log; then \
519 echo 'Duplicate warning/error message prefixes seen in above tests.' >&2; \
523 ## Ensure variables are listed before rules in Makefile.in files we generate.
524 sc_tests_makefile_variable_order: sc_ensure_testsuite_has_run
526 for file in `find tests -name Makefile.in -print`; do \
529 -e '/\\\\$$/{' -e N -e 'b x' -e '}' \
530 -e '# Literal TAB.' \
532 -e '# Allow @ so we match conditionals.' \
533 -e '/^ *[a-zA-Z_@]\{1,\} *=/p' $$file`; \
534 if test -n "$$latevars"; then \
535 echo "Variables are expanded too late in $$file:" >&2; \
536 echo "$$latevars" | sed 's/^/ /' >&2; \
540 test $$st -eq 0 || { \
541 echo 'Ensure variables are expanded before rules' >&2; \
545 ## Using ':' as a PATH separator is not portable.
546 sc_tests_PATH_SEPARATOR:
547 @if grep -E '\bPATH=.*:.*' $(xtests) ; then \
548 echo "Use '\$$PATH_SEPARATOR', not ':', in PATH definitions" \
554 @if grep 'mkdir_p' $(srcdir)/automake.in $(ams) $(xtests); then \
555 echo 'Do not use mkdir_p in the above files, use MKDIR_P.' 1>&2; \
559 ## Try to make sure all @...@ substitutions are covered by our
560 ## substitution rule.
562 @if test `grep -E '^[^#]*@[A-Za-z_0-9]+@' aclocal | wc -l` -ne 0; then \
563 echo "Unresolved @...@ substitution in aclocal" 1>&2; \
566 @if test `grep -E '^[^#]*@[A-Za-z_0-9]+@' automake | wc -l` -ne 0; then \
567 echo "Unresolved @...@ substitution in automake" 1>&2; \
572 @if grep -E "[^\'\"]\\\$$\(DESTDIR" $(ams); then \
573 echo 'Suspicious unquoted DESTDIR uses.' 1>&2 ; \
578 @if grep ' ' $(srcdir)/doc/automake.texi; then \
579 echo 'Do not use tabs in the manual.' 1>&2; \
584 @if grep -E '([^@]|^)@([ ][^@]|$$)' $(srcdir)/doc/automake.texi; \
586 echo 'Unescaped @.' 1>&2; \