chiark / gitweb /
Fix qualified names for types supplied by C.
[mLib-python] / setup.py
CommitLineData
20bce5e9 1from distutils.core import setup, Extension
2from Pyrex.Distutils import build_ext
3from os import *
4from errno import *
5import sre
6import sys
7from sys import stdin, stdout, stderr
8
9incdirs = []
10libdirs = []
11libs = []
12
13def progoutput(cmd):
14 p = popen(cmd)
15 out = p.readline()
16 if p.read() != '': raise 'extra junk from %s' % cmd
17 p.close()
18 return out.rstrip('\n')
19
20def libconfig(lib, ver):
21 config = lib + '-config'
22 if system('%s --check %s' % (config, ver)):
23 raise '%s version %s not found' % (lib, ver)
24 version = progoutput('%s --version' % config)
25 for i in progoutput('%s --cflags' % config).split():
26 if i[:2] == '-I': incdirs.append(i[2:])
27 else: raise 'strange cflags item %s' % i
28 for i in progoutput('%s --libs' % config).split():
29 if i[:2] == '-L': libdirs.append(i[2:])
30 elif i[:2] == '-l': libs.append(i[2:])
31 else: raise 'strange libs item %s' % i
32
33def uniquify(l):
34 u = {}
35 o = []
36 for i in l:
37 if i not in u:
38 o.append(i)
39 u[i] = 1
40 return o
41
42libconfig('catacomb', '2.1.0')
43libconfig('mLib', '2.0.3')
44
45def needs_update_p(target, sources):
46 if not path.exists(target): return True
47 t_target = stat(target).st_mtime
48 for s in sources:
49 if stat(s).st_mtime > t_target: return True
50 return False
51
52rx_subst = sre.compile(r'\%(\w+)\%')
53
579d0169 54def derive(target, src, subs):
55 if needs_update_p(target, [src]):
56 out = file(target + '.new', 'w')
57 for line in file(src):
d8d81d1b 58 out.write(rx_subst.sub((lambda m: subs[m.group(1)]), line))
20bce5e9 59 out.close()
579d0169 60 rename(target + '.new', target)
61
62derive('base64.pyx', 'codec.pyx.in',
63 {'CLASS': 'Base64', 'PREFIX': 'base64'})
64derive('base32.pyx', 'codec.pyx.in',
65 {'CLASS': 'Base32', 'PREFIX': 'base32'})
66derive('hex.pyx', 'codec.pyx.in',
67 {'CLASS': 'Hex', 'PREFIX': 'hex'})
20bce5e9 68
69def mlibext(src):
70 col = src.find('!')
71 if col >= 0:
72 mod = src[:col]
73 srcs = [getsource(s) for s in src[col + 1:].split(',')]
74 else:
75 src = getsource(src)
76 mod, hunoz = src.split('.', 1)
77 srcs = [src]
579d0169 78
79mlib = Extension('mLib', ['mLib.pyx', 'atom-base.c', 'array.c'],
d8d81d1b
MW
80
81 ##extra_compile_args = ['-O0'],
82 include_dirs = uniquify(incdirs),
83 library_dirs = uniquify(libdirs),
84 libraries = uniquify(libs))
20bce5e9 85
86setup(name = 'mLib-python',
87 version = '1.0.0',
88 description = 'Python interface to mLib utilities library',
89 author = 'Straylight/Edgeware',
90 author_email = 'mdw@distorted.org.uk',
91 license = 'GNU General Public License',
579d0169 92 ext_modules = [mlib],
20bce5e9 93 cmdclass = {'build_ext': build_ext})