gladish: recently used projects menu. Fix for #74
[ladish.git] / wscript
blobc3ef3ca72a19f7d87acbf152bd416e36a777a7a8
1 #! /usr/bin/env python
2 # encoding: utf-8
4 import os
5 import Options
6 import Utils
7 import shutil
8 import re
9 import misc
11 APPNAME='ladish'
12 VERSION='0.3-rc'
13 DBUS_NAME_BASE = 'org.ladish'
14 RELEASE = False
16 # these variables are mandatory ('/' are converted automatically)
17 srcdir = '.'
18 blddir = 'build'
20 def display_msg(conf, msg="", status = None, color = None):
21 if status:
22 conf.check_message_1(msg)
23 conf.check_message_2(status, color)
24 else:
25 Utils.pprint('NORMAL', msg)
27 def display_raw_text(conf, text, color = 'NORMAL'):
28 Utils.pprint(color, text, sep = '')
30 def display_line(conf, text, color = 'NORMAL'):
31 Utils.pprint(color, text, sep = os.linesep)
33 def yesno(bool):
34 if bool:
35 return "yes"
36 else:
37 return "no"
39 def set_options(opt):
40 opt.tool_options('compiler_cc')
41 opt.tool_options('compiler_cxx')
42 opt.tool_options('boost')
43 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')
44 opt.add_option('--enable-liblash', action='store_true', default=False, help='Build LASH compatibility library')
45 opt.add_option('--debug', action='store_true', default=False, dest='debug', help="Build debuggable binaries")
46 opt.add_option('--doxygen', action='store_true', default=False, help='Enable build of doxygen documentation')
47 opt.add_option('--distnodeps', action='store_true', default=False, help="When creating distribution tarball, don't package git submodules")
49 def add_cflag(conf, flag):
50 conf.env.append_unique('CXXFLAGS', flag)
51 conf.env.append_unique('CCFLAGS', flag)
53 def add_linkflag(conf, flag):
54 conf.env.append_unique('LINKFLAGS', flag)
56 def check_gcc_optimizations_enabled(flags):
57 gcc_optimizations_enabled = False
58 for flag in flags:
59 if len(flag) < 2 or flag[0] != '-' or flag[1] != 'O':
60 continue
61 if len(flag) == 2:
62 gcc_optimizations_enabled = True;
63 else:
64 gcc_optimizations_enabled = flag[2] != '0';
65 return gcc_optimizations_enabled
67 def create_service_taskgen(bld, target, opath, binary):
68 obj = bld.new_task_gen('subst')
69 obj.source = os.path.join('daemon', 'dbus.service.in')
70 obj.target = target
71 obj.dict = {'dbus_object_path': opath,
72 'daemon_bin_path': os.path.join(bld.env['PREFIX'], 'bin', binary)}
73 obj.install_path = bld.env['DBUS_SERVICES_DIR'] + os.path.sep
74 obj.fun = misc.subst_func
76 def configure(conf):
77 conf.check_tool('compiler_cc')
78 conf.check_tool('compiler_cxx')
79 conf.check_tool('boost')
80 #conf.check_tool('ParallelDebug')
82 conf.check_cfg(
83 package = 'jack',
84 mandatory = True,
85 errmsg = "not installed, see http://jackaudio.org/",
86 args = '--cflags --libs')
88 conf.check_cfg(
89 package = 'dbus-1',
90 atleast_version = '1.0.0',
91 mandatory = True,
92 errmsg = "not installed, see http://dbus.freedesktop.org/",
93 args = '--cflags --libs')
95 dbus_dir = conf.check_cfg(package='dbus-1', args='--variable=session_bus_services_dir', msg="Retrieving D-Bus services dir")
96 if not dbus_dir:
97 return
99 dbus_dir = dbus_dir.strip()
100 conf.env['DBUS_SERVICES_DIR_REAL'] = dbus_dir
102 if Options.options.enable_pkg_config_dbus_service_dir:
103 conf.env['DBUS_SERVICES_DIR'] = dbus_dir
104 else:
105 conf.env['DBUS_SERVICES_DIR'] = os.path.join(os.path.normpath(conf.env['PREFIX']), 'share', 'dbus-1', 'services')
107 conf.env['LIBDIR'] = os.path.join(os.path.normpath(conf.env['PREFIX']), 'lib')
109 conf.env['BUILD_LIBLASH'] = Options.options.enable_liblash
110 conf.env['BUILD_DOXYGEN_DOCS'] = Options.options.doxygen
112 conf.check_cfg(
113 package = 'uuid',
114 mandatory = True,
115 errmsg = "not installed, see http://e2fsprogs.sourceforge.net/",
116 args = '--cflags --libs')
118 conf.check(
119 header_name='expat.h',
120 mandatory = True,
121 errmsg = "not installed, see http://expat.sourceforge.net/")
123 conf.env['LIB_EXPAT'] = ['expat']
125 build_gui = True
127 if build_gui and not conf.check_cfg(
128 package = 'glib-2.0',
129 mandatory = False,
130 errmsg = "not installed, see http://www.gtk.org/",
131 args = '--cflags --libs'):
132 build_gui = False
134 if build_gui and not conf.check_cfg(
135 package = 'dbus-glib-1',
136 mandatory = False,
137 errmsg = "not installed, see http://dbus.freedesktop.org/",
138 args = '--cflags --libs'):
139 build_gui = False
141 if build_gui and not conf.check_cfg(
142 package = 'gtk+-2.0',
143 mandatory = False,
144 atleast_version = '2.20.0',
145 errmsg = "not installed, see http://www.gtk.org/",
146 args = '--cflags --libs'):
147 build_gui = False
149 if build_gui and not conf.check_cfg(
150 package = 'flowcanvas',
151 mandatory = False,
152 atleast_version = '0.6.4',
153 errmsg = "not installed, see http://drobilla.net/software/flowcanvas/",
154 args = '--cflags --libs'):
155 build_gui = False
157 if build_gui:
158 # We need the boost headers package (e.g. libboost-dev)
159 # shared_ptr.hpp and weak_ptr.hpp
160 build_gui = conf.check_boost(errmsg="not found, see http://boost.org/")
162 conf.env['BUILD_GLADISH'] = build_gui
164 conf.env['BUILD_WERROR'] = not RELEASE
165 if conf.env['BUILD_WERROR']:
166 add_cflag(conf, '-Wall')
167 add_cflag(conf, '-Werror')
168 # for pre gcc-4.4, enable optimizations so use of uninitialized variables gets detected
169 try:
170 is_gcc = conf.env['CC_NAME'] == 'gcc'
171 if is_gcc:
172 gcc_ver = []
173 for n in conf.env['CC_VERSION']:
174 gcc_ver.append(int(n))
175 if gcc_ver[0] < 4 or gcc_ver[1] < 4:
176 #print "optimize force enable is required"
177 if not check_gcc_optimizations_enabled(conf.env['CCFLAGS']):
178 if Options.options.debug:
179 print "C optimization must be forced in order to enable -Wuninitialized"
180 print "However this will not be made because debug compilation is enabled"
181 else:
182 print "C optimization forced in order to enable -Wuninitialized"
183 conf.env.append_unique('CCFLAGS', "-O")
184 except:
185 pass
187 conf.env['BUILD_DEBUG'] = Options.options.debug
188 if conf.env['BUILD_DEBUG']:
189 add_cflag(conf, '-g')
190 add_cflag(conf, '-O0')
191 add_linkflag(conf, '-g')
193 conf.define('DATA_DIR', os.path.normpath(os.path.join(conf.env['PREFIX'], 'share', APPNAME)))
194 conf.define('PACKAGE_VERSION', VERSION)
195 conf.define('DBUS_NAME_BASE', DBUS_NAME_BASE)
196 conf.define('DBUS_BASE_PATH', '/' + DBUS_NAME_BASE.replace('.', '/'))
197 conf.define('BASE_NAME', APPNAME)
198 conf.define('_GNU_SOURCE', 1)
199 conf.write_config_header('config.h')
201 display_msg(conf)
203 display_msg(conf, "==================")
204 version_msg = APPNAME + "-" + VERSION
206 if os.access('version.h', os.R_OK):
207 data = file('version.h').read()
208 m = re.match(r'^#define GIT_VERSION "([^"]*)"$', data)
209 if m != None:
210 version_msg += " exported from " + m.group(1)
211 elif os.access('.git', os.R_OK):
212 version_msg += " git revision will checked and eventually updated during build"
214 display_msg(conf, version_msg)
216 display_msg(conf)
217 display_msg(conf, "Install prefix", conf.env['PREFIX'], 'CYAN')
219 display_msg(conf, 'Build gladish', yesno(conf.env['BUILD_GLADISH']))
220 display_msg(conf, 'Build liblash', yesno(Options.options.enable_liblash))
221 display_msg(conf, 'Treat warnings as errors', yesno(conf.env['BUILD_WERROR']))
222 display_msg(conf, 'Debuggable binaries', yesno(conf.env['BUILD_DEBUG']))
223 display_msg(conf, 'Build doxygen documentation', yesno(conf.env['BUILD_DOXYGEN_DOCS']))
225 if conf.env['DBUS_SERVICES_DIR'] != conf.env['DBUS_SERVICES_DIR_REAL']:
226 display_msg(conf)
227 display_line(conf, "WARNING: D-Bus session services directory as reported by pkg-config is", 'RED')
228 display_raw_text(conf, "WARNING:", 'RED')
229 display_line(conf, conf.env['DBUS_SERVICES_DIR_REAL'], 'CYAN')
230 display_line(conf, 'WARNING: but service file will be installed in', 'RED')
231 display_raw_text(conf, "WARNING:", 'RED')
232 display_line(conf, conf.env['DBUS_SERVICES_DIR'], 'CYAN')
233 display_line(conf, 'WARNING: You may need to adjust your D-Bus configuration after installing ladish', 'RED')
234 display_line(conf, 'WARNING: You can override dbus service install directory', 'RED')
235 display_line(conf, 'WARNING: with --enable-pkg-config-dbus-service-dir option to this script', 'RED')
237 display_msg(conf, 'C compiler flags', repr(conf.env['CCFLAGS']))
238 display_msg(conf, 'C++ compiler flags', repr(conf.env['CXXFLAGS']))
240 if not conf.env['BUILD_GLADISH']:
241 display_msg(conf)
242 display_line(conf, "WARNING: The GUI frontend will not built", 'RED')
244 display_msg(conf)
246 def build(bld):
247 daemon = bld.new_task_gen('cc', 'program')
248 daemon.target = 'ladishd'
249 daemon.includes = "build/default" # XXX config.h version.h and other generated files
250 daemon.uselib = 'DBUS-1 UUID EXPAT'
251 daemon.ver_header = 'version.h'
252 daemon.env.append_value("LINKFLAGS", ["-lutil", "-ldl", "-Wl,-E"])
254 daemon.source = []
256 for source in [
257 'main.c',
258 'loader.c',
259 'log.c',
260 'sigsegv.c',
261 'proctitle.c',
262 'appdb.c',
263 'procfs.c',
264 'control.c',
265 'studio.c',
266 'graph.c',
267 'client.c',
268 'port.c',
269 'virtualizer.c',
270 'dict.c',
271 'graph_dict.c',
272 'escape.c',
273 'studio_jack_conf.c',
274 'save.c',
275 'load.c',
276 'cmd_load_studio.c',
277 'cmd_new_studio.c',
278 'cmd_rename_studio.c',
279 'cmd_save_studio.c',
280 'cmd_start_studio.c',
281 'cmd_stop_studio.c',
282 'cmd_unload_studio.c',
283 'cmd_new_app.c',
284 'cmd_change_app_state.c',
285 'cmd_remove_app.c',
286 'cmd_create_room.c',
287 'cmd_delete_room.c',
288 'cmd_save_project.c',
289 'cmd_unload_project.c',
290 'cmd_load_project.c',
291 'cmd_exit.c',
292 'cqueue.c',
293 'app_supervisor.c',
294 'room.c',
295 'room_save.c',
296 'room_load.c',
297 'recent_store.c',
298 'recent_projects.c',
300 daemon.source.append(os.path.join("daemon", source))
302 for source in [
303 'jack_proxy.c',
304 'graph_proxy.c',
305 'a2j_proxy.c',
306 "jmcore_proxy.c",
307 "notify_proxy.c",
308 "conf_proxy.c",
310 daemon.source.append(os.path.join("proxies", source))
312 for source in [
313 'signal.c',
314 'method.c',
315 'error.c',
316 'object_path.c',
317 'interface.c',
318 'helpers.c',
320 daemon.source.append(os.path.join("dbus", source))
322 for source in [
323 'time.c',
324 'dirhelpers.c',
325 'catdup.c',
327 daemon.source.append(os.path.join("common", source))
329 # process dbus.service.in -> ladish.service
330 create_service_taskgen(bld, DBUS_NAME_BASE + '.service', DBUS_NAME_BASE, daemon.target)
332 #####################################################
333 # jmcore
334 jmcore = bld.new_task_gen('cc', 'program')
335 jmcore.target = 'jmcore'
336 jmcore.includes = "build/default" # XXX config.h version.h and other generated files
337 jmcore.uselib = 'DBUS-1 JACK'
338 jmcore.defines = ['LOG_OUTPUT_STDOUT']
339 jmcore.source = ['jmcore.c']
341 for source in [
342 #'signal.c',
343 'method.c',
344 'error.c',
345 'object_path.c',
346 'interface.c',
347 'helpers.c',
349 jmcore.source.append(os.path.join("dbus", source))
351 create_service_taskgen(bld, DBUS_NAME_BASE + '.jmcore.service', DBUS_NAME_BASE + ".jmcore", jmcore.target)
353 #####################################################
354 # conf
355 ladiconfd = bld.new_task_gen('cc', 'program')
356 ladiconfd.target = 'ladiconfd'
357 ladiconfd.includes = "build/default" # XXX config.h version.h and other generated files
358 ladiconfd.uselib = 'DBUS-1'
359 ladiconfd.defines = ['LOG_OUTPUT_STDOUT']
360 ladiconfd.source = ['conf.c']
362 for source in [
363 'dirhelpers.c',
364 'catdup.c',
366 ladiconfd.source.append(os.path.join("common", source))
368 for source in [
369 'signal.c',
370 'method.c',
371 'error.c',
372 'object_path.c',
373 'interface.c',
374 'helpers.c',
376 ladiconfd.source.append(os.path.join("dbus", source))
378 create_service_taskgen(bld, DBUS_NAME_BASE + '.conf.service', DBUS_NAME_BASE + ".conf", ladiconfd.target)
380 #####################################################
381 # liblash
382 if bld.env['BUILD_LIBLASH']:
383 liblash = bld.new_task_gen('cc', 'shlib')
384 liblash.includes = "build/default" # XXX config.h version.h and other generated files
385 liblash.uselib = 'DBUS-1'
386 liblash.target = 'lash'
387 liblash.vnum = "1.1.1"
388 liblash.defines = ['LOG_OUTPUT_STDOUT']
389 liblash.source = [os.path.join("lash_compat", "liblash", 'lash.c')]
391 bld.install_files('${PREFIX}/include/lash', 'lash_compat/liblash/lash/*.h')
393 # process lash-1.0.pc.in -> lash-1.0.pc
394 obj = bld.new_task_gen('subst')
395 obj.source = [os.path.join("lash_compat", 'lash-1.0.pc.in')]
396 obj.target = 'lash-1.0.pc'
397 obj.dict = {'prefix': bld.env['PREFIX'],
398 'exec_prefix': bld.env['PREFIX'],
399 'libdir': bld.env['LIBDIR'],
400 'includedir': os.path.normpath(bld.env['PREFIX'] + '/include'),
402 obj.install_path = '${LIBDIR}/pkgconfig/'
403 obj.fun = misc.subst_func
405 #####################################################
406 # pylash
408 # pkgpyexec_LTLIBRARIES = _lash.la
409 # INCLUDES = $(PYTHON_INCLUDES)
410 # _lash_la_LDFLAGS = -module -avoid-version ../liblash/liblash.la
411 # _lash_la_SOURCES = lash.c lash.h lash_wrap.c
412 # pkgpyexec_SCRIPTS = lash.py
413 # CLEANFILES = lash_wrap.c lash.py lash.pyc zynjacku.defs
414 # EXTRA_DIST = test.py lash.i lash.py
415 # lash_wrap.c lash.py: lash.i lash.h
416 # swig -o lash_wrap.c -I$(top_srcdir) -python $(top_srcdir)/$(subdir)/lash.i
418 #####################################################
419 # gladish
420 if bld.env['BUILD_GLADISH']:
421 gladish = bld.new_task_gen('cxx', 'program')
422 gladish.features.append('cc')
423 gladish.target = 'gladish'
424 gladish.defines = ['LOG_OUTPUT_STDOUT']
425 gladish.includes = "build/default" # XXX config.h version.h and other generated files
426 gladish.uselib = 'DBUS-1 DBUS-GLIB-1 FLOWCANVAS'
428 gladish.source = []
430 for source in [
431 'main.c',
432 'load_project_dialog.c',
433 'save_project_dialog.c',
434 'world_tree.c',
435 'graph_view.c',
436 'canvas.cpp',
437 'graph_canvas.c',
438 'gtk_builder.c',
439 'ask_dialog.c',
440 'create_room_dialog.c',
441 'menu.c',
442 'dynmenu.c',
443 'toolbar.c',
444 'about.c',
445 'dbus.c',
446 'studio.c',
447 'studio_list.c',
448 'dialogs.c',
449 'jack.c',
450 'control.c',
451 'pixbuf.c',
452 'room.c',
453 'statusbar.c',
454 'action.c',
455 'settings.c',
456 'zoom.c',
458 gladish.source.append(os.path.join("gui", source))
460 for source in [
461 'jack_proxy.c',
462 'graph_proxy.c',
463 'studio_proxy.c',
464 'control_proxy.c',
465 'app_supervisor_proxy.c',
466 "room_proxy.c",
467 "conf_proxy.c",
469 gladish.source.append(os.path.join("proxies", source))
471 for source in [
472 'method.c',
473 'helpers.c',
475 gladish.source.append(os.path.join("dbus", source))
477 for source in [
478 'catdup.c',
480 gladish.source.append(os.path.join("common", source))
482 # GtkBuilder UI definitions (XML)
483 bld.install_files(bld.env['DATA_DIR'], 'gui/gladish.ui')
485 bld.install_files('${PREFIX}/bin', 'ladish_control', chmod=0755)
487 # 'Desktop' file (menu entry, icon, etc)
488 bld.install_files('${PREFIX}/share/applications/', 'gui/gladish.desktop', chmod=0644)
490 # Icons
491 icon_sizes = ['16x16', '22x22', '24x24', '32x32', '48x48', '256x256']
492 for icon_size in icon_sizes:
493 bld.path.ant_glob('art/' + icon_size + '/apps/*.png')
494 bld.install_files('${PREFIX}/share/icons/hicolor/' + icon_size + '/apps/', 'art/' + icon_size + '/apps/gladish.png')
496 status_images = []
497 for status in ["down", "unloaded", "started", "stopped", "warning", "error"]:
498 status_images.append("art/status_" + status + ".png")
500 bld.install_files(bld.env['DATA_DIR'], status_images)
501 bld.install_files(bld.env['DATA_DIR'], "art/ladish-logo-128x128.png")
502 bld.install_files(bld.env['DATA_DIR'], ["COPYING", "AUTHORS", "README", "NEWS"])
504 if bld.env['BUILD_DOXYGEN_DOCS'] == True:
505 html_docs_source_dir = "build/default/html"
506 if Options.commands['clean']:
507 if os.access(html_docs_source_dir, os.R_OK):
508 Utils.pprint('CYAN', "Removing doxygen generated documentation...")
509 shutil.rmtree(html_docs_source_dir)
510 Utils.pprint('CYAN', "Removing doxygen generated documentation done.")
511 elif Options.commands['build']:
512 if not os.access(html_docs_source_dir, os.R_OK):
513 os.popen("doxygen").read()
514 else:
515 Utils.pprint('CYAN', "doxygen documentation already built.")
517 def get_tags_dirs():
518 source_root = os.path.dirname(Utils.g_module.root_path)
519 if 'relpath' in os.path.__all__:
520 source_root = os.path.relpath(source_root)
521 paths = source_root
522 paths += " " + os.path.join(source_root, "common")
523 paths += " " + os.path.join(source_root, "dbus")
524 paths += " " + os.path.join(source_root, "proxies")
525 paths += " " + os.path.join(source_root, "daemon")
526 paths += " " + os.path.join(source_root, "gui")
527 paths += " " + os.path.join(source_root, "example-apps")
528 paths += " " + os.path.join(source_root, "lib")
529 paths += " " + os.path.join(source_root, "lash_compat", "liblash")
530 paths += " " + os.path.join(source_root, "lash_compat", "liblash", "lash")
531 return paths
533 def gtags(ctx):
534 '''build tag files for GNU global'''
535 cmd = "find %s -mindepth 1 -maxdepth 1 -name '*.[ch]' -print | gtags --statistics -f -" % get_tags_dirs()
536 #print("Running: %s" % cmd)
537 os.system(cmd)
539 def etags(ctx):
540 '''build TAGS file using etags'''
541 cmd = "find %s -mindepth 1 -maxdepth 1 -name '*.[ch]' -print | etags -" % get_tags_dirs()
542 #print("Running: %s" % cmd)
543 os.system(cmd)
544 os.system("stat -c '%y' TAGS")
546 def dist_hook():
547 #print repr(Options.options)
548 if Options.options.distnodeps:
549 shutil.rmtree('laditools')
550 shutil.rmtree('flowcanvas')
551 shutil.rmtree('jack2')
552 shutil.rmtree('a2jmidid')
553 nodist_files = ['.gitmodules', 'GTAGS', 'GRTAGS', 'GPATH', 'GSYMS'] # waf does not ignore these file
554 for nodist_file in nodist_files:
555 os.remove(nodist_file)
556 shutil.copy('../build/default/version.h', "./")
558 import commands
559 from Constants import RUN_ME
560 from TaskGen import feature, after
561 import Task, Utils
563 @feature('cc')
564 @after('apply_core')
565 def process_git(self):
566 if getattr(self, 'ver_header', None):
567 tsk = self.create_task('git_ver')
568 tsk.set_outputs(self.path.find_or_declare(self.ver_header))
570 # needs some help with implicit dependencies
571 # http://code.google.com/p/waf/issues/detail?id=732
572 tg = self.bld.name_to_obj('ladishd', self.env)
573 if id(tg) != id(self):
574 tg.post()
575 for x in tg.tasks:
576 if x.inputs and x.inputs[0].name == 'main.c' and x.inputs[0].parent.name == 'daemon':
577 x.set_run_after(tsk)
579 def git_ver(self):
580 header = self.outputs[0].abspath(self.env)
581 if os.access('../version.h', os.R_OK):
582 shutil.copy('../version.h', header)
583 data = file(header).read()
584 m = re.match(r'^#define GIT_VERSION "([^"]*)"$', data)
585 if m != None:
586 self.ver = m.group(1)
587 Utils.pprint('BLUE', "tarball from git revision " + self.ver)
588 else:
589 self.ver = "tarball"
590 return
592 if os.access('../.git', os.R_OK):
593 self.ver = commands.getoutput("LANG= git rev-parse HEAD").splitlines()[0]
594 if commands.getoutput("LANG= git diff-index --name-only HEAD").splitlines():
595 self.ver += "-dirty"
597 Utils.pprint('BLUE', "git revision " + self.ver)
598 else:
599 self.ver = "unknown"
601 fi = open(header, 'w')
602 fi.write('#define GIT_VERSION "%s"\n' % self.ver)
603 fi.close()
605 cls = Task.task_type_from_func('git_ver', vars=[], func=git_ver, color='BLUE')
607 def always(self):
608 return RUN_ME
609 cls.runnable_status = always
611 def post_run(self):
612 sg = Utils.h_list(self.ver)
613 node = self.outputs[0]
614 variant = node.variant(self.env)
615 self.generator.bld.node_sigs[variant][node.id] = sg
616 cls.post_run = post_run
618 import Runner
620 old_refill = Runner.Parallel.refill_task_list
621 def refill_task_list(self):
622 old_refill(self)
623 self.outstanding.sort(cmp=lambda a, b: cmp(b.__class__.__name__, a.__class__.__name__))
624 Runner.Parallel.refill_task_list = refill_task_list