#! /usr/bin/env python
# encoding: utf-8
import os, os.path 


def options(opt):
    pass

def configure(conf):
    if not conf.env.LV2GUI:
        return None
    opt = conf.options
    env = conf.env
    conf.check_cfg(package='cairo', args=conf.env['OS_CAIRO_CFGFLAGS'], uselib_store='CAIRO', mandatory=1)
    if conf.env['OS'] == 'win32':
        # workaround: "-liconv" required at end of linker cmdline
        conf.env.append_value('STLIB_CAIRO', ['iconv'])
    else:
        conf.check_cc(lib='X11', uselib_store='X11', mandatory=True) and \
        conf.check_cc(header_name = 'X11/Xlib.h', uselib_store = 'X11', mandatory=1)

def build(bld):
    if not (bld.env.LV2GUI):
        return None

    images = bld.path.ant_glob('resources/*.png')
    targ = (''.join([' ./resources/%s.o'% os.path.splitext(v.name)[0] for v in images]))
    resources = targ.split()

    sources = bld.path.ant_glob('*.cpp')
    sources += bld.path.ant_glob('widgets/*.cpp')
    sources += bld.path.ant_glob('dialogs/*.cpp')
    sources += resources
    
    prog = bld(
        features=['cxx', 'cxxstlib'],
        name = 'xcairo',
        includes = ['.','./header','./header/widgets','./header/dialogs','./resources','./xdgmime'],
        export_includes = ['..'],
        source = sources,
        uselib = ['X11', 'CAIRO'],
        cxxflags='-fPIC',
        target = 'xcairo',
        use = 're_sources',
        )
    prog.install_path = None

