From: Alexandre Duret-Lutz Date: Sun, 30 Nov 2003 17:00:36 +0000 (+0000) Subject: * automake.in (handle_source_transform): If it's present, use X-Git-Tag: Release-1-7h~3 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=a65e0e9ceb3d6be4a82c6edcfa257e1e87e3d4d9;p=automake.git * automake.in (handle_source_transform): If it's present, use libfoo_la.c instead of libfoo.c as the default source of libfoo.la, and issue an -Wobsolete diagnostic. Do not be greedy in the suffix replacement regex. * doc/automake.texi (Default _SOURCES): New node. (Program Sources, Libtool Modules): Refer to it. * tests/ltlibsrc.test: Update to check for old default source files. --- diff --git a/ChangeLog b/ChangeLog index b0c2d55d..0493336d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2003-11-30 Alexandre Duret-Lutz + + * automake.in (handle_source_transform): If it's present, use + libfoo_la.c instead of libfoo.c as the default source of + libfoo.la, and issue an -Wobsolete diagnostic. Do not be + greedy in the suffix replacement regex. + * doc/automake.texi (Default _SOURCES): New node. + (Program Sources, Libtool Modules): Refer to it. + * tests/ltlibsrc.test: Update to check for old default source files. + 2003-11-30 Gary V. Vaughan * automake.in (&handle_source_transform): Calculate a default file diff --git a/NEWS b/NEWS index 6cb9f5e1..fb8d94b6 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,10 @@ New in 1.7g: lib_LTLIBRARIES = foo.la foo_la_LDFLAGS = -module + For backward compatibility, foo_la.c will be used instead of + foo.c if this file exists or is the explicit target of a rule. + However -Wobsolete will warn about this deprecated naming. + - 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 3752415d..11349ba1 100755 --- a/automake.in +++ b/automake.in @@ -1807,7 +1807,22 @@ sub handle_source_transform my @keys = sort keys %used_pfx; if (scalar @keys == 0) { - (my $default_source = $unxformed) =~ s/(\..*)?$/.c/; + # The default source for libfoo.la is libfoo.c, but for + # backward compatibility we first look at libfoo_la.c + my $old_default_source = "$one_file.c"; + (my $default_source = $unxformed) =~ s,(\.[^./\\]*)?$,.c,; + if ($old_default_source ne $default_source + && (rule $old_default_source || -f $old_default_source)) + { + my $loc = $where->clone; + $loc->pop_context; + msg ('obsolete', $loc, + "the default source for `$unxformed' has been changed " + . "to `$default_source'.\n(Using `$old_default_source' for " + . "backward compatibility.)"); + $default_source = $old_default_source; + } + &define_variable ($one_file . "_SOURCES", $default_source, $where); push (@sources, $default_source); push (@dist_sources, $default_source); diff --git a/doc/automake.texi b/doc/automake.texi index cc02c1e2..da848129 100644 --- a/doc/automake.texi +++ b/doc/automake.texi @@ -2231,6 +2231,7 @@ to build programs and libraries. * A Shared Library:: Building a Libtool library * Program and Library Variables:: Variables controlling program and library builds +* Default _SOURCES:: Default source files * LIBOBJS:: Special handling for LIBOBJS and ALLOCA * Program variables:: Variables used when building a program * Yacc and Lex:: Yacc and Lex support @@ -2309,26 +2310,10 @@ corresponding @samp{.o}. Then all are linked to produce @file{hello}. @cindex Primary variable, SOURCES 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. 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.) +file @file{hello.c} (@pxref{Default _SOURCES}). @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. @@ -2883,12 +2868,8 @@ 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 +If @samp{mymodule_la_SOURCES} is not specified, then it defaults to the single +file @file{mymodule.c} (@pxref{Default _SOURCES}). @node Libtool Flags @subsection _LIBADD and _LDFLAGS @@ -3208,6 +3189,80 @@ This facility is rarely needed in practice, and we recommend avoiding it until you find it is required. @end table +@node Default _SOURCES +@section Default @code{_SOURCES} + +@vindex _SOURCES +@vindex SOURCES +@cindex @code{_SOURCES}, default +@cindex default @code{_SOURCES} + +@code{_SOURCES} variables are used to specify source files of programs +(@pxref{A Program}), libraries (@pxref{A Library}), and Libtool +libraries (@pxref{A Shared Library}). + +When no such variable is specified for a target, Automake will define +one itself. The default is to compile a single C file whose base name +is the name of the target itself, with any extension replaced by +@file{.c}. (Defaulting to C is terrible but we are stuck with it for +historical reasons.) + +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 sub/libc++.a +@end example + +@noindent +@file{libfoo.a} will be built using a default source file named +@file{libfoo.c}, and @file{sub/libc++.a} will be built from +@file{sub/libc++.c}. (In older versions @file{sub/libc++.a} +would be built from @file{sub_libc___a.c}, i.e., the default source +was the canonized name of the target, with @file{.c} appended. +Be believe the new behavior is more sensible, but for backward +compatibility automake will use the old name if a file or a rule +with that name exist.) + +@cindex @code{check_PROGRAMS} example +@vindex check_PROGRAMS +Default sources are mainly useful in test suites, when building many +tests programs each from a single source. For instance in + +@example +check_PROGRAMS = test1 test2 test3 +@end example + +@noindent +@file{test1}, @file{test2}, and @file{test3} will be built +from @file{test1.c}, @file{test2.c}, and @file{test3.c}. + +@cindex Libtool modules, default source example +@cindex default source, Libtool modules example +Another case where is this convenient is building many Libtool modules +(@file{moduleN.la}), each defined in its own file (@file{moduleN.c}). + +@example +AM_LDFLAGS = -module +lib_LTLIBRARIES = module1.la module2.la module3.la +@end example + +@cindex empty @code{_SOURCES} +@cindex @code{_SOURCES}, empty +Finally, there is one situation where this default source computation +needs to be avoided: when a target should not be built from sources. +We already saw such an example in @xref{true}; this happens when all +the constituents of a target have already been compiled and need just +to be combined using a @code{_LDADD} variable. Then it is necessary +to define an empty @code{_SOURCES} variable, so that automake does not +compute a default. + +@example +bin_PROGRAMS = target +target_SOURCES = +target_LDADD = libmain.a libmisc.a +@end example + @node LIBOBJS @section Special handling for LIBOBJS and ALLOCA diff --git a/tests/ltlibsrc.test b/tests/ltlibsrc.test index fac0636c..cbb4ae82 100755 --- a/tests/ltlibsrc.test +++ b/tests/ltlibsrc.test @@ -23,37 +23,52 @@ required='libtool gcc' . ./defs || exit 1 -cat > configure.in << 'END' -AC_INIT([foo], [0.1]) -AC_CONFIG_SRCDIR([foo.c]) -AM_INIT_AUTOMAKE +set -e + +cat >> configure.in << 'END' AC_PROG_CC AC_PROG_LIBTOOL -AC_CONFIG_FILES(Makefile) AC_OUTPUT END +mkdir zoo.d + cat > Makefile.am << 'END' -pkglib_LTLIBRARIES = foo.la -foo_la_LDFLAGS = -module +AM_LDFLAGS = -module +pkglib_LTLIBRARIES = zoo.d/bar.la old.la +noinst_LTLIBRARIES = foo.la zoo.d/old2.la + +zoo_d_old2_la.c: old_la.c + cp $< $@ END cat > foo.c << 'END' int foo (void) { return 0; } END +cp foo.c zoo.d/bar.c +cp foo.c old_la.c + libtoolize $ACLOCAL $AUTOCONF -$AUTOMAKE -a +AUTOMAKE_fails -a +grep 'Makefile.am:2:.*old_la.c' stderr +grep 'Makefile.am:2:.*old.c' stderr +grep 'Makefile.am:3:.*zoo_d_old2_la.c' stderr +grep 'Makefile.am:3:.*zoo\.d/old2.c' stderr + +$AUTOMAKE -Wno-obsolete mkdir sub cd sub ../configure -$MAKE || exit 1 +$MAKE -test -f foo.la || exit 1 -: +test -f foo.la +test -f zoo.d/bar.la +test -f old.la +test -f zoo.d/old2.la -exit 0 +$MAKE distcheck