namespace Usm { public class Paths { public string destination { get; set; } public string prefix { get; set; } public string bin { get; set; } public string include { get; set; } public string data { get; set; } public string info { get; set; } public string lib { get; set; } public string man { get; set; } public string libexec { get; set; } public string locale { get; set; } public string local_state { get; set;} public string sbin { get; set; } public string shared_state { get; set; } public string sys_config { get; set; } public string tags { get; set; } public string usm_config_dir { get; set; } public void set_envs() { Environment.set_variable("DESTDIR", destination, true); Environment.set_variable("PREFIX", prefix, true); Environment.set_variable("BINDIR", bin, true); Environment.set_variable("INCLUDEDIR", include, true); Environment.set_variable("DATADIR", data, true); Environment.set_variable("INFODIR", info, true); Environment.set_variable("LIBDIR", lib, true); Environment.set_variable("MANDIR", man, true); Environment.set_variable("LIBEXECDIR", libexec, true); Environment.set_variable("LOCALEDIR", locale, true); Environment.set_variable("LOCALSTATEDIR", local_state, true); Environment.set_variable("SBINDIR", sbin, true); Environment.set_variable("SHAREDSTATEDIR", shared_state, true); Environment.set_variable("SYSCONFIGDIR", sys_config, true); Environment.set_variable("TAGSDIR", tags, true); } public string get_suggested_base_path_for_type(ResourceType type) { switch (type) { case ResourceType.ROOT_PATH: return destination; case ResourceType.PATH: return Path.build_filename(destination, prefix); case ResourceType.OPTIONAL: return Path.build_filename(destination, "opt"); case Usm.ResourceType.RESOURCE: return Path.build_filename(destination, prefix, data); case ResourceType.CONFIGURATION: return Path.build_filename(destination, sys_config); case Usm.ResourceType.BINARY: return Path.build_filename(destination, prefix, bin); case Usm.ResourceType.SUPER_BINARY: return Path.build_filename(destination, prefix, sbin); case Usm.ResourceType.LIBRARY: return Path.build_filename(destination, prefix, lib); case Usm.ResourceType.LIBRARY_EXECUTABLE: return Path.build_filename(destination, prefix, libexec); case Usm.ResourceType.LIBRARY_RESOURCE: return Path.build_filename(destination, prefix, lib); case Usm.ResourceType.INFO_PAGE: return Path.build_filename(destination, prefix, info); case Usm.ResourceType.MANUAL_PAGE: return Path.build_filename(destination, prefix, man); case Usm.ResourceType.LOCALE: return Path.build_filename(destination, prefix, locale); case Usm.ResourceType.APPLICATION: return Path.build_filename(destination, prefix, "share", "applications"); case Usm.ResourceType.INCLUDE: return Path.build_filename(destination, prefix, include); case Usm.ResourceType.PKG_CONFIG: return Path.build_filename(destination, prefix, lib, "pkgconfig"); case Usm.ResourceType.VALA_API: return Path.build_filename(destination, prefix, "share", "vala", "vapi"); case Usm.ResourceType.GOBJECT_IR: return Path.build_filename(destination, prefix, "share", "gir-1.0"); case Usm.ResourceType.TYPELIB: return Path.build_filename(destination, prefix, lib, "girepository-1.0"); case Usm.ResourceType.TAG: return Path.build_filename(destination, prefix, tags); default: assert_not_reached(); } } public string get_suggested_path_for_resource(ResourceRef resource) { if (resource.resource_type == ResourceType.TAG) { return get_tag_file_path(resource.resource); } return Path.build_filename(get_suggested_base_path_for_type(resource.resource_type), resource.resource); } public string get_tag_file_path(string tag) { var tag_path = tag.replace(".", "/"); tag_path += ".tag"; return Path.build_filename(destination, prefix, tags, tag_path); } public string get_tag_dir_path(string tag) { var tag_path = tag.replace(".", "/"); return Path.build_filename(destination, prefix, tags, tag_path); } public Paths.defaults() { destination = "/"; prefix = "/usr"; bin = "bin"; include = "include"; data = "share"; info = "share/info"; lib = sizeof(void*) == 8 ? "lib64" : "lib"; man = "share/man"; libexec = "libexec"; locale = "share/locale"; local_state = "var"; sbin = "sbin"; shared_state = "com"; sys_config = "etc"; tags = "share/usm-tags"; usm_config_dir = "/etc/usm"; } public Paths.usm_environ() { var defaults = new Paths.defaults(); destination = Environment.get_variable("USM_DESTDIR") ?? defaults.destination; prefix = Environment.get_variable("USM_PREFIX") ?? defaults.prefix; bin = Environment.get_variable("USM_BINDIR") ?? defaults.bin; include = Environment.get_variable("USM_INCLUDEDIR") ?? defaults.include; data = Environment.get_variable("USM_DATADIR") ?? defaults.data; info = Environment.get_variable("USM_INFODIR") ?? defaults.info; lib = Environment.get_variable("USM_LIBDIR") ?? defaults.lib; man = Environment.get_variable("USM_MANDIR") ?? defaults.man; libexec = Environment.get_variable("USM_LIBEXECDIR") ?? defaults.libexec; locale = Environment.get_variable("USM_LOCALEDIR") ?? defaults.locale; local_state = Environment.get_variable("USM_LOCALSTATEDIR") ?? defaults.local_state; sbin = Environment.get_variable("USM_SBINDIR") ?? defaults.sbin; shared_state = Environment.get_variable("USM_SHAREDSTATEDIR") ?? defaults.shared_state; sys_config = Environment.get_variable("USM_SYSCONFIGDIR") ?? defaults.sys_config; tags = Environment.get_variable("USM_TAGSDIR") ?? defaults.tags; usm_config_dir = Environment.get_variable("USM_CONFIGDIR") ?? defaults.usm_config_dir; } public Paths clone() { return new Paths() { destination = destination, prefix = prefix, bin = bin, include = include, data = data, info = info, lib = lib, man = man, libexec = libexec, locale = locale, local_state = local_state, sbin = sbin, shared_state = shared_state, sys_config = sys_config, tags = tags, usm_config_dir = usm_config_dir, }; } } }