Am 05.01.2017 um 15:31 schrieb Jim Meyering:
On Mon, Aug 29, 2016 at 11:05 PM, Thomas Martitz <ku...@rockbox.org> wrote:
This option is intended to be used in conjunction with subdir-objects and
Automake-time substitutions for included makefile fragments (%C%, %D%).
Enabling the option shortens the file name of object files such that the
prefix
derived (after canonicalization) from the path is not included.
Enabling the option is basically equivalent to setting foo_SHORTNAME =
foo. However, it also works flawlessly if a Makefile fragment is
conditionally included. Note that actually setting foo_SHORTNAME
still overrides the object name, regardless of this option. This can improve
the modularity of Automake-using projects.
Example:
without object-shortname
sub/Makefile.am:
bin_PROGRAMS += %D%/foo
%C%_foo_CFLAGS = $(AM_CFLAGS) -g
results in objects:
sub/sub_foo-foo.o
with object-shortname the object file name is:
sub/foo-foo.o
And it allows the following in $(top_srcdir)/Makefile.am (not possible with
foo_SHORTNAME=foo)
if ENABLE_SUB
include sub/Makefile.am
endif
Hi Thomas,
Thanks for the addition.
I've only spent a few minutes reading discussion about this patch and
even less looking at the actual code, but so far, I have seen no
addition to the test suite. I suggest you copy an existing test as a
starting point, add something like the above in its Makefile.am
section, and then ensure that the new artifacts appear in the
generated Makefile.in.
You are absolutely right. I added a test case. I hope this is alright?
Best regards
From f5704dffe09c600ae7c90069ef9f6681c8047f49 Mon Sep 17 00:00:00 2001
From: Thomas Martitz <kugel@rockbox.org>
Date: Wed, 6 Jan 2016 10:02:43 +0100
Subject: [PATCH 1/2] new option: object-shortname
This option is intended to be used in conjunction with subdir-objects and
Automake-time substitutions for included makefile fragments (%C%, %D%).
Enabling the option shortens the file name of object files such that the prefix
derived (after canonicalization) from the path is not included.
Enabling the option is basically equivalent to setting foo_SHORTNAME =
foo. However, it also works flawlessly if a Makefile fragment is
conditionally included. Note that actually setting foo_SHORTNAME
still overrides the object name, regardless of this option. This can improve
the modularity of Automake-using projects.
Example:
without object-shortname
sub/Makefile.am:
bin_PROGRAMS += %D%/foo
%C%_foo_CFLAGS = $(AM_CFLAGS) -g
results in objects:
sub/sub_foo-foo.o
with object-shortname the object file name is:
sub/foo-foo.o
And it allows the following in $(top_srcdir)/Makefile.am (not possible with foo_SHORTNAME=foo)
if ENABLE_SUB
include sub/Makefile.am
endif
---
NEWS | 8 ++++++++
bin/automake.in | 19 ++++++++++++++++++-
doc/automake.texi | 47 +++++++++++++++++++++++++++++++++++++++++++++++
lib/Automake/Options.pm | 1 +
4 files changed, 74 insertions(+), 1 deletion(-)
diff --git a/NEWS b/NEWS
index af904d442..15563891f 100644
--- a/NEWS
+++ b/NEWS
@@ -64,6 +64,14 @@
New in 1.16:
+* New option object-shortname
+
+ - This option affects the file name Automake uses for object files. Enabling
+ gives shorter, path-independent default object file names.
+
+ - It does not affect the directory where these object files will be placed.
+ Thus, it is recommended to combine this option with subdir-objects.
+
* Bugs fixed:
- Automatic dependency tracking has been fixed to work also when the
diff --git a/bin/automake.in b/bin/automake.in
index 09a1c956b..b5d3aca3c 100644
--- a/bin/automake.in
+++ b/bin/automake.in
@@ -1711,7 +1711,24 @@ sub handle_single_transform
# some situations. So we provide _SHORTNAME to
# override.
- my $dname = $derived;
+ my $dname = $derived;
+ if (option 'object-shortname')
+ {
+ # If object-shortname is enabled the object's filename shall not contain
+ # the parts derived from its path (e.g. if %C% is used), but just the
+ # name of the object's target e.g. instead of path_to_binary-object.o
+ # just binary-object
+ my $dirname = dirname ($_file);
+ if ($dirname ne ".")
+ {
+ my $canon_dirname = canonicalize ($dirname) . "_";
+ # should never fail since $derived is also
+ # constructed using canonicalize()
+ prog_error("unexpected object name: " . $derived)
+ if (index ($derived, $canon_dirname) != 0);
+ $dname = substr ($derived, length ($canon_dirname));
+ }
+ }
my $var = var ($derived . '_SHORTNAME');
if ($var)
{
diff --git a/doc/automake.texi b/doc/automake.texi
index e46212f98..e15ad48b3 100644
--- a/doc/automake.texi
+++ b/doc/automake.texi
@@ -10286,6 +10286,53 @@ the source file. For instance, if the source file is
@file{subdir/file.cxx}, then the output file would be
@file{subdir/file.o}.
+@item @option{object-shortname}
+@cindex Options, @option{object-shortname}
+@opindex object-shortname
+If this option is specified, then object names constructed by Automake are
+shortened such that they are prefixed only by the target variable they build,
+therefore omitting the canonicalized path (@pxref{Canonicalization}). The
+effect is particularly visible if you use @file{Makefile} fragment inclusion
+feature (@pxref{Include}). Here, object names for files prefixed by @code{%D%}
+would be named @samp{path_to_foo-object.o}. With the this option the object
+name becomes just @samp{foo-object.o}.
+
+Enabling the option is basically equivalent to setting @code{foo_SHORTNAME =
+foo}. However, it also works if a Makefile fragment is conditionally included.
+Note that actually setting @code{foo_SHORTNAME} still overrides the object
+name, regardless of this option.
+
+It is recommended to combine this option and @option{subdir-objects} because
+the object names become independent of the path to the source files. This
+increases the possibility of object file name conflicts if only a single output
+directory is used.
+
+The rationale for this option is to allow a setup where there is a top-level
+@file{Makefile.am} which includes fragments from subdirectories, and a Makefile
+is generated in each directory.
+
+@example
+Makefile.am:
+@code{if ENABLE_SUB}
+@code{include sub/Makefile.am}
+@code{endif}
+
+sub/Makefile.am:
+@code{bin_PROGRAMS = %D%/foo}
+@code{%C%_foo_CFLAGS = $(AM_CFLAGS) -g}
+@end example
+
+Provided @option{subdir-objects} is enabled, executing @command{make} in either
+directory will build @file{foo} using the same object files. Without this
+option, the object file names would be different (@file{sub_foo-foo.o} and
+@file{foo-foo.o}), resulting in extraneous rebuilds and duplicated object
+files. Without subdir-objects the object file names are identical but since
+they are placed in different directories rebuilds still occur.
+
+The benefit of this setup is that executing @command{make} in the top-level
+directory does not use recursive make, which is usually faster and brings
+global knowledge about dependencies (@pxref{Subdirectories}).
+
@anchor{tar-formats}
@item @option{tar-v7}
@itemx @option{tar-ustar}
diff --git a/lib/Automake/Options.pm b/lib/Automake/Options.pm
index a7f271caf..03f212318 100644
--- a/lib/Automake/Options.pm
+++ b/lib/Automake/Options.pm
@@ -293,6 +293,7 @@ sub _is_valid_easy_option ($)
silent-rules
std-options
subdir-objects
+ object-shortname
);
}
--
2.11.0
From f8f32acd38dce7d9aaaf14780f208557916aaaa0 Mon Sep 17 00:00:00 2001
From: Thomas Martitz <kugel@rockbox.org>
Date: Fri, 6 Jan 2017 16:29:18 +0100
Subject: [PATCH 2/2] tests: add test for new object-shortname option
The test ensures the object's file name is short, as expected for the
object-shortname option. It also ensures it's not short without the option.
---
t/list-of-tests.mk | 1 +
t/test-object-shortname.sh | 72 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+)
create mode 100644 t/test-object-shortname.sh
diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk
index defca1361..f3026eff9 100644
--- a/t/list-of-tests.mk
+++ b/t/list-of-tests.mk
@@ -1191,6 +1191,7 @@ t/tar-ustar-id-too-high.sh \
t/tar-override.sh \
t/target-cflags.sh \
t/targetclash.sh \
+t/test-object-shortname.sh \
t/tests-environment-fd-redirect.sh \
t/tests-environment-and-log-compiler.sh \
t/txinfo-absolute-srcdir-pr408.sh \
diff --git a/t/test-object-shortname.sh b/t/test-object-shortname.sh
new file mode 100644
index 000000000..9e2ab8a69
--- /dev/null
+++ b/t/test-object-shortname.sh
@@ -0,0 +1,72 @@
+#! /bin/sh
+# Copyright (C) 1996-2015 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 2, 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/>.
+
+# Test to make sure the object-shortname option works as advertised
+
+. test-init.sh
+
+mkdir -p one/two
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+
+AC_CONFIG_FILES([Makefile2])
+AC_OUTPUT
+END
+
+# Files required because we are using '--gnu'.
+: > INSTALL
+: > NEWS
+: > README
+: > COPYING
+: > AUTHORS
+: > ChangeLog
+
+cat > Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+include one/Makefile.inc
+END
+
+cat > Makefile2.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects object-shortname
+include one/Makefile.inc
+END
+
+cat > one/Makefile.inc << 'END'
+include %D%/two/Makefile.inc
+END
+
+cat > one/two/Makefile.inc << 'END'
+noinst_PROGRAMS = %D%/test
+%C%_test_CFLAGS = $(AM_CFLAGS)
+%C%_test_SOURCES = %D%/test.c
+END
+
+cat > one/two/test.c << 'END'
+int main()
+{
+ return 0;
+}
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --gnu
+
+./configure
+$MAKE -f Makefile && test -f one/two/one_two_test-test.o && test ! -f one/two/test-test.o
+$MAKE clean
+$MAKE -f Makefile2 && test -f one/two/test-test.o && test ! -f one/two/one_two_test-test.o
--
2.11.0