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

def build(bld):
    core_source = '''
            AudioBuffer.cpp
            Broadcaster.cpp
            Buffer.cpp
            BufferFactory.cpp
            ControlBindings.cpp
            DuplexPort.cpp
            EdgeImpl.cpp
            Engine.cpp
            EngineStore.cpp
            EventWriter.cpp
            GraphObjectImpl.cpp
            InputPort.cpp
            InternalPlugin.cpp
            LV2Info.cpp
            LV2Node.cpp
            LV2Plugin.cpp
            MessageContext.cpp
            NodeFactory.cpp
            NodeImpl.cpp
            Notification.cpp
            OutputPort.cpp
            PatchImpl.cpp
            PortImpl.cpp
            PostProcessor.cpp
            PreProcessor.cpp
            ProcessContext.cpp
            ProcessSlave.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 LV2 LILV RAUL SORD'
    autowaf.use_lib(bld, obj, core_libs)

    if bld.env['BUILD_TESTS']:
        obj = bld(features        = 'cxx cxxshlib',
                  source          = core_source,
                  export_includes = ['../..'],
                  includes        = ['.', '../..'],
                  name            = 'libingen_server_profiled',
                  target          = 'ingen_server_profiled',
                  install_path    = '${LIBDIR}',
                  use             = 'libingen_shared_profiled',
                  lib             = bld.env['INGEN_TEST_LIBS'],
                  cxxflags        = bld.env['INGEN_TEST_CXXFLAGS'])
        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)