#Packager: George Vlahavas <vlahavas~at~gmail~dot~com>

pkgname=python3
pkgver=3.3.2
pkgrel=1gv
source=("http://www.python.org/ftp/python/$pkgver/Python-$pkgver.tar.xz" "python330_lib64.patch")
docs=("readme" "license")
url=http://www.python.org

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"python3 (New high-level scripting language)"
"Python 3 is an interpreted, interactive, object-oriented programming "
"language that combines remarkable power with very clear syntax."
"This is a new version of the language that is incompatible with the "
"2.x line of releases."
"The language is mostly the same, but many details, especially how "
"built-in objects like dictionaries and strings work, have changed "
"considerably, and a lot of deprecated features have finally been "
"removed.  Also, the standard library has been reorganized in a few "
"prominent places."
)


build() {
	cd $SRC/Python-$pkgver
	
	# Location for Python site-packages:
	SITEPK=$PKG/usr/lib${LIBDIRSUFFIX}/python3.3/site-packages
	# same as above without $PKG
	TOOLSDIR=/usr/lib${LIBDIRSUFFIX}/python3.3/site-packages
	
	# fix python3 PATH for cgi
	sed -i -e "s|^#.* /usr/local/bin/python|#!/usr/bin/python3|" Lib/cgi.py
		
	# fix lib64
	if [ "$ARCH" = "x86_64" ]; then
		# Install to /usr/lib64 instead of /usr/lib:
		patch -p1 --verbose < ../python330_lib64.patch
	fi
	
	# build	
	./configure --prefix=/usr \
		--libdir=/usr/lib${LIBDIRSUFFIX} \
		--mandir=/usr/man \
		--docdir=/usr/doc/$pkgname-$pkgver \
		--with-threads \
		--enable-ipv6 \
		--enable-shared \
		--with-system-expat \
		--with-system-ffi \
		--with-computed-gotos \
		--build=$ARCH-slackware-linux
		
	make -j $numjobs || return 1
	
	# run some tests
	LD_LIBRARY_PATH="${SRC}/Python-${pkgver}":${LD_LIBRARY_PATH} \
	"${SRC}/Python-${pkgver}/python" -m test.regrtest -x test_distutils test_site \
	test_urllib test_uuid test_pydoc
	
	# install
	make altinstall DESTDIR=$PKG
	
	# symlinks
	(
	cd $PKG/usr/bin
	ln -sf python3.3 python3
	ln -sf python3.3-config python3-config
	ln -sf python3.3m-config python3m-config
	ln -sf pydoc3.3 pydoc3
	ln -sf idle3.3 idle3
	ln -sf 2to3-3.3 2to3-3
	ln -sf pyvenv-3.3 pyvenv3
	)
	
	# python-tools in site-packages:
	mkdir -p $SITEPK
	cp -a Tools/* $SITEPK
	
	# Misc docs
	mkdir -p $PKG/usr/doc/$pkgname-$pkgver
	cp -r Misc $PKG/usr/doc/$pkgname-$pkgver
	mv $SITEPK/README $PKG/usr/doc/$pkgname-$pkgver/README.python-tools
	(
	cd $PKG/usr/doc/$pkgname-$pkgver
	ln -sf $TOOLSDIR Tools
	)
}
