blob: d76d926afc70a24c11de3f7f84e3421e18b7a8a4 [file] [log] [blame]
Mandeep Singh Bainescf70c422010-02-01 16:43:24 -08001# Copyright 1999-2009 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/dev-lang/python/python-2.6.4.ebuild,v 1.7 2009/12/13 16:34:03 armin76 Exp $
4
5EAPI="2"
6
7inherit autotools eutils flag-o-matic multilib pax-utils python toolchain-funcs versionator
8
9# We need this so that we don't depend on python.eclass.
10PYVER_MAJOR="$(get_major_version)"
11PYVER_MINOR="$(get_version_component_range 2)"
12PYVER="${PYVER_MAJOR}.${PYVER_MINOR}"
13
14MY_P="Python-${PV}"
15S="${WORKDIR}/${MY_P}"
16
17PATCHSET_REVISION="0"
18
19DESCRIPTION="Python is an interpreted, interactive, object-oriented programming language."
20HOMEPAGE="http://www.python.org/"
21SRC_URI="http://www.python.org/ftp/python/${PV}/${MY_P}.tar.bz2
22 mirror://gentoo/python-gentoo-patches-${PV}$([[ "${PATCHSET_REVISION}" != "0" ]] && echo "-r${PATCHSET_REVISION}").tar.bz2"
23
24LICENSE="PSF-2.2"
25SLOT="2.6"
26KEYWORDS="~alpha amd64 arm hppa ~ia64 ~m68k ~mips ppc ~ppc64 ~s390 ~sh ~sparc x86 ~sparc-fbsd ~x86-fbsd"
27IUSE="-berkdb build doc elibc_uclibc examples gdbm ipv6 +ncurses +readline sqlite ssl +threads tk +wide-unicode wininst +xml"
28
29# NOTE: dev-python/{elementtree,celementtree,pysqlite,ctypes}
30# do not conflict with the ones in python proper. - liquidx
31
32RDEPEND=">=app-admin/eselect-python-20090606
33 >=sys-libs/zlib-1.1.3
34 virtual/libffi
35 virtual/libintl
36 !build? (
37 berkdb? ( || (
38 sys-libs/db:4.7
39 sys-libs/db:4.6
40 sys-libs/db:4.5
41 sys-libs/db:4.4
42 sys-libs/db:4.3
43 sys-libs/db:4.2
44 ) )
45 doc? ( dev-python/python-docs:${SLOT} )
46 gdbm? ( sys-libs/gdbm )
47 ncurses? (
48 >=sys-libs/ncurses-5.2
49 readline? ( >=sys-libs/readline-4.1 )
50 )
51 sqlite? ( >=dev-db/sqlite-3 )
52 ssl? ( dev-libs/openssl )
53 tk? ( >=dev-lang/tk-8.0 )
54 xml? ( >=dev-libs/expat-2 )
55 )"
56DEPEND="${RDEPEND}
57 dev-util/pkgconfig
58 !sys-devel/gcc[libffi]"
59RDEPEND+=" !build? ( app-misc/mime-types )"
60# ToDo(msb): Undo hack below which removes python-update PDEPEND
61# python-update is not required currently for chrome-os
62#msb: PDEPEND="app-admin/python-updater"
63
64PROVIDE="virtual/python"
65
66pkg_setup() {
67 if use berkdb; then
68 ewarn "\"bsddb\" module is out-of-date and no longer maintained inside dev-lang/python. It has"
69 ewarn "been additionally removed in Python 3. You should use external, still maintained \"bsddb3\""
70 ewarn "module provided by dev-python/bsddb3 which supports both Python 2 and Python 3."
71 fi
72
73 if ! has_version "=dev-lang/python-3*"; then
74 elog "It is highly recommended to additionally install Python 3, but without configuring Python wrapper to use Python 3."
75 fi
76}
77
78src_prepare() {
79 # Ensure that internal copies of expat and libffi aren't used.
80 rm -fr Modules/expat
81 rm -fr Modules/_ctypes/libffi*
82
83 if tc-is-cross-compiler; then
84 epatch "${FILESDIR}/python-2.5-cross-printf.patch"
85 epatch "${FILESDIR}/python-2.6-chflags-cross.patch"
86 epatch "${FILESDIR}/python-2.6-test-cross.patch"
87 else
88 rm "${WORKDIR}/${PV}"/*_all_crosscompile.patch
89 fi
90
91 EPATCH_SUFFIX="patch" epatch "${WORKDIR}/${PV}"
92
93 if tc-is-cross-compiler ; then
94 # Change setup.py to respect the SYSROOT environment variable
95 epatch "${FILESDIR}"/python-2.6.4-cross-setup-sysroot.patch
96 fi
97
98 # Add a libdirname to enable python cross-compiling and add a user specifyable libdir
99 epatch "${FILESDIR}"/python-2.5.2-cross-Makefile.pre.in.patch
100 # Make distutils cross-compile aware
101 epatch "${FILESDIR}"/python-2.5.2-cross-distutils-build_ext.patch
102 epatch "${FILESDIR}"/python-2.6-cross-distutils-sysconfig.patch
103 epatch "${FILESDIR}"/python-2.5.2-cross-distutils-install.patch
104 # Use a cross-compile aware pkg-config command to setup libffi usage
105 epatch "${FILESDIR}"/python-2.6.4-cross-libffi-pkg-config.patch
106
107 sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
108 Lib/distutils/command/install.py \
109 Lib/distutils/sysconfig.py \
110 Lib/site.py \
111 Makefile.pre.in \
112 Modules/Setup.dist \
113 Modules/getpath.c \
114 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
Chris Sosaedf18832010-04-23 15:37:42 -0700115
116 sed -i -e "s:sys.exec_prefix]:sys.exec_prefix, '/usr/local']:g" \
117 Lib/site.py || die "sed failed to add /usr/local to prefixes"
Mandeep Singh Bainescf70c422010-02-01 16:43:24 -0800118
119 # Fix os.utime() on hppa. utimes it not supported but unfortunately reported as working - gmsoft (22 May 04)
120 # PLEASE LEAVE THIS FIX FOR NEXT VERSIONS AS IT'S A CRITICAL FIX !!!
121 [[ "${ARCH}" == "hppa" ]] && sed -e "s/utimes //" -i "${S}/configure"
122
123 if ! use wininst; then
124 # Remove Microsoft Windows executables.
125 rm Lib/distutils/command/wininst-*.exe
126 fi
127
128 # Fix OtherFileTests.testStdin() not to assume
129 # that stdin is a tty for bug #248081.
130 sed -e "s:'osf1V5':'osf1V5' and sys.stdin.isatty():" -i Lib/test/test_file.py || die "sed failed"
131
132 eautoreconf
133}
134
135src_configure() {
136 # Disable extraneous modules with extra dependencies.
137 if use build; then
138 export PYTHON_DISABLE_MODULES="dbm _bsddb gdbm _curses _curses_panel readline _sqlite3 _tkinter _elementtree pyexpat"
139 export PYTHON_DISABLE_SSL="1"
140 else
141 # dbm module can be linked against berkdb or gdbm.
142 # Defaults to gdbm when both are enabled, #204343.
143 local disable
144 use berkdb || use gdbm || disable+=" dbm"
145 use berkdb || disable+=" _bsddb"
146 use gdbm || disable+=" gdbm"
147 use ncurses || disable+=" _curses _curses_panel"
148 use readline || disable+=" readline"
149 use sqlite || disable+=" _sqlite3"
150 use ssl || export PYTHON_DISABLE_SSL="1"
151 use tk || disable+=" _tkinter"
152 use xml || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
153 export PYTHON_DISABLE_MODULES="${disable}"
154
155 if ! use xml; then
156 ewarn "You have configured Python without XML support."
157 ewarn "This is NOT a recommended configuration as you"
158 ewarn "may face problems parsing any XML documents."
159 fi
160 fi
161
162 if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
163 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
164 fi
165
166 export OPT="${CFLAGS}"
167
168 filter-flags -malign-double
169
170 [[ "${ARCH}" == "alpha" ]] && append-flags -fPIC
171
172 # https://bugs.gentoo.org/show_bug.cgi?id=50309
173 if is-flag -O3; then
174 is-flag -fstack-protector-all && replace-flags -O3 -O2
175 use hardened && replace-flags -O3 -O2
176 fi
177
178 if tc-is-cross-compiler; then
179 OPT="-O1" CFLAGS="" LDFLAGS="" CC="" \
180 ./configure --{build,host}=${CBUILD} || die "cross-configure failed"
David James9d8e3312010-03-12 14:10:46 -0800181 # Does not support parallel building
182 emake -j1 python Parser/pgen || die "cross-make failed"
Mandeep Singh Bainescf70c422010-02-01 16:43:24 -0800183 mv python hostpython
184 mv Parser/pgen Parser/hostpgen
185 make distclean
186 # Ugly fix, hostpython require few modules to pass test_unicode.py test
187 cp -v /usr/lib/python${PYVER}/lib-dynload/unicodedata.so Modules/.
188 cp -v /usr/lib/python${PYVER}/lib-dynload/time.so Modules/.
189 cp -v /usr/lib/python${PYVER}/lib-dynload/math.so Modules/.
190 sed -i \
191 -e "/^HOSTPYTHON/s:=.*:=./hostpython:" \
192 -e "/^HOSTPGEN/s:=.*:=./Parser/hostpgen:" \
193 Makefile.pre.in || die "sed failed"
194 fi
195
196 # Export CXX so it ends up in /usr/lib/python2.X/config/Makefile.
197 tc-export CXX
198
199 # Set LDFLAGS so we link modules with -lpython2.6 correctly.
200 # Needed on FreeBSD unless Python 2.6 is already installed.
201 # Please query BSD team before removing this!
202 append-ldflags "-L."
203
204 econf \
205 --with-fpectl \
206 --enable-shared \
207 $(use_enable ipv6) \
208 $(use_with threads) \
209 $(use wide-unicode && echo "--enable-unicode=ucs4" || echo "--enable-unicode=ucs2") \
210 --infodir='${prefix}'/share/info \
211 --mandir='${prefix}'/share/man \
212 --with-libc='' \
213 --with-system-ffi
214}
215
216src_test() {
217 # Tests won't work when cross compiling.
218 if tc-is-cross-compiler; then
219 elog "Disabling tests due to crosscompiling."
220 return
221 fi
222
223 # Byte compiling should be enabled here.
224 # Otherwise test_import fails.
225 python_enable_pyc
226
227 # Skip all tests that fail during emerge but pass without emerge:
228 # (See bug #67970)
229 local skip_tests="distutils minidom pyexpat sax tcl"
230
231 # test_ctypes fails with PAX kernel (bug #234498).
232 host-is-pax && skip_tests+=" ctypes"
233
234 for test in ${skip_tests}; do
235 mv "${S}/Lib/test/test_${test}.py" "${T}"
236 done
237
238 # Rerun failed tests in verbose mode (regrtest -w).
239 EXTRATESTOPTS="-w" make test || die "make test failed"
240
241 for test in ${skip_tests}; do
242 mv "${T}/test_${test}.py" "${S}/Lib/test/test_${test}.py"
243 done
244
245 elog "The following tests have been skipped:"
246 for test in ${skip_tests}; do
247 elog "test_${test}.py"
248 done
249
250 elog "If you'd like to run them, you may:"
251 elog "cd /usr/$(get_libdir)/python${PYVER}/test"
252 elog "and run the tests separately."
253}
254
255src_install() {
David James9d8e3312010-03-12 14:10:46 -0800256 # Does not support parallel building
257 emake -j1 DESTDIR="${D}" altinstall maninstall || die "emake altinstall maninstall failed"
Mandeep Singh Bainescf70c422010-02-01 16:43:24 -0800258
259 mv "${D}usr/bin/python${PYVER}-config" "${D}usr/bin/python-config-${PYVER}"
260
261 # Fix collisions between different slots of Python.
262 mv "${D}usr/bin/2to3" "${D}usr/bin/2to3-${PYVER}"
263 mv "${D}usr/bin/pydoc" "${D}usr/bin/pydoc${PYVER}"
264 mv "${D}usr/bin/idle" "${D}usr/bin/idle${PYVER}"
265 mv "${D}usr/share/man/man1/python.1" "${D}usr/share/man/man1/python${PYVER}.1"
266 rm -f "${D}usr/bin/smtpd.py"
267
268 # Fix the OPT variable so that it doesn't have any flags listed in it.
269 # Prevents the problem with compiling things with conflicting flags later.
270 sed -e "s:^OPT=.*:OPT=-DNDEBUG:" -i "${D}usr/$(get_libdir)/python${PYVER}/config/Makefile"
271
272 if use build; then
273 rm -fr "${D}usr/$(get_libdir)/python${PYVER}/"{bsddb,email,lib-tk,sqlite3,test}
274 else
275 use elibc_uclibc && rm -fr "${D}usr/$(get_libdir)/python${PYVER}/"{bsddb/test,test}
276 use berkdb || rm -fr "${D}usr/$(get_libdir)/python${PYVER}/"{bsddb,test/test_bsddb*}
277 use sqlite || rm -fr "${D}usr/$(get_libdir)/python${PYVER}/"{sqlite3,test/test_sqlite*}
278 use tk || rm -fr "${D}usr/$(get_libdir)/python${PYVER}/lib-tk"
279 fi
280
281 use threads || rm -fr "${D}usr/$(get_libdir)/python${PYVER}/multiprocessing"
282
283 prep_ml_includes usr/include/python${PYVER}
284
285 if use examples; then
286 insinto /usr/share/doc/${PF}/examples
287 doins -r "${S}/Tools" || die "doins failed"
288 fi
289
290 newinitd "${FILESDIR}/pydoc.init" pydoc-${SLOT}
291 newconfd "${FILESDIR}/pydoc.conf" pydoc-${SLOT}
292
293 # Don't install empty directory.
294 rmdir "${D}usr/$(get_libdir)/python${PYVER}/lib-old"
295}
296
297pkg_preinst() {
298 if has_version "<${CATEGORY}/${PN}-${SLOT}" && ! has_version ">=${CATEGORY}/${PN}-${SLOT}_alpha"; then
299 python_updater_warning="1"
300 fi
301}
302
303eselect_python_update() {
304 local ignored_python_slots_options=
305 [[ "$(eselect python show)" == "python2."* ]] && ignored_python_slots_options="--ignore 3.0 --ignore 3.1 --ignore 3.2"
306
307 # Create python2 symlink.
308 eselect python update --ignore 3.0 --ignore 3.1 --ignore 3.2 > /dev/null
309
310 eselect python update ${ignored_python_slots_options}
311}
312
313pkg_postinst() {
314 eselect_python_update
315
316 python_mod_optimize -x "(site-packages|test)" /usr/$(get_libdir)/python${PYVER}
317
318 if [[ "${python_updater_warning}" == "1" ]]; then
319 ewarn
320 ewarn "\e[1;31m************************************************************************\e[0m"
321 ewarn
322 ewarn "You have just upgraded from an older version of Python."
323 ewarn "You should run 'python-updater \${options}' to rebuild Python modules."
324 ewarn
325 ewarn "\e[1;31m************************************************************************\e[0m"
326 ewarn
327 ebeep 12
328 fi
329}
330
331pkg_postrm() {
332 eselect_python_update
333
334 python_mod_cleanup /usr/$(get_libdir)/python${PYVER}
335}