blob: b3d5550df27299406a89e3db00b7c1aa1d070384 [file] [log] [blame]
Eliot Horowitzde72cdc2009-08-21 10:31:23 -04001# -*- mode: python; -*-
2
Mathias Stearn5e282b72009-11-11 14:25:09 -05003
4# --- options ----
5AddOption('--test-server',
6 dest='test_server',
7 default='127.0.0.1',
8 type='string',
9 nargs=1,
10 action='store',
11 help='IP address of server to use for testing')
12
Mathias Stearn0e16c822009-11-16 14:22:17 -050013AddOption('--c99',
14 dest='use_c99',
15 default=False,
16 action='store_true',
17 help='Compile with c99 (recommended for gcc)')
18
Mathias Stearn6870e7b2009-11-17 23:43:54 -050019AddOption('--d',
20 dest='optimize',
21 default=True,
22 action='store_false',
23 help='disable optimizations')
24
Eliot Horowitzde72cdc2009-08-21 10:31:23 -040025import os
Mathias Stearn71f302c2009-11-09 17:44:33 -050026import sys
Eliot Horowitzde72cdc2009-08-21 10:31:23 -040027
Mathias Stearn58e403e2010-02-04 14:32:14 -050028env = Environment( ENV=os.environ )
Eliot Horowitzde72cdc2009-08-21 10:31:23 -040029
Mathias Stearn0827f402010-02-04 18:01:19 -050030if os.sys.platform in ["darwin", "linux2"]:
Mathias Stearn32121ad2010-01-25 14:58:49 -050031 env.Append( CPPFLAGS=" -pedantic -Wall -ggdb " )
Eliot Horowitz43b65ea2009-10-05 19:15:35 -040032 env.Append( CPPPATH=["/opt/local/include/"] )
33 env.Append( LIBPATH=["/opt/local/lib/"] )
Mathias Stearn32121ad2010-01-25 14:58:49 -050034
Mathias Stearn0e16c822009-11-16 14:22:17 -050035 if GetOption('use_c99'):
Mathias Stearn32121ad2010-01-25 14:58:49 -050036 env.Append( CFLAGS=" -std=c99 " )
Mathias Stearn58e403e2010-02-04 14:32:14 -050037 env.Append( CXXDEFINES="MONGO_HAVE_STDINT" )
Mathias Stearn32121ad2010-01-25 14:58:49 -050038 else:
39 env.Append( CFLAGS=" -ansi " )
40
Mathias Stearn6870e7b2009-11-17 23:43:54 -050041 if GetOption('optimize'):
42 env.Append( CPPFLAGS=" -O3 " )
43 # -O3 benchmarks *significantly* faster than -O2 when disabling networking
Mathias Stearn0827f402010-02-04 18:01:19 -050044elif 'win32' == os.sys.platform:
45 env.Append( LIBS='ws2_32' )
Mathias Stearn0e16c822009-11-16 14:22:17 -050046
Eliot Horowitzde72cdc2009-08-21 10:31:23 -040047
Mathias Stearn0e16c822009-11-16 14:22:17 -050048#we shouldn't need these options in c99 mode
49if not GetOption('use_c99'):
50 conf = Configure(env)
Mathias Stearnb1058ca2009-11-12 19:13:32 -050051
Mathias Stearn0e16c822009-11-16 14:22:17 -050052 if not conf.CheckType('int64_t'):
53 if conf.CheckType('int64_t', '#include <stdint.h>\n'):
Mathias Stearn58e403e2010-02-04 14:32:14 -050054 conf.env.Append( CPPDEFINES="MONGO_HAVE_STDINT" )
Mathias Stearn0e16c822009-11-16 14:22:17 -050055 elif conf.CheckType('int64_t', '#include <unistd.h>\n'):
Mathias Stearn58e403e2010-02-04 14:32:14 -050056 conf.env.Append( CPPDEFINES="MONGO_HAVE_UNISTD" )
Mathias Stearn0e16c822009-11-16 14:22:17 -050057 elif conf.CheckType('__int64'):
Mathias Stearn58e403e2010-02-04 14:32:14 -050058 conf.env.Append( CPPDEFINES="MONGO_USE__INT64" )
Mathias Stearn0e16c822009-11-16 14:22:17 -050059 elif conf.CheckType('long long int'):
Mathias Stearn58e403e2010-02-04 14:32:14 -050060 conf.env.Append( CPPDEFINES="MONGO_USE_LONG_LONG_INT" )
Mathias Stearn0e16c822009-11-16 14:22:17 -050061 else:
62 print "*** what is your 64 bit int type? ****"
63 Exit(1)
Mathias Stearn3df607a2009-11-16 13:56:34 -050064
Mathias Stearn0e16c822009-11-16 14:22:17 -050065 env = conf.Finish()
Mathias Stearnb1058ca2009-11-12 19:13:32 -050066
Mathias Stearn0827f402010-02-04 18:01:19 -050067have_libjson = False
68conf = Configure(env)
69if conf.CheckLib('json'):
70 have_libjson = True
71env = conf.Finish()
72
Mathias Stearn71f302c2009-11-09 17:44:33 -050073if sys.byteorder == 'big':
Mathias Stearn58e403e2010-02-04 14:32:14 -050074 env.Append( CPPDEFINES="MONGO_BIG_ENDIAN" )
Mathias Stearn71f302c2009-11-09 17:44:33 -050075
Eliot Horowitzde72cdc2009-08-21 10:31:23 -040076env.Append( CPPPATH=["src/"] )
77
Mathias Stearn24905762009-11-24 18:33:36 -050078coreFiles = ["src/md5.c" ]
Richard Kreuter34560e32010-03-02 09:25:28 -050079mFiles = [ "src/mongo.c"]
80bFiles = [ "src/bson.c", "src/numbers.c"]
81mLibFiles = coreFiles + mFiles + bFiles
82bLibFiles = coreFiles + bFiles
83m = env.Library( "mongoc" , mLibFiles )
84b = env.Library( "bson" , bLibFiles )
Eliot Horowitzf3fb0f22009-10-05 21:29:58 -040085env.Default( env.Alias( "lib" , [ m[0] , b[0] ] ) )
Richard Kreuter34560e32010-03-02 09:25:28 -050086dynm = env.SharedLibrary( "mongoc" , mLibFiles )
87dynb = env.SharedLibrary( "bson" , bLibFiles )
88env.Default( env.Alias( "sharedlib" , [ dynm[0] , dynb[0] ] ) )
Eliot Horowitz43b65ea2009-10-05 19:15:35 -040089
Mathias Stearn6870e7b2009-11-17 23:43:54 -050090benchmarkEnv = env.Clone()
Mathias Stearn0827f402010-02-04 18:01:19 -050091benchmarkEnv.Append( CPPDEFINES=[('TEST_SERVER', r'\"%s\"'%GetOption('test_server'))] )
Mathias Stearn6870e7b2009-11-17 23:43:54 -050092benchmarkEnv.Append( LIBS=[m, b] )
93benchmarkEnv.Prepend( LIBPATH=["."] )
Mathias Stearn24905762009-11-24 18:33:36 -050094benchmarkEnv.Program( "benchmark" , [ "test/benchmark.c"] )
Mathias Stearn6870e7b2009-11-17 23:43:54 -050095
96testEnv = benchmarkEnv.Clone()
Mathias Stearn24905762009-11-24 18:33:36 -050097testCoreFiles = [ ]
Eliot Horowitz673f6a62009-10-07 15:03:30 -040098
Mathias Stearn0827f402010-02-04 18:01:19 -050099tests = Split('sizes resize endian_swap all_types simple update errors count_delete auth pair')
100
101if have_libjson:
102 tests.append('json')
103 testEnv.Append( LIBS=["json"] )
104
105for name in tests:
Mathias Stearnc7b76912009-11-11 12:14:26 -0500106 filename = "test/%s.c" % name
Mathias Stearn2a09ec82009-11-17 15:12:53 -0500107 exe = "test_" + name
Mathias Stearnc7b76912009-11-11 12:14:26 -0500108 test = testEnv.Program( exe , testCoreFiles + [filename] )
Mathias Stearn0827f402010-02-04 18:01:19 -0500109 test_alias = testEnv.Alias('test', [test], test[0].abspath + ' 2> ' + os.path.devnull)
Mathias Stearnc7b76912009-11-11 12:14:26 -0500110 AlwaysBuild(test_alias)
Mathias Stearnfe9cba12009-12-03 19:19:10 -0500111
112# special case for cpptest
113test = testEnv.Program( 'test_cpp' , testCoreFiles + ['test/cpptest.cpp'] )
Mathias Stearn6c6af362010-02-04 18:34:07 -0500114test_alias = testEnv.Alias('test', [test], test[0].abspath + ' 2> '+ os.path.devnull)
Mathias Stearnfe9cba12009-12-03 19:19:10 -0500115AlwaysBuild(test_alias)