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