| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 184 |
| 185 def GetToolPath(toolchain, arch, tool): | 185 def GetToolPath(toolchain, arch, tool): |
| 186 if tool == 'gdb': | 186 if tool == 'gdb': |
| 187 # Always use the same gdb; it supports multiple toolchains/architectures. | 187 # Always use the same gdb; it supports multiple toolchains/architectures. |
| 188 # NOTE: this is always a i686 executable. i686-nacl-gdb is a symlink to | 188 # NOTE: this is always a i686 executable. i686-nacl-gdb is a symlink to |
| 189 # x86_64-nacl-gdb. | 189 # x86_64-nacl-gdb. |
| 190 return posixpath.join(GetToolchainBinDir('newlib', 'x86_64'), | 190 return posixpath.join(GetToolchainBinDir('newlib', 'x86_64'), |
| 191 'x86_64-nacl-gdb') | 191 'x86_64-nacl-gdb') |
| 192 | 192 |
| 193 if toolchain == 'pnacl': | 193 if toolchain == 'pnacl': |
| 194 CheckValidToolchainArch(toolchain, arch) |
| 194 tool = PNACL_TOOLS.get(tool, tool) | 195 tool = PNACL_TOOLS.get(tool, tool) |
| 195 full_tool_name = 'pnacl-%s' % tool | 196 full_tool_name = 'pnacl-%s' % tool |
| 196 else: | 197 else: |
| 198 CheckValidToolchainArch(toolchain, arch, arch_required=True) |
| 197 ExpectArch(arch, VALID_ARCHES) | 199 ExpectArch(arch, VALID_ARCHES) |
| 198 tool = NACL_TOOLS.get(tool, tool) | 200 tool = NACL_TOOLS.get(tool, tool) |
| 199 full_tool_name = '%s-nacl-%s' % (GetArchName(arch), tool) | 201 full_tool_name = '%s-nacl-%s' % (GetArchName(arch), tool) |
| 200 return posixpath.join(GetToolchainBinDir(toolchain, arch), full_tool_name) | 202 return posixpath.join(GetToolchainBinDir(toolchain, arch), full_tool_name) |
| 201 | 203 |
| 202 | 204 |
| 203 def GetCFlags(toolchain): | 205 def GetCFlags(toolchain): |
| 204 ExpectToolchain(toolchain, VALID_TOOLCHAINS) | 206 ExpectToolchain(toolchain, VALID_TOOLCHAINS) |
| 205 return ' '.join('-I%s' % dirname for dirname in GetSDKIncludeDirs(toolchain)) | 207 return ' '.join('-I%s' % dirname for dirname in GetSDKIncludeDirs(toolchain)) |
| 206 | 208 |
| 207 | 209 |
| 210 def GetIncludeDirs(toolchain): |
| 211 ExpectToolchain(toolchain, VALID_TOOLCHAINS) |
| 212 return ' '.join(GetSDKIncludeDirs(toolchain)) |
| 213 |
| 214 |
| 208 def GetLDFlags(): | 215 def GetLDFlags(): |
| 209 return '-L%s' % GetSDKLibDir() | 216 return '-L%s' % GetSDKLibDir() |
| 210 | 217 |
| 211 | 218 |
| 212 def main(args): | 219 def main(args): |
| 213 usage = 'Usage: %prog [options] <command>' | 220 usage = 'Usage: %prog [options] <command>' |
| 214 parser = optparse.OptionParser(usage=usage, description=__doc__) | 221 parser = optparse.OptionParser(usage=usage, description=__doc__) |
| 215 parser.add_option('-t', '--toolchain', help='toolchain name. This can also ' | 222 parser.add_option('-t', '--toolchain', help='toolchain name. This can also ' |
| 216 'be specified with the NACL_TOOLCHAIN environment ' | 223 'be specified with the NACL_TOOLCHAIN environment ' |
| 217 'variable.') | 224 'variable.') |
| 218 parser.add_option('-a', '--arch', help='architecture name. This can also be ' | 225 parser.add_option('-a', '--arch', help='architecture name. This can also be ' |
| 219 'specified with the NACL_ARCH environment variable.') | 226 'specified with the NACL_ARCH environment variable.') |
| 220 | 227 |
| 221 group = optparse.OptionGroup(parser, 'Commands') | 228 group = optparse.OptionGroup(parser, 'Commands') |
| 222 group.add_option('--tool', help='get tool path') | 229 group.add_option('--tool', help='get tool path') |
| 223 group.add_option('--cflags', | 230 group.add_option('--cflags', |
| 224 help='output all preprocessor and compiler flags', | 231 help='output all preprocessor and compiler flags', |
| 225 action='store_true') | 232 action='store_true') |
| 226 group.add_option('--libs', '--ldflags', help='output all linker flags', | 233 group.add_option('--libs', '--ldflags', help='output all linker flags', |
| 227 action='store_true') | 234 action='store_true') |
| 235 group.add_option('--include-dirs', |
| 236 help='output include dirs, separated by spaces', |
| 237 action='store_true') |
| 228 parser.add_option_group(group) | 238 parser.add_option_group(group) |
| 229 | 239 |
| 230 options, _ = parser.parse_args(args) | 240 options, _ = parser.parse_args(args) |
| 231 | 241 |
| 232 # Get toolchain/arch from environment, if not specified on commandline | 242 # Get toolchain/arch from environment, if not specified on commandline |
| 233 options.toolchain = options.toolchain or os.getenv('NACL_TOOLCHAIN') | 243 options.toolchain = options.toolchain or os.getenv('NACL_TOOLCHAIN') |
| 234 options.arch = options.arch or os.getenv('NACL_ARCH') | 244 options.arch = options.arch or os.getenv('NACL_ARCH') |
| 235 | 245 |
| 236 options.toolchain = CanonicalizeToolchain(options.toolchain) | 246 options.toolchain = CanonicalizeToolchain(options.toolchain) |
| 237 CheckValidToolchainArch(options.toolchain, options.arch) | 247 CheckValidToolchainArch(options.toolchain, options.arch) |
| 238 | 248 |
| 239 if options.cflags: | 249 if options.cflags: |
| 240 print GetCFlags(options.toolchain) | 250 print GetCFlags(options.toolchain) |
| 251 elif options.include_dirs: |
| 252 print GetIncludeDirs(options.toolchain) |
| 241 elif options.libs: | 253 elif options.libs: |
| 242 print GetLDFlags() | 254 print GetLDFlags() |
| 243 elif options.tool: | 255 elif options.tool: |
| 244 CheckValidToolchainArch(options.toolchain, options.arch, True) | |
| 245 print GetToolPath(options.toolchain, options.arch, options.tool) | 256 print GetToolPath(options.toolchain, options.arch, options.tool) |
| 246 else: | 257 else: |
| 247 parser.error('Expected a command. Run with --help for more information.') | 258 parser.error('Expected a command. Run with --help for more information.') |
| 248 | 259 |
| 249 return 0 | 260 return 0 |
| 250 | 261 |
| 251 | 262 |
| 252 if __name__ == '__main__': | 263 if __name__ == '__main__': |
| 253 try: | 264 try: |
| 254 sys.exit(main(sys.argv[1:])) | 265 sys.exit(main(sys.argv[1:])) |
| 255 except Error as e: | 266 except Error as e: |
| 256 sys.stderr.write(str(e) + '\n') | 267 sys.stderr.write(str(e) + '\n') |
| 257 sys.exit(1) | 268 sys.exit(1) |
| OLD | NEW |