[英]How to replace the definition of global variable in the target of a makefile?
[英]Makefile target global variable
我想要這樣的東西:
PrintTarget:
@echo Building $(TARGET)
SetRelTarget: TARGET = Release
SetRelTarget:
@echo Target is set.
BuildRel: SetRelTarget PrintTarget
但是在SetRelTargetAs
設置的TARGET
變量不是全局變量。 我的問題是:
是否可以在規則內修改全局變量並在規則外使用修改后的值?
謝謝。
由於代碼中沒有變量,因此您只需執行以下操作:
TARGET = Release
PrintTarget:
@echo Building $(TARGET)
BuildRel: PrintTarget
演示:
$ make BuildRel
Building Release
$ make TARGET=foo BuildRel
Building foo
如果您的用例較為復雜,請提供更多詳細信息。
將TARGET設置為在BuildRel中發布,然后應將其應用於所有先決條件(盡管它不是全局的),
PrintTarget:
@echo Building $(TARGET)
#SetRelTarget: TARGET = Release
SetRelTarget:
@echo Target is set to $(TARGET).
BuildRel: TARGET = Release
BuildRel: SetRelTarget PrintTarget
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.