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