From 1c2472a0920d27f21b454f8eb73f5f2fa47bafb3 Mon Sep 17 00:00:00 2001 From: Jehan Date: Thu, 4 Apr 2024 19:49:30 +0200 Subject: [PATCH] libgimpbase: support multiarch folders for binary relocability on Linux. This is not seen on all distributions (mostly on Debian-based ones in my experience), but some distributions install libraries in a second-level directory under prefix (e.g. lib/x86_64-linux-gnu/ instead of lib/ or lib64/) whereas our prefix-guessing code for relocatable builds harcoded moving up from 1 level. This new heuristic will assume that if the leaf directory is neither bin/ nor starting with `lib`, then it's likely a multiarch folder and we must move up once more to find the prefix folder. This should also fix the problem encountered by Bruno for the current work on a potential official AppImage. --- libgimpbase/gimpreloc.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libgimpbase/gimpreloc.c b/libgimpbase/gimpreloc.c index 90c2b7b59a..cdbc1b6c25 100644 --- a/libgimpbase/gimpreloc.c +++ b/libgimpbase/gimpreloc.c @@ -452,6 +452,7 @@ gchar * _gimp_reloc_find_prefix (const gchar *default_prefix) { gchar *dir1, *dir2; + gchar *exe_dir; if (exe == NULL) { @@ -464,6 +465,24 @@ _gimp_reloc_find_prefix (const gchar *default_prefix) dir1 = g_path_get_dirname (exe); dir2 = g_path_get_dirname (dir1); + + exe_dir = g_path_get_basename (dir1); + if (g_strcmp0 (exe_dir, "bin") != 0 && ! g_str_has_prefix (exe_dir, "lib")) + { + g_free (exe_dir); + exe_dir = g_path_get_basename (dir2); + if (g_str_has_prefix (exe_dir, "lib")) + { + /* Supporting multiarch folders, such as lib/x86_64-linux-gnu/ */ + gchar *dir3 = g_path_get_dirname (dir2); + + g_free (dir2); + dir2 = dir3; + } + } + g_free (dir1); + g_free (exe_dir); + return dir2; }