2 # Copyright (c) 2008 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.
6 """Tools for exporting Native Client ABI header files.
8 This module is used to export Native Client ABI header files -- which
9 are in the native_client/src/trusted/service_runtime/include directory
10 -- for use with the SDK and newlib to compile NaCl applications.
18 def ProcessStream(instr, outstr):
19 """Read internal version of header file from instr, write exported
20 version to outstr. The two transformations are to remove nacl_abi_
21 prefixes (in its various incarnations), and to change include
22 directives from the Google coding style
23 "native_client/include/foo/bar.h" to <foo/bar.h>, and from
24 "native_client/src/trusted/service_runtime/include/baz/quux.h" to
27 pat = r'\b(?:nacl_abi_|NaClAbi|NACL_ABI_)([A-Za-z0-9_]*)'
28 cpat = re.compile(pat)
30 inc = (r'^#\s*include\s+"native_client(?:/src/trusted/service_runtime)?'+
32 cinc = re.compile(inc)
36 print >>outstr, cinc.sub(r'#include <\1>', line)
38 print >>outstr, cpat.sub(r'\1', line),
44 def ProcessDir(srcdir, dstdir):
45 if not os.path.isdir(srcdir):
48 if not os.path.isdir(dstdir):
51 for fn in os.listdir(srcdir):
52 srcpath = os.path.join(srcdir, fn)
53 dstpath = os.path.join(dstdir, fn)
54 if os.path.isfile(srcpath) and fn.endswith('.h'):
55 ProcessStream(open(srcpath),
57 elif os.path.isdir(srcpath):
58 ProcessDir(srcpath, dstpath)
65 print >>sys.stderr, ('Usage: ./export_header source/include/path'
69 ProcessDir(argv[1], argv[2])
73 if __name__ == '__main__':
74 sys.exit(main(sys.argv))