Linux Makefile 生成 *.d 依赖文件及 gcc -M -MF -MP 等相关选项说明
https://blog.csdn.net/QQ1452008/article/details/50855810
实例
objs = a.o b.o c.o
depfiles := $(patsubst %, .%.d, $(objs))
depfiles := $(wildcard $(depfiles))
CFLAGS = -Werror -Iinclude
test: $(objs)
gcc -o test $^
@echo depfiles = $(depfiles)
ifneq ($(depfiles),) #如果变量不等于空,则包含
include $(depfiles)
endif
%.o: %.c
gcc $(CFLAGS) -c -o $@ $< -MD -MF .$@.d
clean:
rm *.o test
distclean:
rm $(depfiles)
.PHONY: clean