1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
8 inherit autotools eutils flag-o-matic multilib pax-utils python-utils-r1 toolchain-funcs multiprocessing
10 MY_P="Python-${PV/_/}"
11 PATCHSET_VERSION="3.4.3-0"
13 DESCRIPTION="An interpreted, interactive, object-oriented programming language"
14 HOMEPAGE="http://www.python.org/"
15 SRC_URI="http://www.python.org/ftp/python/${PV%_rc*}/${MY_P}.tar.xz
16 https://dev.gentoo.org/~floppym/python/python-gentoo-patches-${PATCHSET_VERSION}.tar.xz"
20 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~amd64-fbsd ~sparc-fbsd ~x86-fbsd"
21 IUSE="build elibc_uclibc examples gdbm hardened ipv6 libressl +ncurses +readline sqlite +ssl +threads tk wininst +xml"
23 # Do not add a dependency on dev-lang/python to this ebuild.
24 # If you need to apply a patch which requires python for bootstrapping, please
25 # run the bootstrap code on your dev box and include the results in the
26 # patchset. See bug 447752.
28 RDEPEND="app-arch/bzip2:0=
30 >=sys-libs/zlib-1.1.3:0=
33 gdbm? ( sys-libs/gdbm:0=[berkdb] )
35 >=sys-libs/ncurses-5.2:0=
36 readline? ( >=sys-libs/readline-4.1:0= )
38 sqlite? ( >=dev-db/sqlite-3.3.8:3= )
40 !libressl? ( dev-libs/openssl:0= )
41 libressl? ( dev-libs/libressl:= )
49 xml? ( >=dev-libs/expat-2.1:0= )
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 PDEPEND=">=app-eselect/eselect-python-20140125-r1"
58 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.4.3-ncurses-pkg-config.patch"
75 epatch "${FILESDIR}/${PN}-3.4-gcc-5.patch" #547626
79 sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
80 Lib/distutils/command/install.py \
81 Lib/distutils/sysconfig.py \
84 Lib/test/test_site.py \
88 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
95 use gdbm || disable+=" gdbm"
96 use ncurses || disable+=" _curses _curses_panel"
97 use readline || disable+=" readline"
98 use sqlite || disable+=" _sqlite3"
99 use ssl || export PYTHON_DISABLE_SSL="1"
100 use tk || disable+=" _tkinter"
101 use xml || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
102 export PYTHON_DISABLE_MODULES="${disable}"
105 ewarn "You have configured Python without XML support."
106 ewarn "This is NOT a recommended configuration as you"
107 ewarn "may face problems parsing any XML documents."
110 if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
111 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
114 if [[ "$(gcc-major-version)" -ge 4 ]]; then
118 filter-flags -malign-double
120 # https://bugs.gentoo.org/show_bug.cgi?id=50309
121 if is-flagq -O3; then
122 is-flagq -fstack-protector-all && replace-flags -O3 -O2
123 use hardened && replace-flags -O3 -O2
126 # Export CXX so it ends up in /usr/lib/python3.X/config/Makefile.
129 # The configure script fails to use pkg-config correctly.
130 # http://bugs.python.org/issue15506
131 export ac_cv_path_PKG_CONFIG=$(tc-getPKG_CONFIG)
133 # Set LDFLAGS so we link modules with -lpython3.2 correctly.
134 # Needed on FreeBSD unless Python 3.2 is already installed.
135 # Please query BSD team before removing this!
140 dbmliborder+="${dbmliborder:+:}gdbm"
143 BUILD_DIR="${WORKDIR}/${CHOST}"
144 mkdir -p "${BUILD_DIR}" || die
145 cd "${BUILD_DIR}" || die
147 ECONF_SOURCE="${S}" OPT="" \
152 $(use_with threads) \
153 --infodir='${prefix}/share/info' \
154 --mandir='${prefix}/share/man' \
155 --with-computed-gotos \
156 --with-dbmliborder="${dbmliborder}" \
158 --enable-loadable-sqlite-extensions \
159 --with-system-expat \
163 if use threads && grep -q "#define POSIX_SEMAPHORES_NOT_ENABLED 1" pyconfig.h; then
164 eerror "configure has detected that the sem_open function is broken."
165 eerror "Please ensure that /dev/shm is mounted as a tmpfs with mode 1777."
166 die "Broken sem_open function (bug 496328)"
171 # Avoid invoking pgen for cross-compiles.
172 touch Include/graminit.h Python/graminit.c || die
174 cd "${BUILD_DIR}" || die
176 emake CPPFLAGS= CFLAGS= LDFLAGS=
178 # Work around bug 329499. See also bug 413751 and 457194.
179 if has_version dev-libs/libffi[pax_kernel]; then
187 # Tests will not work when cross compiling.
188 if tc-is-cross-compiler; then
189 elog "Disabling tests due to crosscompiling."
193 cd "${BUILD_DIR}" || die
195 # Skip failing tests.
196 local skipped_tests="gdb"
198 for test in ${skipped_tests}; do
199 mv "${S}"/Lib/test/test_${test}.py "${T}"
202 local -x PYTHONDONTWRITEBYTECODE=
203 emake test EXTRATESTOPTS="-u-network" CPPFLAGS= CFLAGS= LDFLAGS= < /dev/tty
206 for test in ${skipped_tests}; do
207 mv "${T}/test_${test}.py" "${S}"/Lib/test
210 elog "The following tests have been skipped:"
211 for test in ${skipped_tests}; do
212 elog "test_${test}.py"
215 elog "If you would like to run them, you may:"
216 elog "cd '${EPREFIX}/usr/$(get_libdir)/python${PYVER}/test'"
217 elog "and run the tests separately."
219 if [[ ${result} -ne 0 ]]; then
220 die "emake test failed"
225 local libdir=${ED}/usr/$(get_libdir)/python${PYVER}
227 cd "${BUILD_DIR}" || die
229 emake DESTDIR="${D}" altinstall
232 -e "s/\(CONFIGURE_LDFLAGS=\).*/\1/" \
233 -e "s/\(PY_LDFLAGS=\).*/\1/" \
234 -i "${libdir}/config-${PYVER}"*/Makefile || die "sed failed"
236 # Fix collisions between different slots of Python.
237 rm -f "${ED}usr/$(get_libdir)/libpython3.so"
239 # Cheap hack to get version with ABIFLAGS
240 local abiver=$(cd "${ED}usr/include"; echo python*)
241 if [[ ${abiver} != python${PYVER} ]]; then
242 # Replace python3.X with a symlink to python3.Xm
243 rm "${ED}usr/bin/python${PYVER}" || die
244 dosym "${abiver}" "/usr/bin/python${PYVER}"
245 # Create python3.X-config symlink
246 dosym "${abiver}-config" "/usr/bin/python${PYVER}-config"
247 # Create python-3.5m.pc symlink
248 dosym "python-${PYVER}.pc" "/usr/$(get_libdir)/pkgconfig/${abiver/${PYVER}/-${PYVER}}.pc"
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${PYVER}" "${libdir}/"{idlelib,tkinter,test/test_tk*}
255 use threads || rm -fr "${libdir}/multiprocessing"
256 use wininst || rm -f "${libdir}/distutils/command/"wininst-*.exe
258 dodoc "${S}"/Misc/{ACKS,HISTORY,NEWS}
260 if use examples; then
261 insinto /usr/share/doc/${PF}/examples
262 find "${S}"/Tools -name __pycache__ -print0 | xargs -0 rm -fr
263 doins -r "${S}"/Tools
265 insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
266 local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \
267 emake --no-print-directory -s -f - 2>/dev/null)
268 newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py
270 newconfd "${FILESDIR}/pydoc.conf" pydoc-${PYVER}
271 newinitd "${FILESDIR}/pydoc.init" pydoc-${PYVER}
273 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${PYVER/./_}_PORT:" \
274 -e "s:@PYDOC@:pydoc${PYVER}:" \
275 -i "${ED}etc/conf.d/pydoc-${PYVER}" "${ED}etc/init.d/pydoc-${PYVER}" || die "sed failed"
278 local vars=( EPYTHON PYTHON_SITEDIR PYTHON_SCRIPTDIR )
280 # if not using a cross-compiler, use the fresh binary
281 if ! tc-is-cross-compiler; then
282 local -x PYTHON=./python
283 local -x LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}.
285 vars=( PYTHON "${vars[@]}" )
288 python_export "python${PYVER}" "${vars[@]}"
289 echo "EPYTHON='${EPYTHON}'" > epython.py || die
290 python_domodule epython.py
292 # python-exec wrapping support
293 local pymajor=${PYVER%.*}
294 mkdir -p "${D}${PYTHON_SCRIPTDIR}" || die
296 ln -s "../../../bin/${abiver}" \
297 "${D}${PYTHON_SCRIPTDIR}/python${pymajor}" || die
298 ln -s "python${pymajor}" \
299 "${D}${PYTHON_SCRIPTDIR}/python" || die
300 # python-config and pythonX-config
301 # note: we need to create a wrapper rather than symlinking it due
302 # to some random dirname(argv[0]) magic performed by python-config
303 cat > "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" <<-EOF || die
305 exec "${abiver}-config" "\${@}"
307 chmod +x "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" || die
308 ln -s "python${pymajor}-config" \
309 "${D}${PYTHON_SCRIPTDIR}/python-config" || die
310 # 2to3, pydoc, pyvenv
311 ln -s "../../../bin/2to3-${PYVER}" \
312 "${D}${PYTHON_SCRIPTDIR}/2to3" || die
313 ln -s "../../../bin/pydoc${PYVER}" \
314 "${D}${PYTHON_SCRIPTDIR}/pydoc" || die
315 ln -s "../../../bin/pyvenv-${PYVER}" \
316 "${D}${PYTHON_SCRIPTDIR}/pyvenv" || die
319 ln -s "../../../bin/idle${PYVER}" \
320 "${D}${PYTHON_SCRIPTDIR}/idle" || die
325 if has_version "<${CATEGORY}/${PN}-${PYVER}" && ! has_version ">=${CATEGORY}/${PN}-${PYVER}_alpha"; then
326 python_updater_warning="1"
330 eselect_python_update() {
331 if [[ -z "$(eselect python show)" || ! -f "${EROOT}usr/bin/$(eselect python show)" ]]; then
332 eselect python update
335 if [[ -z "$(eselect python show --python${PV%%.*})" || ! -f "${EROOT}usr/bin/$(eselect python show --python${PV%%.*})" ]]; then
336 eselect python update --python${PV%%.*}
341 eselect_python_update
343 if [[ "${python_updater_warning}" == "1" ]]; then
344 ewarn "You have just upgraded from an older version of Python."
346 ewarn "Please adjust PYTHON_TARGETS (if so desired), and run emerge with the --newuse or --changed-use option to rebuild packages installing python modules."
351 eselect_python_update