Assume that a1.c
and a2.c
include a.h
which itself, in turn, includes b.h
. So a1.c
and a2.c
are dependent on b.h
indirectly.
Now I'd like the makefile to compile both of the .c files if b.h
gets modified. One way is adding b.h
to the dependency list of each rule along with a.h
. But I feel this may make things somewhat complicated when the project grows bigger and more complex. Another way may be adding a rule for touch
ing a.h
whenever b.h
changes. (I haven't tried the latter)
What is the best way to deal with nested dependencies in a makefile?
What I mean by the "best way":
the makefile is as compact and simple as possible
each .c file gets compiled only when at least one of its related .h files change
doesn't depend on the capabilities or tools of a specific compiler or OS