mono: Use the relocated directory for finding support libraries in data/config
[mono.git] / mono / metadata / mono-config.c
index c9e9e030b8c41354b5ddf2af83701ec657a40b3a..e73a86b94d28c186bff61876870d5d243bc4a4b2 100644 (file)
@@ -277,9 +277,24 @@ dllmap_start (gpointer user_data,
                for (i = 0; attribute_names [i]; ++i) {
                        if (strcmp (attribute_names [i], "dll") == 0)
                                info->dll = g_strdup (attribute_values [i]);
-                       else if (strcmp (attribute_names [i], "target") == 0)
-                               info->target = g_strdup (attribute_values [i]);
-                       else if (strcmp (attribute_names [i], "os") == 0 && !arch_matches (CONFIG_OS, attribute_values [i]))
+                       else if (strcmp (attribute_names [i], "target") == 0) {
+                               char *match = strstr (attribute_values [i], "$mono_libdir");
+                               if (match != NULL) {
+                                       /* substitude $mono_libdir */
+                                       const char *libdir = mono_assembly_getrootdir ();
+                                       const int libdir_len = strlen (libdir);
+                                       const int varname_len = strlen ("$mono_libdir");
+                                       const int pre_len = match - attribute_values [i];
+                                       const int post_len = strlen (match) - varname_len + 3;
+
+                                       char *result = g_malloc (pre_len + libdir_len + post_len + 1);
+                                       g_strlcpy (result, attribute_values [i], pre_len);
+                                       strncat (result, libdir, libdir_len);
+                                       strncat (result, match + varname_len, post_len);
+                                       info->target = result;
+                               } else
+                                       info->target = g_strdup (attribute_values [i]);
+                       } else if (strcmp (attribute_names [i], "os") == 0 && !arch_matches (CONFIG_OS, attribute_values [i]))
                                info->ignore = TRUE;
                        else if (strcmp (attribute_names [i], "cpu") == 0 && !arch_matches (CONFIG_CPU, attribute_values [i]))
                                info->ignore = TRUE;
@@ -551,7 +566,6 @@ mono_config_for_assembly (MonoImage *assembly)
        int got_it = 0, i;
        char *aname, *cfg, *cfg_name;
        const char *bundled_config;
-       const char *home;
        
        state.assembly = assembly;
 
@@ -567,14 +581,13 @@ mono_config_for_assembly (MonoImage *assembly)
 
        cfg_name = g_strdup_printf ("%s.config", mono_image_get_name (assembly));
 
-       home = g_get_home_dir ();
-
        for (i = 0; (aname = get_assembly_filename (assembly, i)) != NULL; ++i) {
                cfg = g_build_filename (mono_get_config_dir (), "mono", "assemblies", aname, cfg_name, NULL);
                got_it += mono_config_parse_file_with_context (&state, cfg);
                g_free (cfg);
 
 #ifdef TARGET_WIN32
+               const char *home = g_get_home_dir ();
                cfg = g_build_filename (home, ".mono", "assemblies", aname, cfg_name, NULL);
                got_it += mono_config_parse_file_with_context (&state, cfg);
                g_free (cfg);