Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / native_client / pnacl / driver / pnacl-nm.py
1 #!/usr/bin/python
2 # Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import driver_tools
7 from driver_env import env
8 from driver_log import Log
9 import filetype
10
11 EXTRA_ENV = {
12   'TOOLNAME':   '',
13   'INPUTS':     '',
14   'FLAGS':      '',
15 }
16
17 PATTERNS = [
18   ( '(-.*)',    "env.append('FLAGS', $0)"),
19   ( '(.*)',     "env.append('INPUTS', pathtools.normalize($0))"),
20 ]
21
22 def main(argv):
23   env.update(EXTRA_ENV)
24   driver_tools.ParseArgs(argv, PATTERNS)
25
26   inputs = env.get('INPUTS')
27
28   if len(inputs) == 0:
29     Log.Fatal("No input files given")
30
31   for infile in inputs:
32     driver_tools.CheckPathLength(infile)
33     env.push()
34     env.set('input', infile)
35
36     # For frozen PNaCl bitcode, use 'llvm-nm -bitcode-format=pnacl'. For all
37     # other formats, use the binutils nm with our gold plugin.
38     if filetype.IsPNaClBitcode(infile):
39       env.set('TOOLNAME', '${LLVM_NM}')
40       env.append('FLAGS', '-bitcode-format=pnacl')
41     else:
42       env.set('TOOLNAME', '${NM}')
43       env.append('FLAGS', '--plugin=${GOLD_PLUGIN_SO}')
44
45     driver_tools.Run('"${TOOLNAME}" ${FLAGS} ${input}')
46     env.pop()
47
48   # only reached in case of no errors
49   return 0
50
51 def get_help(unused_argv):
52   return """
53 Usage: %s [option(s)] [file(s)]
54  List symbols in [file(s)].
55
56  * For stable PNaCl bitcode files, this calls the llvm-nm tool.
57  * For all other files, this calls the standard nm from binutils - please see
58    that tool's help pages for options.
59 """ % env.getone('SCRIPT_NAME')