~ubuntu-branches/ubuntu/vivid/ardour/vivid-proposed

« back to all changes in this revision

Viewing changes to tools/current-gtk-patches/gtkrelocation.patch

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler, Jaromír Mikeš, Felipe Sateler
  • Date: 2014-05-22 14:39:25 UTC
  • mfrom: (29 sid)
  • mto: This revision was merged to the branch mainline in revision 30.
  • Revision ID: package-import@ubuntu.com-20140522143925-vwqfo9287pmkrroe
Tags: 1:2.8.16+git20131003-3
* Team upload

[ Jaromír Mikeš ]
* Add -dbg package

[ Felipe Sateler ]
* Upload to experimental

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
commit 256085a45e93ec6bf8d9590a893c15c9320ccfe3
 
2
Author: Paul Davis <paul@linuxaudiosystems.com>
 
3
Date:   Sat Jan 26 14:20:45 2013 -0500
 
4
 
 
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
 
6
 
 
7
diff --git a/configure.ac b/configure.ac
 
8
index e777ed0..70e4719 100644
 
9
--- a/configure.ac
 
10
+++ b/configure.ac
 
11
@@ -1253,22 +1253,31 @@ else
 
12
   AM_CONDITIONAL(USE_WIN32, false)
 
13
 fi
 
14
 
 
15
+AC_ARG_ENABLE(relocation,
 
16
+              [AS_HELP_STRING([--enable-relocation],
 
17
+                              [enable bundle-based relocation functions])],
 
18
+                              [allow_relocation=yes])
 
19
+
 
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])
 
28
 
 
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.])
 
34
-  fi
 
35
-
 
36
 else
 
37
   AM_CONDITIONAL(USE_QUARTZ, false)
 
38
 fi
 
39
 
 
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)
 
43
+fi
 
44
+
 
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
 
50
--- a/gtk/Makefile.am
 
51
+++ b/gtk/Makefile.am
 
52
@@ -758,6 +758,10 @@ endif
 
53
 endif
 
54
 endif
 
55
 
 
56
+if USE_RELOCATION
 
57
+gtk_c_sources += gtkrelocation.c
 
58
+endif
 
59
+
 
60
 if USE_QUARTZ
 
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
 
70
 
 
71
-#if defined G_OS_WIN32 \
 
72
-  || (defined GDK_WINDOWING_QUARTZ && defined QUARTZ_RELOCATION)
 
73
+#if defined G_OS_WIN32 || defined ALLOW_RELOCATION
 
74
 
 
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 ()
 
80
 
 
81
-#endif /* G_OS_WIN32 */
 
82
+#endif /* G_OS_WIN32 or ALLOW_RELOCATION */
 
83
 
 
84
 gboolean _gtk_fnmatch (const char *pattern,
 
85
                       const char *string,
 
86
diff --git a/gtk/gtkquartz.c b/gtk/gtkquartz.c
 
87
index 2f8122a..a650489 100644
 
88
--- a/gtk/gtkquartz.c
 
89
+++ b/gtk/gtkquartz.c
 
90
@@ -331,85 +331,3 @@ _gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard     *pasteboard,
 
91
                                        freeWhenDone:NO]
 
92
                                             forType:type];
 
93
 }
 
94
-
 
95
-/*
 
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.
 
100
- */
 
101
-
 
102
-static const gchar *
 
103
-get_bundle_path (void)
 
104
-{
 
105
-  static gchar *path = NULL;
 
106
-
 
107
-  if (path == NULL)
 
108
-    {
 
109
-      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 
110
-      gchar *resource_path = g_strdup ([[[NSBundle mainBundle] resourcePath] UTF8String]);
 
111
-      gchar *base;
 
112
-      [pool drain];
 
113
-
 
114
-      base = g_path_get_basename (resource_path);
 
115
-      if (strcmp (base, "bin") == 0)
 
116
-       path = g_path_get_dirname (resource_path);
 
117
-      else
 
118
-       path = strdup (resource_path);
 
119
-
 
120
-      g_free (resource_path);
 
121
-      g_free (base);
 
122
-    }
 
123
-
 
124
-  return path;
 
125
-}
 
126
-
 
127
-const gchar *
 
128
-_gtk_get_datadir (void)
 
129
-{
 
130
-  static gchar *path = NULL;
 
131
-
 
132
-  if (path == NULL)
 
133
-    path = g_build_filename (get_bundle_path (), "share", NULL);
 
134
-
 
135
-  return path;
 
136
-}
 
137
-
 
138
-const gchar *
 
139
-_gtk_get_libdir (void)
 
140
-{
 
141
-  static gchar *path = NULL;
 
142
-
 
143
-  if (path == NULL)
 
144
-    path = g_build_filename (get_bundle_path (), "lib", NULL);
 
145
-
 
146
-  return path;
 
147
-}
 
148
-
 
149
-const gchar *
 
150
-_gtk_get_localedir (void)
 
151
-{
 
152
-  static gchar *path = NULL;
 
153
-
 
154
-  if (path == NULL)
 
155
-    path = g_build_filename (get_bundle_path (), "share", "locale", NULL);
 
156
-
 
157
-  return path;
 
158
-}
 
159
-
 
160
-const gchar *
 
161
-_gtk_get_sysconfdir (void)
 
162
-{
 
163
-  static gchar *path = NULL;
 
164
-
 
165
-  if (path == NULL)
 
166
-    path = g_build_filename (get_bundle_path (), "etc", NULL);
 
167
-
 
168
-  return path;
 
169
-}
 
170
-
 
171
-const gchar *
 
172
-_gtk_get_data_prefix (void)
 
173
-{
 
174
-  return get_bundle_path ();
 
175
-}
 
176
diff --git a/gtk/gtkrelocation.c b/gtk/gtkrelocation.c
 
177
new file mode 100644
 
178
index 0000000..0109841
 
179
--- /dev/null
 
180
+++ b/gtk/gtkrelocation.c
 
181
@@ -0,0 +1,294 @@
 
182
+/* gtklinuxrelocation: functions used to provide relocation on Linux
 
183
+ *
 
184
+ * Copyright (C) 2013 Whomsoever
 
185
+ *
 
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.
 
190
+ *
 
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.
 
195
+ *
 
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.
 
200
+ */
 
201
+
 
202
+#include "config.h"
 
203
+
 
204
+#include <unistd.h>
 
205
+#include <sys/types.h>
 
206
+#include <errno.h>
 
207
+#include <stdio.h>
 
208
+#include <string.h>
 
209
+#include <glib.h>
 
210
+#include <glib/gstdio.h>
 
211
+
 
212
+#include "gtkalias.h"
 
213
+
 
214
+#ifdef G_OS_WIN32
 
215
+
 
216
+/* include relevant code here  */
 
217
+
 
218
+#elif defined (__APPLE__)
 
219
+
 
220
+#include <Foundation/Foundation.h>
 
221
+
 
222
+static const gchar *
 
223
+get_bundle_path (void)
 
224
+{
 
225
+  static gchar *path = NULL;
 
226
+
 
227
+  if (path == NULL)
 
228
+    {
 
229
+      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 
230
+      gchar *resource_path = g_strdup ([[[NSBundle mainBundle] resourcePath] UTF8String]);
 
231
+      gchar *base;
 
232
+      [pool drain];
 
233
+
 
234
+      base = g_path_get_basename (resource_path);
 
235
+      if (strcmp (base, "bin") == 0)
 
236
+       path = g_path_get_dirname (resource_path);
 
237
+      else
 
238
+       path = strdup (resource_path);
 
239
+
 
240
+      g_free (resource_path);
 
241
+      g_free (base);
 
242
+    }
 
243
+
 
244
+  return path;
 
245
+}
 
246
+
 
247
+#else /* linux */
 
248
+
 
249
+/*
 
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.
 
253
+ */
 
254
+static char *
 
255
+_br_find_exe (gint *error)
 
256
+{
 
257
+        char *path, *path2, *line, *result;
 
258
+        size_t buf_size;
 
259
+        ssize_t size;
 
260
+        struct stat stat_buf;
 
261
+        FILE *f;
 
262
+
 
263
+        /* Read from /proc/self/exe (symlink) */
 
264
+        if (sizeof (path) > SSIZE_MAX)
 
265
+                buf_size = SSIZE_MAX - 1;
 
266
+        else
 
267
+                buf_size = PATH_MAX - 1;
 
268
+        path = g_try_new (char, buf_size);
 
269
+        if (path == NULL) {
 
270
+                /* Cannot allocate memory. */
 
271
+                if (error)
 
272
+                        *error = ENOMEM;
 
273
+                return NULL;
 
274
+        }
 
275
+        path2 = g_try_new (char, buf_size);
 
276
+        if (path2 == NULL) {
 
277
+                /* Cannot allocate memory. */
 
278
+                if (error)
 
279
+                        *error = ENOMEM;
 
280
+                g_free (path);
 
281
+                return NULL;
 
282
+        }
 
283
+
 
284
+        strncpy (path2, "/proc/self/exe", buf_size - 1);
 
285
+
 
286
+        while (1) {
 
287
+                int i;
 
288
+
 
289
+                size = readlink (path2, path, buf_size - 1);
 
290
+                if (size == -1) {
 
291
+                        /* Error. */
 
292
+                        g_free (path2);
 
293
+                        break;
 
294
+                }
 
295
+
 
296
+                /* readlink() success. */
 
297
+                path[size] = '\0';
 
298
+
 
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);
 
302
+                if (i == -1) {
 
303
+                        /* Error. */
 
304
+                        g_free (path2);
 
305
+                        break;
 
306
+                }
 
307
+
 
308
+                /* stat() success. */
 
309
+                if (!S_ISLNK (stat_buf.st_mode)) {
 
310
+                        /* path is not a symlink. Done. */
 
311
+                        g_free (path2);
 
312
+                        return path;
 
313
+                }
 
314
+
 
315
+                /* path is a symlink. Continue loop and resolve this. */
 
316
+                strncpy (path, path2, buf_size - 1);
 
317
+        }
 
318
+
 
319
+
 
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. */
 
322
+
 
323
+        buf_size = PATH_MAX + 128;
 
324
+        line = (char *) g_try_realloc (path, buf_size);
 
325
+        if (line == NULL) {
 
326
+                /* Cannot allocate memory. */
 
327
+                g_free (path);
 
328
+                if (error)
 
329
+                        *error = ENOMEM;
 
330
+                return NULL;
 
331
+        }
 
332
+
 
333
+        f = g_fopen ("/proc/self/maps", "r");
 
334
+        if (f == NULL) {
 
335
+                g_free (line);
 
336
+                if (error)
 
337
+                        *error = ENOENT;
 
338
+                return NULL;
 
339
+        }
 
340
+
 
341
+        /* The first entry should be the executable name. */
 
342
+        result = fgets (line, (int) buf_size, f);
 
343
+        if (result == NULL) {
 
344
+                fclose (f);
 
345
+                g_free (line);
 
346
+                if (error)
 
347
+                        *error = EIO;
 
348
+                return NULL;
 
349
+        }
 
350
+
 
351
+        /* Get rid of newline character. */
 
352
+        buf_size = strlen (line);
 
353
+        if (buf_size <= 0) {
 
354
+                /* Huh? An empty string? */
 
355
+                fclose (f);
 
356
+                g_free (line);
 
357
+                if (error)
 
358
+                        *error = ENOENT;
 
359
+                return NULL;
 
360
+        }
 
361
+        if (line[buf_size - 1] == 10)
 
362
+                line[buf_size - 1] = 0;
 
363
+
 
364
+        /* Extract the filename; it is always an absolute path. */
 
365
+        path = strchr (line, '/');
 
366
+
 
367
+        /* Sanity check. */
 
368
+        if (strstr (line, " r-xp ") == NULL || path == NULL) {
 
369
+                fclose (f);
 
370
+                g_free (line);
 
371
+                if (error)
 
372
+                        *error = EIO;
 
373
+                return NULL;
 
374
+        }
 
375
+
 
376
+        path = g_strdup (path);
 
377
+        g_free (line);
 
378
+        fclose (f);
 
379
+        return path;
 
380
+}
 
381
+
 
382
+static const gchar *
 
383
+get_bundle_path (void)
 
384
+{
 
385
+  static gchar *path = NULL;
 
386
+  
 
387
+  if (path == NULL)
 
388
+          path = (gchar*) g_getenv ("GTK_BUNDLEDIR");     
 
389
+
 
390
+  if (path == NULL)
 
391
+    {
 
392
+      int err;            
 
393
+      path = _br_find_exe (&err);
 
394
+
 
395
+      if (path) 
 
396
+        {      
 
397
+           char* opath = path;
 
398
+           char* dir = g_path_get_dirname (path);
 
399
+
 
400
+           path = g_path_get_dirname (dir);
 
401
+
 
402
+           g_free (opath);
 
403
+
 
404
+           if (dir[0] == '.' && dir[1] == '\0')
 
405
+              g_free (dir);
 
406
+        }
 
407
+
 
408
+    }
 
409
+
 
410
+  return path;
 
411
+}
 
412
+
 
413
+#endif
 
414
+
 
415
+const gchar *
 
416
+_gtk_get_datadir (void)
 
417
+{
 
418
+  static const gchar *path = NULL;
 
419
+
 
420
+  if (path == NULL)
 
421
+     path = g_getenv ("GTK_DATADIR");     
 
422
+
 
423
+  if (path == NULL)
 
424
+    path = g_build_filename (get_bundle_path (), "share", NULL);
 
425
+
 
426
+  return path;
 
427
+}
 
428
+
 
429
+const gchar *
 
430
+_gtk_get_libdir (void)
 
431
+{
 
432
+  static const gchar *path = NULL;
 
433
+
 
434
+  if (path == NULL)
 
435
+     path = g_getenv ("GTK_LIBDIR");     
 
436
+
 
437
+  if (path == NULL)
 
438
+    path = g_build_filename (get_bundle_path (), "lib", NULL);
 
439
+
 
440
+  return path;
 
441
+}
 
442
+
 
443
+const gchar *
 
444
+_gtk_get_localedir (void)
 
445
+{
 
446
+  static const gchar *path = NULL;
 
447
+
 
448
+  if (path == NULL)
 
449
+     path = g_getenv ("GTK_LOCALEDIR");     
 
450
+
 
451
+  if (path == NULL)
 
452
+    path = g_build_filename (get_bundle_path (), "share", "locale", NULL);
 
453
+
 
454
+  return path;
 
455
+}
 
456
+
 
457
+const gchar *
 
458
+_gtk_get_sysconfdir (void)
 
459
+{
 
460
+  static const gchar *path = NULL;
 
461
+
 
462
+  if (path == NULL)
 
463
+     path = g_getenv ("GTK_SYSCONFDIR");     
 
464
+
 
465
+  if (path == NULL)
 
466
+    path = g_build_filename (get_bundle_path (), "etc", NULL);
 
467
+
 
468
+  return path;
 
469
+}
 
470
+
 
471
+const gchar *
 
472
+_gtk_get_data_prefix (void)
 
473
+{
 
474
+  return get_bundle_path ();
 
475
+}