#! /bin/bash

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

rebuild () {
    tar xzf rrdtool-1.0.50.tar.gz
    cd rrdtool-1.0.50
    ./configure --prefix=/usr/local --sysconfdir=/etc --localstatedir=/var
    make
    sudo make -C src install
    cd ..
    rm -rf rrdtool-1.0.50
}

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