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