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