开发者

Makefile syntax $(A,B,C)?

Consider the following code:

$ANIMAL = COW PIG CHICKEN VAMPIRE

all:
        @echo $(ANIMAL, F, >.txt)

I strove to find a section in GNU make manual that mentions the above syntax, but I couldn't find an开发者_如何学运维ything related to it. What does it print and how is the syntax structured for the functionality?

Added: When a line starts with "@--" what does it mean?

@-- $(GEN_ENV); ...


To answer your addition: In regular Makefiles (read: POSIX, GNU, ...)

  • a leading '@' supresses echoing of the command.
  • a leading '-' says to ignore a non-zero exit status
  • both can be combined, and repetitions are okay, so @---@@@-@---echo foo is the same as @-echo foo


This is called "macro modifiers". This is not a GNU make feature. Take a look at this chapter of OPUS make tutorial. The general syntax of these modifiers:

$(name,modifier[,modifier]...) 

name is macro expanded, then each modifier is applied in succession to the elements of the expanded value. 

Take a look then at the list of modifiers and it becomes clear that it forms a list of file names (truncates paths of each variable in ANIMAL) with .txt added. So, in your case it shoud output:

COW.txt PIG.txt CHICKEN.txt VAMPIRE.txt

PS

I looked through the reference mentioned above and don't think the first line ($ANIMAL = ) is correct since macro definition should start without $.


Based on your comments it seems you are actually using OpusMake, rather than GNU make. You can find more information about it on the Opus Software, Inc. website, and also in this handy reference guide. From those sources you can see that you have an example of a macro employing macro modifiers in its expansion.

Generally speaking $(FOO) is expanded to the unmodified value of the variable FOO, while $(FOO,mod1[,mod2[,...]]]) expands to the value of FOO, modified according to the modifiers you specify. Note that you can string together any number of modifiers, and they will be applied in left-to-right order.

There's a ton of possible modifiers, but your example specifically uses two:

  • The F modifier, which means "use just the final path component of each pathname in the variable value"
  • The >str modifier, which means "append the text str to each space-separated word in the value".

Here's a quick example:

FOO=abc/def ghi/jkl
BAR=$(FOO,F)
BAZ=$(FOO,>.txt)
BOO=$(FOO,F,>.txt)
  • BAR will have the value def jkl (ie, just the filename portion of each path).
  • BAZ will have the value abc/def.txt ghi/jkl.txt (ie, append .txt to each space-separated word in the value)
  • BOO will have the value def.txt jkl.txt (ie, first take just the filename portion of each path, then append .txt to each)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜