Make知识点总结, 有时间再补充些自己比较困惑的点
为什么使用make
1、包含多个源文件的项目在编译时有长而复杂的命令行,可以通过makefile保存这些命令行来简化该工作 2、make可以减少重新编译所需要的时间,因为make可以识别出哪些文件是新修改的 3、Make维护了当前项目中各文件的相关关系,从而可以在编译前检查是否可以找到所有的文件
自己也用了很久的make, 以上回答的这3点我也都知道, 可是从来没有系统的写下来总结过, 感谢Make面试题
Special Built-in Target Names
Certain names have special meanings if they appear as targets.Special-Targets
.PHONY
The prerequisites of the special target .PHONY
are considered to be phony targets. When it is time to consider such a target, make
will run its recipe unconditionally, regardless of whether a file with that name exists or what its last-modification time is. See Phony Targets.
.PHONY: clean
clean:
rm *.o temp
Once this is done, ‘make clean’ will run the recipe regardless of whether there is a file named clean.
.SUFFIXES
后缀自定义规则, 定义某一类型的文件的处理规则
compiler flag
Use the
LIBADD
primary for libraries, andLDADD
for executables. If you were building a libtool librarylibfoo.la
, that depended on another librarylibbar.la
, you would use:libfoo_la_LIBADD = libbar.la
If you had other non-libtool libraries, you would also add these with
-L
and-l
options:libfoo_la_LIBADD = libbar.la -L/opt/local/lib -lpng
Typically, you would use the configure script to find these extra libraries, and use
AC_SUBST
to pass them with:libfoo_la_LIBADD = libbar.la $(EXTRA_FOO_LIBS)
For a program, just use
LDADD
:myprog_LDADD = libfoo.la # links libfoo, libbar, and libpng to myprog.
Sometimes the boundaries are a bit vague.
$(EXTRA_FOO_LIBS)
could have been added tomyprog_LDADD
. Adding dependencies to a libtool (.la
) library, and usinglibtool
do all the platform-specific linker magic, is usually the best approach. It keeps all the linker metadata in the one place.