Skip to content

Commit 8aa1599

Browse files
committed
Make Autotools respect tools.build:install_strip
Make Autotools strip libraries if requested, consistent with CMake and Meson, by using the 'install-strip' target instead of 'install'.
1 parent 025cd9c commit 8aa1599

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

conan/tools/gnu/autotools.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ def make(self, target=None, args=None, makefile=None):
8484
command = join_arguments([make_program, str_makefile, target, str_args, str_extra_args, jobs])
8585
self._conanfile.run(command)
8686

87-
def install(self, args=None, target="install", makefile=None):
87+
def install(self, args=None, target=None, makefile=None):
8888
"""
89-
This is just an "alias" of ``self.make(target="install")``
89+
This is just an "alias" of ``self.make(target="install")`` or ``self.make(target="install-strip")``
9090
9191
:param args: (Optional, Defaulted to ``None``): List of arguments to use for the
9292
``make`` call. By default an argument ``DESTDIR=unix_path(self.package_folder)``
@@ -95,6 +95,11 @@ def install(self, args=None, target="install", makefile=None):
9595
:param target: (Optional, Defaulted to ``None``): Choose which target to install.
9696
:param makefile: (Optional, Defaulted to ``None``): Allow specifying a custom makefile to use instead of default "Makefile"
9797
"""
98+
if target is None:
99+
target = "install"
100+
do_strip = self._conanfile.conf.get("tools.build:install_strip", check_type=bool)
101+
if do_strip:
102+
target += "-strip"
98103
args = args if args else []
99104
str_args = " ".join(args)
100105
if "DESTDIR=" not in str_args:

test/unittests/tools/gnu/autotools_test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,28 @@ def test_source_folder_works(chdir_mock):
3333
autotools.autoreconf()
3434
chdir_mock.assert_called_with(autotools, os.path.normpath("/path/to/sources"))
3535
assert conanfile.command == 'autoreconf -bar foo'
36+
37+
@pytest.mark.parametrize("install_strip", [False, True])
38+
def test_install_strip(install_strip):
39+
"""
40+
When the configuration `tools.build:install_strip` is set to True,
41+
the Autotools install command should invoke the `install-strip` target.
42+
"""
43+
44+
settings = MockSettings({"build_type": "Release",
45+
"compiler": "gcc",
46+
"compiler.version": "7",
47+
"os": "Linux",
48+
"arch": "x86_64"})
49+
conanfile = ConanFileMock()
50+
conanfile.settings = settings
51+
conanfile.conf = Conf()
52+
conanfile.conf["tools.build:install_strip"] = install_strip
53+
conanfile.folders.generators = "."
54+
conanfile.folders.set_base_generators(temp_folder())
55+
conanfile.folders.set_base_package(temp_folder())
56+
57+
autotools = Autotools(conanfile)
58+
autotools.install()
59+
60+
assert ('install-strip' in str(conanfile.command)) == install_strip

0 commit comments

Comments
 (0)