@echo off
setlocal
set GPP="C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\g++.exe"
if not exist %GPP% set GPP=g++
rem windres must be invoked through its 8.3 short path: it derives the gcc path from
rem its own location and does NOT quote it, so "C:\Program Files\..." breaks it with
rem "'C:\Program' is not recognized" / "preprocessing failed".
set WINDRES=C:\PROGRA~1\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\windres.exe
if not exist %WINDRES% set WINDRES=windres

echo Building MirrorOverlay.exe ...

set RES=
if exist app.rc (
  %WINDRES% -I. -O coff -i app.rc -o app_res.o
  if errorlevel 1 (
    echo WARNING: resource compile failed - continuing WITHOUT the embedded icon.
    set RES=
  ) else (
    set RES=app_res.o
  )
)

%GPP% -O2 -mwindows MirrorOverlay.cpp %RES% -o MirrorOverlay.exe -ld3d11 -ldxgi -ldxguid -lgdi32 -luser32 -lshell32 -lwinmm
if errorlevel 1 (
  echo BUILD FAILED
  exit /b 1
)
echo OK: MirrorOverlay.exe
endlocal
