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