Paths.vala 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. namespace Usm {
  2. public class Paths {
  3. public string destination { get; set; }
  4. public string prefix { get; set; }
  5. public string bin { get; set; }
  6. public string include { get; set; }
  7. public string data { get; set; }
  8. public string info { get; set; }
  9. public string lib { get; set; }
  10. public string man { get; set; }
  11. public string libexec { get; set; }
  12. public string locale { get; set; }
  13. public string local_state { get; set;}
  14. public string sbin { get; set; }
  15. public string shared_state { get; set; }
  16. public string sys_config { get; set; }
  17. public string tags { get; set; }
  18. public string usm_config_dir { get; set; }
  19. public void set_envs() {
  20. Environment.set_variable("DESTDIR", destination, true);
  21. Environment.set_variable("PREFIX", prefix, true);
  22. Environment.set_variable("BINDIR", bin, true);
  23. Environment.set_variable("INCLUDEDIR", include, true);
  24. Environment.set_variable("DATADIR", data, true);
  25. Environment.set_variable("INFODIR", info, true);
  26. Environment.set_variable("LIBDIR", lib, true);
  27. Environment.set_variable("MANDIR", man, true);
  28. Environment.set_variable("LIBEXECDIR", libexec, true);
  29. Environment.set_variable("LOCALEDIR", locale, true);
  30. Environment.set_variable("LOCALSTATEDIR", local_state, true);
  31. Environment.set_variable("SBINDIR", sbin, true);
  32. Environment.set_variable("SHAREDSTATEDIR", shared_state, true);
  33. Environment.set_variable("SYSCONFIGDIR", sys_config, true);
  34. Environment.set_variable("TAGSDIR", tags, true);
  35. }
  36. public string get_suggested_base_path_for_type(ResourceType type) {
  37. switch (type) {
  38. case ResourceType.ROOT_PATH:
  39. return destination;
  40. case ResourceType.PATH:
  41. return Path.build_filename(destination, prefix);
  42. case ResourceType.OPTIONAL:
  43. return Path.build_filename(destination, "opt");
  44. case Usm.ResourceType.RESOURCE:
  45. return Path.build_filename(destination, prefix, data);
  46. case ResourceType.CONFIGURATION:
  47. return Path.build_filename(destination, sys_config);
  48. case Usm.ResourceType.BINARY:
  49. return Path.build_filename(destination, prefix, bin);
  50. case Usm.ResourceType.SUPER_BINARY:
  51. return Path.build_filename(destination, prefix, sbin);
  52. case Usm.ResourceType.LIBRARY:
  53. return Path.build_filename(destination, prefix, lib);
  54. case Usm.ResourceType.LIBRARY_EXECUTABLE:
  55. return Path.build_filename(destination, prefix, libexec);
  56. case Usm.ResourceType.LIBRARY_RESOURCE:
  57. return Path.build_filename(destination, prefix, lib);
  58. case Usm.ResourceType.INFO_PAGE:
  59. return Path.build_filename(destination, prefix, info);
  60. case Usm.ResourceType.MANUAL_PAGE:
  61. return Path.build_filename(destination, prefix, man);
  62. case Usm.ResourceType.LOCALE:
  63. return Path.build_filename(destination, prefix, locale);
  64. case Usm.ResourceType.APPLICATION:
  65. return Path.build_filename(destination, prefix, "share", "applications");
  66. case Usm.ResourceType.INCLUDE:
  67. return Path.build_filename(destination, prefix, include);
  68. case Usm.ResourceType.PKG_CONFIG:
  69. return Path.build_filename(destination, prefix, lib, "pkgconfig");
  70. case Usm.ResourceType.VALA_API:
  71. return Path.build_filename(destination, prefix, "share", "vala", "vapi");
  72. case Usm.ResourceType.GOBJECT_IR:
  73. return Path.build_filename(destination, prefix, "share", "gir-1.0");
  74. case Usm.ResourceType.TYPELIB:
  75. return Path.build_filename(destination, prefix, lib, "girepository-1.0");
  76. case Usm.ResourceType.TAG:
  77. return Path.build_filename(destination, prefix, tags);
  78. default:
  79. assert_not_reached();
  80. }
  81. }
  82. public string get_suggested_path_for_resource(ResourceRef resource) {
  83. if (resource.resource_type == ResourceType.TAG) {
  84. return get_tag_file_path(resource.resource);
  85. }
  86. return Path.build_filename(get_suggested_base_path_for_type(resource.resource_type), resource.resource);
  87. }
  88. public string get_tag_file_path(string tag) {
  89. var tag_path = tag.replace(".", "/");
  90. tag_path += ".tag";
  91. return Path.build_filename(destination, prefix, tags, tag_path);
  92. }
  93. public string get_tag_dir_path(string tag) {
  94. var tag_path = tag.replace(".", "/");
  95. return Path.build_filename(destination, prefix, tags, tag_path);
  96. }
  97. public Paths.defaults() {
  98. destination = "/";
  99. prefix = "/usr";
  100. bin = "bin";
  101. include = "include";
  102. data = "share";
  103. info = "share/info";
  104. lib = sizeof(void*) == 8 ? "lib64" : "lib";
  105. man = "share/man";
  106. libexec = "libexec";
  107. locale = "share/locale";
  108. local_state = "var";
  109. sbin = "sbin";
  110. shared_state = "com";
  111. sys_config = "etc";
  112. tags = "share/usm-tags";
  113. usm_config_dir = "/etc/usm";
  114. }
  115. public Paths.usm_environ() {
  116. var defaults = new Paths.defaults();
  117. destination = Environment.get_variable("USM_DESTDIR") ?? defaults.destination;
  118. prefix = Environment.get_variable("USM_PREFIX") ?? defaults.prefix;
  119. bin = Environment.get_variable("USM_BINDIR") ?? defaults.bin;
  120. include = Environment.get_variable("USM_INCLUDEDIR") ?? defaults.include;
  121. data = Environment.get_variable("USM_DATADIR") ?? defaults.data;
  122. info = Environment.get_variable("USM_INFODIR") ?? defaults.info;
  123. lib = Environment.get_variable("USM_LIBDIR") ?? defaults.lib;
  124. man = Environment.get_variable("USM_MANDIR") ?? defaults.man;
  125. libexec = Environment.get_variable("USM_LIBEXECDIR") ?? defaults.libexec;
  126. locale = Environment.get_variable("USM_LOCALEDIR") ?? defaults.locale;
  127. local_state = Environment.get_variable("USM_LOCALSTATEDIR") ?? defaults.local_state;
  128. sbin = Environment.get_variable("USM_SBINDIR") ?? defaults.sbin;
  129. shared_state = Environment.get_variable("USM_SHAREDSTATEDIR") ?? defaults.shared_state;
  130. sys_config = Environment.get_variable("USM_SYSCONFIGDIR") ?? defaults.sys_config;
  131. tags = Environment.get_variable("USM_TAGSDIR") ?? defaults.tags;
  132. usm_config_dir = Environment.get_variable("USM_CONFIGDIR") ?? defaults.usm_config_dir;
  133. }
  134. public Paths clone() {
  135. return new Paths() {
  136. destination = destination,
  137. prefix = prefix,
  138. bin = bin,
  139. include = include,
  140. data = data,
  141. info = info,
  142. lib = lib,
  143. man = man,
  144. libexec = libexec,
  145. locale = locale,
  146. local_state = local_state,
  147. sbin = sbin,
  148. shared_state = shared_state,
  149. sys_config = sys_config,
  150. tags = tags,
  151. usm_config_dir = usm_config_dir,
  152. };
  153. }
  154. }
  155. }