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