OSDN Git Service

c8ae32c7023385cc4a9179e7aca8b311eadac11c
[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 bin=bin-$$$$
4
5 write_loser = printf '\#!%s\necho $$0: bad path 1>&2; exit 1\n' '$(SHELL)'
6
7 tmpdir = $(abs_top_builddir)/tests/torture
8
9 t=$(tmpdir)/$(PACKAGE)/test
10 pfx=$(t)/i
11
12 built_programs = $$(cd src && MAKEFLAGS= $(MAKE) -s built_programs.list)
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.
17 tp = $(tmpdir)/taint
18 t_prefix = $(tp)/a
19 t_taint = '$(t_prefix) b'
20 fake_home = $(tp)/home
21
22 # Ensure that tests run from tainted build and src dir names work,
23 # and don't affect anything in $HOME.  Create witness files in $HOME,
24 # record their attributes, and build/test.  Then ensure that the
25 # witnesses were not affected.
26 # Skip this test when using libtool, since libtool-generated scripts
27 # cannot deal with a space-tainted srcdir.
28 ALL_RECURSIVE_TARGETS += taint-distcheck
29 taint-distcheck: $(DIST_ARCHIVES)
30         grep '^[         ]*LT_INIT' configure.ac >/dev/null && exit 0
31         test -d $(t_taint) && chmod -R 700 $(t_taint) || :
32         -rm -rf $(t_taint) $(fake_home)
33         mkdir -p $(t_prefix) $(t_taint) $(fake_home)
34         GZIP=$(GZIP_ENV) $(AMTAR) -C $(t_taint) -zxf $(distdir).tar.gz
35         mkfifo $(fake_home)/fifo
36         touch $(fake_home)/f
37         mkdir -p $(fake_home)/d/e
38         ls -lR $(fake_home) $(t_prefix) > $(tp)/.ls-before
39         HOME=$(fake_home); export HOME;                 \
40         cd $(t_taint)/$(distdir)                        \
41           && ./configure                                \
42           && $(MAKE)                                    \
43           && $(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)
48
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)/sbin/*)" = "$(pfx)/sbin/zyx"        \
56     && test "$$(find $(pfx)/share/man -type f|sed 's,.*/,,;s,\..*,,')" = "zyx"
57 endef
58
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   echo running my-instcheck;                            \
63   $(MAKE) prefix=$(pfx) install                         \
64     && test ! -f $(pfx)/bin/ginstall                    \
65     && { fail=0;                                        \
66       for i in $(built_programs); do                    \
67         test "$$i" = ginstall && i=install;             \
68         for j in "$(pfx)/bin/$$i"                       \
69                  "$(pfx)/share/man/man1/$$i.1"; do      \
70           case $$j in *'[.1') continue;; esac;          \
71           test -f "$$j" && :                            \
72             || { echo "$$j not installed"; fail=1; };   \
73         done;                                           \
74       done;                                             \
75       test $$fail = 1 && exit 1 || :;                   \
76     }
77 endef
78
79 # The hard-linking for-loop below ensures that there is a bin/ directory
80 # full of all of the programs under test (except the ones that are required
81 # for basic Makefile rules), all symlinked to the just-built "false" program.
82 # This is to ensure that if ever a test neglects to make PATH include
83 # the build srcdir, these always-failing programs will run.
84 # Otherwise, it is too easy to test the wrong programs.
85 # Note that "false" itself is a symlink to true, so it too will malfunction.
86 define coreutils-path-check
87   {                                                     \
88     echo running coreutils-path-check;                  \
89     if test -f $(srcdir)/src/true.c; then               \
90       fail=1;                                           \
91       mkdir $(bin)                                      \
92         && ($(write_loser)) > $(bin)/loser              \
93         && chmod a+x $(bin)/loser                       \
94         && for i in $(built_programs); do               \
95                case $$i in                              \
96                  rm|expr|basename|echo|sort|ls|tr);;    \
97                  cat|dirname|mv|wc);;                   \
98                  *) ln $(bin)/loser $(bin)/$$i;;        \
99                esac;                                    \
100              done                                       \
101           && ln -sf ../src/true $(bin)/false            \
102           && PATH=`pwd`/$(bin)$(PATH_SEPARATOR)$$PATH   \
103                 $(MAKE) -C tests check                  \
104           && { test -d gnulib-tests                     \
105                  && $(MAKE) -C gnulib-tests check       \
106                  || :; }                                \
107           && rm -rf $(bin)                              \
108           && fail=0;                                    \
109     else                                                \
110       fail=0;                                           \
111     fi;                                                 \
112     test $$fail = 1 && exit 1 || :;                     \
113   }
114 endef
115
116 # Use this to make sure we don't run these programs when building
117 # from a virgin tgz file, below.
118 null_AM_MAKEFLAGS ?= \
119   ACLOCAL=false \
120   AUTOCONF=false \
121   AUTOMAKE=false \
122   AUTOHEADER=false \
123   GPERF=false \
124   LIBTOOL=false \
125   MAKEINFO=false
126
127 ALL_RECURSIVE_TARGETS += my-distcheck
128 my-distcheck: $(DIST_ARCHIVES) $(local-check)
129         $(MAKE) syntax-check
130         $(MAKE) check
131         -rm -rf $(t)
132         mkdir -p $(t)
133         GZIP=$(GZIP_ENV) $(AMTAR) -C $(t) -zxf $(distdir).tar.gz
134         cd $(t)/$(distdir)                              \
135           && ./configure --quiet --enable-gcc-warnings --disable-nls \
136           && $(MAKE) AM_MAKEFLAGS='$(null_AM_MAKEFLAGS)' \
137           && $(MAKE) dvi                                \
138           && $(install-transform-check)                 \
139           && $(my-instcheck)                            \
140           && $(coreutils-path-check)                    \
141           && $(MAKE) distclean
142         (cd $(t) && mv $(distdir) $(distdir).old        \
143           && $(AMTAR) -zxf - ) < $(distdir).tar.gz
144         diff -ur $(t)/$(distdir).old $(t)/$(distdir)
145         -rm -rf $(t)
146         rmdir $(tmpdir)/$(PACKAGE) $(tmpdir)
147         @echo "========================"; \
148         echo "$(distdir).tar.gz is ready for distribution"; \
149         echo "========================"