#!/bin/sh -e

patch -p1 < python2-always-pip.patch

./configure \
    --prefix=/usr \
    --with-ensurepip=yes

make
make DESTDIR="$1" install

# Make static library writable.
chmod u+w "$1/usr/lib/libpython"*.a

# Let's make some kind of effort to reduce the overall
# size of Python by removing a bunch of rarely used and
# otherwise useless components.
#
# This can't be done via ./configure as the build system
# doesn't give you this much control over the process.
{
    cd "$1/usr/lib/python"*
    rm -rf test ./*/test ./*/tests
    rm -rf lib2to3 pydoc* idlelib turtle* ensurepip lib-tk config

    cd "$1/usr/bin"
    rm -f 2to3* pydoc* idle* python pip
}
