blob: 4bdbaf3ea93c67463671eaa3e65ffa7d55658630 [file] [log] [blame]
Mike Frysinger682d0652012-07-30 11:38:25 -04001# Copyright 1999-2012 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2
Mike Frysinger4cfb44a2013-03-18 22:37:33 -04003# $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
5EAPI="2"
6WANT_AUTOMAKE="none"
7WANT_LIBTOOL="none"
8
Mike Frysinger4cfb44a2013-03-18 22:37:33 -04009inherit autotools eutils flag-o-matic multilib pax-utils python-utils-r1 toolchain-funcs multiprocessing
Mike Frysinger682d0652012-07-30 11:38:25 -040010
11MY_P="Python-${PV}"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040012PATCHSET_REVISION="1"
Mike Frysinger682d0652012-07-30 11:38:25 -040013
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040014DESCRIPTION="An interpreted, interactive, object-oriented programming language"
Mike Frysinger682d0652012-07-30 11:38:25 -040015HOMEPAGE="http://www.python.org/"
16SRC_URI="http://www.python.org/ftp/python/${PV}/${MY_P}.tar.bz2
17 mirror://gentoo/python-gentoo-patches-${PV}-${PATCHSET_REVISION}.tar.bz2"
18
19LICENSE="PSF-2"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040020SLOT="2.7"
Mike Frysinger65332152014-02-14 13:55:27 -050021KEYWORDS="*"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040022IUSE="-berkdb build doc elibc_uclibc examples gdbm hardened ipv6 +ncurses +readline sqlite +ssl +threads tk +wide-unicode wininst +xml"
23
24# Do not add a dependency on dev-lang/python to this ebuild.
25# If you need to apply a patch which requires python for bootstrapping, please
26# run the bootstrap code on your dev box and include the results in the
27# patchset. See bug 447752.
Mike Frysinger682d0652012-07-30 11:38:25 -040028
29RDEPEND="app-arch/bzip2
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040030 >=sys-libs/zlib-1.1.3
31 virtual/libffi
32 virtual/libintl
33 !build? (
34 berkdb? ( || (
35 sys-libs/db:4.8
36 sys-libs/db:4.7
37 sys-libs/db:4.6
38 sys-libs/db:4.5
39 sys-libs/db:4.4
40 sys-libs/db:4.3
41 sys-libs/db:4.2
42 ) )
43 gdbm? ( sys-libs/gdbm )
44 ncurses? (
45 >=sys-libs/ncurses-5.2
46 readline? ( >=sys-libs/readline-4.1 )
Mike Frysinger682d0652012-07-30 11:38:25 -040047 )
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040048 sqlite? ( >=dev-db/sqlite-3.3.8:3[extensions] )
49 ssl? ( dev-libs/openssl )
50 tk? (
51 >=dev-lang/tk-8.0
52 dev-tcltk/blt
53 )
54 xml? ( >=dev-libs/expat-2.1 )
55 )
56 !!<sys-apps/portage-2.1.9"
Mike Frysinger682d0652012-07-30 11:38:25 -040057DEPEND="${RDEPEND}
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040058 virtual/pkgconfig
59 >=sys-devel/autoconf-2.65
60 !sys-devel/gcc[libffi]"
Mike Frysinger682d0652012-07-30 11:38:25 -040061RDEPEND+=" !build? ( app-misc/mime-types )
62 doc? ( dev-python/python-docs:${SLOT} )"
Mike Frysinger419c5642014-03-23 15:36:37 -040063PDEPEND="app-admin/eselect-python"
Mike Frysinger682d0652012-07-30 11:38:25 -040064
65S="${WORKDIR}/${MY_P}"
66
67pkg_setup() {
Mike Frysinger682d0652012-07-30 11:38:25 -040068 if use berkdb; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040069 ewarn "'bsddb' module is out-of-date and no longer maintained inside"
70 ewarn "dev-lang/python. 'bsddb' and 'dbhash' modules have been additionally"
71 ewarn "removed in Python 3. A maintained alternative of 'bsddb3' module"
72 ewarn "is provided by dev-python/bsddb3."
Mike Frysinger682d0652012-07-30 11:38:25 -040073 else
74 if has_version "=${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040075 ewarn "You are migrating from =${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"
76 ewarn "to =${CATEGORY}/${PN}-${PV%%.*}*[-berkdb]."
Mike Frysinger682d0652012-07-30 11:38:25 -040077 ewarn "You might need to migrate your databases."
78 fi
79 fi
80}
81
82src_prepare() {
83 # Ensure that internal copies of expat, libffi and zlib are not used.
84 rm -fr Modules/expat
85 rm -fr Modules/_ctypes/libffi*
86 rm -fr Modules/zlib
87
88 local excluded_patches
89 if ! tc-is-cross-compiler; then
90 excluded_patches="*_all_crosscompile.patch"
91 fi
92
93 EPATCH_EXCLUDE="${excluded_patches}" EPATCH_SUFFIX="patch" \
94 epatch "${WORKDIR}/${PV}-${PATCHSET_REVISION}"
95
96 #
97 # START: ChromiumOS specific changes
98 #
99 if tc-is-cross-compiler ; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400100 epatch "${FILESDIR}"/python-2.7.3-cross-setup-sysroot.patch
101 epatch "${FILESDIR}"/python-2.7.3-cross-h2py.patch
102 epatch "${FILESDIR}"/python-2.7.3-cross-install-compile.patch
Han Shenbbd204e2013-04-02 11:00:24 -0700103 epatch "${FILESDIR}"/python-2.7.3-gcc-4_8.patch
Mike Frysinger682d0652012-07-30 11:38:25 -0400104 sed -i 's:^python$EXE:${HOSTPYTHON}:' Lib/*/regen || die
105 fi
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400106 epatch "${FILESDIR}"/python-2.7.3-cross-distutils.patch
Mike Frysingereb047962014-04-06 10:08:56 -0400107 # Undo the @libdir@ change for portage's pym folder as it is always
108 # installed into /usr/lib/ and not the abi libdir.
109 sed -i \
110 -e '/portage.*pym/s:@@GENTOO_LIBDIR@@:lib:g' \
111 Lib/site.py || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400112
113 sed -i -e "s:sys.exec_prefix]:sys.exec_prefix, '/usr/local']:g" \
114 Lib/site.py || die "sed failed to add /usr/local to prefixes"
115 #
116 # END: ChromiumOS specific changes
117 #
118
119 sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
120 Lib/distutils/command/install.py \
121 Lib/distutils/sysconfig.py \
122 Lib/site.py \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400123 Lib/sysconfig.py \
124 Lib/test/test_site.py \
Mike Frysinger682d0652012-07-30 11:38:25 -0400125 Makefile.pre.in \
126 Modules/Setup.dist \
127 Modules/getpath.c \
128 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
129
130 eautoconf
131 eautoheader
132}
133
134src_configure() {
135 if use build; then
136 # Disable extraneous modules with extra dependencies.
137 export PYTHON_DISABLE_MODULES="dbm _bsddb gdbm _curses _curses_panel readline _sqlite3 _tkinter _elementtree pyexpat"
138 export PYTHON_DISABLE_SSL="1"
139 else
140 # dbm module can be linked against berkdb or gdbm.
141 # Defaults to gdbm when both are enabled, #204343.
142 local disable
143 use berkdb || use gdbm || disable+=" dbm"
144 use berkdb || disable+=" _bsddb"
145 use gdbm || disable+=" gdbm"
146 use ncurses || disable+=" _curses _curses_panel"
147 use readline || disable+=" readline"
148 use sqlite || disable+=" _sqlite3"
149 use ssl || export PYTHON_DISABLE_SSL="1"
150 use tk || disable+=" _tkinter"
151 use xml || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
152 export PYTHON_DISABLE_MODULES="${disable}"
153
154 if ! use xml; then
155 ewarn "You have configured Python without XML support."
156 ewarn "This is NOT a recommended configuration as you"
157 ewarn "may face problems parsing any XML documents."
158 fi
159 fi
160
161 if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
162 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
163 fi
164
165 if [[ "$(gcc-major-version)" -ge 4 ]]; then
166 append-flags -fwrapv
167 fi
168
169 filter-flags -malign-double
170
171 [[ "${ARCH}" == "alpha" ]] && append-flags -fPIC
172
173 # https://bugs.gentoo.org/show_bug.cgi?id=50309
174 if is-flagq -O3; then
175 is-flagq -fstack-protector-all && replace-flags -O3 -O2
176 use hardened && replace-flags -O3 -O2
177 fi
178
179 # Run the configure scripts in parallel.
180 multijob_init
181
182 mkdir -p "${WORKDIR}"/{${CBUILD},${CHOST}}
183
184 if tc-is-cross-compiler; then
185 (
186 multijob_child_init
187 cd "${WORKDIR}"/${CBUILD} >/dev/null
188 OPT="-O1" CFLAGS="" CPPFLAGS="" LDFLAGS="" CC="" \
189 "${S}"/configure \
190 --{build,host}=${CBUILD} \
191 || die "cross-configure failed"
192 ) &
193 multijob_post_fork
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400194
195 # The configure script assumes it's buggy when cross-compiling.
196 export ac_cv_buggy_getaddrinfo=no
197 export ac_cv_have_long_long_format=yes
Mike Frysinger682d0652012-07-30 11:38:25 -0400198 fi
199
200 # Export CXX so it ends up in /usr/lib/python2.X/config/Makefile.
201 tc-export CXX
202 # The configure script fails to use pkg-config correctly.
203 # http://bugs.python.org/issue15506
204 export ac_cv_path_PKG_CONFIG=$(tc-getPKG_CONFIG)
205
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400206 # Set LDFLAGS so we link modules with -lpython2.7 correctly.
207 # Needed on FreeBSD unless Python 2.7 is already installed.
Mike Frysinger682d0652012-07-30 11:38:25 -0400208 # Please query BSD team before removing this!
209 append-ldflags "-L."
210
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400211 local dbmliborder
212 if use gdbm; then
213 dbmliborder+="${dbmliborder:+:}gdbm"
214 fi
215 if use berkdb; then
216 dbmliborder+="${dbmliborder:+:}bdb"
217 fi
218
Mike Frysinger682d0652012-07-30 11:38:25 -0400219 cd "${WORKDIR}"/${CHOST}
220 ECONF_SOURCE=${S} OPT="" \
221 econf \
222 --with-fpectl \
223 --enable-shared \
224 $(use_enable ipv6) \
225 $(use_with threads) \
226 $(use wide-unicode && echo "--enable-unicode=ucs4" || echo "--enable-unicode=ucs2") \
227 --infodir='${prefix}/share/info' \
228 --mandir='${prefix}/share/man' \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400229 --with-dbmliborder="${dbmliborder}" \
Mike Frysinger682d0652012-07-30 11:38:25 -0400230 --with-libc="" \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400231 --enable-loadable-sqlite-extensions \
232 --with-system-expat \
Mike Frysinger682d0652012-07-30 11:38:25 -0400233 --with-system-ffi
234
235 if tc-is-cross-compiler; then
236 # Modify the Makefile.pre so we don't regen for the host/ one.
237 # We need to link the host python programs into $PWD and run
238 # them from here because the distutils sysconfig module will
239 # parse Makefile/etc... from argv[0], and we need it to pick
240 # up the target settings, not the host ones.
241 sed -i \
242 -e '1iHOSTPYTHONPATH = ./hostpythonpath:' \
243 -e '/^HOSTPYTHON/s:=.*:= ./hostpython:' \
244 -e '/^HOSTPGEN/s:=.*:= ./Parser/hostpgen:' \
245 Makefile{.pre,} || die "sed failed"
246 fi
247
248 multijob_finish
249}
250
251src_compile() {
252 if tc-is-cross-compiler; then
253 cd "${WORKDIR}"/${CBUILD}
254 # Disable as many modules as possible -- but we need a few to install.
255 PYTHON_DISABLE_MODULES=$(
256 sed -n "/Extension('/{s:^.*Extension('::;s:'.*::;p}" "${S}"/setup.py | \
257 egrep -v '(unicodedata|time|cStringIO|_struct|binascii)'
258 ) \
259 PTHON_DISABLE_SSL="1" \
260 SYSROOT= \
261 emake || die "cross-make failed"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400262 [[ -e build/lib.linux-x86_64-${SLOT}/unicodedata.so ]] || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400263 # See comment in src_configure about these.
264 ln python ../${CHOST}/hostpython || die
265 ln Parser/pgen ../${CHOST}/Parser/hostpgen || die
266 ln -s ../${CBUILD}/build/lib.*/ ../${CHOST}/hostpythonpath || die
267 fi
268
269 cd "${WORKDIR}"/${CHOST}
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400270 default
Mike Frysinger682d0652012-07-30 11:38:25 -0400271
272 # Work around bug 329499. See also bug 413751.
273 pax-mark m python
274}
275
276src_test() {
277 # Tests will not work when cross compiling.
278 if tc-is-cross-compiler; then
279 elog "Disabling tests due to crosscompiling."
280 return
281 fi
282
283 cd "${WORKDIR}"/${CHOST}
284
Mike Frysinger682d0652012-07-30 11:38:25 -0400285 # Skip failing tests.
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400286 local skipped_tests="distutils gdb"
Mike Frysinger682d0652012-07-30 11:38:25 -0400287
288 for test in ${skipped_tests}; do
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400289 mv "${S}"/Lib/test/test_${test}.py "${T}"
Mike Frysinger682d0652012-07-30 11:38:25 -0400290 done
291
292 # Rerun failed tests in verbose mode (regrtest -w).
293 emake test EXTRATESTOPTS="-w" < /dev/tty
294 local result="$?"
295
296 for test in ${skipped_tests}; do
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400297 mv "${T}/test_${test}.py" "${S}"/Lib/test
Mike Frysinger682d0652012-07-30 11:38:25 -0400298 done
299
300 elog "The following tests have been skipped:"
301 for test in ${skipped_tests}; do
302 elog "test_${test}.py"
303 done
304
305 elog "If you would like to run them, you may:"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400306 elog "cd '${EPREFIX}/usr/$(get_libdir)/python${SLOT}/test'"
Mike Frysinger682d0652012-07-30 11:38:25 -0400307 elog "and run the tests separately."
308
309 python_disable_pyc
310
311 if [[ "${result}" -ne 0 ]]; then
312 die "emake test failed"
313 fi
314}
315
316src_install() {
317 [[ -z "${ED}" ]] && ED="${D%/}${EPREFIX}/"
318
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400319 local libdir=${ED}/usr/$(get_libdir)/python${SLOT}
320
Mike Frysinger682d0652012-07-30 11:38:25 -0400321 cd "${WORKDIR}"/${CHOST}
322 emake DESTDIR="${D}" altinstall maninstall || die "emake altinstall maninstall failed"
Mike Frysinger682d0652012-07-30 11:38:25 -0400323
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400324 sed -e "s/\(LDFLAGS=\).*/\1/" -i "${libdir}/config/Makefile" || die "sed failed"
325
326 # Backwards compat with Gentoo divergence.
327 dosym python${SLOT}-config /usr/bin/python-config-${SLOT} || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400328
329 # Fix collisions between different slots of Python.
330 mv "${ED}usr/bin/2to3" "${ED}usr/bin/2to3-${SLOT}"
331 mv "${ED}usr/bin/pydoc" "${ED}usr/bin/pydoc${SLOT}"
332 mv "${ED}usr/bin/idle" "${ED}usr/bin/idle${SLOT}"
Mike Frysinger682d0652012-07-30 11:38:25 -0400333 rm -f "${ED}usr/bin/smtpd.py"
334
335 if use build; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400336 rm -fr "${ED}usr/bin/idle${SLOT}" "${libdir}/"{bsddb,dbhash.py,idlelib,lib-tk,sqlite3,test}
Mike Frysinger682d0652012-07-30 11:38:25 -0400337 else
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400338 use elibc_uclibc && rm -fr "${libdir}/"{bsddb/test,test}
339 use berkdb || rm -fr "${libdir}/"{bsddb,dbhash.py,test/test_bsddb*}
340 use sqlite || rm -fr "${libdir}/"{sqlite3,test/test_sqlite*}
341 use tk || rm -fr "${ED}usr/bin/idle${SLOT}" "${libdir}/"{idlelib,lib-tk}
Mike Frysinger682d0652012-07-30 11:38:25 -0400342 fi
343
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400344 use threads || rm -fr "${libdir}/multiprocessing"
345 use wininst || rm -f "${libdir})/distutils/command/"wininst-*.exe
Mike Frysinger682d0652012-07-30 11:38:25 -0400346
347 dodoc "${S}"/Misc/{ACKS,HISTORY,NEWS} || die "dodoc failed"
348
349 if use examples; then
350 insinto /usr/share/doc/${PF}/examples
351 doins -r "${S}"/Tools || die "doins failed"
352 fi
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400353 insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
354 local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \
355 emake --no-print-directory -s -f - 2>/dev/null)
356 newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py
Mike Frysinger682d0652012-07-30 11:38:25 -0400357
358 newconfd "${FILESDIR}/pydoc.conf" pydoc-${SLOT} || die "newconfd failed"
359 newinitd "${FILESDIR}/pydoc.init" pydoc-${SLOT} || die "newinitd failed"
360 sed \
361 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${SLOT/./_}_PORT:" \
362 -e "s:@PYDOC@:pydoc${SLOT}:" \
363 -i "${ED}etc/conf.d/pydoc-${SLOT}" "${ED}etc/init.d/pydoc-${SLOT}" || die "sed failed"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400364
365 # for python-exec
366 python_export python${SLOT} EPYTHON PYTHON PYTHON_SITEDIR
367
368 # if not using a cross-compiler, use the fresh binary
369 if ! tc-is-cross-compiler; then
370 local PYTHON=./python \
371 LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}.
372 export LD_LIBRARY_PATH
373 fi
374
375 echo "EPYTHON='${EPYTHON}'" > epython.py
376 python_domodule epython.py
377
378 # The sysconfig module will actually read the pyconfig.h at runtime to see what kind
379 # of functionality is enabled in the build. Deploy it behind the back of portage as
380 # need be.
Mike Frysingerd7685db2013-04-06 02:03:53 -0400381 ln "${ED}/usr/include/python${SLOT}/pyconfig.h" "${libdir}/pyconfig_h" || die
382
383 # Workaround https://bugs.gentoo.org/380569
384 keepdir /etc/env.d/python
Mike Frysinger682d0652012-07-30 11:38:25 -0400385}
386
387pkg_preinst() {
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400388 if has_version "<${CATEGORY}/${PN}-${SLOT}" && ! has_version "${CATEGORY}/${PN}:2.7"; then
Mike Frysinger682d0652012-07-30 11:38:25 -0400389 python_updater_warning="1"
390 fi
391}
392
393eselect_python_update() {
394 [[ -z "${EROOT}" || (! -d "${EROOT}" && -d "${ROOT}") ]] && EROOT="${ROOT%/}${EPREFIX}/"
395
396 if [[ -z "$(eselect python show)" || ! -f "${EROOT}usr/bin/$(eselect python show)" ]]; then
397 eselect python update
398 fi
399
400 if [[ -z "$(eselect python show --python${PV%%.*})" || ! -f "${EROOT}usr/bin/$(eselect python show --python${PV%%.*})" ]]; then
401 eselect python update --python${PV%%.*}
402 fi
403}
404
405pkg_postinst() {
406 eselect_python_update
407
Mike Frysinger682d0652012-07-30 11:38:25 -0400408 if [[ "${python_updater_warning}" == "1" ]]; then
409 ewarn "You have just upgraded from an older version of Python."
410 ewarn "You should switch active version of Python ${PV%%.*} and run"
411 ewarn "'python-updater [options]' to rebuild Python modules."
412 fi
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400413
Mike Frysingerd7685db2013-04-06 02:03:53 -0400414 local pyconfig="${EROOT}/usr/$(get_libdir)/python${SLOT}/pyconfig_h"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400415 if [[ ! -e ${EROOT}/usr/include/python${SLOT}/pyconfig.h ]] ; then
416 # See pkg_preinst above for details.
Mike Frysingerd7685db2013-04-06 02:03:53 -0400417 install -D -m644 "${pyconfig}" "${EROOT}/usr/include/python${SLOT}/pyconfig.h" || die
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400418 fi
Mike Frysingerd7685db2013-04-06 02:03:53 -0400419 rm "${pyconfig}" || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400420}
421
422pkg_postrm() {
423 eselect_python_update
Mike Frysinger682d0652012-07-30 11:38:25 -0400424}