Codebase list virt-viewer / 98c2628
build: merge all syntax-check logic into one file The gnulib syntax-check rules are spread across GNUmakefile, cfg.mk and maint.mk. This made sense when we were getting two of the files from the gnulib submodule. Now that we own all files though, we can at least merge maint.mk and cfg.mk together. GNUmakefile can be eliminated when we switch to meson. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Daniel P. Berrangé 3 years ago
5 changed file(s) with 876 addition(s) and 895 deletion(s). Raw diff Collapse all Expand all
4646 include Makefile
4747
4848 # Some projects override e.g., _autoreconf here.
49 include $(srcdir)/$(_build-aux)/cfg.mk
50 include $(srcdir)/$(_build-aux)/maint.mk
49 include $(srcdir)/$(_build-aux)/syntax-check.mk
5150
5251 else
5352
5554 srcdir = .
5655
5756 # The package can override .DEFAULT_GOAL to run actions like autoreconf.
58 include $(srcdir)/$(_build-aux)/cfg.mk
59 include $(srcdir)/$(_build-aux)/maint.mk
57 include $(srcdir)/$(_build-aux)/syntax-check.mk
6058
6159 ifeq ($(.DEFAULT_GOAL),abort-due-to-no-makefile)
6260 $(MAKECMDGOALS): abort-due-to-no-makefile
88 $(PACKAGE).spec $(PACKAGE).spec.in \
99 mingw-$(PACKAGE).spec.in \
1010 GNUmakefile \
11 build-aux/cfg.mk \
1211 build-aux/gitlog-to-changelog \
13 build-aux/maint.mk \
12 build-aux/syntax-check.mk \
1413 build-aux/useless-if-before-free \
1514 build-aux/vc-list-files \
1615 AUTHORS.in \
+0
-83
build-aux/cfg.mk less more
0 # Customize Makefile.maint. -*- makefile -*-
1 # Copyright (C) 2008-2012 Red Hat, Inc.
2 # Copyright (C) 2003-2008 Free Software Foundation, Inc.
3
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 # Files that should never cause syntax check failures.
18 VC_LIST_ALWAYS_EXCLUDE_REGEX = \
19 (^HACKING|\.po|build-aux/maint.mk)$$
20
21 # Functions like free() that are no-ops on NULL arguments.
22 useless_free_options = \
23 --name=g_free \
24 --name=xmlBufferFree \
25 --name=xmlFree \
26 --name=xmlFreeDoc \
27 --name=xmlXPathFreeContext \
28 --name=xmlFreeParserContext \
29 --name=xmlXPathFreeObject
30
31 # Ensure that no C source file, docs, or rng schema uses TABs for
32 # indentation. Also match *.h.in files, to get libvirt.h.in. Exclude
33 # files in gnulib, since they're imported.
34 space_indent_files=(\.(rng|s?[ch](\.in)?|html.in|py)|(daemon|tools)/.*\.in)
35 sc_TAB_in_indentation:
36 @prohibit='^ * ' \
37 in_vc_files='$(space_indent_files)$$' \
38 halt='indent with space, not TAB, in C, sh, html, py, and RNG schemas' \
39 $(_sc_search_regexp)
40
41 # G_GNUC_UNUSED should only be applied in implementations, not
42 # header declarations
43 sc_avoid_attribute_unused_in_header:
44 @prohibit='^[^#]*G_GNUC_UNUSED([^:]|$$)' \
45 in_vc_files='\.h$$' \
46 halt='use G_GNUC_UNUSED in .c rather than .h files' \
47 $(_sc_search_regexp)
48
49 # Enforce recommended preprocessor indentation style.
50 sc_preprocessor_indentation:
51 @if cppi --version >/dev/null 2>&1; then \
52 $(VC_LIST_EXCEPT) | grep '\.[ch]$$' | xargs cppi -a -c \
53 || { echo '$(ME): incorrect preprocessor indentation' 1>&2; \
54 exit 1; }; \
55 else \
56 echo '$(ME): skipping test $@: cppi not installed' 1>&2; \
57 fi
58
59 sc_copyright_format:
60 @require='Copyright .*Red 'Hat', Inc\.' \
61 containing='Copyright .*Red 'Hat \
62 halt='Red Hat copyright is missing Inc.' \
63 $(_sc_search_regexp)
64 @prohibit='Copyright [^(].*Red 'Hat \
65 halt='consistently use (C) in Red Hat copyright' \
66 $(_sc_search_regexp)
67 @prohibit='\<Red''Hat\>' \
68 halt='spell Red Hat as two words' \
69 $(_sc_search_regexp)
70
71
72 exclude_file_name_regexp--sc_preprocessor_indentation = ^*/*.[ch]
73 exclude_file_name_regexp--sc_prohibit_strcmp = ^*/*.[ch]
74 exclude_file_name_regexp--sc_require_config_h = ^src/gbinding\.c|src/windows-cmdline-wrapper.c
75 exclude_file_name_regexp--sc_require_config_h_first = ^src/gbinding\.c|src/windows-cmdline-wrapper.c
76
77 exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF = ^icons/
78 exclude_file_name_regexp--sc_trailing_blank = ^icons/
79
80 exclude_file_name_regexp--sc_prohibit_magic_number_exit = src/windows-cmdline-wrapper.c
81
82 exclude_file_name_regexp--sc_makefile_at_at_check = data/Makefile.am
+0
-806
build-aux/maint.mk less more
0 # -*-Makefile-*-
1 # This Makefile fragment tries to be general-purpose enough to be
2 # used by many projects via the gnulib maintainer-makefile module.
3
4 ## Copyright (C) 2001-2011 Free Software Foundation, Inc.
5 ##
6 ## This program is free software: you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation, either version 3 of the License, or
9 ## (at your option) any later version.
10 ##
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
15 ##
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 # This is reported not to work with make-3.79.1
20 # ME := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
21 ME := $(_build-aux)/maint.mk
22
23 GIT = git
24 VC = $(GIT)
25
26 VC_LIST = $(srcdir)/$(_build-aux)/vc-list-files -C $(srcdir)
27
28 # You can override this variable in cfg.mk to set your own regexp
29 # matching files to ignore.
30 VC_LIST_ALWAYS_EXCLUDE_REGEX ?= ^$$
31
32 # This is to preprocess robustly the output of $(VC_LIST), so that even
33 # when $(srcdir) is a pathological name like "....", the leading sed command
34 # removes only the intended prefix.
35 _dot_escaped_srcdir = $(subst .,\.,$(srcdir))
36
37 # Post-process $(VC_LIST) output, prepending $(srcdir)/, but only
38 # when $(srcdir) is not ".".
39 ifeq ($(srcdir),.)
40 _prepend_srcdir_prefix =
41 else
42 _prepend_srcdir_prefix = | sed 's|^|$(srcdir)/|'
43 endif
44
45 # In order to be able to consistently filter "."-relative names,
46 # (i.e., with no $(srcdir) prefix), this definition is careful to
47 # remove any $(srcdir) prefix, and to restore what it removes.
48 _sc_excl = \
49 $(if $(exclude_file_name_regexp--$@),$(exclude_file_name_regexp--$@),^$$)
50 VC_LIST_EXCEPT = \
51 $(VC_LIST) | sed 's|^$(_dot_escaped_srcdir)/||' \
52 | if test -f $(srcdir)/.x-$@; then grep -vEf $(srcdir)/.x-$@; \
53 else grep -Ev -e "$${VC_LIST_EXCEPT_DEFAULT-ChangeLog}"; fi \
54 | grep -Ev -e '($(VC_LIST_ALWAYS_EXCLUDE_REGEX)|$(_sc_excl))' \
55 $(_prepend_srcdir_prefix)
56
57 my_distdir = $(PACKAGE)-$(VERSION)
58
59 # Prevent programs like 'sort' from considering distinct strings to be equal.
60 # Doing it here saves us from having to set LC_ALL elsewhere in this file.
61 export LC_ALL = C
62
63 ## --------------- ##
64 ## Sanity checks. ##
65 ## --------------- ##
66
67 _cfg_mk := $(shell test -f $(srcdir)/$(_build-aux)/cfg.mk && echo '$(srcdir)/$(_build-aux)/cfg.mk')
68
69 # Collect the names of rules starting with `sc_'.
70 syntax-check-rules := $(sort $(shell sed -n 's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' \
71 $(srcdir)/$(ME) $(_cfg_mk)))
72 .PHONY: $(syntax-check-rules)
73
74 ifeq ($(shell $(VC_LIST) >/dev/null 2>&1; echo $$?),0)
75 local-checks-available += $(syntax-check-rules)
76 else
77 local-checks-available += no-vc-detected
78 no-vc-detected:
79 @echo "No version control files detected; skipping syntax check"
80 endif
81 .PHONY: $(local-checks-available)
82
83 # Arrange to print the name of each syntax-checking rule just before running it.
84 $(syntax-check-rules): %: %.m
85 sc_m_rules_ = $(patsubst %, %.m, $(syntax-check-rules))
86 .PHONY: $(sc_m_rules_)
87 $(sc_m_rules_):
88 @echo $(patsubst sc_%.m, %, $@)
89 @date +%s.%N > .sc-start-$(basename $@)
90
91 # Compute and print the elapsed time for each syntax-check rule.
92 sc_z_rules_ = $(patsubst %, %.z, $(syntax-check-rules))
93 .PHONY: $(sc_z_rules_)
94 $(sc_z_rules_): %.z: %
95 @end=$$(date +%s.%N); \
96 start=$$(cat .sc-start-$*); \
97 rm -f .sc-start-$*; \
98 awk -v s=$$start -v e=$$end \
99 'END {printf "%.2f $(patsubst sc_%,%,$*)\n", e - s}' < /dev/null
100
101 # The patsubst here is to replace each sc_% rule with its sc_%.z wrapper
102 # that computes and prints elapsed time.
103 local-check := \
104 $(patsubst sc_%, sc_%.z, \
105 $(filter-out $(local-checks-to-skip), $(local-checks-available)))
106
107 syntax-check: $(local-check)
108
109 # _sc_search_regexp
110 #
111 # This macro searches for a given construct in the selected files and
112 # then takes some action.
113 #
114 # Parameters (shell variables):
115 #
116 # prohibit | require
117 #
118 # Regular expression (ERE) denoting either a forbidden construct
119 # or a required construct. Those arguments are exclusive.
120 #
121 # in_vc_files | in_files
122 #
123 # grep-E-style regexp denoting the files to check. If no files
124 # are specified the default are all the files that are under
125 # version control.
126 #
127 # containing | non_containing
128 #
129 # Select the files (non) containing strings matching this regexp.
130 # If both arguments are specified then CONTAINING takes
131 # precedence.
132 #
133 # with_grep_options
134 #
135 # Extra options for grep.
136 #
137 # ignore_case
138 #
139 # Ignore case.
140 #
141 # halt
142 #
143 # Message to display before to halting execution.
144 #
145 # Finally, you may exempt files based on an ERE matching file names.
146 # For example, to exempt from the sc_space_tab check all files with the
147 # .diff suffix, set this Make variable:
148 #
149 # exclude_file_name_regexp--sc_space_tab = \.diff$
150 #
151 # Note that while this functionality is mostly inherited via VC_LIST_EXCEPT,
152 # when filtering by name via in_files, we explicitly filter out matching
153 # names here as well.
154
155 # By default, _sc_search_regexp does not ignore case.
156 export ignore_case =
157 _ignore_case = $$(test -n "$$ignore_case" && printf %s -i || :)
158
159 define _sc_say_and_exit
160 dummy=; : so we do not need a semicolon before each use; \
161 { printf '%s\n' "$(ME): $$msg" 1>&2; exit 1; };
162 endef
163
164 # _sc_search_regexp used to be named _prohibit_regexp. However,
165 # upgrading to the new definition and leaving the old name undefined
166 # would usually convert each custom rule using $(_prohibit_regexp)
167 # (usually defined in cfg.mk) into a no-op. This definition ensures
168 # that people know right away if they're still using the old name.
169 # FIXME: remove in 2012.
170 _prohibit_regexp = \
171 $(error '*** you need to s/_prohibit_regexp/_sc_search_regexp/, and adapt')
172
173 define _sc_search_regexp
174 dummy=; : so we do not need a semicolon before each use; \
175 \
176 : Check arguments; \
177 test -n "$$prohibit" && test -n "$$require" \
178 && { msg='Cannot specify both prohibit and require' \
179 $(_sc_say_and_exit) } || :; \
180 test -z "$$prohibit" && test -z "$$require" \
181 && { msg='Should specify either prohibit or require' \
182 $(_sc_say_and_exit) } || :; \
183 test -n "$$in_vc_files" && test -n "$$in_files" \
184 && { msg='Cannot specify both in_vc_files and in_files' \
185 $(_sc_say_and_exit) } || :; \
186 test "x$$halt" != x \
187 || { msg='halt not defined' $(_sc_say_and_exit) }; \
188 \
189 : Filter by file name; \
190 if test -n "$$in_files"; then \
191 files=$$(find $(srcdir) | grep -E "$$in_files" \
192 | grep -Ev '$(exclude_file_name_regexp--$@)'); \
193 else \
194 files=$$($(VC_LIST_EXCEPT)); \
195 if test -n "$$in_vc_files"; then \
196 files=$$(echo "$$files" | grep -E "$$in_vc_files"); \
197 fi; \
198 fi; \
199 \
200 : Filter by content; \
201 test -n "$$files" && test -n "$$containing" \
202 && { files=$$(grep -l "$$containing" $$files); } || :; \
203 test -n "$$files" && test -n "$$non_containing" \
204 && { files=$$(grep -vl "$$non_containing" $$files); } || :; \
205 \
206 : Check for the construct; \
207 if test -n "$$files"; then \
208 if test -n "$$prohibit"; then \
209 grep $$with_grep_options $(_ignore_case) -nE "$$prohibit" $$files \
210 && { msg="$$halt" $(_sc_say_and_exit) } || :; \
211 else \
212 grep $$with_grep_options $(_ignore_case) -LE "$$require" $$files \
213 | grep . \
214 && { msg="$$halt" $(_sc_say_and_exit) } || :; \
215 fi \
216 else :; \
217 fi || :;
218 endef
219
220 sc_avoid_if_before_free:
221 @$(srcdir)/$(_build-aux)/useless-if-before-free \
222 $(useless_free_options) \
223 $$($(VC_LIST_EXCEPT) | grep -v useless-if-before-free) && \
224 { echo '$(ME): found useless "if" before "free" above' 1>&2; \
225 exit 1; } || :
226
227 sc_cast_of_argument_to_free:
228 @prohibit='\<free *\( *\(' halt='don'\''t cast free argument' \
229 $(_sc_search_regexp)
230
231 sc_cast_of_x_alloc_return_value:
232 @prohibit='\*\) *x(m|c|re)alloc\>' \
233 halt='don'\''t cast x*alloc return value' \
234 $(_sc_search_regexp)
235
236 # Use STREQ rather than comparing strcmp == 0, or != 0.
237 sc_prohibit_strcmp:
238 @grep -nE '! *str''cmp *\(|\<str''cmp *\(.+\) *[!=]=' \
239 $$($(VC_LIST_EXCEPT)) \
240 | grep -vE ':# *define STRN?EQ\(' && \
241 { echo '$(ME): replace str''cmp calls above with STREQ/STRNEQ' \
242 1>&2; exit 1; } || :
243
244 # Pass EXIT_*, not number, to usage, exit, and error (when exiting)
245 # Convert all uses automatically, via these two commands:
246 # git grep -l '\<exit *(1)' \
247 # | grep -vEf .x-sc_prohibit_magic_number_exit \
248 # | xargs --no-run-if-empty \
249 # perl -pi -e 's/(^|[^.])\b(exit ?)\(1\)/$1$2(EXIT_FAILURE)/'
250 # git grep -l '\<exit *(0)' \
251 # | grep -vEf .x-sc_prohibit_magic_number_exit \
252 # | xargs --no-run-if-empty \
253 # perl -pi -e 's/(^|[^.])\b(exit ?)\(0\)/$1$2(EXIT_SUCCESS)/'
254 sc_prohibit_magic_number_exit:
255 @prohibit='(^|[^.])\<(usage|exit) ?\([0-9]|\<error ?\([1-9][0-9]*,' \
256 halt='use EXIT_* values rather than magic number' \
257 $(_sc_search_regexp)
258
259 # `FATAL:' should be fully upper-cased in error messages
260 # `WARNING:' should be fully upper-cased, or fully lower-cased
261 sc_error_message_warn_fatal:
262 @grep -nEA2 '[^rp]error *\(' $$($(VC_LIST_EXCEPT)) \
263 | grep -E '"Warning|"Fatal|"fatal' && \
264 { echo '$(ME): use FATAL, WARNING or warning' 1>&2; \
265 exit 1; } || :
266
267 # Error messages should not end with a period
268 sc_error_message_period:
269 @grep -nEA2 '[^rp]error *\(' $$($(VC_LIST_EXCEPT)) \
270 | grep -E '[^."]\."' && \
271 { echo '$(ME): found error message ending in period' 1>&2; \
272 exit 1; } || :
273
274 # Don't use cpp tests of this symbol. All code assumes config.h is included.
275 sc_prohibit_have_config_h:
276 @prohibit='^# *if.*HAVE''_CONFIG_H' \
277 halt='found use of HAVE''_CONFIG_H; remove' \
278 $(_sc_search_regexp)
279
280 # Nearly all .c files must include <config.h>. However, we also permit this
281 # via inclusion of a package-specific header, if cfg.mk specified one.
282 # config_h_header must be suitable for grep -E.
283 config_h_header ?= <config\.h>
284 sc_require_config_h:
285 @require='^# *include $(config_h_header)' \
286 in_vc_files='\.c$$' \
287 halt='the above files do not include <config.h>' \
288 $(_sc_search_regexp)
289
290 # You must include <config.h> before including any other header file.
291 # This can possibly be via a package-specific header, if given by cfg.mk.
292 sc_require_config_h_first:
293 @if $(VC_LIST_EXCEPT) | grep -l '\.c$$' > /dev/null; then \
294 fail=0; \
295 for i in $$($(VC_LIST_EXCEPT) | grep '\.c$$'); do \
296 grep '^# *include\>' $$i | sed 1q \
297 | grep -E '^# *include $(config_h_header)' > /dev/null \
298 || { echo $$i; fail=1; }; \
299 done; \
300 test $$fail = 1 && \
301 { echo '$(ME): the above files include some other header' \
302 'before <config.h>' 1>&2; exit 1; } || :; \
303 else :; \
304 fi
305
306 sc_prohibit_HAVE_MBRTOWC:
307 @prohibit='\bHAVE_MBRTOWC\b' \
308 halt="do not use $$prohibit; it is always defined" \
309 $(_sc_search_regexp)
310
311 # To use this "command" macro, you must first define two shell variables:
312 # h: the header name, with no enclosing <> or ""
313 # re: a regular expression that matches IFF something provided by $h is used.
314 define _sc_header_without_use
315 dummy=; : so we do not need a semicolon before each use; \
316 h_esc=`echo '[<"]'"$$h"'[">]'|sed 's/\./\\\\./g'`; \
317 if $(VC_LIST_EXCEPT) | grep -l '\.c$$' > /dev/null; then \
318 files=$$(grep -l '^# *include '"$$h_esc" \
319 $$($(VC_LIST_EXCEPT) | grep '\.c$$')) && \
320 grep -LE "$$re" $$files | grep . && \
321 { echo "$(ME): the above files include $$h but don't use it" \
322 1>&2; exit 1; } || :; \
323 else :; \
324 fi
325 endef
326
327 # Prohibit the inclusion of assert.h without an actual use of assert.
328 sc_prohibit_assert_without_use:
329 @h='assert.h' re='\<assert *\(' $(_sc_header_without_use)
330
331 # Prohibit the inclusion of close-stream.h without an actual use.
332 sc_prohibit_close_stream_without_use:
333 @h='close-stream.h' re='\<close_stream *\(' $(_sc_header_without_use)
334
335 # Prohibit the inclusion of getopt.h without an actual use.
336 sc_prohibit_getopt_without_use:
337 @h='getopt.h' re='\<getopt(_long)? *\(' $(_sc_header_without_use)
338
339 # Don't include this header unless you use one of its functions.
340 sc_prohibit_long_options_without_use:
341 @h='long-options.h' re='\<parse_long_options *\(' \
342 $(_sc_header_without_use)
343
344 # Don't include this header unless you use one of its functions.
345 sc_prohibit_inttostr_without_use:
346 @h='inttostr.h' re='\<(off|[iu]max|uint)tostr *\(' \
347 $(_sc_header_without_use)
348
349 # Don't include this header unless you use one of its functions.
350 sc_prohibit_ignore_value_without_use:
351 @h='ignore-value.h' re='\<ignore_(value|ptr) *\(' \
352 $(_sc_header_without_use)
353
354 # Don't include this header unless you use one of its functions.
355 sc_prohibit_error_without_use:
356 @h='error.h' \
357 re='\<error(_at_line|_print_progname|_one_per_line|_message_count)? *\('\
358 $(_sc_header_without_use)
359
360 # Don't include xalloc.h unless you use one of its functions.
361 # Consider these symbols:
362 # perl -lne '/^# *define (\w+)\(/ and print $1' lib/xalloc.h|grep -v '^__';
363 # perl -lne '/^(?:extern )?(?:void|char) \*?(\w+) *\(/ and print $1' lib/xalloc.h
364 # Divide into two sets on case, and filter each through this:
365 # | sort | perl -MRegexp::Assemble -le \
366 # 'print Regexp::Assemble->new(file => "/dev/stdin")->as_string'|sed 's/\?://g'
367 # Note this was produced by the above:
368 # _xa1 = \
369 #x(((2n?)?re|c(har)?|n(re|m)|z)alloc|alloc_(oversized|die)|m(alloc|emdup)|strdup)
370 # But we can do better, in at least two ways:
371 # 1) take advantage of two "dup"-suffixed strings:
372 # x(((2n?)?re|c(har)?|n(re|m)|[mz])alloc|alloc_(oversized|die)|(mem|str)dup)
373 # 2) notice that "c(har)?|[mz]" is equivalent to the shorter and more readable
374 # "char|[cmz]"
375 # x(((2n?)?re|char|n(re|m)|[cmz])alloc|alloc_(oversized|die)|(mem|str)dup)
376 _xa1 = x(((2n?)?re|char|n(re|m)|[cmz])alloc|alloc_(oversized|die)|(mem|str)dup)
377 _xa2 = X([CZ]|N?M)ALLOC
378 sc_prohibit_xalloc_without_use:
379 @h='xalloc.h' \
380 re='\<($(_xa1)|$(_xa2)) *\('\
381 $(_sc_header_without_use)
382
383 sc_prohibit_cloexec_without_use:
384 @h='cloexec.h' re='\<(set_cloexec_flag|dup_cloexec) *\(' \
385 $(_sc_header_without_use)
386
387 sc_prohibit_posixver_without_use:
388 @h='posixver.h' re='\<posix2_version *\(' $(_sc_header_without_use)
389
390 sc_prohibit_same_without_use:
391 @h='same.h' re='\<same_name *\(' $(_sc_header_without_use)
392
393 sc_prohibit_hash_pjw_without_use:
394 @h='hash-pjw.h' \
395 re='\<hash_pjw *\(' \
396 $(_sc_header_without_use)
397
398 sc_prohibit_safe_read_without_use:
399 @h='safe-read.h' re='(\<SAFE_READ_ERROR\>|\<safe_read *\()' \
400 $(_sc_header_without_use)
401
402 sc_prohibit_argmatch_without_use:
403 @h='argmatch.h' \
404 re='(\<(ARRAY_CARDINALITY|X?ARGMATCH(|_TO_ARGUMENT|_VERIFY))\>|\<(invalid_arg|argmatch(_exit_fn|_(in)?valid)?) *\()' \
405 $(_sc_header_without_use)
406
407 sc_prohibit_canonicalize_without_use:
408 @h='canonicalize.h' \
409 re='CAN_(EXISTING|ALL_BUT_LAST|MISSING)|canonicalize_(mode_t|filename_mode)' \
410 $(_sc_header_without_use)
411
412 sc_prohibit_root_dev_ino_without_use:
413 @h='root-dev-ino.h' \
414 re='(\<ROOT_DEV_INO_(CHECK|WARN)\>|\<get_root_dev_ino *\()' \
415 $(_sc_header_without_use)
416
417 sc_prohibit_openat_without_use:
418 @h='openat.h' \
419 re='\<(openat_(permissive|needs_fchdir|(save|restore)_fail)|l?(stat|ch(own|mod))at|(euid)?accessat)\>' \
420 $(_sc_header_without_use)
421
422 # Prohibit the inclusion of c-ctype.h without an actual use.
423 ctype_re = isalnum|isalpha|isascii|isblank|iscntrl|isdigit|isgraph|islower\
424 |isprint|ispunct|isspace|isupper|isxdigit|tolower|toupper
425 sc_prohibit_c_ctype_without_use:
426 @h='c-ctype.h' re='\<c_($(ctype_re)) *\(' \
427 $(_sc_header_without_use)
428
429 _empty =
430 _sp = $(_empty) $(_empty)
431 # The following list was generated by running:
432 # man signal.h|col -b|perl -ne '/bsd_signal.*;/.../sigwaitinfo.*;/ and print' \
433 # | perl -lne '/^\s+(?:int|void).*?(\w+).*/ and print $1' | fmt
434 _sig_functions = \
435 bsd_signal kill killpg pthread_kill pthread_sigmask raise sigaction \
436 sigaddset sigaltstack sigdelset sigemptyset sigfillset sighold sigignore \
437 siginterrupt sigismember signal sigpause sigpending sigprocmask sigqueue \
438 sigrelse sigset sigsuspend sigtimedwait sigwait sigwaitinfo
439 _sig_function_re = $(subst $(_sp),|,$(strip $(_sig_functions)))
440 # The following were extracted from "man signal.h" manually.
441 _sig_types_and_consts = \
442 MINSIGSTKSZ SA_NOCLDSTOP SA_NOCLDWAIT SA_NODEFER SA_ONSTACK \
443 SA_RESETHAND SA_RESTART SA_SIGINFO SIGEV_NONE SIGEV_SIGNAL \
444 SIGEV_THREAD SIGSTKSZ SIG_BLOCK SIG_SETMASK SIG_UNBLOCK SS_DISABLE \
445 SS_ONSTACK mcontext_t pid_t sig_atomic_t sigevent siginfo_t sigset_t \
446 sigstack sigval stack_t ucontext_t
447 # generated via this:
448 # perl -lne '/^#ifdef (SIG\w+)/ and print $1' lib/sig2str.c|sort -u|fmt -70
449 _sig_names = \
450 SIGABRT SIGALRM SIGALRM1 SIGBUS SIGCANCEL SIGCHLD SIGCLD SIGCONT \
451 SIGDANGER SIGDIL SIGEMT SIGFPE SIGFREEZE SIGGRANT SIGHUP SIGILL \
452 SIGINFO SIGINT SIGIO SIGIOT SIGKAP SIGKILL SIGKILLTHR SIGLOST SIGLWP \
453 SIGMIGRATE SIGMSG SIGPHONE SIGPIPE SIGPOLL SIGPRE SIGPROF SIGPWR \
454 SIGQUIT SIGRETRACT SIGSAK SIGSEGV SIGSOUND SIGSTKFLT SIGSTOP SIGSYS \
455 SIGTERM SIGTHAW SIGTRAP SIGTSTP SIGTTIN SIGTTOU SIGURG SIGUSR1 \
456 SIGUSR2 SIGVIRT SIGVTALRM SIGWAITING SIGWINCH SIGWIND SIGWINDOW \
457 SIGXCPU SIGXFSZ
458 _sig_syms_re = $(subst $(_sp),|,$(strip $(_sig_names) $(_sig_types_and_consts)))
459
460 # Prohibit the inclusion of signal.h without an actual use.
461 sc_prohibit_signal_without_use:
462 @h='signal.h' \
463 re='\<($(_sig_function_re)) *\(|\<($(_sig_syms_re))\>' \
464 $(_sc_header_without_use)
465
466 # Don't include stdio--.h unless you use one of its functions.
467 sc_prohibit_stdio--_without_use:
468 @h='stdio--.h' re='\<((f(re)?|p)open|tmpfile) *\(' \
469 $(_sc_header_without_use)
470
471 # Don't include stdio-safer.h unless you use one of its functions.
472 sc_prohibit_stdio-safer_without_use:
473 @h='stdio-safer.h' re='\<((f(re)?|p)open|tmpfile)_safer *\(' \
474 $(_sc_header_without_use)
475
476 # Prohibit the inclusion of strings.h without a sensible use.
477 # Using the likes of bcmp, bcopy, bzero, index or rindex is not sensible.
478 sc_prohibit_strings_without_use:
479 @h='strings.h' \
480 re='\<(strn?casecmp|ffs(ll)?)\>' \
481 $(_sc_header_without_use)
482
483 # Get the list of symbol names with this:
484 # perl -lne '/^# *define ([A-Z]\w+)\(/ and print $1' lib/intprops.h|fmt
485 _intprops_names = \
486 TYPE_IS_INTEGER TYPE_TWOS_COMPLEMENT TYPE_ONES_COMPLEMENT \
487 TYPE_SIGNED_MAGNITUDE TYPE_SIGNED TYPE_MINIMUM TYPE_MAXIMUM \
488 INT_BITS_STRLEN_BOUND INT_STRLEN_BOUND INT_BUFSIZE_BOUND \
489 INT_ADD_RANGE_OVERFLOW INT_SUBTRACT_RANGE_OVERFLOW \
490 INT_NEGATE_RANGE_OVERFLOW INT_MULTIPLY_RANGE_OVERFLOW \
491 INT_DIVIDE_RANGE_OVERFLOW INT_REMAINDER_RANGE_OVERFLOW \
492 INT_LEFT_SHIFT_RANGE_OVERFLOW INT_ADD_OVERFLOW INT_SUBTRACT_OVERFLOW \
493 INT_NEGATE_OVERFLOW INT_MULTIPLY_OVERFLOW INT_DIVIDE_OVERFLOW \
494 INT_REMAINDER_OVERFLOW INT_LEFT_SHIFT_OVERFLOW
495 _intprops_syms_re = $(subst $(_sp),|,$(strip $(_intprops_names)))
496 # Prohibit the inclusion of intprops.h without an actual use.
497 sc_prohibit_intprops_without_use:
498 @h='intprops.h' \
499 re='\<($(_intprops_syms_re)) *\(' \
500 $(_sc_header_without_use)
501
502 _stddef_syms_re = NULL|offsetof|ptrdiff_t|size_t|wchar_t
503 # Prohibit the inclusion of stddef.h without an actual use.
504 sc_prohibit_stddef_without_use:
505 @h='stddef.h' \
506 re='\<($(_stddef_syms_re))\>' \
507 $(_sc_header_without_use)
508
509 _de1 = dirfd|(close|(fd)?open|read|rewind|seek|tell)dir(64)?(_r)?
510 _de2 = (versionsort|struct dirent|getdirentries|alphasort|scandir(at)?)(64)?
511 _de3 = MAXNAMLEN|DIR|ino_t|d_ino|d_fileno|d_namlen
512 _dirent_syms_re = $(_de1)|$(_de2)|$(_de3)
513 # Prohibit the inclusion of dirent.h without an actual use.
514 sc_prohibit_dirent_without_use:
515 @h='dirent.h' \
516 re='\<($(_dirent_syms_re))\>' \
517 $(_sc_header_without_use)
518
519 # Prohibit the inclusion of verify.h without an actual use.
520 sc_prohibit_verify_without_use:
521 @h='verify.h' \
522 re='\<(verify(true|expr)?|static_assert) *\(' \
523 $(_sc_header_without_use)
524
525 # Don't include xfreopen.h unless you use one of its functions.
526 sc_prohibit_xfreopen_without_use:
527 @h='xfreopen.h' re='\<xfreopen *\(' $(_sc_header_without_use)
528
529 # Each nonempty ChangeLog line must start with a year number, or a TAB.
530 sc_changelog:
531 @prohibit='^[^12 ]' \
532 in_vc_files='^ChangeLog$$' \
533 halt='found unexpected prefix in a ChangeLog' \
534 $(_sc_search_regexp)
535
536 sc_trailing_blank:
537 @prohibit='[ ]$$' \
538 halt='found trailing blank(s)' \
539 $(_sc_search_regexp)
540
541 # A regexp matching function names like "error" that may be used
542 # to emit translatable messages.
543 _gl_translatable_diag_func_re ?= error
544
545 # Look for diagnostics that aren't marked for translation.
546 # This won't find any for which error's format string is on a separate line.
547 sc_unmarked_diagnostics:
548 @grep -nE \
549 '\<$(_gl_translatable_diag_func_re) *\([^"]*"[^"]*[a-z]{3}' \
550 $$($(VC_LIST_EXCEPT)) \
551 | grep -Ev '(_|ngettext ?)\(' && \
552 { echo '$(ME): found unmarked diagnostic(s)' 1>&2; \
553 exit 1; } || :
554
555 # Prohibit checked in backup files.
556 sc_prohibit_backup_files:
557 @$(VC_LIST) | grep '~$$' && \
558 { echo '$(ME): found version controlled backup file' 1>&2; \
559 exit 1; } || :
560
561 # Require the latest GFDL. Two regexp, since some .texi files end up
562 # line wrapping between 'Free Documentation License,' and 'Version'.
563 _GFDL_regexp = (Free ''Documentation.*Version 1\.[^3]|Version 1\.[^3] or any)
564 sc_GFDL_version:
565 @prohibit='$(_GFDL_regexp)' \
566 halt='GFDL vN, N!=3' \
567 $(_sc_search_regexp)
568
569 # This Perl code is slightly obfuscated. Not only is each "$" doubled
570 # because it's in a Makefile, but the $$c's are comments; we cannot
571 # use "#" due to the way the script ends up concatenated onto one line.
572 # It would be much more concise, and would produce better output (including
573 # counts) if written as:
574 # perl -ln -0777 -e '/\n(\n+)$/ and print "$ARGV: ".length $1' ...
575 # but that would be far less efficient, reading the entire contents
576 # of each file, rather than just the last two bytes of each.
577 # In addition, while the code below detects both blank lines and a missing
578 # newline at EOF, the above detects only the former.
579 #
580 # This is a perl script that is expected to be the single-quoted argument
581 # to a command-line "-le". The remaining arguments are file names.
582 # Print the name of each file that ends in exactly one newline byte.
583 # I.e., warn if there are blank lines (2 or more newlines), or if the
584 # last byte is not a newline. However, currently we don't complain
585 # about any file that contains exactly one byte.
586 # Exit nonzero if at least one such file is found, otherwise, exit 0.
587 # Warn about, but otherwise ignore open failure. Ignore seek/read failure.
588 #
589 # Use this if you want to remove trailing empty lines from selected files:
590 # perl -pi -0777 -e 's/\n\n+$/\n/' files...
591 #
592 require_exactly_one_NL_at_EOF_ = \
593 foreach my $$f (@ARGV) \
594 { \
595 open F, "<", $$f or (warn "failed to open $$f: $$!\n"), next; \
596 my $$p = sysseek (F, -2, 2); \
597 my $$c = "seek failure probably means file has < 2 bytes; ignore"; \
598 my $$last_two_bytes; \
599 defined $$p and $$p = sysread F, $$last_two_bytes, 2; \
600 close F; \
601 $$c = "ignore read failure"; \
602 $$p && ($$last_two_bytes eq "\n\n" \
603 || substr ($$last_two_bytes,1) ne "\n") \
604 and (print $$f), $$fail=1; \
605 } \
606 END { exit defined $$fail }
607 sc_prohibit_empty_lines_at_EOF:
608 @perl -le '$(require_exactly_one_NL_at_EOF_)' $$($(VC_LIST_EXCEPT)) \
609 || { echo '$(ME): empty line(s) or no newline at EOF' \
610 1>&2; exit 1; } || :
611
612 # Perl block to convert a match to FILE_NAME:LINENO:TEST,
613 # that is shared by two definitions below.
614 perl_filename_lineno_text_ = \
615 -e ' {' \
616 -e ' $$n = ($$` =~ tr/\n/\n/ + 1);' \
617 -e ' ($$v = $$&) =~ s/\n/\\n/g;' \
618 -e ' print "$$ARGV:$$n:$$v\n";' \
619 -e ' }'
620
621 prohibit_doubled_word_RE_ ?= \
622 /\b(then?|[iao]n|i[fst]|but|f?or|at|and|[dt]o)\s+\1\b/gims
623 prohibit_doubled_word_ = \
624 -e 'while ($(prohibit_doubled_word_RE_))' \
625 $(perl_filename_lineno_text_)
626
627 # Define this to a regular expression that matches
628 # any filename:dd:match lines you want to ignore.
629 # The default is to ignore no matches.
630 ignore_doubled_word_match_RE_ ?= ^$$
631
632 sc_prohibit_doubled_word:
633 @perl -n -0777 $(prohibit_doubled_word_) $$($(VC_LIST_EXCEPT)) \
634 | grep -vE '$(ignore_doubled_word_match_RE_)' \
635 | grep . && { echo '$(ME): doubled words' 1>&2; exit 1; } || :
636
637 # A regular expression matching undesirable combinations of words like
638 # "can not"; this matches them even when the two words appear on different
639 # lines, but not when there is an intervening delimiter like "#" or "*".
640 prohibit_undesirable_word_seq_RE_ ?= \
641 /\bcan\s+not\b/gims
642 prohibit_undesirable_word_seq_ = \
643 -e 'while ($(prohibit_undesirable_word_seq_RE_))' \
644 $(perl_filename_lineno_text_)
645 # Define this to a regular expression that matches
646 # any filename:dd:match lines you want to ignore.
647 # The default is to ignore no matches.
648 ignore_undesirable_word_sequence_RE_ ?= ^$$
649
650 sc_prohibit_undesirable_word_seq:
651 @perl -n -0777 $(prohibit_undesirable_word_seq_) \
652 $$($(VC_LIST_EXCEPT)) \
653 | grep -vE '$(ignore_undesirable_word_sequence_RE_)' | grep . \
654 && { echo '$(ME): undesirable word sequence' >&2; exit 1; } || :
655
656 _ptm1 = use "test C1 && test C2", not "test C1 -''a C2"
657 _ptm2 = use "test C1 || test C2", not "test C1 -''o C2"
658 # Using test's -a and -o operators is not portable.
659 # We prefer test over [, since the latter is spelled [[ in configure.ac.
660 sc_prohibit_test_minus_ao:
661 @prohibit='(\<test| \[+) .+ -[ao] ' \
662 halt='$(_ptm1); $(_ptm2)' \
663 $(_sc_search_regexp)
664
665 # Avoid a test bashism.
666 sc_prohibit_test_double_equal:
667 @prohibit='(\<test| \[+) .+ == ' \
668 containing='#! */bin/[a-z]*sh' \
669 halt='use "test x = x", not "test x =''= x"' \
670 $(_sc_search_regexp)
671
672 # Each program that uses proper_name_utf8 must link with one of the
673 # ICONV libraries. Otherwise, some ICONV library must appear in LDADD.
674 # The perl -0777 invocation below extracts the possibly-multi-line
675 # definition of LDADD from the appropriate Makefile.am and exits 0
676 # when it contains "ICONV".
677 sc_proper_name_utf8_requires_ICONV:
678 @progs=$$(grep -l 'proper_name_utf8 ''("' $$($(VC_LIST_EXCEPT)));\
679 if test "x$$progs" != x; then \
680 fail=0; \
681 for p in $$progs; do \
682 dir=$$(dirname "$$p"); \
683 perl -0777 \
684 -ne 'exit !(/^LDADD =(.+?[^\\]\n)/ms && $$1 =~ /ICONV/)' \
685 $$dir/Makefile.am && continue; \
686 base=$$(basename "$$p" .c); \
687 grep "$${base}_LDADD.*ICONV)" $$dir/Makefile.am > /dev/null \
688 || { fail=1; echo 1>&2 "$(ME): $$p uses proper_name_utf8"; }; \
689 done; \
690 test $$fail = 1 && \
691 { echo 1>&2 '$(ME): the above do not link with any ICONV library'; \
692 exit 1; } || :; \
693 fi
694
695 # Warn about "c0nst struct Foo const foo[]",
696 # but not about "char const *const foo" or "#define const const".
697 sc_redundant_const:
698 @prohibit='\bconst\b[[:space:][:alnum:]]{2,}\bconst\b' \
699 halt='redundant "const" in declarations' \
700 $(_sc_search_regexp)
701
702 sc_const_long_option:
703 @grep '^ *static.*struct option ' $$($(VC_LIST_EXCEPT)) \
704 | grep -Ev 'const struct option|struct option const' && { \
705 echo 1>&2 '$(ME): add "const" to the above declarations'; \
706 exit 1; } || :
707
708 # Ensure that we use only the standard $(VAR) notation,
709 # not @...@ in Makefile.am, now that we can rely on automake
710 # to emit a definition for each substituted variable.
711 # However, there is still one case in which @VAR@ use is not just
712 # legitimate, but actually required: when augmenting an automake-defined
713 # variable with a prefix. For example, gettext uses this:
714 # MAKEINFO = env LANG= LC_MESSAGES= LC_ALL= LANGUAGE= @MAKEINFO@
715 # otherwise, makeinfo would put German or French (current locale)
716 # navigation hints in the otherwise-English documentation.
717 #
718 # Allow the package to add exceptions via a hook in cfg.mk;
719 # for example, @PRAGMA_SYSTEM_HEADER@ can be permitted by
720 # setting this to ' && !/PRAGMA_SYSTEM_HEADER/'.
721 _makefile_at_at_check_exceptions ?=
722 sc_makefile_at_at_check:
723 @perl -ne '/\@[A-Z_0-9]+\@/' \
724 -e ' && !/([A-Z_0-9]+)\s+=.*\@\1\@$$/' \
725 -e ''$(_makefile_at_at_check_exceptions) \
726 -e 'and (print "$$ARGV:$$.: $$_"), $$m=1; END {exit !$$m}' \
727 $$($(VC_LIST_EXCEPT) | grep -E '(^|/)(Makefile\.am|[^/]+\.mk)$$') \
728 && { echo '$(ME): use $$(...), not @...@' 1>&2; exit 1; } || :
729
730 sc_makefile_TAB_only_indentation:
731 @prohibit='^ [ ]{8}' \
732 in_vc_files='akefile|\.mk$$' \
733 halt='found TAB-8-space indentation' \
734 $(_sc_search_regexp)
735
736 sc_m4_quote_check:
737 @prohibit='(AC_DEFINE(_UNQUOTED)?|AC_DEFUN)\([^[]' \
738 in_vc_files='(^configure\.ac|\.m4)$$' \
739 halt='quote the first arg to AC_DEF*' \
740 $(_sc_search_regexp)
741
742 fix_po_file_diag = \
743 'you have changed the set of files with translatable diagnostics;\n\
744 apply the above patch\n'
745
746 # Verify that all source files using _() are listed in po/POTFILES.in.
747 po_file ?= $(srcdir)/po/POTFILES.in
748 generated_files ?= $(srcdir)/lib/*.[ch]
749 sc_po_check:
750 @if test -f $(po_file); then \
751 grep -E -v '^(#|$$)' $(po_file) \
752 | grep -v '^src/false\.c$$' \
753 | sed 's|\[type: gettext/glade\] ||' \
754 | sort > $@-1; \
755 files=; \
756 for file in $$($(VC_LIST_EXCEPT)) $(generated_files); do \
757 test -r $$file || continue; \
758 case $$file in \
759 *.m4|*.mk) continue ;; \
760 *.?|*.??) ;; \
761 *.xml) ;; \
762 *.xml.in) ;; \
763 *.desktop.in) ;; \
764 *) continue;; \
765 esac; \
766 case $$file in \
767 *.[ch]) \
768 base=`expr " $$file" : ' \(.*\)\..'`; \
769 { test -f $$base.l || test -f $$base.y; } && continue;; \
770 esac; \
771 files="$$files $$file"; \
772 done; \
773 grep -E -l '(\b(N?_|gettext *)\([^)"]*("|$$))|(<interface>)|^_|<_' $$files \
774 | sed 's|^$(_dot_escaped_srcdir)/||' | sort -u > $@-2; \
775 diff -u -L $(po_file) -L $(po_file) $@-1 $@-2 \
776 || { printf '$(ME): '$(fix_po_file_diag) 1>&2; exit 1; }; \
777 rm -f $@-1 $@-2; \
778 fi
779
780 # #if HAVE_... will evaluate to false for any non numeric string.
781 # That would be flagged by using -Wundef, however gnulib currently
782 # tests many undefined macros, and so we can't enable that option.
783 # So at least preclude common boolean strings as macro values.
784 sc_Wundef_boolean:
785 @prohibit='^#define.*(yes|no|true|false)$$' \
786 in_files='$(CONFIG_INCLUDE)' \
787 halt='Use 0 or 1 for macro values' \
788 $(_sc_search_regexp)
789
790 # Even if you use pathmax.h to guarantee that PATH_MAX is defined, it might
791 # not be constant, or might overflow a stack. In general, use PATH_MAX as
792 # a limit, not an array or alloca size.
793 sc_prohibit_path_max_allocation:
794 @prohibit='(\balloca *\([^)]*|\[[^]]*)PATH_MAX' \
795 halt='Avoid stack allocations of size PATH_MAX' \
796 $(_sc_search_regexp)
797
798 sc_vulnerable_makefile_CVE-2009-4029:
799 @prohibit='perm -777 -exec chmod a\+rwx|chmod 777 \$$\(distdir\)' \
800 in_files=$$(find $(srcdir) -name Makefile.in) \
801 halt=$$(printf '%s\n' \
802 'the above files are vulnerable; beware of running' \
803 ' "make dist*" rules, and upgrade to fixed automake' \
804 ' see http://bugzilla.redhat.com/542609 for details') \
805 $(_sc_search_regexp)
0 # -*-Makefile-*-
1 # This Makefile fragment tries to be general-purpose enough to be
2 # used by many projects via the gnulib maintainer-makefile module.
3
4 ## Copyright (C) 2001-2011 Free Software Foundation, Inc.
5 ## Copyright (C) 2008-2012 Red Hat, Inc.
6 ##
7 ## This program is free software: you can redistribute it and/or modify
8 ## it under the terms of the GNU General Public License as published by
9 ## the Free Software Foundation, either version 3 of the License, or
10 ## (at your option) any later version.
11 ##
12 ## This program is distributed in the hope that it will be useful,
13 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ## GNU General Public License for more details.
16 ##
17 ## You should have received a copy of the GNU General Public License
18 ## along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 # This is reported not to work with make-3.79.1
21 # ME := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
22 ME := $(_build-aux)/syntax-check.mk
23
24 GIT = git
25 VC = $(GIT)
26
27 VC_LIST = $(srcdir)/$(_build-aux)/vc-list-files -C $(srcdir)
28
29 # You can override this variable in syntax-check.mk to set your own regexp
30 # matching files to ignore.
31 VC_LIST_ALWAYS_EXCLUDE_REGEX ?= ^$$
32
33 # This is to preprocess robustly the output of $(VC_LIST), so that even
34 # when $(srcdir) is a pathological name like "....", the leading sed command
35 # removes only the intended prefix.
36 _dot_escaped_srcdir = $(subst .,\.,$(srcdir))
37
38 # Post-process $(VC_LIST) output, prepending $(srcdir)/, but only
39 # when $(srcdir) is not ".".
40 ifeq ($(srcdir),.)
41 _prepend_srcdir_prefix =
42 else
43 _prepend_srcdir_prefix = | sed 's|^|$(srcdir)/|'
44 endif
45
46 # In order to be able to consistently filter "."-relative names,
47 # (i.e., with no $(srcdir) prefix), this definition is careful to
48 # remove any $(srcdir) prefix, and to restore what it removes.
49 _sc_excl = \
50 $(if $(exclude_file_name_regexp--$@),$(exclude_file_name_regexp--$@),^$$)
51 VC_LIST_EXCEPT = \
52 $(VC_LIST) | sed 's|^$(_dot_escaped_srcdir)/||' \
53 | if test -f $(srcdir)/.x-$@; then grep -vEf $(srcdir)/.x-$@; \
54 else grep -Ev -e "$${VC_LIST_EXCEPT_DEFAULT-ChangeLog}"; fi \
55 | grep -Ev -e '($(VC_LIST_ALWAYS_EXCLUDE_REGEX)|$(_sc_excl))' \
56 $(_prepend_srcdir_prefix)
57
58 my_distdir = $(PACKAGE)-$(VERSION)
59
60 # Prevent programs like 'sort' from considering distinct strings to be equal.
61 # Doing it here saves us from having to set LC_ALL elsewhere in this file.
62 export LC_ALL = C
63
64 ## --------------- ##
65 ## Sanity checks. ##
66 ## --------------- ##
67
68 _cfg_mk := $(shell test -f $(srcdir)/$(_build-aux)/syntax-check.mk && echo '$(srcdir)/$(_build-aux)/syntax-check.mk')
69
70 # Collect the names of rules starting with `sc_'.
71 syntax-check-rules := $(sort $(shell sed -n 's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' \
72 $(srcdir)/$(ME) $(_cfg_mk)))
73 .PHONY: $(syntax-check-rules)
74
75 ifeq ($(shell $(VC_LIST) >/dev/null 2>&1; echo $$?),0)
76 local-checks-available += $(syntax-check-rules)
77 else
78 local-checks-available += no-vc-detected
79 no-vc-detected:
80 @echo "No version control files detected; skipping syntax check"
81 endif
82 .PHONY: $(local-checks-available)
83
84 # Arrange to print the name of each syntax-checking rule just before running it.
85 $(syntax-check-rules): %: %.m
86 sc_m_rules_ = $(patsubst %, %.m, $(syntax-check-rules))
87 .PHONY: $(sc_m_rules_)
88 $(sc_m_rules_):
89 @echo $(patsubst sc_%.m, %, $@)
90 @date +%s.%N > .sc-start-$(basename $@)
91
92 # Compute and print the elapsed time for each syntax-check rule.
93 sc_z_rules_ = $(patsubst %, %.z, $(syntax-check-rules))
94 .PHONY: $(sc_z_rules_)
95 $(sc_z_rules_): %.z: %
96 @end=$$(date +%s.%N); \
97 start=$$(cat .sc-start-$*); \
98 rm -f .sc-start-$*; \
99 awk -v s=$$start -v e=$$end \
100 'END {printf "%.2f $(patsubst sc_%,%,$*)\n", e - s}' < /dev/null
101
102 # The patsubst here is to replace each sc_% rule with its sc_%.z wrapper
103 # that computes and prints elapsed time.
104 local-check := \
105 $(patsubst sc_%, sc_%.z, \
106 $(filter-out $(local-checks-to-skip), $(local-checks-available)))
107
108 syntax-check: $(local-check)
109
110 # _sc_search_regexp
111 #
112 # This macro searches for a given construct in the selected files and
113 # then takes some action.
114 #
115 # Parameters (shell variables):
116 #
117 # prohibit | require
118 #
119 # Regular expression (ERE) denoting either a forbidden construct
120 # or a required construct. Those arguments are exclusive.
121 #
122 # in_vc_files | in_files
123 #
124 # grep-E-style regexp denoting the files to check. If no files
125 # are specified the default are all the files that are under
126 # version control.
127 #
128 # containing | non_containing
129 #
130 # Select the files (non) containing strings matching this regexp.
131 # If both arguments are specified then CONTAINING takes
132 # precedence.
133 #
134 # with_grep_options
135 #
136 # Extra options for grep.
137 #
138 # ignore_case
139 #
140 # Ignore case.
141 #
142 # halt
143 #
144 # Message to display before to halting execution.
145 #
146 # Finally, you may exempt files based on an ERE matching file names.
147 # For example, to exempt from the sc_space_tab check all files with the
148 # .diff suffix, set this Make variable:
149 #
150 # exclude_file_name_regexp--sc_space_tab = \.diff$
151 #
152 # Note that while this functionality is mostly inherited via VC_LIST_EXCEPT,
153 # when filtering by name via in_files, we explicitly filter out matching
154 # names here as well.
155
156 # By default, _sc_search_regexp does not ignore case.
157 export ignore_case =
158 _ignore_case = $$(test -n "$$ignore_case" && printf %s -i || :)
159
160 define _sc_say_and_exit
161 dummy=; : so we do not need a semicolon before each use; \
162 { printf '%s\n' "$(ME): $$msg" 1>&2; exit 1; };
163 endef
164
165 # _sc_search_regexp used to be named _prohibit_regexp. However,
166 # upgrading to the new definition and leaving the old name undefined
167 # would usually convert each custom rule using $(_prohibit_regexp)
168 # (usually defined in syntax-check.mk) into a no-op. This definition ensures
169 # that people know right away if they're still using the old name.
170 # FIXME: remove in 2012.
171 _prohibit_regexp = \
172 $(error '*** you need to s/_prohibit_regexp/_sc_search_regexp/, and adapt')
173
174 define _sc_search_regexp
175 dummy=; : so we do not need a semicolon before each use; \
176 \
177 : Check arguments; \
178 test -n "$$prohibit" && test -n "$$require" \
179 && { msg='Cannot specify both prohibit and require' \
180 $(_sc_say_and_exit) } || :; \
181 test -z "$$prohibit" && test -z "$$require" \
182 && { msg='Should specify either prohibit or require' \
183 $(_sc_say_and_exit) } || :; \
184 test -n "$$in_vc_files" && test -n "$$in_files" \
185 && { msg='Cannot specify both in_vc_files and in_files' \
186 $(_sc_say_and_exit) } || :; \
187 test "x$$halt" != x \
188 || { msg='halt not defined' $(_sc_say_and_exit) }; \
189 \
190 : Filter by file name; \
191 if test -n "$$in_files"; then \
192 files=$$(find $(srcdir) | grep -E "$$in_files" \
193 | grep -Ev '$(exclude_file_name_regexp--$@)'); \
194 else \
195 files=$$($(VC_LIST_EXCEPT)); \
196 if test -n "$$in_vc_files"; then \
197 files=$$(echo "$$files" | grep -E "$$in_vc_files"); \
198 fi; \
199 fi; \
200 \
201 : Filter by content; \
202 test -n "$$files" && test -n "$$containing" \
203 && { files=$$(grep -l "$$containing" $$files); } || :; \
204 test -n "$$files" && test -n "$$non_containing" \
205 && { files=$$(grep -vl "$$non_containing" $$files); } || :; \
206 \
207 : Check for the construct; \
208 if test -n "$$files"; then \
209 if test -n "$$prohibit"; then \
210 grep $$with_grep_options $(_ignore_case) -nE "$$prohibit" $$files \
211 && { msg="$$halt" $(_sc_say_and_exit) } || :; \
212 else \
213 grep $$with_grep_options $(_ignore_case) -LE "$$require" $$files \
214 | grep . \
215 && { msg="$$halt" $(_sc_say_and_exit) } || :; \
216 fi \
217 else :; \
218 fi || :;
219 endef
220
221 sc_avoid_if_before_free:
222 @$(srcdir)/$(_build-aux)/useless-if-before-free \
223 $(useless_free_options) \
224 $$($(VC_LIST_EXCEPT) | grep -v useless-if-before-free) && \
225 { echo '$(ME): found useless "if" before "free" above' 1>&2; \
226 exit 1; } || :
227
228 sc_cast_of_argument_to_free:
229 @prohibit='\<free *\( *\(' halt='don'\''t cast free argument' \
230 $(_sc_search_regexp)
231
232 sc_cast_of_x_alloc_return_value:
233 @prohibit='\*\) *x(m|c|re)alloc\>' \
234 halt='don'\''t cast x*alloc return value' \
235 $(_sc_search_regexp)
236
237 # Use STREQ rather than comparing strcmp == 0, or != 0.
238 sc_prohibit_strcmp:
239 @grep -nE '! *str''cmp *\(|\<str''cmp *\(.+\) *[!=]=' \
240 $$($(VC_LIST_EXCEPT)) \
241 | grep -vE ':# *define STRN?EQ\(' && \
242 { echo '$(ME): replace str''cmp calls above with STREQ/STRNEQ' \
243 1>&2; exit 1; } || :
244
245 # Pass EXIT_*, not number, to usage, exit, and error (when exiting)
246 # Convert all uses automatically, via these two commands:
247 # git grep -l '\<exit *(1)' \
248 # | grep -vEf .x-sc_prohibit_magic_number_exit \
249 # | xargs --no-run-if-empty \
250 # perl -pi -e 's/(^|[^.])\b(exit ?)\(1\)/$1$2(EXIT_FAILURE)/'
251 # git grep -l '\<exit *(0)' \
252 # | grep -vEf .x-sc_prohibit_magic_number_exit \
253 # | xargs --no-run-if-empty \
254 # perl -pi -e 's/(^|[^.])\b(exit ?)\(0\)/$1$2(EXIT_SUCCESS)/'
255 sc_prohibit_magic_number_exit:
256 @prohibit='(^|[^.])\<(usage|exit) ?\([0-9]|\<error ?\([1-9][0-9]*,' \
257 halt='use EXIT_* values rather than magic number' \
258 $(_sc_search_regexp)
259
260 # `FATAL:' should be fully upper-cased in error messages
261 # `WARNING:' should be fully upper-cased, or fully lower-cased
262 sc_error_message_warn_fatal:
263 @grep -nEA2 '[^rp]error *\(' $$($(VC_LIST_EXCEPT)) \
264 | grep -E '"Warning|"Fatal|"fatal' && \
265 { echo '$(ME): use FATAL, WARNING or warning' 1>&2; \
266 exit 1; } || :
267
268 # Error messages should not end with a period
269 sc_error_message_period:
270 @grep -nEA2 '[^rp]error *\(' $$($(VC_LIST_EXCEPT)) \
271 | grep -E '[^."]\."' && \
272 { echo '$(ME): found error message ending in period' 1>&2; \
273 exit 1; } || :
274
275 # Don't use cpp tests of this symbol. All code assumes config.h is included.
276 sc_prohibit_have_config_h:
277 @prohibit='^# *if.*HAVE''_CONFIG_H' \
278 halt='found use of HAVE''_CONFIG_H; remove' \
279 $(_sc_search_regexp)
280
281 # Nearly all .c files must include <config.h>. However, we also permit this
282 # via inclusion of a package-specific header, if syntax-check.mk specified one.
283 # config_h_header must be suitable for grep -E.
284 config_h_header ?= <config\.h>
285 sc_require_config_h:
286 @require='^# *include $(config_h_header)' \
287 in_vc_files='\.c$$' \
288 halt='the above files do not include <config.h>' \
289 $(_sc_search_regexp)
290
291 # You must include <config.h> before including any other header file.
292 # This can possibly be via a package-specific header, if given by syntax-check.mk.
293 sc_require_config_h_first:
294 @if $(VC_LIST_EXCEPT) | grep -l '\.c$$' > /dev/null; then \
295 fail=0; \
296 for i in $$($(VC_LIST_EXCEPT) | grep '\.c$$'); do \
297 grep '^# *include\>' $$i | sed 1q \
298 | grep -E '^# *include $(config_h_header)' > /dev/null \
299 || { echo $$i; fail=1; }; \
300 done; \
301 test $$fail = 1 && \
302 { echo '$(ME): the above files include some other header' \
303 'before <config.h>' 1>&2; exit 1; } || :; \
304 else :; \
305 fi
306
307 sc_prohibit_HAVE_MBRTOWC:
308 @prohibit='\bHAVE_MBRTOWC\b' \
309 halt="do not use $$prohibit; it is always defined" \
310 $(_sc_search_regexp)
311
312 # To use this "command" macro, you must first define two shell variables:
313 # h: the header name, with no enclosing <> or ""
314 # re: a regular expression that matches IFF something provided by $h is used.
315 define _sc_header_without_use
316 dummy=; : so we do not need a semicolon before each use; \
317 h_esc=`echo '[<"]'"$$h"'[">]'|sed 's/\./\\\\./g'`; \
318 if $(VC_LIST_EXCEPT) | grep -l '\.c$$' > /dev/null; then \
319 files=$$(grep -l '^# *include '"$$h_esc" \
320 $$($(VC_LIST_EXCEPT) | grep '\.c$$')) && \
321 grep -LE "$$re" $$files | grep . && \
322 { echo "$(ME): the above files include $$h but don't use it" \
323 1>&2; exit 1; } || :; \
324 else :; \
325 fi
326 endef
327
328 # Prohibit the inclusion of assert.h without an actual use of assert.
329 sc_prohibit_assert_without_use:
330 @h='assert.h' re='\<assert *\(' $(_sc_header_without_use)
331
332 # Prohibit the inclusion of close-stream.h without an actual use.
333 sc_prohibit_close_stream_without_use:
334 @h='close-stream.h' re='\<close_stream *\(' $(_sc_header_without_use)
335
336 # Prohibit the inclusion of getopt.h without an actual use.
337 sc_prohibit_getopt_without_use:
338 @h='getopt.h' re='\<getopt(_long)? *\(' $(_sc_header_without_use)
339
340 # Don't include this header unless you use one of its functions.
341 sc_prohibit_long_options_without_use:
342 @h='long-options.h' re='\<parse_long_options *\(' \
343 $(_sc_header_without_use)
344
345 # Don't include this header unless you use one of its functions.
346 sc_prohibit_inttostr_without_use:
347 @h='inttostr.h' re='\<(off|[iu]max|uint)tostr *\(' \
348 $(_sc_header_without_use)
349
350 # Don't include this header unless you use one of its functions.
351 sc_prohibit_ignore_value_without_use:
352 @h='ignore-value.h' re='\<ignore_(value|ptr) *\(' \
353 $(_sc_header_without_use)
354
355 # Don't include this header unless you use one of its functions.
356 sc_prohibit_error_without_use:
357 @h='error.h' \
358 re='\<error(_at_line|_print_progname|_one_per_line|_message_count)? *\('\
359 $(_sc_header_without_use)
360
361 # Don't include xalloc.h unless you use one of its functions.
362 # Consider these symbols:
363 # perl -lne '/^# *define (\w+)\(/ and print $1' lib/xalloc.h|grep -v '^__';
364 # perl -lne '/^(?:extern )?(?:void|char) \*?(\w+) *\(/ and print $1' lib/xalloc.h
365 # Divide into two sets on case, and filter each through this:
366 # | sort | perl -MRegexp::Assemble -le \
367 # 'print Regexp::Assemble->new(file => "/dev/stdin")->as_string'|sed 's/\?://g'
368 # Note this was produced by the above:
369 # _xa1 = \
370 #x(((2n?)?re|c(har)?|n(re|m)|z)alloc|alloc_(oversized|die)|m(alloc|emdup)|strdup)
371 # But we can do better, in at least two ways:
372 # 1) take advantage of two "dup"-suffixed strings:
373 # x(((2n?)?re|c(har)?|n(re|m)|[mz])alloc|alloc_(oversized|die)|(mem|str)dup)
374 # 2) notice that "c(har)?|[mz]" is equivalent to the shorter and more readable
375 # "char|[cmz]"
376 # x(((2n?)?re|char|n(re|m)|[cmz])alloc|alloc_(oversized|die)|(mem|str)dup)
377 _xa1 = x(((2n?)?re|char|n(re|m)|[cmz])alloc|alloc_(oversized|die)|(mem|str)dup)
378 _xa2 = X([CZ]|N?M)ALLOC
379 sc_prohibit_xalloc_without_use:
380 @h='xalloc.h' \
381 re='\<($(_xa1)|$(_xa2)) *\('\
382 $(_sc_header_without_use)
383
384 sc_prohibit_cloexec_without_use:
385 @h='cloexec.h' re='\<(set_cloexec_flag|dup_cloexec) *\(' \
386 $(_sc_header_without_use)
387
388 sc_prohibit_posixver_without_use:
389 @h='posixver.h' re='\<posix2_version *\(' $(_sc_header_without_use)
390
391 sc_prohibit_same_without_use:
392 @h='same.h' re='\<same_name *\(' $(_sc_header_without_use)
393
394 sc_prohibit_hash_pjw_without_use:
395 @h='hash-pjw.h' \
396 re='\<hash_pjw *\(' \
397 $(_sc_header_without_use)
398
399 sc_prohibit_safe_read_without_use:
400 @h='safe-read.h' re='(\<SAFE_READ_ERROR\>|\<safe_read *\()' \
401 $(_sc_header_without_use)
402
403 sc_prohibit_argmatch_without_use:
404 @h='argmatch.h' \
405 re='(\<(ARRAY_CARDINALITY|X?ARGMATCH(|_TO_ARGUMENT|_VERIFY))\>|\<(invalid_arg|argmatch(_exit_fn|_(in)?valid)?) *\()' \
406 $(_sc_header_without_use)
407
408 sc_prohibit_canonicalize_without_use:
409 @h='canonicalize.h' \
410 re='CAN_(EXISTING|ALL_BUT_LAST|MISSING)|canonicalize_(mode_t|filename_mode)' \
411 $(_sc_header_without_use)
412
413 sc_prohibit_root_dev_ino_without_use:
414 @h='root-dev-ino.h' \
415 re='(\<ROOT_DEV_INO_(CHECK|WARN)\>|\<get_root_dev_ino *\()' \
416 $(_sc_header_without_use)
417
418 sc_prohibit_openat_without_use:
419 @h='openat.h' \
420 re='\<(openat_(permissive|needs_fchdir|(save|restore)_fail)|l?(stat|ch(own|mod))at|(euid)?accessat)\>' \
421 $(_sc_header_without_use)
422
423 # Prohibit the inclusion of c-ctype.h without an actual use.
424 ctype_re = isalnum|isalpha|isascii|isblank|iscntrl|isdigit|isgraph|islower\
425 |isprint|ispunct|isspace|isupper|isxdigit|tolower|toupper
426 sc_prohibit_c_ctype_without_use:
427 @h='c-ctype.h' re='\<c_($(ctype_re)) *\(' \
428 $(_sc_header_without_use)
429
430 _empty =
431 _sp = $(_empty) $(_empty)
432 # The following list was generated by running:
433 # man signal.h|col -b|perl -ne '/bsd_signal.*;/.../sigwaitinfo.*;/ and print' \
434 # | perl -lne '/^\s+(?:int|void).*?(\w+).*/ and print $1' | fmt
435 _sig_functions = \
436 bsd_signal kill killpg pthread_kill pthread_sigmask raise sigaction \
437 sigaddset sigaltstack sigdelset sigemptyset sigfillset sighold sigignore \
438 siginterrupt sigismember signal sigpause sigpending sigprocmask sigqueue \
439 sigrelse sigset sigsuspend sigtimedwait sigwait sigwaitinfo
440 _sig_function_re = $(subst $(_sp),|,$(strip $(_sig_functions)))
441 # The following were extracted from "man signal.h" manually.
442 _sig_types_and_consts = \
443 MINSIGSTKSZ SA_NOCLDSTOP SA_NOCLDWAIT SA_NODEFER SA_ONSTACK \
444 SA_RESETHAND SA_RESTART SA_SIGINFO SIGEV_NONE SIGEV_SIGNAL \
445 SIGEV_THREAD SIGSTKSZ SIG_BLOCK SIG_SETMASK SIG_UNBLOCK SS_DISABLE \
446 SS_ONSTACK mcontext_t pid_t sig_atomic_t sigevent siginfo_t sigset_t \
447 sigstack sigval stack_t ucontext_t
448 # generated via this:
449 # perl -lne '/^#ifdef (SIG\w+)/ and print $1' lib/sig2str.c|sort -u|fmt -70
450 _sig_names = \
451 SIGABRT SIGALRM SIGALRM1 SIGBUS SIGCANCEL SIGCHLD SIGCLD SIGCONT \
452 SIGDANGER SIGDIL SIGEMT SIGFPE SIGFREEZE SIGGRANT SIGHUP SIGILL \
453 SIGINFO SIGINT SIGIO SIGIOT SIGKAP SIGKILL SIGKILLTHR SIGLOST SIGLWP \
454 SIGMIGRATE SIGMSG SIGPHONE SIGPIPE SIGPOLL SIGPRE SIGPROF SIGPWR \
455 SIGQUIT SIGRETRACT SIGSAK SIGSEGV SIGSOUND SIGSTKFLT SIGSTOP SIGSYS \
456 SIGTERM SIGTHAW SIGTRAP SIGTSTP SIGTTIN SIGTTOU SIGURG SIGUSR1 \
457 SIGUSR2 SIGVIRT SIGVTALRM SIGWAITING SIGWINCH SIGWIND SIGWINDOW \
458 SIGXCPU SIGXFSZ
459 _sig_syms_re = $(subst $(_sp),|,$(strip $(_sig_names) $(_sig_types_and_consts)))
460
461 # Prohibit the inclusion of signal.h without an actual use.
462 sc_prohibit_signal_without_use:
463 @h='signal.h' \
464 re='\<($(_sig_function_re)) *\(|\<($(_sig_syms_re))\>' \
465 $(_sc_header_without_use)
466
467 # Don't include stdio--.h unless you use one of its functions.
468 sc_prohibit_stdio--_without_use:
469 @h='stdio--.h' re='\<((f(re)?|p)open|tmpfile) *\(' \
470 $(_sc_header_without_use)
471
472 # Don't include stdio-safer.h unless you use one of its functions.
473 sc_prohibit_stdio-safer_without_use:
474 @h='stdio-safer.h' re='\<((f(re)?|p)open|tmpfile)_safer *\(' \
475 $(_sc_header_without_use)
476
477 # Prohibit the inclusion of strings.h without a sensible use.
478 # Using the likes of bcmp, bcopy, bzero, index or rindex is not sensible.
479 sc_prohibit_strings_without_use:
480 @h='strings.h' \
481 re='\<(strn?casecmp|ffs(ll)?)\>' \
482 $(_sc_header_without_use)
483
484 # Get the list of symbol names with this:
485 # perl -lne '/^# *define ([A-Z]\w+)\(/ and print $1' lib/intprops.h|fmt
486 _intprops_names = \
487 TYPE_IS_INTEGER TYPE_TWOS_COMPLEMENT TYPE_ONES_COMPLEMENT \
488 TYPE_SIGNED_MAGNITUDE TYPE_SIGNED TYPE_MINIMUM TYPE_MAXIMUM \
489 INT_BITS_STRLEN_BOUND INT_STRLEN_BOUND INT_BUFSIZE_BOUND \
490 INT_ADD_RANGE_OVERFLOW INT_SUBTRACT_RANGE_OVERFLOW \
491 INT_NEGATE_RANGE_OVERFLOW INT_MULTIPLY_RANGE_OVERFLOW \
492 INT_DIVIDE_RANGE_OVERFLOW INT_REMAINDER_RANGE_OVERFLOW \
493 INT_LEFT_SHIFT_RANGE_OVERFLOW INT_ADD_OVERFLOW INT_SUBTRACT_OVERFLOW \
494 INT_NEGATE_OVERFLOW INT_MULTIPLY_OVERFLOW INT_DIVIDE_OVERFLOW \
495 INT_REMAINDER_OVERFLOW INT_LEFT_SHIFT_OVERFLOW
496 _intprops_syms_re = $(subst $(_sp),|,$(strip $(_intprops_names)))
497 # Prohibit the inclusion of intprops.h without an actual use.
498 sc_prohibit_intprops_without_use:
499 @h='intprops.h' \
500 re='\<($(_intprops_syms_re)) *\(' \
501 $(_sc_header_without_use)
502
503 _stddef_syms_re = NULL|offsetof|ptrdiff_t|size_t|wchar_t
504 # Prohibit the inclusion of stddef.h without an actual use.
505 sc_prohibit_stddef_without_use:
506 @h='stddef.h' \
507 re='\<($(_stddef_syms_re))\>' \
508 $(_sc_header_without_use)
509
510 _de1 = dirfd|(close|(fd)?open|read|rewind|seek|tell)dir(64)?(_r)?
511 _de2 = (versionsort|struct dirent|getdirentries|alphasort|scandir(at)?)(64)?
512 _de3 = MAXNAMLEN|DIR|ino_t|d_ino|d_fileno|d_namlen
513 _dirent_syms_re = $(_de1)|$(_de2)|$(_de3)
514 # Prohibit the inclusion of dirent.h without an actual use.
515 sc_prohibit_dirent_without_use:
516 @h='dirent.h' \
517 re='\<($(_dirent_syms_re))\>' \
518 $(_sc_header_without_use)
519
520 # Prohibit the inclusion of verify.h without an actual use.
521 sc_prohibit_verify_without_use:
522 @h='verify.h' \
523 re='\<(verify(true|expr)?|static_assert) *\(' \
524 $(_sc_header_without_use)
525
526 # Don't include xfreopen.h unless you use one of its functions.
527 sc_prohibit_xfreopen_without_use:
528 @h='xfreopen.h' re='\<xfreopen *\(' $(_sc_header_without_use)
529
530 # Each nonempty ChangeLog line must start with a year number, or a TAB.
531 sc_changelog:
532 @prohibit='^[^12 ]' \
533 in_vc_files='^ChangeLog$$' \
534 halt='found unexpected prefix in a ChangeLog' \
535 $(_sc_search_regexp)
536
537 sc_trailing_blank:
538 @prohibit='[ ]$$' \
539 halt='found trailing blank(s)' \
540 $(_sc_search_regexp)
541
542 # A regexp matching function names like "error" that may be used
543 # to emit translatable messages.
544 _gl_translatable_diag_func_re ?= error
545
546 # Look for diagnostics that aren't marked for translation.
547 # This won't find any for which error's format string is on a separate line.
548 sc_unmarked_diagnostics:
549 @grep -nE \
550 '\<$(_gl_translatable_diag_func_re) *\([^"]*"[^"]*[a-z]{3}' \
551 $$($(VC_LIST_EXCEPT)) \
552 | grep -Ev '(_|ngettext ?)\(' && \
553 { echo '$(ME): found unmarked diagnostic(s)' 1>&2; \
554 exit 1; } || :
555
556 # Prohibit checked in backup files.
557 sc_prohibit_backup_files:
558 @$(VC_LIST) | grep '~$$' && \
559 { echo '$(ME): found version controlled backup file' 1>&2; \
560 exit 1; } || :
561
562 # Require the latest GFDL. Two regexp, since some .texi files end up
563 # line wrapping between 'Free Documentation License,' and 'Version'.
564 _GFDL_regexp = (Free ''Documentation.*Version 1\.[^3]|Version 1\.[^3] or any)
565 sc_GFDL_version:
566 @prohibit='$(_GFDL_regexp)' \
567 halt='GFDL vN, N!=3' \
568 $(_sc_search_regexp)
569
570 # This Perl code is slightly obfuscated. Not only is each "$" doubled
571 # because it's in a Makefile, but the $$c's are comments; we cannot
572 # use "#" due to the way the script ends up concatenated onto one line.
573 # It would be much more concise, and would produce better output (including
574 # counts) if written as:
575 # perl -ln -0777 -e '/\n(\n+)$/ and print "$ARGV: ".length $1' ...
576 # but that would be far less efficient, reading the entire contents
577 # of each file, rather than just the last two bytes of each.
578 # In addition, while the code below detects both blank lines and a missing
579 # newline at EOF, the above detects only the former.
580 #
581 # This is a perl script that is expected to be the single-quoted argument
582 # to a command-line "-le". The remaining arguments are file names.
583 # Print the name of each file that ends in exactly one newline byte.
584 # I.e., warn if there are blank lines (2 or more newlines), or if the
585 # last byte is not a newline. However, currently we don't complain
586 # about any file that contains exactly one byte.
587 # Exit nonzero if at least one such file is found, otherwise, exit 0.
588 # Warn about, but otherwise ignore open failure. Ignore seek/read failure.
589 #
590 # Use this if you want to remove trailing empty lines from selected files:
591 # perl -pi -0777 -e 's/\n\n+$/\n/' files...
592 #
593 require_exactly_one_NL_at_EOF_ = \
594 foreach my $$f (@ARGV) \
595 { \
596 open F, "<", $$f or (warn "failed to open $$f: $$!\n"), next; \
597 my $$p = sysseek (F, -2, 2); \
598 my $$c = "seek failure probably means file has < 2 bytes; ignore"; \
599 my $$last_two_bytes; \
600 defined $$p and $$p = sysread F, $$last_two_bytes, 2; \
601 close F; \
602 $$c = "ignore read failure"; \
603 $$p && ($$last_two_bytes eq "\n\n" \
604 || substr ($$last_two_bytes,1) ne "\n") \
605 and (print $$f), $$fail=1; \
606 } \
607 END { exit defined $$fail }
608 sc_prohibit_empty_lines_at_EOF:
609 @perl -le '$(require_exactly_one_NL_at_EOF_)' $$($(VC_LIST_EXCEPT)) \
610 || { echo '$(ME): empty line(s) or no newline at EOF' \
611 1>&2; exit 1; } || :
612
613 # Perl block to convert a match to FILE_NAME:LINENO:TEST,
614 # that is shared by two definitions below.
615 perl_filename_lineno_text_ = \
616 -e ' {' \
617 -e ' $$n = ($$` =~ tr/\n/\n/ + 1);' \
618 -e ' ($$v = $$&) =~ s/\n/\\n/g;' \
619 -e ' print "$$ARGV:$$n:$$v\n";' \
620 -e ' }'
621
622 prohibit_doubled_word_RE_ ?= \
623 /\b(then?|[iao]n|i[fst]|but|f?or|at|and|[dt]o)\s+\1\b/gims
624 prohibit_doubled_word_ = \
625 -e 'while ($(prohibit_doubled_word_RE_))' \
626 $(perl_filename_lineno_text_)
627
628 # Define this to a regular expression that matches
629 # any filename:dd:match lines you want to ignore.
630 # The default is to ignore no matches.
631 ignore_doubled_word_match_RE_ ?= ^$$
632
633 sc_prohibit_doubled_word:
634 @perl -n -0777 $(prohibit_doubled_word_) $$($(VC_LIST_EXCEPT)) \
635 | grep -vE '$(ignore_doubled_word_match_RE_)' \
636 | grep . && { echo '$(ME): doubled words' 1>&2; exit 1; } || :
637
638 # A regular expression matching undesirable combinations of words like
639 # "can not"; this matches them even when the two words appear on different
640 # lines, but not when there is an intervening delimiter like "#" or "*".
641 prohibit_undesirable_word_seq_RE_ ?= \
642 /\bcan\s+not\b/gims
643 prohibit_undesirable_word_seq_ = \
644 -e 'while ($(prohibit_undesirable_word_seq_RE_))' \
645 $(perl_filename_lineno_text_)
646 # Define this to a regular expression that matches
647 # any filename:dd:match lines you want to ignore.
648 # The default is to ignore no matches.
649 ignore_undesirable_word_sequence_RE_ ?= ^$$
650
651 sc_prohibit_undesirable_word_seq:
652 @perl -n -0777 $(prohibit_undesirable_word_seq_) \
653 $$($(VC_LIST_EXCEPT)) \
654 | grep -vE '$(ignore_undesirable_word_sequence_RE_)' | grep . \
655 && { echo '$(ME): undesirable word sequence' >&2; exit 1; } || :
656
657 _ptm1 = use "test C1 && test C2", not "test C1 -''a C2"
658 _ptm2 = use "test C1 || test C2", not "test C1 -''o C2"
659 # Using test's -a and -o operators is not portable.
660 # We prefer test over [, since the latter is spelled [[ in configure.ac.
661 sc_prohibit_test_minus_ao:
662 @prohibit='(\<test| \[+) .+ -[ao] ' \
663 halt='$(_ptm1); $(_ptm2)' \
664 $(_sc_search_regexp)
665
666 # Avoid a test bashism.
667 sc_prohibit_test_double_equal:
668 @prohibit='(\<test| \[+) .+ == ' \
669 containing='#! */bin/[a-z]*sh' \
670 halt='use "test x = x", not "test x =''= x"' \
671 $(_sc_search_regexp)
672
673 # Each program that uses proper_name_utf8 must link with one of the
674 # ICONV libraries. Otherwise, some ICONV library must appear in LDADD.
675 # The perl -0777 invocation below extracts the possibly-multi-line
676 # definition of LDADD from the appropriate Makefile.am and exits 0
677 # when it contains "ICONV".
678 sc_proper_name_utf8_requires_ICONV:
679 @progs=$$(grep -l 'proper_name_utf8 ''("' $$($(VC_LIST_EXCEPT)));\
680 if test "x$$progs" != x; then \
681 fail=0; \
682 for p in $$progs; do \
683 dir=$$(dirname "$$p"); \
684 perl -0777 \
685 -ne 'exit !(/^LDADD =(.+?[^\\]\n)/ms && $$1 =~ /ICONV/)' \
686 $$dir/Makefile.am && continue; \
687 base=$$(basename "$$p" .c); \
688 grep "$${base}_LDADD.*ICONV)" $$dir/Makefile.am > /dev/null \
689 || { fail=1; echo 1>&2 "$(ME): $$p uses proper_name_utf8"; }; \
690 done; \
691 test $$fail = 1 && \
692 { echo 1>&2 '$(ME): the above do not link with any ICONV library'; \
693 exit 1; } || :; \
694 fi
695
696 # Warn about "c0nst struct Foo const foo[]",
697 # but not about "char const *const foo" or "#define const const".
698 sc_redundant_const:
699 @prohibit='\bconst\b[[:space:][:alnum:]]{2,}\bconst\b' \
700 halt='redundant "const" in declarations' \
701 $(_sc_search_regexp)
702
703 sc_const_long_option:
704 @grep '^ *static.*struct option ' $$($(VC_LIST_EXCEPT)) \
705 | grep -Ev 'const struct option|struct option const' && { \
706 echo 1>&2 '$(ME): add "const" to the above declarations'; \
707 exit 1; } || :
708
709 # Ensure that we use only the standard $(VAR) notation,
710 # not @...@ in Makefile.am, now that we can rely on automake
711 # to emit a definition for each substituted variable.
712 # However, there is still one case in which @VAR@ use is not just
713 # legitimate, but actually required: when augmenting an automake-defined
714 # variable with a prefix. For example, gettext uses this:
715 # MAKEINFO = env LANG= LC_MESSAGES= LC_ALL= LANGUAGE= @MAKEINFO@
716 # otherwise, makeinfo would put German or French (current locale)
717 # navigation hints in the otherwise-English documentation.
718 #
719 # Allow the package to add exceptions via a hook in syntax-check.mk;
720 # for example, @PRAGMA_SYSTEM_HEADER@ can be permitted by
721 # setting this to ' && !/PRAGMA_SYSTEM_HEADER/'.
722 _makefile_at_at_check_exceptions ?=
723 sc_makefile_at_at_check:
724 @perl -ne '/\@[A-Z_0-9]+\@/' \
725 -e ' && !/([A-Z_0-9]+)\s+=.*\@\1\@$$/' \
726 -e ''$(_makefile_at_at_check_exceptions) \
727 -e 'and (print "$$ARGV:$$.: $$_"), $$m=1; END {exit !$$m}' \
728 $$($(VC_LIST_EXCEPT) | grep -E '(^|/)(Makefile\.am|[^/]+\.mk)$$') \
729 && { echo '$(ME): use $$(...), not @...@' 1>&2; exit 1; } || :
730
731 sc_makefile_TAB_only_indentation:
732 @prohibit='^ [ ]{8}' \
733 in_vc_files='akefile|\.mk$$' \
734 halt='found TAB-8-space indentation' \
735 $(_sc_search_regexp)
736
737 sc_m4_quote_check:
738 @prohibit='(AC_DEFINE(_UNQUOTED)?|AC_DEFUN)\([^[]' \
739 in_vc_files='(^configure\.ac|\.m4)$$' \
740 halt='quote the first arg to AC_DEF*' \
741 $(_sc_search_regexp)
742
743 fix_po_file_diag = \
744 'you have changed the set of files with translatable diagnostics;\n\
745 apply the above patch\n'
746
747 # Verify that all source files using _() are listed in po/POTFILES.in.
748 po_file ?= $(srcdir)/po/POTFILES.in
749 generated_files ?= $(srcdir)/lib/*.[ch]
750 sc_po_check:
751 @if test -f $(po_file); then \
752 grep -E -v '^(#|$$)' $(po_file) \
753 | grep -v '^src/false\.c$$' \
754 | sed 's|\[type: gettext/glade\] ||' \
755 | sort > $@-1; \
756 files=; \
757 for file in $$($(VC_LIST_EXCEPT)) $(generated_files); do \
758 test -r $$file || continue; \
759 case $$file in \
760 *.m4|*.mk) continue ;; \
761 *.?|*.??) ;; \
762 *.xml) ;; \
763 *.xml.in) ;; \
764 *.desktop.in) ;; \
765 *) continue;; \
766 esac; \
767 case $$file in \
768 *.[ch]) \
769 base=`expr " $$file" : ' \(.*\)\..'`; \
770 { test -f $$base.l || test -f $$base.y; } && continue;; \
771 esac; \
772 files="$$files $$file"; \
773 done; \
774 grep -E -l '(\b(N?_|gettext *)\([^)"]*("|$$))|(<interface>)|^_|<_' $$files \
775 | sed 's|^$(_dot_escaped_srcdir)/||' | sort -u > $@-2; \
776 diff -u -L $(po_file) -L $(po_file) $@-1 $@-2 \
777 || { printf '$(ME): '$(fix_po_file_diag) 1>&2; exit 1; }; \
778 rm -f $@-1 $@-2; \
779 fi
780
781 # #if HAVE_... will evaluate to false for any non numeric string.
782 # That would be flagged by using -Wundef, however gnulib currently
783 # tests many undefined macros, and so we can't enable that option.
784 # So at least preclude common boolean strings as macro values.
785 sc_Wundef_boolean:
786 @prohibit='^#define.*(yes|no|true|false)$$' \
787 in_files='$(CONFIG_INCLUDE)' \
788 halt='Use 0 or 1 for macro values' \
789 $(_sc_search_regexp)
790
791 # Even if you use pathmax.h to guarantee that PATH_MAX is defined, it might
792 # not be constant, or might overflow a stack. In general, use PATH_MAX as
793 # a limit, not an array or alloca size.
794 sc_prohibit_path_max_allocation:
795 @prohibit='(\balloca *\([^)]*|\[[^]]*)PATH_MAX' \
796 halt='Avoid stack allocations of size PATH_MAX' \
797 $(_sc_search_regexp)
798
799 sc_vulnerable_makefile_CVE-2009-4029:
800 @prohibit='perm -777 -exec chmod a\+rwx|chmod 777 \$$\(distdir\)' \
801 in_files=$$(find $(srcdir) -name Makefile.in) \
802 halt=$$(printf '%s\n' \
803 'the above files are vulnerable; beware of running' \
804 ' "make dist*" rules, and upgrade to fixed automake' \
805 ' see http://bugzilla.redhat.com/542609 for details') \
806 $(_sc_search_regexp)
807
808 # Files that should never cause syntax check failures.
809 VC_LIST_ALWAYS_EXCLUDE_REGEX = \
810 (^HACKING|\.po|build-aux/syntax-check.mk)$$
811
812 # Functions like free() that are no-ops on NULL arguments.
813 useless_free_options = \
814 --name=g_free \
815 --name=xmlBufferFree \
816 --name=xmlFree \
817 --name=xmlFreeDoc \
818 --name=xmlXPathFreeContext \
819 --name=xmlFreeParserContext \
820 --name=xmlXPathFreeObject
821
822 # Ensure that no C source file, docs, or rng schema uses TABs for
823 # indentation. Also match *.h.in files, to get libvirt.h.in. Exclude
824 # files in gnulib, since they're imported.
825 space_indent_files=(\.(rng|s?[ch](\.in)?|html.in|py)|(daemon|tools)/.*\.in)
826 sc_TAB_in_indentation:
827 @prohibit='^ * ' \
828 in_vc_files='$(space_indent_files)$$' \
829 halt='indent with space, not TAB, in C, sh, html, py, and RNG schemas' \
830 $(_sc_search_regexp)
831
832 # G_GNUC_UNUSED should only be applied in implementations, not
833 # header declarations
834 sc_avoid_attribute_unused_in_header:
835 @prohibit='^[^#]*G_GNUC_UNUSED([^:]|$$)' \
836 in_vc_files='\.h$$' \
837 halt='use G_GNUC_UNUSED in .c rather than .h files' \
838 $(_sc_search_regexp)
839
840 # Enforce recommended preprocessor indentation style.
841 sc_preprocessor_indentation:
842 @if cppi --version >/dev/null 2>&1; then \
843 $(VC_LIST_EXCEPT) | grep '\.[ch]$$' | xargs cppi -a -c \
844 || { echo '$(ME): incorrect preprocessor indentation' 1>&2; \
845 exit 1; }; \
846 else \
847 echo '$(ME): skipping test $@: cppi not installed' 1>&2; \
848 fi
849
850 sc_copyright_format:
851 @require='Copyright .*Red 'Hat', Inc\.' \
852 containing='Copyright .*Red 'Hat \
853 halt='Red Hat copyright is missing Inc.' \
854 $(_sc_search_regexp)
855 @prohibit='Copyright [^(].*Red 'Hat \
856 halt='consistently use (C) in Red Hat copyright' \
857 $(_sc_search_regexp)
858 @prohibit='\<Red''Hat\>' \
859 halt='spell Red Hat as two words' \
860 $(_sc_search_regexp)
861
862 exclude_file_name_regexp--sc_preprocessor_indentation = ^*/*.[ch]
863 exclude_file_name_regexp--sc_prohibit_strcmp = ^*/*.[ch]
864 exclude_file_name_regexp--sc_require_config_h = ^src/gbinding\.c|src/windows-cmdline-wrapper.c
865 exclude_file_name_regexp--sc_require_config_h_first = ^src/gbinding\.c|src/windows-cmdline-wrapper.c
866
867 exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF = ^icons/
868 exclude_file_name_regexp--sc_trailing_blank = ^icons/
869
870 exclude_file_name_regexp--sc_prohibit_magic_number_exit = src/windows-cmdline-wrapper.c
871
872 exclude_file_name_regexp--sc_makefile_at_at_check = data/Makefile.am