build: distcheck: do not leave a $TMPDIR/coreutils directory behind
[coreutils.git] / dist-check.mk
blob0299f51784d5c0517453eaafed686818212fcbc8
1 # Most of this is probably too coreutils-centric to be useful to other packages.
3 bin=bin-$$$$
5 write_loser = printf '\#!%s\necho $$0: bad path 1>&2; exit 1\n' '$(SHELL)'
7 tmpdir = $(abs_top_builddir)/tests/torture
9 t=$(tmpdir)/$(PACKAGE)/test
10 pfx=$(t)/i
12 # More than once, tainted build and source directory names would
13 # have caused at least one "make check" test to apply "chmod 700"
14 # to all directories under $HOME. Make sure it doesn't happen again.
15 tp = $(tmpdir)/taint
16 t_prefix = $(tp)/a
17 t_taint = '$(t_prefix) b'
18 fake_home = $(tp)/home
20 # Ensure that tests run from tainted build and src dir names work,
21 # and don't affect anything in $HOME. Create witness files in $HOME,
22 # record their attributes, and build/test. Then ensure that the
23 # witnesses were not affected.
24 ALL_RECURSIVE_TARGETS += taint-distcheck
25 taint-distcheck: $(DIST_ARCHIVES)
26 test -d $(t_taint) && chmod -R 700 $(t_taint) || :
27 -rm -rf $(t_taint) $(fake_home)
28 mkdir -p $(t_prefix) $(t_taint) $(fake_home)
29 GZIP=$(GZIP_ENV) $(AMTAR) -C $(t_taint) -zxf $(distdir).tar.gz
30 mkfifo $(fake_home)/fifo
31 touch $(fake_home)/f
32 mkdir -p $(fake_home)/d/e
33 ls -lR $(fake_home) $(t_prefix) > $(tp)/.ls-before
34 HOME=$(fake_home); export HOME; \
35 cd $(t_taint)/$(distdir) \
36 && ./configure \
37 && $(MAKE) \
38 && $(MAKE) check \
39 && ls -lR $(fake_home) $(t_prefix) > $(tp)/.ls-after \
40 && diff $(tp)/.ls-before $(tp)/.ls-after \
41 && test -d $(t_prefix)
42 rm -rf $(tp)
44 # Verify that a twisted use of --program-transform-name=PROGRAM works.
45 define install-transform-check
46 echo running install-transform-check \
47 && rm -rf $(pfx) \
48 && $(MAKE) program_transform_name='s/.*/zyx/' \
49 prefix=$(pfx) install \
50 && test "$$(echo $(pfx)/bin/*)" = "$(pfx)/bin/zyx" \
51 && test "$$(find $(pfx)/share/man -type f|sed 's,.*/,,;s,\..*,,')" = "zyx"
52 endef
54 # Install, then verify that all binaries and man pages are in place.
55 # Note that neither the binary, ginstall, nor the ].1 man page is installed.
56 define my-instcheck
57 echo running my-instcheck; \
58 $(MAKE) prefix=$(pfx) install \
59 && test ! -f $(pfx)/bin/ginstall \
60 && { fail=0; \
61 for i in $(built_programs); do \
62 test "$$i" = ginstall && i=install; \
63 for j in "$(pfx)/bin/$$i" \
64 "$(pfx)/share/man/man1/$$i.1"; do \
65 case $$j in *'[.1') continue;; esac; \
66 test -f "$$j" && : \
67 || { echo "$$j not installed"; fail=1; }; \
68 done; \
69 done; \
70 test $$fail = 1 && exit 1 || :; \
72 endef
74 define coreutils-path-check
75 { \
76 echo running coreutils-path-check; \
77 if test -f $(srcdir)/src/true.c; then \
78 fail=1; \
79 mkdir $(bin) \
80 && ($(write_loser)) > $(bin)/loser \
81 && chmod a+x $(bin)/loser \
82 && for i in $(built_programs); do \
83 case $$i in \
84 rm|expr|basename|echo|sort|ls|tr);; \
85 cat|dirname|mv|wc);; \
86 *) ln $(bin)/loser $(bin)/$$i;; \
87 esac; \
88 done \
89 && ln -sf ../src/true $(bin)/false \
90 && PATH=`pwd`/$(bin)$(PATH_SEPARATOR)$$PATH \
91 $(MAKE) -C tests check \
92 && { test -d gnulib-tests \
93 && $(MAKE) -C gnulib-tests check \
94 || :; } \
95 && rm -rf $(bin) \
96 && fail=0; \
97 else \
98 fail=0; \
99 fi; \
100 test $$fail = 1 && exit 1 || :; \
102 endef
104 # Use -Wformat -Werror to detect format-string/arg-list mismatches.
105 # Also, check for shadowing problems with -Wshadow, and for pointer
106 # arithmetic problems with -Wpointer-arith.
107 # These CFLAGS are pretty strict. If you build this target, you probably
108 # have to have a recent version of gcc and glibc headers.
109 # The hard-linking for-loop below ensures that there is a bin/ directory
110 # full of all of the programs under test (except the ones that are required
111 # for basic Makefile rules), all symlinked to the just-built "false" program.
112 # This is to ensure that if ever a test neglects to make PATH include
113 # the build srcdir, these always-failing programs will run.
114 # Otherwise, it is too easy to test the wrong programs.
115 # Note that "false" itself is a symlink to true, so it too will malfunction.
116 ALL_RECURSIVE_TARGETS += my-distcheck
117 my-distcheck: $(DIST_ARCHIVES) $(local-check)
118 $(MAKE) syntax-check
119 $(MAKE) check
120 -rm -rf $(t)
121 mkdir -p $(t)
122 GZIP=$(GZIP_ENV) $(AMTAR) -C $(t) -zxf $(distdir).tar.gz
123 cd $(t)/$(distdir) \
124 && ./configure --quiet --enable-gcc-warnings --disable-nls \
125 && $(MAKE) AM_MAKEFLAGS='$(null_AM_MAKEFLAGS)' \
126 && $(MAKE) dvi \
127 && $(install-transform-check) \
128 && $(my-instcheck) \
129 && $(coreutils-path-check) \
130 && $(MAKE) distclean
131 (cd $(t) && mv $(distdir) $(distdir).old \
132 && $(AMTAR) -zxf - ) < $(distdir).tar.gz
133 diff -ur $(t)/$(distdir).old $(t)/$(distdir)
134 -rm -rf $(t)
135 rmdir $(tmpdir)/$(PACKAGE) $(tmpdir)
136 @echo "========================"; \
137 echo "$(distdir).tar.gz is ready for distribution"; \
138 echo "========================"