kick/build.sh
Andrew Hamilton 5a9464c454 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.
2026-09-04 13:07:40 +10:00

68 lines
2.4 KiB
Bash
Executable file

#!/bin/sh
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
# feeds wltest, while meson.build and the vendored subprojects feed both.
stale() {
# $1 = binary; $2.. = source paths/dirs it depends on.
bin=$1
shift
[ -x "$bin" ] || return 0
for p in "$@"; do
[ -e "$p" ] || continue
if [ -d "$p" ]; then
if find "$p" -type f -newer "$bin" ! -name '.wraplock' -print -quit | grep -q .; then
return 0
fi
elif [ "$p" -nt "$bin" ]; then
return 0
fi
done
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
set -x
meson setup build --reconfigure
meson compile -C build
# A successful build means the binaries now reflect every tracked
# source, even ones meson decided not to relink (e.g. wltest after
# only meson.build changed). Touch them so the mtime-based stale()
# fast-path doesn't keep flagging them forever. Ninja tracks
# incrementality via its own dep files, not the binary's mtime, so this
# never fools the next real rebuild.
touch build/kick build/wltest
echo "Built: ./build/kick"
else
echo "build: nothing to do (binaries up to date)"
fi