4 ms·
> Providing a separate %.d rule would fix this issue Yes. The following is an example of how to handle C header dependencies. It could be adapted to build cs
by cgrubb 12y ago
> Providing a separate %.d rule would fix this issue
Yes. The following is an example of how to handle C header dependencies. It could be adapted to build css from less and would be an improvement on the blog post technique.
sources := $(wildcard *.c)
-include $(subst .c,.d,$(sources))
%.d: %.c
$(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\ 1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
It uses the fact that if you include a file which doesn't exist but for which there is a rule to build it, GNU make will build it for you.
- DSMan195276 12y agoYep. Though with newer versions of gcc (I don't know how new though) you can avoid the nasty sed stuff. I'm currently using this to generate my .d files for C files: $(objtree)/%.d: $(srctree)/%.c @$(CC) -MM -MP -MF $@ $(CPPFLAGS) $< -MT $(objtree)/$*.o -MT $@ That generates a dependency file in the form: $(objtree)/%.o $(objtree)/%.d: (dependency list) (dependency-list-entry-1): (dependency-list-entry-2): etc... It's pretty handy. Avoiding all the sed stuff is nice.