Add build system. Fix import.
[checkpath-python] / setup.py
diff --git a/setup.py b/setup.py
new file mode 100644 (file)
index 0000000..5ae8c34
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,67 @@
+#! /usr/bin/python
+
+from distutils.core import setup, Extension
+from os import *
+from errno import *
+
+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('mLib', '2.0.3')
+libconfig('checkpath', '1.1.0')
+
+class SubprocessFailure (Exception):
+  def __init__(me, file, rc):
+    me.args = (file, rc)
+    me.file = file
+    me.rc = rc
+  def __str__(me):
+    if WIFEXITED(me.rc):
+      return '%s failed (rc = %d)' % (me.file, WEXITSTATUS(me.rc))
+    elif WIFSIGNALED(me.rc):
+      return '%s died (signal %d)' % (me.file, WTERMSIG(me.rc))
+    else:
+      return '%s died inexplicably' % (me.file)
+
+chk = Extension('checkpath',
+                ['checkpath.c'],
+                include_dirs = uniquify(incdirs),
+                library_dirs = uniquify(libdirs),
+                libraries = uniquify(libs))
+setup(name = 'CheckPath',
+      version = '1.1.0',
+      description = 'Checking paths for security',
+      author = 'Straylight/Edgeware',
+      author_email = 'mdw@nsict.org',
+      license = 'GNU General Public License',
+      ext_modules = [chk])