diff options
author | Chris Dyer <cdyer@cs.cmu.edu> | 2012-08-10 23:58:41 -0400 |
---|---|---|
committer | Chris Dyer <cdyer@cs.cmu.edu> | 2012-08-10 23:58:41 -0400 |
commit | 88a2df4292f26c4a17de4a856b0579c4ce0de7dd (patch) | |
tree | 9c70700562fd31ec2c7e8182ffbd5bc9982310b7 /python/setup.py.in | |
parent | 3e5590e041563095833753f3fed24373a7461d3e (diff) |
autogenerate setup.py
Diffstat (limited to 'python/setup.py.in')
-rw-r--r-- | python/setup.py.in | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/python/setup.py.in b/python/setup.py.in new file mode 100644 index 00000000..77c10b07 --- /dev/null +++ b/python/setup.py.in @@ -0,0 +1,52 @@ +from distutils.core import setup +from distutils.extension import Extension +import sys +import re + +def fail(msg): + sys.stderr.write(msg) + sys.exit(1) + +INC = ['..', 'src/', '../decoder', '../utils', '../mteval'] +LIB = ['../decoder', '../utils', '../mteval', '../training', '../klm/lm', '../klm/util'] + +# set automatically by configure +raw_config_libs = '@LIBS@' + +try: + with open('../config.status') as config: + config = config.read() + subs = dict(re.findall('s,@(\w+)@,\|#_!!_#\|(.*),g', config)) # sed + if not subs: + subs = dict(re.findall('S\["(\w+)"\]="(.*)"', config)) # awk + if not subs: + fail('Cannot parse config.status\n' + 'Please report this bug to the developers') + LIBS = re.findall('-l([^\s]+)', subs['LIBS']) + CPPFLAGS = re.findall('-[^R][^\s]+', subs['CPPFLAGS']) + LDFLAGS = re.findall('-[^\s]+', subs['LDFLAGS']) + LDFLAGS = [opt.replace('-R', '-Wl,-rpath,') for opt in LDFLAGS] +except IOError: + fail('Did you run ./configure? Cannot find config.status') +except KeyError as e: + fail('Cannot find option {0} in config.status'.format(e)) + +ext_modules = [ + Extension(name='cdec._cdec', + sources=['src/_cdec.cpp'], + include_dirs=INC, + library_dirs=LIB, + libraries=LIBS + ['z', 'cdec', 'utils', 'mteval', 'training', 'klm', 'klm_util'], + extra_compile_args=CPPFLAGS, + extra_link_args=LDFLAGS), + Extension(name='cdec.sa._sa', + sources=['src/sa/_sa.c', 'src/sa/strmap.cc']) +] + +setup( + name='cdec', + ext_modules=ext_modules, + requires=['configobj'], + packages=['cdec', 'cdec.sa'], + package_dir={'': 'pkg'} +) |