automake-patches
[Top][All Lists]
Advanced

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

AM_DEFAULT_SOURCE_EXT (was: Parallel tests execution [0/4])


From: Ralf Wildenhues
Subject: AM_DEFAULT_SOURCE_EXT (was: Parallel tests execution [0/4])
Date: Sat, 18 Oct 2008 10:02:31 +0200
User-agent: Mutt/1.5.18 (2008-05-17)

* Akim Demaille wrote on Thu, Oct 16, 2008 at 04:11:22PM CEST:
> 
> I wish I could define
> 
>   AM_DEFAULT_SOURCE_EXT = .cc
> 
> or whatever, so that I wouldn't have to define all the foo_SOURCES.

I agree "extension" is better than "suffix".  (Even if Automake itself
is inconsistent here and uses both.)

I also agree that using *_EXT is better than *_EXTENSION (too long, also
there is precedent in EXEEXT and OBJEXT).

I am wondering whether DEFAULT_SOURCE_EXT would be preferable to
AM_DEFAULT_SOURCE_EXT?

WDYT about the simplistic patch below?
(yes, allowing conditional definition would be the next step.)

Cheers, and good idea BTW!
Ralf

    Allow to choose default sources: AM_DEFAULT_SOURCE_EXT.
    
    * automake.in (handle_source_transform): Accept unconditional
    AM_DEFAULT_SOURCE_EXT as override for default source extension
    `.c'.  If set, ignore old default source rule.
    * doc/automake.texi (Default _SOURCES): Document this.
    * NEWS: Update.
    * tests/specflg10.test: New test.
    * tests/Makefile.am: Update.
    Suggestion by Akim Demaille.

diff --git a/NEWS b/NEWS
index 1a14ec6..6cd543c 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,9 @@ New in 1.10a:
 
   - Files with extension .sx are also treated as preprocessed assembler.
 
+  - 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
diff --git a/automake.in b/automake.in
index 4e53484..5411ced 100755
--- a/automake.in
+++ b/automake.in
@@ -2042,10 +2042,31 @@ 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 $default_source_ext;
+       my $default_ext_var = var ('AM_DEFAULT_SOURCE_EXT');
+       if ($default_ext_var)
+         {
+           my $def = $default_ext_var->def (TRUE);
+           if ($def)
+             {
+               $default_source_ext = $def->value;
+             }
+           else
+             {
+               my $cond = $default_ext_var->conditions->one_cond;
+               my $where = $default_ext_var->rdef ($cond)->location;
+               msg ('error', $where,
+                    "AM_DEFAULT_SOURCE_EXT must not be defined conditionally");
+             }
+         }
+       $default_source_ext = '.c'
+         unless defined $default_source_ext;
+       (my $default_source = $unxformed) =~ 
s,(\.[^./\\]*)?$,$default_source_ext,;
        if ($old_default_source ne $default_source
+           && !$default_ext_var
            && (rule $old_default_source
                || rule '$(srcdir)/' . $old_default_source
                || rule '${srcdir}/' . $old_default_source
diff --git a/doc/automake.texi b/doc/automake.texi
index c2e0be5..9e09d27 100644
--- a/doc/automake.texi
+++ b/doc/automake.texi
@@ -5599,6 +5599,7 @@ and we recommend avoiding it until you find it is 
required.
 @vindex SOURCES
 @cindex @code{_SOURCES}, default
 @cindex default @code{_SOURCES}
address@hidden AM_DEFAULT_SOURCE_EXT
 
 @code{_SOURCES} variables are used to specify source files of programs
 (@pxref{A Program}), libraries (@pxref{A Library}), and Libtool
@@ -5607,8 +5608,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
address@hidden  (Defaulting to C is terrible but we are stuck with it for
-historical reasons.)
address@hidden, 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}:
@@ -5625,7 +5625,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
@@ -5634,16 +5634,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},
address@hidden, 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}).
+(@address@hidden), each defined in its own file
+(@address@hidden).
 
 @example
 AM_LDFLAGS = -module
diff --git a/tests/Makefile.am b/tests/Makefile.am
index cc95743..5627913 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -529,6 +529,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
index 0000000..4f21cc7
--- /dev/null
+++ b/tests/specflg10.test
@@ -0,0 +1,71 @@
+#! /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 = .cpp
+endif
+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.cpp
+
+$ACLOCAL
+$AUTOCONF
+# Conditional AM_DEFAULT_SOURCE_EXT
+AUTOMAKE_fails --add-missing
+
+sed '/^if/d; /^endif/d' sub2/Makefile.am > t
+mv -f t sub2/Makefile.am
+$AUTOMAKE --add-missing
+
+./configure
+$MAKE
+$MAKE distcheck
+
+:




reply via email to

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