summaryrefslogtreecommitdiff
path: root/python/setup.py
blob: 54510024ea53f9e24be9537c4e9ab2c0fc5f3d02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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']

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'}
)