#!/bin/sh
# DF-1172 build. Usage: ./build.sh [harness|meta|all]
# nataraid IS compiled into X86_64_GENERIC; the bug is a real attach-time OOB.
# The live in-guest trigger is blocked by a QEMU/loader artifact (loader hangs
# on any extra hard disk, as in DF-1171), so the harness is the primary proof.
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 LSI v2 disk image (raid_number/disk_number default 200)"
    python3 build_meta.py crafted_lsiv2.img "${2:-200}" "${3:-200}"
    echo "==> built ./crafted_lsiv2.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
