Support for remote LIBOBJS (and friends) with subdir-objects.
Fixes PR automake/401.
* automake.in (config_libobj_dir): New variable.
(scan_autoconf_traces): Set config_libobj_dir from AC_CONFIG_LIBOBJ_DIR.
(handle_LIBOBJS_or_ALLOCA, require_libsource_with_macro): New functions.
(handle_LIBOBJS, handle_ALLOCA): Use them. Adjust location of
dependency files, possibly in a subdirectory.
* tests/pr401.test, tests/pr401b.test, tests/pr401c.test: New tests.
* tests/Makefile.am (TESTS): Add them.
* doc/automake.texi (Optional) <AC_CONFIG_LIBOBJ_DIR>: Document.
(LIBOBJS): Document changes in behaviour of
LIBOBJS, ALLOCA, LTLIBOBJS & LTALLOCA in the presence of
subdir-objects and an invocation of AC_CONFIG_LIBOBJ_DIR.
+2005-04-25 Gary V. Vaughan <gary@gnu.org>
+ Alexandre Duret-Lutz <adl@gnu.org>
+
+ Support for remote LIBOBJS (and friends) with subdir-objects.
+ Fixes PR automake/401.
+
+ * automake.in (config_libobj_dir): New variable.
+ (scan_autoconf_traces): Set config_libobj_dir from AC_CONFIG_LIBOBJ_DIR.
+ (handle_LIBOBJS_or_ALLOCA, require_libsource_with_macro): New functions.
+ (handle_LIBOBJS, handle_ALLOCA): Use them. Adjust location of
+ dependency files, possibly in a subdirectory.
+ * tests/pr401.test, tests/pr401b.test, tests/pr401c.test: New tests.
+ * tests/Makefile.am (TESTS): Add them.
+ * doc/automake.texi (Optional) <AC_CONFIG_LIBOBJ_DIR>: Document.
+ (LIBOBJS): Document changes in behaviour of
+ LIBOBJS, ALLOCA, LTLIBOBJS & LTALLOCA in the presence of
+ subdir-objects and an invocation of AC_CONFIG_LIBOBJ_DIR.
+
2005-04-18 Jim Meyering <jim@meyering.net>
* doc/automake.texi (Dist): Correct English.
variables are used as ${VAR}, and AC_SUBSTed, then Automake will
be able to output rules anyway.
(See the Automake documentation for AC_CONFIG_FILES.)
+
+ - If `subdir-objects' is set, and AC_CONFIG_LIBOBJ_DIR is specified,
+ $(LIBOBJS), $(LTLIBOBJS), $(ALLOCA), and $(LTALLOCA) can be used
+ in different directories.
+
\f
New in 1.9:
# in Makefiles.
my $am_config_aux_dir = '';
+# Directory to search for AC_LIBSOURCE files, 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.
$depfile =~ s/\.([^.]*)$/.P$1/;
$depfile =~ s/\$\(OBJEXT\)$/o/;
$dep_files{dirname ($depfile) . '/$(DEPDIR)/'
- . basename ($depfile)} = 1;
+ . basename ($depfile)} = 1;
}
}
# Arguments are:
# canonical (transformed) name of target to build
# actual target of object to build
-# object extension (i.e. either `.o' or `$o'.
+# object extension (i.e., either `.o' or `$o')
# location of the source variable
# extra arguments to pass to file_contents when producing rules
-# Return result is name of linker variable that must be used.
+# Return the name of the linker variable that must be used.
# Empty return means just use `LINK'.
sub handle_source_transform ($$$$%)
{
return $seen_libobjs;
}
+# handle_LIBOBJS_or_ALLOCA ($VAR)
+# -------------------------------
+# Definitions common to LIBOBJS and ALLOCA.
+# VAR should be one of LIBOBJS, LTLIBOBJS, ALLOCA, or LTALLOCA.
+sub handle_LIBOBJS_or_ALLOCA ($)
+{
+ my ($var) = @_;
+
+ my $dir = $config_libobj_dir ? "$config_libobj_dir/" : '';
+
+ # If LIBOBJS files must be built in another directory we have
+ # to define LIBOBJDIR and ensure the files get cleaned.
+ # Otherwise LIBOBJDIR can be left undefined, and the cleaning
+ # is achieved by `rm -f *.($OBJEXT)' in compile.am.
+ if ($config_libobj_dir
+ && $relative_dir ne $config_libobj_dir)
+ {
+ if (option 'subdir-objects')
+ {
+ define_variable ('LIBOBJDIR', "\$(top_builddir)/$dir", INTERNAL);
+ $clean_files{"\$($var)"} = MOSTLY_CLEAN;
+ # If LTLIBOBJS is used, we must also clear LIBOBJS (which might
+ # be created by libtool as a side-effect of creating LTLIBOBJS).
+ $clean_files{"\$($var)"} = MOSTLY_CLEAN if $var =~ s/^LT//;
+
+ }
+ else
+ {
+ error ("`\$($var)' cannot be used outside `$dir' if"
+ . " `subdir-objects' is not set");
+ }
+ }
+
+ return $dir;
+}
+
sub handle_LIBOBJS ($$$)
{
my ($var, $cond, $lt) = @_;
$var->requires_variables ("\@${lt}LIBOBJS\@ used", $lt . 'LIBOBJS')
if ! keys %libsources;
+ my $dir = handle_LIBOBJS_or_ALLOCA "${lt}LIBOBJS";
+
foreach my $iter (keys %libsources)
{
if ($iter =~ /\.[cly]$/)
if ($iter =~ /\.h$/)
{
- require_file_with_macro ($cond, $var, FOREIGN, $iter);
+ require_libsource_with_macro ($cond, $var, FOREIGN, $iter);
}
elsif ($iter ne 'alloca.c')
{
my $rewrite = $iter;
$rewrite =~ s/\.c$/.P$myobjext/;
- $dep_files{'$(DEPDIR)/' . $rewrite} = 1;
+ $dep_files{$dir . '$(DEPDIR)/' . $rewrite} = 1;
$rewrite = "^" . quotemeta ($iter) . "\$";
# Only require the file if it is not a built source.
my $bs = var ('BUILT_SOURCES');
if (! $bs || ! grep (/$rewrite/, $bs->value_as_list_recursive))
{
- require_file_with_macro ($cond, $var, FOREIGN, $iter);
+ require_libsource_with_macro ($cond, $var, FOREIGN, $iter);
}
}
}
my ($var, $cond, $lt) = @_;
my $myobjext = ($lt ? 'l' : '') . 'o';
$lt ||= '';
+ my $dir = handle_LIBOBJS_or_ALLOCA "${lt}ALLOCA";
+
$var->requires_variables ("\@${lt}ALLOCA\@ used", $lt . 'ALLOCA');
- $dep_files{'$(DEPDIR)/alloca.P' . $myobjext} = 1;
- require_file_with_macro ($cond, $var, FOREIGN, 'alloca.c');
- &saw_extension ('c');
+ $dep_files{$dir . '$(DEPDIR)/alloca.P' . $myobjext} = 1;
+ require_libsource_with_macro ($cond, $var, FOREIGN, 'alloca.c');
+ &saw_extension ('.c');
}
# Canonicalize the input parameter
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,
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]))
require_file ($macro->rdef ($cond)->location, $mystrict, @files);
}
+# &require_libsource_with_macro ($COND, $MACRO, $MYSTRICT, @FILES)
+# ----------------------------------------------------------------
+# Require an AC_LIBSOURCEd file. If AC_CONFIG_LIBOBJ_DIR was called, it
+# must be in that directory. Otherwise expect it in the current directory.
+sub require_libsource_with_macro ($$$@)
+{
+ my ($cond, $macro, $mystrict, @files) = @_;
+ $macro = rvar ($macro) unless ref $macro;
+ if ($config_libobj_dir)
+ {
+ require_file_internal ($macro->rdef ($cond)->location, $mystrict,
+ $config_libobj_dir, @files);
+ }
+ else
+ {
+ require_file ($macro->rdef ($cond)->location, $mystrict, @files);
+ }
+}
# &require_conf_file ($WHERE, $MYSTRICT, @FILES)
# ----------------------------------------------
Currently recognized macros and their effects are:
@ftable @code
-@item AC_CONFIG_HEADERS
-Automake will generate rules to rebuild these headers. Older versions
-of Automake required the use of @code{AM_CONFIG_HEADER}
-(@pxref{Macros}); this is no longer the case today.
-
-As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
-specification using shell variables will be ignored as far as
-cleaning, distributing, and rebuilding is concerned.
-
-@item AC_CONFIG_LINKS
-Automake will generate rules to remove @file{configure} generated
-links on @samp{make distclean} and to distribute named source files as
-part of @samp{make dist}.
-
-As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
-specification using shell variables will be ignored as far as cleaning
-and distributing is concerned. (There is no rebuild rules for links.)
+@item AC_CANONICAL_BUILD
+@itemx AC_CANONICAL_HOST
+@itemx AC_CANONICAL_TARGET
+@vindex build_triplet
+@vindex host_triplet
+@vindex target_triplet
+Automake will ensure that @file{config.guess} and @file{config.sub}
+exist. Also, the @file{Makefile} variables @code{build_triplet},
+@code{host_triplet} and @code{target_triplet} are introduced. See
+@ref{Canonicalizing, , Getting the Canonical System Type, autoconf,
+The Autoconf Manual}.
@item AC_CONFIG_AUX_DIR
Automake will look for various helper scripts, such as
Required files from @code{AC_CONFIG_AUX_DIR} are automatically
distributed, even if there is no @file{Makefile.am} in this directory.
-@item AC_CANONICAL_BUILD
-@itemx AC_CANONICAL_HOST
-@itemx AC_CANONICAL_TARGET
-@vindex build_triplet
-@vindex host_triplet
-@vindex target_triplet
-Automake will ensure that @file{config.guess} and @file{config.sub}
-exist. Also, the @file{Makefile} variables @code{build_triplet},
-@code{host_triplet} and @code{target_triplet} are introduced. See
-@ref{Canonicalizing, , Getting the Canonical System Type, autoconf,
-The Autoconf Manual}.
+@item AC_CONFIG_LIBOBJ_DIR
+Automake will require the sources file declared with
+@code{AC_LIBSOURCE} (see below) in the directory specified by this
+macro.
-@item AC_LIBSOURCE
+@item AC_CONFIG_HEADERS
+Automake will generate rules to rebuild these headers. Older versions
+of Automake required the use of @code{AM_CONFIG_HEADER}
+(@pxref{Macros}); this is no longer the case today.
+
+As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
+specification using shell variables will be ignored as far as
+cleaning, distributing, and rebuilding is concerned.
+
+@item AC_CONFIG_LINKS
+Automake will generate rules to remove @file{configure} generated
+links on @samp{make distclean} and to distribute named source files as
+part of @samp{make dist}.
+
+As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
+specification using shell variables will be ignored as far as cleaning
+and distributing is concerned. (There is no rebuild rules for links.)
+
+@item AC_LIBOBJ
+@itemx AC_LIBSOURCE
@itemx AC_LIBSOURCES
-@itemx AC_LIBOBJ
@vindex LIBOBJS
Automake will automatically distribute any file listed in
@code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
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
-are expected to be in the directory where the @samp{$(LIBOBJS)} and
-@samp{$(ALLOCA)} variables are used.
+Automake can also use this information, otherwise it expects the
+source files are to be in the directory where the @samp{$(LIBOBJS)}
+and @samp{$(ALLOCA)} variables are used.
The @file{lib/} directory should therefore contain @file{malloc.c},
@file{memcmp.c}, @file{strdup.c}, @file{alloca.c}. Here is its
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.)
+When option @option{subdir-objects} is not used, as in the above
+example, the variables @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} can only
+be used in the directory where their sources lie. E.g., here it would
+be wrong to use @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} in
+@file{src/Makefile.am}. However if both @option{subdir-objects} and
+@code{AC_CONFIG_LIBOBJ_DIR} are used, it is OK to use these variables
+in other directories. For instance @file{src/Makefile.am} could be
+changed as follows.
+
+@example
+# src/Makefile.am
+
+AUTOMAKE_OPTIONS = subdir-objects
+LDADD = $(LIBOBJS) $(ALLOCA)
+
+bin_PROGRAMS = tool1 tool2 @dots{}
+tool1_SOURCES = @dots{}
+tool2_SOURCES = @dots{}
+@end example
Because @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} contain object
file names that end with @samp{.$(OBJEXT)}, they are not suitable for
-@set UPDATED 18 April 2005
-@set UPDATED-MONTH April 2005
+@set UPDATED 14 May 2005
+@set UPDATED-MONTH May 2005
@set EDITION 1.9a
@set VERSION 1.9a
-@set UPDATED 18 April 2005
-@set UPDATED-MONTH April 2005
+@set UPDATED 14 May 2005
+@set UPDATED-MONTH May 2005
@set EDITION 1.9a
@set VERSION 1.9a
pr300-ltlib.test \
pr300-prog.test \
pr307.test \
+pr401.test \
+pr401b.test \
+pr401c.test \
prefix.test \
primary.test \
primary2.test \
pr300-ltlib.test \
pr300-prog.test \
pr307.test \
+pr401.test \
+pr401b.test \
+pr401c.test \
prefix.test \
primary.test \
primary2.test \
--- /dev/null
+#! /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.
+# (pr401b.test and pr401c.test do the same for LTLIBOBJS and ALLOCA)
+
+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)
+{
+ puts (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 = ../lib/libfeep.a
+
+TESTS = feep
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE distcheck
+
+
+## -------------------------------------------- ##
+## 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
+$MAKE distclean
+
+
+## ----------------------------------------- ##
+## 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
+
+check-local:
+ test -f src/feep.$(OBJEXT)
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE distcheck
--- /dev/null
+#! /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 LTLIBOBJS.
+# (pr401.test and pr401c.test do the same for LIBOBJS and ALLOCA)
+
+required='gcc libtoolize'
+. ./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)
+{
+ puts (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_LIBTOOL
+AC_CONFIG_FILES([lib/Makefile src/Makefile])
+AC_OUTPUT
+EOF
+
+## -------------------------------------------- ##
+## First a test of traditional LTLIBOBJS usage. ##
+## -------------------------------------------- ##
+
+cat >Makefile.am <<'EOF'
+SUBDIRS = lib src
+EOF
+
+cat >lib/Makefile.am <<'EOF'
+noinst_LTLIBRARIES = libfeep.la
+libfeep_la_SOURCES =
+libfeep_la_LIBADD = $(LTLIBOBJS)
+EOF
+
+cat >src/Makefile.am <<'EOF'
+check_PROGRAMS = feep
+feep_LDADD = ../lib/libfeep.la
+
+TESTS = feep
+EOF
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+$MAKE distcheck
+
+
+## ---------------------------------------------- ##
+## Test using LTLIBOBJS 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_LTLIBRARIES = libfeep.la
+libfeep_la_SOURCES =
+libfeep_la_LIBADD = $(LTLIBOBJS)
+
+check_PROGRAMS = feep
+feep_LDADD = libfeep.la
+
+TESTS = feep
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+./configure
+$MAKE
+$MAKE check
+$MAKE distclean
+
+
+## ------------------------------------------- ##
+## Test using LTLIBOBJS from parent directory. ##
+## ------------------------------------------- ##
+
+$PERL -pi -e 's/^.*src\/Makefile.*$//' configure.in
+
+cat >Makefile.am <<'EOF'
+AUTOMAKE_OPTIONS = subdir-objects
+
+noinst_LTLIBRARIES = lib/libfeep.la
+lib_libfeep_la_SOURCES =
+lib_libfeep_la_LIBADD = $(LTLIBOBJS)
+
+check_PROGRAMS = src/feep
+src_feep_SOURCES = src/feep.c
+src_feep_LDADD = lib/libfeep.la
+
+TESTS = src/feep
+
+check-local:
+ test -f src/feep.$(OBJEXT)
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE distcheck
--- /dev/null
+#! /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 ALLOCA.
+# (pr401.test and pr401b.test do the same for LIBOBJS and LTLIBOBJS)
+
+required=gcc
+. ./defs || exit 1
+
+set -e
+
+mkdir lib src
+
+ac_cv_func_alloca_works=no
+export ac_cv_func_alloca_works
+
+cat >lib/alloca.c <<'EOF'
+char *
+feep ()
+{
+ return "feep";
+}
+EOF
+
+cat >src/feep.c <<'EOF'
+#include <stdio.h>
+
+extern char *feep ();
+
+int
+main (int argc, char **argv)
+{
+ puts (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_PROG_RANLIB
+AC_FUNC_ALLOCA
+AC_CONFIG_FILES([lib/Makefile src/Makefile])
+AC_OUTPUT
+EOF
+
+## ----------------------------------------- ##
+## First a test of traditional ALLOCA usage. ##
+## ----------------------------------------- ##
+
+cat >Makefile.am <<'EOF'
+SUBDIRS = lib src
+EOF
+
+cat >lib/Makefile.am <<'EOF'
+noinst_LIBRARIES = libfeep.a
+libfeep_a_SOURCES =
+libfeep_a_LIBADD = $(ALLOCA)
+EOF
+
+cat >src/Makefile.am <<'EOF'
+check_PROGRAMS = feep
+feep_LDADD = ../lib/libfeep.a
+
+TESTS = feep
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE distcheck
+
+
+## ------------------------------------------- ##
+## Test using ALLOCA 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 = $(ALLOCA) $(LIBOBJS) # Add LIBOBJS for fun
+
+check_PROGRAMS = feep
+feep_LDADD = libfeep.a
+
+TESTS = feep
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+./configure
+$MAKE
+$MAKE check
+$MAKE distclean
+
+
+## ---------------------------------------- ##
+## Test using ALLOCA 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 = $(ALLOCA)
+
+check_PROGRAMS = src/feep
+src_feep_SOURCES = src/feep.c
+src_feep_LDADD = lib/libfeep.a
+
+TESTS = src/feep
+
+check-local:
+ test -f src/feep.$(OBJEXT)
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+$MAKE distcheck