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