#!/bin/sh
# When building from the monorepo, symlink the C++ core sources into src/ so
# R's standard build system picks them up.  When building from a source tarball
# (R CMD check, r-universe, CRAN) the files are already vendored in src/ and
# this script is a no-op.

SCRIPT_DIR="$(cd "$(dirname "$0")" 2>/dev/null && pwd)"
CORE_DIR="$SCRIPT_DIR/../../src"

if [ ! -d "$CORE_DIR" ]; then
    exit 0
fi

for f in MCMC_core.cpp MCMC_proposals.cpp MCMC_bookkeeping.cpp helpers.cpp fit_result.cpp; do
    target="src/$f"
    if [ ! -e "$target" ]; then
        cp "$CORE_DIR/$f" "$target"
    fi
done
