0004-Adjust-library-header-paths-for-cross-compilation.patch 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. From 61af65485f1dade4aa08d0cf2b24082aeda24c51 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 1a9bd1200f..3cf7d6746e 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 37feae5df7..e9c3a27856 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.25.1