【问题标题】:Error while trying to get value from command in gnu make尝试从 gnu make 中的命令获取值时出错
【发布时间】:2018-10-15 11:33:51
【问题描述】:

我有以下代码在 make gnu 文件上运行

apps := $(shell tbd run apps)
apps := $(subst ],,$(subst [,,$(app)))

现在我想打印应用程序的值,我尝试了

@echo $(app)

我得到了错误

Makefile:12: *** commands commence before first target. Stop.

更新:

目前我的代码是这样的

apps := $(shell tbd run apps)
apps := $(subst ],,$(subst [,,$(apps)))


build:
    @for app in $(apps) ; do \
     bsd start $$app ; \
    done

如果我这样尝试,我会出错

start: 
   apps := $(shell tbd run apps)
   apps := $(subst ],,$(subst [,,$(apps)))

build:
    @for app in $(apps) ; do \
        bsd start $$app ; \
    done

【问题讨论】:

  • @tripleee - 不一样,我尝试使用$app (如在帖子回答中)没有成功同样的错误,知道吗?
  • 不是公认的答案;另一个。
  • @tripleee - 现在也试试,我没有得到错误但我仍然没有看到价值
  • @tripleee - 完成我已经更新,但问题是当我把它放在配方中时我得到了另一个错误,如果我想在其他配方中使用应用程序值,让我们这样说我应该怎么做做吗?

标签: linux shell makefile gnu-make gnu


【解决方案1】:

您不能有意义地将 Makefile 函数调用放在 shell 调用中。我猜你真的只是在寻找

build:
    tbd run apps \
    | sed 's/\[//;s/\]//' \
    | xargs -n 1 bsd start

【讨论】:

  • 谢谢 : ) 我需要的是获取应用程序列表并在它们上循环运行,这可行,但我想打印值
  • 对不起,我不明白这应该如何工作,你能提供完整的代码吗?这会替换我更新中的所有代码吗?
  • 1+ 为您提供帮助:)
  • 这是一个完整的 Makefile 来替换你问题中的代码,是的。
  • 抱歉,bsd start 是什么?可以简化吗?
【解决方案2】:

如果您只想打印一些东西而不考虑任何规则,请使用info 函数...

$(info $(app))

【讨论】:

  • 顺便说一句,我没有看到错误,但我也没有看到值,您认为仍然可能缺少什么?
  • 这表明$(shell tbd run apps) 的输出是一个空字符串。
  • 不,不是 :) 我应该像这样检查它吗@echo $(info $(app))
  • 你怎么知道它不是空的?尝试将$(info app='$(app)') 放在makefile 中app := $(shell tbd run apps) 之后的一行。你看到任何输出了吗?
  • 不,您不能在 Makefile 中间运行 shell 命令,它必须是配方的一部分;这就是错误消息的含义,这就是指定的副本告诉您的内容。
猜你喜欢
  • 2018-11-05
  • 1970-01-01
  • 1970-01-01
  • 2016-05-26
  • 1970-01-01
  • 2013-04-25
  • 1970-01-01
  • 2017-09-14
相关资源
最近更新 更多