1 # Customize maint.mk -*- makefile -*-
2 # Copyright (C) 2003-2020 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
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.
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
51 old_NEWS_hash
= ad874c61dc38785cb432159b725fc3de
53 # Add an exemption for sc_makefile_at_at_check.
54 _makefile_at_at_check_exceptions
= ' && !/^cu_install_prog/ && !/dynamic-dep/'
56 # Our help-version script is in a slightly different location.
57 _hv_file ?
= $(srcdir)/tests
/misc
/help-version
59 # Ensure that the list of O_ symbols used to compute O_FULLBLOCK is complete.
60 dd
= $(srcdir)/src
/dd.c
63 @
{ echo O_FULLBLOCK
; echo O_NOCACHE
; \
64 perl
-nle
'/^ +\| (O_\w*)$$/ and print $$1' $(dd
); } |
sort > $@
.1
65 @
{ echo O_NOFOLLOW
; perl
-nle
'/{"[a-z]+",\s*(O_\w+)},/ and print $$1' \
66 $(dd
); } |
sort > $@
.2
67 @diff
-u
$@
.1 $@
.2; diff
=$$?
; \
70 ||
{ echo
'$(ME): $(dd) has inconsistent O_ flag lists'>&2; \
73 # Ensure that dd's definition of LONGEST_SYMBOL stays in sync
74 # with the strings from the two affected variables.
75 dd_c
= $(srcdir)/src
/dd.c
77 ifneq ($(wildcard $(dd_c
)),)
78 @len
=$$( (sed
-n
'/conversions\[\] =$$/,/^};/p' $(dd_c
);\
79 sed
-n
'/flags\[\] =$$/,/^};/p' $(dd_c
) ) \
80 |sed
-n
'/"/s/^[^"]*"\([^"]*\)".*/\1/p'| wc
-L
);\
81 max
=$$(sed
-n
'/^#define LONGEST_SYMBOL /s///p' $(dd_c
) \
82 |tr
-d
'"' | wc
-L
); \
83 if
test "$$len" = "$$max"; then
:; else \
84 echo
'dd.c: LONGEST_SYMBOL is not longest' 1>&2; \
89 # Many m4 macros names once began with 'jm_'.
90 # On 2004-04-13, they were all changed to start with gl_ instead.
91 # Make sure that none are inadvertently reintroduced.
93 @grep
-nE
'jm_[A-Z]' \
94 $$($(VC_LIST
) m4 |grep
'\.m4$$'; echo
/dev
/null
) && \
95 { echo
'$(ME): do not use jm_ in m4 macro names' \
98 # Ensure that each root-requiring test is run via the "check-root" rule.
100 @t1
=sc-root.expected
; t2
=sc-root.actual
; \
101 grep
-nl
'^ *require_root_$$' `$(VC_LIST) tests` | \
102 sed
's|.*/tests/|tests/|' |
sort > $$t1; \
103 for t in
$(all_root_tests
); do echo
$$t; done |
sort > $$t2; \
104 st
=0; diff
-u
$$t1 $$t2 || st
=1; \
108 # Ensure that all version-controlled test cases are listed in $(all_tests).
109 sc_tests_list_consistency
:
111 test_extensions_rx
=`echo $(TEST_EXTENSIONS) \
112 | sed -e "s/ /|/g" -e "s/$$bs./$$bs$$bs./g"`; \
114 for t in
$(all_tests
); do echo
$$t; done
; \
116 $(SHELL
) build-aux
/vc-list-files tests \
117 | grep
-Ev
'^tests/(factor/(run|create-test)|init)\.sh$$' \
118 |
$(EGREP
) "$$test_extensions_rx\$$"; \
119 } |
sort | uniq
-u | grep .
&& exit
1; :
121 # Ensure that all version-controlled test scripts are executable.
123 @set
-o noglob
2>/dev
/null || set
-f
; \
125 find_ext
="-name '' "`printf -- "-o -name *%s " $(TEST_EXTENSIONS)`;\
126 find
$(srcdir)/tests
/ \
( $$find_ext \
) \
! -perm
-u
+x
-print \
127 |
{ sed
"s|^$(srcdir)/||"; git ls-files
$(srcdir)/tests
/; } \
129 | sed
-e
"s/^/$(ME): Please make test executable: /" | grep . \
132 # Ensure all gnulib patches apply cleanly
133 sc_ensure_gl_diffs_apply_cleanly
:
134 @find
$(srcdir)/gl
/ -name
'*.diff' | while read p
; do \
135 patch
--fuzz
=0 -f
-s
-d
$(srcdir)/gnulib
/ -p1
--dry-run
< "$$p" >&2 \
136 ||
{ echo
"$$p" >&2; echo
'To refresh all gl patches run:' \
137 'make refresh-gnulib-patches' >&2; exit
1; } \
140 # Avoid :>file which doesn't propagate errors
141 sc_prohibit_colon_redirection
:
142 @cd
$(srcdir)/tests
&& GIT_PAGER
= git grep
-En
': *>.*\|\|' \
143 && { echo
'$(ME): '"The leading colon in :> will hide errors" >&2; \
147 # Ensure emit_mandatory_arg_note() is called if required
148 sc_ensure_emit_mandatory_arg_note
:
149 @cd
$(srcdir)/src
&& GIT_PAGER
= git \
150 grep
-l
-- '^ *-[^-].*--.*[^[]=' *.c \
151 | xargs grep
-L emit_mandatory_arg_note | grep . \
152 && { echo
'$(ME): '"emit_mandatory_arg_note() missing" 1>&2; \
155 # Create a list of regular expressions matching the names
156 # of files included from system.h. Exclude a couple.
158 @sed
-n
'/^# *include /s///p' $(srcdir)/src
/system.h \
159 | grep
-Ev
'sys/(param|file)\.h' \
160 | sed
's/ .*//;;s/^["<]/^# *include [<"]/;s/\.h[">]$$/\\.h[">]/' \
165 Exit
() { set
+e
; (exit
$$1); exit
$$1; }; \
166 for sig in
1 2 3 13 15; do \
167 eval
"trap 'Exit $$(expr $$sig + 128)' $$sig"; \
171 # Files in src/ should not include directly any of
172 # the headers already included via system.h.
173 sc_system_h_headers
: .re-list
174 @if
test -f
$(srcdir)/src
/system.h
; then \
175 trap
'rc=$$?; rm -f .re-list; exit $$rc' 0; \
177 grep
-nE
-f .re-list \
178 $$($(VC_LIST_EXCEPT
) | grep
'^\($(srcdir)/\)\?src/') \
179 && { echo
'$(ME): the above are already included via system.h'\
180 1>&2; exit
1; } ||
:; \
183 # Files in src/ should not use '%s' notation in format strings,
184 # i.e., single quotes around %s (or similar) should be avoided.
185 sc_prohibit_quotes_notation
:
186 @cd
$(srcdir)/src
&& GIT_PAGER
= git grep
-n
"\".*[\`']%s'.*\"" *.c \
187 && { echo
'$(ME): '"Use quote() to avoid quoted '%s' notation" 1>&2; \
191 # Files in src/ should quote all strings in error() output, so that
192 # unexpected input chars like \r etc. don't corrupt the error.
193 # In edge cases this can be avoided by putting the format string
194 # on a separate line to the following arguments.
196 @cd
$(srcdir)/src
&& GIT_PAGER
= git grep
-n
'error *(.*%s.*, [^(]*);$$'\
197 *.c | grep
-v
', q' \
198 && { echo
'$(ME): '"Use quote() for error string arguments" 1>&2; \
202 # Files in src/ should quote all file names in error() output
203 # using quotef(), to provide quoting only when necessary,
204 # but also provide better support for copy and paste when used.
205 sc_error_shell_quotes
:
206 @cd
$(srcdir)/src
&& \
207 { GIT_PAGER
= git grep
-E \
208 'error \(.*%s[:"], .*(name|file)[^"]*\);$$' *.c
; \
209 GIT_PAGER
= git grep
-E \
210 ' quote[ _].*file' *.c
; } \
211 | grep
-Ev
'(quotef|q[^ ]*name)' \
212 && { echo
'$(ME): '"Use quotef() for colon delimited names" 1>&2; \
216 # Files in src/ should quote all file names in error() output
217 # using quoteaf() when the name is separated with spaces,
218 # to distinguish the file name at issue and
219 # to provide better support for copy and paste.
220 sc_error_shell_always_quotes
:
221 @cd
$(srcdir)/src
&& GIT_PAGER
= git grep
-E \
222 'error \(.*[^:] %s[ "].*, .*(name|file)[^"]*\);$$' \
223 *.c | grep
-Ev
'(quoteaf|q[^ ]*name)' \
224 && { echo
'$(ME): '"Use quoteaf() for space delimited names" 1>&2; \
227 @cd
$(srcdir)/src
&& GIT_PAGER
= git grep
-E
-A1 \
228 'error \([^%]*[^:] %s[ "]' *.c | grep
'quotef' \
229 && { echo
'$(ME): '"Use quoteaf() for space delimited names" 1>&2; \
233 # Usage of error() with an exit constant, should instead use die(),
234 # as that avoids warnings and may generate better code, due to being apparent
235 # to the compiler that it doesn't return.
237 @cd
$(srcdir)/src
&& GIT_PAGER
= git grep
-E \
238 'error \(.*_(FAILURE|INVALID)' \
239 && { echo
'$(ME): '"Use die() instead of error" 1>&2; \
243 # Avoid unstyled quoting to internal slots and thus destined for diagnostics
244 # as that can leak unescaped control characters to the output, when using
245 # the default "literal" quoting style.
246 # Instead use quotef(), or quoteaf() or in edge cases quotearg_n_style_colon().
247 # A more general PCRE would be @prohibit='quotearg_.*(?!(style|buffer))'
248 sc_prohibit-quotearg
:
249 @prohibit
='quotearg(_n)?(|_colon|_char|_mem) ' \
250 in_vc_files
='\.c$$' \
251 halt
='Unstyled diagnostic quoting detected' \
255 @prohibit
='\|\| skip ' \
256 halt
='Use skip_ not skip' \
261 'solaris[^[:alnum:]]*2\.(7|8|9|[1-9][0-9])|sunos[^[:alnum:]][6-9]' \
262 $$($(VC_LIST_EXCEPT
)) && \
263 { echo
'$(ME): found misuse of Sun OS version numbers' 1>&2; \
266 # Ensure that the list of programs and author names is accurate.
267 # We need a UTF8 locale. If a lack of locale support or a missing
268 # translation inhibits printing of UTF-8 names, just skip this test.
269 au_dotdot
= authors-dotdot
270 au_actual
= authors-actual
271 sc_check-AUTHORS
: $(all_programs
)
272 @locale
=en_US.UTF-8
; \
273 LC_ALL
=$$locale .
/src
/factor
--version \
274 | grep
' Torbjorn ' > /dev
/null \
275 && { echo
"$@: skipping this check"; exit
0; }; \
276 rm -f
$(au_actual
) $(au_dotdot
); \
277 for i in
`ls $(all_programs) \
278 | sed -e 's,^src/,,' -e 's,$(EXEEXT)$$,,' \
280 | $(ASSORT) -u`; do \
281 test "$$i" = '[' && continue
; \
283 if
test "$$i" = install; then \
285 elif
test "$$i" = test; then \
288 LC_ALL
=$$locale .
/src
/$$exe --version \
289 | perl
-0 -p
-e
's/,\n/, /gm' \
290 | sed
-n
-e
'/Written by /{ s//'"$$i"': /;' \
291 -e
's/,* and /, /; s/\.$$//; p; }'; \
292 done
> $(au_actual
) && \
293 sed
-n
'/^[^ ][^ ]*:/p' $(srcdir)/AUTHORS
> $(au_dotdot
) \
294 && diff
$(au_actual
) $(au_dotdot
) \
295 && rm -f
$(au_actual
) $(au_dotdot
)
297 # Each program with a non-ASCII author name must link with LIBICONV.
298 sc_check-I18N-AUTHORS
:
299 @cd
$(srcdir)/src
&& \
300 for i in
$$(git grep
-l
-w proper_name_utf8
*.c|sed
's/\.c//'); do \
301 grep
-E
"^src_$${i}_LDADD"' .?= .*\$$\(LIBICONV\)' local.mk \
303 ||
{ echo
"$(ME): link rules for $$i do not include" \
304 '$$(LIBICONV)' 1>&2; exit
1; }; \
307 # Disallow the C99 printf size specifiers %z and %j as they're not portable.
308 # The gnulib printf replacement does support them, however the printf
309 # replacement is not currently explicitly depended on by the gnulib error()
310 # module for example. Also we use fprintf() in a few places to output simple
311 # formats but don't use the gnulib module as it is seen as overkill at present.
312 # We'd have to adjust the above gnulib items before disabling this.
313 sc_prohibit-c99-printf-format
:
314 @cd
$(srcdir)/src
&& GIT_PAGER
= git grep
-n
'%[0*]*[jz][udx]' *.c \
315 && { echo
'$(ME): Use PRI*MAX instead of %j or %z' 1>&2; exit
1; } \
318 # Ensure the alternative __attribute (keyword) form isn't used as
319 # that form is not elided where required. Also ensure that we don't
320 # directly use attributes already defined by gnulib.
321 # TODO: move the check for _GL... attributes to gnulib.
322 sc_prohibit-gl-attributes
:
323 @prohibit
='__attribute |__(unused|pure|const)__' \
324 in_vc_files
='\.[ch]$$' \
325 halt
='Use _GL... attribute macros' \
328 # Look for lines longer than 80 characters, except omit:
330 # - the fdl.texi file copied from gnulib,
331 # - the help2man script copied from upstream,
332 # - tests involving long checksum lines, and
333 # - the 'pr' test cases.
334 FILTER_LONG_LINES
= \
335 \|^
[^
:]*NEWS
:.
*https\
{,1\
}://| d
; \
336 \|^
[^
:]*doc
/fdl.texi
:| d
; \
337 \|^
[^
:]*man
/help2man
:| d
; \
338 \|^
[^
:]*tests
/misc
/sha
[0-9]*sum.
*\.pl
[-:]| d
; \
339 \|^
[^
:]*tests
/pr
/|
{ \|^
[^
:]*tests
/pr
/pr-tests
:|
!d
; };
341 @wc
-L
/dev
/null
>/dev
/null
2>/dev
/null \
342 ||
{ echo
"$@: skipping: wc -L not supported"; exit
0; }; \
343 sed
-r
1q
/dev
/null
2>/dev
/null \
344 ||
{ echo
"$@: skipping: sed -r not supported"; exit
0; }; \
345 files
=$$($(VC_LIST_EXCEPT
) | xargs wc
-L | sed
-rn
'/ total$$/d;\
346 s/^ *(8[1-9]|9[0-9]|[0-9]{3,}) //p'); \
347 halt
='line(s) with more than 80 characters; reindent'; \
348 for file in
$$files; do \
349 expand
$$file | grep
-nE
'^.{80}.' | \
350 sed
-e
"s|^|$$file:|" -e
'$(FILTER_LONG_LINES)'; \
351 done | grep .
&& { msg
="$$halt" $(_sc_say_and_exit
) } ||
:
353 # Option descriptions should not start with a capital letter.
354 # One could grep source directly as follows:
355 # grep -E " {2,6}-.*[^.] [A-Z][a-z]" $$($(VC_LIST_EXCEPT) | grep '\.c$$')
356 # but that would miss descriptions not on the same line as the -option.
357 sc_option_desc_uppercase
: $(ALL_MANS
)
358 @grep
'^\\fB\\-' -A1 man
/*.1 | LC_ALL
=C grep
'\.1.[A-Z][a-z]' \
359 && { echo
1>&2 '$@: found initial capitals in --help'; exit
1; } ||
:
361 # Ensure all man/*.[1x] files are present.
362 sc_man_file_correlation
: check-x-vs-1 check-programs-vs-x
364 # Ensure that for each .x file in the 'man/' subdirectory, there is a
365 # corresponding .1 file in the definition of $(EXTRA_MANS).
366 # But since that expansion usually lacks programs like arch and hostname,
367 # add them here manually.
370 @PATH
=.
/src
$(PATH_SEPARATOR
)$$PATH; export PATH
; \
372 (cd
$(srcdir)/man
&& ls
-1 *.x
) \
373 | sed
's/\.x$$//' |
$(ASSORT
) > $$t; \
374 (echo
$(patsubst man
/%,%,$(ALL_MANS
)) \
375 | tr
-s
' ' '\n' | sed
's/\.1$$//') \
376 |
$(ASSORT
) -u | diff
- $$t ||
{ rm $$t; exit
1; }; \
379 # Ensure that non-trivial .x files in the 'man/' subdirectory,
380 # i.e., files exceeding a line count of 20 or a byte count of 1000,
381 # contain a Copyright notice.
382 .PHONY
: sc_man_check_x_copyright
383 sc_man_check_x_copyright
:
385 cd
$(srcdir) && wc
-cl man
/*.x | head
-n-1 \
386 | awk
'$$1 >= 20 || $$2 >= 1000 {print $$3}' \
387 | xargs grep
-L
'Copyright .* Free Software Foundation' \
389 && { echo
1>&2 '$@: exceeding file size/line count limit' \
390 '- please add a copyright note'; status
=1; }; \
393 # Writing a portable rule to generate a manpage like '[.1' would be
394 # a nightmare, so filter that out.
395 all-progs-but-lbracket
= $(filter-out [,$(patsubst src
/%,%,$(all_programs
)))
397 # Ensure that for each coreutils program there is a corresponding
398 # '.x' file in the 'man/' subdirectory.
399 .PHONY
: check-programs-vs-x
402 for p in dummy
$(all-progs-but-lbracket
); do \
403 case
$$p in
*.so
) continue
;; esac
; \
404 test $$p = dummy
&& continue
; \
405 test $$p = ginstall
&& p
=install ||
: ; \
406 test -f
$(srcdir)/man
/$$p.x \
407 ||
{ echo missing
$$p.x
1>&2; status
=1; }; \
411 # Ensure we can check out on case insensitive file systems
412 sc_case_insensitive_file_names
: src
/uniq
413 @git
-C
$(srcdir) ls-files |
sort -f | src
/uniq
-Di | grep .
&& \
414 { echo
"$(ME): the above file(s) conflict on case insensitive" \
415 " file systems" 1>&2; exit
1; } ||
:
417 # Ensure that the end of each release's section is marked by two empty lines.
418 sc_NEWS_two_empty_lines
:
419 @sed
-n
4,/Noteworthy
/p
$(srcdir)/NEWS \
420 | perl
-n0e
'/(^|\n)\n\n\* Noteworthy/ or exit 1' \
421 ||
{ echo
'$(ME): use two empty lines to separate NEWS sections' \
424 # With split lines, don't leave an operator at end of line.
425 # Instead, put it on the following line, where it is more apparent.
426 # Don't bother checking for "*" at end of line, since it provokes
427 # far too many false positives, matching constructs like "TYPE *".
428 # Similarly, omit "=" (initializers).
429 binop_re_ ?
= [-/+^
!<>]|
[-/+*^
!<>=]=|
&&?|\|\|?|
<<=?|
>>=?
430 sc_prohibit_operator_at_end_of_line
:
431 @prohibit
='. ($(binop_re_))$$' \
432 in_vc_files
='\.[chly]$$' \
433 halt
='found operator at end of line' \
436 # Don't use "readlink" or "readlinkat" directly
437 sc_prohibit_readlink
:
438 @prohibit
='\<readlink(at)? \(' \
439 halt
='do not use readlink(at); use via xreadlink or areadlink*' \
442 # Don't use address of "stat" or "lstat" functions
443 sc_prohibit_stat_macro_address
:
444 @prohibit
='\<l?stat '':|&l?stat\>' \
445 halt
='stat() and lstat() may be function-like macros' \
448 # Ensure that date's --help output stays in sync with the info
449 # documentation for GNU strftime. The only exception is %N and %q,
450 # which date accepts but GNU strftime does not.
452 # "info foo" fails with error, but not "info foo >/dev/null".
453 extract_char
= sed
's/^[^%][^%]*%\(.\).*/\1/'
455 @if
test -f
$(srcdir)/src
/date.c
; then \
456 if
info libc date calendar format
2>/dev
/null | \
457 grep
"^ *['\`]%.'$$" >$@
-tmp
; then \
458 { echo N
; echo q
; $(extract_char
) $@
-tmp
; }|
sort \
460 grep
'^ %. ' $(srcdir)/src
/date.c |
sort \
461 |
$(extract_char
) > $@
-src
; \
462 diff
-u
$@
-src
$@
-info || exit
1; \
464 echo
'$(ME): skipping $@: libc info not installed' 1>&2; \
466 rm -f
$@
-info $@
-src
$@
-tmp
; \
469 # Indent only with spaces.
470 sc_prohibit_tab_based_indentation
:
472 halt
='TAB in indentation; use only spaces' \
475 # Enforce lowercase 'e' in "I.e.".
476 sc_prohibit_uppercase_id_est
:
478 halt
='Uppercase "Id Est" abbreviation; use "I.e.," instead' \
481 # Enforce double-space before "I.e." at the beginning of a sentence.
482 sc_ensure_dblspace_after_dot_before_id_est
:
483 @prohibit
='\. I\.e\.' \
484 halt
='Single space after dot before "i.e."; use ". i.e." instead' \
487 # Enforce comma after "i.e." (at least before a blank or at EOL).
488 sc_ensure_comma_after_id_est
:
489 @prohibit
='[Ii]\.e\.( |$$)' \
490 halt
='Missing comma after "i.e."; use "i.e.," instead' \
493 # The SEE ALSO section of a man page should not be terminated with
494 # a period. Check the first line after each "SEE ALSO" line in man/*.x:
495 sc_prohibit_man_see_also_period
:
496 @grep
-nB1
'\.$$' $$($(VC_LIST_EXCEPT
) | grep
'man/.*\.x$$') \
497 | grep
-A1
-e
'-\[SEE ALSO\]' | grep
'\.$$' && \
498 { echo
'$(ME): do not end "SEE ALSO" section with a period' \
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' \
507 # Ensure that tests don't include a redundant fail=0.
509 @prohibit
='\<fail=0\>' \
510 halt
='fail=0 initialization' \
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/' \
524 # Ensure that tests don't use `cmd ... || fail` as that's a noop.
526 @prohibit
='\|\| fail$$' \
528 halt
='|| fail detected. Please use: || fail=1' \
529 in_vc_files
='^tests/' \
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/' \
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
='\<setfacl .*-m.*:.*:[rwx-]{1,2} ' \
547 halt
='setfacl mode string length < 3; extend with hyphen(s)' \
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
-l
'\bfreopen \?(' $$($(VC_LIST_EXCEPT
) \
554 | grep
'\.[ch]$$')); \
555 test -n
"$$files" && grep
-LE
'include "stdio--.h"' $$files \
557 { echo
'$(ME): the above files should use "stdio--.h"' \
558 1>&2; exit
1; } ||
:; \
562 sc_prohibit_perl_hash_quotes
:
563 @prohibit
="\{'[A-Z_]+' *[=}]" \
564 halt
="in Perl code, write \$$hash{KEY}, not \$$hash{'K''EY'}" \
567 # Prefer xnanosleep over other less-precise sleep methods
569 @prohibit
='\<(nano|u)?sleep \(' \
570 halt
='prefer xnanosleep over other sleep interfaces' \
573 # Use print_ver_ (from init.cfg), not open-coded $VERBOSE check.
574 sc_prohibit_verbose_version
:
575 @prohibit
='test "\$$VERBOSE" = yes && .* --version' \
576 halt
='use the print_ver_ function instead...' \
579 # Enforce print_ver_ tracking of dependencies
580 # Each coreutils specific program a test requires
581 # should be tagged by calling through env(1).
582 sc_env_test_dependencies
:
583 @cd
$(top_srcdir
) && GIT_PAGER
= git grep
-E \
584 "env ($$(build-aux/gen-lists-of-programs.sh --list-progs | \
585 grep -vF '[' |paste -d'|' -s))" tests | \
586 sed
"s/\([^:]\):.*env \([^)' ]*\).*/\1 \2/" | uniq | \
587 while read
test prog
; do \
588 printf
'%s' $$test | grep
-q
'\.pl$$' && continue
; \
589 grep
-q
"print_ver_.* $$prog" $$test \
590 || echo
$$test should call
: print_ver_
$$prog; \
591 done | grep .
&& exit
1 ||
:
593 # Use framework_failure_, not the old name without the trailing underscore.
594 sc_prohibit_framework_failure
:
595 @prohibit
='\<framework_''failure\>' \
596 halt
='use framework_failure_ instead' \
599 # Prohibit the use of `...` in tests/. Use $(...) instead.
600 sc_prohibit_test_backticks
:
601 @prohibit
='`' in_vc_files
='^tests/' \
602 halt
='use $$(...), not `...` in tests/' \
605 # Ensure that compare is used to check empty files
606 # so that the unexpected contents are displayed
607 sc_prohibit_test_empty
:
608 @prohibit
='test -s.*&&' in_vc_files
='^tests/' \
609 halt
='use `compare /dev/null ...`, not `test -s ...` in tests/' \
612 # Ensure that expr doesn't work directly on various unsigned int types,
613 # as that's not generally supported without GMP.
614 sc_prohibit_expr_unsigned
:
615 @prohibit
='expr .*(UINT|ULONG|[^S]SIZE|[UGP]ID|UINTMAX)' \
616 halt
='avoid passing unsigned limits to `expr` (without GMP)' \
617 in_vc_files
='^tests/' \
620 # Programs like sort, ls, expr use PROG_FAILURE in place of EXIT_FAILURE.
621 # Others, use the EXIT_CANCELED, EXIT_ENOENT, etc. macros defined in system.h.
622 # In those programs, ensure that EXIT_FAILURE is not used by mistake.
623 sc_some_programs_must_avoid_exit_failure
:
625 && grep
-nw EXIT_FAILURE \
626 $$(git grep
-El
'[^T]_FAILURE|EXIT_CANCELED' $(srcdir)/src
) \
627 | grep
-vE
'= EXIT_FAILURE|return .* \?' | grep . \
628 && { echo
'$(ME): do not use EXIT_FAILURE in the above' \
631 # Ensure that tests call the get_min_ulimit_v_ function if using ulimit -v
632 sc_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; } ||
:
638 # Ensure that tests call the cleanup_ function if using background processes
639 sc_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; } ||
:
645 # Ensure that tests call the print_ver_ function for programs which are
646 # actually used in that test.
647 sc_prohibit_test_calls_print_ver_with_irrelevant_argument
:
648 @git
-C
$(srcdir) grep
-w print_ver_ tests \
649 | sed
's#:print_ver_##' \
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
-q . \
656 echo
"*** Test: $$file, offending: $$i." 1>&2; };\
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; }
663 # Exempt the contents of any usage function from the following.
664 _continued_string_col_1
= \
665 s
/^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".
672 sc_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' \
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]'
683 ###########################################################
684 _p0
= \
([^
"'/]\|"\
([^
\"]\|
[\
].\
)*"\|'\([^\']\|[\].\)*'
685 _pre = $(_p0)\|[/][^"'/*]\|[/]"\([^\"]\|[\].\)*"\|[/]'\
([^
\']\|
[\
].\
)*'\)*
686 _pre_anchored = ^\($(_pre)\)
687 _comment_and_close = [^*]\|[*][^/*]\)*[*][*]*/
688 # help font-lock mode: '
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
= \
696 s
,$(_pre_anchored
)//.
*,\
1,; \
698 s
,$(_pre_anchored
)/[*]\
($(_comment_and_close
),\
1 ,; \
701 s
,$(_pre_anchored
)/[*].
*,\
1 ,; \
705 s
,^\
($(_comment_and_close
),,; \
713 # Quote all single quotes.
714 _sed_rm_comments_q
= $(subst ','\'',$(_sed_remove_comments))
715 # help font-lock mode: '
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.
721 sc_space_before_open_paren
:
722 @if
$(VC_LIST_EXCEPT
) | grep
-l
'\.[ch]$$' > /dev
/null
; then \
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"; }; \
731 { echo
'$(ME): the above files lack a space-before-open-paren' \
732 1>&2; exit
1; } ||
:; \
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.
739 @prohibit
='^[^#].*str''ncmp *\(' \
740 halt
='use STREQ_LEN or STRPREFIX instead of str''ncmp' \
743 # Enforce recommended preprocessor indentation style.
744 sc_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; \
750 echo
'$(ME): skipping test $@: cppi not installed' 1>&2; \
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.
759 sc_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' \
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.
772 @printf
'a\n.b\n'|LC_ALL
=en_US.UTF-8 src
/sort -c
2> /dev
/null \
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
=$$?
; \
779 ||
{ echo
'$(ME): THANKS.in is unsorted' 1>&2; exit
1; }; \
781 ||
{ echo
'$(ME): this system has erroneous locale data;' \
782 'skipping $@' 1>&2; }
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.
786 sc_marked_devdiagnostics
:
787 @prohibit
='\<devmsg *\(.*_\(' \
788 halt
='found marked developer diagnostic(s)' \
791 # Ensure we keep hex constants as 4 or 8 bytes for consistency
792 # and so that make src/fs-magic-compare works consistently
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; } ||
:
799 # Ensure gnulib generated files are ignored
800 # TODO: Perhaps augment gnulib-tool to do this in lib/.gitignore?
801 sc_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; } ||
:
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; } || :
817 sc_prohibit-form-feed
:
819 in_vc_files
='\.[chly]$$' \
820 halt
='Form Feed (^L) detected' \
823 # Override the default Cc: used in generating an announcement.
824 announcement_Cc_
= $(translation_project_
), \
825 coreutils@gnu.org
, coreutils-announce@gnu.org
827 -include $(srcdir)/dist-check.mk
829 update-copyright-env
= \
830 UPDATE_COPYRIGHT_FORCE
=1 \
831 UPDATE_COPYRIGHT_USE_INTERVALS
=2 \
832 UPDATE_COPYRIGHT_MAX_LINE_LENGTH
=79
834 # List syntax-check exemptions.
835 exclude_file_name_regexp--sc_space_tab
= \
836 ^
(tests
/pr
/|tests
/misc
/nl\.sh
$$|gl
/.
*\.diff
$$|man
/help2man
$$)
837 exclude_file_name_regexp--sc_bindtextdomain
= \
838 ^
(gl
/.
*|lib
/euidaccess-stat|src
/make-prime-list
)\.c
$$
839 exclude_file_name_regexp--sc_trailing_blank
= \
840 ^
(tests
/pr
/|gl
/.
*\.diff
$$|man
/help2man
)
841 exclude_file_name_regexp--sc_system_h_headers
= \
842 ^src
/((die|system|copy
)\.h|make-prime-list\.c
)$$
844 _src
= (false|lbracket|ls-
(dir|ls|vdir
)|tac-pipe|uname-
(arch|uname
))
845 _gl_src
= (xdecto.max|cl-strtold
)
846 exclude_file_name_regexp--sc_require_config_h_first
= \
847 (^lib
/buffer-lcm\.c|gl
/lib
/$(_gl_src
)\.c|src
/$(_src
)\.c
)$$
848 exclude_file_name_regexp--sc_require_config_h
= \
849 $(exclude_file_name_regexp--sc_require_config_h_first
)
851 exclude_file_name_regexp--sc_po_check
= ^
(gl
/|man
/help2man
)
852 exclude_file_name_regexp--sc_prohibit_always-defined_macros
= \
853 ^src
/(seq|remove
)\.c
$$
854 exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF
= ^tests
/pr
/
855 exclude_file_name_regexp--sc_program_name
= \
856 ^
(gl
/.
*|lib
/euidaccess-stat|src
/make-prime-list
)\.c
$$
857 exclude_file_name_regexp--sc_file_system
= \
858 NEWS|^
(init\.cfg|src
/df\.c|tests
/df
/df-P\.sh|tests
/df
/df-output\.sh
)$$
859 exclude_file_name_regexp--sc_prohibit_always_true_header_tests
= \
861 exclude_file_name_regexp--sc_prohibit_fail_0
= \
862 (^.
*/git-hooks
/commit-msg|^tests
/init\.sh|Makefile\.am|\.mk|.
*\.texi
)$$
863 exclude_file_name_regexp--sc_prohibit_test_minus_ao
= *\.texi
$$
864 exclude_file_name_regexp--sc_prohibit_atoi_atof
= ^lib
/euidaccess-stat\.c
$$
866 # longlong.h is maintained elsewhere.
867 _ll
= ^src
/longlong\.h
$$
868 exclude_file_name_regexp--sc_useless_cpp_parens
= $(_ll
)
869 exclude_file_name_regexp--sc_space_before_open_paren
= $(_ll
)
871 tbi_1
= ^tests
/pr
/|
(\.mk|^man
/help2man
)$$
872 tbi_2
= ^scripts
/git-hooks
/(pre-commit|pre-applypatch|applypatch-msg
)$$
873 tbi_3
= (GNU
)?
[Mm
]akefile
(\.am
)?
$$|
$(_ll
)
874 exclude_file_name_regexp--sc_prohibit_tab_based_indentation
= \
875 $(tbi_1
)|
$(tbi_2
)|
$(tbi_3
)
877 exclude_file_name_regexp--sc_preprocessor_indentation
= \
878 ^
(gl
/lib
/rand-isaac\.
[ch
]|gl
/tests
/test-rand-isaac\.c
)$$|
$(_ll
)
879 exclude_file_name_regexp--sc_prohibit_stat_st_blocks
= \
880 ^
(src
/system\.h|tests
/du
/2g\.sh
)$$
882 exclude_file_name_regexp--sc_prohibit_continued_string_alpha_in_column_1
= \
883 ^src
/(system\.h|od\.c|printf\.c|getlimits\.c
)$$
885 exclude_file_name_regexp--sc_prohibit_test_backticks
= \
886 ^tests
/(local\.mk|
(init|misc
/stdbuf|factor
/create-test
)\.sh
)$$
888 # Exempt test.c, since it's nominally shared, and relatively static.
889 exclude_file_name_regexp--sc_prohibit_operator_at_end_of_line
= \
890 ^src
/(ptx|
test|head
)\.c
$$
892 exclude_file_name_regexp--sc_error_message_uppercase
= ^src
/factor\.c
$$
893 exclude_file_name_regexp--sc_prohibit_atoi_atof
= ^src
/make-prime-list\.c
$$
895 # Exception here as we don't want __attribute elided on non GCC
896 exclude_file_name_regexp--sc_prohibit-gl-attributes
= ^src
/libstdbuf\.c
$$
898 exclude_file_name_regexp--sc_prohibit_uppercase_id_est
= \.diff
$$
899 exclude_file_name_regexp--sc_ensure_dblspace_after_dot_before_id_est
= \.diff
$$
900 exclude_file_name_regexp--sc_ensure_comma_after_id_est
= \.diff|
$(_ll
)$$
901 exclude_file_name_regexp--sc_long_lines
= \.diff
$$|
$(_ll
)
903 # Augment AM_CFLAGS to include our per-directory options:
904 AM_CFLAGS
+= $($(@D
)_CFLAGS
)
906 src_CFLAGS
= $(WARN_CFLAGS
)
907 lib_CFLAGS
= $(GNULIB_WARN_CFLAGS
)
908 gnulib-tests_CFLAGS
= $(GNULIB_TEST_WARN_CFLAGS
)
910 # Configuration to make the tight-scope syntax-check rule work with
911 # non-recursive make.
912 # Note _gl_TS_headers use _single line_ extern function declarations,
913 # while *_SOURCES use the _two line_ form.
914 export _gl_TS_headers
= $(noinst_HEADERS
)
915 # Add exceptions for --enable-single-binary renamed functions.
916 _gl_TS_unmarked_extern_functions
= main usage
917 _gl_TS_unmarked_extern_functions
+= single_binary_main_.
* _usage_.
*
918 # Headers to search for single line extern _data_ declarations.
919 _gl_TS_other_headers
= $(srcdir)/src
/*.h src
/*.h
920 # Tell the tight_scope rule about an exceptional "extern" variable.
921 # Normally, the rule would detect its declaration, but that uses a
922 # different name, __clz_tab.
923 _gl_TS_unmarked_extern_vars
= factor_clz_tab
924 # Other tight_scope settings
926 _gl_TS_obj_files
= src
/*.
$(OBJEXT
)