blob: 0b8f27cd0413e28e8913d98a8869c5745a9ecebf [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"
Nathan Williams84185072010-10-11 16:10:56 -040087 epatch "${FILESDIR}/python-2.6-cross-getaddrinfo.patch"
Mandeep Singh Bainescf70c422010-02-01 16:43:24 -080088 else
89 rm "${WORKDIR}/${PV}"/*_all_crosscompile.patch
90 fi
91
92 EPATCH_SUFFIX="patch" epatch "${WORKDIR}/${PV}"
93
94 if tc-is-cross-compiler ; then
95 # Change setup.py to respect the SYSROOT environment variable
96 epatch "${FILESDIR}"/python-2.6.4-cross-setup-sysroot.patch
97 fi
98
99 # Add a libdirname to enable python cross-compiling and add a user specifyable libdir
100 epatch "${FILESDIR}"/python-2.5.2-cross-Makefile.pre.in.patch
101 # Make distutils cross-compile aware
102 epatch "${FILESDIR}"/python-2.5.2-cross-distutils-build_ext.patch
103 epatch "${FILESDIR}"/python-2.6-cross-distutils-sysconfig.patch
104 epatch "${FILESDIR}"/python-2.5.2-cross-distutils-install.patch
105 # Use a cross-compile aware pkg-config command to setup libffi usage
106 epatch "${FILESDIR}"/python-2.6.4-cross-libffi-pkg-config.patch
107
108 sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
109 Lib/distutils/command/install.py \
110 Lib/distutils/sysconfig.py \
111 Lib/site.py \
112 Makefile.pre.in \
113 Modules/Setup.dist \
114 Modules/getpath.c \
115 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
Chris Sosaedf18832010-04-23 15:37:42 -0700116
117 sed -i -e "s:sys.exec_prefix]:sys.exec_prefix, '/usr/local']:g" \
118 Lib/site.py || die "sed failed to add /usr/local to prefixes"
Mandeep Singh Bainescf70c422010-02-01 16:43:24 -0800119
120 # Fix os.utime() on hppa. utimes it not supported but unfortunately reported as working - gmsoft (22 May 04)
121 # PLEASE LEAVE THIS FIX FOR NEXT VERSIONS AS IT'S A CRITICAL FIX !!!
122 [[ "${ARCH}" == "hppa" ]] && sed -e "s/utimes //" -i "${S}/configure"
123
124 if ! use wininst; then
125 # Remove Microsoft Windows executables.
126 rm Lib/distutils/command/wininst-*.exe
127 fi
128
129 # Fix OtherFileTests.testStdin() not to assume
130 # that stdin is a tty for bug #248081.
131 sed -e "s:'osf1V5':'osf1V5' and sys.stdin.isatty():" -i Lib/test/test_file.py || die "sed failed"
132
133 eautoreconf
134}
135
136src_configure() {
137 # Disable extraneous modules with extra dependencies.
138 if use build; then
139 export PYTHON_DISABLE_MODULES="dbm _bsddb gdbm _curses _curses_panel readline _sqlite3 _tkinter _elementtree pyexpat"
140 export PYTHON_DISABLE_SSL="1"
141 else
142 # dbm module can be linked against berkdb or gdbm.
143 # Defaults to gdbm when both are enabled, #204343.
144 local disable
145 use berkdb || use gdbm || disable+=" dbm"
146 use berkdb || disable+=" _bsddb"
147 use gdbm || disable+=" gdbm"
148 use ncurses || disable+=" _curses _curses_panel"
149 use readline || disable+=" readline"
150 use sqlite || disable+=" _sqlite3"
151 use ssl || export PYTHON_DISABLE_SSL="1"
152 use tk || disable+=" _tkinter"
153 use xml || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
154 export PYTHON_DISABLE_MODULES="${disable}"
155
156 if ! use xml; then
157 ewarn "You have configured Python without XML support."
158 ewarn "This is NOT a recommended configuration as you"
159 ewarn "may face problems parsing any XML documents."
160 fi
161 fi
162
163 if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
164 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
165 fi
166
167 export OPT="${CFLAGS}"
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-flag -O3; then
175 is-flag -fstack-protector-all && replace-flags -O3 -O2
176 use hardened && replace-flags -O3 -O2
177 fi
178
179 if tc-is-cross-compiler; then
180 OPT="-O1" CFLAGS="" LDFLAGS="" CC="" \
181 ./configure --{build,host}=${CBUILD} || die "cross-configure failed"
David James9d8e3312010-03-12 14:10:46 -0800182 # Does not support parallel building
183 emake -j1 python Parser/pgen || die "cross-make failed"
Mandeep Singh Bainescf70c422010-02-01 16:43:24 -0800184 mv python hostpython
185 mv Parser/pgen Parser/hostpgen
186 make distclean
187 # Ugly fix, hostpython require few modules to pass test_unicode.py test
188 cp -v /usr/lib/python${PYVER}/lib-dynload/unicodedata.so Modules/.
189 cp -v /usr/lib/python${PYVER}/lib-dynload/time.so Modules/.
190 cp -v /usr/lib/python${PYVER}/lib-dynload/math.so Modules/.
191 sed -i \
192 -e "/^HOSTPYTHON/s:=.*:=./hostpython:" \
193 -e "/^HOSTPGEN/s:=.*:=./Parser/hostpgen:" \
194 Makefile.pre.in || die "sed failed"
195 fi
196
197 # Export CXX so it ends up in /usr/lib/python2.X/config/Makefile.
198 tc-export CXX
199
200 # Set LDFLAGS so we link modules with -lpython2.6 correctly.
201 # Needed on FreeBSD unless Python 2.6 is already installed.
202 # Please query BSD team before removing this!
203 append-ldflags "-L."
204
205 econf \
206 --with-fpectl \
207 --enable-shared \
208 $(use_enable ipv6) \
209 $(use_with threads) \
210 $(use wide-unicode && echo "--enable-unicode=ucs4" || echo "--enable-unicode=ucs2") \
211 --infodir='${prefix}'/share/info \
212 --mandir='${prefix}'/share/man \
213 --with-libc='' \
214 --with-system-ffi
215}
216
217src_test() {
218 # Tests won't work when cross compiling.
219 if tc-is-cross-compiler; then
220 elog "Disabling tests due to crosscompiling."
221 return
222 fi
223
224 # Byte compiling should be enabled here.
225 # Otherwise test_import fails.
226 python_enable_pyc
227
228 # Skip all tests that fail during emerge but pass without emerge:
229 # (See bug #67970)
230 local skip_tests="distutils minidom pyexpat sax tcl"
231
232 # test_ctypes fails with PAX kernel (bug #234498).
233 host-is-pax && skip_tests+=" ctypes"
234
235 for test in ${skip_tests}; do
236 mv "${S}/Lib/test/test_${test}.py" "${T}"
237 done
238
239 # Rerun failed tests in verbose mode (regrtest -w).
240 EXTRATESTOPTS="-w" make test || die "make test failed"
241
242 for test in ${skip_tests}; do
243 mv "${T}/test_${test}.py" "${S}/Lib/test/test_${test}.py"
244 done
245
246 elog "The following tests have been skipped:"
247 for test in ${skip_tests}; do
248 elog "test_${test}.py"
249 done
250
251 elog "If you'd like to run them, you may:"
252 elog "cd /usr/$(get_libdir)/python${PYVER}/test"
253 elog "and run the tests separately."
254}
255
256src_install() {
David James9d8e3312010-03-12 14:10:46 -0800257 # Does not support parallel building
258 emake -j1 DESTDIR="${D}" altinstall maninstall || die "emake altinstall maninstall failed"
Mandeep Singh Bainescf70c422010-02-01 16:43:24 -0800259
260 mv "${D}usr/bin/python${PYVER}-config" "${D}usr/bin/python-config-${PYVER}"
261
262 # Fix collisions between different slots of Python.
263 mv "${D}usr/bin/2to3" "${D}usr/bin/2to3-${PYVER}"
264 mv "${D}usr/bin/pydoc" "${D}usr/bin/pydoc${PYVER}"
265 mv "${D}usr/bin/idle" "${D}usr/bin/idle${PYVER}"
266 mv "${D}usr/share/man/man1/python.1" "${D}usr/share/man/man1/python${PYVER}.1"
267 rm -f "${D}usr/bin/smtpd.py"
268
269 # Fix the OPT variable so that it doesn't have any flags listed in it.
270 # Prevents the problem with compiling things with conflicting flags later.
271 sed -e "s:^OPT=.*:OPT=-DNDEBUG:" -i "${D}usr/$(get_libdir)/python${PYVER}/config/Makefile"
272
273 if use build; then
274 rm -fr "${D}usr/$(get_libdir)/python${PYVER}/"{bsddb,email,lib-tk,sqlite3,test}
275 else
276 use elibc_uclibc && rm -fr "${D}usr/$(get_libdir)/python${PYVER}/"{bsddb/test,test}
277 use berkdb || rm -fr "${D}usr/$(get_libdir)/python${PYVER}/"{bsddb,test/test_bsddb*}
278 use sqlite || rm -fr "${D}usr/$(get_libdir)/python${PYVER}/"{sqlite3,test/test_sqlite*}
279 use tk || rm -fr "${D}usr/$(get_libdir)/python${PYVER}/lib-tk"
280 fi
281
282 use threads || rm -fr "${D}usr/$(get_libdir)/python${PYVER}/multiprocessing"
283
284 prep_ml_includes usr/include/python${PYVER}
285
286 if use examples; then
287 insinto /usr/share/doc/${PF}/examples
288 doins -r "${S}/Tools" || die "doins failed"
289 fi
290
291 newinitd "${FILESDIR}/pydoc.init" pydoc-${SLOT}
292 newconfd "${FILESDIR}/pydoc.conf" pydoc-${SLOT}
293
294 # Don't install empty directory.
295 rmdir "${D}usr/$(get_libdir)/python${PYVER}/lib-old"
296}
297
298pkg_preinst() {
299 if has_version "<${CATEGORY}/${PN}-${SLOT}" && ! has_version ">=${CATEGORY}/${PN}-${SLOT}_alpha"; then
300 python_updater_warning="1"
301 fi
302}
303
304eselect_python_update() {
305 local ignored_python_slots_options=
306 [[ "$(eselect python show)" == "python2."* ]] && ignored_python_slots_options="--ignore 3.0 --ignore 3.1 --ignore 3.2"
307
308 # Create python2 symlink.
309 eselect python update --ignore 3.0 --ignore 3.1 --ignore 3.2 > /dev/null
310
311 eselect python update ${ignored_python_slots_options}
312}
313
314pkg_postinst() {
315 eselect_python_update
316
317 python_mod_optimize -x "(site-packages|test)" /usr/$(get_libdir)/python${PYVER}
318
319 if [[ "${python_updater_warning}" == "1" ]]; then
320 ewarn
321 ewarn "\e[1;31m************************************************************************\e[0m"
322 ewarn
323 ewarn "You have just upgraded from an older version of Python."
324 ewarn "You should run 'python-updater \${options}' to rebuild Python modules."
325 ewarn
326 ewarn "\e[1;31m************************************************************************\e[0m"
327 ewarn
328 ebeep 12
329 fi
330}
331
332pkg_postrm() {
333 eselect_python_update
334
335 python_mod_cleanup /usr/$(get_libdir)/python${PYVER}
336}