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.

67 lines
3.0 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. diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py
  20. index 74de782d8a..d0c847b365 100644
  21. --- a/Lib/distutils/command/build_ext.py
  22. +++ b/Lib/distutils/command/build_ext.py
  23. @@ -234,7 +234,10 @@ class build_ext(Command):
  24. if (sysconfig.get_config_var('Py_ENABLE_SHARED')):
  25. if not sysconfig.python_build:
  26. # building third party extensions
  27. - self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
  28. + libdir = sysconfig.get_config_var('LIBDIR')
  29. + if "_python_sysroot" in os.environ:
  30. + libdir = os.environ.get("_python_sysroot") + libdir
  31. + self.library_dirs.append(libdir)
  32. else:
  33. # building python standard extensions
  34. self.library_dirs.append('.')
  35. diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
  36. index 2bcd1dd288..422c13fa4f 100644
  37. --- a/Lib/distutils/sysconfig.py
  38. +++ b/Lib/distutils/sysconfig.py
  39. @@ -17,10 +17,17 @@ import sys
  40. from .errors import DistutilsPlatformError
  41. # These are needed in a couple of spots, so just compute them once.
  42. -PREFIX = os.path.normpath(sys.prefix)
  43. -EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
  44. -BASE_PREFIX = os.path.normpath(sys.base_prefix)
  45. -BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
  46. +if "_python_sysroot" in os.environ:
  47. + _sysroot=os.environ.get('_python_sysroot')
  48. + PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_prefix'))
  49. + EXEC_PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_exec_prefix'))
  50. + BASE_PREFIX = PREFIX
  51. + BASE_EXEC_PREFIX = EXEC_PREFIX
  52. +else:
  53. + PREFIX = os.path.normpath(sys.prefix)
  54. + EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
  55. + BASE_PREFIX = os.path.normpath(sys.base_prefix)
  56. + BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
  57. # Path to the base directory of the project. On Windows the binary may
  58. # live in project/PCbuild/win32 or project/PCbuild/amd64.
  59. --
  60. 2.13.5