build: consistently use freopen-safer
[platform/upstream/coreutils.git] / cfg.mk
1 # Customize maint.mk                           -*- makefile -*-
2 # Copyright (C) 2003-2009 Free Software Foundation, Inc.
3
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # Use alpha.gnu.org for alpha and beta releases.
18 # Use ftp.gnu.org for major releases.
19 gnu_ftp_host-alpha = alpha.gnu.org
20 gnu_ftp_host-beta = alpha.gnu.org
21 gnu_ftp_host-major = ftp.gnu.org
22 gnu_rel_host = $(gnu_ftp_host-$(RELEASE_TYPE))
23
24 # Used in maint.mk's web-manual rule
25 manual_title = Core GNU utilities
26
27 url_dir_list = \
28   ftp://$(gnu_rel_host)/gnu/$(PACKAGE)
29
30 # The GnuPG ID of the key used to sign the tarballs.
31 gpg_key_ID = B9AB9A16
32
33 # Tests not to run as part of "make distcheck".
34 local-checks-to-skip =
35
36 # Tools used to bootstrap this package, used for "announcement".
37 bootstrap-tools = autoconf,automake,gnulib,bison
38
39 # Now that we have better tests, make this the default.
40 export VERBOSE = yes
41
42 old_NEWS_hash = 785e51bc9af87e7eb004f9ba24a0ca27
43
44 # Ensure that the list of O_ symbols used to compute O_FULLBLOCK is complete.
45 dd = $(srcdir)/src/dd.c
46 sc_dd_O_FLAGS:
47         @rm -f $@.1 $@.2
48         @{ echo O_FULLBLOCK; perl -nle '/^ +\| (O_\w*)$$/ and print $$1' \
49           $(dd); } | sort > $@.1
50         @{ echo O_NOFOLLOW; perl -nle '/{"[a-z]+",\s*(O_\w+)},/ and print $$1' \
51           $(dd); } | sort > $@.2
52         @diff -u $@.1 $@.2 || diff=1 || diff=;                          \
53         rm -f $@.1 $@.2;                                                \
54         test "$$diff"                                                   \
55           && { echo '$(ME): $(dd) has inconsistent O_ flag lists'>&2;   \
56                exit 1; } || :
57
58 # Ensure that dd's definition of LONGEST_SYMBOL stays in sync
59 # with the strings from the two affected variables.
60 dd_c = $(srcdir)/src/dd.c
61 sc_dd_max_sym_length:
62 ifneq ($(wildcard $(dd_c)),)
63         @len=$$( (sed -n '/conversions\[\] =$$/,/^};/p' $(dd_c);\
64                  sed -n '/flags\[\] =$$/,/^};/p' $(dd_c) )      \
65                 |sed -n '/"/s/^[^"]*"\([^"]*\)".*/\1/p'         \
66               | wc --max-line-length);                          \
67         max=$$(sed -n '/^#define LONGEST_SYMBOL /s///p' $(dd_c) \
68               |tr -d '"' | wc --max-line-length);               \
69         if test "$$len" = "$$max"; then :; else                 \
70           echo 'dd.c: LONGEST_SYMBOL is not longest' 1>&2;      \
71           exit 1;                                               \
72         fi
73 endif
74
75 # Many m4 macros names once began with `jm_'.
76 # On 2004-04-13, they were all changed to start with gl_ instead.
77 # Make sure that none are inadvertently reintroduced.
78 sc_prohibit_jm_in_m4:
79         @grep -nE 'jm_[A-Z]'                                            \
80                 $$($(VC_LIST) m4 |grep '\.m4$$'; echo /dev/null) &&     \
81             { echo '$(ME): do not use jm_ in m4 macro names'            \
82               1>&2; exit 1; } || :
83
84 # Ensure that each root-requiring test is run via the "check-root" rule.
85 sc_root_tests:
86         @if test -d tests \
87               && grep check-root tests/Makefile.am>/dev/null 2>&1; then \
88         t1=sc-root.expected; t2=sc-root.actual;                         \
89         grep -nl '^require_root_$$'                                     \
90           $$($(VC_LIST) tests) |sed s,tests/,, |sort > $$t1;            \
91         sed -n '/^root_tests =[  ]*\\$$/,/[^\]$$/p'                     \
92           $(srcdir)/tests/Makefile.am                                   \
93             | sed 's/^  *//;/^root_tests =/d'                           \
94             | tr -s '\012\\' '  ' | fmt -1 | sort > $$t2;               \
95         diff -u $$t1 $$t2 || diff=1 || diff=;                           \
96         rm -f $$t1 $$t2;                                                \
97         test "$$diff"                                                   \
98           && { echo 'tests/Makefile.am: missing check-root action'>&2;  \
99                exit 1; } || :;                                          \
100         fi
101
102 # Ensure that the syntax_check_exceptions file list in Makefile.am
103 # stays in sync with corresponding files in the repository.
104 sce = syntax_check_exceptions
105 sc_x_sc_dist_check:
106         @test "$$( ($(VC_LIST) | sed -n '/^.x-sc_/p';                   \
107                    sed -n '/^$(sce) =[   ]*\\$$/,/[^\]$$/p'             \
108                      $(srcdir)/Makefile.am                              \
109                        | sed 's/^  *//;/^$(sce) =/d'                    \
110                        | tr -s '\012\\' '  ' | fmt -1                   \
111                    ) | sort | uniq -u)"                                 \
112           && { echo 'Makefile.am: $(sce) mismatch' >&2; exit 1; } || :;
113
114 headers_with_interesting_macro_defs = \
115   exit.h        \
116   fcntl_.h      \
117   fnmatch_.h    \
118   intprops.h    \
119   inttypes_.h   \
120   lchown.h      \
121   openat.h      \
122   stat-macros.h \
123   stdint_.h
124
125 # Create a list of regular expressions matching the names
126 # of macros that are guaranteed by parts of gnulib to be defined.
127 .re-defmac:
128         @(cd $(srcdir)/lib;                                             \
129           for f in $(headers_with_interesting_macro_defs); do           \
130             test -f $$f &&                                              \
131               sed -n '/^# *define \([^_ (][^ (]*\)[ (].*/s//\1/p' $$f;  \
132            done;                                                        \
133          ) | sort -u                                                    \
134            | grep -Ev 'ATTRIBUTE_NORETURN|SIZE_MAX'                     \
135            | sed 's/^/^# *define /'                                     \
136           > $@-t
137         @mv $@-t $@
138
139 # Don't define macros that we already get from gnulib header files.
140 sc_always_defined_macros: .re-defmac
141         @if test -f $(srcdir)/src/system.h; then                        \
142           trap 'rc=$$?; rm -f .re-defmac; exit $$rc' 0 1 2 3 15;        \
143           grep -f .re-defmac $$($(VC_LIST))                             \
144             && { echo '$(ME): define the above via some gnulib .h file' \
145                   1>&2;  exit 1; } || :;                                \
146         fi
147
148 # Create a list of regular expressions matching the names
149 # of files included from system.h.  Exclude a couple.
150 .re-list:
151         @sed -n '/^# *include /s///p' $(srcdir)/src/system.h \
152           | grep -Ev 'sys/(param|file)\.h' \
153           | sed 's/ .*//;;s/^["<]/^# *include [<"]/;s/\.h[">]$$/\\.h[">]/' \
154           > $@-t
155         @mv $@-t $@
156
157 # Files in src/ should not include directly any of
158 # the headers already included via system.h.
159 sc_system_h_headers: .re-list
160         @if test -f $(srcdir)/src/system.h; then                        \
161           trap 'rc=$$?; rm -f .re-list; exit $$rc' 0 1 2 3 15;          \
162           grep -nE -f .re-list                                          \
163               $$($(VC_LIST_EXCEPT) | grep '^src/')                      \
164             && { echo '$(ME): the above are already included via system.h'\
165                   1>&2;  exit 1; } || :;                                \
166         fi
167
168 sc_sun_os_names:
169         @grep -nEi \
170             'solaris[^[:alnum:]]*2\.(7|8|9|[1-9][0-9])|sunos[^[:alnum:]][6-9]' \
171             $$($(VC_LIST_EXCEPT)) &&                                    \
172           { echo '$(ME): found misuse of Sun OS version numbers' 1>&2;  \
173             exit 1; } || :
174
175 ALL_RECURSIVE_TARGETS += sc_tight_scope
176 sc_tight_scope:
177         @$(MAKE) -C src $@
178
179 ALL_RECURSIVE_TARGETS += sc_check-AUTHORS
180 sc_check-AUTHORS:
181         @$(MAKE) -C src $@
182
183 # Perl-based tests used to exec perl from a #!/bin/sh script.
184 # Now they all start with #!/usr/bin/perl and the portability
185 # infrastructure is in tests/Makefile.am.  Make sure no old-style
186 # script sneaks back in.
187 sc_no_exec_perl_coreutils:
188         @if test -f $(srcdir)/tests/Coreutils.pm; then                  \
189           grep '^exec  *\$$PERL.*MCoreutils' $$($(VC_LIST) tests) &&    \
190             { echo 1>&2 '$(ME): found anachronistic Perl-based tests';  \
191               exit 1; } || :;                                           \
192         fi
193
194 # Don't use "readlink" or "readlinkat" directly
195 sc_prohibit_readlink:
196         @re='\<readlink(at)? \('                                        \
197         msg='do not use readlink(at); use via xreadlink or areadlink*'  \
198           $(_prohibit_regexp)
199
200 # Don't use address of "stat" or "lstat" functions
201 sc_prohibit_stat_macro_address:
202         @re='\<l?stat '':|&l?stat\>'                                    \
203         msg='stat() and lstat() may be function-like macros'            \
204           $(_prohibit_regexp)
205
206 # Ensure that date's --help output stays in sync with the info
207 # documentation for GNU strftime.  The only exception is %N,
208 # which date accepts but GNU strftime does not.
209 extract_char = sed 's/^[^%][^%]*%\(.\).*/\1/'
210 sc_strftime_check:
211         @if test -f $(srcdir)/src/date.c; then                          \
212           grep '^  %.  ' $(srcdir)/src/date.c | sort                    \
213             | $(extract_char) > $@-src;                                 \
214           { echo N;                                                     \
215             info libc date calendar format | grep '^    `%.'\'          \
216               | $(extract_char); } | sort > $@-info;                    \
217           diff -u $@-src $@-info || exit 1;                             \
218           rm -f $@-src $@-info;                                         \
219         fi
220
221 # Indent only with spaces.
222 sc_prohibit_tab_based_indentation:
223         @re='^ *        '                                               \
224         msg='TAB in indentation; use only spaces'                       \
225           $(_prohibit_regexp)
226
227 # Don't use "indent-tabs-mode: nil" anymore.  No longer needed.
228 sc_prohibit_emacs__indent_tabs_mode__setting:
229         @re='^( *[*#] *)?indent-tabs-mode:'                             \
230         msg='use of emacs indent-tabs-mode: setting'                    \
231           $(_prohibit_regexp)
232
233 # Ensure that each file that contains fail=1 also contains fail=0.
234 # Otherwise, setting file=1 in the environment would make tests fail unexpectedly.
235 sc_prohibit_fail_0:
236         @re='\<fail=0\>'                                                \
237         msg='fail=0 initialization'                                     \
238           $(_prohibit_regexp)
239
240 # Ensure that "stdio--.h" is used where appropriate.
241 sc_require_stdio_safer:
242         @if $(VC_LIST_EXCEPT) | grep -l '\.[ch]$$' > /dev/null; then    \
243           files=$$(grep -l '\bfreopen \?(' $$($(VC_LIST_EXCEPT)         \
244               | grep '\.[ch]$$'));                                      \
245           test -n "$$files" && grep -LE 'include "stdio--.h"' $$files   \
246               | grep . &&                                               \
247           { echo '$(ME): the above files should use "stdio--.h"'        \
248                 1>&2; exit 1; } || :;                                   \
249         else :;                                                         \
250         fi
251
252 include $(srcdir)/dist-check.mk