#! /usr/bin/python
import os, glob, sys

moduleName='guitareffects'
version = "1.4.0"
description = "Guitar effects for the CLAM framework"
url = 'http://clam-project.org'
clamDependencies = [
	'clam_core',
	'clam_audioio',
	'clam_processing',
	]
otherDependencies = [
	]
libPaths = [
	('guitardistortion', 'GuitarDistortion'),
	('zyndistortion', 'ZynDistortion'),
	('dcremoval', 'DCRemoval'),
	('audioswitch', 'AudioSwitch'),
	('automaticgaincontrol', 'AutomaticGainControl'),
	('timedelay', 'TimeDelay'),
	('audionormalization', 'AudioNormalization'),
	('clipping', 'Clipping'),
]

options = Variables('options.cache', ARGUMENTS)
options.Add(PathVariable('clam_prefix', 'The prefix where CLAM was installed', '/usr/local'))
options.Add(BoolVariable('verbose', 'Display the full command line', 'no') )
options.Add(PathVariable('prefix', 'Installation prefix (normally /usr, by default this is clam_prefix)', "", validator=PathVariable.PathAccept))
options.Add(BoolVariable('crossmingw', 'Using MinGW crosscompiler mode', 'no') )

toolChain = 'default'
if sys.platform == "win32": toolChain = 'mingw'
env = Environment(ENV=os.environ, tools=[toolChain], options=options)
options.Save('options.cache', env)
Help(options.GenerateHelpText(env))
env.SConsignFile() # Single signature file

CLAMInstallDir = env['clam_prefix']
if not env['prefix'] : env['prefix'] = env['clam_prefix']

clam_sconstoolspath = os.path.join(CLAMInstallDir,'share','clam','sconstools')
if not os.access(os.path.join(clam_sconstoolspath,"clam.py"),os.R_OK):
	raise Exception("CLAM not installed at '%s'. Use clam_prefix option."%CLAMInstallDir)
if env['crossmingw'] :
	env.Tool('crossmingw', toolpath=[clam_sconstoolspath])
env.Tool('clam', toolpath=[clam_sconstoolspath])
env.EnableClamModules(clamDependencies, CLAMInstallDir)

examples = [
	'Dist1-rack.ui',
	'Dist1.clamnetwork',
	'TestAll.clamnetwork',
	'SimpleDistortionNetwork.clamnetwork',
	]
dirs = sum((
	env.recursiveDirs(dir)
	for libraryName, dir in libPaths
	),[])

env.Append( CCFLAGS=['-g','-O3','-Wall'] )

install, default = env.ClamModule(
	moduleName,
	version,
	description = description,
	url = url,
	sources = env.scanFiles("*.cxx", dirs),
	headers = env.scanFiles("*.hxx", dirs),
	clamDependencies = clamDependencies,
	otherDependencies = otherDependencies,
	)

install += [
	env.Install(os.path.join(env['prefix'],'share','networkeditor','example-data'), examples)
	]

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

