我正在尝试制作工具的ubuntu版本特定的发行版,因此我想获取OS名称和版本。我有以下代码:
ifeq ($(OS),Windows_NT)
OS_POD+=win
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
OS_VERS := $(shell lsb_release -a 2>/dev/null | grep Description | awk '{ print $2 "-" $3 }')
OS_POD=./dist/linux/$(OS_VERS)
endif
ifeq ($(UNAME_S),Darwin)
OS_POD=./dist/mac
endif
endif
我使用外壳一线:
lsb_release -a 2>/dev/null | grep Description | awk '{ print $2 "-" $3 }'
正确返回makefile之外的 Ubuntu-12.04.2
,但内部没有返回。也就是说,OS_vers变量仅为-
。
我该如何修复?
在makefile中, $
很特别。使用$$
希望壳找到美元的地方。
OS_VERS := $(shell lsb_release -a 2>/dev/null | grep Description | awk '{ print $$2 "-" $$3 }')
您需要在命令中逃脱$
。
OS_VERS:=$(shell lsb_release -a 2>/dev/null | grep Description | awk '{ print $$2 "-" $$3 }')
正确的示例makefile打印可以是您的makefile的另一部分。
print:
@echo $(OS_VERS)
OS_VERS:=$(shell lsb_release -a 2>/dev/null | grep Description | awk '{ print $$2 "-" $$3 }')
OS_VERS := $(shell cat /etc/os-release | grep ^NAME | cut -d'=' -f2 | sed 's/"//gI')