Comment out yesterday's VPATH-friendly addition, for now.
[platform/upstream/coreutils.git] / Makefile.maint
1 # -*-Makefile-*-
2 # This Makefile fragment is shared between the coreutils,
3 # CPPI, Bison, and Autoconf.
4
5 ## Copyright (C) 2001-2008 Free Software Foundation, Inc.
6 ##
7 ## This program is free software: you can redistribute it and/or modify
8 ## it under the terms of the GNU General Public License as published by
9 ## the Free Software Foundation, either version 3 of the License, or
10 ## (at your option) any later version.
11 ##
12 ## This program is distributed in the hope that it will be useful,
13 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ## GNU General Public License for more details.
16 ##
17 ## You should have received a copy of the GNU General Public License
18 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 # This is reported not to work with make-3.79.1
21 # ME := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
22 ME := Makefile.maint
23
24 # Do not save the original name or timestamp in the .tar.gz file.
25 # Use --rsyncable if available.
26 gzip_rsyncable := \
27   $(shell gzip --help 2>/dev/null|grep rsyncable >/dev/null && echo --rsyncable)
28 GZIP_ENV = '--no-name --best $(gzip_rsyncable)'
29
30 CVS = cvs
31 GIT = git
32 VC = $(GIT)
33 VC-tag = git tag -s -m '$(VERSION)'
34
35 CVS_LIST = build-aux/vc-list-files
36
37 CVS_LIST_EXCEPT = \
38   $(CVS_LIST) | if test -f .x-$@; then grep -vEf .x-$@; else grep -v ChangeLog; fi
39
40 ifeq ($(origin prev_version_file), undefined)
41   prev_version_file = .prev-version
42 endif
43
44 PREV_VERSION := $(shell cat $(prev_version_file))
45 VERSION_REGEXP = $(subst .,\.,$(VERSION))
46
47 ifeq ($(VC),$(GIT))
48 this-vc-tag = v$(VERSION)
49 this-vc-tag-regexp = v$(VERSION_REGEXP)
50 else
51 tag-package = $(shell echo "$(PACKAGE)" | tr '[:lower:]' '[:upper:]')
52 tag-this-version = $(subst .,_,$(VERSION))
53 this-vc-tag = $(tag-package)-$(tag-this-version)
54 this-vc-tag-regexp = $(this-vc-tag)
55 endif
56 my_distdir = $(PACKAGE)-$(VERSION)
57
58 # Old releases are stored here.
59 release_archive_dir ?= ../release
60
61 # Prevent programs like 'sort' from considering distinct strings to be equal.
62 # Doing it here saves us from having to set LC_ALL elsewhere in this file.
63 export LC_ALL = C
64
65
66
67 ## --------------- ##
68 ## Sanity checks.  ##
69 ## --------------- ##
70
71 # Collect the names of rules starting with `sc_'.
72 syntax-check-rules := $(shell sed -n 's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' $(ME))
73 .PHONY: $(syntax-check-rules)
74
75 local-checks-available = \
76   po-check copyright-check m4-check author_mark_check \
77   patch-check strftime-check $(syntax-check-rules) \
78   makefile_path_separator_check \
79   makefile-check check-AUTHORS
80 .PHONY: $(local-checks-available)
81
82 local-check := $(filter-out $(local-checks-to-skip), $(local-checks-available))
83
84 syntax-check: $(local-check)
85 #       @grep -nE '#  *include <(limits|std(def|arg|bool))\.h>'         \
86 #           $$(find -type f -name '*.[chly]') &&                        \
87 #         { echo '$(ME): found conditional include' 1>&2;               \
88 #           exit 1; } || :
89
90 #       grep -nE '^#  *include <(string|stdlib)\.h>'                    \
91 #           $(srcdir)/{lib,src}/*.[chy] &&                              \
92 #         { echo '$(ME): FIXME' 1>&2;                                   \
93 #           exit 1; } || :
94 # FIXME: don't allow `#include .strings\.h' anywhere
95
96 sc_avoid_if_before_free:
97         @$(srcdir)/build-aux/useless-if-before-free                     \
98                 $(useless_free_options)                                 \
99             $$($(CVS_LIST_EXCEPT)) &&                                   \
100           { echo '$(ME): found useless "if" before "free" above' 1>&2;  \
101             exit 1; } || :
102
103 sc_cast_of_argument_to_free:
104         @grep -nE '\<free \(\(' $$($(CVS_LIST_EXCEPT)) &&               \
105           { echo '$(ME): don'\''t cast free argument' 1>&2;             \
106             exit 1; } || :
107
108 sc_cast_of_x_alloc_return_value:
109         @grep -nE '\*\) *x(m|c|re)alloc\>' $$($(CVS_LIST_EXCEPT)) &&    \
110           { echo '$(ME): don'\''t cast x*alloc return value' 1>&2;      \
111             exit 1; } || :
112
113 sc_cast_of_alloca_return_value:
114         @grep -nE '\*\) *alloca\>' $$($(CVS_LIST_EXCEPT)) &&            \
115           { echo '$(ME): don'\''t cast alloca return value' 1>&2;       \
116             exit 1; } || :
117
118 sc_space_tab:
119         @grep -n '[ ]   ' $$($(CVS_LIST_EXCEPT)) &&                     \
120           { echo '$(ME): found SPACE-TAB sequence; remove the SPACE'    \
121                 1>&2; exit 1; } || :
122
123 # Don't use *scanf or the old ato* functions in `real' code.
124 # They provide no error checking mechanism.
125 # Instead, use strto* functions.
126 sc_prohibit_atoi_atof:
127         @grep -nE '\<([fs]?scanf|ato([filq]|ll))\>' $$($(CVS_LIST_EXCEPT)) && \
128           { echo '$(ME): do not use *scan''f, ato''f, ato''i, ato''l, ato''ll, ato''q, or ss''canf'     \
129                 1>&2; exit 1; } || :
130
131 # Use STREQ rather than comparing strcmp == 0, or != 0.
132 sc_prohibit_strcmp:
133         @grep -nE '! *str''cmp \(|\<str''cmp \([^)]+\) *==' \
134             $$($(CVS_LIST_EXCEPT)) && \
135           { echo '$(ME): use STREQ in place of the above uses of str''cmp' \
136                 1>&2; exit 1; } || :
137
138 # Using EXIT_SUCCESS as the first argument to error is misleading,
139 # since when that parameter is 0, error does not exit.  Use `0' instead.
140 sc_error_exit_success:
141         @grep -nF 'error (EXIT_SUCCESS,'                                \
142             $$(find -type f -name '*.[chly]') &&                        \
143           { echo '$(ME): found error (EXIT_SUCCESS' 1>&2;               \
144             exit 1; } || :
145
146 sc_file_system:
147         @grep -ni 'file''system' $$($(CVS_LIST_EXCEPT)) &&              \
148           { echo '$(ME): found use of "file''system";'                  \
149             'rewrite to use "file system"' 1>&2;                        \
150             exit 1; } || :
151
152 sc_no_have_config_h:
153         @grep -n 'HAVE''_CONFIG_H' $$($(CVS_LIST_EXCEPT)) &&            \
154           { echo '$(ME): found use of HAVE''_CONFIG_H; remove'          \
155                 1>&2; exit 1; } || :
156
157 # Nearly all .c files must include <config.h>.
158 sc_require_config_h:
159         @if $(CVS_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then         \
160           grep -L '^# *include <config\.h>'                             \
161                 $$($(CVS_LIST_EXCEPT) | grep '\.c$$')                   \
162               | grep . &&                                               \
163           { echo '$(ME): the above files do not include <config.h>'     \
164                 1>&2; exit 1; } || :;                                   \
165         else :;                                                         \
166         fi
167
168 # Prohibit the inclusion of assert.h without an actual use of assert.
169 sc_prohibit_assert_without_use:
170         @if $(CVS_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then         \
171           files=$$(grep -l '# *include <assert\.h>'                     \
172                     $$($(CVS_LIST_EXCEPT) | grep '\.c$$')) &&           \
173           grep -L '\<assert (' $$files                                  \
174               | grep . &&                                               \
175             { echo "$(ME): the above files include <assert.h> but don't use it" \
176                   1>&2; exit 1; } || :;                                 \
177         else :;                                                         \
178         fi
179
180 # Don't include quotearg.h unless you use one of its functions.
181 sc_prohibit_quotearg_without_use:
182         @if $(CVS_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then         \
183           files=$$(grep -l '# *include "quotearg\.h"'                   \
184                     $$($(CVS_LIST_EXCEPT) | grep '\.c$$')) &&           \
185           grep -LE '\<quotearg(_[^ ]+)? \(' $$files                     \
186               | grep . &&                                               \
187             { echo "$(ME): the above files include "quotearg.h" but don't use it" \
188                   1>&2; exit 1; } || :;                                 \
189         else :;                                                         \
190         fi
191
192 # Don't include quote.h unless you use one of its functions.
193 sc_prohibit_quote_without_use:
194         @if $(CVS_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then         \
195           files=$$(grep -l '# *include "quote\.h"'                      \
196                     $$($(CVS_LIST_EXCEPT) | grep '\.c$$')) &&           \
197           grep -LE '\<quote(_n)? \(' $$files                    \
198               | grep . &&                                               \
199             { echo "$(ME): the above files include "quote.h" but don't use it" \
200                   1>&2; exit 1; } || :;                                 \
201         else :;                                                         \
202         fi
203
204 sc_obsolete_symbols:
205         @grep -nE '\<(HAVE''_FCNTL_H|O''_NDELAY)\>'                     \
206              $$($(CVS_LIST_EXCEPT)) &&                                  \
207           { echo '$(ME): do not use HAVE''_FCNTL_H or O''_NDELAY'       \
208                 1>&2; exit 1; } || :
209
210 # FIXME: warn about definitions of EXIT_FAILURE, EXIT_SUCCESS, STREQ
211
212 # Each nonempty line must start with a year number, or a TAB.
213 sc_changelog:
214         @grep -n '^[^12 ]' $$(find . -maxdepth 2 -name ChangeLog) &&    \
215           { echo '$(ME): found unexpected prefix in a ChangeLog' 1>&2;  \
216             exit 1; } || :
217
218 # Ensure that dd's definition of LONGEST_SYMBOL stays in sync
219 # with the strings from the two affected variables.
220 dd_c = $(srcdir)/src/dd.c
221 sc_dd_max_sym_length:
222 ifneq ($(wildcard $(dd_c)),)
223         @len=$$( (sed -n '/conversions\[\] =$$/,/^};/p' $(dd_c);\
224                  sed -n '/flags\[\] =$$/,/^};/p' $(dd_c) )      \
225                 |sed -n '/"/s/^[^"]*"\([^"]*\)".*/\1/p'         \
226               | wc --max-line-length);                          \
227         max=$$(sed -n '/^#define LONGEST_SYMBOL /s///p' $(dd_c) \
228               |tr -d '"' | wc --max-line-length);               \
229         if test "$$len" = "$$max"; then :; else                 \
230           echo 'dd.c: LONGEST_SYMBOL is not longest' 1>&2;      \
231           exit 1;                                               \
232         fi
233 endif
234
235 # Many m4 macros names once began with `jm_'.
236 # On 2004-04-13, they were all changed to start with gl_ instead.
237 # Make sure that none are inadvertently reintroduced.
238 sc_prohibit_jm_in_m4:
239         @grep -nE 'jm_[A-Z]'                                    \
240                 $$($(CVS_LIST) m4 |grep '\.m4$$'; echo /dev/null) && \
241             { echo '$(ME): do not use jm_ in m4 macro names'    \
242               1>&2; exit 1; } || :
243
244 sc_root_tests:
245         @if test -d tests \
246               && grep check-root tests/Makefile.am>/dev/null 2>&1; then \
247         t1=sc-root.expected; t2=sc-root.actual;                         \
248         grep -nl '^require_root_$$'                                     \
249           $$($(CVS_LIST) tests) |sed s,tests,., |sort > $$t1;           \
250         sed -n 's,      cd \([^ ]*\) .*MAKE..check TESTS=\(.*\),./\1/\2,p' \
251           $(srcdir)/tests/Makefile.am |sort > $$t2;                     \
252         diff -u $$t1 $$t2 || diff=1;                                    \
253         rm -f $$t1 $$t2;                                                \
254         test "$$diff"                                                   \
255           && { echo 'tests/Makefile.am: missing check-root action'>&2;  \
256                exit 1; } || :;                                          \
257         fi
258
259 headers_with_interesting_macro_defs = \
260   exit.h        \
261   fcntl_.h      \
262   fnmatch_.h    \
263   intprops.h    \
264   inttypes_.h   \
265   lchown.h      \
266   openat.h      \
267   stat-macros.h \
268   stdint_.h
269
270 # Create a list of regular expressions matching the names
271 # of macros that are guaranteed by parts of gnulib to be defined.
272 .re-defmac:
273         @(cd $(srcdir)/lib;                                             \
274           for f in $(headers_with_interesting_macro_defs); do           \
275             test -f $$f &&                                              \
276               sed -n '/^# *define \([^_ (][^ (]*\)[ (].*/s//\1/p' $$f;  \
277            done;                                                        \
278          ) | sort -u                                                    \
279            | grep -Ev 'ATTRIBUTE_NORETURN|SIZE_MAX'                     \
280            | sed 's/^/^# *define /'                                     \
281           > $@-t
282         @mv $@-t $@
283
284 # Don't define macros that we already get from gnulib header files.
285 sc_always_defined_macros: .re-defmac
286         @if test -f $(srcdir)/src/system.h; then                        \
287           trap 'rc=$$?; rm -f .re-defmac; exit $$rc' 0 1 2 3 15;        \
288           grep -f .re-defmac $$($(CVS_LIST))                            \
289             && { echo '$(ME): define the above via some gnulib .h file' \
290                   1>&2;  exit 1; } || :;                                \
291         fi
292
293 # Create a list of regular expressions matching the names
294 # of files included from system.h.  Exclude a couple.
295 .re-list:
296         @sed -n '/^# *include /s///p' $(srcdir)/src/system.h \
297           | grep -Ev 'sys/(param|file)\.h' \
298           | sed 's/ .*//;;s/^["<]/^# *include [<"]/;s/\.h[">]$$/\\.h[">]/' \
299           > $@-t
300         @mv $@-t $@
301
302 # Files in src/ should not include directly any of
303 # the headers already included via system.h.
304 sc_system_h_headers: .re-list
305         @if test -f $(srcdir)/src/system.h; then                        \
306           trap 'rc=$$?; rm -f .re-list; exit $$rc' 0 1 2 3 15;          \
307           grep -nE -f .re-list                                          \
308               $$($(CVS_LIST) src |                                      \
309                  grep -Ev '((copy|system)\.h|parse-gram\.c)$$')         \
310             && { echo '$(ME): the above are already included via system.h'\
311                   1>&2;  exit 1; } || :;                                \
312         fi
313
314 sc_sun_os_names:
315         @grep -nEi \
316             'solaris[^[:alnum:]]*2\.(7|8|9|[1-9][0-9])|sunos[^[:alnum:]][6-9]' \
317             $$($(CVS_LIST_EXCEPT)) &&                                   \
318           { echo '$(ME): found misuse of Sun OS version numbers' 1>&2;  \
319             exit 1; } || :
320
321 sc_the_the:
322         @grep -ni '\<the ''the\>' $$($(CVS_LIST_EXCEPT)) &&             \
323           { echo '$(ME): found use of "the ''the";' 1>&2;               \
324             exit 1; } || :
325
326 sc_tight_scope:
327         $(MAKE) -C src $@
328
329 sc_trailing_blank:
330         @grep -n '[      ]$$' $$($(CVS_LIST_EXCEPT)) &&                 \
331           { echo '$(ME): found trailing blank(s)'                       \
332                 1>&2; exit 1; } || :
333
334 # Match lines like the following, but where there is only one space
335 # between the options and the description:
336 #   -D, --all-repeated[=delimit-method]  print all duplicate lines\n
337 longopt_re = --[a-z][0-9A-Za-z-]*(\[?=[0-9A-Za-z-]*\]?)?
338 sc_two_space_separator_in_usage:
339         @grep -nE '^   *(-[A-Za-z],)? $(longopt_re) [^ ].*\\$$'         \
340             $$($(CVS_LIST_EXCEPT)) &&                                   \
341           { echo "$(ME): help2man requires at least two spaces between"; \
342             echo "$(ME): an option and its description"; \
343                 1>&2; exit 1; } || :
344
345 # Look for diagnostics that aren't marked for translation.
346 # This won't find any for which error's format string is on a separate line.
347 sc_unmarked_diagnostics:
348         @grep -nE                                                       \
349             '\<error \([^"]*"[^"]*[a-z]{3}' $$($(CVS_LIST_EXCEPT))      \
350           | grep -v '_''(' &&                                           \
351           { echo '$(ME): found unmarked diagnostic(s)' 1>&2;            \
352             exit 1; } || :
353
354 # Avoid useless parentheses like those in this example:
355 # #if defined (SYMBOL) || defined (SYM2)
356 sc_useless_cpp_parens:
357         @grep -n '^# *if .*defined *(' $$($(CVS_LIST_EXCEPT)) &&        \
358           { echo '$(ME): found useless parentheses in cpp directive'    \
359                 1>&2; exit 1; } || :
360
361 # Require the latest GPL.
362 sc_GPL_version:
363         @grep -n 'either ''version [^3]' $$($(CVS_LIST_EXCEPT)) &&      \
364           { echo '$(ME): GPL vN, N!=3' 1>&2; exit 1; } || :
365
366 # Ensure that the c99-to-c89 patch applies cleanly.
367 patch-check:
368         rm -rf src-c89 $@.1 $@.2
369         cp -a src src-c89
370         (cd src-c89; patch -p1 -V never --fuzz=0) < src/c99-to-c89.diff \
371           > $@.1 2>&1
372         if test "$$REGEN_PATCH" = yes; then \
373           diff -upr src src-c89 | sed 's,src-c89/,src/,' \
374             | grep -v '^Only in' > new-diff || : ; fi
375         grep -v '^patching file ' $@.1 > $@.2 || :
376         msg=ok; test -s $@.2 && msg='fuzzy patch' || : ;        \
377         rm -f src-c89/*.o || msg='rm failed';                   \
378         $(MAKE) -C src-c89 CFLAGS='-Wdeclaration-after-statement -Werror' \
379           || msg='compile failure with extra options';          \
380         test "$$msg" = ok && rm -rf src-c89 $@.1 $@.2 || echo "$$msg" 1>&2; \
381         test "$$msg" = ok
382
383 # Ensure that date's --help output stays in sync with the info
384 # documentation for GNU strftime.  The only exception is %N,
385 # which date accepts but GNU strftime does not.
386 extract_char = sed 's/^[^%][^%]*%\(.\).*/\1/'
387 strftime-check:
388         if test -f $(srcdir)/src/date.c; then                           \
389           grep '^  %.  ' $(srcdir)/src/date.c | sort                    \
390             | $(extract_char) > $@-src;                                 \
391           { echo N;                                                     \
392             info libc date calendar format | grep '^    `%.'\'          \
393               | $(extract_char); } | sort > $@-info;                    \
394           diff -u $@-src $@-info || exit 1;                             \
395           rm -f $@-src $@-info;                                         \
396         fi
397
398 check-AUTHORS:
399         $(MAKE) -C src $@
400
401 # Ensure that we use only the standard $(VAR) notation,
402 # not @...@ in Makefile.am, now that we can rely on automake
403 # to emit a definition for each substituted variable.
404 makefile-check:
405         grep -nE '@[A-Z_0-9]+@' `find . -name Makefile.am` \
406           && { echo 'Makefile.maint: use $$(...), not @...@' 1>&2; exit 1; } || :
407
408 news-date-check: NEWS
409         today=`date +%Y-%m-%d`;                                         \
410         if head NEWS | grep '^\*.* $(VERSION_REGEXP) ('$$today')'       \
411             >/dev/null; then                                            \
412           :;                                                            \
413         else                                                            \
414           echo "version or today's date is not in NEWS" 1>&2;           \
415           exit 1;                                                       \
416         fi
417
418 changelog-check:
419         if head ChangeLog | grep 'Version $(VERSION_REGEXP)\.$$'        \
420             >/dev/null; then                                            \
421           :;                                                            \
422         else                                                            \
423           echo "$(VERSION) not in ChangeLog" 1>&2;                      \
424           exit 1;                                                       \
425         fi
426
427 m4-check:
428         @grep -n 'AC_DEFUN([^[]' m4/*.m4 \
429           && { echo 'Makefile.maint: quote the first arg to AC_DEFUN' 1>&2; \
430                exit 1; } || :
431
432 # Verify that all source files using _() are listed in po/POTFILES.in.
433 # FIXME: don't hard-code file names below; use a more general mechanism.
434 po-check:
435         if test -f po/POTFILES.in; then                                 \
436           grep -E -v '^(#|$$)' po/POTFILES.in                           \
437             | grep -v '^src/false\.c$$' | sort > $@-1;                  \
438           files=;                                                       \
439           for file in $$($(CVS_LIST_EXCEPT)) lib/*.[ch]; do             \
440             case $$file in                                              \
441             djgpp/* | man/*) continue;;                                 \
442             */c99-to-c89.diff) continue;;                               \
443             esac;                                                       \
444             case $$file in                                              \
445             *.[ch])                                                     \
446               base=`expr " $$file" : ' \(.*\)\..'`;                     \
447               { test -f $$base.l || test -f $$base.y; } && continue;;   \
448             esac;                                                       \
449             files="$$files $$file";                                     \
450           done;                                                         \
451           grep -E -l '\b(N?_|gettext *)\([^)"]*("|$$)' $$files          \
452             | sort -u > $@-2;                                           \
453           diff -u $@-1 $@-2 || exit 1;                                  \
454           rm -f $@-1 $@-2;                                              \
455         fi
456
457 # In a definition of #define AUTHORS "... and ..." where the RHS contains
458 # the English word `and', the string must be marked with `N_ (...)' so that
459 # gettext recognizes it as a string requiring translation.
460 author_mark_check:
461         @grep -n '^# *define AUTHORS "[^"]* and ' src/*.c |grep -v ' N_ (' && \
462           { echo 'Makefile.maint: enclose the above strings in N_ (...)' 1>&2; \
463             exit 1; } || :
464
465 # Sometimes it is useful to change the PATH environment variable
466 # in Makefiles.  When doing so, it's better not to use the Unix-centric
467 # path separator of `:', but rather the automake-provided `@PATH_SEPARATOR@'.
468 # It'd be better to use `find -print0 ...|xargs -0 ...', but less portable,
469 # and there probably aren't many projects with so many Makefile.am files
470 # that we'd have to worry about limits on command line length.
471 msg = 'Makefile.maint: Do not use `:'\'' above; use @PATH_SEPARATOR@ instead'
472 makefile_path_separator_check:
473         @grep -n 'PATH=.*:' `find $(srcdir) -name Makefile.am` \
474           && { echo $(msg) 1>&2; exit 1; } || :
475
476 # Check that `make alpha' will not fail at the end of the process.
477 writable-files:
478         if test -d $(release_archive_dir); then :; else                 \
479           for file in $(distdir).tar.gz                                 \
480                       $(release_archive_dir)/$(distdir).tar.gz; do      \
481             test -e $$file || continue;                                 \
482             test -w $$file                                              \
483               || { echo ERROR: $$file is not writable; fail=1; };       \
484           done;                                                         \
485           test "$$fail" && exit 1 || :
486         fi
487
488 v_etc_file = lib/version-etc.c
489 sample-test = tests/sample-test
490 texi = doc/$(PACKAGE).texi
491 # Make sure that the copyright date in $(v_etc_file) is up to date.
492 # Do the same for the $(sample-test) and the main doc/.texi file.
493 copyright-check:
494         @if test -f $(v_etc_file); then \
495           grep 'enum { COPYRIGHT_YEAR = '$$(date +%Y)' };' $(v_etc_file) \
496             >/dev/null \
497           || { echo 'out of date copyright in $(v_etc_file); update it' 1>&2; \
498                exit 1; }; \
499         fi
500         @if test -f $(sample-test); then \
501           grep '# Copyright (C) '$$(date +%Y)' Free' $(sample-test) \
502             >/dev/null \
503           || { echo 'out of date copyright in $(sample-test); update it' 1>&2; \
504                exit 1; }; \
505         fi
506         @if test -f $(texi); then \
507           grep 'Copyright @copyright{} .*'$$(date +%Y)' Free' $(texi) \
508             >/dev/null \
509           || { echo 'out of date copyright in $(texi); update it' 1>&2; \
510                exit 1; }; \
511         fi
512
513 vc-diff-check:
514         $(VC) diff > vc-diffs || :
515         if test -s vc-diffs; then                               \
516           cat vc-diffs;                                         \
517           echo "Some files are locally modified:" 1>&2;         \
518           exit 1;                                               \
519         else                                                    \
520           rm vc-diffs;                                          \
521         fi
522
523 cvs-check: vc-diff-check
524
525 maintainer-distcheck:
526         $(MAKE) distcheck
527         $(MAKE) my-distcheck
528
529
530 # Don't make a distribution if checks fail.
531 # Also, make sure the NEWS file is up-to-date.
532 vc-dist: $(local-check) cvs-check maintainer-distcheck
533         $(MAKE) dist
534
535 # Use this to make sure we don't run these programs when building
536 # from a virgin tgz file, below.
537 null_AM_MAKEFLAGS = \
538   ACLOCAL=false \
539   AUTOCONF=false \
540   AUTOMAKE=false \
541   AUTOHEADER=false \
542   MAKEINFO=false
543
544 built_programs = $$(cd src && MAKEFLAGS= $(MAKE) -s built_programs.list)
545
546 warn_cflags = -Dlint -O -Werror -Wall -Wformat -Wshadow -Wpointer-arith
547 bin=bin-$$$$
548
549 write_loser = printf '\#!%s\necho $$0: bad path 1>&2; exit 1\n' '$(SHELL)'
550
551 # Use -Wformat -Werror to detect format-string/arg-list mismatches.
552 # Also, check for shadowing problems with -Wshadow, and for pointer
553 # arithmetic problems with -Wpointer-arith.
554 # These CFLAGS are pretty strict.  If you build this target, you probably
555 # have to have a recent version of gcc and glibc headers.
556 # The for-loop below ensures that there is a bin/ directory full of all
557 # of the programs under test (except the few that are required for basic
558 # Makefile rules), all symlinked to the just-built "false" program.
559 # This is to ensure that if ever a test neglects to make PATH include
560 # the build srcdir, these always-failing programs will run.
561 # Otherwise, it is too easy to test the wrong programs.
562 # Note that "false" itself is a symlink to true, so it too will malfunction.
563 TMPDIR ?= /tmp
564 t=$(TMPDIR)/$(PACKAGE)/test
565 my-distcheck: $(local-check) check
566         -rm -rf $(t)
567         mkdir -p $(t)
568         GZIP=$(GZIP_ENV) $(AMTAR) -C $(t) -zxf $(distdir).tar.gz
569         cd $(t)/$(distdir)                              \
570           && ./configure --disable-nls                  \
571           && $(MAKE) CFLAGS='$(warn_cflags)'            \
572               AM_MAKEFLAGS='$(null_AM_MAKEFLAGS)'       \
573           && $(MAKE) dvi                                \
574           && mkdir $(bin)                               \
575           && ($(write_loser)) > $(bin)/loser            \
576           && chmod a+x $(bin)/loser                     \
577           && for i in $(built_programs); do             \
578                case $$i in                              \
579                  rm|expr|basename|echo|sort|ls|tr);;    \
580                  cat|dirname|mv|wc);;                   \
581                  *) ln $(bin)/loser $(bin)/$$i;;        \
582                esac;                                    \
583              done                                       \
584           && ln -sf ../src/true $(bin)/false            \
585           && PATH=`pwd`/$(bin):$$PATH $(MAKE) -C tests check \
586           && $(MAKE) -C gnulib-tests check              \
587           && rm -rf $(bin)                              \
588           && $(MAKE) distclean
589         (cd $(t) && mv $(distdir) $(distdir).old        \
590           && $(AMTAR) -zxf - ) < $(distdir).tar.gz
591         diff -ur $(t)/$(distdir).old $(t)/$(distdir)
592         if test -f $(srcdir)/src/c99-to-c89.diff; then                  \
593           cd $(t)/$(distdir)                                            \
594             && (cd src && patch -V never --fuzz=0 <c99-to-c89.diff)     \
595             && ./configure --disable-largefile                          \
596                  CFLAGS='-Werror -ansi -Wno-long-long'                  \
597             && $(MAKE);                                                 \
598         fi
599         -rm -rf $(t)
600         @echo "========================"; \
601         echo "$(distdir).tar.gz is ready for distribution"; \
602         echo "========================"
603
604 WGET = wget
605 WGETFLAGS = -C off
606
607 rel-check:
608         tarz=/tmp/rel-check-tarz-$$$$; \
609         md5_tmp=/tmp/rel-check-md5-$$$$; \
610         set -e; \
611         trap 'status=$$?; rm -f $$tarz $$md5_tmp; exit $$status' 0 1 2 3 15; \
612         $(WGET) $(WGETFLAGS) -q --output-document=$$tarz $(url); \
613         echo "$(md5)  -" > $$md5_tmp; \
614         md5sum -c $$md5_tmp < $$tarz
615
616 rel-files = $(DIST_ARCHIVES)
617
618 gnulib-version = $$(cd $(gnulib_dir) && git describe)
619
620 announcement: NEWS ChangeLog $(rel-files)
621         @./build-aux/announce-gen                                       \
622             --release-type=$(RELEASE_TYPE)                              \
623             --package=$(PACKAGE)                                        \
624             --prev=$(PREV_VERSION)                                      \
625             --curr=$(VERSION)                                           \
626             --gpg-key-id=$(gpg_key_ID)                                  \
627             --news=NEWS                                                 \
628             --bootstrap-tools=autoconf,automake,bison,gnulib            \
629             --gnulib-version=$(gnulib-version)                          \
630             $(addprefix --url-dir=, $(url_dir_list))
631
632 ## ---------------- ##
633 ## Updating files.  ##
634 ## ---------------- ##
635
636 ftp-gnu = ftp://ftp.gnu.org/gnu
637 www-gnu = http://www.gnu.org
638
639 # Use mv, if you don't have/want move-if-change.
640 move_if_change ?= move-if-change
641
642 emit_upload_commands:
643         @echo =====================================
644         @echo =====================================
645         @echo "$(srcdir)/build-aux/gnupload $(GNUPLOADFLAGS) \\"
646         @echo "    --to $(gnu_rel_host):$(PACKAGE) \\"
647         @echo "  $(rel-files)"
648         @echo '# send the /tmp/announcement e-mail'
649         @echo =====================================
650         @echo =====================================
651
652 .PHONY: alpha beta major
653 alpha beta major: $(local-check) writable-files
654         test $@ = major                                         \
655           && { echo $(VERSION) | grep -E '^[0-9]+(\.[0-9]+)+$$' \
656                || { echo "invalid version string: $(VERSION)" 1>&2; exit 1;};}\
657           || :
658         $(MAKE) vc-dist
659         $(MAKE) news-date-check changelog-check
660         $(MAKE) -s announcement RELEASE_TYPE=$@ > /tmp/announce-$(my_distdir)
661         if test -d $(release_archive_dir); then                 \
662           ln $(rel-files) $(release_archive_dir);               \
663           chmod a-w $(rel-files);                               \
664         fi
665         $(MAKE) -s emit_upload_commands RELEASE_TYPE=$@
666         echo $(VERSION) > $(prev_version_file)
667         $(VC) commit -m \
668           '$(prev_version_file): Record previous version: $(VERSION).' \
669           $(prev_version_file)