Daniel Kurtz | b5dc783 | 2019-05-22 16:06:45 -0600 | [diff] [blame] | 1 | # Copyright 1999-2018 Gentoo Authors |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 2 | # Distributed under the terms of the GNU General Public License v2 |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 3 | # $Header: /var/cvsroot/gentoo-x86/dev-lang/python/python-2.7.10.ebuild,v 1.2 2015/06/29 17:26:27 floppym Exp $ |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 4 | |
George Burgess IV | b2459ff | 2019-02-05 13:04:40 -0800 | [diff] [blame] | 5 | EAPI="5" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 6 | WANT_LIBTOOL="none" |
| 7 | |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 8 | inherit autotools eutils flag-o-matic multilib pax-utils python-utils-r1 toolchain-funcs multiprocessing |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 9 | |
| 10 | MY_P="Python-${PV}" |
Daniel Kurtz | b5dc783 | 2019-05-22 16:06:45 -0600 | [diff] [blame] | 11 | PATCHSET_VERSION="2.7.15" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 12 | |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 13 | DESCRIPTION="An interpreted, interactive, object-oriented programming language" |
Daniel Kurtz | db13889 | 2019-05-22 11:48:20 -0600 | [diff] [blame] | 14 | HOMEPAGE="https://www.python.org/" |
George Burgess IV | b2459ff | 2019-02-05 13:04:40 -0800 | [diff] [blame] | 15 | |
| 16 | # The version of Python our PGO profile was generated with. Using ${PV} makes |
| 17 | # updates difficult, and we have tricks below to catch a mismatched profile |
| 18 | # version. |
Daniel Kurtz | b5dc783 | 2019-05-22 16:06:45 -0600 | [diff] [blame] | 19 | PROF_VERSION="2.7.15" |
George Burgess IV | b2459ff | 2019-02-05 13:04:40 -0800 | [diff] [blame] | 20 | |
Daniel Kurtz | db13889 | 2019-05-22 11:48:20 -0600 | [diff] [blame] | 21 | SRC_URI="https://www.python.org/ftp/python/${PV}/${MY_P}.tar.xz |
Daniel Kurtz | 67551cf | 2019-05-21 13:45:52 -0600 | [diff] [blame] | 22 | https://dev.gentoo.org/~floppym/python/python-gentoo-patches-${PATCHSET_VERSION}.tar.xz |
George Burgess IV | b2459ff | 2019-02-05 13:04:40 -0800 | [diff] [blame] | 23 | pgo_use? ( gs://chromeos-localmirror/distfiles/python-${PROF_VERSION}-pgo-prof.profdata.tar.xz )" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 24 | |
| 25 | LICENSE="PSF-2" |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 26 | SLOT="2.7" |
Mike Frysinger | 6533215 | 2014-02-14 13:55:27 -0500 | [diff] [blame] | 27 | KEYWORDS="*" |
Daniel Kurtz | 68ac7de | 2019-05-22 12:29:24 -0600 | [diff] [blame] | 28 | IUSE="-berkdb bluetooth build doc elibc_uclibc examples gdbm hardened ipv6 pgo_generate +pgo_use libressl +ncurses +readline sqlite +ssl +threads tk +wide-unicode wininst +xml" |
George Burgess IV | b2459ff | 2019-02-05 13:04:40 -0800 | [diff] [blame] | 29 | |
| 30 | REQUIRED_USE="pgo_generate? ( !pgo_use )" |
| 31 | |
| 32 | # Workaround: re-emerging this after emerging a `pgo_generate` Python gives us |
| 33 | # a really bad time, since we'll try to write to profiles in "restricted" |
| 34 | # places somehow. Specifying this profile file has LLVM write profiles to |
| 35 | # /dev/null, which is always available. |
| 36 | export LLVM_PROFILE_FILE="/dev/null" |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 37 | |
| 38 | # Do not add a dependency on dev-lang/python to this ebuild. |
| 39 | # If you need to apply a patch which requires python for bootstrapping, please |
| 40 | # run the bootstrap code on your dev box and include the results in the |
| 41 | # patchset. See bug 447752. |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 42 | |
Daniel Kurtz | 6008887 | 2019-05-21 13:42:05 -0600 | [diff] [blame] | 43 | RDEPEND="app-arch/bzip2:0= |
| 44 | >=sys-libs/zlib-1.1.3:0= |
Daniel Kurtz | e113131 | 2019-05-22 14:45:16 -0600 | [diff] [blame] | 45 | virtual/libffi:= |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 46 | virtual/libintl |
Daniel Kurtz | 006a1f5 | 2019-05-21 13:35:07 -0600 | [diff] [blame] | 47 | berkdb? ( || ( |
| 48 | sys-libs/db:5.3 |
Daniel Kurtz | 006a1f5 | 2019-05-21 13:35:07 -0600 | [diff] [blame] | 49 | sys-libs/db:5.1 |
Daniel Kurtz | 006a1f5 | 2019-05-21 13:35:07 -0600 | [diff] [blame] | 50 | sys-libs/db:4.8 |
| 51 | sys-libs/db:4.7 |
| 52 | sys-libs/db:4.6 |
| 53 | sys-libs/db:4.5 |
| 54 | sys-libs/db:4.4 |
| 55 | sys-libs/db:4.3 |
| 56 | sys-libs/db:4.2 |
| 57 | ) ) |
Daniel Kurtz | 6008887 | 2019-05-21 13:42:05 -0600 | [diff] [blame] | 58 | gdbm? ( sys-libs/gdbm:0=[berkdb] ) |
Daniel Kurtz | 37f8450 | 2019-05-22 12:13:01 -0600 | [diff] [blame] | 59 | ncurses? ( >=sys-libs/ncurses-5.2:0= ) |
| 60 | readline? ( >=sys-libs/readline-4.1:0= ) |
Daniel Kurtz | 6008887 | 2019-05-21 13:42:05 -0600 | [diff] [blame] | 61 | sqlite? ( >=dev-db/sqlite-3.3.8:3= ) |
Daniel Kurtz | 006a1f5 | 2019-05-21 13:35:07 -0600 | [diff] [blame] | 62 | ssl? ( |
Daniel Kurtz | 6008887 | 2019-05-21 13:42:05 -0600 | [diff] [blame] | 63 | !libressl? ( dev-libs/openssl:0= ) |
Daniel Kurtz | b5dc783 | 2019-05-22 16:06:45 -0600 | [diff] [blame] | 64 | libressl? ( dev-libs/libressl:0= ) |
Daniel Kurtz | 006a1f5 | 2019-05-21 13:35:07 -0600 | [diff] [blame] | 65 | ) |
| 66 | tk? ( |
Daniel Kurtz | 6008887 | 2019-05-21 13:42:05 -0600 | [diff] [blame] | 67 | >=dev-lang/tcl-8.0:0= |
| 68 | >=dev-lang/tk-8.0:0= |
| 69 | dev-tcltk/blt:0= |
Daniel Kurtz | 006a1f5 | 2019-05-21 13:35:07 -0600 | [diff] [blame] | 70 | dev-tcltk/tix |
| 71 | ) |
Daniel Kurtz | 6008887 | 2019-05-21 13:42:05 -0600 | [diff] [blame] | 72 | xml? ( >=dev-libs/expat-2.1 ) |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 73 | !!<sys-apps/portage-2.1.9" |
Daniel Kurtz | 68ac7de | 2019-05-22 12:29:24 -0600 | [diff] [blame] | 74 | # bluetooth requires headers from bluez |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 75 | DEPEND="${RDEPEND} |
Daniel Kurtz | 68ac7de | 2019-05-22 12:29:24 -0600 | [diff] [blame] | 76 | bluetooth? ( net-wireless/bluez ) |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 77 | virtual/pkgconfig |
| 78 | >=sys-devel/autoconf-2.65 |
Daniel Kurtz | aceb8df | 2019-05-22 11:39:28 -0600 | [diff] [blame] | 79 | !sys-devel/gcc[libffi(-)]" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 80 | RDEPEND+=" !build? ( app-misc/mime-types ) |
| 81 | doc? ( dev-python/python-docs:${SLOT} )" |
Daniel Kurtz | 7f55c26 | 2019-05-22 11:23:41 -0600 | [diff] [blame] | 82 | PDEPEND=">=app-eselect/eselect-python-20140125-r1" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 83 | |
| 84 | S="${WORKDIR}/${MY_P}" |
| 85 | |
| 86 | pkg_setup() { |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 87 | if use berkdb; then |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 88 | ewarn "'bsddb' module is out-of-date and no longer maintained inside" |
| 89 | ewarn "dev-lang/python. 'bsddb' and 'dbhash' modules have been additionally" |
| 90 | ewarn "removed in Python 3. A maintained alternative of 'bsddb3' module" |
| 91 | ewarn "is provided by dev-python/bsddb3." |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 92 | else |
| 93 | if has_version "=${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"; then |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 94 | ewarn "You are migrating from =${CATEGORY}/${PN}-${PV%%.*}*[berkdb]" |
| 95 | ewarn "to =${CATEGORY}/${PN}-${PV%%.*}*[-berkdb]." |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 96 | ewarn "You might need to migrate your databases." |
| 97 | fi |
| 98 | fi |
| 99 | } |
| 100 | |
| 101 | src_prepare() { |
Tim Zwiebel | ab07eb2 | 2017-06-03 03:19:57 -0700 | [diff] [blame] | 102 | # According to the comments at the top of cgi.py, Linux vendors need to |
| 103 | # patch the shebang in cgi.py. We'll ignore the comment about not using |
| 104 | # "/usr/bin/env python" and use it anyway. |
| 105 | sed -i -e '1 s:^#!.*$:#! /usr/bin/env python:' Lib/cgi.py || die |
| 106 | |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 107 | # Ensure that internal copies of expat, libffi and zlib are not used. |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 108 | rm -r Modules/expat || die |
| 109 | rm -r Modules/_ctypes/libffi* || die |
| 110 | rm -r Modules/zlib || die |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 111 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 112 | if tc-is-cross-compiler; then |
Daniel Kurtz | b5dc783 | 2019-05-22 16:06:45 -0600 | [diff] [blame] | 113 | local EPATCH_EXCLUDE="*-Regenerate-platform-specific-modules.patch" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 114 | fi |
| 115 | |
Daniel Kurtz | b5dc783 | 2019-05-22 16:06:45 -0600 | [diff] [blame] | 116 | EPATCH_SUFFIX="patch" EPATCH_FORCE="yes" epatch "${WORKDIR}/patches" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 117 | |
| 118 | # |
| 119 | # START: ChromiumOS specific changes |
| 120 | # |
| 121 | if tc-is-cross-compiler ; then |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 122 | epatch "${FILESDIR}"/python-2.7.10-cross-h2py.patch |
| 123 | epatch "${FILESDIR}"/python-2.7.10-cross-hack-compiler.patch |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 124 | sed -i 's:^python$EXE:${HOSTPYTHON}:' Lib/*/regen || die |
| 125 | fi |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 126 | epatch "${FILESDIR}"/python-2.7.10-cross-setup-sysroot.patch |
| 127 | epatch "${FILESDIR}"/python-2.7.10-cross-distutils.patch |
Mike Frysinger | 935ee6f | 2019-09-06 14:38:15 -0400 | [diff] [blame] | 128 | epatch "${FILESDIR}"/python-2.7.10-cross-sysconfig.patch |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 129 | epatch "${FILESDIR}"/python-2.7.10-ldshared.patch |
Mike Frysinger | 0707e93 | 2021-01-27 13:23:58 -0500 | [diff] [blame] | 130 | epatch "${FILESDIR}"/python-2.7.15-deprecate.patch |
Mike Frysinger | eb04796 | 2014-04-06 10:08:56 -0400 | [diff] [blame] | 131 | # Undo the @libdir@ change for portage's pym folder as it is always |
| 132 | # installed into /usr/lib/ and not the abi libdir. |
| 133 | sed -i \ |
| 134 | -e '/portage.*pym/s:@@GENTOO_LIBDIR@@:lib:g' \ |
| 135 | Lib/site.py || die |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 136 | |
| 137 | sed -i -e "s:sys.exec_prefix]:sys.exec_prefix, '/usr/local']:g" \ |
| 138 | Lib/site.py || die "sed failed to add /usr/local to prefixes" |
George Burgess IV | b2459ff | 2019-02-05 13:04:40 -0800 | [diff] [blame] | 139 | |
| 140 | # Enable stealthy profile application; with this, `sysconfig` won't |
| 141 | # report on any CFLAGS in EXTRA_CFLAGS |
| 142 | epatch "${FILESDIR}"/python-2.7-clear-extra-cflags.patch |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 143 | # |
| 144 | # END: ChromiumOS specific changes |
| 145 | # |
| 146 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 147 | # Fix for cross-compiling. |
| 148 | epatch "${FILESDIR}/python-2.7.5-nonfatal-compileall.patch" |
| 149 | epatch "${FILESDIR}/python-2.7.9-ncurses-pkg-config.patch" |
Daniel Kurtz | 6e688d6 | 2019-05-21 13:31:42 -0600 | [diff] [blame] | 150 | epatch "${FILESDIR}/python-2.7.10-cross-compile-warn-test.patch" |
Daniel Kurtz | 7abe6f5 | 2019-05-21 17:41:24 -0600 | [diff] [blame] | 151 | epatch "${FILESDIR}/python-2.7.10-system-libffi.patch" |
Chris McDonald | 5ca5bf2 | 2019-08-07 14:53:57 -0600 | [diff] [blame] | 152 | epatch "${FILESDIR}/python-2.7.15-sigint-handler.patch" |
Chris McDonald | 9b1ed16 | 2020-10-19 17:33:59 -0600 | [diff] [blame] | 153 | epatch "${FILESDIR}/python-2.7.15-no-override-system-CC.patch" |
Daniel Kurtz | 2b44514 | 2019-05-22 11:08:15 -0600 | [diff] [blame] | 154 | epatch_user |
| 155 | |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 156 | sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \ |
| 157 | Lib/distutils/command/install.py \ |
| 158 | Lib/distutils/sysconfig.py \ |
| 159 | Lib/site.py \ |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 160 | Lib/sysconfig.py \ |
| 161 | Lib/test/test_site.py \ |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 162 | Makefile.pre.in \ |
| 163 | Modules/Setup.dist \ |
| 164 | Modules/getpath.c \ |
| 165 | setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@" |
| 166 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 167 | eautoreconf |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 168 | } |
| 169 | |
George Burgess IV | b2459ff | 2019-02-05 13:04:40 -0800 | [diff] [blame] | 170 | # There's a sad story behind this. When we've built our `python` and |
| 171 | # `libpython.so` objects, we'll go to build all of our Python modules. This is |
| 172 | # done with LD_LIBRARY_PATH set to our workdir, and is generally |
| 173 | # well-sandboxed. Sadly, the compiler is a wrapper written in Python and |
| 174 | # invoked via #!/usr/bin/python2, so **the compiler invocations will link to |
| 175 | # the new, not-yet-installed libpython.so**. |
| 176 | # |
| 177 | # Usually, this isn't much of a problem. However, when we're building Python |
| 178 | # with instrumentation enabled, libpython.so is where some of the key |
| 179 | # instrumentation functions end up. Since everything links to libpython.so, and |
| 180 | # since libpython.so shows up in link lines before libclang_rt.profile (where |
| 181 | # these "key instrumentation functions" come from), the only binary we built |
| 182 | # with USE=pgo_generate that has an actual definition for these functions is |
| 183 | # libpython.so. |
| 184 | # |
| 185 | # Hence, the old python invoked by the wrapper looks for its profiling symbols |
| 186 | # in the *new* libpython.so, doesn't find them, and gets sad. |
| 187 | # |
| 188 | # This can all be fixed by moving libclang_rt.profiles up before -lpython2.7 in |
| 189 | # the commandline, which is easily doable. Doing so puts these profiling |
| 190 | # symbols in every binary we produce, but only in pgo_generate builds. They're |
| 191 | # all dynamic symbols, so keeping multiple definitions around should be OK. |
| 192 | # |
| 193 | # Clang is good about moving libclangrt_profile around, so we just parse its |
| 194 | # output to determine where this static lib is located today. |
| 195 | detect_libprofile_rt_location() { |
| 196 | local result |
| 197 | # Clang always gives quoted output. We're picking out the single arg |
| 198 | # with libclang_rt.profile from it, and discarding the quotes. |
| 199 | result=$(echo | \ |
| 200 | $(tc-getCC) -### -fprofile-generate -x c - |& \ |
| 201 | grep -oE '"[^"]+libclang_rt.profile[^"]+"' | \ |
| 202 | tr -d '"') |
| 203 | [[ -n "${result}" ]] || die "libclangrt detection failed" |
| 204 | echo "${result}" |
| 205 | } |
| 206 | |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 207 | src_configure() { |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 208 | # dbm module can be linked against berkdb or gdbm. |
| 209 | # Defaults to gdbm when both are enabled, #204343. |
| 210 | local disable |
| 211 | use berkdb || use gdbm || disable+=" dbm" |
| 212 | use berkdb || disable+=" _bsddb" |
Daniel Kurtz | 68ac7de | 2019-05-22 12:29:24 -0600 | [diff] [blame] | 213 | # disable automagic bluetooth headers detection |
| 214 | use bluetooth || export ac_cv_header_bluetooth_bluetooth_h=no |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 215 | use gdbm || disable+=" gdbm" |
| 216 | use ncurses || disable+=" _curses _curses_panel" |
| 217 | use readline || disable+=" readline" |
| 218 | use sqlite || disable+=" _sqlite3" |
| 219 | use ssl || export PYTHON_DISABLE_SSL="1" |
| 220 | use tk || disable+=" _tkinter" |
| 221 | use xml || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat. |
| 222 | export PYTHON_DISABLE_MODULES="${disable}" |
| 223 | |
| 224 | if ! use xml; then |
| 225 | ewarn "You have configured Python without XML support." |
| 226 | ewarn "This is NOT a recommended configuration as you" |
| 227 | ewarn "may face problems parsing any XML documents." |
| 228 | fi |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 229 | |
| 230 | if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then |
| 231 | einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}" |
| 232 | fi |
| 233 | |
| 234 | if [[ "$(gcc-major-version)" -ge 4 ]]; then |
| 235 | append-flags -fwrapv |
| 236 | fi |
| 237 | |
| 238 | filter-flags -malign-double |
| 239 | |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 240 | # https://bugs.gentoo.org/show_bug.cgi?id=50309 |
| 241 | if is-flagq -O3; then |
| 242 | is-flagq -fstack-protector-all && replace-flags -O3 -O2 |
| 243 | use hardened && replace-flags -O3 -O2 |
| 244 | fi |
| 245 | |
Manoj Gupta | fb92eaba | 2020-06-18 09:59:43 -0700 | [diff] [blame] | 246 | # python2 build is running cross-compiled x86_64 binaries on build |
| 247 | # machine that may not have same ISA. Filter architecture specific |
| 248 | # flags as a workaround, https://crbug.com/1091706 . |
| 249 | if use amd64 && tc-is-cross-compiler; then |
| 250 | filter-flags '-march=*' |
| 251 | fi |
| 252 | |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 253 | if tc-is-cross-compiler; then |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 254 | # Force some tests that try to poke fs paths. |
| 255 | export ac_cv_file__dev_ptc=no |
| 256 | export ac_cv_file__dev_ptmx=yes |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 257 | fi |
| 258 | |
| 259 | # Export CXX so it ends up in /usr/lib/python2.X/config/Makefile. |
| 260 | tc-export CXX |
| 261 | # The configure script fails to use pkg-config correctly. |
| 262 | # http://bugs.python.org/issue15506 |
| 263 | export ac_cv_path_PKG_CONFIG=$(tc-getPKG_CONFIG) |
| 264 | |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 265 | # Set LDFLAGS so we link modules with -lpython2.7 correctly. |
| 266 | # Needed on FreeBSD unless Python 2.7 is already installed. |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 267 | # Please query BSD team before removing this! |
| 268 | append-ldflags "-L." |
| 269 | |
George Burgess IV | b2459ff | 2019-02-05 13:04:40 -0800 | [diff] [blame] | 270 | tc-export CC |
| 271 | if use pgo_generate; then |
| 272 | tc-is-clang || die "Instrumentation is only supported when using clang" |
| 273 | # tc_extra_flags is an invention used to make cflags apply |
| 274 | # equally to Python's C modules and Python itself. This also |
| 275 | # prevents duplication between CFLAGS and LDFLAGS, which is a |
| 276 | # build error with -mllvm -options. |
| 277 | # |
| 278 | # This is a functional change in Python that breaks subversion |
| 279 | # (SWIG Python bindings rely on distutils.sysconfigs' ${CC}), |
| 280 | # so you should consider re-emerge'ing before trying to emerge |
| 281 | # anything else. |
| 282 | # |
| 283 | # We explicitly use /tmp here because this path is *baked into |
| 284 | # Python* as the place where profiles should go when Python is |
| 285 | # run. Hence, it has to be a well-known place that lives after |
| 286 | # `emerge`. |
| 287 | CC+=" -fprofile-generate=/tmp/python_profiles" |
| 288 | |
| 289 | # LLVM intentionally low-balls vp-counters-per-site to save some |
| 290 | # binary size. If left to its default of 1, we get a diagnostic |
| 291 | # asking for it to be raised. Instead of tweaking it and having |
| 292 | # the issue silently appear again in the future, force dynamic |
| 293 | # allocation of counters. It's marginally slower, but less |
| 294 | # error-prone. |
| 295 | CC+=" -mllvm -vp-static-alloc=false" |
| 296 | |
| 297 | append-ldflags "$(detect_libprofile_rt_location)" |
| 298 | fi |
| 299 | |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 300 | local dbmliborder |
| 301 | if use gdbm; then |
| 302 | dbmliborder+="${dbmliborder:+:}gdbm" |
| 303 | fi |
| 304 | if use berkdb; then |
| 305 | dbmliborder+="${dbmliborder:+:}bdb" |
| 306 | fi |
| 307 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 308 | BUILD_DIR="${WORKDIR}/${CHOST}" |
| 309 | mkdir -p "${BUILD_DIR}" || die |
| 310 | cd "${BUILD_DIR}" || die |
| 311 | |
| 312 | ECONF_SOURCE="${S}" OPT="" \ |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 313 | econf \ |
| 314 | --with-fpectl \ |
| 315 | --enable-shared \ |
| 316 | $(use_enable ipv6) \ |
| 317 | $(use_with threads) \ |
| 318 | $(use wide-unicode && echo "--enable-unicode=ucs4" || echo "--enable-unicode=ucs2") \ |
| 319 | --infodir='${prefix}/share/info' \ |
| 320 | --mandir='${prefix}/share/man' \ |
Daniel Kurtz | b5dc783 | 2019-05-22 16:06:45 -0600 | [diff] [blame] | 321 | --with-computed-gotos \ |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 322 | --with-dbmliborder="${dbmliborder}" \ |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 323 | --with-libc="" \ |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 324 | --enable-loadable-sqlite-extensions \ |
| 325 | --with-system-expat \ |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 326 | --with-system-ffi \ |
| 327 | --without-ensurepip |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 328 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 329 | if use threads && grep -q "#define POSIX_SEMAPHORES_NOT_ENABLED 1" pyconfig.h; then |
| 330 | eerror "configure has detected that the sem_open function is broken." |
| 331 | eerror "Please ensure that /dev/shm is mounted as a tmpfs with mode 1777." |
| 332 | die "Broken sem_open function (bug 496328)" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 333 | fi |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | src_compile() { |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 337 | # Avoid invoking pgen for cross-compiles. |
| 338 | touch Include/graminit.h Python/graminit.c |
| 339 | |
George Burgess IV | b2459ff | 2019-02-05 13:04:40 -0800 | [diff] [blame] | 340 | # CFLAGS specified in configure get baked into the `sysconfig` module, |
| 341 | # which is consulted when building e.g. SWIG bindings for subversion. |
| 342 | # OPT, which we wiped out during configuration time anyway, allows us |
| 343 | # to pass flags that `sysconfig` doesn't see. |
| 344 | local extra_cflags=() |
| 345 | if use pgo_use && tc-is-clang; then |
| 346 | # If you're upgrading Python, please also run |
| 347 | # ./files/python2_gen_pgo.sh to build a new PGO profile. |
| 348 | if [[ "${PV}" != "${PROF_VERSION}" ]]; then |
| 349 | die "Please generate a new profile. Details in comments." |
| 350 | fi |
| 351 | |
| 352 | extra_cflags=( |
| 353 | "-fprofile-use=${WORKDIR}/python-${PROF_VERSION}-pgo-prof.profdata" |
| 354 | "-Wno-backend-plugin" |
| 355 | ) |
| 356 | |
| 357 | # LTO only buys us ~2%, it increases binary size around 750KB, |
| 358 | # and it's entirely broken on aarch64 (LTO prompts clang to use |
| 359 | # its built-in assembler, which has issues with inline assembly |
| 360 | # in Python, apparently.) |
| 361 | fi |
| 362 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 363 | cd "${BUILD_DIR}" || die |
George Burgess IV | b2459ff | 2019-02-05 13:04:40 -0800 | [diff] [blame] | 364 | EXTRA_CFLAGS="${extra_cflags[*]}" emake |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 365 | |
| 366 | # Work around bug 329499. See also bug 413751 and 457194. |
| 367 | if has_version dev-libs/libffi[pax_kernel]; then |
| 368 | pax-mark E python |
| 369 | else |
| 370 | pax-mark m python |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 371 | fi |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | src_test() { |
| 375 | # Tests will not work when cross compiling. |
| 376 | if tc-is-cross-compiler; then |
| 377 | elog "Disabling tests due to crosscompiling." |
| 378 | return |
| 379 | fi |
| 380 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 381 | cd "${BUILD_DIR}" || die |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 382 | |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 383 | # Skip failing tests. |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 384 | local skipped_tests="distutils gdb" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 385 | |
| 386 | for test in ${skipped_tests}; do |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 387 | mv "${S}"/Lib/test/test_${test}.py "${T}" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 388 | done |
| 389 | |
Daniel Kurtz | baa5377 | 2019-05-22 11:45:33 -0600 | [diff] [blame] | 390 | # Daylight saving time problem |
| 391 | # https://bugs.python.org/issue22067 |
| 392 | # https://bugs.gentoo.org/610628 |
| 393 | local -x TZ=UTC |
| 394 | |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 395 | # Rerun failed tests in verbose mode (regrtest -w). |
| 396 | emake test EXTRATESTOPTS="-w" < /dev/tty |
| 397 | local result="$?" |
| 398 | |
| 399 | for test in ${skipped_tests}; do |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 400 | mv "${T}/test_${test}.py" "${S}"/Lib/test |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 401 | done |
| 402 | |
| 403 | elog "The following tests have been skipped:" |
| 404 | for test in ${skipped_tests}; do |
| 405 | elog "test_${test}.py" |
| 406 | done |
| 407 | |
| 408 | elog "If you would like to run them, you may:" |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 409 | elog "cd '${EPREFIX}/usr/$(get_libdir)/python${SLOT}/test'" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 410 | elog "and run the tests separately." |
| 411 | |
| 412 | python_disable_pyc |
| 413 | |
| 414 | if [[ "${result}" -ne 0 ]]; then |
| 415 | die "emake test failed" |
| 416 | fi |
| 417 | } |
| 418 | |
| 419 | src_install() { |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 420 | local libdir=${ED}/usr/$(get_libdir)/python${SLOT} |
| 421 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 422 | cd "${BUILD_DIR}" || die |
| 423 | emake DESTDIR="${D}" altinstall |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 424 | |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 425 | sed -e "s/\(LDFLAGS=\).*/\1/" -i "${libdir}/config/Makefile" || die "sed failed" |
| 426 | |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 427 | # Fix collisions between different slots of Python. |
| 428 | mv "${ED}usr/bin/2to3" "${ED}usr/bin/2to3-${SLOT}" |
| 429 | mv "${ED}usr/bin/pydoc" "${ED}usr/bin/pydoc${SLOT}" |
| 430 | mv "${ED}usr/bin/idle" "${ED}usr/bin/idle${SLOT}" |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 431 | rm -f "${ED}usr/bin/smtpd.py" |
| 432 | |
Daniel Kurtz | efb535c | 2019-05-22 11:44:24 -0600 | [diff] [blame] | 433 | use berkdb || rm -r "${libdir}/"{bsddb,dbhash.py*,test/test_bsddb*} || die |
Daniel Kurtz | 221b461 | 2019-05-22 11:42:25 -0600 | [diff] [blame] | 434 | use sqlite || rm -r "${libdir}/"{sqlite3,test/test_sqlite*} || die |
| 435 | use tk || rm -r "${ED}usr/bin/idle${SLOT}" "${libdir}/"{idlelib,lib-tk} || die |
| 436 | use elibc_uclibc && rm -fr "${libdir}/"{bsddb/test,test} |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 437 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 438 | use threads || rm -r "${libdir}/multiprocessing" || die |
| 439 | use wininst || rm -r "${libdir}/distutils/command/"wininst-*.exe || die |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 440 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 441 | dodoc "${S}"/Misc/{ACKS,HISTORY,NEWS} |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 442 | |
| 443 | if use examples; then |
| 444 | insinto /usr/share/doc/${PF}/examples |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 445 | doins -r "${S}"/Tools |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 446 | fi |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 447 | insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510 |
| 448 | local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \ |
| 449 | emake --no-print-directory -s -f - 2>/dev/null) |
| 450 | newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 451 | |
Mike Frysinger | 51f0d52 | 2015-11-21 00:11:17 +0000 | [diff] [blame] | 452 | newconfd "${FILESDIR}/pydoc.conf" pydoc-${SLOT} |
| 453 | newinitd "${FILESDIR}/pydoc.init" pydoc-${SLOT} |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 454 | sed \ |
| 455 | -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${SLOT/./_}_PORT:" \ |
| 456 | -e "s:@PYDOC@:pydoc${SLOT}:" \ |
| 457 | -i "${ED}etc/conf.d/pydoc-${SLOT}" "${ED}etc/init.d/pydoc-${SLOT}" || die "sed failed" |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 458 | |
| 459 | # for python-exec |
Daniel Kurtz | fc1f14d | 2019-05-21 17:01:58 -0600 | [diff] [blame] | 460 | local vars=( EPYTHON PYTHON_SITEDIR PYTHON_SCRIPTDIR ) |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 461 | |
| 462 | # if not using a cross-compiler, use the fresh binary |
| 463 | if ! tc-is-cross-compiler; then |
Daniel Kurtz | fc1f14d | 2019-05-21 17:01:58 -0600 | [diff] [blame] | 464 | local -x PYTHON=./python |
Daniel Kurtz | a22fd60 | 2019-05-22 11:52:20 -0600 | [diff] [blame] | 465 | local -x LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}${PWD} |
Daniel Kurtz | fc1f14d | 2019-05-21 17:01:58 -0600 | [diff] [blame] | 466 | else |
| 467 | vars=( PYTHON "${vars[@]}" ) |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 468 | fi |
| 469 | |
Daniel Kurtz | ee2f728 | 2019-05-21 17:06:08 -0600 | [diff] [blame] | 470 | python_export "python${SLOT}" "${vars[@]}" |
Daniel Kurtz | fc1f14d | 2019-05-21 17:01:58 -0600 | [diff] [blame] | 471 | echo "EPYTHON='${EPYTHON}'" > epython.py || die |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 472 | python_domodule epython.py |
| 473 | |
Chad Versace | 016e873 | 2018-10-26 12:55:13 -0700 | [diff] [blame] | 474 | # python-exec wrapping support |
| 475 | local pymajor=${SLOT%.*} |
| 476 | mkdir -p "${D}${PYTHON_SCRIPTDIR}" || die |
Daniel Kurtz | 31ebeca | 2019-05-21 17:16:54 -0600 | [diff] [blame] | 477 | # python and pythonX |
Daniel Kurtz | b5dc783 | 2019-05-22 16:06:45 -0600 | [diff] [blame] | 478 | ln -s "../../../bin/python${SLOT}" "${D}${PYTHON_SCRIPTDIR}/python${pymajor}" || die |
| 479 | ln -s "python${pymajor}" "${D}${PYTHON_SCRIPTDIR}/python" || die |
Daniel Kurtz | 31ebeca | 2019-05-21 17:16:54 -0600 | [diff] [blame] | 480 | # python-config and pythonX-config |
Daniel Kurtz | b5dc783 | 2019-05-22 16:06:45 -0600 | [diff] [blame] | 481 | ln -s "../../../bin/python${SLOT}-config" "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" || die |
| 482 | ln -s "python${pymajor}-config" "${D}${PYTHON_SCRIPTDIR}/python-config" || die |
Daniel Kurtz | 31ebeca | 2019-05-21 17:16:54 -0600 | [diff] [blame] | 483 | # 2to3, pydoc, pyvenv |
Daniel Kurtz | b5dc783 | 2019-05-22 16:06:45 -0600 | [diff] [blame] | 484 | ln -s "../../../bin/2to3-${SLOT}" "${D}${PYTHON_SCRIPTDIR}/2to3" || die |
| 485 | ln -s "../../../bin/pydoc${SLOT}" "${D}${PYTHON_SCRIPTDIR}/pydoc" || die |
Daniel Kurtz | e185310 | 2019-05-22 10:59:07 -0600 | [diff] [blame] | 486 | # idle |
| 487 | if use tk; then |
Daniel Kurtz | b5dc783 | 2019-05-22 16:06:45 -0600 | [diff] [blame] | 488 | ln -s "../../../bin/idle${SLOT}" "${D}${PYTHON_SCRIPTDIR}/idle" || die |
Daniel Kurtz | e185310 | 2019-05-22 10:59:07 -0600 | [diff] [blame] | 489 | fi |
Chad Versace | 016e873 | 2018-10-26 12:55:13 -0700 | [diff] [blame] | 490 | |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 491 | # The sysconfig module will actually read the pyconfig.h at runtime to see what kind |
| 492 | # of functionality is enabled in the build. Deploy it behind the back of portage as |
| 493 | # need be. |
Mike Frysinger | d7685db | 2013-04-06 02:03:53 -0400 | [diff] [blame] | 494 | ln "${ED}/usr/include/python${SLOT}/pyconfig.h" "${libdir}/pyconfig_h" || die |
| 495 | |
| 496 | # Workaround https://bugs.gentoo.org/380569 |
| 497 | keepdir /etc/env.d/python |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 498 | } |
| 499 | |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 500 | eselect_python_update() { |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 501 | if [[ -z "$(eselect python show)" || ! -f "${EROOT}usr/bin/$(eselect python show)" ]]; then |
| 502 | eselect python update |
| 503 | fi |
| 504 | |
| 505 | if [[ -z "$(eselect python show --python${PV%%.*})" || ! -f "${EROOT}usr/bin/$(eselect python show --python${PV%%.*})" ]]; then |
| 506 | eselect python update --python${PV%%.*} |
| 507 | fi |
| 508 | } |
| 509 | |
| 510 | pkg_postinst() { |
| 511 | eselect_python_update |
| 512 | |
Mike Frysinger | d7685db | 2013-04-06 02:03:53 -0400 | [diff] [blame] | 513 | local pyconfig="${EROOT}/usr/$(get_libdir)/python${SLOT}/pyconfig_h" |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 514 | if [[ ! -e ${EROOT}/usr/include/python${SLOT}/pyconfig.h ]] ; then |
| 515 | # See pkg_preinst above for details. |
Mike Frysinger | d7685db | 2013-04-06 02:03:53 -0400 | [diff] [blame] | 516 | install -D -m644 "${pyconfig}" "${EROOT}/usr/include/python${SLOT}/pyconfig.h" || die |
Mike Frysinger | 4cfb44a | 2013-03-18 22:37:33 -0400 | [diff] [blame] | 517 | fi |
Mike Frysinger | d7685db | 2013-04-06 02:03:53 -0400 | [diff] [blame] | 518 | rm "${pyconfig}" || die |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | pkg_postrm() { |
| 522 | eselect_python_update |
Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame] | 523 | } |