doc: pwd: improve the -P help description
[coreutils.git] / cfg.mk
blob2cfb31877f3fbc94300bb10e228d2caed0671842
1 # Customize maint.mk -*- makefile -*-
2 # Copyright (C) 2003-2024 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_indent
31 # Tools used to bootstrap this package, used for "announcement".
32 bootstrap-tools = autoconf,automake,gnulib,bison
34 # Now that we have better tests, make this the default.
35 export VERBOSE = yes
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
49 export XZ_OPT = -8e
51 old_NEWS_hash = e4007bb11862c8509c974bff2cccdeac
53 # Add an exemption for sc_makefile_at_at_check.
54 _makefile_at_at_check_exceptions = \
55 ' && !/MAKEINFO/ && !/^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 world:
61 ./bootstrap && \
62 ./configure --quiet && \
63 $(MAKE) $(AM_MAKEFLAGS) -j $$(nproc 2>/dev/null || echo 1)
65 # Ensure that the list of O_ symbols used to compute O_FULLBLOCK is complete.
66 dd = $(srcdir)/src/dd.c
67 sc_dd_O_FLAGS:
68 @rm -f $@.1 $@.2
69 @{ echo O_FULLBLOCK; echo O_NOCACHE; \
70 perl -nle '/^ +\| (O_\w*)$$/ and print $$1' $(dd); } | sort > $@.1
71 @{ echo O_NOFOLLOW; perl -nle '/{"[a-z]+",\s*(O_\w+)},/ and print $$1' \
72 $(dd); } | sort > $@.2
73 @diff -u $@.1 $@.2; diff=$$?; \
74 rm -f $@.1 $@.2; \
75 test "$$diff" = 0 \
76 || { echo '$(ME): $(dd) has inconsistent O_ flag lists'>&2; \
77 exit 1; }
79 # Ensure that dd's definition of LONGEST_SYMBOL stays in sync
80 # with the strings from the two affected variables.
81 dd_c = $(srcdir)/src/dd.c
82 sc_dd_max_sym_length:
83 ifneq ($(wildcard $(dd_c)),)
84 @len=$$( (sed -n '/conversions\[] =$$/,/^};/p' $(dd_c);\
85 sed -n '/flags\[] =$$/,/^};/p' $(dd_c) ) \
86 |sed -n '/"/s/^[^"]*"\([^"]*\)".*/\1/p'| wc -L);\
87 max=$$(sed -n '/^#define LONGEST_SYMBOL /s///p' $(dd_c) \
88 |tr -d '"' | wc -L); \
89 if test "$$len" = "$$max"; then :; else \
90 echo 'dd.c: LONGEST_SYMBOL is not longest' 1>&2; \
91 exit 1; \
93 endif
95 # Many m4 macros names once began with 'jm_'.
96 # On 2004-04-13, they were all changed to start with gl_ instead.
97 # Make sure that none are inadvertently reintroduced.
98 sc_prohibit_jm_in_m4:
99 @grep -nE 'jm_[A-Z]' \
100 $$($(VC_LIST) m4 |grep '\.m4$$'; echo /dev/null) && \
101 { echo '$(ME): do not use jm_ in m4 macro names' \
102 1>&2; exit 1; } || :
104 # Ensure that each root-requiring test is run via the "check-root" rule.
105 sc_root_tests:
106 @t1=sc-root.expected; t2=sc-root.actual; \
107 grep -nl '^ *require_root_$$' `$(VC_LIST) tests` | \
108 sed 's|.*/tests/|tests/|' | sort > $$t1; \
109 for t in $(all_root_tests); do echo $$t; done | sort > $$t2; \
110 st=0; diff -u $$t1 $$t2 || st=1; \
111 rm -f $$t1 $$t2; \
112 exit $$st
114 # Ensure that all version-controlled test cases are listed in $(all_tests).
115 sc_tests_list_consistency:
116 @bs="\\"; \
117 test_extensions_rx=`echo $(TEST_EXTENSIONS) \
118 | sed -e "s/ /|/g" -e "s/$$bs./$$bs$$bs./g"`; \
120 for t in $(all_tests); do echo $$t; done; \
121 cd $(top_srcdir); \
122 $(SHELL) build-aux/vc-list-files tests \
123 | grep -Ev '^tests/(factor/(run|create-test)|init)\.sh$$' \
124 | grep -E "$$test_extensions_rx\$$"; \
125 } | sort | uniq -u | grep . && exit 1; :
127 # Ensure that all version-controlled test scripts are executable.
128 sc_tests_executable:
129 @set -o noglob 2>/dev/null || set -f; \
130 cd $(srcdir); \
131 find_ext="-name '' "`printf -- "-o -name *%s " $(TEST_EXTENSIONS)`;\
132 find $(srcdir)/tests/ \( $$find_ext \) \! -perm -u+x -print \
133 | { sed "s|^$(srcdir)/||"; git ls-files $(srcdir)/tests/; } \
134 | sort | uniq -d \
135 | sed -e "s/^/$(ME): Please make test executable: /" | grep . \
136 && exit 1; :
138 # Ensure all gnulib patches apply cleanly
139 sc_ensure_gl_diffs_apply_cleanly:
140 @find $(srcdir)/gl/ -name '*.diff' | while read p; do \
141 patch --fuzz=0 -f -s -d $(srcdir)/gnulib/ -p1 --dry-run < "$$p" >&2 \
142 || { echo "$$p" >&2; echo 'To refresh all gl patches run:' \
143 'make refresh-gnulib-patches' >&2; exit 1; } \
144 done
146 # Avoid :>file which doesn't propagate errors
147 sc_prohibit_colon_redirection:
148 @cd $(srcdir)/tests && GIT_PAGER= git grep -En ': *>.*\|\|' \
149 && { echo '$(ME): '"The leading colon in :> will hide errors" >&2; \
150 exit 1; } \
151 || :
153 # Ensure emit_mandatory_arg_note() is called if required
154 sc_ensure_emit_mandatory_arg_note:
155 @cd $(srcdir)/src && GIT_PAGER= git \
156 grep -l -- '^ *-[^-].*--.*[^[]=' *.c \
157 | xargs grep -L emit_mandatory_arg_note | grep . \
158 && { echo '$(ME): '"emit_mandatory_arg_note() missing" 1>&2; \
159 exit 1; } || :
161 # Create a list of regular expressions matching the names
162 # of files included from system.h. Exclude a couple.
163 .re-list:
164 @sed -n '/^# *include /s///p' $(srcdir)/src/system.h \
165 | grep -Ev 'sys/(param|file)\.h' \
166 | sed 's/ .*//;;s/^["<]/^# *include [<"]/;s/\.h[">]$$/\\.h[">]/' \
167 > $@-t
168 @mv $@-t $@
170 define gl_trap_
171 Exit () { set +e; (exit $$1); exit $$1; }; \
172 for sig in 1 2 3 13 15; do \
173 eval "trap 'Exit $$(expr $$sig + 128)' $$sig"; \
174 done
175 endef
177 # Files in src/ should not include directly any of
178 # the headers already included via system.h.
179 sc_system_h_headers: .re-list
180 @if test -f $(srcdir)/src/system.h; then \
181 trap 'rc=$$?; rm -f .re-list; exit $$rc' 0; \
182 $(gl_trap_); \
183 grep -nE -f .re-list \
184 $$($(VC_LIST_EXCEPT) | grep -E '^($(srcdir)/)?src/') \
185 && { echo '$(ME): the above are already included via system.h'\
186 1>&2; exit 1; } || :; \
189 # Files in src/ should not use '%s' notation in format strings,
190 # i.e., single quotes around %s (or similar) should be avoided.
191 sc_prohibit_quotes_notation:
192 @cd $(srcdir)/src && GIT_PAGER= git grep -n "\".*[\`']%s'.*\"" *.c \
193 && { echo '$(ME): '"Use quote() to avoid quoted '%s' notation" 1>&2; \
194 exit 1; } \
195 || :
197 error_fns = (error|diagnose)
199 # Files in src/ should quote all strings in error() output, so that
200 # unexpected input chars like \r etc. don't corrupt the error.
201 # In edge cases this can be avoided by putting the format string
202 # on a separate line to the arguments, or the arguments in parenthesis.
203 sc_error_quotes:
204 @cd $(srcdir)/src \
205 && GIT_PAGER= git grep -E -n '$(error_fns) *\(.*%s.*, [^(]*\);$$' \
206 *.c | grep -v ', q' \
207 && { echo '$(ME): '"Use quote() for error string arguments" 1>&2; \
208 exit 1; } \
209 || :
211 # Files in src/ should quote all file names in error() output
212 # using quotef(), to provide quoting only when necessary,
213 # but also provide better support for copy and paste when used.
214 sc_error_shell_quotes:
215 @cd $(srcdir)/src && \
216 { GIT_PAGER= git grep -E \
217 '$(error_fns) \(.*%s[:"], .*(name|file)[^"]*\);$$' *.c; \
218 GIT_PAGER= git grep -E \
219 ' quote[ _].*file' *.c; } \
220 | grep -Ev '(quotef|q[^ ]*name)' \
221 && { echo '$(ME): '"Use quotef() for colon delimited names" 1>&2; \
222 exit 1; } \
223 || :
225 # Files in src/ should quote all file names in error() output
226 # using quoteaf() when the name is separated with spaces,
227 # to distinguish the file name at issue and
228 # to provide better support for copy and paste.
229 sc_error_shell_always_quotes:
230 @cd $(srcdir)/src && GIT_PAGER= git grep -E \
231 '$(error_fns) \(.*[^:] %s[ "].*, .*(name|file)[^"]*\);$$' \
232 *.c | grep -Ev '(quoteaf|q[^ ]*name)' \
233 && { echo '$(ME): '"Use quoteaf() for space delimited names" 1>&2; \
234 exit 1; } \
235 || :
236 @cd $(srcdir)/src && GIT_PAGER= git grep -E -A1 \
237 '$(error_fns) \([^%]*[^:] %s[ "]' *.c | grep 'quotef' \
238 && { echo '$(ME): '"Use quoteaf() for space delimited names" 1>&2; \
239 exit 1; } \
240 || :
242 # Avoid unstyled quoting to internal slots and thus destined for diagnostics
243 # as that can leak unescaped control characters to the output, when using
244 # the default "literal" quoting style.
245 # Instead use quotef(), or quoteaf() or in edge cases quotearg_n_style_colon().
246 # A more general PCRE would be @prohibit='quotearg_.*(?!(style|buffer))'
247 sc_prohibit-quotearg:
248 @prohibit='quotearg(_n)?(|_colon|_char|_mem) ' \
249 in_vc_files='\.c$$' \
250 halt='Unstyled diagnostic quoting detected' \
251 $(_sc_search_regexp)
253 sc_prohibit-skip:
254 @prohibit='\|\| skip ' \
255 halt='Use skip_ not skip' \
256 $(_sc_search_regexp)
258 sc_sun_os_names:
259 @grep -nEi \
260 'solaris[^[:alnum:]]*2\.(7|8|9|[1-9][0-9])|sunos[^[:alnum:]][6-9]' \
261 $$($(VC_LIST_EXCEPT)) && \
262 { echo '$(ME): found misuse of Sun OS version numbers' 1>&2; \
263 exit 1; } || :
265 # Ensure that the list of programs and author names is accurate.
266 # We need a UTF8 locale. If a lack of locale support or a missing
267 # translation inhibits printing of UTF-8 names, just skip this test.
268 au_dotdot = authors-dotdot
269 au_actual = authors-actual
270 sc_check-AUTHORS: $(all_programs)
271 @locale=en_US.UTF-8; \
272 LC_ALL=$$locale ./src/factor --version \
273 | grep ' Torbjorn ' > /dev/null \
274 && { echo "$@: skipping this check"; exit 0; }; \
275 rm -f $(au_actual) $(au_dotdot); \
276 for i in `ls $(all_programs) \
277 | sed -e 's,^src/,,' -e 's,$(EXEEXT)$$,,' \
278 | sed /libstdbuf/d \
279 | $(ASSORT) -u`; do \
280 test "$$i" = '[' && continue; \
281 exe=$$i; \
282 if test "$$i" = install; then \
283 exe=ginstall; \
284 elif test "$$i" = test; then \
285 exe='['; \
286 fi; \
287 LC_ALL=$$locale ./src/$$exe --version \
288 | perl -0 -p -e 's/,\n/, /gm' \
289 | sed -n -e '/Written by /{ s//'"$$i"': /;' \
290 -e 's/,* and /, /; s/\.$$//; p; }'; \
291 done > $(au_actual) && \
292 sed -n '/^[^ ][^ ]*:/p' $(srcdir)/AUTHORS > $(au_dotdot) \
293 && diff $(au_actual) $(au_dotdot) \
294 && rm -f $(au_actual) $(au_dotdot)
296 # Ensure the alternative __attribute (keyword) form isn't used as
297 # that form is not elided where required. Also ensure that we don't
298 # directly use attributes already defined by gnulib.
299 # TODO: move the check for _GL... attributes to gnulib.
300 sc_prohibit-gl-attributes:
301 @prohibit='__attribute |__(unused|pure|const)__' \
302 in_vc_files='\.[ch]$$' \
303 halt='Use _GL... attribute macros' \
304 $(_sc_search_regexp)
306 # Prefer the const declaration form, with const following the type
307 sc_prohibit-const-char:
308 @prohibit='const char \*' \
309 in_vc_files='\.[ch]$$' \
310 halt='Use char const *, not const char *' \
311 $(_sc_search_regexp)
313 # Look for lines longer than 80 characters, except omit:
314 # - urls
315 # - the fdl.texi file copied from gnulib,
316 # - the help2man script copied from upstream,
317 # - tests involving long checksum lines, and
318 # - the 'pr' test cases.
319 FILTER_LONG_LINES = \
320 \|^[^:]*NEWS:.*https\{,1\}://| d; \
321 \|^[^:]*doc/fdl.texi:| d; \
322 \|^[^:]*man/help2man:| d; \
323 \|^[^:]*tests/cksum/sha[0-9]*sum.*\.pl[-:]| d; \
324 \|^[^:]*tests/pr/|{ \|^[^:]*tests/pr/pr-tests:| !d; };
325 sc_long_lines:
326 @wc -L /dev/null >/dev/null 2>/dev/null \
327 || { echo "$@: skipping: wc -L not supported"; exit 0; }; \
328 sed -r 1q /dev/null 2>/dev/null \
329 || { echo "$@: skipping: sed -r not supported"; exit 0; }; \
330 files=$$($(VC_LIST_EXCEPT) | xargs wc -L | sed -rn '/ total$$/d;\
331 s/^ *(8[1-9]|9[0-9]|[0-9]{3,}) //p'); \
332 halt='line(s) with more than 80 characters; reindent'; \
333 for file in $$files; do \
334 expand $$file | grep -nE '^.{80}.' | \
335 sed -e "s|^|$$file:|" -e '$(FILTER_LONG_LINES)'; \
336 done | grep . && { msg="$$halt" $(_sc_say_and_exit) } || :
338 # Option descriptions should not start with a capital letter.
339 # One could grep source directly as follows:
340 # grep -E " {2,6}-.*[^.] [A-Z][a-z]" $$($(VC_LIST_EXCEPT) | grep '\.c$$')
341 # but that would miss descriptions not on the same line as the -option.
342 sc_option_desc_uppercase: $(ALL_MANS)
343 @grep '^\\fB\\-' -A1 man/*.1 | LC_ALL=C grep '\.1.[A-Z][a-z]' \
344 && { echo 1>&2 '$@: found initial capitals in --help'; exit 1; } || :
346 # '--' should not be treated as '–' (U+2013 EN DASH) in long option names.
347 sc_texi_long_option_escaped: doc/coreutils.info
348 @grep ' –[^ ]' '$<' \
349 && { echo 1>&2 '$@: found unquoted --long-option'; exit 1; } || :
351 # Ensure all man/*.[1x] files are present.
352 sc_man_file_correlation: check-x-vs-1 check-programs-vs-x
354 # Ensure that for each .x file in the 'man/' subdirectory, there is a
355 # corresponding .1 file in the definition of $(EXTRA_MANS).
356 # But since that expansion usually lacks programs like arch and hostname,
357 # add them here manually.
358 .PHONY: check-x-vs-1
359 check-x-vs-1:
360 @PATH=./src$(PATH_SEPARATOR)$$PATH; export PATH; \
361 t=$@-t; \
362 (cd $(srcdir)/man && ls -1 *.x) \
363 | sed 's/\.x$$//' | $(ASSORT) > $$t; \
364 (echo $(patsubst man/%,%,$(ALL_MANS)) \
365 | tr -s ' ' '\n' | sed 's/\.1$$//') \
366 | $(ASSORT) -u | diff - $$t || { rm $$t; exit 1; }; \
367 rm $$t
369 # Ensure that non-trivial .x files in the 'man/' subdirectory,
370 # i.e., files exceeding a line count of 20 or a byte count of 1000,
371 # contain a Copyright notice.
372 .PHONY: sc_man_check_x_copyright
373 sc_man_check_x_copyright:
374 @status=0; \
375 cd $(srcdir) && wc -cl man/*.x | head -n-1 \
376 | awk '$$1 >= 20 || $$2 >= 1000 {print $$3}' \
377 | xargs grep -L 'Copyright .* Free Software Foundation' \
378 | grep . \
379 && { echo 1>&2 '$@: exceeding file size/line count limit' \
380 '- please add a copyright note'; status=1; }; \
381 exit $$status
383 # Writing a portable rule to generate a manpage like '[.1' would be
384 # a nightmare, so filter that out.
385 all-progs-but-lbracket = $(filter-out [,$(patsubst src/%,%,$(all_programs)))
387 # Ensure that for each coreutils program there is a corresponding
388 # '.x' file in the 'man/' subdirectory.
389 .PHONY: check-programs-vs-x
390 check-programs-vs-x:
391 @status=0; \
392 for p in dummy $(all-progs-but-lbracket); do \
393 case $$p in *.so) continue;; esac; \
394 test $$p = dummy && continue; \
395 test $$p = ginstall && p=install || : ; \
396 test -f $(srcdir)/man/$$p.x \
397 || { echo missing $$p.x 1>&2; status=1; }; \
398 done; \
399 exit $$status
401 # Ensure we can check out on case insensitive file systems
402 sc_case_insensitive_file_names: src/uniq
403 @git -C $(srcdir) ls-files | sort -f | src/uniq -Di | grep . && \
404 { echo "$(ME): the above file(s) conflict on case insensitive" \
405 " file systems" 1>&2; exit 1; } || :
407 # Ensure that the end of each release's section is marked by two empty lines.
408 sc_NEWS_two_empty_lines:
409 @sed -n 4,/Noteworthy/p $(srcdir)/NEWS \
410 | perl -n0e '/(^|\n)\n\n\* Noteworthy/ or exit 1' \
411 || { echo '$(ME): use two empty lines to separate NEWS sections' \
412 1>&2; exit 1; } || :
414 # With split lines, don't leave an operator at end of line.
415 # Instead, put it on the following line, where it is more apparent.
416 # Don't bother checking for "*" at end of line, since it provokes
417 # far too many false positives, matching constructs like "TYPE *".
418 # Similarly, omit "=" (initializers).
419 binop_re_ ?= [-/+^!<>]|[-/+*^!<>=]=|&&?|\|\|?|<<=?|>>=?
420 sc_prohibit_operator_at_end_of_line:
421 @prohibit='. ($(binop_re_))$$' \
422 in_vc_files='\.[chly]$$' \
423 halt='found operator at end of line' \
424 $(_sc_search_regexp)
426 # Partial substitutes for GNU extensions \< and \> in regexps.
427 begword = (^|[^_[:alnum:]])
428 endword = ($$|[^_[:alnum:]])
430 # Don't use address of "stat" or "lstat" functions
431 sc_prohibit_stat_macro_address:
432 @prohibit='$(begword)l?stat '':|&l?stat$(endword)' \
433 halt='stat() and lstat() may be function-like macros' \
434 $(_sc_search_regexp)
436 # Ensure that date's --help output stays in sync with the info
437 # documentation for GNU strftime. The only exception is %N and %q,
438 # which date accepts but GNU strftime does not.
440 # "info foo" fails with error, but not "info foo >/dev/null".
441 extract_char = sed 's/^[^%][^%]*%\(.\).*/\1/'
442 sc_strftime_check:
443 @if test -f $(srcdir)/src/date.c; then \
444 if info libc date calendar format 2>/dev/null | \
445 grep "^ *['\`]%.'$$" >$@-tmp; then \
446 { echo N; echo q; $(extract_char) $@-tmp; }| sort \
447 >$@-info; \
448 grep '^ %. ' $(srcdir)/src/date.c | sort \
449 | $(extract_char) > $@-src; \
450 diff -u $@-src $@-info || exit 1; \
451 else \
452 echo '$(ME): skipping $@: libc info not installed' 1>&2; \
453 fi; \
454 rm -f $@-info $@-src $@-tmp; \
457 # Indent only with spaces.
458 sc_prohibit_tab_based_indentation:
459 @prohibit='^ * ' \
460 halt='TAB in indentation; use only spaces' \
461 $(_sc_search_regexp)
463 # Enforce lowercase 'e' in "I.e.".
464 sc_prohibit_uppercase_id_est:
465 @prohibit='I\.E\.' \
466 halt='Uppercase "Id Est" abbreviation; use "I.e.," instead' \
467 $(_sc_search_regexp)
469 # Enforce double-space before "I.e." at the beginning of a sentence.
470 sc_ensure_dblspace_after_dot_before_id_est:
471 @prohibit='\. I\.e\.' \
472 halt='Single space after dot before "i.e."; use ". i.e." instead' \
473 $(_sc_search_regexp)
475 # Enforce comma after "i.e." (at least before a blank or at EOL).
476 sc_ensure_comma_after_id_est:
477 @prohibit='[Ii]\.e\.( |$$)' \
478 halt='Missing comma after "i.e."; use "i.e.," instead' \
479 $(_sc_search_regexp)
481 # The SEE ALSO section of a man page should not be terminated with
482 # a period. Check the first line after each "SEE ALSO" line in man/*.x:
483 sc_prohibit_man_see_also_period:
484 @grep -nB1 '\.$$' $$($(VC_LIST_EXCEPT) | grep 'man/.*\.x$$') \
485 | grep -A1 -e '-\[SEE ALSO]' | grep '\.$$' && \
486 { echo '$(ME): do not end "SEE ALSO" section with a period' \
487 1>&2; exit 1; } || :
489 sc_prohibit_exit_write_error:
490 @prohibit='error.*EXIT_FAILURE.*write error' \
491 in_vc_files='\.c$$' \
492 halt='Use write_error() instead' \
493 $(_sc_search_regexp)
495 sc_prohibit_NULL:
496 @prohibit='$(begword)NULL$(endword)' \
497 in_vc_files='\.[ch]$$' \
498 halt='use nullptr instead' \
499 $(_sc_search_regexp)
501 # Don't use "indent-tabs-mode: nil" anymore. No longer needed.
502 sc_prohibit_emacs__indent_tabs_mode__setting:
503 @prohibit='^( *[*#] *)?indent-tabs-mode:' \
504 halt='use of emacs indent-tabs-mode: setting' \
505 $(_sc_search_regexp)
507 # Ensure that tests don't include a redundant fail=0.
508 sc_prohibit_fail_0:
509 @prohibit='$(begword)fail=0$(endword)' \
510 halt='fail=0 initialization' \
511 $(_sc_search_regexp)
513 # Ensure that tests don't use `cmd ... && fail=1` as that hides crashes.
514 # The "exclude" expression allows common idioms like `test ... && fail=1`
515 # and the 2>... portion allows commands that redirect stderr and so probably
516 # independently check its contents and thus detect any crash messages.
517 sc_prohibit_and_fail_1:
518 @prohibit='&& fail=1' \
519 exclude='(returns_|stat|kill|test |EGREP|grep|compare|2> *[^/])' \
520 halt='&& fail=1 detected. Please use: returns_ 1 ... || fail=1' \
521 in_vc_files='^tests/' \
522 $(_sc_search_regexp)
524 # Ensure that tests don't use `cmd ... || fail` as that's a noop.
525 sc_prohibit_or_fail:
526 @prohibit='\|\| fail$$' \
527 exclude=':#' \
528 halt='|| fail detected. Please use: || fail=1' \
529 in_vc_files='^tests/' \
530 $(_sc_search_regexp)
532 # Ensure that env vars are not passed through returns_ as
533 # that was seen to fail on FreeBSD /bin/sh at least
534 sc_prohibit_env_returns:
535 @prohibit='=[^ ]* returns_ ' \
536 exclude='_ returns_ ' \
537 halt='Passing env vars to returns_ is non portable' \
538 in_vc_files='^tests/' \
539 $(_sc_search_regexp)
541 # The mode part of a setfacl -m option argument must be three bytes long.
542 # I.e., an argument of user:bin:rw or user:bin:r will make Solaris 10's
543 # setfacl reject it with: "Unrecognized character found in mode field".
544 # Use hyphens to give it a length of 3: "...:rw-" or "...:r--".
545 sc_prohibit_short_facl_mode_spec:
546 @prohibit='$(begword)setfacl .*-m.*:.*:[rwx-]{1,2} ' \
547 halt='setfacl mode string length < 3; extend with hyphen(s)' \
548 $(_sc_search_regexp)
550 # Ensure that "stdio--.h" is used where appropriate.
551 sc_require_stdio_safer:
552 @if $(VC_LIST_EXCEPT) | grep -l '\.[ch]$$' > /dev/null; then \
553 files=$$(grep -El '$(begword)freopen ?\(' $$($(VC_LIST_EXCEPT)\
554 | grep '\.[ch]$$')); \
555 test -n "$$files" && grep -LE 'include "stdio--.h"' $$files \
556 | grep . && \
557 { echo '$(ME): the above files should use "stdio--.h"' \
558 1>&2; exit 1; } || :; \
559 else :; \
562 # Ensure that "stdlib--.h" is used where appropriate.
563 sc_require_stdlib_safer:
564 @if $(VC_LIST_EXCEPT) | grep -l '\.[ch]$$' > /dev/null; then \
565 files=$$(grep -El '$(begword)mkstemp ?\(' $$($(VC_LIST_EXCEPT)\
566 | grep '\.[ch]$$')); \
567 test -n "$$files" && grep -LE 'include "stdlib--.h"' $$files \
568 | grep . && \
569 { echo '$(ME): the above files should use "stdlib--.h"' \
570 1>&2; exit 1; } || :; \
571 else :; \
574 sc_prohibit_perl_hash_quotes:
575 @prohibit="\{'[A-Z_]+' *[=}]" \
576 halt="in Perl code, write \$$hash{KEY}, not \$$hash{'K''EY'}" \
577 $(_sc_search_regexp)
579 # Prefer xnanosleep over other less-precise sleep methods
580 sc_prohibit_sleep:
581 @prohibit='$(begword)(nano|u)?sleep \(' \
582 halt='prefer xnanosleep over other sleep interfaces' \
583 $(_sc_search_regexp)
585 # Use print_ver_ (from init.cfg), not open-coded $VERBOSE check.
586 sc_prohibit_verbose_version:
587 @prohibit='test "\$$VERBOSE" = yes && .* --version' \
588 halt='use the print_ver_ function instead...' \
589 $(_sc_search_regexp)
591 # Enforce print_ver_ tracking of dependencies
592 # Each coreutils specific program a test requires
593 # should be tagged by calling through env(1).
594 sc_env_test_dependencies:
595 @cd $(top_srcdir) && GIT_PAGER= git grep -E \
596 "env ($$(build-aux/gen-lists-of-programs.sh --list-progs | \
597 grep -vF '[' |paste -d'|' -s))" tests | \
598 sed "s/\([^:]\):.*env \([^)' ]*\).*/\1 \2/" | uniq | \
599 while read test prog; do \
600 printf '%s' $$test | grep '\.pl$$' >/dev/null && continue; \
601 grep "print_ver_.* $$prog" $$test >/dev/null \
602 || echo $$test should call: print_ver_ $$prog; \
603 done | grep . && exit 1 || :
605 # Use framework_failure_, not the old name without the trailing underscore.
606 sc_prohibit_framework_failure:
607 @prohibit='$(begword)framework_''failure$(endword)' \
608 halt='use framework_failure_ instead' \
609 $(_sc_search_regexp)
611 # Prohibit the use of `...` in tests/. Use $(...) instead.
612 sc_prohibit_test_backticks:
613 @prohibit='`' in_vc_files='^tests/' \
614 halt='use $$(...), not `...` in tests/' \
615 $(_sc_search_regexp)
617 # Ensure that compare is used to check empty files
618 # so that the unexpected contents are displayed
619 sc_prohibit_test_empty:
620 @prohibit='test -s.*&&' in_vc_files='^tests/' \
621 halt='use `compare /dev/null ...`, not `test -s ...` in tests/' \
622 $(_sc_search_regexp)
624 # Programs like sort, ls, expr use PROG_FAILURE in place of EXIT_FAILURE.
625 # Others, use the EXIT_CANCELED, EXIT_ENOENT, etc. macros defined in system.h.
626 # In those programs, ensure that EXIT_FAILURE is not used by mistake.
627 sc_some_programs_must_avoid_exit_failure:
628 @cd $(srcdir) \
629 && grep -nw EXIT_FAILURE \
630 $$(git grep -El '[^T]_FAILURE|EXIT_CANCELED' src/) \
631 | grep -v '^src/system\.h:' \
632 | grep -vE '= EXIT_FAILURE|return .* \?' | grep . \
633 && { echo '$(ME): do not use EXIT_FAILURE in the above' \
634 1>&2; exit 1; } || :
636 # Ensure that tests call the get_min_ulimit_v_ function if using ulimit -v
637 sc_prohibit_test_ulimit_without_require_:
638 @(git -C $(srcdir) grep -l get_min_ulimit_v_ tests; \
639 git -C $(srcdir) grep -l 'ulimit -v' tests) \
640 | sort | uniq -u | grep . && { echo "$(ME): the above test(s)"\
641 " should match get_min_ulimit_v_ with ulimit -v" 1>&2; exit 1; } || :
643 # Ensure that tests call the cleanup_ function if using background processes
644 sc_prohibit_test_background_without_cleanup_:
645 @(git -C $(srcdir) grep -El '( &$$|&[^&]*=\$$!)' tests; \
646 git -C $(srcdir) grep -l 'cleanup_()' tests | sed p) \
647 | sort | uniq -u | grep . && { echo "$(ME): the above test(s)"\
648 " should use cleanup_ for background processes" 1>&2; exit 1; } || :
650 # Ensure that tests call the print_ver_ function for programs which are
651 # actually used in that test.
652 sc_prohibit_test_calls_print_ver_with_irrelevant_argument:
653 @git -C $(srcdir) grep -w print_ver_ tests \
654 | sed 's#:print_ver_##' \
655 | { fail=0; \
656 while read file name; do \
657 for i in $$name; do \
658 case "$$i" in install) i=ginstall;; esac; \
659 grep -w "$$i" $$file|grep -vw print_ver_|grep . >/dev/null \
660 || { fail=1; \
661 echo "*** Test: $$file, offending: $$i." 1>&2; };\
662 done; \
663 done; \
664 test $$fail = 0 || exit 1; \
665 } || { echo "$(ME): the above test(s) call print_ver_ for" \
666 "program(s) they don't use" 1>&2; exit 1; }
668 # Exempt the contents of any usage function from the following.
669 _continued_string_col_1 = \
670 s/^usage .*?\n}//ms;/\\\n\w/ and print ("$$ARGV\n"),$$e=1;END{$$e||=0;exit $$e}
671 # Ding any source file that has a continued string with an alphabetic in the
672 # first column of the following line. We prohibit them because they usually
673 # trigger false positives in tools that try to map an arbitrary line number
674 # to the enclosing function name. Of course, very many strings do precisely
675 # this, *when they are part of the usage function*. That is why we exempt
676 # the contents of any function named "usage".
677 sc_prohibit_continued_string_alpha_in_column_1:
678 @perl -0777 -ne '$(_continued_string_col_1)' \
679 $$($(VC_LIST_EXCEPT) | grep '\.[ch]$$') \
680 || { echo '$(ME): continued string with word in first column' \
681 1>&2; exit 1; } || :
682 # Use this to list offending lines:
683 # git ls-files |grep '\.[ch]$' | xargs \
684 # perl -n -0777 -e 's/^usage.*?\n}//ms;/\\\n\w/ and print "$ARGV\n"' \
685 # | xargs grep -A1 '\\$'|grep '\.[ch][:-][_a-zA-Z]'
688 ###########################################################
689 _p0 = \([^"'/]\|"\([^\"]\|[\].\)*"\|'\([^\']\|[\].\)*'
690 _pre = $(_p0)\|[/][^"'/*]\|[/]"\([^\"]\|[\].\)*"\|[/]'\([^\']\|[\].\)*'\)*
691 _pre_anchored = ^\($(_pre)\)
692 _comment_and_close = [^*]\|[*][^/*]\)*[*][*]*/
693 # help font-lock mode: '
695 # A sed expression that removes ANSI C and ISO C99 comments.
696 # Derived from the one in GNU gettext's 'moopp' preprocessor.
697 _sed_remove_comments = \
698 /[/][/*]/{ \
699 ta; \
700 :a; \
701 s,$(_pre_anchored)//.*,\1,; \
702 te; \
703 s,$(_pre_anchored)/[*]\($(_comment_and_close),\1 ,; \
704 ta; \
705 /^$(_pre)[/][*]/{ \
706 s,$(_pre_anchored)/[*].*,\1 ,; \
707 tu; \
708 :u; \
709 n; \
710 s,^\($(_comment_and_close),,; \
711 tv; \
712 s,^.*$$,,; \
713 bu; \
714 :v; \
715 }; \
716 :e; \
718 # Quote all single quotes.
719 _sed_rm_comments_q = $(subst ','\'',$(_sed_remove_comments))
720 # help font-lock mode: '
722 _space_before_paren_exempt =? \\n\\$$
723 _space_before_paren_exempt = \
724 (^ *\#|\\n\\$$|%s\(to %s|(date|group|character)\(s\))
725 # Ensure that there is a space before each open parenthesis in C code.
726 sc_space_before_open_paren:
727 @if $(VC_LIST_EXCEPT) | grep -l '\.[ch]$$' > /dev/null; then \
728 fail=0; \
729 for c in $$($(VC_LIST_EXCEPT) | grep '\.[ch]$$'); do \
730 sed '$(_sed_rm_comments_q)' $$c 2>/dev/null \
731 | grep -i '[[:alnum:]](' \
732 | grep -vE '$(_space_before_paren_exempt)' \
733 | grep . && { fail=1; echo "*** $$c"; }; \
734 done; \
735 test $$fail = 1 && \
736 { echo '$(ME): the above files lack a space-before-open-paren' \
737 1>&2; exit 1; } || :; \
738 else :; \
741 # Similar to the gnulib maint.mk rule for sc_prohibit_strcmp
742 # Use STREQ_LEN or STRPREFIX rather than comparing strncmp == 0, or != 0.
743 sc_prohibit_strncmp:
744 @prohibit='^[^#].*str''ncmp *\(' \
745 halt='use STREQ_LEN or STRPREFIX instead of str''ncmp' \
746 $(_sc_search_regexp)
748 # Enforce recommended preprocessor indentation style.
749 sc_preprocessor_indentation:
750 @if cppi --version >/dev/null 2>&1; then \
751 $(VC_LIST_EXCEPT) | grep '\.[ch]$$' | xargs cppi -a -c \
752 || { echo '$(ME): incorrect preprocessor indentation' 1>&2; \
753 exit 1; }; \
754 else \
755 echo '$(ME): skipping test $@: cppi not installed' 1>&2; \
758 # THANKS.in is a list of name/email pairs for people who are mentioned in
759 # commit logs (and generated ChangeLog), but who are not also listed as an
760 # author of a commit. Name/email pairs of commit authors are automatically
761 # extracted from the repository. As a very minor factorization, when
762 # someone who was initially listed only in THANKS.in later authors a commit,
763 # this rule detects that their pair may now be removed from THANKS.in.
764 sc_THANKS_in_duplicates:
765 @{ git -C $(srcdir) log --pretty=format:%aN | sort -u; \
766 cut -b-36 $(srcdir)/THANKS.in \
767 | sed '/^$$/,/^$$/!d;/^$$/d;s/ *$$//'; } \
768 | sort | uniq -d | grep . \
769 && { echo '$(ME): remove the above names from THANKS.in' \
770 1>&2; exit 1; } || :
772 # Ensure the contributor list stays sorted. However, if the system's
773 # en_US.UTF-8 locale data is erroneous, give a diagnostic and skip
774 # this test. This affects OS X, up to at least 10.11.6.
775 # Use our sort as other implementations may result in a different order.
776 sc_THANKS_in_sorted:
777 @printf 'a\n.b\n'|LC_ALL=en_US.UTF-8 src/sort -c 2> /dev/null \
778 && { \
779 sed '/^$$/,/^$$/!d;/^$$/d' $(srcdir)/THANKS.in > $@.1 && \
780 LC_ALL=en_US.UTF-8 src/sort -f -k1,1 $@.1 > $@.2 && \
781 diff -u $@.1 $@.2; diff=$$?; \
782 rm -f $@.1 $@.2; \
783 test "$$diff" = 0 \
784 || { echo '$(ME): THANKS.in is unsorted' 1>&2; exit 1; }; \
786 || { echo '$(ME): this system has erroneous locale data;' \
787 'skipping $@' 1>&2; }
789 # Look for developer diagnostics that are marked for translation.
790 # This won't find any for which devmsg's format string is on a separate line.
791 sc_marked_devdiagnostics:
792 @prohibit='$(begword)devmsg *\(.*_\(' \
793 halt='found marked developer diagnostic(s)' \
794 $(_sc_search_regexp)
796 # Ensure we keep hex constants as 4 or 8 bytes for consistency
797 # and so that make src/fs-magic-compare works consistently
798 sc_fs-magic-compare:
799 @sed -n 's|.*/\* \(0x[0-9A-Fa-f]\{1,\}\) .*\*/|\1|p' \
800 $(srcdir)/src/stat.c | grep -Ev '^0x([0-9A-F]{4}){1,2}$$' \
801 && { echo '$(ME): Constants in src/stat.c should be 4 or 8' \
802 'upper-case chars' 1>&2; exit 1; } || :
804 # Ensure gnulib generated files are ignored
805 # TODO: Perhaps augment gnulib-tool to do this in lib/.gitignore?
806 sc_gitignore_missing:
807 @{ sed -n '/^\/lib\/.*\.h$$/{p;p}' $(srcdir)/.gitignore; \
808 find lib -name '*.in*' ! -name '*~' ! -name 'sys_*' | \
809 sed 's|^|/|; s|_\(.*in\.h\)|/\1|; s/\.in//'; } | \
810 sort | uniq -u | grep . && { echo '$(ME): Add above' \
811 'entries to .gitignore' >&2; exit 1; } || :
813 # Flag redundant entries in .gitignore
814 # Disabled for now as too aggressive flagging
815 # entries like /lib/arg-nonnull.h
816 #sc_gitignore_redundant:
817 # @{ grep ^/lib $(srcdir)/.gitignore; \
818 # sed 's|^|/lib|' $(srcdir)/lib/.gitignore; } | \
819 # sort | uniq -d | grep . && { echo '$(ME): Remove above' \
820 # 'entries from .gitignore' >&2; exit 1; } || :
822 sc_prohibit-form-feed:
823 @prohibit=$$'\f' \
824 in_vc_files='\.[chly]$$' \
825 halt='Form Feed (^L) detected' \
826 $(_sc_search_regexp)
828 # Override the default Cc: used in generating an announcement.
829 announcement_Cc_ = $(translation_project_), \
830 coreutils@gnu.org, coreutils-announce@gnu.org
832 -include $(srcdir)/dist-check.mk
834 update-copyright-env = \
835 UPDATE_COPYRIGHT_FORCE=1 \
836 UPDATE_COPYRIGHT_USE_INTERVALS=2 \
837 UPDATE_COPYRIGHT_MAX_LINE_LENGTH=79
839 # List syntax-check exemptions.
840 exclude_file_name_regexp--sc_space_tab = \
841 ^(tests/pr/|tests/misc/nl\.sh$$|gl/.*\.diff$$|man/help2man$$)
842 exclude_file_name_regexp--sc_bindtextdomain = \
843 ^(gl/.*|lib/euidaccess-stat|src/make-prime-list|src/cksum)\.c$$
844 exclude_file_name_regexp--sc_trailing_blank = \
845 ^(tests/pr/|gl/.*\.diff$$|man/help2man)
846 exclude_file_name_regexp--sc_system_h_headers = \
847 ^src/((system|copy|chown-core|find-mount-point)\.h|make-prime-list\.c)$$
849 _src := (false|lbracket|chown-(chgrp|chown)
850 _src := $(_src)|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)|bootstrap
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 # Avoid tight_scope rule stating these should be static
936 # as there is no way to achieve that with the way these are defined.
937 _gl_TS_unmarked_extern_vars += ptr_MD5_.*
938 # Other tight_scope settings
939 _gl_TS_dir = .
940 _gl_TS_obj_files = src/*.$(OBJEXT)