music-assistant-server

5.5 KBSH
build_binaries.sh
5.5 KB180 lines • bash
1#!/usr/bin/env bash
2set -e
3
4# Build script for shairport-sync binaries across different platforms
5# This script uses Docker to build binaries in isolated environments
6
7SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8SHAIRPORT_VERSION="${SHAIRPORT_VERSION:-4.3.7}"
9
10echo "Building shairport-sync ${SHAIRPORT_VERSION} binaries..."
11
12# Function to build Linux binaries using Docker
13build_linux() {
14    local arch="$1"
15    local platform="$2"
16
17    echo "Building for Linux ${arch}..."
18
19    docker run --rm \
20        --platform "${platform}" \
21        -v "${SCRIPT_DIR}:/output" \
22        debian:bookworm-slim \
23        /bin/bash -c "
24            set -e
25
26            # Install build dependencies
27            # NOTE: Do NOT install libavahi-client-dev - we want tinysvcmdns instead
28            apt-get update && apt-get install -y --no-install-recommends \
29                build-essential \
30                git \
31                autoconf \
32                automake \
33                libtool \
34                pkg-config \
35                libconfig-dev \
36                libpopt-dev \
37                libssl-dev \
38                libdbus-1-dev \
39                libglib2.0-dev \
40                ca-certificates
41
42            # Clone and checkout specific version
43            cd /tmp
44            git clone --depth 1 --branch ${SHAIRPORT_VERSION} https://github.com/mikebrady/shairport-sync.git
45            cd shairport-sync
46
47            # Configure and build
48            # Build with tinysvcmdns (lightweight embedded mDNS, no external daemon needed)
49            autoreconf -fi
50            ./configure \
51                --with-pipe \
52                --with-metadata \
53                --without-avahi \
54                --without-dns-sd \
55                --with-tinysvcmdns \
56                --with-ssl=openssl \
57                --with-stdout \
58                --sysconfdir=/etc
59
60            make -j\$(nproc)
61
62            # Strip binary to reduce size
63            strip shairport-sync
64
65            # Copy to output
66            cp shairport-sync /output/shairport-sync-linux-${arch}
67            chmod +x /output/shairport-sync-linux-${arch}
68
69            # Show size
70            ls -lh /output/shairport-sync-linux-${arch}
71        "
72
73    echo "✓ Built shairport-sync-linux-${arch}"
74}
75
76# Function to build macOS binary
77build_macos() {
78    if [[ "$(uname)" != "Darwin" ]]; then
79        echo "⚠ Skipping macOS build (must run on macOS)"
80        return
81    fi
82
83    echo "Building for macOS arm64..."
84
85    # Check if Homebrew is installed
86    if ! command -v brew &> /dev/null; then
87        echo "Error: Homebrew is required to build on macOS"
88        exit 1
89    fi
90
91    # Install dependencies
92    echo "Installing dependencies via Homebrew..."
93    brew list autoconf &> /dev/null || brew install autoconf
94    brew list automake &> /dev/null || brew install automake
95    brew list libtool &> /dev/null || brew install libtool
96    brew list pkg-config &> /dev/null || brew install pkg-config
97    brew list openssl &> /dev/null || brew install openssl
98    brew list popt &> /dev/null || brew install popt
99    brew list libconfig &> /dev/null || brew install libconfig
100    brew list libdaemon &> /dev/null || brew install libdaemon
101
102    # Create temp directory
103    TEMP_DIR=$(mktemp -d)
104    cd "${TEMP_DIR}"
105
106    # Clone and build
107    git clone --depth 1 --branch "${SHAIRPORT_VERSION}" https://github.com/mikebrady/shairport-sync.git
108    cd shairport-sync
109
110    autoreconf -fi
111
112    # On macOS, librt is not needed and doesn't exist - patch configure to skip the check
113    sed -i.bak 's/as_fn_error $? "librt needed" "$LINENO" 5/echo "librt check skipped on macOS"/' configure
114
115    # Build with tinysvcmdns (lightweight embedded mDNS) for macOS
116    # Note: We still register via Music Assistant's Zeroconf, but shairport-sync
117    # needs some mDNS backend present to function properly
118    ./configure \
119        --with-pipe \
120        --with-metadata \
121        --with-ssl=openssl \
122        --with-stdout \
123        --without-avahi \
124        --without-dns-sd \
125        --with-tinysvcmdns \
126        --with-libdaemon \
127        PKG_CONFIG_PATH="$(brew --prefix openssl)/lib/pkgconfig:$(brew --prefix libconfig)/lib/pkgconfig" \
128        LDFLAGS="-L$(brew --prefix)/lib" \
129        CFLAGS="-I$(brew --prefix)/include" \
130        LIBS="-lm -lpthread -lssl -lcrypto -lconfig -lpopt"
131
132    make -j$(sysctl -n hw.ncpu)
133
134    # Strip binary
135    strip shairport-sync
136
137    # Copy to output
138    cp shairport-sync "${SCRIPT_DIR}/shairport-sync-macos-$(uname -m)"
139    chmod +x "${SCRIPT_DIR}/shairport-sync-macos-$(uname -m)"
140
141    # Cleanup
142    cd "${SCRIPT_DIR}"
143    rm -rf "${TEMP_DIR}"
144
145    ls -lh "${SCRIPT_DIR}/shairport-sync-macos-$(uname -m)"
146    echo "✓ Built shairport-sync-macos-$(uname -m)"
147}
148
149# Main build process
150case "${1:-all}" in
151    linux-x86_64)
152        build_linux "x86_64" "linux/amd64"
153        ;;
154    linux-aarch64)
155        build_linux "aarch64" "linux/arm64"
156        ;;
157    macos)
158        build_macos
159        ;;
160    all)
161        build_linux "x86_64" "linux/amd64"
162        build_linux "aarch64" "linux/arm64"
163        build_macos
164        ;;
165    *)
166        echo "Usage: $0 {linux-x86_64|linux-aarch64|macos|all}"
167        echo
168        echo "Environment variables:"
169        echo "  SHAIRPORT_VERSION  - Version to build (default: 4.3.7)"
170        exit 1
171        ;;
172esac
173
174echo
175echo "Build complete! Binaries are in:"
176ls -lh "${SCRIPT_DIR}"/shairport-sync-* 2>/dev/null || echo "No binaries found"
177echo
178echo "Note: These binaries are dynamically linked. For Docker deployments,"
179echo "it's recommended to install shairport-sync via apk/apt instead."
180