From c59622c07dc9a72cba9b87779b470582eb612c32 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Thu, 16 Sep 2021 15:46:09 -0500 Subject: [PATCH 08/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 | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b2d68de7cd..ddaa6d743c 100644 --- a/setup.py +++ b/setup.py @@ -666,9 +666,30 @@ 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') 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 ['', '/']: + add_dir_to_list(self.compiler.library_dirs, + sysroot + '/usr/lib/') + add_dir_to_list(self.compiler.include_dirs, + sysroot + '/usr/include/') + 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 = ''