質問

In the context of makefiles I often see in documentation/forums the term expansion thrown around quite a bit though it is rarely defined. What exactly does it mean to expand a variable or parameter when talking about makefiles?

役に立ちましたか?

解決

To expand a string means to replace references to variables or function calls within the string, (e.g. $(NAME)), with the values of those things.

Consider:

FOO = a b c
BAR = $(FOO) d e
BAZ = $(BAR) f g

The value of BAZ is $(BAR) f g. If you try to use it:

$(info $(BAZ))

then Make expands the variable, which is to say it replaces $(BAZ) with the value of BAZ:

$(info $(BAR) f g)

then $(BAR) with the value of BAR:

$(info $(FOO) d e f g)

then $(FOO) with the value of FOO:

$(info a b c d e f g)

and with nothing left to expand it executes the info function and prints out "a b c d e f g".

Note that some things expand variables and others don't. For example, the assignment BAR = $(FOO) d e does not expand the $(FOO) on the right-hand side. The other kind of assignment, BAR := $(FOO) d e, does.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top