Initing with 0.1+some changes.

git-svn-id: http://llvm-py.googlecode.com/svn/trunk@2 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
mdevan.foobar 2008-05-27 08:50:46 +00:00
commit 37f3a30a4a
13 changed files with 3593 additions and 0 deletions

80
setup.py Normal file
View file

@ -0,0 +1,80 @@
#!/usr/bin/env python
import sys, os
from distutils.core import setup, Extension
def _run(cmd):
return os.popen(cmd).read().rstrip()
def get_libs(llvm_config, components):
return _run(llvm_config + ' --libs ' + ' '.join(components))
def get_llvm_config():
# get from command-line, or use default
lc = 'llvm-config'
for i in xrange(0, len(sys.argv)):
arg = sys.argv[i]
if arg.startswith('--llvm-config='):
del sys.argv[i]
lc = arg.split('=')[1]
# see if it works
version = _run(lc + ' --version')
if version == '':
return (lc, False) # didn't work
return (lc, True)
def call_setup(llvm_config):
incdir = _run(llvm_config + ' --includedir')
ldflags = _run(llvm_config + ' --ldflags')
libs_core = get_libs(llvm_config, ['core', 'analysis'])
ext_core = Extension(
'llvm._core',
['llvm/_core.c', 'llvm/wrap.c', 'llvm/extra.cpp'],
define_macros = [
('__STDC_LIMIT_MACROS', None),
('_GNU_SOURCE', None)],
include_dirs = [incdir],
extra_link_args = [ldflags + ' ' + libs_core])
setup(
name='llvm-py',
version='0.2',
description='Python Bindings for LLVM',
author='Mahadevan R',
author_email='mdevan.foobar@gmail.com',
url='http://code.google.com/p/llvm-py/',
packages=['llvm'],
py_modules = [ 'llvm.core' ],
ext_modules = [ ext_core ],)
def main():
# get llvm config
llvm_config, is_good = get_llvm_config()
if is_good:
print "Using llvm-config=" + llvm_config
else:
print "Cannot invoke llvm-config (tried '%s')." % llvm_config
print "Try again with --llvm-config=/path/to/llvm-config."
return 1
# setup
call_setup(llvm_config)
# done
return 0
ev = main()
sys.exit(ev)