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

def create_jack_driver_obj(bld, target, sources, uselib = None):
    driver = bld.new_task_gen('cxx', '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.install_path = '${ADDON_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.new_task_gen('cxx', '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.install_path = '${ADDON_DIR}/'
    driver.uselib_local = 'serverlib'
    driver.env.append_value("LINKFLAGS", "-framework CoreAudio -framework CoreServices -framework AudioUnit")
    if uselib:
        driver.uselib = uselib
    return driver

def create_jack_midi_driver_obj(bld, target, sources, uselib = None):
    driver = bld.new_task_gen('cxx', '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.install_path = '${ADDON_DIR}/'
    driver.uselib_local = 'serverlib'
    driver.env.append_value("LINKFLAGS", "-framework CoreMIDI -framework CoreServices -framework AudioUnit")
    if uselib:
        driver.uselib = uselib
    return driver

def build(bld):
    if bld.env['BUILD_JACKD'] == True:
    	jackd = bld.new_task_gen('cxx', '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_driver_obj(bld, 'loopback', '../common/JackLoopbackDriver.cpp')

    create_jack_audio_driver_obj(bld, 'coreaudio', 'coreaudio/JackCoreAudioDriver.cpp')

    create_jack_midi_driver_obj(bld, 'coremidi', 'coremidi/JackCoreMidiDriver.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')

    create_jack_driver_obj(bld, 'netone', [ '../common/JackNetOneDriver.cpp',
		                            '../common/netjack.c',
					    '../common/netjack_packet.c' ], "SAMPLERATE CELT" )
