From d8b47ebdd42801f0f1d5f6e62f8e7cf84756b03c Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 13 Dec 2017 10:53:42 -0800 Subject: [PATCH] [waf] Use RPATH $ORIGIN on FreeBSD/Linux and copy libclang.so.[4-9] to $PREFIX/lib/clang+llvm*/lib/ (#133) Also copy build/release/lib/clang+llvm-5.0.0-linux-x86_64-ubuntu14.04/lib/clang/5.0.0/include/* to $PREFIX/lib/clang+llvm*/resource-dir/include/ --- wscript | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/wscript b/wscript index e5b3de3f..f7b283cb 100644 --- a/wscript +++ b/wscript @@ -141,8 +141,21 @@ def configure(ctx): print('Checking for clang') download_and_extract(CLANG_DIRECTORY, CLANG_TARBALL_URL) - clang_node = ctx.path.find_dir(CLANG_DIRECTORY) + bundled_clang_dir = os.path.join(out, ctx.options.variant, 'lib', CLANG_TARBALL_NAME) + try: + os.makedirs(os.path.dirname(bundled_clang_dir)) + except OSError: + pass + try: + os.symlink('../../' + CLANG_TARBALL_NAME, bundled_clang_dir) + except OSError: + pass + try: + os.symlink(os.path.join('lib/clang', ctx.options.bundled_clang), os.path.join(bundled_clang_dir, 'resource-dir')) + except OSError: + pass + clang_node = ctx.path.find_dir(bundled_clang_dir) ctx.check_cxx(uselib_store='clang', includes=clang_node.find_dir('include').abspath(), libpath=clang_node.find_dir('lib').abspath(), @@ -184,6 +197,14 @@ def build(bld): elif sys.platform == 'darwin': lib.append('pthread') + clang_tarball_name = None + if bld.env['use_system_clang']: + rpath = [] + elif sys.platform.startswith('freebsd') or sys.platform.startswith('linux'): + clang_tarball_name = os.path.basename(os.path.dirname(bld.env['LIBPATH_clang'][0])) + rpath = '$ORIGIN/../lib/' + clang_tarball_name + '/lib' + else: + rpath = bld.env['LIBPATH_clang'] bld.program( source=cc_files, use='clang', @@ -197,9 +218,14 @@ def build(bld): 'third_party/sparsepp/'], defines=['LOGURU_WITH_STREAMS=1'], lib=lib, - rpath=[] if bld.env['use_system_clang'] else bld.env['LIBPATH_clang'], + rpath=rpath, target='bin/cquery') + if bld.cmd == 'install': + if clang_tarball_name is not None: + bld.install_files('${PREFIX}/lib/' + clang_tarball_name + '/lib', bld.path.get_bld().ant_glob('lib/clang+llvm*/lib/libclang.so.[4-9]')) + bld.install_files('${PREFIX}/lib/' + clang_tarball_name + '/resource-dir/include', bld.path.get_bld().ant_glob('lib/clang+llvm*/lib/clang/[4-9]*/include/*')) + #bld.shlib(source='a.cpp', target='mylib', vnum='9.8.7') #bld.shlib(source='a.cpp', target='mylib2', vnum='9.8.7', cnum='9.8') #bld.shlib(source='a.cpp', target='mylib3')