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