1 # Copyright 1999-2015 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
11 PATCHSET_VERSION="2.7.10-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}/${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="-berkdb build doc elibc_uclibc examples gdbm hardened ipv6 +ncurses +readline sqlite +ssl +threads tk +wide-unicode 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
46 gdbm? ( sys-libs/gdbm[berkdb] )
48 >=sys-libs/ncurses-5.2
49 readline? ( >=sys-libs/readline-4.1 )
51 sqlite? ( >=dev-db/sqlite-3.3.8:3 )
52 ssl? ( dev-libs/openssl )
58 xml? ( >=dev-libs/expat-2.1 )
60 !!<sys-apps/portage-2.1.9"
63 >=sys-devel/autoconf-2.65
64 !sys-devel/gcc[libffi]"
65 RDEPEND+=" !build? ( app-misc/mime-types )
66 doc? ( dev-python/python-docs:${SLOT} )"
67 PDEPEND="app-eselect/eselect-python
68 app-admin/python-updater"
70 S="${WORKDIR}/${MY_P}"
74 ewarn "'bsddb' module is out-of-date and no longer maintained inside"
75 ewarn "dev-lang/python. 'bsddb' and 'dbhash' modules have been additionally"
76 ewarn "removed in Python 3. A maintained alternative of 'bsddb3' module"
77 ewarn "is provided by dev-python/bsddb3."
79 if has_version "=${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"; then
80 ewarn "You are migrating from =${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"
81 ewarn "to =${CATEGORY}/${PN}-${PV%%.*}*[-berkdb]."
82 ewarn "You might need to migrate your databases."
88 # Ensure that internal copies of expat, libffi and zlib are not used.
89 rm -r Modules/expat || die
90 rm -r Modules/_ctypes/libffi* || die
91 rm -r Modules/zlib || die
93 if tc-is-cross-compiler; then
94 local EPATCH_EXCLUDE="*_regenerate_platform-specific_modules.patch"
97 EPATCH_SUFFIX="patch" epatch "${WORKDIR}/patches"
99 # Fix for cross-compiling.
100 epatch "${FILESDIR}/python-2.7.5-nonfatal-compileall.patch"
101 epatch "${FILESDIR}/python-2.7.9-ncurses-pkg-config.patch"
103 sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
104 Lib/distutils/command/install.py \
105 Lib/distutils/sysconfig.py \
108 Lib/test/test_site.py \
112 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
121 # Disable extraneous modules with extra dependencies.
122 export PYTHON_DISABLE_MODULES="dbm _bsddb gdbm _curses _curses_panel readline _sqlite3 _tkinter _elementtree pyexpat"
123 export PYTHON_DISABLE_SSL="1"
125 # dbm module can be linked against berkdb or gdbm.
126 # Defaults to gdbm when both are enabled, #204343.
128 use berkdb || use gdbm || disable+=" dbm"
129 use berkdb || disable+=" _bsddb"
130 use gdbm || disable+=" gdbm"
131 use ncurses || disable+=" _curses _curses_panel"
132 use readline || disable+=" readline"
133 use sqlite || disable+=" _sqlite3"
134 use ssl || export PYTHON_DISABLE_SSL="1"
135 use tk || disable+=" _tkinter"
136 use xml || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
137 export PYTHON_DISABLE_MODULES="${disable}"
140 ewarn "You have configured Python without XML support."
141 ewarn "This is NOT a recommended configuration as you"
142 ewarn "may face problems parsing any XML documents."
146 if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
147 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
150 if [[ "$(gcc-major-version)" -ge 4 ]]; then
154 filter-flags -malign-double
156 [[ "${ARCH}" == "alpha" ]] && append-flags -fPIC
158 # https://bugs.gentoo.org/show_bug.cgi?id=50309
159 if is-flagq -O3; then
160 is-flagq -fstack-protector-all && replace-flags -O3 -O2
161 use hardened && replace-flags -O3 -O2
164 if tc-is-cross-compiler; then
165 # Force some tests that try to poke fs paths.
166 export ac_cv_file__dev_ptc=no
167 export ac_cv_file__dev_ptmx=yes
170 # Export CXX so it ends up in /usr/lib/python2.X/config/Makefile.
172 # The configure script fails to use pkg-config correctly.
173 # http://bugs.python.org/issue15506
174 export ac_cv_path_PKG_CONFIG=$(tc-getPKG_CONFIG)
176 # Set LDFLAGS so we link modules with -lpython2.7 correctly.
177 # Needed on FreeBSD unless Python 2.7 is already installed.
178 # Please query BSD team before removing this!
183 dbmliborder+="${dbmliborder:+:}gdbm"
186 dbmliborder+="${dbmliborder:+:}bdb"
189 BUILD_DIR="${WORKDIR}/${CHOST}"
190 mkdir -p "${BUILD_DIR}" || die
191 cd "${BUILD_DIR}" || die
193 ECONF_SOURCE="${S}" OPT="" \
198 $(use_with threads) \
199 $(use wide-unicode && echo "--enable-unicode=ucs4" || echo "--enable-unicode=ucs2") \
200 --infodir='${prefix}/share/info' \
201 --mandir='${prefix}/share/man' \
202 --with-dbmliborder="${dbmliborder}" \
204 --enable-loadable-sqlite-extensions \
205 --with-system-expat \
209 if use threads && grep -q "#define POSIX_SEMAPHORES_NOT_ENABLED 1" pyconfig.h; then
210 eerror "configure has detected that the sem_open function is broken."
211 eerror "Please ensure that /dev/shm is mounted as a tmpfs with mode 1777."
212 die "Broken sem_open function (bug 496328)"
217 # Avoid invoking pgen for cross-compiles.
218 touch Include/graminit.h Python/graminit.c
220 cd "${BUILD_DIR}" || die
223 # Work around bug 329499. See also bug 413751 and 457194.
224 if has_version dev-libs/libffi[pax_kernel]; then
232 # Tests will not work when cross compiling.
233 if tc-is-cross-compiler; then
234 elog "Disabling tests due to crosscompiling."
238 cd "${BUILD_DIR}" || die
240 # Skip failing tests.
241 local skipped_tests="distutils gdb"
243 for test in ${skipped_tests}; do
244 mv "${S}"/Lib/test/test_${test}.py "${T}"
247 # Rerun failed tests in verbose mode (regrtest -w).
248 emake test EXTRATESTOPTS="-w" < /dev/tty
251 for test in ${skipped_tests}; do
252 mv "${T}/test_${test}.py" "${S}"/Lib/test
255 elog "The following tests have been skipped:"
256 for test in ${skipped_tests}; do
257 elog "test_${test}.py"
260 elog "If you would like to run them, you may:"
261 elog "cd '${EPREFIX}/usr/$(get_libdir)/python${SLOT}/test'"
262 elog "and run the tests separately."
264 if [[ "${result}" -ne 0 ]]; then
265 die "emake test failed"
270 local libdir=${ED}/usr/$(get_libdir)/python${SLOT}
272 cd "${BUILD_DIR}" || die
273 emake DESTDIR="${D}" altinstall
275 sed -e "s/\(LDFLAGS=\).*/\1/" -i "${libdir}/config/Makefile" || die "sed failed"
277 # Backwards compat with Gentoo divergence.
278 dosym python${SLOT}-config /usr/bin/python-config-${SLOT}
280 # Fix collisions between different slots of Python.
281 mv "${ED}usr/bin/2to3" "${ED}usr/bin/2to3-${SLOT}"
282 mv "${ED}usr/bin/pydoc" "${ED}usr/bin/pydoc${SLOT}"
283 mv "${ED}usr/bin/idle" "${ED}usr/bin/idle${SLOT}"
284 rm -f "${ED}usr/bin/smtpd.py"
287 rm -fr "${ED}usr/bin/idle${SLOT}" "${libdir}/"{bsddb,dbhash.py,idlelib,lib-tk,sqlite3,test}
289 use berkdb || rm -r "${libdir}/"{bsddb,dbhash.py,test/test_bsddb*} || die
290 use sqlite || rm -r "${libdir}/"{sqlite3,test/test_sqlite*} || die
291 use tk || rm -r "${ED}usr/bin/idle${SLOT}" "${libdir}/"{idlelib,lib-tk} || die
292 use elibc_uclibc && rm -fr "${libdir}/"{bsddb/test,test}
295 use threads || rm -r "${libdir}/multiprocessing" || die
296 use wininst || rm -r "${libdir}/distutils/command/"wininst-*.exe || die
298 dodoc "${S}"/Misc/{ACKS,HISTORY,NEWS}
300 if use examples; then
301 insinto /usr/share/doc/${PF}/examples
302 doins -r "${S}"/Tools
304 insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
305 local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \
306 emake --no-print-directory -s -f - 2>/dev/null)
307 newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py
309 newconfd "${FILESDIR}/pydoc.conf" pydoc-${SLOT}
310 newinitd "${FILESDIR}/pydoc.init" pydoc-${SLOT}
312 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${SLOT/./_}_PORT:" \
313 -e "s:@PYDOC@:pydoc${SLOT}:" \
314 -i "${ED}etc/conf.d/pydoc-${SLOT}" "${ED}etc/init.d/pydoc-${SLOT}" || die "sed failed"
317 python_export python${SLOT} EPYTHON PYTHON PYTHON_SITEDIR
319 # if not using a cross-compiler, use the fresh binary
320 if ! tc-is-cross-compiler; then
321 local PYTHON=./python
322 local -x LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}.
325 echo "EPYTHON='${EPYTHON}'" > epython.py
326 python_domodule epython.py
330 if has_version "<${CATEGORY}/${PN}-${SLOT}" && ! has_version "${CATEGORY}/${PN}:2.7"; 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."
350 ewarn "You should switch active version of Python ${PV%%.*} and run"
351 ewarn "'python-updater [options]' to rebuild Python modules."
356 eselect_python_update