-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconfigure
executable file
·350 lines (286 loc) · 11.8 KB
/
configure
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
#!/usr/bin/env python2.7
# Copyright 2016 Nidium Inc. All rights reserved.
# Use of this source code is governed by a MIT license
# that can be found in the LICENSE file.
import os
from konstructor import Deps
from konstructor import CommandLine
from konstructor import Build
from konstructor import Builder
from konstructor import Platform
from konstructor import Variables as Vars
from konstructor import Konstruct
from konstructor import Utils
from konstructor import assumeYes
from konstructor import Tests
from konstructor import Log
from konstructor import ROOT
Gyp = Builder.Gyp
DEPEDENCY_REPO = "http://deps.nidium.com"
Platform.setEnviron(
"CC=%s" % (os.environ.get("CC", "clang")),
"CXX=%s" % (os.environ.get("CXX", "clang++")),
"LDFLAGS=%s" % (os.environ.get("LDFLAGS", ""))
)
if Platform.system == "Darwin":
Platform.setEnviron("MACOSX_DEPLOYMENT_TARGET=10.7")
# We explicitely set "python2.7 gyp_main.py" because "gyp" executable force
# the use of "python" which could be 2.7 or 3 and gyp does not work with python3
Gyp.setExec("python2.7 third-party/gyp/gyp_main.py")
###
@Deps.register("gyp")
def gyp():
return {
"location": Deps.GitRepo("https://chromium.googlesource.com/external/gyp", revision="4ec6c4e3a94bd04a6da2858163d40b2429b8aad1")
}
@Deps.register("c-ares")
def cares():
makefile = ""
configure = "./configure --enable-shared=no"
env = Utils.Env()
if Konstruct.config("android"):
env.update(Vars.get("androidEnvClang"))
env.append("CFLAGS", "-Wno-invalid-source-encoding")
configure += " --host=%s " % (Vars.get("targetTriplet"))
elif Platform.system == 'Windows':
makefile = " -f Makefile.m32"
return {
"location": "http://c-ares.haxx.se/download/c-ares-1.12.0.tar.gz",
"build": [configure, "make" + makefile],
"env": env,
"outputs": [".libs/libcares.a"]
}
@Deps.register("openssl")
def openssl():
env = Utils.Env()
configure = ["", "make build_libs"]
if Konstruct.config("android"):
# The define OPENSSL_API_COMPAT=0x10100000L prevents OpenSSL from adding deprecated APIs
# (It also fix a naming conflic with skia sk_free() function)
configure = ["./config -fPIC -fno-integrated-as -DOPENSSL_API_COMPAT=0x10100000L", "make build_libs"]
env.update({
"CROSS_COMPILE": "arm-linux-androideabi-",
"MACHINE": Vars.get("targetCpu"),
"ANDROID_DEV": "%s/sysroot/usr/" % (Vars.get("toolchainPath"))
})
elif Platform.system == 'Windows':
configure[0] = "./Configure mingw -fPIC"
elif Platform.system == "Darwin":
configure[0] = "./config -no-shared -DOPENSSL_API_COMPAT=0x10100000L"
else:
configure[0] = "./config -fPIC -DOPENSSL_API_COMPAT=0x10100000L"
return {
"location": "https://github.com/openssl/openssl/archive/OpenSSL_1_1_0c.tar.gz",
"build": configure,
"env": env,
"outputs": ["libssl(.a|.lib)", "libcrypto(.a|.lib)"]
}
@Deps.register("zlib")
def zlip():
env = Utils.Env()
if Konstruct.config("android"):
env = Vars.get("androidEnvClang")
build = ["./configure --static", "make"]
elif Platform.system == 'Windows':
build = ["make -f ./win32/Makefile.gcc"]
else:
build = ["./configure --static", "make"]
return {
"location": "%s/zlib-1.2.11.tar.gz" % (DEPEDENCY_REPO),
"build": build,
"env": env,
"outputs": ["libz.a"]
}
@Deps.register("gperftools")
def gperftools():
return {
"location": "https://github.com/gperftools/gperftools/releases/download/gperftools-2.5/gperftools-2.5.tar.gz",
"build": ["autoconf", "chmod +x ./configure", "./configure --enable-static --enable-shared", "make"],
"outputs": [".libs/libprofiler.so.0$"]
}
@Deps.register("pprof")
def pprof():
from konstructor import ConfigCache
return {
"location": Deps.Command("GOPATH=%s go get github.com/google/pprof" % (os.path.join(Deps.getDir(), "." + ConfigCache.getConfigStr(), "pprof"))),
"outputs": [{"src": "bin/pprof", "dst": os.path.join(Deps.getDir(), "pprof", "tools")}]
}
@Deps.register("gtest")
def gtest():
flags = ""
if Platform.system == "Darwin":
flags = "-DCMAKE_CXX_FLAGS='-std=c++11 -stdlib=libc++'"
return {
"location": Deps.GitRepo("https://github.com/google/googletest.git", revision="d225acc90bc3a8c420a9bcd1f033033c1ccd7fe0"),
"build": ["cmake %s ." % flags, "make"],
"outputs": ["googlemock/libgmock.a", "googlemock/libgmock_main.a", "googlemock/gtest/libgtest.a", "googlemock/gtest/libgtest_main.a"]
}
def setupAndroidSDK():
import shutil
# The android-sdk should be placed in a "tools" directory
# (compatibility with various build system)
src = os.path.join(Deps.getDir(), "android-sdk")
dst = os.path.join(src, "tools")
if not os.path.exists(dst):
Log.debug("Moving android tools in subdirectory (%s)" % (dst))
Utils.mkdir(dst)
for f in os.listdir(src):
shutil.move(os.path.join(src, f), dst)
# Install the platform-tools, build tools, NDK and android libs
sdkManager = (os.path.join(dst, "bin", "sdkmanager"))
Log.info("Downloading android tools, this make take a while, be patient...")
Utils.run("chmod +x %s" % sdkManager)
Utils.run(sdkManager + " platform-tools")
Utils.run(sdkManager + " ndk-bundle")
Utils.run(sdkManager + " \"build-tools;25.0.2\"")
Utils.run(sdkManager + " \"platforms;android-25\"")
# Setup NDK toolchain
androidNdkPath = Vars.get("androidNdkPath")
toolchainPath = Vars.get("toolchainPath")
if os.path.isdir(toolchainPath):
Log.debug("Removing previous android toolchain")
Utils.rmdir(toolchainPath)
Utils.run("chmod +x %s/build/tools/make_standalone_toolchain.py" % (androidNdkPath))
Utils.run("%s/build/tools/make_standalone_toolchain.py \
--api=%d --install-dir=%s --arch=arm \
--stl=libc++" % (androidNdkPath, Vars.get("androidNDKAPIVersion"), toolchainPath))
@Deps.register("android-sdk")
def androidNDK():
NDKAPIVersion = 21
SDKAPIVersion = 25
toolchainPath = ROOT + "/tools/android-toolchain/"
androidSdkPath = Deps.getDir() + "/android-sdk/"
androidNdkPath = androidSdkPath + "/ndk-bundle/"
Vars.set("toolchainPath", toolchainPath);
Vars.set("androidNDKAPIVersion", NDKAPIVersion)
Vars.set("androidSDKAPIVersion", SDKAPIVersion)
Vars.set("androidNdkPath", androidNdkPath)
Vars.set("androidSdkPath", androidSdkPath)
Platform.setEnviron(
"PATH=%s:%s/bin/" % (os.environ.get("PATH", ""), toolchainPath),
"ANDROID_SDK_ROOT=%s" % (androidSdkPath),
"ANDROID_NDK_ROOT=%s" % (androidNdkPath),
)
Vars.set("androidEnvGcc", Utils.Env({
"CC": "%s/bin/arm-linux-androideabi-gcc" % toolchainPath,
"CXX": "%s/bin/arm-linux-androideabi-g++" % toolchainPath,
"AR": "%s/bin/arm-linux-androideabi-ar" % toolchainPath,
"RANLIB": "%s/bin/arm-linux-androideabi-ranlib" % toolchainPath,
"LD": "%s/bin/arm-linux-androideabi-ld.gold" % toolchainPath,
# With android ndk R13 gcc has incorrect include path. Fix that.
# See : https://github.com/android-ndk/ndk/issues/215
"CXXFLAGS": "-nostdinc %s" % (os.environ.get("CXXFLAGS", "")) +
" -I%s/include/c++/4.9.x" % (Vars.get("toolchainPath")) +
" -I%s/include/c++/4.9.x/arm-linux-androideabi" % (Vars.get("toolchainPath")) +
" -I%s/lib/gcc/arm-linux-androideabi/4.9.x/include" % (Vars.get("toolchainPath")) +
" -I%s/lib/gcc/arm-linux-androideabi/4.9.x/include-fixed" % (Vars.get("toolchainPath")) +
" -I%s/sysroot/usr/local/include" % (Vars.get("toolchainPath")) +
" -I%s/sysroot/usr/include" % (Vars.get("toolchainPath"))
}))
Vars.set("androidEnvClang", Utils.Env({
"CC": "%s/bin/arm-linux-androideabi-clang" % toolchainPath,
"CXX": "%s/bin/arm-linux-androideabi-clang++" % toolchainPath,
"AR": "%s/bin/arm-linux-androideabi-ar" % toolchainPath,
"RANLIB": "%s/bin/arm-linux-androideabi-ranlib" % toolchainPath,
"LD": "%s/bin/arm-linux-androideabi-ld.gold" % toolchainPath
}))
return {
"location": "https://dl.google.com/android/repository/tools_r25.2.3-linux.zip",
"build": [setupAndroidSDK]
}
#####
@CommandLine.option("--debug", default=False)
def debug(debug):
if debug:
Vars.set("debug", True)
Gyp.setConfiguration("Debug");
Konstruct.setConfigs(["debug"])
@CommandLine.option("--third-party-path", default="")
def gypConfig(thirdPartyPath):
if thirdPartyPath:
Deps.setDir(thirdPartyPath)
# Gyp needs a relative path
Gyp.set("third_party", os.path.relpath(thirdPartyPath))
Gyp.setExec(os.path.join(thirdPartyPath, "gyp", "gyp"))
@CommandLine.option("--module", default="")
def module(module):
if not module:
return
Deps.set(Deps.Konstruct(module, module + "/configure"))
@CommandLine.option("--unit-tests", nargs="?", const="all", default=None)
def testNetwork(unitTests):
if not unitTests:
return
head, tail = os.path.split(os.getcwd())
cwd = os.path.dirname(os.path.realpath(__file__))
#Builder.Gyp.set("asan", 1)
if unitTests:
Gyp.set("unit_test", 1)
Deps.set("gtest")
Tests.register([
"build/tests/network-unittests"
], builders=[Gyp("%s/gyp/network-unittests.gyp" % cwd)])
@Konstruct.hook("postBuild")
def runNetworkTest(success):
exitCode = 0 if Tests.runTest(success) else 4
Utils.exit(code=exitCode)
@CommandLine.option("--asan", default=False)
def asan(asan):
if asan:
Gyp.set("asan", 1)
@CommandLine.option("--android", default=False)
def android(android):
if not android:
return
if Platform.system != "Linux":
Utils.exit("Building nidium for Android is only supported on Linux")
Konstruct.setConfigs(["android"])
Gyp.set("target_cpu", Vars.get("target_cpu", "arm"));
Gyp.set("target_os", "android");
Gyp.setOutputFormat("ninja-android")
Vars.set("targetTriplet", "arm-linux-androideabi")
Vars.set("targetArch", "arm")
Vars.set("targetCpu", "armv7")
# Add android-sdk dependency just before preparing/building
# all deps so it will be the first dependency to be
# downloaded/build since all dependecies depends on it
@Konstruct.hook("start")
def androidPreBuild():
Deps.append("android-sdk")
@Konstruct.hook("preBuild")
def androidPreBuild():
Platform.setEnviron(Vars.get("androidEnvClang"))
#####
Deps.set("gyp", "c-ares", "openssl", "zlib")
Vars.set("depsRepo", DEPEDENCY_REPO)
@CommandLine.option("--mac-sdk-version", default="")
def macSdkVersion(version):
if version:
Gyp.set("mac_sdk_version", version)
def findAppleSDK(type='macosx'):
import re
type = type.lower()
if type not in [ 'macosx', 'iphoneos', 'iphonesimulator']:
Log.error("Invalid Apple SDK type %s" % type)
exit()
cmd = 'xcodebuild -showsdks'
code, output = Utils.run(cmd, failExit=True, returnOutput=True)
if code != 0 or output is None:
return None
output = output.split("\n")
sdks = []
for line in output:
if type in line:
v = re.search(type + "([0-9\.]+)", line)
if v is not None:
sdks.append(v.group(1))
return sdks[len(sdks) - 1]
if Platform.system == "Darwin":
sdk = findAppleSDK()
if sdk is None:
Utils.exit("No macos SDK detected. Make sure Xcode is correctly installed and configured")
Gyp.set("mac_sdk_version", sdk)
if __name__ == '__main__':
Gyp.setArgs("--depth ./ --include=gyp/config.gypi --include=gyp/common.gypi")
Build.add(Gyp("gyp/network.gyp"));
Konstruct.start()