@echo off
chcp 65001 >nul
setlocal EnableDelayedExpansion

echo ==========================================
echo  Acoustic Offline Multichannel Demo Build
echo ==========================================

set SRC_ROOT=%~dp0
set EIGEN=%SRC_ROOT%third_party\eigen-3.4.0
set ONNX_INC=%SRC_ROOT%third_party\onnxruntime\include
set ONNX_LIB=%SRC_ROOT%third_party\onnxruntime\lib\libonnxruntime.a

set INCLUDES=-I%SRC_ROOT%include -I%EIGEN% -I%ONNX_INC%
set FLAGS=-std=c++17 -O2 -D_USE_MATH_DEFINES -Wa,-mbig-obj
set LIBS=%ONNX_LIB%

if not exist build mkdir build

echo [1/1] Building demo_offline_multichannel.exe ...
g++ %FLAGS% %INCLUDES% ^
    tests\demo_offline_multichannel.cpp ^
    src\core\pipeline.cpp ^
    src\core\audio_buffer.cpp ^
    src\core\fft_utils.cpp ^
    src\core\feature_extractor.cpp ^
    src\core\gunshot_classifier.cpp ^
    src\core\gcc_phat_localizer.cpp ^
    src\core\distance_estimator.cpp ^
    src\core\threat_tracker.cpp ^
    src\io\wav_file_source.cpp ^
    -o build\demo_offline_multichannel.exe ^
    %LIBS% -D_stdcall=
if %ERRORLEVEL% NEQ 0 (
    echo [FAIL] demo_offline_multichannel build failed.
    exit /b 1
)

echo.
echo [OK] demo_offline_multichannel.exe built successfully in build\^
echo.
echo Usage: build\demo_offline_multichannel.exe dataset\multichannel_test.wav --num_mics 4 --layout cross
echo        build\demo_offline_multichannel.exe dataset\real\threat\ --threshold 0.6 --num_mics 4
echo.
echo With ground-truth for error analysis:
echo        build\demo_offline_multichannel.exe synth_90deg_100m.wav --ground_azimuth 90 --ground_distance 100
endlocal
