doc: mention fix for bug#64123
[coreutils.git] / cfg.mk
blob92f119ee2fb99f2419aca55a953fd52f8d7e1210
1 # Customize maint.mk -*- makefile -*-
2 # Copyright (C) 2003-2023 Free Software Foundation, Inc.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17 # Used in maint.mk's web-manual rule
18 manual_title = Core GNU utilities
20 # Use the direct link. This is guaranteed to work immediately, while
21 # it can take a while for the faster mirror links to become usable.
22 url_dir_list = https://ftp.gnu.org/gnu/$(PACKAGE)
24 # Exclude bundled external projects from syntax checks
25 VC_LIST_ALWAYS_EXCLUDE_REGEX = src/blake2/.*$$
27 # Tests not to run as part of "make distcheck".
28 local-checks-to-skip = \
29 sc_proper_name_utf8_requires_ICONV \
30 sc_indent
32 # Tools used to bootstrap this package, used for "announcement".
33 bootstrap-tools = autoconf,automake,gnulib,bison
35 # Now that we have better tests, make this the default.
36 export VERBOSE = yes
38 # Comparing tarball sizes compressed using different xz presets, we see that
39 # an -8e-compressed tarball is only 9KiB larger than the -9e-compressed one.
40 # Using -8e is preferred, since that lets the decompression process use half
41 # the memory (32MiB rather than 64MiB).
42 # $ for i in {7,8,9}{e,}; do \
43 # (n=$(xz -$i < coreutils-8.15*.tar|wc -c);echo $n $i) & done |sort -nr
44 # 5129388 7
45 # 5036524 7e
46 # 5017476 8
47 # 5010604 9
48 # 4923016 8e
49 # 4914152 9e
50 export XZ_OPT = -8e
52 old_NEWS_hash = ac6cb1c35890b53e56acbfbb078fcd53
54 # Add an exemption for sc_makefile_at_at_check.
55 _makefile_at_at_check_exceptions = ' && !/^cu_install_prog/ && !/dynamic-dep/'
57 # Our help-version script is in a slightly different location.
58 _hv_file ?= $(srcdir)/tests/misc/help-version
60 # Ensure that the list of O_ symbols used to compute O_FULLBLOCK is complete.
61 dd = $(srcdir)/src/dd.c
62 sc_dd_O_FLAGS:
63 @rm -f $@.1 $@.2
64 @{ echo O_FULLBLOCK; echo O_NOCACHE; \
65 perl -nle '/^ +\| (O_\w*)$$/ and print $$1' $(dd); } | sort > $@.1
66 @{ echo O_NOFOLLOW; perl -nle '/{"[a-z]+",\s*(O_\w+)},/ and print $$1' \
67 $(dd); } | sort > $@.2
68 @diff -u $@.1 $@.2; diff=$$?; \
69 rm -f $@.1 $@.2; \
70 test "$$diff" = 0 \
71 || { echo '$(ME): $(dd) has inconsistent O_ flag lists'>&2; \
72 exit 1; }
74 # Ensure that dd's definition of LONGEST_SYMBOL stays in sync
75 # with the strings from the two affected variables.
76 dd_c = $(srcdir)/src/dd.c
77 sc_dd_max_sym_length:
78 ifneq ($(wildcard $(dd_c)),)
79 @len=$$( (sed -n '/conversions\[] =$$/,/^};/p' $(dd_c);\
80 sed -n '/flags\[] =$$/,/^};/p' $(dd_c) ) \
81 |sed -n '/"/s/^[^"]*"\([^"]*\)".*/\1/p'| wc -L);\
82 max=$$(sed -n '/^#define LONGEST_SYMBOL /s///p' $(dd_c) \
83 |tr -d '"' | wc -L); \
84 if test "$$len" = "$$max"; then :; else \
85 echo 'dd.c: LONGEST_SYMBOL is not longest' 1>&2; \
86 exit 1; \
88 endif
90 # Many m4 macros names once began with 'jm_'.
91 # On 2004-04-13, they were all changed to start with gl_ instead.
92 # Make sure that none are inadvertently reintroduced.
93 sc_prohibit_jm_in_m4:
94 @grep -nE 'jm_[A-Z]' \
95 $$($(VC_LIST) m4 |grep '\.m4$$'; echo /dev/null) && \
96 { echo '$(ME): do not use jm_ in m4 macro names' \
97 1>&2; exit 1; } || :
99 # Ensure that each root-requiring test is run via the "check-root" rule.
100 sc_root_tests:
101 @t1=sc-root.expected; t2=sc-root.actual; \
102 grep -nl '^ *require_root_$$' `$(VC_LIST) tests` | \
103 sed 's|.*/tests/|tests/|' | sort > $$t1; \
104 for t in $(all_root_tests); do echo $$t; done | sort > $$t2; \
105 st=0; diff -u $$t1 $$t2 || st=1; \
106 rm -f $$t1 $$t2; \
107 exit $$st
109 # Ensure that all version-controlled test cases are listed in $(all_tests).
110 sc_tests_list_consistency:
111 @bs="\\"; \
112 test_extensions_rx=`echo $(TEST_EXTENSIONS) \
113 | sed -e "s/ /|/g" -e "s/$$bs./$$bs$$bs./g"`; \
115 for t in $(all_tests); do echo $$t; done; \
116 cd $(top_srcdir); \
117 $(SHELL) build-aux/vc-list-files tests \
118 | grep -Ev '^tests/(factor/(run|create-test)|init)\.sh$$' \
119 | grep -E "$$test_extensions_rx\$$"; \
120 } | sort | uniq -u | grep . && exit 1; :
122 # Ensure that all version-controlled test scripts are executable.
123 sc_tests_executable:
124 @set -o noglob 2>/dev/null || set -f; \
125 cd $(srcdir); \
126 find_ext="-name '' "`printf -- "-o -name *%s " $(TEST_EXTENSIONS)`;\
127 find $(srcdir)/tests/ \( $$find_ext \) \! -perm -u+x -print \
128 | { sed "s|^$(srcdir)/||"; git ls-files $(srcdir)/tests/; } \
129 | sort | uniq -d \
130 | sed -e "s/^/$(ME): Please make test executable: /" | grep . \
131 && exit 1; :
133 # Ensure all gnulib patches apply cleanly
134 sc_ensure_gl_diffs_apply_cleanly:
135 @find $(srcdir)/gl/ -name '*.diff' | while read p; do \
136 patch --fuzz=0 -f -s -d $(srcdir)/gnulib/ -p1 --dry-run < "$$p" >&2 \
137 || { echo "$$p" >&2; echo 'To refresh all gl patches run:' \
138 'make refresh-gnulib-patches' >&2; exit 1; } \
139 done
141 # Avoid :>file which doesn't propagate errors
142 sc_prohibit_colon_redirection:
143 @cd $(srcdir)/tests && GIT_PAGER= git grep -En ': *>.*\|\|' \
144 && { echo '$(ME): '"The leading colon in :> will hide errors" >&2; \
145 exit 1; } \
146 || :
148 # Ensure emit_mandatory_arg_note() is called if required
149 sc_ensure_emit_mandatory_arg_note:
150 @cd $(srcdir)/src && GIT_PAGER= git \
151 grep -l -- '^ *-[^-].*--.*[^[]=' *.c \
152 | xargs grep -L emit_mandatory_arg_note | grep . \
153 && { echo '$(ME): '"emit_mandatory_arg_note() missing" 1>&2; \
154 exit 1; } || :
156 # Create a list of regular expressions matching the names
157 # of files included from system.h. Exclude a couple.
158 .re-list:
159 @sed -n '/^# *include /s///p' $(srcdir)/src/system.h \
160 | grep -Ev 'sys/(param|file)\.h' \
161 | sed 's/ .*//;;s/^["<]/^# *include [<"]/;s/\.h[">]$$/\\.h[">]/' \
162 > $@-t
163 @mv $@-t $@
165 define gl_trap_
166 Exit () { set +e; (exit $$1); exit $$1; }; \
167 for sig in 1 2 3 13 15; do \
168 eval "trap 'Exit $$(expr $$sig + 128)' $$sig"; \
169 done
170 endef
172 # Files in src/ should not include directly any of
173 # the headers already included via system.h.
174 sc_system_h_headers: .re-list
175 @if test -f $(srcdir)/src/system.h; then \
176 trap 'rc=$$?; rm -f .re-list; exit $$rc' 0; \
177 $(gl_trap_); \
178 grep -nE -f .re-list \
179 $$($(VC_LIST_EXCEPT) | grep -E '^($(srcdir)/)?src/') \
180 && { echo '$(ME): the above are already included via system.h'\
181 1>&2; exit 1; } || :; \
184 # Files in src/ should not use '%s' notation in format strings,
185 # i.e., single quotes around %s (or similar) should be avoided.
186 sc_prohibit_quotes_notation:
187 @cd $(srcdir)/src && GIT_PAGER= git grep -n "\".*[\`']%s'.*\"" *.c \
188 && { echo '$(ME): '"Use quote() to avoid quoted '%s' notation" 1>&2; \
189 exit 1; } \
190 || :
192 error_fns = (error|die|diagnose)
194 # Files in src/ should quote all strings in error() output, so that
195 # unexpected input chars like \r etc. don't corrupt the error.
196 # In edge cases this can be avoided by putting the format string
197 # on a separate line to the arguments, or the arguments in parenthesis.
198 sc_error_quotes:
199 @cd $(srcdir)/src \
200 && GIT_PAGER= git grep -E -n '$(error_fns) *\(.*%s.*, [^(]*\);$$' \
201 *.c | grep -v ', q' \
202 && { echo '$(ME): '"Use quote() for error string arguments" 1>&2; \
203 exit 1; } \
204 || :
206 # Files in src/ should quote all file names in error() output
207 # using quotef(), to provide quoting only when necessary,
208 # but also provide better support for copy and paste when used.
209 sc_error_shell_quotes:
210 @cd $(srcdir)/src && \
211 { GIT_PAGER= git grep -E \
212 '$(error_fns) \(.*%s[:"], .*(name|file)[^"]*\);$$' *.c; \
213 GIT_PAGER= git grep -E \
214 ' quote[ _].*file' *.c; } \
215 | grep -Ev '(quotef|q[^ ]*name)' \
216 && { echo '$(ME): '"Use quotef() for colon delimited names" 1>&2; \
217 exit 1; } \
218 || :
220 # Files in src/ should quote all file names in error() output
221 # using quoteaf() when the name is separated with spaces,
222 # to distinguish the file name at issue and
223 # to provide better support for copy and paste.
224 sc_error_shell_always_quotes:
225 @cd $(srcdir)/src && GIT_PAGER= git grep -E \
226 '$(error_fns) \(.*[^:] %s[ "].*, .*(name|file)[^"]*\);$$' \
227 *.c | grep -Ev '(quoteaf|q[^ ]*name)' \
228 && { echo '$(ME): '"Use quoteaf() for space delimited names" 1>&2; \
229 exit 1; } \
230 || :
231 @cd $(srcdir)/src && GIT_PAGER= git grep -E -A1 \
232 '$(error_fns) \([^%]*[^:] %s[ "]' *.c | grep 'quotef' \
233 && { echo '$(ME): '"Use quoteaf() for space delimited names" 1>&2; \
234 exit 1; } \
235 || :
237 # Usage of error() with an exit constant, should instead use die(),
238 # as that avoids warnings and may generate better code, due to being apparent
239 # to the compiler that it doesn't return.
240 sc_die_EXIT_FAILURE:
241 @cd $(srcdir)/src && GIT_PAGER= git grep -E \
242 'error \([^?]*EXIT_' \
243 && { echo '$(ME): '"Use die() instead of error" 1>&2; \
244 exit 1; } \
245 || :
247 # Avoid unstyled quoting to internal slots and thus destined for diagnostics
248 # as that can leak unescaped control characters to the output, when using
249 # the default "literal" quoting style.
250 # Instead use quotef(), or quoteaf() or in edge cases quotearg_n_style_colon().
251 # A more general PCRE would be @prohibit='quotearg_.*(?!(style|buffer))'
252 sc_prohibit-quotearg:
253 @prohibit='quotearg(_n)?(|_colon|_char|_mem) ' \
254 in_vc_files='\.c$$' \
255 halt='Unstyled diagnostic quoting detected' \
256 $(_sc_search_regexp)
258 sc_prohibit-skip:
259 @prohibit='\|\| skip ' \
260 halt='Use skip_ not skip' \
261 $(_sc_search_regexp)
263 sc_sun_os_names:
264 @grep -nEi \
265 'solaris[^[:alnum:]]*2\.(7|8|9|[1-9][0-9])|sunos[^[:alnum:]][6-9]' \
266 $$($(VC_LIST_EXCEPT)) && \
267 { echo '$(ME): found misuse of Sun OS version numbers' 1>&2; \
268 exit 1; } || :
270 # Ensure that the list of programs and author names is accurate.
271 # We need a UTF8 locale. If a lack of locale support or a missing
272 # translation inhibits printing of UTF-8 names, just skip this test.
273 au_dotdot = authors-dotdot
274 au_actual = authors-actual
275 sc_check-AUTHORS: $(all_programs)
276 @locale=en_US.UTF-8; \
277 LC_ALL=$$locale ./src/factor --version \
278 | grep ' Torbjorn ' > /dev/null \
279 && { echo "$@: skipping this check"; exit 0; }; \
280 rm -f $(au_actual) $(au_dotdot); \
281 for i in `ls $(all_programs) \
282 | sed -e 's,^src/,,' -e 's,$(EXEEXT)$$,,' \
283 | sed /libstdbuf/d \
284 | $(ASSORT) -u`; do \
285 test "$$i" = '[' && continue; \
286 exe=$$i; \
287 if test "$$i" = install; then \
288 exe=ginstall; \
289 elif test "$$i" = test; then \
290 exe='['; \
291 fi; \
292 LC_ALL=$$locale ./src/$$exe --version \
293 | perl -0 -p -e 's/,\n/, /gm' \
294 | sed -n -e '/Written by /{ s//'"$$i"': /;' \
295 -e 's/,* and /, /; s/\.$$//; p; }'; \
296 done > $(au_actual) && \
297 sed -n '/^[^ ][^ ]*:/p' $(srcdir)/AUTHORS > $(au_dotdot) \
298 && diff $(au_actual) $(au_dotdot) \
299 && rm -f $(au_actual) $(au_dotdot)
301 # Each program with a non-ASCII author name must link with LIBICONV.
302 sc_check-I18N-AUTHORS:
303 @cd $(srcdir)/src && \
304 for i in $$(git grep -l -w proper_name_utf8 *.c|sed 's/\.c//'); do \
305 grep -E "^src_$${i}_LDADD"' .?= .*\$$\(LIBICONV\)' local.mk \
306 > /dev/null \
307 || { echo "$(ME): link rules for $$i do not include" \
308 '$$(LIBICONV)' 1>&2; exit 1; }; \
309 done
311 # Disallow the C99 printf size specifiers %z and %j as they're not portable.
312 # The gnulib printf replacement does support them, however the printf
313 # replacement is not currently explicitly depended on by the gnulib error()
314 # module for example. Also we use fprintf() in a few places to output simple
315 # formats but don't use the gnulib module as it is seen as overkill at present.
316 # We'd have to adjust the above gnulib items before disabling this.
317 sc_prohibit-c99-printf-format:
318 @cd $(srcdir)/src && GIT_PAGER= git grep -n '%[0*]*[jz][udx]' *.c \
319 && { echo '$(ME): Use PRI*MAX instead of %j or %z' 1>&2; exit 1; } \
320 || :
322 # Ensure the alternative __attribute (keyword) form isn't used as
323 # that form is not elided where required. Also ensure that we don't
324 # directly use attributes already defined by gnulib.
325 # TODO: move the check for _GL... attributes to gnulib.
326 sc_prohibit-gl-attributes:
327 @prohibit='__attribute |__(unused|pure|const)__' \
328 in_vc_files='\.[ch]$$' \
329 halt='Use _GL... attribute macros' \
330 $(_sc_search_regexp)
332 # Prefer the const declaration form, with const following the type
333 sc_prohibit-const-char:
334 @prohibit='const char \*' \
335 in_vc_files='\.[ch]$$' \
336 halt='Use char const *, not const char *' \
337 $(_sc_search_regexp)
339 # Look for lines longer than 80 characters, except omit:
340 # - urls
341 # - the fdl.texi file copied from gnulib,
342 # - the help2man script copied from upstream,
343 # - tests involving long checksum lines, and
344 # - the 'pr' test cases.
345 FILTER_LONG_LINES = \
346 \|^[^:]*NEWS:.*https\{,1\}://| d; \
347 \|^[^:]*doc/fdl.texi:| d; \
348 \|^[^:]*man/help2man:| d; \
349 \|^[^:]*tests/cksum/sha[0-9]*sum.*\.pl[-:]| d; \
350 \|^[^:]*tests/pr/|{ \|^[^:]*tests/pr/pr-tests:| !d; };
351 sc_long_lines:
352 @wc -L /dev/null >/dev/null 2>/dev/null \
353 || { echo "$@: skipping: wc -L not supported"; exit 0; }; \
354 sed -r 1q /dev/null 2>/dev/null \
355 || { echo "$@: skipping: sed -r not supported"; exit 0; }; \
356 files=$$($(VC_LIST_EXCEPT) | xargs wc -L | sed -rn '/ total$$/d;\
357 s/^ *(8[1-9]|9[0-9]|[0-9]{3,}) //p'); \
358 halt='line(s) with more than 80 characters; reindent'; \
359 for file in $$files; do \
360 expand $$file | grep -nE '^.{80}.' | \
361 sed -e "s|^|$$file:|" -e '$(FILTER_LONG_LINES)'; \
362 done | grep . && { msg="$$halt" $(_sc_say_and_exit) } || :
364 # Option descriptions should not start with a capital letter.
365 # One could grep source directly as follows:
366 # grep -E " {2,6}-.*[^.] [A-Z][a-z]" $$($(VC_LIST_EXCEPT) | grep '\.c$$')
367 # but that would miss descriptions not on the same line as the -option.
368 sc_option_desc_uppercase: $(ALL_MANS)
369 @grep '^\\fB\\-' -A1 man/*.1 | LC_ALL=C grep '\.1.[A-Z][a-z]' \
370 && { echo 1>&2 '$@: found initial capitals in --help'; exit 1; } || :
372 # '--' should not be treated as '–' (U+2013 EN DASH) in long option names.
373 sc_texi_long_option_escaped: doc/coreutils.info
374 @grep ' –[^ ]' '$<' \
375 && { echo 1>&2 '$@: found unquoted --long-option'; exit 1; } || :
377 # Ensure all man/*.[1x] files are present.
378 sc_man_file_correlation: check-x-vs-1 check-programs-vs-x
380 # Ensure that for each .x file in the 'man/' subdirectory, there is a
381 # corresponding .1 file in the definition of $(EXTRA_MANS).
382 # But since that expansion usually lacks programs like arch and hostname,
383 # add them here manually.
384 .PHONY: check-x-vs-1
385 check-x-vs-1:
386 @PATH=./src$(PATH_SEPARATOR)$$PATH; export PATH; \
387 t=$@-t; \
388 (cd $(srcdir)/man && ls -1 *.x) \
389 | sed 's/\.x$$//' | $(ASSORT) > $$t; \
390 (echo $(patsubst man/%,%,$(ALL_MANS)) \
391 | tr -s ' ' '\n' | sed 's/\.1$$//') \
392 | $(ASSORT) -u | diff - $$t || { rm $$t; exit 1; }; \
393 rm $$t
395 # Ensure that non-trivial .x files in the 'man/' subdirectory,
396 # i.e., files exceeding a line count of 20 or a byte count of 1000,
397 # contain a Copyright notice.
398 .PHONY: sc_man_check_x_copyright
399 sc_man_check_x_copyright:
400 @status=0; \
401 cd $(srcdir) && wc -cl man/*.x | head -n-1 \
402 | awk '$$1 >= 20 || $$2 >= 1000 {print $$3}' \
403 | xargs grep -L 'Copyright .* Free Software Foundation' \
404 | grep . \
405 && { echo 1>&2 '$@: exceeding file size/line count limit' \
406 '- please add a copyright note'; status=1; }; \
407 exit $$status
409 # Writing a portable rule to generate a manpage like '[.1' would be
410 # a nightmare, so filter that out.
411 all-progs-but-lbracket = $(filter-out [,$(patsubst src/%,%,$(all_programs)))
413 # Ensure that for each coreutils program there is a corresponding
414 # '.x' file in the 'man/' subdirectory.
415 .PHONY: check-programs-vs-x
416 check-programs-vs-x:
417 @status=0; \
418 for p in dummy $(all-progs-but-lbracket); do \
419 case $$p in *.so) continue;; esac; \
420 test $$p = dummy && continue; \
421 test $$p = ginstall && p=install || : ; \
422 test -f $(srcdir)/man/$$p.x \
423 || { echo missing $$p.x 1>&2; status=1; }; \
424 done; \
425 exit $$status
427 # Ensure we can check out on case insensitive file systems
428 sc_case_insensitive_file_names: src/uniq
429 @git -C $(srcdir) ls-files | sort -f | src/uniq -Di | grep . && \
430 { echo "$(ME): the above file(s) conflict on case insensitive" \
431 " file systems" 1>&2; exit 1; } || :
433 # Ensure that the end of each release's section is marked by two empty lines.
434 sc_NEWS_two_empty_lines:
435 @sed -n 4,/Noteworthy/p $(srcdir)/NEWS \
436 | perl -n0e '/(^|\n)\n\n\* Noteworthy/ or exit 1' \
437 || { echo '$(ME): use two empty lines to separate NEWS sections' \
438 1>&2; exit 1; } || :
440 # With split lines, don't leave an operator at end of line.
441 # Instead, put it on the following line, where it is more apparent.
442 # Don't bother checking for "*" at end of line, since it provokes
443 # far too many false positives, matching constructs like "TYPE *".
444 # Similarly, omit "=" (initializers).
445 binop_re_ ?= [-/+^!<>]|[-/+*^!<>=]=|&&?|\|\|?|<<=?|>>=?
446 sc_prohibit_operator_at_end_of_line:
447 @prohibit='. ($(binop_re_))$$' \
448 in_vc_files='\.[chly]$$' \
449 halt='found operator at end of line' \
450 $(_sc_search_regexp)
452 # Partial substitutes for GNU extensions \< and \> in regexps.
453 begword = (^|[^_[:alnum:]])
454 endword = ($$|[^_[:alnum:]])
456 # Don't use address of "stat" or "lstat" functions
457 sc_prohibit_stat_macro_address:
458 @prohibit='$(begword)l?stat '':|&l?stat$(endword)' \
459 halt='stat() and lstat() may be function-like macros' \
460 $(_sc_search_regexp)
462 # Ensure that date's --help output stays in sync with the info
463 # documentation for GNU strftime. The only exception is %N and %q,
464 # which date accepts but GNU strftime does not.
466 # "info foo" fails with error, but not "info foo >/dev/null".
467 extract_char = sed 's/^[^%][^%]*%\(.\).*/\1/'
468 sc_strftime_check:
469 @if test -f $(srcdir)/src/date.c; then \
470 if info libc date calendar format 2>/dev/null | \
471 grep "^ *['\`]%.'$$" >$@-tmp; then \
472 { echo N; echo q; $(extract_char) $@-tmp; }| sort \
473 >$@-info; \
474 grep '^ %. ' $(srcdir)/src/date.c | sort \
475 | $(extract_char) > $@-src; \
476 diff -u $@-src $@-info || exit 1; \
477 else \
478 echo '$(ME): skipping $@: libc info not installed' 1>&2; \
479 fi; \
480 rm -f $@-info $@-src $@-tmp; \
483 # Indent only with spaces.
484 sc_prohibit_tab_based_indentation:
485 @prohibit='^ * ' \
486 halt='TAB in indentation; use only spaces' \
487 $(_sc_search_regexp)
489 # Enforce lowercase 'e' in "I.e.".
490 sc_prohibit_uppercase_id_est:
491 @prohibit='I\.E\.' \
492 halt='Uppercase "Id Est" abbreviation; use "I.e.," instead' \
493 $(_sc_search_regexp)
495 # Enforce double-space before "I.e." at the beginning of a sentence.
496 sc_ensure_dblspace_after_dot_before_id_est:
497 @prohibit='\. I\.e\.' \
498 halt='Single space after dot before "i.e."; use ". i.e." instead' \
499 $(_sc_search_regexp)
501 # Enforce comma after "i.e." (at least before a blank or at EOL).
502 sc_ensure_comma_after_id_est:
503 @prohibit='[Ii]\.e\.( |$$)' \
504 halt='Missing comma after "i.e."; use "i.e.," instead' \
505 $(_sc_search_regexp)
507 # The SEE ALSO section of a man page should not be terminated with
508 # a period. Check the first line after each "SEE ALSO" line in man/*.x:
509 sc_prohibit_man_see_also_period:
510 @grep -nB1 '\.$$' $$($(VC_LIST_EXCEPT) | grep 'man/.*\.x$$') \
511 | grep -A1 -e '-\[SEE ALSO]' | grep '\.$$' && \
512 { echo '$(ME): do not end "SEE ALSO" section with a period' \
513 1>&2; exit 1; } || :
515 # Don't use "indent-tabs-mode: nil" anymore. No longer needed.
516 sc_prohibit_emacs__indent_tabs_mode__setting:
517 @prohibit='^( *[*#] *)?indent-tabs-mode:' \
518 halt='use of emacs indent-tabs-mode: setting' \
519 $(_sc_search_regexp)
521 # Ensure that tests don't include a redundant fail=0.
522 sc_prohibit_fail_0:
523 @prohibit='$(begword)fail=0$(endword)' \
524 halt='fail=0 initialization' \
525 $(_sc_search_regexp)
527 # Ensure that tests don't use `cmd ... && fail=1` as that hides crashes.
528 # The "exclude" expression allows common idioms like `test ... && fail=1`
529 # and the 2>... portion allows commands that redirect stderr and so probably
530 # independently check its contents and thus detect any crash messages.
531 sc_prohibit_and_fail_1:
532 @prohibit='&& fail=1' \
533 exclude='(returns_|stat|kill|test |EGREP|grep|compare|2> *[^/])' \
534 halt='&& fail=1 detected. Please use: returns_ 1 ... || fail=1' \
535 in_vc_files='^tests/' \
536 $(_sc_search_regexp)
538 # Ensure that tests don't use `cmd ... || fail` as that's a noop.
539 sc_prohibit_or_fail:
540 @prohibit='\|\| fail$$' \
541 exclude=':#' \
542 halt='|| fail detected. Please use: || fail=1' \
543 in_vc_files='^tests/' \
544 $(_sc_search_regexp)
546 # Ensure that env vars are not passed through returns_ as
547 # that was seen to fail on FreeBSD /bin/sh at least
548 sc_prohibit_env_returns:
549 @prohibit='=[^ ]* returns_ ' \
550 exclude='_ returns_ ' \
551 halt='Passing env vars to returns_ is non portable' \
552 in_vc_files='^tests/' \
553 $(_sc_search_regexp)
555 # The mode part of a setfacl -m option argument must be three bytes long.
556 # I.e., an argument of user:bin:rw or user:bin:r will make Solaris 10's
557 # setfacl reject it with: "Unrecognized character found in mode field".
558 # Use hyphens to give it a length of 3: "...:rw-" or "...:r--".
559 sc_prohibit_short_facl_mode_spec:
560 @prohibit='$(begword)setfacl .*-m.*:.*:[rwx-]{1,2} ' \
561 halt='setfacl mode string length < 3; extend with hyphen(s)' \
562 $(_sc_search_regexp)
564 # Ensure that "stdio--.h" is used where appropriate.
565 sc_require_stdio_safer:
566 @if $(VC_LIST_EXCEPT) | grep -l '\.[ch]$$' > /dev/null; then \
567 files=$$(grep -l '$(begword)freopen \?(' $$($(VC_LIST_EXCEPT) \
568 | grep '\.[ch]$$')); \
569 test -n "$$files" && grep -LE 'include "stdio--.h"' $$files \
570 | grep . && \
571 { echo '$(ME): the above files should use "stdio--.h"' \
572 1>&2; exit 1; } || :; \
573 else :; \
576 sc_prohibit_perl_hash_quotes:
577 @prohibit="\{'[A-Z_]+' *[=}]" \
578 halt="in Perl code, write \$$hash{KEY}, not \$$hash{'K''EY'}" \
579 $(_sc_search_regexp)
581 # Prefer xnanosleep over other less-precise sleep methods
582 sc_prohibit_sleep:
583 @prohibit='$(begword)(nano|u)?sleep \(' \
584 halt='prefer xnanosleep over other sleep interfaces' \
585 $(_sc_search_regexp)
587 # Use print_ver_ (from init.cfg), not open-coded $VERBOSE check.
588 sc_prohibit_verbose_version:
589 @prohibit='test "\$$VERBOSE" = yes && .* --version' \
590 halt='use the print_ver_ function instead...' \
591 $(_sc_search_regexp)
593 # Enforce print_ver_ tracking of dependencies
594 # Each coreutils specific program a test requires
595 # should be tagged by calling through env(1).
596 sc_env_test_dependencies:
597 @cd $(top_srcdir) && GIT_PAGER= git grep -E \
598 "env ($$(build-aux/gen-lists-of-programs.sh --list-progs | \
599 grep -vF '[' |paste -d'|' -s))" tests | \
600 sed "s/\([^:]\):.*env \([^)' ]*\).*/\1 \2/" | uniq | \
601 while read test prog; do \
602 printf '%s' $$test | grep '\.pl$$' >/dev/null && continue; \
603 grep "print_ver_.* $$prog" $$test >/dev/null \
604 || echo $$test should call: print_ver_ $$prog; \
605 done | grep . && exit 1 || :
607 # Use framework_failure_, not the old name without the trailing underscore.
608 sc_prohibit_framework_failure:
609 @prohibit='$(begword)framework_''failure$(endword)' \
610 halt='use framework_failure_ instead' \
611 $(_sc_search_regexp)
613 # Prohibit the use of `...` in tests/. Use $(...) instead.
614 sc_prohibit_test_backticks:
615 @prohibit='`' in_vc_files='^tests/' \
616 halt='use $$(...), not `...` in tests/' \
617 $(_sc_search_regexp)
619 # Ensure that compare is used to check empty files
620 # so that the unexpected contents are displayed
621 sc_prohibit_test_empty:
622 @prohibit='test -s.*&&' in_vc_files='^tests/' \
623 halt='use `compare /dev/null ...`, not `test -s ...` in tests/' \
624 $(_sc_search_regexp)
626 # Programs like sort, ls, expr use PROG_FAILURE in place of EXIT_FAILURE.
627 # Others, use the EXIT_CANCELED, EXIT_ENOENT, etc. macros defined in system.h.
628 # In those programs, ensure that EXIT_FAILURE is not used by mistake.
629 sc_some_programs_must_avoid_exit_failure:
630 @cd $(srcdir) \
631 && grep -nw EXIT_FAILURE \
632 $$(git grep -El '[^T]_FAILURE|EXIT_CANCELED' $(srcdir)/src) \
633 | grep -vE '= EXIT_FAILURE|return .* \?' | grep . \
634 && { echo '$(ME): do not use EXIT_FAILURE in the above' \
635 1>&2; exit 1; } || :
637 # Ensure that tests call the get_min_ulimit_v_ function if using ulimit -v
638 sc_prohibit_test_ulimit_without_require_:
639 @(git -C $(srcdir) grep -l get_min_ulimit_v_ tests; \
640 git -C $(srcdir) grep -l 'ulimit -v' tests) \
641 | sort | uniq -u | grep . && { echo "$(ME): the above test(s)"\
642 " should match get_min_ulimit_v_ with ulimit -v" 1>&2; exit 1; } || :
644 # Ensure that tests call the cleanup_ function if using background processes
645 sc_prohibit_test_background_without_cleanup_:
646 @(git -C $(srcdir) grep -El '( &$$|&[^&]*=\$$!)' tests; \
647 git -C $(srcdir) grep -l 'cleanup_()' tests | sed p) \
648 | sort | uniq -u | grep . && { echo "$(ME): the above test(s)"\
649 " should use cleanup_ for background processes" 1>&2; exit 1; } || :
651 # Ensure that tests call the print_ver_ function for programs which are
652 # actually used in that test.
653 sc_prohibit_test_calls_print_ver_with_irrelevant_argument:
654 @git -C $(srcdir) grep -w print_ver_ tests \
655 | sed 's#:print_ver_##' \
656 | { fail=0; \
657 while read file name; do \
658 for i in $$name; do \
659 case "$$i" in install) i=ginstall;; esac; \
660 grep -w "$$i" $$file|grep -vw print_ver_|grep . >/dev/null \
661 || { fail=1; \
662 echo "*** Test: $$file, offending: $$i." 1>&2; };\
663 done; \
664 done; \
665 test $$fail = 0 || exit 1; \
666 } || { echo "$(ME): the above test(s) call print_ver_ for" \
667 "program(s) they don't use" 1>&2; exit 1; }
669 # Exempt the contents of any usage function from the following.
670 _continued_string_col_1 = \
671 s/^usage .*?\n}//ms;/\\\n\w/ and print ("$$ARGV\n"),$$e=1;END{$$e||=0;exit $$e}
672 # Ding any source file that has a continued string with an alphabetic in the
673 # first column of the following line. We prohibit them because they usually
674 # trigger false positives in tools that try to map an arbitrary line number
675 # to the enclosing function name. Of course, very many strings do precisely
676 # this, *when they are part of the usage function*. That is why we exempt
677 # the contents of any function named "usage".
678 sc_prohibit_continued_string_alpha_in_column_1:
679 @perl -0777 -ne '$(_continued_string_col_1)' \
680 $$($(VC_LIST_EXCEPT) | grep '\.[ch]$$') \
681 || { echo '$(ME): continued string with word in first column' \
682 1>&2; exit 1; } || :
683 # Use this to list offending lines:
684 # git ls-files |grep '\.[ch]$' | xargs \
685 # perl -n -0777 -e 's/^usage.*?\n}//ms;/\\\n\w/ and print "$ARGV\n"' \
686 # | xargs grep -A1 '\\$'|grep '\.[ch][:-][_a-zA-Z]'
689 ###########################################################
690 _p0 = \([^"'/]\|"\([^\"]\|[\].\)*"\|'\([^\']\|[\].\)*'
691 _pre = $(_p0)\|[/][^"'/*]\|[/]"\([^\"]\|[\].\)*"\|[/]'\([^\']\|[\].\)*'\)*
692 _pre_anchored = ^\($(_pre)\)
693 _comment_and_close = [^*]\|[*][^/*]\)*[*][*]*/
694 # help font-lock mode: '
696 # A sed expression that removes ANSI C and ISO C99 comments.
697 # Derived from the one in GNU gettext's 'moopp' preprocessor.
698 _sed_remove_comments = \
699 /[/][/*]/{ \
700 ta; \
701 :a; \
702 s,$(_pre_anchored)//.*,\1,; \
703 te; \
704 s,$(_pre_anchored)/[*]\($(_comment_and_close),\1 ,; \
705 ta; \
706 /^$(_pre)[/][*]/{ \
707 s,$(_pre_anchored)/[*].*,\1 ,; \
708 tu; \
709 :u; \
710 n; \
711 s,^\($(_comment_and_close),,; \
712 tv; \
713 s,^.*$$,,; \
714 bu; \
715 :v; \
716 }; \
717 :e; \
719 # Quote all single quotes.
720 _sed_rm_comments_q = $(subst ','\'',$(_sed_remove_comments))
721 # help font-lock mode: '
723 _space_before_paren_exempt =? \\n\\$$
724 _space_before_paren_exempt = \
725 (^ *\#|\\n\\$$|%s\(to %s|(date|group|character)\(s\))
726 # Ensure that there is a space before each open parenthesis in C code.
727 sc_space_before_open_paren:
728 @if $(VC_LIST_EXCEPT) | grep -l '\.[ch]$$' > /dev/null; then \
729 fail=0; \
730 for c in $$($(VC_LIST_EXCEPT) | grep '\.[ch]$$'); do \
731 sed '$(_sed_rm_comments_q)' $$c 2>/dev/null \
732 | grep -i '[[:alnum:]](' \
733 | grep -vE '$(_space_before_paren_exempt)' \
734 | grep . && { fail=1; echo "*** $$c"; }; \
735 done; \
736 test $$fail = 1 && \
737 { echo '$(ME): the above files lack a space-before-open-paren' \
738 1>&2; exit 1; } || :; \
739 else :; \
742 # Similar to the gnulib maint.mk rule for sc_prohibit_strcmp
743 # Use STREQ_LEN or STRPREFIX rather than comparing strncmp == 0, or != 0.
744 sc_prohibit_strncmp:
745 @prohibit='^[^#].*str''ncmp *\(' \
746 halt='use STREQ_LEN or STRPREFIX instead of str''ncmp' \
747 $(_sc_search_regexp)
749 # Enforce recommended preprocessor indentation style.
750 sc_preprocessor_indentation:
751 @if cppi --version >/dev/null 2>&1; then \
752 $(VC_LIST_EXCEPT) | grep '\.[ch]$$' | xargs cppi -a -c \
753 || { echo '$(ME): incorrect preprocessor indentation' 1>&2; \
754 exit 1; }; \
755 else \
756 echo '$(ME): skipping test $@: cppi not installed' 1>&2; \
759 # THANKS.in is a list of name/email pairs for people who are mentioned in
760 # commit logs (and generated ChangeLog), but who are not also listed as an
761 # author of a commit. Name/email pairs of commit authors are automatically
762 # extracted from the repository. As a very minor factorization, when
763 # someone who was initially listed only in THANKS.in later authors a commit,
764 # this rule detects that their pair may now be removed from THANKS.in.
765 sc_THANKS_in_duplicates:
766 @{ git -C $(srcdir) log --pretty=format:%aN | sort -u; \
767 cut -b-36 $(srcdir)/THANKS.in \
768 | sed '/^$$/,/^$$/!d;/^$$/d;s/ *$$//'; } \
769 | sort | uniq -d | grep . \
770 && { echo '$(ME): remove the above names from THANKS.in' \
771 1>&2; exit 1; } || :
773 # Ensure the contributor list stays sorted. However, if the system's
774 # en_US.UTF-8 locale data is erroneous, give a diagnostic and skip
775 # this test. This affects OS X, up to at least 10.11.6.
776 # Use our sort as other implementations may result in a different order.
777 sc_THANKS_in_sorted:
778 @printf 'a\n.b\n'|LC_ALL=en_US.UTF-8 src/sort -c 2> /dev/null \
779 && { \
780 sed '/^$$/,/^$$/!d;/^$$/d' $(srcdir)/THANKS.in > $@.1 && \
781 LC_ALL=en_US.UTF-8 src/sort -f -k1,1 $@.1 > $@.2 && \
782 diff -u $@.1 $@.2; diff=$$?; \
783 rm -f $@.1 $@.2; \
784 test "$$diff" = 0 \
785 || { echo '$(ME): THANKS.in is unsorted' 1>&2; exit 1; }; \
787 || { echo '$(ME): this system has erroneous locale data;' \
788 'skipping $@' 1>&2; }
790 # Look for developer diagnostics that are marked for translation.
791 # This won't find any for which devmsg's format string is on a separate line.
792 sc_marked_devdiagnostics:
793 @prohibit='$(begword)devmsg *\(.*_\(' \
794 halt='found marked developer diagnostic(s)' \
795 $(_sc_search_regexp)
797 # Ensure we keep hex constants as 4 or 8 bytes for consistency
798 # and so that make src/fs-magic-compare works consistently
799 sc_fs-magic-compare:
800 @sed -n 's|.*/\* \(0x[0-9A-Fa-f]\{1,\}\) .*\*/|\1|p' \
801 $(srcdir)/src/stat.c | grep -Ev '^0x([0-9A-F]{4}){1,2}$$' \
802 && { echo '$(ME): Constants in src/stat.c should be 4 or 8' \
803 'upper-case chars' 1>&2; exit 1; } || :
805 # Ensure gnulib generated files are ignored
806 # TODO: Perhaps augment gnulib-tool to do this in lib/.gitignore?
807 sc_gitignore_missing:
808 @{ sed -n '/^\/lib\/.*\.h$$/{p;p}' $(srcdir)/.gitignore; \
809 find lib -name '*.in*' ! -name '*~' ! -name 'sys_*' | \
810 sed 's|^|/|; s|_\(.*in\.h\)|/\1|; s/\.in//'; } | \
811 sort | uniq -u | grep . && { echo '$(ME): Add above' \
812 'entries to .gitignore' >&2; exit 1; } || :
814 # Flag redundant entries in .gitignore
815 # Disabled for now as too aggressive flagging
816 # entries like /lib/arg-nonnull.h
817 #sc_gitignore_redundant:
818 # @{ grep ^/lib $(srcdir)/.gitignore; \
819 # sed 's|^|/lib|' $(srcdir)/lib/.gitignore; } | \
820 # sort | uniq -d | grep . && { echo '$(ME): Remove above' \
821 # 'entries from .gitignore' >&2; exit 1; } || :
823 sc_prohibit-form-feed:
824 @prohibit=$$'\f' \
825 in_vc_files='\.[chly]$$' \
826 halt='Form Feed (^L) detected' \
827 $(_sc_search_regexp)
829 # Override the default Cc: used in generating an announcement.
830 announcement_Cc_ = $(translation_project_), \
831 coreutils@gnu.org, coreutils-announce@gnu.org
833 -include $(srcdir)/dist-check.mk
835 update-copyright-env = \
836 UPDATE_COPYRIGHT_FORCE=1 \
837 UPDATE_COPYRIGHT_USE_INTERVALS=2 \
838 UPDATE_COPYRIGHT_MAX_LINE_LENGTH=79
840 # List syntax-check exemptions.
841 exclude_file_name_regexp--sc_space_tab = \
842 ^(tests/pr/|tests/misc/nl\.sh$$|gl/.*\.diff$$|man/help2man$$)
843 exclude_file_name_regexp--sc_bindtextdomain = \
844 ^(gl/.*|lib/euidaccess-stat|src/make-prime-list|src/cksum)\.c$$
845 exclude_file_name_regexp--sc_trailing_blank = \
846 ^(tests/pr/|gl/.*\.diff$$|man/help2man)
847 exclude_file_name_regexp--sc_system_h_headers = \
848 ^src/((die|system|copy|chown-core|find-mount-point)\.h|make-prime-list\.c)$$
850 _src = (false|lbracket|ls-(dir|ls|vdir)|tac-pipe|uname-(arch|uname))
851 _gl_src = (xdecto.max|cl-strtold)
852 exclude_file_name_regexp--sc_require_config_h_first = \
853 (^lib/buffer-lcm\.c|gl/lib/$(_gl_src)\.c|src/$(_src)\.c)$$
854 exclude_file_name_regexp--sc_require_config_h = \
855 $(exclude_file_name_regexp--sc_require_config_h_first)
857 exclude_file_name_regexp--sc_po_check = ^(gl/|man/help2man)
858 exclude_file_name_regexp--sc_prohibit_always-defined_macros = \
859 ^src/(seq|remove)\.c$$
860 exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF = ^tests/pr/
861 exclude_file_name_regexp--sc_program_name = \
862 ^(gl/.*|lib/euidaccess-stat|src/make-prime-list)\.c$$
863 exclude_file_name_regexp--sc_file_system = \
864 NEWS|^(init\.cfg|src/df\.c|tests/df/df-P\.sh|tests/df/df-output\.sh)$$
865 exclude_file_name_regexp--sc_prohibit_always_true_header_tests = \
866 ^m4/stat-prog\.m4$$
867 exclude_file_name_regexp--sc_prohibit_fail_0 = \
868 (^.*/git-hooks/commit-msg|^tests/init\.sh|Makefile\.am|\.mk|.*\.texi)$$
869 exclude_file_name_regexp--sc_prohibit_test_minus_ao = doc/.*\.texi$$
870 exclude_file_name_regexp--sc_prohibit_atoi_atof = ^lib/euidaccess-stat\.c$$
872 # longlong.h is maintained elsewhere.
873 _ll = ^src/longlong\.h$$
874 exclude_file_name_regexp--sc_useless_cpp_parens = $(_ll)
875 exclude_file_name_regexp--sc_space_before_open_paren = $(_ll)
877 tbi_1 = ^tests/pr/|(\.mk|^man/help2man)$$
878 tbi_2 = ^scripts/git-hooks/(pre-commit|pre-applypatch|applypatch-msg)$$
879 tbi_3 = (GNU)?[Mm]akefile(\.am)?$$|$(_ll)
880 exclude_file_name_regexp--sc_prohibit_tab_based_indentation = \
881 $(tbi_1)|$(tbi_2)|$(tbi_3)
883 exclude_file_name_regexp--sc_preprocessor_indentation = \
884 ^(gl/lib/rand-isaac\.[ch]|gl/tests/test-rand-isaac\.c)$$|$(_ll)
885 exclude_file_name_regexp--sc_prohibit_stat_st_blocks = \
886 ^(src/system\.h|tests/du/2g\.sh)$$
888 exclude_file_name_regexp--sc_prohibit_continued_string_alpha_in_column_1 = \
889 ^src/(system\.h|od\.c|printf\.c|getlimits\.c)$$
891 _cksum = ^tests/cksum/cksum-base64\.pl$$
892 exclude_file_name_regexp--sc_prohibit_test_backticks = \
893 ^tests/(local\.mk|(init|misc/stdbuf|factor/create-test)\.sh)$$|$(_cksum)
895 # Exempt test.c, since it's nominally shared, and relatively static.
896 exclude_file_name_regexp--sc_prohibit_operator_at_end_of_line = \
897 ^src/(ptx|test|head)\.c$$
899 exclude_file_name_regexp--sc_error_message_uppercase = ^src/factor\.c$$
900 exclude_file_name_regexp--sc_prohibit_atoi_atof = ^src/make-prime-list\.c$$
902 # Exception here as we don't want __attribute elided on non GCC
903 exclude_file_name_regexp--sc_prohibit-gl-attributes = ^src/libstdbuf\.c$$
905 exclude_file_name_regexp--sc_prohibit_uppercase_id_est = \.diff$$
906 exclude_file_name_regexp--sc_ensure_dblspace_after_dot_before_id_est = \.diff$$
907 exclude_file_name_regexp--sc_ensure_comma_after_id_est = \.diff|$(_ll)$$
908 exclude_file_name_regexp--sc_long_lines = \.diff$$|$(_ll)|$(_cksum)
910 # `grep . -q` is not exactly equivalent to `grep . >/dev/null`
911 # and this difference is significant in the NEWS description
912 exclude_file_name_regexp--sc_unportable_grep_q = NEWS
914 # Augment AM_CFLAGS to include our per-directory options:
915 AM_CFLAGS += $($(@D)_CFLAGS)
917 src_CFLAGS = $(WARN_CFLAGS)
918 lib_CFLAGS = $(GNULIB_WARN_CFLAGS)
919 gnulib-tests_CFLAGS = $(GNULIB_TEST_WARN_CFLAGS)
921 # Configuration to make the tight-scope syntax-check rule work with
922 # non-recursive make.
923 # Note _gl_TS_headers use _single line_ extern function declarations,
924 # while *_SOURCES use the _two line_ form.
925 export _gl_TS_headers = $(noinst_HEADERS)
926 # Add exceptions for --enable-single-binary renamed functions.
927 _gl_TS_unmarked_extern_functions = main usage
928 _gl_TS_unmarked_extern_functions += single_binary_main_.* _usage_.*
929 # Headers to search for single line extern _data_ declarations.
930 _gl_TS_other_headers = $(srcdir)/src/*.h src/*.h
931 # Tell the tight_scope rule about an exceptional "extern" variable.
932 # Normally, the rule would detect its declaration, but that uses a
933 # different name, __clz_tab.
934 _gl_TS_unmarked_extern_vars = factor_clz_tab
935 # Other tight_scope settings
936 _gl_TS_dir = .
937 _gl_TS_obj_files = src/*.$(OBJEXT)