I ran into this useful tip that if you\'re working on files a lot and you want them to build automatically you run:
watch make
And it re-runs make every couple s
This shell script uses make
itself to detect changes with the -q
flag, and then does a full rebuild if and only if there are changes.
#!/bin/sh
while true;
do
if ! make -q "$@";
then
echo "#-> Starting build: `date`"
make "$@";
echo "#-> Build complete."
fi
sleep 0.5;
done
It does not have any dependencies apart from make
.
You can pass normal make
arguments (such as -C mydir
) to it as they are passed on to the make
command.
As requested in the question it is silent if there is nothing to build but does not swallow output when there is.
You can keep this script handy as e.g. ~/bin/watch-make
to use across multiple projects.