From 35e5c744b2db5f1e87036d6e24758f5f99db535e Mon Sep 17 00:00:00 2001
From: Isuru Fernando <isuruf@gmail.com>
Date: Thu, 16 Sep 2021 15:46:09 -0500
Subject: [PATCH 07/25] bpo-22699: Allow compiling on debian/ubuntu with a
 different compiler

This PR fixes one issue mentioned in the bpo
https://bugs.python.org/issue22699#msg364685 with a slightly better
patch than given
---
 setup.py | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index a15a7a46e0..1bb48591c6 100644
--- a/setup.py
+++ b/setup.py
@@ -687,9 +687,27 @@ def check_extension_import(self, ext):
     def add_multiarch_paths(self):
         # Debian/Ubuntu multiarch support.
         # https://wiki.ubuntu.com/MultiarchSpec
-        tmpfile = os.path.join(self.build_temp, 'multiarch')
+        cc = sysconfig.get_config_var('CC')
         if not os.path.exists(self.build_temp):
             os.makedirs(self.build_temp)
+
+        tmpfile_sysroot = os.path.join(self.build_temp, 'sysroot')
+        ret_sysroot = run_command(
+            '%s -print-sysroot > %s 2> /dev/null' % (cc, tmpfile_sysroot))
+
+        try:
+            if ret_sysroot == 0:
+                with open(tmpfile_sysroot) as fp:
+                    sysroot = fp.readline().strip()
+                    # if the sysroot is not /, then we are not using
+                    # the compiler from debian/ubuntu
+                    if sysroot not in ['', '/']:
+                        return
+        finally:
+            os.unlink(tmpfile_sysroot)
+
+        tmpfile = os.path.join(self.build_temp, 'multiarch')
+
         ret = run_command(
             '%s -print-multiarch > %s 2> /dev/null' % (CC, tmpfile))
         multiarch_path_component = ''
-- 
2.32.1 (Apple Git-133)

