blob: ea54fb9e79b00928ada36e82ebe40c93c0241c47 [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 \
26 file://fix-makefile-for-ptest.patch \
27 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 \
Ross Burton4d4042d2018-05-15 23:32:10 -070033 file://fix-gc-alignment.patch \
Brad Bishop316dfdd2018-06-25 12:45:53 -040034"
35
36S = "${WORKDIR}/Python-${PV}"
37
38inherit autotools multilib_header python-dir pythonnative
39
40CONFIGUREOPTS += " --with-system-ffi "
41
42EXTRA_OECONF += "ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no"
43
44PACKAGECONFIG ??= "bdb"
45PACKAGECONFIG[bdb] = ",,db"
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
132do_install_append_class-nativesdk () {
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700133 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 -0400134}
135
136SSTATE_SCAN_FILES += "Makefile"
137PACKAGE_PREPROCESS_FUNCS += "py_package_preprocess"
138
139py_package_preprocess () {
140 # copy back the old Makefile to fix target package
141 install -m 0644 ${B}/Makefile.orig ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile
142
143 # Remove references to buildmachine paths in target Makefile and _sysconfigdata
144 sed -i -e 's:--sysroot=${STAGING_DIR_TARGET}::g' -e s:'--with-libtool-sysroot=${STAGING_DIR_TARGET}'::g \
145 -e 's|${DEBUG_PREFIX_MAP}||g' \
146 -e 's:${HOSTTOOLS_DIR}/::g' \
147 -e 's:${RECIPE_SYSROOT_NATIVE}::g' \
148 -e 's:${RECIPE_SYSROOT}::g' \
149 -e 's:${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}::g' \
150 ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/config/Makefile \
151 ${PKGD}/${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py
152 (cd ${PKGD}; python -m py_compile ./${libdir}/python${PYTHON_MAJMIN}/_sysconfigdata.py)
153}
154
155
156# manual dependency additions
157RPROVIDES_${PN}-core = "${PN}"
158RRECOMMENDS_${PN}-core_append_class-nativesdk = " nativesdk-python-modules"
159RRECOMMENDS_${PN}-crypt = "openssl"
160
161# package libpython2
162PACKAGES =+ "lib${BPN}2"
163FILES_lib${BPN}2 = "${libdir}/libpython*.so.*"
164
165# catch all the rest (unsorted)
166PACKAGES += "${PN}-misc"
167FILES_${PN}-misc = "${libdir}/python${PYTHON_MAJMIN}"
168RDEPENDS_${PN}-modules += "${PN}-misc"
169
170# ptest
171RDEPENDS_${PN}-ptest = "${PN}-modules ${PN}-tests"
172#inherit ptest after "require python-${PYTHON_MAJMIN}-manifest.inc" so PACKAGES doesn't get overwritten
173inherit ptest
174
175# This must come after inherit ptest for the override to take effect
176do_install_ptest() {
177 cp ${B}/Makefile ${D}${PTEST_PATH}
178 sed -e s:LIBDIR/python/ptest:${PTEST_PATH}:g \
179 -e s:LIBDIR:${libdir}:g \
180 -i ${D}${PTEST_PATH}/run-ptest
181
182 #Remove build host references
183 sed -i \
184 -e 's:--with-libtool-sysroot=${STAGING_DIR_TARGET}'::g \
185 -e 's:--sysroot=${STAGING_DIR_TARGET}::g' \
186 -e 's|${DEBUG_PREFIX_MAP}||g' \
187 -e 's:${HOSTTOOLS_DIR}/::g' \
188 -e 's:${RECIPE_SYSROOT}::g' \
189 -e 's:${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}::g' \
190 ${D}/${PTEST_PATH}/Makefile
191}
192
193# catch manpage
194PACKAGES += "${PN}-man"
195FILES_${PN}-man = "${datadir}/man"
196
197# Nasty but if bdb isn't enabled the package won't be generated
198RDEPENDS_${PN}-modules_remove = "${@bb.utils.contains('PACKAGECONFIG', 'bdb', '', '${PN}-bsddb', d)}"
199
200BBCLASSEXTEND = "nativesdk"
201
202RPROVIDES_${PN} += "${PN}-modules"
203
204# We want bytecode precompiled .py files (.pyc's) by default
205# but the user may set it on their own conf
206
207INCLUDE_PYCS ?= "1"
208
209python(){
Andrew Geissler9f6e9412018-09-19 09:22:28 -0700210 import collections, json
Brad Bishop316dfdd2018-06-25 12:45:53 -0400211
212 filename = os.path.join(d.getVar('THISDIR'), 'python', 'python2-manifest.json')
213 # This python changes the datastore based on the contents of a file, so mark
214 # that dependency.
215 bb.parse.mark_dependency(d, filename)
216
217 with open(filename) as manifest_file:
Andrew Geissler9f6e9412018-09-19 09:22:28 -0700218 python_manifest=json.load(manifest_file, object_pairs_hook=collections.OrderedDict)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400219
220 include_pycs = d.getVar('INCLUDE_PYCS')
221
222 packages = d.getVar('PACKAGES').split()
223 pn = d.getVar('PN')
224
225 newpackages=[]
226
227 for key in python_manifest:
228 pypackage= pn + '-' + key
229
230 if pypackage not in packages:
231 # We need to prepend, otherwise python-misc gets everything
232 # so we use a new variable
233 newpackages.append(pypackage)
234
235 # "Build" python's manifest FILES, RDEPENDS and SUMMARY
236 d.setVar('FILES_' + pypackage, '')
237 for value in python_manifest[key]['files']:
238 d.appendVar('FILES_' + pypackage, ' ' + value)
239 if include_pycs == '1':
240 if value.endswith('.py'):
241 d.appendVar('FILES_' + pypackage, ' ' + value + 'c')
242
243 d.setVar('RDEPENDS_' + pypackage, '')
244 for value in python_manifest[key]['rdepends']:
245 # Make it work with or without $PN
246 if '${PN}' in value:
247 value=value.split('-')[1]
248 d.appendVar('RDEPENDS_' + pypackage, ' ' + pn + '-' + value)
249 d.setVar('SUMMARY_' + pypackage, python_manifest[key]['summary'])
250
Brad Bishop316dfdd2018-06-25 12:45:53 -0400251 # Prepending so to avoid python-misc getting everything
252 packages = newpackages + packages
253 d.setVar('PACKAGES', ' '.join(packages))
254 d.setVar('ALLOW_EMPTY_${PN}-modules', '1')
255}
256
257# Files needed to create a new manifest
258SRC_URI += "file://create_manifest2.py file://get_module_deps2.py file://python2-manifest.json"
259
260do_create_manifest() {
261 # This task should be run with every new release of Python.
262 # We must ensure that PACKAGECONFIG enables everything when creating
263 # a new manifest, this is to base our new manifest on a complete
264 # native python build, containing all dependencies, otherwise the task
265 # wont be able to find the required files.
266 # e.g. BerkeleyDB is an optional build dependency so it may or may not
267 # be present, we must ensure it is.
268
269 cd ${WORKDIR}
270 # This needs to be executed by python-native and NOT by HOST's python
271 nativepython create_manifest2.py
272 cp python2-manifest.json.new ${THISDIR}/python/python2-manifest.json
273}
274
275# bitbake python -c create_manifest
276addtask do_create_manifest
277
278# Make sure we have native python ready when we create a new manifest
279do_create_manifest[depends] += "python:do_prepare_recipe_sysroot"
280do_create_manifest[depends] += "python:do_patch"