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): |
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 | cflags = [] |
44 | libs = [] |
45 | libconfig('mLib', '2.0.3') |
46 | libconfig('catacomb', '2.1.0') |
47 | |
48 | class SubprocessFailure (Exception): |
49 | def __init__(me, file, rc): |
50 | me.args = (file, rc) |
51 | me.file = file |
52 | me.rc = rc |
53 | def __str__(me): |
54 | if WIFEXITED(me.rc): |
55 | return '%s failed (rc = %d)' % (me.file, WEXITSTATUS(me.rc)) |
56 | elif WIFSIGNALED(me.rc): |
57 | return '%s died (signal %d)' % (me.file, WTERMSIG(me.rc)) |
58 | else: |
59 | return '%s died inexplicably' % (me.file) |
60 | |
61 | for g in ['algorithms.h']: |
62 | if type(g) == tuple: |
63 | fin, fout = g |
64 | else: |
65 | root, ext = path.splitext(g) |
66 | fin = root + '.py' |
67 | fout = g |
68 | stin = stat(fin) |
69 | try: |
70 | stout = stat(fout) |
71 | updatep = stin.st_mtime > stout.st_mtime |
72 | except OSError, err: |
73 | if err.errno == ENOENT: |
74 | updatep = True |
75 | else: |
76 | raise |
77 | if updatep: |
78 | kid = fork() |
79 | print 'running %s to create %s' % (fin, fout) |
80 | fnew = fout + '.new' |
81 | if kid == 0: |
82 | try: |
83 | out = file(fnew, 'w') |
84 | dup2(out.fileno(), stdout.fileno()) |
85 | out.close() |
86 | execl(sys.executable, sys.executable, fin) |
87 | except: |
88 | stderr.write('error running %s -> %s: %s\n' % |
89 | (fin, fout, sys.exc_info()[1])) |
90 | _exit(127) |
91 | _, rc = waitpid(kid, 0) |
92 | if rc: |
93 | raise SubprocessFailure, (fin, rc) |
94 | rename(fnew, fout) |
95 | |
96 | cat = Extension('catacomb._base', |
97 | ['catacomb.c', 'bytestring.c', |
98 | 'rand.c', 'algorithms.c', 'pubkey.c', 'pgen.c', |
99 | 'mp.c', 'field.c', 'ec.c', 'group.c', 'passphrase.c'], |
100 | ##extra_compile_args = ['-O0'], |
101 | include_dirs = uniquify(incdirs), |
102 | library_dirs = uniquify(libdirs), |
103 | libraries = uniquify(libs)) |
104 | |
105 | setup(name = 'Catacomb', |
106 | version = '2.1.0', |
107 | description = 'Interface to Catacomb cryptographic library', |
108 | url = 'http://tux.nsict.org/~mdw/Catacomb-2.1.0', |
109 | author = 'Straylight/Edgeware', |
110 | author_email = 'mdw@nsict.org', |
111 | license = 'GNU General Public License', |
112 | packages = ['catacomb'], |
113 | scripts = ['pwsafe'], |
114 | ext_modules = [cat]) |