#!/usr/bin/env python
import subprocess
import waflib.Options as Options
import string
import os

# Version of this package (even if built as a child)
PACKAGE_VERSION = '1.9.5'

# Variables for 'waf dist'
APPNAME = 'non-sequencer'
VERSION = PACKAGE_VERSION

# Mandatory variables
top = '.'
out = 'build'

def options(opt):
    opt.load('compiler_c')
    opt.load('compiler_cxx')
    opt.load('gnu_dirs')

def configure(conf):
    conf.load('compiler_c')
    conf.load('compiler_cxx')
    conf.load('gnu_dirs')

    conf.check_cfg(package='sigc++-2.0', uselib_store='SIGCPP',
                      atleast_version='2.0.0', args="--cflags --libs",  mandatory=True)

    conf.define('VERSION', PACKAGE_VERSION)
    conf.define('SYSTEM_PATH', '/'.join( [ conf.env.DATADIR, APPNAME ] ) )
    conf.define('DOCUMENT_PATH', '/'.join( [ conf.env.DATADIR, 'doc' ] ) )
    conf.define('PIXMAP_PATH', '/'.join( [ conf.env.DATADIR, 'pixmaps' ] ) )

    conf.write_config_header('config.h', remove=False)

    print('')

def build(bld):

    libs = '' 

    bld.program( source = '''
src/NSM.C
src/NSM/Client.C
src/canvas.C
src/debug.C
src/event.C
src/event_list.C
src/grid.C
src/gui/draw.C
src/gui/event_edit.fl
src/gui/input.C
src/gui/ui.fl
src/instrument.C
src/jack.C
src/main.C
src/mapping.C
src/midievent.C
src/pattern.C
src/phrase.C
src/scale.C
src/sequence.C
src/smf.C
src/transport.C
''',
              target       = 'non-sequencer',
              includes     = ['.', 'src', 'src/gui', '../FL', '../nonlib'],
              use = ['nonlib', 'fl_widgets'],
              uselib = [ 'JACK', 'SIGCPP', 'LIBLO', 'XPM', 'NTK', 'NTK_IMAGES', 'PTHREAD'],
              install_path = '${BINDIR}')

    bld( features = 'subst',
         source = 'non-sequencer.desktop.in',
         target = 'non-sequencer.desktop',
         encoding = 'utf8',
         install_path = "${DATADIR}" + '/applications',
         BIN_PATH = bld.env.BINDIR )

    bld.install_files('/'.join( [ '${DATADIR}', APPNAME, 'instruments'] ), bld.path.ant_glob('instruments/*'))

    start_dir = bld.path.find_dir( 'icons/hicolor' )

    bld.install_files('${DATADIR}/icons/hicolor', start_dir.ant_glob('**/*.png'),
                      cwd=start_dir, relative_trick=True)

    bld.install_as('${DATADIR}/pixmaps/' + APPNAME + '/icon-256x256.png', 'icons/hicolor/256x256/apps/' + APPNAME + '.png')

    bld.install_files( '/'.join( [ '${DATADIR}/doc', APPNAME ] ), bld.path.ant_glob( 'doc/*.html doc/*.png' ) )