python-2.7-001-support-for-build.patch 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. Add support in Python build system to specify host tools
  2. Python needs a Python interpreter and a "pgen" program to build
  3. itself. Unfortunately, the Python build system assumes that it can use
  4. the interpreter and pgen program it has just built to build
  5. itself. Obviously, this cannot work in cross-compilation mode since
  6. the interpreter and the pgen program have been built for the target.
  7. Therefore, this patch adds support in the Python build system for the
  8. new PYTHON_FOR_BUILD and PGEN_FOR_BUILD variables, so that we can
  9. point Python ./configure script to the Python interpreter and pgen
  10. program that have been previously built for the host.
  11. Patch ported to python2.7 by Maxime Ripard <ripard@archos.com>, and
  12. later significantly reworked by Thomas Petazzoni
  13. <thomas.petazzoni@free-electrons.com>, with some inspiration taken
  14. from the Python patches of the PTXdist project.
  15. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  16. ---
  17. Makefile.pre.in | 32 +++++++++++++++++---------------
  18. configure.in | 17 +++++++++++++++++
  19. 2 files changed, 34 insertions(+), 15 deletions(-)
  20. Index: Python-2.7.2/Makefile.pre.in
  21. ===================================================================
  22. --- Python-2.7.2.orig/Makefile.pre.in
  23. +++ Python-2.7.2/Makefile.pre.in
  24. @@ -181,7 +181,8 @@
  25. UNICODE_OBJS= @UNICODE_OBJS@
  26. PYTHON= python$(EXE)
  27. -BUILDPYTHON= python$(BUILDEXE)
  28. +BUILDPYTHON= ./python$(BUILDEXE)
  29. +PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@
  30. # The task to run while instrument when building the profile-opt target
  31. PROFILE_TASK= $(srcdir)/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck
  32. @@ -213,7 +214,8 @@
  33. ##########################################################################
  34. # Parser
  35. -PGEN= Parser/pgen$(EXE)
  36. +BUILDPGEN= Parser/pgen$(EXE)
  37. +PGEN_FOR_BUILD=@PGEN_FOR_BUILD@
  38. POBJS= \
  39. Parser/acceler.o \
  40. @@ -407,8 +409,8 @@
  41. # Build the shared modules
  42. sharedmods: $(BUILDPYTHON)
  43. @case $$MAKEFLAGS in \
  44. - *s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
  45. - *) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
  46. + *s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' $(PYTHON_FOR_BUILD) -E $(srcdir)/setup.py -q build;; \
  47. + *) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' $(PYTHON_FOR_BUILD) -E $(srcdir)/setup.py build;; \
  48. esac
  49. # Build static library
  50. @@ -540,13 +542,13 @@
  51. # Use a stamp file to prevent make -j invoking pgen twice
  52. $(GRAMMAR_H) $(GRAMMAR_C): Parser/pgen.stamp
  53. -Parser/pgen.stamp: $(PGEN) $(GRAMMAR_INPUT)
  54. +Parser/pgen.stamp: $(PGEN_FOR_BUILD) $(GRAMMAR_INPUT)
  55. -@$(INSTALL) -d Include
  56. - $(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
  57. + $(PGEN_FOR_BUILD) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
  58. -touch Parser/pgen.stamp
  59. -$(PGEN): $(PGENOBJS)
  60. - $(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN)
  61. +$(BUILDPGEN): $(PGENOBJS)
  62. + $(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(BUILDPGEN)
  63. Parser/grammar.o: $(srcdir)/Parser/grammar.c \
  64. $(srcdir)/Include/token.h \
  65. @@ -926,25 +928,25 @@
  66. done
  67. $(INSTALL_DATA) $(srcdir)/LICENSE $(DESTDIR)$(LIBDEST)/LICENSE.txt
  68. PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
  69. - ./$(BUILDPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
  70. + $(PYTHON_FOR_BUILD) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
  71. -d $(LIBDEST) -f \
  72. -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
  73. $(DESTDIR)$(LIBDEST)
  74. PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
  75. - ./$(BUILDPYTHON) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
  76. + $(PYTHON_FOR_BUILD) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
  77. -d $(LIBDEST) -f \
  78. -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
  79. $(DESTDIR)$(LIBDEST)
  80. -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
  81. - ./$(BUILDPYTHON) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
  82. + $(PYTHON_FOR_BUILD) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
  83. -d $(LIBDEST)/site-packages -f \
  84. -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
  85. -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
  86. - ./$(BUILDPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
  87. + $(PYTHON_FOR_BUILD) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
  88. -d $(LIBDEST)/site-packages -f \
  89. -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
  90. -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
  91. - ./$(BUILDPYTHON) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
  92. + $(PYTHON_FOR_BUILD) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
  93. # Create the PLATDIR source directory, if one wasn't distributed..
  94. $(srcdir)/Lib/$(PLATDIR):
  95. @@ -1049,7 +1051,7 @@
  96. # Install the dynamically loadable modules
  97. # This goes into $(exec_prefix)
  98. sharedinstall: sharedmods
  99. - $(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \
  100. + $(RUNSHARED) $(PYTHON_FOR_BUILD) -E $(srcdir)/setup.py install \
  101. --prefix=$(prefix) \
  102. --install-scripts=$(BINDIR) \
  103. --install-platlib=$(DESTSHARED) \
  104. @@ -1188,7 +1190,7 @@
  105. find . -name '*.gc??' -exec rm -f {} ';'
  106. clobber: clean profile-removal
  107. - -rm -f $(BUILDPYTHON) $(PGEN) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY) \
  108. + -rm -f $(BUILDPYTHON) $(BUILDPGEN) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY) \
  109. tags TAGS Parser/pgen.stamp \
  110. config.cache config.log pyconfig.h Modules/config.c
  111. -rm -rf build platform
  112. Index: Python-2.7.2/configure.in
  113. ===================================================================
  114. --- Python-2.7.2.orig/configure.in
  115. +++ Python-2.7.2/configure.in
  116. @@ -4305,6 +4305,23 @@
  117. done
  118. AC_MSG_RESULT(done)
  119. +if test "$cross_compiling" = "yes"; then
  120. + AC_MSG_CHECKING(python for build)
  121. + PYTHON_FOR_BUILD="${PYTHON_FOR_BUILD}"
  122. + AC_MSG_RESULT($PYTHON_FOR_BUILD)
  123. + AC_MSG_CHECKING(pgen for build)
  124. + PGEN_FOR_BUILD="${PGEN_FOR_BUILD}"
  125. + AC_MSG_RESULT($PGEN_FOR_BUILD)
  126. +else
  127. + PYTHON_FOR_BUILD='$(BUILDPYTHON)'
  128. + PGEN_FOR_BUILD='$(BUILDPGEN)'
  129. +fi
  130. +
  131. +AC_SUBST(PYTHON_FOR_BUILD)
  132. +AC_SUBST(PGEN_FOR_BUILD)
  133. +AC_ARG_VAR(PYTHON_FOR_BUILD,[build system Python])
  134. +AC_ARG_VAR(PGEN_FOR_BUILD,[build system Python pgen])
  135. +
  136. # generate output files
  137. AC_CONFIG_FILES(Makefile.pre Modules/Setup.config Misc/python.pc)
  138. AC_CONFIG_FILES([Modules/ld_so_aix], [chmod +x Modules/ld_so_aix])