1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
7 inherit autotools check-reqs flag-o-matic pax-utils python-utils-r1 \
10 MY_P="Python-${PV/_alpha/a}"
12 PATCHSET="python-gentoo-patches-3.9.0_alpha2"
14 DESCRIPTION="An interpreted, interactive, object-oriented programming language"
15 HOMEPAGE="https://www.python.org/"
16 SRC_URI="https://www.python.org/ftp/python/${PV%_*}/${MY_P}.tar.xz
17 https://dev.gentoo.org/~mgorny/dist/python/${PATCHSET}.tar.xz"
18 S="${WORKDIR}/${MY_P}"
22 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86"
23 IUSE="bluetooth build examples gdbm hardened ipv6 libressl +ncurses +readline sqlite +ssl test tk wininst +xml"
24 RESTRICT="!test? ( test )"
26 # Do not add a dependency on dev-lang/python to this ebuild.
27 # If you need to apply a patch which requires python for bootstrapping, please
28 # run the bootstrap code on your dev box and include the results in the
29 # patchset. See bug 447752.
31 RDEPEND="app-arch/bzip2:=
35 >=sys-libs/zlib-1.1.3:=
38 gdbm? ( sys-libs/gdbm:=[berkdb] )
39 ncurses? ( >=sys-libs/ncurses-5.2:= )
40 readline? ( >=sys-libs/readline-4.1:= )
41 sqlite? ( >=dev-db/sqlite-3.3.8:3= )
43 !libressl? ( dev-libs/openssl:= )
44 libressl? ( dev-libs/libressl:= )
52 xml? ( >=dev-libs/expat-2.1:= )"
53 # bluetooth requires headers from bluez
55 bluetooth? ( net-wireless/bluez )
56 test? ( app-arch/xz-utils[extra-filters(+)] )
58 !sys-devel/gcc[libffi(-)]"
59 RDEPEND+=" !build? ( app-misc/mime-types )"
60 PDEPEND=">=app-eselect/eselect-python-20140125-r1"
62 # large file tests involve a 2.5G file being copied (duplicated)
63 CHECKREQS_DISK_BUILD=5500M
66 use test && check-reqs_pkg_pretend
68 ewarn "This is an early developer preview of Python 3.9. New features"
69 ewarn "can still be added up to 2020-05-18. It's not suitable for production"
70 ewarn "use, and it is not supported for Gentoo packages."
74 use test && check-reqs_pkg_setup
78 # Ensure that internal copies of expat, libffi and zlib are not used.
79 rm -fr Modules/expat || die
80 rm -fr Modules/_ctypes/libffi* || die
81 rm -fr Modules/zlib || die
84 "${WORKDIR}/${PATCHSET}"
89 sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
90 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
97 # disable automagic bluetooth headers detection
98 use bluetooth || export ac_cv_header_bluetooth_bluetooth_h=no
99 use gdbm || disable+=" gdbm"
100 use ncurses || disable+=" _curses _curses_panel"
101 use readline || disable+=" readline"
102 use sqlite || disable+=" _sqlite3"
103 use ssl || export PYTHON_DISABLE_SSL="1"
104 use tk || disable+=" _tkinter"
105 use xml || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat.
106 export PYTHON_DISABLE_MODULES="${disable}"
109 ewarn "You have configured Python without XML support."
110 ewarn "This is NOT a recommended configuration as you"
111 ewarn "may face problems parsing any XML documents."
114 if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
115 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
118 if [[ "$(gcc-major-version)" -ge 4 ]]; then
122 filter-flags -malign-double
124 # https://bugs.gentoo.org/show_bug.cgi?id=50309
125 if is-flagq -O3; then
126 is-flagq -fstack-protector-all && replace-flags -O3 -O2
127 use hardened && replace-flags -O3 -O2
130 # https://bugs.gentoo.org/700012
131 if is-flagq -flto || is-flagq '-flto=*'; then
132 append-cflags $(test-flags-CC -ffat-lto-objects)
135 # Export CXX so it ends up in /usr/lib/python3.X/config/Makefile.
138 # Set LDFLAGS so we link modules with -lpython3.2 correctly.
139 # Needed on FreeBSD unless Python 3.2 is already installed.
140 # Please query BSD team before removing this!
143 # Fix implicit declarations on cross and prefix builds. Bug #674070.
144 use ncurses && append-cppflags -I"${ESYSROOT}"/usr/include/ncursesw
148 dbmliborder+="${dbmliborder:+:}gdbm"
152 # glibc-2.30 removes it; since we can't cleanly force-rebuild
153 # Python on glibc upgrade, remove it proactively to give
154 # a chance for users rebuilding python before glibc
155 ac_cv_header_stropts_h=no
159 --infodir='${prefix}/share/info'
160 --mandir='${prefix}/share/man'
161 --with-computed-gotos
162 --with-dbmliborder="${dbmliborder}"
164 --enable-loadable-sqlite-extensions
170 OPT="" econf "${myeconfargs[@]}"
174 # Ensure sed works as expected
175 # https://bugs.gentoo.org/594768
178 emake CPPFLAGS= CFLAGS= LDFLAGS=
180 # Work around bug 329499. See also bug 413751 and 457194.
181 if has_version dev-libs/libffi[pax_kernel]; then
189 # Tests will not work when cross compiling.
190 if tc-is-cross-compiler; then
191 elog "Disabling tests due to crosscompiling."
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}"
205 local -x PYTHONDONTWRITEBYTECODE=
207 emake test EXTRATESTOPTS="-u-network" CPPFLAGS= CFLAGS= LDFLAGS= < /dev/tty
210 for test in ${skipped_tests}; do
211 mv "${T}/test_${test}.py" "${S}"/Lib/test
214 elog "The following tests have been skipped:"
215 for test in ${skipped_tests}; do
216 elog "test_${test}.py"
219 elog "If you would like to run them, you may:"
220 elog "cd '${EPREFIX}/usr/lib/python${PYVER}/test'"
221 elog "and run the tests separately."
223 if [[ ${result} -ne 0 ]]; then
224 die "emake test failed"
229 local libdir=${ED}/usr/lib/python${PYVER}
231 emake DESTDIR="${D}" altinstall
233 # Remove static library
234 rm "${ED}"/usr/$(get_libdir)/libpython*.a || die
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 "${ED}/usr/$(get_libdir)/libpython3.so" || die
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 # python seems to get rebuilt in src_install (bug 569908)
257 # Work around it for now.
258 if has_version dev-libs/libffi[pax_kernel]; then
259 pax-mark E "${ED}/usr/bin/${abiver}"
261 pax-mark m "${ED}/usr/bin/${abiver}"
264 use sqlite || rm -r "${libdir}/"{sqlite3,test/test_sqlite*} || die
265 use tk || rm -r "${ED}/usr/bin/idle${PYVER}" "${libdir}/"{idlelib,tkinter,test/test_tk*} || die
267 dodoc Misc/{ACKS,HISTORY,NEWS}
269 if use examples; then
271 find Tools -name __pycache__ -exec rm -fr {} + || die
274 insinto /usr/share/gdb/auto-load/usr/$(get_libdir) #443510
275 local libname=$(printf 'e:\n\t@echo $(INSTSONAME)\ninclude Makefile\n' | \
276 emake --no-print-directory -s -f - 2>/dev/null)
277 newins "${S}"/Tools/gdb/libpython.py "${libname}"-gdb.py
279 newconfd "${FILESDIR}/pydoc.conf" pydoc-${PYVER}
280 newinitd "${FILESDIR}/pydoc.init" pydoc-${PYVER}
282 -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${PYVER/./_}_PORT:" \
283 -e "s:@PYDOC@:pydoc${PYVER}:" \
284 -i "${ED}/etc/conf.d/pydoc-${PYVER}" \
285 "${ED}/etc/init.d/pydoc-${PYVER}" || die "sed failed"
288 local vars=( EPYTHON PYTHON_SITEDIR PYTHON_SCRIPTDIR )
290 # if not using a cross-compiler, use the fresh binary
291 if ! tc-is-cross-compiler; then
292 local -x PYTHON=./python
293 local -x LD_LIBRARY_PATH=${LD_LIBRARY_PATH+${LD_LIBRARY_PATH}:}${PWD}
295 vars=( PYTHON "${vars[@]}" )
298 python_export "python${PYVER}" "${vars[@]}"
299 echo "EPYTHON='${EPYTHON}'" > epython.py || die
300 python_domodule epython.py
302 # python-exec wrapping support
303 local pymajor=${PYVER%.*}
304 mkdir -p "${D}${PYTHON_SCRIPTDIR}" || die
306 ln -s "../../../bin/${abiver}" \
307 "${D}${PYTHON_SCRIPTDIR}/python${pymajor}" || die
308 ln -s "python${pymajor}" "${D}${PYTHON_SCRIPTDIR}/python" || die
309 # python-config and pythonX-config
310 # note: we need to create a wrapper rather than symlinking it due
311 # to some random dirname(argv[0]) magic performed by python-config
312 cat > "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" <<-EOF || die
314 exec "${abiver}-config" "\${@}"
316 chmod +x "${D}${PYTHON_SCRIPTDIR}/python${pymajor}-config" || die
317 ln -s "python${pymajor}-config" \
318 "${D}${PYTHON_SCRIPTDIR}/python-config" || die
320 ln -s "../../../bin/2to3-${PYVER}" \
321 "${D}${PYTHON_SCRIPTDIR}/2to3" || die
322 ln -s "../../../bin/pydoc${PYVER}" \
323 "${D}${PYTHON_SCRIPTDIR}/pydoc" || die
326 ln -s "../../../bin/idle${PYVER}" \
327 "${D}${PYTHON_SCRIPTDIR}/idle" || die