# -*-Makefile-*-
# This Makefile fragment tries to be general-purpose enough to be
-# used by at least coreutils, idutils, CPPI, Bison, and Autoconf.
+# used by many projects via the gnulib maintainer-makefile module.
## Copyright (C) 2001-2009 Free Software Foundation, Inc.
##
# ME := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
ME := maint.mk
+# Override this in cfg.mk if you use a non-standard build-aux directory.
+build_aux ?= $(srcdir)/build-aux
+
# Do not save the original name or timestamp in the .tar.gz file.
# Use --rsyncable if available.
gzip_rsyncable := \
$(shell gzip --help 2>/dev/null|grep rsyncable >/dev/null && echo --rsyncable)
GZIP_ENV = '--no-name --best $(gzip_rsyncable)'
+# cfg.mk must define the gpg_key_ID used by this package.
GIT = git
VC = $(GIT)
-VC-tag = git tag -s -m '$(VERSION)'
+VC-tag = git tag -s -m '$(VERSION)' -u '$(gpg_key_ID)'
-VC_LIST = $(srcdir)/build-aux/vc-list-files
+VC_LIST = $(build_aux)/vc-list-files -C $(srcdir)
VC_LIST_EXCEPT = \
- $(VC_LIST) | if test -f .x-$@; then grep -vEf .x-$@; else grep -v ChangeLog; fi
+ $(VC_LIST) | if test -f $(srcdir)/.x-$@; then grep -vEf $(srcdir)/.x-$@; else grep -v ChangeLog; fi
ifeq ($(origin prev_version_file), undefined)
prev_version_file = $(srcdir)/.prev-version
endif
-PREV_VERSION := $(shell cat $(prev_version_file))
+PREV_VERSION := $(shell cat $(prev_version_file) 2>/dev/null)
VERSION_REGEXP = $(subst .,\.,$(VERSION))
PREV_VERSION_REGEXP = $(subst .,\.,$(PREV_VERSION))
## Sanity checks. ##
## --------------- ##
+_cfg_mk := $(shell test -f $(srcdir)/cfg.mk && echo '$(srcdir)/cfg.mk')
+
# Collect the names of rules starting with `sc_'.
syntax-check-rules := $(shell sed -n 's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' \
- $(srcdir)/$(ME) $(srcdir)/cfg.mk)
+ $(srcdir)/$(ME) $(_cfg_mk))
.PHONY: $(syntax-check-rules)
local-checks-available = \
endef
sc_avoid_if_before_free:
- @$(srcdir)/build-aux/useless-if-before-free \
+ @$(build_aux)/useless-if-before-free \
$(useless_free_options) \
- $$($(VC_LIST_EXCEPT)) && \
+ $$($(VC_LIST_EXCEPT) | grep -v useless-if-before-free) && \
{ echo '$(ME): found useless "if" before "free" above' 1>&2; \
exit 1; } || :
{ echo '$(ME): found use of HAVE''_CONFIG_H; remove' \
1>&2; exit 1; } || :
-# Nearly all .c files must include <config.h>.
+# Nearly all .c files must include <config.h>. However, we also permit this
+# via inclusion of a package-specific header, if cfg.mk specified one.
+# config_h_header must be suitable for grep -E.
+config_h_header ?= <config\.h>
sc_require_config_h:
- @if $(VC_LIST_EXCEPT) | grep -l '\.c$$' > /dev/null; then \
- grep -L '^# *include <config\.h>' \
+ @if $(VC_LIST_EXCEPT) | grep -l '\.c$$' > /dev/null; then \
+ grep -EL '^# *include $(config_h_header)' \
$$($(VC_LIST_EXCEPT) | grep '\.c$$') \
| grep . && \
{ echo '$(ME): the above files do not include <config.h>' \
fi
# You must include <config.h> before including any other header file.
+# This can possibly be via a package-specific header, if given by cfg.mk.
sc_require_config_h_first:
@if $(VC_LIST_EXCEPT) | grep -l '\.c$$' > /dev/null; then \
fail=0; \
for i in $$($(VC_LIST_EXCEPT) | grep '\.c$$'); do \
grep '^# *include\>' $$i | sed 1q \
- | grep '^# *include <config\.h>' > /dev/null \
+ | grep -E '^# *include $(config_h_header)' > /dev/null \
|| { echo $$i; fail=1; }; \
done; \
test $$fail = 1 && \
# Require that the final line of each test-lib.sh-using test be this one:
# Exit $fail
# Note: this test requires GNU grep's --label= option.
+Exit_witness_file ?= tests/test-lib.sh
+Exit_base := $(notdir $(Exit_witness_file))
sc_require_test_exit_idiom:
- @if test -f $(srcdir)/tests/test-lib.sh; then \
+ @if test -f $(srcdir)/$(Exit_witness_file); then \
die=0; \
- for i in $$(grep -l -F /../test-lib.sh $$($(VC_LIST) tests)); do \
- tail -n1 $$i | grep '^Exit \$$fail$$' > /dev/null \
+ for i in $$(grep -l -F 'srcdir/$(Exit_base)' \
+ $$($(VC_LIST) tests)); do \
+ tail -n1 $$i | grep '^Exit .' > /dev/null \
&& : || { die=1; echo $$i; } \
done; \
test $$die = 1 && \
{ echo 1>&2 '$(ME): the final line in each of the above is not:'; \
- echo 1>&2 'Exit $$fail'; \
+ echo 1>&2 'Exit something'; \
exit 1; } || :; \
fi
# Update the hash stored above. Do this after each release and
# for any corrections to old entries.
update-NEWS-hash: NEWS
- perl -pi -e 's/^(old_NEWS_hash = ).*/$${1}'"$(NEWS_hash)/" \
+ perl -pi -e 's/^(old_NEWS_hash[ \t]+:?=[ \t]+).*/$${1}'"$(NEWS_hash)/" \
$(srcdir)/cfg.mk
# Ensure that we use only the standard $(VAR) notation,
news-date-check: NEWS
today=`date +%Y-%m-%d`; \
- if head NEWS | grep '^\*.* $(VERSION_REGEXP) ('$$today')' \
+ if head $(srcdir)/NEWS | grep '^\*.* $(VERSION_REGEXP) ('$$today')' \
>/dev/null; then \
:; \
else \
for file in $$($(VC_LIST_EXCEPT)) lib/*.[ch]; do \
test -r $$file || continue; \
case $$file in \
+ *.m4|*.mk) continue ;; \
*.?|*.??) ;; \
*) continue;; \
esac; \
fi
vc-diff-check:
- $(VC) diff > vc-diffs || :
+ (unset CDPATH; cd $(srcdir) && $(VC) diff) > vc-diffs || :
if test -s vc-diffs; then \
cat vc-diffs; \
echo "Some files are locally modified:" 1>&2; \
# Also, make sure the NEWS file is up-to-date.
ALL_RECURSIVE_TARGETS += vc-dist
vc-dist: $(local-check) cvs-check maintainer-distcheck
- XZ_OPT=-9ev $(MAKE) dist
+ XZ_OPT=9ev $(MAKE) dist
# Use this to make sure we don't run these programs when building
# from a virgin tgz file, below.
built_programs = $$(cd src && MAKEFLAGS= $(MAKE) -s built_programs.list)
-warn_cflags = -Dlint -O -Werror -Wall -Wformat -Wshadow -Wpointer-arith
-bin=bin-$$$$
-
-write_loser = printf '\#!%s\necho $$0: bad path 1>&2; exit 1\n' '$(SHELL)'
-
-TMPDIR ?= /tmp
-t=$(TMPDIR)/$(PACKAGE)/test
-pfx=$(t)/i
-
-# More than once, tainted build and source directory names would
-# have caused at least one "make check" test to apply "chmod 700"
-# to all directories under $HOME. Make sure it doesn't happen again.
-tp := $(shell echo "$(TMPDIR)/$(PACKAGE)-$$$$")
-t_prefix = $(tp)/a
-t_taint = '$(t_prefix) b'
-fake_home = $(tp)/home
-
-# Ensure that tests run from tainted build and src dir names work,
-# and don't affect anything in $HOME. Create witness files in $HOME,
-# record their attributes, and build/test. Then ensure that the
-# witnesses were not affected.
-ALL_RECURSIVE_TARGETS += taint-distcheck
-taint-distcheck: $(DIST_ARCHIVES)
- test -d $(t_taint) && chmod -R 700 $(t_taint) || :
- -rm -rf $(t_taint) $(fake_home)
- mkdir -p $(t_prefix) $(t_taint) $(fake_home)
- GZIP=$(GZIP_ENV) $(AMTAR) -C $(t_taint) -zxf $(distdir).tar.gz
- mkfifo $(fake_home)/fifo
- touch $(fake_home)/f
- mkdir -p $(fake_home)/d/e
- ls -lR $(fake_home) $(t_prefix) > $(tp)/.ls-before
- cd $(t_taint)/$(distdir) \
- && ./configure \
- && $(MAKE) \
- && HOME=$(fake_home) $(MAKE) check \
- && ls -lR $(fake_home) $(t_prefix) > $(tp)/.ls-after \
- && diff $(tp)/.ls-before $(tp)/.ls-after \
- && test -d $(t_prefix)
- rm -rf $(tp)
-
-# Verify that a twisted use of --program-transform-name=PROGRAM works.
-define install-transform-check
- echo running install-transform-check \
- && rm -rf $(pfx) \
- && $(MAKE) program_transform_name='s/.*/zyx/' \
- prefix=$(pfx) install \
- && test "$$(echo $(pfx)/bin/*)" = "$(pfx)/bin/zyx" \
- && test "$$(find $(pfx)/share/man -type f|sed 's,.*/,,;s,\..*,,')" = "zyx"
-endef
-
-# Install, then verify that all binaries and man pages are in place.
-# Note that neither the binary, ginstall, nor the ].1 man page is installed.
-define my-instcheck
- $(MAKE) prefix=$(pfx) install \
- && test ! -f $(pfx)/bin/ginstall \
- && { fail=0; \
- for i in $(built_programs); do \
- test "$$i" = ginstall && i=install; \
- for j in "$(pfx)/bin/$$i" \
- "$(pfx)/share/man/man1/$$i.1"; do \
- case $$j in *'[.1') continue;; esac; \
- test -f "$$j" && : \
- || { echo "$$j not installed"; fail=1; }; \
- done; \
- done; \
- test $$fail = 1 && exit 1 || :; \
- }
-endef
-
-define coreutils-path-check
- { \
- if test -f $(srcdir)/src/true.c; then \
- fail=1; \
- mkdir $(bin) \
- && ($(write_loser)) > $(bin)/loser \
- && chmod a+x $(bin)/loser \
- && for i in $(built_programs); do \
- case $$i in \
- rm|expr|basename|echo|sort|ls|tr);; \
- cat|dirname|mv|wc);; \
- *) ln $(bin)/loser $(bin)/$$i;; \
- esac; \
- done \
- && ln -sf ../src/true $(bin)/false \
- && PATH=`pwd`/$(bin)$(PATH_SEPARATOR)$$PATH \
- $(MAKE) -C tests check \
- && { test -d gnulib-tests \
- && $(MAKE) -C gnulib-tests check \
- || :; } \
- && rm -rf $(bin) \
- && fail=0; \
- else \
- fail=0; \
- fi; \
- test $$fail = 1 && exit 1 || :; \
- }
-endef
-
-# Use -Wformat -Werror to detect format-string/arg-list mismatches.
-# Also, check for shadowing problems with -Wshadow, and for pointer
-# arithmetic problems with -Wpointer-arith.
-# These CFLAGS are pretty strict. If you build this target, you probably
-# have to have a recent version of gcc and glibc headers.
-# The hard-linking for-loop below ensures that there is a bin/ directory
-# full of all of the programs under test (except the ones that are required
-# for basic Makefile rules), all symlinked to the just-built "false" program.
-# This is to ensure that if ever a test neglects to make PATH include
-# the build srcdir, these always-failing programs will run.
-# Otherwise, it is too easy to test the wrong programs.
-# Note that "false" itself is a symlink to true, so it too will malfunction.
-ALL_RECURSIVE_TARGETS += my-distcheck
-my-distcheck: $(DIST_ARCHIVES) $(local-check)
- $(MAKE) syntax-check
- $(MAKE) check
- -rm -rf $(t)
- mkdir -p $(t)
- GZIP=$(GZIP_ENV) $(AMTAR) -C $(t) -zxf $(distdir).tar.gz
- cd $(t)/$(distdir) \
- && ./configure --disable-nls \
- && $(MAKE) CFLAGS='$(warn_cflags)' \
- AM_MAKEFLAGS='$(null_AM_MAKEFLAGS)' \
- && $(MAKE) dvi \
- && $(install-transform-check) \
- && $(my-instcheck) \
- && $(coreutils-path-check) \
- && $(MAKE) distclean
- (cd $(t) && mv $(distdir) $(distdir).old \
- && $(AMTAR) -zxf - ) < $(distdir).tar.gz
- diff -ur $(t)/$(distdir).old $(t)/$(distdir)
- -rm -rf $(t)
- @echo "========================"; \
- echo "$(distdir).tar.gz is ready for distribution"; \
- echo "========================"
-
-WGET = wget
-WGETFLAGS = -C off
-
-rel-check:
- tarz=/tmp/rel-check-tarz-$$$$; \
- md5_tmp=/tmp/rel-check-md5-$$$$; \
- set -e; \
- trap 'status=$$?; rm -f $$tarz $$md5_tmp; exit $$status' 0 1 2 3 15; \
- $(WGET) $(WGETFLAGS) -q --output-document=$$tarz $(url); \
- echo "$(md5) -" > $$md5_tmp; \
- md5sum -c $$md5_tmp < $$tarz
-
rel-files = $(DIST_ARCHIVES)
+gnulib_dir ?= $(srcdir)/gnulib
gnulib-version = $$(cd $(gnulib_dir) && git describe)
+bootstrap-tools ?= autoconf,automake,gnulib
announcement: NEWS ChangeLog $(rel-files)
- @./build-aux/announce-gen \
+ @$(build_aux)/announce-gen \
--release-type=$(RELEASE_TYPE) \
--package=$(PACKAGE) \
--prev=$(PREV_VERSION) \
--curr=$(VERSION) \
--gpg-key-id=$(gpg_key_ID) \
--news=NEWS \
- --bootstrap-tools=autoconf,automake,bison,gnulib \
+ --bootstrap-tools=$(bootstrap-tools) \
--gnulib-version=$(gnulib-version) \
--no-print-checksums \
$(addprefix --url-dir=, $(url_dir_list))
ftp-gnu = ftp://ftp.gnu.org/gnu
www-gnu = http://www.gnu.org
-# Use mv, if you don't have/want move-if-change.
-move_if_change ?= move-if-change
-
emit_upload_commands:
@echo =====================================
@echo =====================================
- @echo "$(srcdir)/build-aux/gnupload $(GNUPLOADFLAGS) \\"
+ @echo "$(build_aux)/gnupload $(GNUPLOADFLAGS) \\"
@echo " --to $(gnu_rel_host):$(PACKAGE) \\"
@echo " $(rel-files)"
@echo '# send the /tmp/announcement e-mail'
'* cfg.mk (old_NEWS_hash): Auto-update.'
endef
+.PHONY: no-submodule-changes
+no-submodule-changes:
+ if test -d $(srcdir)/.git; then \
+ diff=$$(cd $(srcdir) && git submodule -q foreach \
+ git diff-index --name-only HEAD) \
+ || exit 1; \
+ case $$diff in '') ;; \
+ *) echo '$(ME): submodule files are locally modified:'; \
+ echo "$$diff"; exit 1;; esac; \
+ else \
+ : ; \
+ fi
+
.PHONY: alpha beta major
ALL_RECURSIVE_TARGETS += alpha beta major
-alpha beta major: $(local-check) writable-files
+alpha beta major: $(local-check) writable-files no-submodule-changes
test $@ = major \
&& { echo $(VERSION) | grep -E '^[0-9]+(\.[0-9]+)+$$' \
|| { echo "invalid version string: $(VERSION)" 1>&2; exit 1;};}\
.PHONY: indent
indent:
indent $(INDENT_SOURCES)
+
+# Run this rule once per year (usually early in January)
+# to update all FSF copyright year lists in your project.
+update-copyright-exclude-regexp ?= (^|/)COPYING$$
+.PHONY: update-copyright
+update-copyright:
+ grep -l -w Copyright $$($(VC_LIST_EXCEPT)) \
+ | grep -v -E '$(update-copyright-exclude-regexp)' \
+ | xargs $(build_aux)/$@