-
Notifications
You must be signed in to change notification settings - Fork 59
/
configure.py
115 lines (88 loc) · 2.84 KB
/
configure.py
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
import optparse
import os
import sys
import shutil
import platform
script_dir = os.path.dirname(__file__)
root_dir = os.path.normpath(script_dir)
output_dir = os.path.join(os.path.abspath(root_dir), 'out')
curl_root = os.path.join(os.path.abspath(root_dir), 'curl')
sys.path.insert(0, os.path.join(root_dir, 'build', 'gyp', 'pylib'))
try:
import gyp
except ImportError:
print('You need to install gyp in build/gyp first. See the README.')
sys.exit(42)
# parse our options
parser = optparse.OptionParser()
parser.add_option("--toolchain",
action="store",
type="choice",
dest="toolchain",
choices=['2008', '2010', '2012', '2013', '2015', 'auto'],
help="msvs toolchain to build for. [default: %default]",
default='auto')
parser.add_option("--target-arch",
action="store",
dest="target_arch",
type='choice',
choices=['x86', 'x64'],
help="CPU architecture to build for. [default: %default]",
default='x86')
(options, args) = parser.parse_args()
def getoption(value, default):
if not value:
return default
return value
def configure_defines(o):
"""
Configures libcurl
"""
o.extend(['-D', 'target_arch=%s' % getoption(options.target_arch, host_arch())])
o.extend(['-D', 'host_arch=%s' % getoption(options.target_arch, host_arch())])
o.extend(['-D', 'library=static_library'])
def configure_buildsystem(o):
"""
Configures buildsystem
"""
# gyp target
args.append(os.path.join(root_dir, 'curl.gyp'))
# includes
args.extend(['-I', os.path.join(root_dir, 'common.gypi')])
# msvs
o.extend(['-f', 'msvs'])
# msvs toolchain
if options.toolchain:
o.extend(['-G', 'msvs_version=' + options.toolchain])
# gyp
o.append('--depth=' + root_dir)
o.append('-Goutput_dir=' + os.path.join(output_dir, options.target_arch))
o.append('--generator-output=' + os.path.join(output_dir, options.target_arch))
o.append('--suffix=.' + options.target_arch)
# copy curlbuild.h
shutil.copy(os.path.join(root_dir, "build\\curlbuild.h"),
os.path.join(curl_root, "include\\curl\\curlbuild.h"))
# copy tool_hugehelp.c
shutil.copy(os.path.join(root_dir, "build\\tool_hugehelp.c"),
os.path.join(curl_root, "lib\\tool_hugehelp.c"))
def host_arch():
machine = platform.machine()
if machine == 'i386':
return 'ia32'
return 'x64'
def run_gyp(args):
"""
Executes gyp
"""
rc = gyp.main(args)
if rc != 0:
print 'Error running GYP'
sys.exit(rc)
# gyp arguments
args = []
# gyp configure
configure_buildsystem(args)
configure_defines(args)
# build
gyp_args = list(args)
run_gyp(gyp_args)