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
11 MY_P="Python-${PV/_/}"
12 PATCHSET_VERSION="3.4.2-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%_rc*}/${MY_P}.tar.xz
17 https://dev.gentoo.org/~floppym/python/python-gentoo-patches-${PATCHSET_VERSION}.tar.xz"
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"
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.
29 RDEPEND="app-arch/bzip2
35 gdbm? ( sys-libs/gdbm[berkdb] )
37 >=sys-libs/ncurses-5.2
38 readline? ( >=sys-libs/readline-4.1 )
40 sqlite? ( >=dev-db/sqlite-3.3.8:3 )
41 ssl? ( dev-libs/openssl )
47 xml? ( >=dev-libs/expat-2.1 )
49 !!<sys-apps/sandbox-2.6-r1"
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"
58 S="${WORKDIR}/${MY_P}"
61 # Ensure that internal copies of expat, libffi and zlib are not used.
63 rm -fr Modules/_ctypes/libffi*
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"
71 EPATCH_SUFFIX="patch" epatch "${WORKDIR}/patches"
73 sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
74 Lib/distutils/command/install.py \
75 Lib/distutils/sysconfig.py \
78 Lib/test/test_site.py \
82 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
85 sed -e "s/ABIFLAGS=\"\${ABIFLAGS}.*\"/:/" -i configure.ac || die "sed failed"
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"
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}"
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."
116 if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
117 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
120 if [[ "$(gcc-major-version)" -ge 4 ]]; then
124 filter-flags -malign-double
126 [[ "${ARCH}" == "alpha" ]] && append-flags -fPIC
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
134 # Export CXX so it ends up in /usr/lib/python3.X/config/Makefile.
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)
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!
147 dbmliborder+="${dbmliborder:+:}gdbm"
150 BUILD_DIR="${WORKDIR}/${CHOST}"
151 mkdir -p "${BUILD_DIR}" || die
152 cd "${BUILD_DIR}" || die
154 ECONF_SOURCE="${S}" OPT="" \
159 $(use_with threads) \
160 --infodir='${prefix}/share/info' \
161 --mandir='${prefix}/share/man' \
162 --with-computed-gotos \
163 --with-dbmliborder="${dbmliborder}" \
165 --enable-loadable-sqlite-extensions \
166 --with-system-expat \
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)"
178 # Avoid invoking pgen for cross-compiles.
179 touch Include/graminit.h Python/graminit.c || die
181 cd "${BUILD_DIR}" || die
182 emake CPPFLAGS="" CFLAGS="" LDFLAGS=""
184 # Work around bug 329499. See also bug 413751 and 457194.
185 if has_version dev-libs/libffi[pax_kernel]; then
193 # Tests will not work when cross compiling.
194 if tc-is-cross-compiler; then
195 elog "Disabling tests due to crosscompiling."
199 cd "${BUILD_DIR}" || die
201 # Skip failing tests.
202 local skipped_tests="gdb"
204 for test in ${skipped_tests}; do
205 mv "${S}"/Lib/test/test_${test}.py "${T}"
208 local -x PYTHONDONTWRITEBYTECODE=
209 emake test EXTRATESTOPTS="-u-network" CPPFLAGS= CFLAGS= LDFLAGS= < /dev/tty
212 for test in ${skipped_tests}; do
213 mv "${T}/test_${test}.py" "${S}"/Lib/test
216 elog "The following tests have been skipped:"
217 for test in ${skipped_tests}; do
218 elog "test_${test}.py"
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."
225 if [[ ${result} -ne 0 ]]; then
226 die "emake test failed"
231 local libdir=${ED}/usr/$(get_libdir)/python${SLOT}
233 cd "${BUILD_DIR}" || die
235 emake DESTDIR="${D}" altinstall
238 -e "s/\(CONFIGURE_LDFLAGS=\).*/\1/" \
239 -e "s/\(PY_LDFLAGS=\).*/\1/" \
240 -i "${libdir}/config-${SLOT}/Makefile" || die "sed failed"
242 # Backwards compat with Gentoo divergence.
243 dosym python${SLOT}-config /usr/bin/python-config-${SLOT}
245 # Fix collisions between different slots of Python.
246 rm -f "${ED}usr/$(get_libdir)/libpython3.so"
249 rm -fr "${ED}usr/bin/idle${SLOT}" "${libdir}/"{idlelib,sqlite3,test,tkinter}
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*}
256 use threads || rm -fr "${libdir}/multiprocessing"
257 use wininst || rm -f "${libdir}/distutils/command/"wininst-*.exe
259 dodoc "${S}"/Misc/{ACKS,HISTORY,NEWS}
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
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
271 newconfd "${FILESDIR}/pydoc.conf" pydoc-${SLOT}
272 newinitd "${FILESDIR}/pydoc.init" pydoc-${SLOT}
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"
279 python_export python${SLOT} EPYTHON PYTHON PYTHON_SITEDIR
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}:}.
287 echo "EPYTHON='${EPYTHON}'" > epython.py
288 python_domodule epython.py
292 if has_version "<${CATEGORY}/${PN}-${SLOT}" && ! has_version ">=${CATEGORY}/${PN}-${SLOT}_alpha"; then
293 python_updater_warning="1"
297 eselect_python_update() {
298 if [[ -z "$(eselect python show)" || ! -f "${EROOT}usr/bin/$(eselect python show)" ]]; then
299 eselect python update
302 if [[ -z "$(eselect python show --python${PV%%.*})" || ! -f "${EROOT}usr/bin/$(eselect python show --python${PV%%.*})" ]]; then
303 eselect python update --python${PV%%.*}
308 eselect_python_update
310 if [[ "${python_updater_warning}" == "1" ]]; then
311 ewarn "You have just upgraded from an older version of Python."
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."
318 eselect_python_update