2 # This Makefile fragment is shared between the coreutils,
3 # CPPI, Bison, and Autoconf.
5 ## Copyright (C) 2001-2006 Free Software Foundation, Inc.
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)
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA
22 # This is reported not to work with make-3.79.1
23 # ME := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
26 # Do not save the original name or timestamp in the .tar.gz file.
28 $(shell gzip --help|grep rsyncable >/dev/null && echo --rsyncable)
29 GZIP_ENV = '--no-name --best $(gzip_rsyncable)'
33 # cvsu is part of the cvsutils package: http://www.red-bean.com/cvsutils/
34 CVS_LIST = $(srcdir)/build-aux/cvsu --find --types=AFGM
36 ifeq ($(origin prev_version_file), undefined)
37 prev_version_file = .prev-version
40 PREV_VERSION := $(shell cat $(prev_version_file))
41 VERSION_REGEXP = $(subst .,\.,$(VERSION))
43 tag-package = $(shell echo "$(PACKAGE)" | tr '[:lower:]' '[:upper:]')
44 tag-this-version = $(subst .,_,$(VERSION))
45 this-cvs-tag = $(tag-package)-$(tag-this-version)
46 my_distdir = $(PACKAGE)-$(VERSION)
48 # Old releases are stored here.
49 # Used for diffs and xdeltas.
50 release_archive_dir ?= ../release
52 # Prevent programs like 'sort' from considering distinct strings to be equal.
53 # Doing it here saves us from having to set LC_ALL elsewhere in this file.
62 # FIXME: add a check to prohibit definition in src/*.c of symbols defined
63 # in system.h. E.g. today I removed from tail.c a useless definition of
64 # ENOSYS. It was useless because system.h ensures it's defined.
66 # Checks that don't require cvs.
67 # Run `changelog-check' last, as previous test may reveal problems requiring
68 # new ChangeLog entries.
69 local-checks-available = \
70 po-check copyright-check writable-files m4-check author_mark_check \
71 changelog-check strftime-check $(syntax-check-rules) \
72 makefile_path_separator_check \
74 .PHONY: $(local-checks-available)
76 local-check = $(filter-out $(local-checks-to-skip), $(local-checks-available))
78 .PHONY: $(syntax-check-rules)
79 syntax-check-rules = \
80 sc_cast_of_argument_to_free \
81 sc_cast_of_x_alloc_return_value \
82 sc_cast_of_alloca_return_value \
83 sc_dd_max_sym_length \
84 sc_error_exit_success \
86 sc_no_if_have_config_h \
88 sc_prohibit_atoi_atof \
89 sc_prohibit_jm_in_m4 \
90 sc_prohibit_assert_without_use \
98 sc_two_space_separator_in_usage \
99 sc_unmarked_diagnostics \
100 sc_useless_cpp_parens
102 syntax-check: $(syntax-check-rules)
103 # @grep -E '# *include <(limits|std(def|arg|bool))\.h>' \
104 # $$(find -type f -name '*.[chly]') && \
105 # { echo '$(ME): found conditional include' 1>&2; \
108 # grep -E '^# *include <(string|stdlib)\.h>' \
109 # $(srcdir)/{lib,src}/*.[chy] && \
110 # { echo '$(ME): FIXME' 1>&2; \
112 # FIXME: don't allow `#include .strings\.h' anywhere
114 sc_cast_of_argument_to_free:
115 @grep -E '\<free \(\(' $(srcdir)/{lib,src}/*.[chly] && \
116 { echo '$(ME): don'\''t cast free argument' 1>&2; \
119 sc_cast_of_x_alloc_return_value:
120 @grep -E --exclude=$(srcdir)/lib/regex.c \
121 '\*\) *x(m|c|re)alloc\>' \
122 $(srcdir)/{lib,src}/*.[chy] && \
123 { echo '$(ME): don'\''t cast x*alloc return value' 1>&2; \
126 sc_cast_of_alloca_return_value:
127 @grep -E '\*\) *alloca\>' \
128 $(srcdir)/src/*.[chy] && \
129 { echo '$(ME): don'\''t cast alloca return value' 1>&2; \
133 @( $(CVS_LIST) ) > /dev/null 2>&1 || : && \
135 $$($(CVS_LIST) | grep -vEf .x-$@ ) && \
136 { echo '$(ME): found SPACE-TAB sequence; remove the SPACE' \
139 # Don't use atoi, atof, atol, atoll, or atoq in `real' code.
140 # They provide no error checking mechanism.
141 # Instead, use strto* functions.
142 sc_prohibit_atoi_atof:
143 @( $(CVS_LIST) ) > /dev/null 2>&1 || : && \
144 grep -E '\<(ato[filq]|atoll)\>' \
145 $$($(CVS_LIST) | grep -vEf .x-$@ ) && \
146 { echo '$(ME): do not use atof, atoi, atol, atoll, or atoq' \
149 # Using EXIT_SUCCESS as the first argument to error is misleading,
150 # since when that parameter is 0, error does not exit. Use `0' instead.
151 sc_error_exit_success:
152 @grep -F 'error (EXIT_SUCCESS,' \
153 $$(find -type f -name '*.[chly]') && \
154 { echo '$(ME): found error (EXIT_SUCCESS' 1>&2; \
158 @grep -i 'filesystem' \
159 $$($(CVS_LIST) | grep -vEf .x-$@ ) && \
160 { echo '$(ME): found use of "filesystem";' \
161 'rewrite to use "file system"' 1>&2; \
164 sc_no_if_have_config_h:
165 @( $(CVS_LIST) ) > /dev/null 2>&1 || : && \
166 grep '^# *if HAVE_CONFIG_H' \
167 $$($(CVS_LIST) | grep -vEf .x-$@ ) && \
168 { echo '$(ME): found use of #if HAVE_CONFIG_H; use #ifdef' \
171 # Nearly all .c files must include <config.h>.
173 @( $(CVS_LIST) ) > /dev/null 2>&1 || : && \
174 grep -L '^# *include <config\.h>' \
175 $$($(CVS_LIST) | grep '\.c$$' | grep -vEf .x-$@ ) \
177 { echo '$(ME): the above files do not include <config.h>' \
180 # Prohibit the inclusion of assert.h without an actual use of assert.
181 sc_prohibit_assert_without_use:
182 @( $(CVS_LIST) ) > /dev/null 2>&1 || : && \
183 grep -L '\<assert (' \
184 $$(grep -l '# *include <assert\.h>' \
185 $$($(CVS_LIST) | grep '\.c$$' | grep -vEf .x-$@ )) \
187 { echo "$(ME): the above files include <assert.h> but don't use it" \
191 @( $(CVS_LIST) ) > /dev/null 2>&1 || : && \
192 grep -E '\<(HAVE_FCNTL_H|O_NDELAY)\>' \
193 $$($(CVS_LIST) | grep -vEf .x-$@ ) && \
194 { echo '$(ME): do not use HAVE_FCNTL_H or O_NDELAY' \
197 # FIXME: warn about definitions of EXIT_FAILURE, EXIT_SUCCESS, STREQ
199 # Each nonempty line must start with a year number, or a TAB.
201 @grep '^[^12 ]' $$(find . -maxdepth 2 -name ChangeLog) && \
202 { echo '$(ME): found unexpected prefix in a ChangeLog' 1>&2; \
205 # Ensure that dd's definition of LONGEST_SYMBOL stays in sync
206 # with the strings from the two affected variables.
207 dd_c = $(srcdir)/src/dd.c
208 sc_dd_max_sym_length:
209 @test -f $(dd_c) || exit 0; \
210 len=$$( (sed -n '/conversions\[\] =$$/,/^};/p' $(dd_c); \
211 sed -n '/flags\[\] =$$/,/^};/p' $(dd_c) ) \
212 |sed -n '/"/s/^[^"]*"\([^"]*\)".*/\1/p' \
213 | wc --max-line-length); \
214 max=$$(sed -n '/^#define LONGEST_SYMBOL /s///p' $(dd_c) \
215 |tr -d '"' | wc --max-line-length); \
216 if test "$$len" = "$$max"; then :; else \
217 echo 'dd.c: LONGEST_SYMBOL is not longest' 1>&2; \
221 # Many m4 macros names once began with `jm_'.
222 # On 2004-04-13, they were all changed to start with gl_ instead.
223 # Make sure that none are inadvertently reintroduced.
224 sc_prohibit_jm_in_m4:
225 @( $(CVS_LIST) ) > /dev/null 2>&1 || : && \
227 $$($(CVS_LIST) $(srcdir)/m4 |grep '\.m4$$') && \
228 { echo '$(ME): do not use jm_ in m4 macro names' \
232 @t1=sc-root.expected; t2=sc-root.actual; \
233 grep -l '^PRIV_CHECK_ARG=require-root' \
234 $$($(CVS_LIST) tests) |sed s,tests,., |sort > $$t1; \
235 sed -n 's, cd \([^ ]*\) .*MAKE..check TESTS=\(.*\),./\1/\2,p' \
236 $(srcdir)/tests/Makefile.am |sort > $$t2; \
237 diff -u $$t1 $$t2 || diff=1; \
240 && { echo 'tests/Makefile.am: missing check-root action'>&2; \
243 # Create a list of regular expressions matching the names
244 # of files included from system.h. Exclude a couple.
246 @sed -n '/^# *include /s///p' $(srcdir)/src/system.h \
247 | grep -Ev 'sys/(param|file)\.h' \
248 | sed 's/ .*//;;s/^["<]/^# *include [<"]/;s/\.h[">]$$/\\.h[">]/' \
252 # Files in src/ should not include directly any of
253 # the headers already included via system.h.
254 sc_system_h_headers: .re-list
255 @if test -f $(srcdir)/src/system.h; then \
256 ( $(CVS_LIST) ) > /dev/null 2>&1 || exit 0; \
257 trap 'rc=$$?; rm -f .re-list; exit $$rc' 0 1 2 3 15; \
258 grep -E -f .re-list \
259 $$($(CVS_LIST) src | grep -Ev '(copy|system)\.h$$') \
260 && { echo '$(ME): the above are already included via system.h'\
261 1>&2; exit 1; } || :; \
265 @( $(CVS_LIST) ) > /dev/null 2>&1 || : && \
267 'solaris[^[:alnum:]]*2\.(7|8|9|[1-9][0-9])|sunos[^[:alnum:]][6-9]' \
268 $$($(CVS_LIST) | grep -vEf .x-$@ ) && \
269 { echo '$(ME): found misuse of Sun OS version numbers' 1>&2; \
276 @( $(CVS_LIST) ) > /dev/null 2>&1 || : && \
278 $$($(CVS_LIST) | grep -vEf .x-$@ ) && \
279 { echo '$(ME): found trailing blank(s)' \
282 sc_two_space_separator_in_usage:
283 @( $(CVS_LIST) ) > /dev/null 2>&1 || : && \
284 grep '^ *--[a-z][0-9A-Za-z-]* [^ ].*\\$$' \
285 $$($(CVS_LIST) | grep 'src/.*\.c$$' | grep -vEf .x-$@) && \
286 { echo "$(ME): help2man requires at least two spaces between"; \
287 echo "$(ME): an option and its description"; \
290 # Look for diagnostics that aren't marked for translation.
291 # This won't find any for which error's format string is on a separate line.
292 sc_unmarked_diagnostics:
293 @( $(CVS_LIST) ) > /dev/null 2>&1 || : && \
295 '\<error \([^"]*"[^"]*[a-z]{3}' \
296 $$($(CVS_LIST) | grep -vEf .x-$@ ) \
298 { echo '$(ME): found unmarked diagnostic(s)' 1>&2; \
301 # Avoid useless parentheses like those in this example:
302 # #if defined (SYMBOL) || defined (SYM2)
303 sc_useless_cpp_parens:
304 @( $(CVS_LIST) ) > /dev/null 2>&1 || : && \
305 grep '^# *if .*defined *(' \
306 $$($(CVS_LIST) | grep -vEf .x-$@ ) && \
307 { echo '$(ME): found useless parentheses in cpp directive' \
310 # Ensure that date's --help output stays in sync with the info
311 # documentation for GNU strftime. The only exception is %N,
312 # which date accepts but GNU strftime does not.
313 extract_char = sed 's/^[^%][^%]*%\(.\).*/\1/'
315 if test -f $(srcdir)/src/date.c; then \
316 grep '^ %. ' $(srcdir)/src/date.c | sort \
317 | $(extract_char) > $@-src; \
319 info libc date calendar format | grep '^ `%.'\' \
320 | $(extract_char); } | sort > $@-info; \
321 diff -u $@-src $@-info || exit 1; \
322 rm -f $@-src $@-info; \
325 # Ensure that we use only the standard $(VAR) notation,
326 # not @...@ in Makefile.am, now that we can rely on automake
327 # to emit a definition for each substituted variable.
329 grep -E '@[A-Z_0-9]+@' `find . -name Makefile.am` \
330 && { echo 'Makefile.maint: use $$(...), not @...@' 1>&2; exit 1; } || :
332 news-date-check: NEWS
333 today=`date +%Y-%m-%d`; \
334 if head NEWS | grep '^\*.* $(VERSION_REGEXP) ('$$today')' \
338 echo "version or today's date is not in NEWS" 1>&2; \
343 if head ChangeLog | grep 'Version $(VERSION_REGEXP)\.$$' \
347 echo "$(VERSION) not in ChangeLog" 1>&2; \
352 @grep 'AC_DEFUN([^[]' m4/*.m4 \
353 && { echo 'Makefile.maint: quote the first arg to AC_DEFUN' 1>&2; \
356 # Verify that all source files using _() are listed in po/POTFILES.in.
357 # FIXME: don't hard-code src/false.c below; use a more general mechanism.
359 ( $(CVS_LIST) ) > /dev/null 2>&1 || : && \
360 if test -f po/POTFILES.in; then \
361 grep -E -v '^(#|$$)' po/POTFILES.in \
362 | grep -v '^src/false\.c$$' | sort > $@-1; \
364 for file in $$($(CVS_LIST) lib src | grep '\.[chly]$$'); do \
367 base=`expr " $$file" : ' \(.*\)\..'`; \
368 { test -f $$base.l || test -f $$base.y; } && continue;; \
370 files="$$files $$file"; \
372 grep -E -l '\bN?_\([^)"]*("|$$)' $$files | sort > $@-2; \
373 diff -u $@-1 $@-2 || exit 1; \
377 # In a definition of #define AUTHORS "... and ..." where the RHS contains
378 # the English word `and', the string must be marked with `N_ (...)' so that
379 # gettext recognizes it as a string requiring translation.
381 @grep '^# *define AUTHORS "[^"]* and ' src/*.c |grep -v ' N_ (' && \
382 { echo 'Makefile.maint: enclose the above strings in N_ (...)' 1>&2; \
385 # Sometimes it is useful to change the PATH environment variable
386 # in Makefiles. When doing so, it's better not to use the Unix-centric
387 # path separator of `:', but rather the automake-provided `@PATH_SEPARATOR@'.
388 # It'd be better to use `find -print0 ...|xargs -0 ...', but less portable,
389 # and there probably aren't many projects with so many Makefile.am files
390 # that we'd have to worry about limits on command line length.
391 msg = 'Makefile.maint: Do not use `:'\'' above; use @PATH_SEPARATOR@ instead'
392 makefile_path_separator_check:
393 @grep 'PATH=.*:' `find $(srcdir) -name Makefile.am` \
394 && { echo $(msg) 1>&2; exit 1; } || :
396 # Check that `make alpha' will not fail at the end of the process.
398 if test -d $(release_archive_dir); then :; else \
399 mkdir $(release_archive_dir); \
401 for file in $(distdir).tar.gz $(xd-delta) \
402 $(release_archive_dir)/$(distdir).tar.gz \
403 $(release_archive_dir)/$(xd-delta); do \
404 test -e $$file || continue; \
406 || { echo ERROR: $$file is not writable; fail=1; }; \
408 test "$$fail" && exit 1 || :
410 v_etc_file = lib/version-etc.c
411 # Make sure that the copyright date in $(v_etc_file) is up to date.
413 @if test -f $(v_etc_file); then \
414 grep 'enum { COPYRIGHT_YEAR = '$$(date +%Y)' };' $(v_etc_file) \
416 || { echo 'out of date copyright in $(v_etc_file); update it' 1>&2; \
421 # Sanity checks with the CVS repository.
423 echo $(this-cvs-tag); \
424 if $(CVS) -n log -h README | grep -e $(this-cvs-tag): >/dev/null; then \
425 echo "$(this-cvs-tag) as already been used; not tagging" 1>&2; \
430 if $(CVS) diff >cvs-diffs; then \
433 echo "Some files are locally modified:" 1>&2; \
438 cvs-check: cvs-diff-check cvs-tag-check
440 maintainer-distcheck: changelog-check
445 # Tag before making distribution. Also, don't make a distribution if
446 # checks fail. Also, make sure the NEWS file is up-to-date.
447 # FIXME: use dist-hook/my-dist like distcheck-hook/my-distcheck.
448 cvs-dist: $(local-check) cvs-check maintainer-distcheck
450 $(CVS) tag -c $(this-cvs-tag)
453 # Use this to make sure we don't run these programs when building
454 # from a virgin tgz file, below.
455 null_AM_MAKEFLAGS = \
462 # Detect format-string/arg-list mismatches that would normally be obscured
463 # by the use of _(). The --disable-nls effectively defines away that macro,
464 # and building with CFLAGS='-Wformat -Werror' causes any format warning to be
465 # treated as a failure. Also, check for shadowing problems with -Wshadow.
466 # These CFLAGS are pretty strict. If you build this target, you probably
467 # have to have a recent version of gcc and glibc headers.
469 t=$(TMPDIR)/$(PACKAGE)/test
470 my-distcheck: $(local-check) $(release_archive_dir)/$(prev-tgz)
473 GZIP=$(GZIP_ENV) $(AMTAR) -C $(t) -zxf $(distdir).tar.gz
475 && ./configure --disable-nls \
476 && $(MAKE) CFLAGS='-Werror -Wall -Wformat -Wshadow' \
477 AM_MAKEFLAGS='$(null_AM_MAKEFLAGS)' \
481 (cd $(t) && mv $(distdir) $(distdir).old \
482 && $(AMTAR) -zxf - ) < $(distdir).tar.gz
483 diff -ur $(t)/$(distdir).old $(t)/$(distdir)
485 @echo "========================"; \
486 echo "$(distdir).tar.gz is ready for distribution"; \
487 echo "========================"
493 tarz=/tmp/rel-check-tarz-$$$$; \
494 md5_tmp=/tmp/rel-check-md5-$$$$; \
496 trap 'status=$$?; rm -f $$tarz $$md5_tmp; exit $$status' 0 1 2 3 15; \
497 $(WGET) $(WGETFLAGS) -q --output-document=$$tarz $(url); \
498 echo "$(md5) -" > $$md5_tmp; \
499 md5sum -c $$md5_tmp < $$tarz
501 prev-tgz = $(PACKAGE)-$(PREV_VERSION).tar.gz
502 xd-delta = $(PACKAGE)-$(PREV_VERSION)-$(VERSION).xdelta
504 rel-files = $(xd-delta) $(DIST_ARCHIVES)
505 announcement: NEWS ChangeLog $(rel-files)
507 --release-type=$(RELEASE_TYPE) \
508 --package=$(PACKAGE) \
509 --prev=$(PREV_VERSION) \
511 --release-archive-directory=$(release_archive_dir) \
512 --gpg-key-id=$(gpg_key_ID) \
514 $(addprefix --url-dir=, $(url_dir_list)) \
517 ## ---------------- ##
518 ## Updating files. ##
519 ## ---------------- ##
521 ftp-gnu = ftp://ftp.gnu.org/gnu
522 www-gnu = http://www.gnu.org
524 # Use mv, if you don't have/want move-if-change.
525 move_if_change ?= move-if-change
528 # --------------------- #
529 # Updating everything. #
530 # --------------------- #
533 local_updates ?= wget-update cvs-update po-update
534 update: $(local_updates)
537 # ------------------- #
538 # Updating PO files. #
539 # ------------------- #
541 po_repo = http://www.iro.umontreal.ca/contrib/po/maint/$(PACKAGE)
542 .PHONY: do-po-update po-update
544 tmppo=/tmp/$(PACKAGE)-$(VERSION)-po &&\
548 $(WGET) $(WGETFLAGS) -r -l1 -nd --no-parent -A '*.po' $(po_repo)) &&\
550 cd po && $(MAKE) update-po
554 if test -d "po"; then \
555 $(MAKE) do-po-update; \
558 # -------------------------- #
559 # Updating GNU build tools. #
560 # -------------------------- #
562 # The following pseudo table associates a local directory and a URL
563 # with each of the files that belongs to some other package and is
564 # regularly updated from the specified URL.
566 $(srcdir)/build-aux/config.guess \
567 $(srcdir)/build-aux/config.sub \
568 $(srcdir)/build-aux/texinfo.tex \
569 $(srcdir)/src/ansi2knr.c
571 get-targets = $(patsubst %, get-%, $(wget_files))
573 config.guess-url_prefix = $(ftp-gnu)/build-aux/
574 config.sub-url_prefix = $(ftp-gnu)/build-aux/
576 ansi2knr.c-url_prefix = ftp://ftp.cs.wisc.edu/ghost/
578 texinfo.tex-url_prefix = $(ftp-gnu)/texinfo/
580 standards.texi-url_prefix = $(www-gnu)/prep/
581 make-stds.texi-url_prefix = $(standards.texi-url_prefix)
583 target = $(patsubst get-%, %, $@)
584 url = $($(notdir $(target))-url_prefix)$(notdir $(target))
586 .PHONY: $(get-targets)
588 $(WGET) $(WGETFLAGS) $(url) -O $(target).t \
589 && $(move_if_change) $(target).t $(target)
592 $(srcdir)/build-aux/depcomp \
593 $(srcdir)/build-aux/install-sh \
594 $(srcdir)/build-aux/missing \
595 $(srcdir)/build-aux/mkinstalldirs \
596 $(srcdir)/src/ansi2knr.c
597 automake_repo=:pserver:anoncvs:anoncvs@sources.redhat.com:/cvs/automake
599 wget-update: $(get-targets)
604 for f in $(cvs_files); do \
605 test -f $$f || { echo "*** skipping $$f" 1>&2; continue; }; \
606 cvs diff $$f > /dev/null \
607 || { echo "*** $$f is locally modified; skipping it" 1>&2; \
608 fail=yes; continue; }; \
609 file=$$(basename $$f); \
610 echo checking out $$file...; \
611 $(CVS) -d $(automake_repo) co -p automake/lib/$$file> $$f.t \
612 && $(move_if_change) $$f.t $$f; \
614 test "$$fail" && exit 1
616 emit_upload_commands:
617 @echo =====================================
618 @echo =====================================
619 @echo "$(srcdir)/gnupload $(GNUPLOADFLAGS) \\"
620 @echo " --to $(gnu_rel_host):coreutils \\"
621 @echo " $(rel-files)"
622 @echo '# send the /tmp/announcement e-mail'
623 @echo =====================================
624 @echo =====================================
626 $(xd-delta): $(release_archive_dir)/$(prev-tgz) $(distdir).tar.gz
627 xdelta delta -9 $^ $@ || :
629 .PHONY: alpha beta major
630 alpha beta major: news-date-check $(local-check)
633 $(MAKE) -s announcement RELEASE_TYPE=$@ > /tmp/announce-$(my_distdir)
634 ln $(rel-files) $(release_archive_dir)
635 chmod a-w $(rel-files)
636 $(MAKE) -s emit_upload_commands RELEASE_TYPE=$@
637 echo $(VERSION) > $(prev_version_file)
638 $(CVS) ci -m. $(prev_version_file)