blob: 94fa972eb671de81628d4e37709729ba8d091ffa [file] [log] [blame]
Mike Frysinger51f0d522015-11-21 00:11:17 +00001# Copyright 1999-2015 Gentoo Foundation
Mike Frysinger682d0652012-07-30 11:38:25 -04002# Distributed under the terms of the GNU General Public License v2
Mike Frysinger51f0d522015-11-21 00:11:17 +00003# $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 Frysinger682d0652012-07-30 11:38:25 -04004
George Burgess IVb2459ff2019-02-05 13:04:40 -08005EAPI="5"
Mike Frysinger682d0652012-07-30 11:38:25 -04006WANT_LIBTOOL="none"
7
Mike Frysinger4cfb44a2013-03-18 22:37:33 -04008inherit autotools eutils flag-o-matic multilib pax-utils python-utils-r1 toolchain-funcs multiprocessing
Mike Frysinger682d0652012-07-30 11:38:25 -04009
10MY_P="Python-${PV}"
Mike Frysinger51f0d522015-11-21 00:11:17 +000011PATCHSET_VERSION="2.7.10-0"
Mike Frysinger682d0652012-07-30 11:38:25 -040012
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040013DESCRIPTION="An interpreted, interactive, object-oriented programming language"
Mike Frysinger682d0652012-07-30 11:38:25 -040014HOMEPAGE="http://www.python.org/"
George Burgess IVb2459ff2019-02-05 13:04:40 -080015
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.
19PROF_VERSION="2.7.10"
20
Mike Frysinger51f0d522015-11-21 00:11:17 +000021SRC_URI="http://www.python.org/ftp/python/${PV}/${MY_P}.tar.xz
Daniel Kurtz67551cf2019-05-21 13:45:52 -060022 https://dev.gentoo.org/~floppym/python/python-gentoo-patches-${PATCHSET_VERSION}.tar.xz
George Burgess IVb2459ff2019-02-05 13:04:40 -080023 pgo_use? ( gs://chromeos-localmirror/distfiles/python-${PROF_VERSION}-pgo-prof.profdata.tar.xz )"
Mike Frysinger682d0652012-07-30 11:38:25 -040024
25LICENSE="PSF-2"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040026SLOT="2.7"
Mike Frysinger65332152014-02-14 13:55:27 -050027KEYWORDS="*"
George Burgess IVb2459ff2019-02-05 13:04:40 -080028IUSE="-berkdb build doc elibc_uclibc examples gdbm hardened ipv6 pgo_generate +pgo_use +ncurses +readline sqlite +ssl +threads tk +wide-unicode wininst +xml"
29
30REQUIRED_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.
36export LLVM_PROFILE_FILE="/dev/null"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040037
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 Frysinger682d0652012-07-30 11:38:25 -040042
43RDEPEND="app-arch/bzip2
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040044 >=sys-libs/zlib-1.1.3
45 virtual/libffi
46 virtual/libintl
47 !build? (
48 berkdb? ( || (
Mike Frysinger51f0d522015-11-21 00:11:17 +000049 sys-libs/db:5.3
50 sys-libs/db:5.2
51 sys-libs/db:5.1
52 sys-libs/db:5.0
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040053 sys-libs/db:4.8
54 sys-libs/db:4.7
55 sys-libs/db:4.6
56 sys-libs/db:4.5
57 sys-libs/db:4.4
58 sys-libs/db:4.3
59 sys-libs/db:4.2
60 ) )
Daniel Kurtza54e8c22019-05-21 14:05:03 -060061 gdbm? ( sys-libs/gdbm[berkdb] )
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040062 ncurses? (
63 >=sys-libs/ncurses-5.2
64 readline? ( >=sys-libs/readline-4.1 )
Mike Frysinger682d0652012-07-30 11:38:25 -040065 )
Ryan Sleevi1a745162014-10-27 18:14:49 -070066 sqlite? ( >=dev-db/sqlite-3.3.8:3 )
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040067 ssl? ( dev-libs/openssl )
68 tk? (
69 >=dev-lang/tk-8.0
70 dev-tcltk/blt
Mike Frysinger51f0d522015-11-21 00:11:17 +000071 dev-tcltk/tix
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040072 )
73 xml? ( >=dev-libs/expat-2.1 )
74 )
75 !!<sys-apps/portage-2.1.9"
Mike Frysinger682d0652012-07-30 11:38:25 -040076DEPEND="${RDEPEND}
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040077 virtual/pkgconfig
78 >=sys-devel/autoconf-2.65
79 !sys-devel/gcc[libffi]"
Mike Frysinger682d0652012-07-30 11:38:25 -040080RDEPEND+=" !build? ( app-misc/mime-types )
81 doc? ( dev-python/python-docs:${SLOT} )"
Daniel Kurtzd47b2922017-07-17 17:47:39 +080082PDEPEND="app-eselect/eselect-python
Mike Frysinger51f0d522015-11-21 00:11:17 +000083 app-admin/python-updater"
Mike Frysinger682d0652012-07-30 11:38:25 -040084
85S="${WORKDIR}/${MY_P}"
86
87pkg_setup() {
Mike Frysinger682d0652012-07-30 11:38:25 -040088 if use berkdb; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040089 ewarn "'bsddb' module is out-of-date and no longer maintained inside"
90 ewarn "dev-lang/python. 'bsddb' and 'dbhash' modules have been additionally"
91 ewarn "removed in Python 3. A maintained alternative of 'bsddb3' module"
92 ewarn "is provided by dev-python/bsddb3."
Mike Frysinger682d0652012-07-30 11:38:25 -040093 else
94 if has_version "=${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040095 ewarn "You are migrating from =${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"
96 ewarn "to =${CATEGORY}/${PN}-${PV%%.*}*[-berkdb]."
Mike Frysinger682d0652012-07-30 11:38:25 -040097 ewarn "You might need to migrate your databases."
98 fi
99 fi
100}
101
102src_prepare() {
Tim Zwiebelab07eb22017-06-03 03:19:57 -0700103 # According to the comments at the top of cgi.py, Linux vendors need to
104 # patch the shebang in cgi.py. We'll ignore the comment about not using
105 # "/usr/bin/env python" and use it anyway.
106 sed -i -e '1 s:^#!.*$:#! /usr/bin/env python:' Lib/cgi.py || die
107
Mike Frysinger682d0652012-07-30 11:38:25 -0400108 # Ensure that internal copies of expat, libffi and zlib are not used.
Mike Frysinger51f0d522015-11-21 00:11:17 +0000109 rm -r Modules/expat || die
110 rm -r Modules/_ctypes/libffi* || die
111 rm -r Modules/zlib || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400112
Mike Frysinger51f0d522015-11-21 00:11:17 +0000113 if tc-is-cross-compiler; then
114 local EPATCH_EXCLUDE="*_regenerate_platform-specific_modules.patch"
Mike Frysinger682d0652012-07-30 11:38:25 -0400115 fi
116
Mike Frysinger51f0d522015-11-21 00:11:17 +0000117 EPATCH_SUFFIX="patch" epatch "${WORKDIR}/patches"
Mike Frysinger682d0652012-07-30 11:38:25 -0400118
119 #
120 # START: ChromiumOS specific changes
121 #
122 if tc-is-cross-compiler ; then
Mike Frysinger51f0d522015-11-21 00:11:17 +0000123 epatch "${FILESDIR}"/python-2.7.10-cross-h2py.patch
124 epatch "${FILESDIR}"/python-2.7.10-cross-hack-compiler.patch
Mike Frysinger682d0652012-07-30 11:38:25 -0400125 sed -i 's:^python$EXE:${HOSTPYTHON}:' Lib/*/regen || die
126 fi
Mike Frysinger51f0d522015-11-21 00:11:17 +0000127 epatch "${FILESDIR}"/python-2.7.10-cross-setup-sysroot.patch
128 epatch "${FILESDIR}"/python-2.7.10-cross-distutils.patch
Paul Hobbs43d07e62015-05-14 16:43:16 -0700129 epatch "${FILESDIR}"/python-2.7.3-unique-semaphore-name.patch
Mike Frysinger51f0d522015-11-21 00:11:17 +0000130 epatch "${FILESDIR}"/python-2.7.10-ldshared.patch
Manoj Gupta85657702018-11-05 18:26:27 -0800131 epatch "${FILESDIR}"/python-2.7.17-getentropy.patch
Yunlian Jiang871d0072018-07-24 11:11:01 -0700132 epatch "${FILESDIR}"/2.7-disable-nis.patch
Mike Frysingereb047962014-04-06 10:08:56 -0400133 # Undo the @libdir@ change for portage's pym folder as it is always
134 # installed into /usr/lib/ and not the abi libdir.
135 sed -i \
136 -e '/portage.*pym/s:@@GENTOO_LIBDIR@@:lib:g' \
137 Lib/site.py || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400138
139 sed -i -e "s:sys.exec_prefix]:sys.exec_prefix, '/usr/local']:g" \
140 Lib/site.py || die "sed failed to add /usr/local to prefixes"
George Burgess IVb2459ff2019-02-05 13:04:40 -0800141
142 # Enable stealthy profile application; with this, `sysconfig` won't
143 # report on any CFLAGS in EXTRA_CFLAGS
144 epatch "${FILESDIR}"/python-2.7-clear-extra-cflags.patch
Mike Frysinger682d0652012-07-30 11:38:25 -0400145 #
146 # END: ChromiumOS specific changes
147 #
148
Mike Frysinger51f0d522015-11-21 00:11:17 +0000149 # Fix for cross-compiling.
150 epatch "${FILESDIR}/python-2.7.5-nonfatal-compileall.patch"
151 epatch "${FILESDIR}/python-2.7.9-ncurses-pkg-config.patch"
152
Mike Frysinger682d0652012-07-30 11:38:25 -0400153 sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
154 Lib/distutils/command/install.py \
155 Lib/distutils/sysconfig.py \
156 Lib/site.py \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400157 Lib/sysconfig.py \
158 Lib/test/test_site.py \
Mike Frysinger682d0652012-07-30 11:38:25 -0400159 Makefile.pre.in \
160 Modules/Setup.dist \
161 Modules/getpath.c \
162 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
163
Mike Frysinger51f0d522015-11-21 00:11:17 +0000164 epatch_user
165
166 eautoreconf
Mike Frysinger682d0652012-07-30 11:38:25 -0400167}
168
George Burgess IVb2459ff2019-02-05 13:04:40 -0800169# There's a sad story behind this. When we've built our `python` and
170# `libpython.so` objects, we'll go to build all of our Python modules. This is
171# done with LD_LIBRARY_PATH set to our workdir, and is generally
172# well-sandboxed. Sadly, the compiler is a wrapper written in Python and
173# invoked via #!/usr/bin/python2, so **the compiler invocations will link to
174# the new, not-yet-installed libpython.so**.
175#
176# Usually, this isn't much of a problem. However, when we're building Python
177# with instrumentation enabled, libpython.so is where some of the key
178# instrumentation functions end up. Since everything links to libpython.so, and
179# since libpython.so shows up in link lines before libclang_rt.profile (where
180# these "key instrumentation functions" come from), the only binary we built
181# with USE=pgo_generate that has an actual definition for these functions is
182# libpython.so.
183#
184# Hence, the old python invoked by the wrapper looks for its profiling symbols
185# in the *new* libpython.so, doesn't find them, and gets sad.
186#
187# This can all be fixed by moving libclang_rt.profiles up before -lpython2.7 in
188# the commandline, which is easily doable. Doing so puts these profiling
189# symbols in every binary we produce, but only in pgo_generate builds. They're
190# all dynamic symbols, so keeping multiple definitions around should be OK.
191#
192# Clang is good about moving libclangrt_profile around, so we just parse its
193# output to determine where this static lib is located today.
194detect_libprofile_rt_location() {
195 local result
196 # Clang always gives quoted output. We're picking out the single arg
197 # with libclang_rt.profile from it, and discarding the quotes.
198 result=$(echo | \
199 $(tc-getCC) -### -fprofile-generate -x c - |& \
200 grep -oE '"[^"]+libclang_rt.profile[^"]+"' | \
201 tr -d '"')
202 [[ -n "${result}" ]] || die "libclangrt detection failed"
203 echo "${result}"
204}
205
Mike Frysinger682d0652012-07-30 11:38:25 -0400206src_configure() {
207 if use build; then
208 # Disable extraneous modules with extra dependencies.
209 export PYTHON_DISABLE_MODULES="dbm _bsddb gdbm _curses _curses_panel readline _sqlite3 _tkinter _elementtree pyexpat"
210 export PYTHON_DISABLE_SSL="1"
211 else
212 # dbm module can be linked against berkdb or gdbm.
213 # Defaults to gdbm when both are enabled, #204343.
214 local disable
215 use berkdb || use gdbm || disable+=" dbm"
216 use berkdb || disable+=" _bsddb"
217 use gdbm || disable+=" gdbm"
218 use ncurses || disable+=" _curses _curses_panel"
219 use readline || disable+=" readline"
220 use sqlite || disable+=" _sqlite3"
221 use ssl || export PYTHON_DISABLE_SSL="1"
222 use tk || disable+=" _tkinter"
223 use xml || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
224 export PYTHON_DISABLE_MODULES="${disable}"
225
226 if ! use xml; then
227 ewarn "You have configured Python without XML support."
228 ewarn "This is NOT a recommended configuration as you"
229 ewarn "may face problems parsing any XML documents."
230 fi
231 fi
232
233 if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
234 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
235 fi
236
237 if [[ "$(gcc-major-version)" -ge 4 ]]; then
238 append-flags -fwrapv
239 fi
240
241 filter-flags -malign-double
242
243 [[ "${ARCH}" == "alpha" ]] && append-flags -fPIC
244
245 # https://bugs.gentoo.org/show_bug.cgi?id=50309
246 if is-flagq -O3; then
247 is-flagq -fstack-protector-all && replace-flags -O3 -O2
248 use hardened && replace-flags -O3 -O2
249 fi
250
Mike Frysinger682d0652012-07-30 11:38:25 -0400251 if tc-is-cross-compiler; then
Mike Frysinger51f0d522015-11-21 00:11:17 +0000252 # Force some tests that try to poke fs paths.
253 export ac_cv_file__dev_ptc=no
254 export ac_cv_file__dev_ptmx=yes
Mike Frysinger682d0652012-07-30 11:38:25 -0400255 fi
256
257 # Export CXX so it ends up in /usr/lib/python2.X/config/Makefile.
258 tc-export CXX
259 # The configure script fails to use pkg-config correctly.
260 # http://bugs.python.org/issue15506
261 export ac_cv_path_PKG_CONFIG=$(tc-getPKG_CONFIG)
262
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400263 # Set LDFLAGS so we link modules with -lpython2.7 correctly.
264 # Needed on FreeBSD unless Python 2.7 is already installed.
Mike Frysinger682d0652012-07-30 11:38:25 -0400265 # Please query BSD team before removing this!
266 append-ldflags "-L."
267
George Burgess IVb2459ff2019-02-05 13:04:40 -0800268 tc-export CC
269 if use pgo_generate; then
270 tc-is-clang || die "Instrumentation is only supported when using clang"
271 # tc_extra_flags is an invention used to make cflags apply
272 # equally to Python's C modules and Python itself. This also
273 # prevents duplication between CFLAGS and LDFLAGS, which is a
274 # build error with -mllvm -options.
275 #
276 # This is a functional change in Python that breaks subversion
277 # (SWIG Python bindings rely on distutils.sysconfigs' ${CC}),
278 # so you should consider re-emerge'ing before trying to emerge
279 # anything else.
280 #
281 # We explicitly use /tmp here because this path is *baked into
282 # Python* as the place where profiles should go when Python is
283 # run. Hence, it has to be a well-known place that lives after
284 # `emerge`.
285 CC+=" -fprofile-generate=/tmp/python_profiles"
286
287 # LLVM intentionally low-balls vp-counters-per-site to save some
288 # binary size. If left to its default of 1, we get a diagnostic
289 # asking for it to be raised. Instead of tweaking it and having
290 # the issue silently appear again in the future, force dynamic
291 # allocation of counters. It's marginally slower, but less
292 # error-prone.
293 CC+=" -mllvm -vp-static-alloc=false"
294
295 append-ldflags "$(detect_libprofile_rt_location)"
296 fi
297
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400298 local dbmliborder
299 if use gdbm; then
300 dbmliborder+="${dbmliborder:+:}gdbm"
301 fi
302 if use berkdb; then
303 dbmliborder+="${dbmliborder:+:}bdb"
304 fi
305
Mike Frysinger51f0d522015-11-21 00:11:17 +0000306 BUILD_DIR="${WORKDIR}/${CHOST}"
307 mkdir -p "${BUILD_DIR}" || die
308 cd "${BUILD_DIR}" || die
309
310 ECONF_SOURCE="${S}" OPT="" \
Mike Frysinger682d0652012-07-30 11:38:25 -0400311 econf \
312 --with-fpectl \
313 --enable-shared \
314 $(use_enable ipv6) \
315 $(use_with threads) \
316 $(use wide-unicode && echo "--enable-unicode=ucs4" || echo "--enable-unicode=ucs2") \
317 --infodir='${prefix}/share/info' \
318 --mandir='${prefix}/share/man' \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400319 --with-dbmliborder="${dbmliborder}" \
Mike Frysinger682d0652012-07-30 11:38:25 -0400320 --with-libc="" \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400321 --enable-loadable-sqlite-extensions \
322 --with-system-expat \
Mike Frysinger51f0d522015-11-21 00:11:17 +0000323 --with-system-ffi \
324 --without-ensurepip
Mike Frysinger682d0652012-07-30 11:38:25 -0400325
Mike Frysinger51f0d522015-11-21 00:11:17 +0000326 if use threads && grep -q "#define POSIX_SEMAPHORES_NOT_ENABLED 1" pyconfig.h; then
327 eerror "configure has detected that the sem_open function is broken."
328 eerror "Please ensure that /dev/shm is mounted as a tmpfs with mode 1777."
329 die "Broken sem_open function (bug 496328)"
Mike Frysinger682d0652012-07-30 11:38:25 -0400330 fi
Mike Frysinger682d0652012-07-30 11:38:25 -0400331}
332
333src_compile() {
Mike Frysinger51f0d522015-11-21 00:11:17 +0000334 # Avoid invoking pgen for cross-compiles.
335 touch Include/graminit.h Python/graminit.c
336
George Burgess IVb2459ff2019-02-05 13:04:40 -0800337 # CFLAGS specified in configure get baked into the `sysconfig` module,
338 # which is consulted when building e.g. SWIG bindings for subversion.
339 # OPT, which we wiped out during configuration time anyway, allows us
340 # to pass flags that `sysconfig` doesn't see.
341 local extra_cflags=()
342 if use pgo_use && tc-is-clang; then
343 # If you're upgrading Python, please also run
344 # ./files/python2_gen_pgo.sh to build a new PGO profile.
345 if [[ "${PV}" != "${PROF_VERSION}" ]]; then
346 die "Please generate a new profile. Details in comments."
347 fi
348
349 extra_cflags=(
350 "-fprofile-use=${WORKDIR}/python-${PROF_VERSION}-pgo-prof.profdata"
351 "-Wno-backend-plugin"
352 )
353
354 # LTO only buys us ~2%, it increases binary size around 750KB,
355 # and it's entirely broken on aarch64 (LTO prompts clang to use
356 # its built-in assembler, which has issues with inline assembly
357 # in Python, apparently.)
358 fi
359
Mike Frysinger51f0d522015-11-21 00:11:17 +0000360 cd "${BUILD_DIR}" || die
George Burgess IVb2459ff2019-02-05 13:04:40 -0800361 EXTRA_CFLAGS="${extra_cflags[*]}" emake
Mike Frysinger51f0d522015-11-21 00:11:17 +0000362
363 # Work around bug 329499. See also bug 413751 and 457194.
364 if has_version dev-libs/libffi[pax_kernel]; then
365 pax-mark E python
366 else
367 pax-mark m python
Mike Frysinger682d0652012-07-30 11:38:25 -0400368 fi
Mike Frysinger682d0652012-07-30 11:38:25 -0400369}
370
371src_test() {
372 # Tests will not work when cross compiling.
373 if tc-is-cross-compiler; then
374 elog "Disabling tests due to crosscompiling."
375 return
376 fi
377
Mike Frysinger51f0d522015-11-21 00:11:17 +0000378 cd "${BUILD_DIR}" || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400379
Mike Frysinger682d0652012-07-30 11:38:25 -0400380 # Skip failing tests.
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400381 local skipped_tests="distutils gdb"
Mike Frysinger682d0652012-07-30 11:38:25 -0400382
383 for test in ${skipped_tests}; do
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400384 mv "${S}"/Lib/test/test_${test}.py "${T}"
Mike Frysinger682d0652012-07-30 11:38:25 -0400385 done
386
387 # Rerun failed tests in verbose mode (regrtest -w).
388 emake test EXTRATESTOPTS="-w" < /dev/tty
389 local result="$?"
390
391 for test in ${skipped_tests}; do
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400392 mv "${T}/test_${test}.py" "${S}"/Lib/test
Mike Frysinger682d0652012-07-30 11:38:25 -0400393 done
394
395 elog "The following tests have been skipped:"
396 for test in ${skipped_tests}; do
397 elog "test_${test}.py"
398 done
399
400 elog "If you would like to run them, you may:"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400401 elog "cd '${EPREFIX}/usr/$(get_libdir)/python${SLOT}/test'"
Mike Frysinger682d0652012-07-30 11:38:25 -0400402 elog "and run the tests separately."
403
404 python_disable_pyc
405
406 if [[ "${result}" -ne 0 ]]; then
407 die "emake test failed"
408 fi
409}
410
411src_install() {
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400412 local libdir=${ED}/usr/$(get_libdir)/python${SLOT}
413
Mike Frysinger51f0d522015-11-21 00:11:17 +0000414 cd "${BUILD_DIR}" || die
415 emake DESTDIR="${D}" altinstall
Mike Frysinger682d0652012-07-30 11:38:25 -0400416
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400417 sed -e "s/\(LDFLAGS=\).*/\1/" -i "${libdir}/config/Makefile" || die "sed failed"
418
419 # Backwards compat with Gentoo divergence.
Mike Frysinger51f0d522015-11-21 00:11:17 +0000420 dosym python${SLOT}-config /usr/bin/python-config-${SLOT}
Mike Frysinger682d0652012-07-30 11:38:25 -0400421
422 # Fix collisions between different slots of Python.
423 mv "${ED}usr/bin/2to3" "${ED}usr/bin/2to3-${SLOT}"
424 mv "${ED}usr/bin/pydoc" "${ED}usr/bin/pydoc${SLOT}"
425 mv "${ED}usr/bin/idle" "${ED}usr/bin/idle${SLOT}"
Mike Frysinger682d0652012-07-30 11:38:25 -0400426 rm -f "${ED}usr/bin/smtpd.py"
427
Chad Versace016e8732018-10-26 12:55:13 -0700428 local abiver="python2.7"
429
Mike Frysinger682d0652012-07-30 11:38:25 -0400430 if use build; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400431 rm -fr "${ED}usr/bin/idle${SLOT}" "${libdir}/"{bsddb,dbhash.py,idlelib,lib-tk,sqlite3,test}
Mike Frysinger682d0652012-07-30 11:38:25 -0400432 else
Mike Frysinger51f0d522015-11-21 00:11:17 +0000433 use berkdb || rm -r "${libdir}/"{bsddb,dbhash.py,test/test_bsddb*} || die
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
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400436 use elibc_uclibc && rm -fr "${libdir}/"{bsddb/test,test}
Mike Frysinger682d0652012-07-30 11:38:25 -0400437 fi
438
Mike Frysinger51f0d522015-11-21 00:11:17 +0000439 use threads || rm -r "${libdir}/multiprocessing" || die
440 use wininst || rm -r "${libdir}/distutils/command/"wininst-*.exe || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400441
Mike Frysinger51f0d522015-11-21 00:11:17 +0000442 dodoc "${S}"/Misc/{ACKS,HISTORY,NEWS}
Mike Frysinger682d0652012-07-30 11:38:25 -0400443
444 if use examples; then
445 insinto /usr/share/doc/${PF}/examples
Mike Frysinger51f0d522015-11-21 00:11:17 +0000446 doins -r "${S}"/Tools
Mike Frysinger682d0652012-07-30 11:38:25 -0400447 fi
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400448 insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
449 local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \
450 emake --no-print-directory -s -f - 2>/dev/null)
451 newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py
Mike Frysinger682d0652012-07-30 11:38:25 -0400452
Mike Frysinger51f0d522015-11-21 00:11:17 +0000453 newconfd "${FILESDIR}/pydoc.conf" pydoc-${SLOT}
454 newinitd "${FILESDIR}/pydoc.init" pydoc-${SLOT}
Mike Frysinger682d0652012-07-30 11:38:25 -0400455 sed \
456 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${SLOT/./_}_PORT:" \
457 -e "s:@PYDOC@:pydoc${SLOT}:" \
458 -i "${ED}etc/conf.d/pydoc-${SLOT}" "${ED}etc/init.d/pydoc-${SLOT}" || die "sed failed"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400459
460 # for python-exec
Chad Versace016e8732018-10-26 12:55:13 -0700461 python_export python${SLOT} EPYTHON PYTHON PYTHON_SITEDIR PYTHON_SCRIPTDIR
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400462
463 # if not using a cross-compiler, use the fresh binary
464 if ! tc-is-cross-compiler; then
Mike Frysinger51f0d522015-11-21 00:11:17 +0000465 local PYTHON=./python
466 local -x LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}.
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400467 fi
468
469 echo "EPYTHON='${EPYTHON}'" > epython.py
470 python_domodule epython.py
471
Chad Versace016e8732018-10-26 12:55:13 -0700472 # python-exec wrapping support
473 local pymajor=${SLOT%.*}
474 mkdir -p "${D}${PYTHON_SCRIPTDIR}" || die
475
476 # python-exec: python, pythonX
477 dosym "../../../bin/${abiver}" \
478 "${PYTHON_SCRIPTDIR}/python${pymajor}"
479 dosym "python${pymajor}" "${PYTHON_SCRIPTDIR}/python"
480
481 # python-exec: python-config, python-configX
482 #
483 # Note: we need to create a wrapper rather than symlinking it due
484 # to some random dirname(argv[0]) magic performed by python-config.
485 cat > "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" <<-EOF || die
486 #!/bin/sh
487 exec "${abiver}-config" "\${@}"
488 EOF
489 # Must strip EPREFIX because fperms prepends ED.
490 fperms 755 "${PYTHON_SCRIPTDIR#$EPREFIX}/python${pymajor}-config"
491 dosym "python${pymajor}-config" \
492 "${PYTHON_SCRIPTDIR}/python-config"
493
494 # python-exec: pydoc, pydocX
495 dosym "../../../bin/pydoc${SLOT}" \
496 "${PYTHON_SCRIPTDIR}/pydoc${pymajor}"
497 dosym "pydoc${pymajor}" "${PYTHON_SCRIPTDIR}/pydoc"
498
499 # python-exec: 2to3
500 dosym "../../../bin/2to3-${SLOT}" \
501 "${PYTHON_SCRIPTDIR}/2to3"
502
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400503 # The sysconfig module will actually read the pyconfig.h at runtime to see what kind
504 # of functionality is enabled in the build. Deploy it behind the back of portage as
505 # need be.
Mike Frysingerd7685db2013-04-06 02:03:53 -0400506 ln "${ED}/usr/include/python${SLOT}/pyconfig.h" "${libdir}/pyconfig_h" || die
507
508 # Workaround https://bugs.gentoo.org/380569
509 keepdir /etc/env.d/python
Mike Frysinger682d0652012-07-30 11:38:25 -0400510}
511
512pkg_preinst() {
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400513 if has_version "<${CATEGORY}/${PN}-${SLOT}" && ! has_version "${CATEGORY}/${PN}:2.7"; then
Mike Frysinger682d0652012-07-30 11:38:25 -0400514 python_updater_warning="1"
515 fi
516}
517
518eselect_python_update() {
Mike Frysinger682d0652012-07-30 11:38:25 -0400519 if [[ -z "$(eselect python show)" || ! -f "${EROOT}usr/bin/$(eselect python show)" ]]; then
520 eselect python update
521 fi
522
523 if [[ -z "$(eselect python show --python${PV%%.*})" || ! -f "${EROOT}usr/bin/$(eselect python show --python${PV%%.*})" ]]; then
524 eselect python update --python${PV%%.*}
525 fi
526}
527
528pkg_postinst() {
529 eselect_python_update
530
Mike Frysinger682d0652012-07-30 11:38:25 -0400531 if [[ "${python_updater_warning}" == "1" ]]; then
532 ewarn "You have just upgraded from an older version of Python."
533 ewarn "You should switch active version of Python ${PV%%.*} and run"
534 ewarn "'python-updater [options]' to rebuild Python modules."
535 fi
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400536
Mike Frysingerd7685db2013-04-06 02:03:53 -0400537 local pyconfig="${EROOT}/usr/$(get_libdir)/python${SLOT}/pyconfig_h"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400538 if [[ ! -e ${EROOT}/usr/include/python${SLOT}/pyconfig.h ]] ; then
539 # See pkg_preinst above for details.
Mike Frysingerd7685db2013-04-06 02:03:53 -0400540 install -D -m644 "${pyconfig}" "${EROOT}/usr/include/python${SLOT}/pyconfig.h" || die
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400541 fi
Mike Frysingerd7685db2013-04-06 02:03:53 -0400542 rm "${pyconfig}" || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400543}
544
545pkg_postrm() {
546 eselect_python_update
Mike Frysinger682d0652012-07-30 11:38:25 -0400547}