本文共 607 字,大约阅读时间需要 2 分钟。
在写makefile时,有一种简单通用的方法指定目标文件对头文件的依赖关系。其使用基础是编译器能分析源文件中头文件的包含关系。
比如:gcc -M
选项可以自动产生依赖关系。
$ echo "#incldue" > stdio.c$ gcc -M stdio.cstdio.o: stdio.c /usr/include/stdio.h /usr/include/_ansi.h \...
下面的makefile:
VPATH = src includeCPPFLAGS - -I includeSOURCES = count_words.c lexer.c counter.ccount_words: counter.c lexer.c -lflcount_words.c:counter.hcounter.c : counter.h lexer.hlexer.o : lexer.hinclude $(subst .c,.d,$(SOURCES))%.d: %.c $(CC) -M $(CPPFLAGS) $< > $@.$$$$; \ sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ rm -f $@.$$$$
make
会把include
指令所指定的文件视为需要跟新的工作目标。
转载地址:http://zeqbb.baihongyu.com/