152 строки
4.3 KiB
Python
152 строки
4.3 KiB
Python
# -*- mode: python; -*-
|
|
|
|
VERSION = "0.3.2"
|
|
|
|
# --- options ----
|
|
AddOption('--test-server',
|
|
dest='test_server',
|
|
default='127.0.0.1',
|
|
type='string',
|
|
nargs=1,
|
|
action='store',
|
|
help='IP address of server to use for testing')
|
|
|
|
AddOption('--seed-start-port',
|
|
dest='seed_start_port',
|
|
default=30000,
|
|
type='int',
|
|
nargs=1,
|
|
action='store',
|
|
help='IP address of server to use for testing')
|
|
|
|
AddOption('--c99',
|
|
dest='use_c99',
|
|
default=False,
|
|
action='store_true',
|
|
help='Compile with c99 (recommended for gcc)')
|
|
|
|
AddOption('--d',
|
|
dest='optimize',
|
|
default=True,
|
|
action='store_false',
|
|
help='disable optimizations')
|
|
|
|
import os
|
|
import sys
|
|
|
|
import buildscripts
|
|
|
|
env = Environment( ENV=os.environ )
|
|
|
|
|
|
|
|
# ---- Docs ----
|
|
def build_docs(env, target, source):
|
|
from buildscripts import docs
|
|
docs.main()
|
|
|
|
env.Alias("docs", [], [build_docs])
|
|
env.AlwaysBuild("docs")
|
|
|
|
|
|
|
|
# ---- Libraries ----
|
|
if os.sys.platform in ["darwin", "linux2"]:
|
|
env.Append( CPPFLAGS=" -pedantic -Wall -ggdb -DMONGO_HAVE_STDINT" )
|
|
env.Append( CPPPATH=["/opt/local/include/"] )
|
|
env.Append( LIBPATH=["/opt/local/lib/"] )
|
|
|
|
if GetOption('use_c99'):
|
|
env.Append( CFLAGS=" -std=c99 " )
|
|
env.Append( CXXDEFINES="MONGO_HAVE_STDINT" )
|
|
else:
|
|
env.Append( CFLAGS=" -ansi " )
|
|
|
|
if GetOption('optimize'):
|
|
env.Append( CPPFLAGS=" -O3 " )
|
|
# -O3 benchmarks *significantly* faster than -O2 when disabling networking
|
|
elif 'win32' == os.sys.platform:
|
|
env.Append( LIBS='ws2_32' )
|
|
|
|
#we shouldn't need these options in c99 mode
|
|
if not GetOption('use_c99'):
|
|
conf = Configure(env)
|
|
|
|
if not conf.CheckType('int64_t'):
|
|
if conf.CheckType('int64_t', '#include <stdint.h>\n'):
|
|
conf.env.Append( CPPDEFINES="MONGO_HAVE_STDINT" )
|
|
elif conf.CheckType('int64_t', '#include <unistd.h>\n'):
|
|
conf.env.Append( CPPDEFINES="MONGO_HAVE_UNISTD" )
|
|
elif conf.CheckType('__int64'):
|
|
conf.env.Append( CPPDEFINES="MONGO_USE__INT64" )
|
|
elif conf.CheckType('long long int'):
|
|
conf.env.Append( CPPDEFINES="MONGO_USE_LONG_LONG_INT" )
|
|
else:
|
|
print "*** what is your 64 bit int type? ****"
|
|
Exit(1)
|
|
|
|
env = conf.Finish()
|
|
|
|
have_libjson = False
|
|
conf = Configure(env)
|
|
if conf.CheckLib('json'):
|
|
have_libjson = True
|
|
env = conf.Finish()
|
|
|
|
if sys.byteorder == 'big':
|
|
env.Append( CPPDEFINES="MONGO_BIG_ENDIAN" )
|
|
|
|
env.Append( CPPPATH=["src/"] )
|
|
|
|
coreFiles = ["src/md5.c" ]
|
|
mFiles = [ "src/mongo.c", "src/net.c", "src/gridfs.c"]
|
|
bFiles = [ "src/bson.c", "src/numbers.c", "src/encoding.c"]
|
|
mLibFiles = coreFiles + mFiles + bFiles
|
|
bLibFiles = coreFiles + bFiles
|
|
m = env.Library( "mongoc" , mLibFiles )
|
|
b = env.Library( "bson" , bLibFiles )
|
|
env.Default( env.Alias( "lib" , [ m[0] , b[0] ] ) )
|
|
|
|
if os.sys.platform == "linux2":
|
|
env.Append( SHLINKFLAGS="-shared -Wl,-soname,libmongoc.so." + VERSION )
|
|
env.Append( SHLINKFLAGS = "-shared -Wl,-soname,libbson.so." + VERSION )
|
|
|
|
dynm = env.SharedLibrary( "mongoc" , mLibFiles )
|
|
dynb = env.SharedLibrary( "bson" , bLibFiles )
|
|
env.Default( env.Alias( "sharedlib" , [ dynm[0] , dynb[0] ] ) )
|
|
|
|
|
|
|
|
# ---- Benchmarking ----
|
|
benchmarkEnv = env.Clone()
|
|
benchmarkEnv.Append( CPPDEFINES=[('TEST_SERVER', r'\"%s\"'%GetOption('test_server')),
|
|
('SEED_START_PORT', r'%d'%GetOption('seed_start_port'))] )
|
|
benchmarkEnv.Append( LIBS=[m, b] )
|
|
benchmarkEnv.Prepend( LIBPATH=["."] )
|
|
benchmarkEnv.Program( "benchmark" , [ "test/benchmark.c"] )
|
|
|
|
|
|
|
|
# ---- Tests ----
|
|
testEnv = benchmarkEnv.Clone()
|
|
testCoreFiles = [ ]
|
|
|
|
tests = Split("sizes resize endian_swap all_types simple update errors "
|
|
"count_delete auth gridfs validate examples replica_set timeouts helpers oid cursors")
|
|
|
|
if have_libjson:
|
|
tests.append('json')
|
|
testEnv.Append( LIBS=["json"] )
|
|
|
|
for name in tests:
|
|
filename = "test/%s.c" % name
|
|
exe = "test_" + name
|
|
test = testEnv.Program( exe , testCoreFiles + [filename] )
|
|
test_alias = testEnv.Alias('test', [test], test[0].abspath + ' 2> ' + os.path.devnull)
|
|
AlwaysBuild(test_alias)
|
|
|
|
# special case for cpptest
|
|
test = testEnv.Program( 'test_cpp' , testCoreFiles + ['test/cpptest.cpp'] )
|
|
test_alias = testEnv.Alias('test', [test], test[0].abspath + ' 2> '+ os.path.devnull)
|
|
AlwaysBuild(test_alias)
|