Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit c4b5bae7d19ad070d1d2ba808ac8377d07f56e8e 1 parent 4a2ab03
Miguel de Icaza migueldeicaza authored
10 mono/metadata/Makefile.am
... ... @@ -1,8 +1,16 @@
1 1 if PLATFORM_WIN32
  2 +# Use -m here. This will use / as directory separator (C:/WINNT).
  3 +# The files that use MONO_ASSEMBLIES and/or MONO_CFG_DIR replace the
  4 +# / by \ if running under WIN32.
  5 +assembliesdir = `cygpath -m "${libdir}"`
  6 +confdir = `cygpath -m "${sysconfdir}"`
2 7 export HOST_CC
  8 +else
3 9 # The mingw math.h has "extern inline" functions that dont appear in libs, so
4 10 # optimisation is required to actually inline them
5 11 AM_CFLAGS = -O
  12 +assembliesdir = $(exec_prefix)/lib
  13 +confdir = $(sysconfdir)
6 14 endif
7 15
8 16 PLATFORM_LIB = ../os/libmonoos.la
@@ -16,7 +24,7 @@ bin_PROGRAMS = pedump monodiet
16 24 noinst_LTLIBRARIES = libmonoruntime.la libmonoruntime-static.la
17 25
18 26
19   -INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/mono $(LIBGC_CFLAGS) $(GLIB_CFLAGS) $(GMODULE_CFLAGS)
  27 +INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/mono $(LIBGC_CFLAGS) $(GLIB_CFLAGS) $(GMODULE_CFLAGS) -DMONO_ASSEMBLIES=\"$(assembliesdir)\" -DMONO_CFG_DIR=\"$(confdir)\"
20 28
21 29 #
22 30 # Make sure any prefix changes are updated in the binaries too.
35 mono/metadata/assembly.c
@@ -431,6 +431,41 @@ mono_assembly_getrootdir (void)
431 431 }
432 432
433 433 /**
  434 + * mono_set_dirs:
  435 + * @assembly_dir: the base directory for assemblies
  436 + * @config_dir: the base directory for configuration files
  437 + *
  438 + * This routine is used internally and by developers embedding
  439 + * the runtime into their own applications. There are a number
  440 + * of cases to consider: Mono as a system-installed package that
  441 + * is available on the location preconfigured or Mono in a relocated
  442 + * location.
  443 + *
  444 + * If you are using a system-installed Mono, you can pass NULL
  445 + * to both parameters. If you are not, you should compute both
  446 + * directory values and call this routine.
  447 + *
  448 + * The values for a given PREFIX are:
  449 + *
  450 + * assembly_dir: PREFIX/lib
  451 + * config_dir: PREFIX/etc
  452 + *
  453 + * Notice that embedders that use Mono in a relocated way must
  454 + * compute the location at runtime, as they will be in control
  455 + * of where Mono is installed.
  456 + */
  457 +void
  458 +mono_set_dirs (const char *assembly_dir, const char *config_dir)
  459 +{
  460 + if (assembly_dir == NULL)
  461 + assembly_dir = MONO_ASSEMBLIES;
  462 + if (config_dir == NULL)
  463 + config_dir = MONO_CFG_DIR;
  464 + mono_assembly_setrootdir (assembly_dir);
  465 + mono_set_config_dir (config_dir);
  466 +}
  467 +
  468 +/**
434 469 * mono_assemblies_init:
435 470 *
436 471 * Initialize global variables used by this module.
1  mono/metadata/assembly.h
@@ -93,6 +93,7 @@ typedef struct {
93 93 void mono_register_bundled_assemblies (const MonoBundledAssembly **assemblies);
94 94 void mono_register_config_for_assembly (const char* assembly_name, const char* config_xml);
95 95
  96 +void mono_set_dirs (const char *assembly_dir, const char *config_dir);
96 97 G_END_DECLS
97 98 #endif
98 99
5 mono/metadata/mono-config.c
@@ -392,7 +392,7 @@ static const char *mono_cfg_dir = NULL;
392 392
393 393 /* Invoked during startup */
394 394 void
395   -mono_internal_set_config_dir (const char *dir)
  395 +mono_set_config_dir (const char *dir)
396 396 {
397 397 /* If this variable is set, overrides the directory computed */
398 398 mono_cfg_dir = g_getenv ("MONO_CFG_DIR");
@@ -403,6 +403,9 @@ mono_internal_set_config_dir (const char *dir)
403 403 const char*
404 404 mono_get_config_dir (void)
405 405 {
  406 + if (mono_cfg_dir == NULL)
  407 + mono_set_rootdir ();
  408 +
406 409 return mono_cfg_dir;
407 410 }
408 411
1  mono/metadata/mono-config.h
@@ -9,6 +9,7 @@
9 9 #define __MONO_METADATA_CONFIG_H__
10 10
11 11 const char* mono_get_config_dir (void);
  12 +void mono_set_config_dir (const char *dir);
12 13
13 14 void mono_config_parse (const char *filename);
14 15 void mono_config_for_assembly (MonoImage *assembly);
33 mono/os/unix/util.c
@@ -14,6 +14,8 @@
14 14 #include <unistd.h>
15 15 #include <mono/os/util.h>
16 16 #include <mono/metadata/assembly.h>
  17 +#include <sys/types.h>
  18 +#include <sys/stat.h>
17 19
18 20 static char *
19 21 compute_base (char *path)
@@ -21,6 +23,11 @@ compute_base (char *path)
21 23 char *p = rindex (path, '/');
22 24 if (p == NULL)
23 25 return NULL;
  26 +
  27 + /* Not a well known Mono executable, we are embedded, cant guess the base */
  28 + if (strcmp (p, "/mono") && strcmp (p, "/monodis") && strcmp (p, "/mint") && strcmp (p, "monodiet"))
  29 + return NULL;
  30 +
24 31 *p = 0;
25 32 p = rindex (path, '/');
26 33 if (p == NULL)
@@ -35,14 +42,15 @@ compute_base (char *path)
35 42 static void
36 43 fallback ()
37 44 {
38   - mono_assembly_setrootdir (MONO_ASSEMBLIES);
39   - mono_internal_set_config_dir (MONO_CFG_DIR);
  45 + mono_set_dirs (MONO_ASSEMBLIES, MONO_CFG_DIR);
40 46 }
41 47
42 48 static void
43 49 set_dirs (char *exe)
44 50 {
45 51 char *base;
  52 + char *config, *lib, *mono;
  53 + struct stat buf;
46 54
47 55 /*
48 56 * Only /usr prefix is treated specially
@@ -50,15 +58,20 @@ set_dirs (char *exe)
50 58 if (strncmp (exe, MONO_BINDIR, strlen (MONO_BINDIR)) == 0 || (base = compute_base (exe)) == NULL){
51 59 fallback ();
52 60 return;
53   - } else {
54   - char *config, *lib;
55   - config = g_build_filename (base, "etc", NULL);
56   - lib = g_build_filename (base, "lib", NULL);
57   - mono_assembly_setrootdir (lib);
58   - mono_internal_set_config_dir (config);
59   - g_free (config);
60   - g_free (lib);
61 61 }
  62 +
  63 + config = g_build_filename (base, "etc", NULL);
  64 + lib = g_build_filename (base, "lib", NULL);
  65 + mono = g_build_filename (lib, "mono/1.0", NULL);
  66 + if (stat (mono, &buf) == -1)
  67 + fallback ();
  68 + else {
  69 + mono_set_dirs (lib, config);
  70 + }
  71 +
  72 + g_free (config);
  73 + g_free (lib);
  74 + g_free (mono);
62 75 }
63 76
64 77
4 mono/os/win32/util.c
@@ -48,10 +48,8 @@ mono_set_rootdir (void)
48 48 installdir = g_path_get_dirname (bindir);
49 49 root = g_build_path (G_DIR_SEPARATOR_S, installdir, "lib", NULL);
50 50
51   - mono_assembly_setrootdir (root);
52   -
53 51 config = g_build_filename (root, "..", "etc", NULL);
54   - mono_internal_set_config_dir (config);
  52 + mono_set_dirs (root, config);
55 53
56 54 g_free (config);
57 55 g_free (root);
1  samples/embed/teste.c
@@ -49,6 +49,7 @@ main(int argc, char* argv[]) {
49 49 * if you are planning on using the dllmaps defined on the
50 50 * system configuration
51 51 */
  52 + mono_set_dirs (NULL, NULL);
52 53 mono_config_parse (NULL);
53 54 /*
54 55 * mono_jit_init() creates a domain: each assembly is
16 support/supportw.c
@@ -158,4 +158,20 @@ FindWindowExW (gpointer hwndParent, gpointer hwndChildAfter, const char *classw,
158 158 return func (hwndParent, hwndChildAfter, classw, window);
159 159 }
160 160
  161 +int
  162 +SetWindowPos (gpointer hwnd, gpointer hwndInsertAfter, int x, int y, int cx, int cy, uint flags)
  163 +{
  164 + fprintf (stderr, "SetWindowPos 0x%x 0x%x to [%d,%dx%d,%d] %d\n", hwnd, hwndInsertAfter, x, y, cx, cy, flags);
  165 + return 1;
  166 +}
161 167
  168 +int
  169 +SendMessageA (gpointer hwnd, uint msg, gpointer wparam, gpointer lparam)
  170 +{
  171 + fprintf (stderr, "SendMessage (%d, 0x%x, 0x%x, 0x%x)\n", hwnd, msg, wparam, lparam);
  172 +}
  173 +
  174 +int
  175 +GetWindowLongA (gpointer hwnd, int a)
  176 +{
  177 +}

0 comments on commit c4b5bae

Please sign in to comment.
Something went wrong with that request. Please try again.