Import('env')
import os

def build_setup(target, source, env):
    open(str(target[0]), 'w').write( open(str(source[0]), 'r').read() )
    os.chmod(str(target[0]), 0755)
    return 0

try:
	import pyexpat
	print "pyexpat found, musetup will run properly."
except:
	print "\nWARNING: pyexpat not found, musetup will NOT run, but will be installed."

targets = [env.Command('musetup', ['musetup.in'], build_setup)]
manfile = ["musetup.1"]

if env["MUSETUPGTK"]:
	try:
		import gtk
		print "PyGTK found, musetup-gtk will run properly."
	except:
		try:
			import pygtk
			print "PyGTK found, musetup-gtk will run properly."
		except:
			print "\nWARNING: PyGTK not found, musetup-gtk will NOT run, but will be installed."
	
	targets.append('musetup-gtk')
	manfile.append ("musetup-gtk.1")
if 'swig' in env['TOOLS']:
	targets.append('mulog')
	targets.append('museekcontrol')
	manfile.append("mulog.1")
 	manfile.append("museekcontrol.1")
	print "SWIG found, mulog and museekcontrol will be installed."
else:
	print "WARNING: SWIG not found, mulog and museekcontrol will NOT be installed."

man_install = env.Install(env['DESTDIR'] + env['MANDIR'], manfile)

install = env.Install(env['DESTDIR'] + env['BINDIR'], targets)
env.Alias('install_pymuseekd', man_install)
env.Alias('install_pymuseekd', install)
env.Alias('install', 'install_pymuseekd')

if 'swig' in env['TOOLS']:
	SConscript(os.path.join('museek', 'SConscript'))
