Subject: bug#54020: Allow user-defined libtool options

From: Bogdan <[email-masked]>
Date: Wed, 15 Mar 2023 17:31:48 +0100

Hi, Automakers!

  Another patch from my side. This one makes it possible for users to 
pass additional options to libtool in 'compile' mode. Fixes #54020.

  Added documentation and a test case including the '-no-suppress' 
option. All tests with 'lt' or 'libtool' in the name pass.

  Feel free to rename the variables, I just came up with the names 
LTCOMPILE_PREFLAGS and LTCOMPILE_POSTFLAGS, reflecting the positions 
where the variables are put and the mode they're used in.

-- 
Regards - Bogdan ('bogdro') D.                 (GNU/Linux & FreeDOS)
X86 assembly (DOS, GNU/Linux):    http://bogdro.evai.pl/index-en.php
Soft(EN): http://bogdro.evai.pl/soft  http://bogdro.evai.pl/soft4asm
www.Xiph.org  www.TorProject.org  www.LibreOffice.org  www.GnuPG.org

From 907c8b7913d1c577b722a24b24cdf9cd8e97755e Mon Sep 17 00:00:00 2001
From: Bogdan Drozdowski <>
Date: Wed, 15 Mar 2023 17:21:52 +0100
Subject: [PATCH] Add support for compile-mode extra libtool options

---
 bin/automake.in    |  6 +++--
 doc/automake.texi  |  8 +++++++
 t/list-of-tests.mk |  1 +
 t/lt_extraopts.sh  | 55 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 68 insertions(+), 2 deletions(-)
 create mode 100644 t/lt_extraopts.sh

diff --git a/bin/automake.in b/bin/automake.in
index f249064d5..c9e235938 100644
--- a/bin/automake.in
+++ b/bin/automake.in
@@ -1474,7 +1474,7 @@ sub handle_languages ()
 	    my $ltverbose = define_verbose_libtool ();
 	    my $obj_ltcompile =
 	      "\$(LIBTOOL) $ltverbose $libtool_tag\$($ptltflags) \$(LIBTOOLFLAGS) "
-	      . "--mode=compile $obj_compile";
+	      . "--mode=compile \$(LTCOMPILE_PREFLAGS) $obj_compile \$(LTCOMPILE_POSTFLAGS)";
 
 	    # We _need_ '-o' for per object rules.
 	    my $output_flag = $lang->output_flag || '-o';
@@ -6331,7 +6331,9 @@ sub define_compiler_variable
 	my $verbose = define_verbose_libtool ();
 	define_variable ("LT$var",
                          "\$(LIBTOOL) $verbose $libtool_tag\$(AM_LIBTOOLFLAGS)"
-                         . " \$(LIBTOOLFLAGS) --mode=compile $value",
+                         . " \$(LIBTOOLFLAGS) --mode=compile "
+                         . "\$(LTCOMPILE_PREFLAGS) $value "
+                         . '$(LTCOMPILE_POSTFLAGS)',
                          INTERNAL);
       }
     define_verbose_tagvar ($lang->ccer || 'GEN');
diff --git a/doc/automake.texi b/doc/automake.texi
index ec14c5c4c..7138758dd 100644
--- a/doc/automake.texi
+++ b/doc/automake.texi
@@ -5607,6 +5607,14 @@ LIBTOOLFLAGS=--silent}, for instance.  Note that the verbosity of
 @command{libtool} can also be influenced by the Automake support
 for silent rules (@pxref{Automake Silent Rules}).
 
+The @samp{LTCOMPILE_PREFLAGS} variable is the place to list
+additional libtool compile flags to be put right after
+@option{--mode=compile} on the command line (only when compiling).
+
+Similarly, the @samp{LTCOMPILE_POSTFLAGS} variable is the place to list
+additional libtool compile flags to be put at the end of the command line
+(only when compiling).
+
 @node LTLIBOBJS, Libtool Issues, Libtool Flags, A Shared Library
 @subsection @code{LTLIBOBJS} and @code{LTALLOCA}
 @cindex @code{LTLIBOBJS}, special handling
diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk
index 6f25f0494..2bff2771c 100644
--- a/t/list-of-tests.mk
+++ b/t/list-of-tests.mk
@@ -685,6 +685,7 @@ t/ltinstloc.sh \
 t/ltlibobjs.sh \
 t/ltlibsrc.sh \
 t/ltorder.sh \
+t/lt_extraopts.sh \
 t/m4-inclusion.sh \
 t/maintclean.sh \
 t/maintclean-vpath.sh \
diff --git a/t/lt_extraopts.sh b/t/lt_extraopts.sh
new file mode 100644
index 000000000..d26f4e689
--- /dev/null
+++ b/t/lt_extraopts.sh
@@ -0,0 +1,55 @@
+#! /bin/sh
+# Copyright (C) 2023 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 <https://www.gnu.org/licenses/>.
+
+# Test the support for LTCOMPILE_PREFLAGS and LTCOMPILE_POSTFLAGS.
+# Also, a good place to test other similar options, if such come in the future.
+
+required='cc libtoolize'
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+AC_CONFIG_MACRO_DIRS([m4])
+LT_INIT
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+lib_LTLIBRARIES = libblah.la
+libblah_la_SOURCES = blah.c
+libblah_la_LDFLAGS = -version-info 1:0:0
+END
+
+cat > blah.c << 'END'
+int main (void)
+{
+   return 0;
+}
+END
+
+libtoolize --force --copy
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing --copy
+
+./configure
+
+run_make -M LTCOMPILE_PREFLAGS=--no-warnings LTCOMPILE_POSTFLAGS=-no-suppress
+grep -- '--mode=compile --no-warnings' output
+grep -- '-no-suppress' output
+
+:
-- 
2.35.1