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