%.d: %.c
@set -e; rm -f $@; \
$(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
Not for the faint of heart, also the thing done by sed is quite trivial. If all you have to support is gcc (portability is overrated!), there's a much more simple way to achieve the same (and more):
%.o: %.c
$(CC) -MMD -MP -MT '$*.d' -c $(CFLAGS) $< -o $@
No comments:
Post a Comment