OSDN Git Service

build: accommodate maint.mk, now that it's pulled from gnulib
[android-x86/external-parted.git] / dist-check.mk
1 # Most of this is probably too coreutils-centric to be useful to other packages.
2
3 warn_cflags = -Dlint -O -Werror -Wall -Wformat -Wshadow -Wpointer-arith
4 bin=bin-$$$$
5
6 write_loser = printf '\#!%s\necho $$0: bad path 1>&2; exit 1\n' '$(SHELL)'
7
8 TMPDIR ?= /tmp
9 t=$(TMPDIR)/$(PACKAGE)/test
10 pfx=$(t)/i
11
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 := $(shell echo "$(TMPDIR)/$(PACKAGE)-$$$$")
16 t_prefix = $(tp)/a
17 t_taint = '$(t_prefix) b'
18 fake_home = $(tp)/home
19
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         cd $(t_taint)/$(distdir)                        \
35           && ./configure                                \
36           && $(MAKE)                                    \
37           && HOME=$(fake_home) $(MAKE) check            \
38           && ls -lR $(fake_home) $(t_prefix) > $(tp)/.ls-after \
39           && diff $(tp)/.ls-before $(tp)/.ls-after      \
40           && test -d $(t_prefix)
41         rm -rf $(tp)
42
43 # Verify that a twisted use of --program-transform-name=PROGRAM works.
44 define install-transform-check
45   echo running install-transform-check                  \
46     && rm -rf $(pfx)                                    \
47     && $(MAKE) program_transform_name='s/.*/zyx/'       \
48       prefix=$(pfx) install                             \
49     && test "$$(echo $(pfx)/bin/*)" = "$(pfx)/bin/zyx"  \
50     && test "$$(find $(pfx)/share/man -type f|sed 's,.*/,,;s,\..*,,')" = "zyx"
51 endef
52
53 # Install, then verify that all binaries and man pages are in place.
54 # Note that neither the binary, ginstall, nor the ].1 man page is installed.
55 define my-instcheck
56   $(MAKE) prefix=$(pfx) install                         \
57     && test ! -f $(pfx)/bin/ginstall                    \
58     && { fail=0;                                        \
59       for i in $(built_programs); do                    \
60         test "$$i" = ginstall && i=install;             \
61         for j in "$(pfx)/bin/$$i"                       \
62                  "$(pfx)/share/man/man1/$$i.1"; do      \
63           case $$j in *'[.1') continue;; esac;          \
64           test -f "$$j" && :                            \
65             || { echo "$$j not installed"; fail=1; };   \
66         done;                                           \
67       done;                                             \
68       test $$fail = 1 && exit 1 || :;                   \
69     }
70 endef
71
72 define coreutils-path-check
73   {                                                     \
74     if test -f $(srcdir)/src/true.c; then               \
75       fail=1;                                           \
76       mkdir $(bin)                                      \
77         && ($(write_loser)) > $(bin)/loser              \
78         && chmod a+x $(bin)/loser                       \
79         && for i in $(built_programs); do               \
80                case $$i in                              \
81                  rm|expr|basename|echo|sort|ls|tr);;    \
82                  cat|dirname|mv|wc);;                   \
83                  *) ln $(bin)/loser $(bin)/$$i;;        \
84                esac;                                    \
85              done                                       \
86           && ln -sf ../src/true $(bin)/false            \
87           && PATH=`pwd`/$(bin)$(PATH_SEPARATOR)$$PATH   \
88                 $(MAKE) -C tests check                  \
89           && { test -d gnulib-tests                     \
90                  && $(MAKE) -C gnulib-tests check       \
91                  || :; }                                \
92           && rm -rf $(bin)                              \
93           && fail=0;                                    \
94     else                                                \
95       fail=0;                                           \
96     fi;                                                 \
97     test $$fail = 1 && exit 1 || :;                     \
98   }
99 endef
100
101 # Use -Wformat -Werror to detect format-string/arg-list mismatches.
102 # Also, check for shadowing problems with -Wshadow, and for pointer
103 # arithmetic problems with -Wpointer-arith.
104 # These CFLAGS are pretty strict.  If you build this target, you probably
105 # have to have a recent version of gcc and glibc headers.
106 # The hard-linking for-loop below ensures that there is a bin/ directory
107 # full of all of the programs under test (except the ones that are required
108 # for basic Makefile rules), all symlinked to the just-built "false" program.
109 # This is to ensure that if ever a test neglects to make PATH include
110 # the build srcdir, these always-failing programs will run.
111 # Otherwise, it is too easy to test the wrong programs.
112 # Note that "false" itself is a symlink to true, so it too will malfunction.
113 ALL_RECURSIVE_TARGETS += my-distcheck
114 my-distcheck: $(DIST_ARCHIVES) $(local-check)
115         $(MAKE) syntax-check
116         $(MAKE) check
117         -rm -rf $(t)
118         mkdir -p $(t)
119         GZIP=$(GZIP_ENV) $(AMTAR) -C $(t) -zxf $(distdir).tar.gz
120         cd $(t)/$(distdir)                              \
121           && ./configure --disable-nls                  \
122           && $(MAKE) CFLAGS='$(warn_cflags)'            \
123               AM_MAKEFLAGS='$(null_AM_MAKEFLAGS)'       \
124           && $(MAKE) dvi                                \
125           && $(install-transform-check)                 \
126           && $(my-instcheck)                            \
127           && $(coreutils-path-check)                    \
128           && $(MAKE) distclean
129         (cd $(t) && mv $(distdir) $(distdir).old        \
130           && $(AMTAR) -zxf - ) < $(distdir).tar.gz
131         diff -ur $(t)/$(distdir).old $(t)/$(distdir)
132         -rm -rf $(t)
133         @echo "========================"; \
134         echo "$(distdir).tar.gz is ready for distribution"; \
135         echo "========================"