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

def create_jack_driver_obj(bld, target, sources, uselib = None):
    driver = bld.create_obj('cpp', 'shlib')
    driver.features.append('cc')
    driver.env['shlib_PATTERN'] = 'jack_%s.so'
    driver.defines = ['HAVE_CONFIG_H','SERVER_SIDE']
    driver.includes = ['.', '../macosx', '../posix', '../common', '../common/jack']
    driver.target = target
    driver.source = sources
    driver.inst_var = bld.env()['ADDON_DIR']
    driver.inst_dir = '/'
    driver.uselib_local = 'serverlib'
    if uselib:
        driver.uselib = uselib
    return driver

def create_jack_audio_driver_obj(bld, target, sources, uselib = None):
    driver = bld.create_obj('cpp', 'shlib')
    driver.features.append('cc')
    driver.env['shlib_PATTERN'] = 'jack_%s.so'
    driver.defines = 'HAVE_CONFIG_H'
    driver.includes = ['.', '../macosx', '../posix', '../common', '../common/jack']
    driver.target = target
    driver.source = sources
    driver.inst_var = bld.env()['ADDON_DIR']
    driver.inst_dir = '/'
    driver.uselib_local = 'serverlib'
    driver.env.append_value("LINKFLAGS", "-framework CoreAudio -framework CoreServices -framework AudioUnit")
    if uselib:
        driver.uselib = uselib
    return driver

def build(bld):
    jackd = bld.create_obj('cpp', 'program')
    jackd.includes = ['.', '../macosx', '../posix', '../common', '../common/jack']
    jackd.defines = 'HAVE_CONFIG_H'
    jackd.source = ['../common/Jackdmp.cpp']
    jackd.uselib = 'PTHREAD DL'
    jackd.uselib_local = 'serverlib'
    jackd.env.append_value("LINKFLAGS", "-framework CoreFoundation")
    jackd.target = 'jackd'

    create_jack_driver_obj(bld, 'dummy', '../common/JackDummyDriver.cpp')

    create_jack_audio_driver_obj(bld, 'coreaudio', 'coreaudio/JackCoreAudioDriver.cpp')
    
    portaudio_src = [
        '../windows/JackPortAudioDriver.cpp',
	'../windows/JackPortAudioDevices.cpp',
    	]

    #create_jack_audio_driver_obj(bld, 'portaudio', portaudio_src)

    create_jack_driver_obj(bld, 'net', '../common/JackNetDriver.cpp')

