Makefile 宏 - Makefile
make程序允许您使用宏,这是类似的变量。 = 一对一个Makefile中定义的宏。例如:
MACROS= -me
PSROFF= groff -Tps
DITROFF= groff -Tdvi
CFLAGS= -O -systype bsd43
LIBS = "-lncurses -lm -lsdl"
MYFACE = ":*)"
- 特殊的宏
目标规则集发出任何命令之前,有一些特殊的预定义宏。
$@ 到的文件的名称。
$? 是改变的眷属的名字。
因此,举例来说,我们可以使用一个规则
hello: main.cpp hello.cpp factorial.cpp
$(CC) $(CFLAGS) $? $(LDFLAGS) -o $@
alternatively:
hello: main.cpp hello.cpp factorial.cpp
$(CC) $(CFLAGS) [email protected] $(LDFLAGS) -o $@
在这个例子中$@代表 hello, $? 或[email protected]将拾取所有更改的源文件。
有两个比较特殊的隐含规则中使用的宏。它们是
$< 导致该操作的相应的文件中的名称。
$* 前缀共享目标和相关文件。
常见的隐含规则的构造 .o(对象)文件,.cpp(源文件)。
.o.cpp:
$(CC) $(CFLAGS) -c $<
alternatively
.o.cpp:
$(CC) $(CFLAGS) -c $*.c
注意:要获得更详细的关于Makefile规则,在另一部分。
- 传统宏
有很多默认的宏(输入“make -p”打印出来的默认值)。大多数使用它们的规则是很明显的:
这些预定义变量,即。在隐含规则中使用的宏分为两大类:那些程序名(例如CC)和那些含有参数的程序(如CFLAGS)。
下面是一些比较常见的变量用作内置规则:makefile文件的程序名称的表。
AR | Archive-maintaining program; default `ar'. |
---|---|
AS | Program for compiling assembly files; default `as'. |
CC | Program for compiling C programs; default `cc'. |
CO | Program for checking out files from RCS; default `co'. |
CXX | Program for compiling C++ programs; default `g++'. |
CPP | Program for running the C preprocessor, with results to standard output; default `$(CC) -E'. |
FC | Program for compiling or preprocessing Fortran and Ratfor programs; default `f77'. |
GET | Program for extracting a file from SCCS; default `get'. |
LEX | Program to use to turn Lex grammars into source code; default `lex'. |
YACC | Program to use to turn Yacc grammars into source code; default `yacc'. |
LINT | Program to use to run lint on source code; default `lint'. |
M2C | Program to use to compile Modula-2 source code; default `m2c'. |
PC | Program for compiling Pascal programs; default `pc'. |
MAKEINFO | Program to convert a Texinfo source file into an Info file; default `makeinfo'. |
TEX | Program to make TeX dvi files from TeX source; default `tex'. |
TEXI2DVI | Program to make TeX dvi files from Texinfo source; default `texi2dvi'. |
WEAVE | Program to translate Web into TeX; default `weave'. |
CWEAVE | Program to translate C Web into TeX; default `cweave'. |
TANGLE | Program to translate Web into Pascal; default `tangle'. |
CTANGLE | Program to translate C Web into C; default `ctangle'. |
RM | Command to remove a file; default `rm -f'. |
这里是一个变量,其值是上述程序的额外的参数表。所有这些的默认值是空字符串,除非另有说明。
ARFLAGS | Flags to give the archive-maintaining program; default `rv'. |
---|---|
ASFLAGS | Extra flags to give to the assembler (when explicitly invoked on a .s' or .S' file). |
CFLAGS | Extra flags to give to the C compiler. |
CXXFLAGS | Extra flags to give to the C compiler. |
COFLAGS | Extra flags to give to the RCS co program. |
CPPFLAGS | Extra flags to give to the C preprocessor and programs that use it (the C and Fortran compilers). |
FFLAGS | Extra flags to give to the Fortran compiler. |
GFLAGS | Extra flags to give to the SCCS get program. |
LDFLAGS | Extra flags to give to compilers when they are supposed to invoke the linker, `ld'. |
LFLAGS | Extra flags to give to Lex. |
YFLAGS | Extra flags to give to Yacc. |
PFLAGS | Extra flags to give to the Pascal compiler. |
RFLAGS | Extra flags to give to the Fortran compiler for Ratfor programs. |
LINTFLAGS | Extra flags to give to lint. |
注:您可以取消-R'或
--no-builtin-variables“选项隐含规则使用的所有变量。
如,也可以在命令行中定义的宏
make CPP = /home/courses/cop4530/spring02