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; \
34 ams := $(shell find $(srcdir) -name '*.am')
36 # Some simple checks, and then ordinary check. These are only really
37 # guaranteed to work on my machine.
38 syntax_check_rules = \
40 sc_diff_automake_in_automake \
41 sc_diff_aclocal_in_automake \
43 sc_no_brace_variable_expansions \
45 sc_no_for_variable_in_macro \
47 sc_pre_normal_post_install_uninstall \
49 sc_perl_no_split_regex_space \
52 sc_perl_at_uscore_in_scalar_context \
54 sc_AMDEP_TRUE_in_automake_in \
55 sc_tests_make_without_am_makeflags \
56 sc_tests_obsolete_variables \
58 sc_tests_plain_autoconf \
59 sc_tests_plain_autoupdate \
60 sc_tests_plain_automake \
61 sc_tests_plain_autom4te \
62 sc_tests_plain_autoheader \
63 sc_tests_plain_autoreconf \
64 sc_tests_here_document_format \
65 sc_tests_Exit_not_exit \
66 sc_tests_automake_fails \
67 sc_tests_plain_aclocal \
69 sc_tests_required_after_defs \
70 sc_tests_overriding_macros_on_cmdline \
71 sc_tests_plain_sleep \
72 sc_tests_plain_egrep_fgrep \
73 sc_tests_no_configure_in \
74 sc_tests_PATH_SEPARATOR \
75 sc_tests_logs_duplicate_prefixes \
76 sc_tests_makefile_variable_order \
83 $(syntax_check_rules): automake aclocal
84 maintainer-check: $(syntax_check_rules)
85 .PHONY: maintainer-check $(syntax_check_rules)
87 ## Check that the list of tests given in the Makefile is equal to the
88 ## list of all test scripts in the Automake testsuite.
89 .PHONY: maintainer-check-list-of-tests
90 maintainer-check-list-of-tests:
92 maintainer-check: maintainer-check-list-of-tests
94 ## Look for test whose names can cause spurious failures when used as
95 ## first argument to AC_INIT (chiefly because they might contain an
96 ## m4/m4sugar builtin or macro name).
146 @m4_builtin_rx=`echo $(m4_builtins) | sed 's/ /|/g'`; \
147 m4_macro_rx="\\<($$m4_builtin_rx)\\>|\\<_?(A[CUMHS]|m4)_"; \
149 for t in $(xtests); do echo $$t; done \
150 | LC_ALL=C grep -E "$$m4_macro_rx"; \
152 echo "the names of the tests above can be problematic" 1>&2; \
153 echo "Avoid test names that contain names of m4 macros" 1>&2; \
157 ## These check avoids accidental configure substitutions in the source.
158 ## There are exactly 9 lines that should be modified from automake.in to
159 ## automake, and 10 lines that should be modified from aclocal.in to
160 ## aclocal; these wors out to 32 and 34 lines of diffs, respectively.
161 sc_diff_automake_in_automake:
162 @if test `diff $(srcdir)/automake.in automake | wc -l` -ne 32; then \
163 echo "found too many diffs between automake.in and automake" 1>&2; \
164 diff -c $(srcdir)/automake.in automake; \
167 sc_diff_aclocal_in_aclocal:
168 @if test `diff $(srcdir)/aclocal.in aclocal | wc -l` -ne 34; then \
169 echo "found too many diffs between aclocal.in and aclocal" 1>&2; \
170 diff -c $(srcdir)/aclocal.in aclocal; \
174 ## Syntax check with default Perl (on my machine, Perl 5).
176 @perllibdir="./lib$(PATH_SEPARATOR)$(srcdir)/lib" $(PERL) -c -w automake
177 @perllibdir="./lib$(PATH_SEPARATOR)$(srcdir)/lib" $(PERL) -c -w aclocal
179 ## expect no instances of '${...}'. However, $${...} is ok, since that
180 ## is a shell construct, not a Makefile construct.
181 sc_no_brace_variable_expansions:
182 @if grep -F '$${' $(ams) | grep -F -v '$$$$'; then \
183 echo "Found too many uses of '\$${' in the lines above." 1>&2; \
187 ## Make sure 'rm' is called with '-f'.
189 @if grep -v '^#' $(ams) $(xtests) \
190 | grep -E '\<rm ([^-]|\-[^f ]*\>)'; \
192 echo "Suspicious 'rm' invocation." 1>&2; \
196 ## Never use something like "for file in $(FILES)", this doesn't work
197 ## if FILES is empty or if it contains shell meta characters (e.g. $ is
198 ## commonly used in Java filenames).
199 sc_no_for_variable_in_macro:
200 @if grep 'for .* in \$$(' $(ams) | grep -v '/Makefile\.am:'; then \
201 echo 'Use "list=$$(mumble); for var in $$$$list".' 1>&2 ; \
205 ## Make sure all invocations of mkinstalldirs are correct.
207 @if grep -n 'mkinstalldirs' $(ams) \
208 | grep -F -v '$$(mkinstalldirs)' \
209 | grep -v '^\./lib/Makefile.am:[0-9][0-9]*: *mkinstalldirs \\$$'; \
211 echo "Found incorrect use of mkinstalldirs in the lines above" 1>&2; \
215 ## Make sure all calls to PRE/NORMAL/POST_INSTALL/UNINSTALL
216 sc_pre_normal_post_install_uninstall:
217 @if grep -E -n '\((PRE|NORMAL|POST)_(|UN)INSTALL\)' $(ams) | \
218 grep -v ':##' | grep -v ': @\$$('; then \
219 echo "Found incorrect use of PRE/NORMAL/POST_INSTALL/UNINSTALL in the lines above" 1>&2; \
223 ## We never want to use "undef", only "delete", but for $/.
225 @if grep -n -w 'undef ' $(srcdir)/automake.in | \
226 grep -F -v 'undef $$/'; then \
227 echo "Found undef in automake.in; use delete instead" 1>&2; \
231 ## We never want split (/ /,...), only split (' ', ...).
232 sc_perl_no_split_regex_space:
233 @if grep -n 'split (/ /' $(srcdir)/automake.in; then \
234 echo "Found bad split in the lines above." 1>&2; \
238 ## Look for cd within backquotes
240 @if grep -n '^[^#]*` *cd ' $(srcdir)/automake.in $(ams); then \
241 echo "Consider using \$$(am__cd) in the lines above." 1>&2; \
245 ## Look for cd to a relative directory (may be influenced by CDPATH).
246 ## Skip some known directories that are OK.
248 @if grep -n '^[^#]*cd ' $(srcdir)/automake.in $(ams) | \
249 grep -v 'echo.*cd ' | \
250 grep -v 'am__cd =' | \
251 grep -v '^[^#]*cd [./]' | \
252 grep -v '^[^#]*cd \$$(top_builddir)' | \
253 grep -v '^[^#]*cd "\$$\$$am__cwd' | \
254 grep -v '^[^#]*cd \$$(abs' | \
255 grep -v '^[^#]*cd "\$$(DESTDIR)'; then \
256 echo "Consider using \$$(am__cd) in the lines above." 1>&2; \
260 ## Using @_ in a scalar context is most probably a programming error.
261 sc_perl_at_uscore_in_scalar_context:
262 @if grep -Hn '[^@_A-Za-z0-9][_A-Za-z0-9]*[^) ] *= *@_' $(srcdir)/automake.in; then \
263 echo "Using @_ in a scalar context in the lines above." 1>&2; \
267 ## Allow only few variables to be localized in Automake.
269 @if egrep -v '^[ \t]*local \$$[_~]( *=|;)' $(srcdir)/automake.in | \
270 grep '^[ \t]*local [^*]'; then \
271 echo "Please avoid 'local'." 1>&2; \
275 ## Don't let AMDEP_TRUE substitution appear in automake.in.
276 sc_AMDEP_TRUE_in_automake_in:
277 @if grep '@AMDEP''_TRUE@' $(srcdir)/automake.in; then \
278 echo "Don't put AMDEP_TRUE substitution in automake.in" 1>&2; \
282 ## Recursive make invocations should always pass $(AM_MAKEFLAGS)
283 ## to $(MAKE), for portability to non-GNU make.
284 sc_tests_make_without_am_makeflags:
285 @if grep '^[^#].*(MAKE) ' $(ams) $(srcdir)/automake.in | \
286 grep -v 'AM_MAKEFLAGS'; then \
287 echo 'Use $$(MAKE) $$(AM_MAKEFLAGS).' 1>&2; \
291 ## Look out for some obsolete variables.
292 sc_tests_obsolete_variables:
296 test_prefer_config_shell \
301 for v in $$vars; do \
302 if grep -E "\b$$v\b" \
303 $(xtests) $(srcdir)/tests/defs \
304 $(srcdir)/tests/defs-static.in \
309 if test -n "$$seen"; then \
310 for v in $$seen; do \
311 echo "Variable '$$v' is obsolete, use 'am_$$v' instead." 1>&2; \
316 ## Tests should never call make directly.
318 @if grep -v '^#' $(xtests) | $(EGREP) ':[ ]*make( |$$)'; then \
319 echo 'Do not run "make" in the above tests. Use "$$MAKE" instead.' 1>&2; \
323 ## Tests should never call autoconf directly.
324 sc_tests_plain_autoconf:
325 @if grep -v '^#' $(xtests) | grep ':[ ]*autoconf\>'; then \
326 echo 'Do not run "autoconf" in the above tests. Use "$$AUTOCONF" instead.' 1>&2; \
330 ## Tests should never call autoupdate directly.
331 sc_tests_plain_autoupdate:
332 @if grep -v '^#' $(xtests) | grep ':[ ]*autoupdate\>'; then \
333 echo 'Do not run "autoupdate" in the above tests. Use "$$AUTOUPDATE" instead.' 1>&2; \
337 ## Tests should never call automake directly.
338 sc_tests_plain_automake:
339 @if grep -v '^#' $(xtests) | grep -E ':[ ]*automake\>([^:]|$$)'; then \
340 echo 'Do not run "automake" in the above tests. Use "$$AUTOMAKE" instead.' 1>&2; \
344 ## Tests should never call autoheader directly.
345 sc_tests_plain_autoheader:
346 @if grep -v '^#' $(xtests) | grep ':[ ]*autoheader\>'; then \
347 echo 'Do not run "autoheader" in the above tests. Use "$$AUTOHEADER" instead.' 1>&2; \
351 ## Tests should never call autoreconf directly.
352 sc_tests_plain_autoreconf:
353 @if grep -v '^#' $(xtests) | grep ':[ ]*autoreconf\>'; then \
354 echo 'Do not run "autoreconf" in the above tests. Use "$$AUTORECONF" instead.' 1>&2; \
358 ## Tests should never call autom4te directly.
359 sc_tests_plain_autom4te:
360 @if grep -v '^#' $(xtests) | grep ':[ ]*autom4te\>'; then \
361 echo 'Do not run "autom4te" in the above tests. Use "$$AUTOM4TE" instead.' 1>&2; \
365 ## Tests should only use END and EOF for here documents
366 ## (so that the next test is effective).
367 sc_tests_here_document_format:
368 @if grep '<<' $(xtests) | grep -v 'END' | grep -v 'EOF'; then \
369 echo 'Use here documents with "END" and "EOF" only, for greppability.' 1>&2; \
373 ## Tests should never call exit directly, but use Exit.
374 ## This is so that the exit status is transported correctly across the 0 trap.
375 ## Ignore comments, testsuite self tests, and one perl line in ext2.test.
376 sc_tests_Exit_not_exit:
377 @found=false; for file in $(xtests); do \
378 case $$file in */self-check-*) continue;; esac; \
379 res=`sed -n -e '/^#/d; /^\$$PERL/d' -e '/<<.*END/,/^END/b' \
380 -e '/<<.*EOF/,/^EOF/b' -e '/exit [$$0-9]/p' $$file`; \
381 if test -n "$$res"; then \
382 echo "$$file:$$res"; \
387 echo 'Do not call plain "exit", use "Exit" instead, in above tests.' 1>&2; \
391 ## Use AUTOMAKE_fails when appropriate
392 sc_tests_automake_fails:
393 @if grep -v '^#' $(xtests) | grep '\$$AUTOMAKE.*&&.*[eE]xit'; then \
394 echo 'Use AUTOMAKE_fails + grep to catch automake failures in the above tests.' 1>&2; \
398 ## Tests should never call aclocal directly.
399 sc_tests_plain_aclocal:
400 @if grep -v '^#' $(xtests) | grep ':[ ]*aclocal\>'; then \
401 echo 'Do not run "aclocal" in the above tests. Use "$$ACLOCAL" instead.' 1>&2; \
405 ## Tests should never call perl directly.
407 @if grep -v '^#' $(xtests) | grep ':[ ]*perl\>'; then \
408 echo 'Do not run "perl" in the above tests. Use "$$PERL" instead.' 1>&2; \
412 ## Setting 'required' after sourcing './defs' is a bug.
413 sc_tests_required_after_defs:
414 @for file in $(xtests); do \
415 if out=`sed -n '/defs/,$${/required=/p;}' $$file`; test -n "$$out"; then \
416 echo 'Do not set "required" after sourcing "defs" in '"$$file: $$out" 1>&2; \
421 ## Overriding a Makefile macro on the command line is not portable when
422 ## recursive targets are used. Better use an envvar. SHELL is an
423 ## exception, POSIX says it can't come from the environment. V, DESTDIR,
424 ## DISTCHECK_CONFIGURE_FLAGS and DISABLE_HARD_ERRORS are exceptions, too,
425 ## as package authors are urged not to initialize them anywhere.
426 ## Finally, 'exp' is used by some ad-hoc checks, where we ensure it's
427 ## ok to override it from the command line.
428 sc_tests_overriding_macros_on_cmdline:
429 @if grep -E '\$$MAKE .*(SHELL=.*=|=.*SHELL=)' $(xtests); then \
430 echo 'Rewrite "$$MAKE foo=bar SHELL=$$SHELL" as "foo=bar $$MAKE -e SHELL=$$SHELL"' 1>&2; \
431 echo ' in the above lines, it is more portable.' 1>&2; \
434 # The first s/// tries to account for usages like "$MAKE || st=$?".
435 # 'DISTCHECK_CONFIGURE_FLAGS' and 'exp' are allowed to contain whitespace in
436 # their definitions, hence the more complex last three substitutions below.
437 # Also, the 'make-dryrun.test' is whitelisted, since there we need to
438 # override variables from the command line in order to cover the expected
440 @tests=`for t in $(xtests); do \
441 case $$t in */make-dryrun.test);; *) echo $$t;; esac; \
443 if sed -e 's/ || .*//' -e 's/ && .*//' \
444 -e 's/ DESTDIR=[^ ]*/ /' -e 's/ SHELL=[^ ]*/ /' \
445 -e 's/ V=[^ ]*/ /' -e 's/ DISABLE_HARD_ERRORS=[^ ]*/ /' \
446 -e "s/ DISTCHECK_CONFIGURE_FLAGS='[^']*'/ /" \
447 -e 's/ DISTCHECK_CONFIGURE_FLAGS="[^"]*"/ /' \
448 -e 's/ DISTCHECK_CONFIGURE_FLAGS=[^ ]/ /' \
449 -e "s/ exp='[^']*'/ /" \
450 -e 's/ exp="[^"]*"/ /' \
451 -e 's/ exp=[^ ]/ /' \
452 $$tests | grep '\$$MAKE .*='; then \
453 echo 'Rewrite "$$MAKE foo=bar" as "foo=bar $$MAKE -e" in the above lines,' 1>&2; \
454 echo 'it is more portable.' 1>&2; \
457 @if grep 'SHELL=.*\$$MAKE' $(xtests); then \
458 echo '$$MAKE ignores the SHELL envvar, use "$$MAKE SHELL=$$SHELL" in' 1>&2; \
459 echo 'the above lines.' 1>&2; \
463 ## Never use 'sleep 1' to create files with different timestamps.
464 ## Use '$sleep' instead. Some filesystems (e.g., Windows) have only
465 ## a 2sec resolution.
466 sc_tests_plain_sleep:
467 @if grep -E '\bsleep +[12345]\b' $(xtests); then \
468 echo 'Do not use "sleep x" in the above tests. Use "$$sleep" instead.' 1>&2; \
472 ## fgrep and egrep are not required by POSIX.
473 sc_tests_plain_egrep_fgrep:
474 @if grep -E '\b[ef]grep\b' $(xtests) ; then \
475 echo 'Do not use egrep or fgrep in test cases. Use $$FGREP or $$EGREP.' 1>&2; \
478 @if grep -E '\b[ef]grep\b' $(ams) $(srcdir)/m4/*.m4; then \
479 echo 'Do not use egrep or fgrep in the above files, they are not portable.' 1>&2; \
483 ## Prefer 'configure.ac' over the obsolescent 'configure.in' as the name
484 ## for configure input files in our testsuite. The latter has been
485 ## deprecated for several years (at least since autoconf 2.50).
486 sc_tests_no_configure_in:
487 @if grep -E '\bconfigure\\*\.in\b' $(xtests) $(srcdir)/tests/defs \
488 | grep -Ev '/backcompat.*\.(test|tap):' \
489 | grep -Ev '/autodist-configure-no-subdir\.test:' \
490 | grep -Ev '/(configure|help)\.test:' \
493 echo "Use 'configure.ac', not 'configure.in', as the name" >&2; \
494 echo "for configure input files in the test cases above." >&2; \
498 ## Rule to ensure that the testsuite has been run before. We don't depend
499 ## on 'check' here, because that would be very wasteful in the common case.
500 ## We could run "make check RECHECK_LOGS=" and avoid toplevel races with
501 ## AM_RECURSIVE_TARGETS. Suggest keeping test directories around for
502 ## greppability of the Makefile.in files.
503 sc_ensure_testsuite_has_run:
504 @if test ! -f tests/test-suite.log; then \
505 echo 'Run "env keep_testdirs=yes make check" before' \
506 'running "make maintainer-check"' >&2; \
509 .PHONY: sc_ensure_testsuite_has_run
511 ## Ensure our warning and error messages do not contain duplicate 'warning:' prefixes.
512 ## This test actually depends on the testsuite having been run before.
513 sc_tests_logs_duplicate_prefixes: sc_ensure_testsuite_has_run
514 @if grep -E '(warning|error):.*(warning|error):' tests/*.log; then \
515 echo 'Duplicate warning/error message prefixes seen in above tests.' >&2; \
519 ## Ensure variables are listed before rules in Makefile.in files we generate.
520 sc_tests_makefile_variable_order: sc_ensure_testsuite_has_run
522 for file in `find tests -name Makefile.in -print`; do \
525 -e '/\\\\$$/{' -e N -e 'b x' -e '}' \
526 -e '# Literal TAB.' \
528 -e '# Allow @ so we match conditionals.' \
529 -e '/^ *[a-zA-Z_@]\{1,\} *=/p' $$file`; \
530 if test -n "$$latevars"; then \
531 echo "Variables are expanded too late in $$file:" >&2; \
532 echo "$$latevars" | sed 's/^/ /' >&2; \
536 test $$st -eq 0 || { \
537 echo 'Ensure variables are expanded before rules' >&2; \
541 ## Using ':' as a PATH separator is not portable.
542 sc_tests_PATH_SEPARATOR:
543 @if grep -E '\bPATH=.*:.*' $(xtests) ; then \
544 echo "Use '\$$PATH_SEPARATOR', not ':', in PATH definitions" \
550 @if grep 'mkdir_p' $(srcdir)/automake.in $(ams) $(xtests); then \
551 echo 'Do not use mkdir_p in the above files, use MKDIR_P.' 1>&2; \
555 ## Try to make sure all @...@ substitutions are covered by our
556 ## substitution rule.
558 @if test `grep -E '^[^#]*@[A-Za-z_0-9]+@' aclocal | wc -l` -ne 0; then \
559 echo "Unresolved @...@ substitution in aclocal" 1>&2; \
562 @if test `grep -E '^[^#]*@[A-Za-z_0-9]+@' automake | wc -l` -ne 0; then \
563 echo "Unresolved @...@ substitution in automake" 1>&2; \
568 @if grep -E "[^\'\"]\\\$$\(DESTDIR" $(ams); then \
569 echo 'Suspicious unquoted DESTDIR uses.' 1>&2 ; \
574 @if grep ' ' $(srcdir)/doc/automake.texi; then \
575 echo 'Do not use tabs in the manual.' 1>&2; \
580 @if grep -E '([^@]|^)@([ ][^@]|$$)' $(srcdir)/doc/automake.texi; \
582 echo 'Unescaped @.' 1>&2; \