1 # Maintainer checks for Automake. Requires GNU make.
3 # Copyright (C) 2012-2024 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 <https://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
/ax
/*.
$$s $$d/t
/*.
$$s $$d/contrib
/t
/*.
$$s 2>/dev
/null
; \
35 $(srcdir)/t
/ax
/am-test-lib.sh \
36 $(srcdir)/t
/ax
/test-lib.sh \
37 $(srcdir)/t
/ax
/test-defs.in
39 # Must prune test dirs since some are intentionally unreadable.
40 ams
:= $(shell find
$(srcdir) -name
'*.dir' -prune
-o
-name
'*.am' -print)
42 # Some simple checks, and then ordinary checks. These are only really
43 # guaranteed to work on my machine.
44 syntax_check_rules
= \
45 $(sc_tests_plain_check_rules
) \
48 sc_no_brace_variable_expansions \
50 sc_no_for_variable_in_macro \
52 sc_pre_normal_post_install_uninstall \
54 sc_perl_no_split_regex_space \
58 sc_perl_at_uscore_in_scalar_context \
60 sc_AMDEP_TRUE_in_automake_in \
61 sc_make_without_am_makeflags \
62 sc_tests_no_source_defs \
63 sc_tests_obsolete_variables \
64 sc_tests_here_document_format \
65 sc_tests_command_subst \
66 sc_tests_no_run_make_redirect \
67 sc_tests_exit_not_Exit \
68 sc_tests_automake_fails \
69 sc_tests_overriding_macros_on_cmdline \
71 sc_tests_plain_sleep \
73 sc_m4_am_plain_egrep_fgrep \
74 sc_tests_no_configure_in \
75 sc_tests_PATH_SEPARATOR \
76 sc_tests_logs_duplicate_prefixes \
77 sc_tests_makefile_variable_order \
83 $(syntax_check_rules
): bin
/automake bin
/aclocal
84 maintainer-check syntax-check
: $(syntax_check_rules
)
85 .PHONY
: maintainer-check syntax-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 maintainer-check
: maintainer-check-list-of-tests
92 lint
: maintainer-check
95 # The recipes of syntax checks require a modern GNU grep.
97 $(AM_V_GEN
)grep
--version | grep
'GNU grep' >/dev
/null
2>&1 \
98 && ab
=$$(printf
'a\nb') \
99 && test "$$(printf 'xa\nb\nc' | grep -Pzo 'a\nb' | tr -d '\0')" \
102 echo
"Syntax checks recipes require a modern GNU grep" >&2; \
105 .PHONY
: sc_sanity_gnu_grep
106 $(syntax_check_rules
): sc_sanity_gnu_grep
108 # Check that every subroutine in perl scripts has a corresponding
111 $(AM_V_GEN
)$(srcdir)/maintainer
/check-perl-protos \
112 <$(srcdir)/bin
/aclocal.in
&& \
113 $(srcdir)/maintainer
/check-perl-protos
<$(srcdir)/bin
/automake.in
115 # These check avoids accidental configure substitutions in the source.
116 # There are exactly 7 lines that should be modified from automake.in to
117 # automake, and 8 lines that should be modified from aclocal.in to
121 sc_diff_automake sc_diff_aclocal
: in
=$($*_in
)
122 sc_diff_automake sc_diff_aclocal
: out
=$($*_script
)
123 sc_diff_automake sc_diff_aclocal
: sc_diff_
% :
125 in
=$*-in.tmp out
=$*-out.tmp diffs
=$*-diffs.tmp \
126 && sed
'/^#!.*[pP]rototypes/d' $(in
) > $$in \
127 && sed
'/^# BEGIN.* PROTO/,/^# END.* PROTO/d' $(out
) > $$out \
128 && { diff
-u
$$in $$out > $$diffs; test $$?
-eq
1; } \
129 && added
=`grep -v '^+++ ' $$diffs | grep -c '^+'` \
130 && removed
=`grep -v '^--- ' $$diffs | grep -c '^-'` \
131 && test $$added,$$removed = $($*_diff_no
),$($*_diff_no
) \
133 echo
"Found unexpected diffs between $(in) and $(out)"; \
134 echo
"Lines added: $$added" ; \
135 echo
"Lines removed: $$removed"; \
139 rm -f
$$in $$out $$diffs
141 # Expect no instances of '${...}'. However, $${...} is ok, since that
142 # is a shell construct, not a Makefile construct.
143 sc_no_brace_variable_expansions
:
144 @if grep
-v
'^ *#' $(ams
) | grep
-F
'$${' | grep
-F
-v
'$$$$'; then \
145 echo
"Found too many uses of '\$${' in the lines above." 1>&2; \
149 # Make sure 'rm' is called with '-f'.
151 @if grep
-v
'^#' $(ams
) $(xtests
) \
152 | grep
-vE
'/(rm-f-probe\.sh|spy-rm\.tap|subobj-clean.*-pr10697\.sh):' \
153 | grep
-E
'\<rm ([^-]|-[^f ]*\>)'; \
155 echo
"Suspicious 'rm' invocation." 1>&2; \
159 # Never use something like "for file in $(FILES)", this doesn't work
160 # if FILES is empty or if it contains shell meta characters (e.g. $ is
161 # commonly used in Java filenames).
162 sc_no_for_variable_in_macro
:
163 @if grep
'for .* in \$$(' $(ams
) | grep
-v
'/Makefile\.am:'; then \
164 echo
'Use "list=$$(mumble); for var in $$$$list".' 1>&2 ; \
168 # Make sure all invocations of mkinstalldirs are correct.
170 @if grep
-n
'mkinstalldirs' $(ams
) \
171 | grep
-F
-v
'$$(mkinstalldirs)' \
172 | grep
-v
'^\./Makefile.am:[0-9][0-9]*: *lib/mkinstalldirs \\$$'; \
174 echo
"Found incorrect use of mkinstalldirs in the lines above" 1>&2; \
178 # Make sure all calls to PRE/NORMAL/POST_INSTALL/UNINSTALL
179 sc_pre_normal_post_install_uninstall
:
180 @if grep
-E
-n
'\((PRE|NORMAL|POST)_(|UN)INSTALL\)' $(ams
) | \
181 grep
-v
':##' | grep
-v
': @\$$('; then \
182 echo
"Found incorrect use of PRE/NORMAL/POST_INSTALL/UNINSTALL in the lines above" 1>&2; \
186 # We never want to use "undef", only "delete", but for $/.
188 @if grep
-n
-w
'undef ' $(automake_in
) | \
189 grep
-F
-v
'undef $$/'; then \
190 echo
"Found 'undef' in the lines above; use 'delete' instead" 1>&2; \
194 # We never want split (/ /,...), only split (' ', ...).
195 sc_perl_no_split_regex_space
:
196 @if grep
-n
'split (/ /' $(automake_in
) $(acloca_in
); then \
197 echo
"Found bad split in the lines above." 1>&2; \
201 # Look for cd within backquotes
203 @if grep
-n
'^[^#]*` *cd ' $(automake_in
) $(ams
); then \
204 echo
"Consider using \$$(am__cd) in the lines above." 1>&2; \
208 # Look for cd to a relative directory (may be influenced by CDPATH).
209 # Skip some known directories that are OK.
211 @if grep
-n
'^[^#]*cd ' $(automake_in
) $(ams
) | \
212 grep
-v
'echo.*cd ' | \
213 grep
-v
'am__cd =' | \
214 grep
-v
'^[^#]*cd [./]' | \
215 grep
-v
'^[^#]*cd \$$(top_builddir)' | \
216 grep
-v
'^[^#]*cd "\$$\$$am__cwd' | \
217 grep
-v
'^[^#]*cd \$$(abs' | \
218 grep
-v
'^[^#]*cd "\$$(DESTDIR)'; then \
219 echo
"Consider using \$$(am__cd) in the lines above." 1>&2; \
223 # Using @_ in a scalar context is most probably a programming error.
224 sc_perl_at_uscore_in_scalar_context
:
225 @if grep
-Hn
'[^%@_A-Za-z0-9][_A-Za-z0-9]*[^) ] *= *@_' \
226 $(automake_in
) $(aclocal_in
); then \
227 echo
"Using @_ in a scalar context in the lines above." 1>&2; \
231 ## Allow only few variables to be localized in automake and aclocal.
233 @if grep
-Ev
'^[ \t]*local \$$[_~]( *=|;)' \
234 $(automake_in
) $(aclocal_in
) | \
235 grep
'^[ \t]*local [^*]'; then \
236 echo
"Please avoid 'local'." 1>&2; \
240 # Don't let AMDEP_TRUE substitution appear in automake.in.
241 sc_AMDEP_TRUE_in_automake_in
:
242 @if grep
'@AMDEP''_TRUE@' $(automake_in
); then \
243 echo
"Don't put AMDEP_TRUE substitution in automake.in" 1>&2; \
247 # Recursive make invocations should always pass $(AM_MAKEFLAGS)
248 # to $(MAKE), for portability to non-GNU make.
249 sc_tests_make_without_am_makeflags
:
250 @if grep
'^[^#].*(MAKE) ' $(ams
) $(automake_in
) \
251 | grep
-Fv
'$$(AM_MAKEFLAGS)'; \
253 echo
'Use $$(MAKE) $$(AM_MAKEFLAGS).' 1>&2; \
257 # Look out for some obsolete variables.
258 sc_tests_obsolete_variables
:
262 test_prefer_config_shell \
269 for v in
$$vars; do \
270 if grep
-E
"\b$$v\b" $(xtests
) $(xdefs
); then \
274 if
test -n
"$$seen"; then \
275 for v in
$$seen; do \
277 parallel_tests|am_parallel_tests
) v2
=am_serial_tests
;; \
280 echo
"Variable '$$v' is obsolete, use '$$v2' instead." 1>&2; \
285 # Tests should never call some programs directly, but only through the
286 # corresponding variable (e.g., '$MAKE', not 'make'). This will allow
287 # the programs to be overridden at configure time (for less brittleness)
288 # or by the user at make time (to allow better testsuite coverage).
289 sc_tests_plain_check_rules
= \
290 sc_tests_plain_egrep \
291 sc_tests_plain_fgrep \
292 sc_tests_plain_make \
293 sc_tests_plain_perl \
294 sc_tests_plain_automake \
295 sc_tests_plain_aclocal \
296 sc_tests_plain_autoconf \
297 sc_tests_plain_autoupdate \
298 sc_tests_plain_autom4te \
299 sc_tests_plain_autoheader \
300 sc_tests_plain_autoreconf
302 toupper
= $(shell echo
$(1) | LC_ALL
=C tr
'[a-z]' '[A-Z]')
304 $(sc_tests_plain_check_rules
): sc_tests_plain_
% :
305 @
# The leading ':' in the grep below is what is printed by the
306 @
# preceding 'grep -v' after the file name.
307 @
# It works here as a poor man's substitute for beginning-of-line
309 @if grep
-v
'^[ ]*#' $(xtests
) \
310 |
$(EGREP
) '(:|\bif|\bnot|[;!{\|\(]|&&|\|\|)[ ]*?$*\b'; \
312 echo
'Do not run "$*" in the above tests.' \
313 'Use "$$$(call toupper,$*)" instead.' 1>&2; \
317 # Tests should only use END and EOF for here documents
318 # (so that the next test is effective).
319 sc_tests_here_document_format
:
320 @if grep
'<<' $(xtests
) | grep
-Ev
'\b(END|EOF)\b|\bcout <<'; then \
321 echo
'Use here documents with "END" and "EOF" only, for greppability.' 1>&2; \
325 # Our test case should use the $(...) POSIX form for command substitution,
326 # rather than the older `...` form.
327 # The point of ignoring text on here-documents is that we want to exempt
328 # Makefile.am rules, configure.ac code and helper shell script created and
329 # used by out shell scripts, because Autoconf (as of version 2.69) does not
330 # yet ensure that $CONFIG_SHELL will be set to a proper POSIX shell.
331 sc_tests_command_subst
:
335 -e
'/<<.*END/,/^END/b' -e
'/<<.*EOF/,/^EOF/b' \
336 -e
's/\\`/\\{backtick}/' \
337 -e
"s/[^\\]'\([^']*\`[^']*\)*'/'{quoted-text}'/g" \
340 for file in
$(xtests
); do \
342 if
test -n
"$$res"; then \
343 echo
"$$file:$$res"; \
348 echo
'Use $$(...), not `...`, for command substitutions.' >&2; \
352 # Tests should no longer call 'Exit', just 'exit'. That's because we
353 # now have in place a better workaround to ensure the exit status is
354 # transported correctly across the exit trap.
355 sc_tests_exit_not_Exit
:
356 @if grep
'Exit' $(xtests
) $(xdefs
) | grep
-Ev
'^[^:]+: *#' | grep .
; then \
357 echo
"Use 'exit', not 'Exit'; it's obsolete now." 1>&2; \
361 # Guard against obsolescent uses of ./defs in tests. Now,
362 # 'test-init.sh' should be used instead.
363 sc_tests_no_source_defs
:
364 @if grep
-E
'\. .*defs($$| )' $(xtests
); then \
365 echo
"Source 'test-init.sh', not './defs'." 1>&2; \
369 # Invocation of 'run_make' should not have output redirections.
370 sc_tests_no_run_make_redirect
:
371 @if grep
-Pzo
'.*(\$$MAKE|\brun_make)\b(.*(\\\n))*.*>.*' $(xtests
); \
373 echo
'Do not redirect stdout/stderr in "run_make" or "$$MAKE"' \
374 'invocations,' >&2; \
375 echo
'use "run_make {-E|-O|-M}" instead.' >&2; \
379 # Use AUTOMAKE_fails when appropriate
380 sc_tests_automake_fails
:
381 @if grep
-v
'^#' $(xtests
) | grep
'\$$AUTOMAKE.*&&.*exit'; then \
382 echo
'Use AUTOMAKE_fails + grep to catch automake failures in the above tests.' 1>&2; \
386 # "make -e" is brittle and unsafe, since it let *all* the environment
387 # win over the macro definitions in the Makefiles. Since we offer
388 # AM_MAKEFLAGS to allow the user to portably override macro definitions
389 # from the command line in a safe way, we should encourage users to use
392 @if grep
-E
'\$$MAKE\b.* -[a-zA-Z0-9]*e' $(xtests
); then \
393 echo
'"make -e" is brittle, use "run_make" instead.' 1>&2; \
397 # Overriding a Makefile macro on the command line is not portable when
398 # recursive targets are used. Better use an envvar. SHELL is an
399 # exception, POSIX says it can't come from the environment. V, DESTDIR,
400 # DISTCHECK_CONFIGURE_FLAGS and DISABLE_HARD_ERRORS are exceptions, too,
401 # as package authors are urged not to initialize them anywhere.
402 # Finally, 'exp' is used by some ad-hoc checks, where we ensure it's
403 # ok to override it from the command line.
404 sc_tests_overriding_macros_on_cmdline
:
405 # The first s/// tries to account for usages like "$MAKE || st=$?".
406 # 'DISTCHECK_CONFIGURE_FLAGS' and 'exp' are allowed to contain whitespace in
407 # their definitions, hence the more complex last three substitutions below.
408 @if sed
-e
's/ || .*//' -e
's/ && .*//' \
409 -e
's/ DESTDIR=[^ ]*/ /' -e
's/ SHELL=[^ ]*/ /' \
410 -e
's/ V=[^ ]*/ /' -e
's/ DISABLE_HARD_ERRORS=[^ ]*/ /' \
411 -e
"s/ DISTCHECK_CONFIGURE_FLAGS='[^']*'/ /" \
412 -e
's/ DISTCHECK_CONFIGURE_FLAGS="[^"]*"/ /' \
413 -e
's/ DISTCHECK_CONFIGURE_FLAGS=[^ ]/ /' \
414 -e
"s/ exp='[^']*'/ /" \
415 -e
's/ exp="[^"]*"/ /' \
416 -e
's/ exp=[^ ]/ /' \
417 $(filter-out %/am-test-lib.sh
,$(xtests
)) \
418 | grep
-E
'\$$MAKE .*\S+='; then \
419 echo
'Rewrite "$$MAKE foo=bar" as "run_make foo=bar" in the lines above,'; \
420 echo
'it is more portable.'; \
423 @if grep
'SHELL=.*\$$MAKE' $(xtests
); then \
424 echo
'$$MAKE ignores the SHELL envvar, use "run_make SHELL=$$SHELL"'; \
425 echo
'in the above lines.'; \
429 # Prefer use of our 'is_newest' auxiliary script over the more hacky
430 # idiom "test $(ls -1t new old | sed 1q) = new", which is both more
431 # cumbersome and more fragile.
433 @if LC_ALL
=C grep
-E
'\bls(\s+-[a-zA-Z0-9]+)*\s+-[a-zA-Z0-9]*t' \
435 echo
"Use 'is_newest' rather than hacks based on 'ls -t'" 1>&2; \
439 # Never use 'sleep 1' to create files with different timestamps.
440 # Use '$sleep' instead. Some file systems (e.g., Windows) have only
442 sc_tests_plain_sleep
:
443 @if grep
-vE
'^[ ]*#' $(xtests
) \
444 | grep
-E
'\bsleep +[12345]\b' | grep .
; then \
445 echo
'Do not use "sleep x" in the above tests. Use "$$sleep" instead.' 1>&2; \
449 # fgrep and egrep are not required by POSIX.
450 sc_m4_am_plain_egrep_fgrep
:
451 @if grep
-E
'\b[ef]grep\b' $(ams
) $(srcdir)/m4
/*.m4
; then \
452 echo
'Do not use egrep or fgrep in the above files,' \
453 'they are not portable.' 1>&2; \
457 # Prefer 'configure.ac' over the obsolescent 'configure.in' as the name
458 # for configure input files in our testsuite. The latter has been
459 # deprecated for several years (at least since autoconf 2.50).
460 sc_tests_no_configure_in
:
461 @if grep
-E
'\bconfigure\\*\.in\b' $(xtests
) $(xdefs
) \
462 | grep
-Ev
'/backcompat.*\.(sh|tap):' \
463 | grep
-Ev
'/autodist-configure-no-subdir\.sh:' \
464 | grep
-Ev
'/(configure|help)\.sh:' \
467 echo
"Use 'configure.ac', not 'configure.in', as the name" >&2; \
468 echo
"for configure input files in the test cases above." >&2; \
472 # Rule to ensure that the testsuite has been run before. We don't depend
473 # on 'check' here, because that would be very wasteful in the common case.
474 # We could run "make check RECHECK_LOGS=" and avoid toplevel races with
475 # AM_RECURSIVE_TARGETS. Suggest keeping test directories around for
476 # greppability of the Makefile.in files.
477 sc_ensure_testsuite_has_run
:
478 @if
test ! -f
'$(TEST_SUITE_LOG)'; then \
479 echo
'Run "env keep_testdirs=yes make check" before' \
480 'running "make maintainer-check"' >&2; \
483 .PHONY
: sc_ensure_testsuite_has_run
485 # Ensure our warning and error messages do not contain duplicate 'warning:' prefixes.
486 # This test actually depends on the testsuite having been run before.
487 sc_tests_logs_duplicate_prefixes
: sc_ensure_testsuite_has_run
488 @if grep
-E
'(warning|error):.*(warning|error):' t
/*.log
; then \
489 echo
'Duplicate warning/error message prefixes seen in above tests.' >&2; \
493 # Ensure variables are listed before rules in Makefile.in files we generate.
494 # (Do not descend into test dirs that are unreadable.)
495 sc_tests_makefile_variable_order
: sc_ensure_testsuite_has_run
497 for file in
`find t ! -perm -o+r -prune -o -name Makefile.in -print`; \
501 -e '/\\\\$$/{' -e N -e 'b x' -e '}' \
502 -e '# Literal TAB.' \
504 -e '# Allow @ so we match conditionals.' \
505 -e '/^ *[a-zA-Z_@]\{1,\} *=/p' $$file`; \
506 if
test -n
"$$latevars"; then \
507 echo
"Variables are expanded too late in $$file:" >&2; \
508 echo
"$$latevars" | sed
's/^/ /' >&2; \
512 test $$st -eq
0 ||
{ \
513 echo
'Ensure variables are expanded before rules' >&2; \
517 # Using ':' as a PATH separator is not portable.
518 sc_tests_PATH_SEPARATOR
:
519 @if grep
-E
'\bPATH=.*:.*' $(xtests
) ; then \
520 echo
"Use '\$$PATH_SEPARATOR', not ':', in PATH definitions" \
525 # Try to make sure all @...@ substitutions are covered by our
528 @if
test `grep -E '^[^#]*@[A-Za-z_0-9]+@' bin/aclocal | wc -l` -ne
0; then \
529 echo
"Unresolved @...@ substitution in aclocal" 1>&2; \
532 @if
test `grep -E '^[^#]*@[A-Za-z_0-9]+@' bin/automake | wc -l` -ne
0; then \
533 echo
"Unresolved @...@ substitution in automake" 1>&2; \
538 @if grep
-E
"[^\'\"]\\\$$\(DESTDIR" $(ams
); then \
539 echo
'Suspicious unquoted DESTDIR uses.' 1>&2 ; \
544 @if grep
' ' $(srcdir)/doc
/automake.texi
; then \
545 echo
'Do not use tabs in the manual.' 1>&2; \
550 @if grep
-E
'([^@]|^)@([ ][^@]|$$)' $(srcdir)/doc
/automake.texi
; \
552 echo
'Unescaped @.' 1>&2; \