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