Don Marti
2013-07-27 00:44:26 UTC
Shell function, "makewatch" to re-run make when
the relevant files change. Surprisingly useful
for refreshing the HTML version of a page when the
Markdown source changes, especially if you're into the
Auto Reload extension. I also plan to use this for
"make test".
Andrew Cowie has something similar...
http://blogs.operationaldynamics.com/andrew/software/haskell/rebuilding-via-inotify
...but I like mine better because it doesn't have to
special-case the irrelevant files--it actually looks
for what "make" needs.
I think I can get rid of the "cut" in the helper
function if I learn more about grep.
make_prereqs() {
# finds all prerequisites mentioned in a Makefile
# that are actual files.
for f in `egrep '^\S.*:\S*' Makefile | \
cut -d ':' -f 2 | tr -s ' ' '\n' | \
sort -u`; do
[ -e $f ] && echo -n "$f ";
done
echo
}
makewatch() {
# re-run make, with the supplied arguments, when a
# Makefile prerequisite changes. Example:
# makewatch test
# Fun to use with Auto Reload and Pandoc
# https://addons.mozilla.org/en-US/firefox/addon/auto-reload/?src=api
# http://johnmacfarlane.net/pandoc/
if [ ! -e Makefile ]; then
echo "No Makefile in this directory." >&2
return
fi
make $*
while true; do
inotifywait -e close_write -e moved_to `make_prereqs`
make $*
done
}
* actual fun achived depends on Makefile content.
the relevant files change. Surprisingly useful
for refreshing the HTML version of a page when the
Markdown source changes, especially if you're into the
Auto Reload extension. I also plan to use this for
"make test".
Andrew Cowie has something similar...
http://blogs.operationaldynamics.com/andrew/software/haskell/rebuilding-via-inotify
...but I like mine better because it doesn't have to
special-case the irrelevant files--it actually looks
for what "make" needs.
I think I can get rid of the "cut" in the helper
function if I learn more about grep.
make_prereqs() {
# finds all prerequisites mentioned in a Makefile
# that are actual files.
for f in `egrep '^\S.*:\S*' Makefile | \
cut -d ':' -f 2 | tr -s ' ' '\n' | \
sort -u`; do
[ -e $f ] && echo -n "$f ";
done
echo
}
makewatch() {
# re-run make, with the supplied arguments, when a
# Makefile prerequisite changes. Example:
# makewatch test
# Fun to use with Auto Reload and Pandoc
# https://addons.mozilla.org/en-US/firefox/addon/auto-reload/?src=api
# http://johnmacfarlane.net/pandoc/
if [ ! -e Makefile ]; then
echo "No Makefile in this directory." >&2
return
fi
make $*
while true; do
inotifywait -e close_write -e moved_to `make_prereqs`
make $*
done
}
* actual fun achived depends on Makefile content.
--
Don Marti +1-510-332-1587 (mobile)
http://zgp.org/~dmarti/ Alameda, California, USA
***@zgp.org
Don Marti +1-510-332-1587 (mobile)
http://zgp.org/~dmarti/ Alameda, California, USA
***@zgp.org