#
# Copyright (C) 2007 Arnold Krille
# Copyright (C) 2007 Pieter Palmers
# Copyright (C) 2008 Marc-Olivier Barre
#
# This file originates from FFADO (www.ffado.org)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import os
from string import Template

Import( 'env' )

# paths where include files can be found
env.AppendUnique( CPPPATH=['#/', '#/common', '#/common/jack', '#/linux'] )

#
# Define the source files
#

srcfiles_linux_server = ['#/common/Jackdmp.cpp']

srcfiles_linux_alsa = [
    'JackAlsaDriver.cpp',
    'alsa_rawmidi.c',
    'alsa_seqmidi.c',
    'alsa_midi_jackmp.cpp',
    'memops.c',
    'generic_hw.c',
    'hdsp.c',
    'hammerfall.c',
    'ice1712.c'
    ]

for i in range(len(srcfiles_linux_alsa)):
    srcfiles_linux_alsa[i] = 'alsa/%s' % srcfiles_linux_alsa[i]

srcfiles_linux_freebob = ['freebob/JackFreebobDriver.cpp']
srcfiles_linux_ffado = ['firewire/JackFFADODriver.cpp']
srcfiles_linux_dummy = ['#/common/JackDummyDriver.cpp']

#
# Start building
#

# build the server and its backends
serverenv = env.Copy()
serverenv.PrependUnique( LIBPATH=env['build_base'] )
serverenv.PrependUnique( LIBS=[env['SERVERLIB'], 'dl'] )

server = serverenv.Program(env['SERVER'], srcfiles_linux_server)
serverenv.Install( env['INSTALL_BINDIR'], server )

driver_dir = env['INSTALL_ADDON_DIR'] + "/"

drv = serverenv.SharedLibrary( 'jack_dummy', srcfiles_linux_dummy )
serverenv.InstallAs( driver_dir + "jack_dummy.so", drv )

if env['ENABLE_ALSA']:
    if not env.GetOption('clean'):
        serverenv.MergeFlags( env['ALSA_FLAGS'] )
    drv = serverenv.SharedLibrary( 'jack_alsa', srcfiles_linux_alsa )
    serverenv.InstallAs( driver_dir + "jack_alsa.so", drv )

if env['ENABLE_FREEBOB']:
    if not env.GetOption('clean'):
        serverenv.MergeFlags( env['FREEBOB_FLAGS'] )
    drv = serverenv.SharedLibrary( 'jack_freebob', srcfiles_linux_freebob )
    serverenv.InstallAs( driver_dir + "jack_freebob.so", drv )

if env['ENABLE_FIREWIRE']:
    if not env.GetOption('clean'):
        serverenv.MergeFlags( env['FFADO_FLAGS'] )
    drv = serverenv.SharedLibrary( 'jack_firewire', srcfiles_linux_ffado )
    serverenv.InstallAs( driver_dir + "jack_firewire.so", drv )
