1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
9 inherit autotools eutils flag-o-matic multilib pax-utils python-utils-r1 toolchain-funcs multiprocessing
12 PATCHSET_VERSION="${PV}-0"
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"
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"
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.
30 RDEPEND="app-arch/bzip2
36 gdbm? ( sys-libs/gdbm[berkdb] )
38 >=sys-libs/ncurses-5.2
39 readline? ( >=sys-libs/readline-4.1 )
41 sqlite? ( >=dev-db/sqlite-3.3.8:3 )
42 ssl? ( dev-libs/openssl )
48 xml? ( >=dev-libs/expat-2.1 )
50 !!<sys-apps/sandbox-2.6-r1"
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"
60 S="${WORKDIR}/${MY_P}"
63 # Ensure that internal copies of expat, libffi and zlib are not used.
65 rm -fr Modules/_ctypes/libffi*
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"
73 EPATCH_SUFFIX="patch" epatch "${WORKDIR}/patches"
74 epatch "${FILESDIR}/${PN}-3.3.5-ncurses-pkg-config.patch"
76 sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
77 Lib/distutils/command/install.py \
78 Lib/distutils/sysconfig.py \
81 Lib/test/test_site.py \
85 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
88 sed -e "s/ABIFLAGS=\"\${ABIFLAGS}.*\"/:/" -i configure.ac || die "sed failed"
91 epatch "${FILESDIR}/${PN}-3.3-CVE-2014-4616.patch"
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"
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}"
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."
122 if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
123 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
126 if [[ "$(gcc-major-version)" -ge 4 ]]; then
130 filter-flags -malign-double
132 [[ "${ARCH}" == "alpha" ]] && append-flags -fPIC
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
140 # Export CXX so it ends up in /usr/lib/python3.X/config/Makefile.
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)
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!
153 dbmliborder+="${dbmliborder:+:}gdbm"
156 BUILD_DIR="${WORKDIR}/${CHOST}"
157 mkdir -p "${BUILD_DIR}" || die
158 cd "${BUILD_DIR}" || die
160 ECONF_SOURCE="${S}" OPT="" \
165 $(use_with threads) \
166 --infodir='${prefix}/share/info' \
167 --mandir='${prefix}/share/man' \
168 --with-computed-gotos \
169 --with-dbmliborder="${dbmliborder}" \
171 --enable-loadable-sqlite-extensions \
172 --with-system-expat \
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)"
183 # Avoid invoking pgen for cross-compiles.
184 touch Include/graminit.h Python/graminit.c || die
186 cd "${BUILD_DIR}" || die
187 emake CPPFLAGS="" CFLAGS="" LDFLAGS=""
189 # Work around bug 329499. See also bug 413751 and 457194.
190 if has_version dev-libs/libffi[pax_kernel]; then
198 # Tests will not work when cross compiling.
199 if tc-is-cross-compiler; then
200 elog "Disabling tests due to crosscompiling."
204 cd "${BUILD_DIR}" || die
206 # Skip failing tests.
207 local skipped_tests="gdb"
209 for test in ${skipped_tests}; do
210 mv "${S}"/Lib/test/test_${test}.py "${T}"
213 PYTHONDONTWRITEBYTECODE="" emake test EXTRATESTOPTS="-u -network" FLAGS="" CFLAGS="" LDFLAGS="" < /dev/tty
216 for test in ${skipped_tests}; do
217 mv "${T}/test_${test}.py" "${S}"/Lib/test
220 elog "The following tests have been skipped:"
221 for test in ${skipped_tests}; do
222 elog "test_${test}.py"
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."
229 if [[ "${result}" -ne 0 ]]; then
230 die "emake test failed"
235 local libdir=${ED}/usr/$(get_libdir)/python${SLOT}
237 cd "${BUILD_DIR}" || die
239 emake DESTDIR="${D}" altinstall
242 -e "s/\(CONFIGURE_LDFLAGS=\).*/\1/" \
243 -e "s/\(PY_LDFLAGS=\).*/\1/" \
244 -i "${libdir}/config-${SLOT}/Makefile" || die "sed failed"
246 # Backwards compat with Gentoo divergence.
247 dosym python${SLOT}-config /usr/bin/python-config-${SLOT}
249 # Fix collisions between different slots of Python.
250 rm -f "${ED}usr/$(get_libdir)/libpython3.so"
253 rm -fr "${ED}usr/bin/idle${SLOT}" "${libdir}/"{idlelib,sqlite3,test,tkinter}
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*}
260 use threads || rm -fr "${libdir}/multiprocessing"
261 use wininst || rm -f "${libdir}/distutils/command/"wininst-*.exe
263 dodoc "${S}"/Misc/{ACKS,HISTORY,NEWS}
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
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
275 newconfd "${FILESDIR}/pydoc.conf" pydoc-${SLOT}
276 newinitd "${FILESDIR}/pydoc.init" pydoc-${SLOT}
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"
283 python_export python${SLOT} EPYTHON PYTHON PYTHON_SITEDIR
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}:}.
291 echo "EPYTHON='${EPYTHON}'" > epython.py
292 python_domodule epython.py
296 if has_version "<${CATEGORY}/${PN}-${SLOT}" && ! has_version ">=${CATEGORY}/${PN}-${SLOT}_alpha"; then
297 python_updater_warning="1"
301 eselect_python_update() {
302 if [[ -z "$(eselect python show)" || ! -f "${EROOT}usr/bin/$(eselect python show)" ]]; then
303 eselect python update
306 if [[ -z "$(eselect python show --python${PV%%.*})" || ! -f "${EROOT}usr/bin/$(eselect python show --python${PV%%.*})" ]]; then
307 eselect python update --python${PV%%.*}
312 eselect_python_update
314 if [[ "${python_updater_warning}" == "1" ]]; then
315 ewarn "You have just upgraded from an older version of Python."
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."
319 ewarn "For legacy packages, you should switch active version of Python and run 'python-updater [options]' to rebuild Python modules."
324 eselect_python_update