debian/control: Add Build-Depends for `dh-python'.
[mLib-python] / setup.py
old mode 100644 (file)
new mode 100755 (executable)
index d59471f..66aafc5
--- a/setup.py
+++ b/setup.py
@@ -1,89 +1,28 @@
-from distutils.core import setup, Extension
-from Pyrex.Distutils import build_ext
-from os import *
-from errno import *
-import re
-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):
-  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('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
-
-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.1.0')
-
-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 = re.compile(r'\%(\w+)\%')
-
-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(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('!')
-  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]
-
-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',
-      description = 'Python interface to mLib utilities library',
-      author = 'Straylight/Edgeware',
-      author_email = 'mdw@distorted.org.uk',
-      license = 'GNU General Public License',
-      ext_modules = [mlib],
-      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 })