- Environment, Automatic, and Predefined Variables
Automatic Variables
***************************************
$@ The filename of a rule's target
$< The name of the first dependency in a rule
$^ Space-delimited list of all the dependencies in a rule
$? Space-delimited list of all the dependencies in a rule that are newer than the target
$(@D) The directory part of a target filename, if the target is in a subdirectory
$(@F) The filename part of a target filename, if the target is in a subdirectory
****************************************
Predefined Varialbes For Program Names and Flags
************************************************
AR Archive-maintenance programs; default value = ar
AS Program to do assembly; default value = as
CC Program for compliling C programs; default value = cc
CPP C Preprocessor program; default value = cpp
RM Program to remove files; default value = "rm -f"
ARFLAGS Flags for the archive-maintenance program; default = rv
ASFLAGS Flags for the assembler program; no default
CFLAGS Flags for the C compiler; no default
LDFLAGS Flags for the linker(ld); no default
****************************************************
If you want, you can redefine these variables in the makefile. In most cases, their default values are reasonable.
- Implicit Rules
Feature : special purpose and limited usage
如果makefile中没有相应的.o文件的生成命令,make 会自动寻找.c然后生成相应的.o文件
- Pattern Rules
除了make自己定义的一些隐含规则外,用户也可以自己定义规则,成为pattern rules. The target contains exactly one character(%)that matches any nonempty string. The dependencies of such a rule also use % in order to mach the target.
eg.
****************************************
%.o : %.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
****************************************
It defines a rule that makes any file x.o from x.c.
- Comments
#This file is used to ...
- Additional make Command-line option
********************************************************
-f file Specify an alternatively-named makefile file
-Idirname Specify dirname as a directory in which make search for included makefiles.
-k If one target fails to build, continue to build other targets. Normally, make terminates if a target fails to build successfully.
********************************************************
- Common make Error Messages
************************************************************
1 No rule to make target 'target'. Stop
2 'target' is up to date
3 Target 'target' not remade because of errors
4 command: Command not found
5 Illegal option -option
************************************************************
- Usefule Makefile Targets
***************************************************
install uninstall dist
test check
installtest installcheck
***************************************************
总结:这次笔记介绍了make的作用,规则, 变量的定义, 命令行参数等等。一些更详细的说明等用到的时候可以查询使用。