1 from distutils.core import setup, Extension
2 from Pyrex.Distutils import build_ext
7 from sys import stdin, stdout, stderr
16 if p.read() != '': raise 'extra junk from %s' % cmd
18 return out.rstrip('\n')
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
38 libconfig('catacomb', '2.1.0')
39 libconfig('mLib', '2.0.3')
41 def needs_update_p(target, sources):
42 if not path.exists(target): return True
43 t_target = stat(target).st_mtime
45 if stat(s).st_mtime > t_target: return True
48 rx_subst = re.compile(r'\%(\w+)\%')
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))
56 rename(target + '.new', target)
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'})
69 srcs = [getsource(s) for s in src[col + 1:].split(',')]
72 mod, hunoz = src.split('.', 1)
75 mlib = Extension('mLib', ['mLib.pyx', 'atom-base.c', 'array.c'],
77 ##extra_compile_args = ['-O0'],
78 include_dirs = uniquify(incdirs),
79 library_dirs = uniquify(libdirs),
80 libraries = uniquify(libs))
82 setup(name = 'mLib-python',
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',
89 cmdclass = {'build_ext': build_ext})