/
/
/
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)"
8
9# Single source of truth: read the pinned version and commit SHA from Dockerfile.base,
10# so the local build always matches what the base image ships.
11DOCKERFILE_BASE="${SCRIPT_DIR}/../../../../Dockerfile.base"
12read_docker_arg() {
13 local name="$1" value
14 value="$(sed -n -E "s/^ARG[[:space:]]+${name}=([^[:space:]]+).*/\1/p" "${DOCKERFILE_BASE}" | head -n1)"
15 if [[ -z "${value}" ]]; then
16 echo "Error: ${name} not found in ${DOCKERFILE_BASE}" >&2
17 exit 1
18 fi
19 printf '%s' "${value}"
20}
21SHAIRPORT_VERSION="$(read_docker_arg SHAIRPORT_VERSION)"
22SHAIRPORT_SHA="$(read_docker_arg SHAIRPORT_SHA)"
23
24echo "Building shairport-sync ${SHAIRPORT_VERSION} (${SHAIRPORT_SHA}) binaries..."
25
26# Function to build Linux binaries using Docker
27build_linux() {
28 local arch="$1"
29 local platform="$2"
30
31 echo "Building for Linux ${arch}..."
32
33 docker run --rm \
34 --platform "${platform}" \
35 -v "${SCRIPT_DIR}:/output" \
36 debian:bookworm-slim \
37 /bin/bash -c "
38 set -e
39
40 # Install build dependencies
41 # NOTE: Do NOT install libavahi-client-dev - we want tinysvcmdns instead
42 apt-get update && apt-get install -y --no-install-recommends \
43 build-essential \
44 git \
45 autoconf \
46 automake \
47 libtool \
48 pkg-config \
49 libconfig-dev \
50 libpopt-dev \
51 libssl-dev \
52 libdbus-1-dev \
53 libglib2.0-dev \
54 ca-certificates
55
56 # Fetch the pinned tag and verify it against the commit SHA from Dockerfile.base
57 cd /tmp
58 git init shairport-sync
59 cd shairport-sync
60 git remote add origin https://github.com/mikebrady/shairport-sync.git
61 git fetch --depth 1 origin refs/tags/${SHAIRPORT_VERSION}
62 git checkout FETCH_HEAD
63 test \"\$(git rev-parse HEAD)\" = \"${SHAIRPORT_SHA}\"
64
65 # Configure and build
66 # Build with tinysvcmdns (lightweight embedded mDNS, no external daemon needed)
67 autoreconf -fi
68 ./configure \
69 --with-pipe \
70 --with-metadata \
71 --without-avahi \
72 --without-dns-sd \
73 --with-tinysvcmdns \
74 --with-ssl=openssl \
75 --with-stdout \
76 --sysconfdir=/etc
77
78 make -j\$(nproc)
79
80 # Strip binary to reduce size
81 strip shairport-sync
82
83 # Copy to output
84 cp shairport-sync /output/shairport-sync-linux-${arch}
85 chmod +x /output/shairport-sync-linux-${arch}
86
87 # Show size
88 ls -lh /output/shairport-sync-linux-${arch}
89 "
90
91 echo "â Built shairport-sync-linux-${arch}"
92}
93
94# Function to build macOS binary
95build_macos() {
96 if [[ "$(uname)" != "Darwin" ]]; then
97 echo "â Skipping macOS build (must run on macOS)"
98 return
99 fi
100
101 echo "Building for macOS arm64..."
102
103 # Check if Homebrew is installed
104 if ! command -v brew &> /dev/null; then
105 echo "Error: Homebrew is required to build on macOS"
106 exit 1
107 fi
108
109 # Install dependencies
110 echo "Installing dependencies via Homebrew..."
111 brew list autoconf &> /dev/null || brew install autoconf
112 brew list automake &> /dev/null || brew install automake
113 brew list libtool &> /dev/null || brew install libtool
114 brew list pkg-config &> /dev/null || brew install pkg-config
115 brew list openssl &> /dev/null || brew install openssl
116 brew list popt &> /dev/null || brew install popt
117 brew list libconfig &> /dev/null || brew install libconfig
118 brew list libdaemon &> /dev/null || brew install libdaemon
119
120 # Create temp directory
121 TEMP_DIR=$(mktemp -d)
122 cd "${TEMP_DIR}"
123
124 # Fetch the pinned tag and verify it against the commit SHA from Dockerfile.base
125 git init shairport-sync
126 cd shairport-sync
127 git remote add origin https://github.com/mikebrady/shairport-sync.git
128 git fetch --depth 1 origin "refs/tags/${SHAIRPORT_VERSION}"
129 git checkout FETCH_HEAD
130 test "$(git rev-parse HEAD)" = "${SHAIRPORT_SHA}"
131
132 autoreconf -fi
133
134 # On macOS, librt is not needed and doesn't exist - patch configure to skip the check
135 sed -i.bak 's/as_fn_error $? "librt needed" "$LINENO" 5/echo "librt check skipped on macOS"/' configure
136
137 # Build with tinysvcmdns (lightweight embedded mDNS) for macOS
138 # Note: We still register via Music Assistant's Zeroconf, but shairport-sync
139 # needs some mDNS backend present to function properly
140 ./configure \
141 --with-pipe \
142 --with-metadata \
143 --with-ssl=openssl \
144 --with-stdout \
145 --without-avahi \
146 --without-dns-sd \
147 --with-tinysvcmdns \
148 --with-libdaemon \
149 PKG_CONFIG_PATH="$(brew --prefix openssl)/lib/pkgconfig:$(brew --prefix libconfig)/lib/pkgconfig" \
150 LDFLAGS="-L$(brew --prefix)/lib" \
151 CFLAGS="-I$(brew --prefix)/include" \
152 LIBS="-lm -lpthread -lssl -lcrypto -lconfig -lpopt"
153
154 make -j$(sysctl -n hw.ncpu)
155
156 # Strip binary
157 strip shairport-sync
158
159 # Copy to output
160 cp shairport-sync "${SCRIPT_DIR}/shairport-sync-macos-$(uname -m)"
161 chmod +x "${SCRIPT_DIR}/shairport-sync-macos-$(uname -m)"
162
163 # Cleanup
164 cd "${SCRIPT_DIR}"
165 rm -rf "${TEMP_DIR}"
166
167 ls -lh "${SCRIPT_DIR}/shairport-sync-macos-$(uname -m)"
168 echo "â Built shairport-sync-macos-$(uname -m)"
169}
170
171# Main build process
172case "${1:-all}" in
173 linux-x86_64)
174 build_linux "x86_64" "linux/amd64"
175 ;;
176 linux-aarch64)
177 build_linux "aarch64" "linux/arm64"
178 ;;
179 macos)
180 build_macos
181 ;;
182 all)
183 build_linux "x86_64" "linux/amd64"
184 build_linux "aarch64" "linux/arm64"
185 build_macos
186 ;;
187 *)
188 echo "Usage: $0 {linux-x86_64|linux-aarch64|macos|all}"
189 echo
190 echo "The version and commit are pinned in Dockerfile.base"
191 echo "(SHAIRPORT_VERSION / SHAIRPORT_SHA) and read from there."
192 exit 1
193 ;;
194esac
195
196echo
197echo "Build complete! Binaries are in:"
198ls -lh "${SCRIPT_DIR}"/shairport-sync-* 2>/dev/null || echo "No binaries found"
199echo
200echo "Note: These binaries are dynamically linked. For Docker deployments,"
201echo "it's recommended to install shairport-sync via apk/apt instead."
202