#!/usr/bin/env python
import autowaf

def build(bld):
	# Headers
	bld.install_files('${INCLUDEDIR}/ingen/engine', '*.hpp')

	core_source = '''
		AudioBuffer.cpp
		BufferFactory.cpp
		ClientBroadcaster.cpp
		ConnectionImpl.cpp
		ControlBindings.cpp
		DuplexPort.cpp
		Engine.cpp
		EngineStore.cpp
		Event.cpp
		EventBuffer.cpp
		EventSink.cpp
		EventSource.cpp
		GraphObjectImpl.cpp
		InputPort.cpp
		InternalPlugin.cpp
		MessageContext.cpp
		NodeBase.cpp
		NodeFactory.cpp
		ObjectBuffer.cpp
		ObjectSender.cpp
		OutputPort.cpp
		PatchImpl.cpp
		PluginImpl.cpp
		PortImpl.cpp
		PostProcessor.cpp
		ProcessSlave.cpp
		QueuedEngineInterface.cpp
		QueuedEvent.cpp
		events/AllNotesOff.cpp
		events/Connect.cpp
		events/CreateNode.cpp
		events/CreatePatch.cpp
		events/CreatePort.cpp
		events/Delete.cpp
		events/Disconnect.cpp
		events/DisconnectAll.cpp
		events/Get.cpp
		events/Learn.cpp
		events/LoadPlugins.cpp
		events/Move.cpp
		events/Note.cpp
		events/RegisterClient.cpp
		events/RequestAllObjects.cpp
		events/RequestMetadata.cpp
		events/RequestPlugins.cpp
		events/SendBinding.cpp
		events/SendPortActivity.cpp
		events/SendPortValue.cpp
		events/SetMetadata.cpp
		events/SetPortValue.cpp
		events/UnregisterClient.cpp
		ingen_engine.cpp
		internals/Controller.cpp
		internals/Note.cpp
		internals/Trigger.cpp
	'''

	obj = bld.new_task_gen('cxx', 'shlib')
	obj.source = core_source
	if bld.env['HAVE_LADSPA_H'] == 1:
		obj.source += ' LADSPAPlugin.cpp LADSPANode.cpp '
	if bld.env['HAVE_SLV2'] == 1:
		obj.source += ' LV2Info.cpp LV2Plugin.cpp LV2Node.cpp '
	obj.export_incdirs = ['.']
	obj.includes     = ['.', '..', '../..', '../common']
	obj.name         = 'libingen_engine'
	obj.target       = 'ingen_engine'
	obj.install_path = '${LIBDIR}/ingen'
	obj.uselib_local = 'libingen_shared'
	core_libs = 'GLIBMM GTHREAD LV2CORE SLV2 RAUL REDLANDMM'
	autowaf.use_lib(bld, obj, core_libs)

	if bld.env['HAVE_SOUP'] == 1:
		obj = bld.new_task_gen('cxx', 'shlib')
		obj.source = '''
			EventSource.cpp
			QueuedEngineInterface.cpp
			HTTPClientSender.cpp
			HTTPEngineReceiver.cpp
			ingen_http.cpp
		'''
		obj.includes     = ['.', '..', '../..', '../common', '../engine']
		obj.name         = 'libingen__http'
		obj.target       = 'ingen_http'
		obj.install_path = '${LIBDIR}/ingen'
		autowaf.use_lib(bld, obj, core_libs + ' SOUP')

	if bld.env['HAVE_LIBLO'] == 1:
		obj = bld.new_task_gen('cxx', 'shlib')
		obj.source = '''
			EventSource.cpp
			QueuedEngineInterface.cpp
			OSCClientSender.cpp
			OSCEngineReceiver.cpp
			ingen_osc.cpp
		'''
		obj.export_incdirs = ['.']
		obj.includes     = ['.', '..', '../..', '../common', '../engine']
		obj.name         = 'libingen_osc'
		obj.target       = 'ingen_osc'
		obj.install_path = '${LIBDIR}/ingen'
		autowaf.use_lib(bld, obj, core_libs + ' LIBLO')

	if bld.env['HAVE_JACK'] == 1:
		obj = bld.new_task_gen('cxx', 'shlib')
		obj.source = 'JackDriver.cpp ingen_jack.cpp'
		obj.export_incdirs = ['.']
		obj.includes     = ['.', '..', '../..', '../common', '../engine']
		obj.name         = 'libingen_jack'
		obj.target       = 'ingen_jack'
		obj.install_path = '${LIBDIR}/ingen'
		autowaf.use_lib(bld, obj, core_libs + ' JACK')

	# Lightweight ingen/lv2 wrapper
	#obj = bld.new_task_gen('cxx', 'shlib')
	#obj.source = core_source
	#if bld.env['HAVE_LADSPA_H'] == 1:
	#	obj.source += ' LADSPAPlugin.cpp LADSPANode.cpp '
	#if bld.env['HAVE_SLV2'] == 1:
	#	obj.source += ' LV2Plugin.cpp LV2Node.cpp '
	#obj.export_incdirs = ['.']
	#obj.includes     = ['.', '..', '../common', './events']
	#obj.name         = 'ingen_lv2'
	#obj.target       = 'ingen.lv2/ingen_lv2'
	#obj.install_path = ''
	#core_libs = 'GLIBMM GTHREAD LV2CORE SLV2 RAUL REDLANDMM'
	#autowaf.use_lib(bld, obj, core_libs)