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.5-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.5-cross.patch"
79 sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
81 Lib/distutils/command/install.py \
82 Lib/distutils/sysconfig.py \
85 Lib/test/test_site.py \
89 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
96 use gdbm || disable+=" gdbm"
97 use ncurses || disable+=" _curses _curses_panel"
98 use readline || disable+=" readline"
99 use sqlite || disable+=" _sqlite3"
100 use ssl || export PYTHON_DISABLE_SSL="1"
101 use tk || disable+=" _tkinter"
102 use xml || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
103 export PYTHON_DISABLE_MODULES="${disable}"
106 ewarn "You have configured Python without XML support."
107 ewarn "This is NOT a recommended configuration as you"
108 ewarn "may face problems parsing any XML documents."
111 if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
112 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
115 if [[ "$(gcc-major-version)" -ge 4 ]]; then
119 filter-flags -malign-double
121 # https://bugs.gentoo.org/show_bug.cgi?id=50309
122 if is-flagq -O3; then
123 is-flagq -fstack-protector-all && replace-flags -O3 -O2
124 use hardened && replace-flags -O3 -O2
127 # Export CXX so it ends up in /usr/lib/python3.X/config/Makefile.
130 # The configure script fails to use pkg-config correctly.
131 # http://bugs.python.org/issue15506
132 export ac_cv_path_PKG_CONFIG=$(tc-getPKG_CONFIG)
134 # Set LDFLAGS so we link modules with -lpython3.2 correctly.
135 # Needed on FreeBSD unless Python 3.2 is already installed.
136 # Please query BSD team before removing this!
141 dbmliborder+="${dbmliborder:+:}gdbm"
144 BUILD_DIR="${WORKDIR}/${CHOST}"
145 mkdir -p "${BUILD_DIR}" || die
146 cd "${BUILD_DIR}" || die
148 ECONF_SOURCE="${S}" OPT="" \
153 $(use_with threads) \
154 --infodir='${prefix}/share/info' \
155 --mandir='${prefix}/share/man' \
156 --with-computed-gotos \
157 --with-dbmliborder="${dbmliborder}" \
159 --enable-loadable-sqlite-extensions \
160 --with-system-expat \
164 if use threads && grep -q "#define POSIX_SEMAPHORES_NOT_ENABLED 1" pyconfig.h; then
165 eerror "configure has detected that the sem_open function is broken."
166 eerror "Please ensure that /dev/shm is mounted as a tmpfs with mode 1777."
167 die "Broken sem_open function (bug 496328)"
172 # Ensure sed works as expected
173 # https://bugs.gentoo.org/594768
176 # Avoid invoking pgen for cross-compiles.
177 touch Include/graminit.h Python/graminit.c || die
179 cd "${BUILD_DIR}" || die
181 emake CPPFLAGS= CFLAGS= LDFLAGS=
183 # Work around bug 329499. See also bug 413751 and 457194.
184 if has_version dev-libs/libffi[pax_kernel]; then
192 # Tests will not work when cross compiling.
193 if tc-is-cross-compiler; then
194 elog "Disabling tests due to crosscompiling."
198 cd "${BUILD_DIR}" || die
200 # Skip failing tests.
201 local skipped_tests="gdb"
203 for test in ${skipped_tests}; do
204 mv "${S}"/Lib/test/test_${test}.py "${T}"
207 local -x PYTHONDONTWRITEBYTECODE=
208 emake test EXTRATESTOPTS="-u-network" CPPFLAGS= CFLAGS= LDFLAGS= < /dev/tty
211 for test in ${skipped_tests}; do
212 mv "${T}/test_${test}.py" "${S}"/Lib/test
215 elog "The following tests have been skipped:"
216 for test in ${skipped_tests}; do
217 elog "test_${test}.py"
220 elog "If you would like to run them, you may:"
221 elog "cd '${EPREFIX}/usr/$(get_libdir)/python${PYVER}/test'"
222 elog "and run the tests separately."
224 if [[ ${result} -ne 0 ]]; then
225 die "emake test failed"
230 local libdir=${ED}/usr/$(get_libdir)/python${PYVER}
232 cd "${BUILD_DIR}" || die
234 emake DESTDIR="${D}" altinstall
237 -e "s/\(CONFIGURE_LDFLAGS=\).*/\1/" \
238 -e "s/\(PY_LDFLAGS=\).*/\1/" \
239 -i "${libdir}/config-${PYVER}"*/Makefile || die "sed failed"
241 # Fix collisions between different slots of Python.
242 rm -f "${ED}usr/$(get_libdir)/libpython3.so"
244 # Cheap hack to get version with ABIFLAGS
245 local abiver=$(cd "${ED}usr/include"; echo python*)
246 if [[ ${abiver} != python${PYVER} ]]; then
247 # Replace python3.X with a symlink to python3.Xm
248 rm "${ED}usr/bin/python${PYVER}" || die
249 dosym "${abiver}" "/usr/bin/python${PYVER}"
250 # Create python3.X-config symlink
251 dosym "${abiver}-config" "/usr/bin/python${PYVER}-config"
252 # Create python-3.5m.pc symlink
253 dosym "python-${PYVER}.pc" "/usr/$(get_libdir)/pkgconfig/${abiver/${PYVER}/-${PYVER}}.pc"
256 use elibc_uclibc && rm -fr "${libdir}/test"
257 use sqlite || rm -fr "${libdir}/"{sqlite3,test/test_sqlite*}
258 use tk || rm -fr "${ED}usr/bin/idle${PYVER}" "${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-${PYVER}
276 newinitd "${FILESDIR}/pydoc.init" pydoc-${PYVER}
278 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${PYVER/./_}_PORT:" \
279 -e "s:@PYDOC@:pydoc${PYVER}:" \
280 -i "${ED}etc/conf.d/pydoc-${PYVER}" "${ED}etc/init.d/pydoc-${PYVER}" || die "sed failed"
283 local vars=( EPYTHON PYTHON_SITEDIR PYTHON_SCRIPTDIR )
285 # if not using a cross-compiler, use the fresh binary
286 if ! tc-is-cross-compiler; then
287 local -x PYTHON=./python
288 local -x LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}.
290 vars=( PYTHON "${vars[@]}" )
293 python_export "python${PYVER}" "${vars[@]}"
294 echo "EPYTHON='${EPYTHON}'" > epython.py || die
295 python_domodule epython.py
297 # python-exec wrapping support
298 local pymajor=${PYVER%.*}
299 mkdir -p "${D}${PYTHON_SCRIPTDIR}" || die
301 ln -s "../../../bin/${abiver}" \
302 "${D}${PYTHON_SCRIPTDIR}/python${pymajor}" || die
303 ln -s "python${pymajor}" \
304 "${D}${PYTHON_SCRIPTDIR}/python" || die
305 # python-config and pythonX-config
306 # note: we need to create a wrapper rather than symlinking it due
307 # to some random dirname(argv[0]) magic performed by python-config
308 cat > "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" <<-EOF || die
310 exec "${abiver}-config" "\${@}"
312 chmod +x "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" || die
313 ln -s "python${pymajor}-config" \
314 "${D}${PYTHON_SCRIPTDIR}/python-config" || die
315 # 2to3, pydoc, pyvenv
316 ln -s "../../../bin/2to3-${PYVER}" \
317 "${D}${PYTHON_SCRIPTDIR}/2to3" || die
318 ln -s "../../../bin/pydoc${PYVER}" \
319 "${D}${PYTHON_SCRIPTDIR}/pydoc" || die
320 ln -s "../../../bin/pyvenv-${PYVER}" \
321 "${D}${PYTHON_SCRIPTDIR}/pyvenv" || die
324 ln -s "../../../bin/idle${PYVER}" \
325 "${D}${PYTHON_SCRIPTDIR}/idle" || die
330 if has_version "<${CATEGORY}/${PN}-${PYVER}" && ! has_version ">=${CATEGORY}/${PN}-${PYVER}_alpha"; then
331 python_updater_warning="1"
335 eselect_python_update() {
336 if [[ -z "$(eselect python show)" || ! -f "${EROOT}usr/bin/$(eselect python show)" ]]; then
337 eselect python update
340 if [[ -z "$(eselect python show --python${PV%%.*})" || ! -f "${EROOT}usr/bin/$(eselect python show --python${PV%%.*})" ]]; then
341 eselect python update --python${PV%%.*}
346 eselect_python_update
348 if [[ "${python_updater_warning}" == "1" ]]; then
349 ewarn "You have just upgraded from an older version of Python."
351 ewarn "Please adjust PYTHON_TARGETS (if so desired), and run emerge with the --newuse or --changed-use option to rebuild packages installing python modules."
356 eselect_python_update