-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsetup.py
134 lines (120 loc) · 3.94 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import shutil, os, sys, errno
from collections import namedtuple
from distutils.core import setup, Extension
from distutils.command.build_ext import build_ext as _build_ext
from distutils.command.install_headers import install_headers
from distutils.sysconfig import get_config_var, PREFIX
from shutil import copyfile
from tools import py_client
VERSION="1.3"
CFLAGS=["-Wall"]
XCB_PATHS = [
"/usr/share/xcb",
"/usr/local/share/xcb",
]
def find_xcb():
for i in XCB_PATHS:
if os.path.isdir(i):
return i
raise ValueError("Could not detect xcb protocol definition location...")
xmlfiles = [
"bigreq", "composite", "damage", "dpms", "glx",
"randr", "record", "render", "res", "screensaver",
"shape", "shm", "sync", "xc_misc", "xevie",
"xf86dri", "xfixes", "xinerama", "xprint", "xproto",
"xtest", "xvmc", "xv"
]
extensions = [
"conn", "constant", "cookie",
"except", "ext", "extkey", "list", "module",
"protobj", "void"
]
ext_modules = [
Extension(
"xcb.xcb",
sources = ["xcb/%s.c" % i for i in extensions],
libraries = ["xcb"],
extra_compile_args=CFLAGS
)
]
class build_ext(_build_ext):
def run(self):
for i in xmlfiles:
py_client.build(os.path.join(find_xcb(), "%s.xml"%i))
return _build_ext.run(self)
### XXX: The following is a hack. py2cairo looks for xpyb.pc when configuring.
### However (as near as I can find) there is no way to get it to install with
### distutils, so we fake it here.
# make xpyb.pc file
class PCOpt(object):
def __init__(self, replace_str, val):
self.replace_str = replace_str
self.val = val
def gen_pc():
# --root is provided when doing maintainer type things, so set the prefix
# to local in that case, or /usr/local when doing normal things.
rootarg = filter(lambda a: a.startswith('--root'), sys.argv)
try:
rootarg = rootarg[0].split('=')[1]
except IndexError:
rootarg = ''
if rootarg:
prefix = '/usr'
else:
prefix = '/usr/local'
pc_opts = {
'--prefix': PCOpt('@prefix@', prefix),
'--exec-prefix': PCOpt('@exec_prefix@', '${prefix}'),
'--install-lib': PCOpt('@libdir@', '${exec_prefix}/lib'),
'--install-headers': PCOpt('@includedir@', '${prefix}/include/python2.7/xpyb'),
# please don't actually use this :-)
'--dont-set-the-xcb-version': PCOpt('@PACKAGE_VERSION@', VERSION),
}
def override_arg(arg):
for (k, v) in pc_opts.items():
if arg.startswith(k):
try:
v.val = arg.split('=')[1]
except IndexError:
pass
for arg in sys.argv:
override_arg(arg)
with open('xpyb.pc.in') as in_:
pc = in_.read()
with open('xpyb.pc', 'w') as out:
for opt in pc_opts.values():
pc = pc.replace(opt.replace_str, opt.val)
out.write(pc)
# if we're not installing, don't install the .pc
if 'install' not in sys.argv:
return
def resolve(path):
""" Resolve a path through pkgconfig variables. """
for opt in pc_opts.values():
name = '${' + opt.replace_str[1:-1] + '}' # strip off @s
if name in path:
path = path.replace(name, opt.val)
path = resolve(path)
return path
# XXX: moar haxxx: here we strip off the leading slash to keep join() happy
install_path = resolve(pc_opts['--install-lib'].val).strip('/')
pkgconfig = os.path.join(rootarg, install_path, 'pkgconfig')
try:
os.makedirs(pkgconfig)
except OSError as e:
if e.errno == errno.EEXIST:
pass
else:
raise
copyfile('xpyb.pc', os.path.join(pkgconfig, 'xpyb.pc'))
setup(
name = 'xpyb',
version = VERSION,
ext_modules = ext_modules,
packages = ["xcb"],
cmdclass = {
"build_ext": build_ext
},
headers=['xcb/xpyb.h'],
)
gen_pc()