Makefile
参数为gcc
开源项目中的某个Makefile`包含以下调用:
CFLAGS = -I$(RM_INCLUDE_DIR) -Wall -g -fPIC -lc -lm -Og -std=gnu99
该-Og
参数被引入gcc 4.8。我的 OSX 包含 gcc 4.2.1,它失败了,并出现了一个相当混乱的错误消息。
问题
是否有一种优雅且标准的(即,适用于任何 POSIX 环境)方法来检查 gcc 的版本并在它低于 4.8 时发出警告?
问题是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.
我的问题
是否有一种优雅、兼容 Makefile 和标准的方法来检查 gcc 的版本,如果版本低于 4.8.x,则发出警告?