blob: aec877825e34a3a3b0e5c973338ce0c8280f143d [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001require python.inc
2
3DEPENDS = "python-native libffi bzip2 gdbm openssl \
4 readline sqlite3 zlib virtual/crypt"
5
6DISTRO_SRC_URI ?= "file://sitecustomize.py"
7DISTRO_SRC_URI_linuxstdbase = ""
8SRC_URI += " \
9 file://01-use-proper-tools-for-cross-build.patch \
10 file://03-fix-tkinter-detection.patch \
11 file://06-avoid_usr_lib_termcap_path_in_linking.patch \
12 ${DISTRO_SRC_URI} \
13 file://multilib.patch \
14 file://cgi_py.patch \
15 file://setup_py_skip_cross_import_check.patch \
16 file://add-md5module-support.patch \
17 file://host_include_contamination.patch \
18 file://fix_for_using_different_libdir.patch \
19 file://setuptweaks.patch \
20 file://check-if-target-is-64b-not-host.patch \
21 file://search_db_h_in_inc_dirs_and_avoid_warning.patch \
22 ${@bb.utils.contains('PACKAGECONFIG', 'tk', '', 'file://avoid_warning_about_tkinter.patch', d)} \
23 file://avoid_warning_for_sunos_specific_module.patch \
24 file://python-2.7.3-remove-bsdb-rpath.patch \
25 file://run-ptest \
26 file://parallel-makeinst-create-bindir.patch \
27 file://use_sysroot_ncurses_instead_of_host.patch \
28 file://add-CROSSPYTHONPATH-for-PYTHON_FOR_BUILD.patch \
29 file://pass-missing-libraries-to-Extension-for-mul.patch \
30 file://support_SOURCE_DATE_EPOCH_in_py_compile_2.7.patch \
31 file://float-endian.patch \
32 file://0001-python2-use-cc_basename-to-replace-CC-for-checking-c.patch \
Brad Bishopf3f93bb2019-10-16 14:33:32 -040033 file://0001-2.7-bpo-34155-Dont-parse-domains-containing-GH-13079.patch \
Brad Bishop15ae2502019-06-18 21:44:24 -040034"
Brad Bishopc342db32019-05-15 21:57:59 -040035
36S = "${WORKDIR}/Python-${PV}"
37
38inherit autotools multilib_header python-dir pythonnative ptest
39
40CONFIGUREOPTS += " --with-system-ffi "
41
42EXTRA_OECONF += "ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no ac_cv_working_tzset=yes"
43
44PACKAGECONFIG ??= "bdb"
45PACKAGECONFIG[bdb] = ",,db"
46PACKAGECONFIG[tk] = ",,tk"
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 # Python 3.x version of 2to3 is now the default
133 mv ${D}/${bindir}/2to3 ${D}/${bindir}/2to3-${PYTHON_MAJMIN}
134}
135
136do_install_append_class-nativesdk () {
137 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'
138}
139
140SSTATE_SCAN_FILES += "Makefile"
141PACKAGE_PREPROCESS_FUNCS += "py_package_preprocess"
142
143py_package_preprocess () {
144 # copy back the old Makefile to fix target package
145 install -m 0644 ${B}/Makefile.orig ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile
146
147 # Remove references to buildmachine paths in target Makefile and _sysconfigdata
148 sed -i -e 's:--sysroot=${STAGING_DIR_TARGET}::g' -e s:'--with-libtool-sysroot=${STAGING_DIR_TARGET}'::g \
149 -e 's|${DEBUG_PREFIX_MAP}||g' \
150 -e 's:${HOSTTOOLS_DIR}/::g' \
151 -e 's:${RECIPE_SYSROOT_NATIVE}::g' \
152 -e 's:${RECIPE_SYSROOT}::g' \
153 -e 's:${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}::g' \
154 ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile \
155 ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py
156 (cd ${PKGD}; python -m py_compile ./${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py)
157}
158
159PACKAGES_remove = "${PN}"
160
161# manual dependency additions
Brad Bishopf3fd2882019-06-21 08:06:37 -0400162RPROVIDES_${PN}-modules = "${PN}"
Brad Bishopc342db32019-05-15 21:57:59 -0400163RRECOMMENDS_${PN}-core_append_class-nativesdk = " nativesdk-python-modules"
164RRECOMMENDS_${PN}-crypt = "openssl"
165
166# package libpython2
167PACKAGES =+ "lib${BPN}2"
168FILES_lib${BPN}2 = "${libdir}/libpython*.so.*"
169
170# catch all the rest (unsorted)
171PACKAGES += "${PN}-misc"
172FILES_${PN}-misc = "${libdir}/python${PYTHON_MAJMIN}"
173RDEPENDS_${PN}-modules += "${PN}-misc"
174
175# ptest
176RDEPENDS_${PN}-ptest = "${PN}-modules ${PN}-tests unzip tzdata-europe coreutils sed"
Brad Bishop00e122a2019-10-05 11:10:57 -0400177RDEPENDS_${PN}-tkinter += "${@bb.utils.contains('PACKAGECONFIG', 'tk', 'tk tk-lib', '', d)}"
Brad Bishopc342db32019-05-15 21:57:59 -0400178# catch manpage
179PACKAGES += "${PN}-man"
180FILES_${PN}-man = "${datadir}/man"
181
182# Nasty but if bdb isn't enabled the package won't be generated
183RDEPENDS_${PN}-modules_remove = "${@bb.utils.contains('PACKAGECONFIG', 'bdb', '', '${PN}-bsddb', d)}"
184
185RDEPENDS_${PN}-dev = ""
186
187BBCLASSEXTEND = "nativesdk"
188
189# We want bytecode precompiled .py files (.pyc's) by default
190# but the user may set it on their own conf
191
192INCLUDE_PYCS ?= "1"
193
194python(){
195 import collections, json
196
197 filename = os.path.join(d.getVar('THISDIR'), 'python', 'python2-manifest.json')
198 # This python changes the datastore based on the contents of a file, so mark
199 # that dependency.
200 bb.parse.mark_dependency(d, filename)
201
202 with open(filename) as manifest_file:
203 manifest_str = manifest_file.read()
204 json_start = manifest_str.find('# EOC') + 6
205 manifest_file.seek(json_start)
206 manifest_str = manifest_file.read()
207 python_manifest = json.loads(manifest_str, object_pairs_hook=collections.OrderedDict)
208
209 include_pycs = d.getVar('INCLUDE_PYCS')
210
211 packages = d.getVar('PACKAGES').split()
212 pn = d.getVar('PN')
213
214 newpackages=[]
215
216 for key in python_manifest:
217 pypackage= pn + '-' + key
218
219 if pypackage not in packages:
220 # We need to prepend, otherwise python-misc gets everything
221 # so we use a new variable
222 newpackages.append(pypackage)
223
224 # "Build" python's manifest FILES, RDEPENDS and SUMMARY
225 d.setVar('FILES_' + pypackage, '')
226 for value in python_manifest[key]['files']:
227 d.appendVar('FILES_' + pypackage, ' ' + value)
228 if include_pycs == '1':
229 if value.endswith('.py'):
230 d.appendVar('FILES_' + pypackage, ' ' + value + 'c')
231
232 for value in python_manifest[key]['rdepends']:
233 # Make it work with or without $PN
234 if '${PN}' in value:
235 value=value.split('-')[1]
236 d.appendVar('RDEPENDS_' + pypackage, ' ' + pn + '-' + value)
237 d.setVar('SUMMARY_' + pypackage, python_manifest[key]['summary'])
238
239 # Prepending so to avoid python-misc getting everything
240 packages = newpackages + packages
241 d.setVar('PACKAGES', ' '.join(packages))
242 d.setVar('ALLOW_EMPTY_${PN}-modules', '1')
243}
244
245# Files needed to create a new manifest
246SRC_URI += "file://create_manifest2.py file://get_module_deps2.py file://python2-manifest.json"
247
248do_create_manifest() {
249 # This task should be run with every new release of Python.
250 # We must ensure that PACKAGECONFIG enables everything when creating
251 # a new manifest, this is to base our new manifest on a complete
252 # native python build, containing all dependencies, otherwise the task
253 # wont be able to find the required files.
254 # e.g. BerkeleyDB is an optional build dependency so it may or may not
255 # be present, we must ensure it is.
256
257 cd ${WORKDIR}
258 # This needs to be executed by python-native and NOT by HOST's python
259 nativepython create_manifest2.py
260 cp python2-manifest.json.new ${THISDIR}/python/python2-manifest.json
261}
262
263# bitbake python -c create_manifest
264addtask do_create_manifest
265
266# Make sure we have native python ready when we create a new manifest
267do_create_manifest[depends] += "python:do_prepare_recipe_sysroot"
268do_create_manifest[depends] += "python:do_patch"