Make ncval-annotate and ncval-stubout executable
[nativeclient.git] / service_runtime / export_header.py
blob2835831fe2ca88bca3e5ad25fe90aedfdadf29d6
1 #!/usr/bin/python
3 # Copyright 2008, Google Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
8 # met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following disclaimer
14 # in the documentation and/or other materials provided with the
15 # distribution.
16 # * Neither the name of Google Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived from
18 # this software without specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 """Tools for exporting NativeClient ABI header files.
35 This module is used to export NativeClient ABI header files -- which are in
36 the native_client/service_runtime/include directory -- for use for NativeClient
37 applications compilation.
38 """
40 import os
41 import re
42 import sys
44 def ProcessStreams(instr, outstr):
45 """Read internal version of header file from instr, write exported version
46 to outstr.
47 """
49 pat = r'\b(?:nacl_abi_|NaClAbi|NACL_ABI_)([A-Za-z0-9_]*)'
50 cpat = re.compile(pat)
52 inc = r'^#\s*include\s+"native_client(?:/service_runtime)?/include/([^"]*)"'
53 incpat = re.compile(inc)
55 for str in instr:
56 if incpat.search(str):
57 print >>outstr, incpat.sub(r'#include <\1>', str)
58 else:
59 print >>outstr, cpat.sub(r'\1', str),
60 # endif
61 # endfor
62 # enddef
64 def ProcessFileList(flist):
65 for f in flist:
66 ProcessStreams(open(f), sys.stdout);
67 # endfor
68 # enddef
70 def ProcessDir(srcdir, dstdir):
71 if not os.path.isdir(srcdir):
72 return
73 # endif
74 if not os.path.isdir(dstdir):
75 os.makedirs(dstdir)
76 # endif
77 for fn in os.listdir(srcdir):
78 srcpath = os.path.join(srcdir, fn)
79 dstpath = os.path.join(dstdir, fn)
80 if os.path.isfile(srcpath) and fn.endswith('.h'):
81 ProcessStreams(open(srcpath),
82 open(dstpath, 'w'));
83 elif os.path.isdir(srcpath):
84 ProcessDir(srcpath, dstpath)
85 # endif
86 # endfor
87 # enddef
89 def main(argv):
90 if len(argv) != 3:
91 print >>sys.stderr, ('Usage: ./export_header source/include/path'
92 ' dest/include/path')
93 return 1
94 # endif
95 ProcessDir(argv[1], argv[2]);
96 return 0
97 # enddef
99 if __name__ == '__main__':
100 sys.exit(main(sys.argv))
101 # endif