OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """A helper script to print paths of NaCl binaries, includes, libs, etc. | 6 """A helper script to print paths of NaCl binaries, includes, libs, etc. |
7 | 7 |
8 It is similar in behavior to pkg-config or sdl-config. | 8 It is similar in behavior to pkg-config or sdl-config. |
9 """ | 9 """ |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... |
37 'x86_64': 'x86_64' | 37 'x86_64': 'x86_64' |
38 } | 38 } |
39 | 39 |
40 ARCH_BASE_NAME = { | 40 ARCH_BASE_NAME = { |
41 'arm': 'arm', | 41 'arm': 'arm', |
42 'x86_32': 'x86', | 42 'x86_32': 'x86', |
43 'i686': 'x86', | 43 'i686': 'x86', |
44 'x86_64': 'x86' | 44 'x86_64': 'x86' |
45 } | 45 } |
46 | 46 |
47 NACL_TOOLCHAINS = ('newlib', 'glibc', 'pnacl', 'bionic') | 47 NACL_TOOLCHAINS = ('newlib', 'glibc', 'pnacl', 'bionic', 'clang-newlib') |
48 HOST_TOOLCHAINS = ('linux', 'mac', 'win') | 48 HOST_TOOLCHAINS = ('linux', 'mac', 'win') |
49 VALID_TOOLCHAINS = list(HOST_TOOLCHAINS) + list(NACL_TOOLCHAINS) + ['host'] | 49 VALID_TOOLCHAINS = list(HOST_TOOLCHAINS) + list(NACL_TOOLCHAINS) + ['host'] |
50 | 50 |
51 # This is not an exhaustive list of tools, just the ones that need to be | 51 # This is not an exhaustive list of tools, just the ones that need to be |
52 # special-cased. | 52 # special-cased. |
53 | 53 |
54 # e.g. For PNaCL cc => pnacl-clang | 54 # e.g. For PNaCL cc => pnacl-clang |
55 # For NaCl cc => pnacl-gcc | 55 # For NaCl cc => pnacl-gcc |
56 # | 56 # |
57 # Most tools will be passed through directly. | 57 # Most tools will be passed through directly. |
58 # e.g. For PNaCl foo => pnacl-foo | 58 # e.g. For PNaCl foo => pnacl-foo |
59 # For NaCl foo => x86_64-nacl-foo. | 59 # For NaCl foo => x86_64-nacl-foo. |
60 PNACL_TOOLS = { | 60 CLANG_TOOLS = { |
61 'cc': 'clang', | 61 'cc': 'clang', |
62 'c++': 'clang++', | 62 'c++': 'clang++', |
63 'gcc': 'clang', | 63 'gcc': 'clang', |
64 'g++': 'clang++', | 64 'g++': 'clang++', |
65 'ld': 'clang++' | 65 'ld': 'clang++' |
66 } | 66 } |
67 | 67 |
68 NACL_TOOLS = { | 68 GCC_TOOLS = { |
69 'cc': 'gcc', | 69 'cc': 'gcc', |
70 'c++': 'g++', | 70 'c++': 'g++', |
71 'gcc': 'gcc', | 71 'gcc': 'gcc', |
72 'g++': 'g++', | 72 'g++': 'g++', |
73 'ld': 'g++' | 73 'ld': 'g++' |
74 } | 74 } |
75 | 75 |
76 | 76 |
77 class Error(Exception): | 77 class Error(Exception): |
78 pass | 78 pass |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 if getos.GetPlatform() == 'win': | 146 if getos.GetPlatform() == 'win': |
147 return sdk_path.replace('\\', '/') | 147 return sdk_path.replace('\\', '/') |
148 else: | 148 else: |
149 return sdk_path | 149 return sdk_path |
150 | 150 |
151 | 151 |
152 def GetToolchainDir(toolchain, arch=None): | 152 def GetToolchainDir(toolchain, arch=None): |
153 ExpectToolchain(toolchain, NACL_TOOLCHAINS) | 153 ExpectToolchain(toolchain, NACL_TOOLCHAINS) |
154 root = GetPosixSDKPath() | 154 root = GetPosixSDKPath() |
155 platform = getos.GetPlatform() | 155 platform = getos.GetPlatform() |
156 if toolchain == 'pnacl': | 156 if toolchain in ('pnacl', 'clang-newlib'): |
157 subdir = '%s_pnacl' % platform | 157 subdir = '%s_pnacl' % platform |
158 else: | 158 else: |
159 assert arch is not None | 159 assert arch is not None |
160 subdir = '%s_%s_%s' % (platform, GetArchBaseName(arch), toolchain) | 160 subdir = '%s_%s_%s' % (platform, GetArchBaseName(arch), toolchain) |
161 | 161 |
162 return posixpath.join(root, 'toolchain', subdir) | 162 return posixpath.join(root, 'toolchain', subdir) |
163 | 163 |
164 | 164 |
165 def GetToolchainArchDir(toolchain, arch): | 165 def GetToolchainArchDir(toolchain, arch): |
166 ExpectToolchain(toolchain, NACL_TOOLCHAINS) | 166 ExpectToolchain(toolchain, NACL_TOOLCHAINS) |
167 assert arch is not None | 167 assert arch is not None |
168 toolchain_dir = GetToolchainDir(toolchain, arch) | 168 toolchain_dir = GetToolchainDir(toolchain, arch) |
169 arch_dir = '%s-nacl' % GetArchName(arch) | 169 arch_dir = '%s-nacl' % GetArchName(arch) |
170 return posixpath.join(toolchain_dir, arch_dir) | 170 return posixpath.join(toolchain_dir, arch_dir) |
171 | 171 |
172 | 172 |
173 def GetToolchainBinDir(toolchain, arch=None): | 173 def GetToolchainBinDir(toolchain, arch=None): |
174 ExpectToolchain(toolchain, NACL_TOOLCHAINS) | 174 ExpectToolchain(toolchain, NACL_TOOLCHAINS) |
175 return posixpath.join(GetToolchainDir(toolchain, arch), 'bin') | 175 return posixpath.join(GetToolchainDir(toolchain, arch), 'bin') |
176 | 176 |
177 | 177 |
178 def GetSDKIncludeDirs(toolchain): | 178 def GetSDKIncludeDirs(toolchain): |
179 root = GetPosixSDKPath() | 179 root = GetPosixSDKPath() |
180 base_include = posixpath.join(root, 'include') | 180 base_include = posixpath.join(root, 'include') |
| 181 if toolchain == 'clang-newlib': |
| 182 toolchain = 'newlib' |
181 return [base_include, posixpath.join(base_include, toolchain)] | 183 return [base_include, posixpath.join(base_include, toolchain)] |
182 | 184 |
183 | 185 |
184 def GetSDKLibDir(): | 186 def GetSDKLibDir(): |
185 return posixpath.join(GetPosixSDKPath(), 'lib') | 187 return posixpath.join(GetPosixSDKPath(), 'lib') |
186 | 188 |
187 | 189 |
188 # Commands | 190 # Commands |
189 | 191 |
190 def GetToolPath(toolchain, arch, tool): | 192 def GetToolPath(toolchain, arch, tool): |
191 if tool == 'gdb': | 193 if tool == 'gdb': |
192 # Always use the same gdb; it supports multiple toolchains/architectures. | 194 # Always use the same gdb; it supports multiple toolchains/architectures. |
193 # NOTE: this is always a i686 executable. i686-nacl-gdb is a symlink to | 195 # NOTE: this is always a i686 executable. i686-nacl-gdb is a symlink to |
194 # x86_64-nacl-gdb. | 196 # x86_64-nacl-gdb. |
195 return posixpath.join(GetToolchainBinDir('newlib', 'x86_64'), | 197 return posixpath.join(GetToolchainBinDir('newlib', 'x86_64'), |
196 'x86_64-nacl-gdb') | 198 'x86_64-nacl-gdb') |
197 | 199 |
198 if toolchain == 'pnacl': | 200 if toolchain == 'pnacl': |
199 CheckValidToolchainArch(toolchain, arch) | 201 CheckValidToolchainArch(toolchain, arch) |
200 tool = PNACL_TOOLS.get(tool, tool) | 202 tool = CLANG_TOOLS.get(tool, tool) |
201 full_tool_name = 'pnacl-%s' % tool | 203 full_tool_name = 'pnacl-%s' % tool |
202 else: | 204 else: |
203 CheckValidToolchainArch(toolchain, arch, arch_required=True) | 205 CheckValidToolchainArch(toolchain, arch, arch_required=True) |
204 ExpectArch(arch, VALID_ARCHES) | 206 ExpectArch(arch, VALID_ARCHES) |
205 tool = NACL_TOOLS.get(tool, tool) | 207 if toolchain == 'clang-newlib': |
| 208 tool = CLANG_TOOLS.get(tool, tool) |
| 209 else: |
| 210 tool = GCC_TOOLS.get(tool, tool) |
206 full_tool_name = '%s-nacl-%s' % (GetArchName(arch), tool) | 211 full_tool_name = '%s-nacl-%s' % (GetArchName(arch), tool) |
207 return posixpath.join(GetToolchainBinDir(toolchain, arch), full_tool_name) | 212 return posixpath.join(GetToolchainBinDir(toolchain, arch), full_tool_name) |
208 | 213 |
209 | 214 |
210 def GetCFlags(toolchain): | 215 def GetCFlags(toolchain): |
211 ExpectToolchain(toolchain, VALID_TOOLCHAINS) | 216 ExpectToolchain(toolchain, VALID_TOOLCHAINS) |
212 return ' '.join('-I%s' % dirname for dirname in GetSDKIncludeDirs(toolchain)) | 217 return ' '.join('-I%s' % dirname for dirname in GetSDKIncludeDirs(toolchain)) |
213 | 218 |
214 | 219 |
215 def GetIncludeDirs(toolchain): | 220 def GetIncludeDirs(toolchain): |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 | 267 |
263 return 0 | 268 return 0 |
264 | 269 |
265 | 270 |
266 if __name__ == '__main__': | 271 if __name__ == '__main__': |
267 try: | 272 try: |
268 sys.exit(main(sys.argv[1:])) | 273 sys.exit(main(sys.argv[1:])) |
269 except Error as e: | 274 except Error as e: |
270 sys.stderr.write(str(e) + '\n') | 275 sys.stderr.write(str(e) + '\n') |
271 sys.exit(1) | 276 sys.exit(1) |
OLD | NEW |