#! /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 squashfs4.2.tar.gz
    cd squashfs4.2/squashfs-tools
    make
    strip -R .note -R .comment mksquashfs
    sudo cp mksquashfs /usr/local/bin/mksquashfs4
    cd ../..
    rm -rf squashfs4.2
}

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