summaryrefslogtreecommitdiff
path: root/SConstruct
blob: 1c109c973c04e2b18371a80d4d2567865639244e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# -*- mode: python; -*-
import re
import os
import shutil
import subprocess
import sys
import tempfile
import textwrap
import distutils.sysconfig

EnsureSConsVersion( 2, 0, 0 )

if not os.sys.platform == "win32":
    print ("SConstruct is only supported for Windows, use build_posix for other platforms")
    Exit(1)

# Command line options
#
AddOption("--dynamic-crt", dest="dynamic-crt", action="store_true", default=False,
          help="Link with the MSVCRT DLL version")

AddOption("--enable-attach", dest="attach", action="store_true", default=False,
          help="Configure for debugger attach on failure.")

AddOption("--enable-diagnostic", dest="diagnostic", action="store_true", default=False,
          help="Configure WiredTiger to perform various run-time diagnostic tests. DO NOT configure this option in production environments.")

AddOption("--enable-python", dest="lang-python", type="string", nargs=1, action="store",
          help="Build Python extension, specify location of swig.exe binary")

AddOption("--enable-snappy", dest="snappy", type="string", nargs=1, action="store",
          help="Use snappy compression")

AddOption("--enable-verbose", dest="verbose", action="store_true", default=False,
          help="Configure WiredTiger to support the verbose configuration string to wiredtiger_open")

AddOption("--enable-zlib", dest="zlib", type="string", nargs=1, action="store",
          help="Use zlib compression")

AddOption("--prefix", dest="prefix", type="string", nargs=1, action="store", default="package",
          help="Install directory")

AddOption("--with-berkeley-db", dest="bdb", type="string", nargs=1, action="store",
          help="Berkeley DB install path, ie, /usr/local")

# Get the swig binary from the command line option since SCONS cannot find it automatically
#
swig_binary = GetOption("lang-python")

# Initialize environment
#
env = Environment(
    CPPPATH = ["#/src/include/",
               "#/build_win",
               "#/test/windows",
               "#/.",
           ],
    CFLAGS = [
        "/Z7", # Generate debugging symbols
        "/wd4090", # Ignore warning about mismatched const qualifiers
        "/wd4996",
        "/W3", # Warning level 3
        "/we4013", # Error on undefined functions
        "/TC", # Compile as C code
        #"/Od", # Disable optimization
        "/Ob1", # inline expansion
        "/O2", # optimize for speed
        "/GF", # enable string pooling
        "/EHsc", # extern "C" does not throw
        #"/RTC1", # enable stack checks
        "/GS", # enable secrutiy checks
        "/Gy", # separate functions for linker
        "/Zc:wchar_t",
        "/Gd",
        "/MD" if GetOption("dynamic-crt") else "/MT",
        ],
    LINKFLAGS = [
        "/DEBUG", # Generate debug symbols
        "/INCREMENTAL:NO", # Disable incremental linking
        "/OPT:REF", # Remove dead code
        "/DYNAMICBASE",
        "/NXCOMPAT",
        ],
    tools=["default", "swig", "textfile"],
    SWIG=swig_binary
)

env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1

useZlib = GetOption("zlib")
useSnappy = GetOption("snappy")
useBdb = GetOption("bdb")
wtlibs = []

conf = Configure(env)
if not conf.CheckCHeader('stdlib.h'):
    print 'stdlib.h must be installed!'
    Exit(1)

if useZlib:
    conf.env.Append(CPPPATH=[useZlib + "/include"])
    conf.env.Append(LIBPATH=[useZlib + "/lib"])
    if conf.CheckCHeader('zlib.h'):
        conf.env.Append(CPPDEFINES=["HAVE_BUILTIN_EXTENSION_ZLIB"])
        wtlibs.append("zlib")
    else:
        print 'zlib.h must be installed!'
        Exit(1)

if useSnappy:
    conf.env.Append(CPPPATH=[useSnappy + "/include"])
    conf.env.Append(LIBPATH=[useSnappy + "/lib"])
    if conf.CheckCHeader('snappy-c.h'):
        conf.env.Append(CPPDEFINES=['HAVE_BUILTIN_EXTENSION_SNAPPY'])
        wtlibs.append("snappy")
    else:
        print 'snappy-c.h must be installed!'
        Exit(1)

if useBdb:
    conf.env.Append(CPPPATH=[useBdb+ "/include"])
    conf.env.Append(LIBPATH=[useBdb+ "/lib"])
    if not conf.CheckCHeader('db.h'):
        print 'db.h must be installed!'
        Exit(1)

env = conf.Finish()

# Configure build environment variables
#
if GetOption("attach"):
    env.Append(CPPDEFINES = ["HAVE_ATTACH"])

if GetOption("diagnostic"):
    env.Append(CPPDEFINES = ["HAVE_DIAGNOSTIC"])

if GetOption("lang-python"):
    env.Append(LIBPATH=[distutils.sysconfig.PREFIX + r"\libs"])
    env.Append(CPPPATH=[distutils.sysconfig.get_python_inc()])

if GetOption("verbose"):
    env.Append(CPPDEFINES = ["HAVE_VERBOSE"])


# Build WiredTiger.h file
#
version_file = 'build_posix/aclocal/version-set.m4'

VERSION_MAJOR = None
VERSION_MINOR = None
VERSION_PATCH = None
VERSION_STRING = None

# Read the version information from the version-set.m4 file
for l in open(File(version_file).srcnode().abspath):
    if re.match(r'^VERSION_[A-Z]+', l):
        exec(l)

if (VERSION_MAJOR == None or
    VERSION_MINOR == None or
    VERSION_PATCH == None or
    VERSION_STRING == None):
    print "Failed to find version variables in " + version_file
    Exit(1)

wiredtiger_includes = """
        #include <sys/types.h>
        #include <stdarg.h>
        #include <stdint.h>
        #include <stdio.h>
    """
wiredtiger_includes = textwrap.dedent(wiredtiger_includes)
replacements = {
    '@VERSION_MAJOR@' : VERSION_MAJOR,
    '@VERSION_MINOR@' : VERSION_MINOR,
    '@VERSION_PATCH@' : VERSION_PATCH,
    '@VERSION_STRING@' : VERSION_STRING,
    '@uintmax_t_decl@': "",
    '@uintptr_t_decl@': "",
    '@off_t_decl@' : 'typedef int64_t wt_off_t;',
    '@wiredtiger_includes_decl@': wiredtiger_includes
}

wtheader = env.Substfile(
    target='wiredtiger.h',
    source=[
        'src/include/wiredtiger.in',
    ],
    SUBST_DICT=replacements)

#
# WiredTiger library
#
filelistfile = r'build_win\filelist.win'
filelist = open(filelistfile)
wtsources = [line.strip()
             for line in filelist
             if not line.startswith("#") and len(line) > 1]
filelist.close()

if useZlib:
    wtsources.append("ext/compressors/zlib/zlib_compress.c")

if useSnappy:
    wtsources.append("ext/compressors/snappy/snappy_compress.c")

wt_objs = [env.Object(a) for a in wtsources]

# Static Library - libwiredtiger.lib
#
wtlib = env.Library(
    target="libwiredtiger",
    source=wt_objs, LIBS=wtlibs)

env.Depends(wtlib, [filelistfile, version_file])

# Dynamically Loaded Library - wiredtiger.dll
#
wtdll = env.SharedLibrary(
    target="wiredtiger",
    source=wt_objs + ['build_win/wiredtiger.def'], LIBS=wtlibs)

env.Depends(wtdll, [filelistfile, version_file])

Default(wtlib, wtdll)

wtbin = env.Program("wt", [
    "src/utilities/util_backup.c",
    "src/utilities/util_cpyright.c",
    "src/utilities/util_compact.c",
    "src/utilities/util_create.c",
    "src/utilities/util_drop.c",
    "src/utilities/util_dump.c",
    "src/utilities/util_list.c",
    "src/utilities/util_load.c",
    "src/utilities/util_load_json.c",
    "src/utilities/util_loadtext.c",
    "src/utilities/util_main.c",
    "src/utilities/util_misc.c",
    "src/utilities/util_printlog.c",
    "src/utilities/util_read.c",
    "src/utilities/util_rename.c",
    "src/utilities/util_salvage.c",
    "src/utilities/util_stat.c",
    "src/utilities/util_upgrade.c",
    "src/utilities/util_verbose.c",
    "src/utilities/util_verify.c",
    "src/utilities/util_write.c"],
    LIBS=[wtlib] + wtlibs)

Default(wtbin)

# Python SWIG wrapper for WiredTiger
if GetOption("lang-python"):
    # Check that this version of python is 64-bit
    #
    if sys.maxsize < 2**32:
        print "The Python Interpreter must be 64-bit in order to build the python bindings"
        Exit(1)

    pythonEnv = env.Clone()
    pythonEnv.Append(SWIGFLAGS=[
            "-python",
            "-threads",
            "-O",
            "-nodefaultctor",
            "-nodefaultdtor",
            ])

    swiglib = pythonEnv.SharedLibrary('_wiredtiger',
                      [ 'lang\python\wiredtiger.i'],
                      SHLIBSUFFIX=".pyd",
                      LIBS=[wtlib] + wtlibs)

    copySwig = pythonEnv.Command(
        'lang/python/wiredtiger/__init__.py',
        'lang/python/wiredtiger.py',
        Copy('$TARGET', '$SOURCE'))
    pythonEnv.Depends(copySwig, swiglib)

    swiginstall = pythonEnv.Install('lang/python/wiredtiger/', swiglib)

    Default(swiginstall, copySwig)

# Shim library of functions to emulate POSIX on Windows
shim = env.Library("window_shim",
        ["test/windows/windows_shim.c"])

t = env.Program("t_bloom",
    "test/bloom/test_bloom.c",
    LIBS=[wtlib] + wtlibs)
Default(t)

#env.Program("t_checkpoint",
    #["test/checkpoint/checkpointer.c",
    #"test/checkpoint/test_checkpoint.c",
    #"test/checkpoint/workers.c"],
    #LIBS=[wtlib])

t = env.Program("t_huge",
    "test/huge/huge.c",
    LIBS=[wtlib] + wtlibs)
Default(t)

#env.Program("t_fops",
    #["test/fops/file.c",
    #"test/fops/fops.c",
    #"test/fops/t.c"],
    #LIBS=[wtlib])

if useBdb:
    benv = env.Clone()

    benv.Append(CPPDEFINES=['BERKELEY_DB_PATH=\\"' + useBdb.replace("\\", "\\\\") + '\\"'])

    t = benv.Program("t_format",
        ["test/format/backup.c",
        "test/format/bdb.c",
        "test/format/bulk.c",
        "test/format/compact.c",
        "test/format/config.c",
        "test/format/ops.c",
        "test/format/salvage.c",
        "test/format/t.c",
        "test/format/util.c",
        "test/format/wts.c"],
         LIBS=[wtlib, shim, "libdb61"] + wtlibs)
    Default(t)

#env.Program("t_thread",
    #["test/thread/file.c",
    #"test/thread/rw.c",
    #"test/thread/stats.c",
    #"test/thread/t.c"],
    #LIBS=[wtlib])

#env.Program("t_salvage",
    #["test/salvage/salvage.c"],
    #LIBS=[wtlib])

t = env.Program("wtperf", [
    "bench/wtperf/config.c",
    "bench/wtperf/misc.c",
    "bench/wtperf/track.c",
    "bench/wtperf/wtperf.c",
    ],
    LIBS=[wtlib, shim]  + wtlibs)
Default(t)

examples = [
    "ex_access",
    "ex_all",
    "ex_async",
    "ex_call_center",
    "ex_config",
    "ex_config_parse",
    "ex_cursor",
    "ex_data_source",
    "ex_extending",
    "ex_hello",
    "ex_log",
    "ex_pack",
    "ex_process",
    "ex_schema",
    "ex_scope",
    "ex_stat",
    "ex_thread",
    ]

# WiredTiger Smoke Test suppor
# Runs each test in a custom temporary directory
#
def run_smoke_test(x):
    print "Running Smoke Test: " + x

    # Make temp dir
    temp_dir = tempfile.mkdtemp(prefix="wt_home")

    try:
        # Set WT_HOME environment variable for test
        os.environ["WIREDTIGER_HOME"] = temp_dir

        # Run the test
        ret = subprocess.call(x);
        if( ret != 0):
            sys.stderr.write("Bad exit code %d\n" % (ret))
            raise Exception()

    finally:
        # Clean directory
        #
        shutil.rmtree(temp_dir)

def builder_smoke_test(target, source, env):
    run_smoke_test(source[0].abspath)
    return None

env.Append(BUILDERS={'SmokeTest' : Builder(action = builder_smoke_test)})

for ex in examples:
    if(ex in ['ex_all', 'ex_async', 'ex_thread']):
        exp = env.Program(ex, "examples/c/" + ex + ".c", LIBS=[wtlib, shim] + wtlibs)
        Default(exp)
        env.Alias("check", env.SmokeTest(exp))
    else:
        exp = env.Program(ex, "examples/c/" + ex + ".c", LIBS=[wtdll[1]] + wtlibs)
        Default(exp)
        if not ex == 'ex_log':
            env.Alias("check", env.SmokeTest(exp))

# Install Target
#
prefix = GetOption("prefix")
env.Alias("install", env.Install(os.path.join(prefix, "bin"), wtbin))
env.Alias("install", env.Install(os.path.join(prefix, "bin"), wtdll[0])) # Just the dll
env.Alias("install", env.Install(os.path.join(prefix, "include"), wtheader))
env.Alias("install", env.Install(os.path.join(prefix, "lib"), wtdll[1])) # Just the import lib
env.Alias("install", env.Install(os.path.join(prefix, "lib"), wtlib))