ab147f75 |
1 | #! /usr/bin/python |
2 | |
3 | from distutils.core import setup, Extension |
4 | from os import * |
5 | from errno import * |
6 | |
7 | incdirs = [] |
8 | libdirs = [] |
9 | libs = [] |
10 | |
11 | def progoutput(cmd): |
12 | p = popen(cmd) |
13 | out = p.readline() |
14 | if p.read() != '': raise 'extra junk from %s' % cmd |
15 | p.close() |
16 | return out.rstrip('\n') |
17 | |
18 | def libconfig(lib, ver): |
19 | config = lib + '-config' |
20 | if system('%s --check %s' % (config, ver)): |
21 | raise '%s version %s not found' % (lib, ver) |
22 | version = progoutput('%s --version' % config) |
23 | for i in progoutput('%s --cflags' % config).split(): |
24 | if i[:2] == '-I': incdirs.append(i[2:]) |
25 | else: raise 'strange cflags item %s' % i |
26 | for i in progoutput('%s --libs' % config).split(): |
27 | if i[:2] == '-L': libdirs.append(i[2:]) |
28 | elif i[:2] == '-l': libs.append(i[2:]) |
29 | else: raise 'strange libs item %s' % i |
30 | |
31 | def uniquify(l): |
32 | u = {} |
33 | o = [] |
34 | for i in l: |
35 | if i not in u: |
36 | o.append(i) |
37 | u[i] = 1 |
38 | return o |
39 | |
40 | libconfig('mLib', '2.0.3') |
41 | libconfig('checkpath', '1.1.0') |
42 | |
43 | class SubprocessFailure (Exception): |
44 | def __init__(me, file, rc): |
45 | me.args = (file, rc) |
46 | me.file = file |
47 | me.rc = rc |
48 | def __str__(me): |
49 | if WIFEXITED(me.rc): |
50 | return '%s failed (rc = %d)' % (me.file, WEXITSTATUS(me.rc)) |
51 | elif WIFSIGNALED(me.rc): |
52 | return '%s died (signal %d)' % (me.file, WTERMSIG(me.rc)) |
53 | else: |
54 | return '%s died inexplicably' % (me.file) |
55 | |
56 | chk = Extension('checkpath', |
57 | ['checkpath.c'], |
58 | include_dirs = uniquify(incdirs), |
59 | library_dirs = uniquify(libdirs), |
60 | libraries = uniquify(libs)) |
61 | setup(name = 'CheckPath', |
62 | version = '1.1.0', |
63 | description = 'Checking paths for security', |
64 | author = 'Straylight/Edgeware', |
65 | author_email = 'mdw@nsict.org', |
66 | license = 'GNU General Public License', |
67 | ext_modules = [chk]) |