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