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) \
42 sc_diff_automake_in_automake \
43 sc_diff_aclocal_in_automake \
45 sc_no_brace_variable_expansions \
47 sc_no_for_variable_in_macro \
49 sc_pre_normal_post_install_uninstall \
51 sc_perl_no_split_regex_space \
54 sc_perl_at_uscore_in_scalar_context \
56 sc_AMDEP_TRUE_in_automake_in \
57 sc_tests_make_without_am_makeflags \
58 $(sc_obsolete_requirements_rules) \
59 sc_tests_obsolete_variables \
60 sc_tests_here_document_format \
61 sc_tests_command_subst \
62 sc_tests_Exit_not_exit \
63 sc_tests_automake_fails \
64 sc_tests_required_after_defs \
65 sc_tests_overriding_macros_on_cmdline \
66 sc_tests_plain_sleep \
68 sc_m4_am_plain_egrep_fgrep \
69 sc_tests_no_configure_in \
70 sc_tests_PATH_SEPARATOR \
71 sc_tests_logs_duplicate_prefixes \
72 sc_tests_makefile_variable_order \
78 ## These check avoids accidental configure substitutions in the source.
79 ## There are exactly 9 lines that should be modified from automake.in to
80 ## automake, and 10 lines that should be modified from aclocal.in to
81 ## aclocal; these wors out to 32 and 34 lines of diffs, respectively.
82 sc_diff_automake_in_automake:
83 @if test `diff $(srcdir)/automake.in automake | wc -l` -ne 32; then \
84 echo "found too many diffs between automake.in and automake" 1>&2; \
85 diff -c $(srcdir)/automake.in automake; \
88 sc_diff_aclocal_in_aclocal:
89 @if test `diff $(srcdir)/aclocal.in aclocal | wc -l` -ne 34; then \
90 echo "found too many diffs between aclocal.in and aclocal" 1>&2; \
91 diff -c $(srcdir)/aclocal.in aclocal; \
95 ## Syntax check with default Perl (on my machine, Perl 5).
97 @perllibdir="./lib$(PATH_SEPARATOR)$(srcdir)/lib" $(PERL) -c -w automake
98 @perllibdir="./lib$(PATH_SEPARATOR)$(srcdir)/lib" $(PERL) -c -w aclocal
100 ## Expect no instances of '${...}'. However, $${...} is ok, since that
101 ## is a shell construct, not a Makefile construct.
102 sc_no_brace_variable_expansions:
103 @if grep -v '^ *#' $(ams) | grep -F '$${' | grep -F -v '$$$$'; then \
104 echo "Found too many uses of '\$${' in the lines above." 1>&2; \
108 ## Make sure 'rm' is called with '-f'.
110 @if grep -v '^#' $(ams) $(xtests) \
111 | grep -vE '/(spy-rm\.tap|subobj-clean.*-pr10697\.sh):' \
112 | grep -E '\<rm ([^-]|\-[^f ]*\>)'; \
114 echo "Suspicious 'rm' invocation." 1>&2; \
118 ## Never use something like "for file in $(FILES)", this doesn't work
119 ## if FILES is empty or if it contains shell meta characters (e.g. $ is
120 ## commonly used in Java filenames).
121 sc_no_for_variable_in_macro:
122 @if grep 'for .* in \$$(' $(ams) | grep -v '/Makefile\.am:'; then \
123 echo 'Use "list=$$(mumble); for var in $$$$list".' 1>&2 ; \
127 ## Make sure all invocations of mkinstalldirs are correct.
129 @if grep -n 'mkinstalldirs' $(ams) \
130 | grep -F -v '$$(mkinstalldirs)' \
131 | grep -v '^\./Makefile.am:[0-9][0-9]*: *lib/mkinstalldirs \\$$'; \
133 echo "Found incorrect use of mkinstalldirs in the lines above" 1>&2; \
137 ## Make sure all calls to PRE/NORMAL/POST_INSTALL/UNINSTALL
138 sc_pre_normal_post_install_uninstall:
139 @if grep -E -n '\((PRE|NORMAL|POST)_(|UN)INSTALL\)' $(ams) | \
140 grep -v ':##' | grep -v ': @\$$('; then \
141 echo "Found incorrect use of PRE/NORMAL/POST_INSTALL/UNINSTALL in the lines above" 1>&2; \
145 ## We never want to use "undef", only "delete", but for $/.
147 @if grep -n -w 'undef ' $(srcdir)/automake.in | \
148 grep -F -v 'undef $$/'; then \
149 echo "Found undef in automake.in; use delete instead" 1>&2; \
153 ## We never want split (/ /,...), only split (' ', ...).
154 sc_perl_no_split_regex_space:
155 @if grep -n 'split (/ /' $(srcdir)/automake.in; then \
156 echo "Found bad split in the lines above." 1>&2; \
160 ## Look for cd within backquotes
162 @if grep -n '^[^#]*` *cd ' $(srcdir)/automake.in $(ams); then \
163 echo "Consider using \$$(am__cd) in the lines above." 1>&2; \
167 ## Look for cd to a relative directory (may be influenced by CDPATH).
168 ## Skip some known directories that are OK.
170 @if grep -n '^[^#]*cd ' $(srcdir)/automake.in $(ams) | \
171 grep -v 'echo.*cd ' | \
172 grep -v 'am__cd =' | \
173 grep -v '^[^#]*cd [./]' | \
174 grep -v '^[^#]*cd \$$(top_builddir)' | \
175 grep -v '^[^#]*cd "\$$\$$am__cwd' | \
176 grep -v '^[^#]*cd \$$(abs' | \
177 grep -v '^[^#]*cd "\$$(DESTDIR)'; then \
178 echo "Consider using \$$(am__cd) in the lines above." 1>&2; \
182 ## Using @_ in a scalar context is most probably a programming error.
183 sc_perl_at_uscore_in_scalar_context:
184 @if grep -Hn '[^@_A-Za-z0-9][_A-Za-z0-9]*[^) ] *= *@_' $(srcdir)/automake.in; then \
185 echo "Using @_ in a scalar context in the lines above." 1>&2; \
189 ## Allow only few variables to be localized in Automake.
191 @if egrep -v '^[ \t]*local \$$[_~]( *=|;)' $(srcdir)/automake.in | \
192 grep '^[ \t]*local [^*]'; then \
193 echo "Please avoid 'local'." 1>&2; \
197 ## Don't let AMDEP_TRUE substitution appear in automake.in.
198 sc_AMDEP_TRUE_in_automake_in:
199 @if grep '@AMDEP''_TRUE@' $(srcdir)/automake.in; then \
200 echo "Don't put AMDEP_TRUE substitution in automake.in" 1>&2; \
204 ## Recursive make invocations should always pass $(AM_MAKEFLAGS)
205 ## to $(MAKE), for portability to non-GNU make.
206 sc_tests_make_without_am_makeflags:
207 @if grep '^[^#].*(MAKE) ' $(ams) $(srcdir)/automake.in \
208 | grep -v 'AM_MAKEFLAGS' \
209 | grep -v '/am/header-vars\.am:.*am--echo.*| $$(MAKE) -f *-'; \
211 echo 'Use $$(MAKE) $$(AM_MAKEFLAGS).' 1>&2; \
215 ## Look out for some obsolete variables.
216 sc_tests_obsolete_variables:
219 test_prefer_config_shell \
226 for v in $$vars; do \
227 if grep -E "\b$$v\b" $(xtests) $(xdefs); then \
231 if test -n "$$seen"; then \
232 for v in $$seen; do \
234 parallel_tests|am_parallel_tests) v2=am_serial_tests;; \
237 echo "Variable '$$v' is obsolete, use '$$v2' instead." 1>&2; \
242 ## Look out for obsolete requirements specified in the test cases.
243 sc_obsolete_requirements_rules = sc_no_texi2dvi-o sc_no_makeinfo-html
244 modern-requirement.texi2dvi-o = texi2dvi
245 modern-requirement.makeinfo-html = makeinfo
247 $(sc_obsolete_requirements_rules): sc_no_% :
248 @if grep -E 'required=.*\b$*\b' $(xtests); then \
249 echo "Requirement '$*' is obsolete and shouldn't" \
250 "be used anymore." >&2; \
251 echo "You should use '$(modern-requirement.$*)' instead." >&2; \
255 ## Tests should never call some programs directly, but only through the
256 ## corresponding variable (e.g., '$MAKE', not 'make'). This will allow
257 ## the programs to be overridden at configure time (for less brittleness)
258 ## or by the user at make time (to allow better testsuite coverage).
259 sc_tests_plain_check_rules = \
260 sc_tests_plain_egrep \
261 sc_tests_plain_fgrep \
262 sc_tests_plain_make \
263 sc_tests_plain_perl \
264 sc_tests_plain_automake \
265 sc_tests_plain_aclocal \
266 sc_tests_plain_autoconf \
267 sc_tests_plain_autoupdate \
268 sc_tests_plain_autom4te \
269 sc_tests_plain_autoheader \
270 sc_tests_plain_autoreconf
272 toupper = $(shell echo $(1) | LC_ALL=C tr '[a-z]' '[A-Z]')
274 $(sc_tests_plain_check_rules): sc_tests_plain_% :
275 @# The leading ':' in the grep below is what is printed by the
276 @# preceding 'grep -v' after the file name.
277 @# It works here as a poor man's substitute for beginning-of-line
279 @if grep -v '^[ ]*#' $(xtests) \
280 | $(EGREP) '(:|\bif|\bnot|[;!{\|\(]|&&|\|\|)[ ]*?$*\b'; \
282 echo 'Do not run "$*" in the above tests.' \
283 'Use "$$$(call toupper,$*)" instead.' 1>&2; \
287 ## Tests should only use END and EOF for here documents
288 ## (so that the next test is effective).
289 sc_tests_here_document_format:
290 @if grep '<<' $(xtests) | grep -Ev '\b(END|EOF)\b|\bcout <<'; then \
291 echo 'Use here documents with "END" and "EOF" only, for greppability.' 1>&2; \
295 ## Our test case should use the $(...) POSIX form for command substitution,
296 ## rather than the older `...` form.
297 ## The point of ignoring text on here-documents is that we want to exempt
298 ## Makefile.am rules, configure.ac code and helper shell script created and
299 ## used by out shell scripts, because Autoconf (as of version 2.69) does not
300 ## yet ensure that $CONFIG_SHELL will be set to a proper POSIX shell.
301 sc_tests_command_subst:
305 -e '/<<.*END/,/^END/b' -e '/<<.*EOF/,/^EOF/b' \
306 -e 's/\\`/\\{backtick}/' \
307 -e "s/[^\\]'\([^']*\`[^']*\)*'/'{quoted-text}'/g" \
310 for file in $(xtests); do \
312 if test -n "$$res"; then \
313 echo "$$file:$$res"; \
318 echo 'Use $$(...), not `...`, for command substitutions.' >&2; \
322 ## Tests should no more call 'Exit', just 'exit'. That's because we
323 ## now have in place a better workaround to ensure the exit status is
324 ## transported correctly across the exit trap.
325 sc_tests_Exit_not_exit:
326 @if grep 'Exit' $(xtests) $(xdefs) | grep -Ev '^[^:]+: *#' | grep .; then \
327 echo "Use 'exit', not 'Exit'; it's obsolete now." 1>&2; \
331 ## Use AUTOMAKE_fails when appropriate
332 sc_tests_automake_fails:
333 @if grep -v '^#' $(xtests) | grep '\$$AUTOMAKE.*&&.*exit'; then \
334 echo 'Use AUTOMAKE_fails + grep to catch automake failures in the above tests.' 1>&2; \
338 ## Setting 'required' after sourcing './defs' is a bug.
339 sc_tests_required_after_defs:
340 @for file in $(xtests); do \
341 if out=`sed -n '/defs/,$${/required=/p;}' $$file`; test -n "$$out"; then \
342 echo 'Do not set "required" after sourcing "defs" in '"$$file: $$out" 1>&2; \
347 ## Overriding a Makefile macro on the command line is not portable when
348 ## recursive targets are used. Better use an envvar. SHELL is an
349 ## exception, POSIX says it can't come from the environment. V, DESTDIR,
350 ## DISTCHECK_CONFIGURE_FLAGS and DISABLE_HARD_ERRORS are exceptions, too,
351 ## as package authors are urged not to initialize them anywhere.
352 ## Finally, 'exp' is used by some ad-hoc checks, where we ensure it's
353 ## ok to override it from the command line.
354 sc_tests_overriding_macros_on_cmdline:
355 @if grep -E '\$$MAKE .*(SHELL=.*=|=.*SHELL=)' $(xtests); then \
356 echo 'Rewrite "$$MAKE foo=bar SHELL=$$SHELL" as "foo=bar $$MAKE -e SHELL=$$SHELL"' 1>&2; \
357 echo ' in the above lines, it is more portable.' 1>&2; \
360 # The first s/// tries to account for usages like "$MAKE || st=$?".
361 # 'DISTCHECK_CONFIGURE_FLAGS' and 'exp' are allowed to contain whitespace in
362 # their definitions, hence the more complex last three substitutions below.
363 # Also, the 'make-dryrun.sh' is whitelisted, since there we need to
364 # override variables from the command line in order to cover the expected
366 @tests=`for t in $(xtests); do \
367 case $$t in */make-dryrun.sh);; *) echo $$t;; esac; \
369 if sed -e 's/ || .*//' -e 's/ && .*//' \
370 -e 's/ DESTDIR=[^ ]*/ /' -e 's/ SHELL=[^ ]*/ /' \
371 -e 's/ V=[^ ]*/ /' -e 's/ DISABLE_HARD_ERRORS=[^ ]*/ /' \
372 -e "s/ DISTCHECK_CONFIGURE_FLAGS='[^']*'/ /" \
373 -e 's/ DISTCHECK_CONFIGURE_FLAGS="[^"]*"/ /' \
374 -e 's/ DISTCHECK_CONFIGURE_FLAGS=[^ ]/ /' \
375 -e "s/ exp='[^']*'/ /" \
376 -e 's/ exp="[^"]*"/ /' \
377 -e 's/ exp=[^ ]/ /' \
378 $$tests | grep '\$$MAKE .*='; then \
379 echo 'Rewrite "$$MAKE foo=bar" as "foo=bar $$MAKE -e" in the above lines,' 1>&2; \
380 echo 'it is more portable.' 1>&2; \
383 @if grep 'SHELL=.*\$$MAKE' $(xtests); then \
384 echo '$$MAKE ignores the SHELL envvar, use "$$MAKE SHELL=$$SHELL" in' 1>&2; \
385 echo 'the above lines.' 1>&2; \
389 ## Prefer use of our 'is_newest' auxiliary script over the more hacky
390 ## idiom "test $(ls -1t new old | sed 1q) = new", which is both more
391 ## cumbersome and more fragile.
393 @if LC_ALL=C grep -E '\bls(\s+-[a-zA-Z0-9]+)*\s+-[a-zA-Z0-9]*t' \
395 echo "Use 'is_newest' rather than hacks based on 'ls -t'" 1>&2; \
399 ## Never use 'sleep 1' to create files with different timestamps.
400 ## Use '$sleep' instead. Some filesystems (e.g., Windows) have only
401 ## a 2sec resolution.
402 sc_tests_plain_sleep:
403 @if grep -E '\bsleep +[12345]\b' $(xtests); then \
404 echo 'Do not use "sleep x" in the above tests. Use "$$sleep" instead.' 1>&2; \
408 ## fgrep and egrep are not required by POSIX.
409 sc_m4_am_plain_egrep_fgrep:
410 @if grep -E '\b[ef]grep\b' $(ams) $(srcdir)/m4/*.m4; then \
411 echo 'Do not use egrep or fgrep in the above files,' \
412 'they are not portable.' 1>&2; \
416 ## Prefer 'configure.ac' over the obsolescent 'configure.in' as the name
417 ## for configure input files in our testsuite. The latter has been
418 ## deprecated for several years (at least since autoconf 2.50).
419 sc_tests_no_configure_in:
420 @if grep -E '\bconfigure\\*\.in\b' $(xtests) $(xdefs) \
421 | grep -Ev '/backcompat.*\.(sh|tap):' \
422 | grep -Ev '/autodist-configure-no-subdir\.sh:' \
423 | grep -Ev '/(configure|help)\.sh:' \
426 echo "Use 'configure.ac', not 'configure.in', as the name" >&2; \
427 echo "for configure input files in the test cases above." >&2; \
431 ## Rule to ensure that the testsuite has been run before. We don't depend
432 ## on 'check' here, because that would be very wasteful in the common case.
433 ## We could run "make check RECHECK_LOGS=" and avoid toplevel races with
434 ## AM_RECURSIVE_TARGETS. Suggest keeping test directories around for
435 ## greppability of the Makefile.in files.
436 sc_ensure_testsuite_has_run:
437 @if test ! -f '$(TEST_SUITE_LOG)'; then \
438 echo 'Run "env keep_testdirs=yes make check" before' \
439 'running "make maintainer-check"' >&2; \
442 .PHONY: sc_ensure_testsuite_has_run
444 ## Ensure our warning and error messages do not contain duplicate 'warning:' prefixes.
445 ## This test actually depends on the testsuite having been run before.
446 sc_tests_logs_duplicate_prefixes: sc_ensure_testsuite_has_run
447 @if grep -E '(warning|error):.*(warning|error):' t/*.log; then \
448 echo 'Duplicate warning/error message prefixes seen in above tests.' >&2; \
452 ## Ensure variables are listed before rules in Makefile.in files we generate.
453 sc_tests_makefile_variable_order: sc_ensure_testsuite_has_run
455 for file in `find t -name Makefile.in -print`; do \
458 -e '/\\\\$$/{' -e N -e 'b x' -e '}' \
459 -e '# Literal TAB.' \
461 -e '# Allow @ so we match conditionals.' \
462 -e '/^ *[a-zA-Z_@]\{1,\} *=/p' $$file`; \
463 if test -n "$$latevars"; then \
464 echo "Variables are expanded too late in $$file:" >&2; \
465 echo "$$latevars" | sed 's/^/ /' >&2; \
469 test $$st -eq 0 || { \
470 echo 'Ensure variables are expanded before rules' >&2; \
474 ## Using ':' as a PATH separator is not portable.
475 sc_tests_PATH_SEPARATOR:
476 @if grep -E '\bPATH=.*:.*' $(xtests) ; then \
477 echo "Use '\$$PATH_SEPARATOR', not ':', in PATH definitions" \
482 ## Try to make sure all @...@ substitutions are covered by our
483 ## substitution rule.
485 @if test `grep -E '^[^#]*@[A-Za-z_0-9]+@' aclocal | wc -l` -ne 0; then \
486 echo "Unresolved @...@ substitution in aclocal" 1>&2; \
489 @if test `grep -E '^[^#]*@[A-Za-z_0-9]+@' automake | wc -l` -ne 0; then \
490 echo "Unresolved @...@ substitution in automake" 1>&2; \
495 @if grep -E "[^\'\"]\\\$$\(DESTDIR" $(ams); then \
496 echo 'Suspicious unquoted DESTDIR uses.' 1>&2 ; \
501 @if grep ' ' $(srcdir)/doc/automake.texi; then \
502 echo 'Do not use tabs in the manual.' 1>&2; \
507 @if grep -E '([^@]|^)@([ ][^@]|$$)' $(srcdir)/doc/automake.texi; \
509 echo 'Unescaped @.' 1>&2; \
513 $(syntax_check_rules): automake aclocal
514 maintainer-check: $(syntax_check_rules)
515 .PHONY: maintainer-check $(syntax_check_rules)
517 ## Check that the list of tests given in the Makefile is equal to the
518 ## list of all test scripts in the Automake testsuite.
519 maintainer-check: maintainer-check-list-of-tests