blob: 5b856a50977d0fe6dbed4b6cc1a394f53b62d47b [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 Bishop15ae2502019-06-18 21:44:24 -040033"
Brad Bishopc342db32019-05-15 21:57:59 -040034
35S = "${WORKDIR}/Python-${PV}"
36
37inherit autotools multilib_header python-dir pythonnative ptest
38
39CONFIGUREOPTS += " --with-system-ffi "
40
41EXTRA_OECONF += "ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no ac_cv_working_tzset=yes"
42
43PACKAGECONFIG ??= "bdb"
44PACKAGECONFIG[bdb] = ",,db"
45PACKAGECONFIG[tk] = ",,tk"
46
47do_configure_append() {
48 rm -f ${S}/Makefile.orig
49 autoreconf -Wcross --verbose --install --force --exclude=autopoint ../Python-${PV}/Modules/_ctypes/libffi
50}
51
52do_compile() {
53 # regenerate platform specific files, because they depend on system headers
54 cd ${S}/Lib/plat-linux2
55 include=${STAGING_INCDIR} ${STAGING_BINDIR_NATIVE}/python-native/python \
56 ${S}/Tools/scripts/h2py.py -i '(u_long)' \
57 ${STAGING_INCDIR}/dlfcn.h \
58 ${STAGING_INCDIR}/linux/cdrom.h \
59 ${STAGING_INCDIR}/netinet/in.h \
60 ${STAGING_INCDIR}/sys/types.h
61 sed -e 's,${STAGING_DIR_HOST},,g' -i *.py
62 cd -
63
64 # remove any bogus LD_LIBRARY_PATH
65 sed -i -e s,RUNSHARED=.*,RUNSHARED=, Makefile
66
67 if [ ! -f Makefile.orig ]; then
68 install -m 0644 Makefile Makefile.orig
69 fi
70 sed -i -e 's#^LDFLAGS=.*#LDFLAGS=${LDFLAGS} -L. -L${STAGING_LIBDIR}#g' \
71 -e 's,libdir=${libdir},libdir=${STAGING_LIBDIR},g' \
72 -e 's,libexecdir=${libexecdir},libexecdir=${STAGING_DIR_HOST}${libexecdir},g' \
73 -e 's,^LIBDIR=.*,LIBDIR=${STAGING_LIBDIR},g' \
74 -e 's,includedir=${includedir},includedir=${STAGING_INCDIR},g' \
75 -e 's,^INCLUDEDIR=.*,INCLUDE=${STAGING_INCDIR},g' \
76 -e 's,^CONFINCLUDEDIR=.*,CONFINCLUDE=${STAGING_INCDIR},g' \
77 Makefile
78 # save copy of it now, because if we do it in do_install and
79 # then call do_install twice we get Makefile.orig == Makefile.sysroot
80 install -m 0644 Makefile Makefile.sysroot
81
82 export CROSS_COMPILE="${TARGET_PREFIX}"
83 export PYTHONBUILDDIR="${B}"
84
85 oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python-native/pgen \
86 HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python-native/python \
87 STAGING_LIBDIR=${STAGING_LIBDIR} \
88 STAGING_INCDIR=${STAGING_INCDIR} \
89 STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \
90 OPT="${CFLAGS}"
91}
92
93do_install() {
94 # make install needs the original Makefile, or otherwise the inclues would
95 # go to ${D}${STAGING...}/...
96 install -m 0644 Makefile.orig Makefile
97
98 export CROSS_COMPILE="${TARGET_PREFIX}"
99 export PYTHONBUILDDIR="${B}"
100
101 # After swizzling the makefile, we need to run the build again.
102 # install can race with the build so we have to run this first, then install
103 oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python-native/pgen \
104 HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python-native/python \
105 CROSSPYTHONPATH=${STAGING_LIBDIR_NATIVE}/python${PYTHON_MAJMIN}/lib-dynload/ \
106 STAGING_LIBDIR=${STAGING_LIBDIR} \
107 STAGING_INCDIR=${STAGING_INCDIR} \
108 STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \
109 DESTDIR=${D} LIBDIR=${libdir}
110
111 oe_runmake HOSTPGEN=${STAGING_BINDIR_NATIVE}/python-native/pgen \
112 HOSTPYTHON=${STAGING_BINDIR_NATIVE}/python-native/python \
113 CROSSPYTHONPATH=${STAGING_LIBDIR_NATIVE}/python${PYTHON_MAJMIN}/lib-dynload/ \
114 STAGING_LIBDIR=${STAGING_LIBDIR} \
115 STAGING_INCDIR=${STAGING_INCDIR} \
116 STAGING_BASELIBDIR=${STAGING_BASELIBDIR} \
117 DESTDIR=${D} LIBDIR=${libdir} install
118
119 install -m 0644 Makefile.sysroot ${D}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile
120
121 if [ -e ${WORKDIR}/sitecustomize.py ]; then
122 install -m 0644 ${WORKDIR}/sitecustomize.py ${D}/${libdir}/python${PYTHON_MAJMIN}
123 fi
124
125 oe_multilib_header python${PYTHON_MAJMIN}/pyconfig.h
126
127 if [ -z "${@bb.utils.filter('PACKAGECONFIG', 'bdb', d)}" ]; then
128 rm -rf ${D}/${libdir}/python${PYTHON_MAJMIN}/bsddb
129 fi
130
131 # Python 3.x version of 2to3 is now the default
132 mv ${D}/${bindir}/2to3 ${D}/${bindir}/2to3-${PYTHON_MAJMIN}
133}
134
135do_install_append_class-nativesdk () {
136 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'
137}
138
139SSTATE_SCAN_FILES += "Makefile"
140PACKAGE_PREPROCESS_FUNCS += "py_package_preprocess"
141
142py_package_preprocess () {
143 # copy back the old Makefile to fix target package
144 install -m 0644 ${B}/Makefile.orig ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile
145
146 # Remove references to buildmachine paths in target Makefile and _sysconfigdata
147 sed -i -e 's:--sysroot=${STAGING_DIR_TARGET}::g' -e s:'--with-libtool-sysroot=${STAGING_DIR_TARGET}'::g \
148 -e 's|${DEBUG_PREFIX_MAP}||g' \
149 -e 's:${HOSTTOOLS_DIR}/::g' \
150 -e 's:${RECIPE_SYSROOT_NATIVE}::g' \
151 -e 's:${RECIPE_SYSROOT}::g' \
152 -e 's:${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}::g' \
153 ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile \
154 ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py
155 (cd ${PKGD}; python -m py_compile ./${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py)
156}
157
158PACKAGES_remove = "${PN}"
159
160# manual dependency additions
Brad Bishopf3fd2882019-06-21 08:06:37 -0400161RPROVIDES_${PN}-modules = "${PN}"
Brad Bishopc342db32019-05-15 21:57:59 -0400162RRECOMMENDS_${PN}-core_append_class-nativesdk = " nativesdk-python-modules"
163RRECOMMENDS_${PN}-crypt = "openssl"
164
165# package libpython2
166PACKAGES =+ "lib${BPN}2"
167FILES_lib${BPN}2 = "${libdir}/libpython*.so.*"
168
169# catch all the rest (unsorted)
170PACKAGES += "${PN}-misc"
171FILES_${PN}-misc = "${libdir}/python${PYTHON_MAJMIN}"
172RDEPENDS_${PN}-modules += "${PN}-misc"
173
174# ptest
175RDEPENDS_${PN}-ptest = "${PN}-modules ${PN}-tests unzip tzdata-europe coreutils sed"
Brad Bishop00e122a2019-10-05 11:10:57 -0400176RDEPENDS_${PN}-tkinter += "${@bb.utils.contains('PACKAGECONFIG', 'tk', 'tk tk-lib', '', d)}"
Brad Bishopc342db32019-05-15 21:57:59 -0400177# catch manpage
178PACKAGES += "${PN}-man"
179FILES_${PN}-man = "${datadir}/man"
180
181# Nasty but if bdb isn't enabled the package won't be generated
182RDEPENDS_${PN}-modules_remove = "${@bb.utils.contains('PACKAGECONFIG', 'bdb', '', '${PN}-bsddb', d)}"
183
184RDEPENDS_${PN}-dev = ""
185
186BBCLASSEXTEND = "nativesdk"
187
188# We want bytecode precompiled .py files (.pyc's) by default
189# but the user may set it on their own conf
190
191INCLUDE_PYCS ?= "1"
192
193python(){
194 import collections, json
195
196 filename = os.path.join(d.getVar('THISDIR'), 'python', 'python2-manifest.json')
197 # This python changes the datastore based on the contents of a file, so mark
198 # that dependency.
199 bb.parse.mark_dependency(d, filename)
200
201 with open(filename) as manifest_file:
202 manifest_str = manifest_file.read()
203 json_start = manifest_str.find('# EOC') + 6
204 manifest_file.seek(json_start)
205 manifest_str = manifest_file.read()
206 python_manifest = json.loads(manifest_str, object_pairs_hook=collections.OrderedDict)
207
208 include_pycs = d.getVar('INCLUDE_PYCS')
209
210 packages = d.getVar('PACKAGES').split()
211 pn = d.getVar('PN')
212
213 newpackages=[]
214
215 for key in python_manifest:
216 pypackage= pn + '-' + key
217
218 if pypackage not in packages:
219 # We need to prepend, otherwise python-misc gets everything
220 # so we use a new variable
221 newpackages.append(pypackage)
222
223 # "Build" python's manifest FILES, RDEPENDS and SUMMARY
224 d.setVar('FILES_' + pypackage, '')
225 for value in python_manifest[key]['files']:
226 d.appendVar('FILES_' + pypackage, ' ' + value)
227 if include_pycs == '1':
228 if value.endswith('.py'):
229 d.appendVar('FILES_' + pypackage, ' ' + value + 'c')
230
231 for value in python_manifest[key]['rdepends']:
232 # Make it work with or without $PN
233 if '${PN}' in value:
234 value=value.split('-')[1]
235 d.appendVar('RDEPENDS_' + pypackage, ' ' + pn + '-' + value)
236 d.setVar('SUMMARY_' + pypackage, python_manifest[key]['summary'])
237
238 # Prepending so to avoid python-misc getting everything
239 packages = newpackages + packages
240 d.setVar('PACKAGES', ' '.join(packages))
241 d.setVar('ALLOW_EMPTY_${PN}-modules', '1')
242}
243
244# Files needed to create a new manifest
245SRC_URI += "file://create_manifest2.py file://get_module_deps2.py file://python2-manifest.json"
246
247do_create_manifest() {
248 # This task should be run with every new release of Python.
249 # We must ensure that PACKAGECONFIG enables everything when creating
250 # a new manifest, this is to base our new manifest on a complete
251 # native python build, containing all dependencies, otherwise the task
252 # wont be able to find the required files.
253 # e.g. BerkeleyDB is an optional build dependency so it may or may not
254 # be present, we must ensure it is.
255
256 cd ${WORKDIR}
257 # This needs to be executed by python-native and NOT by HOST's python
258 nativepython create_manifest2.py
259 cp python2-manifest.json.new ${THISDIR}/python/python2-manifest.json
260}
261
262# bitbake python -c create_manifest
263addtask do_create_manifest
264
265# Make sure we have native python ready when we create a new manifest
266do_create_manifest[depends] += "python:do_prepare_recipe_sysroot"
267do_create_manifest[depends] += "python:do_patch"