Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to have make automatically run when you edit one of the files needed for the build?

Related question: Configure makefile to run on file change, but that only has an answer for Mac OS X - I'd like a more general solution if possible (though I'm actually aiming for linux).

share|improve this question

There isn't a general solution – each OS has its own file monitoring API. On Mac OS X it is FSEvents, on Linux – inotify or fanotify, on BSDs – kqueue.

On Linux, you could use incron or write a script using inotifywait:

#!/usr/bin/env bash
inotifywait -r -m -q -e close_write ~/project \
| while read path event file; do
    if case $file in
        autogenerated.h)   false;;   # ignore a specific file to avoid loops
        *.c|*.h|Makefile)  true;;    # watch all .c, .h files, the Makefile
        *)                 false;;   # ignore all other files to avoid loops
    esac; then                       # (specifically, you MUST ignore auto-
        (cd ~/project && make)       # -generated files)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.