diff --git a/conan/tools/gnu/autotoolstoolchain.py b/conan/tools/gnu/autotoolstoolchain.py index df84c6c2d83..58115a6072b 100644 --- a/conan/tools/gnu/autotoolstoolchain.py +++ b/conan/tools/gnu/autotoolstoolchain.py @@ -13,9 +13,10 @@ class AutotoolsToolchain: - def __init__(self, conanfile, namespace=None): + def __init__(self, conanfile, namespace=None, prefix="/"): self._conanfile = conanfile self._namespace = namespace + self._prefix = prefix self.configure_args = self._default_configure_shared_flags() + self._default_configure_install_flags() self.autoreconf_args = self._default_autoreconf_flags() @@ -168,7 +169,7 @@ def _get_argument(argument_name, cppinfo_name): return "--{}=${{prefix}}/{}".format(argument_name, elements[0]) if elements else "" # If someone want arguments but not the defaults can pass them in args manually - configure_install_flags.extend(["--prefix=/", + configure_install_flags.extend([f"--prefix={self._prefix}", _get_argument("bindir", "bindirs"), _get_argument("sbindir", "bindirs"), _get_argument("libdir", "libdirs"), diff --git a/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py b/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py index 1b9b3269abe..9c91d3c8ef1 100644 --- a/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py +++ b/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py @@ -1,3 +1,4 @@ +import os import platform import textwrap @@ -67,3 +68,28 @@ def generate(self): client.save({"conanfile.py": conanfile}) client.run("install .") + +def test_set_prefix(): + + conanfile = textwrap.dedent(""" + from conan import ConanFile + from conan.tools.gnu import AutotoolsToolchain + from conan.tools.layout import basic_layout + + + class Foo(ConanFile): + name = "foo" + version = "1.0" + def layout(self): + basic_layout(self) + def generate(self): + at_toolchain = AutotoolsToolchain(self, prefix="/somefolder") + at_toolchain.generate() + """) + + client = TestClient() + client.save({"conanfile.py": conanfile}) + client.run("install .") + conanbuild = client.load(os.path.join(client.current_folder, "build", "conan", "conanbuild.conf")) + assert "--prefix=/somefolder" in conanbuild + assert conanbuild.count("--prefix") == 1