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