build: add a 'release' target for an optimized, stripped binary

./build.sh release builds into build-release/ with --buildtype=release
and strips the binary in place (meson's strip only applies on install),
yielding a ~270KB binary for size benchmarking against distro
compositors like labwc.  The default ./build.sh debug path and the
build/ tree used by the test suite are untouched.
This commit is contained in:
Andrew Hamilton 2026-09-04 13:07:40 +10:00
parent 9d1e3e802c
commit 5a9464c454

View file

@ -6,6 +6,10 @@ set -e
cd "$(dirname "$0")"
# ./build.sh -> debug build in build/ (for the test suite)
# ./build.sh release -> optimized + stripped binary in build-release/
# for size benchmarking. The debug build/ is untouched.
#
# Rebuild only when a source is newer than the built binary; otherwise
# meson setup/compile would (re)generate everything each run. Sources
# are tracked per program: kick.c only feeds kick, tests/wltest.c only
@ -28,8 +32,26 @@ stale() {
return 1
}
if [ "$1" = "release" ]; then
[ $# -ne 1 ] && { echo "usage: $0 [release]" >&2; exit 2; }
if stale build-release/kick kick.c meson.build subprojects wlr-protocols; then
set -x
meson setup build-release --reconfigure --buildtype=release
meson compile -C build-release kick
# meson only strips on install, not the build-tree binary, so strip
# it in place to match a distro package.
strip -o build-release/kick.tmp build-release/kick
mv -f build-release/kick.tmp build-release/kick
echo "Built: ./build-release/kick (optimized + stripped)"
else
echo "build: nothing to do (release binary up to date)"
fi
exit $?
fi
[ $# -gt 0 ] && { echo "usage: $0 [release]" >&2; exit 2; }
if stale build/kick kick.c meson.build subprojects wlr-protocols \
|| stale build/wltest tests/wltest.c meson.build subprojects; then
|| stale build/wltest tests/wltest.c meson.build subprojects; then
set -x
meson setup build --reconfigure
meson compile -C build