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