Right now, we use a special token in mono/config which replaces $mono_libdir with the runtime-detected assemblies lib dir - e.g. /usr/lib
Unfortunately, this does not handle cases where a --libdir= value is passed to configure, such as on Red Hat where they use --libdir=/usr/lib64 on AMD64
We already have a variable from configure - reloc_libdir - so introduce some helpers to use it in the $mono_libdir replacement.
This assumes the value of --libdir is a subdirectory of --prefix, but I doubt we have ever worked at all when that is not the case.
Fixes: #41953
AC_SUBST(libmono_ldflags)
# Variable to have relocatable .pc files (lib, or lib64)
-reloc_libdir=`basename ${libdir}`
+# realpath isn't always available, and requires that all but the tip of the provided
+# path exists. Fall back to the old behaviour, but realpath allows depth >1
+# e.g. Debian puts Mono in /usr/bin and libs in /usr/lib/x86_64-linux-gnu/ which is
+# too deep for the old method to work
+reloc_libdir=`realpath --relative-to=${prefix} ${libdir} 2> /dev/null || basename ${libdir}`
AC_SUBST(reloc_libdir)
# Set to yes if Unix sockets cannot be created in an anonymous namespace
libmonoruntime_config_la_SOURCES = \
mono-config-dirs.h \
mono-config-dirs.c
-libmonoruntime_config_la_CPPFLAGS = $(AM_CPPFLAGS) -DMONO_BINDIR=\"$(bindir)/\" -DMONO_ASSEMBLIES=\"$(assembliesdir)\" -DMONO_CFG_DIR=\"$(confdir)\"
+libmonoruntime_config_la_CPPFLAGS = $(AM_CPPFLAGS) -DMONO_BINDIR=\"$(bindir)/\" -DMONO_ASSEMBLIES=\"$(assembliesdir)\" -DMONO_CFG_DIR=\"$(confdir)\" -DMONO_RELOC_LIBDIR=\"../$(reloc_libdir)\"
CLEANFILES = mono-bundle.stamp
return default_path [0];
}
+/**
+ * mono_native_getrootdir:
+ *
+ * Obtains the root directory used for looking up native libs (.so, .dylib).
+ *
+ * Returns: a string with the directory, this string should be freed by
+ * the caller.
+ */
+G_CONST_RETURN gchar *
+mono_native_getrootdir (void)
+{
+ gchar* fullpath = g_build_path (G_DIR_SEPARATOR_S, mono_assembly_getrootdir (), mono_config_get_reloc_lib_dir(), NULL);
+ return fullpath;
+}
+
/**
* mono_set_dirs:
* @assembly_dir: the base directory for assemblies
MONO_API void mono_assembly_close (MonoAssembly *assembly);
MONO_API void mono_assembly_setrootdir (const char *root_dir);
MONO_API MONO_CONST_RETURN char *mono_assembly_getrootdir (void);
+MONO_API MONO_CONST_RETURN char *mono_native_getrootdir (void);
MONO_API void mono_assembly_foreach (MonoFunc func, void* user_data);
MONO_API void mono_assembly_set_main (MonoAssembly *assembly);
MONO_API MonoAssembly *mono_assembly_get_main (void);
#endif
}
+const char*
+mono_config_get_reloc_lib_dir (void)
+{
+#ifdef MONO_RELOC_LIBDIR
+ return MONO_RELOC_LIBDIR;
+#else
+ return NULL;
+#endif
+}
+
const char*
mono_config_get_bin_dir (void);
+const char*
+mono_config_get_reloc_lib_dir (void);
+
#endif
else if (strcmp (attribute_names [i], "target") == 0){
char *p = strstr (attribute_values [i], "$mono_libdir");
if (p != NULL){
- const char *libdir = mono_assembly_getrootdir ();
+ const char *libdir = mono_native_getrootdir ();
size_t libdir_len = strlen (libdir);
char *result;
result = (char *)g_malloc (libdir_len-strlen("$mono_libdir")+strlen(attribute_values[i])+1);
strncpy (result, attribute_values[i], p-attribute_values[i]);
strcpy (result+(p-attribute_values[i]), libdir);
+ g_free (libdir);
strcat (result, p+strlen("$mono_libdir"));
info->target = result;
} else