You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.8 KiB

  1. From e359a7a3c4f9e70360a068bef19c95938fdacede Mon Sep 17 00:00:00 2001
  2. From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  3. Date: Wed, 23 Dec 2015 11:33:14 +0100
  4. Subject: [PATCH] Adjust library/header paths for cross-compilation
  5. When cross-compiling third-party extensions, the get_python_inc() or
  6. get_python_lib() can be called, to return the path to headers or
  7. libraries. However, they use the sys.prefix of the host Python, which
  8. returns incorrect paths when cross-compiling (paths pointing to host
  9. headers and libraries).
  10. In order to fix this, we introduce the _python_sysroot, _python_prefix
  11. and _python_exec_prefix variables, that allow to override these
  12. values, and get correct header/library paths when cross-compiling
  13. third-party Python modules.
  14. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  15. ---
  16. Lib/distutils/command/build_ext.py | 5 ++++-
  17. Lib/distutils/sysconfig.py | 15 +++++++++++----
  18. 2 files changed, 15 insertions(+), 5 deletions(-)
  19. --- a/Lib/distutils/command/build_ext.py
  20. +++ b/Lib/distutils/command/build_ext.py
  21. @@ -234,7 +234,10 @@ class build_ext(Command):
  22. if (sysconfig.get_config_var('Py_ENABLE_SHARED')):
  23. if not sysconfig.python_build:
  24. # building third party extensions
  25. - self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
  26. + libdir = sysconfig.get_config_var('LIBDIR')
  27. + if "_python_sysroot" in os.environ:
  28. + libdir = os.environ.get("_python_sysroot") + libdir
  29. + self.library_dirs.append(libdir)
  30. else:
  31. # building python standard extensions
  32. self.library_dirs.append('.')
  33. --- a/Lib/distutils/sysconfig.py
  34. +++ b/Lib/distutils/sysconfig.py
  35. @@ -18,10 +18,17 @@ from .errors import DistutilsPlatformErr
  36. from .util import get_platform, get_host_platform
  37. # These are needed in a couple of spots, so just compute them once.
  38. -PREFIX = os.path.normpath(sys.prefix)
  39. -EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
  40. -BASE_PREFIX = os.path.normpath(sys.base_prefix)
  41. -BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
  42. +if "_python_sysroot" in os.environ:
  43. + _sysroot=os.environ.get('_python_sysroot')
  44. + PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_prefix'))
  45. + EXEC_PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_exec_prefix'))
  46. + BASE_PREFIX = PREFIX
  47. + BASE_EXEC_PREFIX = EXEC_PREFIX
  48. +else:
  49. + PREFIX = os.path.normpath(sys.prefix)
  50. + EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
  51. + BASE_PREFIX = os.path.normpath(sys.base_prefix)
  52. + BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
  53. # Path to the base directory of the project. On Windows the binary may
  54. # live in project/PCbuild/win32 or project/PCbuild/amd64.