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