# GARstow configuration
# Copyright 2003, 2004, 2005, 2006, 2007, 2009, 2010 Adam Sampson <ats@offog.org>

import sys, os

gar_dir = os.path.normpath(os.path.join(sys.path[0], ".."))

global_settings = {
	"root_dir": "",
	}

def set_root_dir(root):
	"""Set the root of the GARstow system being operated upon."""
	global_settings["root_dir"] = root

def in_root(path):
	"""Return a path inside the GARstow system being operated upon."""
	return global_settings["root_dir"] + path

def out_root(path):
	"""Remove the root prefix from a path."""
	root_dir = global_settings["root_dir"]
	if not path.startswith(root_dir):
		# FIXME: should probably throw an exception
		return path
	else:
		return path[len(root_dir):]

# FIXME This should be a package attribute.
def select_dep_type(dep):
	if dep == "gnome-doc-utils":
		return "BUILDDEPS"
	else:
		return "LIBDEPS"

gararch_kernels = {
	"Linux": "linux",
	}

gararch_cpus = {
	"i686": "ia32",
	}

def get_arch():
	"""Return the GARStow architecture string for the current system."""

	uname = os.uname()
	(kernel, cpu) = (uname[0], uname[4])
	if kernel not in gararch_kernels:
		die("Unknown kernel: ", kernel)
	if cpu not in gararch_cpus:
		die("Unknown CPU: ", cpu)
	return "%s-%s" % (gararch_kernels[kernel], gararch_cpus[cpu])


