1
commit 256085a45e93ec6bf8d9590a893c15c9320ccfe3
2
Author: Paul Davis <paul@linuxaudiosystems.com>
3
Date: Sat Jan 26 14:20:45 2013 -0500
5
initial version of GTK relocation patch, provides relocation on Linux and OSX. Windows code for this exists but has not been merged into gtkrelocation.c
7
diff --git a/configure.ac b/configure.ac
8
index e777ed0..70e4719 100644
11
@@ -1253,22 +1253,31 @@ else
12
AM_CONDITIONAL(USE_WIN32, false)
15
+AC_ARG_ENABLE(relocation,
16
+ [AS_HELP_STRING([--enable-relocation],
17
+ [enable bundle-based relocation functions])],
18
+ [allow_relocation=yes])
20
+# --enable-quartz-relocation is a legacy flag that should eventually
21
+# be removed when the only relocation flag is just --enable-relocation.
22
+# for now, it has the same effect as --enable-relocation
23
AC_ARG_ENABLE(quartz-relocation,
24
[AS_HELP_STRING([--enable-quartz-relocation],
25
[enable bundle-based relocation functions])],
26
- [quartz_relocation=yes])
27
+ [allow_relocation=yes])
29
if test "x$gdktarget" = "xquartz"; then
30
GDK_EXTRA_LIBS="$GDK_EXTRA_LIBS -framework Cocoa"
31
AM_CONDITIONAL(USE_QUARTZ, true)
32
- if test "x$quartz_relocation" = xyes; then
33
- AC_DEFINE([QUARTZ_RELOCATION], [1], [Use NSBundle functions to determine load paths for libraries, translations, etc.])
37
AM_CONDITIONAL(USE_QUARTZ, false)
40
+if test "x$allow_relocation" = xyes; then
41
+ AC_DEFINE([ALLOW_RELOCATION], [1], [Determine load paths for libraries, translations, etc. at runtime instead of build time])
42
+ AM_CONDITIONAL(USE_RELOCATION, true)
45
if test "x$gdktarget" = "xdirectfb"; then
46
DIRECTFB_REQUIRED_VERSION=1.0.0
47
AC_MSG_CHECKING(for DirectFB)
48
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
49
index 908291f..1f16830 100644
52
@@ -758,6 +758,10 @@ endif
57
+gtk_c_sources += gtkrelocation.c
61
gtk_clipboard_dnd_c_sources = gtkclipboard-quartz.c gtkdnd-quartz.c gtkquartz.c
62
gtk_clipboard_dnd_h_sources = gtkquartz.h
63
diff --git a/gtk/gtkprivate.h b/gtk/gtkprivate.h
64
index 6386c32..88a3bb8 100644
65
--- a/gtk/gtkprivate.h
66
+++ b/gtk/gtkprivate.h
67
@@ -74,8 +74,7 @@ typedef enum
68
#define GTK_PRIVATE_SET_FLAG(wid,flag) G_STMT_START{ (GTK_PRIVATE_FLAGS (wid) |= (PRIVATE_ ## flag)); }G_STMT_END
69
#define GTK_PRIVATE_UNSET_FLAG(wid,flag) G_STMT_START{ (GTK_PRIVATE_FLAGS (wid) &= ~(PRIVATE_ ## flag)); }G_STMT_END
71
-#if defined G_OS_WIN32 \
72
- || (defined GDK_WINDOWING_QUARTZ && defined QUARTZ_RELOCATION)
73
+#if defined G_OS_WIN32 || defined ALLOW_RELOCATION
75
const gchar *_gtk_get_datadir ();
76
const gchar *_gtk_get_libdir ();
77
@@ -94,7 +93,7 @@ const gchar *_gtk_get_data_prefix ();
78
#undef GTK_DATA_PREFIX
79
#define GTK_DATA_PREFIX _gtk_get_data_prefix ()
81
-#endif /* G_OS_WIN32 */
82
+#endif /* G_OS_WIN32 or ALLOW_RELOCATION */
84
gboolean _gtk_fnmatch (const char *pattern,
86
diff --git a/gtk/gtkquartz.c b/gtk/gtkquartz.c
87
index 2f8122a..a650489 100644
90
@@ -331,85 +331,3 @@ _gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard *pasteboard,
96
- * Bundle-based functions for various directories. These almost work
97
- * even when the application isn't in a bundle, becuase mainBundle
98
- * paths point to the bin directory in that case. It's a simple matter
99
- * to test for that and remove the last element.
102
-static const gchar *
103
-get_bundle_path (void)
105
- static gchar *path = NULL;
109
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
110
- gchar *resource_path = g_strdup ([[[NSBundle mainBundle] resourcePath] UTF8String]);
114
- base = g_path_get_basename (resource_path);
115
- if (strcmp (base, "bin") == 0)
116
- path = g_path_get_dirname (resource_path);
118
- path = strdup (resource_path);
120
- g_free (resource_path);
128
-_gtk_get_datadir (void)
130
- static gchar *path = NULL;
133
- path = g_build_filename (get_bundle_path (), "share", NULL);
139
-_gtk_get_libdir (void)
141
- static gchar *path = NULL;
144
- path = g_build_filename (get_bundle_path (), "lib", NULL);
150
-_gtk_get_localedir (void)
152
- static gchar *path = NULL;
155
- path = g_build_filename (get_bundle_path (), "share", "locale", NULL);
161
-_gtk_get_sysconfdir (void)
163
- static gchar *path = NULL;
166
- path = g_build_filename (get_bundle_path (), "etc", NULL);
172
-_gtk_get_data_prefix (void)
174
- return get_bundle_path ();
176
diff --git a/gtk/gtkrelocation.c b/gtk/gtkrelocation.c
178
index 0000000..0109841
180
+++ b/gtk/gtkrelocation.c
182
+/* gtklinuxrelocation: functions used to provide relocation on Linux
184
+ * Copyright (C) 2013 Whomsoever
186
+ * This library is free software; you can redistribute it and/or
187
+ * modify it under the terms of the GNU Lesser General Public
188
+ * License as published by the Free Software Foundation; either
189
+ * version 2 of the License, or (at your option) any later version.
191
+ * This library is distributed in the hope that it will be useful,
192
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
193
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
194
+ * Lesser General Public License for more details.
196
+ * You should have received a copy of the GNU Lesser General Public
197
+ * License along with this library; if not, write to the
198
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
199
+ * Boston, MA 02111-1307, USA.
205
+#include <sys/types.h>
210
+#include <glib/gstdio.h>
212
+#include "gtkalias.h"
216
+/* include relevant code here */
218
+#elif defined (__APPLE__)
220
+#include <Foundation/Foundation.h>
222
+static const gchar *
223
+get_bundle_path (void)
225
+ static gchar *path = NULL;
229
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
230
+ gchar *resource_path = g_strdup ([[[NSBundle mainBundle] resourcePath] UTF8String]);
234
+ base = g_path_get_basename (resource_path);
235
+ if (strcmp (base, "bin") == 0)
236
+ path = g_path_get_dirname (resource_path);
238
+ path = strdup (resource_path);
240
+ g_free (resource_path);
250
+ * Find the canonical filename of the executable. Returns the filename
251
+ * (which must be freed) or NULL on error. If the parameter 'error' is
252
+ * not NULL, the error code will be stored there, if an error occured.
255
+_br_find_exe (gint *error)
257
+ char *path, *path2, *line, *result;
260
+ struct stat stat_buf;
263
+ /* Read from /proc/self/exe (symlink) */
264
+ if (sizeof (path) > SSIZE_MAX)
265
+ buf_size = SSIZE_MAX - 1;
267
+ buf_size = PATH_MAX - 1;
268
+ path = g_try_new (char, buf_size);
269
+ if (path == NULL) {
270
+ /* Cannot allocate memory. */
275
+ path2 = g_try_new (char, buf_size);
276
+ if (path2 == NULL) {
277
+ /* Cannot allocate memory. */
284
+ strncpy (path2, "/proc/self/exe", buf_size - 1);
289
+ size = readlink (path2, path, buf_size - 1);
296
+ /* readlink() success. */
299
+ /* Check whether the symlink's target is also a symlink.
300
+ * We want to get the final target. */
301
+ i = stat (path, &stat_buf);
308
+ /* stat() success. */
309
+ if (!S_ISLNK (stat_buf.st_mode)) {
310
+ /* path is not a symlink. Done. */
315
+ /* path is a symlink. Continue loop and resolve this. */
316
+ strncpy (path, path2, buf_size - 1);
320
+ /* readlink() or stat() failed; this can happen when the program is
321
+ * running in Valgrind 2.2. Read from /proc/self/maps as fallback. */
323
+ buf_size = PATH_MAX + 128;
324
+ line = (char *) g_try_realloc (path, buf_size);
325
+ if (line == NULL) {
326
+ /* Cannot allocate memory. */
333
+ f = g_fopen ("/proc/self/maps", "r");
341
+ /* The first entry should be the executable name. */
342
+ result = fgets (line, (int) buf_size, f);
343
+ if (result == NULL) {
351
+ /* Get rid of newline character. */
352
+ buf_size = strlen (line);
353
+ if (buf_size <= 0) {
354
+ /* Huh? An empty string? */
361
+ if (line[buf_size - 1] == 10)
362
+ line[buf_size - 1] = 0;
364
+ /* Extract the filename; it is always an absolute path. */
365
+ path = strchr (line, '/');
367
+ /* Sanity check. */
368
+ if (strstr (line, " r-xp ") == NULL || path == NULL) {
376
+ path = g_strdup (path);
382
+static const gchar *
383
+get_bundle_path (void)
385
+ static gchar *path = NULL;
388
+ path = (gchar*) g_getenv ("GTK_BUNDLEDIR");
393
+ path = _br_find_exe (&err);
397
+ char* opath = path;
398
+ char* dir = g_path_get_dirname (path);
400
+ path = g_path_get_dirname (dir);
404
+ if (dir[0] == '.' && dir[1] == '\0')
416
+_gtk_get_datadir (void)
418
+ static const gchar *path = NULL;
421
+ path = g_getenv ("GTK_DATADIR");
424
+ path = g_build_filename (get_bundle_path (), "share", NULL);
430
+_gtk_get_libdir (void)
432
+ static const gchar *path = NULL;
435
+ path = g_getenv ("GTK_LIBDIR");
438
+ path = g_build_filename (get_bundle_path (), "lib", NULL);
444
+_gtk_get_localedir (void)
446
+ static const gchar *path = NULL;
449
+ path = g_getenv ("GTK_LOCALEDIR");
452
+ path = g_build_filename (get_bundle_path (), "share", "locale", NULL);
458
+_gtk_get_sysconfdir (void)
460
+ static const gchar *path = NULL;
463
+ path = g_getenv ("GTK_SYSCONFDIR");
466
+ path = g_build_filename (get_bundle_path (), "etc", NULL);
472
+_gtk_get_data_prefix (void)
474
+ return get_bundle_path ();