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)/t/ax/test-init.sh $(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 \
67 sc_m4_am_plain_egrep_fgrep \
68 sc_tests_no_configure_in \
69 sc_tests_PATH_SEPARATOR \
70 sc_tests_logs_duplicate_prefixes \
71 sc_tests_makefile_variable_order \
77 ## Look for test whose names can cause spurious failures when used as
78 ## first argument to AC_INIT (chiefly because they might contain an
79 ## m4/m4sugar builtin or macro name).
129 @m4_builtin_rx=`echo $(m4_builtins) | sed 's/ /|/g'`; \
130 m4_macro_rx="\\<($$m4_builtin_rx)\\>|\\<_?(A[CUMHS]|m4)_"; \
132 for t in $(xtests); do echo $$t; done \
133 | LC_ALL=C grep -E "$$m4_macro_rx"; \
135 echo "the names of the tests above can be problematic" 1>&2; \
136 echo "Avoid test names that contain names of m4 macros" 1>&2; \
140 ## These check avoids accidental configure substitutions in the source.
141 ## There are exactly 9 lines that should be modified from automake.in to
142 ## automake, and 10 lines that should be modified from aclocal.in to
143 ## aclocal; these wors out to 32 and 34 lines of diffs, respectively.
144 sc_diff_automake_in_automake:
145 @if test `diff $(srcdir)/automake.in automake | wc -l` -ne 32; then \
146 echo "found too many diffs between automake.in and automake" 1>&2; \
147 diff -c $(srcdir)/automake.in automake; \
150 sc_diff_aclocal_in_aclocal:
151 @if test `diff $(srcdir)/aclocal.in aclocal | wc -l` -ne 34; then \
152 echo "found too many diffs between aclocal.in and aclocal" 1>&2; \
153 diff -c $(srcdir)/aclocal.in aclocal; \
157 ## Syntax check with default Perl (on my machine, Perl 5).
159 @perllibdir="./lib$(PATH_SEPARATOR)$(srcdir)/lib" $(PERL) -c -w automake
160 @perllibdir="./lib$(PATH_SEPARATOR)$(srcdir)/lib" $(PERL) -c -w aclocal
162 ## Expect no instances of '${...}'. However, $${...} is ok, since that
163 ## is a shell construct, not a Makefile construct.
164 sc_no_brace_variable_expansions:
165 @if grep -v '^ *#' $(ams) | grep -F '$${' | grep -F -v '$$$$'; then \
166 echo "Found too many uses of '\$${' in the lines above." 1>&2; \
170 ## Make sure 'rm' is called with '-f'.
172 @if grep -v '^#' $(ams) $(xtests) \
173 | grep -vE '/(spy-rm\.tap|subobj-clean.*-pr10697\.sh):' \
174 | grep -E '\<rm ([^-]|\-[^f ]*\>)'; \
176 echo "Suspicious 'rm' invocation." 1>&2; \
180 ## Never use something like "for file in $(FILES)", this doesn't work
181 ## if FILES is empty or if it contains shell meta characters (e.g. $ is
182 ## commonly used in Java filenames).
183 sc_no_for_variable_in_macro:
184 @if grep 'for .* in \$$(' $(ams) | grep -v '/Makefile\.am:'; then \
185 echo 'Use "list=$$(mumble); for var in $$$$list".' 1>&2 ; \
189 ## Make sure all invocations of mkinstalldirs are correct.
191 @if grep -n 'mkinstalldirs' $(ams) \
192 | grep -F -v '$$(mkinstalldirs)' \
193 | grep -v '^\./Makefile.am:[0-9][0-9]*: *lib/mkinstalldirs \\$$'; \
195 echo "Found incorrect use of mkinstalldirs in the lines above" 1>&2; \
199 ## Make sure all calls to PRE/NORMAL/POST_INSTALL/UNINSTALL
200 sc_pre_normal_post_install_uninstall:
201 @if grep -E -n '\((PRE|NORMAL|POST)_(|UN)INSTALL\)' $(ams) | \
202 grep -v ':##' | grep -v ': @\$$('; then \
203 echo "Found incorrect use of PRE/NORMAL/POST_INSTALL/UNINSTALL in the lines above" 1>&2; \
207 ## We never want to use "undef", only "delete", but for $/.
209 @if grep -n -w 'undef ' $(srcdir)/automake.in | \
210 grep -F -v 'undef $$/'; then \
211 echo "Found undef in automake.in; use delete instead" 1>&2; \
215 ## We never want split (/ /,...), only split (' ', ...).
216 sc_perl_no_split_regex_space:
217 @if grep -n 'split (/ /' $(srcdir)/automake.in; then \
218 echo "Found bad split in the lines above." 1>&2; \
222 ## Look for cd within backquotes
224 @if grep -n '^[^#]*` *cd ' $(srcdir)/automake.in $(ams); then \
225 echo "Consider using \$$(am__cd) in the lines above." 1>&2; \
229 ## Look for cd to a relative directory (may be influenced by CDPATH).
230 ## Skip some known directories that are OK.
232 @if grep -n '^[^#]*cd ' $(srcdir)/automake.in $(ams) | \
233 grep -v 'echo.*cd ' | \
234 grep -v 'am__cd =' | \
235 grep -v '^[^#]*cd [./]' | \
236 grep -v '^[^#]*cd \$$(top_builddir)' | \
237 grep -v '^[^#]*cd "\$$\$$am__cwd' | \
238 grep -v '^[^#]*cd \$$(abs' | \
239 grep -v '^[^#]*cd "\$$(DESTDIR)'; then \
240 echo "Consider using \$$(am__cd) in the lines above." 1>&2; \
244 ## Using @_ in a scalar context is most probably a programming error.
245 sc_perl_at_uscore_in_scalar_context:
246 @if grep -Hn '[^@_A-Za-z0-9][_A-Za-z0-9]*[^) ] *= *@_' $(srcdir)/automake.in; then \
247 echo "Using @_ in a scalar context in the lines above." 1>&2; \
251 ## Allow only few variables to be localized in Automake.
253 @if egrep -v '^[ \t]*local \$$[_~]( *=|;)' $(srcdir)/automake.in | \
254 grep '^[ \t]*local [^*]'; then \
255 echo "Please avoid 'local'." 1>&2; \
259 ## Don't let AMDEP_TRUE substitution appear in automake.in.
260 sc_AMDEP_TRUE_in_automake_in:
261 @if grep '@AMDEP''_TRUE@' $(srcdir)/automake.in; then \
262 echo "Don't put AMDEP_TRUE substitution in automake.in" 1>&2; \
266 ## Recursive make invocations should always pass $(AM_MAKEFLAGS)
267 ## to $(MAKE), for portability to non-GNU make.
268 sc_tests_make_without_am_makeflags:
269 @if grep '^[^#].*(MAKE) ' $(ams) $(srcdir)/automake.in \
270 | grep -v 'AM_MAKEFLAGS' \
271 | grep -v '/am/header-vars\.am:.*am--echo.*| $$(MAKE) -f *-'; \
273 echo 'Use $$(MAKE) $$(AM_MAKEFLAGS).' 1>&2; \
277 ## Look out for some obsolete variables.
278 sc_tests_obsolete_variables:
281 test_prefer_config_shell \
288 for v in $$vars; do \
289 if grep -E "\b$$v\b" $(xtests) $(xdefs); then \
293 if test -n "$$seen"; then \
294 for v in $$seen; do \
296 parallel_tests|am_parallel_tests) v2=am_serial_tests;; \
299 echo "Variable '$$v' is obsolete, use '$$v2' instead." 1>&2; \
304 ## Tests should never call some programs directly, but only through the
305 ## corresponding variable (e.g., '$MAKE', not 'make'). This will allow
306 ## the programs to be overridden at configure time (for less brittleness)
307 ## or by the user at make time (to allow better testsuite coverage).
308 sc_tests_plain_check_rules = \
309 sc_tests_plain_egrep \
310 sc_tests_plain_fgrep \
311 sc_tests_plain_make \
312 sc_tests_plain_perl \
313 sc_tests_plain_automake \
314 sc_tests_plain_aclocal \
315 sc_tests_plain_autoconf \
316 sc_tests_plain_autoupdate \
317 sc_tests_plain_autom4te \
318 sc_tests_plain_autoheader \
319 sc_tests_plain_autoreconf
321 toupper = $(shell echo $(1) | LC_ALL=C tr '[a-z]' '[A-Z]')
323 $(sc_tests_plain_check_rules): sc_tests_plain_% :
324 @# The leading ':' in the grep below is what is printed by the
325 @# preceding 'grep -v' after the file name.
326 @# It works here as a poor man's substitute for beginning-of-line
328 @if grep -v '^[ ]*#' $(xtests) \
329 | $(EGREP) '(:|\bif|\bnot|[;!{\|\(]|&&|\|\|)[ ]*?$*\b'; \
331 echo 'Do not run "$*" in the above tests.' \
332 'Use "$$$(call toupper,$*)" instead.' 1>&2; \
336 ## Tests should only use END and EOF for here documents
337 ## (so that the next test is effective).
338 sc_tests_here_document_format:
339 @if grep '<<' $(xtests) | grep -Ev '\b(END|EOF)\b|\bcout <<'; then \
340 echo 'Use here documents with "END" and "EOF" only, for greppability.' 1>&2; \
344 ## Tests should never call exit directly, but use Exit.
345 ## This is so that the exit status is transported correctly across the 0 trap.
346 ## Ignore comments and our testsuite's own self tests.
347 sc_tests_Exit_not_exit:
348 @found=false; for file in $(xtests); do \
349 case $$file in */self-check-*) continue;; esac; \
350 res=`sed -n -e '/^#/d' -e '/<<.*END/,/^END/b' -e '/<<.*EOF/,/^EOF/b' \
351 -e '/exit [$$0-9]/p' $$file`; \
352 if test -n "$$res"; then \
353 echo "$$file:$$res"; \
358 echo 'Do not call plain "exit", use "Exit" instead, in above tests.' 1>&2; \
362 ## Use AUTOMAKE_fails when appropriate
363 sc_tests_automake_fails:
364 @if grep -v '^#' $(xtests) | grep '\$$AUTOMAKE.*&&.*[eE]xit'; then \
365 echo 'Use AUTOMAKE_fails + grep to catch automake failures in the above tests.' 1>&2; \
369 ## Setting 'required' after sourcing './defs' is a bug.
370 sc_tests_required_after_defs:
371 @for file in $(xtests); do \
372 if out=`sed -n '/defs/,$${/required=/p;}' $$file`; test -n "$$out"; then \
373 echo 'Do not set "required" after sourcing "defs" in '"$$file: $$out" 1>&2; \
378 ## Overriding a Makefile macro on the command line is not portable when
379 ## recursive targets are used. Better use an envvar. SHELL is an
380 ## exception, POSIX says it can't come from the environment. V, DESTDIR,
381 ## DISTCHECK_CONFIGURE_FLAGS and DISABLE_HARD_ERRORS are exceptions, too,
382 ## as package authors are urged not to initialize them anywhere.
383 ## Finally, 'exp' is used by some ad-hoc checks, where we ensure it's
384 ## ok to override it from the command line.
385 sc_tests_overriding_macros_on_cmdline:
386 @if grep -E '\$$MAKE .*(SHELL=.*=|=.*SHELL=)' $(xtests); then \
387 echo 'Rewrite "$$MAKE foo=bar SHELL=$$SHELL" as "foo=bar $$MAKE -e SHELL=$$SHELL"' 1>&2; \
388 echo ' in the above lines, it is more portable.' 1>&2; \
391 # The first s/// tries to account for usages like "$MAKE || st=$?".
392 # 'DISTCHECK_CONFIGURE_FLAGS' and 'exp' are allowed to contain whitespace in
393 # their definitions, hence the more complex last three substitutions below.
394 # Also, the 'make-dryrun.sh' is whitelisted, since there we need to
395 # override variables from the command line in order to cover the expected
397 @tests=`for t in $(xtests); do \
398 case $$t in */make-dryrun.sh);; *) echo $$t;; esac; \
400 if sed -e 's/ || .*//' -e 's/ && .*//' \
401 -e 's/ DESTDIR=[^ ]*/ /' -e 's/ SHELL=[^ ]*/ /' \
402 -e 's/ V=[^ ]*/ /' -e 's/ DISABLE_HARD_ERRORS=[^ ]*/ /' \
403 -e "s/ DISTCHECK_CONFIGURE_FLAGS='[^']*'/ /" \
404 -e 's/ DISTCHECK_CONFIGURE_FLAGS="[^"]*"/ /' \
405 -e 's/ DISTCHECK_CONFIGURE_FLAGS=[^ ]/ /' \
406 -e "s/ exp='[^']*'/ /" \
407 -e 's/ exp="[^"]*"/ /' \
408 -e 's/ exp=[^ ]/ /' \
409 $$tests | grep '\$$MAKE .*='; then \
410 echo 'Rewrite "$$MAKE foo=bar" as "foo=bar $$MAKE -e" in the above lines,' 1>&2; \
411 echo 'it is more portable.' 1>&2; \
414 @if grep 'SHELL=.*\$$MAKE' $(xtests); then \
415 echo '$$MAKE ignores the SHELL envvar, use "$$MAKE SHELL=$$SHELL" in' 1>&2; \
416 echo 'the above lines.' 1>&2; \
420 ## Prefer use of our 'is_newest' auxiliary script over the more hacky
421 ## idiom "test $(ls -1t new old | sed 1q) = new", which is both more
422 ## cumbersome and more fragile.
424 @if LC_ALL=C grep -E '\bls(\s+-[a-zA-Z0-9]+)*\s+-[a-zA-Z0-9]*t' \
426 echo "Use 'is_newest' rather than hacks based on 'ls -t'" 1>&2; \
430 ## Never use 'sleep 1' to create files with different timestamps.
431 ## Use '$sleep' instead. Some filesystems (e.g., Windows) have only
432 ## a 2sec resolution.
433 sc_tests_plain_sleep:
434 @if grep -E '\bsleep +[12345]\b' $(xtests); then \
435 echo 'Do not use "sleep x" in the above tests. Use "$$sleep" instead.' 1>&2; \
439 ## fgrep and egrep are not required by POSIX.
440 sc_m4_am_plain_egrep_fgrep:
441 @if grep -E '\b[ef]grep\b' $(ams) $(srcdir)/m4/*.m4; then \
442 echo 'Do not use egrep or fgrep in the above files,' \
443 'they are not portable.' 1>&2; \
447 ## Prefer 'configure.ac' over the obsolescent 'configure.in' as the name
448 ## for configure input files in our testsuite. The latter has been
449 ## deprecated for several years (at least since autoconf 2.50).
450 sc_tests_no_configure_in:
451 @if grep -E '\bconfigure\\*\.in\b' $(xtests) $(xdefs) \
452 | grep -Ev '/backcompat.*\.(sh|tap):' \
453 | grep -Ev '/autodist-configure-no-subdir\.sh:' \
454 | grep -Ev '/(configure|help)\.sh:' \
457 echo "Use 'configure.ac', not 'configure.in', as the name" >&2; \
458 echo "for configure input files in the test cases above." >&2; \
462 ## Rule to ensure that the testsuite has been run before. We don't depend
463 ## on 'check' here, because that would be very wasteful in the common case.
464 ## We could run "make check RECHECK_LOGS=" and avoid toplevel races with
465 ## AM_RECURSIVE_TARGETS. Suggest keeping test directories around for
466 ## greppability of the Makefile.in files.
467 sc_ensure_testsuite_has_run:
468 @if test ! -f '$(TEST_SUITE_LOG)'; then \
469 echo 'Run "env keep_testdirs=yes make check" before' \
470 'running "make maintainer-check"' >&2; \
473 .PHONY: sc_ensure_testsuite_has_run
475 ## Ensure our warning and error messages do not contain duplicate 'warning:' prefixes.
476 ## This test actually depends on the testsuite having been run before.
477 sc_tests_logs_duplicate_prefixes: sc_ensure_testsuite_has_run
478 @if grep -E '(warning|error):.*(warning|error):' t/*.log; then \
479 echo 'Duplicate warning/error message prefixes seen in above tests.' >&2; \
483 ## Ensure variables are listed before rules in Makefile.in files we generate.
484 sc_tests_makefile_variable_order: sc_ensure_testsuite_has_run
486 for file in `find t -name Makefile.in -print`; do \
489 -e '/\\\\$$/{' -e N -e 'b x' -e '}' \
490 -e '# Literal TAB.' \
492 -e '# Allow @ so we match conditionals.' \
493 -e '/^ *[a-zA-Z_@]\{1,\} *=/p' $$file`; \
494 if test -n "$$latevars"; then \
495 echo "Variables are expanded too late in $$file:" >&2; \
496 echo "$$latevars" | sed 's/^/ /' >&2; \
500 test $$st -eq 0 || { \
501 echo 'Ensure variables are expanded before rules' >&2; \
505 ## Using ':' as a PATH separator is not portable.
506 sc_tests_PATH_SEPARATOR:
507 @if grep -E '\bPATH=.*:.*' $(xtests) ; then \
508 echo "Use '\$$PATH_SEPARATOR', not ':', in PATH definitions" \
513 ## Try to make sure all @...@ substitutions are covered by our
514 ## substitution rule.
516 @if test `grep -E '^[^#]*@[A-Za-z_0-9]+@' aclocal | wc -l` -ne 0; then \
517 echo "Unresolved @...@ substitution in aclocal" 1>&2; \
520 @if test `grep -E '^[^#]*@[A-Za-z_0-9]+@' automake | wc -l` -ne 0; then \
521 echo "Unresolved @...@ substitution in automake" 1>&2; \
526 @if grep -E "[^\'\"]\\\$$\(DESTDIR" $(ams); then \
527 echo 'Suspicious unquoted DESTDIR uses.' 1>&2 ; \
532 @if grep ' ' $(srcdir)/doc/automake.texi; then \
533 echo 'Do not use tabs in the manual.' 1>&2; \
538 @if grep -E '([^@]|^)@([ ][^@]|$$)' $(srcdir)/doc/automake.texi; \
540 echo 'Unescaped @.' 1>&2; \
544 $(syntax_check_rules): automake aclocal
545 maintainer-check: $(syntax_check_rules)
546 .PHONY: maintainer-check $(syntax_check_rules)
548 ## Check that the list of tests given in the Makefile is equal to the
549 ## list of all test scripts in the Automake testsuite.
550 maintainer-check: maintainer-check-list-of-tests