summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons/Tool/gcc.py
diff options
context:
space:
mode:
authorMichael Haubenwallner <haubi@gentoo.org>2014-05-15 08:17:03 (GMT)
committerMichael Haubenwallner <haubi@gentoo.org>2014-05-15 08:17:03 (GMT)
commitc82684ba964183647a1965589ef852eacd9e5447 (patch)
treeeeac860a5e8bba755f8f5dc091702bc78989d8a0 /src/engine/SCons/Tool/gcc.py
parent80cdee0bb0319a9c14abd9c60b4123aee07f0274 (diff)
downloadSCons-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.py58
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