gpt4 book ai didi

makefile - 将 shell (CYGWIN) 命令的输出分配给 Make 变量

转载 作者:行者123 更新时间:2023-12-01 15:32:00 26 4
gpt4 key购买 nike

我想将 shell 命令的输出分配给 make 变量。这是我试过的:

phonegap:
#download new phonegap
cd ${SOURCE_PHONEGAP};git pull
PHONE_VER = $(shell cat d:/path/to/workspace/common/phonegap/VERSION)
echo phonegap version: ${PHONE_VER}

当从命令行运行 MAKE 时,我得到以下信息:

PHONE_VER = 1.3.0 make: PHONE_VER: Command not found so the shell string is translated to the right value (1.3.0) but something fails after that.

我也试过声明:

PHONE_VER = 

然后在命令中: ${PHONE_VER} = $(shell cat d:/path/to/workspace/common/phonegap/VERSION)或使用 := 或 +=。没用

我在 GNU make 3.81 中使用 cygwin(在 win 7 上)

我找到了 this question并回答 - 但这似乎对我不起作用。我显然遗漏了一些东西(可能是基本的),但经过一天的试验后,我不知道遗漏的部分是什么。

最佳答案

您不能在规则配方中分配变量。第一种可能的解决方案是在规则之外的某个地方初始化它,然后像常规一样使用它:

PHONE_VER = $(shell cat d:/path/to/workspace/common/phonegap/VERSION)

phonegap: pull_phonegap
@echo phonegap version: ${PHONE_VER}

pull_phonegap:
@cd ${SOURCE_PHONEGAP}; git pull

只要 PHONE_VER 被递归扩展(注意 = 登录赋值),并且实际调用 shell cat ... 将在满足 pull_phonegap 前提条件后出现。

另一种可能性是为 phonegap 创建 PHONE_VER 变量 target-specific:

phonegap: PHONE_VER = $(shell cat d:/path/to/workspace/common/phonegap/VERSION)
phonegap: pull_phonegap
@echo phonegap version: ${PHONE_VER}

最后,如果你唯一想做的就是打印下载的 repo 的版本,那么完全摆脱变量会更容易:

phonegap: pull_phonegap
@echo phonegap version:
@cat ${SOURCE_PHONEGAP}/VERSION

pull_phonegap:
@cd ${SOURCE_PHONEGAP}; git pull

关于makefile - 将 shell (CYGWIN) 命令的输出分配给 Make 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8624021/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com