MAJOR = 5
MINOR = 1
BUG   = 0

CONFIG={"FLAGS":[]}
def read_config():
	for line in open("config"):
		(key, value) = line.strip().split("=")
		CONFIG[key] = value
		if value == "y":
			CONFIG["FLAGS"] += ["-D"+key]
read_config()

FLAGS = ["-O2"]
if CONFIG["DEBUG"] == "y":
	FLAGS = ["-Wall", "-Werror", "-g"]

env = Environment(CCFLAGS = FLAGS + CONFIG["FLAGS"])
if ARGUMENTS.get('VERBOSE') != "1":
	env.Append(CXXCOMSTR = "CXX $TARGET")
	env.Append(LINKCOMSTR = "Linking $TARGET")
env.Append(CPPPATH = "include")

env.ParseConfig('pkg-config --cflags --libs gtk+-2.0')
env.ParseConfig('pkg-config --cflags --libs gstreamer-0.10')
env.ParseConfig('pkg-config --cflags --libs taglib')

def version_h():
	f = open("include/version.h", "w")
	for line in open("include/version.tmpl", "r"):
		line = line.replace("__MAJOR__", str(MAJOR))
		line = line.replace("__MINOR__", str(MINOR))
		line = line.replace("__BUG__",   str(BUG))
		line = line.replace("__EXTRA__", CONFIG["EXTRA"])
		f.write(line)
	f.close()
version_h()

def list_dirs(directory):
	import os
	dirs  = [x[0] for x in os.walk(directory)]
	return [Glob(dir + "/*.cpp") for dir in dirs]

ocarina=env.Program('ocarina.bin', list_dirs('libsaria') + list_dirs('ocarina'))
Clean(ocarina, "include/version.h")
