#! /usr/bin/python

import os, glob, sys

libPaths = [
	('guitardistortion', 'GuitarDistortion'),
	('dcremoval', 'DCRemoval'),
	('audioswitch', 'AudioSwitch'),
	('automaticgaincontrol', 'AutomaticGainControl'),
]

def scanFiles(pattern, paths) :
	files = []
	for path in paths :
		files+=glob.glob(os.path.join(path,pattern))
	return files

def recursiveDirs(root) :
	return filter( (lambda a : a.rfind( ".svn")==-1 ),  [ a[0] for a in os.walk(root)]  )

options = Options('options.cache', ARGUMENTS)
options.Add(PathOption('clam_prefix', 'The prefix where CLAM was installed', '/bad/path'))
options.Add(PathOption('prefix', 'Installation prefix (normally /usr, by default this is clam_prefix)', "", validator=PathOption.PathAccept))
options.Add(BoolOption('crossmingw', 'Using MinGW crosscompiler mode', 'no') )

env = Environment(ENV=os.environ, options=options)
options.Save('options.cache', env)
Help(options.GenerateHelpText(env))
env.SConsignFile() # Single signature file

CLAMInstallDir = env['clam_prefix']
InstallDir = env['prefix'] or env['clam_prefix']
clam_sconstoolspath = os.path.join(CLAMInstallDir,'share','clam','sconstools')
if env['crossmingw'] :
	env.Tool('crossmingw', toolpath=[clam_sconstoolspath])
env.Tool('clam', toolpath=[clam_sconstoolspath])
env.EnableClamModules([
	'clam_core',
	'clam_audioio',
	'clam_processing',
	] , CLAMInstallDir)

if sys.platform=='linux2' :
	env.Append( CCFLAGS=['-g','-O3','-Wall'] )

libraries = [
	env.SharedLibrary(target=libraryName, source = scanFiles("*.cxx", recursiveDirs(dir))) 
		for libraryName, dir in libPaths
	]

examples = [
	'Dist1-rack.ui',
	'Dist1.clamnetwork',
	'Dist1.clamnetwork.pos',
	'TestAll.clamnetwork',
	'TestAll.clamnetwork.pos',
	]

install = [
	env.Install(os.path.join(InstallDir,'lib','clam'), libraries),
	env.Install(os.path.join(InstallDir,'share','networkeditor','example-data'), examples)
	]

env.Alias('install', install)
env.Default(libraries)


