我正在尝试为我的工具制作特定于 Ubuntu 版本的发行版,所以我想获取操作系统名称和版本。我有以下代码:
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
我使用 shell 单线:
lsb_release -a 2>/dev/null | grep Description | awk '{ print $2 "-" $3 }'
正确返回
Ubuntu-12.04.2
在 Makefile 之外,但在其中它什么也不返回。也就是说,OS_VERS 变量只是 -
.我怎样才能解决这个问题?
最佳答案
在 Makefile 中,$
很特别。使用$$
你想让shell在哪里找到一美元。
OS_VERS := $(shell lsb_release -a 2>/dev/null | grep Description | awk '{ print $$2 "-" $$3 }')
关于shell - 在 Makefile 中使用 shell 查找 Ubuntu 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30088319/