#!/bin/bash set -e BINARY_NAME="opencode-monitor" VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev") SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" cd "$PROJECT_DIR" detect_platform() { local os arch suffix os=$(uname -s | tr '[:upper:]' '[:lower:]') arch=$(uname -m) case "$os" in linux*) os="linux" ;; darwin*) os="darwin" ;; *) os="windows" ;; esac case "$arch" in x86_64|amd64) arch="amd64" ;; aarch64|arm64) arch="arm64" ;; *) arch="amd64" ;; esac if [ "$os" = "windows" ]; then suffix=".exe" else suffix="" fi echo "${os}-${arch}${suffix}" } if [ "$1" = "--only-ble" ]; then echo "=== Building BLE relay only ===" python3 -m pip install pyinstaller bleak || python -m pip install pyinstaller bleak mkdir -p bin python3 -m PyInstaller --onefile --name ble_relay --distpath bin --specpath build --workpath build scripts/ble_relay.py || python -m PyInstaller --onefile --name ble_relay --distpath bin --specpath build --workpath build scripts/ble_relay.py cp bin/ble_relay cmd/monitor/ble_relay echo "" echo "Done: bin/ble_relay + cmd/monitor/ble_relay" elif [ "$1" = "--ble" ]; then PLATFORM=$(detect_platform) echo "=== Building for ${PLATFORM} with BLE ===" echo "Step 1: Building BLE relay..." python3 -m pip install pyinstaller bleak || python -m pip install pyinstaller bleak mkdir -p bin python3 -m PyInstaller --onefile --name ble_relay --distpath bin --specpath build --workpath build scripts/ble_relay.py || python -m PyInstaller --onefile --name ble_relay --distpath bin --specpath build --workpath build scripts/ble_relay.py cp bin/ble_relay cmd/monitor/ble_relay echo "Step 2: Building Go binary with BLE embedded..." go mod tidy mkdir -p dist go build -tags ble -ldflags "-X main.Version=${VERSION}" -o "dist/${BINARY_NAME}-${PLATFORM}" ./cmd/monitor rm -f cmd/monitor/ble_relay echo "" echo "Done: dist/${BINARY_NAME}-${PLATFORM}" else echo "=== Building all platforms (no BLE) ===" mkdir -p dist go mod tidy echo "Building for Linux (amd64)..." GOOS=linux GOARCH=amd64 go build -ldflags "-X main.Version=${VERSION}" -o dist/${BINARY_NAME}-linux-amd64 ./cmd/monitor echo "Building for Linux (arm64)..." GOOS=linux GOARCH=arm64 go build -ldflags "-X main.Version=${VERSION}" -o dist/${BINARY_NAME}-linux-arm64 ./cmd/monitor echo "Building for macOS (amd64)..." GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.Version=${VERSION}" -o dist/${BINARY_NAME}-darwin-amd64 ./cmd/monitor echo "Building for macOS (arm64)..." GOOS=darwin GOARCH=arm64 go build -ldflags "-X main.Version=${VERSION}" -o dist/${BINARY_NAME}-darwin-arm64 ./cmd/monitor echo "Building for Windows (amd64)..." GOOS=windows GOARCH=amd64 go build -ldflags "-X main.Version=${VERSION}" -o dist/${BINARY_NAME}-windows-amd64.exe ./cmd/monitor echo "Building for Windows (arm64)..." GOOS=windows GOARCH=arm64 go build -ldflags "-X main.Version=${VERSION}" -o dist/${BINARY_NAME}-windows-arm64.exe ./cmd/monitor echo "" echo "Done! Binaries in dist/" ls -la dist/ fi