Lines 44-77
Link Here
|
44 |
|
44 |
|
45 |
def generate(env): |
45 |
def generate(env): |
46 |
"""Add Builders and construction variables for gcc to an Environment.""" |
46 |
"""Add Builders and construction variables for gcc to an Environment.""" |
|
|
47 |
|
48 |
if 'CC' not in env: |
49 |
env['CC'] = env.Detect(compilers) or compilers[0] |
50 |
|
47 |
cc.generate(env) |
51 |
cc.generate(env) |
48 |
|
52 |
|
49 |
env['CC'] = env.Detect(compilers) or 'gcc' |
|
|
50 |
if env['PLATFORM'] in ['cygwin', 'win32']: |
53 |
if env['PLATFORM'] in ['cygwin', 'win32']: |
51 |
env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS') |
54 |
env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS') |
52 |
else: |
55 |
else: |
53 |
env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS -fPIC') |
56 |
env['SHCCFLAGS'] = SCons.Util.CLVar('$CCFLAGS -fPIC') |
54 |
# determine compiler version |
57 |
# determine compiler version |
55 |
if env['CC']: |
58 |
version = detect_version(env, env['CC']) |
56 |
#pipe = SCons.Action._subproc(env, [env['CC'], '-dumpversion'], |
59 |
if version: |
57 |
pipe = SCons.Action._subproc(env, [env['CC'], '--version'], |
60 |
env['CCVERSION'] = version |
58 |
stdin = 'devnull', |
|
|
59 |
stderr = 'devnull', |
60 |
stdout = subprocess.PIPE) |
61 |
if pipe.wait() != 0: return |
62 |
# -dumpversion was added in GCC 3.0. As long as we're supporting |
63 |
# GCC versions older than that, we should use --version and a |
64 |
# regular expression. |
65 |
#line = pipe.stdout.read().strip() |
66 |
#if line: |
67 |
# env['CCVERSION'] = line |
68 |
line = pipe.stdout.readline() |
69 |
match = re.search(r'[0-9]+(\.[0-9]+)+', line) |
70 |
if match: |
71 |
env['CCVERSION'] = match.group(0) |
72 |
|
61 |
|
73 |
def exists(env): |
62 |
def exists(env): |
74 |
return env.Detect(compilers) |
63 |
# is executable, and is a GNU compiler (or accepts '--version' at least) |
|
|
64 |
return detect_version(env, env.Detect(env.get('CC', compilers))) |
65 |
|
66 |
def detect_version(env, cc): |
67 |
"""Return the version of the GNU compiler, or None if it is not a GNU compiler.""" |
68 |
cc = env.subst(cc) |
69 |
if not cc: |
70 |
return None |
71 |
version = None |
72 |
#pipe = SCons.Action._subproc(env, SCons.Util.CLVar(cc) + ['-dumpversion'], |
73 |
pipe = SCons.Action._subproc(env, SCons.Util.CLVar(cc) + ['--version'], |
74 |
stdin = 'devnull', |
75 |
stderr = 'devnull', |
76 |
stdout = subprocess.PIPE) |
77 |
# -dumpversion was added in GCC 3.0. As long as we're supporting |
78 |
# GCC versions older than that, we should use --version and a |
79 |
# regular expression. |
80 |
#line = pipe.stdout.read().strip() |
81 |
#if line: |
82 |
# version = line |
83 |
line = pipe.stdout.readline() |
84 |
match = re.search(r'[0-9]+(\.[0-9]+)+', line) |
85 |
if match: |
86 |
version = match.group(0) |
87 |
# Non-GNU compiler's output (like AIX xlc's) may exceed the stdout buffer: |
88 |
# So continue with reading to let the child process actually terminate. |
89 |
while pipe.stdout.readline(): |
90 |
pass |
91 |
ret = pipe.wait() |
92 |
if ret != 0: |
93 |
return None |
94 |
return version |
75 |
|
95 |
|
76 |
# Local Variables: |
96 |
# Local Variables: |
77 |
# tab-width:4 |
97 |
# tab-width:4 |