--- origsrc/automake-1.9.6/automake.in	2008-10-27 08:43:13.042076800 -0400
+++ src/automake-1.9.6/automake.in	2008-10-27 08:43:38.017990400 -0400
@@ -334,6 +334,10 @@
 # in Makefiles.
 my $am_config_aux_dir = '';
 
+# Directory to search for AC_LIBSOURCE file, as set by AC_CONFIG_LIBOBJ_DIR
+# in configure.ac.
+my $config_libobj_dir = '';
+
 # Whether AM_GNU_GETTEXT has been seen in configure.ac.
 my $seen_gettext = 0;
 # Whether AM_GNU_GETTEXT([external]) is used.
@@ -2074,7 +2078,7 @@
 
       if ($iter =~ /\.h$/)
 	{
-	  require_file_with_macro ($cond, $var, FOREIGN, $iter);
+	  require_libobj_with_macro ($cond, $var, FOREIGN, $iter);
 	}
       elsif ($iter ne 'alloca.c')
 	{
@@ -2086,7 +2090,7 @@
 	  my $bs = var ('BUILT_SOURCES');
 	  if (! $bs || ! grep (/$rewrite/, $bs->value_as_list_recursive))
 	    {
-	      require_file_with_macro ($cond, $var, FOREIGN, $iter);
+	      require_libobj_with_macro ($cond, $var, FOREIGN, $iter);
 	    }
 	}
     }
@@ -2099,7 +2103,7 @@
   $lt ||= '';
   $var->requires_variables ("\@${lt}ALLOCA\@ used", $lt . 'ALLOCA');
   $dep_files{'$(DEPDIR)/alloca.P' . $myobjext} = 1;
-  require_file_with_macro ($cond, $var, FOREIGN, 'alloca.c');
+  require_libobj_with_macro ($cond, $var, FOREIGN, 'alloca.c');
   &saw_extension ('c');
 }
 
@@ -4638,6 +4642,7 @@
 		AC_CONFIG_AUX_DIR => 1,
 		AC_CONFIG_FILES => 1,
 		AC_CONFIG_HEADERS => 1,
+		AC_CONFIG_LIBOBJ_DIR => 1,
 		AC_CONFIG_LINKS => 1,
 		AC_INIT => 0,
 		AC_LIBSOURCE => 1,
@@ -4733,6 +4738,12 @@
 	      push @config_headers, $spec;
 	    }
 	}
+      elsif ($macro eq 'AC_CONFIG_LIBOBJ_DIR')
+	{
+	  $config_libobj_dir = $args[1];
+	  $relative_dir = '.';
+	  check_directory ($config_libobj_dir, $where);
+	}
       elsif ($macro eq 'AC_CONFIG_LINKS')
 	{
 	  foreach my $spec (split (' ', $args[1]))
@@ -5766,6 +5777,15 @@
     use constant IN_COMMENT => 2;
     my $prev_state = IN_RULE_DEF;
 
+    # Calculate the relative path from this Makefile to LIBOBJDIR.
+    my $am_libobj_dir = '';
+    unless ($config_libobj_dir eq '')
+      {
+	my $dir = File::Spec->abs2rel ($config_libobj_dir, $relative_dir);
+	$am_libobj_dir = "$dir/" unless $dir eq '';
+      }
+    &define_variable ('LIBOBJDIR', "$am_libobj_dir", INTERNAL);
+
     while ($_ = $am_file->getline)
     {
         $where->set ("$amfile:$.");
@@ -6984,6 +7004,22 @@
     require_file ($macro->rdef ($cond)->location, $mystrict, @files);
 }
 
+# &require_libobj_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
+# -------------------------------------------------------------
+sub require_libobj_with_macro ($$$@)
+{
+    my ($cond, $macro, $mystrict, @files) = @_;
+    $macro = rvar ($macro) unless ref $macro;
+    if ($config_libobj_dir eq '')
+      {
+	require_file ($macro->rdef ($cond)->location, $mystrict, @files);
+      }
+    else
+      {
+	require_file_internal ($macro->rdef ($cond)->location, $mystrict,
+			       $config_libobj_dir, @files);
+      }
+}
 
 # &require_conf_file ($WHERE, $MYSTRICT, @FILES)
 # ----------------------------------------------
--- origsrc/automake-1.9.6/doc/automake.texi	2005-07-09 05:28:44.000000000 -0400
+++ src/automake-1.9.6/doc/automake.texi	2008-10-27 19:44:50.308644800 -0400
@@ -3901,7 +3901,10 @@
 
 The @code{AC_CONFIG_LIBOBJ_DIR} tells Autoconf that the source files
 of these object files are to be found in the @file{lib/} directory.
-Automake does not yet use this information; it knows the source files
+
+In conjunction with @code{subdir-objects}, Automake uses this
+information to deduce that the object files will be in the same
+subdirectory relative to @code{$top_builddir}; it knows the source files
 are expected to be in the directory where the @samp{$(LIBOBJS)} and
 @samp{$(ALLOCA)} variables are used.
 
@@ -3947,13 +3950,9 @@
 tool2_SOURCES = @dots{}
 @end example
 
-Please note it would be wrong to use the variables @samp{$(LIBOBJS)} or
-@samp{$(ALLOCA)} in @file{src/Makefile.am}, because these variables
-contains unprefixed object names, and, for instance,
-@file{malloc.$(OBJEXT)} is not buildable in the @file{src/} directory.
-(Actually if you try using @samp{$(LIBOBJS)} in @file{src/}, Automake
-will require a copy of @file{malloc.c}, @file{memcmp.c},
-@file{strdup.c}, @file{alloca.c} in @file{src/} too.)
+Please note @code{$(LIBOBJS)} or @code{$(ALLOCA)} can only be used in
+@file{src/Makefile.am} in @code{subdir-objects} mode, because these
+variables contain object names prefixed with @code{$(LIBOBJDIR)}.
 
 Because @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} contain object
 file names that end with @samp{.$(OBJEXT)}, they are not suitable for
--- origsrc/automake-1.9.6/tests/Makefile.am	2005-06-30 17:17:13.000000000 -0400
+++ src/automake-1.9.6/tests/Makefile.am	2008-10-27 08:43:38.068062400 -0400
@@ -412,6 +412,7 @@
 pr300-ltlib.test \
 pr300-prog.test \
 pr307.test \
+pr401.test \
 prefix.test \
 primary.test \
 primary2.test \
--- origsrc/automake-1.9.6/tests/pr401.test	1969-12-31 19:00:00.000000000 -0500
+++ src/automake-1.9.6/tests/pr401.test	2008-10-27 08:43:38.078076800 -0400
@@ -0,0 +1,155 @@
+#! /bin/sh
+# Copyright (C) 2005  Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake 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.
+#
+# GNU Automake 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 Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+# Check support for AC_CONFIG_LIBOBJ_DIR vs LIBOBJS.
+
+required=gcc
+. ./defs || exit 1
+
+set -e
+
+mkdir lib src
+
+cat >lib/feep.c <<'EOF'
+char *
+feep ()
+{
+  return "feep";
+}
+EOF
+
+cat >src/feep.c <<'EOF'
+#include <stdio.h>
+
+extern char *feep ();
+
+int
+main (int argc, char **argv)
+{
+  printf ("%s\n", feep ());
+  return 0;
+}
+EOF
+
+cat >>configure.in << 'EOF'
+## These lines are activated for later tests
+#: AC_CONFIG_LIBOBJ_DIR([lib])
+AC_PROG_CC
+#: AM_PROG_CC_C_O
+AC_LIBOBJ([feep])
+AC_LIBSOURCE([feep.c])
+AC_PROG_RANLIB
+AC_CONFIG_FILES([lib/Makefile src/Makefile])
+AC_OUTPUT
+EOF
+
+## ------------------------------------------ ##
+## First a test of traditional LIBOBJS usage. ##
+## ------------------------------------------ ##
+
+cat >Makefile.am <<'EOF'
+SUBDIRS = lib src
+EOF
+
+cat >lib/Makefile.am <<'EOF'
+noinst_LIBRARIES = libfeep.a
+libfeep_a_SOURCES =
+libfeep_a_LIBADD = $(LIBOBJS)
+EOF
+
+cat >src/Makefile.am <<'EOF'
+check_PROGRAMS = feep
+feep_LDADD = $(top_builddir)/lib/libfeep.a
+
+TESTS = feep
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE
+$MAKE check
+
+rm -f configure Makefile* lib/Makefile* src/Makefile* */feep.o */libfeep.a
+
+
+## -------------------------------------------- ##
+## Test using LIBOBJS from a sibling directory. ##
+## -------------------------------------------- ##
+
+$PERL -pi -e 's/#: //' configure.in
+$PERL -pi -e 's/lib\/Makefile //' configure.in
+
+cat >Makefile.am <<'EOF'
+SUBDIRS = src
+EOF
+
+cat > src/Makefile.am <<'EOF'
+AUTOMAKE_OPTIONS = subdir-objects
+
+noinst_LIBRARIES = libfeep.a
+libfeep_a_SOURCES =
+libfeep_a_LIBADD = $(LIBOBJS)
+
+check_PROGRAMS = feep
+feep_LDADD = ./libfeep.a
+
+TESTS = feep
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+./configure
+$MAKE
+$MAKE check
+
+rm -f configure Makefile* src/Makefile* */feep.o */libfeep.a
+
+
+## ----------------------------------------- ##
+## Test using LIBOBJS from parent directory. ##
+## ----------------------------------------- ##
+
+$PERL -pi -e 's/^.*src\/Makefile.*$//' configure.in
+
+cat >Makefile.am <<'EOF'
+AUTOMAKE_OPTIONS = subdir-objects
+
+noinst_LIBRARIES = lib/libfeep.a
+lib_libfeep_a_SOURCES =
+lib_libfeep_a_LIBADD = $(LIBOBJS)
+
+check_PROGRAMS = src/feep
+src_feep_SOURCES = src/feep.c
+src_feep_LDADD = ./lib/libfeep.a
+
+TESTS = src/feep
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE
+$MAKE check
+
+rm -f configure Makefile* */feep.o */libfeep.a
