Codebase list virt-viewer / a743d85
build: move cfg.mk and maint.mk into build-aux directory Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Daniel P. Berrangé 3 years ago
6 changed file(s) with 1649 addition(s) and 1651 deletion(s). Raw diff Collapse all Expand all
1818
1919 # You should have received a copy of the GNU General Public License
2020 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21
22 _build-aux ?= build-aux
23 _autoreconf ?= autoreconf -v
2124
2225 # Systems where /bin/sh is not the default shell need this. The $(shell)
2326 # command below won't work with e.g. stock DOS/Windows shells.
4346 include Makefile
4447
4548 # Some projects override e.g., _autoreconf here.
46 -include $(srcdir)/cfg.mk
47
48 # Allow cfg.mk to override these.
49 _build-aux ?= build-aux
50 _autoreconf ?= autoreconf -v
51
52 include $(srcdir)/maint.mk
49 include $(srcdir)/$(_build-aux)/cfg.mk
50 include $(srcdir)/$(_build-aux)/maint.mk
5351
5452 # Ensure that $(VERSION) is up to date for dist-related targets, but not
5553 # for others: rerunning autoreconf and recompiling everything isn't cheap.
9997 srcdir = .
10098
10199 # The package can override .DEFAULT_GOAL to run actions like autoreconf.
102 -include ./cfg.mk
103 include ./maint.mk
100 include $(srcdir)/$(_build-aux)/cfg.mk
101 include $(srcdir)/$(_build-aux)/maint.mk
104102
105103 ifeq ($(.DEFAULT_GOAL),abort-due-to-no-makefile)
106104 $(MAKECMDGOALS): abort-due-to-no-makefile
88 $(PACKAGE).spec $(PACKAGE).spec.in \
99 mingw-$(PACKAGE).spec.in \
1010 GNUmakefile \
11 maint.mk \
12 cfg.mk \
11 build-aux/cfg.mk \
1312 build-aux/gitlog-to-changelog \
13 build-aux/maint.mk \
1414 build-aux/useless-if-before-free \
1515 build-aux/vc-list-files \
1616 AUTHORS.in \
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 # Tests not to run as part of "make distcheck".
18 local-checks-to-skip = \
19 changelog-check \
20 makefile-check \
21 makefile_path_separator_check \
22 patch-check \
23 sc_GPL_version \
24 sc_always_defined_macros \
25 sc_bindtextdomain \
26 sc_cast_of_alloca_return_value \
27 sc_cross_check_PATH_usage_in_tests \
28 sc_dd_max_sym_length \
29 sc_error_exit_success \
30 sc_file_system \
31 sc_immutable_NEWS \
32 sc_makefile_path_separator_check \
33 sc_obsolete_symbols \
34 sc_prohibit_always_true_header_tests \
35 sc_prohibit_S_IS_definition \
36 sc_prohibit_atoi_atof \
37 sc_prohibit_hash_without_use \
38 sc_prohibit_jm_in_m4 \
39 sc_prohibit_quote_without_use \
40 sc_prohibit_quotearg_without_use \
41 sc_prohibit_stat_st_blocks \
42 sc_root_tests \
43 sc_space_tab \
44 sc_sun_os_names \
45 sc_system_h_headers \
46 sc_texinfo_acronym \
47 sc_tight_scope \
48 sc_two_space_separator_in_usage \
49 sc_error_message_uppercase \
50 sc_program_name \
51 sc_require_test_exit_idiom \
52 sc_makefile_check \
53 sc_useless_cpp_parens
54
55 # Files that should never cause syntax check failures.
56 VC_LIST_ALWAYS_EXCLUDE_REGEX = \
57 (^HACKING|\.po|build-aux/maint.mk)$$
58
59 # Functions like free() that are no-ops on NULL arguments.
60 useless_free_options = \
61 --name=g_free \
62 --name=xmlBufferFree \
63 --name=xmlFree \
64 --name=xmlFreeDoc \
65 --name=xmlXPathFreeContext \
66 --name=xmlFreeParserContext \
67 --name=xmlXPathFreeObject
68
69 # Ensure that no C source file, docs, or rng schema uses TABs for
70 # indentation. Also match *.h.in files, to get libvirt.h.in. Exclude
71 # files in gnulib, since they're imported.
72 space_indent_files=(\.(rng|s?[ch](\.in)?|html.in|py)|(daemon|tools)/.*\.in)
73 sc_TAB_in_indentation:
74 @prohibit='^ * ' \
75 in_vc_files='$(space_indent_files)$$' \
76 halt='indent with space, not TAB, in C, sh, html, py, and RNG schemas' \
77 $(_sc_search_regexp)
78
79 # G_GNUC_UNUSED should only be applied in implementations, not
80 # header declarations
81 sc_avoid_attribute_unused_in_header:
82 @prohibit='^[^#]*G_GNUC_UNUSED([^:]|$$)' \
83 in_vc_files='\.h$$' \
84 halt='use G_GNUC_UNUSED in .c rather than .h files' \
85 $(_sc_search_regexp)
86
87 # Enforce recommended preprocessor indentation style.
88 sc_preprocessor_indentation:
89 @if cppi --version >/dev/null 2>&1; then \
90 $(VC_LIST_EXCEPT) | grep '\.[ch]$$' | xargs cppi -a -c \
91 || { echo '$(ME): incorrect preprocessor indentation' 1>&2; \
92 exit 1; }; \
93 else \
94 echo '$(ME): skipping test $@: cppi not installed' 1>&2; \
95 fi
96
97 sc_copyright_format:
98 @require='Copyright .*Red 'Hat', Inc\.' \
99 containing='Copyright .*Red 'Hat \
100 halt='Red Hat copyright is missing Inc.' \
101 $(_sc_search_regexp)
102 @prohibit='Copyright [^(].*Red 'Hat \
103 halt='consistently use (C) in Red Hat copyright' \
104 $(_sc_search_regexp)
105 @prohibit='\<Red''Hat\>' \
106 halt='spell Red Hat as two words' \
107 $(_sc_search_regexp)
108
109 # We don't use this feature of maint.mk.
110 prev_version_file = /dev/null
111
112
113 exclude_file_name_regexp--sc_preprocessor_indentation = ^*/*.[ch]
114 exclude_file_name_regexp--sc_prohibit_strcmp = ^*/*.[ch]
115 exclude_file_name_regexp--sc_require_config_h = ^src/gbinding\.c|src/windows-cmdline-wrapper.c
116 exclude_file_name_regexp--sc_require_config_h_first = ^src/gbinding\.c|src/windows-cmdline-wrapper.c
117
118 exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF = ^icons/
119 exclude_file_name_regexp--sc_trailing_blank = ^icons/
120
121 exclude_file_name_regexp--sc_prohibit_magic_number_exit = src/windows-cmdline-wrapper.c
122
123 exclude_file_name_regexp--sc_makefile_at_at_check = data/Makefile.am
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 # Diagnostic for continued use of deprecated variable.
24 # Remove in 2013
25 ifneq ($(build_aux),)
26 $(error "$(ME): \
27 set $$(_build-aux) relative to $$(srcdir) instead of $$(build_aux)")
28 endif
29
30 # Do not save the original name or timestamp in the .tar.gz file.
31 # Use --rsyncable if available.
32 gzip_rsyncable := \
33 $(shell gzip --help 2>/dev/null|grep rsyncable >/dev/null \
34 && printf %s --rsyncable)
35 GZIP_ENV = '--no-name --best $(gzip_rsyncable)'
36
37 GIT = git
38 VC = $(GIT)
39
40 VC_LIST = $(srcdir)/$(_build-aux)/vc-list-files -C $(srcdir)
41
42 # You can override this variable in cfg.mk to set your own regexp
43 # matching files to ignore.
44 VC_LIST_ALWAYS_EXCLUDE_REGEX ?= ^$$
45
46 # This is to preprocess robustly the output of $(VC_LIST), so that even
47 # when $(srcdir) is a pathological name like "....", the leading sed command
48 # removes only the intended prefix.
49 _dot_escaped_srcdir = $(subst .,\.,$(srcdir))
50
51 # Post-process $(VC_LIST) output, prepending $(srcdir)/, but only
52 # when $(srcdir) is not ".".
53 ifeq ($(srcdir),.)
54 _prepend_srcdir_prefix =
55 else
56 _prepend_srcdir_prefix = | sed 's|^|$(srcdir)/|'
57 endif
58
59 # In order to be able to consistently filter "."-relative names,
60 # (i.e., with no $(srcdir) prefix), this definition is careful to
61 # remove any $(srcdir) prefix, and to restore what it removes.
62 _sc_excl = \
63 $(if $(exclude_file_name_regexp--$@),$(exclude_file_name_regexp--$@),^$$)
64 VC_LIST_EXCEPT = \
65 $(VC_LIST) | sed 's|^$(_dot_escaped_srcdir)/||' \
66 | if test -f $(srcdir)/.x-$@; then grep -vEf $(srcdir)/.x-$@; \
67 else grep -Ev -e "$${VC_LIST_EXCEPT_DEFAULT-ChangeLog}"; fi \
68 | grep -Ev -e '($(VC_LIST_ALWAYS_EXCLUDE_REGEX)|$(_sc_excl))' \
69 $(_prepend_srcdir_prefix)
70
71 ifeq ($(origin prev_version_file), undefined)
72 prev_version_file = $(srcdir)/.prev-version
73 endif
74
75 PREV_VERSION := $(shell cat $(prev_version_file) 2>/dev/null)
76 VERSION_REGEXP = $(subst .,\.,$(VERSION))
77 PREV_VERSION_REGEXP = $(subst .,\.,$(PREV_VERSION))
78
79 ifeq ($(VC),$(GIT))
80 this-vc-tag = v$(VERSION)
81 this-vc-tag-regexp = v$(VERSION_REGEXP)
82 else
83 tag-package = $(shell echo "$(PACKAGE)" | tr '[:lower:]' '[:upper:]')
84 tag-this-version = $(subst .,_,$(VERSION))
85 this-vc-tag = $(tag-package)-$(tag-this-version)
86 this-vc-tag-regexp = $(this-vc-tag)
87 endif
88 my_distdir = $(PACKAGE)-$(VERSION)
89
90 # Old releases are stored here.
91 release_archive_dir ?= ../release
92
93 # Override gnu_rel_host and url_dir_list in cfg.mk if these are not right.
94 # Use alpha.gnu.org for alpha and beta releases.
95 # Use ftp.gnu.org for stable releases.
96 gnu_ftp_host-alpha = alpha.gnu.org
97 gnu_ftp_host-beta = alpha.gnu.org
98 gnu_ftp_host-stable = ftp.gnu.org
99 gnu_rel_host ?= $(gnu_ftp_host-$(RELEASE_TYPE))
100
101 ifeq ($(gnu_rel_host),ftp.gnu.org)
102 url_dir_list ?= http://ftpmirror.gnu.org/$(PACKAGE)
103 else
104 url_dir_list ?= ftp://$(gnu_rel_host)/gnu/$(PACKAGE)
105 endif
106
107 # Override this in cfg.mk if you are using a different format in your
108 # NEWS file.
109 today = $(shell date +%Y-%m-%d)
110
111 # Select which lines of NEWS are searched for $(news-check-regexp).
112 # This is a sed line number spec. The default says that we search
113 # lines 1..10 of NEWS for $(news-check-regexp).
114 # If you want to search only line 3 or only lines 20-22, use "3" or "20,22".
115 news-check-lines-spec ?= 1,10
116 news-check-regexp ?= '^\*.* $(VERSION_REGEXP) \($(today)\)'
117
118 # Prevent programs like 'sort' from considering distinct strings to be equal.
119 # Doing it here saves us from having to set LC_ALL elsewhere in this file.
120 export LC_ALL = C
121
122 ## --------------- ##
123 ## Sanity checks. ##
124 ## --------------- ##
125
126 _cfg_mk := $(shell test -f $(srcdir)/$(_build-aux)/cfg.mk && echo '$(srcdir)/$(_build-aux)/cfg.mk')
127
128 # Collect the names of rules starting with `sc_'.
129 syntax-check-rules := $(sort $(shell sed -n 's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' \
130 $(srcdir)/$(ME) $(_cfg_mk)))
131 .PHONY: $(syntax-check-rules)
132
133 ifeq ($(shell $(VC_LIST) >/dev/null 2>&1; echo $$?),0)
134 local-checks-available += $(syntax-check-rules)
135 else
136 local-checks-available += no-vc-detected
137 no-vc-detected:
138 @echo "No version control files detected; skipping syntax check"
139 endif
140 .PHONY: $(local-checks-available)
141
142 # Arrange to print the name of each syntax-checking rule just before running it.
143 $(syntax-check-rules): %: %.m
144 sc_m_rules_ = $(patsubst %, %.m, $(syntax-check-rules))
145 .PHONY: $(sc_m_rules_)
146 $(sc_m_rules_):
147 @echo $(patsubst sc_%.m, %, $@)
148 @date +%s.%N > .sc-start-$(basename $@)
149
150 # Compute and print the elapsed time for each syntax-check rule.
151 sc_z_rules_ = $(patsubst %, %.z, $(syntax-check-rules))
152 .PHONY: $(sc_z_rules_)
153 $(sc_z_rules_): %.z: %
154 @end=$$(date +%s.%N); \
155 start=$$(cat .sc-start-$*); \
156 rm -f .sc-start-$*; \
157 awk -v s=$$start -v e=$$end \
158 'END {printf "%.2f $(patsubst sc_%,%,$*)\n", e - s}' < /dev/null
159
160 # The patsubst here is to replace each sc_% rule with its sc_%.z wrapper
161 # that computes and prints elapsed time.
162 local-check := \
163 $(patsubst sc_%, sc_%.z, \
164 $(filter-out $(local-checks-to-skip), $(local-checks-available)))
165
166 syntax-check: $(local-check)
167
168 # _sc_search_regexp
169 #
170 # This macro searches for a given construct in the selected files and
171 # then takes some action.
172 #
173 # Parameters (shell variables):
174 #
175 # prohibit | require
176 #
177 # Regular expression (ERE) denoting either a forbidden construct
178 # or a required construct. Those arguments are exclusive.
179 #
180 # in_vc_files | in_files
181 #
182 # grep-E-style regexp denoting the files to check. If no files
183 # are specified the default are all the files that are under
184 # version control.
185 #
186 # containing | non_containing
187 #
188 # Select the files (non) containing strings matching this regexp.
189 # If both arguments are specified then CONTAINING takes
190 # precedence.
191 #
192 # with_grep_options
193 #
194 # Extra options for grep.
195 #
196 # ignore_case
197 #
198 # Ignore case.
199 #
200 # halt
201 #
202 # Message to display before to halting execution.
203 #
204 # Finally, you may exempt files based on an ERE matching file names.
205 # For example, to exempt from the sc_space_tab check all files with the
206 # .diff suffix, set this Make variable:
207 #
208 # exclude_file_name_regexp--sc_space_tab = \.diff$
209 #
210 # Note that while this functionality is mostly inherited via VC_LIST_EXCEPT,
211 # when filtering by name via in_files, we explicitly filter out matching
212 # names here as well.
213
214 # By default, _sc_search_regexp does not ignore case.
215 export ignore_case =
216 _ignore_case = $$(test -n "$$ignore_case" && printf %s -i || :)
217
218 define _sc_say_and_exit
219 dummy=; : so we do not need a semicolon before each use; \
220 { printf '%s\n' "$(ME): $$msg" 1>&2; exit 1; };
221 endef
222
223 # _sc_search_regexp used to be named _prohibit_regexp. However,
224 # upgrading to the new definition and leaving the old name undefined
225 # would usually convert each custom rule using $(_prohibit_regexp)
226 # (usually defined in cfg.mk) into a no-op. This definition ensures
227 # that people know right away if they're still using the old name.
228 # FIXME: remove in 2012.
229 _prohibit_regexp = \
230 $(error '*** you need to s/_prohibit_regexp/_sc_search_regexp/, and adapt')
231
232 define _sc_search_regexp
233 dummy=; : so we do not need a semicolon before each use; \
234 \
235 : Check arguments; \
236 test -n "$$prohibit" && test -n "$$require" \
237 && { msg='Cannot specify both prohibit and require' \
238 $(_sc_say_and_exit) } || :; \
239 test -z "$$prohibit" && test -z "$$require" \
240 && { msg='Should specify either prohibit or require' \
241 $(_sc_say_and_exit) } || :; \
242 test -n "$$in_vc_files" && test -n "$$in_files" \
243 && { msg='Cannot specify both in_vc_files and in_files' \
244 $(_sc_say_and_exit) } || :; \
245 test "x$$halt" != x \
246 || { msg='halt not defined' $(_sc_say_and_exit) }; \
247 \
248 : Filter by file name; \
249 if test -n "$$in_files"; then \
250 files=$$(find $(srcdir) | grep -E "$$in_files" \
251 | grep -Ev '$(exclude_file_name_regexp--$@)'); \
252 else \
253 files=$$($(VC_LIST_EXCEPT)); \
254 if test -n "$$in_vc_files"; then \
255 files=$$(echo "$$files" | grep -E "$$in_vc_files"); \
256 fi; \
257 fi; \
258 \
259 : Filter by content; \
260 test -n "$$files" && test -n "$$containing" \
261 && { files=$$(grep -l "$$containing" $$files); } || :; \
262 test -n "$$files" && test -n "$$non_containing" \
263 && { files=$$(grep -vl "$$non_containing" $$files); } || :; \
264 \
265 : Check for the construct; \
266 if test -n "$$files"; then \
267 if test -n "$$prohibit"; then \
268 grep $$with_grep_options $(_ignore_case) -nE "$$prohibit" $$files \
269 && { msg="$$halt" $(_sc_say_and_exit) } || :; \
270 else \
271 grep $$with_grep_options $(_ignore_case) -LE "$$require" $$files \
272 | grep . \
273 && { msg="$$halt" $(_sc_say_and_exit) } || :; \
274 fi \
275 else :; \
276 fi || :;
277 endef
278
279 sc_avoid_if_before_free:
280 @$(srcdir)/$(_build-aux)/useless-if-before-free \
281 $(useless_free_options) \
282 $$($(VC_LIST_EXCEPT) | grep -v useless-if-before-free) && \
283 { echo '$(ME): found useless "if" before "free" above' 1>&2; \
284 exit 1; } || :
285
286 sc_cast_of_argument_to_free:
287 @prohibit='\<free *\( *\(' halt='don'\''t cast free argument' \
288 $(_sc_search_regexp)
289
290 sc_cast_of_x_alloc_return_value:
291 @prohibit='\*\) *x(m|c|re)alloc\>' \
292 halt='don'\''t cast x*alloc return value' \
293 $(_sc_search_regexp)
294
295 sc_cast_of_alloca_return_value:
296 @prohibit='\*\) *alloca\>' \
297 halt='don'\''t cast alloca return value' \
298 $(_sc_search_regexp)
299
300 sc_space_tab:
301 @prohibit='[ ] ' \
302 halt='found SPACE-TAB sequence; remove the SPACE' \
303 $(_sc_search_regexp)
304
305 # Don't use *scanf or the old ato* functions in `real' code.
306 # They provide no error checking mechanism.
307 # Instead, use strto* functions.
308 sc_prohibit_atoi_atof:
309 @prohibit='\<([fs]?scanf|ato([filq]|ll)) *\(' \
310 halt='do not use *scan''f, ato''f, ato''i, ato''l, ato''ll or ato''q' \
311 $(_sc_search_regexp)
312
313 # Use STREQ rather than comparing strcmp == 0, or != 0.
314 sc_prohibit_strcmp:
315 @grep -nE '! *str''cmp *\(|\<str''cmp *\(.+\) *[!=]=' \
316 $$($(VC_LIST_EXCEPT)) \
317 | grep -vE ':# *define STRN?EQ\(' && \
318 { echo '$(ME): replace str''cmp calls above with STREQ/STRNEQ' \
319 1>&2; exit 1; } || :
320
321 # Pass EXIT_*, not number, to usage, exit, and error (when exiting)
322 # Convert all uses automatically, via these two commands:
323 # git grep -l '\<exit *(1)' \
324 # | grep -vEf .x-sc_prohibit_magic_number_exit \
325 # | xargs --no-run-if-empty \
326 # perl -pi -e 's/(^|[^.])\b(exit ?)\(1\)/$1$2(EXIT_FAILURE)/'
327 # git grep -l '\<exit *(0)' \
328 # | grep -vEf .x-sc_prohibit_magic_number_exit \
329 # | xargs --no-run-if-empty \
330 # perl -pi -e 's/(^|[^.])\b(exit ?)\(0\)/$1$2(EXIT_SUCCESS)/'
331 sc_prohibit_magic_number_exit:
332 @prohibit='(^|[^.])\<(usage|exit) ?\([0-9]|\<error ?\([1-9][0-9]*,' \
333 halt='use EXIT_* values rather than magic number' \
334 $(_sc_search_regexp)
335
336 # Using EXIT_SUCCESS as the first argument to error is misleading,
337 # since when that parameter is 0, error does not exit. Use `0' instead.
338 sc_error_exit_success:
339 @prohibit='error *\(EXIT_SUCCESS,' \
340 in_vc_files='\.[chly]$$' \
341 halt='found error (EXIT_SUCCESS' \
342 $(_sc_search_regexp)
343
344 # `FATAL:' should be fully upper-cased in error messages
345 # `WARNING:' should be fully upper-cased, or fully lower-cased
346 sc_error_message_warn_fatal:
347 @grep -nEA2 '[^rp]error *\(' $$($(VC_LIST_EXCEPT)) \
348 | grep -E '"Warning|"Fatal|"fatal' && \
349 { echo '$(ME): use FATAL, WARNING or warning' 1>&2; \
350 exit 1; } || :
351
352 # Error messages should not start with a capital letter
353 sc_error_message_uppercase:
354 @grep -nEA2 '[^rp]error *\(' $$($(VC_LIST_EXCEPT)) \
355 | grep -E '"[A-Z]' \
356 | grep -vE '"FATAL|"WARNING|"Java|"C#|PRIuMAX' && \
357 { echo '$(ME): found capitalized error message' 1>&2; \
358 exit 1; } || :
359
360 # Error messages should not end with a period
361 sc_error_message_period:
362 @grep -nEA2 '[^rp]error *\(' $$($(VC_LIST_EXCEPT)) \
363 | grep -E '[^."]\."' && \
364 { echo '$(ME): found error message ending in period' 1>&2; \
365 exit 1; } || :
366
367 sc_file_system:
368 @prohibit=file''system \
369 ignore_case=1 \
370 halt='found use of "file''system"; spell it "file system"' \
371 $(_sc_search_regexp)
372
373 # Don't use cpp tests of this symbol. All code assumes config.h is included.
374 sc_prohibit_have_config_h:
375 @prohibit='^# *if.*HAVE''_CONFIG_H' \
376 halt='found use of HAVE''_CONFIG_H; remove' \
377 $(_sc_search_regexp)
378
379 # Nearly all .c files must include <config.h>. However, we also permit this
380 # via inclusion of a package-specific header, if cfg.mk specified one.
381 # config_h_header must be suitable for grep -E.
382 config_h_header ?= <config\.h>
383 sc_require_config_h:
384 @require='^# *include $(config_h_header)' \
385 in_vc_files='\.c$$' \
386 halt='the above files do not include <config.h>' \
387 $(_sc_search_regexp)
388
389 # You must include <config.h> before including any other header file.
390 # This can possibly be via a package-specific header, if given by cfg.mk.
391 sc_require_config_h_first:
392 @if $(VC_LIST_EXCEPT) | grep -l '\.c$$' > /dev/null; then \
393 fail=0; \
394 for i in $$($(VC_LIST_EXCEPT) | grep '\.c$$'); do \
395 grep '^# *include\>' $$i | sed 1q \
396 | grep -E '^# *include $(config_h_header)' > /dev/null \
397 || { echo $$i; fail=1; }; \
398 done; \
399 test $$fail = 1 && \
400 { echo '$(ME): the above files include some other header' \
401 'before <config.h>' 1>&2; exit 1; } || :; \
402 else :; \
403 fi
404
405 sc_prohibit_HAVE_MBRTOWC:
406 @prohibit='\bHAVE_MBRTOWC\b' \
407 halt="do not use $$prohibit; it is always defined" \
408 $(_sc_search_regexp)
409
410 # To use this "command" macro, you must first define two shell variables:
411 # h: the header name, with no enclosing <> or ""
412 # re: a regular expression that matches IFF something provided by $h is used.
413 define _sc_header_without_use
414 dummy=; : so we do not need a semicolon before each use; \
415 h_esc=`echo '[<"]'"$$h"'[">]'|sed 's/\./\\\\./g'`; \
416 if $(VC_LIST_EXCEPT) | grep -l '\.c$$' > /dev/null; then \
417 files=$$(grep -l '^# *include '"$$h_esc" \
418 $$($(VC_LIST_EXCEPT) | grep '\.c$$')) && \
419 grep -LE "$$re" $$files | grep . && \
420 { echo "$(ME): the above files include $$h but don't use it" \
421 1>&2; exit 1; } || :; \
422 else :; \
423 fi
424 endef
425
426 # Prohibit the inclusion of assert.h without an actual use of assert.
427 sc_prohibit_assert_without_use:
428 @h='assert.h' re='\<assert *\(' $(_sc_header_without_use)
429
430 # Prohibit the inclusion of close-stream.h without an actual use.
431 sc_prohibit_close_stream_without_use:
432 @h='close-stream.h' re='\<close_stream *\(' $(_sc_header_without_use)
433
434 # Prohibit the inclusion of getopt.h without an actual use.
435 sc_prohibit_getopt_without_use:
436 @h='getopt.h' re='\<getopt(_long)? *\(' $(_sc_header_without_use)
437
438 # Don't include quotearg.h unless you use one of its functions.
439 sc_prohibit_quotearg_without_use:
440 @h='quotearg.h' re='\<quotearg(_[^ ]+)? *\(' $(_sc_header_without_use)
441
442 # Don't include quote.h unless you use one of its functions.
443 sc_prohibit_quote_without_use:
444 @h='quote.h' re='\<quote(_n)? *\(' $(_sc_header_without_use)
445
446 # Don't include this header unless you use one of its functions.
447 sc_prohibit_long_options_without_use:
448 @h='long-options.h' re='\<parse_long_options *\(' \
449 $(_sc_header_without_use)
450
451 # Don't include this header unless you use one of its functions.
452 sc_prohibit_inttostr_without_use:
453 @h='inttostr.h' re='\<(off|[iu]max|uint)tostr *\(' \
454 $(_sc_header_without_use)
455
456 # Don't include this header unless you use one of its functions.
457 sc_prohibit_ignore_value_without_use:
458 @h='ignore-value.h' re='\<ignore_(value|ptr) *\(' \
459 $(_sc_header_without_use)
460
461 # Don't include this header unless you use one of its functions.
462 sc_prohibit_error_without_use:
463 @h='error.h' \
464 re='\<error(_at_line|_print_progname|_one_per_line|_message_count)? *\('\
465 $(_sc_header_without_use)
466
467 # Don't include xalloc.h unless you use one of its functions.
468 # Consider these symbols:
469 # perl -lne '/^# *define (\w+)\(/ and print $1' lib/xalloc.h|grep -v '^__';
470 # perl -lne '/^(?:extern )?(?:void|char) \*?(\w+) *\(/ and print $1' lib/xalloc.h
471 # Divide into two sets on case, and filter each through this:
472 # | sort | perl -MRegexp::Assemble -le \
473 # 'print Regexp::Assemble->new(file => "/dev/stdin")->as_string'|sed 's/\?://g'
474 # Note this was produced by the above:
475 # _xa1 = \
476 #x(((2n?)?re|c(har)?|n(re|m)|z)alloc|alloc_(oversized|die)|m(alloc|emdup)|strdup)
477 # But we can do better, in at least two ways:
478 # 1) take advantage of two "dup"-suffixed strings:
479 # x(((2n?)?re|c(har)?|n(re|m)|[mz])alloc|alloc_(oversized|die)|(mem|str)dup)
480 # 2) notice that "c(har)?|[mz]" is equivalent to the shorter and more readable
481 # "char|[cmz]"
482 # x(((2n?)?re|char|n(re|m)|[cmz])alloc|alloc_(oversized|die)|(mem|str)dup)
483 _xa1 = x(((2n?)?re|char|n(re|m)|[cmz])alloc|alloc_(oversized|die)|(mem|str)dup)
484 _xa2 = X([CZ]|N?M)ALLOC
485 sc_prohibit_xalloc_without_use:
486 @h='xalloc.h' \
487 re='\<($(_xa1)|$(_xa2)) *\('\
488 $(_sc_header_without_use)
489
490 # Extract function names:
491 # perl -lne '/^(?:extern )?(?:void|char) \*?(\w+) *\(/ and print $1' lib/hash.h
492 _hash_re = \
493 clear|delete|free|get_(first|next)|insert|lookup|print_statistics|reset_tuning
494 _hash_fn = \<($(_hash_re)) *\(
495 _hash_struct = (struct )?\<[Hh]ash_(table|tuning)\>
496 sc_prohibit_hash_without_use:
497 @h='hash.h' \
498 re='$(_hash_fn)|$(_hash_struct)'\
499 $(_sc_header_without_use)
500
501 sc_prohibit_cloexec_without_use:
502 @h='cloexec.h' re='\<(set_cloexec_flag|dup_cloexec) *\(' \
503 $(_sc_header_without_use)
504
505 sc_prohibit_posixver_without_use:
506 @h='posixver.h' re='\<posix2_version *\(' $(_sc_header_without_use)
507
508 sc_prohibit_same_without_use:
509 @h='same.h' re='\<same_name *\(' $(_sc_header_without_use)
510
511 sc_prohibit_hash_pjw_without_use:
512 @h='hash-pjw.h' \
513 re='\<hash_pjw *\(' \
514 $(_sc_header_without_use)
515
516 sc_prohibit_safe_read_without_use:
517 @h='safe-read.h' re='(\<SAFE_READ_ERROR\>|\<safe_read *\()' \
518 $(_sc_header_without_use)
519
520 sc_prohibit_argmatch_without_use:
521 @h='argmatch.h' \
522 re='(\<(ARRAY_CARDINALITY|X?ARGMATCH(|_TO_ARGUMENT|_VERIFY))\>|\<(invalid_arg|argmatch(_exit_fn|_(in)?valid)?) *\()' \
523 $(_sc_header_without_use)
524
525 sc_prohibit_canonicalize_without_use:
526 @h='canonicalize.h' \
527 re='CAN_(EXISTING|ALL_BUT_LAST|MISSING)|canonicalize_(mode_t|filename_mode)' \
528 $(_sc_header_without_use)
529
530 sc_prohibit_root_dev_ino_without_use:
531 @h='root-dev-ino.h' \
532 re='(\<ROOT_DEV_INO_(CHECK|WARN)\>|\<get_root_dev_ino *\()' \
533 $(_sc_header_without_use)
534
535 sc_prohibit_openat_without_use:
536 @h='openat.h' \
537 re='\<(openat_(permissive|needs_fchdir|(save|restore)_fail)|l?(stat|ch(own|mod))at|(euid)?accessat)\>' \
538 $(_sc_header_without_use)
539
540 # Prohibit the inclusion of c-ctype.h without an actual use.
541 ctype_re = isalnum|isalpha|isascii|isblank|iscntrl|isdigit|isgraph|islower\
542 |isprint|ispunct|isspace|isupper|isxdigit|tolower|toupper
543 sc_prohibit_c_ctype_without_use:
544 @h='c-ctype.h' re='\<c_($(ctype_re)) *\(' \
545 $(_sc_header_without_use)
546
547 _empty =
548 _sp = $(_empty) $(_empty)
549 # The following list was generated by running:
550 # man signal.h|col -b|perl -ne '/bsd_signal.*;/.../sigwaitinfo.*;/ and print' \
551 # | perl -lne '/^\s+(?:int|void).*?(\w+).*/ and print $1' | fmt
552 _sig_functions = \
553 bsd_signal kill killpg pthread_kill pthread_sigmask raise sigaction \
554 sigaddset sigaltstack sigdelset sigemptyset sigfillset sighold sigignore \
555 siginterrupt sigismember signal sigpause sigpending sigprocmask sigqueue \
556 sigrelse sigset sigsuspend sigtimedwait sigwait sigwaitinfo
557 _sig_function_re = $(subst $(_sp),|,$(strip $(_sig_functions)))
558 # The following were extracted from "man signal.h" manually.
559 _sig_types_and_consts = \
560 MINSIGSTKSZ SA_NOCLDSTOP SA_NOCLDWAIT SA_NODEFER SA_ONSTACK \
561 SA_RESETHAND SA_RESTART SA_SIGINFO SIGEV_NONE SIGEV_SIGNAL \
562 SIGEV_THREAD SIGSTKSZ SIG_BLOCK SIG_SETMASK SIG_UNBLOCK SS_DISABLE \
563 SS_ONSTACK mcontext_t pid_t sig_atomic_t sigevent siginfo_t sigset_t \
564 sigstack sigval stack_t ucontext_t
565 # generated via this:
566 # perl -lne '/^#ifdef (SIG\w+)/ and print $1' lib/sig2str.c|sort -u|fmt -70
567 _sig_names = \
568 SIGABRT SIGALRM SIGALRM1 SIGBUS SIGCANCEL SIGCHLD SIGCLD SIGCONT \
569 SIGDANGER SIGDIL SIGEMT SIGFPE SIGFREEZE SIGGRANT SIGHUP SIGILL \
570 SIGINFO SIGINT SIGIO SIGIOT SIGKAP SIGKILL SIGKILLTHR SIGLOST SIGLWP \
571 SIGMIGRATE SIGMSG SIGPHONE SIGPIPE SIGPOLL SIGPRE SIGPROF SIGPWR \
572 SIGQUIT SIGRETRACT SIGSAK SIGSEGV SIGSOUND SIGSTKFLT SIGSTOP SIGSYS \
573 SIGTERM SIGTHAW SIGTRAP SIGTSTP SIGTTIN SIGTTOU SIGURG SIGUSR1 \
574 SIGUSR2 SIGVIRT SIGVTALRM SIGWAITING SIGWINCH SIGWIND SIGWINDOW \
575 SIGXCPU SIGXFSZ
576 _sig_syms_re = $(subst $(_sp),|,$(strip $(_sig_names) $(_sig_types_and_consts)))
577
578 # Prohibit the inclusion of signal.h without an actual use.
579 sc_prohibit_signal_without_use:
580 @h='signal.h' \
581 re='\<($(_sig_function_re)) *\(|\<($(_sig_syms_re))\>' \
582 $(_sc_header_without_use)
583
584 # Don't include stdio--.h unless you use one of its functions.
585 sc_prohibit_stdio--_without_use:
586 @h='stdio--.h' re='\<((f(re)?|p)open|tmpfile) *\(' \
587 $(_sc_header_without_use)
588
589 # Don't include stdio-safer.h unless you use one of its functions.
590 sc_prohibit_stdio-safer_without_use:
591 @h='stdio-safer.h' re='\<((f(re)?|p)open|tmpfile)_safer *\(' \
592 $(_sc_header_without_use)
593
594 # Prohibit the inclusion of strings.h without a sensible use.
595 # Using the likes of bcmp, bcopy, bzero, index or rindex is not sensible.
596 sc_prohibit_strings_without_use:
597 @h='strings.h' \
598 re='\<(strn?casecmp|ffs(ll)?)\>' \
599 $(_sc_header_without_use)
600
601 # Get the list of symbol names with this:
602 # perl -lne '/^# *define ([A-Z]\w+)\(/ and print $1' lib/intprops.h|fmt
603 _intprops_names = \
604 TYPE_IS_INTEGER TYPE_TWOS_COMPLEMENT TYPE_ONES_COMPLEMENT \
605 TYPE_SIGNED_MAGNITUDE TYPE_SIGNED TYPE_MINIMUM TYPE_MAXIMUM \
606 INT_BITS_STRLEN_BOUND INT_STRLEN_BOUND INT_BUFSIZE_BOUND \
607 INT_ADD_RANGE_OVERFLOW INT_SUBTRACT_RANGE_OVERFLOW \
608 INT_NEGATE_RANGE_OVERFLOW INT_MULTIPLY_RANGE_OVERFLOW \
609 INT_DIVIDE_RANGE_OVERFLOW INT_REMAINDER_RANGE_OVERFLOW \
610 INT_LEFT_SHIFT_RANGE_OVERFLOW INT_ADD_OVERFLOW INT_SUBTRACT_OVERFLOW \
611 INT_NEGATE_OVERFLOW INT_MULTIPLY_OVERFLOW INT_DIVIDE_OVERFLOW \
612 INT_REMAINDER_OVERFLOW INT_LEFT_SHIFT_OVERFLOW
613 _intprops_syms_re = $(subst $(_sp),|,$(strip $(_intprops_names)))
614 # Prohibit the inclusion of intprops.h without an actual use.
615 sc_prohibit_intprops_without_use:
616 @h='intprops.h' \
617 re='\<($(_intprops_syms_re)) *\(' \
618 $(_sc_header_without_use)
619
620 _stddef_syms_re = NULL|offsetof|ptrdiff_t|size_t|wchar_t
621 # Prohibit the inclusion of stddef.h without an actual use.
622 sc_prohibit_stddef_without_use:
623 @h='stddef.h' \
624 re='\<($(_stddef_syms_re))\>' \
625 $(_sc_header_without_use)
626
627 _de1 = dirfd|(close|(fd)?open|read|rewind|seek|tell)dir(64)?(_r)?
628 _de2 = (versionsort|struct dirent|getdirentries|alphasort|scandir(at)?)(64)?
629 _de3 = MAXNAMLEN|DIR|ino_t|d_ino|d_fileno|d_namlen
630 _dirent_syms_re = $(_de1)|$(_de2)|$(_de3)
631 # Prohibit the inclusion of dirent.h without an actual use.
632 sc_prohibit_dirent_without_use:
633 @h='dirent.h' \
634 re='\<($(_dirent_syms_re))\>' \
635 $(_sc_header_without_use)
636
637 # Prohibit the inclusion of verify.h without an actual use.
638 sc_prohibit_verify_without_use:
639 @h='verify.h' \
640 re='\<(verify(true|expr)?|static_assert) *\(' \
641 $(_sc_header_without_use)
642
643 # Don't include xfreopen.h unless you use one of its functions.
644 sc_prohibit_xfreopen_without_use:
645 @h='xfreopen.h' re='\<xfreopen *\(' $(_sc_header_without_use)
646
647 sc_obsolete_symbols:
648 @prohibit='\<(HAVE''_FCNTL_H|O''_NDELAY)\>' \
649 halt='do not use HAVE''_FCNTL_H or O'_NDELAY \
650 $(_sc_search_regexp)
651
652 # FIXME: warn about definitions of EXIT_FAILURE, EXIT_SUCCESS, STREQ
653
654 # Each nonempty ChangeLog line must start with a year number, or a TAB.
655 sc_changelog:
656 @prohibit='^[^12 ]' \
657 in_vc_files='^ChangeLog$$' \
658 halt='found unexpected prefix in a ChangeLog' \
659 $(_sc_search_regexp)
660
661 # Ensure that each .c file containing a "main" function also
662 # calls set_program_name.
663 sc_program_name:
664 @require='set_program_name *\(m?argv\[0\]\);' \
665 in_vc_files='\.c$$' \
666 containing='\<main *(' \
667 halt='the above files do not call set_program_name' \
668 $(_sc_search_regexp)
669
670 # Ensure that each .c file containing a "main" function also
671 # calls bindtextdomain.
672 sc_bindtextdomain:
673 @require='bindtextdomain *\(' \
674 in_vc_files='\.c$$' \
675 containing='\<main *(' \
676 halt='the above files do not call bindtextdomain' \
677 $(_sc_search_regexp)
678
679 # Require that the final line of each test-lib.sh-using test be this one:
680 # Exit $fail
681 # Note: this test requires GNU grep's --label= option.
682 Exit_witness_file ?= tests/test-lib.sh
683 Exit_base := $(notdir $(Exit_witness_file))
684 sc_require_test_exit_idiom:
685 @if test -f $(srcdir)/$(Exit_witness_file); then \
686 die=0; \
687 for i in $$(grep -l -F 'srcdir/$(Exit_base)' \
688 $$($(VC_LIST) tests)); do \
689 tail -n1 $$i | grep '^Exit .' > /dev/null \
690 && : || { die=1; echo $$i; } \
691 done; \
692 test $$die = 1 && \
693 { echo 1>&2 '$(ME): the final line in each of the above is not:'; \
694 echo 1>&2 'Exit something'; \
695 exit 1; } || :; \
696 fi
697
698 sc_trailing_blank:
699 @prohibit='[ ]$$' \
700 halt='found trailing blank(s)' \
701 $(_sc_search_regexp)
702
703 # Match lines like the following, but where there is only one space
704 # between the options and the description:
705 # -D, --all-repeated[=delimit-method] print all duplicate lines\n
706 longopt_re = --[a-z][0-9A-Za-z-]*(\[?=[0-9A-Za-z-]*\]?)?
707 sc_two_space_separator_in_usage:
708 @prohibit='^ *(-[A-Za-z],)? $(longopt_re) [^ ].*\\$$' \
709 halt='help2man requires at least two spaces between an option and its description'\
710 $(_sc_search_regexp)
711
712 # A regexp matching function names like "error" that may be used
713 # to emit translatable messages.
714 _gl_translatable_diag_func_re ?= error
715
716 # Look for diagnostics that aren't marked for translation.
717 # This won't find any for which error's format string is on a separate line.
718 sc_unmarked_diagnostics:
719 @grep -nE \
720 '\<$(_gl_translatable_diag_func_re) *\([^"]*"[^"]*[a-z]{3}' \
721 $$($(VC_LIST_EXCEPT)) \
722 | grep -Ev '(_|ngettext ?)\(' && \
723 { echo '$(ME): found unmarked diagnostic(s)' 1>&2; \
724 exit 1; } || :
725
726 # Avoid useless parentheses like those in this example:
727 # #if defined (SYMBOL) || defined (SYM2)
728 sc_useless_cpp_parens:
729 @prohibit='^# *if .*defined *\(' \
730 halt='found useless parentheses in cpp directive' \
731 $(_sc_search_regexp)
732
733 # List headers for which HAVE_HEADER_H is always true, assuming you are
734 # using the appropriate gnulib module. CAUTION: for each "unnecessary"
735 # #if HAVE_HEADER_H that you remove, be sure that your project explicitly
736 # requires the gnulib module that guarantees the usability of that header.
737 gl_assured_headers_ = \
738 cd $(gnulib_dir)/lib && echo *.in.h|sed 's/\.in\.h//g'
739
740 # Convert the list of names to upper case, and replace each space with "|".
741 az_ = abcdefghijklmnopqrstuvwxyz
742 AZ_ = ABCDEFGHIJKLMNOPQRSTUVWXYZ
743 gl_header_upper_case_or_ = \
744 $$($(gl_assured_headers_) \
745 | tr $(az_)/.- $(AZ_)___ \
746 | tr -s ' ' '|' \
747 )
748 sc_prohibit_always_true_header_tests:
749 @or=$(gl_header_upper_case_or_); \
750 re="HAVE_($$or)_H"; \
751 prohibit='\<'"$$re"'\>' \
752 halt=$$(printf '%s\n' \
753 'do not test the above HAVE_<header>_H symbol(s);' \
754 ' with the corresponding gnulib module, they are always true') \
755 $(_sc_search_regexp)
756
757 # ==================================================================
758 gl_other_headers_ ?= \
759 intprops.h \
760 openat.h \
761 stat-macros.h
762
763 # Perl -lne code to extract "significant" cpp-defined symbols from a
764 # gnulib header file, eliminating a few common false-positives.
765 # The exempted names below are defined only conditionally in gnulib,
766 # and hence sometimes must/may be defined in application code.
767 gl_extract_significant_defines_ = \
768 /^\# *define ([^_ (][^ (]*)(\s*\(|\s+\w+)/\
769 && $$2 !~ /(?:rpl_|_used_without_)/\
770 && $$1 !~ /^(?:NSIG|ENODATA)$$/\
771 && $$1 !~ /^(?:SA_RESETHAND|SA_RESTART)$$/\
772 and print $$1
773
774 # Create a list of regular expressions matching the names
775 # of macros that are guaranteed to be defined by parts of gnulib.
776 define def_sym_regex
777 gen_h=$(gl_generated_headers_); \
778 (cd $(gnulib_dir)/lib; \
779 for f in *.in.h $(gl_other_headers_); do \
780 test -f $$f \
781 && perl -lne '$(gl_extract_significant_defines_)' $$f; \
782 done; \
783 ) | sort -u \
784 | sed 's/^/^ *# *(define|undef) */;s/$$/\\>/'
785 endef
786
787 # Don't define macros that we already get from gnulib header files.
788 sc_prohibit_always-defined_macros:
789 @if test -d $(gnulib_dir); then \
790 case $$(echo all: | grep -l -f - Makefile) in Makefile);; *) \
791 echo '$(ME): skipping $@: you lack GNU grep' 1>&2; exit 0;; \
792 esac; \
793 $(def_sym_regex) | grep -E -f - $$($(VC_LIST_EXCEPT)) \
794 && { echo '$(ME): define the above via some gnulib .h file' \
795 1>&2; exit 1; } || :; \
796 fi
797 # ==================================================================
798
799 # Prohibit checked in backup files.
800 sc_prohibit_backup_files:
801 @$(VC_LIST) | grep '~$$' && \
802 { echo '$(ME): found version controlled backup file' 1>&2; \
803 exit 1; } || :
804
805 # Require the latest GPL.
806 sc_GPL_version:
807 @prohibit='either ''version [^3]' \
808 halt='GPL vN, N!=3' \
809 $(_sc_search_regexp)
810
811 # Require the latest GFDL. Two regexp, since some .texi files end up
812 # line wrapping between 'Free Documentation License,' and 'Version'.
813 _GFDL_regexp = (Free ''Documentation.*Version 1\.[^3]|Version 1\.[^3] or any)
814 sc_GFDL_version:
815 @prohibit='$(_GFDL_regexp)' \
816 halt='GFDL vN, N!=3' \
817 $(_sc_search_regexp)
818
819 # Don't use Texinfo's @acronym{}.
820 # http://lists.gnu.org/archive/html/bug-gnulib/2010-03/msg00321.html
821 texinfo_suffix_re_ ?= \.(txi|texi(nfo)?)$$
822 sc_texinfo_acronym:
823 @prohibit='@acronym\{' \
824 in_vc_files='$(texinfo_suffix_re_)' \
825 halt='found use of Texinfo @acronym{}' \
826 $(_sc_search_regexp)
827
828 cvs_keywords = \
829 Author|Date|Header|Id|Name|Locker|Log|RCSfile|Revision|Source|State
830
831 sc_prohibit_cvs_keyword:
832 @prohibit='\$$($(cvs_keywords))\$$' \
833 halt='do not use CVS keyword expansion' \
834 $(_sc_search_regexp)
835
836 # This Perl code is slightly obfuscated. Not only is each "$" doubled
837 # because it's in a Makefile, but the $$c's are comments; we cannot
838 # use "#" due to the way the script ends up concatenated onto one line.
839 # It would be much more concise, and would produce better output (including
840 # counts) if written as:
841 # perl -ln -0777 -e '/\n(\n+)$/ and print "$ARGV: ".length $1' ...
842 # but that would be far less efficient, reading the entire contents
843 # of each file, rather than just the last two bytes of each.
844 # In addition, while the code below detects both blank lines and a missing
845 # newline at EOF, the above detects only the former.
846 #
847 # This is a perl script that is expected to be the single-quoted argument
848 # to a command-line "-le". The remaining arguments are file names.
849 # Print the name of each file that ends in exactly one newline byte.
850 # I.e., warn if there are blank lines (2 or more newlines), or if the
851 # last byte is not a newline. However, currently we don't complain
852 # about any file that contains exactly one byte.
853 # Exit nonzero if at least one such file is found, otherwise, exit 0.
854 # Warn about, but otherwise ignore open failure. Ignore seek/read failure.
855 #
856 # Use this if you want to remove trailing empty lines from selected files:
857 # perl -pi -0777 -e 's/\n\n+$/\n/' files...
858 #
859 require_exactly_one_NL_at_EOF_ = \
860 foreach my $$f (@ARGV) \
861 { \
862 open F, "<", $$f or (warn "failed to open $$f: $$!\n"), next; \
863 my $$p = sysseek (F, -2, 2); \
864 my $$c = "seek failure probably means file has < 2 bytes; ignore"; \
865 my $$last_two_bytes; \
866 defined $$p and $$p = sysread F, $$last_two_bytes, 2; \
867 close F; \
868 $$c = "ignore read failure"; \
869 $$p && ($$last_two_bytes eq "\n\n" \
870 || substr ($$last_two_bytes,1) ne "\n") \
871 and (print $$f), $$fail=1; \
872 } \
873 END { exit defined $$fail }
874 sc_prohibit_empty_lines_at_EOF:
875 @perl -le '$(require_exactly_one_NL_at_EOF_)' $$($(VC_LIST_EXCEPT)) \
876 || { echo '$(ME): empty line(s) or no newline at EOF' \
877 1>&2; exit 1; } || :
878
879 # Make sure we don't use st_blocks. Use ST_NBLOCKS instead.
880 # This is a bit of a kludge, since it prevents use of the string
881 # even in comments, but for now it does the job with no false positives.
882 sc_prohibit_stat_st_blocks:
883 @prohibit='[.>]st_blocks' \
884 halt='do not use st_blocks; use ST_NBLOCKS' \
885 $(_sc_search_regexp)
886
887 # Make sure we don't define any S_IS* macros in src/*.c files.
888 # They're already defined via gnulib's sys/stat.h replacement.
889 sc_prohibit_S_IS_definition:
890 @prohibit='^ *# *define *S_IS' \
891 halt='do not define S_IS* macros; include <sys/stat.h>' \
892 $(_sc_search_regexp)
893
894 # Perl block to convert a match to FILE_NAME:LINENO:TEST,
895 # that is shared by two definitions below.
896 perl_filename_lineno_text_ = \
897 -e ' {' \
898 -e ' $$n = ($$` =~ tr/\n/\n/ + 1);' \
899 -e ' ($$v = $$&) =~ s/\n/\\n/g;' \
900 -e ' print "$$ARGV:$$n:$$v\n";' \
901 -e ' }'
902
903 prohibit_doubled_word_RE_ ?= \
904 /\b(then?|[iao]n|i[fst]|but|f?or|at|and|[dt]o)\s+\1\b/gims
905 prohibit_doubled_word_ = \
906 -e 'while ($(prohibit_doubled_word_RE_))' \
907 $(perl_filename_lineno_text_)
908
909 # Define this to a regular expression that matches
910 # any filename:dd:match lines you want to ignore.
911 # The default is to ignore no matches.
912 ignore_doubled_word_match_RE_ ?= ^$$
913
914 sc_prohibit_doubled_word:
915 @perl -n -0777 $(prohibit_doubled_word_) $$($(VC_LIST_EXCEPT)) \
916 | grep -vE '$(ignore_doubled_word_match_RE_)' \
917 | grep . && { echo '$(ME): doubled words' 1>&2; exit 1; } || :
918
919 # A regular expression matching undesirable combinations of words like
920 # "can not"; this matches them even when the two words appear on different
921 # lines, but not when there is an intervening delimiter like "#" or "*".
922 prohibit_undesirable_word_seq_RE_ ?= \
923 /\bcan\s+not\b/gims
924 prohibit_undesirable_word_seq_ = \
925 -e 'while ($(prohibit_undesirable_word_seq_RE_))' \
926 $(perl_filename_lineno_text_)
927 # Define this to a regular expression that matches
928 # any filename:dd:match lines you want to ignore.
929 # The default is to ignore no matches.
930 ignore_undesirable_word_sequence_RE_ ?= ^$$
931
932 sc_prohibit_undesirable_word_seq:
933 @perl -n -0777 $(prohibit_undesirable_word_seq_) \
934 $$($(VC_LIST_EXCEPT)) \
935 | grep -vE '$(ignore_undesirable_word_sequence_RE_)' | grep . \
936 && { echo '$(ME): undesirable word sequence' >&2; exit 1; } || :
937
938 _ptm1 = use "test C1 && test C2", not "test C1 -''a C2"
939 _ptm2 = use "test C1 || test C2", not "test C1 -''o C2"
940 # Using test's -a and -o operators is not portable.
941 # We prefer test over [, since the latter is spelled [[ in configure.ac.
942 sc_prohibit_test_minus_ao:
943 @prohibit='(\<test| \[+) .+ -[ao] ' \
944 halt='$(_ptm1); $(_ptm2)' \
945 $(_sc_search_regexp)
946
947 # Avoid a test bashism.
948 sc_prohibit_test_double_equal:
949 @prohibit='(\<test| \[+) .+ == ' \
950 containing='#! */bin/[a-z]*sh' \
951 halt='use "test x = x", not "test x =''= x"' \
952 $(_sc_search_regexp)
953
954 # Each program that uses proper_name_utf8 must link with one of the
955 # ICONV libraries. Otherwise, some ICONV library must appear in LDADD.
956 # The perl -0777 invocation below extracts the possibly-multi-line
957 # definition of LDADD from the appropriate Makefile.am and exits 0
958 # when it contains "ICONV".
959 sc_proper_name_utf8_requires_ICONV:
960 @progs=$$(grep -l 'proper_name_utf8 ''("' $$($(VC_LIST_EXCEPT)));\
961 if test "x$$progs" != x; then \
962 fail=0; \
963 for p in $$progs; do \
964 dir=$$(dirname "$$p"); \
965 perl -0777 \
966 -ne 'exit !(/^LDADD =(.+?[^\\]\n)/ms && $$1 =~ /ICONV/)' \
967 $$dir/Makefile.am && continue; \
968 base=$$(basename "$$p" .c); \
969 grep "$${base}_LDADD.*ICONV)" $$dir/Makefile.am > /dev/null \
970 || { fail=1; echo 1>&2 "$(ME): $$p uses proper_name_utf8"; }; \
971 done; \
972 test $$fail = 1 && \
973 { echo 1>&2 '$(ME): the above do not link with any ICONV library'; \
974 exit 1; } || :; \
975 fi
976
977 # Warn about "c0nst struct Foo const foo[]",
978 # but not about "char const *const foo" or "#define const const".
979 sc_redundant_const:
980 @prohibit='\bconst\b[[:space:][:alnum:]]{2,}\bconst\b' \
981 halt='redundant "const" in declarations' \
982 $(_sc_search_regexp)
983
984 sc_const_long_option:
985 @grep '^ *static.*struct option ' $$($(VC_LIST_EXCEPT)) \
986 | grep -Ev 'const struct option|struct option const' && { \
987 echo 1>&2 '$(ME): add "const" to the above declarations'; \
988 exit 1; } || :
989
990 NEWS_hash = \
991 $$(sed -n '/^\*.* $(PREV_VERSION_REGEXP) ([0-9-]*)/,$$p' \
992 $(srcdir)/NEWS \
993 | perl -0777 -pe \
994 's/^Copyright.+?Free\sSoftware\sFoundation,\sInc\.\n//ms' \
995 | md5sum - \
996 | sed 's/ .*//')
997
998 # Ensure that we don't accidentally insert an entry into an old NEWS block.
999 sc_immutable_NEWS:
1000 @if test -f $(srcdir)/NEWS; then \
1001 test "$(NEWS_hash)" = '$(old_NEWS_hash)' && : || \
1002 { echo '$(ME): you have modified old NEWS' 1>&2; exit 1; }; \
1003 fi
1004
1005 # Update the hash stored above. Do this after each release and
1006 # for any corrections to old entries.
1007 update-NEWS-hash: NEWS
1008 perl -pi -e 's/^(old_NEWS_hash[ \t]+:?=[ \t]+).*/$${1}'"$(NEWS_hash)/" \
1009 $(srcdir)/$(_build-aux)/cfg.mk
1010
1011 # Ensure that we use only the standard $(VAR) notation,
1012 # not @...@ in Makefile.am, now that we can rely on automake
1013 # to emit a definition for each substituted variable.
1014 # However, there is still one case in which @VAR@ use is not just
1015 # legitimate, but actually required: when augmenting an automake-defined
1016 # variable with a prefix. For example, gettext uses this:
1017 # MAKEINFO = env LANG= LC_MESSAGES= LC_ALL= LANGUAGE= @MAKEINFO@
1018 # otherwise, makeinfo would put German or French (current locale)
1019 # navigation hints in the otherwise-English documentation.
1020 #
1021 # Allow the package to add exceptions via a hook in cfg.mk;
1022 # for example, @PRAGMA_SYSTEM_HEADER@ can be permitted by
1023 # setting this to ' && !/PRAGMA_SYSTEM_HEADER/'.
1024 _makefile_at_at_check_exceptions ?=
1025 sc_makefile_at_at_check:
1026 @perl -ne '/\@[A-Z_0-9]+\@/' \
1027 -e ' && !/([A-Z_0-9]+)\s+=.*\@\1\@$$/' \
1028 -e ''$(_makefile_at_at_check_exceptions) \
1029 -e 'and (print "$$ARGV:$$.: $$_"), $$m=1; END {exit !$$m}' \
1030 $$($(VC_LIST_EXCEPT) | grep -E '(^|/)(Makefile\.am|[^/]+\.mk)$$') \
1031 && { echo '$(ME): use $$(...), not @...@' 1>&2; exit 1; } || :
1032
1033 news-check: NEWS
1034 if sed -n $(news-check-lines-spec)p $(srcdir)/NEWS \
1035 | grep -E $(news-check-regexp) >/dev/null; then \
1036 :; \
1037 else \
1038 echo 'NEWS: $$(news-check-regexp) failed to match' 1>&2; \
1039 exit 1; \
1040 fi
1041
1042 sc_makefile_TAB_only_indentation:
1043 @prohibit='^ [ ]{8}' \
1044 in_vc_files='akefile|\.mk$$' \
1045 halt='found TAB-8-space indentation' \
1046 $(_sc_search_regexp)
1047
1048 sc_m4_quote_check:
1049 @prohibit='(AC_DEFINE(_UNQUOTED)?|AC_DEFUN)\([^[]' \
1050 in_vc_files='(^configure\.ac|\.m4)$$' \
1051 halt='quote the first arg to AC_DEF*' \
1052 $(_sc_search_regexp)
1053
1054 fix_po_file_diag = \
1055 'you have changed the set of files with translatable diagnostics;\n\
1056 apply the above patch\n'
1057
1058 # Verify that all source files using _() are listed in po/POTFILES.in.
1059 po_file ?= $(srcdir)/po/POTFILES.in
1060 generated_files ?= $(srcdir)/lib/*.[ch]
1061 sc_po_check:
1062 @if test -f $(po_file); then \
1063 grep -E -v '^(#|$$)' $(po_file) \
1064 | grep -v '^src/false\.c$$' \
1065 | sed 's|\[type: gettext/glade\] ||' \
1066 | sort > $@-1; \
1067 files=; \
1068 for file in $$($(VC_LIST_EXCEPT)) $(generated_files); do \
1069 test -r $$file || continue; \
1070 case $$file in \
1071 *.m4|*.mk) continue ;; \
1072 *.?|*.??) ;; \
1073 *.xml) ;; \
1074 *.xml.in) ;; \
1075 *.desktop.in) ;; \
1076 *) continue;; \
1077 esac; \
1078 case $$file in \
1079 *.[ch]) \
1080 base=`expr " $$file" : ' \(.*\)\..'`; \
1081 { test -f $$base.l || test -f $$base.y; } && continue;; \
1082 esac; \
1083 files="$$files $$file"; \
1084 done; \
1085 grep -E -l '(\b(N?_|gettext *)\([^)"]*("|$$))|(<interface>)|^_|<_' $$files \
1086 | sed 's|^$(_dot_escaped_srcdir)/||' | sort -u > $@-2; \
1087 diff -u -L $(po_file) -L $(po_file) $@-1 $@-2 \
1088 || { printf '$(ME): '$(fix_po_file_diag) 1>&2; exit 1; }; \
1089 rm -f $@-1 $@-2; \
1090 fi
1091
1092 # Sometimes it is useful to change the PATH environment variable
1093 # in Makefiles. When doing so, it's better not to use the Unix-centric
1094 # path separator of `:', but rather the automake-provided `$(PATH_SEPARATOR)'.
1095 msg = '$(ME): Do not use `:'\'' above; use $$(PATH_SEPARATOR) instead'
1096 sc_makefile_path_separator_check:
1097 @prohibit='PATH[=].*:' \
1098 in_vc_files='akefile|\.mk$$' \
1099 halt=$(msg) \
1100 $(_sc_search_regexp)
1101
1102 # Check that `make alpha' will not fail at the end of the process,
1103 # i.e., when pkg-M.N.tar.xz already exists (either in "." or in ../release)
1104 # and is read-only.
1105 writable-files:
1106 if test -d $(release_archive_dir); then \
1107 for file in $(DIST_ARCHIVES); do \
1108 for p in ./ $(release_archive_dir)/; do \
1109 test -e $$p$$file || continue; \
1110 test -w $$p$$file \
1111 || { echo ERROR: $$p$$file is not writable; fail=1; }; \
1112 done; \
1113 done; \
1114 test "$$fail" && exit 1 || : ; \
1115 else :; \
1116 fi
1117
1118 v_etc_file = $(gnulib_dir)/lib/version-etc.c
1119 sample-test = tests/sample-test
1120 texi = doc/$(PACKAGE).texi
1121 # Make sure that the copyright date in $(v_etc_file) is up to date.
1122 # Do the same for the $(sample-test) and the main doc/.texi file.
1123 sc_copyright_check:
1124 @require='enum { COPYRIGHT_YEAR = '$$(date +%Y)' };' \
1125 in_files=$(v_etc_file) \
1126 halt='out of date copyright in $(v_etc_file); update it' \
1127 $(_sc_search_regexp)
1128 @require='# Copyright \(C\) '$$(date +%Y)' Free' \
1129 in_vc_files=$(sample-test) \
1130 halt='out of date copyright in $(sample-test); update it' \
1131 $(_sc_search_regexp)
1132 @require='Copyright @copyright\{\} .*'$$(date +%Y)' Free' \
1133 in_vc_files=$(texi) \
1134 halt='out of date copyright in $(texi); update it' \
1135 $(_sc_search_regexp)
1136
1137 # If tests/help-version exists and seems to be new enough, assume that its
1138 # use of init.sh and path_prepend_ is correct, and ensure that every other
1139 # use of init.sh is identical.
1140 # This is useful because help-version cross-checks prog --version
1141 # with $(VERSION), which verifies that its path_prepend_ invocation
1142 # sets PATH correctly. This is an inexpensive way to ensure that
1143 # the other init.sh-using tests also get it right.
1144 _hv_file ?= $(srcdir)/tests/help-version
1145 _hv_regex_weak ?= ^ *\. .*/init\.sh"
1146 # Fix syntax-highlighters "
1147 _hv_regex_strong ?= ^ *\. "\$${srcdir=\.}/init\.sh"
1148 sc_cross_check_PATH_usage_in_tests:
1149 @if test -f $(_hv_file); then \
1150 grep -l 'VERSION mismatch' $(_hv_file) >/dev/null \
1151 || { echo "$@: skipped: no such file: $(_hv_file)" 1>&2; \
1152 exit 0; }; \
1153 grep -lE '$(_hv_regex_strong)' $(_hv_file) >/dev/null \
1154 || { echo "$@: $(_hv_file) lacks conforming use of init.sh" 1>&2; \
1155 exit 1; }; \
1156 good=$$(grep -E '$(_hv_regex_strong)' $(_hv_file)); \
1157 grep -LFx "$$good" \
1158 $$(grep -lE '$(_hv_regex_weak)' $$($(VC_LIST_EXCEPT))) \
1159 | grep . && \
1160 { echo "$(ME): the above files use path_prepend_ inconsistently" \
1161 1>&2; exit 1; } || :; \
1162 fi
1163
1164 # #if HAVE_... will evaluate to false for any non numeric string.
1165 # That would be flagged by using -Wundef, however gnulib currently
1166 # tests many undefined macros, and so we can't enable that option.
1167 # So at least preclude common boolean strings as macro values.
1168 sc_Wundef_boolean:
1169 @prohibit='^#define.*(yes|no|true|false)$$' \
1170 in_files='$(CONFIG_INCLUDE)' \
1171 halt='Use 0 or 1 for macro values' \
1172 $(_sc_search_regexp)
1173
1174 # Even if you use pathmax.h to guarantee that PATH_MAX is defined, it might
1175 # not be constant, or might overflow a stack. In general, use PATH_MAX as
1176 # a limit, not an array or alloca size.
1177 sc_prohibit_path_max_allocation:
1178 @prohibit='(\balloca *\([^)]*|\[[^]]*)PATH_MAX' \
1179 halt='Avoid stack allocations of size PATH_MAX' \
1180 $(_sc_search_regexp)
1181
1182 sc_vulnerable_makefile_CVE-2009-4029:
1183 @prohibit='perm -777 -exec chmod a\+rwx|chmod 777 \$$\(distdir\)' \
1184 in_files=$$(find $(srcdir) -name Makefile.in) \
1185 halt=$$(printf '%s\n' \
1186 'the above files are vulnerable; beware of running' \
1187 ' "make dist*" rules, and upgrade to fixed automake' \
1188 ' see http://bugzilla.redhat.com/542609 for details') \
1189 $(_sc_search_regexp)
1190
1191 vc-diff-check:
1192 (unset CDPATH; cd $(srcdir) && $(VC) diff) > vc-diffs || :
1193 if test -s vc-diffs; then \
1194 cat vc-diffs; \
1195 echo "Some files are locally modified:" 1>&2; \
1196 exit 1; \
1197 else \
1198 rm vc-diffs; \
1199 fi
1200
1201 rel-files = $(DIST_ARCHIVES)
1202
1203 gnulib_dir ?= $(srcdir)/gnulib
1204 gnulib-version = $$(cd $(gnulib_dir) && git describe)
1205 bootstrap-tools ?= autoconf,automake,gnulib
1206
1207 # If it's not already specified, derive the GPG key ID from
1208 # the signed tag we've just applied to mark this release.
1209 gpg_key_ID ?= \
1210 $$(git cat-file tag v$(VERSION) > .ann-sig \
1211 && gpgv .ann-sig - < /dev/null 2>&1 \
1212 | sed -n '/.*key ID \([0-9A-F]*\)/s//\1/p'; rm -f .ann-sig)
1213
1214 translation_project_ ?= coordinator@translationproject.org
1215
1216 # Make info-gnu the default only for a stable release.
1217 ifeq ($(RELEASE_TYPE),stable)
1218 announcement_Cc_ ?= $(translation_project_), $(PACKAGE_BUGREPORT)
1219 announcement_mail_headers_ ?= \
1220 To: info-gnu@gnu.org \
1221 Cc: $(announcement_Cc_) \
1222 Mail-Followup-To: $(PACKAGE_BUGREPORT)
1223 else
1224 announcement_Cc_ ?= $(translation_project_)
1225 announcement_mail_headers_ ?= \
1226 To: $(PACKAGE_BUGREPORT) \
1227 Cc: $(announcement_Cc_)
1228 endif
1229
1230 announcement: NEWS ChangeLog $(rel-files)
1231 @$(srcdir)/$(_build-aux)/announce-gen \
1232 --mail-headers='$(announcement_mail_headers_)' \
1233 --release-type=$(RELEASE_TYPE) \
1234 --package=$(PACKAGE) \
1235 --prev=$(PREV_VERSION) \
1236 --curr=$(VERSION) \
1237 --gpg-key-id=$(gpg_key_ID) \
1238 --news=$(srcdir)/NEWS \
1239 --bootstrap-tools=$(bootstrap-tools) \
1240 --gnulib-version=$(gnulib-version) \
1241 --no-print-checksums \
1242 $(addprefix --url-dir=, $(url_dir_list))
1243
1244 ## ---------------- ##
1245 ## Updating files. ##
1246 ## ---------------- ##
1247
1248 ftp-gnu = ftp://ftp.gnu.org/gnu
1249 www-gnu = http://www.gnu.org
1250
1251 upload_dest_dir_ ?= $(PACKAGE)
1252 emit_upload_commands:
1253 @echo =====================================
1254 @echo =====================================
1255 @echo "$(srcdir)/$(_build-aux)/gnupload $(GNUPLOADFLAGS) \\"
1256 @echo " --to $(gnu_rel_host):$(upload_dest_dir_) \\"
1257 @echo " $(rel-files)"
1258 @echo '# send the ~/announce-$(my_distdir) e-mail'
1259 @echo =====================================
1260 @echo =====================================
1261
1262 define emit-commit-log
1263 printf '%s\n' 'maint: post-release administrivia' '' \
1264 '* NEWS: Add header line for next release.' \
1265 '* .prev-version: Record previous version.' \
1266 '* cfg.mk (old_NEWS_hash): Auto-update.'
1267 endef
1268
1269 .PHONY: no-submodule-changes
1270 no-submodule-changes:
1271 if test -d $(srcdir)/.git; then \
1272 diff=$$(cd $(srcdir) && git submodule -q foreach \
1273 git diff-index --name-only HEAD) \
1274 || exit 1; \
1275 case $$diff in '') ;; \
1276 *) echo '$(ME): submodule files are locally modified:'; \
1277 echo "$$diff"; exit 1;; esac; \
1278 else \
1279 : ; \
1280 fi
1281
1282 submodule-checks ?= no-submodule-changes public-submodule-commit
1283
1284 # Ensure that each sub-module commit we're using is public.
1285 # Without this, it is too easy to tag and release code that
1286 # cannot be built from a fresh clone.
1287 .PHONY: public-submodule-commit
1288 public-submodule-commit:
1289 $(AM_V_GEN)if test -d $(srcdir)/.git; then \
1290 cd $(srcdir) && \
1291 git submodule --quiet foreach test '$$(git rev-parse $$sha1)' \
1292 = '$$(git merge-base origin $$sha1)' \
1293 || { echo '$(ME): found non-public submodule commit' >&2; \
1294 exit 1; }; \
1295 else \
1296 : ; \
1297 fi
1298 # This rule has a high enough utility/cost ratio that it should be a
1299 # dependent of "check" by default. However, some of us do occasionally
1300 # commit a temporary change that deliberately points to a non-public
1301 # submodule commit, and want to be able to use rules like "make check".
1302 # In that case, run e.g., "make check gl_public_submodule_commit="
1303 # to disable this test.
1304 gl_public_submodule_commit ?= public-submodule-commit
1305 check: $(gl_public_submodule_commit)
1306
1307 .PHONY: alpha beta stable
1308 ALL_RECURSIVE_TARGETS += alpha beta stable
1309 alpha beta stable: $(local-check) writable-files $(submodule-checks)
1310 test $@ = stable \
1311 && { echo $(VERSION) | grep -E '^[0-9]+(\.[0-9]+)+$$' \
1312 || { echo "invalid version string: $(VERSION)" 1>&2; exit 1;};}\
1313 || :
1314 $(MAKE) vc-diff-check
1315 $(MAKE) news-check
1316 $(MAKE) distcheck
1317 $(MAKE) dist XZ_OPT=-9ev
1318 $(MAKE) $(release-prep-hook) RELEASE_TYPE=$@
1319 $(MAKE) -s emit_upload_commands RELEASE_TYPE=$@
1320
1321 # Override this in cfg.mk if you follow different procedures.
1322 release-prep-hook ?= release-prep
1323
1324 gl_noteworthy_news_ = * Noteworthy changes in release ?.? (????-??-??) [?]
1325 .PHONY: release-prep
1326 release-prep:
1327 case $$RELEASE_TYPE in alpha|beta|stable) ;; \
1328 *) echo "invalid RELEASE_TYPE: $$RELEASE_TYPE" 1>&2; exit 1;; esac
1329 $(MAKE) --no-print-directory -s announcement > ~/announce-$(my_distdir)
1330 if test -d $(release_archive_dir); then \
1331 ln $(rel-files) $(release_archive_dir); \
1332 chmod a-w $(rel-files); \
1333 fi
1334 echo $(VERSION) > $(prev_version_file)
1335 $(MAKE) update-NEWS-hash
1336 perl -pi -e '$$. == 3 and print "$(gl_noteworthy_news_)\n\n\n"' NEWS
1337 $(emit-commit-log) > .ci-msg
1338 $(VC) commit -F .ci-msg -a
1339 rm .ci-msg
1340
1341 # Override this with e.g., -s $(srcdir)/some_other_name.texi
1342 # if the default $(PACKAGE)-derived name doesn't apply.
1343 gendocs_options_ ?=
1344
1345 .PHONY: web-manual
1346 web-manual:
1347 @test -z "$(manual_title)" \
1348 && { echo define manual_title in cfg.mk 1>&2; exit 1; } || :
1349 @cd '$(srcdir)/doc'; \
1350 $(SHELL) ../$(_build-aux)/gendocs.sh $(gendocs_options_) \
1351 -o '$(abs_builddir)/doc/manual' \
1352 --email $(PACKAGE_BUGREPORT) $(PACKAGE) \
1353 "$(PACKAGE_NAME) - $(manual_title)"
1354 @echo " *** Upload the doc/manual directory to web-cvs."
1355
1356 # Code Coverage
1357
1358 init-coverage:
1359 $(MAKE) $(AM_MAKEFLAGS) clean
1360 lcov --directory . --zerocounters
1361
1362 COVERAGE_CCOPTS ?= "-g --coverage"
1363 COVERAGE_OUT ?= doc/coverage
1364
1365 build-coverage:
1366 $(MAKE) $(AM_MAKEFLAGS) CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS)
1367 $(MAKE) $(AM_MAKEFLAGS) CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS) check
1368 mkdir -p $(COVERAGE_OUT)
1369 lcov --directory . --output-file $(COVERAGE_OUT)/$(PACKAGE).info \
1370 --capture
1371
1372 gen-coverage:
1373 genhtml --output-directory $(COVERAGE_OUT) \
1374 $(COVERAGE_OUT)/$(PACKAGE).info \
1375 --highlight --frames --legend \
1376 --title "$(PACKAGE_NAME)"
1377
1378 coverage: init-coverage build-coverage gen-coverage
1379
1380 # Update gettext files.
1381 PACKAGE ?= $(shell basename $(PWD))
1382 PO_DOMAIN ?= $(PACKAGE)
1383 POURL = http://translationproject.org/latest/$(PO_DOMAIN)/
1384 PODIR ?= po
1385 refresh-po:
1386 rm -f $(PODIR)/*.po && \
1387 echo "$(ME): getting translations into po (please ignore the robots.txt ERROR 404)..." && \
1388 wget --no-verbose --directory-prefix $(PODIR) --no-directories --recursive --level 1 --accept .po --accept .po.1 $(POURL) && \
1389 echo 'en@boldquot' > $(PODIR)/LINGUAS && \
1390 echo 'en@quot' >> $(PODIR)/LINGUAS && \
1391 ls $(PODIR)/*.po | sed 's/\.po//' | sed 's,$(PODIR)/,,' | sort >> $(PODIR)/LINGUAS
1392
1393 # Running indent once is not idempotent, but running it twice is.
1394 INDENT_SOURCES ?= $(C_SOURCES)
1395 .PHONY: indent
1396 indent:
1397 indent $(INDENT_SOURCES)
1398 indent $(INDENT_SOURCES)
1399
1400 # If you want to set UPDATE_COPYRIGHT_* environment variables,
1401 # put the assignments in this variable.
1402 update-copyright-env ?=
1403
1404 # Run this rule once per year (usually early in January)
1405 # to update all FSF copyright year lists in your project.
1406 # If you have an additional project-specific rule,
1407 # add it in cfg.mk along with a line 'update-copyright: prereq'.
1408 # By default, exclude all variants of COPYING; you can also
1409 # add exemptions (such as ChangeLog..* for rotated change logs)
1410 # in the file .x-update-copyright.
1411 .PHONY: update-copyright
1412 update-copyright:
1413 grep -l -w Copyright \
1414 $$(export VC_LIST_EXCEPT_DEFAULT=COPYING && $(VC_LIST_EXCEPT)) \
1415 | $(update-copyright-env) xargs $(srcdir)/$(_build-aux)/$@
1416
1417 # This tight_scope test is skipped with a warning if $(_gl_TS_headers) is not
1418 # overridden and $(_gl_TS_dir)/Makefile.am does not mention noinst_HEADERS.
1419
1420 # NOTE: to override any _gl_TS_* default value, you must
1421 # define the variable(s) using "export" in cfg.mk.
1422 _gl_TS_dir ?= src
1423
1424 ALL_RECURSIVE_TARGETS += sc_tight_scope
1425 sc_tight_scope: tight-scope.mk
1426 @fail=0; \
1427 if ! grep '^ *export _gl_TS_headers *=' $(srcdir)/$(_build-aux)/cfg.mk \
1428 > /dev/null \
1429 && ! grep -w noinst_HEADERS $(srcdir)/$(_gl_TS_dir)/Makefile.am \
1430 > /dev/null 2>&1; then \
1431 echo '$(ME): skipping $@'; \
1432 else \
1433 $(MAKE) -s -C $(_gl_TS_dir) \
1434 -f Makefile \
1435 -f $(abs_top_srcdir)/$(_build-aux)/cfg.mk \
1436 -f $(abs_top_builddir)/$< \
1437 _gl_tight_scope \
1438 || fail=1; \
1439 fi; \
1440 rm -f $<; \
1441 exit $$fail
1442
1443 tight-scope.mk: $(ME)
1444 @rm -f $@ $@-t
1445 @perl -ne '/^# TS-start/.../^# TS-end/ and print' $(ME) > $@-t
1446 @chmod a=r $@-t && mv $@-t $@
1447
1448 ifeq (a,b)
1449 # TS-start
1450
1451 # Most functions should have static scope.
1452 # Any that don't must be marked with `extern', but `main'
1453 # and `usage' are exceptions: they're always extern, but
1454 # do not need to be marked. Symbols matching `__.*' are
1455 # reserved by the compiler, so are automatically excluded below.
1456 _gl_TS_unmarked_extern_functions ?= main usage
1457 _gl_TS_function_match ?= /^(?:$(_gl_TS_extern)) +.*?(\S+) *\(/
1458
1459 # If your project uses a macro like "XTERN", then put
1460 # the following in cfg.mk to override this default:
1461 # export _gl_TS_extern = extern|XTERN
1462 _gl_TS_extern ?= extern
1463
1464 # The second nm|grep checks for file-scope variables with `extern' scope.
1465 # Without gnulib's progname module, you might put program_name here.
1466 # Symbols matching `__.*' are reserved by the compiler,
1467 # so are automatically excluded below.
1468 _gl_TS_unmarked_extern_vars ?=
1469
1470 # NOTE: the _match variables are perl expressions -- not mere regular
1471 # expressions -- so that you can extend them to match other patterns
1472 # and easily extract matched variable names.
1473 # For example, if your project declares some global variables via
1474 # a macro like this: GLOBAL(type, var_name, initializer), then you
1475 # can override this definition to automatically extract those names:
1476 # export _gl_TS_var_match = \
1477 # /^(?:$(_gl_TS_extern)) .*?\**(\w+)(\[.*?\])?;/ || /\bGLOBAL\(.*?,\s*(.*?),/
1478 _gl_TS_var_match ?= /^(?:$(_gl_TS_extern)) .*?(\w+)(\[.*?\])?;/
1479
1480 # The names of object files in (or relative to) $(_gl_TS_dir).
1481 _gl_TS_obj_files ?= *.$(OBJEXT)
1482
1483 # Files in which to search for the one-line style extern declarations.
1484 # $(_gl_TS_dir)-relative.
1485 _gl_TS_headers ?= $(noinst_HEADERS)
1486
1487 .PHONY: _gl_tight_scope
1488 _gl_tight_scope: $(bin_PROGRAMS)
1489 t=exceptions-$$$$; \
1490 trap 's=$$?; rm -f $$t; exit $$s' 0; \
1491 for sig in 1 2 3 13 15; do \
1492 eval "trap 'v=`expr $$sig + 128`; (exit $$v); exit $$v' $$sig"; \
1493 done; \
1494 src=`for f in $(SOURCES); do \
1495 test -f $$f && d= || d=$(srcdir)/; echo $$d$$f; done`; \
1496 hdr=`for f in $(_gl_TS_headers); do \
1497 test -f $$f && d= || d=$(srcdir)/; echo $$d$$f; done`; \
1498 ( printf '^%s$$\n' '__.*' $(_gl_TS_unmarked_extern_functions); \
1499 grep -h -A1 '^extern .*[^;]$$' $$src \
1500 | grep -vE '^(extern |--)' | sed 's/ .*//'; \
1501 perl -lne \
1502 '$(_gl_TS_function_match) and print "^$$1\$$"' $$hdr; \
1503 ) | sort -u > $$t; \
1504 nm -e $(_gl_TS_obj_files) | sed -n 's/.* T //p'|grep -Ev -f $$t \
1505 && { echo the above functions should have static scope >&2; \
1506 exit 1; } || : ; \
1507 ( printf '^%s$$\n' '__.*' $(_gl_TS_unmarked_extern_vars); \
1508 perl -lne '$(_gl_TS_var_match) and print "^$$1\$$"' $$hdr *.h \
1509 ) | sort -u > $$t; \
1510 nm -e $(_gl_TS_obj_files) | sed -n 's/.* [BCDGRS] //p' \
1511 | sort -u | grep -Ev -f $$t \
1512 && { echo the above variables should have static scope >&2; \
1513 exit 1; } || :
1514 # TS-end
1515 endif
+0
-124
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 # Tests not to run as part of "make distcheck".
18 local-checks-to-skip = \
19 changelog-check \
20 makefile-check \
21 makefile_path_separator_check \
22 patch-check \
23 sc_GPL_version \
24 sc_always_defined_macros \
25 sc_bindtextdomain \
26 sc_cast_of_alloca_return_value \
27 sc_cross_check_PATH_usage_in_tests \
28 sc_dd_max_sym_length \
29 sc_error_exit_success \
30 sc_file_system \
31 sc_immutable_NEWS \
32 sc_makefile_path_separator_check \
33 sc_obsolete_symbols \
34 sc_prohibit_always_true_header_tests \
35 sc_prohibit_S_IS_definition \
36 sc_prohibit_atoi_atof \
37 sc_prohibit_hash_without_use \
38 sc_prohibit_jm_in_m4 \
39 sc_prohibit_quote_without_use \
40 sc_prohibit_quotearg_without_use \
41 sc_prohibit_stat_st_blocks \
42 sc_root_tests \
43 sc_space_tab \
44 sc_sun_os_names \
45 sc_system_h_headers \
46 sc_texinfo_acronym \
47 sc_tight_scope \
48 sc_two_space_separator_in_usage \
49 sc_error_message_uppercase \
50 sc_program_name \
51 sc_require_test_exit_idiom \
52 sc_makefile_check \
53 sc_useless_cpp_parens
54
55 # Files that should never cause syntax check failures.
56 VC_LIST_ALWAYS_EXCLUDE_REGEX = \
57 (^HACKING|\.po|maint.mk)$$
58
59 # Functions like free() that are no-ops on NULL arguments.
60 useless_free_options = \
61 --name=g_free \
62 --name=xmlBufferFree \
63 --name=xmlFree \
64 --name=xmlFreeDoc \
65 --name=xmlXPathFreeContext \
66 --name=xmlFreeParserContext \
67 --name=xmlXPathFreeObject
68
69 # Ensure that no C source file, docs, or rng schema uses TABs for
70 # indentation. Also match *.h.in files, to get libvirt.h.in. Exclude
71 # files in gnulib, since they're imported.
72 space_indent_files=(\.(rng|s?[ch](\.in)?|html.in|py)|(daemon|tools)/.*\.in)
73 sc_TAB_in_indentation:
74 @prohibit='^ * ' \
75 in_vc_files='$(space_indent_files)$$' \
76 halt='indent with space, not TAB, in C, sh, html, py, and RNG schemas' \
77 $(_sc_search_regexp)
78
79 # G_GNUC_UNUSED should only be applied in implementations, not
80 # header declarations
81 sc_avoid_attribute_unused_in_header:
82 @prohibit='^[^#]*G_GNUC_UNUSED([^:]|$$)' \
83 in_vc_files='\.h$$' \
84 halt='use G_GNUC_UNUSED in .c rather than .h files' \
85 $(_sc_search_regexp)
86
87 # Enforce recommended preprocessor indentation style.
88 sc_preprocessor_indentation:
89 @if cppi --version >/dev/null 2>&1; then \
90 $(VC_LIST_EXCEPT) | grep '\.[ch]$$' | xargs cppi -a -c \
91 || { echo '$(ME): incorrect preprocessor indentation' 1>&2; \
92 exit 1; }; \
93 else \
94 echo '$(ME): skipping test $@: cppi not installed' 1>&2; \
95 fi
96
97 sc_copyright_format:
98 @require='Copyright .*Red 'Hat', Inc\.' \
99 containing='Copyright .*Red 'Hat \
100 halt='Red Hat copyright is missing Inc.' \
101 $(_sc_search_regexp)
102 @prohibit='Copyright [^(].*Red 'Hat \
103 halt='consistently use (C) in Red Hat copyright' \
104 $(_sc_search_regexp)
105 @prohibit='\<Red''Hat\>' \
106 halt='spell Red Hat as two words' \
107 $(_sc_search_regexp)
108
109 # We don't use this feature of maint.mk.
110 prev_version_file = /dev/null
111
112
113 exclude_file_name_regexp--sc_preprocessor_indentation = ^*/*.[ch]
114 exclude_file_name_regexp--sc_prohibit_strcmp = ^*/*.[ch]
115 exclude_file_name_regexp--sc_require_config_h = ^src/gbinding\.c|src/windows-cmdline-wrapper.c
116 exclude_file_name_regexp--sc_require_config_h_first = ^src/gbinding\.c|src/windows-cmdline-wrapper.c
117
118 exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF = ^icons/
119 exclude_file_name_regexp--sc_trailing_blank = ^icons/
120
121 exclude_file_name_regexp--sc_prohibit_magic_number_exit = src/windows-cmdline-wrapper.c
122
123 exclude_file_name_regexp--sc_makefile_at_at_check = data/Makefile.am
+0
-1516
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 := maint.mk
22
23 # Diagnostic for continued use of deprecated variable.
24 # Remove in 2013
25 ifneq ($(build_aux),)
26 $(error "$(ME): \
27 set $$(_build-aux) relative to $$(srcdir) instead of $$(build_aux)")
28 endif
29
30 # Do not save the original name or timestamp in the .tar.gz file.
31 # Use --rsyncable if available.
32 gzip_rsyncable := \
33 $(shell gzip --help 2>/dev/null|grep rsyncable >/dev/null \
34 && printf %s --rsyncable)
35 GZIP_ENV = '--no-name --best $(gzip_rsyncable)'
36
37 GIT = git
38 VC = $(GIT)
39
40 VC_LIST = $(srcdir)/$(_build-aux)/vc-list-files -C $(srcdir)
41
42 # You can override this variable in cfg.mk to set your own regexp
43 # matching files to ignore.
44 VC_LIST_ALWAYS_EXCLUDE_REGEX ?= ^$$
45
46 # This is to preprocess robustly the output of $(VC_LIST), so that even
47 # when $(srcdir) is a pathological name like "....", the leading sed command
48 # removes only the intended prefix.
49 _dot_escaped_srcdir = $(subst .,\.,$(srcdir))
50
51 # Post-process $(VC_LIST) output, prepending $(srcdir)/, but only
52 # when $(srcdir) is not ".".
53 ifeq ($(srcdir),.)
54 _prepend_srcdir_prefix =
55 else
56 _prepend_srcdir_prefix = | sed 's|^|$(srcdir)/|'
57 endif
58
59 # In order to be able to consistently filter "."-relative names,
60 # (i.e., with no $(srcdir) prefix), this definition is careful to
61 # remove any $(srcdir) prefix, and to restore what it removes.
62 _sc_excl = \
63 $(if $(exclude_file_name_regexp--$@),$(exclude_file_name_regexp--$@),^$$)
64 VC_LIST_EXCEPT = \
65 $(VC_LIST) | sed 's|^$(_dot_escaped_srcdir)/||' \
66 | if test -f $(srcdir)/.x-$@; then grep -vEf $(srcdir)/.x-$@; \
67 else grep -Ev -e "$${VC_LIST_EXCEPT_DEFAULT-ChangeLog}"; fi \
68 | grep -Ev -e '($(VC_LIST_ALWAYS_EXCLUDE_REGEX)|$(_sc_excl))' \
69 $(_prepend_srcdir_prefix)
70
71 ifeq ($(origin prev_version_file), undefined)
72 prev_version_file = $(srcdir)/.prev-version
73 endif
74
75 PREV_VERSION := $(shell cat $(prev_version_file) 2>/dev/null)
76 VERSION_REGEXP = $(subst .,\.,$(VERSION))
77 PREV_VERSION_REGEXP = $(subst .,\.,$(PREV_VERSION))
78
79 ifeq ($(VC),$(GIT))
80 this-vc-tag = v$(VERSION)
81 this-vc-tag-regexp = v$(VERSION_REGEXP)
82 else
83 tag-package = $(shell echo "$(PACKAGE)" | tr '[:lower:]' '[:upper:]')
84 tag-this-version = $(subst .,_,$(VERSION))
85 this-vc-tag = $(tag-package)-$(tag-this-version)
86 this-vc-tag-regexp = $(this-vc-tag)
87 endif
88 my_distdir = $(PACKAGE)-$(VERSION)
89
90 # Old releases are stored here.
91 release_archive_dir ?= ../release
92
93 # Override gnu_rel_host and url_dir_list in cfg.mk if these are not right.
94 # Use alpha.gnu.org for alpha and beta releases.
95 # Use ftp.gnu.org for stable releases.
96 gnu_ftp_host-alpha = alpha.gnu.org
97 gnu_ftp_host-beta = alpha.gnu.org
98 gnu_ftp_host-stable = ftp.gnu.org
99 gnu_rel_host ?= $(gnu_ftp_host-$(RELEASE_TYPE))
100
101 ifeq ($(gnu_rel_host),ftp.gnu.org)
102 url_dir_list ?= http://ftpmirror.gnu.org/$(PACKAGE)
103 else
104 url_dir_list ?= ftp://$(gnu_rel_host)/gnu/$(PACKAGE)
105 endif
106
107 # Override this in cfg.mk if you are using a different format in your
108 # NEWS file.
109 today = $(shell date +%Y-%m-%d)
110
111 # Select which lines of NEWS are searched for $(news-check-regexp).
112 # This is a sed line number spec. The default says that we search
113 # lines 1..10 of NEWS for $(news-check-regexp).
114 # If you want to search only line 3 or only lines 20-22, use "3" or "20,22".
115 news-check-lines-spec ?= 1,10
116 news-check-regexp ?= '^\*.* $(VERSION_REGEXP) \($(today)\)'
117
118 # Prevent programs like 'sort' from considering distinct strings to be equal.
119 # Doing it here saves us from having to set LC_ALL elsewhere in this file.
120 export LC_ALL = C
121
122 ## --------------- ##
123 ## Sanity checks. ##
124 ## --------------- ##
125
126 _cfg_mk := $(shell test -f $(srcdir)/cfg.mk && echo '$(srcdir)/cfg.mk')
127
128 # Collect the names of rules starting with `sc_'.
129 syntax-check-rules := $(sort $(shell sed -n 's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' \
130 $(srcdir)/$(ME) $(_cfg_mk)))
131 .PHONY: $(syntax-check-rules)
132
133 ifeq ($(shell $(VC_LIST) >/dev/null 2>&1; echo $$?),0)
134 local-checks-available += $(syntax-check-rules)
135 else
136 local-checks-available += no-vc-detected
137 no-vc-detected:
138 @echo "No version control files detected; skipping syntax check"
139 endif
140 .PHONY: $(local-checks-available)
141
142 # Arrange to print the name of each syntax-checking rule just before running it.
143 $(syntax-check-rules): %: %.m
144 sc_m_rules_ = $(patsubst %, %.m, $(syntax-check-rules))
145 .PHONY: $(sc_m_rules_)
146 $(sc_m_rules_):
147 @echo $(patsubst sc_%.m, %, $@)
148 @date +%s.%N > .sc-start-$(basename $@)
149
150 # Compute and print the elapsed time for each syntax-check rule.
151 sc_z_rules_ = $(patsubst %, %.z, $(syntax-check-rules))
152 .PHONY: $(sc_z_rules_)
153 $(sc_z_rules_): %.z: %
154 @end=$$(date +%s.%N); \
155 start=$$(cat .sc-start-$*); \
156 rm -f .sc-start-$*; \
157 awk -v s=$$start -v e=$$end \
158 'END {printf "%.2f $(patsubst sc_%,%,$*)\n", e - s}' < /dev/null
159
160 # The patsubst here is to replace each sc_% rule with its sc_%.z wrapper
161 # that computes and prints elapsed time.
162 local-check := \
163 $(patsubst sc_%, sc_%.z, \
164 $(filter-out $(local-checks-to-skip), $(local-checks-available)))
165
166 syntax-check: $(local-check)
167
168 # _sc_search_regexp
169 #
170 # This macro searches for a given construct in the selected files and
171 # then takes some action.
172 #
173 # Parameters (shell variables):
174 #
175 # prohibit | require
176 #
177 # Regular expression (ERE) denoting either a forbidden construct
178 # or a required construct. Those arguments are exclusive.
179 #
180 # in_vc_files | in_files
181 #
182 # grep-E-style regexp denoting the files to check. If no files
183 # are specified the default are all the files that are under
184 # version control.
185 #
186 # containing | non_containing
187 #
188 # Select the files (non) containing strings matching this regexp.
189 # If both arguments are specified then CONTAINING takes
190 # precedence.
191 #
192 # with_grep_options
193 #
194 # Extra options for grep.
195 #
196 # ignore_case
197 #
198 # Ignore case.
199 #
200 # halt
201 #
202 # Message to display before to halting execution.
203 #
204 # Finally, you may exempt files based on an ERE matching file names.
205 # For example, to exempt from the sc_space_tab check all files with the
206 # .diff suffix, set this Make variable:
207 #
208 # exclude_file_name_regexp--sc_space_tab = \.diff$
209 #
210 # Note that while this functionality is mostly inherited via VC_LIST_EXCEPT,
211 # when filtering by name via in_files, we explicitly filter out matching
212 # names here as well.
213
214 # By default, _sc_search_regexp does not ignore case.
215 export ignore_case =
216 _ignore_case = $$(test -n "$$ignore_case" && printf %s -i || :)
217
218 define _sc_say_and_exit
219 dummy=; : so we do not need a semicolon before each use; \
220 { printf '%s\n' "$(ME): $$msg" 1>&2; exit 1; };
221 endef
222
223 # _sc_search_regexp used to be named _prohibit_regexp. However,
224 # upgrading to the new definition and leaving the old name undefined
225 # would usually convert each custom rule using $(_prohibit_regexp)
226 # (usually defined in cfg.mk) into a no-op. This definition ensures
227 # that people know right away if they're still using the old name.
228 # FIXME: remove in 2012.
229 _prohibit_regexp = \
230 $(error '*** you need to s/_prohibit_regexp/_sc_search_regexp/, and adapt')
231
232 define _sc_search_regexp
233 dummy=; : so we do not need a semicolon before each use; \
234 \
235 : Check arguments; \
236 test -n "$$prohibit" && test -n "$$require" \
237 && { msg='Cannot specify both prohibit and require' \
238 $(_sc_say_and_exit) } || :; \
239 test -z "$$prohibit" && test -z "$$require" \
240 && { msg='Should specify either prohibit or require' \
241 $(_sc_say_and_exit) } || :; \
242 test -n "$$in_vc_files" && test -n "$$in_files" \
243 && { msg='Cannot specify both in_vc_files and in_files' \
244 $(_sc_say_and_exit) } || :; \
245 test "x$$halt" != x \
246 || { msg='halt not defined' $(_sc_say_and_exit) }; \
247 \
248 : Filter by file name; \
249 if test -n "$$in_files"; then \
250 files=$$(find $(srcdir) | grep -E "$$in_files" \
251 | grep -Ev '$(exclude_file_name_regexp--$@)'); \
252 else \
253 files=$$($(VC_LIST_EXCEPT)); \
254 if test -n "$$in_vc_files"; then \
255 files=$$(echo "$$files" | grep -E "$$in_vc_files"); \
256 fi; \
257 fi; \
258 \
259 : Filter by content; \
260 test -n "$$files" && test -n "$$containing" \
261 && { files=$$(grep -l "$$containing" $$files); } || :; \
262 test -n "$$files" && test -n "$$non_containing" \
263 && { files=$$(grep -vl "$$non_containing" $$files); } || :; \
264 \
265 : Check for the construct; \
266 if test -n "$$files"; then \
267 if test -n "$$prohibit"; then \
268 grep $$with_grep_options $(_ignore_case) -nE "$$prohibit" $$files \
269 && { msg="$$halt" $(_sc_say_and_exit) } || :; \
270 else \
271 grep $$with_grep_options $(_ignore_case) -LE "$$require" $$files \
272 | grep . \
273 && { msg="$$halt" $(_sc_say_and_exit) } || :; \
274 fi \
275 else :; \
276 fi || :;
277 endef
278
279 sc_avoid_if_before_free:
280 @$(srcdir)/$(_build-aux)/useless-if-before-free \
281 $(useless_free_options) \
282 $$($(VC_LIST_EXCEPT) | grep -v useless-if-before-free) && \
283 { echo '$(ME): found useless "if" before "free" above' 1>&2; \
284 exit 1; } || :
285
286 sc_cast_of_argument_to_free:
287 @prohibit='\<free *\( *\(' halt='don'\''t cast free argument' \
288 $(_sc_search_regexp)
289
290 sc_cast_of_x_alloc_return_value:
291 @prohibit='\*\) *x(m|c|re)alloc\>' \
292 halt='don'\''t cast x*alloc return value' \
293 $(_sc_search_regexp)
294
295 sc_cast_of_alloca_return_value:
296 @prohibit='\*\) *alloca\>' \
297 halt='don'\''t cast alloca return value' \
298 $(_sc_search_regexp)
299
300 sc_space_tab:
301 @prohibit='[ ] ' \
302 halt='found SPACE-TAB sequence; remove the SPACE' \
303 $(_sc_search_regexp)
304
305 # Don't use *scanf or the old ato* functions in `real' code.
306 # They provide no error checking mechanism.
307 # Instead, use strto* functions.
308 sc_prohibit_atoi_atof:
309 @prohibit='\<([fs]?scanf|ato([filq]|ll)) *\(' \
310 halt='do not use *scan''f, ato''f, ato''i, ato''l, ato''ll or ato''q' \
311 $(_sc_search_regexp)
312
313 # Use STREQ rather than comparing strcmp == 0, or != 0.
314 sc_prohibit_strcmp:
315 @grep -nE '! *str''cmp *\(|\<str''cmp *\(.+\) *[!=]=' \
316 $$($(VC_LIST_EXCEPT)) \
317 | grep -vE ':# *define STRN?EQ\(' && \
318 { echo '$(ME): replace str''cmp calls above with STREQ/STRNEQ' \
319 1>&2; exit 1; } || :
320
321 # Pass EXIT_*, not number, to usage, exit, and error (when exiting)
322 # Convert all uses automatically, via these two commands:
323 # git grep -l '\<exit *(1)' \
324 # | grep -vEf .x-sc_prohibit_magic_number_exit \
325 # | xargs --no-run-if-empty \
326 # perl -pi -e 's/(^|[^.])\b(exit ?)\(1\)/$1$2(EXIT_FAILURE)/'
327 # git grep -l '\<exit *(0)' \
328 # | grep -vEf .x-sc_prohibit_magic_number_exit \
329 # | xargs --no-run-if-empty \
330 # perl -pi -e 's/(^|[^.])\b(exit ?)\(0\)/$1$2(EXIT_SUCCESS)/'
331 sc_prohibit_magic_number_exit:
332 @prohibit='(^|[^.])\<(usage|exit) ?\([0-9]|\<error ?\([1-9][0-9]*,' \
333 halt='use EXIT_* values rather than magic number' \
334 $(_sc_search_regexp)
335
336 # Using EXIT_SUCCESS as the first argument to error is misleading,
337 # since when that parameter is 0, error does not exit. Use `0' instead.
338 sc_error_exit_success:
339 @prohibit='error *\(EXIT_SUCCESS,' \
340 in_vc_files='\.[chly]$$' \
341 halt='found error (EXIT_SUCCESS' \
342 $(_sc_search_regexp)
343
344 # `FATAL:' should be fully upper-cased in error messages
345 # `WARNING:' should be fully upper-cased, or fully lower-cased
346 sc_error_message_warn_fatal:
347 @grep -nEA2 '[^rp]error *\(' $$($(VC_LIST_EXCEPT)) \
348 | grep -E '"Warning|"Fatal|"fatal' && \
349 { echo '$(ME): use FATAL, WARNING or warning' 1>&2; \
350 exit 1; } || :
351
352 # Error messages should not start with a capital letter
353 sc_error_message_uppercase:
354 @grep -nEA2 '[^rp]error *\(' $$($(VC_LIST_EXCEPT)) \
355 | grep -E '"[A-Z]' \
356 | grep -vE '"FATAL|"WARNING|"Java|"C#|PRIuMAX' && \
357 { echo '$(ME): found capitalized error message' 1>&2; \
358 exit 1; } || :
359
360 # Error messages should not end with a period
361 sc_error_message_period:
362 @grep -nEA2 '[^rp]error *\(' $$($(VC_LIST_EXCEPT)) \
363 | grep -E '[^."]\."' && \
364 { echo '$(ME): found error message ending in period' 1>&2; \
365 exit 1; } || :
366
367 sc_file_system:
368 @prohibit=file''system \
369 ignore_case=1 \
370 halt='found use of "file''system"; spell it "file system"' \
371 $(_sc_search_regexp)
372
373 # Don't use cpp tests of this symbol. All code assumes config.h is included.
374 sc_prohibit_have_config_h:
375 @prohibit='^# *if.*HAVE''_CONFIG_H' \
376 halt='found use of HAVE''_CONFIG_H; remove' \
377 $(_sc_search_regexp)
378
379 # Nearly all .c files must include <config.h>. However, we also permit this
380 # via inclusion of a package-specific header, if cfg.mk specified one.
381 # config_h_header must be suitable for grep -E.
382 config_h_header ?= <config\.h>
383 sc_require_config_h:
384 @require='^# *include $(config_h_header)' \
385 in_vc_files='\.c$$' \
386 halt='the above files do not include <config.h>' \
387 $(_sc_search_regexp)
388
389 # You must include <config.h> before including any other header file.
390 # This can possibly be via a package-specific header, if given by cfg.mk.
391 sc_require_config_h_first:
392 @if $(VC_LIST_EXCEPT) | grep -l '\.c$$' > /dev/null; then \
393 fail=0; \
394 for i in $$($(VC_LIST_EXCEPT) | grep '\.c$$'); do \
395 grep '^# *include\>' $$i | sed 1q \
396 | grep -E '^# *include $(config_h_header)' > /dev/null \
397 || { echo $$i; fail=1; }; \
398 done; \
399 test $$fail = 1 && \
400 { echo '$(ME): the above files include some other header' \
401 'before <config.h>' 1>&2; exit 1; } || :; \
402 else :; \
403 fi
404
405 sc_prohibit_HAVE_MBRTOWC:
406 @prohibit='\bHAVE_MBRTOWC\b' \
407 halt="do not use $$prohibit; it is always defined" \
408 $(_sc_search_regexp)
409
410 # To use this "command" macro, you must first define two shell variables:
411 # h: the header name, with no enclosing <> or ""
412 # re: a regular expression that matches IFF something provided by $h is used.
413 define _sc_header_without_use
414 dummy=; : so we do not need a semicolon before each use; \
415 h_esc=`echo '[<"]'"$$h"'[">]'|sed 's/\./\\\\./g'`; \
416 if $(VC_LIST_EXCEPT) | grep -l '\.c$$' > /dev/null; then \
417 files=$$(grep -l '^# *include '"$$h_esc" \
418 $$($(VC_LIST_EXCEPT) | grep '\.c$$')) && \
419 grep -LE "$$re" $$files | grep . && \
420 { echo "$(ME): the above files include $$h but don't use it" \
421 1>&2; exit 1; } || :; \
422 else :; \
423 fi
424 endef
425
426 # Prohibit the inclusion of assert.h without an actual use of assert.
427 sc_prohibit_assert_without_use:
428 @h='assert.h' re='\<assert *\(' $(_sc_header_without_use)
429
430 # Prohibit the inclusion of close-stream.h without an actual use.
431 sc_prohibit_close_stream_without_use:
432 @h='close-stream.h' re='\<close_stream *\(' $(_sc_header_without_use)
433
434 # Prohibit the inclusion of getopt.h without an actual use.
435 sc_prohibit_getopt_without_use:
436 @h='getopt.h' re='\<getopt(_long)? *\(' $(_sc_header_without_use)
437
438 # Don't include quotearg.h unless you use one of its functions.
439 sc_prohibit_quotearg_without_use:
440 @h='quotearg.h' re='\<quotearg(_[^ ]+)? *\(' $(_sc_header_without_use)
441
442 # Don't include quote.h unless you use one of its functions.
443 sc_prohibit_quote_without_use:
444 @h='quote.h' re='\<quote(_n)? *\(' $(_sc_header_without_use)
445
446 # Don't include this header unless you use one of its functions.
447 sc_prohibit_long_options_without_use:
448 @h='long-options.h' re='\<parse_long_options *\(' \
449 $(_sc_header_without_use)
450
451 # Don't include this header unless you use one of its functions.
452 sc_prohibit_inttostr_without_use:
453 @h='inttostr.h' re='\<(off|[iu]max|uint)tostr *\(' \
454 $(_sc_header_without_use)
455
456 # Don't include this header unless you use one of its functions.
457 sc_prohibit_ignore_value_without_use:
458 @h='ignore-value.h' re='\<ignore_(value|ptr) *\(' \
459 $(_sc_header_without_use)
460
461 # Don't include this header unless you use one of its functions.
462 sc_prohibit_error_without_use:
463 @h='error.h' \
464 re='\<error(_at_line|_print_progname|_one_per_line|_message_count)? *\('\
465 $(_sc_header_without_use)
466
467 # Don't include xalloc.h unless you use one of its functions.
468 # Consider these symbols:
469 # perl -lne '/^# *define (\w+)\(/ and print $1' lib/xalloc.h|grep -v '^__';
470 # perl -lne '/^(?:extern )?(?:void|char) \*?(\w+) *\(/ and print $1' lib/xalloc.h
471 # Divide into two sets on case, and filter each through this:
472 # | sort | perl -MRegexp::Assemble -le \
473 # 'print Regexp::Assemble->new(file => "/dev/stdin")->as_string'|sed 's/\?://g'
474 # Note this was produced by the above:
475 # _xa1 = \
476 #x(((2n?)?re|c(har)?|n(re|m)|z)alloc|alloc_(oversized|die)|m(alloc|emdup)|strdup)
477 # But we can do better, in at least two ways:
478 # 1) take advantage of two "dup"-suffixed strings:
479 # x(((2n?)?re|c(har)?|n(re|m)|[mz])alloc|alloc_(oversized|die)|(mem|str)dup)
480 # 2) notice that "c(har)?|[mz]" is equivalent to the shorter and more readable
481 # "char|[cmz]"
482 # x(((2n?)?re|char|n(re|m)|[cmz])alloc|alloc_(oversized|die)|(mem|str)dup)
483 _xa1 = x(((2n?)?re|char|n(re|m)|[cmz])alloc|alloc_(oversized|die)|(mem|str)dup)
484 _xa2 = X([CZ]|N?M)ALLOC
485 sc_prohibit_xalloc_without_use:
486 @h='xalloc.h' \
487 re='\<($(_xa1)|$(_xa2)) *\('\
488 $(_sc_header_without_use)
489
490 # Extract function names:
491 # perl -lne '/^(?:extern )?(?:void|char) \*?(\w+) *\(/ and print $1' lib/hash.h
492 _hash_re = \
493 clear|delete|free|get_(first|next)|insert|lookup|print_statistics|reset_tuning
494 _hash_fn = \<($(_hash_re)) *\(
495 _hash_struct = (struct )?\<[Hh]ash_(table|tuning)\>
496 sc_prohibit_hash_without_use:
497 @h='hash.h' \
498 re='$(_hash_fn)|$(_hash_struct)'\
499 $(_sc_header_without_use)
500
501 sc_prohibit_cloexec_without_use:
502 @h='cloexec.h' re='\<(set_cloexec_flag|dup_cloexec) *\(' \
503 $(_sc_header_without_use)
504
505 sc_prohibit_posixver_without_use:
506 @h='posixver.h' re='\<posix2_version *\(' $(_sc_header_without_use)
507
508 sc_prohibit_same_without_use:
509 @h='same.h' re='\<same_name *\(' $(_sc_header_without_use)
510
511 sc_prohibit_hash_pjw_without_use:
512 @h='hash-pjw.h' \
513 re='\<hash_pjw *\(' \
514 $(_sc_header_without_use)
515
516 sc_prohibit_safe_read_without_use:
517 @h='safe-read.h' re='(\<SAFE_READ_ERROR\>|\<safe_read *\()' \
518 $(_sc_header_without_use)
519
520 sc_prohibit_argmatch_without_use:
521 @h='argmatch.h' \
522 re='(\<(ARRAY_CARDINALITY|X?ARGMATCH(|_TO_ARGUMENT|_VERIFY))\>|\<(invalid_arg|argmatch(_exit_fn|_(in)?valid)?) *\()' \
523 $(_sc_header_without_use)
524
525 sc_prohibit_canonicalize_without_use:
526 @h='canonicalize.h' \
527 re='CAN_(EXISTING|ALL_BUT_LAST|MISSING)|canonicalize_(mode_t|filename_mode)' \
528 $(_sc_header_without_use)
529
530 sc_prohibit_root_dev_ino_without_use:
531 @h='root-dev-ino.h' \
532 re='(\<ROOT_DEV_INO_(CHECK|WARN)\>|\<get_root_dev_ino *\()' \
533 $(_sc_header_without_use)
534
535 sc_prohibit_openat_without_use:
536 @h='openat.h' \
537 re='\<(openat_(permissive|needs_fchdir|(save|restore)_fail)|l?(stat|ch(own|mod))at|(euid)?accessat)\>' \
538 $(_sc_header_without_use)
539
540 # Prohibit the inclusion of c-ctype.h without an actual use.
541 ctype_re = isalnum|isalpha|isascii|isblank|iscntrl|isdigit|isgraph|islower\
542 |isprint|ispunct|isspace|isupper|isxdigit|tolower|toupper
543 sc_prohibit_c_ctype_without_use:
544 @h='c-ctype.h' re='\<c_($(ctype_re)) *\(' \
545 $(_sc_header_without_use)
546
547 _empty =
548 _sp = $(_empty) $(_empty)
549 # The following list was generated by running:
550 # man signal.h|col -b|perl -ne '/bsd_signal.*;/.../sigwaitinfo.*;/ and print' \
551 # | perl -lne '/^\s+(?:int|void).*?(\w+).*/ and print $1' | fmt
552 _sig_functions = \
553 bsd_signal kill killpg pthread_kill pthread_sigmask raise sigaction \
554 sigaddset sigaltstack sigdelset sigemptyset sigfillset sighold sigignore \
555 siginterrupt sigismember signal sigpause sigpending sigprocmask sigqueue \
556 sigrelse sigset sigsuspend sigtimedwait sigwait sigwaitinfo
557 _sig_function_re = $(subst $(_sp),|,$(strip $(_sig_functions)))
558 # The following were extracted from "man signal.h" manually.
559 _sig_types_and_consts = \
560 MINSIGSTKSZ SA_NOCLDSTOP SA_NOCLDWAIT SA_NODEFER SA_ONSTACK \
561 SA_RESETHAND SA_RESTART SA_SIGINFO SIGEV_NONE SIGEV_SIGNAL \
562 SIGEV_THREAD SIGSTKSZ SIG_BLOCK SIG_SETMASK SIG_UNBLOCK SS_DISABLE \
563 SS_ONSTACK mcontext_t pid_t sig_atomic_t sigevent siginfo_t sigset_t \
564 sigstack sigval stack_t ucontext_t
565 # generated via this:
566 # perl -lne '/^#ifdef (SIG\w+)/ and print $1' lib/sig2str.c|sort -u|fmt -70
567 _sig_names = \
568 SIGABRT SIGALRM SIGALRM1 SIGBUS SIGCANCEL SIGCHLD SIGCLD SIGCONT \
569 SIGDANGER SIGDIL SIGEMT SIGFPE SIGFREEZE SIGGRANT SIGHUP SIGILL \
570 SIGINFO SIGINT SIGIO SIGIOT SIGKAP SIGKILL SIGKILLTHR SIGLOST SIGLWP \
571 SIGMIGRATE SIGMSG SIGPHONE SIGPIPE SIGPOLL SIGPRE SIGPROF SIGPWR \
572 SIGQUIT SIGRETRACT SIGSAK SIGSEGV SIGSOUND SIGSTKFLT SIGSTOP SIGSYS \
573 SIGTERM SIGTHAW SIGTRAP SIGTSTP SIGTTIN SIGTTOU SIGURG SIGUSR1 \
574 SIGUSR2 SIGVIRT SIGVTALRM SIGWAITING SIGWINCH SIGWIND SIGWINDOW \
575 SIGXCPU SIGXFSZ
576 _sig_syms_re = $(subst $(_sp),|,$(strip $(_sig_names) $(_sig_types_and_consts)))
577
578 # Prohibit the inclusion of signal.h without an actual use.
579 sc_prohibit_signal_without_use:
580 @h='signal.h' \
581 re='\<($(_sig_function_re)) *\(|\<($(_sig_syms_re))\>' \
582 $(_sc_header_without_use)
583
584 # Don't include stdio--.h unless you use one of its functions.
585 sc_prohibit_stdio--_without_use:
586 @h='stdio--.h' re='\<((f(re)?|p)open|tmpfile) *\(' \
587 $(_sc_header_without_use)
588
589 # Don't include stdio-safer.h unless you use one of its functions.
590 sc_prohibit_stdio-safer_without_use:
591 @h='stdio-safer.h' re='\<((f(re)?|p)open|tmpfile)_safer *\(' \
592 $(_sc_header_without_use)
593
594 # Prohibit the inclusion of strings.h without a sensible use.
595 # Using the likes of bcmp, bcopy, bzero, index or rindex is not sensible.
596 sc_prohibit_strings_without_use:
597 @h='strings.h' \
598 re='\<(strn?casecmp|ffs(ll)?)\>' \
599 $(_sc_header_without_use)
600
601 # Get the list of symbol names with this:
602 # perl -lne '/^# *define ([A-Z]\w+)\(/ and print $1' lib/intprops.h|fmt
603 _intprops_names = \
604 TYPE_IS_INTEGER TYPE_TWOS_COMPLEMENT TYPE_ONES_COMPLEMENT \
605 TYPE_SIGNED_MAGNITUDE TYPE_SIGNED TYPE_MINIMUM TYPE_MAXIMUM \
606 INT_BITS_STRLEN_BOUND INT_STRLEN_BOUND INT_BUFSIZE_BOUND \
607 INT_ADD_RANGE_OVERFLOW INT_SUBTRACT_RANGE_OVERFLOW \
608 INT_NEGATE_RANGE_OVERFLOW INT_MULTIPLY_RANGE_OVERFLOW \
609 INT_DIVIDE_RANGE_OVERFLOW INT_REMAINDER_RANGE_OVERFLOW \
610 INT_LEFT_SHIFT_RANGE_OVERFLOW INT_ADD_OVERFLOW INT_SUBTRACT_OVERFLOW \
611 INT_NEGATE_OVERFLOW INT_MULTIPLY_OVERFLOW INT_DIVIDE_OVERFLOW \
612 INT_REMAINDER_OVERFLOW INT_LEFT_SHIFT_OVERFLOW
613 _intprops_syms_re = $(subst $(_sp),|,$(strip $(_intprops_names)))
614 # Prohibit the inclusion of intprops.h without an actual use.
615 sc_prohibit_intprops_without_use:
616 @h='intprops.h' \
617 re='\<($(_intprops_syms_re)) *\(' \
618 $(_sc_header_without_use)
619
620 _stddef_syms_re = NULL|offsetof|ptrdiff_t|size_t|wchar_t
621 # Prohibit the inclusion of stddef.h without an actual use.
622 sc_prohibit_stddef_without_use:
623 @h='stddef.h' \
624 re='\<($(_stddef_syms_re))\>' \
625 $(_sc_header_without_use)
626
627 _de1 = dirfd|(close|(fd)?open|read|rewind|seek|tell)dir(64)?(_r)?
628 _de2 = (versionsort|struct dirent|getdirentries|alphasort|scandir(at)?)(64)?
629 _de3 = MAXNAMLEN|DIR|ino_t|d_ino|d_fileno|d_namlen
630 _dirent_syms_re = $(_de1)|$(_de2)|$(_de3)
631 # Prohibit the inclusion of dirent.h without an actual use.
632 sc_prohibit_dirent_without_use:
633 @h='dirent.h' \
634 re='\<($(_dirent_syms_re))\>' \
635 $(_sc_header_without_use)
636
637 # Prohibit the inclusion of verify.h without an actual use.
638 sc_prohibit_verify_without_use:
639 @h='verify.h' \
640 re='\<(verify(true|expr)?|static_assert) *\(' \
641 $(_sc_header_without_use)
642
643 # Don't include xfreopen.h unless you use one of its functions.
644 sc_prohibit_xfreopen_without_use:
645 @h='xfreopen.h' re='\<xfreopen *\(' $(_sc_header_without_use)
646
647 sc_obsolete_symbols:
648 @prohibit='\<(HAVE''_FCNTL_H|O''_NDELAY)\>' \
649 halt='do not use HAVE''_FCNTL_H or O'_NDELAY \
650 $(_sc_search_regexp)
651
652 # FIXME: warn about definitions of EXIT_FAILURE, EXIT_SUCCESS, STREQ
653
654 # Each nonempty ChangeLog line must start with a year number, or a TAB.
655 sc_changelog:
656 @prohibit='^[^12 ]' \
657 in_vc_files='^ChangeLog$$' \
658 halt='found unexpected prefix in a ChangeLog' \
659 $(_sc_search_regexp)
660
661 # Ensure that each .c file containing a "main" function also
662 # calls set_program_name.
663 sc_program_name:
664 @require='set_program_name *\(m?argv\[0\]\);' \
665 in_vc_files='\.c$$' \
666 containing='\<main *(' \
667 halt='the above files do not call set_program_name' \
668 $(_sc_search_regexp)
669
670 # Ensure that each .c file containing a "main" function also
671 # calls bindtextdomain.
672 sc_bindtextdomain:
673 @require='bindtextdomain *\(' \
674 in_vc_files='\.c$$' \
675 containing='\<main *(' \
676 halt='the above files do not call bindtextdomain' \
677 $(_sc_search_regexp)
678
679 # Require that the final line of each test-lib.sh-using test be this one:
680 # Exit $fail
681 # Note: this test requires GNU grep's --label= option.
682 Exit_witness_file ?= tests/test-lib.sh
683 Exit_base := $(notdir $(Exit_witness_file))
684 sc_require_test_exit_idiom:
685 @if test -f $(srcdir)/$(Exit_witness_file); then \
686 die=0; \
687 for i in $$(grep -l -F 'srcdir/$(Exit_base)' \
688 $$($(VC_LIST) tests)); do \
689 tail -n1 $$i | grep '^Exit .' > /dev/null \
690 && : || { die=1; echo $$i; } \
691 done; \
692 test $$die = 1 && \
693 { echo 1>&2 '$(ME): the final line in each of the above is not:'; \
694 echo 1>&2 'Exit something'; \
695 exit 1; } || :; \
696 fi
697
698 sc_trailing_blank:
699 @prohibit='[ ]$$' \
700 halt='found trailing blank(s)' \
701 $(_sc_search_regexp)
702
703 # Match lines like the following, but where there is only one space
704 # between the options and the description:
705 # -D, --all-repeated[=delimit-method] print all duplicate lines\n
706 longopt_re = --[a-z][0-9A-Za-z-]*(\[?=[0-9A-Za-z-]*\]?)?
707 sc_two_space_separator_in_usage:
708 @prohibit='^ *(-[A-Za-z],)? $(longopt_re) [^ ].*\\$$' \
709 halt='help2man requires at least two spaces between an option and its description'\
710 $(_sc_search_regexp)
711
712 # A regexp matching function names like "error" that may be used
713 # to emit translatable messages.
714 _gl_translatable_diag_func_re ?= error
715
716 # Look for diagnostics that aren't marked for translation.
717 # This won't find any for which error's format string is on a separate line.
718 sc_unmarked_diagnostics:
719 @grep -nE \
720 '\<$(_gl_translatable_diag_func_re) *\([^"]*"[^"]*[a-z]{3}' \
721 $$($(VC_LIST_EXCEPT)) \
722 | grep -Ev '(_|ngettext ?)\(' && \
723 { echo '$(ME): found unmarked diagnostic(s)' 1>&2; \
724 exit 1; } || :
725
726 # Avoid useless parentheses like those in this example:
727 # #if defined (SYMBOL) || defined (SYM2)
728 sc_useless_cpp_parens:
729 @prohibit='^# *if .*defined *\(' \
730 halt='found useless parentheses in cpp directive' \
731 $(_sc_search_regexp)
732
733 # List headers for which HAVE_HEADER_H is always true, assuming you are
734 # using the appropriate gnulib module. CAUTION: for each "unnecessary"
735 # #if HAVE_HEADER_H that you remove, be sure that your project explicitly
736 # requires the gnulib module that guarantees the usability of that header.
737 gl_assured_headers_ = \
738 cd $(gnulib_dir)/lib && echo *.in.h|sed 's/\.in\.h//g'
739
740 # Convert the list of names to upper case, and replace each space with "|".
741 az_ = abcdefghijklmnopqrstuvwxyz
742 AZ_ = ABCDEFGHIJKLMNOPQRSTUVWXYZ
743 gl_header_upper_case_or_ = \
744 $$($(gl_assured_headers_) \
745 | tr $(az_)/.- $(AZ_)___ \
746 | tr -s ' ' '|' \
747 )
748 sc_prohibit_always_true_header_tests:
749 @or=$(gl_header_upper_case_or_); \
750 re="HAVE_($$or)_H"; \
751 prohibit='\<'"$$re"'\>' \
752 halt=$$(printf '%s\n' \
753 'do not test the above HAVE_<header>_H symbol(s);' \
754 ' with the corresponding gnulib module, they are always true') \
755 $(_sc_search_regexp)
756
757 # ==================================================================
758 gl_other_headers_ ?= \
759 intprops.h \
760 openat.h \
761 stat-macros.h
762
763 # Perl -lne code to extract "significant" cpp-defined symbols from a
764 # gnulib header file, eliminating a few common false-positives.
765 # The exempted names below are defined only conditionally in gnulib,
766 # and hence sometimes must/may be defined in application code.
767 gl_extract_significant_defines_ = \
768 /^\# *define ([^_ (][^ (]*)(\s*\(|\s+\w+)/\
769 && $$2 !~ /(?:rpl_|_used_without_)/\
770 && $$1 !~ /^(?:NSIG|ENODATA)$$/\
771 && $$1 !~ /^(?:SA_RESETHAND|SA_RESTART)$$/\
772 and print $$1
773
774 # Create a list of regular expressions matching the names
775 # of macros that are guaranteed to be defined by parts of gnulib.
776 define def_sym_regex
777 gen_h=$(gl_generated_headers_); \
778 (cd $(gnulib_dir)/lib; \
779 for f in *.in.h $(gl_other_headers_); do \
780 test -f $$f \
781 && perl -lne '$(gl_extract_significant_defines_)' $$f; \
782 done; \
783 ) | sort -u \
784 | sed 's/^/^ *# *(define|undef) */;s/$$/\\>/'
785 endef
786
787 # Don't define macros that we already get from gnulib header files.
788 sc_prohibit_always-defined_macros:
789 @if test -d $(gnulib_dir); then \
790 case $$(echo all: | grep -l -f - Makefile) in Makefile);; *) \
791 echo '$(ME): skipping $@: you lack GNU grep' 1>&2; exit 0;; \
792 esac; \
793 $(def_sym_regex) | grep -E -f - $$($(VC_LIST_EXCEPT)) \
794 && { echo '$(ME): define the above via some gnulib .h file' \
795 1>&2; exit 1; } || :; \
796 fi
797 # ==================================================================
798
799 # Prohibit checked in backup files.
800 sc_prohibit_backup_files:
801 @$(VC_LIST) | grep '~$$' && \
802 { echo '$(ME): found version controlled backup file' 1>&2; \
803 exit 1; } || :
804
805 # Require the latest GPL.
806 sc_GPL_version:
807 @prohibit='either ''version [^3]' \
808 halt='GPL vN, N!=3' \
809 $(_sc_search_regexp)
810
811 # Require the latest GFDL. Two regexp, since some .texi files end up
812 # line wrapping between 'Free Documentation License,' and 'Version'.
813 _GFDL_regexp = (Free ''Documentation.*Version 1\.[^3]|Version 1\.[^3] or any)
814 sc_GFDL_version:
815 @prohibit='$(_GFDL_regexp)' \
816 halt='GFDL vN, N!=3' \
817 $(_sc_search_regexp)
818
819 # Don't use Texinfo's @acronym{}.
820 # http://lists.gnu.org/archive/html/bug-gnulib/2010-03/msg00321.html
821 texinfo_suffix_re_ ?= \.(txi|texi(nfo)?)$$
822 sc_texinfo_acronym:
823 @prohibit='@acronym\{' \
824 in_vc_files='$(texinfo_suffix_re_)' \
825 halt='found use of Texinfo @acronym{}' \
826 $(_sc_search_regexp)
827
828 cvs_keywords = \
829 Author|Date|Header|Id|Name|Locker|Log|RCSfile|Revision|Source|State
830
831 sc_prohibit_cvs_keyword:
832 @prohibit='\$$($(cvs_keywords))\$$' \
833 halt='do not use CVS keyword expansion' \
834 $(_sc_search_regexp)
835
836 # This Perl code is slightly obfuscated. Not only is each "$" doubled
837 # because it's in a Makefile, but the $$c's are comments; we cannot
838 # use "#" due to the way the script ends up concatenated onto one line.
839 # It would be much more concise, and would produce better output (including
840 # counts) if written as:
841 # perl -ln -0777 -e '/\n(\n+)$/ and print "$ARGV: ".length $1' ...
842 # but that would be far less efficient, reading the entire contents
843 # of each file, rather than just the last two bytes of each.
844 # In addition, while the code below detects both blank lines and a missing
845 # newline at EOF, the above detects only the former.
846 #
847 # This is a perl script that is expected to be the single-quoted argument
848 # to a command-line "-le". The remaining arguments are file names.
849 # Print the name of each file that ends in exactly one newline byte.
850 # I.e., warn if there are blank lines (2 or more newlines), or if the
851 # last byte is not a newline. However, currently we don't complain
852 # about any file that contains exactly one byte.
853 # Exit nonzero if at least one such file is found, otherwise, exit 0.
854 # Warn about, but otherwise ignore open failure. Ignore seek/read failure.
855 #
856 # Use this if you want to remove trailing empty lines from selected files:
857 # perl -pi -0777 -e 's/\n\n+$/\n/' files...
858 #
859 require_exactly_one_NL_at_EOF_ = \
860 foreach my $$f (@ARGV) \
861 { \
862 open F, "<", $$f or (warn "failed to open $$f: $$!\n"), next; \
863 my $$p = sysseek (F, -2, 2); \
864 my $$c = "seek failure probably means file has < 2 bytes; ignore"; \
865 my $$last_two_bytes; \
866 defined $$p and $$p = sysread F, $$last_two_bytes, 2; \
867 close F; \
868 $$c = "ignore read failure"; \
869 $$p && ($$last_two_bytes eq "\n\n" \
870 || substr ($$last_two_bytes,1) ne "\n") \
871 and (print $$f), $$fail=1; \
872 } \
873 END { exit defined $$fail }
874 sc_prohibit_empty_lines_at_EOF:
875 @perl -le '$(require_exactly_one_NL_at_EOF_)' $$($(VC_LIST_EXCEPT)) \
876 || { echo '$(ME): empty line(s) or no newline at EOF' \
877 1>&2; exit 1; } || :
878
879 # Make sure we don't use st_blocks. Use ST_NBLOCKS instead.
880 # This is a bit of a kludge, since it prevents use of the string
881 # even in comments, but for now it does the job with no false positives.
882 sc_prohibit_stat_st_blocks:
883 @prohibit='[.>]st_blocks' \
884 halt='do not use st_blocks; use ST_NBLOCKS' \
885 $(_sc_search_regexp)
886
887 # Make sure we don't define any S_IS* macros in src/*.c files.
888 # They're already defined via gnulib's sys/stat.h replacement.
889 sc_prohibit_S_IS_definition:
890 @prohibit='^ *# *define *S_IS' \
891 halt='do not define S_IS* macros; include <sys/stat.h>' \
892 $(_sc_search_regexp)
893
894 # Perl block to convert a match to FILE_NAME:LINENO:TEST,
895 # that is shared by two definitions below.
896 perl_filename_lineno_text_ = \
897 -e ' {' \
898 -e ' $$n = ($$` =~ tr/\n/\n/ + 1);' \
899 -e ' ($$v = $$&) =~ s/\n/\\n/g;' \
900 -e ' print "$$ARGV:$$n:$$v\n";' \
901 -e ' }'
902
903 prohibit_doubled_word_RE_ ?= \
904 /\b(then?|[iao]n|i[fst]|but|f?or|at|and|[dt]o)\s+\1\b/gims
905 prohibit_doubled_word_ = \
906 -e 'while ($(prohibit_doubled_word_RE_))' \
907 $(perl_filename_lineno_text_)
908
909 # Define this to a regular expression that matches
910 # any filename:dd:match lines you want to ignore.
911 # The default is to ignore no matches.
912 ignore_doubled_word_match_RE_ ?= ^$$
913
914 sc_prohibit_doubled_word:
915 @perl -n -0777 $(prohibit_doubled_word_) $$($(VC_LIST_EXCEPT)) \
916 | grep -vE '$(ignore_doubled_word_match_RE_)' \
917 | grep . && { echo '$(ME): doubled words' 1>&2; exit 1; } || :
918
919 # A regular expression matching undesirable combinations of words like
920 # "can not"; this matches them even when the two words appear on different
921 # lines, but not when there is an intervening delimiter like "#" or "*".
922 prohibit_undesirable_word_seq_RE_ ?= \
923 /\bcan\s+not\b/gims
924 prohibit_undesirable_word_seq_ = \
925 -e 'while ($(prohibit_undesirable_word_seq_RE_))' \
926 $(perl_filename_lineno_text_)
927 # Define this to a regular expression that matches
928 # any filename:dd:match lines you want to ignore.
929 # The default is to ignore no matches.
930 ignore_undesirable_word_sequence_RE_ ?= ^$$
931
932 sc_prohibit_undesirable_word_seq:
933 @perl -n -0777 $(prohibit_undesirable_word_seq_) \
934 $$($(VC_LIST_EXCEPT)) \
935 | grep -vE '$(ignore_undesirable_word_sequence_RE_)' | grep . \
936 && { echo '$(ME): undesirable word sequence' >&2; exit 1; } || :
937
938 _ptm1 = use "test C1 && test C2", not "test C1 -''a C2"
939 _ptm2 = use "test C1 || test C2", not "test C1 -''o C2"
940 # Using test's -a and -o operators is not portable.
941 # We prefer test over [, since the latter is spelled [[ in configure.ac.
942 sc_prohibit_test_minus_ao:
943 @prohibit='(\<test| \[+) .+ -[ao] ' \
944 halt='$(_ptm1); $(_ptm2)' \
945 $(_sc_search_regexp)
946
947 # Avoid a test bashism.
948 sc_prohibit_test_double_equal:
949 @prohibit='(\<test| \[+) .+ == ' \
950 containing='#! */bin/[a-z]*sh' \
951 halt='use "test x = x", not "test x =''= x"' \
952 $(_sc_search_regexp)
953
954 # Each program that uses proper_name_utf8 must link with one of the
955 # ICONV libraries. Otherwise, some ICONV library must appear in LDADD.
956 # The perl -0777 invocation below extracts the possibly-multi-line
957 # definition of LDADD from the appropriate Makefile.am and exits 0
958 # when it contains "ICONV".
959 sc_proper_name_utf8_requires_ICONV:
960 @progs=$$(grep -l 'proper_name_utf8 ''("' $$($(VC_LIST_EXCEPT)));\
961 if test "x$$progs" != x; then \
962 fail=0; \
963 for p in $$progs; do \
964 dir=$$(dirname "$$p"); \
965 perl -0777 \
966 -ne 'exit !(/^LDADD =(.+?[^\\]\n)/ms && $$1 =~ /ICONV/)' \
967 $$dir/Makefile.am && continue; \
968 base=$$(basename "$$p" .c); \
969 grep "$${base}_LDADD.*ICONV)" $$dir/Makefile.am > /dev/null \
970 || { fail=1; echo 1>&2 "$(ME): $$p uses proper_name_utf8"; }; \
971 done; \
972 test $$fail = 1 && \
973 { echo 1>&2 '$(ME): the above do not link with any ICONV library'; \
974 exit 1; } || :; \
975 fi
976
977 # Warn about "c0nst struct Foo const foo[]",
978 # but not about "char const *const foo" or "#define const const".
979 sc_redundant_const:
980 @prohibit='\bconst\b[[:space:][:alnum:]]{2,}\bconst\b' \
981 halt='redundant "const" in declarations' \
982 $(_sc_search_regexp)
983
984 sc_const_long_option:
985 @grep '^ *static.*struct option ' $$($(VC_LIST_EXCEPT)) \
986 | grep -Ev 'const struct option|struct option const' && { \
987 echo 1>&2 '$(ME): add "const" to the above declarations'; \
988 exit 1; } || :
989
990 NEWS_hash = \
991 $$(sed -n '/^\*.* $(PREV_VERSION_REGEXP) ([0-9-]*)/,$$p' \
992 $(srcdir)/NEWS \
993 | perl -0777 -pe \
994 's/^Copyright.+?Free\sSoftware\sFoundation,\sInc\.\n//ms' \
995 | md5sum - \
996 | sed 's/ .*//')
997
998 # Ensure that we don't accidentally insert an entry into an old NEWS block.
999 sc_immutable_NEWS:
1000 @if test -f $(srcdir)/NEWS; then \
1001 test "$(NEWS_hash)" = '$(old_NEWS_hash)' && : || \
1002 { echo '$(ME): you have modified old NEWS' 1>&2; exit 1; }; \
1003 fi
1004
1005 # Update the hash stored above. Do this after each release and
1006 # for any corrections to old entries.
1007 update-NEWS-hash: NEWS
1008 perl -pi -e 's/^(old_NEWS_hash[ \t]+:?=[ \t]+).*/$${1}'"$(NEWS_hash)/" \
1009 $(srcdir)/cfg.mk
1010
1011 # Ensure that we use only the standard $(VAR) notation,
1012 # not @...@ in Makefile.am, now that we can rely on automake
1013 # to emit a definition for each substituted variable.
1014 # However, there is still one case in which @VAR@ use is not just
1015 # legitimate, but actually required: when augmenting an automake-defined
1016 # variable with a prefix. For example, gettext uses this:
1017 # MAKEINFO = env LANG= LC_MESSAGES= LC_ALL= LANGUAGE= @MAKEINFO@
1018 # otherwise, makeinfo would put German or French (current locale)
1019 # navigation hints in the otherwise-English documentation.
1020 #
1021 # Allow the package to add exceptions via a hook in cfg.mk;
1022 # for example, @PRAGMA_SYSTEM_HEADER@ can be permitted by
1023 # setting this to ' && !/PRAGMA_SYSTEM_HEADER/'.
1024 _makefile_at_at_check_exceptions ?=
1025 sc_makefile_at_at_check:
1026 @perl -ne '/\@[A-Z_0-9]+\@/' \
1027 -e ' && !/([A-Z_0-9]+)\s+=.*\@\1\@$$/' \
1028 -e ''$(_makefile_at_at_check_exceptions) \
1029 -e 'and (print "$$ARGV:$$.: $$_"), $$m=1; END {exit !$$m}' \
1030 $$($(VC_LIST_EXCEPT) | grep -E '(^|/)(Makefile\.am|[^/]+\.mk)$$') \
1031 && { echo '$(ME): use $$(...), not @...@' 1>&2; exit 1; } || :
1032
1033 news-check: NEWS
1034 if sed -n $(news-check-lines-spec)p $(srcdir)/NEWS \
1035 | grep -E $(news-check-regexp) >/dev/null; then \
1036 :; \
1037 else \
1038 echo 'NEWS: $$(news-check-regexp) failed to match' 1>&2; \
1039 exit 1; \
1040 fi
1041
1042 sc_makefile_TAB_only_indentation:
1043 @prohibit='^ [ ]{8}' \
1044 in_vc_files='akefile|\.mk$$' \
1045 halt='found TAB-8-space indentation' \
1046 $(_sc_search_regexp)
1047
1048 sc_m4_quote_check:
1049 @prohibit='(AC_DEFINE(_UNQUOTED)?|AC_DEFUN)\([^[]' \
1050 in_vc_files='(^configure\.ac|\.m4)$$' \
1051 halt='quote the first arg to AC_DEF*' \
1052 $(_sc_search_regexp)
1053
1054 fix_po_file_diag = \
1055 'you have changed the set of files with translatable diagnostics;\n\
1056 apply the above patch\n'
1057
1058 # Verify that all source files using _() are listed in po/POTFILES.in.
1059 po_file ?= $(srcdir)/po/POTFILES.in
1060 generated_files ?= $(srcdir)/lib/*.[ch]
1061 sc_po_check:
1062 @if test -f $(po_file); then \
1063 grep -E -v '^(#|$$)' $(po_file) \
1064 | grep -v '^src/false\.c$$' \
1065 | sed 's|\[type: gettext/glade\] ||' \
1066 | sort > $@-1; \
1067 files=; \
1068 for file in $$($(VC_LIST_EXCEPT)) $(generated_files); do \
1069 test -r $$file || continue; \
1070 case $$file in \
1071 *.m4|*.mk) continue ;; \
1072 *.?|*.??) ;; \
1073 *.xml) ;; \
1074 *.xml.in) ;; \
1075 *.desktop.in) ;; \
1076 *) continue;; \
1077 esac; \
1078 case $$file in \
1079 *.[ch]) \
1080 base=`expr " $$file" : ' \(.*\)\..'`; \
1081 { test -f $$base.l || test -f $$base.y; } && continue;; \
1082 esac; \
1083 files="$$files $$file"; \
1084 done; \
1085 grep -E -l '(\b(N?_|gettext *)\([^)"]*("|$$))|(<interface>)|^_|<_' $$files \
1086 | sed 's|^$(_dot_escaped_srcdir)/||' | sort -u > $@-2; \
1087 diff -u -L $(po_file) -L $(po_file) $@-1 $@-2 \
1088 || { printf '$(ME): '$(fix_po_file_diag) 1>&2; exit 1; }; \
1089 rm -f $@-1 $@-2; \
1090 fi
1091
1092 # Sometimes it is useful to change the PATH environment variable
1093 # in Makefiles. When doing so, it's better not to use the Unix-centric
1094 # path separator of `:', but rather the automake-provided `$(PATH_SEPARATOR)'.
1095 msg = '$(ME): Do not use `:'\'' above; use $$(PATH_SEPARATOR) instead'
1096 sc_makefile_path_separator_check:
1097 @prohibit='PATH[=].*:' \
1098 in_vc_files='akefile|\.mk$$' \
1099 halt=$(msg) \
1100 $(_sc_search_regexp)
1101
1102 # Check that `make alpha' will not fail at the end of the process,
1103 # i.e., when pkg-M.N.tar.xz already exists (either in "." or in ../release)
1104 # and is read-only.
1105 writable-files:
1106 if test -d $(release_archive_dir); then \
1107 for file in $(DIST_ARCHIVES); do \
1108 for p in ./ $(release_archive_dir)/; do \
1109 test -e $$p$$file || continue; \
1110 test -w $$p$$file \
1111 || { echo ERROR: $$p$$file is not writable; fail=1; }; \
1112 done; \
1113 done; \
1114 test "$$fail" && exit 1 || : ; \
1115 else :; \
1116 fi
1117
1118 v_etc_file = $(gnulib_dir)/lib/version-etc.c
1119 sample-test = tests/sample-test
1120 texi = doc/$(PACKAGE).texi
1121 # Make sure that the copyright date in $(v_etc_file) is up to date.
1122 # Do the same for the $(sample-test) and the main doc/.texi file.
1123 sc_copyright_check:
1124 @require='enum { COPYRIGHT_YEAR = '$$(date +%Y)' };' \
1125 in_files=$(v_etc_file) \
1126 halt='out of date copyright in $(v_etc_file); update it' \
1127 $(_sc_search_regexp)
1128 @require='# Copyright \(C\) '$$(date +%Y)' Free' \
1129 in_vc_files=$(sample-test) \
1130 halt='out of date copyright in $(sample-test); update it' \
1131 $(_sc_search_regexp)
1132 @require='Copyright @copyright\{\} .*'$$(date +%Y)' Free' \
1133 in_vc_files=$(texi) \
1134 halt='out of date copyright in $(texi); update it' \
1135 $(_sc_search_regexp)
1136
1137 # If tests/help-version exists and seems to be new enough, assume that its
1138 # use of init.sh and path_prepend_ is correct, and ensure that every other
1139 # use of init.sh is identical.
1140 # This is useful because help-version cross-checks prog --version
1141 # with $(VERSION), which verifies that its path_prepend_ invocation
1142 # sets PATH correctly. This is an inexpensive way to ensure that
1143 # the other init.sh-using tests also get it right.
1144 _hv_file ?= $(srcdir)/tests/help-version
1145 _hv_regex_weak ?= ^ *\. .*/init\.sh"
1146 # Fix syntax-highlighters "
1147 _hv_regex_strong ?= ^ *\. "\$${srcdir=\.}/init\.sh"
1148 sc_cross_check_PATH_usage_in_tests:
1149 @if test -f $(_hv_file); then \
1150 grep -l 'VERSION mismatch' $(_hv_file) >/dev/null \
1151 || { echo "$@: skipped: no such file: $(_hv_file)" 1>&2; \
1152 exit 0; }; \
1153 grep -lE '$(_hv_regex_strong)' $(_hv_file) >/dev/null \
1154 || { echo "$@: $(_hv_file) lacks conforming use of init.sh" 1>&2; \
1155 exit 1; }; \
1156 good=$$(grep -E '$(_hv_regex_strong)' $(_hv_file)); \
1157 grep -LFx "$$good" \
1158 $$(grep -lE '$(_hv_regex_weak)' $$($(VC_LIST_EXCEPT))) \
1159 | grep . && \
1160 { echo "$(ME): the above files use path_prepend_ inconsistently" \
1161 1>&2; exit 1; } || :; \
1162 fi
1163
1164 # #if HAVE_... will evaluate to false for any non numeric string.
1165 # That would be flagged by using -Wundef, however gnulib currently
1166 # tests many undefined macros, and so we can't enable that option.
1167 # So at least preclude common boolean strings as macro values.
1168 sc_Wundef_boolean:
1169 @prohibit='^#define.*(yes|no|true|false)$$' \
1170 in_files='$(CONFIG_INCLUDE)' \
1171 halt='Use 0 or 1 for macro values' \
1172 $(_sc_search_regexp)
1173
1174 # Even if you use pathmax.h to guarantee that PATH_MAX is defined, it might
1175 # not be constant, or might overflow a stack. In general, use PATH_MAX as
1176 # a limit, not an array or alloca size.
1177 sc_prohibit_path_max_allocation:
1178 @prohibit='(\balloca *\([^)]*|\[[^]]*)PATH_MAX' \
1179 halt='Avoid stack allocations of size PATH_MAX' \
1180 $(_sc_search_regexp)
1181
1182 sc_vulnerable_makefile_CVE-2009-4029:
1183 @prohibit='perm -777 -exec chmod a\+rwx|chmod 777 \$$\(distdir\)' \
1184 in_files=$$(find $(srcdir) -name Makefile.in) \
1185 halt=$$(printf '%s\n' \
1186 'the above files are vulnerable; beware of running' \
1187 ' "make dist*" rules, and upgrade to fixed automake' \
1188 ' see http://bugzilla.redhat.com/542609 for details') \
1189 $(_sc_search_regexp)
1190
1191 vc-diff-check:
1192 (unset CDPATH; cd $(srcdir) && $(VC) diff) > vc-diffs || :
1193 if test -s vc-diffs; then \
1194 cat vc-diffs; \
1195 echo "Some files are locally modified:" 1>&2; \
1196 exit 1; \
1197 else \
1198 rm vc-diffs; \
1199 fi
1200
1201 rel-files = $(DIST_ARCHIVES)
1202
1203 gnulib_dir ?= $(srcdir)/gnulib
1204 gnulib-version = $$(cd $(gnulib_dir) && git describe)
1205 bootstrap-tools ?= autoconf,automake,gnulib
1206
1207 # If it's not already specified, derive the GPG key ID from
1208 # the signed tag we've just applied to mark this release.
1209 gpg_key_ID ?= \
1210 $$(git cat-file tag v$(VERSION) > .ann-sig \
1211 && gpgv .ann-sig - < /dev/null 2>&1 \
1212 | sed -n '/.*key ID \([0-9A-F]*\)/s//\1/p'; rm -f .ann-sig)
1213
1214 translation_project_ ?= coordinator@translationproject.org
1215
1216 # Make info-gnu the default only for a stable release.
1217 ifeq ($(RELEASE_TYPE),stable)
1218 announcement_Cc_ ?= $(translation_project_), $(PACKAGE_BUGREPORT)
1219 announcement_mail_headers_ ?= \
1220 To: info-gnu@gnu.org \
1221 Cc: $(announcement_Cc_) \
1222 Mail-Followup-To: $(PACKAGE_BUGREPORT)
1223 else
1224 announcement_Cc_ ?= $(translation_project_)
1225 announcement_mail_headers_ ?= \
1226 To: $(PACKAGE_BUGREPORT) \
1227 Cc: $(announcement_Cc_)
1228 endif
1229
1230 announcement: NEWS ChangeLog $(rel-files)
1231 @$(srcdir)/$(_build-aux)/announce-gen \
1232 --mail-headers='$(announcement_mail_headers_)' \
1233 --release-type=$(RELEASE_TYPE) \
1234 --package=$(PACKAGE) \
1235 --prev=$(PREV_VERSION) \
1236 --curr=$(VERSION) \
1237 --gpg-key-id=$(gpg_key_ID) \
1238 --news=$(srcdir)/NEWS \
1239 --bootstrap-tools=$(bootstrap-tools) \
1240 --gnulib-version=$(gnulib-version) \
1241 --no-print-checksums \
1242 $(addprefix --url-dir=, $(url_dir_list))
1243
1244 ## ---------------- ##
1245 ## Updating files. ##
1246 ## ---------------- ##
1247
1248 ftp-gnu = ftp://ftp.gnu.org/gnu
1249 www-gnu = http://www.gnu.org
1250
1251 upload_dest_dir_ ?= $(PACKAGE)
1252 emit_upload_commands:
1253 @echo =====================================
1254 @echo =====================================
1255 @echo "$(srcdir)/$(_build-aux)/gnupload $(GNUPLOADFLAGS) \\"
1256 @echo " --to $(gnu_rel_host):$(upload_dest_dir_) \\"
1257 @echo " $(rel-files)"
1258 @echo '# send the ~/announce-$(my_distdir) e-mail'
1259 @echo =====================================
1260 @echo =====================================
1261
1262 define emit-commit-log
1263 printf '%s\n' 'maint: post-release administrivia' '' \
1264 '* NEWS: Add header line for next release.' \
1265 '* .prev-version: Record previous version.' \
1266 '* cfg.mk (old_NEWS_hash): Auto-update.'
1267 endef
1268
1269 .PHONY: no-submodule-changes
1270 no-submodule-changes:
1271 if test -d $(srcdir)/.git; then \
1272 diff=$$(cd $(srcdir) && git submodule -q foreach \
1273 git diff-index --name-only HEAD) \
1274 || exit 1; \
1275 case $$diff in '') ;; \
1276 *) echo '$(ME): submodule files are locally modified:'; \
1277 echo "$$diff"; exit 1;; esac; \
1278 else \
1279 : ; \
1280 fi
1281
1282 submodule-checks ?= no-submodule-changes public-submodule-commit
1283
1284 # Ensure that each sub-module commit we're using is public.
1285 # Without this, it is too easy to tag and release code that
1286 # cannot be built from a fresh clone.
1287 .PHONY: public-submodule-commit
1288 public-submodule-commit:
1289 $(AM_V_GEN)if test -d $(srcdir)/.git; then \
1290 cd $(srcdir) && \
1291 git submodule --quiet foreach test '$$(git rev-parse $$sha1)' \
1292 = '$$(git merge-base origin $$sha1)' \
1293 || { echo '$(ME): found non-public submodule commit' >&2; \
1294 exit 1; }; \
1295 else \
1296 : ; \
1297 fi
1298 # This rule has a high enough utility/cost ratio that it should be a
1299 # dependent of "check" by default. However, some of us do occasionally
1300 # commit a temporary change that deliberately points to a non-public
1301 # submodule commit, and want to be able to use rules like "make check".
1302 # In that case, run e.g., "make check gl_public_submodule_commit="
1303 # to disable this test.
1304 gl_public_submodule_commit ?= public-submodule-commit
1305 check: $(gl_public_submodule_commit)
1306
1307 .PHONY: alpha beta stable
1308 ALL_RECURSIVE_TARGETS += alpha beta stable
1309 alpha beta stable: $(local-check) writable-files $(submodule-checks)
1310 test $@ = stable \
1311 && { echo $(VERSION) | grep -E '^[0-9]+(\.[0-9]+)+$$' \
1312 || { echo "invalid version string: $(VERSION)" 1>&2; exit 1;};}\
1313 || :
1314 $(MAKE) vc-diff-check
1315 $(MAKE) news-check
1316 $(MAKE) distcheck
1317 $(MAKE) dist XZ_OPT=-9ev
1318 $(MAKE) $(release-prep-hook) RELEASE_TYPE=$@
1319 $(MAKE) -s emit_upload_commands RELEASE_TYPE=$@
1320
1321 # Override this in cfg.mk if you follow different procedures.
1322 release-prep-hook ?= release-prep
1323
1324 gl_noteworthy_news_ = * Noteworthy changes in release ?.? (????-??-??) [?]
1325 .PHONY: release-prep
1326 release-prep:
1327 case $$RELEASE_TYPE in alpha|beta|stable) ;; \
1328 *) echo "invalid RELEASE_TYPE: $$RELEASE_TYPE" 1>&2; exit 1;; esac
1329 $(MAKE) --no-print-directory -s announcement > ~/announce-$(my_distdir)
1330 if test -d $(release_archive_dir); then \
1331 ln $(rel-files) $(release_archive_dir); \
1332 chmod a-w $(rel-files); \
1333 fi
1334 echo $(VERSION) > $(prev_version_file)
1335 $(MAKE) update-NEWS-hash
1336 perl -pi -e '$$. == 3 and print "$(gl_noteworthy_news_)\n\n\n"' NEWS
1337 $(emit-commit-log) > .ci-msg
1338 $(VC) commit -F .ci-msg -a
1339 rm .ci-msg
1340
1341 # Override this with e.g., -s $(srcdir)/some_other_name.texi
1342 # if the default $(PACKAGE)-derived name doesn't apply.
1343 gendocs_options_ ?=
1344
1345 .PHONY: web-manual
1346 web-manual:
1347 @test -z "$(manual_title)" \
1348 && { echo define manual_title in cfg.mk 1>&2; exit 1; } || :
1349 @cd '$(srcdir)/doc'; \
1350 $(SHELL) ../$(_build-aux)/gendocs.sh $(gendocs_options_) \
1351 -o '$(abs_builddir)/doc/manual' \
1352 --email $(PACKAGE_BUGREPORT) $(PACKAGE) \
1353 "$(PACKAGE_NAME) - $(manual_title)"
1354 @echo " *** Upload the doc/manual directory to web-cvs."
1355
1356 # Code Coverage
1357
1358 init-coverage:
1359 $(MAKE) $(AM_MAKEFLAGS) clean
1360 lcov --directory . --zerocounters
1361
1362 COVERAGE_CCOPTS ?= "-g --coverage"
1363 COVERAGE_OUT ?= doc/coverage
1364
1365 build-coverage:
1366 $(MAKE) $(AM_MAKEFLAGS) CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS)
1367 $(MAKE) $(AM_MAKEFLAGS) CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS) check
1368 mkdir -p $(COVERAGE_OUT)
1369 lcov --directory . --output-file $(COVERAGE_OUT)/$(PACKAGE).info \
1370 --capture
1371
1372 gen-coverage:
1373 genhtml --output-directory $(COVERAGE_OUT) \
1374 $(COVERAGE_OUT)/$(PACKAGE).info \
1375 --highlight --frames --legend \
1376 --title "$(PACKAGE_NAME)"
1377
1378 coverage: init-coverage build-coverage gen-coverage
1379
1380 # Update gettext files.
1381 PACKAGE ?= $(shell basename $(PWD))
1382 PO_DOMAIN ?= $(PACKAGE)
1383 POURL = http://translationproject.org/latest/$(PO_DOMAIN)/
1384 PODIR ?= po
1385 refresh-po:
1386 rm -f $(PODIR)/*.po && \
1387 echo "$(ME): getting translations into po (please ignore the robots.txt ERROR 404)..." && \
1388 wget --no-verbose --directory-prefix $(PODIR) --no-directories --recursive --level 1 --accept .po --accept .po.1 $(POURL) && \
1389 echo 'en@boldquot' > $(PODIR)/LINGUAS && \
1390 echo 'en@quot' >> $(PODIR)/LINGUAS && \
1391 ls $(PODIR)/*.po | sed 's/\.po//' | sed 's,$(PODIR)/,,' | sort >> $(PODIR)/LINGUAS
1392
1393 # Running indent once is not idempotent, but running it twice is.
1394 INDENT_SOURCES ?= $(C_SOURCES)
1395 .PHONY: indent
1396 indent:
1397 indent $(INDENT_SOURCES)
1398 indent $(INDENT_SOURCES)
1399
1400 # If you want to set UPDATE_COPYRIGHT_* environment variables,
1401 # put the assignments in this variable.
1402 update-copyright-env ?=
1403
1404 # Run this rule once per year (usually early in January)
1405 # to update all FSF copyright year lists in your project.
1406 # If you have an additional project-specific rule,
1407 # add it in cfg.mk along with a line 'update-copyright: prereq'.
1408 # By default, exclude all variants of COPYING; you can also
1409 # add exemptions (such as ChangeLog..* for rotated change logs)
1410 # in the file .x-update-copyright.
1411 .PHONY: update-copyright
1412 update-copyright:
1413 grep -l -w Copyright \
1414 $$(export VC_LIST_EXCEPT_DEFAULT=COPYING && $(VC_LIST_EXCEPT)) \
1415 | $(update-copyright-env) xargs $(srcdir)/$(_build-aux)/$@
1416
1417 # This tight_scope test is skipped with a warning if $(_gl_TS_headers) is not
1418 # overridden and $(_gl_TS_dir)/Makefile.am does not mention noinst_HEADERS.
1419
1420 # NOTE: to override any _gl_TS_* default value, you must
1421 # define the variable(s) using "export" in cfg.mk.
1422 _gl_TS_dir ?= src
1423
1424 ALL_RECURSIVE_TARGETS += sc_tight_scope
1425 sc_tight_scope: tight-scope.mk
1426 @fail=0; \
1427 if ! grep '^ *export _gl_TS_headers *=' $(srcdir)/cfg.mk \
1428 > /dev/null \
1429 && ! grep -w noinst_HEADERS $(srcdir)/$(_gl_TS_dir)/Makefile.am \
1430 > /dev/null 2>&1; then \
1431 echo '$(ME): skipping $@'; \
1432 else \
1433 $(MAKE) -s -C $(_gl_TS_dir) \
1434 -f Makefile \
1435 -f $(abs_top_srcdir)/cfg.mk \
1436 -f $(abs_top_builddir)/$< \
1437 _gl_tight_scope \
1438 || fail=1; \
1439 fi; \
1440 rm -f $<; \
1441 exit $$fail
1442
1443 tight-scope.mk: $(ME)
1444 @rm -f $@ $@-t
1445 @perl -ne '/^# TS-start/.../^# TS-end/ and print' $(ME) > $@-t
1446 @chmod a=r $@-t && mv $@-t $@
1447
1448 ifeq (a,b)
1449 # TS-start
1450
1451 # Most functions should have static scope.
1452 # Any that don't must be marked with `extern', but `main'
1453 # and `usage' are exceptions: they're always extern, but
1454 # do not need to be marked. Symbols matching `__.*' are
1455 # reserved by the compiler, so are automatically excluded below.
1456 _gl_TS_unmarked_extern_functions ?= main usage
1457 _gl_TS_function_match ?= /^(?:$(_gl_TS_extern)) +.*?(\S+) *\(/
1458
1459 # If your project uses a macro like "XTERN", then put
1460 # the following in cfg.mk to override this default:
1461 # export _gl_TS_extern = extern|XTERN
1462 _gl_TS_extern ?= extern
1463
1464 # The second nm|grep checks for file-scope variables with `extern' scope.
1465 # Without gnulib's progname module, you might put program_name here.
1466 # Symbols matching `__.*' are reserved by the compiler,
1467 # so are automatically excluded below.
1468 _gl_TS_unmarked_extern_vars ?=
1469
1470 # NOTE: the _match variables are perl expressions -- not mere regular
1471 # expressions -- so that you can extend them to match other patterns
1472 # and easily extract matched variable names.
1473 # For example, if your project declares some global variables via
1474 # a macro like this: GLOBAL(type, var_name, initializer), then you
1475 # can override this definition to automatically extract those names:
1476 # export _gl_TS_var_match = \
1477 # /^(?:$(_gl_TS_extern)) .*?\**(\w+)(\[.*?\])?;/ || /\bGLOBAL\(.*?,\s*(.*?),/
1478 _gl_TS_var_match ?= /^(?:$(_gl_TS_extern)) .*?(\w+)(\[.*?\])?;/
1479
1480 # The names of object files in (or relative to) $(_gl_TS_dir).
1481 _gl_TS_obj_files ?= *.$(OBJEXT)
1482
1483 # Files in which to search for the one-line style extern declarations.
1484 # $(_gl_TS_dir)-relative.
1485 _gl_TS_headers ?= $(noinst_HEADERS)
1486
1487 .PHONY: _gl_tight_scope
1488 _gl_tight_scope: $(bin_PROGRAMS)
1489 t=exceptions-$$$$; \
1490 trap 's=$$?; rm -f $$t; exit $$s' 0; \
1491 for sig in 1 2 3 13 15; do \
1492 eval "trap 'v=`expr $$sig + 128`; (exit $$v); exit $$v' $$sig"; \
1493 done; \
1494 src=`for f in $(SOURCES); do \
1495 test -f $$f && d= || d=$(srcdir)/; echo $$d$$f; done`; \
1496 hdr=`for f in $(_gl_TS_headers); do \
1497 test -f $$f && d= || d=$(srcdir)/; echo $$d$$f; done`; \
1498 ( printf '^%s$$\n' '__.*' $(_gl_TS_unmarked_extern_functions); \
1499 grep -h -A1 '^extern .*[^;]$$' $$src \
1500 | grep -vE '^(extern |--)' | sed 's/ .*//'; \
1501 perl -lne \
1502 '$(_gl_TS_function_match) and print "^$$1\$$"' $$hdr; \
1503 ) | sort -u > $$t; \
1504 nm -e $(_gl_TS_obj_files) | sed -n 's/.* T //p'|grep -Ev -f $$t \
1505 && { echo the above functions should have static scope >&2; \
1506 exit 1; } || : ; \
1507 ( printf '^%s$$\n' '__.*' $(_gl_TS_unmarked_extern_vars); \
1508 perl -lne '$(_gl_TS_var_match) and print "^$$1\$$"' $$hdr *.h \
1509 ) | sort -u > $$t; \
1510 nm -e $(_gl_TS_obj_files) | sed -n 's/.* [BCDGRS] //p' \
1511 | sort -u | grep -Ev -f $$t \
1512 && { echo the above variables should have static scope >&2; \
1513 exit 1; } || :
1514 # TS-end
1515 endif