#!/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.2.0'

# Variables for 'waf dist'
APPNAME = 'non-session-manager'
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.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/session-manager.C
''',
              target       = 'non-session-manager',
              includes     = ['.', 'src', '../nonlib', '..' ],
              uselib = [  'LIBLO', 'XPM', 'NTK', 'NTK_IMAGES' ],
              use = [ 'fl_widgets', 'nonlib'],
              install_path = '${BINDIR}')

    bld.program( source = '''
src/nsmd.C
''',
              target       = 'nsmd',
              includes     = ['.', 'src', '../nonlib'],
              uselib = [  'LIBLO' ],
              use = [ 'nonlib'],
              install_path = '${BINDIR}')

    bld.program( source = '''
src/nsm-proxy.C
''',
              target       = 'nsm-proxy',
              includes     = ['.', 'src', '../nonlib', '..' ],
              uselib = [ 'LIBLO' ],
              use = [ 'nonlib'],
              install_path = '${BINDIR}')

    bld.program( source = '''
src/nsm-proxy-gui.C
src/NSM_Proxy_UI.fl
''',
              target       = 'nsm-proxy-gui',
              includes     = ['.', 'src'],
              uselib = [  'LIBLO', 'XPM', 'NTK', 'NTK_IMAGES ' ],
              install_path = '${BINDIR}')

    bld.program( source = '''
src/jackpatch.c
''',
              target       = 'jackpatch',
              includes     = ['.', 'src'],
              uselib = [ 'LIBLO', 'JACK' ],
              install_path = '${BINDIR}')


    bld.program( source = '''
src/send_osc.C
''',
              target       = 'send_osc',
              includes     = ['.', 'src', '../nonlib' ],
              uselib = [ 'LIBLO' ],
              use = [ 'nonlib'],
              install_path = None )

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

    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' ) )