forked from libswift/libswift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
186 lines (153 loc) · 5.99 KB
/
SConstruct
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
# Written by Victor Grishchenko, Arno Bakker
# see LICENSE.txt for license information
#
# Requirements:
# - scons: Cross-platform build system http://www.scons.org/
# - libevent2: Event driven network I/O http://www.libevent.org/
# * Set install path below >= 2.0.17
# For unittests:
# - googletest: Google C++ Test Framework http://code.google.com/p/googletest/
# * Set install path in tests/SConscript
#
import os
import sys
DEBUG = True
#CODECOVERAGE = (DEBUG and True)
CODECOVERAGE = False
WITHOPENSSL = True
TestDir = u"tests"
target = 'swift'
source = [ 'bin.cpp', 'binmap.cpp', 'sha1.cpp','hashtree.cpp',
'transfer.cpp', 'channel.cpp', 'sendrecv.cpp', 'send_control.cpp',
'compat.cpp','avgspeed.cpp', 'avail.cpp', 'cmdgw.cpp', 'httpgw.cpp',
'storage.cpp', 'zerostate.cpp', 'zerohashtree.cpp',
'api.cpp', 'content.cpp', 'live.cpp', 'swarmmanager.cpp',
'address.cpp', 'livehashtree.cpp', 'livesig.cpp', 'exttrack.cpp']
# cmdgw.cpp now in there for SOCKTUNNEL
env = Environment()
if sys.platform == "win32":
# get default environment
include = os.environ.get("INCLUDE", u"")
libpath = os.environ.get("LIBPATH", u"")
cxxpath = os.environ.get('CXXPATH', u"")
# "MSVC works out of the box". Sure.
# Make sure scons finds cl.exe, etc.
env.Append ( ENV = { 'PATH' : os.environ['PATH'] } )
# Make sure scons finds std MSVC include files
if not include:
print "swift: Please run scons in a Visual Studio Command Prompt"
sys.exit(-1)
# some library dir settings
LIBEVENT2_PATH = u"\\build\\libevent-2.0.20-stable-debug"
if not os.path.exists(LIBEVENT2_PATH):
LIBEVENT2_PATH = u"\\build\\libevent-2.0.19-stable"
if not os.path.exists(LIBEVENT2_PATH):
LIBEVENT2_PATH = u"C:\\build\\libevent-2.0.21-stable"
if WITHOPENSSL:
OPENSSL_PATH = u"C:\\OpenSSL-Win32"
if not os.path.exists(OPENSSL_PATH):
OPENSSL_PATH = u"C:\\build\\openssl-1.0.1f"
include += LIBEVENT2_PATH + u"\\include;"
include += LIBEVENT2_PATH + u"\\WIN32-Code;"
libpath += LIBEVENT2_PATH + u"\\lib;"
libpath += LIBEVENT2_PATH + u";"
if WITHOPENSSL:
include += OPENSSL_PATH + u"\\include;"
libpath += OPENSSL_PATH + u"\\lib;"
env.Append ( ENV = { 'INCLUDE' : include } )
cxxpath += include
if DEBUG:
env.Append(CXXFLAGS="/Zi /MTd")
env.Append(LINKFLAGS="/DEBUG")
else:
env.Append(CXXFLAGS="/DNDEBUG") # disable asserts
if WITHOPENSSL:
env.Append(CXXFLAGS="/DOPENSSL")
env.Append(CXXPATH=cxxpath)
env.Append(CPPPATH=cxxpath)
# getopt for win32
source += [u'getopt.c', u'getopt_long.c']
# Set libs to link to
# Advapi32.lib for CryptGenRandom in evutil_rand.obj
libs = ['ws2_32', 'libevent', 'Advapi32']
if WITHOPENSSL:
libs.append('libeay32')
if DEBUG:
libs.append('Dbghelp')
# Somehow linker can't find uuid.lib
WINSDK_70 = u"C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0"
WINSDK_70A = u"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A"
WINSDK_71A = u"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.1A"
WINSDK_80A = u"C:\\Program Files (x86)\\Windows Kits\\8.0"
WINSDK_81A = u"C:\\Program Files (x86)\\Windows Kits\\8.1"
if os.path.exists(WINSDK_81A):
libpath += os.path.join(WINSDK_81A, u"Lib\\winv6.3\\um\\x86") + u";"
elif os.path.exists(WINSDK_80A):
libpath += os.path.join(WINSDK_80A, u"Lib\\Win8\\um\\x86") + u";"
elif os.path.exists(WINSDK_71A):
libpath += os.path.join(WINSDK_71A, u"Lib") + u";"
elif os.path.exists(WINSDK_70A):
libpath += os.path.join(WINSDK_70A, u"Lib") + u";"
elif os.path.exists(WINSDK_70):
libpath += os.path.join(WINSDK_70, u"Lib") + u";"
else:
print u"swift: Cannot find Windows SDK."
sys.exit(-1)
# Make the swift.exe a Windows program not a Console program when used inside another prog
if not DEBUG:
env.Append(LINKFLAGS="/SUBSYSTEM:WINDOWS")
linkflags = u""
APPSOURCE = [u'swift.cpp', u'statsgw.cpp', u'getopt.c', u'getopt_long.c']
else:
# Linux or Mac build
libevent2path = '/home/arno/pkgs/libevent-2.0.20-stable-debug'
if WITHOPENSSL:
opensslpath = '/usr/lib/i386-linux-gnu'
# Enable the user defining external includes
cpppath = os.environ.get('CPPPATH', '')
if not cpppath:
print "To use external libs, set CPPPATH environment variable to list of colon-separated include dirs"
cpppath += libevent2path+'/include:'
env.Append(CPPPATH=".:"+cpppath)
#env.Append(LINKFLAGS="--static")
#if DEBUG:
# env.Append(CXXFLAGS="-g")
# Large-file support always
env.Append(CXXFLAGS="-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE")
if WITHOPENSSL:
env.Append(CXXFLAGS="-DOPENSSL")
# Set libs to link to
libs = ['stdc++','libevent','pthread']
if WITHOPENSSL:
libs.append('ssl')
libs.append('crypto')
libpath = os.environ.get('LIBPATH', '')
if not libpath:
print "To use external libs, set LIBPATH environment variable to list of colon-separated lib dirs"
libpath += libevent2path+'/lib:'
if WITHOPENSSL:
libpath += opensslpath
linkflags = '-Wl,-rpath,'+libevent2path+'/lib'
env.Append(LINKFLAGS=linkflags);
APPSOURCE=['swift.cpp','statsgw.cpp']
env.Append(LIBPATH=libpath);
if DEBUG:
env.Append(CXXFLAGS="-DDEBUG")
env.StaticLibrary (
target='libswift',
source = source,
LIBS=libs,
LIBPATH=libpath )
env.Program(
target='swift',
source=APPSOURCE,
#CPPPATH=cpppath,
LIBS=['libswift',libs],
LIBPATH=libpath+':.')
Export("env")
Export("libs")
Export("linkflags")
Export("DEBUG")
Export("CODECOVERAGE")
# Uncomment the following line to build the tests
#SConscript('tests/SConscript')