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