87 lines
3.3 KiB
Bash
87 lines
3.3 KiB
Bash
#!/bin/bash
|
|
|
|
# MPVJ Build Script
|
|
# Runs on x86_64 (e.g., Docker) to cross-compile artifacts for aarch64 (RPi 3B).
|
|
# Outputs (committed back to the repo):
|
|
# frontend/dist/ — pre-built Vite bundle
|
|
# bin/ofxPiMapper — aarch64 binary
|
|
#
|
|
# Usage:
|
|
# bash build.sh <REPO_URL> # clones repo into ./mapper, then builds
|
|
# bash build.sh <REPO_URL> <DIR> # clones into DIR, then builds
|
|
|
|
set -e
|
|
|
|
REPO_URL="${1:-}"
|
|
REPO_DIR="${2:-$(pwd)/mapper}"
|
|
BIN_OUT="$REPO_DIR/bin"
|
|
|
|
if [ -z "$REPO_URL" ]; then
|
|
echo "Usage: bash $0 <REPO_URL> [CLONE_DIR]"
|
|
exit 1
|
|
fi
|
|
|
|
# ── Clone repo if needed ─────────────────────────────────────────────────────
|
|
if [ ! -d "$REPO_DIR/frontend" ] || [ ! -d "$REPO_DIR/backend" ]; then
|
|
echo "Cloning $REPO_URL into $REPO_DIR ..."
|
|
git clone "$REPO_URL" "$REPO_DIR"
|
|
fi
|
|
echo "Building from: $REPO_DIR"
|
|
|
|
# ── 1. Install build dependencies ───────────────────────────────────────────
|
|
echo "Installing build dependencies..."
|
|
if command -v apt-get > /dev/null 2>&1; then
|
|
apt-get update -y
|
|
DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
|
git curl wget unzip build-essential \
|
|
gcc-aarch64-linux-gnu g++-aarch64-linux-gnu \
|
|
binutils-aarch64-linux-gnu \
|
|
libmpg123-dev libsndfile1-dev libopenal-dev libassimp-dev \
|
|
libglew-dev libglfw3-dev liburiparser-dev \
|
|
libcurl4-openssl-dev libpugixml-dev libasound2-dev \
|
|
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
|
|
gstreamer1.0-plugins-good gstreamer1.0-plugins-bad \
|
|
gstreamer1.0-plugins-ugly gstreamer1.0-libav \
|
|
libgtk-3-dev libboost-filesystem-dev \
|
|
libfontconfig1-dev libfreetype-dev libx11-dev \
|
|
libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev \
|
|
libpulse-dev libudev-dev libfreeimage-dev librtaudio-dev \
|
|
freeglut3-dev libxxf86vm-dev
|
|
fi
|
|
|
|
# Install Node.js if missing
|
|
if ! command -v node > /dev/null 2>&1; then
|
|
echo "Installing Node.js 20..."
|
|
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
|
|
apt-get install -y nodejs
|
|
fi
|
|
|
|
# ── 2. Build frontend ────────────────────────────────────────────────────────
|
|
echo ""
|
|
echo "=== Building frontend ==="
|
|
cd "$REPO_DIR/frontend"
|
|
rm -rf node_modules package-lock.json
|
|
npm install --package-lock=false
|
|
NODE_OPTIONS="--max-old-space-size=512" npm run build
|
|
echo "Frontend built → $REPO_DIR/frontend/dist/"
|
|
|
|
# ── 3. Commit and push frontend artifact back to repo ───────────────────────
|
|
echo ""
|
|
echo "=== Pushing frontend/dist to remote ==="
|
|
cd "$REPO_DIR"
|
|
git config user.email "build-bot@mpvj" 2>/dev/null || true
|
|
git config user.name "MPVJ Build Bot" 2>/dev/null || true
|
|
git add frontend/dist/
|
|
git commit -m "ci: add pre-built frontend/dist" || echo "(nothing new to commit)"
|
|
git push
|
|
|
|
echo ""
|
|
echo "============================================"
|
|
echo " BUILD COMPLETE + PUSHED"
|
|
echo "============================================"
|
|
echo " Frontend: $REPO_DIR/frontend/dist/"
|
|
echo ""
|
|
echo " ofxPiMapper will be compiled natively on"
|
|
echo " the Pi when you run setup.sh."
|
|
echo "============================================"
|