Skip to content

Commit

Permalink
Miguel's patch to allow mono to be relocatable.
Browse files Browse the repository at this point in the history
svn path=/branches/mono-1-1-7/mono/; revision=52333
  • Loading branch information
Wade Berrier committed Oct 28, 2005
1 parent e8db9d0 commit e580913
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 50 deletions.
12 changes: 12 additions & 0 deletions mono/metadata/ChangeLog
@@ -1,3 +1,15 @@
2005-10-25 Miguel de Icaza <miguel@novell.com>

* 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 <robertj@gmx.net>

* assembly.c: fixed MONO_ASSEMBLIES to be NULL on cygwin as well.


2005-07-09 Atsushi Enomoto <atsushi@ximian.com>

* culture-info-table.h : regenerated.
Expand Down
14 changes: 3 additions & 11 deletions mono/metadata/Makefile.am
@@ -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

#
Expand All @@ -23,8 +16,7 @@ bin_PROGRAMS = pedump monodiet
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.
Expand Down
19 changes: 8 additions & 11 deletions mono/metadata/assembly.c
Expand Up @@ -26,24 +26,18 @@
#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 {
const char* assembly_name;
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
};

Expand Down Expand Up @@ -296,9 +290,12 @@ mono_assembly_getrootdir (void)
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 ();
Expand Down
26 changes: 7 additions & 19 deletions mono/metadata/mono-config.c
Expand Up @@ -390,31 +390,19 @@ mono_config_parse (const char *filename) {

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;
}

3 changes: 2 additions & 1 deletion mono/mini/Makefile.am
Expand Up @@ -45,9 +45,10 @@ export HOST_CC
# 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)

Expand Down
12 changes: 11 additions & 1 deletion mono/os/unix/Makefile.am
@@ -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

Expand Down
80 changes: 74 additions & 6 deletions mono/os/unix/util.c
Expand Up @@ -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);
}
}

8 changes: 7 additions & 1 deletion mono/os/win32/util.c
Expand Up @@ -40,7 +40,7 @@ void
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);
Expand All @@ -49,10 +49,16 @@ mono_set_rootdir (void)
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);

}


0 comments on commit e580913

Please sign in to comment.