#!/bin/sh
set -e

# check environment variables are set
if [ -z "$CC03_ROOT" ]; then
    echo "Error: CC03_ROOT not set, nothing done"
    exit 1
fi
${CC03_ROOT}/bin/cc03-check

# remove and recreate the apt-ftparchive cache database
# (otherwise apt-ftparchive notices the change to package files)
rm -f ${CC03_ROOT}/main/db
touch ${CC03_ROOT}/main/db

# attempt build for each directory
cd ${CC03_ROOT}
for package in ../livewires cc03-*; do
    if [ ! -d ${CC03_ROOT}/${package} ]; then
        continue
    fi
    echo "cc03-build: building package ${package}"
    cd ${CC03_ROOT}/${package}
    if [ ! -e Makefile ]; then
        if [ ! -e configure ]; then
            autoconf
        fi
	./configure
    fi
    make release
done

echo "cc03-build: all packages built"
