tests: fix a spurious typo-related failure
[automake.git] / syntax-checks.mk
blob89b4d2cdcdd7db277cd1795d7f03839abd90c9d4
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)
8 # any later version.
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).
22 xtests := $(shell \
23 if test $(srcdir) = .; then \
24 dirs=.; \
25 else \
26 dirs='$(srcdir) .'; \
27 fi; \
28 for d in $$dirs; do \
29 for s in tap sh; do \
30 ls $$d/t/*.$$s $$d/t/ax/*.$$s 2>/dev/null; \
31 done; \
32 done | sort)
34 xdefs = \
35 $(srcdir)/t/ax/am-test-lib.sh \
36 $(srcdir)/t/ax/test-lib.sh \
37 $(srcdir)/t/ax/test-defs.in \
38 $(srcdir)/defs
40 ams := $(shell find $(srcdir) -name '*.dir' -prune -o -name '*.am' -print)
42 # Some simple checks, and then ordinary check. These are only really
43 # guaranteed to work on my machine.
44 syntax_check_rules = \
45 $(sc_tests_plain_check_rules) \
46 sc_diff_automake_in_automake \
47 sc_diff_aclocal_in_automake \
48 sc_perl_syntax \
49 sc_no_brace_variable_expansions \
50 sc_rm_minus_f \
51 sc_no_for_variable_in_macro \
52 sc_mkinstalldirs \
53 sc_pre_normal_post_install_uninstall \
54 sc_perl_no_undef \
55 sc_perl_no_split_regex_space \
56 sc_cd_in_backquotes \
57 sc_cd_relative_dir \
58 sc_perl_at_uscore_in_scalar_context \
59 sc_perl_local \
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 \
70 sc_tests_ls_t \
71 sc_tests_executable \
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 \
77 sc_perl_at_substs \
78 sc_unquoted_DESTDIR \
79 sc_tabs_in_texi \
80 sc_at_in_texi
82 ## These check avoids accidental configure substitutions in the source.
83 ## There are exactly 9 lines that should be modified from automake.in to
84 ## automake, and 10 lines that should be modified from aclocal.in to
85 ## aclocal; these wors out to 32 and 34 lines of diffs, respectively.
86 sc_diff_automake_in_automake:
87 @if test `diff $(srcdir)/automake.in automake | wc -l` -ne 32; then \
88 echo "found too many diffs between automake.in and automake" 1>&2; \
89 diff -c $(srcdir)/automake.in automake; \
90 exit 1; \
92 sc_diff_aclocal_in_aclocal:
93 @if test `diff $(srcdir)/aclocal.in aclocal | wc -l` -ne 34; then \
94 echo "found too many diffs between aclocal.in and aclocal" 1>&2; \
95 diff -c $(srcdir)/aclocal.in aclocal; \
96 exit 1; \
99 ## Syntax check with default Perl (on my machine, Perl 5).
100 sc_perl_syntax:
101 @perllibdir="./lib$(PATH_SEPARATOR)$(srcdir)/lib" $(PERL) -c -w automake
102 @perllibdir="./lib$(PATH_SEPARATOR)$(srcdir)/lib" $(PERL) -c -w aclocal
104 ## Expect no instances of '${...}'. However, $${...} is ok, since that
105 ## is a shell construct, not a Makefile construct.
106 sc_no_brace_variable_expansions:
107 @if grep -v '^ *#' $(ams) | grep -F '$${' | grep -F -v '$$$$'; then \
108 echo "Found too many uses of '\$${' in the lines above." 1>&2; \
109 exit 1; \
110 else :; fi
112 ## Make sure 'rm' is called with '-f'.
113 sc_rm_minus_f:
114 @if grep -v '^#' $(ams) $(xtests) \
115 | grep -vE '/(spy-rm\.tap|subobj-clean.*-pr10697\.sh):' \
116 | grep -E '\<rm ([^-]|\-[^f ]*\>)'; \
117 then \
118 echo "Suspicious 'rm' invocation." 1>&2; \
119 exit 1; \
120 else :; fi
122 ## Never use something like "for file in $(FILES)", this doesn't work
123 ## if FILES is empty or if it contains shell meta characters (e.g. $ is
124 ## commonly used in Java filenames).
125 sc_no_for_variable_in_macro:
126 @if grep 'for .* in \$$(' $(ams) | grep -v '/Makefile\.am:'; then \
127 echo 'Use "list=$$(mumble); for var in $$$$list".' 1>&2 ; \
128 exit 1; \
129 else :; fi
131 ## Make sure all invocations of mkinstalldirs are correct.
132 sc_mkinstalldirs:
133 @if grep -n 'mkinstalldirs' $(ams) \
134 | grep -F -v '$$(mkinstalldirs)' \
135 | grep -v '^\./Makefile.am:[0-9][0-9]*: *lib/mkinstalldirs \\$$'; \
136 then \
137 echo "Found incorrect use of mkinstalldirs in the lines above" 1>&2; \
138 exit 1; \
139 else :; fi
141 ## Make sure all calls to PRE/NORMAL/POST_INSTALL/UNINSTALL
142 sc_pre_normal_post_install_uninstall:
143 @if grep -E -n '\((PRE|NORMAL|POST)_(|UN)INSTALL\)' $(ams) | \
144 grep -v ':##' | grep -v ': @\$$('; then \
145 echo "Found incorrect use of PRE/NORMAL/POST_INSTALL/UNINSTALL in the lines above" 1>&2; \
146 exit 1; \
147 else :; fi
149 ## We never want to use "undef", only "delete", but for $/.
150 sc_perl_no_undef:
151 @if grep -n -w 'undef ' $(srcdir)/automake.in | \
152 grep -F -v 'undef $$/'; then \
153 echo "Found undef in automake.in; use delete instead" 1>&2; \
154 exit 1; \
157 ## We never want split (/ /,...), only split (' ', ...).
158 sc_perl_no_split_regex_space:
159 @if grep -n 'split (/ /' $(srcdir)/automake.in; then \
160 echo "Found bad split in the lines above." 1>&2; \
161 exit 1; \
164 ## Look for cd within backquotes
165 sc_cd_in_backquotes:
166 @if grep -n '^[^#]*` *cd ' $(srcdir)/automake.in $(ams); then \
167 echo "Consider using \$$(am__cd) in the lines above." 1>&2; \
168 exit 1; \
171 ## Look for cd to a relative directory (may be influenced by CDPATH).
172 ## Skip some known directories that are OK.
173 sc_cd_relative_dir:
174 @if grep -n '^[^#]*cd ' $(srcdir)/automake.in $(ams) | \
175 grep -v 'echo.*cd ' | \
176 grep -v 'am__cd =' | \
177 grep -v '^[^#]*cd [./]' | \
178 grep -v '^[^#]*cd \$$(top_builddir)' | \
179 grep -v '^[^#]*cd "\$$\$$am__cwd' | \
180 grep -v '^[^#]*cd \$$(abs' | \
181 grep -v '^[^#]*cd "\$$(DESTDIR)'; then \
182 echo "Consider using \$$(am__cd) in the lines above." 1>&2; \
183 exit 1; \
186 ## Using @_ in a scalar context is most probably a programming error.
187 sc_perl_at_uscore_in_scalar_context:
188 @if grep -Hn '[^@_A-Za-z0-9][_A-Za-z0-9]*[^) ] *= *@_' $(srcdir)/automake.in; then \
189 echo "Using @_ in a scalar context in the lines above." 1>&2; \
190 exit 1; \
193 ## Allow only few variables to be localized in Automake.
194 sc_perl_local:
195 @if egrep -v '^[ \t]*local \$$[_~]( *=|;)' $(srcdir)/automake.in | \
196 grep '^[ \t]*local [^*]'; then \
197 echo "Please avoid 'local'." 1>&2; \
198 exit 1; \
201 ## Don't let AMDEP_TRUE substitution appear in automake.in.
202 sc_AMDEP_TRUE_in_automake_in:
203 @if grep '@AMDEP''_TRUE@' $(srcdir)/automake.in; then \
204 echo "Don't put AMDEP_TRUE substitution in automake.in" 1>&2; \
205 exit 1; \
208 ## Recursive make invocations should always pass $(AM_MAKEFLAGS)
209 ## to $(MAKE), for portability to non-GNU make.
210 sc_tests_make_without_am_makeflags:
211 @if grep '^[^#].*(MAKE) ' $(ams) $(srcdir)/automake.in \
212 | grep -v 'AM_MAKEFLAGS' \
213 | grep -v '/am/header-vars\.am:.*am--echo.*| $$(MAKE) -f *-'; \
214 then \
215 echo 'Use $$(MAKE) $$(AM_MAKEFLAGS).' 1>&2; \
216 exit 1; \
219 ## Look out for some obsolete variables.
220 sc_tests_obsolete_variables:
221 @vars=" \
222 using_tap \
223 am_using_tap \
224 test_prefer_config_shell \
225 original_AUTOMAKE \
226 original_ACLOCAL \
227 parallel_tests \
228 am_parallel_tests \
229 "; \
230 seen=""; \
231 for v in $$vars; do \
232 if grep -E "\b$$v\b" $(xtests) $(xdefs); then \
233 seen="$$seen $$v"; \
234 fi; \
235 done; \
236 if test -n "$$seen"; then \
237 for v in $$seen; do \
238 case $$v in \
239 parallel_tests|am_parallel_tests) v2=am_serial_tests;; \
240 *) v2=am_$$v;; \
241 esac; \
242 echo "Variable '$$v' is obsolete, use '$$v2' instead." 1>&2; \
243 done; \
244 exit 1; \
245 else :; fi
247 ## Tests should never call some programs directly, but only through the
248 ## corresponding variable (e.g., '$MAKE', not 'make'). This will allow
249 ## the programs to be overridden at configure time (for less brittleness)
250 ## or by the user at make time (to allow better testsuite coverage).
251 sc_tests_plain_check_rules = \
252 sc_tests_plain_egrep \
253 sc_tests_plain_fgrep \
254 sc_tests_plain_make \
255 sc_tests_plain_perl \
256 sc_tests_plain_automake \
257 sc_tests_plain_aclocal \
258 sc_tests_plain_autoconf \
259 sc_tests_plain_autoupdate \
260 sc_tests_plain_autom4te \
261 sc_tests_plain_autoheader \
262 sc_tests_plain_autoreconf
264 toupper = $(shell echo $(1) | LC_ALL=C tr '[a-z]' '[A-Z]')
266 $(sc_tests_plain_check_rules): sc_tests_plain_% :
267 @# The leading ':' in the grep below is what is printed by the
268 @# preceding 'grep -v' after the file name.
269 @# It works here as a poor man's substitute for beginning-of-line
270 @# marker.
271 @if grep -v '^[ ]*#' $(xtests) \
272 | $(EGREP) '(:|\bif|\bnot|[;!{\|\(]|&&|\|\|)[ ]*?$*\b'; \
273 then \
274 echo 'Do not run "$*" in the above tests.' \
275 'Use "$$$(call toupper,$*)" instead.' 1>&2; \
276 exit 1; \
279 ## Tests should only use END and EOF for here documents
280 ## (so that the next test is effective).
281 sc_tests_here_document_format:
282 @if grep '<<' $(xtests) | grep -Ev '\b(END|EOF)\b|\bcout <<'; then \
283 echo 'Use here documents with "END" and "EOF" only, for greppability.' 1>&2; \
284 exit 1; \
287 ## Our test case should use the $(...) POSIX form for command substitution,
288 ## rather than the older `...` form.
289 ## The point of ignoring text on here-documents is that we want to exempt
290 ## Makefile.am rules, configure.ac code and helper shell script created and
291 ## used by out shell scripts, because Autoconf (as of version 2.69) does not
292 ## yet ensure that $CONFIG_SHELL will be set to a proper POSIX shell.
293 sc_tests_command_subst:
294 @found=false; \
295 scan () { \
296 sed -n -e '/^#/d' \
297 -e '/<<.*END/,/^END/b' -e '/<<.*EOF/,/^EOF/b' \
298 -e 's/\\`/\\{backtick}/' \
299 -e "s/[^\\]'\([^']*\`[^']*\)*'/'{quoted-text}'/g" \
300 -e '/`/p' $$*; \
301 }; \
302 for file in $(xtests); do \
303 res=`scan $$file`; \
304 if test -n "$$res"; then \
305 echo "$$file:$$res"; \
306 found=true; \
307 fi; \
308 done; \
309 if $$found; then \
310 echo 'Use $$(...), not `...`, for command substitutions.' >&2; \
311 exit 1; \
314 ## Tests should no more call 'Exit', just 'exit'. That's because we
315 ## now have in place a better workaround to ensure the exit status is
316 ## transported correctly across the exit trap.
317 sc_tests_Exit_not_exit:
318 @if grep 'Exit' $(xtests) $(xdefs) | grep -Ev '^[^:]+: *#' | grep .; then \
319 echo "Use 'exit', not 'Exit'; it's obsolete now." 1>&2; \
320 exit 1; \
323 ## Use AUTOMAKE_fails when appropriate
324 sc_tests_automake_fails:
325 @if grep -v '^#' $(xtests) | grep '\$$AUTOMAKE.*&&.*exit'; then \
326 echo 'Use AUTOMAKE_fails + grep to catch automake failures in the above tests.' 1>&2; \
327 exit 1; \
330 ## Setting 'required' after sourcing './defs' is a bug.
331 sc_tests_required_after_defs:
332 @for file in $(xtests); do \
333 if out=`sed -n '/defs/,$${/required=/p;}' $$file`; test -n "$$out"; then \
334 echo 'Do not set "required" after sourcing "defs" in '"$$file: $$out" 1>&2; \
335 exit 1; \
336 fi; \
337 done
339 ## Overriding a Makefile macro on the command line is not portable when
340 ## recursive targets are used. Better use an envvar. SHELL is an
341 ## exception, POSIX says it can't come from the environment. V, DESTDIR,
342 ## DISTCHECK_CONFIGURE_FLAGS and DISABLE_HARD_ERRORS are exceptions, too,
343 ## as package authors are urged not to initialize them anywhere.
344 ## Finally, 'exp' is used by some ad-hoc checks, where we ensure it's
345 ## ok to override it from the command line.
346 sc_tests_overriding_macros_on_cmdline:
347 @if grep -E '\$$MAKE .*(SHELL=.*=|=.*SHELL=)' $(xtests); then \
348 echo 'Rewrite "$$MAKE foo=bar SHELL=$$SHELL" as "foo=bar $$MAKE -e SHELL=$$SHELL"' 1>&2; \
349 echo ' in the above lines, it is more portable.' 1>&2; \
350 exit 1; \
352 # The first s/// tries to account for usages like "$MAKE || st=$?".
353 # 'DISTCHECK_CONFIGURE_FLAGS' and 'exp' are allowed to contain whitespace in
354 # their definitions, hence the more complex last three substitutions below.
355 # Also, the 'make-dryrun.sh' is whitelisted, since there we need to
356 # override variables from the command line in order to cover the expected
357 # code paths.
358 @tests=`for t in $(xtests); do \
359 case $$t in */make-dryrun.sh);; *) echo $$t;; esac; \
360 done`; \
361 if sed -e 's/ || .*//' -e 's/ && .*//' \
362 -e 's/ DESTDIR=[^ ]*/ /' -e 's/ SHELL=[^ ]*/ /' \
363 -e 's/ V=[^ ]*/ /' -e 's/ DISABLE_HARD_ERRORS=[^ ]*/ /' \
364 -e "s/ DISTCHECK_CONFIGURE_FLAGS='[^']*'/ /" \
365 -e 's/ DISTCHECK_CONFIGURE_FLAGS="[^"]*"/ /' \
366 -e 's/ DISTCHECK_CONFIGURE_FLAGS=[^ ]/ /' \
367 -e "s/ exp='[^']*'/ /" \
368 -e 's/ exp="[^"]*"/ /' \
369 -e 's/ exp=[^ ]/ /' \
370 $$tests | grep '\$$MAKE .*='; then \
371 echo 'Rewrite "$$MAKE foo=bar" as "foo=bar $$MAKE -e" in the above lines,' 1>&2; \
372 echo 'it is more portable.' 1>&2; \
373 exit 1; \
375 @if grep 'SHELL=.*\$$MAKE' $(xtests); then \
376 echo '$$MAKE ignores the SHELL envvar, use "$$MAKE SHELL=$$SHELL" in' 1>&2; \
377 echo 'the above lines.' 1>&2; \
378 exit 1; \
381 ## Prefer use of our 'is_newest' auxiliary script over the more hacky
382 ## idiom "test $(ls -1t new old | sed 1q) = new", which is both more
383 ## cumbersome and more fragile.
384 sc_tests_ls_t:
385 @if LC_ALL=C grep -E '\bls(\s+-[a-zA-Z0-9]+)*\s+-[a-zA-Z0-9]*t' \
386 $(xtests); then \
387 echo "Use 'is_newest' rather than hacks based on 'ls -t'" 1>&2; \
388 exit 1; \
391 ## Test scripts must be executable.
392 sc_tests_executable:
393 @st=0; \
394 for f in $(xtests); do \
395 case $$f in \
396 t/ax/*|./t/ax/*|$(srcdir)/t/ax/*);; \
397 *) test -x $$f || { echo "$$f: not executable" >&2; st=1; }; \
398 esac; \
399 done; \
400 test $$st -eq 0 || echo '$@: some test scripts are not executable' >&2; \
401 exit $$st;
404 ## Never use 'sleep 1' to create files with different timestamps.
405 ## Use '$sleep' instead. Some filesystems (e.g., Windows) have only
406 ## a 2sec resolution.
407 sc_tests_plain_sleep:
408 @if grep -E '\bsleep +[12345]\b' $(xtests); then \
409 echo 'Do not use "sleep x" in the above tests. Use "$$sleep" instead.' 1>&2; \
410 exit 1; \
413 ## fgrep and egrep are not required by POSIX.
414 sc_m4_am_plain_egrep_fgrep:
415 @if grep -E '\b[ef]grep\b' $(ams) $(srcdir)/m4/*.m4; then \
416 echo 'Do not use egrep or fgrep in the above files,' \
417 'they are not portable.' 1>&2; \
418 exit 1; \
421 ## Prefer 'configure.ac' over the obsolescent 'configure.in' as the name
422 ## for configure input files in our testsuite. The latter has been
423 ## deprecated for several years (at least since autoconf 2.50).
424 sc_tests_no_configure_in:
425 @if grep -E '\bconfigure\\*\.in\b' $(xtests) $(xdefs) \
426 | grep -Ev '/backcompat.*\.(sh|tap):' \
427 | grep -Ev '/autodist-configure-no-subdir\.sh:' \
428 | grep -Ev '/(configure|help)\.sh:' \
429 | grep .; \
430 then \
431 echo "Use 'configure.ac', not 'configure.in', as the name" >&2; \
432 echo "for configure input files in the test cases above." >&2; \
433 exit 1; \
436 ## Rule to ensure that the testsuite has been run before. We don't depend
437 ## on 'check' here, because that would be very wasteful in the common case.
438 ## We could run "make check RECHECK_LOGS=" and avoid toplevel races with
439 ## AM_RECURSIVE_TARGETS. Suggest keeping test directories around for
440 ## greppability of the Makefile.in files.
441 sc_ensure_testsuite_has_run:
442 @if test ! -f '$(TEST_SUITE_LOG)'; then \
443 echo 'Run "env keep_testdirs=yes make check" before' \
444 'running "make maintainer-check"' >&2; \
445 exit 1; \
447 .PHONY: sc_ensure_testsuite_has_run
449 ## Ensure our warning and error messages do not contain duplicate 'warning:' prefixes.
450 ## This test actually depends on the testsuite having been run before.
451 sc_tests_logs_duplicate_prefixes: sc_ensure_testsuite_has_run
452 @if grep -E '(warning|error):.*(warning|error):' t/*.log; then \
453 echo 'Duplicate warning/error message prefixes seen in above tests.' >&2; \
454 exit 1; \
457 ## Ensure variables are listed before rules in Makefile.in files we generate.
458 sc_tests_makefile_variable_order: sc_ensure_testsuite_has_run
459 @st=0; \
460 for file in `find t -name Makefile.in -print`; do \
461 latevars=`sed -n \
462 -e :x -e 's/#.*//' \
463 -e '/\\\\$$/{' -e N -e 'b x' -e '}' \
464 -e '# Literal TAB.' \
465 -e '1,/^ /d' \
466 -e '# Allow @ so we match conditionals.' \
467 -e '/^ *[a-zA-Z_@]\{1,\} *=/p' $$file`; \
468 if test -n "$$latevars"; then \
469 echo "Variables are expanded too late in $$file:" >&2; \
470 echo "$$latevars" | sed 's/^/ /' >&2; \
471 st=1; \
472 fi; \
473 done; \
474 test $$st -eq 0 || { \
475 echo 'Ensure variables are expanded before rules' >&2; \
476 exit 1; \
479 ## Using ':' as a PATH separator is not portable.
480 sc_tests_PATH_SEPARATOR:
481 @if grep -E '\bPATH=.*:.*' $(xtests) ; then \
482 echo "Use '\$$PATH_SEPARATOR', not ':', in PATH definitions" \
483 "above." 1>&2; \
484 exit 1; \
487 ## Try to make sure all @...@ substitutions are covered by our
488 ## substitution rule.
489 sc_perl_at_substs:
490 @if test `grep -E '^[^#]*@[A-Za-z_0-9]+@' aclocal | wc -l` -ne 0; then \
491 echo "Unresolved @...@ substitution in aclocal" 1>&2; \
492 exit 1; \
494 @if test `grep -E '^[^#]*@[A-Za-z_0-9]+@' automake | wc -l` -ne 0; then \
495 echo "Unresolved @...@ substitution in automake" 1>&2; \
496 exit 1; \
499 sc_unquoted_DESTDIR:
500 @if grep -E "[^\'\"]\\\$$\(DESTDIR" $(ams); then \
501 echo 'Suspicious unquoted DESTDIR uses.' 1>&2 ; \
502 exit 1; \
505 sc_tabs_in_texi:
506 @if grep ' ' $(srcdir)/doc/automake.texi; then \
507 echo 'Do not use tabs in the manual.' 1>&2; \
508 exit 1; \
511 sc_at_in_texi:
512 @if grep -E '([^@]|^)@([ ][^@]|$$)' $(srcdir)/doc/automake.texi; \
513 then \
514 echo 'Unescaped @.' 1>&2; \
515 exit 1; \
518 $(syntax_check_rules): automake aclocal
519 maintainer-check: $(syntax_check_rules)
520 .PHONY: maintainer-check $(syntax_check_rules)
522 ## Check that the list of tests given in the Makefile is equal to the
523 ## list of all test scripts in the Automake testsuite.
524 maintainer-check: maintainer-check-list-of-tests