forked from mefyl/drake
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdrakefile
More file actions
412 lines (363 loc) · 13.6 KB
/
drakefile
File metadata and controls
412 lines (363 loc) · 13.6 KB
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
from itertools import chain
import drake
import drake.cxx
# Import the GNUBuilder.
with open(str(drake.path_source('drake-utils/gnu_builder.py')), 'r') as f:
exec(f.read(), globals(), globals())
def configure(cxx_toolkit = None,
cxx_config = drake.cxx.Config()):
# Create a default C++ toolkit if none is provided.
# This will use the default system compiler.
cxx_toolkit = cxx_toolkit or drake.cxx.GccToolkit()
if cxx_toolkit.os not in [drake.os.linux, drake.os.macos, drake.os.windows]:
raise Exception('Unknown OS')
## -------- ##
## Patchelf ##
## -------- ##
# This is a list of other, global dependencies that is platform specific.
# This is used to ensure that we have patchelf before building other libraries
# on Linux.
other_deps = []
# We only need patchelf for Linux.
if cxx_toolkit.os is drake.os.linux:
# Specify a rule for building patchelf.
# This is optional but would be useful if you just needed to build patchelf.
patchelf_rule = drake.Rule('patchelf')
# Specify the variables required to fetch and extract the patchelf tarball.
patchelf_version = '0.8'
patchelf_basename = 'patchelf-%s' % patchelf_version
patchelf_url = \
'http://releases.nixos.org/patchelf/%s/%s.tar.bz2' % \
(patchelf_basename, patchelf_basename)
patchelf_tarball = \
drake.node('patchelf/%s.tar.bz2' % patchelf_basename)
patchelf_configure = \
drake.node('patchelf/%s/configure' % patchelf_basename)
patchelf_prefix = drake.path_build('patchelf')
patchelf_prefix_absolute = drake.path_root() / patchelf_prefix
patchelf = drake.node('patchelf/bin/patchelf')
# Download the patchelf tarball.
drake.HTTPDownload(
patchelf_url,
patchelf_tarball,
fingerprint = '5b151e3c83b31f5931b4a9fc01635bfd',
)
# Extract the patchelf tarball.
drake.TarballExtractor(
patchelf_tarball,
targets = ['%s/configure' % patchelf_basename],
)
print(patchelf_prefix_absolute)
# Build patchelf.
GNUBuilder(
cxx_toolkit,
configure = patchelf_configure,
configure_args = [
'--prefix=%s' % patchelf_prefix_absolute,
'CXX=%s' % cxx_toolkit.cxx,
],
targets = [patchelf],
sources = [],
)
# Add patchelf to the compiler configuration.
cxx_toolkit.patchelf = patchelf
# Add the patchelf binary target to the patchelf build rule.
patchelf_rule << patchelf
other_deps.append(patchelf)
## ---- ##
## Zlib ##
## ---- ##
# Specify a rule for building zlib.
# This is optional but would be useful if you just needed to build zlib.
zlib_rule = drake.Rule('zlib')
# Specify the variables required to fetch and extract the zlib tarball.
zlib_version = '1.2.11'
zlib_basename = 'zlib-%s' % zlib_version
zlib_tarball = drake.node('zlib/%s.tar.gz' % zlib_basename)
zlib_prefix = drake.Path('zlib')
zlib_build = zlib_prefix / zlib_basename
zlib_configure = drake.node(zlib_build / 'configure')
zlib_url = 'http://zlib.net/%s.tar.gz' % zlib_basename
# Download the zlib tarball and check that the MD5 hash of the file matches
# the fingerprint.
drake.HTTPDownload(
url = zlib_url,
dest = zlib_tarball,
fingerprint = '1c9f62f0778697a09d36121ead88e08e',
)
# Extract the tarball.
# Drake will check that the specified targets are created.
drake.TarballExtractor(
tarball = zlib_tarball,
targets = ['%s/%s' % (zlib_basename, 'configure')],
)
# Different platforms may require different configure options, environments,
# etc. Drake knows which platform we're building for and so we can specify
# these differences as shown below.
zlib_configure_args = []
zlib_env = {
'CC': cxx_toolkit.c,
}
if cxx_toolkit.os is drake.os.windows:
zlib_configure_args.append('--static')
del zlib_env['CC']
zlib_configure_call = None
zlib_makefile = 'win32/Makefile.gcc'
zlib_lib = drake.cxx.StaticLib('zlib/lib/libz.a')
else:
zlib_env['CFLAGS'] = '-fPIC'
zlib_configure_call = zlib_configure
zlib_makefile = None
if cxx_toolkit.os is drake.os.macos:
zlib_lib = drake.cxx.DynLib('zlib/lib/libz.%s.dylib' % zlib_version)
elif cxx_toolkit.os is drake.os.linux:
zlib_lib = drake.cxx.DynLib('zlib/lib/libz.so.1')
zlib_prefix_absolute = drake.path_build(zlib_prefix, absolute = True)
zlib_args = [
"INCLUDE_PATH='%s/include'" % zlib_prefix_absolute,
"BINARY_PATH='%s/bin'" % zlib_prefix_absolute,
"LIBRARY_PATH='%s/lib'" % zlib_prefix_absolute,
]
if cxx_toolkit.os is drake.os.windows:
zlib_args.append("PREFIX=%s" % cxx_toolkit.prefix)
# We can now call configure and make to build zlib.
GNUBuilder(
cxx_toolkit = cxx_toolkit,
configure = zlib_configure_call,
configure_args = [
'--prefix=%s' % zlib_prefix_absolute,
] + zlib_configure_args,
additional_env = zlib_env,
working_directory = drake.path_build(zlib_build),
targets = [zlib_lib] + drake.nodes('zlib/include/zlib.h',
'zlib/include/zconf.h'),
makefile = zlib_makefile,
sources = [zlib_configure] + other_deps,
build_args = ['install'] + list(s.replace('\\', '/') for s in zlib_args)
)
# Finally we add the zlib library to the //zlib rule so that zlib can be built
# using ./drake //zlib.
zlib_rule << zlib_lib
## ------- ##
## OpenSSL ##
## ------- ##
# Specify a rule for building just OpenSSL.
openssl_rule = drake.Rule('openssl')
# Specify the parameters reuqired for fetching and extracting the OpenSSL
# tarball.
openssl_version = '1.0.2'
openssl_release_tag = 'd'
openssl_basename = 'openssl-%s' % (openssl_version + openssl_release_tag)
openssl_tarball = drake.node('openssl/%s.tar.gz' % openssl_basename)
openssl_prefix = drake.Path('openssl')
openssl_build = openssl_prefix / openssl_basename
openssl_url = 'http://www.openssl.org/source/old/%s/%s.tar.gz' % (
openssl_version, openssl_basename)
# Fetch the OpenSSL tarball.
drake.HTTPDownload(openssl_url, openssl_tarball,
fingerprint = '38dd619b2e77cbac69b99f52a053d25a')
# Extract the OpenSSL tarball.
drake.TarballExtractor(
openssl_tarball,
targets = ['%s/Configure' % openssl_basename],
patch_dir = openssl_basename,
)
# Set platform specific configuration for building OpenSSL.
openssl_configure = drake.node(openssl_build / 'Configure')
openssl_env = {
'PERL': 'perl',
'CC': cxx_toolkit.c,
'CFLAGS': '-w',
}
from drake.cxx import DynLib, StaticLib
if cxx_toolkit.os is drake.os.linux:
openssl_shared = True
openssl_lib_ssl = DynLib(openssl_prefix / 'lib/libssl.so.1.0.0')
openssl_lib_crypto = DynLib(openssl_prefix / 'lib/libcrypto.so.1.0.0')
elif cxx_toolkit.os is drake.os.macos:
openssl_shared = True
openssl_lib_ssl = DynLib(openssl_prefix / 'lib/libssl.1.0.0.dylib')
openssl_lib_crypto = DynLib(openssl_prefix / 'lib/libcrypto.1.0.0.dylib')
elif cxx_toolkit.os is drake.os.windows:
openssl_shared = False
openssl_lib_ssl = StaticLib(openssl_prefix / 'lib/libssl.a')
openssl_lib_crypto = StaticLib(openssl_prefix / 'lib/libcrypto.a')
openssl_libs = [openssl_lib_ssl, openssl_lib_crypto]
openssl_prefix_absolute = drake.path_build(openssl_prefix, absolute = True)
if cxx_toolkit.os is drake.os.linux:
if cxx_toolkit.architecture is drake.architecture.x86_64:
os_string = 'linux-x86_64'
elif cxx_toolkit.architecture is drake.architecture.x86:
os_string = 'linux-generic32'
elif cxx_toolkit.os is drake.os.macos:
os_string = 'darwin64-x86_64-cc'
elif cxx_toolkit.os is drake.os.windows:
os_string = 'mingw64'
del openssl_env['CC']
openssl_env['CROSS_COMPILE'] = '%s' % cxx_toolkit.prefix
# Build OpenSSL.
GNUBuilder(
cxx_toolkit = cxx_toolkit,
configure = openssl_configure,
configure_interpreter = 'perl',
sources = other_deps,
targets = openssl_libs,
configure_args = [
'--prefix=%s' % openssl_prefix_absolute,
openssl_shared and 'shared' or 'no-shared',
'no-asm',
'-DPURIFY',
os_string,
],
build_args = [
'all', 'install',
],
additional_env = openssl_env,
)
# Add the OpenSSL libraries to the //openssl rule.
openssl_rule << openssl_libs
## ---- ##
## Curl ##
## ---- ##
# Specify a //curl rule.
curl_rule = drake.Rule('curl')
# Specify the variables required to fetch and extract the cURL tarball.
curl_version = '7.47.0'
curl_basename = 'curl-%s' % curl_version
curl_tarball = drake.node('curl/%s.tar.gz' % curl_basename)
curl_prefix = drake.Path('curl')
curl_build = curl_prefix / curl_basename
curl_url = 'http://curl.haxx.se/download/%s.tar.gz' % curl_basename
# Fetch the cURL tarball.
drake.HTTPDownload(curl_url, curl_tarball,
fingerprint = '5109d1232d208dfd712c0272b8360393')
# Extract the cURL tarball.
drake.TarballExtractor(
curl_tarball,
targets = ['%s/%s' % (curl_basename, f) for f in (
'configure',
)],
patches = ((drake.node('patches/curl.patch'),1),),
patch_dir = curl_basename,
)
# Specify the parameters needed to configure and build cURL.
# Note that we use the zlib and OpenSSL that we specified earlier.
curl_configure = drake.node(curl_build / 'configure')
from drake.cxx import DynLib, StaticLib
if cxx_toolkit.os is drake.os.linux:
curl_lib = DynLib(curl_prefix / 'lib/libcurl.so.4')
elif cxx_toolkit.os is drake.os.macos:
curl_lib = DynLib(curl_prefix / 'lib/libcurl.4.dylib')
elif cxx_toolkit.os is drake.os.windows:
curl_lib = StaticLib(curl_prefix / 'lib/libcurl.a')
curl_openssl_libs = drake.copy(openssl_libs, curl_prefix / 'lib',
strip_prefix = True)
curl_zlib_lib = drake.copy(zlib_lib, curl_prefix / 'lib',
strip_prefix = True)
curl_configure_args = [
'--with-ssl=%s' % drake.path_build(openssl_prefix, absolute = True),
'--with-zlib=%s' % drake.path_build(zlib_prefix, absolute = True),
'--enable-hidden-symbols',
'--enable-optimize',
'--enable-warnings',
'--enable-threaded-resolver',
'--disable-ldap',
'--disable-ldaps',
'--disable-manual',
'--disable-rtmp',
'--disable-sspi',
'--disable-ssh',
'--disable-rtsp',
'--with-gssapi',
'--without-libidn',
]
curl_configure_args.append(
'--prefix=%s' % drake.path_build(curl_prefix, absolute = True))
if isinstance(curl_lib, StaticLib):
curl_configure_args.extend([
'--disable-shared',
'--enable-static',
])
else:
curl_configure_args.extend([
'--enable-shared',
'--disable-static',
])
curl_environment = {
'CC': cxx_toolkit.c,
'CFLAGS': '-w',
}
curl_configure_args.append('--host=%s' % drake.host())
if cxx_toolkit.os is drake.os.linux:
# So curl links its curl binary with the right SSL.
curl_configure_args.append(
'LDFLAGS=-Wl,-rpath-link,%s -ldl' % (openssl_prefix / 'lib'))
elif cxx_toolkit.os is drake.os.macos:
path = drake.path_build(zlib_prefix, absolute = True) / 'lib'
curl_configure_args.append('DYLD_FALLBACK_LIBRARY_PATH=%s' % path)
elif cxx_toolkit.os is drake.os.windows:
curl_environment['LIBS'] = '-lcrypt32 -lgdi32'
curl_dependency_libs = curl_openssl_libs + [curl_zlib_lib]
# As we will be using cURL in our example executable, we will add its headers
# to the expected targets of the GNUBuilder. Doing this will ensure that drake
# checks for the files once the builder has run.
curl_headers = [
'include/curl/typecheck-gcc.h',
'include/curl/stdcheaders.h',
'include/curl/easy.h',
'include/curl/mprintf.h',
'include/curl/curl.h',
'include/curl/curlver.h',
'include/curl/multi.h',
'include/curl/curlrules.h'
]
# Build cURL.
GNUBuilder(
cxx_toolkit,
configure = curl_configure,
working_directory = drake.path_build(curl_build),
targets = [curl_lib] +
drake.nodes(*(curl_prefix / path for path in curl_headers)),
configure_args = curl_configure_args,
sources = curl_dependency_libs + [curl_configure] + other_deps,
build_args = ['all', 'install',],
additional_env = curl_environment,
)
# As we built cURL with our own zlib and OpenSSL, we need to tell drake that
# it depends on them.
for lib in curl_dependency_libs:
curl_lib.dependency_add(lib)
# Specify a compiler configuration for using cURL.
# This adds the cURL headers to the compiler includes which is useful if you
# would like to use cURL somewhere.
curl_config = drake.cxx.Config()
curl_config.add_local_include_path(curl_prefix / 'include')
if cxx_toolkit.os is drake.os.windows:
curl_config.define('CURL_STATICLIB', '1')
# Add the cURL library to the curl rule.
curl_rule << curl_lib
## ---------- ##
## Executable ##
## ---------- ##
# Make a copy of the global compiler configuration for the executable.
exec_cxx_config = drake.cxx.Config(cxx_config)
# Add the cURL compiler configuration so that we get the required headers.
exec_cxx_config += curl_config
# Add the path where the libraries will be found at runtime.
exec_cxx_config.lib_path_runtime('../lib')
# Specify the sources for the executable.
sources = drake.nodes(
'http_request.cc',
)
# Add a global build rule.
build_rule = drake.Rule('build')
# Copy the cURL library (and it's dependencies) to the 'lib' directory in the
# root of the build directory.
curl_lib = drake.copy(curl_lib, 'lib', strip_prefix = True)
# Add the creation of the executable to the build rule.
build_rule << drake.cxx.Executable(
path = drake.Path('bin/http_request'),
sources = sources + [curl_lib],
tk = cxx_toolkit,
cfg = exec_cxx_config,
)