-
Notifications
You must be signed in to change notification settings - Fork 0
/
wscript
236 lines (189 loc) · 8.04 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
#! /usr/bin/env python
# encoding: utf-8
from __future__ import with_statement
parallel_debug = False
APPNAME='cdbus'
VERSION='1.0'
# these variables are mandatory ('/' are converted automatically)
top = '.'
out = 'build'
import os, re, shutil
from waflib import Options, Logs
from waflib import Context
def display_msg(conf, msg="", status = None, color = None):
if status:
conf.msg(msg, status, color)
else:
Logs.pprint('NORMAL', msg)
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 yesno(bool):
if bool:
return "yes"
else:
return "no"
def options(opt):
opt.load('compiler_c')
opt.add_option('--debug', action='store_true', default=False, dest='debug', help="Build debuggable binaries")
# opt.add_option('--distnodeps', action='store_true', default=False, help="When creating distribution tarball, don't package git submodules")
# opt.add_option('--distname', type='string', default=None, help="Name for the distribution tarball")
# opt.add_option('--distsuffix', type='string', default="", help="String to append to the distribution tarball name")
# opt.add_option('--tagdist', action='store_true', default=False, help='Create of git tag for distname')
opt.add_option('--libdir', type='string', default=None, help='Define lib dir')
opt.add_option('--docdir', type='string', default=None, help="Define doc dir [default: PREFIX'/share/doc/" + APPNAME + ']')
if parallel_debug:
opt.load('parallel_debug')
def add_cflag(conf, flag):
conf.env.prepend_value('CFLAGS', flag)
def add_linkflag(conf, flag):
conf.env.prepend_value('LINKFLAGS', flag)
def check_gcc_optimizations_enabled(flags):
gcc_optimizations_enabled = False
for flag in flags:
if len(flag) < 2 or flag[0] != '-' or flag[1] != 'O':
continue
if len(flag) == 2:
gcc_optimizations_enabled = True;
else:
gcc_optimizations_enabled = flag[2] != '0';
return gcc_optimizations_enabled
def configure(conf):
conf.load('compiler_c')
if parallel_debug:
conf.load('parallel_debug')
conf.check_cfg(
package = 'dbus-1',
atleast_version = '1.0.0',
mandatory = True,
errmsg = "not installed, see http://dbus.freedesktop.org/",
args = '--cflags --libs')
if Options.options.libdir:
conf.env['LIBDIR'] = Options.options.libdir
else:
conf.env['LIBDIR'] = os.path.join(os.path.normpath(conf.env['PREFIX']), 'lib')
if Options.options.docdir:
conf.env['DOCDIR'] = Options.options.docdir
else:
conf.env['DOCDIR'] = os.path.join(os.path.normpath(conf.env['PREFIX']), 'share', 'doc', APPNAME)
#conf.env['BUILD_DOXYGEN_DOCS'] = Options.options.doxygen
add_cflag(conf, '-fvisibility=hidden')
conf.env['BUILD_WERROR'] = Options.options.debug
add_cflag(conf, '-Wall')
add_cflag(conf, '-Wextra')
#conf.env.append_unique('CXXFLAGS', '-Wno-unused-parameter') # the UNUSED() macro doesnt work for C++
#add_cflag(conf, '-Wimplicit-fallthrough=2')
if conf.env['BUILD_WERROR']:
add_cflag(conf, '-Werror')
conf.env['BUILD_DEBUG'] = Options.options.debug
if conf.env['BUILD_DEBUG']:
add_cflag(conf, '-g')
add_cflag(conf, '-O0')
add_linkflag(conf, '-g')
else:
add_cflag(conf, '-O1')
conf.env['DATA_DIR'] = os.path.normpath(os.path.join(conf.env['PREFIX'], 'share', APPNAME))
conf.env['LOCALE_DIR'] = os.path.normpath(os.path.join(conf.env['PREFIX'], 'share', 'locale'))
# write some parts of the configure environment to the config.h file
conf.define('DATA_DIR', conf.env['DATA_DIR'])
conf.define('LOCALE_DIR', conf.env['LOCALE_DIR'])
conf.define('PACKAGE_VERSION', VERSION)
conf.define('_GNU_SOURCE', 1)
conf.write_config_header('config.h')
display_msg(conf)
display_msg(conf, "==================")
version_msg = APPNAME + "-" + VERSION
if os.access('version.h', os.R_OK):
data = open('version.h').read()
m = re.match(r'^#define CDBUS_GIT_VERSION "([^"]*)"$', data)
if m != None:
version_msg += " exported from " + m.group(1)
elif os.access('.git', os.R_OK):
version_msg += " git revision will checked and eventually updated during build"
display_msg(conf, version_msg)
display_msg(conf)
display_msg(conf, "Install prefix", conf.env['PREFIX'], 'CYAN')
#display_msg(conf, 'Treat warnings as errors', yesno(conf.env['BUILD_WERROR']))
display_msg(conf, 'Debuggable binaries', yesno(conf.env['BUILD_DEBUG']))
#display_msg(conf, 'Build doxygen documentation', yesno(conf.env['BUILD_DOXYGEN_DOCS']))
display_msg(conf, 'C compiler flags', repr(conf.env['CFLAGS']))
display_msg(conf)
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 CDBUS_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')
fi.write('#define CDBUS_GIT_VERSION "%s"\n' % self.ver)
fi.close()
def build(bld):
if not bld.env['DATA_DIR']:
raise "DATA_DIR is emtpy"
bld(rule=git_ver, target='version.h', update_outputs=True, always=True, ext_out=['.h'])
libcdbus = bld.shlib(source = [], features = 'c cshlib', includes = [bld.path.get_bld(), "./include/cdbus-1"])
libcdbus.uselib = 'DBUS-1'
libcdbus.target = 'cdbus'
libcdbus.vnum = "1.0.0"
libcdbus.defines = ['LOG_OUTPUT_STDOUT']
libcdbus.source = [
'src/signal.c',
'src/method.c',
'src/object_path.c',
'src/interface.c',
'src/helpers.c',
'src/log.c',
]
bld.install_files('${PREFIX}/include/cdbus-1/cdbus', [
'version.h',
'include/cdbus-1/cdbus/signal.h',
'include/cdbus-1/cdbus/method.h',
'include/cdbus-1/cdbus/object_path.h',
'include/cdbus-1/cdbus/interface.h',
'include/cdbus-1/cdbus/cdbus.h',
'include/cdbus-1/cdbus/log.h',
])
# process cdbus-1.pc.in -> cdbus-1.pc
bld(
features = 'subst', # the feature 'subst' overrides the source/target processing
source = 'cdbus-1.pc.in', # list of string or nodes
target = 'cdbus-1.pc', # list of strings or nodes
install_path = '${LIBDIR}/pkgconfig/',
# variables to use in the substitution
prefix = bld.env['PREFIX'],
libdir = bld.env['LIBDIR'],
includedir = os.path.normpath(bld.env['PREFIX'] + '/include'))
bld.install_files('${DOCDIR}', [
"NEWS.adoc",
"README.adoc",
"doc/gpl2.txt",
"AUTHORS",
])
# if bld.env['BUILD_DOXYGEN_DOCS'] == True:
# html_docs_source_dir = "build/default/html"
# if bld.cmd == 'clean':
# if os.access(html_docs_source_dir, os.R_OK):
# Logs.pprint('CYAN', "Removing doxygen generated documentation...")
# shutil.rmtree(html_docs_source_dir)
# Logs.pprint('CYAN', "Removing doxygen generated documentation done.")
# elif bld.cmd == 'build':
# if not os.access(html_docs_source_dir, os.R_OK):
# os.popen("doxygen").read()
# else:
# Logs.pprint('CYAN', "doxygen documentation already built.")