#! /bin/bash

trap "echo '*** BUILD FAILED! ***' 1>&2" ERR
set -ex -o pipefail
umask 022
export PATH='/bin:/usr/bin:/usr/local/bin'
export CFLAGS=${CFLAGS:--Os}
export CXXFLAGS=${CXXFLAGS:--Os}

rebuild () {
    tar xjf opkg-utils-svn210411.tar.bz2
    cd opkg-utils
    make
    sudo make install
    for pyscript in arfile.py opkg.py; do
	sudo mv /usr/local/bin/$pyscript /usr/lib/python*/site-packages/
	sudo py_compilefiles /usr/lib/python*/site-packages/$pyscript
    done
    cd ..
    rm -rf opkg-utils
}

while read FN; do
    eval "[ -e $FN ] || rebuild"
done < MANIFEST
