如何在makefile中打印出变量 [英] How to print out a variable in makefile

查看:2847
本文介绍了如何在makefile中打印出变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的makefile文件中,我有一个变量"NDK_PROJECT_PATH",我的问题是在编译时如何将其打印出来?

In my makefile, I have a variable 'NDK_PROJECT_PATH', my question is how can I print it out when it compiles?

我阅读了使文件回显显示为"$ PATH";字符串,而我尝试过:

I read Make file echo displaying "$PATH" string and I tried:

@echo $(NDK_PROJECT_PATH)
@echo $(value NDK_PROJECT_PATH)

两个都给我

"build-local.mk:102: *** missing separator.  Stop."

有人知道为什么它对我不起作用吗?

Any one knows why it is not working for me?

推荐答案

使用此方法(带有名为"var"的变量)时,可以在读取makefile时打印出变量(假设已正确标记了此问题,则假定为GNU make). ):

You can print out variables as the makefile is read (assuming GNU make as you have tagged this question appropriately) using this method (with a variable named "var"):

$(info $$var is [${var}])

您可以将此构造添加到任何配方中,以查看make将传递给shell的内容:

You can add this construct to any recipe to see what make will pass to the shell:

.PHONY: all
all: ; $(info $$var is [${var}])echo Hello world

现在,这里发生的事情是make将整个配方($(info $$var is [${var}])echo Hello world)存储为单个递归扩展变量.当make决定运行配方时(例如,当您告诉它构建all时),它将扩展该变量,然后将每行结果分别传递给shell.

Now, what happens here is that make stores the entire recipe ($(info $$var is [${var}])echo Hello world) as a single recursively expanded variable. When make decides to run the recipe (for instance when you tell it to build all), it expands the variable, and then passes each resulting line separately to the shell.

所以,很痛苦的细节:

  • 它展开$(info $$var is [${var}])echo Hello world
  • 为此,首先扩展$(info $$var is [${var}])
    • $$变成文字$
    • ${var}变为:-)(说)
    • 副作用是$var is [:-)]出现在标准输出上
    • $(info...)的扩展名是空的
    • It expands $(info $$var is [${var}])echo Hello world
    • To do this it first expands $(info $$var is [${var}])
      • $$ becomes literal $
      • ${var} becomes :-) (say)
      • The side effect is that $var is [:-)] appears on standard out
      • The expansion of the $(info...) though is empty
      • 首先在stdout上打印echo Hello world,以使您知道要shell执行的操作
      • Make prints echo Hello world on stdout first to let you know what it's going to ask the shell to do

      这篇关于如何在makefile中打印出变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆