blob: d5d1b1cfb18264457cf5023c54cde2049f95879f [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
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +00005# ******************************* README ***************************************
6# WARNING! ANY CHANGE TO THIS FILE *MUST* BE ACCOMPANIED BY A CHANGE TO
7# chromeos-base/dev-install's ebuild, which depends on python indirectly.
8# Otherwise, incremental builds will break. See crbug.com/489895.
9# ******************************************************************************
10
George Burgess IVb2459ff2019-02-05 13:04:40 -080011EAPI="5"
Mike Frysinger682d0652012-07-30 11:38:25 -040012WANT_LIBTOOL="none"
13
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040014inherit autotools eutils flag-o-matic multilib pax-utils python-utils-r1 toolchain-funcs multiprocessing
Mike Frysinger682d0652012-07-30 11:38:25 -040015
16MY_P="Python-${PV}"
Mike Frysinger51f0d522015-11-21 00:11:17 +000017PATCHSET_VERSION="2.7.10-0"
Mike Frysinger682d0652012-07-30 11:38:25 -040018
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040019DESCRIPTION="An interpreted, interactive, object-oriented programming language"
Mike Frysinger682d0652012-07-30 11:38:25 -040020HOMEPAGE="http://www.python.org/"
George Burgess IVb2459ff2019-02-05 13:04:40 -080021
22# The version of Python our PGO profile was generated with. Using ${PV} makes
23# updates difficult, and we have tricks below to catch a mismatched profile
24# version.
25PROF_VERSION="2.7.10"
26
Mike Frysinger51f0d522015-11-21 00:11:17 +000027SRC_URI="http://www.python.org/ftp/python/${PV}/${MY_P}.tar.xz
George Burgess IVb2459ff2019-02-05 13:04:40 -080028 http://dev.gentoo.org/~floppym/python/python-gentoo-patches-${PATCHSET_VERSION}.tar.xz
29 pgo_use? ( gs://chromeos-localmirror/distfiles/python-${PROF_VERSION}-pgo-prof.profdata.tar.xz )"
Mike Frysinger682d0652012-07-30 11:38:25 -040030
31LICENSE="PSF-2"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040032SLOT="2.7"
Mike Frysinger65332152014-02-14 13:55:27 -050033KEYWORDS="*"
George Burgess IVb2459ff2019-02-05 13:04:40 -080034IUSE="-berkdb build doc elibc_uclibc examples gdbm hardened ipv6 pgo_generate +pgo_use +ncurses +readline sqlite +ssl +threads tk +wide-unicode wininst +xml"
35
36REQUIRED_USE="pgo_generate? ( !pgo_use )"
37
38# Workaround: re-emerging this after emerging a `pgo_generate` Python gives us
39# a really bad time, since we'll try to write to profiles in "restricted"
40# places somehow. Specifying this profile file has LLVM write profiles to
41# /dev/null, which is always available.
42export LLVM_PROFILE_FILE="/dev/null"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040043
44# Do not add a dependency on dev-lang/python to this ebuild.
45# If you need to apply a patch which requires python for bootstrapping, please
46# run the bootstrap code on your dev box and include the results in the
47# patchset. See bug 447752.
Mike Frysinger682d0652012-07-30 11:38:25 -040048
49RDEPEND="app-arch/bzip2
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040050 >=sys-libs/zlib-1.1.3
51 virtual/libffi
52 virtual/libintl
53 !build? (
54 berkdb? ( || (
Mike Frysinger51f0d522015-11-21 00:11:17 +000055 sys-libs/db:5.3
56 sys-libs/db:5.2
57 sys-libs/db:5.1
58 sys-libs/db:5.0
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040059 sys-libs/db:4.8
60 sys-libs/db:4.7
61 sys-libs/db:4.6
62 sys-libs/db:4.5
63 sys-libs/db:4.4
64 sys-libs/db:4.3
65 sys-libs/db:4.2
66 ) )
67 gdbm? ( sys-libs/gdbm )
68 ncurses? (
69 >=sys-libs/ncurses-5.2
70 readline? ( >=sys-libs/readline-4.1 )
Mike Frysinger682d0652012-07-30 11:38:25 -040071 )
Ryan Sleevi1a745162014-10-27 18:14:49 -070072 sqlite? ( >=dev-db/sqlite-3.3.8:3 )
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040073 ssl? ( dev-libs/openssl )
74 tk? (
75 >=dev-lang/tk-8.0
76 dev-tcltk/blt
Mike Frysinger51f0d522015-11-21 00:11:17 +000077 dev-tcltk/tix
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040078 )
79 xml? ( >=dev-libs/expat-2.1 )
80 )
81 !!<sys-apps/portage-2.1.9"
Mike Frysinger682d0652012-07-30 11:38:25 -040082DEPEND="${RDEPEND}
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040083 virtual/pkgconfig
84 >=sys-devel/autoconf-2.65
85 !sys-devel/gcc[libffi]"
Mike Frysinger682d0652012-07-30 11:38:25 -040086RDEPEND+=" !build? ( app-misc/mime-types )
87 doc? ( dev-python/python-docs:${SLOT} )"
Daniel Kurtzd47b2922017-07-17 17:47:39 +080088PDEPEND="app-eselect/eselect-python
Mike Frysinger51f0d522015-11-21 00:11:17 +000089 app-admin/python-updater"
Mike Frysinger682d0652012-07-30 11:38:25 -040090
91S="${WORKDIR}/${MY_P}"
92
93pkg_setup() {
Mike Frysinger682d0652012-07-30 11:38:25 -040094 if use berkdb; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040095 ewarn "'bsddb' module is out-of-date and no longer maintained inside"
96 ewarn "dev-lang/python. 'bsddb' and 'dbhash' modules have been additionally"
97 ewarn "removed in Python 3. A maintained alternative of 'bsddb3' module"
98 ewarn "is provided by dev-python/bsddb3."
Mike Frysinger682d0652012-07-30 11:38:25 -040099 else
100 if has_version "=${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400101 ewarn "You are migrating from =${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"
102 ewarn "to =${CATEGORY}/${PN}-${PV%%.*}*[-berkdb]."
Mike Frysinger682d0652012-07-30 11:38:25 -0400103 ewarn "You might need to migrate your databases."
104 fi
105 fi
106}
107
108src_prepare() {
Tim Zwiebelab07eb22017-06-03 03:19:57 -0700109 # According to the comments at the top of cgi.py, Linux vendors need to
110 # patch the shebang in cgi.py. We'll ignore the comment about not using
111 # "/usr/bin/env python" and use it anyway.
112 sed -i -e '1 s:^#!.*$:#! /usr/bin/env python:' Lib/cgi.py || die
113
Mike Frysinger682d0652012-07-30 11:38:25 -0400114 # Ensure that internal copies of expat, libffi and zlib are not used.
Mike Frysinger51f0d522015-11-21 00:11:17 +0000115 rm -r Modules/expat || die
116 rm -r Modules/_ctypes/libffi* || die
117 rm -r Modules/zlib || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400118
Mike Frysinger51f0d522015-11-21 00:11:17 +0000119 if tc-is-cross-compiler; then
120 local EPATCH_EXCLUDE="*_regenerate_platform-specific_modules.patch"
Mike Frysinger682d0652012-07-30 11:38:25 -0400121 fi
122
Mike Frysinger51f0d522015-11-21 00:11:17 +0000123 EPATCH_SUFFIX="patch" epatch "${WORKDIR}/patches"
Mike Frysinger682d0652012-07-30 11:38:25 -0400124
125 #
126 # START: ChromiumOS specific changes
127 #
128 if tc-is-cross-compiler ; then
Mike Frysinger51f0d522015-11-21 00:11:17 +0000129 epatch "${FILESDIR}"/python-2.7.10-cross-h2py.patch
130 epatch "${FILESDIR}"/python-2.7.10-cross-hack-compiler.patch
Mike Frysinger682d0652012-07-30 11:38:25 -0400131 sed -i 's:^python$EXE:${HOSTPYTHON}:' Lib/*/regen || die
132 fi
Mike Frysinger51f0d522015-11-21 00:11:17 +0000133 epatch "${FILESDIR}"/python-2.7.10-cross-setup-sysroot.patch
134 epatch "${FILESDIR}"/python-2.7.10-cross-distutils.patch
Paul Hobbs43d07e62015-05-14 16:43:16 -0700135 epatch "${FILESDIR}"/python-2.7.3-unique-semaphore-name.patch
Mike Frysinger51f0d522015-11-21 00:11:17 +0000136 epatch "${FILESDIR}"/python-2.7.10-ldshared.patch
Manoj Gupta85657702018-11-05 18:26:27 -0800137 epatch "${FILESDIR}"/python-2.7.17-getentropy.patch
Yunlian Jiang871d0072018-07-24 11:11:01 -0700138 epatch "${FILESDIR}"/2.7-disable-nis.patch
Mike Frysingereb047962014-04-06 10:08:56 -0400139 # Undo the @libdir@ change for portage's pym folder as it is always
140 # installed into /usr/lib/ and not the abi libdir.
141 sed -i \
142 -e '/portage.*pym/s:@@GENTOO_LIBDIR@@:lib:g' \
143 Lib/site.py || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400144
145 sed -i -e "s:sys.exec_prefix]:sys.exec_prefix, '/usr/local']:g" \
146 Lib/site.py || die "sed failed to add /usr/local to prefixes"
George Burgess IVb2459ff2019-02-05 13:04:40 -0800147
148 # Enable stealthy profile application; with this, `sysconfig` won't
149 # report on any CFLAGS in EXTRA_CFLAGS
150 epatch "${FILESDIR}"/python-2.7-clear-extra-cflags.patch
Mike Frysinger682d0652012-07-30 11:38:25 -0400151 #
152 # END: ChromiumOS specific changes
153 #
154
Mike Frysinger51f0d522015-11-21 00:11:17 +0000155 # Fix for cross-compiling.
156 epatch "${FILESDIR}/python-2.7.5-nonfatal-compileall.patch"
157 epatch "${FILESDIR}/python-2.7.9-ncurses-pkg-config.patch"
158
Mike Frysinger682d0652012-07-30 11:38:25 -0400159 sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
160 Lib/distutils/command/install.py \
161 Lib/distutils/sysconfig.py \
162 Lib/site.py \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400163 Lib/sysconfig.py \
164 Lib/test/test_site.py \
Mike Frysinger682d0652012-07-30 11:38:25 -0400165 Makefile.pre.in \
166 Modules/Setup.dist \
167 Modules/getpath.c \
168 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
169
Mike Frysinger51f0d522015-11-21 00:11:17 +0000170 epatch_user
171
172 eautoreconf
Mike Frysinger682d0652012-07-30 11:38:25 -0400173}
174
George Burgess IVb2459ff2019-02-05 13:04:40 -0800175# There's a sad story behind this. When we've built our `python` and
176# `libpython.so` objects, we'll go to build all of our Python modules. This is
177# done with LD_LIBRARY_PATH set to our workdir, and is generally
178# well-sandboxed. Sadly, the compiler is a wrapper written in Python and
179# invoked via #!/usr/bin/python2, so **the compiler invocations will link to
180# the new, not-yet-installed libpython.so**.
181#
182# Usually, this isn't much of a problem. However, when we're building Python
183# with instrumentation enabled, libpython.so is where some of the key
184# instrumentation functions end up. Since everything links to libpython.so, and
185# since libpython.so shows up in link lines before libclang_rt.profile (where
186# these "key instrumentation functions" come from), the only binary we built
187# with USE=pgo_generate that has an actual definition for these functions is
188# libpython.so.
189#
190# Hence, the old python invoked by the wrapper looks for its profiling symbols
191# in the *new* libpython.so, doesn't find them, and gets sad.
192#
193# This can all be fixed by moving libclang_rt.profiles up before -lpython2.7 in
194# the commandline, which is easily doable. Doing so puts these profiling
195# symbols in every binary we produce, but only in pgo_generate builds. They're
196# all dynamic symbols, so keeping multiple definitions around should be OK.
197#
198# Clang is good about moving libclangrt_profile around, so we just parse its
199# output to determine where this static lib is located today.
200detect_libprofile_rt_location() {
201 local result
202 # Clang always gives quoted output. We're picking out the single arg
203 # with libclang_rt.profile from it, and discarding the quotes.
204 result=$(echo | \
205 $(tc-getCC) -### -fprofile-generate -x c - |& \
206 grep -oE '"[^"]+libclang_rt.profile[^"]+"' | \
207 tr -d '"')
208 [[ -n "${result}" ]] || die "libclangrt detection failed"
209 echo "${result}"
210}
211
Mike Frysinger682d0652012-07-30 11:38:25 -0400212src_configure() {
213 if use build; then
214 # Disable extraneous modules with extra dependencies.
215 export PYTHON_DISABLE_MODULES="dbm _bsddb gdbm _curses _curses_panel readline _sqlite3 _tkinter _elementtree pyexpat"
216 export PYTHON_DISABLE_SSL="1"
217 else
218 # dbm module can be linked against berkdb or gdbm.
219 # Defaults to gdbm when both are enabled, #204343.
220 local disable
221 use berkdb || use gdbm || disable+=" dbm"
222 use berkdb || disable+=" _bsddb"
223 use gdbm || disable+=" gdbm"
224 use ncurses || disable+=" _curses _curses_panel"
225 use readline || disable+=" readline"
226 use sqlite || disable+=" _sqlite3"
227 use ssl || export PYTHON_DISABLE_SSL="1"
228 use tk || disable+=" _tkinter"
229 use xml || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
230 export PYTHON_DISABLE_MODULES="${disable}"
231
232 if ! use xml; then
233 ewarn "You have configured Python without XML support."
234 ewarn "This is NOT a recommended configuration as you"
235 ewarn "may face problems parsing any XML documents."
236 fi
237 fi
238
239 if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
240 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
241 fi
242
243 if [[ "$(gcc-major-version)" -ge 4 ]]; then
244 append-flags -fwrapv
245 fi
246
247 filter-flags -malign-double
248
249 [[ "${ARCH}" == "alpha" ]] && append-flags -fPIC
250
251 # https://bugs.gentoo.org/show_bug.cgi?id=50309
252 if is-flagq -O3; then
253 is-flagq -fstack-protector-all && replace-flags -O3 -O2
254 use hardened && replace-flags -O3 -O2
255 fi
256
Mike Frysinger682d0652012-07-30 11:38:25 -0400257 if tc-is-cross-compiler; then
Mike Frysinger51f0d522015-11-21 00:11:17 +0000258 # Force some tests that try to poke fs paths.
259 export ac_cv_file__dev_ptc=no
260 export ac_cv_file__dev_ptmx=yes
Mike Frysinger682d0652012-07-30 11:38:25 -0400261 fi
262
263 # Export CXX so it ends up in /usr/lib/python2.X/config/Makefile.
264 tc-export CXX
265 # The configure script fails to use pkg-config correctly.
266 # http://bugs.python.org/issue15506
267 export ac_cv_path_PKG_CONFIG=$(tc-getPKG_CONFIG)
268
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400269 # Set LDFLAGS so we link modules with -lpython2.7 correctly.
270 # Needed on FreeBSD unless Python 2.7 is already installed.
Mike Frysinger682d0652012-07-30 11:38:25 -0400271 # Please query BSD team before removing this!
272 append-ldflags "-L."
273
George Burgess IVb2459ff2019-02-05 13:04:40 -0800274 tc-export CC
275 if use pgo_generate; then
276 tc-is-clang || die "Instrumentation is only supported when using clang"
277 # tc_extra_flags is an invention used to make cflags apply
278 # equally to Python's C modules and Python itself. This also
279 # prevents duplication between CFLAGS and LDFLAGS, which is a
280 # build error with -mllvm -options.
281 #
282 # This is a functional change in Python that breaks subversion
283 # (SWIG Python bindings rely on distutils.sysconfigs' ${CC}),
284 # so you should consider re-emerge'ing before trying to emerge
285 # anything else.
286 #
287 # We explicitly use /tmp here because this path is *baked into
288 # Python* as the place where profiles should go when Python is
289 # run. Hence, it has to be a well-known place that lives after
290 # `emerge`.
291 CC+=" -fprofile-generate=/tmp/python_profiles"
292
293 # LLVM intentionally low-balls vp-counters-per-site to save some
294 # binary size. If left to its default of 1, we get a diagnostic
295 # asking for it to be raised. Instead of tweaking it and having
296 # the issue silently appear again in the future, force dynamic
297 # allocation of counters. It's marginally slower, but less
298 # error-prone.
299 CC+=" -mllvm -vp-static-alloc=false"
300
301 append-ldflags "$(detect_libprofile_rt_location)"
302 fi
303
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400304 local dbmliborder
305 if use gdbm; then
306 dbmliborder+="${dbmliborder:+:}gdbm"
307 fi
308 if use berkdb; then
309 dbmliborder+="${dbmliborder:+:}bdb"
310 fi
311
Mike Frysinger51f0d522015-11-21 00:11:17 +0000312 BUILD_DIR="${WORKDIR}/${CHOST}"
313 mkdir -p "${BUILD_DIR}" || die
314 cd "${BUILD_DIR}" || die
315
316 ECONF_SOURCE="${S}" OPT="" \
Mike Frysinger682d0652012-07-30 11:38:25 -0400317 econf \
318 --with-fpectl \
319 --enable-shared \
320 $(use_enable ipv6) \
321 $(use_with threads) \
322 $(use wide-unicode && echo "--enable-unicode=ucs4" || echo "--enable-unicode=ucs2") \
323 --infodir='${prefix}/share/info' \
324 --mandir='${prefix}/share/man' \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400325 --with-dbmliborder="${dbmliborder}" \
Mike Frysinger682d0652012-07-30 11:38:25 -0400326 --with-libc="" \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400327 --enable-loadable-sqlite-extensions \
328 --with-system-expat \
Mike Frysinger51f0d522015-11-21 00:11:17 +0000329 --with-system-ffi \
330 --without-ensurepip
Mike Frysinger682d0652012-07-30 11:38:25 -0400331
Mike Frysinger51f0d522015-11-21 00:11:17 +0000332 if use threads && grep -q "#define POSIX_SEMAPHORES_NOT_ENABLED 1" pyconfig.h; then
333 eerror "configure has detected that the sem_open function is broken."
334 eerror "Please ensure that /dev/shm is mounted as a tmpfs with mode 1777."
335 die "Broken sem_open function (bug 496328)"
Mike Frysinger682d0652012-07-30 11:38:25 -0400336 fi
Mike Frysinger682d0652012-07-30 11:38:25 -0400337}
338
339src_compile() {
Mike Frysinger51f0d522015-11-21 00:11:17 +0000340 # Avoid invoking pgen for cross-compiles.
341 touch Include/graminit.h Python/graminit.c
342
George Burgess IVb2459ff2019-02-05 13:04:40 -0800343 # CFLAGS specified in configure get baked into the `sysconfig` module,
344 # which is consulted when building e.g. SWIG bindings for subversion.
345 # OPT, which we wiped out during configuration time anyway, allows us
346 # to pass flags that `sysconfig` doesn't see.
347 local extra_cflags=()
348 if use pgo_use && tc-is-clang; then
349 # If you're upgrading Python, please also run
350 # ./files/python2_gen_pgo.sh to build a new PGO profile.
351 if [[ "${PV}" != "${PROF_VERSION}" ]]; then
352 die "Please generate a new profile. Details in comments."
353 fi
354
355 extra_cflags=(
356 "-fprofile-use=${WORKDIR}/python-${PROF_VERSION}-pgo-prof.profdata"
357 "-Wno-backend-plugin"
358 )
359
360 # LTO only buys us ~2%, it increases binary size around 750KB,
361 # and it's entirely broken on aarch64 (LTO prompts clang to use
362 # its built-in assembler, which has issues with inline assembly
363 # in Python, apparently.)
364 fi
365
Mike Frysinger51f0d522015-11-21 00:11:17 +0000366 cd "${BUILD_DIR}" || die
George Burgess IVb2459ff2019-02-05 13:04:40 -0800367 EXTRA_CFLAGS="${extra_cflags[*]}" emake
Mike Frysinger51f0d522015-11-21 00:11:17 +0000368
369 # Work around bug 329499. See also bug 413751 and 457194.
370 if has_version dev-libs/libffi[pax_kernel]; then
371 pax-mark E python
372 else
373 pax-mark m python
Mike Frysinger682d0652012-07-30 11:38:25 -0400374 fi
Mike Frysinger682d0652012-07-30 11:38:25 -0400375}
376
377src_test() {
378 # Tests will not work when cross compiling.
379 if tc-is-cross-compiler; then
380 elog "Disabling tests due to crosscompiling."
381 return
382 fi
383
Mike Frysinger51f0d522015-11-21 00:11:17 +0000384 cd "${BUILD_DIR}" || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400385
Mike Frysinger682d0652012-07-30 11:38:25 -0400386 # Skip failing tests.
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400387 local skipped_tests="distutils gdb"
Mike Frysinger682d0652012-07-30 11:38:25 -0400388
389 for test in ${skipped_tests}; do
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400390 mv "${S}"/Lib/test/test_${test}.py "${T}"
Mike Frysinger682d0652012-07-30 11:38:25 -0400391 done
392
393 # Rerun failed tests in verbose mode (regrtest -w).
394 emake test EXTRATESTOPTS="-w" < /dev/tty
395 local result="$?"
396
397 for test in ${skipped_tests}; do
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400398 mv "${T}/test_${test}.py" "${S}"/Lib/test
Mike Frysinger682d0652012-07-30 11:38:25 -0400399 done
400
401 elog "The following tests have been skipped:"
402 for test in ${skipped_tests}; do
403 elog "test_${test}.py"
404 done
405
406 elog "If you would like to run them, you may:"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400407 elog "cd '${EPREFIX}/usr/$(get_libdir)/python${SLOT}/test'"
Mike Frysinger682d0652012-07-30 11:38:25 -0400408 elog "and run the tests separately."
409
410 python_disable_pyc
411
412 if [[ "${result}" -ne 0 ]]; then
413 die "emake test failed"
414 fi
415}
416
417src_install() {
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400418 local libdir=${ED}/usr/$(get_libdir)/python${SLOT}
419
Mike Frysinger51f0d522015-11-21 00:11:17 +0000420 cd "${BUILD_DIR}" || die
421 emake DESTDIR="${D}" altinstall
Mike Frysinger682d0652012-07-30 11:38:25 -0400422
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400423 sed -e "s/\(LDFLAGS=\).*/\1/" -i "${libdir}/config/Makefile" || die "sed failed"
424
425 # Backwards compat with Gentoo divergence.
Mike Frysinger51f0d522015-11-21 00:11:17 +0000426 dosym python${SLOT}-config /usr/bin/python-config-${SLOT}
Mike Frysinger682d0652012-07-30 11:38:25 -0400427
428 # Fix collisions between different slots of Python.
429 mv "${ED}usr/bin/2to3" "${ED}usr/bin/2to3-${SLOT}"
430 mv "${ED}usr/bin/pydoc" "${ED}usr/bin/pydoc${SLOT}"
431 mv "${ED}usr/bin/idle" "${ED}usr/bin/idle${SLOT}"
Mike Frysinger682d0652012-07-30 11:38:25 -0400432 rm -f "${ED}usr/bin/smtpd.py"
433
Chad Versace016e8732018-10-26 12:55:13 -0700434 local abiver="python2.7"
435
Mike Frysinger682d0652012-07-30 11:38:25 -0400436 if use build; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400437 rm -fr "${ED}usr/bin/idle${SLOT}" "${libdir}/"{bsddb,dbhash.py,idlelib,lib-tk,sqlite3,test}
Mike Frysinger682d0652012-07-30 11:38:25 -0400438 else
Mike Frysinger51f0d522015-11-21 00:11:17 +0000439 use berkdb || rm -r "${libdir}/"{bsddb,dbhash.py,test/test_bsddb*} || die
440 use sqlite || rm -r "${libdir}/"{sqlite3,test/test_sqlite*} || die
441 use tk || rm -r "${ED}usr/bin/idle${SLOT}" "${libdir}/"{idlelib,lib-tk} || die
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400442 use elibc_uclibc && rm -fr "${libdir}/"{bsddb/test,test}
Mike Frysinger682d0652012-07-30 11:38:25 -0400443 fi
444
Mike Frysinger51f0d522015-11-21 00:11:17 +0000445 use threads || rm -r "${libdir}/multiprocessing" || die
446 use wininst || rm -r "${libdir}/distutils/command/"wininst-*.exe || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400447
Mike Frysinger51f0d522015-11-21 00:11:17 +0000448 dodoc "${S}"/Misc/{ACKS,HISTORY,NEWS}
Mike Frysinger682d0652012-07-30 11:38:25 -0400449
450 if use examples; then
451 insinto /usr/share/doc/${PF}/examples
Mike Frysinger51f0d522015-11-21 00:11:17 +0000452 doins -r "${S}"/Tools
Mike Frysinger682d0652012-07-30 11:38:25 -0400453 fi
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400454 insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
455 local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \
456 emake --no-print-directory -s -f - 2>/dev/null)
457 newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py
Mike Frysinger682d0652012-07-30 11:38:25 -0400458
Mike Frysinger51f0d522015-11-21 00:11:17 +0000459 newconfd "${FILESDIR}/pydoc.conf" pydoc-${SLOT}
460 newinitd "${FILESDIR}/pydoc.init" pydoc-${SLOT}
Mike Frysinger682d0652012-07-30 11:38:25 -0400461 sed \
462 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${SLOT/./_}_PORT:" \
463 -e "s:@PYDOC@:pydoc${SLOT}:" \
464 -i "${ED}etc/conf.d/pydoc-${SLOT}" "${ED}etc/init.d/pydoc-${SLOT}" || die "sed failed"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400465
466 # for python-exec
Chad Versace016e8732018-10-26 12:55:13 -0700467 python_export python${SLOT} EPYTHON PYTHON PYTHON_SITEDIR PYTHON_SCRIPTDIR
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400468
469 # if not using a cross-compiler, use the fresh binary
470 if ! tc-is-cross-compiler; then
Mike Frysinger51f0d522015-11-21 00:11:17 +0000471 local PYTHON=./python
472 local -x LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}.
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400473 fi
474
475 echo "EPYTHON='${EPYTHON}'" > epython.py
476 python_domodule epython.py
477
Chad Versace016e8732018-10-26 12:55:13 -0700478 # python-exec wrapping support
479 local pymajor=${SLOT%.*}
480 mkdir -p "${D}${PYTHON_SCRIPTDIR}" || die
481
482 # python-exec: python, pythonX
483 dosym "../../../bin/${abiver}" \
484 "${PYTHON_SCRIPTDIR}/python${pymajor}"
485 dosym "python${pymajor}" "${PYTHON_SCRIPTDIR}/python"
486
487 # python-exec: python-config, python-configX
488 #
489 # Note: we need to create a wrapper rather than symlinking it due
490 # to some random dirname(argv[0]) magic performed by python-config.
491 cat > "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" <<-EOF || die
492 #!/bin/sh
493 exec "${abiver}-config" "\${@}"
494 EOF
495 # Must strip EPREFIX because fperms prepends ED.
496 fperms 755 "${PYTHON_SCRIPTDIR#$EPREFIX}/python${pymajor}-config"
497 dosym "python${pymajor}-config" \
498 "${PYTHON_SCRIPTDIR}/python-config"
499
500 # python-exec: pydoc, pydocX
501 dosym "../../../bin/pydoc${SLOT}" \
502 "${PYTHON_SCRIPTDIR}/pydoc${pymajor}"
503 dosym "pydoc${pymajor}" "${PYTHON_SCRIPTDIR}/pydoc"
504
505 # python-exec: 2to3
506 dosym "../../../bin/2to3-${SLOT}" \
507 "${PYTHON_SCRIPTDIR}/2to3"
508
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400509 # The sysconfig module will actually read the pyconfig.h at runtime to see what kind
510 # of functionality is enabled in the build. Deploy it behind the back of portage as
511 # need be.
Mike Frysingerd7685db2013-04-06 02:03:53 -0400512 ln "${ED}/usr/include/python${SLOT}/pyconfig.h" "${libdir}/pyconfig_h" || die
513
514 # Workaround https://bugs.gentoo.org/380569
515 keepdir /etc/env.d/python
Mike Frysinger682d0652012-07-30 11:38:25 -0400516}
517
518pkg_preinst() {
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400519 if has_version "<${CATEGORY}/${PN}-${SLOT}" && ! has_version "${CATEGORY}/${PN}:2.7"; then
Mike Frysinger682d0652012-07-30 11:38:25 -0400520 python_updater_warning="1"
521 fi
522}
523
524eselect_python_update() {
Mike Frysinger682d0652012-07-30 11:38:25 -0400525 if [[ -z "$(eselect python show)" || ! -f "${EROOT}usr/bin/$(eselect python show)" ]]; then
526 eselect python update
527 fi
528
529 if [[ -z "$(eselect python show --python${PV%%.*})" || ! -f "${EROOT}usr/bin/$(eselect python show --python${PV%%.*})" ]]; then
530 eselect python update --python${PV%%.*}
531 fi
532}
533
534pkg_postinst() {
535 eselect_python_update
536
Mike Frysinger682d0652012-07-30 11:38:25 -0400537 if [[ "${python_updater_warning}" == "1" ]]; then
538 ewarn "You have just upgraded from an older version of Python."
539 ewarn "You should switch active version of Python ${PV%%.*} and run"
540 ewarn "'python-updater [options]' to rebuild Python modules."
541 fi
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400542
Mike Frysingerd7685db2013-04-06 02:03:53 -0400543 local pyconfig="${EROOT}/usr/$(get_libdir)/python${SLOT}/pyconfig_h"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400544 if [[ ! -e ${EROOT}/usr/include/python${SLOT}/pyconfig.h ]] ; then
545 # See pkg_preinst above for details.
Mike Frysingerd7685db2013-04-06 02:03:53 -0400546 install -D -m644 "${pyconfig}" "${EROOT}/usr/include/python${SLOT}/pyconfig.h" || die
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400547 fi
Mike Frysingerd7685db2013-04-06 02:03:53 -0400548 rm "${pyconfig}" || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400549}
550
551pkg_postrm() {
552 eselect_python_update
Mike Frysinger682d0652012-07-30 11:38:25 -0400553}