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 any utility to monitor file changes and invoke GNU make?

Or, more generally, periodically invoke a command when some file changed? or Makefile contains the checking interval?

share|improve this question
This would probably be better on Stack Overflow – user1596 Jul 9 '10 at 14:36
Note that there is no need to check explicitly for changes because make does that – dmckee Jul 9 '10 at 15:59
up vote 1 down vote accepted

periodically invoke a command when some file changed

You can do that with incron. To prevent loops, build outside the source tree, check that the modified file is under source control, or use the IN_NO_LOOP option.

share|improve this answer

What platform? You can invoke the following line in Bourne shell or bash to run make every 60 seconds, for example. If your Makefile is designed correctly, it will exit without changing anything if no files have changed:

while true ; do make ; sleep 60; done

If you are trying to compile code as it is checked in, take a look at "Continuous Integration" by Paul Duvall, Addison Wesley. It outlines tools and techniques for this.

share|improve this answer
Thank you, I do have a Hudson CI for Java projects, but that's not what I want. Well sleep loop is just fine, and I have written some bash scripts similar to what you provided to check file for modification periodically, but its function is limited and doesn't scale very well. So I guess there maybe someone had do the stuff in depth, or should I publish my working result as a .deb? – Xiè Jìléi Jul 10 '10 at 0:38

Yes, there are ways you could do this, but you didn't specify your platform.

If make and source is involved, then a Version Control System should be involved and modern VCS have "commit hooks" which can trigger a build based on certain VCS activities.

Randomly attempting a build based merely on "the source has changed" is a very easy way to produce builds that don't work.

added based on comment:

I'm guessing that you are coming from an IDE environment and brought some bad habits with you. You should spend much time thinking, a little time coding, and compile rarely. To do otherwise generates sloppy code which will be unhappy for you and the next guy so don't do it.

Also, there is nothing stopping you from using Git or Mercurial for your own local changes and pushing up to Subversion when you have something worthy for the central repository while being protected from your own bad changes.

However, I strongly recommend that you don't use your compiler as an error checker. You will be a worse programmer if you do.

share|improve this answer
I'm using Ubuntu 9 and Bash shell. Well, what am I want is the feature of type-and-see or check the syntax error & quick preview. The source I mainly working on is small piece of code and the project won't have too many files. The commit hooks doesn't work because SVN server is at remote and I need to check the result at my own computer. And it's just change the problem from auto make' into auto commit'. – Xiè Jìléi Jul 10 '10 at 0:31
Thanks for your advice, msw. I do agree with you that think much code little. But there are many kinds of things living on the earth, most projects should be programmed in think-more' mode, but there's also some projects that should be programmed in try-more-build-cycle' mode. And, for example, even think-more' projects have several stage, at the starting stage, it might be in think-more' stage, and then it becomes a debug-more' stage, or sth else. So, while think-more' is always good, strengthen my brain and expand my life, but for some tasks, WYSIWIG is more convenient. Isn't it? – Xiè Jìléi Jul 10 '10 at 8:43

You could set up some sort of cron task to do this at a specified interval.

Or, write a shell script that uses a polling loop to check if files were modified. Then either sleep or run make. You would run this as a daemon or in the background of your session.

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.