]> git.draconx.ca Git - dxcommon.git/blobdiff - snippet/autotest.mk
Import getline helper from cdecl99.
[dxcommon.git] / snippet / autotest.mk
index 293a85860976c8a8fd4f97d58c3427733f2acd22..4e02f0be045fd0defa28fd62e0618ffe04f8b627 100644 (file)
@@ -1,17 +1,18 @@
-# Copyright © 2015 Nick Bowler
+# Copyright © 2015,2019-2023 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
-# testsuite will be output to $(builddir)/testsuite.
+# 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 testsuite will be output to $(builddir)/testsuite.
+#
+# The DX_AUTOMAKE_COMPAT macro must be expanded by configure.ac to
+# provide necessary substitutions.
 #
 # You must define the AUTOTEST variable to the Autotest program (normally,
-# this is autom4te -l autotest).  The DX_PROG_AUTOTEST macro can be used
-# to set this automatically.  You must also define the HAVE_AUTOTEST Automake
-# conditional which controls whether the testsuite-generating rules are
-# enabled.  If DX_PROG_AUTOTEST is used, this may be set like:
+# this is autom4te -l autotest).  You must also define the HAVE_AUTOTEST
+# Automake conditional which controls whether the testsuite-generating
+# rules are enabled (that is, if Autotest is available and works).
 #
-#   DX_PROG_AUTOTEST
-#   AM_CONDITIONAL([HAVE_AUTOTEST], [test x"$dx_cv_autotest_works" = x"yes"])
+# The DX_PROG_AUTOTEST_AM macro may be used to set all of the above.
 #
 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
 # This is free software: you are free to do what the fuck you want to.
@@ -31,10 +32,10 @@ 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)' \
@@ -53,24 +54,22 @@ DX_AUTOTEST_ERROR = @:; { \
          printf 'Autoconf package: <https://gnu.org/s/autoconf/>\n'; \
        } 1>&2; false
 
-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_at) mv -f $@.tmp $@
+DX_AUTOTEST = $(AUTOTEST) -I$(srcdir) $(ATFLAGS)
 
-testsuite.deps: testsuite
+testsuite: testsuite.at package.m4
 if !HAVE_AUTOTEST
        $(DX_AUTOTEST_ERROR)
 endif
-       $(AM_V_GEN) $(AUTOTEST) $(ATFLAGS) -t m4_include:'$$1' -o $@.tmp \
+       $(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
+if AMDEP
+       $(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
+endif
+       $(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
@@ -85,4 +84,27 @@ dist-autotest-deps: testsuite.deps
 EXTRA_DIST += testsuite testsuite.at testsuite.deps package.m4
 DISTCLEANFILES += atconfig $(DEPDIR)/testsuite.P
 
-@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/testsuite.P@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/testsuite.P@am__quote@@dx_include_marker@
+
+# 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_depfiles_target@: ./$(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 $@