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