>From d6163111d30ecc4e2c98018d6a405b131f7a7a3d Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Wed, 6 Jan 2016 10:02:43 +0100 Subject: [PATCH] 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 | 14 ++++++++++++++ bin/automake.in | 14 ++++++++++++++ doc/automake.texi | 45 +++++++++++++++++++++++++++++++++++++++++++++ lib/Automake/Options.pm | 1 + 4 files changed, 74 insertions(+) diff --git a/NEWS b/NEWS index af904d4..c47736e 100644 --- a/NEWS +++ b/NEWS @@ -64,6 +64,20 @@ New in 1.16: +* New option object-shortname + + - This option affects the file name automake uses for object files. + + Enabling the option shortens the file name such that the prefix + derived (after canonicalization) from the path is not included. For + instance, it is always foo-foo.o regardless of the path leading to the + source file. + + It does not change the directory where these object files will be placed. + Thus, it is recommended to combine this option with subdir-objects. + + - Please read the corresponding manual entry for an extensive description. + * Bugs fixed: - Automatic dependency tracking has been fixed to work also when the diff --git a/bin/automake.in b/bin/automake.in index 09a1c95..c337435 100644 --- a/bin/automake.in +++ b/bin/automake.in @@ -1712,6 +1712,20 @@ sub handle_single_transform # override. 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 e46212f..a0554cd 100644 --- a/doc/automake.texi +++ b/doc/automake.texi @@ -10286,6 +10286,51 @@ the source file. For instance, if the source file is @file{subdir/file.cxx}, then the output file would be @file{subdir/file.o}. address@hidden @option{object-shortname} address@hidden Options, @option{object-shortname} address@hidden 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 ommitting the canonicalized path (@pxref{Canonicalization}). The +effect is particularly visible if you use 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 flawlessly if a Makefile fragment is +conditionally included. Note that actually setting @code{foo_SHORTNAME} +still overrides the object name, regardless of this option. + +This is best combined with @option{subdir-objects} because it file name +conflicts become more likely. + +The rationale for this option is to allow a setup where there is a top-level address@hidden which includes fragments from subdirectories, which also +generate a Makefile. + address@hidden +Makefile.am: address@hidden ENABLE_SUB} address@hidden sub/Makefile.am} address@hidden + +sub/Makefile.am: address@hidden = %D%/foo} address@hidden = $(AM_CFLAGS) -g} address@hidden 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 address@hidden), 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 a7f271c..03f2123 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.9.3