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