Author: miguel
Date: 2005-11-09 21:24:50 -0500 (Wed, 09 Nov 2005)
New Revision: 52816

Modified:
   trunk/mono/mono/metadata/Makefile.am
   trunk/mono/mono/metadata/assembly.c
   trunk/mono/mono/metadata/assembly.h
   trunk/mono/mono/metadata/mono-config.c
   trunk/mono/mono/metadata/mono-config.h
   trunk/mono/mono/os/unix/util.c
   trunk/mono/mono/os/win32/util.c
   trunk/mono/samples/embed/teste.c
   trunk/mono/support/supportw.c
Log:
2005-11-09  Miguel de Icaza  <[EMAIL PROTECTED]>

        * 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.



Modified: trunk/mono/mono/metadata/Makefile.am
===================================================================
--- trunk/mono/mono/metadata/Makefile.am        2005-11-10 01:54:42 UTC (rev 
52815)
+++ trunk/mono/mono/metadata/Makefile.am        2005-11-10 02:24:50 UTC (rev 
52816)
@@ -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 @@
 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.

Modified: trunk/mono/mono/metadata/assembly.c
===================================================================
--- trunk/mono/mono/metadata/assembly.c 2005-11-10 01:54:42 UTC (rev 52815)
+++ trunk/mono/mono/metadata/assembly.c 2005-11-10 02:24:50 UTC (rev 52816)
@@ -431,6 +431,41 @@
 }
 
 /**
+ * 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:
  *
  *  Initialize global variables used by this module.

Modified: trunk/mono/mono/metadata/assembly.h
===================================================================
--- trunk/mono/mono/metadata/assembly.h 2005-11-10 01:54:42 UTC (rev 52815)
+++ trunk/mono/mono/metadata/assembly.h 2005-11-10 02:24:50 UTC (rev 52816)
@@ -93,6 +93,7 @@
 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
 

Modified: trunk/mono/mono/metadata/mono-config.c
===================================================================
--- trunk/mono/mono/metadata/mono-config.c      2005-11-10 01:54:42 UTC (rev 
52815)
+++ trunk/mono/mono/metadata/mono-config.c      2005-11-10 02:24:50 UTC (rev 
52816)
@@ -392,7 +392,7 @@
 
 /* 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 @@
 const char* 
 mono_get_config_dir (void)
 {
+       if (mono_cfg_dir == NULL)
+               mono_set_rootdir ();
+
        return mono_cfg_dir;
 }
 

Modified: trunk/mono/mono/metadata/mono-config.h
===================================================================
--- trunk/mono/mono/metadata/mono-config.h      2005-11-10 01:54:42 UTC (rev 
52815)
+++ trunk/mono/mono/metadata/mono-config.h      2005-11-10 02:24:50 UTC (rev 
52816)
@@ -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);

Modified: trunk/mono/mono/os/unix/util.c
===================================================================
--- trunk/mono/mono/os/unix/util.c      2005-11-10 01:54:42 UTC (rev 52815)
+++ trunk/mono/mono/os/unix/util.c      2005-11-10 02:24:50 UTC (rev 52816)
@@ -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 @@
        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 @@
 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 @@
        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);
 }
        
 

Modified: trunk/mono/mono/os/win32/util.c
===================================================================
--- trunk/mono/mono/os/win32/util.c     2005-11-10 01:54:42 UTC (rev 52815)
+++ trunk/mono/mono/os/win32/util.c     2005-11-10 02:24:50 UTC (rev 52816)
@@ -48,10 +48,8 @@
        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);

Modified: trunk/mono/samples/embed/teste.c
===================================================================
--- trunk/mono/samples/embed/teste.c    2005-11-10 01:54:42 UTC (rev 52815)
+++ trunk/mono/samples/embed/teste.c    2005-11-10 02:24:50 UTC (rev 52816)
@@ -49,6 +49,7 @@
         * 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

Modified: trunk/mono/support/supportw.c
===================================================================
--- trunk/mono/support/supportw.c       2005-11-10 01:54:42 UTC (rev 52815)
+++ trunk/mono/support/supportw.c       2005-11-10 02:24:50 UTC (rev 52816)
@@ -158,4 +158,20 @@
        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)
+{
+}

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to