| 1 | # build.ps1 - Windows MinGW-w64 static build for plugin_google_quota |
| 2 | # |
| 3 | # Usage (from the repo root, PowerShell): |
| 4 | # powershell -ExecutionPolicy Bypass -File build.ps1 |
| 5 | # |
| 6 | # Produces .\plugin_google_quota.exe (static PE, runs on any Windows 10/11 x64 node). |
| 7 | # Requires x86_64-w64-mingw32-gcc or a WinLibs/UCRT gcc on PATH (or C:\gcc16\bin). |
| 8 | |
| 9 | $ErrorActionPreference = "Stop" |
| 10 | $ScriptDir = $PSScriptRoot |
| 11 | Push-Location $ScriptDir |
| 12 | try { |
| 13 | $Src = Join-Path $ScriptDir "src\plugin_google_quota.c" |
| 14 | $Out = Join-Path $ScriptDir "plugin_google_quota.exe" |
| 15 | $Cc = "x86_64-w64-mingw32-gcc" |
| 16 | |
| 17 | if (-not (Test-Path $Src)) { throw "source not found: $Src" } |
| 18 | |
| 19 | if (-not (Get-Command $Cc -ErrorAction SilentlyContinue)) { |
| 20 | if (Test-Path "C:\gcc16\bin\gcc.exe") { |
| 21 | $Cc = "C:\gcc16\bin\gcc.exe" |
| 22 | } elseif (Get-Command gcc -ErrorAction SilentlyContinue) { |
| 23 | $Cc = "gcc" |
| 24 | } else { |
| 25 | throw "no C compiler found (need x86_64-w64-mingw32-gcc or gcc)" |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | if (Get-Command python -ErrorAction SilentlyContinue) { |
| 30 | python tools\gen_ui.py |
| 31 | } |
| 32 | |
| 33 | Write-Host "==> building plugin_google_quota.exe with $Cc" |
| 34 | & $Cc -O2 -std=c99 -Wall -Wextra -I src -static -o $Out $Src |
| 35 | if ($LASTEXITCODE -ne 0) { throw "compile failed (exit $LASTEXITCODE)" } |
| 36 | |
| 37 | if (-not (Test-Path $Out)) { throw "build produced no output" } |
| 38 | |
| 39 | $bytes = [System.IO.File]::ReadAllBytes($Out) |
| 40 | if ($bytes.Length -lt 2 -or $bytes[0] -ne 0x4D -or $bytes[1] -ne 0x5A) { |
| 41 | throw "output is not a PE executable (missing MZ header)" |
| 42 | } |
| 43 | |
| 44 | Write-Host "==> ok: $Out ($($bytes.Length) bytes)" |
| 45 | Write-Host " smoke test: .\plugin_google_quota.exe --meta" |
| 46 | } finally { |
| 47 | Pop-Location |
| 48 | } |