Subject: bug#10434: FAIL: depmod.tap 50 - tru64 [long VPATH] make & remake

From: Stefano Lattarini <[email-masked]>
Date: Sun, 05 Feb 2012 14:16:59 +0100

On 02/02/2012 11:41 PM, Peter Rosin wrote:
> Stefano Lattarini skrev 2012-02-02 22:45:
>> Reference:
>>   <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=10434>
>>
>> OK, the attached patch fixes the two spurious failures of GCC forced into
>> Tru64 mode.  About time I'd say.
>>
>> But I'm not sure whether we should apply this without first testing it
>> on a real Tru64 compiler, lest we cause a real regression just to fix a
>> spurious failure.  Thoughts?
> 
> I just had a look at that test, and it seems like a very crappy test
> to me.  I had some failures with cl, but figured it was the same as
> these Tru64 failures that I had seen flying past, and put it all on
> the back burner.  But the test is destined to cause troubles if IIUC.
> 
> It's just dead wrong to assume that feeding -M or -xM to the compiler
> (or whatever other random stuff depcomp might do) and not get an error
> is the same as dependencies magically appearing.  Or do I read the
> test wrong?  Please tell me that I do!
> 
Unfortunately you read the test right.  And in hindsight I must agree
with you: its approach is fundamentally flawed.

So, what about the attached patch, that overhauls (and hopefully improve)
the coverage for automatic dependency tracking support?  It is probably
possible to improve the patch even more (esp. w.r.t. optimizations for
speed), but that can be left for follow-up changes IMHO.

I will push (to master) in 72 hours if there is no objection by then.

Thanks,
  Stefano
>From 2008b6bd27bba6194856cb5a58eb8c5e700e35c8 Mon Sep 17 00:00:00 2001
Message-Id: <2008b6bd2[email-masked]>
From: Stefano Lattarini <[email-masked]>
Date: Fri, 3 Feb 2012 15:05:48 +0100
Subject: [PATCH] tests: improve and rework tests on dependency tracking

Fixes automake bug#10434.  Suggestion by Peter Rosin.

The 'depcomp.tap' test case worked by trying to unconditionally
force the compiler in use by the testsuite to use, one by one, *all*
the dependency modes known by the 'depcomp' script, and, for each
such forced mode that was compatible enough with said compiler not
to cause breakage in the basic compilation rules, checking that it
was *also* good enough not to break remake rules in VPATH builds.

This seemed a good approach when this test was first introduced, as
it apparently increased coverage for the less used and less tested
dependency-tracking modes.  But in the log run it turned out the
approach was actually in part to brittle, causing some annoying
spurious failures (as with the Tru64 depmode forced on GCC, see
automake bug#10434), and partly too forgiving, since, for some of
the more corner-case dependency modes, the 'depcomp' script simply
reverts to silently disabling dependency tracking when an error is
encountered (this happened e.g., with the Tru64 depmode forced on
the Sun C compiler 5.9), so that a passing test means nothing, and
only gives a false sense of security.

As Peter Rosin put it, "it's just dead wrong to assume that feeding
-M or -xM to the compiler (or whatever other random stuff 'depcomp'
might do) and not get an error is the same as dependencies magically
appearing".

So we get rid of this wrong approach, and in the process proceed to
a complete overhaul of many of the tests on automatic dependency
tracking, extending the offered coverage and rationalizing their
organization.

* tests/decomp.sh: New helper script, used by several new
autogenerated tests.
* tests/gen-testsuite-part: Generate several tests based on the
new 'decomp.sh' script.  Emit makefile code that declares their
dependency on that script, and that extends EXTRA_DIST in order
to distribute it.
* tests/depmod.tap: Remove.
* tests/depend2.test: Remove, it has been subsumed by the new
test 'depcomp-disabled.tap'.
* tests/depcomp3.test: Remove, it has been subsumed by the new
autogenerated test 'depmod-dashmstdout.tap'.
* tests/depcomp3.test: Remove, it has been subsumed by the new
autogenerated test 'depmod-lt-makedepend.tap'.
* tests/depcomp6.test: Remove, it has been subsumed by the new
autogenerated test 'depmod-auto.tap'.
* tests/depcomp7.test: Remove, it has been subsumed by the new
autogenerated test 'depmod-lt-auto.tap'.
* tests/depcomp5.test: Remove as obsolescent.
* test/list-of-tests.mk: Adjust.
* .gitignore: List the new autogenerated tests.
---
 .gitignore               |    1 +
 tests/depcomp.sh         |  378 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/depcomp3.test      |   63 --------
 tests/depcomp4.test      |   59 -------
 tests/depcomp5.test      |   69 ---------
 tests/depcomp6.test      |  110 --------------
 tests/depcomp7.test      |  126 ---------------
 tests/depend2.test       |   54 -------
 tests/depmod.tap         |  209 -------------------------
 tests/gen-testsuite-part |   72 ++++++++-
 tests/list-of-tests.mk   |    7 -
 11 files changed, 447 insertions(+), 701 deletions(-)
 create mode 100755 tests/depcomp.sh
 delete mode 100755 tests/depcomp3.test
 delete mode 100755 tests/depcomp4.test
 delete mode 100755 tests/depcomp5.test
 delete mode 100755 tests/depcomp6.test
 delete mode 100755 tests/depcomp7.test
 delete mode 100755 tests/depend2.test
 delete mode 100755 tests/depmod.tap

diff --git a/.gitignore b/.gitignore
index 46607dc..c95a193 100644
--- a/.gitignore
+++ b/.gitignore
@@ -53,6 +53,7 @@ Makefile
 /tests/testsuite-part.am
 /tests/*-w.tap
 /tests/*-w.test
+/tests/depcomp-*.tap
 /tests/*.dir
 /tests/*.log
 /tests/*.trs
diff --git a/tests/depcomp.sh b/tests/depcomp.sh
new file mode 100755
index 0000000..147e8ca
--- /dev/null
+++ b/tests/depcomp.sh
@@ -0,0 +1,378 @@
+#! /bin/sh
+# Copyright (C) 2012 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Check dependency tracking in various flavours.
+# Contains both libtool and non-libtool case.
+# Sourced by the various (autogenerated) 'depcomp*.tap' tests.
+# Examples of reported failures that motivated those test are
+# listed below.
+
+# -------------------------------------------------------------------------
+
+# <http://lists.gnu.org/archive/html/automake-patches/2011-04/msg00028.html>
+#
+# Here's the bug: makedepend will prefix VPATH to the object file name,
+# thus the second make will invoke depcomp with object='../../src/foo.o',
+# causing errors such as:
+#
+#  touch: cannot touch `../../src/.deps/foo.TPo': No such file or directory
+#  makedepend: error:  cannot open "../../src/.deps/foo.TPo"
+#  ../../depcomp: line 560: ../../src/.deps/foo.TPo: No such file or directory
+
+# -------------------------------------------------------------------------
+
+# <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8473>
+# <http://lists.gnu.org/archive/html/automake-patches/2011-04/msg00079.html>
+#
+# Here's the bug: hp depmode will prefix VPATH to the object file name,
+# thus the second gmake will invoke depcomp with object='../../src/foo.o',
+# causing errors such as (broken on multiple lines for clarity):
+#
+#   cpp: "", line 0: error 4066: Cannot create
+#        "../../gllib/.deps/nonblocking.TPo" file for
+#        "-M../../gllib/.deps/nonblocking.TPo" option.
+#        (No such file or directory[errno=2])
+#
+
+# -------------------------------------------------------------------------
+
+# <http://lists.gnu.org/archive/html/automake-patches/2011-04/msg00140.html>
+# <http://lists.gnu.org/archive/html/automake-patches/2011-05/msg00019.html>
+#
+# A partial failure of an earlier version of this test; some bad
+# post-processing of the `*.Po' files led to the following broken
+# contents of `src/sub/.deps/subfoo.Po':
+#
+#  > sub/subfoo.o: ../../depmod-data.dir/src/sub/subfoo.c \
+#  >   ../../depmod-data.dir/src/foo.h
+#  > ../../depmod-data.dir/src/sub/subfoo.c \:
+#  >   ../../depmod-data.dir/src/foo.h:
+#
+# which caused make to die with an error like:
+#
+#  "sub/.deps/subfoo.Po:3: *** missing separator.  Stop."
+
+# -------------------------------------------------------------------------
+
+am_create_testdir=empty
+. ./defs || Exit 1
+
+ocwd=`pwd` || fatal_ "cannot get current working directory"
+longpath=this-is/a-path/which-has/quite-a/definitely/truly/long_long_name
+cachevar=am_cv_CC_dependencies_compiler_type
+
+srctree=depmod-1.0
+mkdir $srctree
+cd $srctree
+
+cd_top ()
+{
+  cd "$ocwd" || fatal_ "cannot chdir back to top directory"
+}
+
+delete ()
+{
+  test -f "$1" || fatal_ "$1: file does not exist"
+  rm -f "$1" || fatal_ "$1: couldn't remove"
+}
+
+edit ()
+{
+  file=$1; shift
+  sed "$@" <"$file" > t && mv -f t "$file" \
+    || fatal_ "$file: editing of file failed"
+}
+
+rewrite ()
+{
+  file=$1; shift
+  "$@" > "$file" || fatal_ "$file: couldn't rewrite"
+}
+
+setup_srcdir ()
+{
+  srcdir=$1 # This is intended to be global.
+  mkdir -p "$srcdir" \
+    || fatal_ "couldn't create source directory '$srcdir'"
+  cp -pR "$ocwd/$srctree"/* "$srcdir"/ \
+    || fatal_ "couldn't populate source directory '$srcdir'"
+}
+
+
+check_no_depfiles ()
+{
+  find . -name '*.Plo' -o -name '*.Po' | grep . && return 1
+  return 0
+}
+
+check_distclean ()
+{
+  # "make distcleancheck" can only run from a VPATH build.
+  if test $vpath = no; then
+    make_ok distclean && check_no_depfiles
+  else
+    $MAKE distcleancheck
+  fi
+}
+
+cat > configure.in <<END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([build-aux])
+AM_INIT_AUTOMAKE
+AC_PROG_CC
+AM_PROG_CC_C_O
+AM_PROG_AR
+`if test $depcomp_with_libtool = yes; then
+  echo AC_PROG_LIBTOOL
+else
+  echo AC_PROG_RANLIB
+fi`
+AC_CONFIG_FILES([Makefile src/Makefile])
+AC_OUTPUT
+END
+
+mkdir build-aux sub src src/sub2
+
+case $depcomp_with_libtool in
+  yes)
+    plan_ 72
+    po=Plo objext=lo a=la
+    normalized_target=libfoo_la
+    LIBPRIMARY=LTLIBRARIES LINKADD=LIBADD
+    echo lib_LTLIBRARIES = libfoo.la >> Makefile.am
+    make_ok ()
+    {
+      $MAKE ${1+"$@"} >output 2>&1 || { cat output; return 1; }
+      cat output
+      $FGREP 'unknown directive' output && return 1
+      rm -f output
+      # Checks for stray files possible left around by less common
+      # depmodes.
+      find . -name '*.[ud]' | grep . && return 1
+      return 0
+    }
+    ;;
+  no)
+    plan_ 24
+    po=Po objext='$(OBJEXT)' a=a
+    normalized_target=foo
+    LIBPRIMARY=LIBRARIES LINKADD=LDADD
+    echo bin_PROGRAMS = foo >> Makefile.am
+    make_ok ()
+    {
+      $MAKE ${1+"$@"}
+    }
+    ;;
+  *)
+    fatal_ "invalid value '$depcomp_with_libtool' for variable" \
+           "\$depcomp_with_libtool"
+    ;;
+esac
+
+cat >> Makefile.am <<END
+SUBDIRS = src
+# We include subfoo only to be sure that the munging in depcomp
+# doesn't remove too much from the object file name.
+${normalized_target}_SOURCES = foo.c sub/subfoo.c foo.h sub/subfoo.h
+${normalized_target}_${LINKADD} = src/libbaz.$a
+
+.PHONY: grep-test
+grep-test:
+## For debugging.
+	cat \$(DEPDIR)/foo.$po || :
+	cat \$(DEPDIR)/subfoo.$po || :
+	cat src/\$(DEPDIR)/baz.$po || :
+	cat src/sub2/\$(DEPDIR)/sub2foo.$po || :
+## Checks done here.
+	grep '^foo.$objext.*:' \$(DEPDIR)/foo.$po
+	grep '^subfoo\.$objext.*:' \$(DEPDIR)/subfoo.$po
+	grep '^baz\.$objext.*:' src/\$(DEPDIR)/baz.$po
+	grep '^sub2/sub2foo\.$objext.*:' src/sub2/\$(DEPDIR)/sub2foo.$po
+END
+
+cat > src/Makefile.am <<END
+AUTOMAKE_OPTIONS = subdir-objects
+noinst_${LIBPRIMARY} = libbaz.$a
+# We include sub2foo only to be sure that the munging in depcomp
+# doesn't remove too much from the object file name.
+libbaz_${a}_SOURCES = baz.c sub2/sub2foo.c baz.h sub2/sub2foo.h
+END
+
+cat > foo.c <<'END'
+#include "foo.h"
+#include "src/baz.h"
+#include <stdlib.h>
+int main (void)
+{
+  printf ("foo bar\n");
+  exit (EXIT_SUCCESS + subfoo () + baz ());
+}
+END
+
+cat > foo.h <<'END'
+#include <stdio.h>
+#include "sub/subfoo.h"
+END
+
+cat > sub/subfoo.c <<'END'
+#include "sub/subfoo.h"
+int subfoo (void) { return 0; }
+END
+
+echo '/* empty */' > src/sub2/sub2foo.h
+
+cat > sub/subfoo.h <<'END'
+#include <stdio.h>
+extern int subfoo (void);
+END
+
+cat > src/baz.c <<'END'
+#include "baz.h"
+int baz (void) { return 0; }
+END
+
+cat > src/baz.h <<'END'
+extern int baz (void);
+END
+
+cat > src/sub2/sub2foo.c <<'END'
+#include "sub2foo.h"
+int sub2foo (void) { return 0; }
+END
+
+test $depcomp_with_libtool = no || libtoolize \
+  || fatal_ "libtoolize failed"
+$ACLOCAL && $AUTOCONF && $AUTOMAKE -a \
+  || fatal_ "autotools failed"
+test -f build-aux/depcomp \
+  || fatal_ "depcomp script not installed"
+
+case $depmode in
+  auto)
+    cfg_deptrack=--enable-dependency-tracking ;;
+  disabled)
+    cfg_deptrack=--disable-dependency-tracking ;;
+  *)
+    # Sanity check: ensure the cache variable we force is truly
+    # used by configure.
+    $FGREP $cachevar configure \
+      || fatal_ "configure lacks required cache variable '$cachevar'"
+    cfg_deptrack="cachevar=$depmode" ;;
+esac
+
+cd_top
+
+do_test ()
+{
+  cd_top
+  if test $vpath = no; then
+    pfx="in-tree build"
+  else
+    pfx="$vpath VPATH"
+  fi
+  if test $# -gt 0; then
+    subdir=$1; shift
+    pfx="$pfx, $subdir"
+    test -d $subdir || mkdir $subdir || fatal_ "creating directory $subdir"
+    cd $subdir
+  fi
+  pfx="[$pfx]"
+  case $vpath in
+    simple)
+      mkdir -p vpath-simple/build
+      cd vpath-simple/build
+      setup_srcdir ..
+      ;;
+    long)
+      mkdir -p vpath-long/src vpath-long/wrk
+      cd vpath-long/wrk
+      setup_srcdir ../src/$longpath
+      ;;
+    absolute)
+      mkdir -p vpath-abs/build
+      cd vpath-abs/build
+      absdir="`(cd .. && pwd)`" || fatal_ "getting absolute directory"
+      setup_srcdir "$absdir/vpath-abs"
+      unset absdir
+      ;;
+    no)
+      mkdir intree
+      cd intree
+      setup_srcdir .
+      ;;
+    *)
+      fatal_ "invalid value '$vpath' for variable \$vpath"
+      ;;
+  esac
+
+  command_ok_ "$pfx configure" "$srcdir"/configure $cfg_deptrack ${1+"$@"}
+  command_ok_ "$pfx simple make" make_ok
+  # Some bugs in VPATH builds only kick in during a rebuild.
+  command_ok_ "$pfx clean & rebuild" eval '$MAKE clean && make_ok'
+
+  if test $depmode = disabled; then
+      command_ok_ "$pfx no dependency files generated" check_no_depfiles
+      r=ok \
+        && grep "[ $tab]depmode=none" Makefile \
+        && rewrite "$srcdir"/src/sub2/sub2foo.h echo 'choke me' \
+        && delete "$srcdir"/sub/subfoo.h \
+        && make_ok \
+        || r='not ok'
+      result_ "$r" "$pfx dependency tracking is truly disabled"
+  elif grep "[ $tab]depmode=none" Makefile; then
+    skip_row_ 2 -r "automatic dependency tracking couldn't be activated"
+  else
+    command_ok_ "$pfx generated $po files look correct" $MAKE grep-test
+    r=ok \
+      && : "Some checks in the subdir." \
+      && $sleep \
+      && : "Ensure rebuild rules do really kick in." \
+      && rewrite "$srcdir"/src/sub2/sub2foo.h echo 'choke me' \
+      && cd src \
+      && not $MAKE  \
+      && cd .. \
+      && : "Ensure the deleted header bug is fixed." \
+      && delete "$srcdir"/src/sub2/sub2foo.h \
+      && edit "$srcdir"/src/sub2/sub2foo.c -e 1d \
+      && cd src \
+      && make_ok \
+      && : "Now do similar checks for the parent directory." \
+      && cd .. \
+      && rewrite "$srcdir"/sub/subfoo.h echo 'choke me' \
+      && not $MAKE \
+      && delete "$srcdir"/sub/subfoo.h \
+      && edit "$srcdir"/sub/subfoo.c -e 1d \
+      && edit "$srcdir"/foo.h -e 2d \
+      && make_ok \
+      || r='not ok'
+    result_ "$r" "$pfx dependency tracking works"
+  fi
+
+  command_ok_ "$pfx make distclean" check_distclean
+  cd_top
+}
+
+for vpath in no simple long absolute; do
+  if test $depcomp_with_libtool = no; then
+    do_test
+  else
+    do_test default
+    do_test noshared --disable-shared
+    do_test nostatic --disable-static
+  fi
+done
+
+:
diff --git a/tests/depcomp3.test b/tests/depcomp3.test
deleted file mode 100755
index 058d7e9..0000000
--- a/tests/depcomp3.test
+++ /dev/null
@@ -1,63 +0,0 @@
-#! /bin/sh
-# Copyright (C) 2003, 2010, 2011 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-# Make sure dashmstdout generates dependencies.
-
-required='gcc'
-. ./defs || Exit 1
-
-cat >> configure.in << 'END'
-AC_PROG_CC
-AM_PROG_CC_C_O
-AC_OUTPUT
-END
-
-cat > Makefile.am << 'END'
-AUTOMAKE_OPTIONS = subdir-objects
-check_PROGRAMS = prg
-prg_SOURCES = src/sub.c src/foo.h
-
-.PHONY: grepdeps
-grepdeps:
-	grep 'src/sub\.$(OBJEXT).*:' src/$(DEPDIR)/sub.Po
-
-END
-
-mkdir src
-
-: > src/foo.h
-
-cat >src/sub.c <<EOF
-#include "foo.h"
-int
-main ()
-{
-   return 0;
-}
-EOF
-
-$ACLOCAL
-$AUTOCONF
-$AUTOMAKE -a
-
-# Sanity check: make sure the cache variable we force is used by configure.
-grep am_cv_CC_dependencies_compiler_type configure
-
-./configure am_cv_CC_dependencies_compiler_type=dashmstdout
-$MAKE check
-$MAKE grepdeps
-
-:
diff --git a/tests/depcomp4.test b/tests/depcomp4.test
deleted file mode 100755
index fc62990..0000000
--- a/tests/depcomp4.test
+++ /dev/null
@@ -1,59 +0,0 @@
-#! /bin/sh
-# Copyright (C) 2003, 2010, 2011 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-# Test for PR 385: makedepend doesn't work with Libtool.
-
-required='libtoolize gcc makedepend'
-. ./defs || Exit 1
-
-cat >> configure.in << 'END'
-AC_PROG_CC
-AM_PROG_AR
-AC_PROG_LIBTOOL
-AC_OUTPUT
-END
-
-cat > Makefile.am << 'END'
-noinst_LTLIBRARIES = liba.la
-liba_la_SOURCES = a.c foo.h
-
-.PHONY: grepdeps
-grepdeps:
-	grep 'a\.lo *:' ./$(DEPDIR)/a.Plo
-END
-
-: > foo.h
-
-cat >a.c <<EOF
-#include "foo.h"
-int a() { return 0; }
-EOF
-
-libtoolize --force
-$ACLOCAL
-$AUTOCONF
-$AUTOMAKE -a
-
-# Sanity check: make sure the cache variable we force is used by configure.
-grep am_cv_CC_dependencies_compiler_type configure
-
-./configure am_cv_CC_dependencies_compiler_type=makedepend
-$MAKE >output 2>&1 || { cat output; Exit 1; }
-cat output
-grep 'unknown directive' output && Exit 1
-$MAKE grepdeps
-
-:
diff --git a/tests/depcomp5.test b/tests/depcomp5.test
deleted file mode 100755
index 586a98b..0000000
--- a/tests/depcomp5.test
+++ /dev/null
@@ -1,69 +0,0 @@
-#! /bin/sh
-# Copyright (C) 2003, 2004, 2010, 2011 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-# Check icc's dependency mode.
-
-required='icc'
-. ./defs || Exit 1
-
-# Automake supports icc since version 7.0 through a dedicated depcomp mode.
-# icc 8.0 and greater understand gcc options, so depmode is set to gcc.
-if icc -V -help 2>&1 | grep 'Version 7'; then
-  expect='depmode=icc'
-else
-  expect='depmode=gcc'
-fi
-
-cat >> configure.in << 'END'
-AC_PROG_CC
-AM_PROG_CC_C_O
-AC_OUTPUT
-END
-
-cat > Makefile.am << 'END'
-AUTOMAKE_OPTIONS = subdir-objects
-check_PROGRAMS = prg
-prg_SOURCES = src/sub.c src/foo.h
-
-.PHONY: grepdeps
-grepdeps:
-	grep 'src/sub\.$(OBJEXT).*:' src/$(DEPDIR)/sub.Po
-
-END
-
-mkdir src
-
-touch src/foo.h
-
-cat >src/sub.c <<EOF
-#include "foo.h"
-int
-main ()
-{
-   return 0;
-}
-EOF
-
-$ACLOCAL
-$AUTOCONF
-$AUTOMAKE -a
-
-./configure
-grep "$expect" Makefile
-$MAKE check
-$MAKE grepdeps
-
-:
diff --git a/tests/depcomp6.test b/tests/depcomp6.test
deleted file mode 100755
index 2d43c28..0000000
--- a/tests/depcomp6.test
+++ /dev/null
@@ -1,110 +0,0 @@
-#! /bin/sh
-# Copyright (C) 2006, 2010, 2011 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-# Check dependency generation (non libtool case).
-
-required=cc
-. ./defs || Exit 1
-
-cat >> configure.in << 'END'
-AC_PROG_CC
-AM_PROG_CC_C_O
-AM_PROG_AR
-AC_PROG_RANLIB
-AC_CONFIG_FILES([sub2/Makefile])
-AC_OUTPUT
-END
-
-mkdir sub sub2 sub2/sub3
-
-cat >Makefile.am <<'END'
-SUBDIRS = sub2
-bin_PROGRAMS = foo
-foo_SOURCES = foo.c sub/bar.c foo.h sub/bar.h
-foo_LDADD = sub2/libbaz.a
-END
-
-cat >sub2/Makefile.am <<'END'
-AUTOMAKE_OPTIONS = subdir-objects
-noinst_LIBRARIES = libbaz.a
-libbaz_a_SOURCES = baz.c sub3/ba3.c baz.h sub3/ba3.h
-END
-
-cat >foo.c <<'END'
-#include "foo.h"
-#include "sub2/baz.h"
-#include <stdlib.h>
-int main (void) { printf ("foo"); return bar () + baz (); }
-END
-
-cat >foo.h <<'END'
-#include <stdio.h>
-#include "sub/bar.h"
-END
-
-cat >sub/bar.c <<'END'
-#include "sub/bar.h"
-int bar (void) { return 0; }
-END
-
-touch sub2/sub3/ba3.h
-
-cat >sub/bar.h <<'END'
-#include <stdio.h>
-extern int bar (void);
-END
-
-cat >sub2/baz.c <<'END'
-#include "baz.h"
-int baz (void) { return 0; }
-END
-
-cat >sub2/baz.h <<'END'
-extern int baz (void);
-END
-
-cat >sub2/sub3/ba3.c <<'END'
-#include "ba3.h"
-int ba3 (void) { return 0; }
-END
-
-$ACLOCAL
-$AUTOCONF
-$AUTOMAKE -a
-
-./configure --enable-dependency-tracking
-$MAKE
-
-if grep 'depmode=none' Makefile; then
-  skip_ "automatic dependency tracking couldn't be activated"
-fi
-
-cd sub2
-$sleep
-echo 'choke me' > sub3/ba3.h
-# Do not use `$MAKE && Exit 1' here, since even relatively-recent
-# versions of the BSD shell wrongly exit when the `errexit' shell
-# flag is active if a command within "&&" fails inside a compound
-# statement.
-if $MAKE; then Exit 1; else :; fi
-
-# Ensure the deleted header bug is fixed.
-rm -f sub3/ba3.h
-sed 1d sub3/ba3.c >sub3/ba3.t
-mv -f sub3/ba3.t sub3/ba3.c
-$MAKE
-
-:
diff --git a/tests/depcomp7.test b/tests/depcomp7.test
deleted file mode 100755
index f553894..0000000
--- a/tests/depcomp7.test
+++ /dev/null
@@ -1,126 +0,0 @@
-#! /bin/sh
-# Copyright (C) 2006, 2007, 2010, 2011 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-# Check dependency generation (libtool case).
-
-required='cc libtoolize'
-. ./defs || Exit 1
-
-cat >> configure.in << 'END'
-AC_PROG_CC
-AM_PROG_CC_C_O
-AM_PROG_AR
-AM_PROG_LIBTOOL
-AC_CONFIG_FILES([sub2/Makefile])
-AC_OUTPUT
-END
-
-mkdir sub sub2 sub2/sub3
-
-cat >Makefile.am <<'END'
-SUBDIRS = sub2
-bin_PROGRAMS = foo
-foo_SOURCES = foo.c sub/bar.c foo.h sub/bar.h
-foo_LDADD = sub2/libbaz.la
-END
-
-cat >sub2/Makefile.am <<'END'
-AUTOMAKE_OPTIONS = subdir-objects
-noinst_LTLIBRARIES = libbaz.la
-libbaz_la_SOURCES = baz.c sub3/ba3.c baz.h sub3/ba3.h
-END
-
-cat >foo.c <<'END'
-#include "foo.h"
-#include "sub2/baz.h"
-#include <stdlib.h>
-int main (void) { printf ("foo"); return bar () + baz (); }
-END
-
-cat >foo.h <<'END'
-#include <stdio.h>
-#include "sub/bar.h"
-END
-
-cat >sub/bar.c <<'END'
-#include "sub/bar.h"
-int bar (void) { return 0; }
-END
-
-echo 'extern int x;' > sub2/sub3/ba3.h
-
-cat >sub/bar.h <<'END'
-#include <stdio.h>
-extern int bar (void);
-END
-
-cat >sub2/baz.c <<'END'
-#include "baz.h"
-int baz (void) { return 0; }
-END
-
-cat >sub2/baz.h <<'END'
-extern int baz (void);
-END
-
-cat >sub2/sub3/ba3.in <<'END'
-#include "ba3.h"
-int ba3 (void) { return 0; }
-END
-
-libtoolize
-$ACLOCAL
-$AUTOCONF
-$AUTOMAKE -a
-
-st=0
-for staticshared in --disable-shared "" --disable-static; do
-
-  cp sub2/sub3/ba3.in sub2/sub3/ba3.c
-  ./configure --enable-dependency-tracking $staticshared
-  $MAKE
-
-  # If we cannot enable dependency tracking, perform only the most basic
-  # checks, and don't consider this test to be PASSed but SKIPped, because
-  # the main purpose of this test is exposing the depmode features.
-  if grep 'depmode=none' Makefile; then
-    st=77
-  else
-    cd sub2
-    $sleep
-    echo 'choke me' > sub3/ba3.h
-    # Do not use `$MAKE && Exit 1' here, since even relatively-recent
-    # versions of the BSD shell wrongly exit when the `errexit' shell
-    # flag is active if a command within "&&" fails inside a compound
-    # statement.
-    if $MAKE; then Exit 1; else :; fi
-
-    # Ensure the deleted header bug is fixed.
-    rm -f sub3/ba3.h
-    sed 1d sub3/ba3.in >sub3/ba3.c
-    $MAKE
-    cd ..
-  fi
-
-  $MAKE distclean
-  test ! -f sub2/sub3/ba3.u
-  test ! -f sub2/sub3/ba3.d
-
-  echo 'extern int x;' > sub2/sub3/ba3.h
-
-done
-
-Exit $st
diff --git a/tests/depend2.test b/tests/depend2.test
deleted file mode 100755
index ec949e3..0000000
--- a/tests/depend2.test
+++ /dev/null
@@ -1,54 +0,0 @@
-#! /bin/sh
-# Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2010, 2011 Free
-# Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-# Test to make sure dependency tracking works with
-# --disable-dependency-tracking.
-# Report from Robert Boehne.
-
-required=cc
-. ./defs || Exit 1
-
-cat >> configure.in << 'END'
-AC_PROG_CC
-AC_OUTPUT
-END
-
-cat > Makefile.am << 'END'
-bin_PROGRAMS = hello
-END
-
-cat > hello.h << 'END'
-#include <stdio.h>
-END
-
-cat > hello.c << 'END'
-#include "hello.h"
-int main (int argc, char *argv[])
-{
-   printf ("yeah, yeah\n");
-   return 0;
-}
-END
-
-$ACLOCAL
-$AUTOCONF
-$AUTOMAKE -a
-
-./configure --disable-dependency-tracking
-$MAKE
-
-:
diff --git a/tests/depmod.tap b/tests/depmod.tap
deleted file mode 100755
index e1fbef5..0000000
--- a/tests/depmod.tap
+++ /dev/null
@@ -1,209 +0,0 @@
-#! /bin/sh
-# Copyright (C) 2011 Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-# Check that dependency tracking in various flavours works with VPATH
-# builds.  Examples of reported failures follows ...
-
-# <http://lists.gnu.org/archive/html/automake-patches/2011-04/msg00028.html>
-#
-# Here's the bug: makedepend will prefix VPATH to the object file name,
-# thus the second make will invoke depcomp with object='../../src/foo.o',
-# causing errors such as:
-# touch: cannot touch `../../src/.deps/foo.TPo': No such file or directory
-# makedepend: error:  cannot open "../../src/.deps/foo.TPo"
-# ../../depcomp: line 560: ../../src/.deps/foo.TPo: No such file or directory
-
-# <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8473>
-# <http://lists.gnu.org/archive/html/automake-patches/2011-04/msg00079.html>
-#
-# Here's the bug: hp depmode will prefix VPATH to the object file name,
-# thus the second gmake will invoke depcomp with object='../../src/foo.o',
-# causing errors such as (broken on multiple lines for clarity):
-#   cpp: "", line 0: error 4066: Cannot create
-#        "../../gllib/.deps/nonblocking.TPo" file for
-#        "-M../../gllib/.deps/nonblocking.TPo" option.
-#        (No such file or directory[errno=2])
-#
-
-# <http://lists.gnu.org/archive/html/automake-patches/2011-04/msg00140.html>
-# <http://lists.gnu.org/archive/html/automake-patches/2011-05/msg00019.html>
-#
-# A partial failure of an earlier version of this test; some bad
-# post-processing of the `*.Po' files led to the following broken
-# contents of `src/sub/.deps/subfoo.Po':
-#  > sub/subfoo.o: ../../depmod-data.dir/src/sub/subfoo.c \
-#  >   ../../depmod-data.dir/src/foo.h
-#  > ../../depmod-data.dir/src/sub/subfoo.c \:
-#  >   ../../depmod-data.dir/src/foo.h:
-# which caused make to die with an error like:
-#  "sub/.deps/subfoo.Po:3: *** missing separator.  Stop."
-
-required=cc
-. ./defs || Exit 99
-
-# Keep this in sync with the contents of depend.m4.
-all_depmodes=`\
-  sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < "$am_scriptdir/depcomp" \
-    | grep -v '^none$'` \
-  && : Turn newlines and tabs into spaces, and strip extra whitespace. \
-  && all_depmodes=`echo $all_depmodes` \
-  && test -n "$all_depmodes" \
-  || fatal_ "can't extract list of valid depmodes"
-
-# Allow the user to select a subset of the tests.
-if test $# -gt 0; then
-  tested_depmodes=$*
-  for depmode in $tested_depmodes; do
-    case " $all_depmodes " in
-      *" $depmode "*);;
-      *) fatal_ "invalid user-specified depmode '$depmode'"
-    esac
-  done
-  n=`for m in $tested_depmodes; do echo $m; done | wc -l`
-  # We need to determine the TAP plan adaptively.
-  # Per each valid depmode three kinds of VPATH, and per each of them
-  # a test on "./configure" and one on "make & remake"; so there are
-  # $n * 3 * 2 tests.
-  plan_ `expr $n '*' 6`
-  unset n
-else
-  tested_depmodes=$all_depmodes
-  # Prefer static TAP plan if possible, minimizes the chance of errors.
-  plan_ 102
-fi
-
-ocwd=`pwd` || fatal_ "cannot get current working directory"
-
-srctree=depmod-1.0
-mkdir $srctree
-mv missing install-sh depcomp configure.in $srctree
-cd $srctree
-
-mkdir src src/sub
-
-cat >> configure.in << 'END'
-AC_CONFIG_FILES([src/Makefile])
-AC_PROG_CC
-AM_PROG_CC_C_O
-AC_OUTPUT
-END
-
-echo 'SUBDIRS = src' > Makefile.am
-
-cat > src/Makefile.am << 'END'
-AUTOMAKE_OPTIONS = subdir-objects
-bin_PROGRAMS = foo
-foo_SOURCES = foo.c foo.h sub/subfoo.c
-END
-
-echo 'extern int subfoo (void);' > src/foo.h
-
-cat > src/foo.c << 'END'
-#include "foo.h"
-int main (void)
-{
-  return subfoo ();
-}
-END
-
-# We include subfoo only to be sure that we don't remove too much
-# from the object file name.
-cat > src/sub/subfoo.c << 'END'
-#include "foo.h"
-int subfoo (void)
-{
-  return 0;
-}
-END
-
-$ACLOCAL
-$AUTOCONF
-$AUTOMAKE -a
-
-# Sanity check: make sure the cache variable we force is used
-# by configure.
-grep am_cv_CC_dependencies_compiler_type configure \
-  || fatal_ "configure lacks required cache variable"
-
-cd "$ocwd" || fatal_ "cannot chdir back to top directory"
-
-longpath=this-is/a-path/which-have/quite-a/long_long_name
-$srctree/install-sh -d $longpath || fatal_ "cannot create long path"
-cp -pR $srctree/* $longpath || fatal_ "cannot populate long path"
-cp -pR $srctree/* . || fatal_ "cannot populate top-level directory"
-
-for vpath in simple long absolute; do
-  for depmode in $tested_depmodes; do
-    case $vpath in
-      simple)
-        srcdir=..;;
-      long)
-        srcdir=../$longpath;;
-      absolute)
-        srcdir=$ocwd;;
-      *)
-        fatal_ "bad \$vpath value '$vpath'";;
-    esac
-
-    pfx="$depmode [$vpath VPATH]"
-
-    mkdir $depmode-$vpath.d
-    cd $depmode-$vpath.d
-
-    if "$srcdir"/configure am_cv_CC_dependencies_compiler_type=$depmode
-    then
-      r0='ok'
-    else
-      r0='not ok'
-    fi
-    result_ "$r0" "$pfx configure" \
-
-    # Do not fail with the first call to make fails, as the depmode
-    # we've forced might not actually work, but we have overridden the
-    # _AM_DEPENDENCIES tests.
-    r1='not ok'
-    if $MAKE; then
-      # We must clean and rebuild, as the actual error only happens the
-      # second time the objects are built because 'depcomp' has silently
-      # messed up the .Po files the first time.
-      $MAKE clean \
-        && { e=0; $MAKE >output 2>&1 || e=1; cat output; test $e -eq 0; } \
-        && { if grep 'src/[._]deps' output; then false; else :; fi; } \
-        && r1='ok'
-      result_ "$r1" "$pfx make & remake"
-    else
-      skip_ -r "can't force depmode" "$pfx make & remake"
-    fi
-
-    cd "$ocwd" || fatal_ "cannot chdir back to top directory"
-
-    # Remove subdirectories for tests that have passed, to avoid ending up
-    # with a too big test directory.  This is especially important since,
-    # on each and every system, at least some tests in this script are
-    # expected to be skipped (which ones exactly depends on the system),
-    # thus causing the test directory not to be removed when the script
-    # terminates.
-    if not am_keeping_testdirs && test "$r0,$r1" = ok,ok; then
-      rm_rf_ $depmode-$vpath.d \
-        || fatal_ "removing directory \`$depmode-$vpath.d'"
-    else
-      : For lesser shells with broken 'set -e'.
-    fi
-
-  done
-done
-
-:
diff --git a/tests/gen-testsuite-part b/tests/gen-testsuite-part
index 51b634f..40e6dfc 100755
--- a/tests/gen-testsuite-part
+++ b/tests/gen-testsuite-part
@@ -23,6 +23,8 @@
 use warnings FATAL => "all";
 use strict;
 use File::Basename ();
+use constant TRUE => 1;
+use constant FALSE => 0;
 
 my $me = File::Basename::basename $0;
 
@@ -173,6 +175,11 @@ my %deps_extractor =
         dist_prereqs => "tap-setup.sh",
         nodist_prereqs => "tap-common-setup.log",
       },
+    depcomp =>
+      {
+        line_matcher => qr/\bdepcomp\.sh\b/,
+        dist_prereqs => "depcomp.sh",
+      },
   );
 
 #--------------------------------------------------------------------------
@@ -267,8 +274,6 @@ print <<EOF;
 ##  Autogenerated tests and their dependencies.  ##
 ## --------------------------------------------- ##
 
-generated_TESTS =
-
 EOF
 
 # FIXME: the following is not really right, since cannot compose wrapping
@@ -292,8 +297,6 @@ while (my ($k, $g) = each %test_generators)
                      sub { write_wrapper_script $_[0], $wrapped_test,
                            $g->{shell_setup_code} },
                      0555;
-        # Update generated makefile fragment to account for it.
-        print "generated_TESTS += $wrapper_test\n";
         # The generated test works by sourcing the original test, so that
         # it has to be re-run every time that changes ...
         print "$base-w.log: $wrapped_test\n";
@@ -307,6 +310,67 @@ while (my ($k, $g) = each %test_generators)
       }
   }
 
+print <<EOF;
+
+## ---------------------------------------------------- ##
+##  Ad-hoc autogenerated tests and their dependencies.  ##
+## ---------------------------------------------------- ##
+
+EOF
+
+print "## Tests on automatic dependency tracking (see 'depcomp.sh').\n";
+
+# Key: depmode, value: list of required programs.
+my %depmodes =
+  (
+    auto         => ["cc"],
+    disabled     => ["cc"],
+    makedepend   => ["cc", "makedepend"],
+    dashmstdout  => ["gcc"],
+    dashXmstdout => ["gcc"],
+    cpp          => ["gcc"],
+# This is for older (pre-3.x) GCC versions.  Newer versions
+# have depmode "gcc3".
+    gcc          => ["gcc"],
+  );
+
+foreach my $lt (TRUE, FALSE)
+  {
+    foreach my $m (keys %depmodes)
+      {
+        my @required =
+          (
+            @{$depmodes{$m}},
+            $lt ? ("libtoolize",) : (),
+          );
+        my @vars_init =
+          (
+            "depmode=$m",
+            "depcomp_with_libtool=" . ($lt ? "yes" : "no"),
+          );
+        my $base = "depcomp" . ($lt ? "-lt-" : "-") . $m;
+        # Register wrapper test as "autogenerated" ...
+        push @generated_tests, "$base.tap";
+        atomic_write ("$base.tap", sub
+          {
+            my $file_handle = shift;
+            print $file_handle unindent <<EOF;
+              #! /bin/sh
+              # Automatically generated test.  DO NOT EDIT BY HAND!
+              @vars_init
+              required="@required"
+              . ./defs-static || exit '99'
+              . "\$testsrcdir/depcomp.sh"; exit "\$?"
+EOF
+          },
+          0555);
+      }
+   }
+
+# Update generated makefile fragment to account for all the generated tests.
+print "generated_TESTS =\n";
+map { print "generated_TESTS += $_\n" } @generated_tests;
+
 # The test scripts are scanned for automatic dependency generation *after*
 # the generated tests have been created, so they too can be scanned.  To
 # do so correctly, we need to update the list in `@all_tests' to make it
diff --git a/tests/list-of-tests.mk b/tests/list-of-tests.mk
index f3cb769..47eb5bc 100644
--- a/tests/list-of-tests.mk
+++ b/tests/list-of-tests.mk
@@ -39,7 +39,6 @@ pm/Wrap.pl
 handwritten_TESTS = \
 get-sysconf.test \
 $(perl_TESTS) \
-depmod.tap \
 instspc.tap \
 aclocal.test \
 aclocal3.test \
@@ -325,16 +324,10 @@ deleted-m4.test \
 depacl2.test \
 depcomp.test \
 depcomp2.test \
-depcomp3.test \
-depcomp4.test \
-depcomp5.test \
-depcomp6.test \
-depcomp7.test \
 depcomp8a.test \
 depcomp8b.test \
 depdist.test \
 depend.test \
-depend2.test \
 depend3.test \
 depend4.test \
 depend5.test \
-- 
1.7.7.3