3 ## Copyright (C) 2001-2007 Free Software Foundation, Inc.
5 ## This program is free software; you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3, or (at your option)
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ## GNU General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # This is reported not to work with make-3.79.1
19 # ME := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
22 # Do not save the original name or timestamp in the .tar.gz file.
23 # Use --rsyncable if available.
25 $(shell gzip --help 2>/dev/null|grep rsyncable >/dev/null && echo --rsyncable)
26 GZIP_ENV = '--no-name --best $(gzip_rsyncable)'
31 VC-tag = git-tag -s -m '$(VERSION)'
33 CVS_LIST = build-aux/vc-list-files
36 $(CVS_LIST) | if test -f .x-$@; then grep -vEf .x-$@; else grep -v ChangeLog; fi
38 ifeq ($(origin prev_version_file), undefined)
39 prev_version_file = .prev-version
42 PREV_VERSION := $(shell cat $(prev_version_file))
43 VERSION_REGEXP = $(subst .,\.,$(VERSION))
45 tag-package = $(shell echo "$(PACKAGE)" | tr '[:lower:]' '[:upper:]')
46 tag-this-version = $(subst .,_,$(VERSION))
47 this-vc-tag = $(tag-package)-$(tag-this-version)
48 my_distdir = $(PACKAGE)-$(VERSION)
50 # Old releases are stored here.
51 # Used for diffs and xdeltas.
52 release_archive_dir ?= ../release
54 # Prevent programs like 'sort' from considering distinct strings to be equal.
55 # Doing it here saves us from having to set LC_ALL elsewhere in this file.
64 # FIXME: add a check to prohibit definition in src/*.c of symbols defined
65 # in system.h. E.g. today I removed from tail.c a useless definition of
66 # ENOSYS. It was useless because system.h ensures it's defined.
68 # Collect the names of rules starting with `sc_'.
69 syntax-check-rules := $(shell sed -n 's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' $(ME))
70 .PHONY: $(syntax-check-rules)
72 # Checks that don't require cvs.
73 # Run `changelog-check' last, as previous test may reveal problems requiring
74 # new ChangeLog entries.
75 local-checks-available = \
76 po-check copyright-check m4-check author_mark_check \
77 changelog-check patch-check strftime-check $(syntax-check-rules) \
78 makefile_path_separator_check \
79 makefile-check check-AUTHORS
80 .PHONY: $(local-checks-available)
82 local-check := $(filter-out $(local-checks-to-skip), $(local-checks-available))
84 syntax-check: $(local-check)
85 # @grep -nE '# *include <(limits|std(def|arg|bool))\.h>' \
86 # $$(find -type f -name '*.[chly]') && \
87 # { echo '$(ME): found conditional include' 1>&2; \
90 # grep -nE '^# *include <(string|stdlib)\.h>' \
91 # $(srcdir)/{lib,src}/*.[chy] && \
92 # { echo '$(ME): FIXME' 1>&2; \
94 # FIXME: don't allow `#include .strings\.h' anywhere
96 sc_cast_of_argument_to_free:
97 @grep -nE '\<free \(\(' $$($(CVS_LIST_EXCEPT)) && \
98 { echo '$(ME): don'\''t cast free argument' 1>&2; \
101 sc_cast_of_x_alloc_return_value:
102 @grep -nE '\*\) *x(m|c|re)alloc\>' $$($(CVS_LIST_EXCEPT)) && \
103 { echo '$(ME): don'\''t cast x*alloc return value' 1>&2; \
106 sc_cast_of_alloca_return_value:
107 @grep -nE '\*\) *alloca\>' $$($(CVS_LIST_EXCEPT)) && \
108 { echo '$(ME): don'\''t cast alloca return value' 1>&2; \
112 @grep -n '[ ] ' $$($(CVS_LIST_EXCEPT)) && \
113 { echo '$(ME): found SPACE-TAB sequence; remove the SPACE' \
116 # Don't use the old ato* functions in `real' code.
117 # They provide no error checking mechanism.
118 # Instead, use strto* functions.
119 sc_prohibit_atoi_atof:
120 @grep -nE '\<ato([filq]|ll)\>' $$($(CVS_LIST_EXCEPT)) && \
121 { echo '$(ME): do not use ato''f, ato''i, ato''l, ato''ll, or ato''q' \
124 # Using EXIT_SUCCESS as the first argument to error is misleading,
125 # since when that parameter is 0, error does not exit. Use `0' instead.
126 sc_error_exit_success:
127 @grep -nF 'error (EXIT_SUCCESS,' \
128 $$(find -type f -name '*.[chly]') && \
129 { echo '$(ME): found error (EXIT_SUCCESS' 1>&2; \
133 @grep -ni 'file''system' $$($(CVS_LIST_EXCEPT)) && \
134 { echo '$(ME): found use of "file''system";' \
135 'rewrite to use "file system"' 1>&2; \
139 @grep -n 'HAVE''_CONFIG_H' $$($(CVS_LIST_EXCEPT)) && \
140 { echo '$(ME): found use of HAVE''_CONFIG_H; remove' \
143 # Nearly all .c files must include <config.h>.
145 @if $(CVS_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then \
146 grep -L '^# *include <config\.h>' \
147 $$($(CVS_LIST_EXCEPT) | grep '\.c$$') \
149 { echo '$(ME): the above files do not include <config.h>' \
150 1>&2; exit 1; } || :; \
154 # Prohibit the inclusion of assert.h without an actual use of assert.
155 sc_prohibit_assert_without_use:
156 @if $(CVS_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then \
157 files=$$(grep -l '# *include <assert\.h>' \
158 $$($(CVS_LIST_EXCEPT) | grep '\.c$$')) && \
159 grep -L '\<assert (' $$files \
161 { echo "$(ME): the above files include <assert.h> but don't use it" \
162 1>&2; exit 1; } || :; \
167 @grep -nE '\<(HAVE''_FCNTL_H|O''_NDELAY)\>' \
168 $$($(CVS_LIST_EXCEPT)) && \
169 { echo '$(ME): do not use HAVE''_FCNTL_H or O''_NDELAY' \
172 # FIXME: warn about definitions of EXIT_FAILURE, EXIT_SUCCESS, STREQ
174 # Each nonempty line must start with a year number, or a TAB.
176 @grep -n '^[^12 ]' $$(find . -maxdepth 2 -name ChangeLog) && \
177 { echo '$(ME): found unexpected prefix in a ChangeLog' 1>&2; \
180 # Each test must source ./init.sh
181 test_file_names = $(CVS_LIST_EXCEPT) | grep -E '/t[0-9].*\.sh$$'
183 @if grep '^init\.sh:' tests/Makefile.am; then \
184 if $(test_file_names) > /dev/null; then \
185 grep -L '^\. \./init\.sh$$' $$($(test_file_names)) \
187 { echo "$(ME): the above files lack '. ./init.sh'" \
188 1>&2; exit 1; } || :; \
194 # Ensure that dd's definition of LONGEST_SYMBOL stays in sync
195 # with the strings from the two affected variables.
196 dd_c = $(srcdir)/src/dd.c
197 sc_dd_max_sym_length:
198 ifneq ($(wildcard $(dd_c)),)
199 @len=$$( (sed -n '/conversions\[\] =$$/,/^};/p' $(dd_c);\
200 sed -n '/flags\[\] =$$/,/^};/p' $(dd_c) ) \
201 |sed -n '/"/s/^[^"]*"\([^"]*\)".*/\1/p' \
202 | wc --max-line-length); \
203 max=$$(sed -n '/^#define LONGEST_SYMBOL /s///p' $(dd_c) \
204 |tr -d '"' | wc --max-line-length); \
205 if test "$$len" = "$$max"; then :; else \
206 echo 'dd.c: LONGEST_SYMBOL is not longest' 1>&2; \
211 # Many m4 macros names once began with `jm_'.
212 # On 2004-04-13, they were all changed to start with gl_ instead.
213 # Make sure that none are inadvertently reintroduced.
214 sc_prohibit_jm_in_m4:
215 @grep -nE 'jm_[A-Z]' \
216 $$($(CVS_LIST) m4 |grep '\.m4$$'; echo /dev/null) && \
217 { echo '$(ME): do not use jm_ in m4 macro names' \
222 && grep check-root tests/Makefile.am>/dev/null 2>&1; then \
223 t1=sc-root.expected; t2=sc-root.actual; \
224 grep -nl '^PRIV_CHECK_ARG=require-root' \
225 $$($(CVS_LIST) tests) |sed s,tests,., |sort > $$t1; \
226 sed -n 's, cd \([^ ]*\) .*MAKE..check TESTS=\(.*\),./\1/\2,p' \
227 $(srcdir)/tests/Makefile.am |sort > $$t2; \
228 diff -u $$t1 $$t2 || diff=1; \
231 && { echo 'tests/Makefile.am: missing check-root action'>&2; \
235 headers_with_interesting_macro_defs = \
246 # Create a list of regular expressions matching the names
247 # of macros that are guaranteed by parts of gnulib to be defined.
249 @(cd $(srcdir)/lib; \
250 for f in $(headers_with_interesting_macro_defs); do \
252 sed -n '/^# *define \([^_ (][^ (]*\)[ (].*/s//\1/p' $$f; \
255 | grep -Ev 'ATTRIBUTE_NORETURN|SIZE_MAX' \
256 | sed 's/^/^# *define /' \
260 # Don't define macros that we already get from gnulib header files.
261 sc_always_defined_macros: .re-defmac
262 @if test -f $(srcdir)/src/system.h; then \
263 trap 'rc=$$?; rm -f .re-defmac; exit $$rc' 0 1 2 3 15; \
264 grep -f .re-defmac $$($(CVS_LIST)) \
265 && { echo '$(ME): define the above via some gnulib .h file' \
266 1>&2; exit 1; } || :; \
269 # Create a list of regular expressions matching the names
270 # of files included from system.h. Exclude a couple.
272 @sed -n '/^# *include /s///p' $(srcdir)/src/system.h \
273 | grep -Ev 'sys/(param|file)\.h' \
274 | sed 's/ .*//;;s/^["<]/^# *include [<"]/;s/\.h[">]$$/\\.h[">]/' \
278 # Files in src/ should not include directly any of
279 # the headers already included via system.h.
280 sc_system_h_headers: .re-list
281 @if test -f $(srcdir)/src/system.h; then \
282 trap 'rc=$$?; rm -f .re-list; exit $$rc' 0 1 2 3 15; \
283 grep -nE -f .re-list \
284 $$($(CVS_LIST) src | \
285 grep -Ev '((copy|system)\.h|parse-gram\.c)$$') \
286 && { echo '$(ME): the above are already included via system.h'\
287 1>&2; exit 1; } || :; \
292 'solaris[^[:alnum:]]*2\.(7|8|9|[1-9][0-9])|sunos[^[:alnum:]][6-9]' \
293 $$($(CVS_LIST_EXCEPT)) && \
294 { echo '$(ME): found misuse of Sun OS version numbers' 1>&2; \
298 @grep -ni '\<the ''the\>' $$($(CVS_LIST_EXCEPT)) && \
299 { echo '$(ME): found use of "the ''the";' 1>&2; \
306 @grep -n '[ ]$$' $$($(CVS_LIST_EXCEPT)) && \
307 { echo '$(ME): found trailing blank(s)' \
310 # Match lines like the following, but where there is only one space
311 # between the options and the description:
312 # -D, --all-repeated[=delimit-method] print all duplicate lines\n
313 longopt_re = --[a-z][0-9A-Za-z-]*(\[?=[0-9A-Za-z-]*\]?)?
314 sc_two_space_separator_in_usage:
315 @grep -nE '^ *(-[A-Za-z],)? $(longopt_re) [^ ].*\\$$' \
316 $$($(CVS_LIST_EXCEPT)) && \
317 { echo "$(ME): help2man requires at least two spaces between"; \
318 echo "$(ME): an option and its description"; \
321 # Look for diagnostics that aren't marked for translation.
322 # This won't find any for which error's format string is on a separate line.
323 sc_unmarked_diagnostics:
325 '\<error \([^"]*"[^"]*[a-z]{3}' $$($(CVS_LIST_EXCEPT)) \
326 | grep -v '_''(' && \
327 { echo '$(ME): found unmarked diagnostic(s)' 1>&2; \
330 # Avoid useless parentheses like those in this example:
331 # #if defined (SYMBOL) || defined (SYM2)
332 sc_useless_cpp_parens:
333 @grep -n '^# *if .*defined *(' $$($(CVS_LIST_EXCEPT)) && \
334 { echo '$(ME): found useless parentheses in cpp directive' \
337 # Ensure that the c99-to-c89 patch applies cleanly.
339 rm -rf src-c89 $@.1 $@.2
341 (cd src-c89; patch -p2 -V never --fuzz=0) < src/c99-to-c89.diff \
343 if test "$${REGEN_PATCH+set}" = set; then \
344 diff -upr src src-c89 > new-diff || : ; fi
345 grep -v '^patching file ' $@.1 > $@.2 || :
346 msg=ok; test -s $@.2 && msg='fuzzy patch' || : ; \
347 rm -f src-c89/*.o || msg='rm failed'; \
348 $(MAKE) -C src-c89 CFLAGS='-Wdeclaration-after-statement -Werror' \
349 || msg='compile failure with extra options'; \
350 rm -rf src-c89 $@.1 $@.2; \
351 test "$$msg" = ok && : || echo "$$msg" 1>&2; \
354 # Ensure that date's --help output stays in sync with the info
355 # documentation for GNU strftime. The only exception is %N,
356 # which date accepts but GNU strftime does not.
357 extract_char = sed 's/^[^%][^%]*%\(.\).*/\1/'
359 if test -f $(srcdir)/src/date.c; then \
360 grep '^ %. ' $(srcdir)/src/date.c | sort \
361 | $(extract_char) > $@-src; \
363 info libc date calendar format | grep '^ `%.'\' \
364 | $(extract_char); } | sort > $@-info; \
365 diff -u $@-src $@-info || exit 1; \
366 rm -f $@-src $@-info; \
372 # Ensure that we use only the standard $(VAR) notation,
373 # not @...@ in Makefile.am, now that we can rely on automake
374 # to emit a definition for each substituted variable.
376 grep -nE '@[A-Z_0-9]+@' `find . -name Makefile.am` \
377 && { echo 'Makefile.maint: use $$(...), not @...@' 1>&2; exit 1; } || :
379 news-date-check: NEWS
380 today=`date +%Y-%m-%d`; \
381 if head NEWS | grep '^\*.* $(VERSION_REGEXP) ('$$today')' \
385 echo "version or today's date is not in NEWS" 1>&2; \
390 if head ChangeLog | grep 'Version $(VERSION_REGEXP)\.$$' \
394 echo "$(VERSION) not in ChangeLog" 1>&2; \
399 @grep -n 'AC_DEFUN([^[]' m4/*.m4 \
400 && { echo 'Makefile.maint: quote the first arg to AC_DEFUN' 1>&2; \
403 # Verify that all source files using _() are listed in po/POTFILES.in.
404 # FIXME: don't hard-code file names below; use a more general mechanism.
406 if test -f po/POTFILES.in; then \
407 grep -E -v '^(#|$$)' po/POTFILES.in \
408 | grep -v '^src/false\.c$$' | sort > $@-1; \
410 for file in $$($(CVS_LIST_EXCEPT)) lib/*.[ch]; do \
412 djgpp/* | man/*) continue;; \
416 base=`expr " $$file" : ' \(.*\)\..'`; \
417 { test -f $$base.l || test -f $$base.y; } && continue;; \
419 files="$$files $$file"; \
421 grep -E -l '\b(N?_|gettext *)\([^)"]*("|$$)' $$files \
423 diff -u $@-1 $@-2 || exit 1; \
427 # In a definition of #define AUTHORS "... and ..." where the RHS contains
428 # the English word `and', the string must be marked with `N_ (...)' so that
429 # gettext recognizes it as a string requiring translation.
431 @grep -n '^# *define AUTHORS "[^"]* and ' src/*.c |grep -v ' N_ (' && \
432 { echo 'Makefile.maint: enclose the above strings in N_ (...)' 1>&2; \
435 # Sometimes it is useful to change the PATH environment variable
436 # in Makefiles. When doing so, it's better not to use the Unix-centric
437 # path separator of `:', but rather the automake-provided `@PATH_SEPARATOR@'.
438 # It'd be better to use `find -print0 ...|xargs -0 ...', but less portable,
439 # and there probably aren't many projects with so many Makefile.am files
440 # that we'd have to worry about limits on command line length.
441 msg = 'Makefile.maint: Do not use `:'\'' above; use @PATH_SEPARATOR@ instead'
442 makefile_path_separator_check:
443 @grep -n 'PATH=.*:' `find $(srcdir) -name Makefile.am` \
444 && { echo $(msg) 1>&2; exit 1; } || :
446 # Check that `make alpha' will not fail at the end of the process.
448 if test -d $(release_archive_dir); then :; else \
449 mkdir $(release_archive_dir); \
451 for file in $(distdir).tar.gz $(xd-delta) \
452 $(release_archive_dir)/$(distdir).tar.gz \
453 $(release_archive_dir)/$(xd-delta); do \
454 test -e $$file || continue; \
456 || { echo ERROR: $$file is not writable; fail=1; }; \
458 test "$$fail" && exit 1 || :
460 v_etc_file = lib/version-etc.c
461 sample-test = tests/sample-test
462 # Make sure that the copyright date in $(v_etc_file) is up to date.
464 @if test -f $(v_etc_file); then \
465 grep 'enum { COPYRIGHT_YEAR = '$$(date +%Y)' };' $(v_etc_file) \
467 || { echo 'out of date copyright in $(v_etc_file); update it' 1>&2; \
470 @if test -f $(sample-test); then \
471 grep '# Copyright (C) '$$(date +%Y)' Free' $(sample-test) \
473 || { echo 'out of date copyright in $(sample-test); update it' 1>&2; \
478 # Sanity checks with the repository.
479 # Abort early if this tag has already been used.
482 if $(VC) --help | grep CVS; then \
483 $(CVS) -n log -h README|grep -e $(this-vc-tag): >/dev/null \
486 $(GIT) tag -l '^$(this-vc-tag)$$' && used=yes; \
488 if test "$$used" = yes; then \
489 echo "$(this-vc-tag) has already been used; not tagging" 1>&2; \
494 $(VC) diff > vc-diffs || :
495 if test -s vc-diffs; then \
497 echo "Some files are locally modified:" 1>&2; \
503 cvs-check: vc-diff-check vc-tag-check
505 maintainer-distcheck:
510 # Tag before making distribution. Also, don't make a distribution if
511 # checks fail. Also, make sure the NEWS file is up-to-date.
512 # FIXME: use dist-hook/my-dist like distcheck-hook/my-distcheck.
513 vc-dist: $(local-check) cvs-check maintainer-distcheck
514 $(VC-tag) $(this-vc-tag)
517 # Use this to make sure we don't run these programs when building
518 # from a virgin tgz file, below.
519 null_AM_MAKEFLAGS = \
526 warn_cflags = -Dlint -O -Werror -Wall -Wformat -Wshadow -Wpointer-arith
528 # Use -Wformat -Werror to detect format-string/arg-list mismatches.
529 # Also, check for shadowing problems with -Wshadow, and for pointer
530 # arithmetic problems with -Wpointer-arith.
531 # These CFLAGS are pretty strict. If you build this target, you probably
532 # have to have a recent version of gcc and glibc headers.
534 t=$(TMPDIR)/$(PACKAGE)/test
535 my-distcheck: $(local-check)
538 GZIP=$(GZIP_ENV) $(AMTAR) -C $(t) -zxf $(distdir).tar.gz
540 && ./configure --disable-nls \
541 && $(MAKE) CFLAGS='$(warn_cflags)' \
542 AM_MAKEFLAGS='$(null_AM_MAKEFLAGS)' \
546 (cd $(t) && mv $(distdir) $(distdir).old \
547 && $(AMTAR) -zxf - ) < $(distdir).tar.gz
548 diff -ur $(t)/$(distdir).old $(t)/$(distdir)
549 if test -f $(srcdir)/src/c99-to-c89.diff; then \
551 && (cd src && patch -V never --fuzz=0 <c99-to-c89.diff) \
552 && ./configure --disable-largefile \
553 CFLAGS='-Werror -ansi -pedantic -Wno-long-long' \
557 @echo "========================"; \
558 echo "$(distdir).tar.gz is ready for distribution"; \
559 echo "========================"
565 tarz=/tmp/rel-check-tarz-$$$$; \
566 md5_tmp=/tmp/rel-check-md5-$$$$; \
568 trap 'status=$$?; rm -f $$tarz $$md5_tmp; exit $$status' 0 1 2 3 15; \
569 $(WGET) $(WGETFLAGS) -q --output-document=$$tarz $(url); \
570 echo "$(md5) -" > $$md5_tmp; \
571 md5sum -c $$md5_tmp < $$tarz
573 prev-tgz = $(PACKAGE)-$(PREV_VERSION).tar.gz
574 xd-delta = $(PACKAGE)-$(PREV_VERSION)-$(VERSION).xdelta
576 rel-files = $(xd-delta) $(DIST_ARCHIVES)
578 # Approximate the date of last gnulib "update" by the ChangeLog file's
579 # mtime, and provide that date in the announcement.
580 announcement: NEWS ChangeLog $(rel-files)
581 @cl_date=$$(stat --printf @%Y $(gnulib_dir)/ChangeLog); \
582 utc_date=$$(date -u --date $$cl_date '+%Y-%m-%d %T %z'); \
583 ./build-aux/announce-gen \
584 --release-type=$(RELEASE_TYPE) \
585 --package=$(PACKAGE) \
586 --prev=$(PREV_VERSION) \
588 --gpg-key-id=$(gpg_key_ID) \
590 --bootstrap-tools=autoconf,automake,bison,gnulib \
591 --gnulib-snapshot-time-stamp="$$utc_date" \
592 $(addprefix --url-dir=, $(url_dir_list))
594 ## ---------------- ##
595 ## Updating files. ##
596 ## ---------------- ##
598 ftp-gnu = ftp://ftp.gnu.org/gnu
599 www-gnu = http://www.gnu.org
601 # Use mv, if you don't have/want move-if-change.
602 move_if_change ?= move-if-change
604 emit_upload_commands:
605 @echo =====================================
606 @echo =====================================
607 @echo "$(srcdir)/build-aux/gnupload $(GNUPLOADFLAGS) \\"
608 @echo " --to $(gnu_rel_host):$(PACKAGE) \\"
609 @echo " $(rel-files)"
610 @echo '# send the /tmp/announcement e-mail'
611 @echo =====================================
612 @echo =====================================
614 $(xd-delta): $(release_archive_dir)/$(prev-tgz) $(distdir).tar.gz
615 xdelta delta -9 $^ $@ || :
617 .PHONY: alpha beta major
618 alpha beta major: news-date-check changelog-check $(local-check) writable-files
620 && { echo $(VERSION) | grep -E '^[0-9]+(\.[0-9]+)+$$' \
621 || { echo "invalid version string: $(VERSION)" 1>&2; exit 1;};}\
625 $(MAKE) -s announcement RELEASE_TYPE=$@ > /tmp/announce-$(my_distdir)
626 ln $(rel-files) $(release_archive_dir)
627 chmod a-w $(rel-files)
628 $(MAKE) -s emit_upload_commands RELEASE_TYPE=$@
629 echo $(VERSION) > $(prev_version_file)
631 '$(prev_version_file): Record previous version: $(VERSION).' \