From 7714adaef85cb7d83b1624db2198aec40ddefa24 Mon Sep 17 00:00:00 2001
From: Sergei Golubchik <sergii@pisem.net>
Date: Wed, 2 Nov 2011 12:26:30 +0100
Subject: [PATCH] build on windows

---
 CMakeLists.txt                        |  7 +------
 dbug/dbug.c                           | 12 ++++++++----
 dbug/my_main.c                        |  7 -------
 libmysql/CMakeLists.txt               |  2 +-
 libmysqld/CMakeLists.txt              |  2 +-
 mysys/CMakeLists.txt                  |  2 +-
 sql/CMakeLists.txt                    |  2 +-
 storage/heap/CMakeLists.txt           |  4 ++--
 storage/innobase/sync/sync0sync.c     |  3 +++
 storage/maria/unittest/CMakeLists.txt |  2 +-
 10 files changed, 19 insertions(+), 24 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5fd951584e2..83145c72f43 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -285,12 +285,7 @@ SET (MYSQLD_STATIC_PLUGIN_LIBS "" CACHE INTERNAL "")
 ENDIF()
 
 ADD_SUBDIRECTORY(include)
-IF(CMAKE_GENERATOR MATCHES "Makefiles" AND NOT CMAKE_BUILD_TYPE MATCHES "Debug")
-  SET(DBUG_LIBRARY)
-ELSE()
-  SET(DBUG_LIBRARY dbug)
-  ADD_SUBDIRECTORY(dbug)
-ENDIF()
+ADD_SUBDIRECTORY(dbug)
 ADD_SUBDIRECTORY(strings)
 ADD_SUBDIRECTORY(vio)
 ADD_SUBDIRECTORY(regex)
diff --git a/dbug/dbug.c b/dbug/dbug.c
index 63b373921be..16ac5277707 100644
--- a/dbug/dbug.c
+++ b/dbug/dbug.c
@@ -86,6 +86,8 @@
 #include <m_string.h>
 #include <errno.h>
 
+#ifndef DBUG_OFF
+
 #ifdef HAVE_FNMATCH_H
 #include <fnmatch.h>
 #else
@@ -424,7 +426,7 @@ void _db_process_(const char *name)
  *      0 - a list of functions was not changed
  */
 
-int DbugParse(CODE_STATE *cs, const char *control)
+static int DbugParse(CODE_STATE *cs, const char *control)
 {
   const char *end;
   int rel, f_used=0;
@@ -661,8 +663,8 @@ int DbugParse(CODE_STATE *cs, const char *control)
                               (ListFlags(cs->stack->functions) & INCLUDE) ?  \
                                        0 : (uint)TRACE_ON)
 
-void FixTraceFlags_helper(CODE_STATE *cs, const char *func,
-                          struct _db_stack_frame_ *framep)
+static void FixTraceFlags_helper(CODE_STATE *cs, const char *func,
+                                 struct _db_stack_frame_ *framep)
 {
   if (framep->prev)
     FixTraceFlags_helper(cs, framep->func, framep->prev);
@@ -687,7 +689,7 @@ void FixTraceFlags_helper(CODE_STATE *cs, const char *func,
 
 #define fflags(cs) cs->stack->out_file ? ListFlags(cs->stack->functions) : TRACE_ON;
 
-void FixTraceFlags(uint old_fflags, CODE_STATE *cs)
+static void FixTraceFlags(uint old_fflags, CODE_STATE *cs)
 {
   const char *func;
   uint new_fflags, traceon, level;
@@ -2491,3 +2493,5 @@ static void sf_terminate()
 
   return;
 }
+
+#endif /* DBUG_OFF */
diff --git a/dbug/my_main.c b/dbug/my_main.c
index 48d092ca10a..d8bffe662e2 100644
--- a/dbug/my_main.c
+++ b/dbug/my_main.c
@@ -3,10 +3,6 @@
   fixed so that it could compile and run in MySQL source tree
 */
 
-#ifdef DBUG_OFF				/* We are testing dbug */
-#undef DBUG_OFF
-#endif
-
 #include <my_global.h>	/* This includes dbug.h */
 #include <my_pthread.h>
 
@@ -16,9 +12,6 @@ char *argv[];
 {
   register int result, ix;
   extern int factorial(int);
-#if defined(HAVE_PTHREAD_INIT)
-  pthread_init();			/* Must be called before DBUG_ENTER */
-#endif
   my_thread_global_init();
 
   {
diff --git a/libmysql/CMakeLists.txt b/libmysql/CMakeLists.txt
index 34bc20d77a1..6cd9b287262 100644
--- a/libmysql/CMakeLists.txt
+++ b/libmysql/CMakeLists.txt
@@ -150,7 +150,7 @@ ADD_CONVENIENCE_LIBRARY(clientlib ${CLIENT_SOURCES})
 DTRACE_INSTRUMENT(clientlib)
 ADD_DEPENDENCIES(clientlib GenError)
 
-SET(LIBS clientlib ${DBUG_LIBRARY} strings vio mysys ${ZLIB_LIBRARY} ${SSL_LIBRARIES} ${LIBDL})
+SET(LIBS clientlib dbug strings vio mysys ${ZLIB_LIBRARY} ${SSL_LIBRARIES} ${LIBDL})
 
 # Merge several convenience libraries into one big mysqlclient
 # and link them together into shared library.
diff --git a/libmysqld/CMakeLists.txt b/libmysqld/CMakeLists.txt
index f45a03cdb19..6919c1c6a32 100644
--- a/libmysqld/CMakeLists.txt
+++ b/libmysqld/CMakeLists.txt
@@ -113,7 +113,7 @@ ENDIF()
 
 
 SET(LIBS 
-  ${DBUG_LIBRARY} strings regex mysys vio 
+  dbug strings regex mysys vio 
   ${ZLIB_LIBRARY} ${SSL_LIBRARIES} 
   ${LIBWRAP} ${LIBCRYPT} ${LIBDL}
   ${MYSQLD_STATIC_PLUGIN_LIBS}
diff --git a/mysys/CMakeLists.txt b/mysys/CMakeLists.txt
index ca338369dad..c1b9efea0e2 100644
--- a/mysys/CMakeLists.txt
+++ b/mysys/CMakeLists.txt
@@ -66,7 +66,7 @@ IF(HAVE_MLOCK)
 ENDIF()
 
 ADD_CONVENIENCE_LIBRARY(mysys ${MYSYS_SOURCES})
-TARGET_LINK_LIBRARIES(mysys ${DBUG_LIBRARY} strings ${ZLIB_LIBRARY} 
+TARGET_LINK_LIBRARIES(mysys dbug strings ${ZLIB_LIBRARY} 
  ${LIBNSL} ${LIBM} ${LIBRT})
 DTRACE_INSTRUMENT(mysys)
 
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
index 1b06252d6a3..93023ae6158 100644
--- a/sql/CMakeLists.txt
+++ b/sql/CMakeLists.txt
@@ -92,7 +92,7 @@ ADD_LIBRARY(sql STATIC ${SQL_SOURCE})
 ADD_DEPENDENCIES(sql GenServerSource)
 DTRACE_INSTRUMENT(sql)
 TARGET_LINK_LIBRARIES(sql ${MYSQLD_STATIC_PLUGIN_LIBS} 
-  mysys ${DBUG_LIBRARY} strings vio regex
+  mysys dbug strings vio regex
   ${LIBWRAP} ${LIBCRYPT} ${LIBDL}
   ${SSL_LIBRARIES})
 
diff --git a/storage/heap/CMakeLists.txt b/storage/heap/CMakeLists.txt
index 4d8dc2bdd3e..0b9372bf224 100644
--- a/storage/heap/CMakeLists.txt
+++ b/storage/heap/CMakeLists.txt
@@ -22,7 +22,7 @@ SET(HEAP_SOURCES  _check.c _rectest.c hp_block.c hp_clear.c hp_close.c hp_create
 MYSQL_ADD_PLUGIN(heap ${HEAP_SOURCES} STORAGE_ENGINE MANDATORY RECOMPILE_FOR_EMBEDDED)
 
 ADD_EXECUTABLE(hp_test1 hp_test1.c)
-TARGET_LINK_LIBRARIES(hp_test1 heap mysys ${DBUG_LIBRARY} strings)
+TARGET_LINK_LIBRARIES(hp_test1 heap mysys dbug strings)
 
 ADD_EXECUTABLE(hp_test2 hp_test2.c)
-TARGET_LINK_LIBRARIES(hp_test2 heap mysys ${DBUG_LIBRARY} strings)
+TARGET_LINK_LIBRARIES(hp_test2 heap mysys dbug strings)
diff --git a/storage/innobase/sync/sync0sync.c b/storage/innobase/sync/sync0sync.c
index 0b56e736209..cef50fe4aff 100644
--- a/storage/innobase/sync/sync0sync.c
+++ b/storage/innobase/sync/sync0sync.c
@@ -35,6 +35,9 @@ Created 9/5/1995 Heikki Tuuri
 #include "sync0sync.ic"
 #endif
 
+/* disable timed_mutexes - obsolete feature that doesn't link on windows */
+#define timed_mutexes 0
+
 #include "sync0rw.h"
 #include "buf0buf.h"
 #include "srv0srv.h"
diff --git a/storage/maria/unittest/CMakeLists.txt b/storage/maria/unittest/CMakeLists.txt
index 8a83a589706..fd3e3f909ce 100644
--- a/storage/maria/unittest/CMakeLists.txt
+++ b/storage/maria/unittest/CMakeLists.txt
@@ -16,7 +16,7 @@
 
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/zlib
                     ${CMAKE_SOURCE_DIR}/unittest/mytap)
-LINK_LIBRARIES(aria myisam mytap mysys ${DBUG_LIBRARY} strings ${ZLIB_LIBRARY})
+LINK_LIBRARIES(aria myisam mytap mysys dbug strings ${ZLIB_LIBRARY})
 
 MY_ADD_TESTS(ma_control_file trnman)
 
-- 
2.30.9