2008-04-10 10:38:50 -06:00
|
|
|
|
# -*- python -*-
|
2012-12-18 21:46:13 -07:00
|
|
|
|
|
|
|
|
|
import os
|
2011-02-17 11:42:22 -07:00
|
|
|
|
import subprocess
|
2011-03-10 00:32:04 -07:00
|
|
|
|
import string
|
2011-02-17 20:17:56 -07:00
|
|
|
|
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.
|
|
|
|
|
"""
|
2011-03-10 00:32:04 -07:00
|
|
|
|
xml = subprocess.Popen(["dbus-binding-tool",
|
|
|
|
|
"--mode=glib-server",
|
|
|
|
|
"--prefix=" + env['DBUS_PREFIX'], source[0].get_path()],
|
2011-02-17 20:17:56 -07:00
|
|
|
|
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)
|
2011-02-17 11:42:22 -07:00
|
|
|
|
|
2011-02-17 20:17:56 -07:00
|
|
|
|
with open(target[0].get_path(), "w") as f:
|
|
|
|
|
f.write(xml)
|
|
|
|
|
|
2011-03-10 00:32:04 -07:00
|
|
|
|
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")
|
|
|
|
|
|
|
|
|
|
|
2012-12-18 21:46:13 -07:00
|
|
|
|
env = Environment(ENV=os.environ, BUILDERS = {
|
2011-03-10 00:32:04 -07:00
|
|
|
|
'DBusGlue' : Builder(action = build_dbus_glue),
|
|
|
|
|
'Bin2H' : Builder(action = build_bin2h)
|
|
|
|
|
})
|
2011-01-21 19:11:10 -07:00
|
|
|
|
|
|
|
|
|
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')
|
2015-05-04 16:03:26 -06:00
|
|
|
|
opts.Add('AR', 'Library archiver')
|
2011-01-21 19:11:10 -07:00
|
|
|
|
opts.Add('CC', 'C Compiler')
|
|
|
|
|
opts.Add('CXX', 'C++ Compiler')
|
2011-01-22 04:16:42 -07:00
|
|
|
|
opts.Add('BUILD', 'Build type: release, custom, development')
|
2015-05-04 17:13:19 -06:00
|
|
|
|
opts.Add('PKG_CONFIG', 'pkg-config helper tool', 'pkg-config')
|
2011-01-21 19:11:10 -07:00
|
|
|
|
|
|
|
|
|
opts.Update(env)
|
|
|
|
|
Help(opts.GenerateHelpText(env))
|
|
|
|
|
|
|
|
|
|
env.Append(CPPPATH=["src/"])
|
|
|
|
|
|
|
|
|
|
if 'BUILD' in env and env['BUILD'] == 'development':
|
|
|
|
|
env.Append(CXXFLAGS = [ "-O3",
|
|
|
|
|
"-g3",
|
|
|
|
|
"-ansi",
|
|
|
|
|
"-pedantic",
|
|
|
|
|
"-Wall",
|
|
|
|
|
"-Wextra",
|
|
|
|
|
"-Werror",
|
|
|
|
|
"-Wnon-virtual-dtor",
|
|
|
|
|
"-Weffc++",
|
2011-05-25 16:53:17 -06:00
|
|
|
|
# "-Wunreachable-code",
|
2011-01-21 19:11:10 -07:00
|
|
|
|
# "-Wconversion",
|
|
|
|
|
"-Wold-style-cast",
|
|
|
|
|
"-Wshadow",
|
|
|
|
|
"-Wcast-qual",
|
|
|
|
|
"-Winit-self", # only works with >= -O1
|
|
|
|
|
"-Wno-unused-parameter"])
|
2011-01-22 04:16:42 -07:00
|
|
|
|
elif 'BUILD' in env and env['BUILD'] == 'custom':
|
|
|
|
|
pass
|
2010-04-30 17:34:34 -06:00
|
|
|
|
else:
|
2011-01-21 19:11:10 -07:00
|
|
|
|
env.Append(CPPFLAGS = ['-g', '-O3', '-Wall', '-ansi', '-pedantic'])
|
2010-05-26 10:56:05 -06:00
|
|
|
|
|
2015-05-04 17:13:19 -06:00
|
|
|
|
env.ParseConfig(env['PKG_CONFIG'] + " --cflags --libs dbus-glib-1 | sed 's/-I/-isystem/g'")
|
|
|
|
|
env.ParseConfig(env['PKG_CONFIG'] + " --cflags --libs glib-2.0 | sed 's/-I/-isystem/g'")
|
|
|
|
|
env.ParseConfig(env['PKG_CONFIG'] + " --cflags --libs gthread-2.0 | sed 's/-I/-isystem/g'")
|
|
|
|
|
env.ParseConfig(env['PKG_CONFIG'] + " --cflags --libs libusb-1.0 | sed 's/-I/-isystem/g'")
|
|
|
|
|
env.ParseConfig(env['PKG_CONFIG'] + " --cflags --libs libudev | sed 's/-I/-isystem/g'")
|
2011-01-13 12:54:58 -07:00
|
|
|
|
|
2010-05-26 10:56:05 -06:00
|
|
|
|
f = open("VERSION")
|
|
|
|
|
package_version = f.read()
|
|
|
|
|
f.close()
|
|
|
|
|
|
2011-01-21 19:11:10 -07:00
|
|
|
|
env.Append(CPPDEFINES = { 'PACKAGE_VERSION': "'\"%s\"'" % package_version })
|
2010-05-26 10:56:05 -06:00
|
|
|
|
|
2009-07-29 09:07:52 -06:00
|
|
|
|
conf = Configure(env)
|
|
|
|
|
|
2009-08-20 04:35:04 -06:00
|
|
|
|
if not conf.env['CXX']:
|
|
|
|
|
print "g++ must be installed!"
|
|
|
|
|
Exit(1)
|
|
|
|
|
|
2009-07-29 09:07:52 -06:00
|
|
|
|
# X11 checks
|
|
|
|
|
if not conf.CheckLibWithHeader('X11', 'X11/Xlib.h', 'C++'):
|
|
|
|
|
print 'libx11-dev must be installed!'
|
|
|
|
|
Exit(1)
|
2008-04-10 10:38:50 -06:00
|
|
|
|
|
2009-07-29 09:07:52 -06:00
|
|
|
|
env = conf.Finish()
|
2011-03-10 00:32:04 -07:00
|
|
|
|
|
|
|
|
|
env.Bin2H("src/xboxdrv_vfs.hpp", [
|
|
|
|
|
"examples/mouse.xboxdrv",
|
|
|
|
|
"examples/xpad-wireless.xboxdrv"
|
|
|
|
|
],
|
|
|
|
|
BIN2H_NAMESPACE="xboxdrv_vfs")
|
2011-02-17 20:17:56 -07:00
|
|
|
|
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")
|
|
|
|
|
|
2011-02-22 17:24:02 -07:00
|
|
|
|
libxboxdrv = env.StaticLibrary('xboxdrv',
|
|
|
|
|
Glob('src/*.cpp') +
|
|
|
|
|
Glob('src/axisfilter/*.cpp') +
|
|
|
|
|
Glob('src/buttonfilter/*.cpp') +
|
2011-04-12 04:16:21 -06:00
|
|
|
|
Glob('src/axisevent/*.cpp') +
|
|
|
|
|
Glob('src/buttonevent/*.cpp') +
|
2011-02-22 17:24:02 -07:00
|
|
|
|
Glob('src/modifier/*.cpp'))
|
2011-07-24 10:06:50 -06:00
|
|
|
|
env.Prepend(LIBS = libxboxdrv)
|
2011-02-22 17:24:02 -07:00
|
|
|
|
|
|
|
|
|
for file in Glob('test/*_test.cpp', strings=True):
|
2011-07-11 17:08:27 -06:00
|
|
|
|
Alias('tests', env.Program(file[:-4], file))
|
|
|
|
|
|
|
|
|
|
Default(env.Program('xboxdrv', Glob('src/main/main.cpp')))
|
2008-12-26 21:13:00 -07:00
|
|
|
|
|
2008-04-10 10:38:50 -06:00
|
|
|
|
# EOF #
|