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 |
11 import optparse | 11 import argparse |
12 import os | 12 import os |
13 import posixpath | 13 import posixpath |
14 import sys | 14 import sys |
15 | 15 |
16 import getos | 16 import getos |
17 | 17 |
18 | 18 |
19 if sys.version_info < (2, 7, 0): | 19 if sys.version_info < (2, 7, 0): |
20 sys.stderr.write("python 2.7 or later is required run this script\n") | 20 sys.stderr.write("python 2.7 or later is required run this script\n") |
21 sys.exit(1) | 21 sys.exit(1) |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 def GetIncludeDirs(toolchain): | 215 def GetIncludeDirs(toolchain): |
216 ExpectToolchain(toolchain, VALID_TOOLCHAINS) | 216 ExpectToolchain(toolchain, VALID_TOOLCHAINS) |
217 return ' '.join(GetSDKIncludeDirs(toolchain)) | 217 return ' '.join(GetSDKIncludeDirs(toolchain)) |
218 | 218 |
219 | 219 |
220 def GetLDFlags(): | 220 def GetLDFlags(): |
221 return '-L%s' % GetSDKLibDir() | 221 return '-L%s' % GetSDKLibDir() |
222 | 222 |
223 | 223 |
224 def main(args): | 224 def main(args): |
225 usage = 'Usage: %prog [options] <command>' | 225 parser = argparse.ArgumentParser(description=__doc__) |
226 parser = optparse.OptionParser(usage=usage, description=__doc__) | 226 parser.add_argument('-t', '--toolchain', help='toolchain name. This can also ' |
227 parser.add_option('-t', '--toolchain', help='toolchain name. This can also ' | 227 'be specified with the NACL_TOOLCHAIN environment ' |
228 'be specified with the NACL_TOOLCHAIN environment ' | 228 'variable.') |
229 'variable.') | 229 parser.add_argument('-a', '--arch', help='architecture name. This can also ' |
230 parser.add_option('-a', '--arch', help='architecture name. This can also be ' | 230 'be specified with the NACL_ARCH environment variable.') |
231 'specified with the NACL_ARCH environment variable.') | |
232 | 231 |
233 group = optparse.OptionGroup(parser, 'Commands') | 232 group = parser.add_argument_group('Commands') |
234 group.add_option('--tool', help='get tool path') | 233 group.add_argument('--tool', help='get tool path') |
235 group.add_option('--cflags', | 234 group.add_argument('--cflags', |
236 help='output all preprocessor and compiler flags', | 235 help='output all preprocessor and compiler flags', |
237 action='store_true') | 236 action='store_true') |
238 group.add_option('--libs', '--ldflags', help='output all linker flags', | 237 group.add_argument('--libs', '--ldflags', help='output all linker flags', |
239 action='store_true') | 238 action='store_true') |
240 group.add_option('--include-dirs', | 239 group.add_argument('--include-dirs', |
241 help='output include dirs, separated by spaces', | 240 help='output include dirs, separated by spaces', |
242 action='store_true') | 241 action='store_true') |
243 parser.add_option_group(group) | |
244 | 242 |
245 options, _ = parser.parse_args(args) | 243 options = parser.parse_args(args) |
246 | 244 |
247 # Get toolchain/arch from environment, if not specified on commandline | 245 # Get toolchain/arch from environment, if not specified on commandline |
248 options.toolchain = options.toolchain or os.getenv('NACL_TOOLCHAIN') | 246 options.toolchain = options.toolchain or os.getenv('NACL_TOOLCHAIN') |
249 options.arch = options.arch or os.getenv('NACL_ARCH') | 247 options.arch = options.arch or os.getenv('NACL_ARCH') |
250 | 248 |
251 options.toolchain = CanonicalizeToolchain(options.toolchain) | 249 options.toolchain = CanonicalizeToolchain(options.toolchain) |
252 CheckValidToolchainArch(options.toolchain, options.arch) | 250 CheckValidToolchainArch(options.toolchain, options.arch) |
253 | 251 |
254 if options.cflags: | 252 if options.cflags: |
255 print GetCFlags(options.toolchain) | 253 print GetCFlags(options.toolchain) |
256 elif options.include_dirs: | 254 elif options.include_dirs: |
257 print GetIncludeDirs(options.toolchain) | 255 print GetIncludeDirs(options.toolchain) |
258 elif options.libs: | 256 elif options.libs: |
259 print GetLDFlags() | 257 print GetLDFlags() |
260 elif options.tool: | 258 elif options.tool: |
261 print GetToolPath(options.toolchain, options.arch, options.tool) | 259 print GetToolPath(options.toolchain, options.arch, options.tool) |
262 else: | 260 else: |
263 parser.error('Expected a command. Run with --help for more information.') | 261 parser.error('Expected a command. Run with --help for more information.') |
264 | 262 |
265 return 0 | 263 return 0 |
266 | 264 |
267 | 265 |
268 if __name__ == '__main__': | 266 if __name__ == '__main__': |
269 try: | 267 try: |
270 sys.exit(main(sys.argv[1:])) | 268 sys.exit(main(sys.argv[1:])) |
271 except Error as e: | 269 except Error as e: |
272 sys.stderr.write(str(e) + '\n') | 270 sys.stderr.write(str(e) + '\n') |
273 sys.exit(1) | 271 sys.exit(1) |
OLD | NEW |