1# Most of this is probably too coreutils-centric to be useful to other packages.
2
3bin=bin-$$$$
4
5write_loser = printf '\#!%s\necho $$0: bad path 1>&2; exit 1\n' '$(SHELL)'
6
7tmpdir = $(abs_top_builddir)/tests/torture
8
9t=$(tmpdir)/$(PACKAGE)/test
10pfx=$(t)/i
11
12built_programs := $(sort $(patsubst src/%$(EXEEXT),%,$(bin_PROGRAMS)))
13
14# More than once, tainted build and source directory names would
15# have caused at least one "make check" test to apply "chmod 700"
16# to all directories under $HOME.  Make sure it doesn't happen again.
17tp = $(tmpdir)/taint
18t_prefix = $(tp)/a
19t_taint = '$(t_prefix) b'
20fake_home = $(tp)/home
21
22# When extracting from a distribution tarball, extract using the fastest
23# method possible.  With dist-xz, that means using the *.xz file.
24ifneq ('', $(filter *.xz, $(DIST_ARCHIVES)))
25  tar_decompress_opt_ = J
26  suffix_ = xz
27else
28  ifneq ('', $(filter *.gz, $(DIST_ARCHIVES)))
29    tar_decompress_opt_ = z
30    suffix_ = gz
31  else
32    tar_decompress_opt_ = j
33    suffix_ = bz2
34  endif
35endif
36amtar_extract_ = $(AMTAR) -$(tar_decompress_opt_)xf
37preferred_tarball_ = $(distdir).tar.$(suffix_)
38
39# Ensure that tests run from tainted build and src dir names work,
40# and don't affect anything in $HOME.  Create witness files in $HOME,
41# record their attributes, and build/test.  Then ensure that the
42# witnesses were not affected.
43# Skip this test when using libtool, since libtool-generated scripts
44# cannot deal with a space-tainted srcdir.
45ALL_RECURSIVE_TARGETS += taint-distcheck
46taint-distcheck: $(DIST_ARCHIVES)
47	grep '^[	 ]*LT_INIT' configure.ac >/dev/null && exit 0 || :
48	test -d $(t_taint) && chmod -R 700 $(t_taint) || :
49	-rm -rf $(t_taint) $(fake_home)
50	mkdir -p $(t_prefix) $(t_taint) $(fake_home)
51	$(amtar_extract_) $(preferred_tarball_) -C $(t_taint)
52	mkfifo $(fake_home)/fifo
53	touch $(fake_home)/f
54	mkdir -p $(fake_home)/d/e
55	ls -lR $(fake_home) $(t_prefix) > $(tp)/.ls-before
56	HOME=$(fake_home); export HOME;			\
57	cd $(t_taint)/$(distdir)			\
58	  && ./configure				\
59	  && $(MAKE)					\
60	  && $(MAKE) check				\
61	  && ls -lR $(fake_home) $(t_prefix) > $(tp)/.ls-after \
62	  && diff $(tp)/.ls-before $(tp)/.ls-after	\
63	  && test -d $(t_prefix)
64	rm -rf $(tp)
65
66# Verify that a twisted use of --program-transform-name=PROGRAM works.
67define install-transform-check
68  echo running install-transform-check			\
69    && rm -rf $(pfx)					\
70    && $(MAKE) program_transform_name='s/.*/zyx/'	\
71      prefix=$(pfx) install				\
72    && test "$$(echo $(pfx)/bin/*)" = "$(pfx)/bin/zyx"	\
73    && test "$$(find $(pfx)/share/man -type f|sed 's,.*/,,;s,\..*,,')" = "zyx"
74endef
75
76# Install, then verify that all binaries and man pages are in place.
77# Note that neither the binary, ginstall, nor the [.1 man page is installed.
78define my-instcheck
79  echo running my-instcheck;				\
80  $(MAKE) prefix=$(pfx) install				\
81    && test ! -f $(pfx)/bin/ginstall			\
82    && { fail=0;					\
83      for i in $(built_programs); do			\
84        test "$$i" = ginstall && i=install;		\
85        for j in "$(pfx)/bin/$$i"			\
86                 "$(pfx)/share/man/man1/$$i.1"; do	\
87          case $$j in *'[.1') continue;; esac;		\
88          test -f "$$j" && :				\
89            || { echo "$$j not installed"; fail=1; };	\
90        done;						\
91      done;						\
92      test $$fail = 1 && exit 1 || :;			\
93    }
94endef
95
96# Use this to make sure we don't run these programs when building
97# from a virgin compressed tarball file, below.
98null_AM_MAKEFLAGS ?= \
99  ACLOCAL=false \
100  AUTOCONF=false \
101  AUTOMAKE=false \
102  AUTOHEADER=false \
103  GPERF=false \
104  MAKEINFO=false
105
106ALL_RECURSIVE_TARGETS += my-distcheck
107my-distcheck: $(DIST_ARCHIVES) $(local-check)
108	$(MAKE) syntax-check
109	$(MAKE) check
110	-rm -rf $(t)
111	mkdir -p $(t)
112	$(amtar_extract_) $(preferred_tarball_) -C $(t)
113	(set -e; cd $(t)/$(distdir);			\
114	  ./configure --quiet --enable-gcc-warnings --disable-nls; \
115	  $(MAKE) AM_MAKEFLAGS='$(null_AM_MAKEFLAGS)';	\
116	  $(MAKE) dvi;					\
117	  $(install-transform-check);			\
118	  $(my-instcheck);				\
119	  $(MAKE) distclean				\
120	)
121	(cd $(t) && mv $(distdir) $(distdir).old	\
122	  && $(amtar_extract_) - ) < $(preferred_tarball_)
123# With post-v1.15 automake, "distclean" would fail to remove .deps
124# directories, leading to a spurious failure of the following recursive diff.
125# FIXME: remove this, once automake is fixed.
126	find $(t)/$(distdir).old $(t)/$(distdir) -name .deps | xargs -r rmdir
127	diff -ur $(t)/$(distdir).old $(t)/$(distdir)
128	-rm -rf $(t)
129	rmdir $(tmpdir)/$(PACKAGE) $(tmpdir)
130	@echo "========================"; \
131	echo "ready for distribution:"; \
132	for i in $(DIST_ARCHIVES); do echo "  $$i"; done; \
133	echo "========================"
134