- 論壇徽章:
- 0
|
(歡迎轉載,轉載請注明出處--chley)
Solaris上的make與其它Unix或GNU make都有所不同,特別是在定義和使用Macro時。
make(1S)
target: something to create or update
dependency: something that a target depends on.
rule: a list of commands, can be explicit or implicit(supplied by make)
調用make命令,無參數(shù)時,make會檢查makefile中每個target的dependency,如果某個target
file不存在或者比dependency舊,則rebuild it。
如果一個target在makefile中沒有entry,或者它的entry沒有rule,make會試圖使用下述方法尋找一個合適的rule:
1)模式匹配規(guī)則
2)implicit
rule:可以是用戶提供的makefile定義的,也可以是標準的潛規(guī)則(/usr/share/lib/make/make.rules)。
3)SCCS retrieval
4) rule from .DEFAULT entry.
target format:
target [:|::] [dependency] ... [;command] ...
[command]
...
注:1)target可以是一個name,也可以是一列空格分開的name
2)dependency可以是一個,也可以是多個
3)dependency可以用;結束,后跟一個Bourn shell command.
4)在rule中的command都必須以tab開始,并且必須是Bourn shell command. 可以用 \
轉義跨越多行,但是每一行的開始都必須是TAB
%:模式匹配通配符,與shell中的*類似。
Macro:
基本格式
macro=value
= 定義一個macro
$() ${} 引用一個macro
+= appends a string to a macro definition(兩邊必須有空格)
:= 條件賦值
:sh = Define the value of a macro to be the output of a command
macro中的替代:
$(name:string1=string2) $name中的string1會被string2代替。
$(name:op%os=np%ns) $name中的所有匹配op%os的字符串會被np%ns代替,例如
PROGRAM=fabricate
DEBUG= $(PROGRAM:%=tmp/%-g) --
$(PROGRAM)中的所有字符串會被tmp/fabricate-g代替,從而DEBUG得到的就是tmp/fabricate-g
Dynamic Macros:
$* basename of the current target
$< name of a dependency file
$@ name of the current target
$? The list of dependencies that are newer than the target.
$% name of the library member being processed
Conditional Macro Definitions:
target-list := macro = value
表示在處理target
list中的target及其dependency時,macro使用這里給出的value,而不是其它地方可能已經(jīng)定義的value。
target-list := macro += value
使用這種格式時,表示在處理target-list中的target時,暫時把valueappend到macro中。
Rules:
+ make總會執(zhí)行這條命令,即使在命令行使用了 -n
@ 在執(zhí)行之前,不打印這條命令
Pattern Matching Rule:
tp%ts:dp%ds
rule
tp is a target prefix,ts is a target suffix. dp is a dependency
prefix, and ds is a dependency suffix(any of which can be null).
Suffix Rules:
DsTs: rule
Ts is the suffix of the target, Ds is the suffix of the dependency
file.
To refer to a shell variable, use a double-dollar-sign ($$).
命令替換:
MACRO:sh =command -- MACRO的value是command的輸出,如 POUND_SIGN:sh= echo \\043
$(MACRO:sh) -- 在sh中執(zhí)行MACRO,并捕獲輸出,如:REAL_CC= $(CW_CC_CMD:sh)
本文來自ChinaUnix博客,如果查看原文請點:http://blog.chinaunix.net/u/24393/showart_223506.html |
|