From 5942b96363da8bfef3c0132face74b8897e92e51 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Sun, 30 Nov 2003 13:35:29 +0000 Subject: [PATCH] * automake.in (&handle_source_transform): Calculate a default file for use in the absence of an appropriate _SOURCES declaration by first stripping any suffix from the unxformed target name, and appending `.c'. * doc/automake.texi (Program Sources, Libtool Modules): Document this. * tests/ltlibsrc.test: New file. * tests/Makefile.am (TESTS): Add ltlibsrc.test. --- ChangeLog | 10 ++++++++ NEWS | 8 ++++++ automake.in | 9 ++++--- doc/automake.texi | 25 +++++++++++++++++-- doc/stamp-vti | 2 +- doc/version.texi | 2 +- tests/Makefile.am | 1 + tests/Makefile.in | 1 + tests/ltlibsrc.test | 59 +++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 109 insertions(+), 8 deletions(-) create mode 100755 tests/ltlibsrc.test diff --git a/ChangeLog b/ChangeLog index e0e1e44c..b0c2d55d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2003-11-30 Gary V. Vaughan + + * automake.in (&handle_source_transform): Calculate a default file + for use in the absence of an appropriate _SOURCES declaration by + first stripping any suffix from the unxformed target name, and + appending `.c'. + * doc/automake.texi (Program Sources, Libtool Modules): Document this. + * tests/ltlibsrc.test: New file. + * tests/Makefile.am (TESTS): Add ltlibsrc.test. + 2003-11-29 Alexandre Duret-Lutz * lib/Automake/Variable.pm (loc_and_value_as_list_recursive, diff --git a/NEWS b/NEWS index 5c6e37de..6cb9f5e1 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,14 @@ New in 1.7g: * New features + - Default source file names in the absence of a _SOURCES declaration + are made by removing any target extension before appending `.c', so + to make the libtool module `foo.la' from `foo.c', you only need to + do this: + + lib_LTLIBRARIES = foo.la + foo_la_LDFLAGS = -module + - AR's `cru' flags are now set in a global ARFLAGS variable instead of being hard-coded in each $(AR) invocation, so they can be substituted from configure.ac. This has been requested by people diff --git a/automake.in b/automake.in index cc29348d..3752415d 100755 --- a/automake.in +++ b/automake.in @@ -1807,16 +1807,17 @@ sub handle_source_transform my @keys = sort keys %used_pfx; if (scalar @keys == 0) { - &define_variable ($one_file . "_SOURCES", $unxformed . ".c", $where); - push (@sources, $unxformed . '.c'); - push (@dist_sources, $unxformed . '.c'); + (my $default_source = $unxformed) =~ s/(\..*)?$/.c/; + &define_variable ($one_file . "_SOURCES", $default_source, $where); + push (@sources, $default_source); + push (@dist_sources, $default_source); %linkers_used = (); my (@result) = &handle_single_transform_list ($one_file . '_SOURCES', $one_file . '_SOURCES', $one_file, $obj, - "$unxformed.c"); + $default_source); $linker ||= &resolve_linker (%linkers_used); define_pretty_variable ($one_file . '_OBJECTS', TRUE, $where, @result); } diff --git a/doc/automake.texi b/doc/automake.texi index 4f19f116..cc02c1e2 100644 --- a/doc/automake.texi +++ b/doc/automake.texi @@ -2310,11 +2310,25 @@ corresponding @samp{.o}. Then all are linked to produce @file{hello}. If @samp{hello_SOURCES} is not specified, then it defaults to the single file @file{hello.c}; that is, the default is to compile a single C file -whose base name is the name of the program itself. (This is a terrible -default but we are stuck with it for historical reasons.) +whose base name is the name of the program itself. In this context, +the base name is always the name that would have gone to the left of +the @samp{_SOURCES} primary, before canonicalization and with any +suffixes replaced with @samp{.c} (This is a terrible default but we +are stuck with it for historical reasons.) @vindex _SOURCES @vindex SOURCES +For example if you have the following somewhere in your +@file{Makefile.am} with no corresponding @samp{libfoo_a_SOURCES}: + +@example +lib_LIBRARIES = libfoo.a +@end example + +@noindent +@file{libfoo.a} will be built using a default source file named +@file{libfoo.c}. + Multiple programs can be built in a single directory. Multiple programs can share a single source file, which must be listed in each @samp{_SOURCES} definition. @@ -2869,6 +2883,13 @@ Ordinarily, Automake requires that a Library's name starts with @samp{lib}. However, when building a dynamically loadable module you might wish to use a "nonstandard" name. +If @samp{mymodule_SOURCES} is not specified, then it defaults to the single +file @file{mymodule.c}; that is, the default is to compile a single C file +whose base name is the name of the module itself. (This is a terrible +default but we are stuck with it for historical reasons.) +@vindex _SOURCES +@vindex SOURCES + @node Libtool Flags @subsection _LIBADD and _LDFLAGS @cindex _LIBADD, libtool diff --git a/doc/stamp-vti b/doc/stamp-vti index 3ba12101..fdce8f00 100644 --- a/doc/stamp-vti +++ b/doc/stamp-vti @@ -1,4 +1,4 @@ -@set UPDATED 29 November 2003 +@set UPDATED 30 November 2003 @set UPDATED-MONTH November 2003 @set EDITION 1.7g @set VERSION 1.7g diff --git a/doc/version.texi b/doc/version.texi index 3ba12101..fdce8f00 100644 --- a/doc/version.texi +++ b/doc/version.texi @@ -1,4 +1,4 @@ -@set UPDATED 29 November 2003 +@set UPDATED 30 November 2003 @set UPDATED-MONTH November 2003 @set EDITION 1.7g @set VERSION 1.7g diff --git a/tests/Makefile.am b/tests/Makefile.am index e466f923..b7c21a4d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -293,6 +293,7 @@ ltcond2.test \ ltconv.test \ ltdeps.test \ ltlibobjs.test \ +ltlibsrc.test \ maintclean.test \ make.test \ makej.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index 5ab156d8..97800d7b 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -407,6 +407,7 @@ ltcond2.test \ ltconv.test \ ltdeps.test \ ltlibobjs.test \ +ltlibsrc.test \ maintclean.test \ make.test \ makej.test \ diff --git a/tests/ltlibsrc.test b/tests/ltlibsrc.test new file mode 100755 index 00000000..fac0636c --- /dev/null +++ b/tests/ltlibsrc.test @@ -0,0 +1,59 @@ +#! /bin/sh +# Copyright (C) 2003 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. + +# Test to make sure a sensible default source for libraries is used. + +required='libtool gcc' +. ./defs || exit 1 + +cat > configure.in << 'END' +AC_INIT([foo], [0.1]) +AC_CONFIG_SRCDIR([foo.c]) +AM_INIT_AUTOMAKE +AC_PROG_CC +AC_PROG_LIBTOOL +AC_CONFIG_FILES(Makefile) +AC_OUTPUT +END + +cat > Makefile.am << 'END' +pkglib_LTLIBRARIES = foo.la +foo_la_LDFLAGS = -module +END + +cat > foo.c << 'END' +int foo (void) { return 0; } +END + +libtoolize +$ACLOCAL +$AUTOCONF +$AUTOMAKE -a + +mkdir sub +cd sub + +../configure +$MAKE || exit 1 + +test -f foo.la || exit 1 +: + +exit 0 -- 2.43.5