]> git.draconx.ca Git - dxcommon.git/blob - snippet/autotest.mk
Fix Autotest depfiles generation with non-GNU makes.
[dxcommon.git] / snippet / autotest.mk
1 # Copyright © 2015,2019-2021 Nick Bowler
2 #
3 # Automake fragment to hook up a basic Autotest test suite into the
4 # build.  It is expected that a testsuite.at file exists in $(srcdir).
5 # The testsuite will be output to $(builddir)/testsuite.
6 #
7 # The DX_AUTOMAKE_COMPAT macro must be expanded by configure.ac to
8 # provide necessary substitutions.  If DX_PROG_AUTOTEST is used, this
9 # will be included automatically.
10 #
11 # You must define the AUTOTEST variable to the Autotest program (normally,
12 # this is autom4te -l autotest).  The DX_PROG_AUTOTEST macro can be used
13 # to set this automatically.  You must also define the HAVE_AUTOTEST Automake
14 # conditional which controls whether the testsuite-generating rules are
15 # enabled.  If DX_PROG_AUTOTEST is used, this may be set like:
16 #
17 #   DX_PROG_AUTOTEST
18 #   AM_CONDITIONAL([HAVE_AUTOTEST], [test x"$dx_cv_autotest_works" = x"yes"])
19 #
20 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
21 # This is free software: you are free to do what the fuck you want to.
22 # There is NO WARRANTY, to the extent permitted by law.
23
24 check-local: check-autotest
25 check-autotest: testsuite
26         $(SHELL) $? $(TESTSUITEFLAGS)
27 .PHONY: check-autotest
28
29 clean-local: clean-autotest
30 clean-autotest:
31         for f in testsuite "$(srcdir)/testsuite"; do \
32           test ! -f "$$f" || { $(SHELL) "$$f" --clean; break; }; \
33         done
34 .PHONY: clean-autotest
35
36 maintainer-clean-local: maintainer-clean-autotest
37 maintainer-clean-autotest:
38         rm -f testsuite testsuite.deps package.m4
39 .PHONY: maintainerclean-autotest
40
41 package.m4: $(top_srcdir)/configure.ac
42         $(AM_V_GEN) :; { \
43           printf 'm4_define([%s], [%s])\n' \
44             AT_PACKAGE_NAME      '$(PACKAGE_NAME)' \
45             AT_PACKAGE_TARNAME   '$(PACKAGE_TARNAME)' \
46             AT_PACKAGE_VERSION   '$(PACKAGE_VERSION)' \
47             AT_PACKAGE_STRING    '$(PACKAGE_STRING)' \
48             AT_PACKAGE_BUGREPORT '$(PACKAGE_BUGREPORT)' \
49             AT_PACKAGE_URL       '$(PACKAGE_URL)' \
50         ; } >$@.tmp
51         $(AM_V_at) mv -f $@.tmp $@
52
53 DX_AUTOTEST_ERROR = @:; { \
54           printf 'ERROR: Autotest was not available at configure time.\n'; \
55           printf 'You should only need it if you modified the test suite.\n'; \
56           printf 'Autotest is part of autom4te, included in the GNU\n'; \
57           printf 'Autoconf package: <https://gnu.org/s/autoconf/>\n'; \
58         } 1>&2; false
59
60 DX_AUTOTEST = $(AUTOTEST) -I$(srcdir) $(ATFLAGS)
61
62 testsuite: testsuite.at package.m4
63 if !HAVE_AUTOTEST
64         $(DX_AUTOTEST_ERROR)
65 endif
66         $(AM_V_GEN) $(DX_AUTOTEST) -p m4_include -o $@.tmp testsuite.at
67         $(AM_V_at) $(DX_AUTOTEST) -t m4_include:'$$1' -o $@.deps.tmp \
68           testsuite.at
69         $(AM_V_at) exec 3<$@.deps.tmp 4>$(DEPDIR)/$(@F).P; \
70           while read f <&3; do printf '$@: %s\n%s:\n' "$$f" "$$f" >&4; done
71         $(AM_V_at) mv -f $@.deps.tmp $@.deps
72         $(AM_V_at) mv -f $@.tmp $@
73 testsuite.deps: testsuite
74
75 dist-hook: dist-autotest-deps
76 dist-autotest-deps: testsuite.deps
77         exec 3<$?; while read f <&3; do \
78           dir=`expr "$$f" : '\(.*\)/'`; \
79           $(MKDIR_P) "$(distdir)/$$dir" && \
80           chmod u+w "$(distdir)/$$dir" && \
81           cp -p "$(srcdir)/$$f" "$(distdir)/$$f" || exit; \
82         done
83 .PHONY: dist-autotest-deps
84
85 EXTRA_DIST += testsuite testsuite.at testsuite.deps package.m4
86 DISTCLEANFILES += atconfig $(DEPDIR)/testsuite.P
87
88 @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/testsuite.P@am__quote@@dx_include_marker@
89
90 # Automake 1.16 and newer use make rules to generate the dependency stubs.
91 # Use this opportunity to generate accurate prerequisites from distributed
92 # testsuite dependencies, needed so that make knows to rebuild the testsuite
93 # when source files are modified in a distribution tarball, or after a make
94 # distclean.
95 #
96 # With older Automake the stubs are generated directly in config.status.
97 # Since this rule is ignored things should still work but the build may
98 # miss modifications to the testsuite on the first build from a tarball.
99 @dx_depfiles_target@: ./$(DEPDIR)/testsuite.P
100 ./$(DEPDIR)/testsuite.P:
101         @$(MKDIR_P) $(@D)
102         @if test -f $(builddir)/testsuite.deps; then \
103           exec 3<$(builddir)/testsuite.deps; \
104         elif test -f $(srcdir)/testsuite.deps; then \
105           exec 3<$(srcdir)/testsuite.deps; \
106         else \
107           echo '# dummy' >$@-t && exit; \
108         fi; exec 4>$@-t; while read f <&3; do \
109           printf 'testsuite: %s\n%s:\n' "$$f" "$$f" >&4; \
110         done
111         @mv -f $@-t $@