Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 1 | Extensions should be installed to the targets libdir. This is important if e.g. host |
| 2 | has a 64bit /usr/lib64, but the target is 32bit and has $ROOT/usr/lib. Make sure we |
| 3 | respect the target's lib structure by getting the libdir name from Makefile. |
| 4 | |
| 5 | --- a/Lib/distutils/command/install.py |
| 6 | +++ b/Lib/distutils/command/install.py |
| 7 | @@ -38,8 +38,8 @@ |
| 8 | |
| 9 | INSTALL_SCHEMES = { |
| 10 | 'unix_prefix': { |
| 11 | - 'purelib': '$base/@@GENTOO_LIBDIR@@/python$py_version_short/site-packages', |
| 12 | - 'platlib': '$platbase/@@GENTOO_LIBDIR@@/python$py_version_short/site-packages', |
| 13 | + 'purelib': '$base/$libdirname/python$py_version_short/site-packages', |
| 14 | + 'platlib': '$platbase/$libdirname/python$py_version_short/site-packages', |
| 15 | 'headers': '$base/include/python$py_version_short/$dist_name', |
| 16 | 'scripts': '$base/bin', |
| 17 | 'data' : '$base', |
Jason D. Clinton | 2f60b84 | 2018-11-15 20:49:44 -0700 | [diff] [blame] | 18 | @@ -289,6 +289,8 @@ |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 19 | # everything else. |
| 20 | self.config_vars['base'] = self.install_base |
| 21 | self.config_vars['platbase'] = self.install_platbase |
Jason D. Clinton | 2f60b84 | 2018-11-15 20:49:44 -0700 | [diff] [blame] | 22 | + if not self.user and self.home is None: |
| 23 | + self.config_vars['libdirname'] = self.install_libdirname |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 24 | |
| 25 | if DEBUG: |
| 26 | from pprint import pprint |
| 27 | @@ -394,6 +395,10 @@ |
| 28 | |
| 29 | self.install_base = self.prefix |
| 30 | self.install_platbase = self.exec_prefix |
| 31 | + self.install_libdirname = os.path.basename(get_config_vars('LIBDIR')[0]) |
| 32 | + if self.install_libdirname is None: |
| 33 | + self.install_libdirname = '@@GENTOO_LIBDIR@@' |
| 34 | + |
| 35 | self.select_scheme("unix_prefix") |
| 36 | |
| 37 | # finalize_unix () |
| 38 | --- a/Lib/distutils/command/build_ext.py |
| 39 | +++ b/Lib/distutils/command/build_ext.py |
| 40 | @@ -201,7 +201,8 @@ |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 41 | and sysconfig.get_config_var('Py_ENABLE_SHARED'): |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 42 | if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")): |
| 43 | # building third party extensions |
| 44 | - self.library_dirs.append(sysconfig.get_config_var('LIBDIR')) |
| 45 | + sysroot = os.getenv('SYSROOT', '') |
| 46 | + self.library_dirs.append(sysroot + sysconfig.get_config_var('LIBDIR')) |
| 47 | else: |
| 48 | # building python standard extensions |
| 49 | self.library_dirs.append('.') |
| 50 | --- a/Lib/distutils/sysconfig.py |
| 51 | +++ b/Lib/distutils/sysconfig.py |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 52 | @@ -12,6 +12,7 @@ |
| 53 | __revision__ = "$Id$" |
| 54 | |
| 55 | import os |
| 56 | +import imp |
| 57 | import re |
| 58 | import string |
| 59 | import sys |
| 60 | @@ -19,9 +20,16 @@ |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 61 | from distutils.errors import DistutilsPlatformError |
| 62 | |
| 63 | # These are needed in a couple of spots, so just compute them once. |
| 64 | +SYSROOT = os.getenv('SYSROOT', '') |
| 65 | PREFIX = os.path.normpath(sys.prefix) |
| 66 | EXEC_PREFIX = os.path.normpath(sys.exec_prefix) |
| 67 | |
| 68 | +# Make sure we respect the user specified SYSROOT environment variable. |
| 69 | +# This is the first step to get distutils to crosscompile stuff. |
| 70 | +if SYSROOT: |
| 71 | + PREFIX = os.path.normpath(SYSROOT + os.path.sep + PREFIX) |
| 72 | + EXEC_PREFIX = os.path.normpath(SYSROOT + os.path.sep + EXEC_PREFIX) |
| 73 | + |
| 74 | # Path to the base directory of the project. On Windows the binary may |
| 75 | # live in project/PCBuild9. If we're dealing with an x64 Windows build, |
| 76 | # it'll live in project/PCbuild/amd64. |
Mike Frysinger | 74fb2fe | 2018-08-27 02:26:32 -0400 | [diff] [blame] | 77 | @@ -114,13 +122,30 @@ |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 78 | |
| 79 | If 'prefix' is supplied, use it instead of sys.prefix or |
| 80 | sys.exec_prefix -- i.e., ignore 'plat_specific'. |
| 81 | + |
| 82 | + For the posix system we can not always assume the host's notion of the |
| 83 | + libdir is the same for the target. e.g. compiling on an x86_64 system |
| 84 | + will use 'lib64' but an arm 32bit target will use 'lib'. So encode all |
| 85 | + the known lists of dirs and search them all (starting with the host one |
| 86 | + so that native builds work just fine). |
| 87 | """ |
| 88 | if prefix is None: |
| 89 | prefix = plat_specific and EXEC_PREFIX or PREFIX |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 90 | |
| 91 | if os.name == "posix": |
| 92 | - libpython = os.path.join(prefix, |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 93 | - "@@GENTOO_LIBDIR@@", "python" + get_python_version()) |
Mike Frysinger | 74fb2fe | 2018-08-27 02:26:32 -0400 | [diff] [blame] | 94 | + # Search known Gentoo vars first. |
| 95 | + libpython = None |
| 96 | + if SYSROOT: |
| 97 | + abi = os.environ.get('ABI') |
| 98 | + libdir = os.environ.get('LIBDIR_%s' % abi) |
| 99 | + if libdir: |
| 100 | + libpython = os.path.join(prefix, libdir, "python" + get_python_version()) |
| 101 | + if not libpython: |
| 102 | + # Fallback to hardcoded search. |
| 103 | + for libdir in ['@@GENTOO_LIBDIR@@', 'lib64', 'lib32', 'libx32', 'lib']: |
| 104 | + libpython = os.path.join(prefix, libdir, "python" + get_python_version()) |
| 105 | + if os.path.exists(libpython): |
| 106 | + break |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 107 | if standard_lib: |
| 108 | return libpython |
| 109 | else: |
Mike Frysinger | 74fb2fe | 2018-08-27 02:26:32 -0400 | [diff] [blame] | 110 | @@ -409,10 +434,14 @@ |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 111 | def _init_posix(): |
| 112 | """Initialize the module as appropriate for POSIX systems.""" |
| 113 | # _sysconfigdata is generated at build time, see the sysconfig module |
| 114 | - from _sysconfigdata import build_time_vars |
| 115 | + lib_dir = get_python_lib(plat_specific=1, standard_lib=1) |
| 116 | + sysconfig_path = os.path.join(lib_dir, "_sysconfigdata.py") |
| 117 | + if not os.path.exists(sysconfig_path): |
| 118 | + _, sysconfig_path, _ = imp.find_module("_sysconfigdata") |
| 119 | + sysconfig_module = imp.load_source("_sysconfigdata", sysconfig_path) |
| 120 | global _config_vars |
| 121 | _config_vars = {} |
| 122 | - _config_vars.update(build_time_vars) |
| 123 | + _config_vars.update(sysconfig_module.build_time_vars) |
| 124 | |
| 125 | |
| 126 | def _init_nt(): |