X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib-python/blobdiff_plain/20bce5e92b01cd928f26b61be78215117039c561..23bff39b96e98bc1969d275bc7c43e1d6dd28429:/setup.py diff --git a/setup.py b/setup.py index f8c091b..d59471f 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from distutils.core import setup, Extension from Pyrex.Distutils import build_ext from os import * from errno import * -import sre +import re import sys from sys import stdin, stdout, stderr @@ -18,14 +18,10 @@ def progoutput(cmd): return out.rstrip('\n') def libconfig(lib, ver): - config = lib + '-config' - if system('%s --check %s' % (config, ver)): - raise '%s version %s not found' % (lib, ver) - version = progoutput('%s --version' % config) - for i in progoutput('%s --cflags' % config).split(): + for i in progoutput('pkg-config --cflags "%s >= %s"' % (lib, ver)).split(): if i[:2] == '-I': incdirs.append(i[2:]) else: raise 'strange cflags item %s' % i - for i in progoutput('%s --libs' % config).split(): + for i in progoutput('pkg-config --libs "%s >= %s"' % (lib, ver)).split(): if i[:2] == '-L': libdirs.append(i[2:]) elif i[:2] == '-l': libs.append(i[2:]) else: raise 'strange libs item %s' % i @@ -40,7 +36,7 @@ def uniquify(l): return o libconfig('catacomb', '2.1.0') -libconfig('mLib', '2.0.3') +libconfig('mLib', '2.1.0') def needs_update_p(target, sources): if not path.exists(target): return True @@ -49,26 +45,22 @@ def needs_update_p(target, sources): if stat(s).st_mtime > t_target: return True return False -rx_subst = sre.compile(r'\%(\w+)\%') +rx_subst = re.compile(r'\%(\w+)\%') -def getsource(src): - br = src.find('[') - if br >= 0: - if src[-1] != ']': - raise SyntaxError, 'bad auto file' - subst = src[br + 1:-1] - src = src[:br] - x = subst.split(':') - infile = x[0] - if needs_update_p(src, [infile]): - print 'creating %s from %s...' % (src, infile) - d = dict([i.split('/', 1) for i in x[1:]]) - out = file(src + '.new', 'w') - for line in file(infile): - out.write(rx_subst.sub((lambda m: d[m.group(1)]), line)) +def derive(target, src, subs): + if needs_update_p(target, [src]): + out = file(target + '.new', 'w') + for line in file(src): + out.write(rx_subst.sub((lambda m: subs[m.group(1)]), line)) out.close() - rename(src + '.new', src) - return src + rename(target + '.new', target) + +derive('base64.pyx', 'codec.pyx.in', + {'CLASS': 'Base64', 'PREFIX': 'base64'}) +derive('base32.pyx', 'codec.pyx.in', + {'CLASS': 'Base32', 'PREFIX': 'base32'}) +derive('hex.pyx', 'codec.pyx.in', + {'CLASS': 'Hex', 'PREFIX': 'hex'}) def mlibext(src): col = src.find('!') @@ -79,11 +71,13 @@ def mlibext(src): src = getsource(src) mod, hunoz = src.split('.', 1) srcs = [src] - return Extension('mLib.' + mod, srcs, - ##extra_compile_args = ['-O0'], - include_dirs = uniquify(incdirs), - library_dirs = uniquify(libdirs), - libraries = uniquify(libs)) + +mlib = Extension('mLib', ['mLib.pyx', 'atom-base.c', 'array.c'], + + ##extra_compile_args = ['-O0'], + include_dirs = uniquify(incdirs), + library_dirs = uniquify(libdirs), + libraries = uniquify(libs)) setup(name = 'mLib-python', version = '1.0.0', @@ -91,12 +85,5 @@ setup(name = 'mLib-python', author = 'Straylight/Edgeware', author_email = 'mdw@distorted.org.uk', license = 'GNU General Public License', - packages = ['mLib'], - ext_modules = [mlibext(x) for x in ''' - select.pyx crc32.pyx unihash.pyx report.pyx - base64.pyx[codec.pyx.in:PREFIX/base64] - base32.pyx[codec.pyx.in:PREFIX/base32] - hex.pyx[codec.pyx.in:PREFIX/hex] - array.c sym.pyx atom!atom-base.c,atom.pyx - '''.split()], + ext_modules = [mlib], cmdclass = {'build_ext': build_ext})