1 # Maintainer checks for Automake. Requires GNU make.
3 # Copyright (C) 2012-2013 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
/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 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
) \
47 sc_no_brace_variable_expansions \
49 sc_no_for_variable_in_macro \
51 sc_pre_normal_post_install_uninstall \
53 sc_perl_no_split_regex_space \
56 sc_perl_at_uscore_in_scalar_context \
58 sc_AMDEP_TRUE_in_automake_in \
59 sc_tests_make_without_am_makeflags \
60 $(sc_obsolete_requirements_rules
) \
61 sc_tests_no_source_defs \
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 ## These check avoids accidental configure substitutions in the source.
83 ## There are exactly 8 lines that should be modified from automake.in to
84 ## automake, and 9 lines that should be modified from aclocal.in to
88 sc_diff_automake sc_diff_aclocal
: sc_diff_
% :
89 @set
+e
; tmp
=$*-diffs.tmp
; \
90 diff
-u
$(srcdir)/$*.in
$* > $$tmp; test $$?
-eq
1 || exit
1; \
91 added
=`grep -v '^+++ ' $$tmp | grep -c '^+'` || exit
1; \
92 removed
=`grep -v '^--- ' $$tmp | grep -c '^-'` || exit
1; \
93 test $$added,$$removed = $($*_diff_no
),$($*_diff_no
) \
95 echo
"Found unexpected diffs between $*.in and $*"; \
96 echo
"Lines added: $$added" ; \
97 echo
"Lines removed: $$removed"; \
103 ## Expect no instances of '${...}'. However, $${...} is ok, since that
104 ## is a shell construct, not a Makefile construct.
105 sc_no_brace_variable_expansions
:
106 @if grep
-v
'^ *#' $(ams
) | grep
-F
'$${' | grep
-F
-v
'$$$$'; then \
107 echo
"Found too many uses of '\$${' in the lines above." 1>&2; \
111 ## Make sure 'rm' is called with '-f'.
113 @if grep
-v
'^#' $(ams
) $(xtests
) \
114 | grep
-vE
'/(spy-rm\.tap|subobj-clean.*-pr10697\.sh):' \
115 | grep
-E
'\<rm ([^-]|\-[^f ]*\>)'; \
117 echo
"Suspicious 'rm' invocation." 1>&2; \
121 ## Never use something like "for file in $(FILES)", this doesn't work
122 ## if FILES is empty or if it contains shell meta characters (e.g. $ is
123 ## commonly used in Java filenames).
124 sc_no_for_variable_in_macro
:
125 @if grep
'for .* in \$$(' $(ams
) | grep
-v
'/Makefile\.am:'; then \
126 echo
'Use "list=$$(mumble); for var in $$$$list".' 1>&2 ; \
130 ## Make sure all invocations of mkinstalldirs are correct.
132 @if grep
-n
'mkinstalldirs' $(ams
) \
133 | grep
-F
-v
'$$(mkinstalldirs)' \
134 | grep
-v
'^\./Makefile.am:[0-9][0-9]*: *lib/mkinstalldirs \\$$'; \
136 echo
"Found incorrect use of mkinstalldirs in the lines above" 1>&2; \
140 ## Make sure all calls to PRE/NORMAL/POST_INSTALL/UNINSTALL
141 sc_pre_normal_post_install_uninstall
:
142 @if grep
-E
-n
'\((PRE|NORMAL|POST)_(|UN)INSTALL\)' $(ams
) | \
143 grep
-v
':##' | grep
-v
': @\$$('; then \
144 echo
"Found incorrect use of PRE/NORMAL/POST_INSTALL/UNINSTALL in the lines above" 1>&2; \
148 ## We never want to use "undef", only "delete", but for $/.
150 @if grep
-n
-w
'undef ' $(srcdir)/automake.in | \
151 grep
-F
-v
'undef $$/'; then \
152 echo
"Found undef in automake.in; use delete instead" 1>&2; \
156 ## We never want split (/ /,...), only split (' ', ...).
157 sc_perl_no_split_regex_space
:
158 @if grep
-n
'split (/ /' $(srcdir)/automake.in
; then \
159 echo
"Found bad split in the lines above." 1>&2; \
163 ## Look for cd within backquotes
165 @if grep
-n
'^[^#]*` *cd ' $(srcdir)/automake.in
$(ams
); then \
166 echo
"Consider using \$$(am__cd) in the lines above." 1>&2; \
170 ## Look for cd to a relative directory (may be influenced by CDPATH).
171 ## Skip some known directories that are OK.
173 @if grep
-n
'^[^#]*cd ' $(srcdir)/automake.in
$(ams
) | \
174 grep
-v
'echo.*cd ' | \
175 grep
-v
'am__cd =' | \
176 grep
-v
'^[^#]*cd [./]' | \
177 grep
-v
'^[^#]*cd \$$(top_builddir)' | \
178 grep
-v
'^[^#]*cd "\$$\$$am__cwd' | \
179 grep
-v
'^[^#]*cd \$$(abs' | \
180 grep
-v
'^[^#]*cd "\$$(DESTDIR)'; then \
181 echo
"Consider using \$$(am__cd) in the lines above." 1>&2; \
185 ## Using @_ in a scalar context is most probably a programming error.
186 sc_perl_at_uscore_in_scalar_context
:
187 @if grep
-Hn
'[^@_A-Za-z0-9][_A-Za-z0-9]*[^) ] *= *@_' $(srcdir)/automake.in
; then \
188 echo
"Using @_ in a scalar context in the lines above." 1>&2; \
192 ## Allow only few variables to be localized in Automake.
194 @if egrep
-v
'^[ \t]*local \$$[_~]( *=|;)' $(srcdir)/automake.in | \
195 grep
'^[ \t]*local [^*]'; then \
196 echo
"Please avoid 'local'." 1>&2; \
200 ## Don't let AMDEP_TRUE substitution appear in automake.in.
201 sc_AMDEP_TRUE_in_automake_in
:
202 @if grep
'@AMDEP''_TRUE@' $(srcdir)/automake.in
; then \
203 echo
"Don't put AMDEP_TRUE substitution in automake.in" 1>&2; \
207 ## Recursive make invocations should always pass $(AM_MAKEFLAGS)
208 ## to $(MAKE), for portability to non-GNU make.
209 sc_tests_make_without_am_makeflags
:
210 @if grep
'^[^#].*(MAKE) ' $(ams
) $(srcdir)/automake.in \
211 | grep
-v
'AM_MAKEFLAGS' \
212 | grep
-v
'/am/header-vars\.am:.*am--echo.*| $$(MAKE) -f *-'; \
214 echo
'Use $$(MAKE) $$(AM_MAKEFLAGS).' 1>&2; \
218 ## Look out for some obsolete variables.
219 sc_tests_obsolete_variables
:
223 test_prefer_config_shell \
230 for v in
$$vars; do \
231 if grep
-E
"\b$$v\b" $(xtests
) $(xdefs
); then \
235 if
test -n
"$$seen"; then \
236 for v in
$$seen; do \
238 parallel_tests|am_parallel_tests
) v2
=am_serial_tests
;; \
241 echo
"Variable '$$v' is obsolete, use '$$v2' instead." 1>&2; \
246 ## Look out for obsolete requirements specified in the test cases.
247 sc_obsolete_requirements_rules
= sc_no_texi2dvi-o sc_no_makeinfo-html
248 modern-requirement.texi2dvi-o
= texi2dvi
249 modern-requirement.makeinfo-html
= makeinfo
251 $(sc_obsolete_requirements_rules
): sc_no_
% :
252 @if grep
-E
'required=.*\b$*\b' $(xtests
); then \
253 echo
"Requirement '$*' is obsolete and shouldn't" \
254 "be used anymore." >&2; \
255 echo
"You should use '$(modern-requirement.$*)' instead." >&2; \
259 ## Tests should never call some programs directly, but only through the
260 ## corresponding variable (e.g., '$MAKE', not 'make'). This will allow
261 ## the programs to be overridden at configure time (for less brittleness)
262 ## or by the user at make time (to allow better testsuite coverage).
263 sc_tests_plain_check_rules
= \
264 sc_tests_plain_egrep \
265 sc_tests_plain_fgrep \
266 sc_tests_plain_make \
267 sc_tests_plain_perl \
268 sc_tests_plain_automake \
269 sc_tests_plain_aclocal \
270 sc_tests_plain_autoconf \
271 sc_tests_plain_autoupdate \
272 sc_tests_plain_autom4te \
273 sc_tests_plain_autoheader \
274 sc_tests_plain_autoreconf
276 toupper
= $(shell echo
$(1) | LC_ALL
=C tr
'[a-z]' '[A-Z]')
278 $(sc_tests_plain_check_rules
): sc_tests_plain_
% :
279 @
# The leading ':' in the grep below is what is printed by the
280 @
# preceding 'grep -v' after the file name.
281 @
# It works here as a poor man's substitute for beginning-of-line
283 @if grep
-v
'^[ ]*#' $(xtests
) \
284 |
$(EGREP
) '(:|\bif|\bnot|[;!{\|\(]|&&|\|\|)[ ]*?$*\b'; \
286 echo
'Do not run "$*" in the above tests.' \
287 'Use "$$$(call toupper,$*)" instead.' 1>&2; \
291 ## Tests should only use END and EOF for here documents
292 ## (so that the next test is effective).
293 sc_tests_here_document_format
:
294 @if grep
'<<' $(xtests
) | grep
-Ev
'\b(END|EOF)\b|\bcout <<'; then \
295 echo
'Use here documents with "END" and "EOF" only, for greppability.' 1>&2; \
299 ## Our test case should use the $(...) POSIX form for command substitution,
300 ## rather than the older `...` form.
301 ## The point of ignoring text on here-documents is that we want to exempt
302 ## Makefile.am rules, configure.ac code and helper shell script created and
303 ## used by out shell scripts, because Autoconf (as of version 2.69) does not
304 ## yet ensure that $CONFIG_SHELL will be set to a proper POSIX shell.
305 sc_tests_command_subst
:
309 -e
'/<<.*END/,/^END/b' -e
'/<<.*EOF/,/^EOF/b' \
310 -e
's/\\`/\\{backtick}/' \
311 -e
"s/[^\\]'\([^']*\`[^']*\)*'/'{quoted-text}'/g" \
314 for file in
$(xtests
); do \
316 if
test -n
"$$res"; then \
317 echo
"$$file:$$res"; \
322 echo
'Use $$(...), not `...`, for command substitutions.' >&2; \
326 ## Tests should no longer call 'Exit', just 'exit'. That's because we
327 ## now have in place a better workaround to ensure the exit status is
328 ## transported correctly across the exit trap.
329 sc_tests_exit_not_Exit
:
330 @if grep
'Exit' $(xtests
) $(xdefs
) | grep
-Ev
'^[^:]+: *#' | grep .
; then \
331 echo
"Use 'exit', not 'Exit'; it's obsolete now." 1>&2; \
335 ## Guard against obsolescent uses of ./defs in tests. Now,
336 ## 'test-init.sh' should be used instead.
337 sc_tests_no_source_defs
:
338 @if grep
-E
'\. .*defs($$| )' $(xtests
); then \
339 echo
"Source 'test-init.sh', not './defs'." 1>&2; \
343 ## Use AUTOMAKE_fails when appropriate
344 sc_tests_automake_fails
:
345 @if grep
-v
'^#' $(xtests
) | grep
'\$$AUTOMAKE.*&&.*exit'; then \
346 echo
'Use AUTOMAKE_fails + grep to catch automake failures in the above tests.' 1>&2; \
350 ## Setting 'required' after sourcing './defs' is a bug.
351 sc_tests_required_after_defs
:
352 @for file in
$(xtests
); do \
353 if out
=`sed -n '/defs/,$${/required=/p;}' $$file`; test -n
"$$out"; then \
354 echo
'Do not set "required" after sourcing "defs" in '"$$file: $$out" 1>&2; \
359 ## Overriding a Makefile macro on the command line is not portable when
360 ## recursive targets are used. Better use an envvar. SHELL is an
361 ## exception, POSIX says it can't come from the environment. V, DESTDIR,
362 ## DISTCHECK_CONFIGURE_FLAGS and DISABLE_HARD_ERRORS are exceptions, too,
363 ## as package authors are urged not to initialize them anywhere.
364 ## Finally, 'exp' is used by some ad-hoc checks, where we ensure it's
365 ## ok to override it from the command line.
366 sc_tests_overriding_macros_on_cmdline
:
367 @if grep
-E
'\$$MAKE .*(SHELL=.*=|=.*SHELL=)' $(xtests
); then \
368 echo
'Rewrite "$$MAKE foo=bar SHELL=$$SHELL" as "foo=bar $$MAKE -e SHELL=$$SHELL"' 1>&2; \
369 echo
' in the above lines, it is more portable.' 1>&2; \
372 # The first s/// tries to account for usages like "$MAKE || st=$?".
373 # 'DISTCHECK_CONFIGURE_FLAGS' and 'exp' are allowed to contain whitespace in
374 # their definitions, hence the more complex last three substitutions below.
375 # Also, the 'make-dryrun.sh' is whitelisted, since there we need to
376 # override variables from the command line in order to cover the expected
378 @tests
=`for t in $(xtests); do \
379 case $$t in */make-dryrun.sh);; *) echo $$t;; esac; \
381 if sed
-e
's/ || .*//' -e
's/ && .*//' \
382 -e
's/ DESTDIR=[^ ]*/ /' -e
's/ SHELL=[^ ]*/ /' \
383 -e
's/ V=[^ ]*/ /' -e
's/ DISABLE_HARD_ERRORS=[^ ]*/ /' \
384 -e
"s/ DISTCHECK_CONFIGURE_FLAGS='[^']*'/ /" \
385 -e
's/ DISTCHECK_CONFIGURE_FLAGS="[^"]*"/ /' \
386 -e
's/ DISTCHECK_CONFIGURE_FLAGS=[^ ]/ /' \
387 -e
"s/ exp='[^']*'/ /" \
388 -e
's/ exp="[^"]*"/ /' \
389 -e
's/ exp=[^ ]/ /' \
390 $$tests | grep
'\$$MAKE .*='; then \
391 echo
'Rewrite "$$MAKE foo=bar" as "foo=bar $$MAKE -e" in the above lines,' 1>&2; \
392 echo
'it is more portable.' 1>&2; \
395 @if grep
'SHELL=.*\$$MAKE' $(xtests
); then \
396 echo
'$$MAKE ignores the SHELL envvar, use "$$MAKE SHELL=$$SHELL" in' 1>&2; \
397 echo
'the above lines.' 1>&2; \
401 ## Prefer use of our 'is_newest' auxiliary script over the more hacky
402 ## idiom "test $(ls -1t new old | sed 1q) = new", which is both more
403 ## cumbersome and more fragile.
405 @if LC_ALL
=C grep
-E
'\bls(\s+-[a-zA-Z0-9]+)*\s+-[a-zA-Z0-9]*t' \
407 echo
"Use 'is_newest' rather than hacks based on 'ls -t'" 1>&2; \
411 ## Test scripts must be executable.
414 for f in
$(xtests
); do \
416 t
/ax
/*|.
/t
/ax
/*|
$(srcdir)/t
/ax
/*);; \
417 *) test -x
$$f ||
{ echo
"$$f: not executable" >&2; st
=1; }; \
420 test $$st -eq
0 || echo
'$@: some test scripts are not executable' >&2; \
424 ## Never use 'sleep 1' to create files with different timestamps.
425 ## Use '$sleep' instead. Some filesystems (e.g., Windows) have only
426 ## a 2sec resolution.
427 sc_tests_plain_sleep
:
428 @if grep
-E
'\bsleep +[12345]\b' $(xtests
); then \
429 echo
'Do not use "sleep x" in the above tests. Use "$$sleep" instead.' 1>&2; \
433 ## fgrep and egrep are not required by POSIX.
434 sc_m4_am_plain_egrep_fgrep
:
435 @if grep
-E
'\b[ef]grep\b' $(ams
) $(srcdir)/m4
/*.m4
; then \
436 echo
'Do not use egrep or fgrep in the above files,' \
437 'they are not portable.' 1>&2; \
441 ## Prefer 'configure.ac' over the obsolescent 'configure.in' as the name
442 ## for configure input files in our testsuite. The latter has been
443 ## deprecated for several years (at least since autoconf 2.50).
444 sc_tests_no_configure_in
:
445 @if grep
-E
'\bconfigure\\*\.in\b' $(xtests
) $(xdefs
) \
446 | grep
-Ev
'/backcompat.*\.(sh|tap):' \
447 | grep
-Ev
'/autodist-configure-no-subdir\.sh:' \
448 | grep
-Ev
'/(configure|help)\.sh:' \
451 echo
"Use 'configure.ac', not 'configure.in', as the name" >&2; \
452 echo
"for configure input files in the test cases above." >&2; \
456 ## Rule to ensure that the testsuite has been run before. We don't depend
457 ## on 'check' here, because that would be very wasteful in the common case.
458 ## We could run "make check RECHECK_LOGS=" and avoid toplevel races with
459 ## AM_RECURSIVE_TARGETS. Suggest keeping test directories around for
460 ## greppability of the Makefile.in files.
461 sc_ensure_testsuite_has_run
:
462 @if
test ! -f
'$(TEST_SUITE_LOG)'; then \
463 echo
'Run "env keep_testdirs=yes make check" before' \
464 'running "make maintainer-check"' >&2; \
467 .PHONY
: sc_ensure_testsuite_has_run
469 ## Ensure our warning and error messages do not contain duplicate 'warning:' prefixes.
470 ## This test actually depends on the testsuite having been run before.
471 sc_tests_logs_duplicate_prefixes
: sc_ensure_testsuite_has_run
472 @if grep
-E
'(warning|error):.*(warning|error):' t
/*.log
; then \
473 echo
'Duplicate warning/error message prefixes seen in above tests.' >&2; \
477 ## Ensure variables are listed before rules in Makefile.in files we generate.
478 sc_tests_makefile_variable_order
: sc_ensure_testsuite_has_run
480 for file in
`find t -name Makefile.in -print`; do \
483 -e '/\\\\$$/{' -e N -e 'b x' -e '}' \
484 -e '# Literal TAB.' \
486 -e '# Allow @ so we match conditionals.' \
487 -e '/^ *[a-zA-Z_@]\{1,\} *=/p' $$file`; \
488 if
test -n
"$$latevars"; then \
489 echo
"Variables are expanded too late in $$file:" >&2; \
490 echo
"$$latevars" | sed
's/^/ /' >&2; \
494 test $$st -eq
0 ||
{ \
495 echo
'Ensure variables are expanded before rules' >&2; \
499 ## Using ':' as a PATH separator is not portable.
500 sc_tests_PATH_SEPARATOR
:
501 @if grep
-E
'\bPATH=.*:.*' $(xtests
) ; then \
502 echo
"Use '\$$PATH_SEPARATOR', not ':', in PATH definitions" \
507 ## Try to make sure all @...@ substitutions are covered by our
508 ## substitution rule.
510 @if
test `grep -E '^[^#]*@[A-Za-z_0-9]+@' aclocal | wc -l` -ne
0; then \
511 echo
"Unresolved @...@ substitution in aclocal" 1>&2; \
514 @if
test `grep -E '^[^#]*@[A-Za-z_0-9]+@' automake | wc -l` -ne
0; then \
515 echo
"Unresolved @...@ substitution in automake" 1>&2; \
520 @if grep
-E
"[^\'\"]\\\$$\(DESTDIR" $(ams
); then \
521 echo
'Suspicious unquoted DESTDIR uses.' 1>&2 ; \
526 @if grep
' ' $(srcdir)/doc
/automake.texi
; then \
527 echo
'Do not use tabs in the manual.' 1>&2; \
532 @if grep
-E
'([^@]|^)@([ ][^@]|$$)' $(srcdir)/doc
/automake.texi
; \
534 echo
'Unescaped @.' 1>&2; \
538 $(syntax_check_rules
): automake aclocal
539 maintainer-check
: $(syntax_check_rules
)
540 .PHONY
: maintainer-check
$(syntax_check_rules
)
542 ## Check that the list of tests given in the Makefile is equal to the
543 ## list of all test scripts in the Automake testsuite.
544 maintainer-check
: maintainer-check-list-of-tests