#!/usr/bin/python
# SConstruct file for CLAMprocessing
from buildtools import *
from buildtools.file_retriever import FileRetriever
from buildtools.rulesets import *

import os, sys

Import('processing_env version top install_dirs')

def define_module_contents(env) :
	if not os.path.exists('src') :
		os.mkdir('src')
	if not os.path.exists('include' ) :
		os.makedirs('include/CLAM')

	folders = [
		'src/Data/BasicProcessing',
		'src/Data/Descriptors',
		'src/Data/Descriptors/Melody',
		'src/Processing/Analysis',
		'src/Processing/Analysis/Tonal',
		'src/Processing/ArithOps',
		'src/Processing/Generators/',
		'src/Processing/Synthesis',
		'src/Processing/Transformations',
		'externals/numrec',
		'src/Processing/SDIFIO',
		'src/Tools/SDIF',
		'src/Processing/Default*.*xx',
		'src/Processing/SMS*.*xx',
		'src/Standard/ScaleCnv.*',
		'src/Processing/Transformations/SMS',
		'src/Processing/Transformations/Spectral',
		'src/Processing/Controls',
		'src/Visualization/Base',
		'src/Visualization/View',
		'src/Visualization/Util',
		'src/Visualization/QTVM/Network/Processings/PortMonitor*xx',
		]

	if sys.platform == 'win32':
		folders.append('src/Processing/InitProcessing*.*xx')

	blacklist = [
		'GT_FilterBank',
		'OnsetDetector',
		r'Audio\..+' ,
		'FileChooser',
		'MessageBox',
		'FLTKConfigurator',
		'QTConfigurator',
		'WidgetTKWrapper',
		'FDFilterController',
		'SupportedToolkits',
		]
	if not env.has_key('with_mad') or not env['with_mad'] :
		blacklist.append('MpegAudioStream')
	if not processing_env.has_key('with_osc_support') or not env['with_osc_support'] :
		blacklist.append('OSCSender')

	if not env.has_key('with_fftw3') or not env['with_fftw3'] :
		blacklist.append('.+fftw3.+')
	if not env.has_key('with_fftw') or not env['with_fftw'] :
		blacklist.append('.+rfftw.+')
	if not env.has_key('with_nr_fft') or not env['with_nr_fft'] :
		blacklist.append('.*numrecipes.+')
		blacklist.append('.+numrec.+')
	
	file_retriever = FileRetriever( top+'/..', folders, blacklist )

	file_retriever.scan_without_copy()

	realHeaders = []
	for orig,target in file_retriever.origTargetHeaders :
		env.CopyFileAndUpdateIncludes(target, orig)
		realHeaders.append(target)


	realSources = []
	for orig,target in file_retriever.origTargetSources:
		env.CopyFileAndUpdateIncludes(target,orig)
		realSources.append(target)
	return realHeaders, realSources

realHeaders, realSources = define_module_contents(processing_env)

moduleDependencies = ['core']

lib_tgt, install_tgt = lib_rules( 'processing', version, realHeaders, realSources, install_dirs, processing_env, moduleDependencies )

Return( 'lib_tgt', 'install_tgt' )
