blob: 85d5f752a1ca29bde0e183389f1cf8e57d1cb84f [file] [log] [blame]
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +00001# Copyright 1999-2012 Gentoo Foundation
Mike Frysinger682d0652012-07-30 11:38:25 -04002# Distributed under the terms of the GNU General Public License v2
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +00003# $Header: /var/cvsroot/gentoo-x86/dev-lang/python/python-2.7.3-r3.ebuild,v 1.5 2012/12/19 18:03:41 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
11EAPI="2"
12WANT_AUTOMAKE="none"
Mike Frysinger682d0652012-07-30 11:38:25 -040013WANT_LIBTOOL="none"
14
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040015inherit autotools eutils flag-o-matic multilib pax-utils python-utils-r1 toolchain-funcs multiprocessing
Mike Frysinger682d0652012-07-30 11:38:25 -040016
17MY_P="Python-${PV}"
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +000018PATCHSET_REVISION="1"
Mike Frysinger682d0652012-07-30 11:38:25 -040019
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040020DESCRIPTION="An interpreted, interactive, object-oriented programming language"
Mike Frysinger682d0652012-07-30 11:38:25 -040021HOMEPAGE="http://www.python.org/"
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +000022SRC_URI="http://www.python.org/ftp/python/${PV}/${MY_P}.tar.bz2
23 mirror://gentoo/python-gentoo-patches-${PV}-${PATCHSET_REVISION}.tar.bz2"
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="*"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040028IUSE="-berkdb build doc elibc_uclibc examples gdbm hardened ipv6 +ncurses +readline sqlite +ssl +threads tk +wide-unicode wininst +xml"
29
30# Do not add a dependency on dev-lang/python to this ebuild.
31# If you need to apply a patch which requires python for bootstrapping, please
32# run the bootstrap code on your dev box and include the results in the
33# patchset. See bug 447752.
Mike Frysinger682d0652012-07-30 11:38:25 -040034
35RDEPEND="app-arch/bzip2
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040036 >=sys-libs/zlib-1.1.3
37 virtual/libffi
38 virtual/libintl
39 !build? (
40 berkdb? ( || (
41 sys-libs/db:4.8
42 sys-libs/db:4.7
43 sys-libs/db:4.6
44 sys-libs/db:4.5
45 sys-libs/db:4.4
46 sys-libs/db:4.3
47 sys-libs/db:4.2
48 ) )
49 gdbm? ( sys-libs/gdbm )
50 ncurses? (
51 >=sys-libs/ncurses-5.2
52 readline? ( >=sys-libs/readline-4.1 )
Mike Frysinger682d0652012-07-30 11:38:25 -040053 )
Ryan Sleevi1a745162014-10-27 18:14:49 -070054 sqlite? ( >=dev-db/sqlite-3.3.8:3 )
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040055 ssl? ( dev-libs/openssl )
56 tk? (
57 >=dev-lang/tk-8.0
58 dev-tcltk/blt
59 )
60 xml? ( >=dev-libs/expat-2.1 )
61 )
62 !!<sys-apps/portage-2.1.9"
Mike Frysinger682d0652012-07-30 11:38:25 -040063DEPEND="${RDEPEND}
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040064 virtual/pkgconfig
65 >=sys-devel/autoconf-2.65
66 !sys-devel/gcc[libffi]"
Mike Frysinger682d0652012-07-30 11:38:25 -040067RDEPEND+=" !build? ( app-misc/mime-types )
68 doc? ( dev-python/python-docs:${SLOT} )"
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +000069PDEPEND="app-admin/eselect-python"
Mike Frysinger682d0652012-07-30 11:38:25 -040070
71S="${WORKDIR}/${MY_P}"
72
73pkg_setup() {
Mike Frysinger682d0652012-07-30 11:38:25 -040074 if use berkdb; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040075 ewarn "'bsddb' module is out-of-date and no longer maintained inside"
76 ewarn "dev-lang/python. 'bsddb' and 'dbhash' modules have been additionally"
77 ewarn "removed in Python 3. A maintained alternative of 'bsddb3' module"
78 ewarn "is provided by dev-python/bsddb3."
Mike Frysinger682d0652012-07-30 11:38:25 -040079 else
80 if has_version "=${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040081 ewarn "You are migrating from =${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"
82 ewarn "to =${CATEGORY}/${PN}-${PV%%.*}*[-berkdb]."
Mike Frysinger682d0652012-07-30 11:38:25 -040083 ewarn "You might need to migrate your databases."
84 fi
85 fi
86}
87
88src_prepare() {
89 # Ensure that internal copies of expat, libffi and zlib are not used.
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +000090 rm -fr Modules/expat
91 rm -fr Modules/_ctypes/libffi*
92 rm -fr Modules/zlib
Mike Frysinger682d0652012-07-30 11:38:25 -040093
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +000094 local excluded_patches
95 if ! tc-is-cross-compiler; then
96 excluded_patches="*_all_crosscompile.patch"
Mike Frysinger682d0652012-07-30 11:38:25 -040097 fi
98
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +000099 EPATCH_EXCLUDE="${excluded_patches}" EPATCH_SUFFIX="patch" \
100 epatch "${WORKDIR}/${PV}-${PATCHSET_REVISION}"
Mike Frysinger682d0652012-07-30 11:38:25 -0400101
102 #
103 # START: ChromiumOS specific changes
104 #
105 if tc-is-cross-compiler ; then
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000106 epatch "${FILESDIR}"/python-2.7.3-cross-setup-sysroot.patch
107 epatch "${FILESDIR}"/python-2.7.3-cross-h2py.patch
108 epatch "${FILESDIR}"/python-2.7.3-cross-install-compile.patch
109 epatch "${FILESDIR}"/python-2.7.3-gcc-4_8.patch
Mike Frysinger682d0652012-07-30 11:38:25 -0400110 sed -i 's:^python$EXE:${HOSTPYTHON}:' Lib/*/regen || die
111 fi
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000112 epatch "${FILESDIR}"/python-2.7.3-cross-distutils.patch
Paul Hobbs43d07e62015-05-14 16:43:16 -0700113 epatch "${FILESDIR}"/python-2.7.3-unique-semaphore-name.patch
Mike Frysingereb047962014-04-06 10:08:56 -0400114 # Undo the @libdir@ change for portage's pym folder as it is always
115 # installed into /usr/lib/ and not the abi libdir.
116 sed -i \
117 -e '/portage.*pym/s:@@GENTOO_LIBDIR@@:lib:g' \
118 Lib/site.py || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400119
120 sed -i -e "s:sys.exec_prefix]:sys.exec_prefix, '/usr/local']:g" \
121 Lib/site.py || die "sed failed to add /usr/local to prefixes"
122 #
123 # END: ChromiumOS specific changes
124 #
125
126 sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
127 Lib/distutils/command/install.py \
128 Lib/distutils/sysconfig.py \
129 Lib/site.py \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400130 Lib/sysconfig.py \
131 Lib/test/test_site.py \
Mike Frysinger682d0652012-07-30 11:38:25 -0400132 Makefile.pre.in \
133 Modules/Setup.dist \
134 Modules/getpath.c \
135 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
136
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000137 eautoconf
138 eautoheader
Mike Frysinger682d0652012-07-30 11:38:25 -0400139}
140
141src_configure() {
142 if use build; then
143 # Disable extraneous modules with extra dependencies.
144 export PYTHON_DISABLE_MODULES="dbm _bsddb gdbm _curses _curses_panel readline _sqlite3 _tkinter _elementtree pyexpat"
145 export PYTHON_DISABLE_SSL="1"
146 else
147 # dbm module can be linked against berkdb or gdbm.
148 # Defaults to gdbm when both are enabled, #204343.
149 local disable
150 use berkdb || use gdbm || disable+=" dbm"
151 use berkdb || disable+=" _bsddb"
152 use gdbm || disable+=" gdbm"
153 use ncurses || disable+=" _curses _curses_panel"
154 use readline || disable+=" readline"
155 use sqlite || disable+=" _sqlite3"
156 use ssl || export PYTHON_DISABLE_SSL="1"
157 use tk || disable+=" _tkinter"
158 use xml || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
159 export PYTHON_DISABLE_MODULES="${disable}"
160
161 if ! use xml; then
162 ewarn "You have configured Python without XML support."
163 ewarn "This is NOT a recommended configuration as you"
164 ewarn "may face problems parsing any XML documents."
165 fi
166 fi
167
168 if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
169 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
170 fi
171
172 if [[ "$(gcc-major-version)" -ge 4 ]]; then
173 append-flags -fwrapv
174 fi
175
176 filter-flags -malign-double
177
178 [[ "${ARCH}" == "alpha" ]] && append-flags -fPIC
179
180 # https://bugs.gentoo.org/show_bug.cgi?id=50309
181 if is-flagq -O3; then
182 is-flagq -fstack-protector-all && replace-flags -O3 -O2
183 use hardened && replace-flags -O3 -O2
184 fi
185
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000186 # Run the configure scripts in parallel.
187 multijob_init
188
189 mkdir -p "${WORKDIR}"/{${CBUILD},${CHOST}}
190
Mike Frysinger682d0652012-07-30 11:38:25 -0400191 if tc-is-cross-compiler; then
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000192 (
193 multijob_child_init
194 cd "${WORKDIR}"/${CBUILD} >/dev/null
195 OPT="-O1" CFLAGS="" CPPFLAGS="" LDFLAGS="" CC="" \
196 "${S}"/configure \
197 --{build,host}=${CBUILD} \
198 || die "cross-configure failed"
199 ) &
200 multijob_post_fork
201
202 # The configure script assumes it's buggy when cross-compiling.
203 export ac_cv_buggy_getaddrinfo=no
204 export ac_cv_have_long_long_format=yes
Mike Frysinger682d0652012-07-30 11:38:25 -0400205 fi
206
207 # Export CXX so it ends up in /usr/lib/python2.X/config/Makefile.
208 tc-export CXX
209 # The configure script fails to use pkg-config correctly.
210 # http://bugs.python.org/issue15506
211 export ac_cv_path_PKG_CONFIG=$(tc-getPKG_CONFIG)
212
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400213 # Set LDFLAGS so we link modules with -lpython2.7 correctly.
214 # Needed on FreeBSD unless Python 2.7 is already installed.
Mike Frysinger682d0652012-07-30 11:38:25 -0400215 # Please query BSD team before removing this!
216 append-ldflags "-L."
217
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400218 local dbmliborder
219 if use gdbm; then
220 dbmliborder+="${dbmliborder:+:}gdbm"
221 fi
222 if use berkdb; then
223 dbmliborder+="${dbmliborder:+:}bdb"
224 fi
225
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000226 cd "${WORKDIR}"/${CHOST}
227 ECONF_SOURCE=${S} OPT="" \
Mike Frysinger682d0652012-07-30 11:38:25 -0400228 econf \
229 --with-fpectl \
230 --enable-shared \
231 $(use_enable ipv6) \
232 $(use_with threads) \
233 $(use wide-unicode && echo "--enable-unicode=ucs4" || echo "--enable-unicode=ucs2") \
234 --infodir='${prefix}/share/info' \
235 --mandir='${prefix}/share/man' \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400236 --with-dbmliborder="${dbmliborder}" \
Mike Frysinger682d0652012-07-30 11:38:25 -0400237 --with-libc="" \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400238 --enable-loadable-sqlite-extensions \
239 --with-system-expat \
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000240 --with-system-ffi
Mike Frysinger682d0652012-07-30 11:38:25 -0400241
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000242 if tc-is-cross-compiler; then
243 # Modify the Makefile.pre so we don't regen for the host/ one.
244 # We need to link the host python programs into $PWD and run
245 # them from here because the distutils sysconfig module will
246 # parse Makefile/etc... from argv[0], and we need it to pick
247 # up the target settings, not the host ones.
248 sed -i \
249 -e '1iHOSTPYTHONPATH = ./hostpythonpath:' \
250 -e '/^HOSTPYTHON/s:=.*:= ./hostpython:' \
251 -e '/^HOSTPGEN/s:=.*:= ./Parser/hostpgen:' \
252 Makefile{.pre,} || die "sed failed"
Mike Frysinger682d0652012-07-30 11:38:25 -0400253 fi
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000254
255 multijob_finish
Mike Frysinger682d0652012-07-30 11:38:25 -0400256}
257
258src_compile() {
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000259 if tc-is-cross-compiler; then
260 cd "${WORKDIR}"/${CBUILD}
261 # Disable as many modules as possible -- but we need a few to install.
262 PYTHON_DISABLE_MODULES=$(
263 sed -n "/Extension('/{s:^.*Extension('::;s:'.*::;p}" "${S}"/setup.py | \
264 egrep -v '(unicodedata|time|cStringIO|_struct|binascii)'
265 ) \
266 PTHON_DISABLE_SSL="1" \
267 SYSROOT= \
268 emake || die "cross-make failed"
269 [[ -e build/lib.linux-x86_64-${SLOT}/unicodedata.so ]] || die
270 # See comment in src_configure about these.
271 ln python ../${CHOST}/hostpython || die
272 ln Parser/pgen ../${CHOST}/Parser/hostpgen || die
273 ln -s ../${CBUILD}/build/lib.*/ ../${CHOST}/hostpythonpath || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400274 fi
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000275
276 cd "${WORKDIR}"/${CHOST}
277 default
278
279 # Work around bug 329499. See also bug 413751.
280 pax-mark m python
Mike Frysinger682d0652012-07-30 11:38:25 -0400281}
282
283src_test() {
284 # Tests will not work when cross compiling.
285 if tc-is-cross-compiler; then
286 elog "Disabling tests due to crosscompiling."
287 return
288 fi
289
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000290 cd "${WORKDIR}"/${CHOST}
Mike Frysinger682d0652012-07-30 11:38:25 -0400291
Mike Frysinger682d0652012-07-30 11:38:25 -0400292 # Skip failing tests.
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400293 local skipped_tests="distutils gdb"
Mike Frysinger682d0652012-07-30 11:38:25 -0400294
295 for test in ${skipped_tests}; do
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400296 mv "${S}"/Lib/test/test_${test}.py "${T}"
Mike Frysinger682d0652012-07-30 11:38:25 -0400297 done
298
299 # Rerun failed tests in verbose mode (regrtest -w).
300 emake test EXTRATESTOPTS="-w" < /dev/tty
301 local result="$?"
302
303 for test in ${skipped_tests}; do
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400304 mv "${T}/test_${test}.py" "${S}"/Lib/test
Mike Frysinger682d0652012-07-30 11:38:25 -0400305 done
306
307 elog "The following tests have been skipped:"
308 for test in ${skipped_tests}; do
309 elog "test_${test}.py"
310 done
311
312 elog "If you would like to run them, you may:"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400313 elog "cd '${EPREFIX}/usr/$(get_libdir)/python${SLOT}/test'"
Mike Frysinger682d0652012-07-30 11:38:25 -0400314 elog "and run the tests separately."
315
316 python_disable_pyc
317
318 if [[ "${result}" -ne 0 ]]; then
319 die "emake test failed"
320 fi
321}
322
323src_install() {
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000324 [[ -z "${ED}" ]] && ED="${D%/}${EPREFIX}/"
325
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400326 local libdir=${ED}/usr/$(get_libdir)/python${SLOT}
327
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000328 cd "${WORKDIR}"/${CHOST}
329 emake DESTDIR="${D}" altinstall maninstall || die "emake altinstall maninstall failed"
Mike Frysinger682d0652012-07-30 11:38:25 -0400330
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400331 sed -e "s/\(LDFLAGS=\).*/\1/" -i "${libdir}/config/Makefile" || die "sed failed"
332
333 # Backwards compat with Gentoo divergence.
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000334 dosym python${SLOT}-config /usr/bin/python-config-${SLOT} || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400335
336 # Fix collisions between different slots of Python.
337 mv "${ED}usr/bin/2to3" "${ED}usr/bin/2to3-${SLOT}"
338 mv "${ED}usr/bin/pydoc" "${ED}usr/bin/pydoc${SLOT}"
339 mv "${ED}usr/bin/idle" "${ED}usr/bin/idle${SLOT}"
Mike Frysinger682d0652012-07-30 11:38:25 -0400340 rm -f "${ED}usr/bin/smtpd.py"
341
342 if use build; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400343 rm -fr "${ED}usr/bin/idle${SLOT}" "${libdir}/"{bsddb,dbhash.py,idlelib,lib-tk,sqlite3,test}
Mike Frysinger682d0652012-07-30 11:38:25 -0400344 else
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400345 use elibc_uclibc && rm -fr "${libdir}/"{bsddb/test,test}
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000346 use berkdb || rm -fr "${libdir}/"{bsddb,dbhash.py,test/test_bsddb*}
347 use sqlite || rm -fr "${libdir}/"{sqlite3,test/test_sqlite*}
348 use tk || rm -fr "${ED}usr/bin/idle${SLOT}" "${libdir}/"{idlelib,lib-tk}
Mike Frysinger682d0652012-07-30 11:38:25 -0400349 fi
350
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000351 use threads || rm -fr "${libdir}/multiprocessing"
352 use wininst || rm -f "${libdir})/distutils/command/"wininst-*.exe
Mike Frysinger682d0652012-07-30 11:38:25 -0400353
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000354 dodoc "${S}"/Misc/{ACKS,HISTORY,NEWS} || die "dodoc failed"
Mike Frysinger682d0652012-07-30 11:38:25 -0400355
356 if use examples; then
357 insinto /usr/share/doc/${PF}/examples
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000358 doins -r "${S}"/Tools || die "doins failed"
Mike Frysinger682d0652012-07-30 11:38:25 -0400359 fi
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400360 insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
361 local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \
362 emake --no-print-directory -s -f - 2>/dev/null)
363 newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py
Mike Frysinger682d0652012-07-30 11:38:25 -0400364
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000365 newconfd "${FILESDIR}/pydoc.conf" pydoc-${SLOT} || die "newconfd failed"
366 newinitd "${FILESDIR}/pydoc.init" pydoc-${SLOT} || die "newinitd failed"
Mike Frysinger682d0652012-07-30 11:38:25 -0400367 sed \
368 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${SLOT/./_}_PORT:" \
369 -e "s:@PYDOC@:pydoc${SLOT}:" \
370 -i "${ED}etc/conf.d/pydoc-${SLOT}" "${ED}etc/init.d/pydoc-${SLOT}" || die "sed failed"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400371
372 # for python-exec
373 python_export python${SLOT} EPYTHON PYTHON PYTHON_SITEDIR
374
375 # if not using a cross-compiler, use the fresh binary
376 if ! tc-is-cross-compiler; then
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000377 local PYTHON=./python \
378 LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}.
379 export LD_LIBRARY_PATH
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400380 fi
381
382 echo "EPYTHON='${EPYTHON}'" > epython.py
383 python_domodule epython.py
384
385 # The sysconfig module will actually read the pyconfig.h at runtime to see what kind
386 # of functionality is enabled in the build. Deploy it behind the back of portage as
387 # need be.
Mike Frysingerd7685db2013-04-06 02:03:53 -0400388 ln "${ED}/usr/include/python${SLOT}/pyconfig.h" "${libdir}/pyconfig_h" || die
389
390 # Workaround https://bugs.gentoo.org/380569
391 keepdir /etc/env.d/python
Mike Frysinger682d0652012-07-30 11:38:25 -0400392}
393
394pkg_preinst() {
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400395 if has_version "<${CATEGORY}/${PN}-${SLOT}" && ! has_version "${CATEGORY}/${PN}:2.7"; then
Mike Frysinger682d0652012-07-30 11:38:25 -0400396 python_updater_warning="1"
397 fi
398}
399
400eselect_python_update() {
Cheng-Yi Chiangb88f6962015-08-06 13:49:23 +0000401 [[ -z "${EROOT}" || (! -d "${EROOT}" && -d "${ROOT}") ]] && EROOT="${ROOT%/}${EPREFIX}/"
402
Mike Frysinger682d0652012-07-30 11:38:25 -0400403 if [[ -z "$(eselect python show)" || ! -f "${EROOT}usr/bin/$(eselect python show)" ]]; then
404 eselect python update
405 fi
406
407 if [[ -z "$(eselect python show --python${PV%%.*})" || ! -f "${EROOT}usr/bin/$(eselect python show --python${PV%%.*})" ]]; then
408 eselect python update --python${PV%%.*}
409 fi
410}
411
412pkg_postinst() {
413 eselect_python_update
414
Mike Frysinger682d0652012-07-30 11:38:25 -0400415 if [[ "${python_updater_warning}" == "1" ]]; then
416 ewarn "You have just upgraded from an older version of Python."
417 ewarn "You should switch active version of Python ${PV%%.*} and run"
418 ewarn "'python-updater [options]' to rebuild Python modules."
419 fi
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400420
Mike Frysingerd7685db2013-04-06 02:03:53 -0400421 local pyconfig="${EROOT}/usr/$(get_libdir)/python${SLOT}/pyconfig_h"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400422 if [[ ! -e ${EROOT}/usr/include/python${SLOT}/pyconfig.h ]] ; then
423 # See pkg_preinst above for details.
Mike Frysingerd7685db2013-04-06 02:03:53 -0400424 install -D -m644 "${pyconfig}" "${EROOT}/usr/include/python${SLOT}/pyconfig.h" || die
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400425 fi
Mike Frysingerd7685db2013-04-06 02:03:53 -0400426 rm "${pyconfig}" || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400427}
428
429pkg_postrm() {
430 eselect_python_update
Mike Frysinger682d0652012-07-30 11:38:25 -0400431}