Browse files

Fix mingw cross build

* don't require libevent when winsock2 available
* use sasl_client_init() for sasl presence check
* remove pthread flags
* add plugin-win32.c to SOURCES and -Iwin32 to CPPFLAGS
* remove configuration header (NMakefile users could use configuration.h
  from the tarball)

Change-Id: I38e44c7475a39117aadfa98edbabd78075ab70d8
Reviewed-on: http://review.couchbase.org/13262
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
  • Loading branch information...
1 parent c8e0a65 commit 433491865f01ebbac1dbb94ff2aaaac13498ec67 @avsej avsej committed with trondn Feb 15, 2012
View
12 Makefile.am
@@ -57,7 +57,6 @@ libcouchbase_la_SOURCES = \
src/handler.c \
src/instance.c \
src/internal.h \
- src/iofactory.c \
src/packet.c \
src/remove.c \
src/ringbuffer.c \
@@ -86,20 +85,25 @@ libcouchbase_la_LDFLAGS= -version-info $(LIBCOUCHBASE_API_CURRENT):$(LIBCOUCHBAS
libcouchbase_la_CPPFLAGS=$(AM_CPPFLAGS) $(CPPFLAGS) -DLIBCOUCHBASE_INTERNAL=1
libcouchbase_la_LIBADD=-lvbucket $(LIBSASL)
+if HAVE_WINSOCK2
+if !HAVE_LIBEVENT
+libcouchbase_la_SOURCES += src/plugin-win32.c src/iofactory_win32.c
+libcouchbase_la_CPPFLAGS += -Iwin32
+endif
+else
+libcouchbase_la_SOURCES += src/iofactory.c
if LIBCOUCHBASE_LIBEVENT_PLUGIN_EMBED
libcouchbase_la_SOURCES += src/plugin-libevent.c
libcouchbase_la_LIBADD += -levent
libcouchbase_la_CPPFLAGS += -DLIBCOUCHBASE_LIBEVENT_PLUGIN_EMBED
-
else
lib_LTLIBRARIES += libcouchbase_libevent.la
libcouchbase_libevent_la_SOURCES = src/plugin-libevent.c
libcouchbase_libevent_la_LDFLAGS=-version-info 1:0:0
libcouchbase_libevent_la_LIBADD=-levent
libcouchbase_libevent_la_CPPFLAGS=$(AM_CPPFLAGS) $(CPPFLAGS) -DLIBCOUCHBASE_INTERNAL=1
-
endif
-
+endif
tests/CouchbaseMock.jar:
@echo "+---------------------------------------------+"
View
29 configure.ac
@@ -135,6 +135,24 @@ AC_CACHE_CHECK([for libvbucket], [ac_cv_have_libvbucket],
AS_IF([test "x${ac_cv_have_libvbucket}" != "xyes" -o "x$ac_cv_header_libvbucket_vbucket_h" != "xyes"],
[AC_MSG_ERROR(Failed to locate libvbucket)])
+dnl Check that we can use winsock2 plugin
+AC_CACHE_CHECK([for winsock2], [ac_cv_have_winsock2],
+ [ saved_libs="$LIBS"
+ LIBS=-lws2_32
+ AC_TRY_LINK([
+ #include <winsock2.h>
+ #include <ws2tcpip.h>
+ ],[
+ DWORD error = WSAGetLastError();
+ ],[
+ ac_cv_have_winsock2="yes"
+ ], [
+ ac_cv_have_winsock2="no"
+ ])
+ LIBS="$saved_libs"
+ ])
+AM_CONDITIONAL(HAVE_WINSOCK2, [test "$ac_cv_have_winsock2" = "yes"])
+
dnl Check that we've got a usable libevent
AC_CACHE_CHECK([for libevent], [ac_cv_have_libevent],
[ saved_libs="$LIBS"
@@ -150,8 +168,10 @@ AC_CACHE_CHECK([for libevent], [ac_cv_have_libevent],
])
LIBS="$saved_libs"
])
+AM_CONDITIONAL(HAVE_LIBEVENT, [test "x${ac_cv_have_libevent}" = "xyes"])
-AS_IF([test "x${ac_cv_have_libevent}" != "xyes" -o "x$ac_cv_header_event_h" != "xyes"],
+dnl Fail if libevent is the only networking backend accessible
+AS_IF([test "x${ac_cv_have_winsock2}" != "xyes" -a \( "x${ac_cv_have_libevent}" != "xyes" -o "x$ac_cv_header_event_h" != "xyes" \)],
[AC_MSG_ERROR(Failed to locate libevent)])
AC_CACHE_CHECK([for libevent2], [ac_cv_have_libevent2],
@@ -198,7 +218,7 @@ AC_CACHE_CHECK([for libsasl], [ac_cv_have_libsasl],
#include <stdlib.h>
#include <sasl/sasl.h>
],[
- sasl_server_init(NULL, NULL);
+ sasl_client_init(NULL);
],[
ac_cv_have_libsasl="yes"
], [
@@ -215,7 +235,7 @@ AS_IF([test "$ac_cv_have_libsasl" = no], [
#include <stdlib.h>
#include <sasl/sasl.h>
],[
- sasl_server_init(NULL, NULL);
+ sasl_client_init(NULL);
],[
ac_cv_have_libsasl2="yes"
], [
@@ -272,10 +292,9 @@ AS_IF([test "x${ac_cv_enable_tools}" = "xyes"],
AM_CONDITIONAL(BUILD_TOOLS, [test "x${ac_cv_enable_tools}" = "xyes"])
-AC_CHECK_FUNCS_ONCE(gethrtime clock_gettime gettimeofday)
+AC_CHECK_FUNCS_ONCE(gethrtime clock_gettime gettimeofday QueryPerformanceCounter)
AM_CONDITIONAL(HAVE_GETHRTIME, [test "x${ac_cv_func_gethrtime}" = "xyes"])
-
AC_ARG_ENABLE([embed-libevent-plugin],
[AS_HELP_STRING([--enable-embed-libevent-plugin],
[embed libevent plugin into libcouchbase rather
View
14 include/libcouchbase/configuration.h.in
@@ -40,6 +40,19 @@
extern "C" {
#endif
+#ifdef _WIN32
+#define PACKAGE_STRING "@PACKAGE_STRING@"
+ typedef __int64 libcouchbase_int64_t;
+ typedef unsigned long libcouchbase_size_t;
+ typedef long libcouchbase_ssize_t;
+ typedef unsigned __int8 libcouchbase_uint8_t;
+ typedef unsigned __int16 libcouchbase_vbucket_t;
+ typedef unsigned __int16 libcouchbase_uint16_t;
+ typedef unsigned __int32 libcouchbase_uint32_t;
+ typedef unsigned __int64 libcouchbase_cas_t;
+ typedef unsigned __int64 libcouchbase_uint64_t;
+ typedef time_t libcouchbase_time_t;
+#else
typedef int64_t libcouchbase_int64_t;
typedef size_t libcouchbase_size_t;
typedef ssize_t libcouchbase_ssize_t;
@@ -50,6 +63,7 @@ extern "C" {
typedef uint64_t libcouchbase_cas_t;
typedef uint64_t libcouchbase_uint64_t;
typedef time_t libcouchbase_time_t;
+#endif
#ifdef __cplusplus
}
View
2 include/libcouchbase/types.h
@@ -93,7 +93,7 @@ extern "C" {
struct libcouchbase_tap_filter_st;
typedef struct libcouchbase_tap_filter_st* libcouchbase_tap_filter_t;
-#ifdef WIN32
+#ifdef _WIN32
typedef SOCKET libcouchbase_socket_t;
#else
typedef int libcouchbase_socket_t;
View
4 m4/couchbase.m4
@@ -44,12 +44,12 @@ AC_DEFUN([COUCHBASE_GENERIC_COMPILER], [
GCC_C_DEBUG="-O0 -g3"
GCC_CXX_DEBUG="-O0 -g3"
GCC_VISIBILITY="-DHAVE_VISIBILITY=1 -fvisibility=hidden"
- GCC_CPPFLAGS="-pthread -pipe -D_THREAD_SAFE"
+ GCC_CPPFLAGS="-pipe"
GCC_CFLAGS="-std=gnu99"
GCC_CXXFLAGS=""
GCC_C89=-std=c89
GCC_C99=-std=gnu99
- GCC_LDFLAGS="-lpthread"
+ GCC_LDFLAGS=""
GCC_CPP_WARNINGS="-Wall -pedantic -Wundef -Wshadow -fdiagnostics-show-option -Wformat -fno-strict-aliasing -Wno-strict-aliasing -Wextra"
GCC_C_COMPILER_WARNINGS="-Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -Wmissing-declarations -Wcast-align"
GCC_CXX_COMPILER_WARNINGS="-std=gnu++98 -Woverloaded-virtual -Wnon-virtual-dtor -Wctor-dtor-privacy -Wno-long-long -Wno-redundant-decls"
View
43 src/config_static.h
@@ -56,10 +56,42 @@
#include <sys/time.h>
#endif
-#ifndef WIN32
+#ifdef _WIN32
+/* winsock error map */
+#include <errno.h>
+#ifndef ECONNRESET
+#define ECONNRESET WSAECONNRESET
+#endif
+#ifndef EWOULDBLOCK
+#define EWOULDBLOCK WSAEWOULDBLOCK
+#endif
+#ifndef EINVAL
+#define EINVAL WSAEINVAL
+#endif
+#ifndef EINPROGRESS
+#define EINPROGRESS WSAEINPROGRESS
+#endif
+#ifndef EALREADY
+#define EALREADY WSAEALREADY
+#endif
+#ifndef EISCONN
+#define EISCONN WSAEISCONN
+#endif
+#ifndef ENOTCONN
+#define ENOTCONN WSAENOTCONN
+#endif
+#ifndef ECONNREFUSED
+#define ECONNREFUSED WSAECONNREFUSED
+#endif
+
+typedef int ssize_t;
+#define snprintf _snprintf
+#undef strdup
+#define strdup _strdup
+#else
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
-#endif
+#endif /* _WIN32 */
#ifndef HAVE_HTONLL
#ifdef WORDS_BIGENDIAN
@@ -76,8 +108,8 @@ extern "C" {
#ifdef __cplusplus
}
#endif
-#endif
-#endif
+#endif /* WORDS_BIGENDIAN */
+#endif /* HAVE_HTONLL */
#ifdef linux
@@ -88,9 +120,8 @@ extern "C" {
#endif
#ifndef HAVE_GETHRTIME
-#include <stdint.h>
typedef uint64_t hrtime_t;
extern hrtime_t gethrtime(void);
#endif
-#endif
+#endif /* LIBCOUCHBASE_CONFIG_STATIC_H */
View
2 tests/getopt-test.cc
@@ -517,7 +517,7 @@ static int testParseMix() {
Getopt getopt;
setup(getopt);
-#ifdef WIN32
+#ifdef _WIN32
assertFalse(getopt.parse(argv));
#else
if (!getopt.parse(argv)) {
View
4 tools/cbc-util.cc
@@ -16,7 +16,7 @@
*/
#include "config.h"
-#ifdef WIN32
+#ifdef _WIN32
#include <io.h>
#include <fcntl.h>
#endif
@@ -73,7 +73,7 @@ bool readIt(libcouchbase_uint8_t *ptr, libcouchbase_size_t size)
return true;
}
-#ifdef WIN32
+#ifdef _WIN32
void setBinaryIO(void)
{
// Windows defaults to text mode, but we're going to read/write
View
2 tools/cbc-util.h
@@ -20,7 +20,7 @@
void sendIt(const libcouchbase_uint8_t *ptr, libcouchbase_size_t size);
bool readIt(libcouchbase_uint8_t *ptr, libcouchbase_size_t size);
-#ifdef WIN32
+#ifdef _WIN32
void setBinaryIO(void);
#else
#define setBinaryIO()
View
10 win32/config.h
@@ -1,5 +1,3 @@
-#ifndef CONFIG_H
-#define CONFIG_H
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 2011 Couchbase, Inc.
@@ -28,18 +26,14 @@
* @author Trond Norbye
*/
+#ifndef CONFIG_H
+#define CONFIG_H
#include <stdint.h>
#include <string.h>
#define HAVE_WINSOCK2_H 1
#define HAVE_WS2TCPIP_H 1
#define HAVE_QUERYPERFORMANCECOUNTER 1
-typedef int ssize_t;
-
-#define snprintf _snprintf
-#undef strdup
-#define strdup _strdup
-
#include "config_static.h"
#endif
View
19 win32/libcouchbase/configuration.h
@@ -32,15 +32,16 @@
#include <stddef.h>
#include <time.h>
-#define LIBCOUCHBASE_VERSION_STRING "1.0.0"
-#define LIBCOUCHBASE_VERSION 0x010000
+#define LIBCOUCHBASE_VERSION_STRING "1.0.1"
+#define LIBCOUCHBASE_VERSION 0x010001
#define LIBCOUCHBASE_VERSION_CHANGESET unknown
-#define PACKAGE_STRING "libcouchbase 1.8.0"
#ifdef __cplusplus
extern "C" {
#endif
+#ifdef _WIN32
+#define PACKAGE_STRING "libcouchbase 1.0.1"
typedef __int64 libcouchbase_int64_t;
typedef unsigned long libcouchbase_size_t;
typedef long libcouchbase_ssize_t;
@@ -51,6 +52,18 @@ extern "C" {
typedef unsigned __int64 libcouchbase_cas_t;
typedef unsigned __int64 libcouchbase_uint64_t;
typedef time_t libcouchbase_time_t;
+#else
+ typedef int64_t libcouchbase_int64_t;
+ typedef size_t libcouchbase_size_t;
+ typedef ssize_t libcouchbase_ssize_t;
+ typedef uint16_t libcouchbase_vbucket_t;
+ typedef uint8_t libcouchbase_uint8_t;
+ typedef uint16_t libcouchbase_uint16_t;
+ typedef uint32_t libcouchbase_uint32_t;
+ typedef uint64_t libcouchbase_cas_t;
+ typedef uint64_t libcouchbase_uint64_t;
+ typedef time_t libcouchbase_time_t;
+#endif
#ifdef __cplusplus
}

0 comments on commit 4334918

Please sign in to comment.