#! /bin/sh
#
#   Examples build helper
#   Syntax: build all | clean
#
#   This controls whether we get debug or release builds
test -z "$BOOM_MODEL" && BOOM_MODEL=debug

ZMQOPTS='-lzmq -lczmq'
if pkg-config libzmq --exists; then
  ZMQOPTS=$(pkg-config --libs --cflags libczmq libzmq)
fi

CCLIBS="$CCLIBS $ZMQOPTS"
export CCLIBS

if [ /$1/ = /all/ ]; then
    echo "Building C examples..."
    for MAIN in `egrep -l "main \(" *.c`; do
        echo "$MAIN"
        ./c -l -q $MAIN
    done
elif [ /$1/ = /clean/ ]; then
    echo "Cleaning C examples directory..."
    rm -f *.o *.lst core
    for MAIN in `egrep -l "main \(" *.c`; do
        rm -f `basename $MAIN .c`
    done
elif [ -f $1.c ]; then
    echo "$1"
    ./c -l -q $1
else
    echo "syntax: build all | clean"
fi
