Permalink
Browse files

Merge branch 'master-mongo-c-driver-master'

  • Loading branch information...
2 parents 2f4a39f + 631fc11 commit 6aad30a09ae4f11e63c3e56e315609fc3978e900 Jérôme Lebel committed Mar 23, 2012
View
174 Makefile
@@ -0,0 +1,174 @@
+# MongoDB C Driver Makefile
+#
+# Copyright 2009, 2010 10gen Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Version
+MONGO_MAJOR=0
+MONGO_MINOR=4
+BSON_MAJOR=$(MONGO_MAJOR)
+BSON_MINOR=$(MONGO_MINOR)
+
+# Library names
+MONGO_LIBNAME=libmongoc
+BSON_LIBNAME=libbson
+
+# TODO: add replica set test, cpp test, platform tests, json_test
+TESTS=test/auth_test test/bson_test test/bson_subobject_test test/count_delete_test \
+ test/cursors_test test/endian_swap_test test/errors_test test/examples_test \
+ test/functions_test test/gridfs_test test/helpers_test \
+ test/oid_test test/resize_test test/simple_test test/sizes_test test/update_test \
+ test/validate_test
+MONGO_OBJECTS=src/bson.o src/encoding.o src/gridfs.o src/md5.o src/mongo.o \
+ src/numbers.o src/env_posix.o
+BSON_OBJECTS=src/bson.o src/numbers.o
+
+# Compile flags
+ALL_DEFINES=$(DEFINES)
+ALL_DEFINES+=-DMONGO_USE_GETADDRINFO
+CC:=$(shell sh -c 'type $(CC) >/dev/null 2>/dev/null && echo $(CC) || echo gcc')
+
+# Endianness check
+endian := $(shell sh -c 'echo "ab" | od -x | grep "6261" >/dev/null && echo little || echo big')
+ifeq ($(endian),big)
+ ALL_DEFINES+=-DMONGO_BIG_ENDIAN
+endif
+
+# Posix settings
+
+# Int64 type check
+int64:=$(shell ./check_int64.sh $(CC) stdint.h && echo stdint)
+ifeq ($(int64),stdint)
+ ALL_DEFINES+=-DMONGO_HAVE_STDINT
+else
+ int64:=$(shell ./check_int64.sh $(CC) unistd.h && echo unistd)
+ ifeq ($(int64),unistd)
+ ALL_DEFINES+=-DMONGO_HAVE_UNISTD
+ endif
+endif
+$(shell rm header_check.tmp tmp.c)
+
+TEST_DEFINES=$(ALL_DEFINES)
+TEST_DEFINES+=-DTEST_SERVER="\"127.0.0.1\""
+
+OPTIMIZATION?=-O3
+WARNINGS?=-Wall
+DEBUG?=-ggdb
+ALL_CFLAGS=$(CFLAGS) $(OPTIMIZATION) $(WARNINGS) $(DEBUG) $(ALL_DEFINES)
+ALL_LDFLAGS=$(LDFLAGS)
+
+# Shared libraries
+DYLIBSUFFIX=so
+STLIBSUFFIX=a
+MONGO_DYLIBNAME=$(MONGO_LIBNAME).$(DYLIBSUFFIX)
+MONGO_DYLIB_MINOR_NAME=$(MONGO_LIBNAME).$(DYLIBSUFFIX).$(MONGO_MAJOR).$(MONGO_MINOR)
+MONGO_DYLIB_MAJOR_NAME=$(MONGO_LIBNAME).$(DYLIBSUFFIX).$(MONGO_MAJOR)
+MONGO_DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(MONGO_DYLIB_MINOR_NAME) -o $(MONGO_DYLIBNAME) $(ALL_LDFLAGS)
+
+BSON_DYLIBNAME=$(BSON_LIBNAME).$(DYLIBSUFFIX)
+BSON_DYLIB_MINOR_NAME=$(BSON_LIBNAME).$(DYLIBSUFFIX).$(BSON_MAJOR).$(BSON_MINOR)
+BSON_DYLIB_MAJOR_NAME=$(BSON_LIBNAME).$(DYLIBSUFFIX).$(BSON_MAJOR)
+BSON_DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(BSON_DYLIBNAME_VERSIONED) -o $(BSON_DYLIBNAME) $(ALL_LDFLAGS)
+
+# Static libraries
+MONGO_STLIBNAME=$(MONGO_LIBNAME).$(STLIBSUFFIX)
+BSON_STLIBNAME=$(BSON_LIBNAME).$(STLIBSUFFIX)
+
+# Overrides
+kernel_name := $(shell sh -c 'uname -s 2>/dev/null || echo not')
+ifeq ($(kernel_name),SunOS)
+ ALL_LDFLAGS+=-ldl -lnsl -lsocket
+ INSTALL_CMD=cp -r
+ MONGO_DYLIB_MAKE_CMD=$(CC) -G -o $(MONGO_DYLIBNAME) -h $(MONGO_DYLIB_MINOR_NAME) $(ALL_LDFLAGS)
+ BSON_DYLIB_MAKE_CMD=$(CC) -G -o $(BSON_DYLIBNAME) -h $(BSON_DYLIB_MINOR_NAME) $(ALL_LDFLAGS)
+endif
+ifeq ($(kernel_name),Darwin)
+ DYLIBSUFFIX=dylib
+ MONGO_DYLIB_MINOR_NAME=$(MONGO_LIBNAME).$(DYLIBSUFFIX).$(MONGO_MAJOR).$(MONGO_MINOR)
+ MONGO_DYLIB_MAJOR_NAME=$(MONGO_LIBNAME).$(DYLIBSUFFIX).$(MONGO_MAJOR)
+ MONGO_DYLIB_MAKE_CMD=$(CC) -shared -Wl,-install_name,$(MONGO_DYLIB_MINOR_NAME) -o $(MONGO_DYLIBNAME)
+
+ BSON_DYLIB_MINOR_NAME=$(BSON_LIBNAME).$(DYLIBSUFFIX).$(BSON_MAJOR).$(BSON_MINOR)
+ BSON_DYLIB_MAJOR_NAME=$(BSON_LIBNAME).$(DYLIBSUFFIX).$(BSON_MAJOR)
+ BSON_DYLIB_NAME_CMD=$(CC) -shared -Wl,-install_name,$(BSON_DYLIB_MINOR_NAME) -o $(BSON_DYLIBNAME)
+endif
+
+# Installation
+ifeq ($(kernel_name),SunOS)
+ INSTALL?=cp -r
+endif
+INSTALL?= cp -a
+INSTALL_INCLUDE_PATH?=/usr/local/include
+INSTALL_LIBRARY_PATH?=/usr/local/lib
+
+# TARGETS
+all: $(MONGO_DYLIBNAME) $(BSON_DYLIBNAME) $(MONGO_STLIBNAME) $(BSON_STLIBNAME)
+
+# Dependency targets. Run 'make deps' to generate these.
+bson.o: src/bson.c src/bson.h src/platform.h src/encoding.h
+encoding.o: src/encoding.c src/bson.h src/platform.h src/encoding.h
+env_default.o: src/env_default.c src/env.h src/mongo.h src/bson.h \
+ src/platform.h
+env_posix.o: src/env_posix.c src/env.h src/mongo.h src/bson.h \
+ src/platform.h
+gridfs.o: src/gridfs.c src/gridfs.h src/mongo.h src/bson.h src/platform.h
+md5.o: src/md5.c src/md5.h
+mongo.o: src/mongo.c src/mongo.h src/bson.h src/platform.h src/md5.h \
+ src/env.h
+numbers.o: src/numbers.c
+
+$(MONGO_DYLIBNAME): $(MONGO_OBJECTS)
+ $(MONGO_DYLIB_MAKE_CMD)
+
+$(MONGO_STLIBNAME): $(MONGO_OBJECTS)
+ $(AR) -rs $@ $(MONGO_OBJECTS)
+
+$(BSON_DYLIBNAME): $(BSON_OBJECTS)
+ $(BSON_DYLIB_MAKE_CMD)
+
+$(BSON_STLIBNAME): $(BSON_OBJECTS)
+ $(AR) -rs $@ $(BSON_OBJECTS)
+
+install:
+ mkdir -p $(INSTALL_INCLUDE_PATH) $(INSTALL_LIBRARY_PATH)
+ $(INSTALL) src/mongo.h src/bson.h $(INSTALL_INCLUDE_PATH)
+ $(INSTALL) $(MONGO_DYLIBNAME) $(INSTALL_LIBRARY_PATH)/$(MONGO_DYLIB_MINOR_NAME)
+ $(INSTALL) $(BSON_DYLIBNAME) $(INSTALL_LIBRARY_PATH)/$(BSON_DYLIB_MINOR_NAME)
+ cd $(INSTALL_LIBRARY_PATH) && ln -sf $(MONGO_DYLIB_MINOR_NAME) $(MONGO_DYLIB_MAJOR_NAME)
+ cd $(INSTALL_LIBRARY_PATH) && ln -sf $(BSON_DYLIB_MINOR_NAME) $(BSON_DYLIB_MAJOR_NAME)
+ $(INSTALL) $(MONGO_STLIBNAME) $(INSTALL_LIBRARY_PATH)
+ $(INSTALL) $(BSON_STLIBNAME) $(INSTALL_LIBRARY_PATH)
+
+test: $(TESTS)
+ sh runtests.sh
+
+valgrind: $(TESTS)
+ sh runtests.sh -v
+
+clean:
+ rm -rf $(MONGO_DYLIBNAME) $(MONGO_STLIBNAME) $(BSON_DYLIBNAME) $(BSON_STLIBNAME) src/*.o test/*_test
+
+deps:
+ $(CC) -MM -DMONGO_HAVE_STDINT src/*.c
+
+32bit:
+ $(MAKE) CFLAGS="-m32" LDFLAGS="-pg"
+
+%_test: %_test.c $(MONGO_STLIBNAME)
+ $(CC) -o $@ -Isrc $(TEST_DEFINES) $(ALL_LDFLAGS) $< $(MONGO_STLIBNAME)
+
+%.o: %.c
+ $(CC) -o $@ -c $(ALL_CFLAGS) $<
+
+.PHONY: clean
View
@@ -79,14 +79,14 @@ env.AlwaysBuild("docs")
PLATFORM_TEST_DIR = None
if "LINUX" == GetOption('compile_platform'):
env.Append( CPPFLAGS=" -D_MONGO_USE_LINUX_SYSTEM -D_POSIX_SOURCE" )
- NET_LIB = "src/platform/linux/net.c"
+ NET_LIB = "src/env_posix.c"
PLATFORM_TEST_DIR = "test/platform/linux/"
PLATFORM_TESTS = [ "timeouts" ]
elif "CUSTOM" == GetOption('compile_platform'):
env.Append( CPPFLAGS=" -D_MONGO_USE_CUSTOM_SYSTEM" )
- NET_LIB = "src/platform/custom/net.c"
+ NET_LIB = "src/env_default.c"
else:
- NET_LIB = "src/net.c"
+ NET_LIB = "src/env_default.c"
# ---- Libraries ----
if os.sys.platform in ["darwin", "linux2"]:
@@ -169,8 +169,6 @@ dynb = bsonEnv.SharedLibrary( "bson" , bSharedObjs )
env.Default( env.Alias( "sharedlib" , [ dynm[0] , dynb[0] ] ) )
-
-
# ---- Benchmarking ----
benchmarkEnv = env.Clone()
benchmarkEnv.Append( CPPDEFINES=[('TEST_SERVER', r'\"%s\"'%GetOption('test_server')),
@@ -214,4 +212,3 @@ AlwaysBuild(test_alias)
repl_testEnv = benchmarkEnv.Clone()
repl_tests = ["replica_set"]
run_tests("test", repl_tests, repl_testEnv, "repl_test")
-
View
@@ -0,0 +1,21 @@
+#!/bin/bash
+#
+# Copyright 2009, 2010 10gen Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# $1 is C compiler. $2 is header file
+cat <<EOF >tmp.c && $1 -o header_check.tmp tmp.c
+#include <$2>
+int main() { int64_t i=0; return 0; }
+EOF
View
@@ -0,0 +1,44 @@
+#!/bin/bash
+# Arguments -v for valgrind
+
+usage()
+{
+cat <<EOF
+ usage $0 options
+
+ OPTIONS:
+
+ -h usage
+ -v run the tests using valgrind
+EOF
+}
+
+valgrind=0
+while getopts "h:v" OPTION
+do
+ case $OPTION in
+ h)
+ usage
+ exit 1
+ ;;
+ v)
+ valgrind=1
+ ;;
+ esac
+done
+
+for i in `find . -name *_test`
+do
+ if [ $valgrind -eq 1 ]
+ then
+ valgrind $i
+ else
+ $i
+ fi
+
+ if [ $? != 0 ];
+ then
+ echo "$i failed!"
+ exit 1
+ fi
+done
View
File renamed without changes.
@@ -16,7 +16,7 @@
*/
/* Implementation for generic version of net.h */
-#include "net.h"
+#include "env.h"
#include <errno.h>
#include <string.h>
#include <errno.h>
@@ -16,8 +16,11 @@
*/
/* Implementation for Linux version of net.h */
-#include "net.h"
#include <string.h>
+#include <errno.h>
+#include <sys/time.h>
+
+#include "env.h"
#ifndef NI_MAXSERV
# define NI_MAXSERV 32
@@ -57,32 +60,6 @@ int mongo_read_socket( mongo *conn, void *buf, int len ) {
return MONGO_OK;
}
-static int mongo_set_blocking_status( mongo *conn ) {
- int flags;
- int blocking;
-
- blocking = ( conn->conn_timeout_ms == 0 );
- if( blocking )
- return MONGO_OK;
- else {
- if( ( flags = fcntl( conn->sock, F_GETFL ) ) == -1 ) {
- conn->err = MONGO_IO_ERROR;
- mongo_close_socket( conn->sock );
- return MONGO_ERROR;
- }
-
- flags |= O_NONBLOCK;
-
- if( ( flags = fcntl( conn->sock, F_SETFL, flags ) ) == -1 ) {
- conn->err = MONGO_IO_ERROR;
- mongo_close_socket( conn->sock );
- return MONGO_ERROR;
- }
- }
-
- return MONGO_OK;
-}
-
int mongo_set_socket_op_timeout( mongo *conn, int millis ) {
struct timeval tv;
tv.tv_sec = millis / 1000;
File renamed without changes.
View
@@ -24,11 +24,11 @@
#include <stdlib.h>
#ifdef _USE_LINUX_SYSTEM
-#include "platform/linux/net.h"
+#include "env_posix.h"
#elif defined _USE_CUSTOM_SYSTEM
-#include "platform/custom/net.h"
+#include "env.h"
#else
-#include "net.h"
+#include "env.h"
#endif
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 6aad30a

Please sign in to comment.