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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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.1/Makefile.pre.in
  21. ===================================================================
  22. --- Python-2.7.1.orig/Makefile.pre.in
  23. +++ Python-2.7.1/Makefile.pre.in
  24. @@ -178,7 +178,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. @@ -210,7 +211,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. @@ -404,8 +406,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. @@ -536,12 +538,12 @@
  51. $(MAINCC) -c $(PY_CFLAGS) -o $@ $(srcdir)/Modules/python.c
  52. -$(GRAMMAR_H) $(GRAMMAR_C): $(PGEN) $(GRAMMAR_INPUT)
  53. +$(GRAMMAR_H) $(GRAMMAR_C): $(PGEN_FOR_BUILD) $(GRAMMAR_INPUT)
  54. -@$(INSTALL) -d Include
  55. - -$(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
  56. + -$(PGEN_FOR_BUILD) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
  57. -$(PGEN): $(PGENOBJS)
  58. - $(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN)
  59. +$(BUILDPGEN): $(PGENOBJS)
  60. + $(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(BUILDPGEN)
  61. Parser/grammar.o: $(srcdir)/Parser/grammar.c \
  62. $(srcdir)/Include/token.h \
  63. @@ -921,25 +923,25 @@
  64. done
  65. $(INSTALL_DATA) $(srcdir)/LICENSE $(DESTDIR)$(LIBDEST)/LICENSE.txt
  66. PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
  67. - ./$(BUILDPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
  68. + $(PYTHON_FOR_BUILD) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
  69. -d $(LIBDEST) -f \
  70. -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
  71. $(DESTDIR)$(LIBDEST)
  72. PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
  73. - ./$(BUILDPYTHON) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
  74. + $(PYTHON_FOR_BUILD) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
  75. -d $(LIBDEST) -f \
  76. -x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
  77. $(DESTDIR)$(LIBDEST)
  78. -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
  79. - ./$(BUILDPYTHON) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
  80. + $(PYTHON_FOR_BUILD) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
  81. -d $(LIBDEST)/site-packages -f \
  82. -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
  83. -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
  84. - ./$(BUILDPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
  85. + $(PYTHON_FOR_BUILD) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
  86. -d $(LIBDEST)/site-packages -f \
  87. -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
  88. -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
  89. - ./$(BUILDPYTHON) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
  90. + $(PYTHON_FOR_BUILD) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
  91. # Create the PLATDIR source directory, if one wasn't distributed..
  92. $(srcdir)/Lib/$(PLATDIR):
  93. @@ -1044,7 +1046,7 @@
  94. # Install the dynamically loadable modules
  95. # This goes into $(exec_prefix)
  96. sharedinstall: sharedmods
  97. - $(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \
  98. + $(RUNSHARED) $(PYTHON_FOR_BUILD) -E $(srcdir)/setup.py install \
  99. --prefix=$(prefix) \
  100. --install-scripts=$(BINDIR) \
  101. --install-platlib=$(DESTSHARED) \
  102. @@ -1183,7 +1185,7 @@
  103. find . -name '*.gc??' -exec rm -f {} ';'
  104. clobber: clean profile-removal
  105. - -rm -f $(BUILDPYTHON) $(PGEN) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY) \
  106. + -rm -f $(BUILDPYTHON) $(BUILDPGEN) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY) \
  107. tags TAGS \
  108. config.cache config.log pyconfig.h Modules/config.c
  109. -rm -rf build platform
  110. Index: Python-2.7.1/configure.in
  111. ===================================================================
  112. --- Python-2.7.1.orig/configure.in
  113. +++ Python-2.7.1/configure.in
  114. @@ -4291,6 +4291,23 @@
  115. done
  116. AC_MSG_RESULT(done)
  117. +if test "$cross_compiling" = "yes"; then
  118. + AC_MSG_CHECKING(python for build)
  119. + PYTHON_FOR_BUILD="${PYTHON_FOR_BUILD}"
  120. + AC_MSG_RESULT($PYTHON_FOR_BUILD)
  121. + AC_MSG_CHECKING(pgen for build)
  122. + PGEN_FOR_BUILD="${PGEN_FOR_BUILD}"
  123. + AC_MSG_RESULT($PGEN_FOR_BUILD)
  124. +else
  125. + PYTHON_FOR_BUILD='$(BUILDPYTHON)'
  126. + PGEN_FOR_BUILD='$(BUILDPGEN)'
  127. +fi
  128. +
  129. +AC_SUBST(PYTHON_FOR_BUILD)
  130. +AC_SUBST(PGEN_FOR_BUILD)
  131. +AC_ARG_VAR(PYTHON_FOR_BUILD,[build system Python])
  132. +AC_ARG_VAR(PGEN_FOR_BUILD,[build system Python pgen])
  133. +
  134. # generate output files
  135. AC_CONFIG_FILES(Makefile.pre Modules/Setup.config Misc/python.pc)
  136. AC_CONFIG_FILES([Modules/ld_so_aix], [chmod +x Modules/ld_so_aix])