1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
7 inherit autotools flag-o-matic pax-utils python-utils-r1 toolchain-funcs
11 PATCHSET="python-gentoo-patches-2.7.17-r1"
13 DESCRIPTION="An interpreted, interactive, object-oriented programming language"
14 HOMEPAGE="https://www.python.org/"
15 SRC_URI="https://www.python.org/ftp/python/${PV}/${MY_P}.tar.xz
16 https://dev.gentoo.org/~mgorny/dist/python/${PATCHSET}.tar.xz"
17 S="${WORKDIR}/${MY_P}"
21 KEYWORDS="~alpha amd64 arm arm64 hppa ia64 ~m68k ~mips ppc ppc64 s390 sparc x86"
22 IUSE="-berkdb bluetooth build elibc_uclibc examples gdbm hardened ipv6 libressl +ncurses +readline sqlite +ssl +threads tk +wide-unicode 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:=
31 >=sys-libs/zlib-1.1.3:=
45 gdbm? ( sys-libs/gdbm:=[berkdb] )
46 ncurses? ( >=sys-libs/ncurses-5.2:= )
47 readline? ( >=sys-libs/readline-4.1:= )
48 sqlite? ( >=dev-db/sqlite-3.3.8:3= )
50 !libressl? ( dev-libs/openssl:= )
51 libressl? ( dev-libs/libressl:= )
59 xml? ( >=dev-libs/expat-2.1:= )"
60 # bluetooth requires headers from bluez
62 bluetooth? ( net-wireless/bluez )
64 !sys-devel/gcc[libffi(-)]"
65 RDEPEND+=" !build? ( app-misc/mime-types )"
66 PDEPEND=">=app-eselect/eselect-python-20140125-r1"
70 ewarn "'bsddb' module is out-of-date and no longer maintained inside"
71 ewarn "dev-lang/python. 'bsddb' and 'dbhash' modules have been additionally"
72 ewarn "removed in Python 3. A maintained alternative of 'bsddb3' module"
73 ewarn "is provided by dev-python/bsddb3."
75 if has_version "=${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"; then
76 ewarn "You are migrating from =${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"
77 ewarn "to =${CATEGORY}/${PN}-${PV%%.*}*[-berkdb]."
78 ewarn "You might need to migrate your databases."
84 # Ensure that internal copies of expat, libffi and zlib are not used.
85 rm -fr Modules/expat || die
86 rm -fr Modules/_ctypes/libffi* || die
87 rm -fr Modules/zlib || die
90 "${WORKDIR}/${PATCHSET}"
95 sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
96 Lib/distutils/command/install.py \
97 Lib/distutils/sysconfig.py \
100 Lib/test/test_site.py \
104 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
110 # dbm module can be linked against berkdb or gdbm.
111 # Defaults to gdbm when both are enabled, #204343.
113 use berkdb || use gdbm || disable+=" dbm"
114 use berkdb || disable+=" _bsddb"
115 # disable automagic bluetooth headers detection
116 use bluetooth || export ac_cv_header_bluetooth_bluetooth_h=no
117 use gdbm || disable+=" gdbm"
118 use ncurses || disable+=" _curses _curses_panel"
119 use readline || disable+=" readline"
120 use sqlite || disable+=" _sqlite3"
121 use ssl || export PYTHON_DISABLE_SSL="1"
122 use tk || disable+=" _tkinter"
123 use xml || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
124 export PYTHON_DISABLE_MODULES="${disable}"
127 ewarn "You have configured Python without XML support."
128 ewarn "This is NOT a recommended configuration as you"
129 ewarn "may face problems parsing any XML documents."
132 if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
133 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
136 if [[ "$(gcc-major-version)" -ge 4 ]]; then
140 filter-flags -malign-double
142 # https://bugs.gentoo.org/show_bug.cgi?id=50309
143 if is-flagq -O3; then
144 is-flagq -fstack-protector-all && replace-flags -O3 -O2
145 use hardened && replace-flags -O3 -O2
148 if tc-is-cross-compiler; then
149 # Force some tests that try to poke fs paths.
150 export ac_cv_file__dev_ptc=no
151 export ac_cv_file__dev_ptmx=yes
154 # Export CXX so it ends up in /usr/lib/python2.X/config/Makefile.
156 # The configure script fails to use pkg-config correctly.
157 # http://bugs.python.org/issue15506
158 export ac_cv_path_PKG_CONFIG=$(tc-getPKG_CONFIG)
160 # Set LDFLAGS so we link modules with -lpython2.7 correctly.
161 # Needed on FreeBSD unless Python 2.7 is already installed.
162 # Please query BSD team before removing this!
167 dbmliborder+="${dbmliborder:+:}gdbm"
170 dbmliborder+="${dbmliborder:+:}bdb"
174 # The check is broken on clang, and gives false positive:
175 # https://bugs.gentoo.org/596798
176 # (upstream dropped this flag in 3.2a4 anyway)
177 ac_cv_opt_olimit_ok=no
178 # glibc-2.30 removes it; since we can't cleanly force-rebuild
179 # Python on glibc upgrade, remove it proactively to give
180 # a chance for users rebuilding python before glibc
181 ac_cv_header_stropts_h=no
187 $(use wide-unicode && echo "--enable-unicode=ucs4" || echo "--enable-unicode=ucs2")
188 --infodir='${prefix}/share/info'
189 --mandir='${prefix}/share/man'
190 --with-computed-gotos
191 --with-dbmliborder="${dbmliborder}"
193 --enable-loadable-sqlite-extensions
199 OPT="" econf "${myeconfargs[@]}"
201 if use threads && grep -q "#define POSIX_SEMAPHORES_NOT_ENABLED 1" pyconfig.h; then
202 eerror "configure has detected that the sem_open function is broken."
203 eerror "Please ensure that /dev/shm is mounted as a tmpfs with mode 1777."
204 die "Broken sem_open function (bug 496328)"
209 # Ensure sed works as expected
210 # https://bugs.gentoo.org/594768
213 # Avoid invoking pgen for cross-compiles.
214 touch Include/graminit.h Python/graminit.c
218 # Work around bug 329499. See also bug 413751 and 457194.
219 if has_version dev-libs/libffi[pax_kernel]; then
227 # Tests will not work when cross compiling.
228 if tc-is-cross-compiler; then
229 elog "Disabling tests due to crosscompiling."
233 # Skip failing tests.
234 local skipped_tests="distutils gdb"
236 for test in ${skipped_tests}; do
237 mv "${S}"/Lib/test/test_${test}.py "${T}"
243 # Daylight saving time problem
244 # https://bugs.python.org/issue22067
245 # https://bugs.gentoo.org/610628
248 # Rerun failed tests in verbose mode (regrtest -w).
249 emake test EXTRATESTOPTS="-w" < /dev/tty
252 for test in ${skipped_tests}; do
253 mv "${T}/test_${test}.py" "${S}"/Lib/test
256 elog "The following tests have been skipped:"
257 for test in ${skipped_tests}; do
258 elog "test_${test}.py"
261 elog "If you would like to run them, you may:"
262 elog "cd '${EPREFIX}/usr/$(get_libdir)/python${PYVER}/test'"
263 elog "and run the tests separately."
265 if [[ ${result} -ne 0 ]]; then
266 die "emake test failed"
271 local libdir=${ED}/usr/$(get_libdir)/python${PYVER}
273 emake DESTDIR="${D}" altinstall
275 sed -e "s/\(LDFLAGS=\).*/\1/" -i "${libdir}/config/Makefile" || die
277 # Fix collisions between different slots of Python.
278 mv "${ED}/usr/bin/2to3" "${ED}/usr/bin/2to3-${PYVER}" || die
279 mv "${ED}/usr/bin/pydoc" "${ED}/usr/bin/pydoc${PYVER}" || die
280 mv "${ED}/usr/bin/idle" "${ED}/usr/bin/idle${PYVER}" || die
281 rm "${ED}/usr/bin/smtpd.py" || die
283 use berkdb || rm -r "${libdir}/"{bsddb,dbhash.py*,test/test_bsddb*} || die
284 use sqlite || rm -r "${libdir}/"{sqlite3,test/test_sqlite*} || die
285 use tk || rm -r "${ED}/usr/bin/idle${PYVER}" "${libdir}/"{idlelib,lib-tk} || die
286 use elibc_uclibc && rm -fr "${libdir}/"{bsddb/test,test}
288 use threads || rm -r "${libdir}/multiprocessing" || die
289 use wininst || rm "${libdir}/distutils/command/"wininst-*.exe || die
291 dodoc Misc/{ACKS,HISTORY,NEWS}
293 if use examples; then
297 insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
298 local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \
299 emake --no-print-directory -s -f - 2>/dev/null)
300 newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py
302 newconfd "${FILESDIR}/pydoc.conf" pydoc-${PYVER}
303 newinitd "${FILESDIR}/pydoc.init" pydoc-${PYVER}
305 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${PYVER/./_}_PORT:" \
306 -e "s:@PYDOC@:pydoc${PYVER}:" \
307 -i "${ED}/etc/conf.d/pydoc-${PYVER}" \
308 "${ED}/etc/init.d/pydoc-${PYVER}" || die "sed failed"
311 local vars=( EPYTHON PYTHON_SITEDIR PYTHON_SCRIPTDIR )
313 # if not using a cross-compiler, use the fresh binary
314 if ! tc-is-cross-compiler; then
315 local -x PYTHON=./python
316 local -x LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}${PWD}
318 vars=( PYTHON "${vars[@]}" )
321 python_export "python${PYVER}" "${vars[@]}"
322 echo "EPYTHON='${EPYTHON}'" > epython.py || die
323 python_domodule epython.py
325 # python-exec wrapping support
326 local pymajor=${PYVER%.*}
327 mkdir -p "${D}${PYTHON_SCRIPTDIR}" || die
329 ln -s "../../../bin/python${PYVER}" \
330 "${D}${PYTHON_SCRIPTDIR}/python${pymajor}" || die
331 ln -s "python${pymajor}" "${D}${PYTHON_SCRIPTDIR}/python" || die
332 # python-config and pythonX-config
333 ln -s "../../../bin/python${PYVER}-config" \
334 "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" || die
335 ln -s "python${pymajor}-config" \
336 "${D}${PYTHON_SCRIPTDIR}/python-config" || die
337 # 2to3, pydoc, pyvenv
338 ln -s "../../../bin/2to3-${PYVER}" \
339 "${D}${PYTHON_SCRIPTDIR}/2to3" || die
340 ln -s "../../../bin/pydoc${PYVER}" \
341 "${D}${PYTHON_SCRIPTDIR}/pydoc" || die
344 ln -s "../../../bin/idle${PYVER}" \
345 "${D}${PYTHON_SCRIPTDIR}/idle" || die
349 eselect_python_update() {
350 if [[ -z "$(eselect python show)" || \
351 ! -f "${EROOT}/usr/bin/$(eselect python show)" ]]; then
352 eselect python update
355 if [[ -z "$(eselect python show --python${PV%%.*})" || \
356 ! -f "${EROOT}/usr/bin/$(eselect python show --python${PV%%.*})" ]]
358 eselect python update --python${PV%%.*}
363 eselect_python_update
367 eselect_python_update