📅  最后修改于: 2020-11-01 04:36:38             🧑  作者: Mango
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) $@.cpp $(LDFLAGS) -o $@
在此示例中,$ @代表您好,$?代表或$ @。cpp拾取所有已更改的源文件。
隐式规则中使用了两个以上的特殊宏。他们是-
$ <引起操作的相关文件的名称。
$ *目标文件和从属文件共享的前缀。
常见的隐式规则是从.cpp(源文件)中构造.o(目标)文件。
.cpp.o:
$(CC) $(CFLAGS) -c $<
Alternatively:
.cpp.o:
$(CC) $(CFLAGS) -c $*.c
有各种默认宏。您可以通过键入“ make -p”以显示默认值来查看它们。从使用规则中,大多数都是显而易见的。
这些预定义变量(即,隐式规则中使用的宏)分为两类。它们如下-
作为程序名称的宏(例如CC)
包含程序参数的宏(例如CFLAGS)。
以下是一些常用变量的表,这些变量在makefile的内置规则中用作程序的名称-
Sr.No | Variables & Description |
---|---|
1 |
AR Archive-maintaining program; default is `ar’. |
2 |
AS Program to compiling assembly files; default is `as’. |
3 |
CC Program to compiling C programs; default is `cc’. |
4 |
CO Program to checking out files from RCS; default is `co’. |
5 |
CXX Program to compiling C++ programs; default is `g++’. |
6 |
CPP Program to running the C preprocessor, with results to standard output; default is `$(CC) -E’. |
7 |
FC Program to compiling or preprocessing Fortran and Ratfor programs; default is `f77′. |
8 |
GET Program to extract a file from SCCS; default is `get’. |
9 |
LEX Program to use to turn Lex grammars into source code; default is `lex’. |
10 |
YACC Program to use to turn Yacc grammars into source code; default is `yacc’. |
11 |
LINT Program to use to run lint on source code; default is `lint’. |
12 |
M2C Program to use to compile Modula-2 source code; default is `m2c’. |
13 |
PC Program for compile Pascal programs; default is `pc’. |
14 |
MAKEINFO Program to convert a Texinfo source file into an Info file; default is `makeinfo’. |
15 |
TEX Program to make TeX dvi files from TeX source; default is `tex’. |
16 |
TEXI2DVI Program to make TeX dvi files from Texinfo source; default is `texi2dvi’. |
17 |
WEAVE Program to translate Web into TeX; default is `weave’. |
18 |
CWEAVE Program to translate C Web into TeX; default is `cweave’. |
19 |
TANGLE Program to translate Web into Pascal; default is `tangle’. |
20 |
CTANGLE Program to translate C Web into C; default is `ctangle’. |
21 |
RM Command to remove a file; default is `rm -f’. |
这是一个变量表,其值是上述程序的附加参数。除非另有说明,否则所有这些的默认值为空字符串。
Sr.No. | Variables & Description |
---|---|
1 |
ARFLAGS Flags to give the archive-maintaining program; default is `rv’. |
2 |
ASFLAGS Extra flags to give to the assembler when explicitly invoked on a `.s’ or `.S’ file. |
3 |
CFLAGS Extra flags to give to the C compiler. |
4 |
CXXFLAGS Extra flags to give to the C compiler. |
5 |
COFLAGS Extra flags to give to the RCS co program. |
6 |
CPPFLAGS Extra flags to give to the C preprocessor and programs, which use it (such as C and Fortran compilers). |
7 |
FFLAGS Extra flags to give to the Fortran compiler. |
8 |
GFLAGS Extra flags to give to the SCCS get program. |
9 |
LDFLAGS Extra flags to give to compilers when they are supposed to invoke the linker, `ld’. |
10 |
LFLAGS Extra flags to give to Lex. |
11 |
YFLAGS Extra flags to give to Yacc. |
12 |
PFLAGS Extra flags to give to the Pascal compiler. |
13 |
RFLAGS Extra flags to give to the Fortran compiler for Ratfor programs. |
14 |
LINTFLAGS Extra flags to give to lint. |
注意–您可以使用’-R’或’–no-builtin-variables’选项取消隐式规则使用的所有变量。
您还可以在命令行中定义宏,如下所示:
make CPP = /home/courses/cop4530/spring02