#!/usr/bin/env bash # scripts/remote-build-display-control.sh # Build the display_control universal binary on a remote Mac via SSH, # then pull the result back to resources/bin/display_control. # # Use this from the Linux workstation when you don't have a Mac locally. # The target Mac must have Xcode Command Line Tools installed. # # USAGE: # ./scripts/remote-build-display-control.sh # uses default Mac (laptop 01) # ./scripts/remote-build-display-control.sh 192.168.32.102 # # The default IP is laptop 01 — the designated build Mac. # Change DEFAULT_IP below if Xcode moves to a different laptop. # # SSH key must already be installed on the target: # ssh-copy-id "speaker ready"@192.168.32.101 set -eo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" SRC="$SCRIPT_DIR/display_control.m" OUT_BIN="$REPO_ROOT/resources/bin/display_control" SSH_USER="speaker ready" DEFAULT_IP="192.168.32.101" IP="${1:-$DEFAULT_IP}" REMOTE_TMP="/tmp/ae_display_control_build" echo "═══════════════════════════════════════════════" echo " Remote build: display_control" echo " Build Mac: $SSH_USER @ $IP" echo "═══════════════════════════════════════════════" # ── Step 1: Copy source to remote ──────────────────────────────────────────── echo "" echo "Step 1/4 — Copying source to $IP..." ssh "$SSH_USER@$IP" "mkdir -p $REMOTE_TMP" ssh "$SSH_USER@$IP" "cat > $REMOTE_TMP/display_control.m" < "$SRC" # ── Step 2: Build universal binary on remote ────────────────────────────────── echo "" echo "Step 2/4 — Building on $IP..." ssh "$SSH_USER@$IP" bash << 'ENDSSH' set -e REMOTE_TMP="/tmp/ae_display_control_build" SRC="$REMOTE_TMP/display_control.m" TMP_X86="$REMOTE_TMP/display_control_x86_64" TMP_ARM="$REMOTE_TMP/display_control_arm64" OUT="$REMOTE_TMP/display_control" echo " Compiling x86_64..." clang -arch x86_64 -framework Cocoa -framework Carbon -o "$TMP_X86" "$SRC" echo " Compiling arm64..." clang -arch arm64 -framework Cocoa -framework Carbon -o "$TMP_ARM" "$SRC" echo " Linking universal binary..." lipo -create -output "$OUT" "$TMP_X86" "$TMP_ARM" rm "$TMP_X86" "$TMP_ARM" chmod +x "$OUT" echo " Archs: $(lipo -archs "$OUT")" ENDSSH # ── Step 3: Pull binary back ────────────────────────────────────────────────── echo "" echo "Step 3/4 — Pulling binary to resources/bin/..." mkdir -p "$(dirname "$OUT_BIN")" ssh "$SSH_USER@$IP" "cat $REMOTE_TMP/display_control" > "$OUT_BIN" chmod +x "$OUT_BIN" # ── Step 4: Clean up remote ─────────────────────────────────────────────────── echo "" echo "Step 4/4 — Cleaning up remote..." ssh "$SSH_USER@$IP" "rm -rf $REMOTE_TMP" # ── Done ────────────────────────────────────────────────────────────────────── echo "" echo "═══════════════════════════════════════════════" echo " Built: $OUT_BIN" file "$OUT_BIN" echo "" echo " If both archs shown above, you're good:" echo " git add resources/bin/display_control" echo " git commit -m \"build: update display_control binary (universal)\"" echo "═══════════════════════════════════════════════"