blob: f16026aa6d0228b7eef40a9bfe244821b36a7686 [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"
21KEYWORDS="alpha amd64 arm hppa ia64 m68k ~mips ppc ppc64 s390 sh sparc x86 ~amd64-fbsd ~sparc-fbsd ~x86-fbsd"
22IUSE="-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 Frysinger4cfb44a2013-03-18 22:37:33 -040063PDEPEND="app-admin/eselect-python
64 app-admin/python-updater"
Mike Frysinger682d0652012-07-30 11:38:25 -040065
66S="${WORKDIR}/${MY_P}"
67
68pkg_setup() {
Mike Frysinger682d0652012-07-30 11:38:25 -040069 if use berkdb; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040070 ewarn "'bsddb' module is out-of-date and no longer maintained inside"
71 ewarn "dev-lang/python. 'bsddb' and 'dbhash' modules have been additionally"
72 ewarn "removed in Python 3. A maintained alternative of 'bsddb3' module"
73 ewarn "is provided by dev-python/bsddb3."
Mike Frysinger682d0652012-07-30 11:38:25 -040074 else
75 if has_version "=${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -040076 ewarn "You are migrating from =${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"
77 ewarn "to =${CATEGORY}/${PN}-${PV%%.*}*[-berkdb]."
Mike Frysinger682d0652012-07-30 11:38:25 -040078 ewarn "You might need to migrate your databases."
79 fi
80 fi
81}
82
83src_prepare() {
84 # Ensure that internal copies of expat, libffi and zlib are not used.
85 rm -fr Modules/expat
86 rm -fr Modules/_ctypes/libffi*
87 rm -fr Modules/zlib
88
89 local excluded_patches
90 if ! tc-is-cross-compiler; then
91 excluded_patches="*_all_crosscompile.patch"
92 fi
93
94 EPATCH_EXCLUDE="${excluded_patches}" EPATCH_SUFFIX="patch" \
95 epatch "${WORKDIR}/${PV}-${PATCHSET_REVISION}"
96
97 #
98 # START: ChromiumOS specific changes
99 #
100 if tc-is-cross-compiler ; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400101 epatch "${FILESDIR}"/python-2.7.3-cross-setup-sysroot.patch
102 epatch "${FILESDIR}"/python-2.7.3-cross-h2py.patch
103 epatch "${FILESDIR}"/python-2.7.3-cross-install-compile.patch
Han Shenbbd204e2013-04-02 11:00:24 -0700104 epatch "${FILESDIR}"/python-2.7.3-gcc-4_8.patch
Mike Frysinger682d0652012-07-30 11:38:25 -0400105 sed -i 's:^python$EXE:${HOSTPYTHON}:' Lib/*/regen || die
106 fi
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400107 epatch "${FILESDIR}"/python-2.7.3-cross-distutils.patch
Mike Frysinger682d0652012-07-30 11:38:25 -0400108
109 sed -i -e "s:sys.exec_prefix]:sys.exec_prefix, '/usr/local']:g" \
110 Lib/site.py || die "sed failed to add /usr/local to prefixes"
111 #
112 # END: ChromiumOS specific changes
113 #
114
115 sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
116 Lib/distutils/command/install.py \
117 Lib/distutils/sysconfig.py \
118 Lib/site.py \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400119 Lib/sysconfig.py \
120 Lib/test/test_site.py \
Mike Frysinger682d0652012-07-30 11:38:25 -0400121 Makefile.pre.in \
122 Modules/Setup.dist \
123 Modules/getpath.c \
124 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
125
126 eautoconf
127 eautoheader
128}
129
130src_configure() {
131 if use build; then
132 # Disable extraneous modules with extra dependencies.
133 export PYTHON_DISABLE_MODULES="dbm _bsddb gdbm _curses _curses_panel readline _sqlite3 _tkinter _elementtree pyexpat"
134 export PYTHON_DISABLE_SSL="1"
135 else
136 # dbm module can be linked against berkdb or gdbm.
137 # Defaults to gdbm when both are enabled, #204343.
138 local disable
139 use berkdb || use gdbm || disable+=" dbm"
140 use berkdb || disable+=" _bsddb"
141 use gdbm || disable+=" gdbm"
142 use ncurses || disable+=" _curses _curses_panel"
143 use readline || disable+=" readline"
144 use sqlite || disable+=" _sqlite3"
145 use ssl || export PYTHON_DISABLE_SSL="1"
146 use tk || disable+=" _tkinter"
147 use xml || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
148 export PYTHON_DISABLE_MODULES="${disable}"
149
150 if ! use xml; then
151 ewarn "You have configured Python without XML support."
152 ewarn "This is NOT a recommended configuration as you"
153 ewarn "may face problems parsing any XML documents."
154 fi
155 fi
156
157 if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
158 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
159 fi
160
161 if [[ "$(gcc-major-version)" -ge 4 ]]; then
162 append-flags -fwrapv
163 fi
164
165 filter-flags -malign-double
166
167 [[ "${ARCH}" == "alpha" ]] && append-flags -fPIC
168
169 # https://bugs.gentoo.org/show_bug.cgi?id=50309
170 if is-flagq -O3; then
171 is-flagq -fstack-protector-all && replace-flags -O3 -O2
172 use hardened && replace-flags -O3 -O2
173 fi
174
175 # Run the configure scripts in parallel.
176 multijob_init
177
178 mkdir -p "${WORKDIR}"/{${CBUILD},${CHOST}}
179
180 if tc-is-cross-compiler; then
181 (
182 multijob_child_init
183 cd "${WORKDIR}"/${CBUILD} >/dev/null
184 OPT="-O1" CFLAGS="" CPPFLAGS="" LDFLAGS="" CC="" \
185 "${S}"/configure \
186 --{build,host}=${CBUILD} \
187 || die "cross-configure failed"
188 ) &
189 multijob_post_fork
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400190
191 # The configure script assumes it's buggy when cross-compiling.
192 export ac_cv_buggy_getaddrinfo=no
193 export ac_cv_have_long_long_format=yes
Mike Frysinger682d0652012-07-30 11:38:25 -0400194 fi
195
196 # Export CXX so it ends up in /usr/lib/python2.X/config/Makefile.
197 tc-export CXX
198 # The configure script fails to use pkg-config correctly.
199 # http://bugs.python.org/issue15506
200 export ac_cv_path_PKG_CONFIG=$(tc-getPKG_CONFIG)
201
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400202 # Set LDFLAGS so we link modules with -lpython2.7 correctly.
203 # Needed on FreeBSD unless Python 2.7 is already installed.
Mike Frysinger682d0652012-07-30 11:38:25 -0400204 # Please query BSD team before removing this!
205 append-ldflags "-L."
206
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400207 local dbmliborder
208 if use gdbm; then
209 dbmliborder+="${dbmliborder:+:}gdbm"
210 fi
211 if use berkdb; then
212 dbmliborder+="${dbmliborder:+:}bdb"
213 fi
214
Mike Frysinger682d0652012-07-30 11:38:25 -0400215 cd "${WORKDIR}"/${CHOST}
216 ECONF_SOURCE=${S} OPT="" \
217 econf \
218 --with-fpectl \
219 --enable-shared \
220 $(use_enable ipv6) \
221 $(use_with threads) \
222 $(use wide-unicode && echo "--enable-unicode=ucs4" || echo "--enable-unicode=ucs2") \
223 --infodir='${prefix}/share/info' \
224 --mandir='${prefix}/share/man' \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400225 --with-dbmliborder="${dbmliborder}" \
Mike Frysinger682d0652012-07-30 11:38:25 -0400226 --with-libc="" \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400227 --enable-loadable-sqlite-extensions \
228 --with-system-expat \
Mike Frysinger682d0652012-07-30 11:38:25 -0400229 --with-system-ffi
230
231 if tc-is-cross-compiler; then
232 # Modify the Makefile.pre so we don't regen for the host/ one.
233 # We need to link the host python programs into $PWD and run
234 # them from here because the distutils sysconfig module will
235 # parse Makefile/etc... from argv[0], and we need it to pick
236 # up the target settings, not the host ones.
237 sed -i \
238 -e '1iHOSTPYTHONPATH = ./hostpythonpath:' \
239 -e '/^HOSTPYTHON/s:=.*:= ./hostpython:' \
240 -e '/^HOSTPGEN/s:=.*:= ./Parser/hostpgen:' \
241 Makefile{.pre,} || die "sed failed"
242 fi
243
244 multijob_finish
245}
246
247src_compile() {
248 if tc-is-cross-compiler; then
249 cd "${WORKDIR}"/${CBUILD}
250 # Disable as many modules as possible -- but we need a few to install.
251 PYTHON_DISABLE_MODULES=$(
252 sed -n "/Extension('/{s:^.*Extension('::;s:'.*::;p}" "${S}"/setup.py | \
253 egrep -v '(unicodedata|time|cStringIO|_struct|binascii)'
254 ) \
255 PTHON_DISABLE_SSL="1" \
256 SYSROOT= \
257 emake || die "cross-make failed"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400258 [[ -e build/lib.linux-x86_64-${SLOT}/unicodedata.so ]] || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400259 # See comment in src_configure about these.
260 ln python ../${CHOST}/hostpython || die
261 ln Parser/pgen ../${CHOST}/Parser/hostpgen || die
262 ln -s ../${CBUILD}/build/lib.*/ ../${CHOST}/hostpythonpath || die
263 fi
264
265 cd "${WORKDIR}"/${CHOST}
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400266 default
Mike Frysinger682d0652012-07-30 11:38:25 -0400267
268 # Work around bug 329499. See also bug 413751.
269 pax-mark m python
270}
271
272src_test() {
273 # Tests will not work when cross compiling.
274 if tc-is-cross-compiler; then
275 elog "Disabling tests due to crosscompiling."
276 return
277 fi
278
279 cd "${WORKDIR}"/${CHOST}
280
Mike Frysinger682d0652012-07-30 11:38:25 -0400281 # Skip failing tests.
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400282 local skipped_tests="distutils gdb"
Mike Frysinger682d0652012-07-30 11:38:25 -0400283
284 for test in ${skipped_tests}; do
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400285 mv "${S}"/Lib/test/test_${test}.py "${T}"
Mike Frysinger682d0652012-07-30 11:38:25 -0400286 done
287
288 # Rerun failed tests in verbose mode (regrtest -w).
289 emake test EXTRATESTOPTS="-w" < /dev/tty
290 local result="$?"
291
292 for test in ${skipped_tests}; do
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400293 mv "${T}/test_${test}.py" "${S}"/Lib/test
Mike Frysinger682d0652012-07-30 11:38:25 -0400294 done
295
296 elog "The following tests have been skipped:"
297 for test in ${skipped_tests}; do
298 elog "test_${test}.py"
299 done
300
301 elog "If you would like to run them, you may:"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400302 elog "cd '${EPREFIX}/usr/$(get_libdir)/python${SLOT}/test'"
Mike Frysinger682d0652012-07-30 11:38:25 -0400303 elog "and run the tests separately."
304
305 python_disable_pyc
306
307 if [[ "${result}" -ne 0 ]]; then
308 die "emake test failed"
309 fi
310}
311
312src_install() {
313 [[ -z "${ED}" ]] && ED="${D%/}${EPREFIX}/"
314
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400315 local libdir=${ED}/usr/$(get_libdir)/python${SLOT}
316
Mike Frysinger682d0652012-07-30 11:38:25 -0400317 cd "${WORKDIR}"/${CHOST}
318 emake DESTDIR="${D}" altinstall maninstall || die "emake altinstall maninstall failed"
Mike Frysinger682d0652012-07-30 11:38:25 -0400319
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400320 sed -e "s/\(LDFLAGS=\).*/\1/" -i "${libdir}/config/Makefile" || die "sed failed"
321
322 # Backwards compat with Gentoo divergence.
323 dosym python${SLOT}-config /usr/bin/python-config-${SLOT} || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400324
325 # Fix collisions between different slots of Python.
326 mv "${ED}usr/bin/2to3" "${ED}usr/bin/2to3-${SLOT}"
327 mv "${ED}usr/bin/pydoc" "${ED}usr/bin/pydoc${SLOT}"
328 mv "${ED}usr/bin/idle" "${ED}usr/bin/idle${SLOT}"
Mike Frysinger682d0652012-07-30 11:38:25 -0400329 rm -f "${ED}usr/bin/smtpd.py"
330
331 if use build; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400332 rm -fr "${ED}usr/bin/idle${SLOT}" "${libdir}/"{bsddb,dbhash.py,idlelib,lib-tk,sqlite3,test}
Mike Frysinger682d0652012-07-30 11:38:25 -0400333 else
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400334 use elibc_uclibc && rm -fr "${libdir}/"{bsddb/test,test}
335 use berkdb || rm -fr "${libdir}/"{bsddb,dbhash.py,test/test_bsddb*}
336 use sqlite || rm -fr "${libdir}/"{sqlite3,test/test_sqlite*}
337 use tk || rm -fr "${ED}usr/bin/idle${SLOT}" "${libdir}/"{idlelib,lib-tk}
Mike Frysinger682d0652012-07-30 11:38:25 -0400338 fi
339
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400340 use threads || rm -fr "${libdir}/multiprocessing"
341 use wininst || rm -f "${libdir})/distutils/command/"wininst-*.exe
Mike Frysinger682d0652012-07-30 11:38:25 -0400342
343 dodoc "${S}"/Misc/{ACKS,HISTORY,NEWS} || die "dodoc failed"
344
345 if use examples; then
346 insinto /usr/share/doc/${PF}/examples
347 doins -r "${S}"/Tools || die "doins failed"
348 fi
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400349 insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
350 local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \
351 emake --no-print-directory -s -f - 2>/dev/null)
352 newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py
Mike Frysinger682d0652012-07-30 11:38:25 -0400353
354 newconfd "${FILESDIR}/pydoc.conf" pydoc-${SLOT} || die "newconfd failed"
355 newinitd "${FILESDIR}/pydoc.init" pydoc-${SLOT} || die "newinitd failed"
356 sed \
357 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${SLOT/./_}_PORT:" \
358 -e "s:@PYDOC@:pydoc${SLOT}:" \
359 -i "${ED}etc/conf.d/pydoc-${SLOT}" "${ED}etc/init.d/pydoc-${SLOT}" || die "sed failed"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400360
361 # for python-exec
362 python_export python${SLOT} EPYTHON PYTHON PYTHON_SITEDIR
363
364 # if not using a cross-compiler, use the fresh binary
365 if ! tc-is-cross-compiler; then
366 local PYTHON=./python \
367 LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}.
368 export LD_LIBRARY_PATH
369 fi
370
371 echo "EPYTHON='${EPYTHON}'" > epython.py
372 python_domodule epython.py
373
374 # The sysconfig module will actually read the pyconfig.h at runtime to see what kind
375 # of functionality is enabled in the build. Deploy it behind the back of portage as
376 # need be.
Mike Frysingerd7685db2013-04-06 02:03:53 -0400377 ln "${ED}/usr/include/python${SLOT}/pyconfig.h" "${libdir}/pyconfig_h" || die
378
379 # Workaround https://bugs.gentoo.org/380569
380 keepdir /etc/env.d/python
Mike Frysinger682d0652012-07-30 11:38:25 -0400381}
382
383pkg_preinst() {
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400384 if has_version "<${CATEGORY}/${PN}-${SLOT}" && ! has_version "${CATEGORY}/${PN}:2.7"; then
Mike Frysinger682d0652012-07-30 11:38:25 -0400385 python_updater_warning="1"
386 fi
387}
388
389eselect_python_update() {
390 [[ -z "${EROOT}" || (! -d "${EROOT}" && -d "${ROOT}") ]] && EROOT="${ROOT%/}${EPREFIX}/"
391
392 if [[ -z "$(eselect python show)" || ! -f "${EROOT}usr/bin/$(eselect python show)" ]]; then
393 eselect python update
394 fi
395
396 if [[ -z "$(eselect python show --python${PV%%.*})" || ! -f "${EROOT}usr/bin/$(eselect python show --python${PV%%.*})" ]]; then
397 eselect python update --python${PV%%.*}
398 fi
399}
400
401pkg_postinst() {
402 eselect_python_update
403
Mike Frysinger682d0652012-07-30 11:38:25 -0400404 if [[ "${python_updater_warning}" == "1" ]]; then
405 ewarn "You have just upgraded from an older version of Python."
406 ewarn "You should switch active version of Python ${PV%%.*} and run"
407 ewarn "'python-updater [options]' to rebuild Python modules."
408 fi
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400409
Mike Frysingerd7685db2013-04-06 02:03:53 -0400410 local pyconfig="${EROOT}/usr/$(get_libdir)/python${SLOT}/pyconfig_h"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400411 if [[ ! -e ${EROOT}/usr/include/python${SLOT}/pyconfig.h ]] ; then
412 # See pkg_preinst above for details.
Mike Frysingerd7685db2013-04-06 02:03:53 -0400413 install -D -m644 "${pyconfig}" "${EROOT}/usr/include/python${SLOT}/pyconfig.h" || die
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400414 fi
Mike Frysingerd7685db2013-04-06 02:03:53 -0400415 rm "${pyconfig}" || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400416}
417
418pkg_postrm() {
419 eselect_python_update
Mike Frysinger682d0652012-07-30 11:38:25 -0400420}