[PATCH] new option: object-shortname

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[PATCH] new option: object-shortname

Thomas Martitz-2
This option is intended to be used in conjunction with subdir-objects and
Automake-time substitutions for included makefile fragments (%C%, %D%). It
suppresses the generation path components in object filenames.

It should equivalent to setting %C%_foo_SHORTNAME=foo, except it can work if
the makefile fragment is conditionally included, which improves the modularity
of Automake-using projects.

Example:
without object-shortname
   root/path/to/Makefile.am:
   bin_PROGRAMS += foo
   %C%_foo_CFLAGS = $(CFLAGS)

results in objects:
   root/path/to/root_path_to_foo-foo.o

with object-shortname the object filename is:
   root/path/to/foo-foo.o

And it allows the following in root/Makefile.am (not possible with foo_SHORTNAME=foo)
   if ENABLE_FOO
   include path/too/Makefile.am
   endif

* bin/automake.in: Handle new object-shortname option
* lib/Automake/Options.pm: Add the option

---
  bin/automake.in         | 13 +++++++++++++
  lib/Automake/Options.pm |  1 +
  2 files changed, 14 insertions(+)

diff --git a/bin/automake.in b/bin/automake.in
index eedc8bc..cea04c6 100644
--- a/bin/automake.in
+++ b/bin/automake.in
@@ -1691,6 +1691,19 @@ 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) . "_";
+ # paranoid check: should never fail but ensure path prefix is part of the filename
+ if (index ($derived, $canon_dirname) == 0) {
+ $dname = substr ($derived, length ($canon_dirname));
+ }
+ }
+ }
  my $var = var ($derived . '_SHORTNAME');
  if ($var)
  {
diff --git a/lib/Automake/Options.pm b/lib/Automake/Options.pm
index 7d782c3..819c5ff 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.7.0


Loading...