Blame dist-check.mk

Packit 709fb3
# Most of this is probably too coreutils-centric to be useful to other packages.
Packit 709fb3
Packit 709fb3
bin=bin-$$$$
Packit 709fb3
Packit 709fb3
write_loser = printf '\#!%s\necho $$0: bad path 1>&2; exit 1\n' '$(SHELL)'
Packit 709fb3
Packit 709fb3
tmpdir = $(abs_top_builddir)/tests/torture
Packit 709fb3
Packit 709fb3
t=$(tmpdir)/$(PACKAGE)/test
Packit 709fb3
pfx=$(t)/i
Packit 709fb3
Packit 709fb3
built_programs =						\
Packit 709fb3
  $$(echo 'spy:;@echo $$(bin_PROGRAMS)'				\
Packit 709fb3
    | MAKEFLAGS= $(MAKE) -s -f Makefile -f - spy		\
Packit 709fb3
    | fmt -1 | sed 's,$(EXEEXT)$$,,' | sort -u)
Packit 709fb3
Packit 709fb3
# More than once, tainted build and source directory names would
Packit 709fb3
# have caused at least one "make check" test to apply "chmod 700"
Packit 709fb3
# to all directories under $HOME.  Make sure it doesn't happen again.
Packit 709fb3
tp = $(tmpdir)/taint
Packit 709fb3
t_prefix = $(tp)/a
Packit 709fb3
t_taint = '$(t_prefix) b'
Packit 709fb3
fake_home = $(tp)/home
Packit 709fb3
Packit 709fb3
# When extracting from a distribution tarball, extract using the fastest
Packit 709fb3
# method possible.  With dist-xz, that means using the *.xz file.
Packit 709fb3
ifneq ('', $(filter *.xz, $(DIST_ARCHIVES)))
Packit 709fb3
  tar_decompress_opt_ = J
Packit 709fb3
  suffix_ = xz
Packit 709fb3
else
Packit 709fb3
  ifneq ('', $(filter *.gz, $(DIST_ARCHIVES)))
Packit 709fb3
    tar_decompress_opt_ = z
Packit 709fb3
    suffix_ = gz
Packit 709fb3
  else
Packit 709fb3
    tar_decompress_opt_ = j
Packit 709fb3
    suffix_ = bz2
Packit 709fb3
  endif
Packit 709fb3
endif
Packit 709fb3
amtar_extract_ = $(AMTAR) -$(tar_decompress_opt_)xf
Packit 709fb3
preferred_tarball_ = $(distdir).tar.$(suffix_)
Packit 709fb3
Packit 709fb3
# Ensure that tests run from tainted build and src dir names work,
Packit 709fb3
# and don't affect anything in $HOME.  Create witness files in $HOME,
Packit 709fb3
# record their attributes, and build/test.  Then ensure that the
Packit 709fb3
# witnesses were not affected.
Packit 709fb3
# Skip this test when using libtool, since libtool-generated scripts
Packit 709fb3
# cannot deal with a space-tainted srcdir.
Packit 709fb3
ALL_RECURSIVE_TARGETS += taint-distcheck
Packit 709fb3
taint-distcheck: $(DIST_ARCHIVES)
Packit 709fb3
	grep '^[	 ]*LT_INIT' configure.ac >/dev/null && exit 0 || :
Packit 709fb3
	test -d $(t_taint) && chmod -R 700 $(t_taint) || :
Packit 709fb3
	-rm -rf $(t_taint) $(fake_home)
Packit 709fb3
	mkdir -p $(t_prefix) $(t_taint) $(fake_home)
Packit 709fb3
	$(amtar_extract_) $(preferred_tarball_) -C $(t_taint)
Packit 709fb3
	mkfifo $(fake_home)/fifo
Packit 709fb3
	touch $(fake_home)/f
Packit 709fb3
	mkdir -p $(fake_home)/d/e
Packit 709fb3
	ls -lR $(fake_home) $(t_prefix) > $(tp)/.ls-before
Packit 709fb3
	HOME=$(fake_home); export HOME;			\
Packit 709fb3
	cd $(t_taint)/$(distdir)			\
Packit 709fb3
	  && ./configure				\
Packit 709fb3
	  && $(MAKE)					\
Packit 709fb3
	  && $(MAKE) check				\
Packit 709fb3
	  && ls -lR $(fake_home) $(t_prefix) > $(tp)/.ls-after \
Packit 709fb3
	  && diff $(tp)/.ls-before $(tp)/.ls-after	\
Packit 709fb3
	  && test -d $(t_prefix)
Packit 709fb3
	rm -rf $(tp)
Packit 709fb3
Packit 709fb3
# Verify that a twisted use of --program-transform-name=PROGRAM works.
Packit 709fb3
define install-transform-check
Packit 709fb3
  echo running install-transform-check			\
Packit 709fb3
    && rm -rf $(pfx)					\
Packit 709fb3
    && $(MAKE) program_transform_name='s/.*/zyx/'	\
Packit 709fb3
      prefix=$(pfx) install				\
Packit 709fb3
    && test "$$(echo $(pfx)/bin/*)" = "$(pfx)/bin/zyx"	\
Packit 709fb3
    && test "$$(find $(pfx)/share/man -type f|sed 's,.*/,,;s,\..*,,')" = "zyx"
Packit 709fb3
endef
Packit 709fb3
Packit 709fb3
# Install, then verify that all binaries and man pages are in place.
Packit 709fb3
# Note that neither the binary, ginstall, nor the [.1 man page is installed.
Packit 709fb3
define my-instcheck
Packit 709fb3
  echo running my-instcheck;				\
Packit 709fb3
  $(MAKE) prefix=$(pfx) install				\
Packit 709fb3
    && test ! -f $(pfx)/bin/ginstall			\
Packit 709fb3
    && { fail=0;					\
Packit 709fb3
      for i in $(built_programs); do			\
Packit 709fb3
        test "$$i" = ginstall && i=install;		\
Packit 709fb3
        for j in "$(pfx)/bin/$$i"			\
Packit 709fb3
                 "$(pfx)/share/man/man1/$$i.1"; do	\
Packit 709fb3
          case $$j in *'[.1') continue;; esac;		\
Packit 709fb3
          test -f "$$j" && :				\
Packit 709fb3
            || { echo "$$j not installed"; fail=1; };	\
Packit 709fb3
        done;						\
Packit 709fb3
      done;						\
Packit 709fb3
      test $$fail = 1 && exit 1 || :;			\
Packit 709fb3
    }
Packit 709fb3
endef
Packit 709fb3
Packit 709fb3
# The hard-linking for-loop below ensures that there is a bin/ directory
Packit 709fb3
# full of all of the programs under test (except the ones that are required
Packit 709fb3
# for basic Makefile rules), all symlinked to the just-built "false" program.
Packit 709fb3
# This is to ensure that if ever a test neglects to make PATH include
Packit 709fb3
# the build srcdir, these always-failing programs will run.
Packit 709fb3
# Otherwise, it is too easy to test the wrong programs.
Packit 709fb3
# Note that "false" itself is a symlink to true, so it too will malfunction.
Packit 709fb3
define coreutils-path-check
Packit 709fb3
  {							\
Packit 709fb3
    echo running coreutils-path-check;			\
Packit 709fb3
    if test -f $(srcdir)/src/true.c; then		\
Packit 709fb3
      fail=1;						\
Packit 709fb3
      mkdir $(bin)					\
Packit 709fb3
	&& ($(write_loser)) > $(bin)/loser		\
Packit 709fb3
	&& chmod a+x $(bin)/loser			\
Packit 709fb3
	&& for i in $(built_programs); do		\
Packit 709fb3
	       case $$i in				\
Packit 709fb3
		 rm|expr|basename|echo|sort|ls|tr);;	\
Packit 709fb3
		 cat|dirname|mv|wc);;			\
Packit 709fb3
		 *) ln $(bin)/loser $(bin)/$$i;;	\
Packit 709fb3
	       esac;					\
Packit 709fb3
	     done					\
Packit 709fb3
	  && ln -sf ../src/true $(bin)/false		\
Packit 709fb3
	  && PATH=`pwd`/$(bin)$(PATH_SEPARATOR)$$PATH	\
Packit 709fb3
		$(MAKE) -C tests check			\
Packit 709fb3
	  && { test -d gnulib-tests			\
Packit 709fb3
		 && $(MAKE) -C gnulib-tests check	\
Packit 709fb3
		 || :; }				\
Packit 709fb3
	  && rm -rf $(bin)				\
Packit 709fb3
	  && fail=0;					\
Packit 709fb3
    else						\
Packit 709fb3
      fail=0;						\
Packit 709fb3
    fi;							\
Packit 709fb3
    test $$fail = 1 && exit 1 || :;			\
Packit 709fb3
  }
Packit 709fb3
endef
Packit 709fb3
Packit 709fb3
# More generic version of the rule above.
Packit 709fb3
define generic-path-check
Packit 709fb3
  {							\
Packit 709fb3
    echo running generic-path-check;			\
Packit 709fb3
    if test -f /bin/false; then				\
Packit 709fb3
      fail=1;						\
Packit 709fb3
      mkdir $(bin)					\
Packit 709fb3
	&& ($(write_loser)) > $(bin)/loser		\
Packit 709fb3
	&& chmod a+x $(bin)/loser			\
Packit 709fb3
	&& for i in $(built_programs); do		\
Packit 709fb3
	     ln $(bin)/loser $(bin)/$$i;		\
Packit 709fb3
	   done						\
Packit 709fb3
	&& PATH=`pwd`/$(bin)$(PATH_SEPARATOR)$$PATH	\
Packit 709fb3
	     $(MAKE) check				\
Packit 709fb3
	&& { test -d gnulib-tests			\
Packit 709fb3
	       && $(MAKE) -C gnulib-tests check		\
Packit 709fb3
	       || :; }					\
Packit 709fb3
	&& rm -rf $(bin)				\
Packit 709fb3
	&& fail=0;					\
Packit 709fb3
    else						\
Packit 709fb3
      fail=0;						\
Packit 709fb3
    fi;							\
Packit 709fb3
    test $$fail = 1 && exit 1 || :;			\
Packit 709fb3
  }
Packit 709fb3
endef
Packit 709fb3
Packit 709fb3
# Use this to make sure we don't run these programs when building
Packit 709fb3
# from a virgin compressed tarball file, below.
Packit 709fb3
null_AM_MAKEFLAGS ?= \
Packit 709fb3
  ACLOCAL=false \
Packit 709fb3
  AUTOCONF=false \
Packit 709fb3
  AUTOMAKE=false \
Packit 709fb3
  AUTOHEADER=false \
Packit 709fb3
  GPERF=false \
Packit 709fb3
  MAKEINFO=false
Packit 709fb3
Packit 709fb3
ALL_RECURSIVE_TARGETS += my-distcheck
Packit 709fb3
my-distcheck: $(DIST_ARCHIVES) $(local-check)
Packit 709fb3
	$(MAKE) syntax-check
Packit 709fb3
	$(MAKE) check
Packit 709fb3
	-rm -rf $(t)
Packit 709fb3
	mkdir -p $(t)
Packit 709fb3
	$(amtar_extract_) $(preferred_tarball_) -C $(t)
Packit 709fb3
	(set -e; cd $(t)/$(distdir);			\
Packit 709fb3
	  ./configure --quiet --enable-gcc-warnings --disable-nls; \
Packit 709fb3
	  $(MAKE) AM_MAKEFLAGS='$(null_AM_MAKEFLAGS)';	\
Packit 709fb3
	  $(MAKE) dvi;					\
Packit 709fb3
	  $(install-transform-check);			\
Packit 709fb3
	  $(my-instcheck);				\
Packit 709fb3
	  $(coreutils-path-check);			\
Packit 709fb3
	  $(generic-path-check);			\
Packit 709fb3
	  $(MAKE) distclean				\
Packit 709fb3
	)
Packit 709fb3
	(cd $(t) && mv $(distdir) $(distdir).old	\
Packit 709fb3
	  && $(amtar_extract_) - ) < $(preferred_tarball_)
Packit 709fb3
	find $(t)/$(distdir).old $(t)/$(distdir) -name .deps | xargs rmdir
Packit 709fb3
	diff -ur $(t)/$(distdir).old $(t)/$(distdir)
Packit 709fb3
	-rm -rf $(t)
Packit 709fb3
	rmdir $(tmpdir)/$(PACKAGE) $(tmpdir)
Packit 709fb3
	@echo "========================"; \
Packit 709fb3
	echo "ready for distribution:"; \
Packit 709fb3
	for i in $(DIST_ARCHIVES); do echo "  $$i"; done; \
Packit 709fb3
	echo "========================"