#!/usr/bin/env python
import os
import autowaf

# Version of this package (even if built as a child)
MACHINA_VERSION = '0.5.0'

# Variables for 'waf dist'
APPNAME = 'machina'
VERSION = MACHINA_VERSION

# Mandatory variables
top = '.'
out = 'build'

def options(opt):
	autowaf.set_options(opt)

def configure(conf):
	autowaf.configure(conf)
	autowaf.display_header('Machina Configuration')
	conf.check_tool('compiler_cxx')
	autowaf.check_pkg(conf, 'glibmm-2.4', uselib_store='GLIBMM',
			atleast_version='2.14.0', mandatory=True)
	autowaf.check_pkg(conf, 'gthread-2.0', uselib_store='GTHREAD',
			atleast_version='2.14.0', mandatory=True)
	autowaf.check_pkg(conf, 'gtkmm-2.4', uselib_store='GTKMM',
			atleast_version='2.11.12', mandatory=False)
	autowaf.check_pkg(conf, 'jack', uselib_store='JACK',
			  atleast_version='0.109.0', mandatory=True)
	autowaf.check_pkg(conf, 'raul', uselib_store='RAUL',
			atleast_version='0.5.1', mandatory=True)
	autowaf.check_pkg(conf, 'flowcanvas', uselib_store='FLOWCANVAS',
			atleast_version='0.5.1', mandatory=False)
	autowaf.check_pkg(conf, 'libglademm-2.4', uselib_store='GLADEMM',
			atleast_version='2.6.0', mandatory=False)
	autowaf.check_pkg(conf, 'rasqal', uselib_store='RASQAL', mandatory=False)
	autowaf.check_pkg(conf, 'sord', uselib_store='SORD',
			atleast_version='0.1.0', mandatory=False)
	#autowaf.check_pkg(conf, 'eugene', uselib_store='EUGENE',
	#		atleast_version='0.0.0', mandatory=False)

	# Check for posix_memalign (OSX, amazingly, doesn't have it)
	conf.check(function_name='posix_memalign',
	           header_name='stdlib.h',
	           define_name='HAVE_POSIX_MEMALIGN',
	           mandatory=False)

	build_gui = conf.env['HAVE_GLADEMM'] == 1 and conf.env['HAVE_FLOWCANVAS'] == 1

	autowaf.define(conf, 'MACHINA_PPQN', 19200)
	autowaf.define(conf, 'MACHINA_VERSION', MACHINA_VERSION)
	autowaf.define(conf, 'MACHINA_BUILD_GUI', int(build_gui))
	autowaf.define(conf, 'MACHINA_DATA_DIR', os.path.join(
			conf.env['DATADIR'], 'machina'))

	conf.write_config_header('machina-config.h', remove=False)

	autowaf.display_msg(conf, "Jack", str(conf.env['HAVE_JACK'] == 1))
	autowaf.display_msg(conf, "GUI", str(conf.env['MACHINA_BUILD_GUI'] == 1))
	print

def build(bld):
	bld.add_subdirs('src/engine')
	bld.add_subdirs('src/client')

	if bld.env['MACHINA_BUILD_GUI']:
		bld.add_subdirs('src/gui')