# build.ps1 — build plugin_starter on Windows without a POSIX shell.
#
# powershell -ExecutionPolicy Bypass -File build.ps1
# powershell -ExecutionPolicy Bypass -File build.ps1 -Static
#
# Uses MinGW-w64 (x86_64-w64-mingw32-gcc) because the result must be a STATIC
# native PE: a node that lacks the Visual C++ runtime must still run it.
# MSVC cl.exe works for local testing but produces a binary that may need
# vcruntime140.dll, so it is not used for publishing.
param(
[switch]$Static = $true,
[string]$CC = "x86_64-w64-mingw32-gcc",
[string]$Src = "plugin_starter.c",
[string]$Out = "plugin_starter.exe"
)
$ErrorActionPreference = "Stop"
function Fail($msg) { Write-Host "error: $msg" -ForegroundColor Red; exit 1 }
if (-not (Get-Command $CC -ErrorAction SilentlyContinue)) {
Fail "$CC not found on PATH (install MinGW-w64, or pass -CC C:\msys64\mingw64\bin\gcc.exe)"
}
if (-not (Test-Path $Src)) { Fail "$Src not found in $(Get-Location)" }
$args = @("-O2", "-std=c99", "-Wall", "-Wextra", "-Wno-overlength-strings")
if ($Static) { $args += "-static" }
$args += @("-o", $Out, $Src)
Write-Host "==> $CC $($args -join ' ')"
& $CC @args
if ($LASTEXITCODE -ne 0) { Fail "compile failed (exit $LASTEXITCODE)" }
if (-not (Test-Path $Out)) { Fail "no output produced" }
$size = (Get-Item $Out).Length
Write-Host ("==> built {0} ({1} bytes)" -f $Out, $size)
Write-Host "==> metadata"
& ".\$Out" --meta
if ($LASTEXITCODE -ne 0) { Fail "--meta smoke test failed" }
Write-Host ""
Write-Host "Install on this node (no server restart needed):"
Write-Host (" copy {0} `$env:LOCALAPPDATA\scorpiox\plugins\" -f $Out)
Write-Host "Then open Settings -> Menus -> Plugins and press Rescan."