#!/bin/bash

# python.SlackBuild
# Heavily based on the original Slackware build script,
# Modified by Stuart Winter <stuart@armedslack.org> for the Slackware porting Project.
# 24-Jun-2004

# Record toolchain & other info for the build log:
slackbuildinfo

# Paths to skeleton port's source & real Slackware source tree:
export CWD=$SLACKSOURCE/$PKGSERIES/$PACKAGE
export PORTCWD=$PWD

# Location for Python site-packages:
SITEPK=$PKG/usr/lib/python2.4/site-packages
# same as above without $PKG
TOOLSDIR=/usr/lib/python2.4/site-packages

# Temporary build locations:
export TMPBUILD=$TMP/build-$PACKAGE
export PKG=$TMP/package-$PACKAGE
mkpkgdirs # Delete & re-create temporary directories then cd into $TMPBUILD

# Determine the CFLAGS for the known architectures:
case $PORTARCH in
   arm)     export SLKCFLAGS="-O3 -march=armv3 -mtune=xscale" ;;
   powerpc) export SLKCFLAGS="-O3" ;;
   sparc)   export SLKCFLAGS="-O3" ;;
   alpha)   export SLKCFLAGS="-O3" ;;
   x86_64)  export SLKCFLAGS="-O3" ;;
   i486)    export SLKCFLAGS="-O3" ;;
   mips)    export SLKCFLAGS="-O3" ;;
   *)       export SLKCFLAGS="-O3" ;;
esac

# Extract source:
tar jxvvf $CWD/Python-$VERSION.tar.bz2
cd Python-*
slackhousekeeping

# Configure:
OPT="$SLKCFLAGS" \
./configure \
   --prefix=/usr \
   --with-ncurses \
   --with-threads \
   --enable-ipv6 \
   --enable-shared || failconfig

# Build:
make || failmake

# Install into package:
make install DESTDIR=$PKG || failinstall

# Install some python-demo files:
mkdir -pm755 $PKG/usr/doc/$PACKAGE-$VERSION/html
cp -a Demo $PKG/usr/doc/$PACKAGE-$VERSION

# We'll install the python-tools under site-packages:
mkdir -p $SITEPK
( cd Tools ; cp -a * $SITEPK )
mkdir -p $PKG/usr/doc/$PACKAGE-$VERSION
mv $SITEPK/README $PKG/usr/doc/$PACKAGE-$VERSION/README.python-tools
( cd $PKG/usr/doc/$PACKAGE-$VERSION
  ln -sf $TOOLSDIR Tools )
# Make a few useful symlinks:
mkdir -p $PKG/usr/bin
( cd $PKG/usr/bin
  ln -sf /usr/lib/python2.4/site-packages/modulator/modulator.py modulator
  ln -sf /usr/lib/python2.4/site-packages/pynche/pynche pynche
  ln -sf /usr/lib/python2.4/site-packages/i18n/msgfmt.py .
  ln -sf /usr/lib/python2.4/site-packages/i18n/pygettext.py . )

# Replace hardlink with symlink:
( cd $PKG/usr/bin
  rm -f python
  ln -sf python2.4 python )

# Install docs:
cp -a README Misc $PKG/usr/doc/$PACKAGE-$VERSION
tar jxvvf $CWD/html-$VERSION.tar.bz2 -C${PKG}/usr/doc/$PACKAGE-$VERSION/html

# If necessary, start the fakeroot server so we can set file/dir ownerships:
start_fakeroot

# Apply generic Slackware packaging policies:
cd $PKG
slackstripall   # strip all .a archives and all ELFs
slackgzpages -i # compress man & info pages and delete usr/info/dir
slackslack      # chown -R root:root, chmod -R og-w, slackchown, slack644docs
slackdesc       # install slack-desc and doinst.sh

# Build the package:
if [ $PORTARCH = arm ]; then
   slackmp # run makepkg
  else
   makepkg -l y -c n $PKGSTORE/$PKGSERIES/$PACKAGE-$VERSION-$ARCH-$BUILD.tgz
fi

# Perform any final checks on the package:
cd $PKG
slackhlinks     # search for any hard links	
