Advertisement
tomkiewicz

fhs-5

Apr 24th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 11.89 KB | None | 0 0
  1. diff --git a/config.h.mingw b/config.h.mingw
  2. --- a/config.h.mingw
  3. +++ b/config.h.mingw
  4. @@ -406,10 +406,10 @@
  5.   */
  6.  #define HAVE_VSNPRINTF 1
  7.  
  8. -#define FINCH_LIBDIR wpurple_lib_dir()
  9. -#define PIDGIN_LIBDIR wpurple_lib_dir()
  10. -#define PURPLE_DATADIR wpurple_install_dir()
  11. -#define PURPLE_LIBDIR wpurple_lib_dir()
  12. +#define FINCH_LIBDIR wpurple_lib_dir(NULL)
  13. +#define PIDGIN_LIBDIR wpurple_lib_dir(NULL)
  14. +#define PURPLE_DATADIR wpurple_bin_dir()
  15. +#define PURPLE_LIBDIR wpurple_lib_dir(NULL)
  16.  #define PURPLE_LOCALEDIR wpurple_locale_dir()
  17.  #define PURPLE_SYSCONFDIR wpurple_sysconf_dir()
  18.  
  19. diff --git a/configure.ac b/configure.ac
  20. --- a/configure.ac
  21. +++ b/configure.ac
  22. @@ -177,12 +177,46 @@
  23.  
  24.  AC_C_BIGENDIAN
  25.  
  26. +AC_ARG_WITH(win32-dirs, [AS_HELP_STRING([--with-win32-dirs=<classic|fhs>],
  27. +   [use win32 classic (Program Files-like) or FHS (unix-like) directory structure (default: classic)])], [
  28. +       if test "x$withval" != "xclassic" -a "x$withval" != "xfhs" ; then
  29. +           AC_MSG_ERROR([Unsupported win32-dirs option. Please choose "classic" or "fhs".])
  30. +       fi
  31. +       with_win32_dirs="$withval"
  32. +   ], with_win32_dirs="classic")
  33. +if test "x$is_win32" = "xyes" -a "x$with_win32_dirs" = "xfhs" ; then
  34. +   AC_DEFINE(USE_WIN32_FHS, 1, [Define to 1, to use FHS on win32.])
  35. +fi
  36. +
  37.  dnl Check for directories
  38.  if test "x$is_win32" = "xyes" ; then
  39. -   purple_datadir="wpurple_install_dir()"
  40. -   purple_libdir="wpurple_lib_dir()"
  41. -   pidgin_libdir="wpurple_lib_dir()"
  42. -   finch_libdir="wpurple_lib_dir()"
  43. +   if test "x$with_win32_dirs" = "xfhs" ; then
  44. +       AS_AC_EXPAND(win32_fhs_bindir, "$bindir")
  45. +       AC_DEFINE_UNQUOTED([WIN32_FHS_BINDIR], ["$win32_fhs_bindir"],
  46. +           [bindir, as defined by configure])
  47. +       AS_AC_EXPAND(win32_fhs_libdir, "$libdir")
  48. +       AC_DEFINE_UNQUOTED([WIN32_FHS_LIBDIR], ["$win32_fhs_libdir"],
  49. +           [libdir, as defined by configure])
  50. +       AS_AC_EXPAND(win32_fhs_datadir, "$datadir")
  51. +       AC_DEFINE_UNQUOTED([WIN32_FHS_DATADIR], ["$win32_fhs_datadir"],
  52. +           [datadir, as defined by configure])
  53. +       AS_AC_EXPAND(win32_fhs_sysconfdir, "$sysconfdir")
  54. +       AC_DEFINE_UNQUOTED([WIN32_FHS_SYSCONFDIR], ["$win32_fhs_sysconfdir"],
  55. +           [sysconfdir, as defined by configure])
  56. +       AS_AC_EXPAND(win32_fhs_localedir, "$localedir")
  57. +       AC_DEFINE_UNQUOTED([WIN32_FHS_LOCALEDIR], ["$win32_fhs_localedir"],
  58. +           [localedir, as defined by configure])
  59. +
  60. +       purple_libdir="wpurple_lib_dir(\"purple-$PURPLE_MAJOR_VERSION\")"
  61. +       pidgin_libdir="wpurple_lib_dir(\"pidgin-$PURPLE_MAJOR_VERSION\")"
  62. +       finch_libdir="wpurple_lib_dir(\"finch-$PURPLE_MAJOR_VERSION\")"
  63. +   else
  64. +       purple_libdir="wpurple_lib_dir(NULL)"
  65. +       pidgin_libdir="wpurple_lib_dir(NULL)"
  66. +       finch_libdir="wpurple_lib_dir(NULL)"
  67. +   fi
  68. +
  69. +   purple_datadir="wpurple_data_dir()"
  70.     purple_sysconfdir="wpurple_sysconf_dir()"
  71.     purple_localedir="wpurple_locale_dir()"
  72.  else
  73. diff --git a/libpurple/certificate.c b/libpurple/certificate.c
  74. --- a/libpurple/certificate.c
  75. +++ b/libpurple/certificate.c
  76. @@ -922,7 +922,7 @@
  77.         x509_ca_paths = g_list_append(x509_ca_paths,
  78.             g_strdup(SSL_CERTIFICATES_DIR));
  79.  #endif
  80. -#ifdef _WIN32
  81. +#if defined(_WIN32) && !defined(USE_WIN32_FHS)
  82.         x509_ca_paths = g_list_append(x509_ca_paths, g_build_filename(
  83.             PURPLE_DATADIR, "ca-certs", NULL));
  84.  #else
  85. diff --git a/libpurple/protocols/jabber/jabber.c b/libpurple/protocols/jabber/jabber.c
  86. --- a/libpurple/protocols/jabber/jabber.c
  87. +++ b/libpurple/protocols/jabber/jabber.c
  88. @@ -3814,7 +3814,7 @@
  89.     if (!sasl_initialized) {
  90.         sasl_initialized = TRUE;
  91.  #ifdef _WIN32
  92. -       sasldir = g_build_filename(wpurple_install_dir(), "sasl2", NULL);
  93. +       sasldir = g_build_filename(wpurple_bin_dir(), "sasl2", NULL);
  94.         sasl_set_path(SASL_PATH_TYPE_PLUGIN, sasldir);
  95.         g_free(sasldir);
  96.         /* Suppress error popups for failing to load sasl plugins */
  97. diff --git a/libpurple/win32/win32dep.c b/libpurple/win32/win32dep.c
  98. --- a/libpurple/win32/win32dep.c
  99. +++ b/libpurple/win32/win32dep.c
  100. @@ -29,10 +29,12 @@
  101.  #include "glibcompat.h"
  102.  #include "notify.h"
  103.  
  104. +#define MAX_PATH_LEN 2048
  105. +
  106.  /*
  107.   * LOCALS
  108.   */
  109. -static char *app_data_dir = NULL, *install_dir = NULL,
  110. +static char *app_data_dir = NULL, *bin_dir = NULL, *data_dir = NULL,
  111.     *lib_dir = NULL, *locale_dir = NULL, *sysconf_dir = NULL;
  112.  
  113.  static HINSTANCE libpurpledll_hInstance = NULL;
  114. @@ -128,12 +130,17 @@
  115.     return retval;
  116.  }
  117.  
  118. -const char *wpurple_install_dir(void) {
  119. +const char *wpurple_bin_dir(void) {
  120.     static gboolean initialized = FALSE;
  121.  
  122.     if (!initialized) {
  123.         char *tmp = NULL;
  124.         wchar_t winstall_dir[MAXPATHLEN];
  125. +
  126. +       /* We might use g_win32_get_package_installation_directory_of_module
  127. +        * here, but we won't because this routine strips bin or lib
  128. +        * part of the path.
  129. +        */
  130.         if (GetModuleFileNameW(libpurpledll_hInstance, winstall_dir,
  131.                 MAXPATHLEN) > 0) {
  132.             tmp = g_utf16_to_utf8(winstall_dir, -1,
  133. @@ -147,42 +154,142 @@
  134.             g_free(tmp);
  135.             return NULL;
  136.         } else {
  137. -           install_dir = g_path_get_dirname(tmp);
  138. +           bin_dir = g_path_get_dirname(tmp);
  139.             g_free(tmp);
  140.             initialized = TRUE;
  141.         }
  142.     }
  143.  
  144. -   return install_dir;
  145. +   return bin_dir;
  146.  }
  147.  
  148. -const char *wpurple_lib_dir(void) {
  149. +#ifdef USE_WIN32_FHS
  150. +static gchar *
  151. +wpurple_install_relative_path(const gchar *abspath)
  152. +{
  153. +   const gchar *bindir = WIN32_FHS_BINDIR;
  154. +   const gchar *relpath;
  155. +   int i, last_dirsep = -1, bin_esc_cnt;
  156. +   gchar *ret;
  157. +   GString *bin_esc;
  158. +
  159. +   g_return_val_if_fail(bindir != NULL, NULL);
  160. +   g_return_val_if_fail(bindir[0] != '\0', NULL);
  161. +   g_return_val_if_fail(abspath != NULL, NULL);
  162. +   g_return_val_if_fail(abspath[0] != '\0', NULL);
  163. +
  164. +   /* let's find the common prefix of those paths */
  165. +   for (i = 0; bindir[i] == abspath[i]; i++) {
  166. +       if (bindir[i] == '\0')
  167. +           break;
  168. +       if (bindir[i] == '\\' || bindir[i] == '/')
  169. +           last_dirsep = i;
  170. +   }
  171. +   if (bindir[i] == '\0' && (abspath[i] == '\\' || abspath[i] == '/'))
  172. +       last_dirsep = i;
  173. +   if (abspath[i] == '\0' && (bindir[i] == '\\' || bindir[i] == '/'))
  174. +       last_dirsep = i;
  175. +
  176. +   /* there is no common prefix, return absolute path */
  177. +   if (last_dirsep == -1)
  178. +       return g_strdup(abspath);
  179. +
  180. +   /* let's check, how many dirs we need to go up to the common prefix */
  181. +   bin_esc_cnt = 0;
  182. +   for (i = last_dirsep; bindir[i]; i++) {
  183. +       if (bindir[i] != '\\' && bindir[i] != '/')
  184. +           continue;
  185. +       if (bindir[i + 1] == '\0') /* trailing dir separator */
  186. +           break;
  187. +       bin_esc_cnt++;
  188. +   }
  189. +   bin_esc = g_string_new("");
  190. +   for (i = 0; i < bin_esc_cnt; i++)
  191. +       g_string_append(bin_esc, ".." G_DIR_SEPARATOR_S);
  192. +
  193. +   /* now, we need to go back deeper into the directory tree */
  194. +   relpath = &abspath[last_dirsep];
  195. +   if (relpath[0] != '\0')
  196. +       relpath++;
  197. +
  198. +   purple_debug_misc("wpurple", "relpath bin_dir=%s", wpurple_bin_dir());
  199. +   purple_debug_misc("wpurple", "relpath bin_esc=%s", bin_esc->str);
  200. +   purple_debug_misc("wpurple", "relpath relpath=%s", relpath);
  201. +
  202. +   /* - enter bin dir
  203. +    * - escape it to the common prefix
  204. +    * - dive into the abspath dir
  205. +    */
  206. +   ret = g_build_filename(wpurple_bin_dir(), bin_esc->str, relpath, NULL);
  207. +   g_string_free(bin_esc, TRUE);
  208. +
  209. +   purple_debug_misc("wpurple", "wpurple_install_relative_path(%s) = %s",
  210. +       abspath, ret);
  211. +
  212. +   return ret;
  213. +}
  214. +#endif
  215. +
  216. +const char *
  217. +wpurple_data_dir(void) {
  218. +#ifdef USE_WIN32_FHS
  219.     static gboolean initialized = FALSE;
  220. +   if (initialized)
  221. +       return data_dir;
  222. +   data_dir = wpurple_install_relative_path(WIN32_FHS_DATADIR);
  223. +   initialized = TRUE;
  224. +
  225. +   return data_dir;
  226. +#else
  227. +   return wpurple_bin_dir();
  228. +#endif
  229. +}
  230. +
  231. +
  232. +const char *wpurple_lib_dir(const char *subdir)
  233. +{
  234. +   static gboolean initialized = FALSE;
  235. +   static gchar subpath[MAX_PATH_LEN];
  236.  
  237.     if (!initialized) {
  238. -       const char *inst_dir = wpurple_install_dir();
  239. +#ifdef USE_WIN32_FHS
  240. +       lib_dir = wpurple_install_relative_path(WIN32_FHS_LIBDIR);
  241. +       initialized = TRUE;
  242. +#else
  243. +       const char *inst_dir = wpurple_bin_dir();
  244.         if (inst_dir != NULL) {
  245.             lib_dir = g_strdup_printf("%s" G_DIR_SEPARATOR_S "plugins", inst_dir);
  246.             initialized = TRUE;
  247.         } else {
  248.             return NULL;
  249.         }
  250. +#endif
  251.     }
  252.  
  253. -   return lib_dir;
  254. +   if (subdir == NULL)
  255. +       return lib_dir;
  256. +
  257. +   g_snprintf(subpath, sizeof(subpath),
  258. +       "%s" G_DIR_SEPARATOR_S "%s", lib_dir, subdir);
  259. +   return subpath;
  260.  }
  261.  
  262.  const char *wpurple_locale_dir(void) {
  263.     static gboolean initialized = FALSE;
  264.  
  265.     if (!initialized) {
  266. -       const char *inst_dir = wpurple_install_dir();
  267. +#ifdef USE_WIN32_FHS
  268. +       locale_dir = wpurple_install_relative_path(WIN32_FHS_LOCALEDIR);
  269. +       initialized = TRUE;
  270. +#else
  271. +       const char *inst_dir = wpurple_bin_dir();
  272.         if (inst_dir != NULL) {
  273.             locale_dir = g_strdup_printf("%s" G_DIR_SEPARATOR_S "locale", inst_dir);
  274.             initialized = TRUE;
  275.         } else {
  276.             return NULL;
  277.         }
  278. +#endif
  279.     }
  280.  
  281.     return locale_dir;
  282. @@ -212,7 +319,11 @@
  283.     static gboolean initialized = FALSE;
  284.  
  285.     if (!initialized) {
  286. +#ifdef USE_WIN32_FHS
  287. +       sysconf_dir = wpurple_install_relative_path(WIN32_FHS_SYSCONFDIR);
  288. +#else
  289.         sysconf_dir = wpurple_get_special_folder(CSIDL_COMMON_APPDATA);
  290. +#endif
  291.         initialized = TRUE;
  292.     }
  293.  
  294. @@ -540,13 +651,15 @@
  295.     WSACleanup();
  296.  
  297.     g_free(app_data_dir);
  298. -   g_free(install_dir);
  299. +   g_free(bin_dir);
  300. +   g_free(data_dir);
  301.     g_free(lib_dir);
  302.     g_free(locale_dir);
  303.     g_free(sysconf_dir);
  304.  
  305.     app_data_dir = NULL;
  306. -   install_dir = NULL;
  307. +   bin_dir = NULL;
  308. +   data_dir = NULL;
  309.     lib_dir = NULL;
  310.     locale_dir = NULL;
  311.     sysconf_dir = NULL;
  312. diff --git a/libpurple/win32/win32dep.h b/libpurple/win32/win32dep.h
  313. --- a/libpurple/win32/win32dep.h
  314. +++ b/libpurple/win32/win32dep.h
  315. @@ -69,8 +69,9 @@
  316.  
  317.  /* Determine Purple paths */
  318.  gchar *wpurple_get_special_folder(int folder_type); /* needs to be g_free'd */
  319. -const char *wpurple_install_dir(void);
  320. -const char *wpurple_lib_dir(void);
  321. +const char *wpurple_bin_dir(void);
  322. +const char *wpurple_data_dir(void);
  323. +const char *wpurple_lib_dir(const char *subdir);
  324.  const char *wpurple_locale_dir(void);
  325.  const char *wpurple_home_dir(void);
  326.  const char *wpurple_sysconf_dir(void);
  327. diff --git a/pidgin/gtkconv-theme.c b/pidgin/gtkconv-theme.c
  328. --- a/pidgin/gtkconv-theme.c
  329. +++ b/pidgin/gtkconv-theme.c
  330. @@ -125,7 +125,7 @@
  331.  
  332.     if (!g_file_test(file, G_FILE_TEST_EXISTS)) {
  333.         g_free(file);
  334. -#ifdef _WIN32
  335. +#if defined(_WIN32) && !defined(USE_WIN32_FHS)
  336.         file = g_build_filename(PURPLE_DATADIR,
  337.             "theme", "Template.html", NULL);
  338.  #else
  339. diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
  340. --- a/pidgin/gtkconv.c
  341. +++ b/pidgin/gtkconv.c
  342. @@ -8940,7 +8940,7 @@
  343.             PURPLE_CALLBACK(wrote_msg_update_unseen_cb), NULL);
  344.  
  345.     purple_theme_manager_register_type(g_object_new(PIDGIN_TYPE_CONV_THEME_LOADER, "type", "conversation", NULL));
  346. -#ifdef _WIN32
  347. +#if defined(_WIN32) && !defined(USE_WIN32_FHS)
  348.     theme_dir = g_build_filename(PURPLE_DATADIR, "theme", NULL);
  349.  #else
  350.     theme_dir = g_build_filename(PURPLE_DATADIR, "pidgin", "theme", NULL);
  351. diff --git a/pidgin/plugins/win32/winprefs/winprefs.c b/pidgin/plugins/win32/winprefs/winprefs.c
  352. --- a/pidgin/plugins/win32/winprefs/winprefs.c
  353. +++ b/pidgin/plugins/win32/winprefs/winprefs.c
  354. @@ -190,7 +190,7 @@
  355.     char *runval = NULL;
  356.  
  357.     if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)))
  358. -       runval = g_strdup_printf("\"%s" G_DIR_SEPARATOR_S "pidgin.exe\"", wpurple_install_dir());
  359. +       runval = g_strdup_printf("\"%s" G_DIR_SEPARATOR_S "pidgin.exe\"", wpurple_bin_dir());
  360.  
  361.     if(!wpurple_write_reg_string(HKEY_CURRENT_USER, RUNKEY, "Pidgin", runval)
  362.         /* For Win98 */
  363. diff --git a/pidgin/win32/gtkwin32dep.c b/pidgin/win32/gtkwin32dep.c
  364. --- a/pidgin/win32/gtkwin32dep.c
  365. +++ b/pidgin/win32/gtkwin32dep.c
  366. @@ -396,7 +396,7 @@
  367.     if (purple_debug_is_verbose())
  368.         purple_debug_misc("winpidgin", "winpidgin_init start\n");
  369.  
  370. -   exchndl_dll_path = g_build_filename(wpurple_install_dir(), "exchndl.dll", NULL);
  371. +   exchndl_dll_path = g_build_filename(wpurple_bin_dir(), "exchndl.dll", NULL);
  372.     MySetLogFile = (LPFNSETLOGFILE) wpurple_find_and_loadproc(exchndl_dll_path, "SetLogFile");
  373.     g_free(exchndl_dll_path);
  374.     exchndl_dll_path = NULL;
  375. diff --git a/pidgin/win32/wspell.c b/pidgin/win32/wspell.c
  376. --- a/pidgin/win32/wspell.c
  377. +++ b/pidgin/win32/wspell.c
  378. @@ -79,7 +79,7 @@
  379.     gchar *tmp, *tmp2;
  380.  
  381.     const char *path = g_getenv("PATH");
  382. -   tmp = g_build_filename(wpurple_install_dir(), "spellcheck", NULL);
  383. +   tmp = g_build_filename(wpurple_bin_dir(), "spellcheck", NULL);
  384.     tmp2 = g_strdup_printf("%s%s%s", tmp,
  385.         (path ? G_SEARCHPATH_SEPARATOR_S : ""),
  386.         (path ? path : ""));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement