Mike Frysinger | 682d065 | 2012-07-30 11:38:25 -0400 | [diff] [blame^] | 1 | # Copyright 1999-2012 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/dev-lang/python/python-2.6.8.ebuild,v 1.15 2012/05/26 17:27:12 armin76 Exp $ |
| 4 | |
| 5 | EAPI="2" |
| 6 | WANT_AUTOMAKE="none" |
| 7 | WANT_LIBTOOL="none" |
| 8 | |
| 9 | inherit autotools eutils flag-o-matic multilib pax-utils python toolchain-funcs multiprocessing |
| 10 | |
| 11 | MY_P="Python-${PV}" |
| 12 | PATCHSET_REVISION="0" |
| 13 | |
| 14 | DESCRIPTION="Python is an interpreted, interactive, object-oriented programming language." |
| 15 | HOMEPAGE="http://www.python.org/" |
| 16 | SRC_URI="http://www.python.org/ftp/python/${PV}/${MY_P}.tar.bz2 |
| 17 | mirror://gentoo/python-gentoo-patches-${PV}-${PATCHSET_REVISION}.tar.bz2" |
| 18 | |
| 19 | LICENSE="PSF-2" |
| 20 | SLOT="2.6" |
| 21 | PYTHON_ABI="${SLOT}" |
| 22 | KEYWORDS="alpha amd64 arm hppa ia64 m68k ~mips ppc ppc64 s390 sh sparc x86 ~sparc-fbsd ~x86-fbsd" |
| 23 | IUSE="-berkdb build doc elibc_uclibc examples gdbm ipv6 +ncurses +readline sqlite +ssl +threads tk +wide-unicode wininst +xml" |
| 24 | |
| 25 | RDEPEND="app-arch/bzip2 |
| 26 | >=sys-libs/zlib-1.1.3 |
| 27 | virtual/libffi |
| 28 | virtual/libintl |
| 29 | !build? ( |
| 30 | berkdb? ( || ( |
| 31 | sys-libs/db:4.7 |
| 32 | sys-libs/db:4.6 |
| 33 | sys-libs/db:4.5 |
| 34 | sys-libs/db:4.4 |
| 35 | sys-libs/db:4.3 |
| 36 | sys-libs/db:4.2 |
| 37 | ) ) |
| 38 | gdbm? ( sys-libs/gdbm ) |
| 39 | ncurses? ( |
| 40 | >=sys-libs/ncurses-5.2 |
| 41 | readline? ( >=sys-libs/readline-4.1 ) |
| 42 | ) |
| 43 | sqlite? ( >=dev-db/sqlite-3.3.3:3 ) |
| 44 | ssl? ( dev-libs/openssl ) |
| 45 | tk? ( |
| 46 | >=dev-lang/tk-8.0 |
| 47 | dev-tcltk/blt |
| 48 | ) |
| 49 | xml? ( >=dev-libs/expat-2.1 ) |
| 50 | ) |
| 51 | !!<sys-apps/portage-2.1.9" |
| 52 | DEPEND="${RDEPEND} |
| 53 | virtual/pkgconfig |
| 54 | >=sys-devel/autoconf-2.61 |
| 55 | !sys-devel/gcc[libffi]" |
| 56 | RDEPEND+=" !build? ( app-misc/mime-types ) |
| 57 | doc? ( dev-python/python-docs:${SLOT} )" |
| 58 | |
| 59 | S="${WORKDIR}/${MY_P}" |
| 60 | |
| 61 | pkg_setup() { |
| 62 | python_pkg_setup |
| 63 | |
| 64 | if use berkdb; then |
| 65 | ewarn "\"bsddb\" module is out-of-date and no longer maintained inside dev-lang/python." |
| 66 | ewarn "\"bsddb\" and \"dbhash\" modules have been additionally removed in Python 3." |
| 67 | ewarn "You should use external, still maintained \"bsddb3\" module provided by dev-python/bsddb3," |
| 68 | ewarn "which supports both Python 2 and Python 3." |
| 69 | else |
| 70 | if has_version "=${CATEGORY}/${PN}-${PV%%.*}*[berkdb]"; then |
| 71 | ewarn "You are migrating from =${CATEGORY}/${PN}-${PV%%.*}*[berkdb] to =${CATEGORY}/${PN}-${PV%%.*}*[-berkdb]." |
| 72 | ewarn "You might need to migrate your databases." |
| 73 | fi |
| 74 | fi |
| 75 | } |
| 76 | |
| 77 | src_prepare() { |
| 78 | # Ensure that internal copies of expat, libffi and zlib are not used. |
| 79 | rm -fr Modules/expat |
| 80 | rm -fr Modules/_ctypes/libffi* |
| 81 | rm -fr Modules/zlib |
| 82 | |
| 83 | local excluded_patches |
| 84 | if ! tc-is-cross-compiler; then |
| 85 | excluded_patches="*_all_crosscompile.patch" |
| 86 | fi |
| 87 | |
| 88 | EPATCH_EXCLUDE="${excluded_patches}" EPATCH_SUFFIX="patch" \ |
| 89 | epatch "${WORKDIR}/${PV}-${PATCHSET_REVISION}" |
| 90 | |
| 91 | # |
| 92 | # START: ChromiumOS specific changes |
| 93 | # |
| 94 | if tc-is-cross-compiler ; then |
| 95 | epatch "${FILESDIR}"/python-2.6-cross-getaddrinfo.patch |
| 96 | epatch "${FILESDIR}"/python-2.6.8-cross-setup-sysroot.patch |
| 97 | epatch "${FILESDIR}"/python-2.6.8-cross-h2py.patch |
| 98 | epatch "${FILESDIR}"/python-2.6.8-cross-install-compile.patch |
| 99 | epatch "${FILESDIR}"/python-2.6.8-cross-libdirname.patch |
| 100 | sed -i 's:^python$EXE:${HOSTPYTHON}:' Lib/*/regen || die |
| 101 | fi |
| 102 | epatch "${FILESDIR}"/python-2.6.8-cross-distutils.patch |
| 103 | |
| 104 | sed -i -e "s:sys.exec_prefix]:sys.exec_prefix, '/usr/local']:g" \ |
| 105 | Lib/site.py || die "sed failed to add /usr/local to prefixes" |
| 106 | # |
| 107 | # END: ChromiumOS specific changes |
| 108 | # |
| 109 | |
| 110 | sed -i -e "s:@@GENTOO_LIBDIR@@:$(get_libdir):g" \ |
| 111 | Lib/distutils/command/install.py \ |
| 112 | Lib/distutils/sysconfig.py \ |
| 113 | Lib/site.py \ |
| 114 | Makefile.pre.in \ |
| 115 | Modules/Setup.dist \ |
| 116 | Modules/getpath.c \ |
| 117 | setup.py || die "sed failed to replace @@GENTOO_LIBDIR@@" |
| 118 | |
| 119 | eautoconf |
| 120 | eautoheader |
| 121 | } |
| 122 | |
| 123 | src_configure() { |
| 124 | if use build; then |
| 125 | # Disable extraneous modules with extra dependencies. |
| 126 | export PYTHON_DISABLE_MODULES="dbm _bsddb gdbm _curses _curses_panel readline _sqlite3 _tkinter _elementtree pyexpat" |
| 127 | export PYTHON_DISABLE_SSL="1" |
| 128 | else |
| 129 | # dbm module can be linked against berkdb or gdbm. |
| 130 | # Defaults to gdbm when both are enabled, #204343. |
| 131 | local disable |
| 132 | use berkdb || use gdbm || disable+=" dbm" |
| 133 | use berkdb || disable+=" _bsddb" |
| 134 | use gdbm || disable+=" gdbm" |
| 135 | use ncurses || disable+=" _curses _curses_panel" |
| 136 | use readline || disable+=" readline" |
| 137 | use sqlite || disable+=" _sqlite3" |
| 138 | use ssl || export PYTHON_DISABLE_SSL="1" |
| 139 | use tk || disable+=" _tkinter" |
| 140 | use xml || disable+=" _elementtree pyexpat" # _elementtree uses pyexpat. |
| 141 | export PYTHON_DISABLE_MODULES="${disable}" |
| 142 | |
| 143 | if ! use xml; then |
| 144 | ewarn "You have configured Python without XML support." |
| 145 | ewarn "This is NOT a recommended configuration as you" |
| 146 | ewarn "may face problems parsing any XML documents." |
| 147 | fi |
| 148 | fi |
| 149 | |
| 150 | if [[ -n "${PYTHON_DISABLE_MODULES}" ]]; then |
| 151 | einfo "Disabled modules: ${PYTHON_DISABLE_MODULES}" |
| 152 | fi |
| 153 | |
| 154 | if [[ "$(gcc-major-version)" -ge 4 ]]; then |
| 155 | append-flags -fwrapv |
| 156 | fi |
| 157 | |
| 158 | filter-flags -malign-double |
| 159 | |
| 160 | [[ "${ARCH}" == "alpha" ]] && append-flags -fPIC |
| 161 | |
| 162 | # https://bugs.gentoo.org/show_bug.cgi?id=50309 |
| 163 | if is-flagq -O3; then |
| 164 | is-flagq -fstack-protector-all && replace-flags -O3 -O2 |
| 165 | use hardened && replace-flags -O3 -O2 |
| 166 | fi |
| 167 | |
| 168 | # Run the configure scripts in parallel. |
| 169 | multijob_init |
| 170 | |
| 171 | mkdir -p "${WORKDIR}"/{${CBUILD},${CHOST}} |
| 172 | |
| 173 | if tc-is-cross-compiler; then |
| 174 | ( |
| 175 | multijob_child_init |
| 176 | cd "${WORKDIR}"/${CBUILD} >/dev/null |
| 177 | OPT="-O1" CFLAGS="" CPPFLAGS="" LDFLAGS="" CC="" \ |
| 178 | "${S}"/configure \ |
| 179 | --{build,host}=${CBUILD} \ |
| 180 | || die "cross-configure failed" |
| 181 | ) & |
| 182 | multijob_post_fork |
| 183 | fi |
| 184 | |
| 185 | # Export CXX so it ends up in /usr/lib/python2.X/config/Makefile. |
| 186 | tc-export CXX |
| 187 | # The configure script fails to use pkg-config correctly. |
| 188 | # http://bugs.python.org/issue15506 |
| 189 | export ac_cv_path_PKG_CONFIG=$(tc-getPKG_CONFIG) |
| 190 | |
| 191 | # Set LDFLAGS so we link modules with -lpython2.6 correctly. |
| 192 | # Needed on FreeBSD unless Python 2.6 is already installed. |
| 193 | # Please query BSD team before removing this! |
| 194 | append-ldflags "-L." |
| 195 | |
| 196 | cd "${WORKDIR}"/${CHOST} |
| 197 | ECONF_SOURCE=${S} OPT="" \ |
| 198 | econf \ |
| 199 | --with-fpectl \ |
| 200 | --enable-shared \ |
| 201 | $(use_enable ipv6) \ |
| 202 | $(use_with threads) \ |
| 203 | $(use wide-unicode && echo "--enable-unicode=ucs4" || echo "--enable-unicode=ucs2") \ |
| 204 | --infodir='${prefix}/share/info' \ |
| 205 | --mandir='${prefix}/share/man' \ |
| 206 | --with-libc="" \ |
| 207 | --with-system-ffi |
| 208 | |
| 209 | if tc-is-cross-compiler; then |
| 210 | # Modify the Makefile.pre so we don't regen for the host/ one. |
| 211 | # We need to link the host python programs into $PWD and run |
| 212 | # them from here because the distutils sysconfig module will |
| 213 | # parse Makefile/etc... from argv[0], and we need it to pick |
| 214 | # up the target settings, not the host ones. |
| 215 | sed -i \ |
| 216 | -e '1iHOSTPYTHONPATH = ./hostpythonpath:' \ |
| 217 | -e '/^HOSTPYTHON/s:=.*:= ./hostpython:' \ |
| 218 | -e '/^HOSTPGEN/s:=.*:= ./Parser/hostpgen:' \ |
| 219 | Makefile{.pre,} || die "sed failed" |
| 220 | fi |
| 221 | |
| 222 | multijob_finish |
| 223 | } |
| 224 | |
| 225 | src_compile() { |
| 226 | if tc-is-cross-compiler; then |
| 227 | cd "${WORKDIR}"/${CBUILD} |
| 228 | # Disable as many modules as possible -- but we need a few to install. |
| 229 | PYTHON_DISABLE_MODULES=$( |
| 230 | sed -n "/Extension('/{s:^.*Extension('::;s:'.*::;p}" "${S}"/setup.py | \ |
| 231 | egrep -v '(unicodedata|time|cStringIO|_struct|binascii)' |
| 232 | ) \ |
| 233 | PTHON_DISABLE_SSL="1" \ |
| 234 | SYSROOT= \ |
| 235 | emake || die "cross-make failed" |
| 236 | [[ -e build/lib.linux-x86_64-2.6/unicodedata.so ]] || die |
| 237 | # See comment in src_configure about these. |
| 238 | ln python ../${CHOST}/hostpython || die |
| 239 | ln Parser/pgen ../${CHOST}/Parser/hostpgen || die |
| 240 | ln -s ../${CBUILD}/build/lib.*/ ../${CHOST}/hostpythonpath || die |
| 241 | fi |
| 242 | |
| 243 | cd "${WORKDIR}"/${CHOST} |
| 244 | emake EPYTHON="python${PV%%.*}" || die "emake failed" |
| 245 | |
| 246 | # Work around bug 329499. See also bug 413751. |
| 247 | pax-mark m python |
| 248 | } |
| 249 | |
| 250 | src_test() { |
| 251 | # Tests will not work when cross compiling. |
| 252 | if tc-is-cross-compiler; then |
| 253 | elog "Disabling tests due to crosscompiling." |
| 254 | return |
| 255 | fi |
| 256 | |
| 257 | cd "${WORKDIR}"/${CHOST} |
| 258 | |
| 259 | # Byte compiling should be enabled here. |
| 260 | # Otherwise test_import fails. |
| 261 | python_enable_pyc |
| 262 | |
| 263 | # Skip failing tests. |
| 264 | local skipped_tests="distutils tcl" |
| 265 | |
| 266 | for test in ${skipped_tests}; do |
| 267 | mv "${S}"/Lib/test/test_${test}.py "${T}" || die |
| 268 | done |
| 269 | |
| 270 | # Rerun failed tests in verbose mode (regrtest -w). |
| 271 | emake test EXTRATESTOPTS="-w" < /dev/tty |
| 272 | local result="$?" |
| 273 | |
| 274 | for test in ${skipped_tests}; do |
| 275 | mv "${T}/test_${test}.py" "${S}"/Lib/test/ || die |
| 276 | done |
| 277 | |
| 278 | elog "The following tests have been skipped:" |
| 279 | for test in ${skipped_tests}; do |
| 280 | elog "test_${test}.py" |
| 281 | done |
| 282 | |
| 283 | elog "If you would like to run them, you may:" |
| 284 | elog "cd '${EPREFIX}$(python_get_libdir)/test'" |
| 285 | elog "and run the tests separately." |
| 286 | |
| 287 | python_disable_pyc |
| 288 | |
| 289 | if [[ "${result}" -ne 0 ]]; then |
| 290 | die "emake test failed" |
| 291 | fi |
| 292 | } |
| 293 | |
| 294 | src_install() { |
| 295 | [[ -z "${ED}" ]] && ED="${D%/}${EPREFIX}/" |
| 296 | |
| 297 | cd "${WORKDIR}"/${CHOST} |
| 298 | emake DESTDIR="${D}" altinstall maninstall || die "emake altinstall maninstall failed" |
| 299 | python_clean_installation_image -q |
| 300 | |
| 301 | mv "${ED}usr/bin/python${SLOT}-config" "${ED}usr/bin/python-config-${SLOT}" |
| 302 | |
| 303 | # Fix collisions between different slots of Python. |
| 304 | mv "${ED}usr/bin/2to3" "${ED}usr/bin/2to3-${SLOT}" |
| 305 | mv "${ED}usr/bin/pydoc" "${ED}usr/bin/pydoc${SLOT}" |
| 306 | mv "${ED}usr/bin/idle" "${ED}usr/bin/idle${SLOT}" |
| 307 | mv "${ED}usr/share/man/man1/python.1" "${ED}usr/share/man/man1/python${SLOT}.1" |
| 308 | rm -f "${ED}usr/bin/smtpd.py" |
| 309 | |
| 310 | if use build; then |
| 311 | rm -fr "${ED}usr/bin/idle${SLOT}" "${ED}$(python_get_libdir)/"{bsddb,dbhash.py,idlelib,lib-tk,sqlite3,test} |
| 312 | else |
| 313 | use elibc_uclibc && rm -fr "${ED}$(python_get_libdir)/"{bsddb/test,test} |
| 314 | use berkdb || rm -fr "${ED}$(python_get_libdir)/"{bsddb,dbhash.py,test/test_bsddb*} |
| 315 | use sqlite || rm -fr "${ED}$(python_get_libdir)/"{sqlite3,test/test_sqlite*} |
| 316 | use tk || rm -fr "${ED}usr/bin/idle${SLOT}" "${ED}$(python_get_libdir)/"{idlelib,lib-tk} |
| 317 | fi |
| 318 | |
| 319 | use threads || rm -fr "${ED}$(python_get_libdir)/multiprocessing" |
| 320 | use wininst || rm -f "${ED}$(python_get_libdir)/distutils/command/"wininst-*.exe |
| 321 | |
| 322 | dodoc "${S}"/Misc/{ACKS,HISTORY,NEWS} || die "dodoc failed" |
| 323 | |
| 324 | if use examples; then |
| 325 | insinto /usr/share/doc/${PF}/examples |
| 326 | doins -r "${S}"/Tools || die "doins failed" |
| 327 | fi |
| 328 | |
| 329 | newconfd "${FILESDIR}/pydoc.conf" pydoc-${SLOT} || die "newconfd failed" |
| 330 | newinitd "${FILESDIR}/pydoc.init" pydoc-${SLOT} || die "newinitd failed" |
| 331 | sed \ |
| 332 | -e "s:@PYDOC_PORT_VARIABLE@:PYDOC${SLOT/./_}_PORT:" \ |
| 333 | -e "s:@PYDOC@:pydoc${SLOT}:" \ |
| 334 | -i "${ED}etc/conf.d/pydoc-${SLOT}" "${ED}etc/init.d/pydoc-${SLOT}" || die "sed failed" |
| 335 | } |
| 336 | |
| 337 | pkg_preinst() { |
| 338 | if has_version "<${CATEGORY}/${PN}-${SLOT}" && ! has_version "${CATEGORY}/${PN}:2.6" && ! has_version "${CATEGORY}/${PN}:2.7"; then |
| 339 | python_updater_warning="1" |
| 340 | fi |
| 341 | } |
| 342 | |
| 343 | eselect_python_update() { |
| 344 | [[ -z "${EROOT}" || (! -d "${EROOT}" && -d "${ROOT}") ]] && EROOT="${ROOT%/}${EPREFIX}/" |
| 345 | |
| 346 | if [[ -z "$(eselect python show)" || ! -f "${EROOT}usr/bin/$(eselect python show)" ]]; then |
| 347 | eselect python update |
| 348 | fi |
| 349 | |
| 350 | if [[ -z "$(eselect python show --python${PV%%.*})" || ! -f "${EROOT}usr/bin/$(eselect python show --python${PV%%.*})" ]]; then |
| 351 | eselect python update --python${PV%%.*} |
| 352 | fi |
| 353 | } |
| 354 | |
| 355 | pkg_postinst() { |
| 356 | eselect_python_update |
| 357 | |
| 358 | python_mod_optimize -f -x "/(site-packages|test|tests)/" $(python_get_libdir) |
| 359 | |
| 360 | if [[ "${python_updater_warning}" == "1" ]]; then |
| 361 | ewarn "You have just upgraded from an older version of Python." |
| 362 | ewarn "You should switch active version of Python ${PV%%.*} and run" |
| 363 | ewarn "'python-updater [options]' to rebuild Python modules." |
| 364 | fi |
| 365 | } |
| 366 | |
| 367 | pkg_postrm() { |
| 368 | eselect_python_update |
| 369 | |
| 370 | python_mod_cleanup $(python_get_libdir) |
| 371 | } |