Use https by default
[gentoo.git] / dev-lang / python / python-3.3.5-r1.ebuild
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI="4"
6 WANT_AUTOMAKE="none"
7 WANT_LIBTOOL="none"
8
9 inherit autotools eutils flag-o-matic multilib pax-utils python-utils-r1 toolchain-funcs multiprocessing
10
11 MY_P="Python-${PV}"
12 PATCHSET_VERSION="${PV}-0"
13
14 DESCRIPTION="An interpreted, interactive, object-oriented programming language"
15 HOMEPAGE="http://www.python.org/"
16 SRC_URI="http://www.python.org/ftp/python/${PV}/${MY_P}.tar.xz
17         https://dev.gentoo.org/~floppym/python/python-gentoo-patches-${PATCHSET_VERSION}.tar.xz
18         mirror://gentoo/python-gentoo-patches-${PATCHSET_VERSION}.tar.xz"
19
20 LICENSE="PSF-2"
21 SLOT="3.3"
22 KEYWORDS="alpha amd64 arm arm64 hppa ia64 m68k ~mips ppc ppc64 s390 sh sparc x86 ~amd64-fbsd ~sparc-fbsd ~x86-fbsd"
23 IUSE="build doc elibc_uclibc examples gdbm hardened ipv6 +ncurses +readline sqlite +ssl +threads tk wininst +xml"
24
25 # Do not add a dependency on dev-lang/python to this ebuild.
26 # If you need to apply a patch which requires python for bootstrapping, please
27 # run the bootstrap code on your dev box and include the results in the
28 # patchset. See bug 447752.
29
30 RDEPEND="app-arch/bzip2
31         app-arch/xz-utils
32         >=sys-libs/zlib-1.1.3
33         virtual/libffi
34         virtual/libintl
35         !build? (
36                 gdbm? ( sys-libs/gdbm[berkdb] )
37                 ncurses? (
38                         >=sys-libs/ncurses-5.2
39                         readline? ( >=sys-libs/readline-4.1 )
40                 )
41                 sqlite? ( >=dev-db/sqlite-3.3.8:3 )
42                 ssl? ( dev-libs/openssl )
43                 tk? (
44                         >=dev-lang/tk-8.0
45                         dev-tcltk/blt
46                         dev-tcltk/tix
47                 )
48                 xml? ( >=dev-libs/expat-2.1 )
49         )
50         !!<sys-apps/sandbox-2.6-r1"
51 DEPEND="${RDEPEND}
52         virtual/pkgconfig
53         >=sys-devel/autoconf-2.65
54         !sys-devel/gcc[libffi]"
55 RDEPEND+=" !build? ( app-misc/mime-types )
56         doc? ( dev-python/python-docs:${SLOT} )"
57 PDEPEND="app-eselect/eselect-python
58         app-admin/python-updater"
59
60 S="${WORKDIR}/${MY_P}"
61
62 src_prepare() {
63         # Ensure that internal copies of expat, libffi and zlib are not used.
64         rm -fr Modules/expat
65         rm -fr Modules/_ctypes/libffi*
66         rm -fr Modules/zlib
67
68         if tc-is-cross-compiler; then
69                 # Invokes BUILDPYTHON, which is built for the host arch
70                 local EPATCH_EXCLUDE="*_regenerate_platform-specific_modules.patch"
71         fi
72
73         EPATCH_SUFFIX="patch" epatch "${WORKDIR}/patches"
74         epatch "${FILESDIR}/${PN}-3.3.5-ncurses-pkg-config.patch"
75
76         sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
77                 Lib/distutils/command/install.py \
78                 Lib/distutils/sysconfig.py \
79                 Lib/site.py \
80                 Lib/sysconfig.py \
81                 Lib/test/test_site.py \
82                 Makefile.pre.in \
83                 Modules/Setup.dist \
84                 Modules/getpath.c \
85                 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
86
87         # Disable ABI flags.
88         sed -e "s/ABIFLAGS=\"\${ABIFLAGS}.*\"/:/" -i configure.ac || die "sed failed"
89
90         # bug #514686
91         epatch "${FILESDIR}/${PN}-3.3-CVE-2014-4616.patch"
92
93         epatch_user
94
95         eautoconf
96         eautoheader
97 }
98
99 src_configure() {
100         if use build; then
101                 # Disable extraneous modules with extra dependencies.
102                 export PYTHON_DISABLE_MODULES="gdbm _curses _curses_panel readline _sqlite3 _tkinter _elementtree pyexpat"
103                 export PYTHON_DISABLE_SSL="1"
104         else
105                 local disable
106                 use gdbm     || disable+=" gdbm"
107                 use ncurses  || disable+=" _curses _curses_panel"
108                 use readline || disable+=" readline"
109                 use sqlite   || disable+=" _sqlite3"
110                 use ssl      || export PYTHON_DISABLE_SSL="1"
111                 use tk       || disable+=" _tkinter"
112                 use xml      || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
113                 export PYTHON_DISABLE_MODULES="${disable}"
114
115                 if ! use xml; then
116                         ewarn "You have configured Python without XML support."
117                         ewarn "This is NOT a recommended configuration as you"
118                         ewarn "may face problems parsing any XML documents."
119                 fi
120         fi
121
122         if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
123                 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
124         fi
125
126         if [[ "$(gcc-major-version)" -ge 4 ]]; then
127                 append-flags -fwrapv
128         fi
129
130         filter-flags -malign-double
131
132         [[ "${ARCH}" == "alpha" ]] && append-flags -fPIC
133
134         # https://bugs.gentoo.org/show_bug.cgi?id=50309
135         if is-flagq -O3; then
136                 is-flagq -fstack-protector-all && replace-flags -O3 -O2
137                 use hardened && replace-flags -O3 -O2
138         fi
139
140         # Export CXX so it ends up in /usr/lib/python3.X/config/Makefile.
141         tc-export CXX
142         # The configure script fails to use pkg-config correctly.
143         # http://bugs.python.org/issue15506
144         export ac_cv_path_PKG_CONFIG=$(tc-getPKG_CONFIG)
145
146         # Set LDFLAGS so we link modules with -lpython3.2 correctly.
147         # Needed on FreeBSD unless Python 3.2 is already installed.
148         # Please query BSD team before removing this!
149         append-ldflags "-L."
150
151         local dbmliborder
152         if use gdbm; then
153                 dbmliborder+="${dbmliborder:+:}gdbm"
154         fi
155
156         BUILD_DIR="${WORKDIR}/${CHOST}"
157         mkdir -p "${BUILD_DIR}" || die
158         cd "${BUILD_DIR}" || die
159
160         ECONF_SOURCE="${S}" OPT="" \
161         econf \
162                 --with-fpectl \
163                 --enable-shared \
164                 $(use_enable ipv6) \
165                 $(use_with threads) \
166                 --infodir='${prefix}/share/info' \
167                 --mandir='${prefix}/share/man' \
168                 --with-computed-gotos \
169                 --with-dbmliborder="${dbmliborder}" \
170                 --with-libc="" \
171                 --enable-loadable-sqlite-extensions \
172                 --with-system-expat \
173                 --with-system-ffi
174
175         if use threads && grep -q "#define POSIX_SEMAPHORES_NOT_ENABLED 1" pyconfig.h; then
176                 eerror "configure has detected that the sem_open function is broken."
177                 eerror "Please ensure that /dev/shm is mounted as a tmpfs with mode 1777."
178                 die "Broken sem_open function (bug 496328)"
179         fi
180 }
181
182 src_compile() {
183         # Avoid invoking pgen for cross-compiles.
184         touch Include/graminit.h Python/graminit.c || die
185
186         cd "${BUILD_DIR}" || die
187         emake CPPFLAGS="" CFLAGS="" LDFLAGS=""
188
189         # Work around bug 329499. See also bug 413751 and 457194.
190         if has_version dev-libs/libffi[pax_kernel]; then
191                 pax-mark E python
192         else
193                 pax-mark m python
194         fi
195 }
196
197 src_test() {
198         # Tests will not work when cross compiling.
199         if tc-is-cross-compiler; then
200                 elog "Disabling tests due to crosscompiling."
201                 return
202         fi
203
204         cd "${BUILD_DIR}" || die
205
206         # Skip failing tests.
207         local skipped_tests="gdb"
208
209         for test in ${skipped_tests}; do
210                 mv "${S}"/Lib/test/test_${test}.py "${T}"
211         done
212
213         PYTHONDONTWRITEBYTECODE="" emake test EXTRATESTOPTS="-u -network" FLAGS="" CFLAGS="" LDFLAGS="" < /dev/tty
214         local result="$?"
215
216         for test in ${skipped_tests}; do
217                 mv "${T}/test_${test}.py" "${S}"/Lib/test
218         done
219
220         elog "The following tests have been skipped:"
221         for test in ${skipped_tests}; do
222                 elog "test_${test}.py"
223         done
224
225         elog "If you would like to run them, you may:"
226         elog "cd '${EPREFIX}/usr/$(get_libdir)/python${SLOT}/test'"
227         elog "and run the tests separately."
228
229         if [[ "${result}" -ne 0 ]]; then
230                 die "emake test failed"
231         fi
232 }
233
234 src_install() {
235         local libdir=${ED}/usr/$(get_libdir)/python${SLOT}
236
237         cd "${BUILD_DIR}" || die
238
239         emake DESTDIR="${D}" altinstall
240
241         sed \
242                 -e "s/\(CONFIGURE_LDFLAGS=\).*/\1/" \
243                 -e "s/\(PY_LDFLAGS=\).*/\1/" \
244                 -i "${libdir}/config-${SLOT}/Makefile" || die "sed failed"
245
246         # Backwards compat with Gentoo divergence.
247         dosym python${SLOT}-config /usr/bin/python-config-${SLOT}
248
249         # Fix collisions between different slots of Python.
250         rm -f "${ED}usr/$(get_libdir)/libpython3.so"
251
252         if use build; then
253                 rm -fr "${ED}usr/bin/idle${SLOT}" "${libdir}/"{idlelib,sqlite3,test,tkinter}
254         else
255                 use elibc_uclibc && rm -fr "${libdir}/test"
256                 use sqlite || rm -fr "${libdir}/"{sqlite3,test/test_sqlite*}
257                 use tk || rm -fr "${ED}usr/bin/idle${SLOT}" "${libdir}/"{idlelib,tkinter,test/test_tk*}
258         fi
259
260         use threads || rm -fr "${libdir}/multiprocessing"
261         use wininst || rm -f "${libdir}/distutils/command/"wininst-*.exe
262
263         dodoc "${S}"/Misc/{ACKS,HISTORY,NEWS}
264
265         if use examples; then
266                 insinto /usr/share/doc/${PF}/examples
267                 find "${S}"/Tools -name __pycache__ -print0 | xargs -0 rm -fr
268                 doins -r "${S}"/Tools
269         fi
270         insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
271         local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \
272                 emake --no-print-directory -s -f - 2>/dev/null)
273         newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py
274
275         newconfd "${FILESDIR}/pydoc.conf" pydoc-${SLOT}
276         newinitd "${FILESDIR}/pydoc.init" pydoc-${SLOT}
277         sed \
278                 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${SLOT/./_}_PORT:" \
279                 -e "s:@PYDOC@:pydoc${SLOT}:" \
280                 -i "${ED}etc/conf.d/pydoc-${SLOT}" "${ED}etc/init.d/pydoc-${SLOT}" || die "sed failed"
281
282         # for python-exec
283         python_export python${SLOT} EPYTHON PYTHON PYTHON_SITEDIR
284
285         # if not using a cross-compiler, use the fresh binary
286         if ! tc-is-cross-compiler; then
287                 local PYTHON=./python
288                 local -x LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}.
289         fi
290
291         echo "EPYTHON='${EPYTHON}'" > epython.py
292         python_domodule epython.py
293 }
294
295 pkg_preinst() {
296         if has_version "<${CATEGORY}/${PN}-${SLOT}" && ! has_version ">=${CATEGORY}/${PN}-${SLOT}_alpha"; then
297                 python_updater_warning="1"
298         fi
299 }
300
301 eselect_python_update() {
302         if [[ -z "$(eselect python show)" || ! -f "${EROOT}usr/bin/$(eselect python show)" ]]; then
303                 eselect python update
304         fi
305
306         if [[ -z "$(eselect python show --python${PV%%.*})" || ! -f "${EROOT}usr/bin/$(eselect python show --python${PV%%.*})" ]]; then
307                 eselect python update --python${PV%%.*}
308         fi
309 }
310
311 pkg_postinst() {
312         eselect_python_update
313
314         if [[ "${python_updater_warning}" == "1" ]]; then
315                 ewarn "You have just upgraded from an older version of Python."
316                 ewarn
317                 ewarn "Please adjust PYTHON_TARGETS (if so desired), and run emerge with the --newuse or --changed-use option to rebuild packages installing python modules."
318                 ewarn
319                 ewarn "For legacy packages, you should switch active version of Python and run 'python-updater [options]' to rebuild Python modules."
320         fi
321 }
322
323 pkg_postrm() {
324         eselect_python_update
325 }