properly handle ladishd crashes
[ladish.git] / wscript
blob69b10e71929bdd214bff17f49bca7830186e57f5
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 'catdup.c',
205 for source in [
206 'main.c',
207 'loader.c',
208 'log.c',
209 'dirhelpers.c',
210 'sigsegv.c',
211 'proctitle.c',
212 'appdb.c',
213 'procfs.c',
214 'control.c',
215 'studio.c',
216 'graph.c',
217 'client.c',
218 'port.c',
219 'virtualizer.c',
220 'dict.c',
221 'graph_dict.c',
222 'escape.c',
223 'studio_jack_conf.c',
224 'cmd_load_studio.c',
225 'cmd_new_studio.c',
226 'cmd_rename_studio.c',
227 'cmd_save_studio.c',
228 'cmd_start_studio.c',
229 'cmd_stop_studio.c',
230 'cmd_unload_studio.c',
231 'cmd_exit.c',
232 'cqueue.c',
233 'app_supervisor.c',
235 daemon.source.append(os.path.join("daemon", source))
237 for source in [
238 'jack_proxy.c',
239 'graph_proxy.c',
240 'a2j_proxy.c',
242 daemon.source.append(os.path.join("proxies", source))
244 for source in [
245 'signal.c',
246 'method.c',
247 'error.c',
248 'object_path.c',
249 'interface.c',
250 'helpers.c',
252 daemon.source.append(os.path.join("dbus", source))
254 daemon.source.append(os.path.join("common", "safety.c"))
256 # process name.arnaudov.nedko.ladish.service.in -> name.arnaudov.nedko.ladish.service
257 import misc
258 obj = bld.new_task_gen('subst')
259 obj.source = os.path.join('daemon', 'dbus.service.in')
260 obj.target = DBUS_NAME_BASE + '.service'
261 obj.dict = {'dbus_object_path': DBUS_NAME_BASE,
262 'daemon_bin_path': os.path.join(bld.env['PREFIX'], 'bin', daemon.target)}
263 obj.install_path = bld.env['DBUS_SERVICES_DIR'] + os.path.sep
264 obj.fun = misc.subst_func
266 if bld.env['BUILD_LIBLASH']:
267 liblash = bld.new_task_gen('cc', 'shlib')
268 liblash.includes = "build/default" # XXX config.h version.h and other generated files
269 liblash.uselib = 'DBUS-1'
270 liblash.target = 'lash'
271 liblash.vnum = "1.1.1"
272 liblash.defines = ['LOG_OUTPUT_STDOUT']
273 liblash.source = [os.path.join("lash_compat", "liblash", 'lash.c')]
275 # pkgpyexec_LTLIBRARIES = _lash.la
276 # INCLUDES = $(PYTHON_INCLUDES)
277 # _lash_la_LDFLAGS = -module -avoid-version ../liblash/liblash.la
278 # _lash_la_SOURCES = lash.c lash.h lash_wrap.c
279 # pkgpyexec_SCRIPTS = lash.py
280 # CLEANFILES = lash_wrap.c lash.py lash.pyc zynjacku.defs
281 # EXTRA_DIST = test.py lash.i lash.py
282 # lash_wrap.c lash.py: lash.i lash.h
283 # swig -o lash_wrap.c -I$(top_srcdir) -python $(top_srcdir)/$(subdir)/lash.i
285 #####################################################
286 # gladish
287 if bld.env['BUILD_GLADISH']:
288 gladish = bld.new_task_gen('cxx', 'program')
289 gladish.features.append('cc')
290 gladish.target = 'gladish'
291 gladish.defines = ['LOG_OUTPUT_STDOUT']
292 gladish.includes = "build/default" # XXX config.h version.h and other generated files
293 gladish.uselib = 'DBUS-1 DBUS-GLIB-1 LIBGLADE-2.0 FLOWCANVAS'
295 gladish.source = [
296 'catdup.c',
299 for source in [
300 'main.c',
301 #'lash_client.cpp',
302 #'lash_proxy.cpp',
303 #'load_projects_dialog.cpp',
304 #'project.cpp',
305 'world_tree.c',
306 'graph_view.c',
307 #'project_properties.cpp',
308 #'session.cpp',
309 'canvas.cpp',
310 'graph_canvas.c',
311 'glade.c',
312 'ask_dialog.c',
314 gladish.source.append(os.path.join("gui", source))
316 for source in [
317 'jack_proxy.c',
318 'graph_proxy.c',
319 'studio_proxy.c',
320 'control_proxy.c',
321 'app_supervisor_proxy.c',
323 gladish.source.append(os.path.join("proxies", source))
325 for source in [
326 'method.c',
327 'helpers.c',
329 gladish.source.append(os.path.join("dbus", source))
331 # Glade UI definitions (XML)
332 bld.install_files(bld.env['DATA_DIR'], 'gui/gui.glade')
334 bld.install_files('${PREFIX}/bin', 'ladish_control', chmod=0755)
336 # 'Desktop' file (menu entry, icon, etc)
337 #obj = bld.create_obj('subst')
338 #obj.source = 'patchage.desktop.in'
339 #obj.target = 'patchage.desktop'
340 #obj.dict = {
341 # 'BINDIR' : bld.env()['BINDIR'],
342 # 'APP_INSTALL_NAME' : bld.env()['APP_INSTALL_NAME'],
343 # 'APP_HUMAN_NAME' : bld.env()['APP_HUMAN_NAME'],
345 #install_as(os.path.normpath(bld.env()['DATADIR'] + 'applications/'), bld.env()['APP_INSTALL_NAME'] + '.desktop', 'build/default/patchage.desktop')
347 # Icons
349 # Installation layout (with /usr prefix)
350 # /usr/bin/patchage
351 # /usr/share/applications/patchage.desktop
352 # /usr/share/icons/hicolor/16x16/apps/patchage.png
353 # /usr/share/icons/hicolor/22x22/apps/patchage.png
354 # /usr/share/icons/hicolor/24x24/apps/patchage.png
355 # /usr/share/icons/hicolor/32x32/apps/patchage.png
356 # /usr/share/icons/hicolor/48x48/apps/patchage.png
357 # /usr/share/icons/hicolor/scalable/apps/patchage.svg
358 # /usr/share/patchage/patchage.glade
360 # icon cache is updated using:
361 # gtk-update-icon-cache -f -t $(datadir)/icons/hicolor
363 # Dave disabled this, ask why before removing this
364 #install_as(os.path.normpath(bld.env()['PREFIX'] + '/share/icons/hicolor/scalable/apps/'), bld.env()['APP_INSTALL_NAME'] + '.svg', 'icons/scalable/patchage.svg')
366 #icon_sizes = ['16x16', '22x22', '24x24', '32x32', '48x48']
367 #for icon_size in icon_sizes:
368 # install_as(os.path.normpath(bld.env()['DATADIR'] + '/icons/hicolor/' + icon_size + '/apps/'), bld.env()['APP_INSTALL_NAME'] + '.png', 'icons/' + icon_size + '/patchage.png')
370 def dist_hook():
371 shutil.copy('../build/default/version.h', "./")
373 import commands
374 from Constants import RUN_ME
375 from TaskGen import feature, after
376 import Task, Utils
378 @feature('cc')
379 @after('apply_core')
380 def process_git(self):
381 if getattr(self, 'ver_header', None):
382 tsk = self.create_task('git_ver')
383 tsk.set_outputs(self.path.find_or_declare(self.ver_header))
385 def git_ver(self):
386 header = self.outputs[0].abspath(self.env)
387 if os.access('../version.h', os.R_OK):
388 shutil.copy('../version.h', header)
389 data = file(header).read()
390 m = re.match(r'^#define GIT_VERSION "([^"]*)"$', data)
391 if m != None:
392 self.ver = m.group(1)
393 Utils.pprint('BLUE', "tarball from git revision " + self.ver)
394 else:
395 self.ver = "tarball"
396 return
398 if os.access('../.git', os.R_OK):
399 self.ver = commands.getoutput("LANG= git rev-parse HEAD").splitlines()[0]
400 if commands.getoutput("LANG= git diff-index --name-only HEAD").splitlines():
401 self.ver += "-dirty"
403 Utils.pprint('BLUE', "git revision " + self.ver)
404 else:
405 self.ver = "unknown"
407 fi = open(header, 'w')
408 fi.write('#define GIT_VERSION "%s"\n' % self.ver)
409 fi.close()
411 cls = Task.task_type_from_func('git_ver', vars=[], func=git_ver, color='BLUE', before='cc')
413 def always(self):
414 return RUN_ME
415 cls.runnable_status = always
417 def post_run(self):
418 sg = Utils.h_list(self.ver)
419 node = self.outputs[0]
420 variant = node.variant(self.env)
421 self.generator.bld.node_sigs[variant][node.id] = sg
422 cls.post_run = post_run