| 1 | # build.ps1 - Windows MinGW-w64 static build for plugin_ntfy |
| 2 | # |
| 3 | # Usage (from the repo root, PowerShell): |
| 4 | # powershell -ExecutionPolicy Bypass -File build.ps1 |
| 5 | # |
| 6 | # Produces .\plugin_ntfy.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 | # The link needs -lws2_32 (Winsock) and -lbcrypt (mbedTLS bcrypt RNG path). |
| 10 | # Sources: the three plugin files + the two vendored libraries (yyjson and |
| 11 | # Mbed TLS 3.6.6). The vendored public headers live in src\mbedtls + src\psa |
| 12 | # so the fixed -I src resolves quoted "mbedtls/*.h" includes. |
| 13 | |
| 14 | $ErrorActionPreference = "Stop" |
| 15 | $ScriptDir = $PSScriptRoot |
| 16 | Push-Location $ScriptDir |
| 17 | try { |
| 18 | $Out = Join-Path $ScriptDir "plugin_ntfy.exe" |
| 19 | $Cc = "x86_64-w64-mingw32-gcc" |
| 20 | |
| 21 | if (-not (Get-Command $Cc -ErrorAction SilentlyContinue)) { |
| 22 | if (Test-Path "C:\gcc16\bin\gcc.exe") { |
| 23 | $Cc = "C:\gcc16\bin\gcc.exe" |
| 24 | } elseif (Get-Command gcc -ErrorAction SilentlyContinue) { |
| 25 | $Cc = "gcc" |
| 26 | } else { |
| 27 | throw "no C compiler found (need x86_64-w64-mingw32-gcc or gcc)" |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | # Regenerate the page header so the binary always matches src\ui.html. |
| 32 | if (Get-Command python -ErrorAction SilentlyContinue) { |
| 33 | python tools\gen_ui.py |
| 34 | } |
| 35 | |
| 36 | $Srcs = @( |
| 37 | "src\plugin_ntfy.c", "src\sx_http.c", "src\sx_connectors.c", |
| 38 | "vendor\yyjson.c" |
| 39 | ) + (Get-ChildItem "vendor\mbedtls\*.c" | ForEach-Object { $_.FullName }) |
| 40 | |
| 41 | Write-Host "==> building plugin_ntfy.exe with $Cc ($($Srcs.Count) sources)" |
| 42 | & $Cc -O2 -std=c99 -Wall -Wextra -Wno-overlength-strings -I src -I vendor ` |
| 43 | "-DMBEDTLS_CONFIG_FILE=<sx_ntfy_mbedtls_config.h>" -static ` |
| 44 | -o $Out $Srcs -lws2_32 -lbcrypt |
| 45 | if ($LASTEXITCODE -ne 0) { throw "compile failed (exit $LASTEXITCODE)" } |
| 46 | |
| 47 | if (-not (Test-Path $Out)) { throw "build produced no output" } |
| 48 | |
| 49 | $bytes = [System.IO.File]::ReadAllBytes($Out) |
| 50 | if ($bytes.Length -lt 2 -or $bytes[0] -ne 0x4D -or $bytes[1] -ne 0x5A) { |
| 51 | throw "output is not a PE executable (missing MZ header)" |
| 52 | } |
| 53 | |
| 54 | Write-Host "==> ok: $Out ($($bytes.Length) bytes)" |
| 55 | Write-Host " smoke test: .\plugin_ntfy.exe --meta" |
| 56 | } finally { |
| 57 | Pop-Location |
| 58 | } |