Commit | Line | Data |
---|---|---|
c84bdaf6 LC |
1 | # -*-Makefile-*- |
2 | # This Makefile fragment tries to be general-purpose enough to be | |
3 | # used by many projects via the gnulib maintainer-makefile module. | |
4 | ||
5 | ## Copyright (C) 2001-2009 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 | # Override this in cfg.mk if you use a non-standard build-aux directory. | |
25 | build_aux ?= $(srcdir)/build-aux | |
26 | ||
27 | # Do not save the original name or timestamp in the .tar.gz file. | |
28 | # Use --rsyncable if available. | |
29 | gzip_rsyncable := \ | |
30 | $(shell gzip --help 2>/dev/null|grep rsyncable >/dev/null && echo --rsyncable) | |
31 | GZIP_ENV = '--no-name --best $(gzip_rsyncable)' | |
32 | ||
33 | # cfg.mk must define the gpg_key_ID used by this package. | |
34 | GIT = git | |
35 | VC = $(GIT) | |
36 | VC-tag = git tag -s -m '$(VERSION)' -u '$(gpg_key_ID)' | |
37 | ||
38 | VC_LIST = $(build_aux)/vc-list-files -C $(srcdir) | |
39 | ||
40 | VC_LIST_EXCEPT = \ | |
41 | $(VC_LIST) | if test -f $(srcdir)/.x-$@; then grep -vEf $(srcdir)/.x-$@; \ | |
42 | else grep -Ev "$${VC_LIST_EXCEPT_DEFAULT-ChangeLog}"; fi | |
43 | ||
44 | ifeq ($(origin prev_version_file), undefined) | |
45 | prev_version_file = $(srcdir)/.prev-version | |
46 | endif | |
47 | ||
48 | PREV_VERSION := $(shell cat $(prev_version_file) 2>/dev/null) | |
49 | VERSION_REGEXP = $(subst .,\.,$(VERSION)) | |
50 | PREV_VERSION_REGEXP = $(subst .,\.,$(PREV_VERSION)) | |
51 | ||
52 | ifeq ($(VC),$(GIT)) | |
53 | this-vc-tag = v$(VERSION) | |
54 | this-vc-tag-regexp = v$(VERSION_REGEXP) | |
55 | else | |
56 | tag-package = $(shell echo "$(PACKAGE)" | tr '[:lower:]' '[:upper:]') | |
57 | tag-this-version = $(subst .,_,$(VERSION)) | |
58 | this-vc-tag = $(tag-package)-$(tag-this-version) | |
59 | this-vc-tag-regexp = $(this-vc-tag) | |
60 | endif | |
61 | my_distdir = $(PACKAGE)-$(VERSION) | |
62 | ||
63 | # Old releases are stored here. | |
64 | release_archive_dir ?= ../release | |
65 | ||
414e4441 LC |
66 | # Override gnu_rel_host and url_dir_list in cfg.mk if these are not right. |
67 | # Use alpha.gnu.org for alpha and beta releases. | |
68 | # Use ftp.gnu.org for stable releases. | |
69 | gnu_ftp_host-alpha = alpha.gnu.org | |
70 | gnu_ftp_host-beta = alpha.gnu.org | |
71 | gnu_ftp_host-stable = ftp.gnu.org | |
72 | gnu_rel_host ?= $(gnu_ftp_host-$(RELEASE_TYPE)) | |
73 | ||
74 | ifeq ($(gnu_rel_host),ftp.gnu.org) | |
75 | url_dir_list ?= http://ftpmirror.gnu.org/$(PACKAGE) | |
76 | else | |
77 | url_dir_list ?= ftp://$(gnu_rel_host)/gnu/$(PACKAGE) | |
78 | endif | |
79 | ||
c84bdaf6 LC |
80 | # Prevent programs like 'sort' from considering distinct strings to be equal. |
81 | # Doing it here saves us from having to set LC_ALL elsewhere in this file. | |
82 | export LC_ALL = C | |
83 | ||
84 | ## --------------- ## | |
85 | ## Sanity checks. ## | |
86 | ## --------------- ## | |
87 | ||
88 | _cfg_mk := $(shell test -f $(srcdir)/cfg.mk && echo '$(srcdir)/cfg.mk') | |
89 | ||
90 | # Collect the names of rules starting with `sc_'. | |
91 | syntax-check-rules := $(sort $(shell sed -n 's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' \ | |
92 | $(srcdir)/$(ME) $(_cfg_mk))) | |
93 | .PHONY: $(syntax-check-rules) | |
94 | ||
95 | local-checks-available = \ | |
96 | $(syntax-check-rules) | |
97 | .PHONY: $(local-checks-available) | |
98 | ||
99 | # Arrange to print the name of each syntax-checking rule just before running it. | |
100 | $(syntax-check-rules): %: %.m | |
101 | $(patsubst %, %.m, $(syntax-check-rules)): | |
102 | @echo $(patsubst sc_%.m, %, $@) | |
103 | ||
104 | local-check := $(filter-out $(local-checks-to-skip), $(local-checks-available)) | |
105 | ||
106 | syntax-check: $(local-check) | |
107 | # @grep -nE '# *include <(limits|std(def|arg|bool))\.h>' \ | |
108 | # $$(find -type f -name '*.[chly]') && \ | |
109 | # { echo '$(ME): found conditional include' 1>&2; \ | |
110 | # exit 1; } || : | |
111 | ||
112 | # grep -nE '^# *include <(string|stdlib)\.h>' \ | |
113 | # $(srcdir)/{lib,src}/*.[chy] && \ | |
114 | # { echo '$(ME): FIXME' 1>&2; \ | |
115 | # exit 1; } || : | |
116 | # FIXME: don't allow `#include .strings\.h' anywhere | |
117 | ||
118 | # By default, _prohibit_regexp does not ignore case. | |
119 | export ignore_case = | |
120 | _ignore_case = $$(test -n "$$ignore_case" && echo -i || :) | |
121 | ||
122 | # There are many rules below that prohibit constructs in this package. | |
123 | # If the offending construct can be matched with a grep-E-style regexp, | |
124 | # use this macro. The shell variables "re" and "msg" must be defined. | |
125 | define _prohibit_regexp | |
126 | dummy=; : so we do not need a semicolon before each use; \ | |
127 | test "x$$re" != x || { echo '$(ME): re not defined' 1>&2; exit 1; }; \ | |
128 | test "x$$msg" != x || { echo '$(ME): msg not defined' 1>&2; exit 1; };\ | |
129 | grep $(_ignore_case) -nE "$$re" $$($(VC_LIST_EXCEPT)) && \ | |
130 | { echo '$(ME): '"$$msg" 1>&2; exit 1; } || : | |
131 | endef | |
132 | ||
133 | sc_avoid_if_before_free: | |
134 | @$(build_aux)/useless-if-before-free \ | |
135 | $(useless_free_options) \ | |
136 | $$($(VC_LIST_EXCEPT) | grep -v useless-if-before-free) && \ | |
137 | { echo '$(ME): found useless "if" before "free" above' 1>&2; \ | |
138 | exit 1; } || : | |
139 | ||
140 | sc_cast_of_argument_to_free: | |
141 | @re='\<free *\( *\(' msg='don'\''t cast free argument' \ | |
142 | $(_prohibit_regexp) | |
143 | ||
144 | sc_cast_of_x_alloc_return_value: | |
145 | @re='\*\) *x(m|c|re)alloc\>' \ | |
146 | msg='don'\''t cast x*alloc return value' \ | |
147 | $(_prohibit_regexp) | |
148 | ||
149 | sc_cast_of_alloca_return_value: | |
150 | @re='\*\) *alloca\>' msg='don'\''t cast alloca return value' \ | |
151 | $(_prohibit_regexp) | |
152 | ||
153 | sc_space_tab: | |
154 | @re='[ ] ' msg='found SPACE-TAB sequence; remove the SPACE' \ | |
155 | $(_prohibit_regexp) | |
156 | ||
157 | # Don't use *scanf or the old ato* functions in `real' code. | |
158 | # They provide no error checking mechanism. | |
159 | # Instead, use strto* functions. | |
160 | sc_prohibit_atoi_atof: | |
161 | @re='\<([fs]?scanf|ato([filq]|ll)) *\(' \ | |
162 | msg='do not use *scan''f, ato''f, ato''i, ato''l, ato''ll or ato''q' \ | |
163 | $(_prohibit_regexp) | |
164 | ||
165 | # Use STREQ rather than comparing strcmp == 0, or != 0. | |
166 | sc_prohibit_strcmp: | |
167 | @grep -nE '! *str''cmp *\(|\<str''cmp *\([^)]+\) *==' \ | |
168 | $$($(VC_LIST_EXCEPT)) \ | |
169 | | grep -vE ':# *define STREQ\(' && \ | |
170 | { echo '$(ME): use STREQ in place of the above uses of str''cmp' \ | |
171 | 1>&2; exit 1; } || : | |
172 | ||
173 | # Pass EXIT_*, not number, to usage, exit, and error (when exiting) | |
414e4441 LC |
174 | # Convert all uses automatically, via these two commands: |
175 | # git grep -l '\<exit *(1)' \ | |
176 | # | grep -vEf .x-sc_prohibit_magic_number_exit \ | |
177 | # | xargs --no-run-if-empty \ | |
178 | # perl -pi -e 's/(^|[^.])\b(exit ?)\(1\)/$1$2(EXIT_FAILURE)/' | |
179 | # git grep -l '\<exit *(0)' \ | |
180 | # | grep -vEf .x-sc_prohibit_magic_number_exit \ | |
181 | # | xargs --no-run-if-empty \ | |
182 | # perl -pi -e 's/(^|[^.])\b(exit ?)\(0\)/$1$2(EXIT_SUCCESS)/' | |
c84bdaf6 | 183 | sc_prohibit_magic_number_exit: |
414e4441 | 184 | @re='(^|[^.])\<(usage|exit) ?\([0-9]|\<error ?\([1-9][0-9]*,' \ |
c84bdaf6 LC |
185 | msg='use EXIT_* values rather than magic number' \ |
186 | $(_prohibit_regexp) | |
187 | ||
188 | # Using EXIT_SUCCESS as the first argument to error is misleading, | |
189 | # since when that parameter is 0, error does not exit. Use `0' instead. | |
190 | sc_error_exit_success: | |
191 | @grep -nE 'error \(EXIT_SUCCESS,' \ | |
192 | $$($(VC_LIST_EXCEPT) | grep -E '\.[chly]$$') && \ | |
193 | { echo '$(ME): found error (EXIT_SUCCESS' 1>&2; exit 1; } || : | |
194 | ||
195 | # `FATAL:' should be fully upper-cased in error messages | |
196 | # `WARNING:' should be fully upper-cased, or fully lower-cased | |
197 | sc_error_message_warn_fatal: | |
198 | @grep -nEA2 '[^rp]error \(' $$($(VC_LIST_EXCEPT)) \ | |
199 | | grep -E '"Warning|"Fatal|"fatal' && \ | |
200 | { echo '$(ME): use FATAL, WARNING or warning' 1>&2; \ | |
201 | exit 1; } || : | |
202 | ||
203 | # Error messages should not start with a capital letter | |
204 | sc_error_message_uppercase: | |
205 | @grep -nEA2 '[^rp]error \(' $$($(VC_LIST_EXCEPT)) \ | |
206 | | grep -E '"[A-Z]' \ | |
207 | | grep -vE '"FATAL|"WARNING|"Java|"C#|PRIuMAX' && \ | |
208 | { echo '$(ME): found capitalized error message' 1>&2; \ | |
209 | exit 1; } || : | |
210 | ||
211 | # Error messages should not end with a period | |
212 | sc_error_message_period: | |
213 | @grep -nEA2 '[^rp]error \(' $$($(VC_LIST_EXCEPT)) \ | |
214 | | grep -E '[^."]\."' && \ | |
215 | { echo '$(ME): found error message ending in period' 1>&2; \ | |
216 | exit 1; } || : | |
217 | ||
218 | sc_file_system: | |
219 | @re=file''system ignore_case=1 \ | |
220 | msg='found use of "file''system"; spell it "file system"' \ | |
221 | $(_prohibit_regexp) | |
222 | ||
223 | # Don't use cpp tests of this symbol. All code assumes config.h is included. | |
224 | sc_prohibit_have_config_h: | |
225 | @grep -n '^# *if.*HAVE''_CONFIG_H' $$($(VC_LIST_EXCEPT)) && \ | |
226 | { echo '$(ME): found use of HAVE''_CONFIG_H; remove' \ | |
227 | 1>&2; exit 1; } || : | |
228 | ||
229 | # Nearly all .c files must include <config.h>. However, we also permit this | |
230 | # via inclusion of a package-specific header, if cfg.mk specified one. | |
231 | # config_h_header must be suitable for grep -E. | |
232 | config_h_header ?= <config\.h> | |
233 | sc_require_config_h: | |
234 | @if $(VC_LIST_EXCEPT) | grep -l '\.c$$' > /dev/null; then \ | |
235 | grep -EL '^# *include $(config_h_header)' \ | |
236 | $$($(VC_LIST_EXCEPT) | grep '\.c$$') \ | |
237 | | grep . && \ | |
238 | { echo '$(ME): the above files do not include <config.h>' \ | |
239 | 1>&2; exit 1; } || :; \ | |
240 | else :; \ | |
241 | fi | |
242 | ||
243 | # You must include <config.h> before including any other header file. | |
244 | # This can possibly be via a package-specific header, if given by cfg.mk. | |
245 | sc_require_config_h_first: | |
246 | @if $(VC_LIST_EXCEPT) | grep -l '\.c$$' > /dev/null; then \ | |
247 | fail=0; \ | |
248 | for i in $$($(VC_LIST_EXCEPT) | grep '\.c$$'); do \ | |
249 | grep '^# *include\>' $$i | sed 1q \ | |
250 | | grep -E '^# *include $(config_h_header)' > /dev/null \ | |
251 | || { echo $$i; fail=1; }; \ | |
252 | done; \ | |
253 | test $$fail = 1 && \ | |
254 | { echo '$(ME): the above files include some other header' \ | |
255 | 'before <config.h>' 1>&2; exit 1; } || :; \ | |
256 | else :; \ | |
257 | fi | |
258 | ||
259 | sc_prohibit_HAVE_MBRTOWC: | |
260 | @re='\bHAVE_MBRTOWC\b' msg="do not use $$re; it is always defined" \ | |
261 | $(_prohibit_regexp) | |
262 | ||
263 | # To use this "command" macro, you must first define two shell variables: | |
264 | # h: the header, enclosed in <> or "" | |
265 | # re: a regular expression that matches IFF something provided by $h is used. | |
266 | define _header_without_use | |
267 | dummy=; : so we do not need a semicolon before each use; \ | |
268 | h_esc=`echo "$$h"|sed 's/\./\\\\./g'`; \ | |
269 | if $(VC_LIST_EXCEPT) | grep -l '\.c$$' > /dev/null; then \ | |
270 | files=$$(grep -l '^# *include '"$$h_esc" \ | |
271 | $$($(VC_LIST_EXCEPT) | grep '\.c$$')) && \ | |
272 | grep -LE "$$re" $$files | grep . && \ | |
273 | { echo "$(ME): the above files include $$h but don't use it" \ | |
274 | 1>&2; exit 1; } || :; \ | |
275 | else :; \ | |
276 | fi | |
277 | endef | |
278 | ||
279 | # Prohibit the inclusion of assert.h without an actual use of assert. | |
280 | sc_prohibit_assert_without_use: | |
281 | @h='<assert.h>' re='\<assert *\(' $(_header_without_use) | |
282 | ||
283 | # Prohibit the inclusion of close-stream.h without an actual use. | |
284 | sc_prohibit_close_stream_without_use: | |
285 | @h='"close-stream.h"' re='\<close_stream *\(' $(_header_without_use) | |
286 | ||
287 | # Prohibit the inclusion of getopt.h without an actual use. | |
288 | sc_prohibit_getopt_without_use: | |
289 | @h='<getopt.h>' re='\<getopt(_long)? *\(' $(_header_without_use) | |
290 | ||
291 | # Don't include quotearg.h unless you use one of its functions. | |
292 | sc_prohibit_quotearg_without_use: | |
293 | @h='"quotearg.h"' re='\<quotearg(_[^ ]+)? *\(' $(_header_without_use) | |
294 | ||
295 | # Don't include quote.h unless you use one of its functions. | |
296 | sc_prohibit_quote_without_use: | |
297 | @h='"quote.h"' re='\<quote(_n)? *\(' $(_header_without_use) | |
298 | ||
299 | # Don't include this header unless you use one of its functions. | |
300 | sc_prohibit_long_options_without_use: | |
301 | @h='"long-options.h"' re='\<parse_long_options *\(' \ | |
302 | $(_header_without_use) | |
303 | ||
304 | # Don't include this header unless you use one of its functions. | |
305 | sc_prohibit_inttostr_without_use: | |
306 | @h='"inttostr.h"' re='\<(off|[iu]max|uint)tostr *\(' \ | |
307 | $(_header_without_use) | |
308 | ||
309 | # Don't include this header unless you use one of its functions. | |
310 | sc_prohibit_error_without_use: | |
311 | @h='"error.h"' \ | |
312 | re='\<error(_at_line|_print_progname|_one_per_line|_message_count)? *\('\ | |
313 | $(_header_without_use) | |
314 | ||
315 | # Don't include xalloc.h unless you use one of its functions. | |
316 | # Consider these symbols: | |
317 | # perl -lne '/^# *define (\w+)\(/ and print $1' lib/xalloc.h|grep -v '^__'; | |
318 | # perl -lne '/^(?:extern )?(?:void|char) \*?(\w+) \(/ and print $1' lib/xalloc.h | |
319 | # Divide into two sets on case, and filter each through this: | |
320 | # | sort | perl -MRegexp::Assemble -le \ | |
321 | # 'print Regexp::Assemble->new(file => "/dev/stdin")->as_string'|sed 's/\?://g' | |
322 | # Note this was produced by the above: | |
323 | # _xa1 = x(alloc_(oversized|die)|([cz]|2?re)alloc|m(alloc|emdup)|strdup) | |
324 | # But we can do better: | |
325 | _xa1 = x(alloc_(oversized|die)|([cmz]|2?re)alloc|(mem|str)dup) | |
326 | _xa2 = X([CZ]|N?M)ALLOC | |
327 | sc_prohibit_xalloc_without_use: | |
328 | @h='"xalloc.h"' \ | |
329 | re='\<($(_xa1)|$(_xa2)) *\('\ | |
330 | $(_header_without_use) | |
331 | ||
332 | sc_prohibit_safe_read_without_use: | |
333 | @h='"safe-read.h"' re='(\<SAFE_READ_ERROR\>|\<safe_read *\()' \ | |
334 | $(_header_without_use) | |
335 | ||
336 | sc_prohibit_argmatch_without_use: | |
337 | @h='"argmatch.h"' \ | |
338 | re='(\<(ARRAY_CARDINALITY|X?ARGMATCH(|_TO_ARGUMENT|_VERIFY))\>|\<argmatch(_exit_fn|_(in)?valid) *\()' \ | |
339 | $(_header_without_use) | |
340 | ||
341 | sc_prohibit_canonicalize_without_use: | |
342 | @h='"canonicalize.h"' \ | |
343 | re='CAN_(EXISTING|ALL_BUT_LAST|MISSING)|canonicalize_(mode_t|filename_mode)' \ | |
344 | $(_header_without_use) | |
345 | ||
346 | sc_prohibit_root_dev_ino_without_use: | |
347 | @h='"root-dev-ino.h"' \ | |
348 | re='(\<ROOT_DEV_INO_(CHECK|WARN)\>|\<get_root_dev_ino *\()' \ | |
349 | $(_header_without_use) | |
350 | ||
351 | sc_prohibit_openat_without_use: | |
352 | @h='"openat.h"' \ | |
353 | re='\<(openat_(permissive|needs_fchdir|(save|restore)_fail)|l?(stat|ch(own|mod))at|(euid)?accessat)\>' \ | |
354 | $(_header_without_use) | |
355 | ||
356 | # Prohibit the inclusion of c-ctype.h without an actual use. | |
357 | ctype_re = isalnum|isalpha|isascii|isblank|iscntrl|isdigit|isgraph|islower\ | |
358 | |isprint|ispunct|isspace|isupper|isxdigit|tolower|toupper | |
359 | sc_prohibit_c_ctype_without_use: | |
360 | @h='[<"]c-ctype.h[">]' re='\<c_($(ctype_re)) *\(' $(_header_without_use) | |
361 | ||
362 | _empty = | |
363 | _sp = $(_empty) $(_empty) | |
364 | # The following list was generated by running: | |
365 | # man signal.h|col -b|perl -ne '/bsd_signal.*;/.../sigwaitinfo.*;/ and print' \ | |
366 | # | perl -lne '/^\s+(?:int|void).*?(\w+).*/ and print $1' | fmt | |
367 | _sig_functions = \ | |
368 | bsd_signal kill killpg pthread_kill pthread_sigmask raise sigaction \ | |
369 | sigaddset sigaltstack sigdelset sigemptyset sigfillset sighold sigignore \ | |
370 | siginterrupt sigismember signal sigpause sigpending sigprocmask sigqueue \ | |
371 | sigrelse sigset sigsuspend sigtimedwait sigwait sigwaitinfo | |
372 | _sig_function_re = $(subst $(_sp),|,$(strip $(_sig_functions))) | |
373 | # The following were extracted from "man signal.h" manually. | |
374 | _sig_types_and_consts = \ | |
375 | MINSIGSTKSZ SA_NOCLDSTOP SA_NOCLDWAIT SA_NODEFER SA_ONSTACK \ | |
376 | SA_RESETHAND SA_RESTART SA_SIGINFO SIGEV_NONE SIGEV_SIGNAL \ | |
377 | SIGEV_THREAD SIGSTKSZ SIG_BLOCK SIG_SETMASK SIG_UNBLOCK SS_DISABLE \ | |
378 | SS_ONSTACK mcontext_t pid_t sig_atomic_t sigevent siginfo_t sigset_t \ | |
379 | sigstack sigval stack_t ucontext_t | |
380 | # generated via this: | |
381 | # perl -lne '/^#ifdef (SIG\w+)/ and print $1' lib/sig2str.c|sort -u|fmt -70 | |
382 | _sig_names = \ | |
383 | SIGABRT SIGALRM SIGALRM1 SIGBUS SIGCANCEL SIGCHLD SIGCLD SIGCONT \ | |
384 | SIGDANGER SIGDIL SIGEMT SIGFPE SIGFREEZE SIGGRANT SIGHUP SIGILL \ | |
385 | SIGINFO SIGINT SIGIO SIGIOT SIGKAP SIGKILL SIGKILLTHR SIGLOST SIGLWP \ | |
386 | SIGMIGRATE SIGMSG SIGPHONE SIGPIPE SIGPOLL SIGPRE SIGPROF SIGPWR \ | |
387 | SIGQUIT SIGRETRACT SIGSAK SIGSEGV SIGSOUND SIGSTKFLT SIGSTOP SIGSYS \ | |
388 | SIGTERM SIGTHAW SIGTRAP SIGTSTP SIGTTIN SIGTTOU SIGURG SIGUSR1 \ | |
389 | SIGUSR2 SIGVIRT SIGVTALRM SIGWAITING SIGWINCH SIGWIND SIGWINDOW \ | |
390 | SIGXCPU SIGXFSZ | |
391 | _sig_syms_re = $(subst $(_sp),|,$(strip $(_sig_names) $(_sig_types_and_consts))) | |
392 | ||
393 | # Prohibit the inclusion of signal.h without an actual use. | |
394 | sc_prohibit_signal_without_use: | |
395 | @h='<signal.h>' \ | |
396 | re='\<($(_sig_function_re)) *\(|\<($(_sig_syms_re))\>' \ | |
397 | $(_header_without_use) | |
398 | ||
399 | sc_obsolete_symbols: | |
400 | @re='\<(HAVE''_FCNTL_H|O''_NDELAY)\>' \ | |
401 | msg='do not use HAVE''_FCNTL_H or O'_NDELAY \ | |
402 | $(_prohibit_regexp) | |
403 | ||
404 | # FIXME: warn about definitions of EXIT_FAILURE, EXIT_SUCCESS, STREQ | |
405 | ||
406 | # Each nonempty ChangeLog line must start with a year number, or a TAB. | |
407 | sc_changelog: | |
408 | @if $(VC_LIST_EXCEPT) | grep -l '^ChangeLog$$' >/dev/null; then \ | |
409 | grep -n '^[^12 ]' \ | |
410 | $$($(VC_LIST_EXCEPT) | grep '^ChangeLog$$') && \ | |
411 | { echo '$(ME): found unexpected prefix in a ChangeLog' 1>&2; \ | |
412 | exit 1; } || :; \ | |
413 | fi | |
414 | ||
415 | # Ensure that each .c file containing a "main" function also | |
416 | # calls set_program_name. | |
417 | sc_program_name: | |
418 | @if $(VC_LIST_EXCEPT) | grep -l '\.c$$' > /dev/null; then \ | |
419 | files=$$(grep -l '^main *(' $$($(VC_LIST_EXCEPT) | grep '\.c$$')); \ | |
420 | grep -LE 'set_program_name *\(m?argv\[0\]\);' $$files \ | |
421 | | grep . && \ | |
422 | { echo '$(ME): the above files do not call set_program_name' \ | |
423 | 1>&2; exit 1; } || :; \ | |
424 | else :; \ | |
425 | fi | |
426 | ||
427 | # Require that the final line of each test-lib.sh-using test be this one: | |
428 | # Exit $fail | |
429 | # Note: this test requires GNU grep's --label= option. | |
430 | Exit_witness_file ?= tests/test-lib.sh | |
431 | Exit_base := $(notdir $(Exit_witness_file)) | |
432 | sc_require_test_exit_idiom: | |
433 | @if test -f $(srcdir)/$(Exit_witness_file); then \ | |
434 | die=0; \ | |
435 | for i in $$(grep -l -F 'srcdir/$(Exit_base)' \ | |
436 | $$($(VC_LIST) tests)); do \ | |
437 | tail -n1 $$i | grep '^Exit .' > /dev/null \ | |
438 | && : || { die=1; echo $$i; } \ | |
439 | done; \ | |
440 | test $$die = 1 && \ | |
441 | { echo 1>&2 '$(ME): the final line in each of the above is not:'; \ | |
442 | echo 1>&2 'Exit something'; \ | |
443 | exit 1; } || :; \ | |
444 | fi | |
445 | ||
446 | sc_the_the: | |
447 | @re='\<the ''the\>' \ | |
448 | ignore_case=1 msg='found use of "the ''the";' \ | |
449 | $(_prohibit_regexp) | |
450 | ||
451 | sc_trailing_blank: | |
452 | @re='[ ]$$' \ | |
453 | msg='found trailing blank(s)' \ | |
454 | $(_prohibit_regexp) | |
455 | ||
456 | # Match lines like the following, but where there is only one space | |
457 | # between the options and the description: | |
458 | # -D, --all-repeated[=delimit-method] print all duplicate lines\n | |
459 | longopt_re = --[a-z][0-9A-Za-z-]*(\[?=[0-9A-Za-z-]*\]?)? | |
460 | sc_two_space_separator_in_usage: | |
461 | @grep -nE '^ *(-[A-Za-z],)? $(longopt_re) [^ ].*\\$$' \ | |
462 | $$($(VC_LIST_EXCEPT)) && \ | |
463 | { echo "$(ME): help2man requires at least two spaces between"; \ | |
464 | echo "$(ME): an option and its description"; \ | |
465 | 1>&2; exit 1; } || : | |
466 | ||
467 | # Look for diagnostics that aren't marked for translation. | |
468 | # This won't find any for which error's format string is on a separate line. | |
469 | sc_unmarked_diagnostics: | |
470 | @grep -nE \ | |
471 | '\<error \([^"]*"[^"]*[a-z]{3}' $$($(VC_LIST_EXCEPT)) \ | |
472 | | grep -v '_''(' && \ | |
473 | { echo '$(ME): found unmarked diagnostic(s)' 1>&2; \ | |
474 | exit 1; } || : | |
475 | ||
476 | # Avoid useless parentheses like those in this example: | |
477 | # #if defined (SYMBOL) || defined (SYM2) | |
478 | sc_useless_cpp_parens: | |
479 | @grep -n '^# *if .*defined *(' $$($(VC_LIST_EXCEPT)) && \ | |
480 | { echo '$(ME): found useless parentheses in cpp directive' \ | |
481 | 1>&2; exit 1; } || : | |
482 | ||
483 | # Require the latest GPL. | |
484 | sc_GPL_version: | |
485 | @re='either ''version [^3]' msg='GPL vN, N!=3' \ | |
486 | $(_prohibit_regexp) | |
487 | ||
488 | cvs_keywords = \ | |
489 | Author|Date|Header|Id|Name|Locker|Log|RCSfile|Revision|Source|State | |
490 | ||
491 | sc_prohibit_cvs_keyword: | |
492 | @re='\$$($(cvs_keywords))\$$' \ | |
493 | msg='do not use CVS keyword expansion' \ | |
494 | $(_prohibit_regexp) | |
495 | ||
496 | # Make sure we don't use st_blocks. Use ST_NBLOCKS instead. | |
497 | # This is a bit of a kludge, since it prevents use of the string | |
498 | # even in comments, but for now it does the job with no false positives. | |
499 | sc_prohibit_stat_st_blocks: | |
500 | @re='[.>]st_blocks' msg='do not use st_blocks; use ST_NBLOCKS' \ | |
501 | $(_prohibit_regexp) | |
502 | ||
503 | # Make sure we don't define any S_IS* macros in src/*.c files. | |
504 | # They're already defined via gnulib's sys/stat.h replacement. | |
505 | sc_prohibit_S_IS_definition: | |
506 | @re='^ *# *define *S_IS' \ | |
507 | msg='do not define S_IS* macros; include <sys/stat.h>' \ | |
508 | $(_prohibit_regexp) | |
509 | ||
510 | # Each program that uses proper_name_utf8 must link with | |
511 | # one of the ICONV libraries. | |
512 | sc_proper_name_utf8_requires_ICONV: | |
513 | @progs=$$(grep -l 'proper_name_utf8 ''("' $$($(VC_LIST_EXCEPT)));\ | |
514 | if test "x$$progs" != x; then \ | |
515 | fail=0; \ | |
516 | for p in $$progs; do \ | |
517 | dir=$$(dirname "$$p"); \ | |
518 | base=$$(basename "$$p" .c); \ | |
519 | grep "$${base}_LDADD.*ICONV)" $$dir/Makefile.am > /dev/null \ | |
520 | || { fail=1; echo 1>&2 "$(ME): $$p uses proper_name_utf8"; }; \ | |
521 | done; \ | |
522 | test $$fail = 1 && \ | |
523 | { echo 1>&2 '$(ME): the above do not link with any ICONV library'; \ | |
524 | exit 1; } || :; \ | |
525 | fi | |
526 | ||
527 | # Warn about "c0nst struct Foo const foo[]", | |
528 | # but not about "char const *const foo" or "#define const const". | |
529 | sc_redundant_const: | |
530 | @re='\bconst\b[[:space:][:alnum:]]{2,}\bconst\b' \ | |
531 | msg='redundant "const" in declarations' \ | |
532 | $(_prohibit_regexp) | |
533 | ||
534 | sc_const_long_option: | |
535 | @grep '^ *static.*struct option ' $$($(VC_LIST_EXCEPT)) \ | |
536 | | grep -Ev 'const struct option|struct option const' && { \ | |
537 | echo 1>&2 '$(ME): add "const" to the above declarations'; \ | |
538 | exit 1; } || : | |
539 | ||
540 | NEWS_hash = \ | |
541 | $$(sed -n '/^\*.* $(PREV_VERSION_REGEXP) ([0-9-]*)/,$$p' \ | |
542 | $(srcdir)/NEWS \ | |
543 | | grep -v '^Copyright .*Free Software' \ | |
544 | | md5sum - \ | |
545 | | sed 's/ .*//') | |
546 | ||
547 | # Ensure that we don't accidentally insert an entry into an old NEWS block. | |
548 | sc_immutable_NEWS: | |
549 | @if test -f $(srcdir)/NEWS; then \ | |
550 | test "$(NEWS_hash)" = '$(old_NEWS_hash)' && : || \ | |
551 | { echo '$(ME): you have modified old NEWS' 1>&2; exit 1; }; \ | |
552 | fi | |
553 | ||
554 | # Update the hash stored above. Do this after each release and | |
555 | # for any corrections to old entries. | |
556 | update-NEWS-hash: NEWS | |
557 | perl -pi -e 's/^(old_NEWS_hash[ \t]+:?=[ \t]+).*/$${1}'"$(NEWS_hash)/" \ | |
558 | $(srcdir)/cfg.mk | |
559 | ||
560 | # Ensure that we use only the standard $(VAR) notation, | |
561 | # not @...@ in Makefile.am, now that we can rely on automake | |
562 | # to emit a definition for each substituted variable. | |
563 | # We use perl rather than "grep -nE ..." to exempt a single | |
564 | # use of an @...@-delimited variable name in src/Makefile.am. | |
565 | sc_makefile_check: | |
566 | @perl -ne '/\@[A-Z_0-9]+\@/ && !/^cu_install_program =/' \ | |
567 | -e 'and (print "$$ARGV:$$.: $$_"), $$m=1; END {exit !$$m}' \ | |
568 | $$($(VC_LIST_EXCEPT) | grep -E '(^|/)Makefile\.am$$') \ | |
569 | && { echo '$(ME): use $$(...), not @...@' 1>&2; exit 1; } || : | |
570 | ||
571 | news-date-check: NEWS | |
572 | today=`date +%Y-%m-%d`; \ | |
573 | if head $(srcdir)/NEWS | grep '^\*.* $(VERSION_REGEXP) ('$$today')' \ | |
574 | >/dev/null; then \ | |
575 | :; \ | |
576 | else \ | |
577 | echo "version or today's date is not in NEWS" 1>&2; \ | |
578 | exit 1; \ | |
579 | fi | |
580 | ||
581 | sc_makefile_TAB_only_indentation: | |
582 | @grep -nE '^ [ ]{8}' \ | |
583 | $$($(VC_LIST_EXCEPT) | grep -E 'akefile|\.mk$$') \ | |
584 | && { echo '$(ME): found TAB-8-space indentation' 1>&2; \ | |
585 | exit 1; } || : | |
586 | ||
587 | sc_m4_quote_check: | |
588 | @grep -nE '(AC_DEFINE(_UNQUOTED)?|AC_DEFUN)\([^[]' \ | |
589 | $$($(VC_LIST_EXCEPT) | grep -E '(^configure\.ac|\.m4)$$') \ | |
590 | && { echo '$(ME): quote the first arg to AC_DEF*' 1>&2; \ | |
591 | exit 1; } || : | |
592 | ||
593 | fix_po_file_diag = \ | |
594 | 'you have changed the set of files with translatable diagnostics;\n\ | |
595 | apply the above patch\n' | |
596 | ||
597 | # Verify that all source files using _() are listed in po/POTFILES.in. | |
598 | po_file = po/POTFILES.in | |
599 | sc_po_check: | |
600 | @if test -f $(po_file); then \ | |
601 | grep -E -v '^(#|$$)' $(po_file) \ | |
602 | | grep -v '^src/false\.c$$' | sort > $@-1; \ | |
603 | files=; \ | |
604 | for file in $$($(VC_LIST_EXCEPT)) lib/*.[ch]; do \ | |
605 | test -r $$file || continue; \ | |
606 | case $$file in \ | |
607 | *.m4|*.mk) continue ;; \ | |
608 | *.?|*.??) ;; \ | |
609 | *) continue;; \ | |
610 | esac; \ | |
611 | case $$file in \ | |
612 | *.[ch]) \ | |
613 | base=`expr " $$file" : ' \(.*\)\..'`; \ | |
614 | { test -f $$base.l || test -f $$base.y; } && continue;; \ | |
615 | esac; \ | |
616 | files="$$files $$file"; \ | |
617 | done; \ | |
618 | grep -E -l '\b(N?_|gettext *)\([^)"]*("|$$)' $$files \ | |
619 | | sort -u > $@-2; \ | |
620 | diff -u -L $(po_file) -L $(po_file) $@-1 $@-2 \ | |
621 | || { printf '$(ME): '$(fix_po_file_diag) 1>&2; exit 1; }; \ | |
622 | rm -f $@-1 $@-2; \ | |
623 | fi | |
624 | ||
625 | # Sometimes it is useful to change the PATH environment variable | |
626 | # in Makefiles. When doing so, it's better not to use the Unix-centric | |
627 | # path separator of `:', but rather the automake-provided `$(PATH_SEPARATOR)'. | |
628 | msg = '$(ME): Do not use `:'\'' above; use $$(PATH_SEPARATOR) instead' | |
629 | sc_makefile_path_separator_check: | |
630 | @grep -nE 'PATH[=].*:' \ | |
631 | $$($(VC_LIST_EXCEPT) | grep -E 'akefile|\.mk$$') \ | |
632 | && { echo $(msg) 1>&2; exit 1; } || : | |
633 | ||
634 | # Check that `make alpha' will not fail at the end of the process. | |
635 | writable-files: | |
636 | if test -d $(release_archive_dir); then :; else \ | |
637 | for file in $(distdir).tar.gz \ | |
638 | $(release_archive_dir)/$(distdir).tar.gz; do \ | |
639 | test -e $$file || continue; \ | |
640 | test -w $$file \ | |
641 | || { echo ERROR: $$file is not writable; fail=1; }; \ | |
642 | done; \ | |
643 | test "$$fail" && exit 1 || : ; \ | |
644 | fi | |
645 | ||
646 | v_etc_file = lib/version-etc.c | |
647 | sample-test = tests/sample-test | |
648 | texi = doc/$(PACKAGE).texi | |
649 | # Make sure that the copyright date in $(v_etc_file) is up to date. | |
650 | # Do the same for the $(sample-test) and the main doc/.texi file. | |
651 | sc_copyright_check: | |
652 | @if test -f $(v_etc_file); then \ | |
653 | grep 'enum { COPYRIGHT_YEAR = '$$(date +%Y)' };' $(v_etc_file) \ | |
654 | >/dev/null \ | |
655 | || { echo 'out of date copyright in $(v_etc_file); update it' 1>&2; \ | |
656 | exit 1; }; \ | |
657 | fi | |
658 | @if test -f $(sample-test); then \ | |
659 | grep '# Copyright (C) '$$(date +%Y)' Free' $(sample-test) \ | |
660 | >/dev/null \ | |
661 | || { echo 'out of date copyright in $(sample-test); update it' 1>&2; \ | |
662 | exit 1; }; \ | |
663 | fi | |
664 | @if test -f $(texi); then \ | |
665 | grep 'Copyright @copyright{} .*'$$(date +%Y)' Free' $(texi) \ | |
666 | >/dev/null \ | |
667 | || { echo 'out of date copyright in $(texi); update it' 1>&2; \ | |
668 | exit 1; }; \ | |
669 | fi | |
670 | ||
671 | vc-diff-check: | |
672 | (unset CDPATH; cd $(srcdir) && $(VC) diff) > vc-diffs || : | |
673 | if test -s vc-diffs; then \ | |
674 | cat vc-diffs; \ | |
675 | echo "Some files are locally modified:" 1>&2; \ | |
676 | exit 1; \ | |
677 | else \ | |
678 | rm vc-diffs; \ | |
679 | fi | |
680 | ||
681 | # Use this to make sure we don't run these programs when building | |
682 | # from a virgin tgz file, below. | |
683 | null_AM_MAKEFLAGS = \ | |
684 | ACLOCAL=false \ | |
685 | AUTOCONF=false \ | |
686 | AUTOMAKE=false \ | |
687 | AUTOHEADER=false \ | |
688 | MAKEINFO=false | |
689 | ||
690 | built_programs = $$(cd src && MAKEFLAGS= $(MAKE) -s built_programs.list) | |
691 | ||
692 | rel-files = $(DIST_ARCHIVES) | |
693 | ||
694 | gnulib_dir ?= $(srcdir)/gnulib | |
695 | gnulib-version = $$(cd $(gnulib_dir) && git describe) | |
696 | bootstrap-tools ?= autoconf,automake,gnulib | |
697 | ||
698 | announcement: NEWS ChangeLog $(rel-files) | |
699 | @$(build_aux)/announce-gen \ | |
700 | --release-type=$(RELEASE_TYPE) \ | |
701 | --package=$(PACKAGE) \ | |
702 | --prev=$(PREV_VERSION) \ | |
703 | --curr=$(VERSION) \ | |
704 | --gpg-key-id=$(gpg_key_ID) \ | |
705 | --news=NEWS \ | |
706 | --bootstrap-tools=$(bootstrap-tools) \ | |
707 | --gnulib-version=$(gnulib-version) \ | |
708 | --no-print-checksums \ | |
709 | $(addprefix --url-dir=, $(url_dir_list)) | |
710 | ||
711 | ## ---------------- ## | |
712 | ## Updating files. ## | |
713 | ## ---------------- ## | |
714 | ||
715 | ftp-gnu = ftp://ftp.gnu.org/gnu | |
716 | www-gnu = http://www.gnu.org | |
717 | ||
718 | emit_upload_commands: | |
719 | @echo ===================================== | |
720 | @echo ===================================== | |
721 | @echo "$(build_aux)/gnupload $(GNUPLOADFLAGS) \\" | |
722 | @echo " --to $(gnu_rel_host):$(PACKAGE) \\" | |
723 | @echo " $(rel-files)" | |
724 | @echo '# send the /tmp/announcement e-mail' | |
725 | @echo ===================================== | |
726 | @echo ===================================== | |
727 | ||
728 | noteworthy = * Noteworthy changes in release ?.? (????-??-??) [?] | |
729 | define emit-commit-log | |
730 | printf '%s\n' 'post-release administrivia' '' \ | |
731 | '* NEWS: Add header line for next release.' \ | |
732 | '* .prev-version: Record previous version.' \ | |
733 | '* cfg.mk (old_NEWS_hash): Auto-update.' | |
734 | endef | |
735 | ||
736 | .PHONY: no-submodule-changes | |
737 | no-submodule-changes: | |
738 | if test -d $(srcdir)/.git; then \ | |
739 | diff=$$(cd $(srcdir) && git submodule -q foreach \ | |
740 | git diff-index --name-only HEAD) \ | |
741 | || exit 1; \ | |
742 | case $$diff in '') ;; \ | |
743 | *) echo '$(ME): submodule files are locally modified:'; \ | |
744 | echo "$$diff"; exit 1;; esac; \ | |
745 | else \ | |
746 | : ; \ | |
747 | fi | |
748 | ||
749 | .PHONY: alpha beta stable | |
750 | ALL_RECURSIVE_TARGETS += alpha beta stable | |
751 | alpha beta stable: $(local-check) writable-files no-submodule-changes | |
752 | test $@ = stable \ | |
753 | && { echo $(VERSION) | grep -E '^[0-9]+(\.[0-9]+)+$$' \ | |
754 | || { echo "invalid version string: $(VERSION)" 1>&2; exit 1;};}\ | |
755 | || : | |
756 | $(MAKE) vc-diff-check | |
757 | $(MAKE) news-date-check | |
758 | $(MAKE) distcheck | |
759 | $(MAKE) dist XZ_OPT=-9ev | |
760 | $(MAKE) -s announcement RELEASE_TYPE=$@ > /tmp/announce-$(my_distdir) | |
761 | if test -d $(release_archive_dir); then \ | |
762 | ln $(rel-files) $(release_archive_dir); \ | |
763 | chmod a-w $(rel-files); \ | |
764 | fi | |
765 | $(MAKE) -s emit_upload_commands RELEASE_TYPE=$@ | |
766 | echo $(VERSION) > $(prev_version_file) | |
767 | $(MAKE) update-NEWS-hash | |
768 | perl -pi -e '$$. == 3 and print "$(noteworthy)\n\n\n"' NEWS | |
769 | $(emit-commit-log) > .ci-msg | |
770 | $(VC) commit -F .ci-msg -a | |
771 | ||
772 | .PHONY: web-manual | |
773 | web-manual: | |
774 | @test -z "$(manual_title)" \ | |
775 | && { echo define manual_title in cfg.mk 1>&2; exit 1; } || : | |
776 | @cd '$(srcdir)/doc'; \ | |
777 | $(SHELL) ../build-aux/gendocs.sh -o '$(abs_builddir)/doc/manual' \ | |
778 | --email $(PACKAGE_BUGREPORT) $(PACKAGE) \ | |
779 | "$(PACKAGE_NAME) - $(manual_title)" | |
780 | @echo " *** Upload the doc/manual directory to web-cvs." | |
781 | ||
782 | # Code Coverage | |
783 | ||
784 | init-coverage: | |
785 | $(MAKE) $(AM_MAKEFLAGS) clean | |
786 | lcov --directory . --zerocounters | |
787 | ||
788 | COVERAGE_CCOPTS ?= "-g --coverage" | |
789 | COVERAGE_OUT ?= doc/coverage | |
790 | ||
791 | build-coverage: | |
792 | $(MAKE) $(AM_MAKEFLAGS) CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS) | |
793 | $(MAKE) $(AM_MAKEFLAGS) CFLAGS=$(COVERAGE_CCOPTS) CXXFLAGS=$(COVERAGE_CCOPTS) check | |
794 | mkdir -p $(COVERAGE_OUT) | |
795 | lcov --directory . --output-file $(COVERAGE_OUT)/$(PACKAGE).info \ | |
796 | --capture | |
797 | ||
798 | gen-coverage: | |
799 | genhtml --output-directory $(COVERAGE_OUT) \ | |
800 | $(COVERAGE_OUT)/$(PACKAGE).info \ | |
801 | --highlight --frames --legend \ | |
802 | --title "$(PACKAGE_NAME)" | |
803 | ||
804 | coverage: init-coverage build-coverage gen-coverage | |
805 | ||
806 | # Update gettext files. | |
807 | PACKAGE ?= $(shell basename $(PWD)) | |
808 | PO_DOMAIN ?= $(PACKAGE) | |
809 | POURL = http://translationproject.org/latest/$(PO_DOMAIN)/ | |
810 | PODIR ?= po | |
811 | refresh-po: | |
812 | rm -f $(PODIR)/*.po && \ | |
813 | echo "$(ME): getting translations into po (please ignore the robots.txt ERROR 404)..." && \ | |
814 | wget --no-verbose --directory-prefix $(PODIR) --no-directories --recursive --level 1 --accept .po --accept .po.1 $(POURL) && \ | |
815 | echo 'en@boldquot' > $(PODIR)/LINGUAS && \ | |
816 | echo 'en@quot' >> $(PODIR)/LINGUAS && \ | |
817 | ls $(PODIR)/*.po | sed 's/\.po//' | sed 's,$(PODIR)/,,' | sort >> $(PODIR)/LINGUAS | |
818 | ||
819 | INDENT_SOURCES ?= $(C_SOURCES) | |
820 | .PHONY: indent | |
821 | indent: | |
822 | indent $(INDENT_SOURCES) | |
823 | ||
824 | # If you want to set UPDATE_COPYRIGHT_* environment variables, | |
825 | # put the assignments in this variable. | |
826 | update-copyright-env ?= | |
827 | ||
828 | # Run this rule once per year (usually early in January) | |
829 | # to update all FSF copyright year lists in your project. | |
830 | # If you have an additional project-specific rule, | |
831 | # add it in cfg.mk along with a line 'update-copyright: prereq'. | |
832 | # By default, exclude all variants of COPYING; you can also | |
833 | # add exemptions (such as ChangeLog..* for rotated change logs) | |
834 | # in the file .x-update-copyright. | |
835 | .PHONY: update-copyright | |
836 | update-copyright: | |
837 | grep -l -w Copyright \ | |
838 | $$(export VC_LIST_EXCEPT_DEFAULT=COPYING && $(VC_LIST_EXCEPT)) \ | |
839 | | $(update-copyright-env) xargs $(build_aux)/$@ |