python-2.7-015-distutils-cross-compilation-support.patch 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. Add some cross-compilation fixes to distutils
  2. Inspired by work done by Marc Kleine-Budde <mkl@pengutronix.de> in
  3. PTXdist.
  4. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  5. ---
  6. Lib/distutils/sysconfig.py | 7 ++++---
  7. 1 files changed, 4 insertions(+), 3 deletions(-)
  8. Index: b/Lib/distutils/sysconfig.py
  9. ===================================================================
  10. --- a/Lib/distutils/sysconfig.py
  11. +++ b/Lib/distutils/sysconfig.py
  12. @@ -18,14 +18,38 @@
  13. from distutils.errors import DistutilsPlatformError
  14. -# These are needed in a couple of spots, so just compute them once.
  15. -PREFIX = os.path.normpath(sys.prefix)
  16. -EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
  17. +if os.environ.get('CROSS_COMPILING') == 'yes':
  18. + _sysroot=os.environ.get('_python_sysroot')
  19. + PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_prefix'))
  20. + EXEC_PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_exec_prefix'))
  21. + # In the cross-compilation case, we have two cases:
  22. + #
  23. + # 1/ We're currently cross-compiling Python itself. In this case,
  24. + # EXECUTABLE_DIRNAME should point to the source directory of the
  25. + # target Python, so that the rest of the code, especially the
  26. + # _python_build() function will properly understand that we are
  27. + # building Python itself. In this case, _python_srcdir is
  28. + # defined.
  29. + #
  30. + # 2/ We're currently cross-compiling third party Python
  31. + # modules. In this case, EXECUTABLE_DIRNAME should point to where
  32. + # the target python executable is installed in the sysroot, so
  33. + # that the proper Makefile is going to be read. In this case,
  34. + # _python_srcdir is not defined.
  35. + #
  36. + if os.environ.get('_python_srcdir') is not None:
  37. + EXECUTABLE_DIRNAME = os.environ.get('_python_srcdir')
  38. + else:
  39. + EXECUTABLE_DIRNAME = os.path.join(_sysroot, "usr/bin")
  40. +else:
  41. + PREFIX = os.path.normpath(sys.prefix)
  42. + EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
  43. + EXECUTABLE_DIRNAME = os.path.dirname(os.path.realpath(sys.executable))
  44. # Path to the base directory of the project. On Windows the binary may
  45. # live in project/PCBuild9. If we're dealing with an x64 Windows build,
  46. # it'll live in project/PCbuild/amd64.
  47. -project_base = os.path.dirname(os.path.abspath(sys.executable))
  48. +project_base = EXECUTABLE_DIRNAME
  49. if os.name == "nt" and "pcbuild" in project_base[-8:].lower():
  50. project_base = os.path.abspath(os.path.join(project_base, os.path.pardir))
  51. # PC/VS7.1
  52. @@ -74,7 +98,7 @@
  53. if os.name == "posix":
  54. if python_build:
  55. - buildir = os.path.dirname(sys.executable)
  56. + buildir = EXECUTABLE_DIRNAME
  57. if plat_specific:
  58. # python.h is located in the buildir
  59. inc_dir = buildir
  60. @@ -245,7 +269,7 @@
  61. def get_makefile_filename():
  62. """Return full pathname of installed Makefile from the Python build."""
  63. if python_build:
  64. - return os.path.join(os.path.dirname(sys.executable), "Makefile")
  65. + return os.path.join(EXECUTABLE_DIRNAME, "Makefile")
  66. lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
  67. return os.path.join(lib_dir, "config", "Makefile")
  68. @@ -311,6 +335,11 @@
  69. # `$$' is a literal `$' in make
  70. tmpv = v.replace('$$', '')
  71. + # Adjust prefix and exec_prefix when we're cross compiling
  72. + if os.environ.get('CROSS_COMPILING') == "yes":
  73. + if n == "prefix" or n == "exec_prefix":
  74. + v = _sysroot + v
  75. +
  76. if "$" in tmpv:
  77. notdone[n] = v
  78. else:
  79. Index: b/configure.in
  80. ===================================================================
  81. --- a/configure.in
  82. +++ b/configure.in
  83. @@ -4342,6 +4342,20 @@
  84. CROSS_COMPILING=$cross_compiling
  85. AC_SUBST(CROSS_COMPILING)
  86. +#
  87. +# Cross compiling
  88. +#
  89. +# special RUNSHARED
  90. +if test "$cross_compiling" = "yes"; then
  91. + RUNSHARED="\
  92. + CROSS_COMPILING=yes \
  93. + _python_cross_host=${ac_cv_host} \
  94. + _python_srcdir=\"\$(srcdir)\" \
  95. + _python_prefix=\"\$(prefix)\" \
  96. + _python_exec_prefix=\"\$(exec_prefix)\""
  97. +fi
  98. +
  99. +
  100. # generate output files
  101. AC_CONFIG_FILES(Makefile.pre Modules/Setup.config Misc/python.pc)
  102. AC_CONFIG_FILES([Modules/ld_so_aix], [chmod +x Modules/ld_so_aix])
  103. Index: b/Lib/distutils/command/build_ext.py
  104. ===================================================================
  105. --- a/Lib/distutils/command/build_ext.py
  106. +++ b/Lib/distutils/command/build_ext.py
  107. @@ -237,7 +237,7 @@
  108. if ((sys.platform.startswith('linux') or sys.platform.startswith('gnu')
  109. or sys.platform.startswith('sunos'))
  110. and sysconfig.get_config_var('Py_ENABLE_SHARED')):
  111. - if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
  112. + if not sysconfig.python_build:
  113. # building third party extensions
  114. self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
  115. else: