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