set -x
set -eu

plat=plat-linux$(uname -r | sed 's/^\(.\).*$/\1/')

if [ -d /usr/lib/x86_64-linux-gnu ]
then
    export LDFLAGS="${LDFLAGS:-} -L/usr/lib/x86_64-linux-gnu/"
elif [ -d /usr/lib/i386-linux-gnu ]
then
    export LDFLAGS="${LDFLAGS:-} -L/usr/lib/i386-linux-gnu/"
else
    :
fi

export LDFLAGS="-L/usr/local/c$which_python/lib -Wl,-rpath -Wl,/usr/local/c$which_python/lib $LDFLAGS"

# Otherwise we get a buffer overflow during installation!
export BASECFLAGS='-U_FORTIFY_SOURCE'

case 2 in
    1)
        # something like this used to work, but it has problems on Debian. Or is it the kernel version?
        # It's not a Mint vs Debian thing.
        ./configure --prefix="/usr/local/c$which_python" --enable-shared

        mkdir -p Lib/"$plat"

        (cd Lib/plat-linux2 && tar cflS - .) | (cd Lib/"$plat" && tar xvfp -)

        make
        ;;
    2)
        ./configure --prefix="/usr/local/c$which_python" --enable-shared
        make
        # make test
        ;;
esac