blob: f8d43a1f96914bfefaa3d5148c8ee98739b585c8 [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
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 Frysinger682d0652012-07-30 11:38:25 -0400107
108 sed -i -e "s:sys.exec_prefix]:sys.exec_prefix, '/usr/local']:g" \
109 Lib/site.py || die "sed failed to add /usr/local to prefixes"
110 #
111 # END: ChromiumOS specific changes
112 #
113
114 sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
115 Lib/distutils/command/install.py \
116 Lib/distutils/sysconfig.py \
117 Lib/site.py \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400118 Lib/sysconfig.py \
119 Lib/test/test_site.py \
Mike Frysinger682d0652012-07-30 11:38:25 -0400120 Makefile.pre.in \
121 Modules/Setup.dist \
122 Modules/getpath.c \
123 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
124
125 eautoconf
126 eautoheader
127}
128
129src_configure() {
130 if use build; then
131 # Disable extraneous modules with extra dependencies.
132 export PYTHON_DISABLE_MODULES="dbm _bsddb gdbm _curses _curses_panel readline _sqlite3 _tkinter _elementtree pyexpat"
133 export PYTHON_DISABLE_SSL="1"
134 else
135 # dbm module can be linked against berkdb or gdbm.
136 # Defaults to gdbm when both are enabled, #204343.
137 local disable
138 use berkdb || use gdbm || disable+=" dbm"
139 use berkdb || disable+=" _bsddb"
140 use gdbm || disable+=" gdbm"
141 use ncurses || disable+=" _curses _curses_panel"
142 use readline || disable+=" readline"
143 use sqlite || disable+=" _sqlite3"
144 use ssl || export PYTHON_DISABLE_SSL="1"
145 use tk || disable+=" _tkinter"
146 use xml || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
147 export PYTHON_DISABLE_MODULES="${disable}"
148
149 if ! use xml; then
150 ewarn "You have configured Python without XML support."
151 ewarn "This is NOT a recommended configuration as you"
152 ewarn "may face problems parsing any XML documents."
153 fi
154 fi
155
156 if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
157 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
158 fi
159
160 if [[ "$(gcc-major-version)" -ge 4 ]]; then
161 append-flags -fwrapv
162 fi
163
164 filter-flags -malign-double
165
166 [[ "${ARCH}" == "alpha" ]] && append-flags -fPIC
167
168 # https://bugs.gentoo.org/show_bug.cgi?id=50309
169 if is-flagq -O3; then
170 is-flagq -fstack-protector-all && replace-flags -O3 -O2
171 use hardened && replace-flags -O3 -O2
172 fi
173
174 # Run the configure scripts in parallel.
175 multijob_init
176
177 mkdir -p "${WORKDIR}"/{${CBUILD},${CHOST}}
178
179 if tc-is-cross-compiler; then
180 (
181 multijob_child_init
182 cd "${WORKDIR}"/${CBUILD} >/dev/null
183 OPT="-O1" CFLAGS="" CPPFLAGS="" LDFLAGS="" CC="" \
184 "${S}"/configure \
185 --{build,host}=${CBUILD} \
186 || die "cross-configure failed"
187 ) &
188 multijob_post_fork
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400189
190 # The configure script assumes it's buggy when cross-compiling.
191 export ac_cv_buggy_getaddrinfo=no
192 export ac_cv_have_long_long_format=yes
Mike Frysinger682d0652012-07-30 11:38:25 -0400193 fi
194
195 # Export CXX so it ends up in /usr/lib/python2.X/config/Makefile.
196 tc-export CXX
197 # The configure script fails to use pkg-config correctly.
198 # http://bugs.python.org/issue15506
199 export ac_cv_path_PKG_CONFIG=$(tc-getPKG_CONFIG)
200
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400201 # Set LDFLAGS so we link modules with -lpython2.7 correctly.
202 # Needed on FreeBSD unless Python 2.7 is already installed.
Mike Frysinger682d0652012-07-30 11:38:25 -0400203 # Please query BSD team before removing this!
204 append-ldflags "-L."
205
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400206 local dbmliborder
207 if use gdbm; then
208 dbmliborder+="${dbmliborder:+:}gdbm"
209 fi
210 if use berkdb; then
211 dbmliborder+="${dbmliborder:+:}bdb"
212 fi
213
Mike Frysinger682d0652012-07-30 11:38:25 -0400214 cd "${WORKDIR}"/${CHOST}
215 ECONF_SOURCE=${S} OPT="" \
216 econf \
217 --with-fpectl \
218 --enable-shared \
219 $(use_enable ipv6) \
220 $(use_with threads) \
221 $(use wide-unicode && echo "--enable-unicode=ucs4" || echo "--enable-unicode=ucs2") \
222 --infodir='${prefix}/share/info' \
223 --mandir='${prefix}/share/man' \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400224 --with-dbmliborder="${dbmliborder}" \
Mike Frysinger682d0652012-07-30 11:38:25 -0400225 --with-libc="" \
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400226 --enable-loadable-sqlite-extensions \
227 --with-system-expat \
Mike Frysinger682d0652012-07-30 11:38:25 -0400228 --with-system-ffi
229
230 if tc-is-cross-compiler; then
231 # Modify the Makefile.pre so we don't regen for the host/ one.
232 # We need to link the host python programs into $PWD and run
233 # them from here because the distutils sysconfig module will
234 # parse Makefile/etc... from argv[0], and we need it to pick
235 # up the target settings, not the host ones.
236 sed -i \
237 -e '1iHOSTPYTHONPATH = ./hostpythonpath:' \
238 -e '/^HOSTPYTHON/s:=.*:= ./hostpython:' \
239 -e '/^HOSTPGEN/s:=.*:= ./Parser/hostpgen:' \
240 Makefile{.pre,} || die "sed failed"
241 fi
242
243 multijob_finish
244}
245
246src_compile() {
247 if tc-is-cross-compiler; then
248 cd "${WORKDIR}"/${CBUILD}
249 # Disable as many modules as possible -- but we need a few to install.
250 PYTHON_DISABLE_MODULES=$(
251 sed -n "/Extension('/{s:^.*Extension('::;s:'.*::;p}" "${S}"/setup.py | \
252 egrep -v '(unicodedata|time|cStringIO|_struct|binascii)'
253 ) \
254 PTHON_DISABLE_SSL="1" \
255 SYSROOT= \
256 emake || die "cross-make failed"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400257 [[ -e build/lib.linux-x86_64-${SLOT}/unicodedata.so ]] || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400258 # See comment in src_configure about these.
259 ln python ../${CHOST}/hostpython || die
260 ln Parser/pgen ../${CHOST}/Parser/hostpgen || die
261 ln -s ../${CBUILD}/build/lib.*/ ../${CHOST}/hostpythonpath || die
262 fi
263
264 cd "${WORKDIR}"/${CHOST}
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400265 default
Mike Frysinger682d0652012-07-30 11:38:25 -0400266
267 # Work around bug 329499. See also bug 413751.
268 pax-mark m python
269}
270
271src_test() {
272 # Tests will not work when cross compiling.
273 if tc-is-cross-compiler; then
274 elog "Disabling tests due to crosscompiling."
275 return
276 fi
277
278 cd "${WORKDIR}"/${CHOST}
279
Mike Frysinger682d0652012-07-30 11:38:25 -0400280 # Skip failing tests.
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400281 local skipped_tests="distutils gdb"
Mike Frysinger682d0652012-07-30 11:38:25 -0400282
283 for test in ${skipped_tests}; do
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400284 mv "${S}"/Lib/test/test_${test}.py "${T}"
Mike Frysinger682d0652012-07-30 11:38:25 -0400285 done
286
287 # Rerun failed tests in verbose mode (regrtest -w).
288 emake test EXTRATESTOPTS="-w" < /dev/tty
289 local result="$?"
290
291 for test in ${skipped_tests}; do
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400292 mv "${T}/test_${test}.py" "${S}"/Lib/test
Mike Frysinger682d0652012-07-30 11:38:25 -0400293 done
294
295 elog "The following tests have been skipped:"
296 for test in ${skipped_tests}; do
297 elog "test_${test}.py"
298 done
299
300 elog "If you would like to run them, you may:"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400301 elog "cd '${EPREFIX}/usr/$(get_libdir)/python${SLOT}/test'"
Mike Frysinger682d0652012-07-30 11:38:25 -0400302 elog "and run the tests separately."
303
304 python_disable_pyc
305
306 if [[ "${result}" -ne 0 ]]; then
307 die "emake test failed"
308 fi
309}
310
311src_install() {
312 [[ -z "${ED}" ]] && ED="${D%/}${EPREFIX}/"
313
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400314 local libdir=${ED}/usr/$(get_libdir)/python${SLOT}
315
Mike Frysinger682d0652012-07-30 11:38:25 -0400316 cd "${WORKDIR}"/${CHOST}
317 emake DESTDIR="${D}" altinstall maninstall || die "emake altinstall maninstall failed"
Mike Frysinger682d0652012-07-30 11:38:25 -0400318
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400319 sed -e "s/\(LDFLAGS=\).*/\1/" -i "${libdir}/config/Makefile" || die "sed failed"
320
321 # Backwards compat with Gentoo divergence.
322 dosym python${SLOT}-config /usr/bin/python-config-${SLOT} || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400323
324 # Fix collisions between different slots of Python.
325 mv "${ED}usr/bin/2to3" "${ED}usr/bin/2to3-${SLOT}"
326 mv "${ED}usr/bin/pydoc" "${ED}usr/bin/pydoc${SLOT}"
327 mv "${ED}usr/bin/idle" "${ED}usr/bin/idle${SLOT}"
Mike Frysinger682d0652012-07-30 11:38:25 -0400328 rm -f "${ED}usr/bin/smtpd.py"
329
330 if use build; then
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400331 rm -fr "${ED}usr/bin/idle${SLOT}" "${libdir}/"{bsddb,dbhash.py,idlelib,lib-tk,sqlite3,test}
Mike Frysinger682d0652012-07-30 11:38:25 -0400332 else
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400333 use elibc_uclibc && rm -fr "${libdir}/"{bsddb/test,test}
334 use berkdb || rm -fr "${libdir}/"{bsddb,dbhash.py,test/test_bsddb*}
335 use sqlite || rm -fr "${libdir}/"{sqlite3,test/test_sqlite*}
336 use tk || rm -fr "${ED}usr/bin/idle${SLOT}" "${libdir}/"{idlelib,lib-tk}
Mike Frysinger682d0652012-07-30 11:38:25 -0400337 fi
338
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400339 use threads || rm -fr "${libdir}/multiprocessing"
340 use wininst || rm -f "${libdir})/distutils/command/"wininst-*.exe
Mike Frysinger682d0652012-07-30 11:38:25 -0400341
342 dodoc "${S}"/Misc/{ACKS,HISTORY,NEWS} || die "dodoc failed"
343
344 if use examples; then
345 insinto /usr/share/doc/${PF}/examples
346 doins -r "${S}"/Tools || die "doins failed"
347 fi
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400348 insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
349 local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \
350 emake --no-print-directory -s -f - 2>/dev/null)
351 newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py
Mike Frysinger682d0652012-07-30 11:38:25 -0400352
353 newconfd "${FILESDIR}/pydoc.conf" pydoc-${SLOT} || die "newconfd failed"
354 newinitd "${FILESDIR}/pydoc.init" pydoc-${SLOT} || die "newinitd failed"
355 sed \
356 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${SLOT/./_}_PORT:" \
357 -e "s:@PYDOC@:pydoc${SLOT}:" \
358 -i "${ED}etc/conf.d/pydoc-${SLOT}" "${ED}etc/init.d/pydoc-${SLOT}" || die "sed failed"
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400359
360 # for python-exec
361 python_export python${SLOT} EPYTHON PYTHON PYTHON_SITEDIR
362
363 # if not using a cross-compiler, use the fresh binary
364 if ! tc-is-cross-compiler; then
365 local PYTHON=./python \
366 LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}.
367 export LD_LIBRARY_PATH
368 fi
369
370 echo "EPYTHON='${EPYTHON}'" > epython.py
371 python_domodule epython.py
372
373 # The sysconfig module will actually read the pyconfig.h at runtime to see what kind
374 # of functionality is enabled in the build. Deploy it behind the back of portage as
375 # need be.
376 ln "${ED}/usr/include/python${SLOT}"/pyconfig{.,_}h || die
Mike Frysinger682d0652012-07-30 11:38:25 -0400377}
378
379pkg_preinst() {
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400380 # Workaround https://bugs.gentoo.org/380569
381 mkdir -p "${ED}/etc/env.d/python"
382
383 # See end of src_install above.
384 mv "${ED}/usr/include/python${SLOT}/pyconfig_h" "${T}/" || die
385
386 if has_version "<${CATEGORY}/${PN}-${SLOT}" && ! has_version "${CATEGORY}/${PN}:2.7"; then
Mike Frysinger682d0652012-07-30 11:38:25 -0400387 python_updater_warning="1"
388 fi
389}
390
391eselect_python_update() {
392 [[ -z "${EROOT}" || (! -d "${EROOT}" && -d "${ROOT}") ]] && EROOT="${ROOT%/}${EPREFIX}/"
393
394 if [[ -z "$(eselect python show)" || ! -f "${EROOT}usr/bin/$(eselect python show)" ]]; then
395 eselect python update
396 fi
397
398 if [[ -z "$(eselect python show --python${PV%%.*})" || ! -f "${EROOT}usr/bin/$(eselect python show --python${PV%%.*})" ]]; then
399 eselect python update --python${PV%%.*}
400 fi
401}
402
403pkg_postinst() {
404 eselect_python_update
405
Mike Frysinger682d0652012-07-30 11:38:25 -0400406 if [[ "${python_updater_warning}" == "1" ]]; then
407 ewarn "You have just upgraded from an older version of Python."
408 ewarn "You should switch active version of Python ${PV%%.*} and run"
409 ewarn "'python-updater [options]' to rebuild Python modules."
410 fi
Mike Frysinger4cfb44a2013-03-18 22:37:33 -0400411
412 if [[ ! -e ${EROOT}/usr/include/python${SLOT}/pyconfig.h ]] ; then
413 # See pkg_preinst above for details.
414 install -D -m644 "${T}/pyconfig_h" "${EROOT}/usr/include/python${SLOT}/pyconfig.h" || die
415 fi
Mike Frysinger682d0652012-07-30 11:38:25 -0400416}
417
418pkg_postrm() {
419 eselect_python_update
Mike Frysinger682d0652012-07-30 11:38:25 -0400420}