From a6f536ce5753e95d2ecfd392ebc7deb37aceea09 Mon Sep 17 00:00:00 2001
From: Samuli Piippo <samuli.piippo@qt.io>
Date: Wed, 15 Mar 2017 13:53:28 +0200
Subject: [PATCH] Force host toolchain configuration

Force gcc/g++ to be used for parts using host toolchain, since
the option(host_build) does not work in yocto builds.

Don't use QT_ARCH for the host architecture, since that's always
the target architecture in bitbake builds, instead ask specifically
for the qmakes's host architecture.

Upstream-Status: Inappropriate [OE specific]
Signed-off-by: Samuli Piippo <samuli.piippo@qt.io>
---
 src/buildtools/config/linux.pri   |  2 +-
 src/buildtools/configure_host.pro | 14 +++++++-------
 src/buildtools/gn.pro             |  4 ++--
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/buildtools/config/linux.pri b/src/buildtools/config/linux.pri
index 455a2e3c..6178d860 100644
--- a/src/buildtools/config/linux.pri
+++ b/src/buildtools/config/linux.pri
@@ -122,7 +122,7 @@ contains(QT_ARCH, "mips") {
 
 host_build {
     gn_args += custom_toolchain=\"$$QTWEBENGINE_OUT_ROOT/src/toolchain:host\"
-    GN_HOST_CPU = $$gnArch($$QT_ARCH)
+    GN_HOST_CPU = $$gnArch($$QMAKE_HOST.arch)
     gn_args += host_cpu=\"$$GN_HOST_CPU\"
     # Don't bother trying to use system libraries in this case
     gn_args += use_glib=false
diff --git a/src/buildtools/configure_host.pro b/src/buildtools/configure_host.pro
index dd0d3e32..6312c867 100644
--- a/src/buildtools/configure_host.pro
+++ b/src/buildtools/configure_host.pro
@@ -4,7 +4,7 @@ TEMPLATE = aux
 # Pick up the host toolchain
 option(host_build)
 
-GN_HOST_CPU = $$gnArch($$QT_ARCH)
+GN_HOST_CPU = $$gnArch($$QMAKE_HOST.arch)
 !isEmpty(QT_TARGET_ARCH): GN_TARGET_CPU = $$gnArch($$QT_TARGET_ARCH)
 else: GN_TARGET_CPU = $$GN_HOST_CPU
 GN_OS = $$gnOS()
@@ -31,9 +31,9 @@ GN_CONTENTS = \
 "import(\"//build/config/sysroot.gni\")" \
 "import(\"//build/toolchain/gcc_toolchain.gni\")" \
 "gcc_toolchain(\"host\") {" \
-"  cc = \"$$which($$QMAKE_CC)\" " \
-"  cxx = \"$$which($$QMAKE_CXX)\" " \
-"  ld = \"$$which($$QMAKE_LINK)\" " \
+"  cc = \"$$which($$CC_host)\" " \
+"  cxx = \"$$which($$CXX_host)\" " \
+"  ld = \"$$which($$CXX_host)\" " \
 "  ar = \"$$which(ar)\" " \
 "  nm = \"$$which(nm)\" " \
 "  extra_cppflags = \"$$GN_HOST_EXTRA_CPPFLAGS\" " \
@@ -45,9 +45,9 @@ GN_CONTENTS = \
 "  } " \
 "}" \
 "gcc_toolchain(\"v8_snapshot\") {" \
-"  cc = \"$$which($$QMAKE_CC)\" " \
-"  cxx = \"$$which($$QMAKE_CXX)\" " \
-"  ld = \"$$which($$QMAKE_LINK)\" " \
+"  cc = \"$$which($$CC_host)\" " \
+"  cxx = \"$$which($$CXX_host)\" " \
+"  ld = \"$$which($$CXX_host)\" " \
 "  ar = \"$$which(ar)\" " \
 "  nm = \"$$which(nm)\" " \
 "  toolchain_args = { " \
diff --git a/src/buildtools/gn.pro b/src/buildtools/gn.pro
index 033202e6..a8ca6567 100644
--- a/src/buildtools/gn.pro
+++ b/src/buildtools/gn.pro
@@ -19,8 +19,8 @@ build_pass|!debug_and_release {
             gn_bootstrap = $$system_path($$absolute_path(gn/build/gen.py, $$src_3rd_party_dir))
 
             gn_gen_args = --no-last-commit-position --out-path $$out_path \
-                          --cc \"$$which($$QMAKE_CC)\" --cxx \"$$which($$QMAKE_CXX)\" \
-                          --ld \"$$which($$QMAKE_LINK)\"
+                          --cc \"$$which($$CC_host)\" --cxx \"$$which($$CXX_host)\" \
+                          --ld \"$$which($$CXX_host)\" --ar \"$$which(ar)\"
 
             msvc:!clang_cl: gn_gen_args += --use-lto
 
