Author: wade
Date: 2005-10-28 12:34:39 -0400 (Fri, 28 Oct 2005)
New Revision: 52333
Modified:
branches/mono-1-1-7/mono/mono/metadata/ChangeLog
branches/mono-1-1-7/mono/mono/metadata/Makefile.am
branches/mono-1-1-7/mono/mono/metadata/assembly.c
branches/mono-1-1-7/mono/mono/metadata/mono-config.c
branches/mono-1-1-7/mono/mono/mini/Makefile.am
branches/mono-1-1-7/mono/mono/os/unix/Makefile.am
branches/mono-1-1-7/mono/mono/os/unix/util.c
branches/mono-1-1-7/mono/mono/os/win32/util.c
Log:
Miguel's patch to allow mono to be relocatable.
Modified: branches/mono-1-1-7/mono/mono/metadata/ChangeLog
===================================================================
--- branches/mono-1-1-7/mono/mono/metadata/ChangeLog 2005-10-28 16:13:49 UTC
(rev 52332)
+++ branches/mono-1-1-7/mono/mono/metadata/ChangeLog 2005-10-28 16:34:39 UTC
(rev 52333)
@@ -1,3 +1,15 @@
+2005-10-25 Miguel de Icaza <[EMAIL PROTECTED]>
+
+ * assembly.c (mono_assemblies_init): Do not set the Mono root dir
+ if it has been previously set (embedders).
+
+ Make mono_set_rootdir available also on Unix.
+
+005-10-24 Robert Jordan <[EMAIL PROTECTED]>
+
+ * assembly.c: fixed MONO_ASSEMBLIES to be NULL on cygwin as well.
+
+
2005-07-09 Atsushi Enomoto <[EMAIL PROTECTED]>
* culture-info-table.h : regenerated.
Modified: branches/mono-1-1-7/mono/mono/metadata/Makefile.am
===================================================================
--- branches/mono-1-1-7/mono/mono/metadata/Makefile.am 2005-10-28 16:13:49 UTC
(rev 52332)
+++ branches/mono-1-1-7/mono/mono/metadata/Makefile.am 2005-10-28 16:34:39 UTC
(rev 52333)
@@ -1,19 +1,12 @@
if PLATFORM_WIN32
export HOST_CC
-# Use -m here. This will use / as directory separator (C:/WINNT).
-# The files that use MONO_ASSEMBLIES and/or MONO_CFG_DIR replace the
-# / by \ if running under WIN32.
-assembliesdir = `cygpath -m "${libdir}"`
-confdir = `cygpath -m "${sysconfdir}"`
# The mingw math.h has "extern inline" functions that dont appear in libs, so
# optimisation is required to actually inline them
AM_CFLAGS = -O
-PLATFORM_LIB = ../os/libmonoos.la
-else
-assembliesdir = $(exec_prefix)/lib
-confdir = $(sysconfdir)
endif
+PLATFORM_LIB = ../os/libmonoos.la
+
bin_PROGRAMS = pedump monodiet
#
@@ -23,8 +16,7 @@
noinst_LTLIBRARIES = libmonoruntime.la libmonoruntime-static.la
-INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/mono $(LIBGC_CFLAGS) $(GLIB_CFLAGS)
$(GMODULE_CFLAGS) $(ICU_CFLAGS) \
- -DMONO_ASSEMBLIES=\"$(assembliesdir)\" -DMONO_CFG_DIR=\"$(confdir)\"
+INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/mono $(LIBGC_CFLAGS) $(GLIB_CFLAGS)
$(GMODULE_CFLAGS)
#
# Make sure any prefix changes are updated in the binaries too.
Modified: branches/mono-1-1-7/mono/mono/metadata/assembly.c
===================================================================
--- branches/mono-1-1-7/mono/mono/metadata/assembly.c 2005-10-28 16:13:49 UTC
(rev 52332)
+++ branches/mono-1-1-7/mono/mono/metadata/assembly.c 2005-10-28 16:34:39 UTC
(rev 52333)
@@ -26,13 +26,7 @@
#include <mono/metadata/mono-config.h>
#include <mono/utils/mono-digest.h>
#include <mono/utils/mono-logger.h>
-#ifdef PLATFORM_WIN32
#include <mono/os/util.h>
-#ifdef _MSC_VER
- /* not used on Windows - see mono_set_rootdir () */
- #define MONO_ASSEMBLIES NULL
-#endif
-#endif
/* AssemblyVersionMap: an assembly name and the assembly version set on which
it is based */
typedef struct {
@@ -40,10 +34,10 @@
guint8 version_set_index;
} AssemblyVersionMap;
-/* the default search path is just MONO_ASSEMBLIES */
+/* the default search path is empty, the first slot is replaced with the
computed value */
static const char*
default_path [] = {
- MONO_ASSEMBLIES,
+ NULL,
NULL
};
@@ -296,9 +290,12 @@
void
mono_assemblies_init (void)
{
-#ifdef PLATFORM_WIN32
- mono_set_rootdir ();
-#endif
+ /*
+ * Initialize our internal paths if we have not been initialized yet.
+ * This happens when embedders use Mono.
+ */
+ if (mono_assembly_getrootdir () == NULL)
+ mono_set_rootdir ();
check_path_env ();
check_extra_gac_path_env ();
Modified: branches/mono-1-1-7/mono/mono/metadata/mono-config.c
===================================================================
--- branches/mono-1-1-7/mono/mono/metadata/mono-config.c 2005-10-28
16:13:49 UTC (rev 52332)
+++ branches/mono-1-1-7/mono/mono/metadata/mono-config.c 2005-10-28
16:34:39 UTC (rev 52333)
@@ -390,31 +390,19 @@
static const char *mono_cfg_dir = NULL;
-static void
-mono_install_get_config_dir (void)
+/* Invoked during startup */
+void
+mono_internal_set_config_dir (const char *dir)
{
-#ifdef PLATFORM_WIN32
- gchar *prefix;
-#endif
-
- mono_cfg_dir = g_getenv ("MONO_CFG_DIR");
-
- if (!mono_cfg_dir) {
-#ifndef PLATFORM_WIN32
- mono_cfg_dir = MONO_CFG_DIR;
-#else
- prefix = g_path_get_dirname (mono_assembly_getrootdir ());
- mono_cfg_dir = g_build_filename (prefix, "etc", NULL);
- g_free (prefix);
-#endif
- }
+ /* If this variable is set, overrides the directory computed */
+ mono_cfg_dir = g_getenv ("MONO_CFG_DIR");
+ if (mono_cfg_dir == NULL)
+ mono_cfg_dir = g_strdup (dir);
}
const char*
mono_get_config_dir (void)
{
- if (!mono_cfg_dir)
- mono_install_get_config_dir ();
return mono_cfg_dir;
}
Modified: branches/mono-1-1-7/mono/mono/mini/Makefile.am
===================================================================
--- branches/mono-1-1-7/mono/mono/mini/Makefile.am 2005-10-28 16:13:49 UTC
(rev 52332)
+++ branches/mono-1-1-7/mono/mono/mini/Makefile.am 2005-10-28 16:34:39 UTC
(rev 52333)
@@ -45,9 +45,10 @@
# The mingw math.h has "extern inline" functions that dont appear in libs, so
# optimisation is required to actually inline them
AM_CFLAGS = -O
-PLATFORM_LIB = ../os/libmonoos.la
endif
+PLATFORM_LIB = ../os/libmonoos.la
+
# hack for automake to have the same source file in a library and a bin
genmdesc_CFLAGS = $(AM_CFLAGS)
Modified: branches/mono-1-1-7/mono/mono/os/unix/Makefile.am
===================================================================
--- branches/mono-1-1-7/mono/mono/os/unix/Makefile.am 2005-10-28 16:13:49 UTC
(rev 52332)
+++ branches/mono-1-1-7/mono/mono/os/unix/Makefile.am 2005-10-28 16:34:39 UTC
(rev 52333)
@@ -1,5 +1,15 @@
+if PLATFORM_WIN32
+# Use -m here. This will use / as directory separator (C:/WINNT).
+# The files that use MONO_ASSEMBLIES and/or MONO_CFG_DIR replace the
+# / by \ if running under WIN32.
+assembliesdir = `cygpath -m "${libdir}"`
+confdir = `cygpath -m "${sysconfdir}"`
+else
+assembliesdir = $(exec_prefix)/lib
+confdir = $(sysconfdir)
+endif
-INCLUDES = -I$(top_srcdir)
+INCLUDES = -I$(top_srcdir) -DMONO_ASSEMBLIES=\"$(assembliesdir)\"
-DMONO_CFG_DIR=\"$(confdir)\" $(GLIB_CFLAGS)
noinst_LTLIBRARIES = libmonoos.la
Modified: branches/mono-1-1-7/mono/mono/os/unix/util.c
===================================================================
--- branches/mono-1-1-7/mono/mono/os/unix/util.c 2005-10-28 16:13:49 UTC
(rev 52332)
+++ branches/mono-1-1-7/mono/mono/os/unix/util.c 2005-10-28 16:34:39 UTC
(rev 52333)
@@ -7,19 +7,87 @@
* (C) 2002 Ximian, Inc. (http://www.ximian.com)
*/
#include <config.h>
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
+#include <sys/types.h>
+#include <unistd.h>
#include <mono/os/util.h>
+#include <mono/metadata/assembly.h>
-/*
+static char *
+compute_base (char *path)
+{
+ char *p = rindex (path, '/');
+ if (p == NULL)
+ return NULL;
+ *p = 0;
+ p = rindex (path, '/');
+ if (p == NULL){
+ return NULL;
+ }
+
+ if (strcmp (p, "/bin") != 0){
+
+ return NULL;
+ }
+ *p = 0;
+ return path;
+}
+
+static void set_dirs (char *exe)
+{
+ char *base = compute_base (exe);
+
+ /*
+ * Only /usr prefix is treated specially
+ */
+ if (base == NULL || strncmp (exe, "/usr/bin/", 9) == 0){
+ mono_assembly_setrootdir (MONO_ASSEMBLIES);
+ mono_internal_set_config_dir (MONO_CFG_DIR);
+ } else {
+ char *config, *lib;
+ config = g_build_filename (base, "etc", NULL);
+ lib = g_build_filename (base, "lib", NULL);
+ mono_assembly_setrootdir (lib);
+ mono_internal_set_config_dir (config);
+ g_free (config);
+ g_free (lib);
+ }
+}
+
+
+/**
* mono_set_rootdir:
*
- * Informs the runtime of the root directory for the Mono installation,
- * the vm_file
+ * Registers the root directory for the Mono runtime, for Linux and Solaris 10,
+ * this auto-detects the prefix where Mono was installed.
*/
void
mono_set_rootdir (void)
{
- /* nothing on Unix */
+ char buf [4096];
+ int s;
+ char *str;
+
+ /* Linux style */
+ str = g_strdup_printf ("/proc/%d/exe", getpid ());
+ s = readlink (str, buf, sizeof (buf)-1);
+ g_free (str);
+
+ if (s != -1){
+ buf [s] = 0;
+ set_dirs (buf);
+ return;
+ }
+
+ /* Solaris 10 style */
+ str = g_strdup_printf ("/proc/%d/path/a.out", getpid ());
+ s = readlink (str, buf, sizeof (buf)-1);
+ g_free (str);
+ if (s != -1){
+ buf [s] = 0;
+ set_dirs (buf);
+ }
}
-
-
Modified: branches/mono-1-1-7/mono/mono/os/win32/util.c
===================================================================
--- branches/mono-1-1-7/mono/mono/os/win32/util.c 2005-10-28 16:13:49 UTC
(rev 52332)
+++ branches/mono-1-1-7/mono/mono/os/win32/util.c 2005-10-28 16:34:39 UTC
(rev 52333)
@@ -40,7 +40,7 @@
mono_set_rootdir (void)
{
gunichar2 moddir [MAXPATHLEN];
- gchar *bindir, *installdir, *root, *utf8name;
+ gchar *bindir, *installdir, *root, *utf8name, *config;
GetModuleFileNameW (NULL, moddir, MAXPATHLEN);
utf8name = g_utf16_to_utf8 (moddir, -1, NULL, NULL, NULL);
@@ -49,10 +49,16 @@
root = g_build_path (G_DIR_SEPARATOR_S, installdir, "lib", NULL);
mono_assembly_setrootdir (root);
+
+ config = g_build_filename (root, "etc", NULL);
+ mono_internal_set_config_dir (etc);
+
+ g_free (config);
g_free (root);
g_free (installdir);
g_free (bindir);
g_free (utf8name);
+
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches