kick/build.sh

47 lines
1.5 KiB
Bash
Raw Normal View History

2026-08-09 21:07:51 +10:00
#!/bin/sh
set -e
cd "$(dirname "$0")"
# 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 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