From e5f90e06d10fc3f64c4951a032bc6ecdb94aa723 Mon Sep 17 00:00:00 2001
From: Jonathan Helmus <jjhelmus@gmail.com>
Date: Tue, 5 Nov 2019 09:01:44 -0600
Subject: [PATCH 3/5] add install_rpath to meson build files

As per https://github.com/conda-forge/glib-feedstock/issues/40, the new Meson
build system can cause problems on Linux. When installing executables
(including shared libraries), Meson edits their RPATHs. When no
"install_rpath" setting has been configured, Meson removes the RPATH entry.
First, this can break our executables. Second, historically, the way that
Meson does so was legal, but ends up altering the file structure in a way
that a few naive programs can't handle. One of those programs is ldconfig, and
its confusion can result in it trying to create files with junk names, which
then confuse downstream tools.

So we the install rpath to something nonempty.

original patch by Peter Williams
https://github.com/conda-forge/glib-feedstock/blob/082ae2bfe3d8758aa1773d6a2521e29255063784/recipe/meson-rpaths.patch

diff --git a/gio/meson.build b/gio/meson.build
index 39e246b..548d6a0 100644
--- a/gio/meson.build
+++ b/gio/meson.build
@@ -794,6 +794,7 @@ libgio = library('gio-2.0',
   soversion : soversion,
   darwin_versions : darwin_versions,
   install : true,
+  install_rpath : glib_libdir,
   include_directories : [configinc, gioinc],
   #  '$(gio_win32_res_ldflag)',
   dependencies : [libz_dep, libdl_dep, libmount_dep, libglib_dep,
@@ -931,6 +932,7 @@ gio_tool_sources = [
 
 executable('gio', gio_tool_sources,
   install : true,
+  install_rpath : glib_libdir,
   c_args : gio_c_args,
   # intl.lib is not compatible with SAFESEH
   link_args : noseh_link_args,
@@ -938,12 +940,14 @@ executable('gio', gio_tool_sources,
 
 executable('gresource', 'gresource-tool.c',
   install : true,
+  install_rpath : glib_libdir,
   # intl.lib is not compatible with SAFESEH
   link_args : noseh_link_args,
   dependencies : [libelf, libgio_dep, libgobject_dep, libgmodule_dep, libglib_dep])
 
 gio_querymodules = executable('gio-querymodules', 'gio-querymodules.c', 'giomodule-priv.c',
   install : true,
+  install_rpath : glib_libdir,
   c_args : gio_c_args,
   # intl.lib is not compatible with SAFESEH
   link_args : noseh_link_args,
@@ -952,6 +956,7 @@ gio_querymodules = executable('gio-querymodules', 'gio-querymodules.c', 'giomodu
 glib_compile_schemas = executable('glib-compile-schemas',
   [gconstructor_as_data_h, 'gvdb/gvdb-builder.c', 'glib-compile-schemas.c'],
   install : true,
+  install_rpath : glib_libdir,
   # intl.lib is not compatible with SAFESEH
   link_args : noseh_link_args,
   dependencies : [libgio_dep, libgobject_dep, libgmodule_dep, libglib_dep])
@@ -959,6 +964,7 @@ glib_compile_schemas = executable('glib-compile-schemas',
 glib_compile_resources = executable('glib-compile-resources',
   [gconstructor_as_data_h, 'gvdb/gvdb-builder.c', 'glib-compile-resources.c'],
   install : true,
+  install_rpath : glib_libdir,
   c_args : gio_c_args,
   # intl.lib is not compatible with SAFESEH
   link_args : noseh_link_args,
@@ -974,6 +980,7 @@ endif
 
 executable('gsettings', 'gsettings-tool.c',
   install : true,
+  install_rpath : glib_libdir,
   c_args : gio_c_args,
   # intl.lib is not compatible with SAFESEH
   link_args : noseh_link_args,
@@ -986,6 +993,7 @@ install_data(['gschema.loc', 'gschema.its'],
 
 executable('gdbus', 'gdbus-tool.c',
   install : true,
+  install_rpath : glib_libdir,
   c_args : gio_c_args,
   # intl.lib is not compatible with SAFESEH
   link_args : noseh_link_args,
@@ -994,6 +1002,7 @@ executable('gdbus', 'gdbus-tool.c',
 if host_system != 'windows' and not glib_have_cocoa
   executable('gapplication', 'gapplication-tool.c',
     install : true,
+    install_rpath : glib_libdir,
     c_args : gio_c_args,
     # intl.lib is not compatible with SAFESEH
     link_args : noseh_link_args,
diff --git a/glib/meson.build b/glib/meson.build
index 3f24579..265feb0 100644
--- a/glib/meson.build
+++ b/glib/meson.build
@@ -353,6 +353,7 @@ libglib = library('glib-2.0',
   soversion : soversion,
   darwin_versions : darwin_versions,
   install : true,
+  install_rpath : glib_libdir,
   # intl.lib is not compatible with SAFESEH
   link_args : [noseh_link_args, glib_link_flags, win32_ldflags],
   include_directories : configinc,
@@ -415,6 +416,7 @@ if host_system == 'windows'
 else
   gtester = executable('gtester', 'gtester.c',
     install : true,
+    install_rpath : glib_libdir,
     c_args : ['-UG_DISABLE_ASSERT'],
     include_directories : configinc,
     dependencies : [libglib_dep])
diff --git a/gmodule/meson.build b/gmodule/meson.build
index b1a5a11..9ba2a79 100644
--- a/gmodule/meson.build
+++ b/gmodule/meson.build
@@ -78,6 +78,7 @@ libgmodule = library('gmodule-2.0',
   soversion : soversion,
   darwin_versions : darwin_versions,
   install : true,
+  install_rpath : glib_libdir,
   include_directories : [configinc, gmoduleinc],
   dependencies : [libdl_dep, libglib_dep],
   c_args : ['-DG_LOG_DOMAIN="GModule"'] + glib_hidden_visibility_args,
diff --git a/gobject/meson.build b/gobject/meson.build
index 536f153..9b483e9 100644
--- a/gobject/meson.build
+++ b/gobject/meson.build
@@ -124,6 +124,7 @@ libgobject = library('gobject-2.0',
   soversion : soversion,
   darwin_versions : darwin_versions,
   install : true,
+  install_rpath : glib_libdir,
   include_directories : [configinc],
   dependencies : [libffi_dep, libglib_dep],
   c_args : ['-DG_LOG_DOMAIN="GLib-GObject"', '-DGOBJECT_COMPILATION'] + glib_hidden_visibility_args,
@@ -149,6 +150,7 @@ endif
 
 executable('gobject-query', 'gobject-query.c',
   install : true,
+  install_rpath : glib_libdir,
   dependencies : [libglib_dep, libgobject_dep])
 
 install_data('gobject_gdb.py', install_dir : join_paths(glib_pkgdatadir, 'gdb'))
diff --git a/gthread/meson.build b/gthread/meson.build
index 808e889..56da3cb 100644
--- a/gthread/meson.build
+++ b/gthread/meson.build
@@ -18,6 +18,7 @@ libgthread = library('gthread-2.0',
   soversion : soversion,
   darwin_versions : darwin_versions,
   install : true,
+  install_rpath : glib_libdir,
   dependencies : [libglib_dep],
   c_args : ['-DG_LOG_DOMAIN="GThread"' ] + glib_hidden_visibility_args,
   link_args : glib_link_flags,
