#!/usr/bin/env python

import waflib.Utils as Utils
import waflib.Options as Options


def options(ctx):
    opt = ctx.configuration_options()
    opt.add_option('--light-theme', action='store_true', dest='light_theme',
                   help='use light coloured theme')


def configure(conf):
    conf.check_pkg('glibmm-2.4 >= 2.14.0',
                   uselib_store='GLIBMM',
                   system=True,
                   mandatory=False)
    conf.check_pkg('gthread-2.0 >= 2.14.0',
                   uselib_store='GTHREAD',
                   system=True,
                   mandatory=False)
    conf.check_pkg('gtkmm-2.4 >= 2.14.0',
                   uselib_store='GTKMM',
                   system=True,
                   mandatory=False)
    conf.check_pkg('ganv-1 >= 1.5.4',
                   uselib_store='GANV',
                   mandatory=False)
    if not Options.options.no_webkit:
        conf.check_pkg('webkit-1.0 >= 1.4.0',
                       uselib_store='WEBKIT',
                       system=True,
                       mandatory=False)

    if conf.env.HAVE_GANV and conf.env.HAVE_GTKMM:
        conf.env.INGEN_BUILD_GUI = 1

    if Options.options.light_theme:
        conf.define('INGEN_USE_LIGHT_THEME', 1)


def build(bld):
    obj = bld(features        = 'cxx cxxshlib',
              cflags          = ['-fvisibility=hidden'],
              export_includes = ['../..'],
              includes        = ['../..'],
              name            = 'libingen_gui',
              target          = 'ingen_gui',
              install_path    = '${LIBDIR}',
              use             = 'libingen libingen_client',
              uselib          = '''
            GANV
            GLADEMM
            GLIBMM
            GNOMECANVAS
            GTKMM
            LILV
            LV2
            RAUL
            SIGCPP
            SERD
            SORD
            SRATOM
            SOUP
            SUIL
            WEBKIT
    ''')

    obj.source = '''
            App.cpp
            Arc.cpp
            BreadCrumbs.cpp
            ConnectWindow.cpp
            GraphBox.cpp
            GraphCanvas.cpp
            GraphPortModule.cpp
            GraphTreeWindow.cpp
            GraphView.cpp
            GraphWindow.cpp
            LoadGraphWindow.cpp
            LoadPluginWindow.cpp
            MessagesWindow.cpp
            NewSubgraphWindow.cpp
            NodeMenu.cpp
            NodeModule.cpp
            ObjectMenu.cpp
            PluginMenu.cpp
            Port.cpp
            PortMenu.cpp
            PropertiesWindow.cpp
            RDFS.cpp
            RenameWindow.cpp
            Style.cpp
            SubgraphModule.cpp
            ThreadedLoader.cpp
            URIEntry.cpp
            WidgetFactory.cpp
            WindowFactory.cpp
            ingen_gui.cpp
    '''

    # XML UI definition
    bld(features      = 'subst',
        source        = 'ingen_gui.ui',
        target        = '../../ingen_gui.ui',
        install_path  = '${DATADIR}/ingen',
        chmod         = Utils.O755,
        INGEN_VERSION = bld.env.INGEN_VERSION)

    # Gtk style
    bld(features      = 'subst',
        is_copy       = True,
        source        = 'ingen_style.rc',
        target        = '../../ingen_style.rc',
        install_path  = '${DATADIR}/ingen',
        chmod         = Utils.O755)

    # LV2 UI
    obj = bld(features     = 'cxx cxxshlib',
              cflags       = ['-fvisibility=hidden'],
              source       = 'ingen_gui_lv2.cpp',
              includes     = ['.', '../..'],
              name         = 'ingen_gui_lv2',
              target       = 'ingen_gui_lv2',
              install_path = '${LV2DIR}/ingen.lv2/',
              use          = 'libingen libingen_gui',
              uselib       = 'LV2 SERD SORD SRATOM LILV RAUL GLIBMM GTKMM')