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

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

def configure(conf):
    autowaf.check_pkg(conf, 'gtkmm-2.4', uselib_store='GTKMM',
                      atleast_version='2.12.0', mandatory=False)
    autowaf.check_pkg(conf, 'gtkmm-2.4', uselib_store='NEW_GTKMM',
                      atleast_version='2.14.0', mandatory=False)
    autowaf.check_pkg(conf, 'ganv-1', uselib_store='GANV',
                      atleast_version='1.5.4', mandatory=False)
    if not Options.options.no_webkit:
        autowaf.check_pkg(conf, 'webkit-1.0', uselib_store='WEBKIT',
                          atleast_version='1.4.0', mandatory=False)

    if conf.env.HAVE_GANV and conf.env.HAVE_GTKMM:
        autowaf.define(conf, 'INGEN_BUILD_GUI', 1)

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

def build(bld):
    obj = bld(features        = 'cxx cxxshlib',
              export_includes = ['../..'],
              includes        = ['../..'],
              name            = 'libingen_gui',
              target          = 'ingen_gui',
              install_path    = '${LIBDIR}',
              use             = 'libingen libingen_client')
    autowaf.use_lib(bld, obj, '''
            GANV
            GLADEMM
            GLIBMM
            GNOMECANVAS
            GTKMM
            LILV
            LV2
            RAUL
            SIGCPP
            SORD
            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',
              source       = 'ingen_gui_lv2.cpp',
              includes     = ['.', '../..'],
              name         = 'ingen_gui_lv2',
              target       = 'ingen_gui_lv2',
              install_path = '${LV2DIR}/ingen.lv2/',
              use          = 'libingen libingen_gui')
    autowaf.use_lib(bld, obj, 'LV2 SERD SORD LILV RAUL GLIBMM GTKMM')