#!/usr/bin/env python
# encoding: utf-8

import sys, os, TaskGen, ctypes

def configure(conf):
    pass

def build(bld):
    bundle = 'gxamp.lv2'
    
    src = ['gxamp.cpp',
           'DSP/gx_resampler.cc',
           'DSP/gx_convolver.cc'
           ]
    incl = ['../../','./', './DSP']
    lib = []
    if sys.platform.startswith("linux"):
        lib.append('dl')
    uselib = ['LV2CORE','GLIBMM']
    if bld.env['ZITA_CONVOLVER']:
        uselib.append('ZITA_CONVOLVER')
    else:
        src.append('../../zita-convolver/zita-convolver.cc')
        incl.append('../../zita-convolver');
        uselib.append('FFTW3')
    if bld.env['ZITA_RESAMPLER']:
        uselib.append('ZITA_RESAMPLER')
    else:
        src.append('../../zita-resampler-1.1.0/resampler.cc')
        src.append('../../zita-resampler-1.1.0/resampler-table.cc')
        incl.append('../../zita-resampler-1.1.0')
    cxxflag =[]
    if not bld.env['OPT']:
        cxxflag = [ "-msse2", "-mfpmath=sse"]
    lv2_plugin = bld(
        features='cxx cshlib ',
        includes = incl,
        lib = lib,
        uselib = uselib,
        obj_ext  = '_2.o',
        cxxflags = cxxflag,
        defines  = ["LV2_SO"],
        target   = 'gxamp',
        source   = src,
        install_path = '${LV2DIR}/%s' % bundle,
        chmod = 0o755,
        )
    lv2_plugin.env['shlib_PATTERN'] = '%s.so'
    
    uselib_local1 = []
    libpath1 = []
    lib1 = []
    incl = ['../../../libgxwmm','../../../libgxw']
    if sys.platform.startswith("linux"):
        lib1.append('dl')
    if bld.env["GX_LIB_SHARED"]:
        lib1 += ['gxwmm','gxw']
        libpath1 += [bld.path.find_dir("../../../libgxw/gxw").bldpath(bld.env),
                    bld.path.find_dir("../../../libgxwmm/gxwmm").bldpath(bld.env)]
    else:
        uselib_local1 += ['gxwmm','gxw']
    
    lv2_plugin_gui = bld(
        features='cxx cshlib ',
        includes = incl,
        lib = lib1,
        uselib = 'LV2CORE GTKMM',
        libpath = libpath1,
        uselib_local = uselib_local1,
        linkflags = '-Wl,-z,nodelete',
        defines  = ["LV2_GUI"],
        target   = 'gxamp_gui',
        source   = 'widget.cpp gxamp_gui.cpp',
        install_path = '${LV2DIR}/%s' % bundle,
        chmod = 0o755,
        )
    lv2_plugin_gui.env['shlib_PATTERN'] = '%s.so'

    
    install_path = '${LV2DIR}/%s' % bundle,
    bld.install_files('${LV2DIR}/gxamp.lv2', 'manifest.ttl')
    bld.install_files('${LV2DIR}/gxamp.lv2', 'gxamp.ttl')
    
    gxlv2style_files = [
        'GUI/amp21.png',
        'GUI/amp22.png',
        'GUI/amp23.png',
        'GUI/amp24.png',
        'GUI/amp25.png',
        'GUI/mastergain-label.png',
        'GUI/pregain-label.png',
        'GUI/drive-label.png',
        'GUI/distortion-label.png',
        'GUI/cabinet-label.png',
        'GUI/presence-label.png',
        'GUI/presence-label.png',
        'GUI/bass-label.png',
        'GUI/treble-label.png',
        'GUI/mid-label.png',
        'GUI/knob.png',
        'GUI/knob-middle.png',
        'GUI/knob-small.png',
        'GUI/metalic1-knob.png',
        'GUI/metalic1-knob-middle.png',
        'GUI/metalic1-knob-small.png',
        'GUI/black-knob.png',
        'GUI/black-knob-middle.png',
        'GUI/black-knob-small.png',]

    bld.install_files(bld.env['GX_STYLE_DIR'], gxlv2style_files, chmod=0o644)

