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