#!/bin/sh
# build.sh — Build both the userspace stress harness and the kernel-module
# race harness for DF-0886.  Run as root on the DragonFly guest.
#
#   ./build.sh
#
# Produces:
#   ./stress_autofs_race  — userspace concurrent-stat stress (probabilistic)
#   ./df0886_race.ko      — kernel module that deterministically races
#                           the REAL autofs_node_vn() (root-only kldload)
set -e

# 1. Userspace stress harness
cc -O2 -o stress_autofs_race stress_autofs_race.c
echo "built: stress_autofs_race"

# 2. Kernel-module race harness (needs /usr/src)
if [ -d /usr/src/sys/vfs/autofs ]; then
    mkdir -p /root/df0886
    cp df0886_race.c Makefile /root/df0886/
    (cd /root/df0886 && make KERNCONF=X86_64_GENERIC)
    cp /root/df0886/df0886_race.ko .
    echo "built: df0886_race.ko"
else
    echo "WARNING: /usr/src not present, skipping kernel-module build"
fi

echo "BUILD OK"
