# $Id: PKGBUILD 96373 2010-10-20 03:29:47Z allan $
# Maintainer: Allan McRae <allan@archlinux.org>
# Contributer: Jason Chu <jason@archlinux.org>

pkgname=python2
pkgver=2.7
pkgrel=3
_pybasever=2.7
pkgdesc="A high-level scripting language"
arch=('i686' 'x86_64')
license=('PSF')
url="http://www.python.org"
depends=('db' 'bzip2' 'gdbm' 'openssl' 'zlib' 'expat' 'sqlite3')
makedepends=('tk')
optdepends=('tk: for IDLE')
conflicts=('python<3')
options=('!makeflags')
source=(http://www.python.org/ftp/python/${pkgver}/Python-${pkgver}.tar.bz2
        python-2.7-db51.diff)
md5sums=('0e8c9ec32abf5b732bea7d91b38c3339'
         'd9b8161568ce17a305c1b71e61ccd4b5')

build() {
  cd ${srcdir}/Python-${pkgver}

  patch -Np1 -i $srcdir/python-2.7-db51.diff

  export OPT="${CFLAGS}"
  ./configure --prefix=/usr --enable-shared --with-threads \
              --enable-unicode=ucs4 --with-system-expat

  make || return 1
}

package() {
  cd ${srcdir}/Python-${pkgver}
  make DESTDIR=${pkgdir} altinstall || return 1

  ln -sf python${_pybasever} $pkgdir/usr/bin/python2
  ln -sf python${_pybasever}-config $pkgdir/usr/bin/python2-config

  ln -sf ../../libpython${_pybasever}.so \
    ${pkgdir}/usr/lib/python${_pybasever}/config/libpython${_pybasever}.so

  mv $pkgdir/usr/bin/smtpd.py $pkgdir/usr/lib/python${_pybasever}/

  # some useful "stuff"
  install -dm755 ${pkgdir}/usr/lib/python${_pybasever}/Tools/{i18n,scripts}
  install -m755 Tools/i18n/{msgfmt,pygettext}.py \
    ${pkgdir}/usr/lib/python${_pybasever}/Tools/i18n/
  install -m755 Tools/scripts/{README,*py} \
    ${pkgdir}/usr/lib/python${_pybasever}/Tools/scripts/

  # fix conflicts with python
  mv $pkgdir/usr/bin/idle{,2}
  mv $pkgdir/usr/bin/pydoc{,2}

  # clean up #!s
  find $pkgdir/usr/lib/python2.7/ -name '*.py' | \
    xargs sed -i "s|#[ ]*![ ]*/usr/bin/env python$|#!/usr/bin/env python2|"

  # clean-up reference to build directory
  sed -i "s#$srcdir/Python-${pkgver}:##" \
    $pkgdir/usr/lib/python${_pybasever}/config/Makefile

  # license
  install -Dm644 LICENSE ${pkgdir}/usr/share/licenses/${pkgname}/LICENSE
}