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
|
#!/usr/bin/env python
import optparse
import os
import pprint
import re
import shlex
import subprocess
import sys
root_dir = os.path.dirname(__file__)
# parse our options
parser = optparse.OptionParser()
parser.add_option("--debug",
action="store_true",
dest="debug",
help="Also build debug build")
parser.add_option("--node",
action="store",
dest="node",
help="Name of the node executable (defaults to node)")
parser.add_option("--npm",
action="store",
dest="npm",
help="Name of the npm executable (defaults to npm)")
parser.add_option("--pkg-config-root",
action="store",
dest="pkgconfig_root",
help="Path to pkg-config directory")
parser.add_option("--boost",
action="store",
dest="boost_root",
help="Path to boost (defaults to /usr/local)")
(options, args) = parser.parse_args()
def pkg_config(pkg, pkgconfig_root):
env = os.environ.copy()
if pkgconfig_root:
env["PKG_CONFIG_PATH"] = pkgconfig_root
env["PKG_CONFIG_ALLOW_SYSTEM_CFLAGS"] = "1"
env["PKG_CONFIG_ALLOW_SYSTEM_LIBS"] = "1"
cmd = subprocess.Popen(['pkg-config', '--static', '--libs', pkg], stdout=subprocess.PIPE, env=env)
libs, ret = cmd.communicate()
if (ret): return None
cmd = subprocess.Popen(['pkg-config', '--static', '--cflags', pkg], stdout=subprocess.PIPE, env=env)
cflags, ret = cmd.communicate()
if (ret): return None
return (libs, cflags)
def configure_mbgl(o):
if options.boost_root:
o['variables']['boost_root'] = options.boost_root
else:
o['variables']['boost_root'] = '/usr/local'
if options.node:
o['variables']['node'] = options.node
else:
o['variables']['node'] = 'node'
if options.npm:
o['variables']['npm'] = options.npm
else:
o['variables']['npm'] = 'npm'
o['target_defaults']['default_configuration'] = 'Debug' if options.debug else 'Release'
def fix_frameworks(libs):
# don't split "-framework Foo"
return re.split('(?<!-framework)\s+', libs.strip())
def configure_glfw3(o):
ret = pkg_config('glfw3', options.pkgconfig_root)
if not ret:
sys.stderr.write('could not find glfw3 with pkg-config')
sys.exit(-1)
o['variables']['glfw3_libraries'] = fix_frameworks(ret[0])
o['variables']['glfw3_cflags'] = ret[1].split()
def configure_uv(o):
ret = pkg_config('libuv', options.pkgconfig_root)
if not ret:
sys.stderr.write('could not find uv with pkg-config')
sys.exit(-1)
o['variables']['uv_libraries'] = ret[0].split()
o['variables']['uv_cflags'] = ret[1].split()
def configure_png(o):
ret = pkg_config('libpng', options.pkgconfig_root)
if not ret:
sys.stderr.write('could not find png with pkg-config')
sys.exit(-1)
o['variables']['png_libraries'] = ret[0].split()
o['variables']['png_cflags'] = ret[1].split()
def configure_curl(o):
ret = pkg_config('libcurl', options.pkgconfig_root)
if not ret:
sys.stderr.write('could not find curl with pkg-config')
sys.exit(-1)
o['variables']['curl_libraries'] = ret[0].split()
o['variables']['curl_cflags'] = ret[1].split()
def write(filename, data):
filename = os.path.join(root_dir, filename)
print "creating ", filename
f = open(filename, 'w+')
f.write(data)
output = {
'variables': { 'python': sys.executable },
'target_defaults' : {
'include_dirs': [],
'libraries': [],
'defines': [],
'cflags': []
}
}
if __name__ == '__main__':
configure_mbgl(output)
configure_glfw3(output)
configure_uv(output)
configure_png(output)
configure_curl(output)
pprint.pprint(output, indent=2)
write('config.gypi', "# Do not edit. Generated by the configure script.\n" +
pprint.pformat(output, indent=2) + "\n")
|