Skip to content
This repository was archived by the owner on Apr 20, 2026. It is now read-only.

Commit 5dff85f

Browse files
committed
Bundle Linux shared libs and add wrapper
Discover non-system shared libraries with ldd and copy them to dist/lib (skip libc, ld-linux, libm, libpthread, etc.). Rename qemu-pebble to qemu-pebble.bin and add a wrapper that sets LD_LIBRARY_PATH so the binary uses the bundled libs.
1 parent 732d798 commit 5dff85f

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

build.sh

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,10 @@ rm -f "${BUILD_DIR}/build.ninja"
217217

218218
cd "${BUILD_DIR}"
219219

220-
# Linux gets a fully static binary so the dist tarball doesn't need bundled libs.
221-
# macOS dynamically links and ships dylibs alongside the binary (static linking
222-
# of system frameworks isn't supported on Darwin).
220+
# Both macOS and Linux dynamically link and ship dependent libs alongside the
221+
# binary. Fully static linking on Linux with SDL2 is a trap: libudev, libdbus,
222+
# libwayland etc. don't ship .a files on most distros.
223223
CONFIGURE_EXTRA=()
224-
if [ "$OS" = "Linux" ]; then
225-
CONFIGURE_EXTRA+=(--static --disable-pie)
226-
fi
227224

228225
"${QEMU_SRC}/configure" \
229226
--target-list=arm-softmmu \
@@ -283,8 +280,31 @@ if [ "$OS" = "Darwin" ]; then
283280
fi
284281
done
285282
else
286-
# Linux build is fully static — no bundled libs needed.
287-
echo " static build — no libs to bundle"
283+
mkdir -p "${DIST_DIR}/lib"
284+
# Linux: discover non-system shared libs via ldd and copy them.
285+
# Skip libc, libm, libpthread, libdl, ld-linux, etc. — those must come from the host.
286+
SKIP_RE='^(linux-vdso\.|ld-linux|libc\.|libm\.|libdl\.|libpthread\.|librt\.|libresolv\.|libnsl\.|libutil\.|libgcc_s\.|libstdc\+\+\.)'
287+
ldd "${BUILD_DIR}/qemu-system-arm" \
288+
| awk '/=>/ {print $1, $3}' \
289+
| while read -r soname libpath; do
290+
[ -z "$libpath" ] && continue
291+
[ ! -f "$libpath" ] && continue
292+
if echo "$soname" | grep -Eq "$SKIP_RE"; then
293+
continue
294+
fi
295+
cp -L "$libpath" "${DIST_DIR}/lib/"
296+
echo " -> lib/$(basename "$libpath")"
297+
done
298+
299+
# Write a wrapper so the binary finds its bundled libs via $ORIGIN/../lib
300+
mv "${DIST_DIR}/bin/qemu-pebble" "${DIST_DIR}/bin/qemu-pebble.bin"
301+
cat > "${DIST_DIR}/bin/qemu-pebble" << 'WRAPPER'
302+
#!/bin/sh
303+
HERE="$(cd "$(dirname "$0")" && pwd)"
304+
export LD_LIBRARY_PATH="${HERE}/../lib:${LD_LIBRARY_PATH:-}"
305+
exec "${HERE}/qemu-pebble.bin" "$@"
306+
WRAPPER
307+
chmod +x "${DIST_DIR}/bin/qemu-pebble"
288308
fi
289309

290310
echo ""

0 commit comments

Comments
 (0)