#!/usr/bin/env python
from waflib.extras import autowaf as autowaf

def build(bld):
    core_source = '''
            AudioBuffer.cpp
            BufferFactory.cpp
            ClientBroadcaster.cpp
            ConnectionImpl.cpp
            ControlBindings.cpp
            DuplexPort.cpp
            Engine.cpp
            EngineStore.cpp
            Event.cpp
            EventBuffer.cpp
            EventSource.cpp
            GraphObjectImpl.cpp
            InputPort.cpp
            InternalPlugin.cpp
            LV2Info.cpp
            LV2Node.cpp
            LV2Plugin.cpp
            MessageContext.cpp
            NodeFactory.cpp
            NodeImpl.cpp
            Notification.cpp
            ObjectBuffer.cpp
            ObjectSender.cpp
            OutputPort.cpp
            PatchImpl.cpp
            PluginImpl.cpp
            PortImpl.cpp
            PostProcessor.cpp
            ProcessContext.cpp
            ProcessSlave.cpp
            ServerInterfaceImpl.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/Move.cpp
            events/SetMetadata.cpp
            events/SetPortValue.cpp
            ingen_engine.cpp
            internals/Controller.cpp
            internals/Delay.cpp
            internals/Note.cpp
            internals/Trigger.cpp
    '''

    obj = bld(features        = 'cxx cxxshlib',
              source          = core_source,
              export_includes = ['../..'],
              includes        = ['.', '../..'],
              name            = 'libingen_server',
              target          = 'ingen_server',
              install_path    = '${LIBDIR}',
              use             = 'libingen_shared')
    core_libs = 'GLIBMM GTHREAD LV2CORE LILV RAUL SORD'
    autowaf.use_lib(bld, obj, core_libs)

    if bld.is_defined('HAVE_JACK'):
        obj = bld(features        = 'cxx cxxshlib',
                  source          = 'JackDriver.cpp ingen_jack.cpp',
                  includes        = ['.', '../..'],
                  name            = 'libingen_jack',
                  target          = 'ingen_jack',
                  install_path    = '${LIBDIR}',
                  use             = 'libingen_server')
        autowaf.use_lib(bld, obj, core_libs + ' JACK')

    # Ingen LV2 wrapper
    obj = bld(features     = 'cxx cxxshlib',
              source       = ' ingen_lv2.cpp ',
              includes     = ['.', '../..'],
              name         = 'libingen_lv2',
              target       = 'ingen_lv2',
              install_path = '${LV2DIR}/ingen.lv2/',
              use          = 'libingen_server libingen_shared')
    autowaf.use_lib(bld, obj, core_libs + ' LV2_STATE')