]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
Choose default source extension: AM_DEFAULT_SOURCE_EXT.
authorRalf Wildenhues <Ralf.Wildenhues@gmx.de>
Sun, 2 Nov 2008 21:55:30 +0000 (22:55 +0100)
committerRalf Wildenhues <Ralf.Wildenhues@gmx.de>
Sun, 2 Nov 2008 21:55:30 +0000 (22:55 +0100)
* automake.in (handle_source_transform): Accept unconditional
literal extension in AM_DEFAULT_SOURCE_EXT as override for the
default source extension `.c'.  If set, ignore the old default
source rule for libtool libraries.
* doc/automake.texi (Default _SOURCES): Document this.
* NEWS: Update.
* tests/specflg10.test: New test.
* tests/Makefile.am: Update.
Suggestion by Akim Demaille.

Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
ChangeLog
NEWS
automake.in
doc/automake.texi
tests/Makefile.am
tests/Makefile.in
tests/specflg10.test [new file with mode: 0755]

index 95fba5c51e3761d648afe39a2066f09fe44eb6b7..00cfc0b9196279ced244690e086fd0ca986298bd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2008-11-02  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>
 
+       Choose default source extension: AM_DEFAULT_SOURCE_EXT.
+       * automake.in (handle_source_transform): Accept unconditional
+       literal extension in AM_DEFAULT_SOURCE_EXT as override for the
+       default source extension `.c'.  If set, ignore the old default
+       source rule for libtool libraries.
+       * doc/automake.texi (Default _SOURCES): Document this.
+       * NEWS: Update.
+       * tests/specflg10.test: New test.
+       * tests/Makefile.am: Update.
+       Suggestion by Akim Demaille.
+
        Fix maintainer-check failure.
        * tests/parallel-am.test: Rename variable to not match pattern
        used in maintainer-check.
diff --git a/NEWS b/NEWS
index 98f6b5344bf35e202055988bf25c559c36eb9c7d..5c7d295a39dbdb217fc8075b8f4e590a5da01d67 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -36,6 +36,9 @@ New in 1.10a:
   - Python 3.0 is supported now, Python releases prior to 2.0 are no
     longer supported.
 
+  - The default source file extension (.c) can be overridden with
+    AM_DEFAULT_SOURCE_EXT now.
+
 * Miscellaneous changes:
 
   - Automake development is done in a git repository on Savannah now, see
index 08157737ad2172125d1d7a151ba953210d8bd233..4b54457bddf0c73c6202908f5d72407373321ff4 100755 (executable)
@@ -2058,10 +2058,16 @@ sub handle_source_transform ($$$$%)
     if (scalar @keys == 0)
     {
        # The default source for libfoo.la is libfoo.c, but for
-       # backward compatibility we first look at libfoo_la.c
+       # backward compatibility we first look at libfoo_la.c,
+       # if no default source suffix is given.
        my $old_default_source = "$one_file.c";
-       (my $default_source = $unxformed) =~ s,(\.[^./\\]*)?$,.c,;
+       my $ext_var = var ('AM_DEFAULT_SOURCE_EXT');
+       my $default_source_ext = $ext_var ? variable_value ($ext_var) : '.c';
+       msg_var ('unsupported', $ext_var, $ext_var->name . " can assume at most one value")
+         if $default_source_ext =~ /[\t ]/;
+       (my $default_source = $unxformed) =~ s,(\.[^./\\]*)?$,$default_source_ext,;
        if ($old_default_source ne $default_source
+           && !$default_source_ext
            && (rule $old_default_source
                || rule '$(srcdir)/' . $old_default_source
                || rule '${srcdir}/' . $old_default_source
index cd2f92009f9929c9b489a7639427a5a454cbf496..86f131268cea8ecadbaa85e57203b43eb2e045f9 100644 (file)
@@ -5605,6 +5605,7 @@ and we recommend avoiding it until you find it is required.
 @vindex SOURCES
 @cindex @code{_SOURCES}, default
 @cindex default @code{_SOURCES}
+@vindex AM_DEFAULT_SOURCE_EXT
 
 @code{_SOURCES} variables are used to specify source files of programs
 (@pxref{A Program}), libraries (@pxref{A Library}), and Libtool
@@ -5613,8 +5614,7 @@ 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.)
+@code{AM_DEFAULT_SOURCE_EXT}, which defaults to @file{.c}.
 
 For example if you have the following somewhere in your
 @file{Makefile.am} with no corresponding @code{libfoo_a_SOURCES}:
@@ -5631,7 +5631,7 @@ 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.
 We 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.)
+with that name exist and @code{AM_DEFAULT_SOURCE_EXT} is not used.)
 
 @cindex @code{check_PROGRAMS} example
 @vindex check_PROGRAMS
@@ -5640,16 +5640,20 @@ tests programs each from a single source.  For instance, in
 
 @example
 check_PROGRAMS = test1 test2 test3
+AM_DEFAULT_SOURCE_EXT = .cpp
 @end example
 
 @noindent
 @file{test1}, @file{test2}, and @file{test3} will be built
-from @file{test1.c}, @file{test2.c}, and @file{test3.c}.
+from @file{test1.cpp}, @file{test2.cpp}, and @file{test3.cpp}.
+Without the last line, they 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}).
+(@file{module@var{N}.la}), each defined in its own file
+(@file{module@var{N}.c}).
 
 @example
 AM_LDFLAGS = -module
index 2526acf02675096903a2f78f89ada0fe6c4b152a..fa2b9a8666eef5ca761275a8a4fe4611b6b21d2b 100644 (file)
@@ -533,6 +533,7 @@ specflg6.test       \
 specflg7.test  \
 specflg8.test  \
 specflg9.test  \
+specflg10.test \
 spell.test \
 spell2.test \
 spell3.test \
index 05bf946887ee2adc2f079d85a44b87e081d89f41..f063770665ad04227542a73c50cacac9121be96b 100644 (file)
@@ -686,6 +686,7 @@ specflg6.test       \
 specflg7.test  \
 specflg8.test  \
 specflg9.test  \
+specflg10.test \
 spell.test \
 spell2.test \
 spell3.test \
diff --git a/tests/specflg10.test b/tests/specflg10.test
new file mode 100755 (executable)
index 0000000..23a7e64
--- /dev/null
@@ -0,0 +1,87 @@
+#! /bin/sh
+# Copyright (C) 2008  Free Software Foundation, Inc.
+#
+# This program 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 3, or (at your option)
+# any later version.
+#
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# AM_DEFAULT_SOURCE_EXT
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in << 'END'
+AC_PROG_CC
+AC_PROG_CXX
+AC_CONFIG_FILES([sub/Makefile sub2/Makefile])
+AM_CONDITIONAL([COND], [:])
+AC_OUTPUT
+END
+
+mkdir sub sub2
+
+cat > Makefile.am << 'END'
+SUBDIRS = sub sub2
+bin_PROGRAMS = foo
+END
+
+cat > sub/Makefile.am << 'END'
+bin_PROGRAMS = bar baz
+AM_DEFAULT_SOURCE_EXT = .cpp
+END
+
+cat > sub2/Makefile.am << 'END'
+bin_PROGRAMS = bla
+if COND
+AM_DEFAULT_SOURCE_EXT = .foo .quux
+endif
+SUFFIXES = .foo .c
+.foo.c:
+       cat $< >$@
+CLEANFILES = bla.c
+END
+
+cat > foo.c << 'END'
+int main () { return 0; }
+END
+
+cp foo.c sub/bar.cpp
+cp foo.c sub/baz.cpp
+cp foo.c sub2/bla.foo
+
+$ACLOCAL
+$AUTOCONF
+
+# Conditional AM_DEFAULT_SOURCE_EXT does not work yet  :-(
+# (this limitation could be lifted).
+AUTOMAKE_fails --add-missing
+grep 'defined conditionally' stderr
+
+sed '/^if/d; /^endif/d' sub2/Makefile.am > t
+mv -f t sub2/Makefile.am
+
+# AM_DEFAULT_SOURCE_EXT can only assume one value
+# (lifting this limitation is not such a good idea).
+AUTOMAKE_fails --add-missing
+grep 'at most one value' stderr
+
+sed 's/ \.quux//' sub2/Makefile.am > t
+mv -f t sub2/Makefile.am
+
+$AUTOMAKE --add-missing
+
+./configure
+$MAKE
+$MAKE distcheck
+
+: