#!/bin/sh

###############################################
# Config vars
# (you will most probably need to change these)
###############################################

# Paths to prerequisites
TARBALLPATH=/mnt/smbfs/laokoon/download/Python/Python-2.3.2/Python-2.3.2.tar.bz2 # Python 2.3.2 tarball
PATCHPATH=../python-2.3.2-mingw32-cross.patch # path to the actual patch file

# Command line
UNPACK='tar -jxvf'		# depends on the kind of python source package you use (*.tar.bz2, *.tgz, *.zip?)

# configure arguments
BUILDCONF=i686-pc-linux		# => cross compiling on linux for mingw (alternatives: i686-pc-cygwin, ...)
BUILDARGS='CC=i586-mingw32msvc-gcc CXX=i586-mingw32msvc-g++ AR=i586-mingw32msvc-ar RANLIB=i586-mingw32msvc-ranlib' # this works
				# on debian with cross-mingw32 from testing, YMMV
OPT='-g -Wall -Wstrict-prototypes' # the usual -O3 breaks the regression tests (see patch description)

# pgen target
PGENTARGET=Parser/pgen		# on cygwin you will need to append the '.exe' extension


###############################################
# Preference vars
# (you can probably leave these alone)
###############################################

# directories
XBUILDDIR=xbuild-2.3.2-mingw32	# directory for the cross build
NBUILDDIR=nbuild-2.3.2		# directory for the native build (must be a relative path)

# more configure arguments
HOSTCONF=i686-pc-mingw32	# host configuration (i.e. the cross-build target spec)
CONFIGUREARGS='--enable-shared --with-threads --with-universal-newlines' # I've tested only these



###############################################
# let's go
###############################################

SRCDIR=`pwd`/Python-2.3.2

# 1) apply the patch
#-------------------
$UNPACK $TARBALLPATH
patch -p0 < $PATCHPATH

(cd $SRCDIR && autoreconf)


# 2) build a native pgen
#-----------------------
mkdir -p $NBUILDDIR
(cd $NBUILDDIR && $SRCDIR/configure && make $PGENTARGET)
PGENPATH=`pwd`/$NBUILDDIR/$PGENTARGET


# 3) cross build
#---------------
mkdir -p $XBUILDDIR
cd $XBUILDDIR

$SRCDIR/configure --build="$BUILDCONF" --host="$HOSTCONF" $CONFIGUREARGS $BUILDARGS OPT="$OPT" BUILDPGEN="$PGENPATH"
make && echo 'Success!' && exit 0
echo 'Error!'
exit 1

 	  	 
