鍍金池/ 教程/ Java/ Makefile 宏
Makefile 定義依賴性
Makefile 定義規(guī)則
Makefile 文件重新編譯
Makefile 自定義后綴規(guī)則
為什么需要Makefile?
Makefile 指令
Makefile
Makefile 宏
Makefile 其他功能
Makefile include
makefile 例子

Makefile 宏

make程序允許您使用宏,這是類似的變量。 = 一對一個Makefile中定義的宏。例如:

MACROS=  -me
PSROFF=  groff -Tps
DITROFF= groff -Tdvi
CFLAGS= -O -systype bsd43
LIBS = "-lncurses -lm -lsdl"
MYFACE = ":*)"
  • 特殊的宏

目標(biāo)規(guī)則集發(fā)出任何命令之前,有一些特殊的預(yù)定義宏。

  • $@ 到的文件的名稱。

  • $? 是改變的眷屬的名字。

因此,舉例來說,我們可以使用一個規(guī)則

hello: main.cpp hello.cpp factorial.cpp
	$(CC) $(CFLAGS) $? $(LDFLAGS) -o $@

alternatively:

hello: main.cpp hello.cpp factorial.cpp
        $(CC) $(CFLAGS) $@.cpp $(LDFLAGS) -o $@

在這個例子中$@代表 hello, $? 或$@.cpp將拾取所有更改的源文件。

有兩個比較特殊的隱含規(guī)則中使用的宏。它們是

  • $< 導(dǎo)致該操作的相應(yīng)的文件中的名稱。

  • $* 前綴共享目標(biāo)和相關(guān)文件。

常見的隱含規(guī)則的構(gòu)造 .o(對象)文件,.cpp(源文件)。

.o.cpp:
        $(CC) $(CFLAGS) -c $<

alternatively

.o.cpp:
        $(CC) $(CFLAGS) -c $*.c

注意:要獲得更詳細(xì)的關(guān)于Makefile規(guī)則,在另一部分。

  • 傳統(tǒng)宏

有很多默認(rèn)的宏(輸入“make -p”打印出來的默認(rèn)值)。大多數(shù)使用它們的規(guī)則是很明顯的:

這些預(yù)定義變量,即。在隱含規(guī)則中使用的宏分為兩大類:那些程序名(例如CC)和那些含有參數(shù)的程序(如CFLAGS)。

下面是一些比較常見的變量用作內(nèi)置規(guī)則: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'.

這里是一個變量,其值是上述程序的額外的參數(shù)表。所有這些的默認(rèn)值是空字符串,除非另有說明。

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“選項(xiàng)隱含規(guī)則使用的所有變量。

如,也可以在命令行中定義的宏

          make CPP = /home/courses/cop4530/spring02