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