]> git.draconx.ca Git - dxcommon.git/blobdiff - snippet/autotest.mk
fix-gnulib: Improvements for program-only packages.
[dxcommon.git] / snippet / autotest.mk
index b2baa2d09b4f45a2e5f019b636c9c9972898eb85..badfc9f97ce0c11d71c4d83f8a1989fb0a52e596 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright © 2015 Nick Bowler
+# Copyright © 2015,2019-2020 Nick Bowler
 #
 # Automake fragment to hook up a basic Autotest test suite into the build.
 # It is expected that a testsuite.at file exists in $(srcdir).  The
 
 check-local: check-autotest
 check-autotest: testsuite
-       $(SHELL) testsuite $(TESTSUITEFLAGS)
+       $(SHELL) $? $(TESTSUITEFLAGS)
 .PHONY: check-autotest
 
 clean-local: clean-autotest
 clean-autotest:
-       test ! -f testsuite || $(SHELL) testsuite --clean
+       for f in testsuite "$(srcdir)/testsuite"; do \
+         test ! -f "$$f" || { $(SHELL) "$$f" --clean; break; }; \
+       done
 .PHONY: clean-autotest
 
 maintainer-clean-local: maintainer-clean-autotest
 maintainer-clean-autotest:
-       rm -f testsuite package.m4
+       rm -f testsuite testsuite.deps package.m4
 .PHONY: maintainerclean-autotest
 
-package.m4:
+package.m4: $(top_srcdir)/configure.ac
        $(AM_V_GEN) :; { \
          printf 'm4_define([%s], [%s])\n' \
            AT_PACKAGE_NAME      '$(PACKAGE_NAME)' \
@@ -44,22 +46,63 @@ package.m4:
        ; } >$@.tmp
        $(AM_V_at) mv -f $@.tmp $@
 
-testsuite: testsuite.at package.m4
-if !HAVE_AUTOTEST
-       @:; { \
+DX_AUTOTEST_ERROR = @:; { \
          printf 'ERROR: Autotest was not available at configure time.\n'; \
          printf 'You should only need it if you modified the test suite.\n'; \
          printf 'Autotest is part of autom4te, included in the GNU\n'; \
          printf 'Autoconf package: <https://gnu.org/s/autoconf/>\n'; \
-       } 1>&2
-       @false
+       } 1>&2; false
+
+DX_AUTOTEST = $(AUTOTEST) -I$(srcdir) $(ATFLAGS)
+
+testsuite: testsuite.at package.m4
+if !HAVE_AUTOTEST
+       $(DX_AUTOTEST_ERROR)
 endif
-       $(AM_V_GEN) $(AUTOTEST) $(ATFLAGS) -p m4_include -o $@.tmp testsuite.at
-       $(AM_V_at) :; { \
-         $(AUTOTEST) $(ATFLAGS) -t m4_include:'$@: $$1' testsuite.at; \
-         $(AUTOTEST) $(ATFLAGS) -t m4_include:'$$1:' testsuite.at; \
-       } >$(DEPDIR)/$(@F).P
+       $(AM_V_GEN) $(DX_AUTOTEST) -p m4_include -o $@.tmp testsuite.at
+       $(AM_V_at) $(DX_AUTOTEST) -t m4_include:'$$1' -o $@.deps.tmp \
+         testsuite.at
+       $(AM_V_at) exec 3<$@.deps.tmp 4>$(DEPDIR)/$(@F).P; \
+         while read f <&3; do printf '$@: %s\n%s:\n' "$$f" "$$f" >&4; done
+       $(AM_V_at) mv -f $@.deps.tmp $@.deps
        $(AM_V_at) mv -f $@.tmp $@
+testsuite.deps: testsuite
+
+dist-hook: dist-autotest-deps
+dist-autotest-deps: testsuite.deps
+       exec 3<$?; while read f <&3; do \
+         dir=`expr "$$f" : '\(.*\)/'`; \
+         $(MKDIR_P) "$(distdir)/$$dir" && \
+         chmod u+w "$(distdir)/$$dir" && \
+         cp -p "$(srcdir)/$$f" "$(distdir)/$$f" || exit; \
+       done
+.PHONY: dist-autotest-deps
+
+EXTRA_DIST += testsuite testsuite.at testsuite.deps package.m4
+DISTCLEANFILES += atconfig $(DEPDIR)/testsuite.P
 
-EXTRA_DIST += testsuite testsuite.at package.m4
 @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/testsuite.P@am__quote@
+
+# Automake 1.16 and newer use make rules to generate the dependency stubs.
+# Use this opportunity to generate accurate prerequisites from distributed
+# testsuite dependencies, needed so that make knows to rebuild the testsuite
+# when source files are modified in a distribution tarball, or after a make
+# distclean.
+#
+# With older Automake the stubs are generated directly in config.status.
+# Since this rule is ignored things should still work but the build may
+# miss modifications to the testsuite on the first build from a tarball.
+_dx_autotest_depfiles = am--depfiles
+$(_dx_autotest_depfiles): $(DEPDIR)/testsuite.P
+$(DEPDIR)/testsuite.P:
+       @$(MKDIR_P) $(@D)
+       @if test -f $(builddir)/testsuite.deps; then \
+         exec 3<$(builddir)/testsuite.deps; \
+       elif test -f $(srcdir)/testsuite.deps; then \
+         exec 3<$(srcdir)/testsuite.deps; \
+       else \
+         echo '# dummy' >$@-t && exit; \
+       fi; exec 4>$@-t; while read f <&3; do \
+         printf 'testsuite: %s\n%s:\n' "$$f" "$$f" >&4; \
+       done
+       @mv -f $@-t $@