@echo off
setlocal
cd /d "%~dp0"

if exist WinResizer.exe del WinResizer.exe

where g++ >nul 2>nul
if not errorlevel 1 (
    echo Building with MinGW g++ (static runtime)
    g++ -O2 -static -mwindows ^
        WinResizer.cpp -o WinResizer.exe ^
        -lcomctl32 -ldwmapi -lgdi32 -luser32 -lole32 -luuid
    if errorlevel 1 goto :fail
    echo.
    echo OK -^> WinResizer.exe
    echo.
    choice /C YN /M "Also build + run the smoke test"
    if errorlevel 2 goto :eof
    g++ -O2 -static smoketest.cpp -o smoketest.exe
    smoketest.exe
    goto :eof
)

where cl >nul 2>nul
if not errorlevel 1 (
    echo Building with MSVC cl (static CRT)
    cl /O2 /EHsc /MT WinResizer.cpp user32.lib gdi32.lib comctl32.lib dwmapi.lib /link /SUBSYSTEM:WINDOWS
    if errorlevel 1 goto :fail
    echo OK -> WinResizer.exe
    goto :eof
)

echo ERROR: no C++ compiler found. Install MinGW-w64 or Visual Studio.
exit /b 1

:fail
echo.
echo BUILD FAILED
exit /b 1
