2
1

python-2.7-001-cross-compile.patch 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. Add cross-compilation support in the python Makefile and setup.py since
  2. python has no such support.
  3. The main point here is to first build a python interpreter to run on the
  4. host, and then use it to compile the target python.
  5. We also remove some error-generating code that is irrelevant in our
  6. situation, such as checking if we can import a cross-compiled module.
  7. Patch ported to python2.7 by Maxime Ripard <ripard@archos.com>
  8. diff -rduNp Python-2.7.orig/Makefile.pre.in Python-2.7/Makefile.pre.in
  9. --- Python-2.7.orig/Makefile.pre.in 2010-04-12 02:10:46.000000000 +0200
  10. +++ Python-2.7/Makefile.pre.in 2010-09-21 16:46:07.000000000 +0200
  11. @@ -404,8 +404,8 @@ platform: $(BUILDPYTHON)
  12. # Build the shared modules
  13. sharedmods: $(BUILDPYTHON)
  14. @case $$MAKEFLAGS in \
  15. - *s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
  16. - *) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
  17. + *s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' OPT='$(OPT)' $(HOSTPYTHON) -E $(srcdir)/setup.py -q build;; \
  18. + *) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' OPT='$(OPT)' $(HOSTPYTHON) -E $(srcdir)/setup.py build;; \
  19. esac
  20. # Build static library
  21. @@ -538,7 +538,7 @@ Modules/python.o: $(srcdir)/Modules/pyth
  22. $(GRAMMAR_H) $(GRAMMAR_C): $(PGEN) $(GRAMMAR_INPUT)
  23. -@$(INSTALL) -d Include
  24. - -$(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
  25. + -$(HOSTPGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
  26. $(PGEN): $(PGENOBJS)
  27. $(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN)
  28. @@ -920,25 +920,25 @@ libinstall: build_all $(srcdir)/Lib/$(PL
  29. done
  30. $(INSTALL_DATA) $(srcdir)/LICENSE $(DESTDIR)$(LIBDEST)/LICENSE.txt
  31. PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
  32. - ./$(BUILDPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
  33. + $(HOSTPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
  34. -d $(LIBDEST) -f \
  35. -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
  36. $(DESTDIR)$(LIBDEST)
  37. PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
  38. - ./$(BUILDPYTHON) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
  39. + $(HOSTPYTHON) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
  40. -d $(LIBDEST) -f \
  41. -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
  42. $(DESTDIR)$(LIBDEST)
  43. -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
  44. - ./$(BUILDPYTHON) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
  45. + $(HOSTPYTHON) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
  46. -d $(LIBDEST)/site-packages -f \
  47. -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
  48. -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
  49. - ./$(BUILDPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
  50. + $(HOSTPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
  51. -d $(LIBDEST)/site-packages -f \
  52. -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
  53. -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
  54. - ./$(BUILDPYTHON) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
  55. + $(HOSTPYTHON) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
  56. # Create the PLATDIR source directory, if one wasn't distributed..
  57. $(srcdir)/Lib/$(PLATDIR):
  58. @@ -1043,7 +1043,7 @@ libainstall: all python-config
  59. # Install the dynamically loadable modules
  60. # This goes into $(exec_prefix)
  61. sharedinstall:
  62. - $(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \
  63. + $(RUNSHARED) $(HOSTPYTHON) -E $(srcdir)/setup.py install \
  64. --prefix=$(prefix) \
  65. --install-scripts=$(BINDIR) \
  66. --install-platlib=$(DESTSHARED) \
  67. diff -rduNp Python-2.7.orig/setup.py Python-2.7/setup.py
  68. --- Python-2.7.orig/setup.py 2010-06-27 14:36:16.000000000 +0200
  69. +++ Python-2.7/setup.py 2010-09-21 16:59:59.000000000 +0200
  70. @@ -310,9 +310,9 @@ class PyBuildExt(build_ext):
  71. try:
  72. imp.load_dynamic(ext.name, ext_filename)
  73. except ImportError, why:
  74. - self.failed.append(ext.name)
  75. - self.announce('*** WARNING: renaming "%s" since importing it'
  76. - ' failed: %s' % (ext.name, why), level=3)
  77. + self.announce('*** WARNING: Importing "%s" failed, probably '
  78. + 'because of cross-compilation' % ext.name, level=3)
  79. + return
  80. assert not self.inplace
  81. basename, tail = os.path.splitext(ext_filename)
  82. newname = basename + "_failed" + tail
  83. @@ -346,10 +346,6 @@ class PyBuildExt(build_ext):
  84. return sys.platform
  85. def detect_modules(self):
  86. - # Ensure that /usr/local is always used
  87. - add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
  88. - add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
  89. -
  90. # Add paths specified in the environment variables LDFLAGS and
  91. # CPPFLAGS for header and library files.
  92. # We must get the values from the Makefile and not the environment
  93. @@ -384,12 +380,6 @@ class PyBuildExt(build_ext):
  94. for directory in reversed(options.dirs):
  95. add_dir_to_list(dir_list, directory)
  96. - if os.path.normpath(sys.prefix) != '/usr':
  97. - add_dir_to_list(self.compiler.library_dirs,
  98. - sysconfig.get_config_var("LIBDIR"))
  99. - add_dir_to_list(self.compiler.include_dirs,
  100. - sysconfig.get_config_var("INCLUDEDIR"))
  101. -
  102. try:
  103. have_unicode = unicode
  104. except NameError: