#!/usr/bin/env zsh
# build.zsh -- compile the SAT solver, sanity tests, and the four examples.
#
# No Makefile, no Xcode project: a single TU library plus four demos.

set -e

CC=${CC:-cc}
CFLAGS=( ${=CFLAGS:--std=c99 -O2 -Wall -Wextra -Isrc} )
LDFLAGS=()

mkdir -p build

echo "=== compiling core ==="
$CC $CFLAGS -c src/sat.c -o build/sat.o

CORE_OBJS=(build/sat.o)

echo "=== sanity ==="
$CC $CFLAGS sanity.c $CORE_OBJS -o build/sanity $LDFLAGS
./build/sanity

echo
echo "=== examples ==="
for ex in examples/ex1_pigeonhole.c examples/ex2_queens.c \
          examples/ex3_coloring.c   examples/ex4_sudoku.c; do
    name=$(basename "$ex" .c)
    $CC $CFLAGS "$ex" $CORE_OBJS -o "build/$name" $LDFLAGS
    echo
    echo "----- $name -----"
    "./build/$name"
done

echo
echo "build complete."
