automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 1bis-gary-strip-target-suffix-from-default-source.patch


From: Alexandre Duret-Lutz
Subject: Re: 1bis-gary-strip-target-suffix-from-default-source.patch
Date: Sun, 30 Nov 2003 18:00:17 +0100
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3 (gnu/linux)

>>> "Gary" == Gary V Vaughan <address@hidden> writes:

[...]

 Gary> Index: ChangeLog
 Gary> from  Gary V. Vaughan  <address@hidden>

 Gary> * automake.in (&handle_source_transform): Calculate a default file
 Gary> for use in the absence of an appropriate _SOURCES declaration by
 Gary> first stripping any suffix from the unxformed target name, and
 Gary> appending `.c'.

Thanks I've installed this, with the ChangeLog augmented as follows

2003-11-30  Gary V. Vaughan  <address@hidden>

        * 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.


I'm also checking the following in.  This should clear Tom's concerns.

2003-11-30  Alexandre Duret-Lutz  <address@hidden>

        * 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.

Index: NEWS
===================================================================
RCS file: /cvs/automake/automake/NEWS,v
retrieving revision 1.251
diff -u -r1.251 NEWS
--- NEWS        30 Nov 2003 13:35:29 -0000      1.251
+++ NEWS        30 Nov 2003 16:59:00 -0000
@@ -18,6 +18,10 @@
        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
Index: automake.in
===================================================================
RCS file: /cvs/automake/automake/automake.in,v
retrieving revision 1.1522
diff -u -r1.1522 automake.in
--- automake.in 30 Nov 2003 13:35:29 -0000      1.1522
+++ automake.in 30 Nov 2003 16:59:05 -0000
@@ -1807,7 +1807,22 @@
     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);
Index: doc/automake.texi
===================================================================
RCS file: /cvs/automake/automake/doc/automake.texi,v
retrieving revision 1.14
diff -u -r1.14 automake.texi
--- doc/automake.texi   30 Nov 2003 13:35:29 -0000      1.14
+++ doc/automake.texi   30 Nov 2003 16:59:10 -0000
@@ -2231,6 +2231,7 @@
 * 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 @@
 @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
address@hidden with no corresponding @samp{libfoo_a_SOURCES}:
-
address@hidden
-lib_LIBRARIES = libfoo.a
address@hidden example
-
address@hidden
address@hidden will be built using a default source file named
address@hidden
-
 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 @@
 @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.)
address@hidden _SOURCES
address@hidden 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
@@ -3207,6 +3188,80 @@
 This facility is rarely needed in practice,
 and we recommend avoiding it until you find it is required.
 @end table
+
address@hidden Default _SOURCES
address@hidden Default @code{_SOURCES}
+
address@hidden _SOURCES
address@hidden SOURCES
address@hidden @code{_SOURCES}, default
address@hidden default @code{_SOURCES}
+
address@hidden 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
address@hidden  (Defaulting to C is terrible but we are stuck with it for
+historical reasons.)
+
+For example if you have the following somewhere in your
address@hidden with no corresponding @samp{libfoo_a_SOURCES}:
+
address@hidden
+lib_LIBRARIES = libfoo.a sub/libc++.a
address@hidden example
+
address@hidden
address@hidden will be built using a default source file named
address@hidden, and @file{sub/libc++.a} will be built from
address@hidden/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.)
+
address@hidden @code{check_PROGRAMS} example
address@hidden check_PROGRAMS
+Default sources are mainly useful in test suites, when building many
+tests programs each from a single source.  For instance in
+
address@hidden
+check_PROGRAMS = test1 test2 test3
address@hidden example
+
address@hidden
address@hidden, @file{test2}, and @file{test3} will be built
+from @file{test1.c}, @file{test2.c}, and @file{test3.c}.
+
address@hidden Libtool modules, default source example
address@hidden 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}).
+
address@hidden
+AM_LDFLAGS = -module
+lib_LTLIBRARIES = module1.la module2.la module3.la
address@hidden example
+
address@hidden empty @code{_SOURCES}
address@hidden @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.
+
address@hidden
+bin_PROGRAMS = target
+target_SOURCES =
+target_LDADD = libmain.a libmisc.a
address@hidden example
 
 @node LIBOBJS
 @section Special handling for LIBOBJS and ALLOCA
Index: tests/ltlibsrc.test
===================================================================
RCS file: /cvs/automake/automake/tests/ltlibsrc.test,v
retrieving revision 1.1
diff -u -r1.1 ltlibsrc.test
--- tests/ltlibsrc.test 30 Nov 2003 13:35:29 -0000      1.1
+++ tests/ltlibsrc.test 30 Nov 2003 16:59:10 -0000
@@ -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
-- 
Alexandre Duret-Lutz





reply via email to

[Prev in Thread] Current Thread [Next in Thread]