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