[英]Makefile: Emit warning gcc version is lower than 4.8.0
Makefile
parameters to gcc
gcc
的Makefile
参数A certain Makefile` in an Open-Source project contains the following call: 开源项目中的某个Makefile`包含以下调用:
CFLAGS = -I$(RM_INCLUDE_DIR) -Wall -g -fPIC -lc -lm -Og -std=gnu99
The -Og
parameter was introduced to gcc 4.8 . -Og
参数被引入到gcc 4.8 中。 My OSX contained gcc 4.2.1, and it failed with a rather confusing error message.我的 OSX 包含 gcc 4.2.1,它失败了,错误消息相当混乱。
Is there an elegant and standard (ie, works on any POSIX environment) way to check the version of gcc and emit a warning if it's lower than 4.8?是否有一种优雅和标准(即,适用于任何 POSIX 环境)的方法来检查 gcc 的版本并在低于 4.8 时发出警告?
The problem is that gcc --version
has different output formats:问题是
gcc --version
有不同的输出格式:
$ gcc --version
gcc (Homebrew gcc 5.3.0) 5.3.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.4.0
Thread model: posix
$ gcc --version
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Is there an elegant, Makefile-compatible and standard way to check the version of gcc, and emit a warning if the version is lower than 4.8.x?是否有一种优雅的、兼容 Makefile 的标准方法来检查 gcc 的版本,并在版本低于 4.8.x 时发出警告?
Following Checking the gcc version in a Makefile?在检查 Makefile 中的 gcc 版本之后? , I ended up with the following code:
,我最终得到了以下代码:
# Warn if gcc version is lower than 4.8 (-Og was introduced in this version)
MIN_GCC_VERSION = "4.8"
GCC_VERSION := "`gcc -dumpversion`"
IS_GCC_ABOVE_MIN_VERSION := $(shell expr "$(GCC_VERSION)" ">=" "$(MIN_GCC_VERSION)")
ifeq "$(IS_GCC_ABOVE_MIN_VERSION)" "1"
GCC_VERSION_STRING := "GCC version OK $(GCC_VERSION) >= $(MIN_GCC_VERSION)"
else
GCC_VERSION_STRING := "ERROR: gcc version $(GCC_VERSION) is lower than $(MIN_GCC_VERSION), 'gcc -Og' might fail."
endif
Notes:笔记:
gcc -dumpversion
to avoid the abovementioned clutter in gcc --version
gcc -dumpversion
避免gcc --version
的上述混乱shell expr
to compare the versionsshell expr
比较版本Thanks sycko and madscientist for your useful comments!感谢sycko和madscientist的有用评论!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.