python_2.7.15.bb 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. require python.inc
  2. DEPENDS = "python-native libffi bzip2 gdbm openssl \
  3. readline sqlite3 zlib virtual/crypt"
  4. PR = "${INC_PR}"
  5. DISTRO_SRC_URI ?= "file://sitecustomize.py"
  6. DISTRO_SRC_URI_linuxstdbase = ""
  7. SRC_URI += "\
  8. file://01-use-proper-tools-for-cross-build.patch \
  9. file://03-fix-tkinter-detection.patch \
  10. file://06-avoid_usr_lib_termcap_path_in_linking.patch \
  11. ${DISTRO_SRC_URI} \
  12. file://multilib.patch \
  13. file://cgi_py.patch \
  14. file://setup_py_skip_cross_import_check.patch \
  15. file://add-md5module-support.patch \
  16. file://host_include_contamination.patch \
  17. file://fix_for_using_different_libdir.patch \
  18. file://setuptweaks.patch \
  19. file://check-if-target-is-64b-not-host.patch \
  20. file://search_db_h_in_inc_dirs_and_avoid_warning.patch \
  21. file://avoid_warning_about_tkinter.patch \
  22. file://avoid_warning_for_sunos_specific_module.patch \
  23. file://python-2.7.3-remove-bsdb-rpath.patch \
  24. file://run-ptest \
  25. file://parallel-makeinst-create-bindir.patch \
  26. file://use_sysroot_ncurses_instead_of_host.patch \
  27. file://add-CROSSPYTHONPATH-for-PYTHON_FOR_BUILD.patch \
  28. file://pass-missing-libraries-to-Extension-for-mul.patch \
  29. file://support_SOURCE_DATE_EPOCH_in_py_compile_2.7.patch \
  30. file://float-endian.patch \
  31. file://0001-closes-bpo-34540-Convert-shutil._call_external_zip-t.patch \
  32. file://0001-2.7-bpo-34623-Use-XML_SetHashSalt-in-_elementtree-GH.patch \
  33. "
  34. S = "${WORKDIR}/Python-${PV}"
  35. inherit autotools multilib_header python-dir pythonnative ptest
  36. CONFIGUREOPTS += " --with-system-ffi "
  37. EXTRA_OECONF += "ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no ac_cv_working_tzset=yes"
  38. PACKAGECONFIG ??= "bdb"
  39. PACKAGECONFIG[bdb] = ",,db"
  40. do_configure_append() {
  41. rm -f ${S}/Makefile.orig
  42. autoreconf -Wcross --verbose --install --force --exclude=autopoint ../Python-${PV}/Modules/_ctypes/libffi
  43. }
  44. do_compile() {
  45. # regenerate platform specific files, because they depend on system headers
  46. cd ${S}/Lib/plat-linux2
  47. include=${STAGING_INCDIR} ${STAGING_BINDIR_NATIVE}/python-native/python \
  48. ${S}/Tools/scripts/h2py.py -i '(u_long)' \
  49. ${STAGING_INCDIR}/dlfcn.h \
  50. ${STAGING_INCDIR}/linux/cdrom.h \
  51. ${STAGING_INCDIR}/netinet/in.h \
  52. ${STAGING_INCDIR}/sys/types.h
  53. sed -e 's,${STAGING_DIR_HOST},,g' -i *.py
  54. cd -
  55. # remove any bogus LD_LIBRARY_PATH
  56. sed -i -e s,RUNSHARED=.*,RUNSHARED=, Makefile
  57. if [ ! -f Makefile.orig ]; then
  58. install -m 0644 Makefile Makefile.orig
  59. fi
  60. sed -i -e 's#^LDFLAGS=.*#LDFLAGS=${LDFLAGS} -L. -L${STAGING_LIBDIR}#g' \
  61. -e 's,libdir=${libdir},libdir=${STAGING_LIBDIR},g' \
  62. -e 's,libexecdir=${libexecdir},libexecdir=${STAGING_DIR_HOST}${libexecdir},g' \
  63. -e 's,^LIBDIR=.*,LIBDIR=${STAGING_LIBDIR},g' \
  64. -e 's,includedir=${includedir},includedir=${STAGING_INCDIR},g' \
  65. -e 's,^INCLUDEDIR=.*,INCLUDE=${STAGING_INCDIR},g' \
  66. -e 's,^CONFINCLUDEDIR=.*,CONFINCLUDE=${STAGING_INCDIR},g' \
  67. Makefile
  68. # save copy of it now, because if we do it in do_install and
  69. # then call do_install twice we get Makefile.orig == Makefile.sysroot
  70. install -m 0644 Makefile Makefile.sysroot
  71. export CROSS_COMPILE="${TARGET_PREFIX}"
  72. export PYTHONBUILDDIR="${B}"
  73. oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python-native/pgen \
  74. HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python-native/python \
  75. STAGING_LIBDIR=${STAGING_LIBDIR} \
  76. STAGING_INCDIR=${STAGING_INCDIR} \
  77. STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \
  78. OPT="${CFLAGS}"
  79. }
  80. do_install() {
  81. # make install needs the original Makefile, or otherwise the inclues would
  82. # go to ${D}${STAGING...}/...
  83. install -m 0644 Makefile.orig Makefile
  84. export CROSS_COMPILE="${TARGET_PREFIX}"
  85. export PYTHONBUILDDIR="${B}"
  86. # After swizzling the makefile, we need to run the build again.
  87. # install can race with the build so we have to run this first, then install
  88. oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python-native/pgen \
  89. HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python-native/python \
  90. CROSSPYTHONPATH=${STAGING_LIBDIR_NATIVE}/python${PYTHON_MAJMIN}/lib-dynload/ \
  91. STAGING_LIBDIR=${STAGING_LIBDIR} \
  92. STAGING_INCDIR=${STAGING_INCDIR} \
  93. STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \
  94. DESTDIR=${D} LIBDIR=${libdir}
  95. oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python-native/pgen \
  96. HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python-native/python \
  97. CROSSPYTHONPATH=${STAGING_LIBDIR_NATIVE}/python${PYTHON_MAJMIN}/lib-dynload/ \
  98. STAGING_LIBDIR=${STAGING_LIBDIR} \
  99. STAGING_INCDIR=${STAGING_INCDIR} \
  100. STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \
  101. DESTDIR=${D} LIBDIR=${libdir} install
  102. install -m 0644 Makefile.sysroot ${D}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile
  103. if [ -e ${WORKDIR}/sitecustomize.py ]; then
  104. install -m 0644 ${WORKDIR}/sitecustomize.py ${D}/${libdir}/python${PYTHON_MAJMIN}
  105. fi
  106. oe_multilib_header python${PYTHON_MAJMIN}/pyconfig.h
  107. if [ -z "${@bb.utils.filter('PACKAGECONFIG', 'bdb', d)}" ]; then
  108. rm -rf ${D}/${libdir}/python${PYTHON_MAJMIN}/bsddb
  109. fi
  110. }
  111. do_install_append_class-nativesdk () {
  112. create_wrapper ${D}${bindir}/python2.7 PYTHONHOME='${prefix}' TERMINFO_DIRS='${sysconfdir}/terminfo:/etc/terminfo:/usr/share/terminfo:/usr/share/misc/terminfo:/lib/terminfo' PYTHONNOUSERSITE='1'
  113. }
  114. SSTATE_SCAN_FILES += "Makefile"
  115. PACKAGE_PREPROCESS_FUNCS += "py_package_preprocess"
  116. py_package_preprocess () {
  117. # copy back the old Makefile to fix target package
  118. install -m 0644 ${B}/Makefile.orig ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile
  119. # Remove references to buildmachine paths in target Makefile and _sysconfigdata
  120. sed -i -e 's:--sysroot=${STAGING_DIR_TARGET}::g' -e s:'--with-libtool-sysroot=${STAGING_DIR_TARGET}'::g \
  121. -e 's|${DEBUG_PREFIX_MAP}||g' \
  122. -e 's:${HOSTTOOLS_DIR}/::g' \
  123. -e 's:${RECIPE_SYSROOT_NATIVE}::g' \
  124. -e 's:${RECIPE_SYSROOT}::g' \
  125. -e 's:${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}::g' \
  126. ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile \
  127. ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py
  128. (cd ${PKGD}; python -m py_compile ./${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py)
  129. }
  130. PACKAGES_remove = "${PN}"
  131. # manual dependency additions
  132. RPROVIDES_${PN}-core = "${PN}"
  133. RRECOMMENDS_${PN}-core_append_class-nativesdk = " nativesdk-python-modules"
  134. RRECOMMENDS_${PN}-crypt = "openssl"
  135. # package libpython2
  136. PACKAGES =+ "lib${BPN}2"
  137. FILES_lib${BPN}2 = "${libdir}/libpython*.so.*"
  138. # catch all the rest (unsorted)
  139. PACKAGES += "${PN}-misc"
  140. FILES_${PN}-misc = "${libdir}/python${PYTHON_MAJMIN}"
  141. RDEPENDS_${PN}-modules += "${PN}-misc"
  142. # ptest
  143. RDEPENDS_${PN}-ptest = "${PN}-modules ${PN}-tests unzip"
  144. # catch manpage
  145. PACKAGES += "${PN}-man"
  146. FILES_${PN}-man = "${datadir}/man"
  147. # Nasty but if bdb isn't enabled the package won't be generated
  148. RDEPENDS_${PN}-modules_remove = "${@bb.utils.contains('PACKAGECONFIG', 'bdb', '', '${PN}-bsddb', d)}"
  149. RDEPENDS_${PN}-dev = ""
  150. BBCLASSEXTEND = "nativesdk"
  151. # We want bytecode precompiled .py files (.pyc's) by default
  152. # but the user may set it on their own conf
  153. INCLUDE_PYCS ?= "1"
  154. python(){
  155. import collections, json
  156. filename = os.path.join(d.getVar('THISDIR'), 'python', 'python2-manifest.json')
  157. # This python changes the datastore based on the contents of a file, so mark
  158. # that dependency.
  159. bb.parse.mark_dependency(d, filename)
  160. with open(filename) as manifest_file:
  161. manifest_str = manifest_file.read()
  162. json_start = manifest_str.find('# EOC') + 6
  163. manifest_file.seek(json_start)
  164. manifest_str = manifest_file.read()
  165. python_manifest = json.loads(manifest_str, object_pairs_hook=collections.OrderedDict)
  166. include_pycs = d.getVar('INCLUDE_PYCS')
  167. packages = d.getVar('PACKAGES').split()
  168. pn = d.getVar('PN')
  169. newpackages=[]
  170. for key in python_manifest:
  171. pypackage= pn + '-' + key
  172. if pypackage not in packages:
  173. # We need to prepend, otherwise python-misc gets everything
  174. # so we use a new variable
  175. newpackages.append(pypackage)
  176. # "Build" python's manifest FILES, RDEPENDS and SUMMARY
  177. d.setVar('FILES_' + pypackage, '')
  178. for value in python_manifest[key]['files']:
  179. d.appendVar('FILES_' + pypackage, ' ' + value)
  180. if include_pycs == '1':
  181. if value.endswith('.py'):
  182. d.appendVar('FILES_' + pypackage, ' ' + value + 'c')
  183. for value in python_manifest[key]['rdepends']:
  184. # Make it work with or without $PN
  185. if '${PN}' in value:
  186. value=value.split('-')[1]
  187. d.appendVar('RDEPENDS_' + pypackage, ' ' + pn + '-' + value)
  188. d.setVar('SUMMARY_' + pypackage, python_manifest[key]['summary'])
  189. # Prepending so to avoid python-misc getting everything
  190. packages = newpackages + packages
  191. d.setVar('PACKAGES', ' '.join(packages))
  192. d.setVar('ALLOW_EMPTY_${PN}-modules', '1')
  193. }
  194. # Files needed to create a new manifest
  195. SRC_URI += "file://create_manifest2.py file://get_module_deps2.py file://python2-manifest.json"
  196. do_create_manifest() {
  197. # This task should be run with every new release of Python.
  198. # We must ensure that PACKAGECONFIG enables everything when creating
  199. # a new manifest, this is to base our new manifest on a complete
  200. # native python build, containing all dependencies, otherwise the task
  201. # wont be able to find the required files.
  202. # e.g. BerkeleyDB is an optional build dependency so it may or may not
  203. # be present, we must ensure it is.
  204. cd ${WORKDIR}
  205. # This needs to be executed by python-native and NOT by HOST's python
  206. nativepython create_manifest2.py
  207. cp python2-manifest.json.new ${THISDIR}/python/python2-manifest.json
  208. }
  209. # bitbake python -c create_manifest
  210. addtask do_create_manifest
  211. # Make sure we have native python ready when we create a new manifest
  212. do_create_manifest[depends] += "python:do_prepare_recipe_sysroot"
  213. do_create_manifest[depends] += "python:do_patch"