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