[linux-elitists] Fun* with inotify and make

Teh Entar-Nick nick at teh.entar.net
Sat Jul 27 03:47:48 PDT 2013

Don Marti:
> 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.

Neat, but nearly all of my Makefiles use patterns like this:

    MARKDOWNS=$(wildcard *.md)
    all: $(patsubst %.md,%.html,$(MARKDOWNS))
    %.html: %.md
            pandoc -t html5 --ascii --section-divs --standalone --smart -o
            $@ $<
    %.pdf: %.md
            pandoc --chapters --variable=papersize:'a5paper' -o $@ $<

It doesn't seem that this kind of automatic pattern-driven makefile is
supported by your script.

> I also plan to use this for "make test".

I did this in Python for yardbird a few years ago:


Note that it uses pyinotify (for inotify) as well as pynotify (for
dbus-driven desktop notification popups).  

> 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
> }


    gawk -F ':\\s*' '$1 ~ /^\S+$/ && $2 ~ /\S/ {gsub(/\s+/, "\n"); print $2}' Makefile | sort -u | xargs ls 2>/dev/null | xargs echo

It even supports whitespace after the : now.  It switched to xargs just
because that's how I roll.

Content-type: lies/all-lies
Content-disposition: blatant

More information about the linux-elitists mailing list