import os

target="xmmsclient"
source=["rb_xmmsclient_main.c", "rb_xmmsclient.c", "rb_result.c"]
loadable=True
static=False

def config(env):
	if env.tryaction ("ruby --version") :
		# we require ruby 1.8 or greater
		print "Checking for Ruby 1.8 or greater... ",

		version = env.run("ruby -e 'puts defined?(VERSION) ? VERSION : RUBY_VERSION'").strip()
		if not version or [int(a) for a in version.split(".")] < [1, 8] :
			print "no"
			raise ConfigError("Need ruby 1.8")

		print version

		got_ruby_h = env.run("ruby -rrbconfig -e 'puts File.exist?(Config::CONFIG[\"archdir\"] + \"/ruby.h\")'").strip()
		if got_ruby_h != "true" :
			raise ConfigError("bad")

		cmd = "ruby -rrbconfig -e 'puts \"-I%s -L%s\" % [].fill(Config::CONFIG[\"archdir\"], 0..1)'"
		env.configcmd(cmd)
		if env.has_key("RUBYARCHDIR"):
			env.librarypath = env["RUBYARCHDIR"]
		else:
			cmd = "ruby -rrbconfig -e 'print Config::CONFIG[\"sitearchdir\"]'"
			env.librarypath = os.popen(cmd).read().strip()

		env.Prepend(LIBPATH="src/clients/lib/xmmsclient")
		env.Append(LIBS=["xmmsclient"])
		env["SHLIBPREFIX"]=''
		if env.platform == 'darwin':
			env["SHLIBSUFFIX"] = ".bundle"

		return
	raise ConfigError("Ruby baaad - money goood")

