Repository: conan-io/conan

Issue:
[feature] Add `tools.gnu:build_triplet` to conf
### What is your suggestion?

Related to https://github.com/conan-io/conan/issues/14947

Instead of changing the recipe, it'd be great to have a conf mechanism to change the build triplet like:

```
[conf]
tools.gnu:build_triplet="build_triplet"
```
For now, it's only used by AutotoolsToolchain. The question is: Should the rest of the toolchains read that conf/s too?

### Have you read the CONTRIBUTING guide?

- [ ] I've read the CONTRIBUTING guide


Discussion:

Patch:
diff --git a/conan/tools/gnu/autotoolstoolchain.py b/conan/tools/gnu/autotoolstoolchain.py
index e106367c047..4142494a474 100644
--- a/conan/tools/gnu/autotoolstoolchain.py
+++ b/conan/tools/gnu/autotoolstoolchain.py
@@ -56,7 +56,7 @@ def __init__(self, conanfile, namespace=None, prefix="/"):
 
         # Cross build triplets
         self._host = self._conanfile.conf.get("tools.gnu:host_triplet")
-        self._build = None
+        self._build = self._conanfile.conf.get("tools.gnu:build_triplet")
         self._target = None
 
         self.apple_arch_flag = self.apple_isysroot_flag = None
@@ -78,7 +78,8 @@ def __init__(self, conanfile, namespace=None, prefix="/"):
             if not self._host:
                 self._host = _get_gnu_triplet(os_host, arch_host, compiler=compiler)
             # Build triplet
-            self._build = _get_gnu_triplet(os_build, arch_build, compiler=compiler)
+            if not self._build:
+                self._build = _get_gnu_triplet(os_build, arch_build, compiler=compiler)
             # Apple Stuff
             if os_build == "Macos" and is_apple_os(conanfile):
                 # SDK path is mandatory for cross-building
diff --git a/conans/model/conf.py b/conans/model/conf.py
index d35ec8fa752..f74ee2107c4 100644
--- a/conans/model/conf.py
+++ b/conans/model/conf.py
@@ -86,6 +86,7 @@
     "tools.gnu:make_program": "Indicate path to make program",
     "tools.gnu:define_libcxx11_abi": "Force definition of GLIBCXX_USE_CXX11_ABI=1 for libstdc++11",
     "tools.gnu:pkg_config": "Path to pkg-config executable used by PkgConfig build helper",
+    "tools.gnu:build_triplet": "Custom build triplet to pass to Autotools scripts",
     "tools.gnu:host_triplet": "Custom host triplet to pass to Autotools scripts",
     "tools.google.bazel:configs": "List of Bazel configurations to be used as 'bazel build --config=config1 ...'",
     "tools.google.bazel:bazelrc_path": "List of paths to bazelrc files to be used as 'bazel --bazelrc=rcpath1 ... build'",


Test patch:
diff --git a/conans/test/unittests/client/toolchain/autotools/autotools_toolchain_test.py b/conans/test/unittests/client/toolchain/autotools/autotools_toolchain_test.py
index 47650ab9a18..d8fa16cf938 100644
--- a/conans/test/unittests/client/toolchain/autotools/autotools_toolchain_test.py
+++ b/conans/test/unittests/client/toolchain/autotools/autotools_toolchain_test.py
@@ -57,6 +57,7 @@ def test_invalid_target_triple():
     assert "Unknown 'UNKNOWN_ARCH' machine, Conan doesn't know how " \
            "to translate it to the GNU triplet," in str(excinfo)
 
+
 def test_custom_host_triple():
     conanfile = ConanFileMock()
     conanfile.settings = MockSettings({"os": "Linux", "arch": "x86"})
@@ -67,6 +68,18 @@ def test_custom_host_triple():
     obj = load_toolchain_args()
     assert "--host=i686-pc-linux-gnu" in obj["configure_args"]
 
+
+def test_custom_build_triple():
+    conanfile = ConanFileMock()
+    conanfile.settings = MockSettings({"os": "Linux", "arch": "x86"})
+    conanfile.settings_build = MockSettings({"os": "Linux", "arch": "x86_64"})
+    conanfile.conf.define("tools.gnu:build_triplet", "i686-pc-linux-gnu")
+    tc = AutotoolsToolchain(conanfile)
+    tc.generate_args()
+    obj = load_toolchain_args()
+    assert "--build=i686-pc-linux-gnu" in obj["configure_args"]
+
+
 def test_cppstd():
     # Using "cppstd" is discarded
     conanfile = ConanFileMock()