*/*: Discontinue Gentoo SuperH port
[gentoo.git] / dev-lang / python / python-2.7.17-r1.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI="7"
5 WANT_LIBTOOL="none"
6
7 inherit autotools flag-o-matic pax-utils python-utils-r1 toolchain-funcs
8
9 MY_P="Python-${PV}"
10 PYVER=$(ver_cut 1-2)
11 PATCHSET="python-gentoo-patches-2.7.17-r1"
12
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}"
18
19 LICENSE="PSF-2"
20 SLOT="${PYVER}"
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"
23
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.
28
29 RDEPEND="app-arch/bzip2:=
30         dev-libs/libffi:=
31         >=sys-libs/zlib-1.1.3:=
32         virtual/libcrypt:=
33         virtual/libintl
34         berkdb? ( || (
35                 sys-libs/db:5.3
36                 sys-libs/db:5.1
37                 sys-libs/db:4.8
38                 sys-libs/db:4.7
39                 sys-libs/db:4.6
40                 sys-libs/db:4.5
41                 sys-libs/db:4.4
42                 sys-libs/db:4.3
43                 sys-libs/db:4.2
44         ) )
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= )
49         ssl? (
50                 !libressl? ( dev-libs/openssl:= )
51                 libressl? ( dev-libs/libressl:= )
52         )
53         tk? (
54                 >=dev-lang/tcl-8.0:=
55                 >=dev-lang/tk-8.0:=
56                 dev-tcltk/blt:=
57                 dev-tcltk/tix
58         )
59         xml? ( >=dev-libs/expat-2.1:= )"
60 # bluetooth requires headers from bluez
61 DEPEND="${RDEPEND}
62         bluetooth? ( net-wireless/bluez )
63         virtual/pkgconfig
64         !sys-devel/gcc[libffi(-)]"
65 RDEPEND+=" !build? ( app-misc/mime-types )"
66 PDEPEND=">=app-eselect/eselect-python-20140125-r1"
67
68 pkg_setup() {
69         if use berkdb; then
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."
74         else
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."
79                 fi
80         fi
81 }
82
83 src_prepare() {
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
88
89         local PATCHES=(
90                 "${WORKDIR}/${PATCHSET}"
91         )
92
93         default
94
95         sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \
96                 Lib/distutils/command/install.py \
97                 Lib/distutils/sysconfig.py \
98                 Lib/site.py \
99                 Lib/sysconfig.py \
100                 Lib/test/test_site.py \
101                 Makefile.pre.in \
102                 Modules/Setup.dist \
103                 Modules/getpath.c \
104                 setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@"
105
106         eautoreconf
107 }
108
109 src_configure() {
110         # dbm module can be linked against berkdb or gdbm.
111         # Defaults to gdbm when both are enabled, #204343.
112         local disable
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}"
125
126         if ! use xml; then
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."
130         fi
131
132         if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then
133                 einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}"
134         fi
135
136         if [[ "$(gcc-major-version)" -ge 4 ]]; then
137                 append-flags -fwrapv
138         fi
139
140         filter-flags -malign-double
141
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
146         fi
147
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
152         fi
153
154         # Export CXX so it ends up in /usr/lib/python2.X/config/Makefile.
155         tc-export CXX
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)
159
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!
163         append-ldflags "-L."
164
165         local dbmliborder
166         if use gdbm; then
167                 dbmliborder+="${dbmliborder:+:}gdbm"
168         fi
169         if use berkdb; then
170                 dbmliborder+="${dbmliborder:+:}bdb"
171         fi
172
173         local myeconfargs=(
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
182
183                 --with-fpectl
184                 --enable-shared
185                 $(use_enable ipv6)
186                 $(use_with threads)
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}"
192                 --with-libc=
193                 --enable-loadable-sqlite-extensions
194                 --with-system-expat
195                 --with-system-ffi
196                 --without-ensurepip
197         )
198
199         OPT="" econf "${myeconfargs[@]}"
200
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)"
205         fi
206 }
207
208 src_compile() {
209         # Ensure sed works as expected
210         # https://bugs.gentoo.org/594768
211         local -x LC_ALL=C
212
213         # Avoid invoking pgen for cross-compiles.
214         touch Include/graminit.h Python/graminit.c
215
216         emake
217
218         # Work around bug 329499. See also bug 413751 and 457194.
219         if has_version dev-libs/libffi[pax_kernel]; then
220                 pax-mark E python
221         else
222                 pax-mark m python
223         fi
224 }
225
226 src_test() {
227         # Tests will not work when cross compiling.
228         if tc-is-cross-compiler; then
229                 elog "Disabling tests due to crosscompiling."
230                 return
231         fi
232
233         # Skip failing tests.
234         local skipped_tests="distutils gdb"
235
236         for test in ${skipped_tests}; do
237                 mv "${S}"/Lib/test/test_${test}.py "${T}"
238         done
239
240         # bug 660358
241         local -x COLUMNS=80
242
243         # Daylight saving time problem
244         # https://bugs.python.org/issue22067
245         # https://bugs.gentoo.org/610628
246         local -x TZ=UTC
247
248         # Rerun failed tests in verbose mode (regrtest -w).
249         emake test EXTRATESTOPTS="-w" < /dev/tty
250         local result="$?"
251
252         for test in ${skipped_tests}; do
253                 mv "${T}/test_${test}.py" "${S}"/Lib/test
254         done
255
256         elog "The following tests have been skipped:"
257         for test in ${skipped_tests}; do
258                 elog "test_${test}.py"
259         done
260
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."
264
265         if [[ ${result} -ne 0 ]]; then
266                 die "emake test failed"
267         fi
268 }
269
270 src_install() {
271         local libdir=${ED}/usr/$(get_libdir)/python${PYVER}
272
273         emake DESTDIR="${D}" altinstall
274
275         sed -e "s/\(LDFLAGS=\).*/\1/" -i "${libdir}/config/Makefile" || die
276
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
282
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}
287
288         use threads || rm -r "${libdir}/multiprocessing" || die
289         use wininst || rm "${libdir}/distutils/command/"wininst-*.exe || die
290
291         dodoc Misc/{ACKS,HISTORY,NEWS}
292
293         if use examples; then
294                 docinto examples
295                 dodoc -r Tools
296         fi
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
301
302         newconfd "${FILESDIR}/pydoc.conf" pydoc-${PYVER}
303         newinitd "${FILESDIR}/pydoc.init" pydoc-${PYVER}
304         sed \
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"
309
310         # for python-exec
311         local vars=( EPYTHON PYTHON_SITEDIR PYTHON_SCRIPTDIR )
312
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}
317         else
318                 vars=( PYTHON "${vars[@]}" )
319         fi
320
321         python_export "python${PYVER}" "${vars[@]}"
322         echo "EPYTHON='${EPYTHON}'" > epython.py || die
323         python_domodule epython.py
324
325         # python-exec wrapping support
326         local pymajor=${PYVER%.*}
327         mkdir -p "${D}${PYTHON_SCRIPTDIR}" || die
328         # python and pythonX
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
342         # idle
343         if use tk; then
344                 ln -s "../../../bin/idle${PYVER}" \
345                         "${D}${PYTHON_SCRIPTDIR}/idle" || die
346         fi
347 }
348
349 eselect_python_update() {
350         if [[ -z "$(eselect python show)" || \
351                         ! -f "${EROOT}/usr/bin/$(eselect python show)" ]]; then
352                 eselect python update
353         fi
354
355         if [[ -z "$(eselect python show --python${PV%%.*})" || \
356                         ! -f "${EROOT}/usr/bin/$(eselect python show --python${PV%%.*})" ]]
357         then
358                 eselect python update --python${PV%%.*}
359         fi
360 }
361
362 pkg_postinst() {
363         eselect_python_update
364 }
365
366 pkg_postrm() {
367         eselect_python_update
368 }