--- automake.in.orig	2005-02-12 10:06:56.000000000 +0000
+++ automake.in	2005-04-20 14:08:05.000000000 +0100
@@ -333,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.
@@ -2067,7 +2072,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')
 	{
@@ -2079,7 +2084,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);
 	    }
 	}
     }
@@ -2092,7 +2097,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');
 }
 
@@ -4636,6 +4641,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,
@@ -4731,6 +4737,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]))
@@ -5761,6 +5773,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:$.");
@@ -6975,6 +6996,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)
 # ----------------------------------------------
--- tests/Makefile.am.orig	2005-04-20 13:09:37.000000000 +0100
+++ tests/Makefile.am	2005-04-20 13:39:05.000000000 +0100
@@ -405,6 +405,7 @@
 pr300-ltlib.test \
 pr300-prog.test \
 pr307.test \
+pr401.test \
 prefix.test \
 primary.test \
 primary2.test \
--- /dev/null	2005-04-25 18:07:47.000000000 +0100
+++ tests/pr401.test	2005-04-25 18:24:31.000000000 +0100
@@ -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
--- doc/automake.texi.orig	2005-04-25 18:27:36.000000000 +0100
+++ doc/automake.texi	2005-04-25 19:31:09.000000000 +0100
@@ -3785,7 +3785,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 @code{$(LIBOBJS)} and
 @code{$(ALLOCA)} variables are used.
 
@@ -3831,13 +3834,9 @@
 tool2_SOURCES = @dots{}
 @end example
 
-Please note it would be wrong to use the @code{$(LIBOBJS)} or
-@code{$(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 @code{$(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 @code{$(LIBOBJS)} and @code{$(ALLOCA)} contain object
 filenames that end with @code{.$(OBJEXT)}, they are not suitable for
