Permalink
Browse files

2005-11-09 Miguel de Icaza <miguel@novell.com>

	* assembly.c (mono_set_dirs): New API entry point to set the
	assembly and the config directory in one call

A more robust framework for relocation and a public API for embedders to use.


svn path=/trunk/mono/; revision=52816
  • Loading branch information...
1 parent 4a2ab03 commit c4b5bae7d19ad070d1d2ba808ac8377d07f56e8e @migueldeicaza migueldeicaza committed Nov 10, 2005
View
@@ -1,8 +1,16 @@
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}"`
export HOST_CC
+else
# The mingw math.h has "extern inline" functions that dont appear in libs, so
# optimisation is required to actually inline them
AM_CFLAGS = -O
+assembliesdir = $(exec_prefix)/lib
+confdir = $(sysconfdir)
endif
PLATFORM_LIB = ../os/libmonoos.la
@@ -16,7 +24,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)
+INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/mono $(LIBGC_CFLAGS) $(GLIB_CFLAGS) $(GMODULE_CFLAGS) -DMONO_ASSEMBLIES=\"$(assembliesdir)\" -DMONO_CFG_DIR=\"$(confdir)\"
#
# Make sure any prefix changes are updated in the binaries too.
View
@@ -430,6 +430,41 @@ mono_assembly_getrootdir (void)
return default_path [0];
}
+/**
+ * mono_set_dirs:
+ * @assembly_dir: the base directory for assemblies
+ * @config_dir: the base directory for configuration files
+ *
+ * This routine is used internally and by developers embedding
+ * the runtime into their own applications. There are a number
+ * of cases to consider: Mono as a system-installed package that
+ * is available on the location preconfigured or Mono in a relocated
+ * location.
+ *
+ * If you are using a system-installed Mono, you can pass NULL
+ * to both parameters. If you are not, you should compute both
+ * directory values and call this routine.
+ *
+ * The values for a given PREFIX are:
+ *
+ * assembly_dir: PREFIX/lib
+ * config_dir: PREFIX/etc
+ *
+ * Notice that embedders that use Mono in a relocated way must
+ * compute the location at runtime, as they will be in control
+ * of where Mono is installed.
+ */
+void
+mono_set_dirs (const char *assembly_dir, const char *config_dir)
+{
+ if (assembly_dir == NULL)
+ assembly_dir = MONO_ASSEMBLIES;
+ if (config_dir == NULL)
+ config_dir = MONO_CFG_DIR;
+ mono_assembly_setrootdir (assembly_dir);
+ mono_set_config_dir (config_dir);
+}
+
/**
* mono_assemblies_init:
*
View
@@ -93,6 +93,7 @@ typedef struct {
void mono_register_bundled_assemblies (const MonoBundledAssembly **assemblies);
void mono_register_config_for_assembly (const char* assembly_name, const char* config_xml);
+void mono_set_dirs (const char *assembly_dir, const char *config_dir);
G_END_DECLS
#endif
@@ -392,7 +392,7 @@ static const char *mono_cfg_dir = NULL;
/* Invoked during startup */
void
-mono_internal_set_config_dir (const char *dir)
+mono_set_config_dir (const char *dir)
{
/* If this variable is set, overrides the directory computed */
mono_cfg_dir = g_getenv ("MONO_CFG_DIR");
@@ -403,6 +403,9 @@ mono_internal_set_config_dir (const char *dir)
const char*
mono_get_config_dir (void)
{
+ if (mono_cfg_dir == NULL)
+ mono_set_rootdir ();
+
return mono_cfg_dir;
}
@@ -9,6 +9,7 @@
#define __MONO_METADATA_CONFIG_H__
const char* mono_get_config_dir (void);
+void mono_set_config_dir (const char *dir);
void mono_config_parse (const char *filename);
void mono_config_for_assembly (MonoImage *assembly);
View
@@ -14,13 +14,20 @@
#include <unistd.h>
#include <mono/os/util.h>
#include <mono/metadata/assembly.h>
+#include <sys/types.h>
+#include <sys/stat.h>
static char *
compute_base (char *path)
{
char *p = rindex (path, '/');
if (p == NULL)
return NULL;
+
+ /* Not a well known Mono executable, we are embedded, cant guess the base */
+ if (strcmp (p, "/mono") && strcmp (p, "/monodis") && strcmp (p, "/mint") && strcmp (p, "monodiet"))
+ return NULL;
+
*p = 0;
p = rindex (path, '/');
if (p == NULL)
@@ -35,30 +42,36 @@ compute_base (char *path)
static void
fallback ()
{
- mono_assembly_setrootdir (MONO_ASSEMBLIES);
- mono_internal_set_config_dir (MONO_CFG_DIR);
+ mono_set_dirs (MONO_ASSEMBLIES, MONO_CFG_DIR);
}
static void
set_dirs (char *exe)
{
char *base;
+ char *config, *lib, *mono;
+ struct stat buf;
/*
* Only /usr prefix is treated specially
*/
if (strncmp (exe, MONO_BINDIR, strlen (MONO_BINDIR)) == 0 || (base = compute_base (exe)) == NULL){
fallback ();
return;
- } 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);
}
+
+ config = g_build_filename (base, "etc", NULL);
+ lib = g_build_filename (base, "lib", NULL);
+ mono = g_build_filename (lib, "mono/1.0", NULL);
+ if (stat (mono, &buf) == -1)
+ fallback ();
+ else {
+ mono_set_dirs (lib, config);
+ }
+
+ g_free (config);
+ g_free (lib);
+ g_free (mono);
}
View
@@ -48,10 +48,8 @@ mono_set_rootdir (void)
installdir = g_path_get_dirname (bindir);
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 (config);
+ mono_set_dirs (root, config);
g_free (config);
g_free (root);
View
@@ -49,6 +49,7 @@ main(int argc, char* argv[]) {
* if you are planning on using the dllmaps defined on the
* system configuration
*/
+ mono_set_dirs (NULL, NULL);
mono_config_parse (NULL);
/*
* mono_jit_init() creates a domain: each assembly is
View
@@ -158,4 +158,20 @@ FindWindowExW (gpointer hwndParent, gpointer hwndChildAfter, const char *classw,
return func (hwndParent, hwndChildAfter, classw, window);
}
+int
+SetWindowPos (gpointer hwnd, gpointer hwndInsertAfter, int x, int y, int cx, int cy, uint flags)
+{
+ fprintf (stderr, "SetWindowPos 0x%x 0x%x to [%d,%dx%d,%d] %d\n", hwnd, hwndInsertAfter, x, y, cx, cy, flags);
+ return 1;
+}
+int
+SendMessageA (gpointer hwnd, uint msg, gpointer wparam, gpointer lparam)
+{
+ fprintf (stderr, "SendMessage (%d, 0x%x, 0x%x, 0x%x)\n", hwnd, msg, wparam, lparam);
+}
+
+int
+GetWindowLongA (gpointer hwnd, int a)
+{
+}

0 comments on commit c4b5bae

Please sign in to comment.