From 2c3e8b6aa6427797af7afc003ea4a539577d5fa1 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 13 Aug 2012 15:29:09 +0200 Subject: [PATCH] build: rework -fvisibility=hidden detection Make the gcc_version macro conform with what node.js and v8 use. Important because node.js's common.gypi is going to export it soon. --- build/gcc_version.py | 20 -------------------- common.gypi | 7 +++---- gyp_uv | 23 ++++++++++++++++------- 3 files changed, 19 insertions(+), 31 deletions(-) delete mode 100644 build/gcc_version.py diff --git a/build/gcc_version.py b/build/gcc_version.py deleted file mode 100644 index da019e86..00000000 --- a/build/gcc_version.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/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 79306a75..0ffb45e8 100644 --- a/common.gypi +++ b/common.gypi @@ -6,6 +6,8 @@ 'library%': 'static_library', # allow override to 'shared_library' for DLL/.so builds 'component%': 'static_library', # NB. these names match with what V8 expects 'msvs_multi_core_compile': '0', # we do enable multicore compiles, but not using the V8 way + 'gcc_version%': 'unknown', + 'clang%': 0, }, 'target_defaults': { @@ -117,9 +119,6 @@ ], }], [ 'OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="solaris"', { - 'variables': { - 'gcc_version%': ')', - }, 'cflags': [ '-Wall' ], 'cflags_cc': [ '-fno-rtti', '-fno-exceptions' ], 'conditions': [ @@ -137,7 +136,7 @@ 'cflags': [ '-pthread' ], 'ldflags': [ '-pthread' ], }], - [ 'visibility=="hidden" and gcc_version >= "4.0.0"', { + [ 'visibility=="hidden" and (clang==1 or gcc_version >= 40)', { 'cflags': [ '-fvisibility=hidden' ], }], ], diff --git a/gyp_uv b/gyp_uv index 14a3cae7..00da3aed 100755 --- a/gyp_uv +++ b/gyp_uv @@ -1,11 +1,14 @@ #!/usr/bin/env python + import glob import os -import shlex +import subprocess import sys +CC = os.environ.get('CC', 'cc') script_dir = os.path.dirname(__file__) uv_root = os.path.normpath(script_dir) +output_dir = os.path.join(os.path.abspath(uv_root), 'out') sys.path.insert(0, os.path.join(uv_root, 'build', 'gyp', 'pylib')) try: @@ -14,9 +17,14 @@ except ImportError: print('You need to install gyp in build/gyp first. See the README.') sys.exit(42) -# Directory within which we want all generated files (including Makefiles) -# to be written. -output_dir = os.path.join(os.path.abspath(uv_root), 'out') + +def compiler_version(): + proc = subprocess.Popen(CC.split() + ['--version'], stdout=subprocess.PIPE) + is_clang = 'clang' in proc.communicate()[0].split('\n')[0] + proc = subprocess.Popen(CC.split() + ['-dumpversion'], stdout=subprocess.PIPE) + version = tuple(map(int, proc.communicate()[0].split('.'))) + return (version, is_clang) + def run_gyp(args): rc = gyp.main(args) @@ -24,6 +32,7 @@ def run_gyp(args): print 'Error running GYP' sys.exit(rc) + if __name__ == '__main__': args = sys.argv[1:] @@ -49,12 +58,12 @@ if __name__ == '__main__': # There's a bug with windows which doesn't allow this feature. if sys.platform != 'win32': - # Tell gyp to write the Makefiles into output_dir args.extend(['--generator-output', output_dir]) - # Tell make to write its output into the same dir args.extend(['-Goutput_dir=' + output_dir]) - # Create Makefiles, not XCode projects args.extend('-f make'.split()) + (major, minor), is_clang = compiler_version() + args.append('-Dgcc_version=%d' % (10 * major + minor)) + args.append('-Dclang=%d' % int(is_clang)) args.append('-Dtarget_arch=ia32') args.append('-Dcomponent=static_library')