[Top][All Lists]

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

[PATCH] Silent make output for custom link commands

From: Nick Gasson
Subject: [PATCH] Silent make output for custom link commands
Date: Thu, 15 Jul 2021 21:41:31 +0800

In my project I use a custom _LINK variable for a particular target which
needs to force using the C++ linker for an otherwise C program when linking
statically against a C++ library.  I do it like this:

  # Force linking as C++ to allow LLVM static libraries
  nodist_EXTRA_bin_nvc_SOURCES = dummy.cxx   # Make sure CXXLD is defined
  bin_nvc_LINK = $(CXXLD) $(AM_CFLAGS) $(CFLAGS) $(bin_nvc_LDFLAGS) -o $@
  bin_nvc_LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(bin_nvc_LDFLAGS) -o $@

This works well except when using silent make rules where it prints "GEN"
instead of the usual "CCLD" or "CXXLD".  The patch below allows one to define
a AM_V_*_LINK variable which is used instead of the default AM_V_GEN.  In the
above example I would just add

  AM_V_bin_nvc_LINK = $(AM_V_CCLD)

to get the expected output.

* bin/ (define_per_target_linker_variable): Use AM_V_${target}_LINK
if defined as the verbose variable name for custom link commands.
* doc/automake.texi (Program and Library Variables): Document the new
* t/ Add extra checks for silent make rules.
 bin/    | 8 ++++++--
 doc/automake.texi  | 3 +++
 t/ | 7 +++++++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/bin/ b/bin/
index f6ebe30ea8b4..f04f5d5f5554 100644
--- a/bin/
+++ b/bin/
@@ -6360,8 +6360,12 @@ sub define_per_target_linker_variable
   my ($linker, $target) = @_;
   # If the user wrote a custom link command, we don't define ours.
-  return "${target}_LINK"
-    if set_seen "${target}_LINK";
+  my $custom_link = "${target}_LINK";
+  if (set_seen ($custom_link))
+    {
+      my $verbose = $custom_link if var (verbose_var ($custom_link));
+      return ($custom_link, $verbose);
+    }
   my $xlink = $linker ? $linker : 'LINK';
diff --git a/doc/automake.texi b/doc/automake.texi
index dd932ddd796a..2babde9d6ddc 100644
--- a/doc/automake.texi
+++ b/doc/automake.texi
@@ -5903,6 +5903,9 @@ and used by Automake due to the use of per-target link 
flags such as
 @code{_CFLAGS}, @code{_LDFLAGS} or @code{_LIBTOOLFLAGS}, in cases where
 they apply.
+If the variable @code{AM_V_*_LINK} exists it will be used to output a
+status line in silent mode, otherwise @code{AM_V_GEN} is used.
 @item maude_CCASFLAGS
 @itemx maude_CFLAGS
 @itemx maude_CPPFLAGS
diff --git a/t/ b/t/
index 1ac45fc5d240..81787af914ec 100644
--- a/t/
+++ b/t/
@@ -27,6 +27,8 @@ bin_PROGRAMS = foo bar baz boo
 foo_LINK = $(LINK)
 bar_LINK = $(LINK)
+baz_LINK = $(LINK)
+AM_V_baz_LINK = xyz
@@ -41,4 +43,9 @@ grep '.\$(LINK).*foo' && exit 1
 grep '^ *bar_LINK *=.*bar_LDFLAGS' && exit 1
 grep '.\$(bar_LINK).*bar'
+# Silent make rules should use AM_V_GEN unless overriden.
+grep '.\$(AM_V_GEN)\$(foo_LINK)'
+grep '.\$(AM_V_baz_LINK)\$(baz_LINK)'
+grep '.\$(AM_V_GEN)\$(baz_LINK)' && exit 1
 exit 0

reply via email to

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