#!/bin/sh

. config/options

$SCRIPTS/build toolchain
$SCRIPTS/build sqlite
$SCRIPTS/build openssl
$SCRIPTS/build zlib
$SCRIPTS/build libffi

PY_DISABLED_MODULES="readline _curses _curses_panel _tkinter nis gdbm bsddb _codecs_kr _codecs_jp _codecs_cn _codecs_tw _codecs_hk"
PY_BUILD_DIR=`ls -d $ROOT/$PKG_BUILD`
PY_BASE_VERSION=2.6

cd $PKG_BUILD

setup_toolchain host

rm -rf config.cache

CONFIG_SITE= \
OPT="$HOST_CFLAGS" \
./configure --prefix=$ROOT/$TOOLCHAIN \
            --without-cxx-main \
            --with-threads \
            --enable-unicode=ucs4 \

OPT="$HOST_CFLAGS" \
make python Parser/pgen

OPT="$HOST_CFLAGS" \
PYTHON_MODULES_INCLUDE=/usr/include \
PYTHON_MODULES_LIB="/lib /lib64 /usr/lib /usr/lib64" \
make HOSTPYTHON=./python sharedmods install

mv Parser/pgen ./hostpgen
cp python ./hostpython

make distclean

setup_toolchain target

ac_cv_file__dev_ptmx=no \
ac_cv_file__dev_ptc=no \
ac_cv_lib_readline_readline=no \
ac_cv_printf_zd_format=no \
OPT="$CFLAGS -fno-strict-aliasing" \
./configure --host=$TARGET_NAME \
            --build=$HOST_NAME \
            --prefix=/usr \
            --sysconfdir=/etc \
            --enable-shared \
            --with-threads \
            --enable-unicode=ucs4 \
            --disable-ipv6 \
            --disable-profiling \
            --without-pydebug \
            --without-doc-strings \
            --without-tsc \
            --without-pymalloc \
            --without-fpectl \
            --without-wctype-functions \
            --without-cxx-main \
            --with-system-ffi \

make  CC=$TARGET_CC \
      GNU_HOST=$TARGET_NAME \
      GNU_BUILD=$HOST_NAME \
      DESTDIR=$SYSROOT_PREFIX \
      CROSS_COMPILE=yes \
      PYTHON_DISABLE_MODULES="$PY_DISABLED_MODULES" \
      PYTHON_MODULES_INCLUDE=$SYSROOT_PREFIX/usr/include \
      PYTHON_MODULES_LIB="$SYSROOT_PREFIX/lib $SYSROOT_PREFIX/usr/lib" \
      HOSTPYTHON=./hostpython \
      HOSTPGEN=./hostpgen

make  CC=$TARGET_CC \
      GNU_HOST=$TARGET_NAME \
      GNU_BUILD=$HOST_NAME \
      DESTDIR=$SYSROOT_PREFIX \
      CROSS_COMPILE=yes \
      PYTHON_DISABLE_MODULES="$PY_DISABLED_MODULES" \
      PYTHON_MODULES_INCLUDE=$SYSROOT_PREFIX/usr/include \
      PYTHON_MODULES_LIB="$SYSROOT_PREFIX/lib $SYSROOT_PREFIX/usr/lib" \
      HOSTPYTHON=./hostpython \
      HOSTPGEN=./hostpgen \
      install

$STRIP python

$ROOT/$TOOLCHAIN/bin/python -Wi -t Lib/compileall.py -f -x test ./Lib

# ugly hack to fix some issues with crosscompile:
  cp pyconfig.h $ROOT/$TOOLCHAIN/include/python*/
