build: ensure sys/select.h is included
[coreutils.git] / cfg.mk
blob1aa1b265ce1600118c90a53c1c3ccc390460cd33
1 # Customize maint.mk -*- makefile -*-
2 # Copyright (C) 2003-2019 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.
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 = 79133b52351baf64693804eed58a0cbc
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
61 sc_dd_O_FLAGS:
62 @rm -f $@.1 $@.2
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=$$?; \
68 rm -f $@.1 $@.2; \
69 test "$$diff" = 0 \
70 || { echo '$(ME): $(dd) has inconsistent O_ flag lists'>&2; \
71 exit 1; }
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
76 sc_dd_max_sym_length:
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; \
85 exit 1; \
87 endif
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.
92 sc_prohibit_jm_in_m4:
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' \
96 1>&2; exit 1; } || :
98 # Ensure that each root-requiring test is run via the "check-root" rule.
99 sc_root_tests:
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; \
105 rm -f $$t1 $$t2; \
106 exit $$st
108 # Ensure that all version-controlled test cases are listed in $(all_tests).
109 sc_tests_list_consistency:
110 @bs="\\"; \
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; \
115 cd $(top_srcdir); \
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.
122 sc_tests_executable:
123 @set -o noglob 2>/dev/null || set -f; \
124 find_ext="-name '' "`printf -- "-o -name *%s " $(TEST_EXTENSIONS)`;\
125 find $(srcdir)/tests/ \( $$find_ext \) \! -perm -u+x -print \
126 | { sed "s|^$(srcdir)/||"; git ls-files $(srcdir)/tests/; } \
127 | sort | uniq -d \
128 | sed -e "s/^/$(ME): Please make test executable: /" | grep . \
129 && exit 1; :
131 # Ensure all gnulib patches apply cleanly
132 sc_ensure_gl_diffs_apply_cleanly:
133 @find $(srcdir)/gl/ -name '*.diff' | while read p; do \
134 patch --fuzz=0 -f -s -d $(srcdir)/gnulib/ -p1 --dry-run < "$$p" >&2 \
135 || { echo "$$p" >&2; echo 'To refresh all gl patches run:' \
136 'make refresh-gnulib-patches' >&2; exit 1; } \
137 done
139 # Avoid :>file which doesn't propagate errors
140 sc_prohibit_colon_redirection:
141 @cd $(srcdir)/tests && GIT_PAGER= git grep -n ': *>.*||' \
142 && { echo '$(ME): '"The leading colon in :> will hide errors" 1>&2; \
143 exit 1; } \
144 || :
146 # Ensure emit_mandatory_arg_note() is called if required
147 sc_ensure_emit_mandatory_arg_note:
148 @cd $(srcdir)/src && GIT_PAGER= git \
149 grep -l -- '^ *-[^-].*--.*[^[]=' *.c \
150 | xargs grep -L emit_mandatory_arg_note | grep . \
151 && { echo '$(ME): '"emit_mandatory_arg_note() missing" 1>&2; \
152 exit 1; } || :
154 # Create a list of regular expressions matching the names
155 # of files included from system.h. Exclude a couple.
156 .re-list:
157 @sed -n '/^# *include /s///p' $(srcdir)/src/system.h \
158 | grep -Ev 'sys/(param|file)\.h' \
159 | sed 's/ .*//;;s/^["<]/^# *include [<"]/;s/\.h[">]$$/\\.h[">]/' \
160 > $@-t
161 @mv $@-t $@
163 define gl_trap_
164 Exit () { set +e; (exit $$1); exit $$1; }; \
165 for sig in 1 2 3 13 15; do \
166 eval "trap 'Exit $$(expr $$sig + 128)' $$sig"; \
167 done
168 endef
170 # Files in src/ should not include directly any of
171 # the headers already included via system.h.
172 sc_system_h_headers: .re-list
173 @if test -f $(srcdir)/src/system.h; then \
174 trap 'rc=$$?; rm -f .re-list; exit $$rc' 0; \
175 $(gl_trap_); \
176 grep -nE -f .re-list \
177 $$($(VC_LIST_EXCEPT) | grep '^\($(srcdir)/\)\?src/') \
178 && { echo '$(ME): the above are already included via system.h'\
179 1>&2; exit 1; } || :; \
182 # Files in src/ should not use '%s' notation in format strings,
183 # i.e., single quotes around %s (or similar) should be avoided.
184 sc_prohibit_quotes_notation:
185 @cd $(srcdir)/src && GIT_PAGER= git grep -n "\".*[\`']%s'.*\"" *.c \
186 && { echo '$(ME): '"Use quote() to avoid quoted '%s' notation" 1>&2; \
187 exit 1; } \
188 || :
190 # Files in src/ should quote all strings in error() output, so that
191 # unexpected input chars like \r etc. don't corrupt the error.
192 # In edge cases this can be avoided by putting the format string
193 # on a separate line to the following arguments.
194 sc_error_quotes:
195 @cd $(srcdir)/src && GIT_PAGER= git grep -n 'error *(.*%s.*, [^(]*);$$'\
196 *.c | grep -v ', q' \
197 && { echo '$(ME): '"Use quote() for error string arguments" 1>&2; \
198 exit 1; } \
199 || :
201 # Files in src/ should quote all file names in error() output
202 # using quotef(), to provide quoting only when necessary,
203 # but also provide better support for copy and paste when used.
204 sc_error_shell_quotes:
205 @cd $(srcdir)/src && \
206 { GIT_PAGER= git grep -E \
207 'error \(.*%s[:"], .*(name|file)[^"]*\);$$' *.c; \
208 GIT_PAGER= git grep -E \
209 ' quote[ _].*file' *.c; } \
210 | grep -Ev '(quotef|q[^ ]*name)' \
211 && { echo '$(ME): '"Use quotef() for colon delimited names" 1>&2; \
212 exit 1; } \
213 || :
215 # Files in src/ should quote all file names in error() output
216 # using quoteaf() when the name is separated with spaces,
217 # to distinguish the file name at issue and
218 # to provide better support for copy and paste.
219 sc_error_shell_always_quotes:
220 @cd $(srcdir)/src && GIT_PAGER= git grep -E \
221 'error \(.*[^:] %s[ "].*, .*(name|file)[^"]*\);$$' \
222 *.c | grep -Ev '(quoteaf|q[^ ]*name)' \
223 && { echo '$(ME): '"Use quoteaf() for space delimited names" 1>&2; \
224 exit 1; } \
225 || :
226 @cd $(srcdir)/src && GIT_PAGER= git grep -E -A1 \
227 'error \([^%]*[^:] %s[ "]' *.c | grep 'quotef' \
228 && { echo '$(ME): '"Use quoteaf() for space delimited names" 1>&2; \
229 exit 1; } \
230 || :
232 # Usage of error() with an exit constant, should instead use die(),
233 # as that avoids warnings and may generate better code, due to being apparent
234 # to the compiler that it doesn't return.
235 sc_die_EXIT_FAILURE:
236 @cd $(srcdir)/src && GIT_PAGER= git grep -E \
237 'error \(.*_(FAILURE|INVALID)' \
238 && { echo '$(ME): '"Use die() instead of error" 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 # Each program with a non-ASCII author name must link with LIBICONV.
297 sc_check-I18N-AUTHORS:
298 @cd $(srcdir)/src && \
299 for i in $$(git grep -l -w proper_name_utf8 *.c|sed 's/\.c//'); do \
300 grep -E "^src_$${i}_LDADD"' .?= .*\$$\(LIBICONV\)' local.mk \
301 > /dev/null \
302 || { echo "$(ME): link rules for $$i do not include" \
303 '$$(LIBICONV)' 1>&2; exit 1; }; \
304 done
306 # Disallow the C99 printf size specifiers %z and %j as they're not portable.
307 # The gnulib printf replacement does support them, however the printf
308 # replacement is not currently explicitly depended on by the gnulib error()
309 # module for example. Also we use fprintf() in a few places to output simple
310 # formats but don't use the gnulib module as it is seen as overkill at present.
311 # We'd have to adjust the above gnulib items before disabling this.
312 sc_prohibit-c99-printf-format:
313 @cd $(srcdir)/src && GIT_PAGER= git grep -n '%[0*]*[jz][udx]' *.c \
314 && { echo '$(ME): Use PRI*MAX instead of %j or %z' 1>&2; exit 1; } \
315 || :
317 # Ensure the alternative __attribute (keyword) form isn't used as
318 # that form is not elided where required. Also ensure that we don't
319 # directly use attributes already defined by gnulib.
320 # TODO: move the check for _GL... attributes to gnulib.
321 sc_prohibit-gl-attributes:
322 @prohibit='__attribute |__(unused|pure|const)__' \
323 in_vc_files='\.[ch]$$' \
324 halt='Use _GL... attribute macros' \
325 $(_sc_search_regexp)
327 # Look for lines longer than 80 characters, except omit:
328 # - urls
329 # - the help2man script copied from upstream,
330 # - tests involving long checksum lines, and
331 # - the 'pr' test cases.
332 FILTER_LONG_LINES = \
333 \|^[^:]*NEWS:.*https\{,1\}://| d; \
334 \|^[^:]*man/help2man:| d; \
335 \|^[^:]*tests/misc/sha[0-9]*sum.*\.pl[-:]| d; \
336 \|^[^:]*tests/pr/|{ \|^[^:]*tests/pr/pr-tests:| !d; };
337 sc_long_lines:
338 @wc -L /dev/null >/dev/null 2>/dev/null \
339 || { echo "$@: skipping: wc -L not supported"; exit 0; }; \
340 sed -r 1q /dev/null 2>/dev/null \
341 || { echo "$@: skipping: sed -r not supported"; exit 0; }; \
342 files=$$($(VC_LIST_EXCEPT) | xargs wc -L | sed -rn '/ total$$/d;\
343 s/^ *(8[1-9]|9[0-9]|[0-9]{3,}) //p'); \
344 halt='line(s) with more than 80 characters; reindent'; \
345 for file in $$files; do \
346 expand $$file | grep -nE '^.{80}.' | \
347 sed -e "s|^|$$file:|" -e '$(FILTER_LONG_LINES)'; \
348 done | grep . && { msg="$$halt" $(_sc_say_and_exit) } || :
350 # Option descriptions should not start with a capital letter.
351 # One could grep source directly as follows:
352 # grep -E " {2,6}-.*[^.] [A-Z][a-z]" $$($(VC_LIST_EXCEPT) | grep '\.c$$')
353 # but that would miss descriptions not on the same line as the -option.
354 sc_option_desc_uppercase: $(ALL_MANS)
355 @grep '^\\fB\\-' -A1 man/*.1 | LC_ALL=C grep '\.1.[A-Z][a-z]' \
356 && { echo 1>&2 '$@: found initial capitals in --help'; exit 1; } || :
358 # Ensure all man/*.[1x] files are present.
359 sc_man_file_correlation: check-x-vs-1 check-programs-vs-x
361 # Ensure that for each .x file in the 'man/' subdirectory, there is a
362 # corresponding .1 file in the definition of $(EXTRA_MANS).
363 # But since that expansion usually lacks programs like arch and hostname,
364 # add them here manually.
365 .PHONY: check-x-vs-1
366 check-x-vs-1:
367 @PATH=./src$(PATH_SEPARATOR)$$PATH; export PATH; \
368 t=$@-t; \
369 (cd $(srcdir)/man && ls -1 *.x) \
370 | sed 's/\.x$$//' | $(ASSORT) > $$t; \
371 (echo $(patsubst man/%,%,$(ALL_MANS)) \
372 | tr -s ' ' '\n' | sed 's/\.1$$//') \
373 | $(ASSORT) -u | diff - $$t || { rm $$t; exit 1; }; \
374 rm $$t
376 # Ensure that non-trivial .x files in the 'man/' subdirectory,
377 # i.e., files exceeding a line count of 20 or a byte count of 1000,
378 # contain a Copyright notice.
379 .PHONY: sc_man_check_x_copyright
380 sc_man_check_x_copyright:
381 @status=0; \
382 cd $(srcdir) && wc -cl man/*.x | head -n-1 \
383 | awk '$$1 >= 20 || $$2 >= 1000 {print $$3}' \
384 | xargs grep -L 'Copyright .* Free Software Foundation' \
385 | grep . \
386 && { echo 1>&2 '$@: exceeding file size/line count limit' \
387 '- please add a copyright note'; status=1; }; \
388 exit $$status
390 # Writing a portable rule to generate a manpage like '[.1' would be
391 # a nightmare, so filter that out.
392 all-progs-but-lbracket = $(filter-out [,$(patsubst src/%,%,$(all_programs)))
394 # Ensure that for each coreutils program there is a corresponding
395 # '.x' file in the 'man/' subdirectory.
396 .PHONY: check-programs-vs-x
397 check-programs-vs-x:
398 @status=0; \
399 for p in dummy $(all-progs-but-lbracket); do \
400 case $$p in *.so) continue;; esac; \
401 test $$p = dummy && continue; \
402 test $$p = ginstall && p=install || : ; \
403 test -f $(srcdir)/man/$$p.x \
404 || { echo missing $$p.x 1>&2; status=1; }; \
405 done; \
406 exit $$status
408 # Ensure we can check out on case insensitive file systems
409 sc_case_insensitive_file_names: src/uniq
410 @git ls-files | sort -f | src/uniq -Di | grep . && \
411 { echo "$(ME): the above file(s) conflict on case insensitive" \
412 " file systems" 1>&2; exit 1; } || :
414 # Ensure that the end of each release's section is marked by two empty lines.
415 sc_NEWS_two_empty_lines:
416 @sed -n 4,/Noteworthy/p $(srcdir)/NEWS \
417 | perl -n0e '/(^|\n)\n\n\* Noteworthy/ or exit 1' \
418 || { echo '$(ME): use two empty lines to separate NEWS sections' \
419 1>&2; exit 1; } || :
421 # With split lines, don't leave an operator at end of line.
422 # Instead, put it on the following line, where it is more apparent.
423 # Don't bother checking for "*" at end of line, since it provokes
424 # far too many false positives, matching constructs like "TYPE *".
425 # Similarly, omit "=" (initializers).
426 binop_re_ ?= [-/+^!<>]|[-/+*^!<>=]=|&&?|\|\|?|<<=?|>>=?
427 sc_prohibit_operator_at_end_of_line:
428 @prohibit='. ($(binop_re_))$$' \
429 in_vc_files='\.[chly]$$' \
430 halt='found operator at end of line' \
431 $(_sc_search_regexp)
433 # Don't use "readlink" or "readlinkat" directly
434 sc_prohibit_readlink:
435 @prohibit='\<readlink(at)? \(' \
436 halt='do not use readlink(at); use via xreadlink or areadlink*' \
437 $(_sc_search_regexp)
439 # Don't use address of "stat" or "lstat" functions
440 sc_prohibit_stat_macro_address:
441 @prohibit='\<l?stat '':|&l?stat\>' \
442 halt='stat() and lstat() may be function-like macros' \
443 $(_sc_search_regexp)
445 # Ensure that date's --help output stays in sync with the info
446 # documentation for GNU strftime. The only exception is %N and %q,
447 # which date accepts but GNU strftime does not.
448 extract_char = sed 's/^[^%][^%]*%\(.\).*/\1/'
449 sc_strftime_check:
450 @if test -f $(srcdir)/src/date.c; then \
451 grep '^ %. ' $(srcdir)/src/date.c | sort \
452 | $(extract_char) > $@-src; \
453 { echo N; echo q; \
454 info libc date calendar format 2>/dev/null \
455 | grep "^ *['\`]%.'$$"| $(extract_char); }| sort >$@-info;\
456 if test $$(stat --format %s $@-info) != 2; then \
457 diff -u $@-src $@-info || exit 1; \
458 else \
459 echo '$(ME): skipping $@: libc info not installed' 1>&2; \
460 fi; \
461 rm -f $@-src $@-info; \
464 # Indent only with spaces.
465 sc_prohibit_tab_based_indentation:
466 @prohibit='^ * ' \
467 halt='TAB in indentation; use only spaces' \
468 $(_sc_search_regexp)
470 # Enforce lowercase 'e' in "I.e.".
471 sc_prohibit_uppercase_id_est:
472 @prohibit='I\.E\.' \
473 halt='Uppercase "Id Est" abbreviation; use "I.e.," instead' \
474 $(_sc_search_regexp)
476 # Enforce double-space before "I.e." at the beginning of a sentence.
477 sc_ensure_dblspace_after_dot_before_id_est:
478 @prohibit='\. I\.e\.' \
479 halt='Single space after dot before "i.e."; use ". i.e." instead' \
480 $(_sc_search_regexp)
482 # Enforce comma after "i.e." (at least before a blank or at EOL).
483 sc_ensure_comma_after_id_est:
484 @prohibit='[Ii]\.e\.( |$$)' \
485 halt='Missing comma after "i.e."; use "i.e.," instead' \
486 $(_sc_search_regexp)
488 # The SEE ALSO section of a man page should not be terminated with
489 # a period. Check the first line after each "SEE ALSO" line in man/*.x:
490 sc_prohibit_man_see_also_period:
491 @grep -nB1 '\.$$' $$($(VC_LIST_EXCEPT) | grep 'man/.*\.x$$') \
492 | grep -A1 -e '-\[SEE ALSO\]' | grep '\.$$' && \
493 { echo '$(ME): do not end "SEE ALSO" section with a period' \
494 1>&2; exit 1; } || :
496 # Don't use "indent-tabs-mode: nil" anymore. No longer needed.
497 sc_prohibit_emacs__indent_tabs_mode__setting:
498 @prohibit='^( *[*#] *)?indent-tabs-mode:' \
499 halt='use of emacs indent-tabs-mode: setting' \
500 $(_sc_search_regexp)
502 # Ensure that tests don't include a redundant fail=0.
503 sc_prohibit_fail_0:
504 @prohibit='\<fail=0\>' \
505 halt='fail=0 initialization' \
506 $(_sc_search_regexp)
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.
512 sc_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)
519 # Ensure that env vars are not passed through returns_ as
520 # that was seen to fail on FreeBSD /bin/sh at least
521 sc_prohibit_env_returns:
522 @prohibit='=[^ ]* returns_ ' \
523 exclude='_ returns_ ' \
524 halt='Passing env vars to returns_ is non portable' \
525 in_vc_files='^tests/' \
526 $(_sc_search_regexp)
528 # The mode part of a setfacl -m option argument must be three bytes long.
529 # I.e., an argument of user:bin:rw or user:bin:r will make Solaris 10's
530 # setfacl reject it with: "Unrecognized character found in mode field".
531 # Use hyphens to give it a length of 3: "...:rw-" or "...:r--".
532 sc_prohibit_short_facl_mode_spec:
533 @prohibit='\<setfacl .*-m.*:.*:[rwx-]{1,2} ' \
534 halt='setfacl mode string length < 3; extend with hyphen(s)' \
535 $(_sc_search_regexp)
537 # Ensure that "stdio--.h" is used where appropriate.
538 sc_require_stdio_safer:
539 @if $(VC_LIST_EXCEPT) | grep -l '\.[ch]$$' > /dev/null; then \
540 files=$$(grep -l '\bfreopen \?(' $$($(VC_LIST_EXCEPT) \
541 | grep '\.[ch]$$')); \
542 test -n "$$files" && grep -LE 'include "stdio--.h"' $$files \
543 | grep . && \
544 { echo '$(ME): the above files should use "stdio--.h"' \
545 1>&2; exit 1; } || :; \
546 else :; \
549 sc_prohibit_perl_hash_quotes:
550 @prohibit="\{'[A-Z_]+' *[=}]" \
551 halt="in Perl code, write \$$hash{KEY}, not \$$hash{'K''EY'}" \
552 $(_sc_search_regexp)
554 # Prefer xnanosleep over other less-precise sleep methods
555 sc_prohibit_sleep:
556 @prohibit='\<(nano|u)?sleep \(' \
557 halt='prefer xnanosleep over other sleep interfaces' \
558 $(_sc_search_regexp)
560 # Use print_ver_ (from init.cfg), not open-coded $VERBOSE check.
561 sc_prohibit_verbose_version:
562 @prohibit='test "\$$VERBOSE" = yes && .* --version' \
563 halt='use the print_ver_ function instead...' \
564 $(_sc_search_regexp)
566 # Enforce print_ver_ tracking of dependencies
567 # Each coreutils specific program a test requires
568 # should be tagged by calling through env(1).
569 sc_env_test_dependencies:
570 @cd $(top_srcdir) && GIT_PAGER= git grep -E \
571 "env ($$(build-aux/gen-lists-of-programs.sh --list-progs | \
572 grep -vF '[' |paste -d'|' -s))" tests | \
573 sed "s/\([^:]\):.*env \([^)' ]*\).*/\1 \2/" | uniq | \
574 while read test prog; do \
575 printf '%s' $$test | grep -q '\.pl$$' && continue; \
576 grep -q "print_ver_.* $$prog" $$test \
577 || echo $$test should call: print_ver_ $$prog; \
578 done | grep . && exit 1 || :
580 # Use framework_failure_, not the old name without the trailing underscore.
581 sc_prohibit_framework_failure:
582 @prohibit='\<framework_''failure\>' \
583 halt='use framework_failure_ instead' \
584 $(_sc_search_regexp)
586 # Prohibit the use of `...` in tests/. Use $(...) instead.
587 sc_prohibit_test_backticks:
588 @prohibit='`' in_vc_files='^tests/' \
589 halt='use $$(...), not `...` in tests/' \
590 $(_sc_search_regexp)
592 # Ensure that compare is used to check empty files
593 # so that the unexpected contents are displayed
594 sc_prohibit_test_empty:
595 @prohibit='test -s.*&&' in_vc_files='^tests/' \
596 halt='use `compare /dev/null ...`, not `test -s ...` in tests/' \
597 $(_sc_search_regexp)
599 # Ensure that expr doesn't work directly on various unsigned int types,
600 # as that's not generally supported without GMP.
601 sc_prohibit_expr_unsigned:
602 @prohibit='expr .*(UINT|ULONG|[^S]SIZE|[UGP]ID|UINTMAX)' \
603 halt='avoid passing unsigned limits to `expr` (without GMP)' \
604 in_vc_files='^tests/' \
605 $(_sc_search_regexp)
607 # Programs like sort, ls, expr use PROG_FAILURE in place of EXIT_FAILURE.
608 # Others, use the EXIT_CANCELED, EXIT_ENOENT, etc. macros defined in system.h.
609 # In those programs, ensure that EXIT_FAILURE is not used by mistake.
610 sc_some_programs_must_avoid_exit_failure:
611 @grep -nw EXIT_FAILURE \
612 $$(git grep -El '[^T]_FAILURE|EXIT_CANCELED' $(srcdir)/src) \
613 | grep -vE '= EXIT_FAILURE|return .* \?' | grep . \
614 && { echo '$(ME): do not use EXIT_FAILURE in the above' \
615 1>&2; exit 1; } || :
617 # Ensure that tests call the get_min_ulimit_v_ function if using ulimit -v
618 sc_prohibit_test_ulimit_without_require_:
619 @(git grep -l get_min_ulimit_v_ $(srcdir)/tests; \
620 git grep -l 'ulimit -v' $(srcdir)/tests) \
621 | sort | uniq -u | grep . && { echo "$(ME): the above test(s)"\
622 " should match get_min_ulimit_v_ with ulimit -v" 1>&2; exit 1; } || :
624 # Ensure that tests call the cleanup_ function if using background processes
625 sc_prohibit_test_background_without_cleanup_:
626 @(git grep -El '( &$$|&[^&]*=\$$!)' $(srcdir)/tests; \
627 git grep -l 'cleanup_()' $(srcdir)/tests | sed p) \
628 | sort | uniq -u | grep . && { echo "$(ME): the above test(s)"\
629 " should use cleanup_ for background processes" 1>&2; exit 1; } || :
631 # Ensure that tests call the print_ver_ function for programs which are
632 # actually used in that test.
633 sc_prohibit_test_calls_print_ver_with_irrelevant_argument:
634 @git grep -w print_ver_ $(srcdir)/tests \
635 | sed 's#:print_ver_##' \
636 | { fail=0; \
637 while read file name; do \
638 for i in $$name; do \
639 case "$$i" in install) i=ginstall;; esac; \
640 grep -w "$$i" $$file|grep -vw print_ver_|grep -q . \
641 || { fail=1; \
642 echo "*** Test: $$file, offending: $$i." 1>&2; };\
643 done; \
644 done; \
645 test $$fail = 0 || exit 1; \
646 } || { echo "$(ME): the above test(s) call print_ver_ for" \
647 "program(s) they don't use" 1>&2; exit 1; }
649 # Exempt the contents of any usage function from the following.
650 _continued_string_col_1 = \
651 s/^usage .*?\n}//ms;/\\\n\w/ and print ("$$ARGV\n"),$$e=1;END{$$e||=0;exit $$e}
652 # Ding any source file that has a continued string with an alphabetic in the
653 # first column of the following line. We prohibit them because they usually
654 # trigger false positives in tools that try to map an arbitrary line number
655 # to the enclosing function name. Of course, very many strings do precisely
656 # this, *when they are part of the usage function*. That is why we exempt
657 # the contents of any function named "usage".
658 sc_prohibit_continued_string_alpha_in_column_1:
659 @perl -0777 -ne '$(_continued_string_col_1)' \
660 $$($(VC_LIST_EXCEPT) | grep '\.[ch]$$') \
661 || { echo '$(ME): continued string with word in first column' \
662 1>&2; exit 1; } || :
663 # Use this to list offending lines:
664 # git ls-files |grep '\.[ch]$' | xargs \
665 # perl -n -0777 -e 's/^usage.*?\n}//ms;/\\\n\w/ and print "$ARGV\n"' \
666 # | xargs grep -A1 '\\$'|grep '\.[ch][:-][_a-zA-Z]'
669 ###########################################################
670 _p0 = \([^"'/]\|"\([^\"]\|[\].\)*"\|'\([^\']\|[\].\)*'
671 _pre = $(_p0)\|[/][^"'/*]\|[/]"\([^\"]\|[\].\)*"\|[/]'\([^\']\|[\].\)*'\)*
672 _pre_anchored = ^\($(_pre)\)
673 _comment_and_close = [^*]\|[*][^/*]\)*[*][*]*/
674 # help font-lock mode: '
676 # A sed expression that removes ANSI C and ISO C99 comments.
677 # Derived from the one in GNU gettext's 'moopp' preprocessor.
678 _sed_remove_comments = \
679 /[/][/*]/{ \
680 ta; \
681 :a; \
682 s,$(_pre_anchored)//.*,\1,; \
683 te; \
684 s,$(_pre_anchored)/[*]\($(_comment_and_close),\1 ,; \
685 ta; \
686 /^$(_pre)[/][*]/{ \
687 s,$(_pre_anchored)/[*].*,\1 ,; \
688 tu; \
689 :u; \
690 n; \
691 s,^\($(_comment_and_close),,; \
692 tv; \
693 s,^.*$$,,; \
694 bu; \
695 :v; \
696 }; \
697 :e; \
699 # Quote all single quotes.
700 _sed_rm_comments_q = $(subst ','\'',$(_sed_remove_comments))
701 # help font-lock mode: '
703 _space_before_paren_exempt =? \\n\\$$
704 _space_before_paren_exempt = \
705 (^ *\#|\\n\\$$|%s\(to %s|(date|group|character)\(s\))
706 # Ensure that there is a space before each open parenthesis in C code.
707 sc_space_before_open_paren:
708 @if $(VC_LIST_EXCEPT) | grep -l '\.[ch]$$' > /dev/null; then \
709 fail=0; \
710 for c in $$($(VC_LIST_EXCEPT) | grep '\.[ch]$$'); do \
711 sed '$(_sed_rm_comments_q)' $$c 2>/dev/null \
712 | grep -i '[[:alnum:]](' \
713 | grep -vE '$(_space_before_paren_exempt)' \
714 | grep . && { fail=1; echo "*** $$c"; }; \
715 done; \
716 test $$fail = 1 && \
717 { echo '$(ME): the above files lack a space-before-open-paren' \
718 1>&2; exit 1; } || :; \
719 else :; \
722 # Similar to the gnulib maint.mk rule for sc_prohibit_strcmp
723 # Use STREQ_LEN or STRPREFIX rather than comparing strncmp == 0, or != 0.
724 sc_prohibit_strncmp:
725 @prohibit='^[^#].*str''ncmp *\(' \
726 halt='use STREQ_LEN or STRPREFIX instead of str''ncmp' \
727 $(_sc_search_regexp)
729 # Enforce recommended preprocessor indentation style.
730 sc_preprocessor_indentation:
731 @if cppi --version >/dev/null 2>&1; then \
732 $(VC_LIST_EXCEPT) | grep '\.[ch]$$' | xargs cppi -a -c \
733 || { echo '$(ME): incorrect preprocessor indentation' 1>&2; \
734 exit 1; }; \
735 else \
736 echo '$(ME): skipping test $@: cppi not installed' 1>&2; \
739 # THANKS.in is a list of name/email pairs for people who are mentioned in
740 # commit logs (and generated ChangeLog), but who are not also listed as an
741 # author of a commit. Name/email pairs of commit authors are automatically
742 # extracted from the repository. As a very minor factorization, when
743 # someone who was initially listed only in THANKS.in later authors a commit,
744 # this rule detects that their pair may now be removed from THANKS.in.
745 sc_THANKS_in_duplicates:
746 @{ git log --pretty=format:%aN | sort -u; \
747 cut -b-36 $(srcdir)/THANKS.in \
748 | sed '/^$$/,/^$$/!d;/^$$/d;s/ *$$//'; } \
749 | sort | uniq -d | grep . \
750 && { echo '$(ME): remove the above names from THANKS.in' \
751 1>&2; exit 1; } || :
753 # Ensure the contributor list stays sorted. However, if the system's
754 # en_US.UTF-8 locale data is erroneous, give a diagnostic and skip
755 # this test. This affects OS X, up to at least 10.11.6.
756 # Use our sort as other implementations may result in a different order.
757 sc_THANKS_in_sorted:
758 @printf 'a\n.b\n'|LC_ALL=en_US.UTF-8 src/sort -c 2> /dev/null \
759 && { \
760 sed '/^$$/,/^$$/!d;/^$$/d' $(srcdir)/THANKS.in > $@.1 && \
761 LC_ALL=en_US.UTF-8 src/sort -f -k1,1 $@.1 > $@.2 && \
762 diff -u $@.1 $@.2; diff=$$?; \
763 rm -f $@.1 $@.2; \
764 test "$$diff" = 0 \
765 || { echo '$(ME): THANKS.in is unsorted' 1>&2; exit 1; }; \
767 || { echo '$(ME): this system has erroneous locale data;' \
768 'skipping $@' 1>&2; }
770 # Look for developer diagnostics that are marked for translation.
771 # This won't find any for which devmsg's format string is on a separate line.
772 sc_marked_devdiagnostics:
773 @prohibit='\<devmsg *\(.*_\(' \
774 halt='found marked developer diagnostic(s)' \
775 $(_sc_search_regexp)
777 # Ensure we keep hex constants as 4 or 8 bytes for consistency
778 # and so that make src/fs-magic-compare works consistently
779 sc_fs-magic-compare:
780 @sed -n 's|.*/\* \(0x[0-9A-Fa-f]\{1,\}\) .*\*/|\1|p' \
781 $(srcdir)/src/stat.c | grep -Ev '^0x([0-9A-F]{4}){1,2}$$' \
782 && { echo '$(ME): Constants in src/stat.c should be 4 or 8' \
783 'upper-case chars' 1>&2; exit 1; } || :
785 # Ensure gnulib generated files are ignored
786 # TODO: Perhaps augment gnulib-tool to do this in lib/.gitignore?
787 sc_gitignore_missing:
788 @{ sed -n '/^\/lib\/.*\.h$$/{p;p}' $(srcdir)/.gitignore; \
789 find lib -name '*.in*' ! -name '*~' ! -name 'sys_*' | \
790 sed 's|^|/|; s|_\(.*in\.h\)|/\1|; s/\.in//'; } | \
791 sort | uniq -u | grep . && { echo '$(ME): Add above' \
792 'entries to .gitignore' >&2; exit 1; } || :
794 # Flag redundant entries in .gitignore
795 # Disabled for now as too aggressive flagging
796 # entries like /lib/arg-nonnull.h
797 #sc_gitignore_redundant:
798 # @{ grep ^/lib $(srcdir)/.gitignore; \
799 # sed 's|^|/lib|' $(srcdir)/lib/.gitignore; } | \
800 # sort | uniq -d | grep . && { echo '$(ME): Remove above' \
801 # 'entries from .gitignore' >&2; exit 1; } || :
803 sc_prohibit-form-feed:
804 @prohibit=$$'\f' \
805 in_vc_files='\.[chly]$$' \
806 halt='Form Feed (^L) detected' \
807 $(_sc_search_regexp)
809 # Override the default Cc: used in generating an announcement.
810 announcement_Cc_ = $(translation_project_), \
811 coreutils@gnu.org, coreutils-announce@gnu.org
813 -include $(srcdir)/dist-check.mk
815 update-copyright-env = \
816 UPDATE_COPYRIGHT_FORCE=1 \
817 UPDATE_COPYRIGHT_USE_INTERVALS=2 \
818 UPDATE_COPYRIGHT_MAX_LINE_LENGTH=79
820 # List syntax-check exemptions.
821 exclude_file_name_regexp--sc_space_tab = \
822 ^(tests/pr/|tests/misc/nl\.sh$$|gl/.*\.diff$$|man/help2man$$)
823 exclude_file_name_regexp--sc_bindtextdomain = \
824 ^(gl/.*|lib/euidaccess-stat|src/make-prime-list)\.c$$
825 exclude_file_name_regexp--sc_trailing_blank = \
826 ^(tests/pr/|gl/.*\.diff$$|man/help2man)
827 exclude_file_name_regexp--sc_system_h_headers = \
828 ^src/((die|system|copy)\.h|make-prime-list\.c)$$
830 _src = (false|lbracket|ls-(dir|ls|vdir)|tac-pipe|uname-(arch|uname))
831 _gl_src = (xdecto.max|cl-strtold)
832 exclude_file_name_regexp--sc_require_config_h_first = \
833 (^lib/buffer-lcm\.c|gl/lib/$(_gl_src)\.c|src/$(_src)\.c)$$
834 exclude_file_name_regexp--sc_require_config_h = \
835 $(exclude_file_name_regexp--sc_require_config_h_first)
837 exclude_file_name_regexp--sc_po_check = ^(gl/|man/help2man)
838 exclude_file_name_regexp--sc_prohibit_always-defined_macros = \
839 ^src/(seq|remove)\.c$$
840 exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF = ^tests/pr/
841 exclude_file_name_regexp--sc_program_name = \
842 ^(gl/.*|lib/euidaccess-stat|src/make-prime-list)\.c$$
843 exclude_file_name_regexp--sc_file_system = \
844 NEWS|^(init\.cfg|src/df\.c|tests/df/df-P\.sh|tests/df/df-output\.sh)$$
845 exclude_file_name_regexp--sc_prohibit_always_true_header_tests = \
846 ^m4/stat-prog\.m4$$
847 exclude_file_name_regexp--sc_prohibit_fail_0 = \
848 (^.*/git-hooks/commit-msg|^tests/init\.sh|Makefile\.am|\.mk|.*\.texi)$$
849 exclude_file_name_regexp--sc_prohibit_test_minus_ao = *\.texi$$
850 exclude_file_name_regexp--sc_prohibit_atoi_atof = ^lib/euidaccess-stat\.c$$
852 # longlong.h is maintained elsewhere.
853 _ll = ^src/longlong\.h$$
854 exclude_file_name_regexp--sc_useless_cpp_parens = $(_ll)
855 exclude_file_name_regexp--sc_space_before_open_paren = $(_ll)
857 tbi_1 = ^tests/pr/|(\.mk|^man/help2man)$$
858 tbi_2 = ^scripts/git-hooks/(pre-commit|pre-applypatch|applypatch-msg)$$
859 tbi_3 = (GNU)?[Mm]akefile(\.am)?$$|$(_ll)
860 exclude_file_name_regexp--sc_prohibit_tab_based_indentation = \
861 $(tbi_1)|$(tbi_2)|$(tbi_3)
863 exclude_file_name_regexp--sc_preprocessor_indentation = \
864 ^(gl/lib/rand-isaac\.[ch]|gl/tests/test-rand-isaac\.c)$$|$(_ll)
865 exclude_file_name_regexp--sc_prohibit_stat_st_blocks = \
866 ^(src/system\.h|tests/du/2g\.sh)$$
868 exclude_file_name_regexp--sc_prohibit_continued_string_alpha_in_column_1 = \
869 ^src/(system\.h|od\.c|printf\.c|getlimits\.c)$$
871 exclude_file_name_regexp--sc_prohibit_test_backticks = \
872 ^tests/(local\.mk|(init|misc/stdbuf|factor/create-test)\.sh)$$
874 # Exempt test.c, since it's nominally shared, and relatively static.
875 exclude_file_name_regexp--sc_prohibit_operator_at_end_of_line = \
876 ^src/(ptx|test|head)\.c$$
878 exclude_file_name_regexp--sc_error_message_uppercase = ^src/factor\.c$$
879 exclude_file_name_regexp--sc_prohibit_atoi_atof = ^src/make-prime-list\.c$$
881 # Exception here as we don't want __attribute elided on non GCC
882 exclude_file_name_regexp--sc_prohibit-gl-attributes = ^src/libstdbuf\.c$$
884 exclude_file_name_regexp--sc_prohibit_uppercase_id_est = \.diff$$
885 exclude_file_name_regexp--sc_ensure_dblspace_after_dot_before_id_est = \.diff$$
886 exclude_file_name_regexp--sc_ensure_comma_after_id_est = \.diff|$(_ll)$$
887 exclude_file_name_regexp--sc_long_lines = \.diff$$|$(_ll)
889 # Augment AM_CFLAGS to include our per-directory options:
890 AM_CFLAGS += $($(@D)_CFLAGS)
892 src_CFLAGS = $(WARN_CFLAGS)
893 lib_CFLAGS = $(GNULIB_WARN_CFLAGS)
894 gnulib-tests_CFLAGS = $(GNULIB_TEST_WARN_CFLAGS)
896 # Configuration to make the tight-scope syntax-check rule work with
897 # non-recursive make.
898 # Note _gl_TS_headers use _single line_ extern function declarations,
899 # while *_SOURCES use the _two line_ form.
900 export _gl_TS_headers = $(noinst_HEADERS)
901 # Add exceptions for --enable-single-binary renamed functions.
902 _gl_TS_unmarked_extern_functions = main usage
903 _gl_TS_unmarked_extern_functions += single_binary_main_.* _usage_.*
904 # Headers to search for single line extern _data_ declarations.
905 _gl_TS_other_headers = $(srcdir)/src/*.h src/*.h
906 # Tell the tight_scope rule about an exceptional "extern" variable.
907 # Normally, the rule would detect its declaration, but that uses a
908 # different name, __clz_tab.
909 _gl_TS_unmarked_extern_vars = factor_clz_tab
910 # Other tight_scope settings
911 _gl_TS_dir = .
912 _gl_TS_obj_files = src/*.$(OBJEXT)