waf: fix debuggable builds; disable werror for release builds (fixes #15)
[ladish.git] / wscript
blob89844a8b72d0e0ea2ff6addcae9914064f8232c0
1 #! /usr/bin/env python
2 # encoding: utf-8
4 import os
5 import Options
6 import Utils
7 import shutil
8 import re
10 APPNAME='ladish'
11 VERSION='0.2'
12 DBUS_NAME_BASE = 'org.ladish'
13 RELEASE = False
15 # these variables are mandatory ('/' are converted automatically)
16 srcdir = '.'
17 blddir = 'build'
19 def display_msg(conf, msg="", status = None, color = None):
20 if status:
21 conf.check_message_1(msg)
22 conf.check_message_2(status, color)
23 else:
24 Utils.pprint('NORMAL', msg)
26 def display_raw_text(conf, text, color = 'NORMAL'):
27 Utils.pprint(color, text, sep = '')
29 def display_line(conf, text, color = 'NORMAL'):
30 Utils.pprint(color, text, sep = os.linesep)
32 def yesno(bool):
33 if bool:
34 return "yes"
35 else:
36 return "no"
38 def set_options(opt):
39 opt.tool_options('compiler_cc')
40 opt.tool_options('compiler_cxx')
41 opt.tool_options('boost')
42 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')
43 opt.add_option('--enable-liblash', action='store_true', default=False, help='Build LASH compatibility library')
44 if RELEASE:
45 opt.add_option('--debug', action='store_true', default=False, dest='debug', help="Build debuggable binaries")
47 def add_cflag(conf, flag):
48 conf.env.append_unique('CXXFLAGS', flag)
49 conf.env.append_unique('CCFLAGS', flag)
51 def add_linkflag(conf, flag):
52 conf.env.append_unique('LINKFLAGS', flag)
54 def configure(conf):
55 conf.check_tool('compiler_cc')
56 conf.check_tool('compiler_cxx')
57 conf.check_tool('boost')
59 conf.check_cfg(
60 package = 'dbus-1',
61 atleast_version = '1.0.0',
62 mandatory = True,
63 errmsg = "not installed, see http://dbus.freedesktop.org/",
64 args = '--cflags --libs')
66 dbus_dir = conf.check_cfg(package='dbus-1', args='--variable=session_bus_services_dir', msg="Retrieving D-Bus services dir")
67 if not dbus_dir:
68 return
70 dbus_dir = dbus_dir.strip()
71 conf.env['DBUS_SERVICES_DIR_REAL'] = dbus_dir
73 if Options.options.enable_pkg_config_dbus_service_dir:
74 conf.env['DBUS_SERVICES_DIR'] = dbus_dir
75 else:
76 conf.env['DBUS_SERVICES_DIR'] = os.path.join(os.path.normpath(conf.env['PREFIX']), 'share', 'dbus-1', 'services')
78 conf.env['BUILD_LIBLASH'] = Options.options.enable_liblash
80 conf.check_cfg(
81 package = 'uuid',
82 mandatory = True,
83 errmsg = "not installed, see http://e2fsprogs.sourceforge.net/",
84 args = '--cflags --libs')
86 conf.check(
87 header_name='expat.h',
88 mandatory = True,
89 errmsg = "not installed, see http://expat.sourceforge.net/")
91 conf.env['LIB_EXPAT'] = ['expat']
93 build_gui = True
95 if build_gui and not conf.check_cfg(
96 package = 'glib-2.0',
97 mandatory = False,
98 errmsg = "not installed, see http://www.gtk.org/",
99 args = '--cflags --libs'):
100 build_gui = False
102 if build_gui and not conf.check_cfg(
103 package = 'dbus-glib-1',
104 mandatory = False,
105 errmsg = "not installed, see http://dbus.freedesktop.org/",
106 args = '--cflags --libs'):
107 build_gui = False
109 if build_gui and not conf.check_cfg(
110 package = 'gtk+-2.0',
111 mandatory = False,
112 errmsg = "not installed, see http://www.gtk.org/",
113 args = '--cflags --libs'):
114 build_gui = False
116 if build_gui and not conf.check_cfg(
117 package = 'libglade-2.0',
118 mandatory = False,
119 errmsg = "not installed, see http://ftp.gnome.org/pub/GNOME/sources/libglade/",
120 args = '--cflags --libs'):
121 build_gui = False
123 if build_gui and not conf.check_cfg(
124 package = 'flowcanvas',
125 mandatory = False,
126 atleast_version = '0.5.3',
127 errmsg = "not installed, see http://drobilla.net/software/flowcanvas/",
128 args = '--cflags --libs'):
129 build_gui = False
131 if build_gui:
132 # We need the boost headers package (e.g. libboost-dev)
133 # shared_ptr.hpp and weak_ptr.hpp
134 build_gui = conf.check_boost(errmsg="not found, see http://boost.org/")
136 conf.env['BUILD_GLADISH'] = build_gui
138 conf.env['BUILD_WERROR'] = not RELEASE
139 if conf.env['BUILD_WERROR']:
140 add_cflag(conf, '-Wall')
141 add_cflag(conf, '-Werror')
143 conf.env['BUILD_DEBUG'] = not RELEASE or Options.options.debug
144 if conf.env['BUILD_DEBUG']:
145 add_cflag(conf, '-g')
146 add_linkflag(conf, '-g')
148 conf.define('DATA_DIR', os.path.normpath(os.path.join(conf.env['PREFIX'], 'share', APPNAME)))
149 conf.define('PACKAGE_VERSION', VERSION)
150 conf.define('DBUS_NAME_BASE', DBUS_NAME_BASE)
151 conf.define('DBUS_BASE_PATH', '/' + DBUS_NAME_BASE.replace('.', '/'))
152 conf.define('BASE_NAME', APPNAME)
153 conf.define('_GNU_SOURCE', 1)
154 conf.write_config_header('config.h')
156 display_msg(conf)
158 display_msg(conf, "==================")
159 version_msg = APPNAME + "-" + VERSION
161 if os.access('version.h', os.R_OK):
162 data = file('version.h').read()
163 m = re.match(r'^#define GIT_VERSION "([^"]*)"$', data)
164 if m != None:
165 version_msg += " exported from " + m.group(1)
166 elif os.access('.git', os.R_OK):
167 version_msg += " git revision will checked and eventually updated during build"
169 display_msg(conf, version_msg)
171 display_msg(conf)
172 display_msg(conf, "Install prefix", conf.env['PREFIX'], 'CYAN')
174 display_msg(conf, 'Build gladish', yesno(conf.env['BUILD_GLADISH']))
175 display_msg(conf, 'Build liblash', yesno(Options.options.enable_liblash))
176 display_msg(conf, 'Treat warnings as errors', yesno(conf.env['BUILD_WERROR']))
177 display_msg(conf, 'Debuggable binaries', yesno(conf.env['BUILD_DEBUG']))
179 if conf.env['DBUS_SERVICES_DIR'] != conf.env['DBUS_SERVICES_DIR_REAL']:
180 display_msg(conf)
181 display_line(conf, "WARNING: D-Bus session services directory as reported by pkg-config is", 'RED')
182 display_raw_text(conf, "WARNING:", 'RED')
183 display_line(conf, conf.env['DBUS_SERVICES_DIR_REAL'], 'CYAN')
184 display_line(conf, 'WARNING: but service file will be installed in', 'RED')
185 display_raw_text(conf, "WARNING:", 'RED')
186 display_line(conf, conf.env['DBUS_SERVICES_DIR'], 'CYAN')
187 display_line(conf, 'WARNING: You may need to adjust your D-Bus configuration after installing ladish', 'RED')
188 display_line(conf, 'WARNING: You can override dbus service install directory', 'RED')
189 display_line(conf, 'WARNING: with --enable-pkg-config-dbus-service-dir option to this script', 'RED')
191 display_msg(conf)
193 def build(bld):
194 daemon = bld.new_task_gen('cc', 'program')
195 daemon.target = 'ladishd'
196 daemon.includes = "build/default" # XXX config.h version.h and other generated files
197 daemon.uselib = 'DBUS-1 UUID EXPAT'
198 daemon.ver_header = 'version.h'
199 daemon.env.append_value("LINKFLAGS", ["-lutil", "-ldl", "-Wl,-E"])
201 daemon.source = [
202 'jack_proxy.c',
203 'graph_proxy.c',
204 'catdup.c',
207 for source in [
208 'main.c',
209 'loader.c',
210 'log.c',
211 'dirhelpers.c',
212 'sigsegv.c',
213 'proctitle.c',
214 'appdb.c',
215 'procfs.c',
216 'control.c',
217 'studio.c',
218 'graph.c',
219 'client.c',
220 'port.c',
221 'virtualizer.c',
222 'dict.c',
223 'graph_dict.c',
224 'escape.c',
225 'studio_jack_conf.c',
226 'cmd_load_studio.c',
227 'cmd_new_studio.c',
228 'cmd_rename_studio.c',
229 'cmd_save_studio.c',
230 'cmd_start_studio.c',
231 'cmd_stop_studio.c',
232 'cmd_unload_studio.c',
233 'cmd_exit.c',
234 'cqueue.c',
235 'app_supervisor.c',
236 'a2j_proxy.c',
238 daemon.source.append(os.path.join("daemon", source))
240 for source in [
241 'signal.c',
242 'method.c',
243 'error.c',
244 'object_path.c',
245 'interface.c',
246 'helpers.c',
248 daemon.source.append(os.path.join("dbus", source))
250 daemon.source.append(os.path.join("common", "safety.c"))
252 # process name.arnaudov.nedko.ladish.service.in -> name.arnaudov.nedko.ladish.service
253 import misc
254 obj = bld.new_task_gen('subst')
255 obj.source = os.path.join('daemon', 'dbus.service.in')
256 obj.target = DBUS_NAME_BASE + '.service'
257 obj.dict = {'dbus_object_path': DBUS_NAME_BASE,
258 'daemon_bin_path': os.path.join(bld.env['PREFIX'], 'bin', daemon.target)}
259 obj.install_path = bld.env['DBUS_SERVICES_DIR'] + os.path.sep
260 obj.fun = misc.subst_func
262 if bld.env['BUILD_LIBLASH']:
263 liblash = bld.new_task_gen('cc', 'shlib')
264 liblash.includes = "build/default" # XXX config.h version.h and other generated files
265 liblash.uselib = 'DBUS-1'
266 liblash.target = 'lash'
267 liblash.vnum = "1.1.1"
268 liblash.defines = ['LOG_OUTPUT_STDOUT']
269 liblash.source = [os.path.join("lash_compat", "liblash", 'lash.c')]
271 # pkgpyexec_LTLIBRARIES = _lash.la
272 # INCLUDES = $(PYTHON_INCLUDES)
273 # _lash_la_LDFLAGS = -module -avoid-version ../liblash/liblash.la
274 # _lash_la_SOURCES = lash.c lash.h lash_wrap.c
275 # pkgpyexec_SCRIPTS = lash.py
276 # CLEANFILES = lash_wrap.c lash.py lash.pyc zynjacku.defs
277 # EXTRA_DIST = test.py lash.i lash.py
278 # lash_wrap.c lash.py: lash.i lash.h
279 # swig -o lash_wrap.c -I$(top_srcdir) -python $(top_srcdir)/$(subdir)/lash.i
281 #####################################################
282 # gladish
283 if bld.env['BUILD_GLADISH']:
284 gladish = bld.new_task_gen('cxx', 'program')
285 gladish.features.append('cc')
286 gladish.target = 'gladish'
287 gladish.defines = ['LOG_OUTPUT_STDOUT']
288 gladish.includes = "build/default" # XXX config.h version.h and other generated files
289 gladish.uselib = 'DBUS-1 DBUS-GLIB-1 LIBGLADE-2.0 FLOWCANVAS'
291 gladish.source = [
292 'jack_proxy.c',
293 'graph_proxy.c',
294 'studio_proxy.c',
295 'catdup.c',
298 for source in [
299 'main.c',
300 #'lash_client.cpp',
301 #'lash_proxy.cpp',
302 #'load_projects_dialog.cpp',
303 #'project.cpp',
304 'world_tree.c',
305 'graph_view.c',
306 #'project_properties.cpp',
307 #'session.cpp',
308 'dbus_helpers.c',
309 'canvas.cpp',
310 'graph_canvas.c',
311 'glade.c',
312 'control_proxy.c',
313 'app_supervisor_proxy.c',
314 'ask_dialog.c',
316 gladish.source.append(os.path.join("gui", source))
318 for source in [
319 'method.c',
320 'helpers.c',
322 gladish.source.append(os.path.join("dbus", source))
324 # Glade UI definitions (XML)
325 bld.install_files(bld.env['DATA_DIR'], 'gui/gui.glade')
327 bld.install_files('${PREFIX}/bin', 'ladish_control', chmod=0755)
329 # 'Desktop' file (menu entry, icon, etc)
330 #obj = bld.create_obj('subst')
331 #obj.source = 'patchage.desktop.in'
332 #obj.target = 'patchage.desktop'
333 #obj.dict = {
334 # 'BINDIR' : bld.env()['BINDIR'],
335 # 'APP_INSTALL_NAME' : bld.env()['APP_INSTALL_NAME'],
336 # 'APP_HUMAN_NAME' : bld.env()['APP_HUMAN_NAME'],
338 #install_as(os.path.normpath(bld.env()['DATADIR'] + 'applications/'), bld.env()['APP_INSTALL_NAME'] + '.desktop', 'build/default/patchage.desktop')
340 # Icons
342 # Installation layout (with /usr prefix)
343 # /usr/bin/patchage
344 # /usr/share/applications/patchage.desktop
345 # /usr/share/icons/hicolor/16x16/apps/patchage.png
346 # /usr/share/icons/hicolor/22x22/apps/patchage.png
347 # /usr/share/icons/hicolor/24x24/apps/patchage.png
348 # /usr/share/icons/hicolor/32x32/apps/patchage.png
349 # /usr/share/icons/hicolor/48x48/apps/patchage.png
350 # /usr/share/icons/hicolor/scalable/apps/patchage.svg
351 # /usr/share/patchage/patchage.glade
353 # icon cache is updated using:
354 # gtk-update-icon-cache -f -t $(datadir)/icons/hicolor
356 # Dave disabled this, ask why before removing this
357 #install_as(os.path.normpath(bld.env()['PREFIX'] + '/share/icons/hicolor/scalable/apps/'), bld.env()['APP_INSTALL_NAME'] + '.svg', 'icons/scalable/patchage.svg')
359 #icon_sizes = ['16x16', '22x22', '24x24', '32x32', '48x48']
360 #for icon_size in icon_sizes:
361 # install_as(os.path.normpath(bld.env()['DATADIR'] + '/icons/hicolor/' + icon_size + '/apps/'), bld.env()['APP_INSTALL_NAME'] + '.png', 'icons/' + icon_size + '/patchage.png')
363 def dist_hook():
364 shutil.copy('../build/default/version.h', "./")
366 import commands
367 from Constants import RUN_ME
368 from TaskGen import feature, after
369 import Task, Utils
371 @feature('cc')
372 @after('apply_core')
373 def process_git(self):
374 if getattr(self, 'ver_header', None):
375 tsk = self.create_task('git_ver')
376 tsk.set_outputs(self.path.find_or_declare(self.ver_header))
378 def git_ver(self):
379 header = self.outputs[0].abspath(self.env)
380 if os.access('../version.h', os.R_OK):
381 shutil.copy('../version.h', header)
382 data = file(header).read()
383 m = re.match(r'^#define GIT_VERSION "([^"]*)"$', data)
384 if m != None:
385 self.ver = m.group(1)
386 Utils.pprint('BLUE', "tarball from git revision " + self.ver)
387 else:
388 self.ver = "tarball"
389 return
391 if os.access('../.git', os.R_OK):
392 self.ver = commands.getoutput("LANG= git rev-parse HEAD").splitlines()[0]
393 if commands.getoutput("LANG= git diff-index --name-only HEAD").splitlines():
394 self.ver += "-dirty"
396 Utils.pprint('BLUE', "git revision " + self.ver)
397 else:
398 self.ver = "unknown"
400 fi = open(header, 'w')
401 fi.write('#define GIT_VERSION "%s"\n' % self.ver)
402 fi.close()
404 cls = Task.task_type_from_func('git_ver', vars=[], func=git_ver, color='BLUE', before='cc')
406 def always(self):
407 return RUN_ME
408 cls.runnable_status = always
410 def post_run(self):
411 sg = Utils.h_list(self.ver)
412 node = self.outputs[0]
413 variant = node.variant(self.env)
414 self.generator.bld.node_sigs[variant][node.id] = sg
415 cls.post_run = post_run