 <p>You didn't specify what compiler(s) you are using, but if you have access to gcc/g++ you can use the -MM option. </p> <p>What I do is create a file with the extension of .d for every .c or .cpp file, and then "include" the .d files. I use something like this in my Makefile:</p> <pre><code>%.d: %.c gcc $(INCS) $(CFLAGS) -MM $&lt; -MF $@ %.d: %.cpp g++ $(INCS) $(CXXFLAGS) -MM $&lt; -MF $@ </code></pre> <p>I then create the dependencies like this:</p> <pre><code>C_DEPS=$(C_SRCS:.c=.d) CPP_DEPS=$(CPP_SRCS:.cpp=.d) DEPS=$(C_DEPS) $(CPP_DEPS) </code></pre> <p>and this at the bottom of the Makefile:</p> <pre><code>include $(DEPS) </code></pre> <p>Is this the kind of behavior you're going for? The beauty of this method is that even if you're using a non-GNU compiler for actual compiling, the GNU compilers do a good job of calculating the dependencies.</p>