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
; \
35 $(srcdir)/t
/ax
/test-init.sh \
36 $(srcdir)/t
/ax
/test-defs.in \
39 ams
:= $(shell find
$(srcdir) -name
'*.dir' -prune
-o
-name
'*.am' -print)
41 # Some simple checks, and then ordinary check. These are only really
42 # guaranteed to work on my machine.
43 syntax_check_rules
= \
44 $(sc_tests_plain_check_rules
) \
46 sc_diff_automake_in_automake \
47 sc_diff_aclocal_in_automake \
49 sc_no_brace_variable_expansions \
51 sc_no_for_variable_in_macro \
53 sc_pre_normal_post_install_uninstall \
55 sc_perl_no_split_regex_space \
58 sc_perl_at_uscore_in_scalar_context \
60 sc_AMDEP_TRUE_in_automake_in \
61 sc_tests_make_without_am_makeflags \
62 sc_tests_obsolete_variables \
63 sc_tests_here_document_format \
64 sc_tests_command_subst \
65 sc_tests_Exit_not_exit \
66 sc_tests_automake_fails \
67 sc_tests_required_after_defs \
68 sc_tests_overriding_macros_on_cmdline \
69 sc_tests_plain_sleep \
72 sc_m4_am_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 \
82 ## Look for test whose names can cause spurious failures when used as
83 ## first argument to AC_INIT (chiefly because they might contain an
84 ## m4/m4sugar builtin or macro name).
134 @m4_builtin_rx
=`echo $(m4_builtins) | sed 's/ /|/g'`; \
135 m4_macro_rx
="\\<($$m4_builtin_rx)\\>|\\<_?(A[CUMHS]|m4)_"; \
137 for t in
$(xtests
); do echo
$$t; done \
138 | LC_ALL
=C grep
-E
"$$m4_macro_rx"; \
140 echo
"the names of the tests above can be problematic" 1>&2; \
141 echo
"Avoid test names that contain names of m4 macros" 1>&2; \
145 ## These check avoids accidental configure substitutions in the source.
146 ## There are exactly 9 lines that should be modified from automake.in to
147 ## automake, and 10 lines that should be modified from aclocal.in to
148 ## aclocal; these wors out to 32 and 34 lines of diffs, respectively.
149 sc_diff_automake_in_automake
:
150 @if
test `diff $(srcdir)/automake.in automake | wc -l` -ne
32; then \
151 echo
"found too many diffs between automake.in and automake" 1>&2; \
152 diff
-c
$(srcdir)/automake.in automake
; \
155 sc_diff_aclocal_in_aclocal
:
156 @if
test `diff $(srcdir)/aclocal.in aclocal | wc -l` -ne
34; then \
157 echo
"found too many diffs between aclocal.in and aclocal" 1>&2; \
158 diff
-c
$(srcdir)/aclocal.in aclocal
; \
162 ## Syntax check with default Perl (on my machine, Perl 5).
164 @perllibdir
="./lib$(PATH_SEPARATOR)$(srcdir)/lib" $(PERL
) -c
-w automake
165 @perllibdir
="./lib$(PATH_SEPARATOR)$(srcdir)/lib" $(PERL
) -c
-w aclocal
167 ## Expect no instances of '${...}'. However, $${...} is ok, since that
168 ## is a shell construct, not a Makefile construct.
169 sc_no_brace_variable_expansions
:
170 @if grep
-v
'^ *#' $(ams
) | grep
-F
'$${' | grep
-F
-v
'$$$$'; then \
171 echo
"Found too many uses of '\$${' in the lines above." 1>&2; \
175 ## Make sure 'rm' is called with '-f'.
177 @if grep
-v
'^#' $(ams
) $(xtests
) \
178 | grep
-vE
'/(spy-rm\.tap|subobj-clean.*-pr10697\.sh):' \
179 | grep
-E
'\<rm ([^-]|\-[^f ]*\>)'; \
181 echo
"Suspicious 'rm' invocation." 1>&2; \
185 ## Never use something like "for file in $(FILES)", this doesn't work
186 ## if FILES is empty or if it contains shell meta characters (e.g. $ is
187 ## commonly used in Java filenames).
188 sc_no_for_variable_in_macro
:
189 @if grep
'for .* in \$$(' $(ams
) | grep
-v
'/Makefile\.am:'; then \
190 echo
'Use "list=$$(mumble); for var in $$$$list".' 1>&2 ; \
194 ## Make sure all invocations of mkinstalldirs are correct.
196 @if grep
-n
'mkinstalldirs' $(ams
) \
197 | grep
-F
-v
'$$(mkinstalldirs)' \
198 | grep
-v
'^\./Makefile.am:[0-9][0-9]*: *lib/mkinstalldirs \\$$'; \
200 echo
"Found incorrect use of mkinstalldirs in the lines above" 1>&2; \
204 ## Make sure all calls to PRE/NORMAL/POST_INSTALL/UNINSTALL
205 sc_pre_normal_post_install_uninstall
:
206 @if grep
-E
-n
'\((PRE|NORMAL|POST)_(|UN)INSTALL\)' $(ams
) | \
207 grep
-v
':##' | grep
-v
': @\$$('; then \
208 echo
"Found incorrect use of PRE/NORMAL/POST_INSTALL/UNINSTALL in the lines above" 1>&2; \
212 ## We never want to use "undef", only "delete", but for $/.
214 @if grep
-n
-w
'undef ' $(srcdir)/automake.in | \
215 grep
-F
-v
'undef $$/'; then \
216 echo
"Found undef in automake.in; use delete instead" 1>&2; \
220 ## We never want split (/ /,...), only split (' ', ...).
221 sc_perl_no_split_regex_space
:
222 @if grep
-n
'split (/ /' $(srcdir)/automake.in
; then \
223 echo
"Found bad split in the lines above." 1>&2; \
227 ## Look for cd within backquotes
229 @if grep
-n
'^[^#]*` *cd ' $(srcdir)/automake.in
$(ams
); then \
230 echo
"Consider using \$$(am__cd) in the lines above." 1>&2; \
234 ## Look for cd to a relative directory (may be influenced by CDPATH).
235 ## Skip some known directories that are OK.
237 @if grep
-n
'^[^#]*cd ' $(srcdir)/automake.in
$(ams
) | \
238 grep
-v
'echo.*cd ' | \
239 grep
-v
'am__cd =' | \
240 grep
-v
'^[^#]*cd [./]' | \
241 grep
-v
'^[^#]*cd \$$(top_builddir)' | \
242 grep
-v
'^[^#]*cd "\$$\$$am__cwd' | \
243 grep
-v
'^[^#]*cd \$$(abs' | \
244 grep
-v
'^[^#]*cd "\$$(DESTDIR)'; then \
245 echo
"Consider using \$$(am__cd) in the lines above." 1>&2; \
249 ## Using @_ in a scalar context is most probably a programming error.
250 sc_perl_at_uscore_in_scalar_context
:
251 @if grep
-Hn
'[^@_A-Za-z0-9][_A-Za-z0-9]*[^) ] *= *@_' $(srcdir)/automake.in
; then \
252 echo
"Using @_ in a scalar context in the lines above." 1>&2; \
256 ## Allow only few variables to be localized in Automake.
258 @if egrep
-v
'^[ \t]*local \$$[_~]( *=|;)' $(srcdir)/automake.in | \
259 grep
'^[ \t]*local [^*]'; then \
260 echo
"Please avoid 'local'." 1>&2; \
264 ## Don't let AMDEP_TRUE substitution appear in automake.in.
265 sc_AMDEP_TRUE_in_automake_in
:
266 @if grep
'@AMDEP''_TRUE@' $(srcdir)/automake.in
; then \
267 echo
"Don't put AMDEP_TRUE substitution in automake.in" 1>&2; \
271 ## Recursive make invocations should always pass $(AM_MAKEFLAGS)
272 ## to $(MAKE), for portability to non-GNU make.
273 sc_tests_make_without_am_makeflags
:
274 @if grep
'^[^#].*(MAKE) ' $(ams
) $(srcdir)/automake.in \
275 | grep
-v
'AM_MAKEFLAGS' \
276 | grep
-v
'/am/header-vars\.am:.*am--echo.*| $$(MAKE) -f *-'; \
278 echo
'Use $$(MAKE) $$(AM_MAKEFLAGS).' 1>&2; \
282 ## Look out for some obsolete variables.
283 sc_tests_obsolete_variables
:
286 test_prefer_config_shell \
293 for v in
$$vars; do \
294 if grep
-E
"\b$$v\b" $(xtests
) $(xdefs
); then \
298 if
test -n
"$$seen"; then \
299 for v in
$$seen; do \
301 parallel_tests|am_parallel_tests
) v2
=am_serial_tests
;; \
304 echo
"Variable '$$v' is obsolete, use '$$v2' instead." 1>&2; \
309 ## Tests should never call some programs directly, but only through the
310 ## corresponding variable (e.g., '$MAKE', not 'make'). This will allow
311 ## the programs to be overridden at configure time (for less brittleness)
312 ## or by the user at make time (to allow better testsuite coverage).
313 sc_tests_plain_check_rules
= \
314 sc_tests_plain_egrep \
315 sc_tests_plain_fgrep \
316 sc_tests_plain_make \
317 sc_tests_plain_perl \
318 sc_tests_plain_automake \
319 sc_tests_plain_aclocal \
320 sc_tests_plain_autoconf \
321 sc_tests_plain_autoupdate \
322 sc_tests_plain_autom4te \
323 sc_tests_plain_autoheader \
324 sc_tests_plain_autoreconf
326 toupper
= $(shell echo
$(1) | LC_ALL
=C tr
'[a-z]' '[A-Z]')
328 $(sc_tests_plain_check_rules
): sc_tests_plain_
% :
329 @
# The leading ':' in the grep below is what is printed by the
330 @
# preceding 'grep -v' after the file name.
331 @
# It works here as a poor man's substitute for beginning-of-line
333 @if grep
-v
'^[ ]*#' $(xtests
) \
334 |
$(EGREP
) '(:|\bif|\bnot|[;!{\|\(]|&&|\|\|)[ ]*?$*\b'; \
336 echo
'Do not run "$*" in the above tests.' \
337 'Use "$$$(call toupper,$*)" instead.' 1>&2; \
341 ## Tests should only use END and EOF for here documents
342 ## (so that the next test is effective).
343 sc_tests_here_document_format
:
344 @if grep
'<<' $(xtests
) | grep
-Ev
'\b(END|EOF)\b|\bcout <<'; then \
345 echo
'Use here documents with "END" and "EOF" only, for greppability.' 1>&2; \
349 ## Our test case should use the $(...) POSIX form for command substitution,
350 ## rather than the older `...` form.
351 ## The point of ignoring text on here-documents is that we want to exempt
352 ## Makefile.am rules, configure.ac code and helper shell script created and
353 ## used by out shell scripts, because Autoconf (as of version 2.69) does not
354 ## yet ensure that $CONFIG_SHELL will be set to a proper POSIX shell.
355 sc_tests_command_subst
:
359 -e
'/<<.*END/,/^END/b' -e
'/<<.*EOF/,/^EOF/b' \
360 -e
's/\\`/\\{backtick}/' \
361 -e
"s/[^\\]'\([^']*\`[^']*\)*'/'{quoted-text}'/g" \
364 for file in
$(xtests
); do \
366 if
test -n
"$$res"; then \
367 echo
"$$file:$$res"; \
372 echo
'Use $$(...), not `...`, for command substitutions.' >&2; \
376 ## Tests should no more call 'Exit', just 'exit'. That's because we
377 ## now have in place a better workaround to ensure the exit status is
378 ## transported correctly across the exit trap.
379 sc_tests_Exit_not_exit
:
380 @if grep
'Exit' $(xtests
) $(xdefs
) | grep
-Ev
'^[^:]+: *#' | grep .
; then \
381 echo
"Use 'exit', not 'Exit'; it's obsolete now." 1>&2; \
385 ## Use AUTOMAKE_fails when appropriate
386 sc_tests_automake_fails
:
387 @if grep
-v
'^#' $(xtests
) | grep
'\$$AUTOMAKE.*&&.*exit'; then \
388 echo
'Use AUTOMAKE_fails + grep to catch automake failures in the above tests.' 1>&2; \
392 ## Setting 'required' after sourcing './defs' is a bug.
393 sc_tests_required_after_defs
:
394 @for file in
$(xtests
); do \
395 if out
=`sed -n '/defs/,$${/required=/p;}' $$file`; test -n
"$$out"; then \
396 echo
'Do not set "required" after sourcing "defs" in '"$$file: $$out" 1>&2; \
401 ## Overriding a Makefile macro on the command line is not portable when
402 ## recursive targets are used. Better use an envvar. SHELL is an
403 ## exception, POSIX says it can't come from the environment. V, DESTDIR,
404 ## DISTCHECK_CONFIGURE_FLAGS and DISABLE_HARD_ERRORS are exceptions, too,
405 ## as package authors are urged not to initialize them anywhere.
406 ## Finally, 'exp' is used by some ad-hoc checks, where we ensure it's
407 ## ok to override it from the command line.
408 sc_tests_overriding_macros_on_cmdline
:
409 @if grep
-E
'\$$MAKE .*(SHELL=.*=|=.*SHELL=)' $(xtests
); then \
410 echo
'Rewrite "$$MAKE foo=bar SHELL=$$SHELL" as "foo=bar $$MAKE -e SHELL=$$SHELL"' 1>&2; \
411 echo
' in the above lines, it is more portable.' 1>&2; \
414 # The first s/// tries to account for usages like "$MAKE || st=$?".
415 # 'DISTCHECK_CONFIGURE_FLAGS' and 'exp' are allowed to contain whitespace in
416 # their definitions, hence the more complex last three substitutions below.
417 # Also, the 'make-dryrun.sh' is whitelisted, since there we need to
418 # override variables from the command line in order to cover the expected
420 @tests
=`for t in $(xtests); do \
421 case $$t in */make-dryrun.sh);; *) echo $$t;; esac; \
423 if sed
-e
's/ || .*//' -e
's/ && .*//' \
424 -e
's/ DESTDIR=[^ ]*/ /' -e
's/ SHELL=[^ ]*/ /' \
425 -e
's/ V=[^ ]*/ /' -e
's/ DISABLE_HARD_ERRORS=[^ ]*/ /' \
426 -e
"s/ DISTCHECK_CONFIGURE_FLAGS='[^']*'/ /" \
427 -e
's/ DISTCHECK_CONFIGURE_FLAGS="[^"]*"/ /' \
428 -e
's/ DISTCHECK_CONFIGURE_FLAGS=[^ ]/ /' \
429 -e
"s/ exp='[^']*'/ /" \
430 -e
's/ exp="[^"]*"/ /' \
431 -e
's/ exp=[^ ]/ /' \
432 $$tests | grep
'\$$MAKE .*='; then \
433 echo
'Rewrite "$$MAKE foo=bar" as "foo=bar $$MAKE -e" in the above lines,' 1>&2; \
434 echo
'it is more portable.' 1>&2; \
437 @if grep
'SHELL=.*\$$MAKE' $(xtests
); then \
438 echo
'$$MAKE ignores the SHELL envvar, use "$$MAKE SHELL=$$SHELL" in' 1>&2; \
439 echo
'the above lines.' 1>&2; \
443 ## Prefer use of our 'is_newest' auxiliary script over the more hacky
444 ## idiom "test $(ls -1t new old | sed 1q) = new", which is both more
445 ## cumbersome and more fragile.
447 @if LC_ALL
=C grep
-E
'\bls(\s+-[a-zA-Z0-9]+)*\s+-[a-zA-Z0-9]*t' \
449 echo
"Use 'is_newest' rather than hacks based on 'ls -t'" 1>&2; \
453 ## Test scripts must be executable.
456 for f in
$(xtests
); do \
458 t
/ax
/*|.
/t
/ax
/*|
$(srcdir)/t
/ax
/*);; \
459 *) test -x
$$f ||
{ echo
"$$f: not executable" >&2; st
=1; }; \
462 test $$st -eq
0 || echo
'$@: some test scripts are not executable' >&2; \
466 ## Never use 'sleep 1' to create files with different timestamps.
467 ## Use '$sleep' instead. Some filesystems (e.g., Windows) have only
468 ## a 2sec resolution.
469 sc_tests_plain_sleep
:
470 @if grep
-E
'\bsleep +[12345]\b' $(xtests
); then \
471 echo
'Do not use "sleep x" in the above tests. Use "$$sleep" instead.' 1>&2; \
475 ## fgrep and egrep are not required by POSIX.
476 sc_m4_am_plain_egrep_fgrep
:
477 @if grep
-E
'\b[ef]grep\b' $(ams
) $(srcdir)/m4
/*.m4
; then \
478 echo
'Do not use egrep or fgrep in the above files,' \
479 '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
) $(xdefs
) \
488 | grep
-Ev
'/backcompat.*\.(sh|tap):' \
489 | grep
-Ev
'/autodist-configure-no-subdir\.sh:' \
490 | grep
-Ev
'/(configure|help)\.sh:' \
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
'$(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):' t
/*.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 t -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" \
549 ## Try to make sure all @...@ substitutions are covered by our
550 ## substitution rule.
552 @if
test `grep -E '^[^#]*@[A-Za-z_0-9]+@' aclocal | wc -l` -ne
0; then \
553 echo
"Unresolved @...@ substitution in aclocal" 1>&2; \
556 @if
test `grep -E '^[^#]*@[A-Za-z_0-9]+@' automake | wc -l` -ne
0; then \
557 echo
"Unresolved @...@ substitution in automake" 1>&2; \
562 @if grep
-E
"[^\'\"]\\\$$\(DESTDIR" $(ams
); then \
563 echo
'Suspicious unquoted DESTDIR uses.' 1>&2 ; \
568 @if grep
' ' $(srcdir)/doc
/automake.texi
; then \
569 echo
'Do not use tabs in the manual.' 1>&2; \
574 @if grep
-E
'([^@]|^)@([ ][^@]|$$)' $(srcdir)/doc
/automake.texi
; \
576 echo
'Unescaped @.' 1>&2; \
580 $(syntax_check_rules
): automake aclocal
581 maintainer-check
: $(syntax_check_rules
)
582 .PHONY
: maintainer-check
$(syntax_check_rules
)
584 ## Check that the list of tests given in the Makefile is equal to the
585 ## list of all test scripts in the Automake testsuite.
586 maintainer-check
: maintainer-check-list-of-tests