Reputation: 140
I would like to have something like that:
PrintTarget:
@echo Building $(TARGET)
SetRelTarget: TARGET = Release
SetRelTarget:
@echo Target is set.
BuildRel: SetRelTarget PrintTarget
But TARGET
variable set in SetRelTargetAs
is not a global.
My question is:
Is it possible to modify global variables inside the rule and use this modified value outside this rule?
Thank you.
Upvotes: 1
Views: 1680
Reputation: 471
Set TARGET to release in BuildRel, then it should apply to all its prerequisites (although it's not global),
PrintTarget:
@echo Building $(TARGET)
#SetRelTarget: TARGET = Release
SetRelTarget:
@echo Target is set to $(TARGET).
BuildRel: TARGET = Release
BuildRel: SetRelTarget PrintTarget
Upvotes: 1
Reputation: 58858
Since there is nothing variable in the code you can simply do this:
TARGET = Release
PrintTarget:
@echo Building $(TARGET)
BuildRel: PrintTarget
Demo:
$ make BuildRel
Building Release
$ make TARGET=foo BuildRel
Building foo
If your use case is more complex please include more details.
Upvotes: 0