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 \
30 ls $$d/t/*.$$s $$d/t/ax/*.$$s 2>/dev/null; \
34 xdefs = $(srcdir)/defs $(srcdir)/defs-static.in
36 ams := $(shell find $(srcdir) -name '*.dir' -prune -o -name '*.am' -print)
38 # Some simple checks, and then ordinary check. These are only really
39 # guaranteed to work on my machine.
40 syntax_check_rules = \
41 $(sc_tests_plain_check_rules) \
43 sc_diff_automake_in_automake \
44 sc_diff_aclocal_in_automake \
46 sc_no_brace_variable_expansions \
48 sc_no_for_variable_in_macro \
50 sc_pre_normal_post_install_uninstall \
52 sc_perl_no_split_regex_space \
55 sc_perl_at_uscore_in_scalar_context \
57 sc_AMDEP_TRUE_in_automake_in \
58 sc_tests_make_without_am_makeflags \
59 sc_tests_obsolete_variables \
60 sc_tests_here_document_format \
61 sc_tests_Exit_not_exit \
62 sc_tests_automake_fails \
63 sc_tests_required_after_defs \
64 sc_tests_overriding_macros_on_cmdline \
65 sc_tests_plain_sleep \
66 sc_m4_am_plain_egrep_fgrep \
67 sc_tests_no_configure_in \
68 sc_tests_PATH_SEPARATOR \
69 sc_tests_logs_duplicate_prefixes \
70 sc_tests_makefile_variable_order \
76 ## Look for test whose names can cause spurious failures when used as
77 ## first argument to AC_INIT (chiefly because they might contain an
78 ## m4/m4sugar builtin or macro name).
128 @m4_builtin_rx=`echo $(m4_builtins) | sed 's/ /|/g'`; \
129 m4_macro_rx="\\<($$m4_builtin_rx)\\>|\\<_?(A[CUMHS]|m4)_"; \
131 for t in $(xtests); do echo $$t; done \
132 | LC_ALL=C grep -E "$$m4_macro_rx"; \
134 echo "the names of the tests above can be problematic" 1>&2; \
135 echo "Avoid test names that contain names of m4 macros" 1>&2; \
139 ## These check avoids accidental configure substitutions in the source.
140 ## There are exactly 9 lines that should be modified from automake.in to
141 ## automake, and 10 lines that should be modified from aclocal.in to
142 ## aclocal; these wors out to 32 and 34 lines of diffs, respectively.
143 sc_diff_automake_in_automake:
144 @if test `diff $(srcdir)/automake.in automake | wc -l` -ne 32; then \
145 echo "found too many diffs between automake.in and automake" 1>&2; \
146 diff -c $(srcdir)/automake.in automake; \
149 sc_diff_aclocal_in_aclocal:
150 @if test `diff $(srcdir)/aclocal.in aclocal | wc -l` -ne 34; then \
151 echo "found too many diffs between aclocal.in and aclocal" 1>&2; \
152 diff -c $(srcdir)/aclocal.in aclocal; \
156 ## Syntax check with default Perl (on my machine, Perl 5).
158 @perllibdir="./lib$(PATH_SEPARATOR)$(srcdir)/lib" $(PERL) -c -w automake
159 @perllibdir="./lib$(PATH_SEPARATOR)$(srcdir)/lib" $(PERL) -c -w aclocal
161 ## expect no instances of '${...}'. However, $${...} is ok, since that
162 ## is a shell construct, not a Makefile construct.
163 sc_no_brace_variable_expansions:
164 @if grep -F '$${' $(ams) | grep -F -v '$$$$'; then \
165 echo "Found too many uses of '\$${' in the lines above." 1>&2; \
169 ## Make sure 'rm' is called with '-f'.
171 @if grep -v '^#' $(ams) $(xtests) \
172 | grep -v '/spy-rm\.tap:' \
173 | grep -E '\<rm ([^-]|\-[^f ]*\>)'; \
175 echo "Suspicious 'rm' invocation." 1>&2; \
179 ## Never use something like "for file in $(FILES)", this doesn't work
180 ## if FILES is empty or if it contains shell meta characters (e.g. $ is
181 ## commonly used in Java filenames).
182 sc_no_for_variable_in_macro:
183 @if grep 'for .* in \$$(' $(ams) | grep -v '/Makefile\.am:'; then \
184 echo 'Use "list=$$(mumble); for var in $$$$list".' 1>&2 ; \
188 ## Make sure all invocations of mkinstalldirs are correct.
190 @if grep -n 'mkinstalldirs' $(ams) \
191 | grep -F -v '$$(mkinstalldirs)' \
192 | grep -v '^\./Makefile.am:[0-9][0-9]*: *lib/mkinstalldirs \\$$'; \
194 echo "Found incorrect use of mkinstalldirs in the lines above" 1>&2; \
198 ## Make sure all calls to PRE/NORMAL/POST_INSTALL/UNINSTALL
199 sc_pre_normal_post_install_uninstall:
200 @if grep -E -n '\((PRE|NORMAL|POST)_(|UN)INSTALL\)' $(ams) | \
201 grep -v ':##' | grep -v ': @\$$('; then \
202 echo "Found incorrect use of PRE/NORMAL/POST_INSTALL/UNINSTALL in the lines above" 1>&2; \
206 ## We never want to use "undef", only "delete", but for $/.
208 @if grep -n -w 'undef ' $(srcdir)/automake.in | \
209 grep -F -v 'undef $$/'; then \
210 echo "Found undef in automake.in; use delete instead" 1>&2; \
214 ## We never want split (/ /,...), only split (' ', ...).
215 sc_perl_no_split_regex_space:
216 @if grep -n 'split (/ /' $(srcdir)/automake.in; then \
217 echo "Found bad split in the lines above." 1>&2; \
221 ## Look for cd within backquotes
223 @if grep -n '^[^#]*` *cd ' $(srcdir)/automake.in $(ams); then \
224 echo "Consider using \$$(am__cd) in the lines above." 1>&2; \
228 ## Look for cd to a relative directory (may be influenced by CDPATH).
229 ## Skip some known directories that are OK.
231 @if grep -n '^[^#]*cd ' $(srcdir)/automake.in $(ams) | \
232 grep -v 'echo.*cd ' | \
233 grep -v 'am__cd =' | \
234 grep -v '^[^#]*cd [./]' | \
235 grep -v '^[^#]*cd \$$(top_builddir)' | \
236 grep -v '^[^#]*cd "\$$\$$am__cwd' | \
237 grep -v '^[^#]*cd \$$(abs' | \
238 grep -v '^[^#]*cd "\$$(DESTDIR)'; then \
239 echo "Consider using \$$(am__cd) in the lines above." 1>&2; \
243 ## Using @_ in a scalar context is most probably a programming error.
244 sc_perl_at_uscore_in_scalar_context:
245 @if grep -Hn '[^@_A-Za-z0-9][_A-Za-z0-9]*[^) ] *= *@_' $(srcdir)/automake.in; then \
246 echo "Using @_ in a scalar context in the lines above." 1>&2; \
250 ## Allow only few variables to be localized in Automake.
252 @if egrep -v '^[ \t]*local \$$[_~]( *=|;)' $(srcdir)/automake.in | \
253 grep '^[ \t]*local [^*]'; then \
254 echo "Please avoid 'local'." 1>&2; \
258 ## Don't let AMDEP_TRUE substitution appear in automake.in.
259 sc_AMDEP_TRUE_in_automake_in:
260 @if grep '@AMDEP''_TRUE@' $(srcdir)/automake.in; then \
261 echo "Don't put AMDEP_TRUE substitution in automake.in" 1>&2; \
265 ## Recursive make invocations should always pass $(AM_MAKEFLAGS)
266 ## to $(MAKE), for portability to non-GNU make.
267 sc_tests_make_without_am_makeflags:
268 @if grep '^[^#].*(MAKE) ' $(ams) $(srcdir)/automake.in \
269 | grep -v 'AM_MAKEFLAGS' \
270 | grep -v '/am/header-vars\.am:.*am--echo.*| $$(MAKE) -f *-'; \
272 echo 'Use $$(MAKE) $$(AM_MAKEFLAGS).' 1>&2; \
276 ## Look out for some obsolete variables.
277 sc_tests_obsolete_variables:
280 test_prefer_config_shell \
287 for v in $$vars; do \
288 if grep -E "\b$$v\b" $(xtests) $(xdefs); then \
292 if test -n "$$seen"; then \
293 for v in $$seen; do \
295 parallel_tests|am_parallel_tests) v2=am_serial_tests;; \
298 echo "Variable '$$v' is obsolete, use '$$v2' instead." 1>&2; \
303 ## Tests should never call some programs directly, but only through the
304 ## corresponding variable (e.g., '$MAKE', not 'make'). This will allow
305 ## the programs to be overridden at configure time (for less brittleness)
306 ## or by the user at make time (to allow better testsuite coverage).
307 sc_tests_plain_check_rules = \
308 sc_tests_plain_egrep \
309 sc_tests_plain_fgrep \
310 sc_tests_plain_make \
311 sc_tests_plain_perl \
312 sc_tests_plain_automake \
313 sc_tests_plain_aclocal \
314 sc_tests_plain_autoconf \
315 sc_tests_plain_autoupdate \
316 sc_tests_plain_autom4te \
317 sc_tests_plain_autoheader \
318 sc_tests_plain_autoreconf
320 toupper = $(shell echo $(1) | LC_ALL=C tr '[a-z]' '[A-Z]')
322 $(sc_tests_plain_check_rules): sc_tests_plain_% :
323 @# The leading ':' in the grep below is what is printed by the
324 @# preceding 'grep -v' after the file name.
325 @# It works here as a poor man's substitute for beginning-of-line
327 @if grep -v '^[ ]*#' $(xtests) \
328 | $(EGREP) '(:|\bif|\bnot|[;!{\|\(]|&&|\|\|)[ ]*?$*\b'; \
330 echo 'Do not run "$*" in the above tests.' \
331 'Use "$$$(call toupper,$*)" instead.' 1>&2; \
335 ## Tests should only use END and EOF for here documents
336 ## (so that the next test is effective).
337 sc_tests_here_document_format:
338 @if grep '<<' $(xtests) | grep -Ev '\b(END|EOF)\b|\bstd::cout <<'; then \
339 echo 'Use here documents with "END" and "EOF" only, for greppability.' 1>&2; \
343 ## Tests should never call exit directly, but use Exit.
344 ## This is so that the exit status is transported correctly across the 0 trap.
345 ## Ignore comments, testsuite self tests, and one perl line in ext2.sh.
346 sc_tests_Exit_not_exit:
347 @found=false; for file in $(xtests); do \
348 case $$file in */self-check-*) continue;; esac; \
349 res=`sed -n -e '/^#/d; /^\$$PERL/d' -e '/<<.*END/,/^END/b' \
350 -e '/<<.*EOF/,/^EOF/b' -e '/exit [$$0-9]/p' $$file`; \
351 if test -n "$$res"; then \
352 echo "$$file:$$res"; \
357 echo 'Do not call plain "exit", use "Exit" instead, in above tests.' 1>&2; \
361 ## Use AUTOMAKE_fails when appropriate
362 sc_tests_automake_fails:
363 @if grep -v '^#' $(xtests) | grep '\$$AUTOMAKE.*&&.*[eE]xit'; then \
364 echo 'Use AUTOMAKE_fails + grep to catch automake failures in the above tests.' 1>&2; \
368 ## Setting 'required' after sourcing './defs' is a bug.
369 sc_tests_required_after_defs:
370 @for file in $(xtests); do \
371 if out=`sed -n '/defs/,$${/required=/p;}' $$file`; test -n "$$out"; then \
372 echo 'Do not set "required" after sourcing "defs" in '"$$file: $$out" 1>&2; \
377 ## Overriding a Makefile macro on the command line is not portable when
378 ## recursive targets are used. Better use an envvar. SHELL is an
379 ## exception, POSIX says it can't come from the environment. V, DESTDIR,
380 ## DISTCHECK_CONFIGURE_FLAGS and DISABLE_HARD_ERRORS are exceptions, too,
381 ## as package authors are urged not to initialize them anywhere.
382 ## Finally, 'exp' is used by some ad-hoc checks, where we ensure it's
383 ## ok to override it from the command line.
384 sc_tests_overriding_macros_on_cmdline:
385 @if grep -E '\$$MAKE .*(SHELL=.*=|=.*SHELL=)' $(xtests); then \
386 echo 'Rewrite "$$MAKE foo=bar SHELL=$$SHELL" as "foo=bar $$MAKE -e SHELL=$$SHELL"' 1>&2; \
387 echo ' in the above lines, it is more portable.' 1>&2; \
390 # The first s/// tries to account for usages like "$MAKE || st=$?".
391 # 'DISTCHECK_CONFIGURE_FLAGS' and 'exp' are allowed to contain whitespace in
392 # their definitions, hence the more complex last three substitutions below.
393 # Also, the 'make-dryrun.sh' is whitelisted, since there we need to
394 # override variables from the command line in order to cover the expected
396 @tests=`for t in $(xtests); do \
397 case $$t in */make-dryrun.sh);; *) echo $$t;; esac; \
399 if sed -e 's/ || .*//' -e 's/ && .*//' \
400 -e 's/ DESTDIR=[^ ]*/ /' -e 's/ SHELL=[^ ]*/ /' \
401 -e 's/ V=[^ ]*/ /' -e 's/ DISABLE_HARD_ERRORS=[^ ]*/ /' \
402 -e "s/ DISTCHECK_CONFIGURE_FLAGS='[^']*'/ /" \
403 -e 's/ DISTCHECK_CONFIGURE_FLAGS="[^"]*"/ /' \
404 -e 's/ DISTCHECK_CONFIGURE_FLAGS=[^ ]/ /' \
405 -e "s/ exp='[^']*'/ /" \
406 -e 's/ exp="[^"]*"/ /' \
407 -e 's/ exp=[^ ]/ /' \
408 $$tests | grep '\$$MAKE .*='; then \
409 echo 'Rewrite "$$MAKE foo=bar" as "foo=bar $$MAKE -e" in the above lines,' 1>&2; \
410 echo 'it is more portable.' 1>&2; \
413 @if grep 'SHELL=.*\$$MAKE' $(xtests); then \
414 echo '$$MAKE ignores the SHELL envvar, use "$$MAKE SHELL=$$SHELL" in' 1>&2; \
415 echo 'the above lines.' 1>&2; \
419 ## Never use 'sleep 1' to create files with different timestamps.
420 ## Use '$sleep' instead. Some filesystems (e.g., Windows) have only
421 ## a 2sec resolution.
422 sc_tests_plain_sleep:
423 @if grep -E '\bsleep +[12345]\b' $(xtests); then \
424 echo 'Do not use "sleep x" in the above tests. Use "$$sleep" instead.' 1>&2; \
428 ## fgrep and egrep are not required by POSIX.
429 sc_m4_am_plain_egrep_fgrep:
430 @if grep -E '\b[ef]grep\b' $(ams) $(srcdir)/m4/*.m4; then \
431 echo 'Do not use egrep or fgrep in the above files,' \
432 'they are not portable.' 1>&2; \
436 ## Prefer 'configure.ac' over the obsolescent 'configure.in' as the name
437 ## for configure input files in our testsuite. The latter has been
438 ## deprecated for several years (at least since autoconf 2.50).
439 sc_tests_no_configure_in:
440 @if grep -E '\bconfigure\\*\.in\b' $(xtests) $(xdefs) \
441 | grep -Ev '/backcompat.*\.(sh|tap):' \
442 | grep -Ev '/autodist-configure-no-subdir\.sh:' \
443 | grep -Ev '/(configure|help)\.sh:' \
446 echo "Use 'configure.ac', not 'configure.in', as the name" >&2; \
447 echo "for configure input files in the test cases above." >&2; \
451 ## Rule to ensure that the testsuite has been run before. We don't depend
452 ## on 'check' here, because that would be very wasteful in the common case.
453 ## We could run "make check RECHECK_LOGS=" and avoid toplevel races with
454 ## AM_RECURSIVE_TARGETS. Suggest keeping test directories around for
455 ## greppability of the Makefile.in files.
456 sc_ensure_testsuite_has_run:
457 @if test ! -f '$(TEST_SUITE_LOG)'; then \
458 echo 'Run "env keep_testdirs=yes make check" before' \
459 'running "make maintainer-check"' >&2; \
462 .PHONY: sc_ensure_testsuite_has_run
464 ## Ensure our warning and error messages do not contain duplicate 'warning:' prefixes.
465 ## This test actually depends on the testsuite having been run before.
466 sc_tests_logs_duplicate_prefixes: sc_ensure_testsuite_has_run
467 @if grep -E '(warning|error):.*(warning|error):' t/*.log; then \
468 echo 'Duplicate warning/error message prefixes seen in above tests.' >&2; \
472 ## Ensure variables are listed before rules in Makefile.in files we generate.
473 sc_tests_makefile_variable_order: sc_ensure_testsuite_has_run
475 for file in `find t -name Makefile.in -print`; do \
478 -e '/\\\\$$/{' -e N -e 'b x' -e '}' \
479 -e '# Literal TAB.' \
481 -e '# Allow @ so we match conditionals.' \
482 -e '/^ *[a-zA-Z_@]\{1,\} *=/p' $$file`; \
483 if test -n "$$latevars"; then \
484 echo "Variables are expanded too late in $$file:" >&2; \
485 echo "$$latevars" | sed 's/^/ /' >&2; \
489 test $$st -eq 0 || { \
490 echo 'Ensure variables are expanded before rules' >&2; \
494 ## Using ':' as a PATH separator is not portable.
495 sc_tests_PATH_SEPARATOR:
496 @if grep -E '\bPATH=.*:.*' $(xtests) ; then \
497 echo "Use '\$$PATH_SEPARATOR', not ':', in PATH definitions" \
502 ## Try to make sure all @...@ substitutions are covered by our
503 ## substitution rule.
505 @if test `grep -E '^[^#]*@[A-Za-z_0-9]+@' aclocal | wc -l` -ne 0; then \
506 echo "Unresolved @...@ substitution in aclocal" 1>&2; \
509 @if test `grep -E '^[^#]*@[A-Za-z_0-9]+@' automake | wc -l` -ne 0; then \
510 echo "Unresolved @...@ substitution in automake" 1>&2; \
515 @if grep -E "[^\'\"]\\\$$\(DESTDIR" $(ams); then \
516 echo 'Suspicious unquoted DESTDIR uses.' 1>&2 ; \
521 @if grep ' ' $(srcdir)/doc/automake.texi; then \
522 echo 'Do not use tabs in the manual.' 1>&2; \
527 @if grep -E '([^@]|^)@([ ][^@]|$$)' $(srcdir)/doc/automake.texi; \
529 echo 'Unescaped @.' 1>&2; \
533 $(syntax_check_rules): automake aclocal
534 maintainer-check: $(syntax_check_rules)
535 .PHONY: maintainer-check $(syntax_check_rules)
537 ## Check that the list of tests given in the Makefile is equal to the
538 ## list of all test scripts in the Automake testsuite.
539 maintainer-check: maintainer-check-list-of-tests