forked from xboxdrv/xboxdrv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
198 lines (163 loc) · 7.12 KB
/
SConstruct
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# -*- python -*-
import os
import subprocess
import string
import re
def build_dbus_glue(target, source, env):
"""
C++ doesn't allow casting from void* to a function pointer,
thus we have to change the code to use a union to do the
conversion.
"""
xml = subprocess.Popen(["dbus-binding-tool",
"--mode=glib-server",
"--prefix=" + env['DBUS_PREFIX'], source[0].get_path()],
stdout=subprocess.PIPE).communicate()[0]
xml = re.sub(r"callback = \(([A-Za-z_]+)\) \(marshal_data \? marshal_data : cc->callback\);",
r"union { \1 fn; void* obj; } conv;\n "
"conv.obj = (marshal_data ? marshal_data : cc->callback);\n "
"callback = conv.fn;", xml)
with open(target[0].get_path(), "w") as f:
f.write(xml)
def build_bin2h(target, source, env):
"""
Takes a list of files and converts them into a C source that can be included
"""
def c_escape(str):
return str.translate(string.maketrans("/.-", "___"))
print target
print source
with open(target[0].get_path(), "w") as fout:
fout.write("// autogenerated by scons Bin2H builder, do not edit by hand!\n\n")
if env.has_key("BIN2H_NAMESPACE"):
fout.write("namespace %s {\n\n" % env["BIN2H_NAMESPACE"])
# write down data
for src in source:
with open(src.get_path(), "rb") as fin:
data = fin.read()
fout.write("// \"%s\"\n" % src.get_path())
fout.write("const char %s[] = {" % c_escape(src.get_path()))
bytes_arr = ["0x%02x" % ord(c) for c in data]
for i in xrange(len(bytes_arr)):
if i % 13 == 0:
fout.write("\n ")
fout.write(bytes_arr[i])
if i != len(bytes_arr)-1:
fout.write(", ")
fout.write("\n};\n\n")
# write down file table
if False:
fout.write("const char** file_table = {\n")
fout.write(string.join([" %-35s %-s" % ("\"%s\"," % src.get_path(),
c_escape(src.get_path()))
for src in source], ",\n"))
fout.write("\n}\n\n")
if env.has_key("BIN2H_NAMESPACE"):
fout.write("} // namespace %s\n\n" % env["BIN2H_NAMESPACE"])
fout.write("/* EOF */\n")
def CheckPKGConfig(context, name):
context.Message( 'Checking for %s... ' % name )
ret = context.TryAction('pkg-config --exists \'%s\'' % name)[0]
context.Result( ret )
return ret
env = Environment(
ENV = os.environ,
CPPPATH = ["src/"],
BUILDERS = {
'DBusGlue' : Builder(action = build_dbus_glue),
'Bin2H' : Builder(action = build_bin2h)
},
)
# Begin: Option handling
opts = Variables(['custom.py'], ARGUMENTS)
opts.Add('CPPPATH', 'Additional preprocessor paths')
opts.Add('CPPFLAGS', 'Additional preprocessor flags')
opts.Add('CPPDEFINES', 'defined constants')
opts.Add('LIBPATH', 'Additional library paths')
opts.Add('LIBS', 'Additional libraries')
opts.Add('CCFLAGS', 'C Compiler flags')
opts.Add('CXXFLAGS', 'C++ Compiler flags')
opts.Add('LINKFLAGS', 'Linker Compiler flags')
opts.Add('CC', 'C Compiler')
opts.Add('CXX', 'C++ Compiler')
opts.Add('BUILD', 'Build type: release, custom, development')
opts.Update(env)
Help(opts.GenerateHelpText(env))
# End: Option handling
if 'BUILD' in env and env['BUILD'] == 'development':
env.Append(CXXFLAGS = [ "-O0",
"-g3",
# "-ansi", # disabled due to GNU extension being used in bluetooth.h
"-pedantic",
"-Wall",
"-Wextra",
"-Werror",
"-Wnon-virtual-dtor",
"-Weffc++",
# "-Wunreachable-code",
"-Wconversion",
"-Wold-style-cast",
"-Wshadow",
"-Wcast-qual",
"-Winit-self", # only works with >= -O1
"-Wno-unused-parameter"])
elif 'BUILD' in env and env['BUILD'] == 'custom':
pass
else:
# -ansi removed for now, see above
env.Append(CPPFLAGS = ['-g', '-O3', '-Wall', '-pedantic'])
env.ParseConfig("pkg-config --cflags --libs dbus-glib-1 | sed 's/-I/-isystem/g'")
env.ParseConfig("pkg-config --cflags --libs glib-2.0 | sed 's/-I/-isystem/g'")
env.ParseConfig("pkg-config --cflags --libs gthread-2.0 | sed 's/-I/-isystem/g'")
env.ParseConfig("pkg-config --cflags --libs libusb-1.0 | sed 's/-I/-isystem/g'")
env.ParseConfig("pkg-config --cflags --libs libudev | sed 's/-I/-isystem/g'")
with open("VERSION", "r") as fin:
package_version = fin.readline().strip()
env.Append(CPPDEFINES = { 'PACKAGE_VERSION': "'\"%s\"'" % package_version })
conf = Configure(env,
custom_tests = { 'CheckPKG' : CheckPKGConfig })
if not conf.env['CXX']:
print "g++ must be installed!"
Exit(1)
# X11 checks
if not conf.CheckLibWithHeader('X11', 'X11/Xlib.h', 'C++'):
print 'libx11-dev must be installed!'
Exit(1)
if conf.CheckPKG('cwiid'):
conf.env.ParseConfig("pkg-config --cflags --libs cwiid | sed 's/-I/-isystem/g'")
conf.env.Append(CPPDEFINES = 'HAVE_CWIID')
env = conf.Finish()
gtk_env = env.Clone()
conf = Configure(gtk_env,
custom_tests = { 'CheckPKG' : CheckPKGConfig })
if conf.CheckPKG('gtk+-2.0'):
gtk_env.ParseConfig("pkg-config --libs --cflags gtk+-2.0")
gtk_env['BUILD_VIRTUALKEYBOARD'] = True
else:
gtk_env['BUILD_VIRTUALKEYBOARD'] = False
print "gtk+-2.0 not found, virtualkeyboard will not be build"
gtk_env = conf.Finish()
env.Bin2H("src/xboxdrv_vfs.hpp", [
"examples/mouse.xboxdrv",
"examples/xpad-wireless.xboxdrv"
],
BIN2H_NAMESPACE="xboxdrv_vfs")
env.DBusGlue("src/xboxdrv_daemon_glue.hpp", "src/xboxdrv_daemon.xml", DBUS_PREFIX="xboxdrv_daemon")
env.DBusGlue("src/xboxdrv_controller_glue.hpp", "src/xboxdrv_controller.xml", DBUS_PREFIX="xboxdrv_controller")
libxboxdrv = env.StaticLibrary('xboxdrv',
Glob('src/*.cpp') +
Glob('src/axisevent/*.cpp') +
Glob('src/axisfilter/*.cpp') +
Glob('src/buttonevent/*.cpp') +
Glob('src/buttonfilter/*.cpp') +
Glob('src/controller/*.cpp') +
Glob('src/modifier/*.cpp') +
Glob('src/symbols/*.cpp'))
env.Prepend(LIBS = libxboxdrv)
gtk_env.Prepend(LIBS = libxboxdrv)
for file in Glob('test/*_test.cpp', strings=True):
Alias('tests', env.Program(file[:-4], file))
if gtk_env['BUILD_VIRTUALKEYBOARD']:
Default(gtk_env.Program("virtualkeyboard", Glob("src/virtualkeyboard/*.cpp")))
Default(env.Program('xboxdrv', Glob('src/main/main.cpp')))
# EOF #