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

set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
if not exist "%VSWHERE%" (
    echo ERROR: neither g++ nor Visual Studio found
    exit /b 1
)
for /f "usebackq delims=" %%i in (`
    "%VSWHERE%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -find VC\Auxiliary\Build\vcvars64.bat
`) do set "VCVARS=%%i"
if not defined VCVARS (
    echo ERROR: vcvars64.bat not found
    exit /b 1
)
call "%VCVARS%"
cl /O2 /W3 esp.c /Fe:chameleon_esp.exe /link user32.lib gdi32.lib dwmapi.lib advapi32.lib
