General: Fix lots of whitespace issues.
[catacomb-python] / setup.py
1 #! /usr/bin/python
2
3 from distutils.core import setup, Extension
4 from os import *
5 from os import _exit
6 from errno import *
7 import sys
8 from sys import stdin, stdout, stderr
9
10 def progoutput(cmd):
11 p = popen(cmd)
12 out = p.readline()
13 if p.read() != '': raise 'extra junk from %s' % cmd
14 p.close()
15 return out.rstrip('\n')
16
17 incdirs = []
18 libdirs = []
19 libs = []
20
21 def libconfig(lib, ver):
22 config = lib + '-config'
23 if system('%s --check %s' % (config, ver)):
24 raise '%s version %s not found' % (lib, ver)
25 version = progoutput('%s --version' % config)
26 for i in progoutput('%s --cflags' % config).split():
27 if i[:2] == '-I': incdirs.append(i[2:])
28 else: raise 'strange cflags item %s' % i
29 for i in progoutput('%s --libs' % config).split():
30 if i[:2] == '-L': libdirs.append(i[2:])
31 elif i[:2] == '-l': libs.append(i[2:])
32 else: raise 'strange libs item %s' % i
33
34 def uniquify(l):
35 u = {}
36 o = []
37 for i in l:
38 if i not in u:
39 o.append(i)
40 u[i] = 1
41 return o
42
43 libconfig('catacomb', '2.1.0')
44 libconfig('mLib', '2.0.3')
45
46 class SubprocessFailure (Exception):
47 def __init__(me, file, rc):
48 me.args = (file, rc)
49 me.file = file
50 me.rc = rc
51 def __str__(me):
52 if WIFEXITED(me.rc):
53 return '%s failed (rc = %d)' % (me.file, WEXITSTATUS(me.rc))
54 elif WIFSIGNALED(me.rc):
55 return '%s died (signal %d)' % (me.file, WTERMSIG(me.rc))
56 else:
57 return '%s died inexplicably' % (me.file)
58
59 for g in ['algorithms.h']:
60 if type(g) == tuple:
61 fin, fout = g
62 else:
63 root, ext = path.splitext(g)
64 fin = root + '.py'
65 fout = g
66 stin = stat(fin)
67 try:
68 stout = stat(fout)
69 updatep = stin.st_mtime > stout.st_mtime
70 except OSError, err:
71 if err.errno == ENOENT:
72 updatep = True
73 else:
74 raise
75 if updatep:
76 kid = fork()
77 print 'running %s to create %s' % (fin, fout)
78 fnew = fout + '.new'
79 if kid == 0:
80 try:
81 out = file(fnew, 'w')
82 dup2(out.fileno(), stdout.fileno())
83 out.close()
84 execl(sys.executable, sys.executable, fin)
85 except:
86 stderr.write('error running %s -> %s: %s\n' %
87 (fin, fout, sys.exc_info()[1]))
88 _exit(127)
89 _, rc = waitpid(kid, 0)
90 if rc:
91 raise SubprocessFailure, (fin, rc)
92 rename(fnew, fout)
93
94 cat = Extension('catacomb._base',
95 ['catacomb.c', 'bytestring.c', 'buffer.c',
96 'rand.c', 'algorithms.c', 'pubkey.c', 'pgen.c',
97 'mp.c', 'field.c', 'ec.c', 'group.c', 'passphrase.c',
98 'share.c', 'key.c', 'util.c'],
99 ##extra_compile_args = ['-O0'],
100 include_dirs = uniquify(incdirs),
101 library_dirs = uniquify(libdirs),
102 libraries = uniquify(libs))
103
104 setup(name = 'catacomb-python',
105 version = '1.0.0',
106 description = 'Interface to Catacomb cryptographic library',
107 url = 'http://www.distorted.org.uk/~mdw/Catacomb-2.1.0',
108 author = 'Straylight/Edgeware',
109 author_email = 'mdw@distorted.org.uk',
110 license = 'GNU General Public License',
111 packages = ['catacomb'],
112 scripts = ['pwsafe'],
113 ext_modules = [cat])