#!/usr/bin/env python

def configure (conf):
	conf.check_tool('gcc')
	conf.check_tool('misc')

	conf.find_program('gzip', var = 'GZIP')

	conf.check_cfg(
		package = 'dbus-1',
		uselib_store = 'DBUS',
		variables = ['session_bus_services_dir']
	)

	if not conf.env.VERSION:
		conf.env.VERSION = ''

def build (bld):
	bld.install_files('${DATAROOTDIR}/sushi/maki', 'dbus.xml')

	dbus_dir = bld.env['DBUS_session_bus_services_dir']

	if dbus_dir and dbus_dir.startswith(bld.env.PREFIX):
		bld.new_task_gen(
			features = 'subst',
			source = 'de.ikkoku.sushi.service.in',
			target = 'de.ikkoku.sushi.service',
			install_path = '${DBUS_session_bus_services_dir}'
		)

	for man in ('maki.1', 'sushi-remote.1'):
		bld.new_task_gen(
			features = 'subst',
			source = '%s.in' % (man),
			target = man,
			install_path = None,
			dict = {'SUSHI_VERSION': bld.env.VERSION}
		)

	bld.add_group()

	for man in ('maki.1', 'sushi-remote.1'):
		bld.new_task_gen(
			source = man,
			target = '%s.gz' % (man),
			rule = '${GZIP} -c ${SRC} > ${TGT}',
			install_path = '${MANDIR}/man1'
		)
