@echo off
chcp 65001 >nul
setlocal EnableDelayedExpansion

set "VCVARS=C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
if not exist "!VCVARS!" (
    echo [ERROR] MSVC Build Tools not found at !VCVARS!
    exit /b 1
)

call "!VCVARS!" >nul
echo [BUILD] Compiling d3d_gltf_demo with eduwin.lib...

rc /nologo app.rc
cl /nologo /W3 /utf-8 /std:c17 /I..\..\eduwin\include /c main.c
if errorlevel 1 (
    echo [ERROR] Compilation failed
    exit /b 1
)

link /nologo main.obj app.res ..\..\eduwin\lib\eduwin.lib user32.lib gdi32.lib gdiplus.lib comctl32.lib comdlg32.lib shell32.lib winmm.lib ole32.lib oleaut32.lib version.lib advapi32.lib d3d11.lib d3dcompiler.lib /out:d3d_gltf_demo.exe /subsystem:windows /entry:mainCRTStartup
if errorlevel 1 (
    echo [ERROR] Link failed
    exit /b 1
) else (
    echo [OK] Build success! d3d_gltf_demo.exe created
)
