diff --git a/acconfig.h b/acconfig.h
index 67e9d1759c6aa5d4652bd8dbe09689c047edd18f..9b85f47ce353d87665d1bd326dfd674af8fc2c6a 100644
--- a/acconfig.h
+++ b/acconfig.h
@@ -197,6 +197,15 @@
 /* If we want to have query cache */
 #undef HAVE_QUERY_CACHE
 
+/* Spatial extentions */
+#undef HAVE_SPATIAL
+
+/* RTree keys */
+#undef HAVE_RTREE_KEYS
+
+/* Access checks in embedded library */
+#undef HAVE_EMBEDDED_PRIVILEGE_CONTROL
+
 /* Solaris define gethostbyaddr_r with 7 arguments. glibc2 defines
    this with 8 arguments */
 #undef HAVE_SOLARIS_STYLE_GETHOST
diff --git a/configure.in b/configure.in
index 0d38e6fa37b3569558265559343d1f5a0194b52e..01b030dbfd4cdf363e0daf2281c7e42d1922ad7e 100644
--- a/configure.in
+++ b/configure.in
@@ -2132,6 +2132,31 @@ then
   AC_DEFINE(HAVE_QUERY_CACHE)
 fi
 
+AC_ARG_WITH(geometry,
+    [  --without-geometry      Do not build geometry-related parts.],
+    [with_geometry=$withval],
+    [with_geometry=yes]
+)
+
+if test "$with_geometry" = "yes"
+then
+  AC_DEFINE(HAVE_SPATIAL)
+  AC_DEFINE(HAVE_RTREE_KEYS)
+fi
+
+AC_ARG_WITH(embedded_privilege_control,
+    [  --with-embedded-privilege-control
+                          Build parts to check user's privileges.
+			  Only affects embedded library.],
+    [with_embedded_privilege_control=$withval],
+    [with_embedded_privilege_control=no]
+)
+
+if test "$with_embedded_privilege_control" = "yes"
+then
+  AC_DEFINE(HAVE_EMBEDDED_PRIVILEGE_CONTROL)
+fi
+
 AC_ARG_WITH(extra-tools,
     [  --without-extra-tools   Skip building utilites in the tools directory.],
     [with_tools=$withval],
diff --git a/include/my_global.h b/include/my_global.h
index 57c736d6f75a9dc94403cc45c671859a5aff65d7..3d1a770d87798d14ba0c9be7ce99532b5cbb0b9b 100644
--- a/include/my_global.h
+++ b/include/my_global.h
@@ -1194,6 +1194,8 @@ do { doubleget_union _tmp; \
 #define MYSQL_UNIVERSAL_CLIENT_CHARSET MYSQL_DEFAULT_CHARSET_NAME
 #endif
 
-#define HAVE_SPATIAL
-#define HAVE_RTREE_KEYS
+#if defined(EMBEDDED_LIBRARY) && !defined(HAVE_EMBEDDED_PRIVILEGE_CONTROL)
+#define NO_EMBEDDED_ACCESS_CHECKS
+#endif
+
 #endif /* my_global_h */
diff --git a/myisam/mi_open.c b/myisam/mi_open.c
index 562227d2f030669bf24c8cbffe833bd119ca673f..d03c18091aaa1ee082c567e4170a5c0dec8b6599 100644
--- a/myisam/mi_open.c
+++ b/myisam/mi_open.c
@@ -20,6 +20,7 @@
 #include "sp_defs.h"
 #include "rt_index.h"
 #include <m_ctype.h>
+#include <assert.h>
 
 #if defined(MSDOS) || defined(__WIN__)
 #ifdef __WIN__
diff --git a/mysql-test/include/have_geometry.inc b/mysql-test/include/have_geometry.inc
new file mode 100644
index 0000000000000000000000000000000000000000..169c3a41ee700c836237457e9a854fed3a04a93c
--- /dev/null
+++ b/mysql-test/include/have_geometry.inc
@@ -0,0 +1,4 @@
+-- require r/have_geometry.require
+disable_query_log;
+show variables like "have_geometry";
+enable_query_log;
diff --git a/mysql-test/r/have_geometry.require b/mysql-test/r/have_geometry.require
new file mode 100644
index 0000000000000000000000000000000000000000..ba515a4bbb618875fe0c740734144ae65dc01baf
--- /dev/null
+++ b/mysql-test/r/have_geometry.require
@@ -0,0 +1,2 @@
+Variable_name	Value
+have_geometry	YES
diff --git a/mysql-test/t/gis-rtree.test b/mysql-test/t/gis-rtree.test
index 8e91e5891b8087df7275aef8b26568b0e33349d3..817249b7e4cad9d66e6a0c5c1eb424de3be25a20 100644
--- a/mysql-test/t/gis-rtree.test
+++ b/mysql-test/t/gis-rtree.test
@@ -1,3 +1,5 @@
+-- source include/have_geometry.inc
+
 #
 # test of rtree (using with spatial data)
 #
diff --git a/mysql-test/t/gis.test b/mysql-test/t/gis.test
index ea460d5f7b0978879a47570df5774f4fa750cea8..590007caba1c0862bf74ce56783fdec593f063e6 100644
--- a/mysql-test/t/gis.test
+++ b/mysql-test/t/gis.test
@@ -1,3 +1,5 @@
+-- source include/have_geometry.inc
+
 #
 # Spatial objects
 #
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index fb9ff5be77128a7cddc64364430e1b8b39dcc8a1..368774877d0c0286c6efd560af8809b17463e47a 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -918,6 +918,7 @@ extern struct my_option my_long_options[];
 extern SHOW_COMP_OPTION have_isam, have_innodb, have_berkeley_db, have_example_db;
 extern SHOW_COMP_OPTION have_raid, have_openssl, have_symlink;
 extern SHOW_COMP_OPTION have_query_cache, have_berkeley_db, have_innodb;
+extern SHOW_COMP_OPTION have_geometry, have_rtree_keys;
 extern SHOW_COMP_OPTION have_crypt;
 extern SHOW_COMP_OPTION have_compress;
 
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index d6ecbd990c17948c9dfe561ad6c2810e7b4b1ce7..ccdb8674bc3631b98cc9cac5d145e20f0889c3d1 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -378,6 +378,7 @@ CHARSET_INFO *national_charset_info, *table_alias_charset;
 SHOW_COMP_OPTION have_berkeley_db, have_innodb, have_isam, 
  have_ndbcluster, have_example_db;
 SHOW_COMP_OPTION have_raid, have_openssl, have_symlink, have_query_cache;
+SHOW_COMP_OPTION have_geometry, have_rtree_keys;
 SHOW_COMP_OPTION have_crypt, have_compress;
 
 /* Thread specific variables */
@@ -5362,6 +5363,16 @@ static void mysql_init_variables(void)
 #else
   have_query_cache=SHOW_OPTION_NO;
 #endif
+#ifdef HAVE_SPATIAL
+  have_geometry=SHOW_OPTION_YES;
+#else
+  have_geometry=SHOW_OPTION_NO;
+#endif
+#ifdef HAVE_RTREE_KEYS
+  have_rtree_keys=SHOW_OPTION_YES;
+#else
+  have_rtree_keys=SHOW_OPTION_NO;
+#endif
 #ifdef HAVE_CRYPT
   have_crypt=SHOW_OPTION_YES;
 #else
diff --git a/sql/set_var.cc b/sql/set_var.cc
index b3b0153652bfe0bcfcd518376b1431c197500b49..1112a869515b029e004a54a1f736aa5d24618551 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -643,10 +643,12 @@ struct show_var_st init_vars[]= {
   {"have_crypt",	      (char*) &have_crypt,		    SHOW_HAVE},
   {"have_innodb",	      (char*) &have_innodb,		    SHOW_HAVE},
   {"have_isam",		      (char*) &have_isam,		    SHOW_HAVE},
+  {"have_geometry",           (char*) &have_geometry,               SHOW_HAVE},
   {"have_ndbcluster",         (char*) &have_ndbcluster,             SHOW_HAVE},
   {"have_openssl",	      (char*) &have_openssl,		    SHOW_HAVE},
   {"have_query_cache",        (char*) &have_query_cache,            SHOW_HAVE},
   {"have_raid",		      (char*) &have_raid,		    SHOW_HAVE},
+  {"have_rtree_keys",         (char*) &have_rtree_keys,             SHOW_HAVE},
   {"have_symlink",            (char*) &have_symlink,                SHOW_HAVE},
   {"init_connect",            (char*) &sys_init_connect,            SHOW_SYS},
   {"init_file",               (char*) &opt_init_file,               SHOW_CHAR_PTR},