如何提取make的版本号?
How to extract make's version number?
如何从 bash shell 中获取 make
的数字版本号?
我尝试过,其中包括:
MAKE_VERSION=$(make --version 2>&1 | awk '/Make/ {print }')
但我得到的是 "Make" 而不是它的版本。
这是我从 make --version
得到的输出:
GNU Make 4.1
Built for x86_64-unknown-cygwin
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
在这种情况下,我想获取字符串“4.1
”。
$ make --version | head -1 | cut -d" " -f3
3.81
您可以使用:
make_version=$(make --version 2>&1 | awk '/Make/ {print $NF}')
因为最后一个字段给了我们版本号。
对于make
版本的4.0+你也可以使用这个:
mver=$(make --eval '$(info $(MAKE_VERSION))' --eval 'all:;' -q)
对于 make
版本 3.81 和 3.82(假设 bash
),您可以使用:
mver=$(make -f <(echo '$(info $(MAKE_VERSION)) all:;') -q)
make
3.80(及更早版本)没有 $(info)
函数,因此您只能使用此处其他答案中的方法或使用 $(warning)
并且仍然需要解析它:
mver=$(make -f <(echo '$(warning $(MAKE_VERSION)) all:;') -q 2>&1 | awk '{print $NF}')
如何从 bash shell 中获取 make
的数字版本号?
我尝试过,其中包括:
MAKE_VERSION=$(make --version 2>&1 | awk '/Make/ {print }')
但我得到的是 "Make" 而不是它的版本。
这是我从 make --version
得到的输出:
GNU Make 4.1
Built for x86_64-unknown-cygwin
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
在这种情况下,我想获取字符串“4.1
”。
$ make --version | head -1 | cut -d" " -f3
3.81
您可以使用:
make_version=$(make --version 2>&1 | awk '/Make/ {print $NF}')
因为最后一个字段给了我们版本号。
对于make
版本的4.0+你也可以使用这个:
mver=$(make --eval '$(info $(MAKE_VERSION))' --eval 'all:;' -q)
对于 make
版本 3.81 和 3.82(假设 bash
),您可以使用:
mver=$(make -f <(echo '$(info $(MAKE_VERSION)) all:;') -q)
make
3.80(及更早版本)没有 $(info)
函数,因此您只能使用此处其他答案中的方法或使用 $(warning)
并且仍然需要解析它:
mver=$(make -f <(echo '$(warning $(MAKE_VERSION)) all:;') -q 2>&1 | awk '{print $NF}')