首页 > 解决方案 > 如何从 shell 命令的输出中分配 Makefile 变量

问题描述

我正在尝试从文件中提取字符串并将其分配给变量。我有一个名为 tool_vaersions.env 的文件,它包含以下内容:

armcc install_dir /tools/compiler/armcc
gcc   intall_dir /tools/compiler/gcc

Makefile 有以下内容:

TOOL1 := gcc
TOOL2 := armcc

TOOL_VER1 := $(shell "grep -i $(TOOL1)  tool_versions.env" )

TOOL_INFO:
    $(eval TOOL_VER2=$(shell "grep -i $(TOOL2)  tool_versions.env" ))
    @(echo TOOL_VER1 is $(TOOL_VER1))
    @(echo TOOL_VER2 is $(TOOL_VER2))

我不确定我在这里做错了什么,但 TOOL_VER1 和 TOOL_VER2 的回声没有返回任何内容。我希望这两个变量都只有路径 /tools/compiler/gcc 和 /tools/compiler/armcc 但在我引入条带和字符串操作之前我似乎无法完成这项工作。

谢谢你帮助我。

标签: variablesmakefiletargetassignrecipe

解决方案


推荐阅读