#encoding: latin-1

# libzzub, Buz, Aldrin
# Modular Sequencer
# Copyright (C) 2006 The Aldrin Development Team
#
# 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 2
# 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

Import('env', 'posix', 'win32', 'install_lib', 'cl', 'gcc', 'install_plugin', 'install_plugin_help', 'vs_projects')
import glob, os

#######################################
#
# zzub plugins
#
#######################################

# this code basically just scans subdirectories for additional sconscript files
# and also provides a context for that sconscript to build a plugin.
# this allows the plugin sconscript to be as tiny as possible, and still
# enables us to generate project files and the like.

plugin_dir_path = ""
pluginenv = None
def build_plugin(localenv, libname, files, helpfiles=None):
	global vs_projects
	files = [plugin_dir_path + "/" + filename for filename in files]
	if win32:
		files.append('../zzub_plugin.def')
	plugin = localenv.SharedLibrary('${LIB_BUILD_PATH}/zzub/'+libname, files)
	if hasattr(localenv, 'MSVSProject'):
		localenv.MSVSProject(target = libname + localenv['MSVSPROJECTSUFFIX'],
			srcs = glob.glob(plugin_dir_path + "/" + '*.cpp'),
			incs = glob.glob(plugin_dir_path + "/" + '*.h'),
			buildtarget = plugin[0],
			variant = 'Debug',
			auto_build_solution=0)
		vs_projects+=[plugin_dir_path + '/' + libname + localenv.subst('$MSVSPROJECTSUFFIX') ]
	install_plugin(plugin)
	if helpfiles:
		helpsrcdir = '${ROOTPATH}/share/doc/zzub/plugins/'+libname+'/'
		install_plugin_help(libname, [helpsrcdir+filename for filename in helpfiles])

Export('build_plugin')

for filename in os.listdir('.'):
	plugin_dir_path = os.path.abspath(filename)
	if os.path.isfile(os.path.join(plugin_dir_path,'SConscript')):
		pluginenv = env.Copy()
		Export('plugin_dir_path','pluginenv')
		env.SConscript(os.path.join(plugin_dir_path,'SConscript'))
