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