#!/bin/sh
# DF-1171 build harness. Usage: ./build.sh [harness|meta|all]
set -e
cd "$(dirname "$0")"
MODE="${1:-all}"

build_harness() {
    echo "==> building overflow_harness (cc -Wall -O2)"
    cc -Wall -O2 -o overflow_harness overflow_harness.c
    echo "==> built ./overflow_harness"
}

build_meta() {
    echo "==> building crafted Intel-RAID disk image (map->total_disks default 32)"
    python3 build_meta.py crafted_raid.img "${1:-32}"
    echo "==> built ./crafted_raid.img"
}

case "$MODE" in
    harness) build_harness ;;
    meta)    shift 2>/dev/null; build_meta "$@" ;;
    all)     build_harness; build_meta ;;
    *)       echo "usage: $0 [harness|meta|all]"; exit 2 ;;
esac
