diff options
author | Michael Haubenwallner <haubi@gentoo.org> | 2014-05-15 08:17:03 (GMT) |
---|---|---|
committer | Michael Haubenwallner <haubi@gentoo.org> | 2014-05-15 08:17:03 (GMT) |
commit | c82684ba964183647a1965589ef852eacd9e5447 (patch) | |
tree | eeac860a5e8bba755f8f5dc091702bc78989d8a0 /src/engine/SCons/Tool/gcc.py | |
parent | 80cdee0bb0319a9c14abd9c60b4123aee07f0274 (diff) | |
download | SCons-c82684ba964183647a1965589ef852eacd9e5447.zip SCons-c82684ba964183647a1965589ef852eacd9e5447.tar.gz SCons-c82684ba964183647a1965589ef852eacd9e5447.tar.bz2 |
Respect preset CC/CXX values detecting cc/c++/gcc/g++ Tools.
As the user-preset values for CC/CXX should rule always, also respect them in
exists() and generate() methods of these Tools. As a result, the value for
CCVERSION/CXXVERSION does match the CC/CXX compiler used (issue#1723).
Diffstat (limited to 'src/engine/SCons/Tool/gcc.py')
-rw-r--r-- | src/engine/SCons/Tool/gcc.py | 58 |
1 files changed, 39 insertions, 19 deletions
diff --git a/src/engine/SCons/Tool/gcc.py b/src/engine/SCons/Tool/gcc.py index 71f60a3..df65647 100644 --- a/src/engine/SCons/Tool/gcc.py +++ b/src/engine/SCons/Tool/gcc.py @@ -44,34 +44,54 @@ compilers = ['gcc', 'cc'] def generate(env): """Add Builders and construction variables for gcc to an Environment.""" + + if 'CC' not in env: + env['CC'] = env.Detect(compilers) or compilers[0] + cc.generate(env) - env['CC'] = env.Detect(compilers) or 'gcc' if env['PLATFORM'] in ['cygwin', 'win32']: env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS') else: env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS -fPIC') # determine compiler version - if env['CC']: - #pipe = SCons.Action._subproc(env, [env['CC'], '-dumpversion'], - pipe = SCons.Action._subproc(env, [env['CC'], '--version'], - stdin = 'devnull', - stderr = 'devnull', - stdout = subprocess.PIPE) - if pipe.wait() != 0: return - # -dumpversion was added in GCC 3.0. As long as we're supporting - # GCC versions older than that, we should use --version and a - # regular expression. - #line = pipe.stdout.read().strip() - #if line: - # env['CCVERSION'] = line - line = pipe.stdout.readline() - match = re.search(r'[0-9]+(\.[0-9]+)+', line) - if match: - env['CCVERSION'] = match.group(0) + version = detect_version(env, env['CC']) + if version: + env['CCVERSION'] = version def exists(env): - return env.Detect(compilers) + # is executable, and is a GNU compiler (or accepts '--version' at least) + return detect_version(env, env.Detect(env.get('CC', compilers))) + +def detect_version(env, cc): + """Return the version of the GNU compiler, or None if it is not a GNU compiler.""" + cc = env.subst(cc) + if not cc: + return None + version = None + #pipe = SCons.Action._subproc(env, SCons.Util.CLVar(cc) + ['-dumpversion'], + pipe = SCons.Action._subproc(env, SCons.Util.CLVar(cc) + ['--version'], + stdin = 'devnull', + stderr = 'devnull', + stdout = subprocess.PIPE) + # -dumpversion was added in GCC 3.0. As long as we're supporting + # GCC versions older than that, we should use --version and a + # regular expression. + #line = pipe.stdout.read().strip() + #if line: + # version = line + line = pipe.stdout.readline() + match = re.search(r'[0-9]+(\.[0-9]+)+', line) + if match: + version = match.group(0) + # Non-GNU compiler's output (like AIX xlc's) may exceed the stdout buffer: + # So continue with reading to let the child process actually terminate. + while pipe.stdout.readline(): + pass + ret = pipe.wait() + if ret != 0: + return None + return version # Local Variables: # tab-width:4 |