@echo off
setlocal enabledelayedexpansion

if "%~1"=="" (
    echo Usage: build.cmd [Debug^|Release]
    exit /b 1
)

set CONFIG=%~1

if /I "%CONFIG%"=="Debug" (
    set CFLAGS=/MDd /Od /Zi /DDEBUG /DEBUG -diagnostics:caret -diagnostics:column -D_CRT_SECURE_NO_WARNINGS -D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING -D_CRT_NONSTDC_NO_DEPRECATE -D_USE_MATH_DEFINES
    set LIB_PATH=bin
    set IMGUI_LIB_PATH=bin\Debug\dear-imgui.lib
) else if /I "%CONFIG%"=="Release" (
    set CFLAGS=/MD /O2 /DNDEBUG
    set LIB_PATH=bin
    set IMGUI_LIB_PATH=bin\Release\dear-imgui.lib
) else (
    echo Invalid configuration: %CONFIG%
    echo Usage: build.cmd [Debug^|Release]
    exit /b 1
)

set OBJDIR=obj

if not exist "%LIB_PATH%" mkdir "%LIB_PATH%"
if not exist obj mkdir obj

set LIB_NAME=musa

set SRC_FILES=^
  exe_main.cpp

set INCLUDE_DIRS=^
  /Isrc ^
  /Ilib ^
  /Ilib\api ^
  /Ithird_party

set LINK_LIBS=^
  %IMGUI_LIB_PATH%

rem NOTE: it defaults to C++11, so /std:c++11 is redundant
rem SHARED LIBRARY:
    rem echo Building DLL (%CONFIG%) 
    rem cl /nologo /EHsc /DWIN32 /wd4530 %CFLAGS% %INCLUDE_DIRS% %SRC_FILES% /LD /Fe%LIB_PATH%\%LIB_NAME%.dll /Fo%OBJDIR%\ /link %LINK_LIBS%
echo Building EXE (%CONFIG%)...
cl /nologo /EHsc /DWIN32 /wd4530 %CFLAGS% %INCLUDE_DIRS% %SRC_FILES% /link /MACHINE:AMD64 %LINK_LIBS% /OUT:%LIB_PATH%\%LIB_NAME%.exe

rem cleanup...
rd /s /q "%OBJDIR%"

rem echo Running post-build script...
rem nothing to do (for now).
endlocal
