-
Notifications
You must be signed in to change notification settings - Fork 0
/
wscript
296 lines (254 loc) · 9.78 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#! /usr/bin/env python
# encoding: utf-8
#
# wscript for building and installing catroof
from __future__ import print_function
import os
import subprocess
import shutil
import re
import time
from waflib import Logs, Options, TaskGen, Context, Utils
from waftoolchainflags import WafToolchainFlags
APPNAME='catroof'
VERSION='0-dev'
# these variables are mandatory ('/' are converted automatically)
srcdir = '.'
blddir = 'build'
def git_ver(self):
bld = self.generator.bld
header = self.outputs[0].abspath()
if os.access('./version.h', os.R_OK):
header = os.path.join(os.getcwd(), out, "version.h")
shutil.copy('./version.h', header)
data = open(header).read()
m = re.match(r'^#define GIT_VERSION "([^"]*)"$', data)
if m != None:
self.ver = m.group(1)
Logs.pprint('BLUE', "tarball from git revision " + self.ver)
else:
self.ver = "tarball"
return
if bld.srcnode.find_node('.git'):
self.ver = bld.cmd_and_log("LANG= git rev-parse HEAD", quiet=Context.BOTH).splitlines()[0]
if bld.cmd_and_log("LANG= git diff-index --name-only HEAD", quiet=Context.BOTH).splitlines():
self.ver += "-dirty"
Logs.pprint('BLUE', "git revision " + self.ver)
else:
self.ver = "unknown"
fi = open(header, 'w')
if self.ver != "unknown":
fi.write('#define GIT_VERSION "%s"\n' % self.ver)
fi.close()
def display_msg(conf, msg="", status = None, color = None):
if status is None:
Logs.pprint('NORMAL', msg)
return
if isinstance(status,bool):
if status:
status = "yes"
if not color:
color = 'GREEN'
else:
status = "no"
if not color:
color = 'YELLOW'
elif not isinstance(status,str):
status = repr(status)
conf.msg(msg, status, color=color)
#Logs.pprint(msg, status, color)
def display_raw_text(conf, text, color = 'NORMAL'):
Logs.pprint(color, text, sep = '')
def display_line(conf, text, color = 'NORMAL'):
Logs.pprint(color, text, sep = os.linesep)
def options(opt):
# options provided by the modules
opt.load('compiler_c')
opt.load('wafautooptions')
build_catroof_opt = opt.add_auto_option(
'catroof',
help='Enable catroof',
conf_dest='BUILD_CATROOF',
style="yesno_and_hack",
)
build_catroof_opt.check_cfg(
package = 'dbus-1',
atleast_version = '1.0.0',
errmsg = "not installed, see http://dbus.freedesktop.org/",
args = '--cflags --libs')
build_catroof_opt.check_cfg(
package = 'cdbus-1',
atleast_version = '1.0.0',
errmsg = "not installed, see https://github.com/LADI/cdbus",
args = '--cflags --libs')
opt.add_auto_option(
'devmode',
help='Enable devmode', # enable warnings and treat them as errors
conf_dest='BUILD_DEVMODE',
default=False,
)
opt.add_auto_option(
'debug',
help='Enable debug symbols',
conf_dest='BUILD_DEBUG',
default=False,
)
opt.add_option('--mandir', type='string', help="Manpage directory [Default: <prefix>/share/man]")
opt.add_option('--enable-pkg-config-dbus-service-dir', action='store_true', default=False, help='force D-Bus service install dir to be one returned by pkg-config')
def configure(conf):
conf.load('compiler_c')
conf.load('wafautooptions')
flags = WafToolchainFlags(conf)
conf.check_cfg(
package = 'alsa',
mandatory = True,
errmsg = "not installed, see http://www.alsa-project.org/",
args = '--cflags --libs')
if conf.env["BUILD_CATROOF"]:
dbus_dir = conf.check_cfg(
package='dbus-1',
args='--variable=session_bus_services_dir',
msg="Retrieving D-Bus services dir")
if not dbus_dir:
return
dbus_dir = dbus_dir.strip()
conf.env['DBUS_SERVICES_DIR_REAL'] = dbus_dir
if Options.options.enable_pkg_config_dbus_service_dir:
conf.env['DBUS_SERVICES_DIR'] = dbus_dir
else:
conf.env['DBUS_SERVICES_DIR'] = os.path.join(
os.path.normpath(conf.env['PREFIX']),
'share',
'dbus-1',
'services')
if Options.options.mandir:
conf.env['MANDIR'] = Options.options.mandir
else:
conf.env['MANDIR'] = conf.env['PREFIX'] + '/share/man'
conf.define('CATROOF_VERSION', VERSION)
conf.define('HAVE_GITVERSION_H', 1)
conf.define('BUILD_TIMESTAMP', time.ctime())
conf.write_config_header('config.h')
flags.add_c('-std=gnu99')
if conf.env['BUILD_DEVMODE']:
flags.add_c(['-Wall', '-Wextra'])
#flags.add_c('-Wpedantic')
flags.add_c('-Werror')
flags.add_c(['-Wno-variadic-macros', '-Wno-gnu-zero-variadic-macro-arguments'])
# https://wiki.gentoo.org/wiki/Modern_C_porting
if conf.env['CC'] == 'clang':
flags.add_c('-Wno-unknown-argumemt')
flags.add_c('-Werror=implicit-function-declaration')
flags.add_c('-Werror=incompatible-function-pointer-types')
flags.add_c('-Werror=deprecated-non-prototype')
flags.add_c('-Werror=strict-prototypes')
if int(conf.env['CC_VERSION'][0]) < 16:
flags.add_c('-Werror=implicit-int')
else:
flags.add_c('-Wno-unknown-warning-option')
flags.add_c('-Werror=implicit-function-declaration')
flags.add_c('-Werror=implicit-int')
flags.add_c('-Werror=incompatible-pointer-types')
flags.add_c('-Werror=strict-prototypes')
if conf.env['BUILD_DEBUG']:
flags.add_c(['-O0', '-g', '-fno-omit-frame-pointer'])
flags.add_link('-g')
flags.flush()
gitrev = None
if os.access('gitversion.h', os.R_OK):
data = file('gitversion.h').read()
m = re.match(r'^#define GIT_VERSION "([^"]*)"$', data)
if m != None:
gitrev = m.group(1)
print()
display_msg(conf, "==================")
version_msg = "catroof-" + VERSION
if gitrev:
version_msg += " exported from " + gitrev
else:
version_msg += " git revision will checked and eventually updated during build"
print(version_msg)
print()
display_msg(conf, "Install prefix", conf.env['PREFIX'], 'CYAN')
display_msg(conf, "Compiler", conf.env['CC'][0], 'CYAN')
display_msg(conf, "Enable lscatroof", True)
#display_msg(conf, "Enable libcatroof", conf.env["BUILD_CATROOF"])
#display_msg(conf, "Enable catroof", conf.env["BUILD_CATROOF"])
#display_msg(conf, "Enable gcatroof", conf.env["BUILD_CATROOF"])
#display_msg(conf, "Enable ncatroof", conf.env["BUILD_CATROOF"])
#display_msg(conf, "Enable catroofd", conf.env["BUILD_CATROOF"])
conf.summarize_auto_options()
if conf.env['HAVE_DBUS_1']:
if conf.env['DBUS_SERVICES_DIR'] != conf.env['DBUS_SERVICES_DIR_REAL']:
display_msg(conf)
display_line(conf, "WARNING: D-Bus session services directory as reported by pkg-config is", 'RED')
display_raw_text(conf, "WARNING:", 'RED')
display_line(conf, conf.env['DBUS_SERVICES_DIR_REAL'], 'CYAN')
display_line(conf, 'WARNING: but service file will be installed in', 'RED')
display_raw_text(conf, "WARNING:", 'RED')
display_line(conf, conf.env['DBUS_SERVICES_DIR'], 'CYAN')
display_line(conf, 'WARNING: You may need to adjust your D-Bus configuration after installing catroof', 'RED')
display_line(conf, 'WARNING: You can override dbus service install directory', 'RED')
display_line(conf, 'WARNING: with --enable-pkg-config-dbus-service-dir option to this script', 'RED')
flags.display()
print()
def build(bld):
bin_dir = bld.env['BINDIR']
# bld.options.destdir +
share_dir = bld.env['PREFIX'] + '/share/' + APPNAME
#print(bin_dir)
#print(share_dir)
bld(rule=git_ver,
target='gitversion.h',
update_outputs=True,
always=True,
ext_out=['.h'])
# config.h, gitverson.h include path; public headers include path
includes = [bld.path.get_bld(), "../include"]
prog = bld(features=['c', 'cprogram'])
prog.source = [
'src/alsa.c',
'src/catdup.c',
'src/log.c',
'src/file.c',
'src/sysfs_devices.c',
'src/lscatroof.c',
]
prog.includes = includes
prog.target = 'lscatroof'
prog.use = ['ALSA', 'CDBUS-1']
prog.defines = ["HAVE_CONFIG_H"]
if bld.env["BUILD_CATROOF"]:
shlib = bld(features=['c', 'cshlib'])
shlib.includes = includes
shlib.target = 'catroof'
shlib.env.cshlib_PATTERN = '%s.so'
shlib.install_path = bld.env['LUA_INSTALL_CMOD']
shlib.uselib = ['ALSA', 'LUA', 'CDBUS-1']
shlib.source = [
'src/alsa.c',
'src/catdup.c',
'src/log.c',
]
bld.install_as(bin_dir + "/" + "catroof", 'src/catroof.lua', chmod=Utils.O755)
bld.symlink_as(bin_dir + "/" + "ncatroof", 'catroof')
bld.symlink_as(bin_dir + "/" + "gcatroof", 'catroof')
bld.install_as(share_dir + "/" + "catroof.ui", 'src/catroof.ui')
# prog = bld(features=['c', 'cprogram'])
# prog.source = [
# 'src/alsa.c',
# 'src/log.c',
# 'src/catdup.c',
# 'src/catroofd.c',
# ]
# prog.includes = includes
# prog.target = 'catroofd'
# prog.use = ['ALSA', 'CDBUS-1']
# prog.defines = ["HAVE_CONFIG_H"]
# install man pages
man_pages = [
#TODO: "catroof.1",
]
for i in range(len(man_pages)):
man_pages[i] = "man/" + man_pages[i]
bld.install_files(os.path.join(bld.env['MANDIR'], 'man1'), man_pages)