2005-11-09 Miguel de Icaza <miguel@novell.com>
authorMiguel de Icaza <miguel@gnome.org>
Thu, 10 Nov 2005 02:24:50 +0000 (02:24 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Thu, 10 Nov 2005 02:24:50 +0000 (02:24 -0000)
* 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

mono/metadata/Makefile.am
mono/metadata/assembly.c
mono/metadata/assembly.h
mono/metadata/mono-config.c
mono/metadata/mono-config.h
mono/os/unix/util.c
mono/os/win32/util.c
samples/embed/teste.c
support/supportw.c

index da1839fc6f6ec7f4f00c18bb11ba8a624c32b488..89d26ddd96553b7583689dada2eff3fdba293b1f 100644 (file)
@@ -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.
index cdd680983dd429c79b988cd76978df069b86de4c..dbae3e620219b4092d34ca2ad784216ab1384a18 100644 (file)
@@ -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:
  *
index b46a169550d2e7e2faccb7bf3311b4879b8a2b6b..34518d5491d22b16ce795fa33beb1d52d5031d99 100644 (file)
@@ -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
 
index b0b3e6e48bccc75d0c9dfd61563307f2896596ca..689ad309835a5257814bd31876cbd431d778d219 100644 (file)
@@ -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;
 }
 
index ab045fa16d50a81e0000d5736d50250c9d16c1dd..5541315122f7b88ca44e5d264eb1c096f22e0835 100644 (file)
@@ -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);
index 8115c6bdfdef0515d72813c6292d2c568e7138e9..e4b96d707020b6b5607a49166e6abfc621730ebb 100644 (file)
@@ -14,6 +14,8 @@
 #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)
@@ -21,6 +23,11 @@ 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,14 +42,15 @@ 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
@@ -50,15 +58,20 @@ set_dirs (char *exe)
        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);
 }
        
 
index b69b99ba0ae51ee06ae903d8c5d6b496788f6455..33c6923c74e42008dfc6621429b16c0b19747705 100644 (file)
@@ -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);
index d6a7b8381a18e7c6899ef76ea1df2681bee5f011..acfcabee6e608e977bbd1a4213317bc21b7948dd 100644 (file)
@@ -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
index 5e3daa4f2c57fd09530cf91fbb3089ea04c8dbae..9c843e4c4f9ec73079e8994471ef5f07e2fb2808 100644 (file)
@@ -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)
+{
+}