-
Notifications
You must be signed in to change notification settings - Fork 159
/
wscript
248 lines (186 loc) · 6.03 KB
/
wscript
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/usr/bin/env python
import time
import sys
import os
top = "."
out = "build"
# change this stuff
APPNAME = "libmonome"
VERSION = "1.4.8"
#
# dep checking functions
#
def check_poll(conf):
# borrowed from glib's poll test
code = """
#include <stdlib.h>
#include <poll.h>
int main(int argc, char **argv) {
struct pollfd fds[1];
fds[0].fd = open("/dev/null", 1);
fds[0].events = POLLIN;
if( poll(fds, 1, 0) < 0 || fds[0].revents & POLLNVAL )
exit(1);
exit(0);
}"""
conf.check_cc(
define_name="HAVE_WORKING_POLL",
mandatory=False,
quote=0,
execute=True,
fragment=code,
msg="Checking for working poll()",
errmsg="no (will use select())")
def check_udev(conf):
conf.check_cc(
define_name="HAVE_LIBUDEV",
mandatory=False,
quote=0,
execute=True,
lib="udev",
uselib_store="UDEV",
msg="Checking for libudev",
errmsg="no (will use sysfs)")
def check_liblo(conf):
conf.check_cc(
define_name="HAVE_LO",
mandatory=True,
quote=0,
execute=True,
lib="lo",
uselib_store="LO",
msg="Checking for liblo")
#
# waf stuff
#
def override_find_program(prefix):
from waflib.Configure import find_program as orig_find
from waflib.Configure import conf
if prefix[-1] != '-':
prefix += '-'
@conf
def find_program(self, filename, **kw):
if type(filename) == str:
return orig_find(self, prefix + filename, **kw)
else:
return orig_find(self, [prefix + x for x in filename], **kw)
return orig_find(self, filename, **kw)
def options(opt):
opt.load("compiler_c")
opt.load("cython", tooldir='.waf')
xcomp_opts = opt.add_option_group('cross-compilation')
xcomp_opts.add_option('--host', action='store', default=False)
lm_opts = opt.add_option_group("libmonome options")
lm_opts.add_option("--disable-osc", action="store_true",
default=False, help="disable OSC/liblo support [enabled by default]")
lm_opts.add_option("--disable-udev", action="store_true",
default=False, help="disable udev support [enabled by default]")
lm_opts.add_option("--enable-python", action="store_true",
default=False, help="enable python bindings [disabled by default]")
lm_opts.add_option("--python",
default=None, help="python to build against")
lm_opts.add_option("--pythondir",
default=None, help="python to build against")
lm_opts.add_option("--pythonarchdir",
default=None, help="python to build against")
lm_opts.add_option("--enable-multilib", action="store_true",
default=False, help="on Darwin, build libmonome as a combination 32 and 64 bit library [disabled by default]")
lm_opts.add_option('--enable-debug', action='store_true',
default=False, help="Build debuggable binaries")
lm_opts.add_option('--enable-embedded-protos', action='store_true',
default=False, help="Embed protos in the library")
lm_opts.add_option('--enable-mac-bundle', action='store_true',
default=False, help="look for protocol libraries in a Mac bundle's Frameworks directory")
lm_opts.add_option('--mac-version-min', type=str,
default=False, help="specify minimum macOS ABI version [optional]")
def configure(conf):
# just for output prettifying
# print() (as a function) ddoesn't work on python <2.7
separator = lambda: sys.stdout.write("\n")
if conf.options.host:
override_find_program(conf.options.host)
separator()
conf.load("compiler_c")
conf.load("gnu_dirs")
if conf.check_endianness() == "big":
conf.define("LM_BIG_ENDIAN", 1)
#
# conf checks
#
separator()
if conf.env.DEST_OS == "win32":
conf.env.append_unique('LINKFLAGS', ['-static', '-static-libgcc'])
conf.env.append_unique('LIB', ['setupapi'])
else:
check_poll(conf)
conf.check_cc(lib='dl', uselib_store='DL', mandatory=True)
if conf.env.DEST_OS == "linux" and not conf.options.disable_udev:
check_udev(conf)
if not conf.options.disable_osc:
check_liblo(conf)
separator()
if conf.options.enable_python:
conf.load("python")
conf.check_python_version(minver=(2,7,0))
conf.check_python_headers()
conf.load("cython")
separator()
#
# setting defines, etc
#
conf.env.append_unique("CFLAGS", [
"-std=c99", "-Wall", "-Werror",
"-Wno-initializer-overrides"])
if conf.options.enable_multilib:
conf.env.ARCH = ["i386", "x86_64"]
if conf.options.enable_debug:
conf.env.append_unique('CFLAGS', "-g")
conf.env.append_unique('LINKFLAGS', "-g")
if conf.env.DEST_OS == "darwin" and conf.options.mac_version_min:
abi_version = "-mmacosx-version-min=" + conf.options.mac_version_min
conf.env.append_unique("CFLAGS", [abi_version])
conf.env.append_unique("LINKFLAGS", [abi_version])
if os.path.basename(conf.env.CC[0]) == "clang":
conf.env.append_unique("CFLAGS", ["-Wno-initializer-overrides"])
conf.env.PROTOCOLS = ["40h", "series", "mext"]
if conf.env.LIB_LO:
conf.env.PROTOCOLS.append("osc")
conf.define("BUILD_OSC_PROTO", 1)
if conf.options.libdir:
conf.env.LIBDIR = conf.options.libdir
if conf.options.enable_mac_bundle:
conf.env.LD_LIBDIR = '@executable_path/../Frameworks'
conf.env.ENABLE_MAC_BUNDLE = True
else:
conf.env.LD_LIBDIR = conf.env.LIBDIR
conf.define('LIBDIR', conf.env.LD_LIBDIR)
conf.define("LIBSUFFIX", "." + conf.env.cshlib_PATTERN.rsplit(".", 1)[-1])
if conf.options.enable_embedded_protos:
conf.define("EMBED_PROTOS", 1)
conf.env.EMBED_PROTOS = conf.options.enable_embedded_protos
conf.env.VERSION = VERSION
conf.define("VERSION", VERSION)
def build(bld):
bld.install_files("${PREFIX}/include", ["public/monome.h"])
bld.recurse("src")
bld.recurse("utils")
# win32 doesn't have nanosleep()
if bld.env.DEST_OS != "win32":
bld.recurse("examples")
# man page
bld(
source="doc/monomeserial.in.1",
target="doc/monomeserial.1",
install_path="${PREFIX}/share/man/man1",
features="subst",
MDOCDATE=time.strftime("%B %d, %Y"))
if bld.env.CYTHON:
bld.recurse("bindings/python")
def dist(dst):
pats = [".git*", "**/.git*", ".travis.yml"]
with open(".gitignore") as gitignore:
for l in gitignore.readlines():
if l[0] == "#":
continue
pats.append(l.rstrip("\n"))
dst.excl = " ".join(pats)