putpop
putpop

Reputation: 23

Makefile rebuilds projects on source update

Is there a way to have a 'watch' target in my Makefile which would keep looping and rebuilding the project every time the source file gets changed?

Upvotes: 2

Views: 38

Answers (1)

Anton Krug
Anton Krug

Reputation: 1781

I have this for my Latex project:

.PHONY : monitor 
monitor:
    while true; do \
        inotifywait  -e modify -q *.tex *.cls; make all; \
    done

Interesting arguments:

-q for quiet

-r for recursive (if you want to watch the whole src folder)

-e to list specific events (if your editor does more file operations and retriggers the build way too often)

--exclude to exclude some (if your src folder contains build artifacts) to make sure the build itself will not retrigger this loop (which would be equivalent of an infinite loop without any delays)

More arguments here (inotify tools are amazing):

https://linux.die.net/man/1/inotifywait

Depending on your distribution you might have to install separate package, on my Debian I had to do

sudo apt-get install inotify-tools

Upvotes: 1

Related Questions