Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1 | require python.inc |
| 2 | |
| 3 | DEPENDS = "python-native libffi bzip2 gdbm openssl readline sqlite3 zlib" |
| 4 | |
| 5 | PR = "${INC_PR}" |
| 6 | |
| 7 | DISTRO_SRC_URI ?= "file://sitecustomize.py" |
| 8 | DISTRO_SRC_URI_linuxstdbase = "" |
| 9 | SRC_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 Burton | 4d4042d | 2018-05-15 23:32:10 -0700 | [diff] [blame] | 33 | file://fix-gc-alignment.patch \ |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 34 | " |
| 35 | |
| 36 | S = "${WORKDIR}/Python-${PV}" |
| 37 | |
| 38 | inherit autotools multilib_header python-dir pythonnative |
| 39 | |
| 40 | CONFIGUREOPTS += " --with-system-ffi " |
| 41 | |
| 42 | EXTRA_OECONF += "ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no" |
| 43 | |
| 44 | PACKAGECONFIG ??= "bdb" |
| 45 | PACKAGECONFIG[bdb] = ",,db" |
| 46 | |
| 47 | do_configure_append() { |
| 48 | rm -f ${S}/Makefile.orig |
| 49 | autoreconf -Wcross --verbose --install --force --exclude=autopoint ../Python-${PV}/Modules/_ctypes/libffi |
| 50 | } |
| 51 | |
| 52 | do_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 | |
| 93 | do_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 | |
| 132 | do_install_append_class-nativesdk () { |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 133 | 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 Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | SSTATE_SCAN_FILES += "Makefile" |
| 137 | PACKAGE_PREPROCESS_FUNCS += "py_package_preprocess" |
| 138 | |
| 139 | py_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 |
| 157 | RPROVIDES_${PN}-core = "${PN}" |
| 158 | RRECOMMENDS_${PN}-core_append_class-nativesdk = " nativesdk-python-modules" |
| 159 | RRECOMMENDS_${PN}-crypt = "openssl" |
| 160 | |
| 161 | # package libpython2 |
| 162 | PACKAGES =+ "lib${BPN}2" |
| 163 | FILES_lib${BPN}2 = "${libdir}/libpython*.so.*" |
| 164 | |
| 165 | # catch all the rest (unsorted) |
| 166 | PACKAGES += "${PN}-misc" |
| 167 | FILES_${PN}-misc = "${libdir}/python${PYTHON_MAJMIN}" |
| 168 | RDEPENDS_${PN}-modules += "${PN}-misc" |
| 169 | |
| 170 | # ptest |
| 171 | RDEPENDS_${PN}-ptest = "${PN}-modules ${PN}-tests" |
| 172 | #inherit ptest after "require python-${PYTHON_MAJMIN}-manifest.inc" so PACKAGES doesn't get overwritten |
| 173 | inherit ptest |
| 174 | |
| 175 | # This must come after inherit ptest for the override to take effect |
| 176 | do_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 |
| 194 | PACKAGES += "${PN}-man" |
| 195 | FILES_${PN}-man = "${datadir}/man" |
| 196 | |
| 197 | # Nasty but if bdb isn't enabled the package won't be generated |
| 198 | RDEPENDS_${PN}-modules_remove = "${@bb.utils.contains('PACKAGECONFIG', 'bdb', '', '${PN}-bsddb', d)}" |
| 199 | |
| 200 | BBCLASSEXTEND = "nativesdk" |
| 201 | |
| 202 | RPROVIDES_${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 | |
| 207 | INCLUDE_PYCS ?= "1" |
| 208 | |
| 209 | python(){ |
Andrew Geissler | 9f6e941 | 2018-09-19 09:22:28 -0700 | [diff] [blame] | 210 | import collections, json |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 211 | |
| 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 Geissler | 9f6e941 | 2018-09-19 09:22:28 -0700 | [diff] [blame] | 218 | python_manifest=json.load(manifest_file, object_pairs_hook=collections.OrderedDict) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 219 | |
| 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 Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 251 | # 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 |
| 258 | SRC_URI += "file://create_manifest2.py file://get_module_deps2.py file://python2-manifest.json" |
| 259 | |
| 260 | do_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 |
| 276 | addtask do_create_manifest |
| 277 | |
| 278 | # Make sure we have native python ready when we create a new manifest |
| 279 | do_create_manifest[depends] += "python:do_prepare_recipe_sysroot" |
| 280 | do_create_manifest[depends] += "python:do_patch" |