param( [ValidateSet("Release", "Debug", "Fast")] [string]$Mode = "Fast", [string[]]$Include = @(), [string[]]$Define = @(), [string[]]$Source = @(), [string[]]$Header = @(), [string[]]$Option = @(), [string]$Output, [string]$ObjectDir = "./build" ) New-Item -ItemType Directory -Force $ObjectDir | Out-Null if ($Source.Count -gt 1) { $unitySource = Join-Path $ObjectDir "unity.cc" $unityLines = @() foreach ($src in $Source) { if (-not $src) { continue } $full = (Resolve-Path $src).Path $includePath = $full.Replace('\', '/').Replace('"', '\"') $unityLines += "#include `"$includePath`"" } Set-Content -Path $unitySource -Value $unityLines -Encoding UTF8 $Source = @($unitySource) } $includeFlags = foreach ($item in $Include) { if ($item) { "-I$item" } } $defineFlags = foreach ($item in $Define) { if ($item) { "-D$item" } } if ($IsWindows) { $modeFlags = switch ($Mode) { "Debug" { @("/Ob0", "/Od", "-MDd", "-RTC1", "-Zi", "/FS") } "Fast" { @("/Od", "/Ob0", "-MD") } "Release" { @("/O2", "-MD", "-DNDEBUG") } } $linkLibraries = @( "user32.lib" "XInput.lib", "BCrypt.lib", "ole32.lib" ) cl /nologo /MP /TP /std:c++latest ` -IC:\VulkanSDK\1.4.341.1\Include\ ` $includeFlags ` $defineFlags ` $modeFlags ` /Zc:preprocessor /arch:AVX2 /EHs- /EHc- /GR- /Zc:threadSafeInit- ` /Fe:$Output ` /Fo:$ObjectDir/ ` /Fd:$ObjectDir/ ` $Option ` $Source ` /link $linkLibraries exit $LASTEXITCODE } else { $modeFlags = switch ($Mode) { "Debug" { @("-O0", "-g") } "Fast" { @("-O0", "-g0") } "Release" { @("-O2", "-DNDEBUG") } } $linkLibraries = @( "-lm", "-pthread", "-lxcb", "-lxcb-errors", "-lxcb-util", "-lxcb-xkb", "-lxkbcommon", "-lxkbcommon-x11", "-lxcb-xinput", "-lxcb-randr" ) g++ -x c++ -std=c++23 ` $includeFlags ` $defineFlags ` $modeFlags ` -fno-asynchronous-unwind-tables ` -fno-exceptions ` -fno-unwind-tables ` -fno-strict-aliasing ` -fvisibility=hidden ` -mavx2 ` -fno-rtti ` -fno-threadsafe-statics ` $Option ` $Source ` -o $Output ` -nostdlib++ ` $linkLibraries exit $LASTEXITCODE }