diff --git a/build/gcc_version.py b/build/gcc_version.py new file mode 100644 index 00000000..da019e86 --- /dev/null +++ b/build/gcc_version.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +import os +import re +import subprocess +import sys + + +def DoMain(*args): + cc = os.environ.get('CC', 'gcc') + stdin, stderr = os.pipe() + subprocess.call([cc, '-v'], stderr=stderr) + output = os.read(stdin, 4096) + match = re.search("\ngcc version (\d+\.\d+\.\d+)", output) + if match: + print(match.group(1)) + + +if __name__ == '__main__': + DoMain(*sys.argv) diff --git a/common.gypi b/common.gypi index 373c3aa9..3e4e0a5a 100644 --- a/common.gypi +++ b/common.gypi @@ -114,6 +114,9 @@ ], }], [ 'OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="solaris"', { + 'variables': { + 'gcc_version%': ')', + }, 'cflags': [ '-Wall', '-pthread', ], 'cflags_cc': [ '-fno-rtti', '-fno-exceptions' ], 'ldflags': [ '-pthread', ], @@ -125,7 +128,7 @@ [ 'OS=="linux"', { 'cflags': [ '-ansi' ], }], - [ 'visibility=="hidden"', { + [ 'visibility=="hidden" and gcc_version >= "4.0.0"', { 'cflags': [ '-fvisibility=hidden' ], }], ],