debian/control: Add Build-Depends for `dh-python'.
[mLib-python] / setup.py
old mode 100644 (file)
new mode 100755 (executable)
index f8c091b..66aafc5
--- a/setup.py
+++ b/setup.py
-from distutils.core import setup, Extension
-from Pyrex.Distutils import build_ext
-from os import *
-from errno import *
-import sre
-import sys
-from sys import stdin, stdout, stderr
-
-incdirs = []
-libdirs = []
-libs = []
-
-def progoutput(cmd):
-  p = popen(cmd)
-  out = p.readline()
-  if p.read() != '': raise 'extra junk from %s' % cmd
-  p.close()
-  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():
-    if i[:2] == '-I': incdirs.append(i[2:])
-    else: raise 'strange cflags item %s' % i
-  for i in progoutput('%s --libs' % config).split():
-    if i[:2] == '-L': libdirs.append(i[2:])
-    elif i[:2] == '-l': libs.append(i[2:])
-    else: raise 'strange libs item %s' % i
-
-def uniquify(l):
-  u = {}
-  o = []
-  for i in l:
-    if i not in u:
-      o.append(i)
-      u[i] = 1
-  return o
-
-libconfig('catacomb', '2.1.0')
-libconfig('mLib', '2.0.3')
-
-def needs_update_p(target, sources):
-  if not path.exists(target): return True
-  t_target = stat(target).st_mtime
-  for s in sources:
-    if stat(s).st_mtime > t_target: return True
-  return False
-
-rx_subst = sre.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))
-      out.close()
-      rename(src + '.new', src)
-  return src
-
-def mlibext(src):
-  col = src.find('!')
-  if col >= 0:
-    mod = src[:col]
-    srcs = [getsource(s) for s in src[col + 1:].split(',')]
-  else:
-    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))
-
-setup(name = 'mLib-python',
-      version = '1.0.0',
-      description = 'Python interface to mLib utilities library',
-      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()],
-      cmdclass = {'build_ext': build_ext})
+#! /usr/bin/python
+
+import distutils.core as DC
+import Pyrex.Distutils as PXD
+import mdwsetup as MS
+
+MS.pkg_config('mLib', '2.1.0')
+
+mLib = DC.Extension('mLib', ['mLib.pyx', 'atom-base.c', 'array.c'],
+                    ##extra_compile_args = ['-O0'],
+                    include_dirs = MS.uniquify(MS.INCLUDEDIRS),
+                    library_dirs = MS.uniquify(MS.LIBDIRS),
+                    libraries = MS.uniquify(MS.LIBS))
+
+MS.setup(name = 'mLib-python',
+         description = 'Python interface to mLib utilities library',
+         author = 'Straylight/Edgeware',
+         author_email = 'mdw@distorted.org.uk',
+         license = 'GNU General Public License',
+         ext_modules = [mLib],
+         genfiles = [MS.Derive('base64.pyx', 'codec.pyx.in',
+                               {'CLASS': 'Base64', 'PREFIX': 'base64'}),
+                     MS.Derive('base32.pyx', 'codec.pyx.in',
+                               {'CLASS': 'Base32', 'PREFIX': 'base32'}),
+                     MS.Derive('hex.pyx', 'codec.pyx.in',
+                               {'CLASS': 'Hex', 'PREFIX': 'hex'})],
+         cleanfiles = ['mLib.c'],
+         cmdclass = { 'build_ext': PXD.build_ext })