#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
GO_BIN="${GO_BIN:-go}"
command -v "$GO_BIN" >/dev/null 2>&1 || { echo "Go compiler not found" >&2; exit 1; }
mkdir -p "$ROOT/bin" "$ROOT/android/lib/arm64-v8a"
cd "$ROOT/core"

echo "[core] Android ARM64 client..."
CGO_ENABLED=0 GOOS=android GOARCH=arm64 "$GO_BIN" build -trimpath -ldflags='-s -w' \
  -o "$ROOT/android/lib/arm64-v8a/libdragontcp_client.so" ./cmd/dragontcp-client

echo "[core] Linux AMD64 server..."
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 "$GO_BIN" build -trimpath -ldflags='-s -w' \
  -o "$ROOT/bin/dragontcp-hybrid-server-linux-amd64" ./cmd/dragontcp-server

echo "[core] Linux ARM64 server..."
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 "$GO_BIN" build -trimpath -ldflags='-s -w' \
  -o "$ROOT/bin/dragontcp-hybrid-server-linux-arm64" ./cmd/dragontcp-server

echo "Core build complete."
