(sc_changelog): Add another nit-picky check.
[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-2003 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 2, or (at your option)
10 ## 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, write to the Free Software
19 ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 ## 02111-1307, USA.
21
22 ME := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
23
24 # Do not save the original name or timestamp in the .tar.gz file.
25 GZIP_ENV = '--no-name --best'
26
27 CVS = cvs
28
29 ifeq ($(origin prev_version_file), undefined)
30   prev_version_file = .prev-version
31 endif
32
33 PREV_VERSION := $(shell cat $(prev_version_file))
34
35 tag-package = $(shell echo "$(PACKAGE)" | tr '[:lower:]' '[:upper:]')
36 tag-this-version = $(subst .,_,$(VERSION))
37 this-cvs-tag = $(tag-package)-$(tag-this-version)
38 my_distdir = $(PACKAGE)-$(VERSION)
39
40 # Old releases are stored here.
41 # Used for diffs and xdeltas.
42 release_archive_dir ?= ../release
43
44
45
46 ## --------------- ##
47 ## Sanity checks.  ##
48 ## --------------- ##
49
50 # Checks that don't require cvs.
51 # Run `changelog-check' last, as previous test may reveal problems requiring
52 # new ChangeLog entries.
53 local-check = \
54   po-check copyright-check writable-files m4-check author_mark_check \
55   changelog-check strftime-check syntax-check makefile_path_separator_check \
56   makefile-check
57 .PHONY: $(local-check)
58
59 # Make sure C source files in src/ don't include xalloc.h directly,
60 # since they all already include it via sys2.h.
61 # It's not a big deal -- just aesthetics.
62 .PHONY: $(syntax-check-rules)
63 syntax-check-rules = \
64   sc_unmarked_diagnostics \
65   sc_cast_of_argument_to_free \
66   sc_cast_of_x_alloc_return_value \
67   sc_space_tab \
68   sc_error_exit_success \
69   sc_xalloc_h_in_src \
70   sc_changelog
71
72 syntax-check: $(syntax-check-rules)
73 #       @grep -E '#  *include <(limits|std(def|arg|bool))\.h>'          \
74 #           $$(find -type f -name '*.[chly]') &&                        \
75 #         { echo '$(ME): found conditional include' 1>&2;               \
76 #           exit 1; } || :
77
78 #       grep -E '^#  *include <(string|stdlib)\.h>'                     \
79 #           $(srcdir)/{lib,src}/*.[chy] &&                              \
80 #         { echo '$(ME): FIXME' 1>&2;                                   \
81 #           exit 1; } || :
82 # FIXME: don't allow `#include .strings\.h' anywhere
83
84 # Look for diagnostics that aren't marked for translation.
85 # This won't find any for which error's format string is on a separate line.
86 sc_unmarked_diagnostics:
87         @grep --exclude=$(srcdir)/src/shred.c -E                        \
88             '\<error \([^"]*"[^"]*[a-z]{3}' $(srcdir)/{lib,src}/*.c     \
89           | grep -v '_(' &&                                             \
90           { echo '$(ME): found unmarked diagnostic(s)' 1>&2;            \
91             exit 1; } || :
92
93 sc_cast_of_argument_to_free:
94         @grep -E '\<free \(\(' $(srcdir)/{lib,src}/*.[chly] &&          \
95           { echo '$(ME): don'\''t cast free argument' 1>&2;             \
96             exit 1; } || :
97
98 sc_cast_of_x_alloc_return_value:
99         @grep -E --exclude=$(srcdir)/lib/regex.c                        \
100             '\*\) *x(m|c|re)alloc\>' $(srcdir)/{lib,src}/*.[chy] &&     \
101           { echo '$(ME): don'\''t cast x*alloc return value' 1>&2;      \
102             exit 1; } || :
103
104 sc_space_tab:
105         @grep -E '[ ]   ' --exclude=$(srcdir)/lib/regex.c               \
106                 $(srcdir)/{lib,src}/*.[chly]                            \
107                 $(find -name Makefile.am) &&                            \
108           { echo '$(ME): found SPACE-TAB sequence; remove the SPACE'    \
109                 1>&2; \
110             exit 1; } || :
111
112 # Using EXIT_SUCCESS as the first argument to error is misleading,
113 # since when that parameter is 0, error does not exit.  Use `0' instead.
114 sc_error_exit_success:
115         @grep -F 'error (EXIT_SUCCESS,'                                 \
116             $$(find -type f -name '*.[chly]') &&                        \
117           { echo '$(ME): found error (EXIT_SUCCESS' 1>&2;               \
118             exit 1; } || :
119
120 # xalloc.h is included via system.h, so should not be included
121 # directly by any file in src/.
122 sc_xalloc_h_in_src:
123         @if test -f $(srcdir)/src/sys2.h; then                          \
124           if grep 'xalloc\.h' $(srcdir)/src/*.c; then                   \
125             exit 1;                                                     \
126           fi;                                                           \
127         fi
128
129 # Each nonempty line must start with a year number, or a TAB.
130 sc_changelog:
131         @grep '^[^12    ]' $$(find . -name ChangeLog -maxdepth 2) &&    \
132           { echo '$(ME): found unexpected prefix in a ChangeLog' 1>&2;  \
133             exit 1; } || :
134
135 # Ensure that date's --help output stays in sync with the info
136 # documentation for GNU strftime.  The only exception is %N,
137 # which date accepts but GNU strftime does not.
138 extract_char = sed 's/^[^%][^%]*%\(.\).*/\1/'
139 strftime-check:
140         if test -f $(srcdir)/src/date.c; then                           \
141           grep '^  %.  ' $(srcdir)/src/date.c | sort                    \
142             | $(extract_char) > $@-src;                                 \
143           { echo N;                                                     \
144             info libc date calendar format | grep '^    `%.'\'          \
145               | $(extract_char); } | sort > $@-info;                    \
146           diff -u $@-src $@-info || exit 1;                             \
147           rm -f $@-src $@-info;                                         \
148         fi
149
150 # Ensure that we use only the standard $(VAR) notation,
151 # not @...@ in Makefile.am, now that we can rely on automake
152 # to emit a definition for each substituted variable.
153 makefile-check:
154         grep -E '@[A-Z_]+@' `find . -name Makefile.am` \
155           && { echo 'Makefile.maint: use $(...), not @...@' 1>&2; exit 1; } || :
156
157 changelog-check:
158         if head ChangeLog | grep 'Version $(VERSION)' >/dev/null; then \
159           :; \
160         else \
161           echo "$(VERSION) not in ChangeLog" 1>&2; \
162           exit 1; \
163         fi
164
165 m4-check:
166         @grep 'AC_DEFUN([^[]' m4/*.m4 \
167           && { echo 'Makefile.maint: quote the first arg to AC_DEFUN' 1>&2; \
168                exit 1; } || :
169
170 # Verify that all source files using _() are listed in po/POTFILES.in.
171 po-check:
172         if test -f po/POTFILES.in; then \
173           grep -E -v '^(#|$$)' po/POTFILES.in | sort > $@-1; \
174           files=; \
175           for file in lib/*.[chly] src/*.[chly]; do \
176             case $$file in \
177             *.[ch]) \
178               base=`expr " $$file" : ' \(.*\)\..'`; \
179               { test -f $$base.l || test -f $$base.y; } && continue;; \
180             esac; \
181             files="$$files $$file"; \
182           done; \
183           grep -E -l '\bN?_\([^)"]*("|$$)' $$files | sort > $@-2; \
184           diff -u $@-1 $@-2 || exit 1; \
185           rm -f $@-1 $@-2; \
186         fi
187
188 # In a definition of #define AUTHORS "... and ..." where the RHS contains
189 # the English word `and', the string must be marked with `N_ (...)' so that
190 # gettext recognizes it as a string requiring translation.
191 author_mark_check:
192         @grep '^# *define AUTHORS "[^"]* and ' src/*.c |grep -v ' N_ (' && \
193           { echo 'Makefile.maint: enclose the above strings in N_ (...)' 1>&2; \
194             exit 1; } || :
195
196 # Sometimes it is useful to change the PATH environment variable
197 # in Makefiles.  When doing so, it's better not to use the Unix-centric
198 # path separator of `:', but rather the automake-provided `@PATH_SEPARATOR@'.
199 # It'd be better to use `find -print0 ...|xargs -0 ...', but less portable,
200 # and there probably aren't many projects with so many Makefile.am files
201 # that we'd have to worry about limits on command line length.
202 msg = 'Makefile.maint: Do not use `:'\'' above; use @PATH_SEPARATOR@ instead'
203 makefile_path_separator_check:
204         @grep 'PATH=.*:' `find $(srcdir) -name Makefile.am` \
205           && { echo $(msg) 1>&2; exit 1; } || :
206
207 # Check that `make alpha' will not fail at the end of the process.
208 writable-files:
209         if test -d $(release_archive_dir); then :; else                 \
210           mkdir $(release_archive_dir);                                 \
211         fi
212         for file in $(distdir).tar.gz $(xd-delta)                       \
213                     $(release_archive_dir)/$(distdir).tar.gz            \
214                     $(release_archive_dir)/$(xd-delta); do              \
215           test -e $$file || continue;                                   \
216           test -w $$file                                                \
217             || { echo ERROR: $$file is not writable; fail=1; };         \
218         done;                                                           \
219         test "$$fail" && exit 1 || :
220
221 v_etc_file = lib/version-etc.c
222 # Make sure that the copyright date in $(v_etc_file) is up to date.
223 copyright-check:
224         @if test -f $(v_etc_file); then \
225           grep '"Copyright (C) $(shell date +%Y) Free' $(v_etc_file) \
226             >/dev/null \
227           || { echo 'out of date copyright in $(v_etc_file); update it' 1>&2; \
228                exit 1; }; \
229         fi
230
231
232 # Sanity checks with the CVS repository.
233 cvs-tag-check:
234         echo $(this-cvs-tag); \
235         if $(CVS) -n log -h README | grep -e $(this-cvs-tag): >/dev/null; then \
236           echo "$(this-cvs-tag) as already been used; not tagging" 1>&2; \
237           exit 1; \
238         else :; fi
239
240 cvs-diff-check:
241         if $(CVS) diff >cvs-diffs; then                         \
242           rm cvs-diffs;                                         \
243         else                                                    \
244           echo "Some files are locally modified:" 1>&2;         \
245           cat cvs-diffs;                                        \
246           exit 1;                                               \
247         fi
248
249 cvs-check: cvs-diff-check cvs-tag-check
250
251 maintainer-distcheck: changelog-check
252         $(MAKE) distcheck
253         $(MAKE) my-distcheck
254
255
256 # Tag before making distribution.  Also, don't make a distribution if
257 # checks fail.  Also, make sure the NEWS file is up-to-date.
258 # FIXME: use dist-hook/my-dist like distcheck-hook/my-distcheck.
259 cvs-dist: $(local-check) cvs-check maintainer-distcheck
260         $(CVS) update po
261         $(CVS) tag -c $(this-cvs-tag)
262         $(MAKE) dist
263
264 # Use this to make sure we don't run these programs when building
265 # from a virgin tgz file, below.
266 null_AM_MAKEFLAGS = \
267   ACLOCAL=false \
268   AUTOCONF=false \
269   AUTOMAKE=false \
270   AUTOHEADER=false \
271   MAKEINFO=false
272
273 # Detect format-string/arg-list mismatches that would normally be obscured
274 # by the use of _().  The --disable-nls effectively defines away that macro,
275 # and building with CFLAGS='-Wformat -Werror' causes any format warning to be
276 # treated as a failure.
277 TMPDIR ?= /tmp
278 t=$(TMPDIR)/$(PACKAGE)/test
279 my-distcheck: $(local-check)
280         -rm -rf $(t)
281         mkdir -p $(t)
282         GZIP=$(GZIP_ENV) $(AMTAR) -C $(t) -zxf $(distdir).tar.gz
283         cd $(t)/$(distdir) \
284           && ./configure --disable-nls \
285           && $(MAKE) CFLAGS='-Wformat -Werror' \
286               AM_MAKEFLAGS='$(null_AM_MAKEFLAGS)' \
287           && $(MAKE) dvi \
288           && $(MAKE) check \
289           && $(MAKE) distclean
290         (cd $(t) && mv $(distdir) $(distdir).old \
291           && $(AMTAR) -zxf - ) < $(distdir).tar.gz
292         diff -ur $(t)/$(distdir).old $(t)/$(distdir)
293         -rm -rf $(t)
294         @echo "========================"; \
295         echo "$(distdir).tar.gz is ready for distribution"; \
296         echo "========================"
297
298 tgz-md5 = $(shell md5sum < $(my_distdir).tar.gz|sed 's/  -//')
299 tgz-sha1 = $(shell sha1sum < $(my_distdir).tar.gz|sed 's/  -//')
300 bz2-md5 = $(shell md5sum < $(my_distdir).tar.bz2|sed 's/  -//')
301 bz2-sha1 = $(shell sha1sum < $(my_distdir).tar.bz2|sed 's/  -//')
302 xdelta-md5 = $(shell md5sum < $(xd-delta)|sed 's/  -//')
303 xdelta-sha1 = $(shell sha1sum < $(xd-delta)|sed 's/  -//')
304 tgz-size = $(shell du --human $(my_distdir).tar.gz|sed 's/\([MkK]\).*/ \1B/')
305 bz2-size = $(shell du --human $(my_distdir).tar.bz2|sed 's/\([MkK]\).*/ \1B/')
306 xd-size = $(shell du --human $(xd-delta)|sed 's/\([MkK]\).*/ \1B/')
307
308 rel-check:
309         tarz=/tmp/rel-check-tarz-$$$$; \
310         md5_tmp=/tmp/rel-check-md5-$$$$; \
311         set -e; \
312         trap 'status=$$?; rm -f $$tarz $$md5_tmp; exit $$status' 0 1 2 3 15; \
313         wget -q --output-document=$$tarz $(url); \
314         echo "$(md5)  -" > $$md5_tmp; \
315         md5sum -c $$md5_tmp < $$tarz
316
317 prev-tgz = $(PACKAGE)-$(PREV_VERSION).tar.gz
318 xd-delta = $(PACKAGE)-$(PREV_VERSION)-$(VERSION).xdelta
319
320 signatures ?= $(distdir).tar.bz2.asc $(distdir).tar.gz.asc
321 %.asc: %
322         rm -f $@
323         gpg --armor --detach-sign -o $@ $<
324
325 rel-files = $(xd-delta) $(distdir).tar.bz2 $(distdir).tar.gz $(signatures)
326 announcement: NEWS ChangeLog $(rel-files) $(signatures)
327         @./announce-gen                                                 \
328             --release-type=$(RELEASE_TYPE)                              \
329             --package=$(PACKAGE)                                        \
330             --prev=$(PREV_VERSION)                                      \
331             --curr=$(VERSION)                                           \
332             --release-archive-directory=$(release_archive_dir)          \
333             --news=NEWS                                                 \
334             $(addprefix --url-dir=, $(url_dir_list))                    \
335
336
337 ## ---------------- ##
338 ## Updating files.  ##
339 ## ---------------- ##
340
341 WGET = wget
342 ftp-gnu = ftp://ftp.gnu.org/gnu
343 www-gnu = http://www.gnu.org
344
345 # Use mv, if you don't have/want move-if-change.
346 move_if_change ?= move-if-change
347
348
349 # --------------------- #
350 # Updating everything.  #
351 # --------------------- #
352
353 .PHONY: update
354 local_updates ?= wget-update cvs-update po-update
355 update: $(local_updates)
356
357
358 # ------------------- #
359 # Updating PO files.  #
360 # ------------------- #
361
362 po_repo = http://www.iro.umontreal.ca/contrib/po/maint/$(PACKAGE)
363 .PHONY: do-po-update po-update
364 do-po-update:
365         tmppo=/tmp/$(PACKAGE)-$(VERSION)-po &&\
366         rm -rf $$tmppo && \
367         mkdir $$tmppo && \
368         (cd $$tmppo && $(WGET) -r -l1 -nd --no-parent -A '*.po' $(po_repo)) &&\
369         cp $$tmppo/*.po po
370         cd po && $(MAKE) update-po
371         $(MAKE) po-check
372
373 po-update:
374         if test -d "po"; then \
375           $(MAKE) do-po-update; \
376         fi
377
378 # -------------------------- #
379 # Updating GNU build tools.  #
380 # -------------------------- #
381
382 # The following pseudo table associates a local directory and a URL
383 # with each of the files that belongs to some other package and is
384 # regularly updated from the specified URL.
385 wget_files ?= $(srcdir)/config/config.guess \
386               $(srcdir)/config/config.sub \
387               $(srcdir)/src/ansi2knr.c \
388               $(srcdir)/config/texinfo.tex
389 get-targets = $(patsubst %, get-%, $(wget_files))
390
391 config.guess-url_prefix = $(ftp-gnu)/config/
392 config.sub-url_prefix = $(ftp-gnu)/config/
393
394 ansi2knr.c-url_prefix = ftp://ftp.cs.wisc.edu/ghost/
395
396 texinfo.tex-url_prefix = $(ftp-gnu)/texinfo/
397
398 standards.texi-url_prefix = $(www-gnu)/prep/
399 make-stds.texi-url_prefix = $(standards.texi-url_prefix)
400
401 target = $(patsubst get-%, %, $@)
402 url = $($(notdir $(target))-url_prefix)$(notdir $(target))
403
404 .PHONY: $(get-targets)
405 $(get-targets):
406         $(WGET) $(url) -O $(target).t \
407           && $(move_if_change) $(target).t $(target)
408
409 cvs_files ?= $(srcdir)/config/depcomp $(srcdir)/config/missing \
410              $(srcdir)/config/mkinstalldirs \
411              $(srcdir)/config/install-sh $(srcdir)/src/ansi2knr.c
412 automake_repo=:pserver:anoncvs:anoncvs@sources.redhat.com:/cvs/automake
413 .PHONY: wget-update
414 wget-update: $(get-targets)
415
416 .PHONY: cvs-update
417 cvs-update:
418         fail=;                                                          \
419         for f in $(cvs_files); do                                       \
420           test -f $$f || { echo "*** skipping $$f" 1>&2; continue; };   \
421           cvs diff $$f > /dev/null                                      \
422             || { echo "*** $$f is locally modified; skipping it" 1>&2;  \
423                  fail=yes; continue; };                                 \
424           file=$$(basename $$f);                                        \
425           echo checking out $$file...;                                  \
426           $(CVS) -d $(automake_repo) co -p automake/lib/$$file> $$f.t   \
427             && $(move_if_change) $$f.t $$f;                             \
428         done;                                                           \
429         test "$$fail" && exit 1
430
431 define emit-upload-commands
432         echo =====================================
433         echo =====================================
434         echo upload $(PACKAGE) $(PREV_VERSION) $(VERSION)
435         echo '# send the /tmp/announcement e-mail'
436         echo =====================================
437         echo =====================================
438 endef
439
440 $(xd-delta): $(release_archive_dir)/$(prev-tgz) $(distdir).tar.gz
441         xdelta delta -9 $^ $@ || :
442
443 .PHONY: alpha beta major
444 alpha beta major: $(local-check)
445         $(MAKE) cvs-dist
446         $(MAKE) $(xd-delta)
447         $(MAKE) -s announcement RELEASE_TYPE=$@ > /tmp/announce-$(my_distdir)
448         ln $(rel-files) $(release_archive_dir)
449         chmod a-w $(rel-files)
450         echo $(VERSION) > $(prev_version_file)
451         $(CVS) ci -m. $(prev_version_file)
452         @$(emit-upload-commands)