# $Id: PKGBUILD 101741 2010-12-01 12:46:53Z stephane $
# Maintainer: JT Wilkinson <jowilkin@tu.archserver.org>
# Contributer: Allan McRae <allan@archlinux.org>
# Contributer: Jason Chu <jason@archlinux.org>

pkgname=python3
pkgver=3.1.3
pkgrel=1
_pybasever=3.1
pkgdesc="Next generation of the python high-level scripting language"
arch=('i686' 'x86_64')
license=('custom')
url="http://www.python.org"
depends=('expat' 'bzip2' 'gdbm' 'openssl' 'libffi' 'zlib')
makedepends=('sqlite3')
options=('!makeflags')
source=(http://www.python.org/ftp/python/${pkgver}/Python-${pkgver}.tar.bz2
        python-internal-expat.patch)
md5sums=('ad5e5f1c07e829321e0a015f8cafe245'
         '57fa26dd3353a697e8262d926aa035ad')

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

  # Ensure that we are using the system copy of various libraries (expat, zlib and libffi),
  # rather than copies shipped in the tarball
  patch -Np0 -i ../python-internal-expat.patch
  rm -r Modules/expat
  rm -r Modules/zlib
  rm -r Modules/_ctypes/{darwin,libffi}*

  export OPT="${CFLAGS}"
  export CPPFLAGS+="`pkg-config --cflags-only-I libffi`"
  ./configure --prefix=/usr \
              --enable-shared \
              --with-threads \
              --with-computed-gotos \
              --enable-ipv6 \
              --with-wide-unicode \
              --with-system-ffi

  make

  # Run the upstream test suite
  LD_LIBRARY_PATH=${srcdir}/Python-${pkgver}:${LD_LIBRARY_PATH} PYTHON=./python \
     ./runtests.sh -x test_distutils
  for testname in $(cat BAD); do
     echo "== ${testname} =="
     cat OUT/${testname}.out
  done
}

package() {
  cd "${srcdir}/Python-${pkgver}"
  make DESTDIR=${pkgdir} install

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

  # Fix conflicts with python2 - python2 version is newer...
  rm ${pkgdir}/usr/bin/2to3

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