Skip to content
Snippets Groups Projects
Commit 4e28fb9c authored by Andrea Shepard's avatar Andrea Shepard
Browse files

Pass LLVM includes and defines to python bindings

parent e31d1206
No related branches found
No related tags found
No related merge requests found
...@@ -190,6 +190,29 @@ class LLVMConfigSanitizer: ...@@ -190,6 +190,29 @@ class LLVMConfigSanitizer:
env.MergeFlags(filtered_cmd, unique) env.MergeFlags(filtered_cmd, unique)
llvm_config_sanitizer = LLVMConfigSanitizer() llvm_config_sanitizer = LLVMConfigSanitizer()
# LLVM defines, which the python bindings need
try:
llvm_config_cflags = subprocess.Popen('%s --cflags' % env["LLVM_CONFIG"], \
shell=True, \
stdin=subprocess.PIPE, stdout=subprocess.PIPE).communicate()
flags = llvm_config_cflags[0].split()
# get just the -D ones
p = re.compile("^-D(.*)$")
llvm_defines = [p.match(flag).group(1) for flag in flags if p.match(flag)]
except:
print "%s failed. Make sure you have LLVM and clang installed." % env["LLVM_CONFIG"]
Exit(1)
# Get the llvm includedir, which the python bindings need
try:
llvm_config_includes = subprocess.Popen('%s --includedir' % env["LLVM_CONFIG"], \
shell=True, \
stdin=subprocess.PIPE, stdout=subprocess.PIPE).communicate()
llvm_includes = llvm_config_includes[0].splitlines()
except:
print "%s failed. Make sure you have LLVM and clang installed." % env["LLVM_CONFIG"]
Exit(1)
# This goes here so we already know all the LLVM crap # This goes here so we already know all the LLVM crap
# Make a fresh environment to parse the config into, to read out just LLVM stuff # Make a fresh environment to parse the config into, to read out just LLVM stuff
llvm_dummy_env = Environment() llvm_dummy_env = Environment()
...@@ -229,6 +252,8 @@ Export('targets') ...@@ -229,6 +252,8 @@ Export('targets')
Export('llvm_computed_shared_lib_name') Export('llvm_computed_shared_lib_name')
Export('llvm_config_sanitizer') Export('llvm_config_sanitizer')
Export('llvm_config_version') Export('llvm_config_version')
Export('llvm_defines')
Export('llvm_includes')
Export('llvm_linkage_type_flag') Export('llvm_linkage_type_flag')
Export('llvm_required_components') Export('llvm_required_components')
Export('llvm_system_libs_flag') Export('llvm_system_libs_flag')
......
# -*- python -*- # -*- python -*-
import os, os.path import os, os.path
Import('env libhammer_shared testruns targets') Import('env libhammer_shared testruns targets')
Import('llvm_defines')
Import('llvm_includes')
pythonenv = env.Clone(IMPLICIT_COMMAND_DEPENDENCIES = 0) pythonenv = env.Clone(IMPLICIT_COMMAND_DEPENDENCIES = 0)
swig = pythonenv.Command("hammer.i", "../swig/hammer.i", Copy("$TARGET", "$SOURCE")) swig = pythonenv.Command("hammer.i", "../swig/hammer.i", Copy("$TARGET", "$SOURCE"))
setup = ['setup.py'] setup = ['setup.py']
pydir = os.path.join(env['BUILD_BASE'], 'src/bindings/python') pydir = os.path.join(env['BUILD_BASE'], 'src/bindings/python')
libhammer_python = pythonenv.Command(['hammer.py', 'hammer_wrap.c'], [swig, setup], 'python ' + os.path.join(pydir, 'setup.py') + ' build_ext --inplace') define_list = ','.join(llvm_defines)
inc_list = ' '.join(['-I' + e for e in llvm_includes])
swig_opt_list = '-DHAMMER_INTERNAL__NO_STDARG_H -I../../ ' + inc_list
libhammer_python = pythonenv.Command(['hammer.py', 'hammer_wrap.c'], [swig, setup], \
'python ' + os.path.join(pydir, 'setup.py') + ' build_ext --inplace ' + inc_list + \
' --define=\"' + define_list + '\" --swig-opts=\"' + swig_opt_list + '\"')
Default(libhammer_python) Default(libhammer_python)
pytestenv = pythonenv.Clone() pytestenv = pythonenv.Clone()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment