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