]> git.draconx.ca Git - dxcommon.git/commitdiff
Fix Autotest depfiles generation with non-GNU makes.
authorNick Bowler <nbowler@draconx.ca>
Sat, 6 Mar 2021 21:22:50 +0000 (16:22 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sun, 7 Mar 2021 02:41:06 +0000 (21:41 -0500)
Depfiles generation uses the $MAKE value set at configure time, and
apparently I never actually tried this with non-GNU makes.  So of
course it does not work.  Let's try to improve the situation.

m4/am-compat.m4
m4/autotest.m4
snippet/autotest.mk
tests/snippets.at [new file with mode: 0644]
testsuite.at

index 46b2edfa436928e5bd5e8942adc277746460bb5b..ec148199f2117d414a8644930d13548ad4394e4c 100644 (file)
@@ -1,6 +1,6 @@
-dnl Copyright © 2012 Nick Bowler
+dnl Copyright © 2012, 2021 Nick Bowler
 dnl
-dnl Definitions to help maintain compatibility with older versions of Automake.
+dnl Definitions to help maintain compatibility with multiple Automake versions.
 dnl
 dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
 dnl This is free software: you are free to do what the fuck you want to.
@@ -50,7 +50,7 @@ cat >conftest.sed <<'EOF'
        p
 }
 EOF
-if sed -nf conftest.sed Makefile.in >conftest.out 2>/dev/null; then
+if sed -nf conftest.sed "$srcdir/Makefile.in" >conftest.out 2>/dev/null; then
        read dx_genline <conftest.out
        dx_cv_align_v=`expr "$dx_genline" : '.*'`
        test $dx_cv_align_v -eq 0 && dx_cv_align_v=unknown
@@ -60,5 +60,19 @@ rm -f conftest*
 ])
 
 AS_IF([test x"$dx_cv_align_v" != x"unknown"],
-       [AC_SUBST([DX_ALIGN_V], [-$dx_cv_align_v.$dx_cv_align_v])])
+  [AC_SUBST([DX_ALIGN_V], [-$dx_cv_align_v.$dx_cv_align_v])])
+
+AC_CACHE_CHECK([for depfiles generation method], [dx_cv_am_depfiles],
+  [AS_IF([grep '^am--depfiles:' "$srcdir/Makefile.in" >/dev/null ||
+          grep '[[$]](am__maybe_remake_depfiles)' "$srcdir/Makefile.in" >/dev/null],
+    [dx_cv_am_depfiles='make am--depfiles'],
+    [dx_cv_am_depfiles='config.status'])])
+AS_CASE([$dx_cv_am_depfiles],
+  ['make am--depfiles'], [dx_include_marker=' @%:@ am--include-marker'],
+  [dx_include_marker=''])
+AC_SUBST([dx_depfiles_target], [am--depfiles])
+AC_SUBST([dx_include_marker])
+AM_SUBST_NOTMAKE([dx_depfiles_target])
+AM_SUBST_NOTMAKE([dx_include_marker])
+
 ])
index f9e1eea81e6e2efbb13ea9d535c467b9ee45e5a4..063144a19039688feb1dbf6d4486ae51047a3cab 100644 (file)
@@ -36,7 +36,7 @@ m4_define([_DX_PROG_AUTOTEST_SET_VAR],
     [AUTOTEST=$dx_cv_autotest_cmd])])
 
 AC_DEFUN([DX_PROG_AUTOTEST],
-  [m4_do([AC_REQUIRE([AC_PROG_FGREP])],
+  [m4_do([AC_REQUIRE([AC_PROG_FGREP])AC_REQUIRE([DX_AUTOMAKE_COMPAT])],
     [AC_ARG_VAR([AUTOTEST], [command to compile autotest programs])],
     [DX_DO([_DX_PROG_AUTOTEST_SRC],
       [_DX_PROG_AUTOTEST_SET_VAR],
index badfc9f97ce0c11d71c4d83f8a1989fb0a52e596..10acd7134d8548ef971b8d124f11dfc5ed6f1147 100644 (file)
@@ -1,8 +1,12 @@
-# Copyright © 2015,2019-2020 Nick Bowler
+# Copyright © 2015,2019-2021 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.  If DX_PROG_AUTOTEST is used, this
+# will be included automatically.
 #
 # You must define the AUTOTEST variable to the Autotest program (normally,
 # this is autom4te -l autotest).  The DX_PROG_AUTOTEST macro can be used
@@ -81,7 +85,7 @@ 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
@@ -92,9 +96,8 @@ DISTCLEANFILES += atconfig $(DEPDIR)/testsuite.P
 # 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:
+@dx_depfiles_target@: ./$(DEPDIR)/testsuite.P
+./$(DEPDIR)/testsuite.P:
        @$(MKDIR_P) $(@D)
        @if test -f $(builddir)/testsuite.deps; then \
          exec 3<$(builddir)/testsuite.deps; \
diff --git a/tests/snippets.at b/tests/snippets.at
new file mode 100644 (file)
index 0000000..32c1f70
--- /dev/null
@@ -0,0 +1,60 @@
+dnl Copyright © 2021 Nick Bowler
+dnl
+dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
+dnl This is free software: you are free to do what the fuck you want to.
+dnl There is NO WARRANTY, to the extent permitted by law.
+
+AT_BANNER([Automake snippet tests])
+
+m4_define([TEST_DEPFILES_INIT],
+[TEST_CONFIGURE_AC(
+[[AM_INIT_AUTOMAKE([foreign])
+
+DX_PROG_AUTOTEST
+AM_CONDITIONAL([HAVE_AUTOTEST], [test x"$dx_cv_autotest_works" = x"yes"])
+
+AM_SET_DEPDIR
+AM_OUTPUT_DEPENDENCY_COMMANDS
+AM_MAKE_INCLUDE
+AM_DEP_TRACK
+
+AC_CONFIG_FILES([Makefile])
+]])
+
+cp "$srcdir/snippet/autotest.mk" .
+AT_DATA([Makefile.am],
+[[EXTRA_DIST =
+DISTCLEANFILES =
+include $(top_srcdir)/autotest.mk
+]])
+
+TEST_AUTORECONF])
+
+AT_SETUP([autotest.mk depfiles (MAKE=gmake)])
+
+TEST_DEPFILES_INIT
+
+# gmake sanity check
+AT_CHECK([{ echo 'rule:; @: $(info works)' |
+              gmake --no-print-directory -f - >out 2>/dev/null &&
+            read s <out && test x"$s" = x"works"; } || exit 77])
+
+mkdir build
+AT_CHECK([cd build && ../configure MAKE=gmake && test -f .deps/testsuite.P],
+  [0], [ignore])
+AT_CHECK([gmake --no-print-directory -sC build distclean &&
+  find build -type f])
+
+AT_CLEANUP
+
+AT_SETUP([autotest.mk depfiles (MAKE=dmake)])
+
+TEST_DEPFILES_INIT
+
+# dmake sanity check
+AT_CHECK([{ echo 'rule:; @echo works' | dmake -f - >out 2>/dev/null &&
+            read s <out && test x"$s" = x"works"; } || exit 77])
+
+AT_CHECK([./configure MAKE=dmake && test -f .deps/testsuite.P], [0], [ignore])
+
+AT_CLEANUP
index 2c08518b4c733eaddfe94d2afd693426d2544dd7..7e5ea5d63dc6add5c9acef160243be95ef6b320b 100644 (file)
@@ -9,6 +9,13 @@ AT_COLOR_TESTS
 
 AT_TESTED([prove])
 
+m4_divert_push([PREPARE_TESTS])dnl
+# Reduce influence from the toplevel "make" invocation on test cases.
+AS_UNSET([MAKEFLAGS])
+AS_UNSET([MAKELEVEL])
+AS_UNSET([MFLAGS])
+m4_divert_pop([PREPARE_TESTS])
+
 m4_define([TEST_CONFIGURE_AC], [AT_KEYWORDS([autoconf m4])dnl
 AT_DATA([configure.ac],
 [[AC_INIT([test], [0])
@@ -16,6 +23,8 @@ AT_DATA([configure.ac],
 AC_OUTPUT
 ]])
 cp "$srcdir/install-sh" \
+   "$srcdir/depcomp" \
+   "$srcdir/missing" \
    "$srcdir/config.guess" \
    "$srcdir/config.sub" \
    .
@@ -27,6 +36,7 @@ m4_define([TEST_CONFIGURE], [AT_KEYWORDS([configure])dnl
 AT_CHECK([export CC; ./configure $1], [0], [ignore])])
 
 m4_include([tests/macros.at])
+m4_include([tests/snippets.at])
 m4_include([tests/functions.at])
 m4_include([tests/programs.at])
 m4_include([tests/libs.at])