1
# This Source Code Form is subject to the terms of the Mozilla Public
2
# License, v. 2.0. If a copy of the MPL was not distributed with this
3
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
import os, re, string, sys
7
def find_in_path(file, searchpath):
8
for dir in searchpath.split(os.pathsep):
9
f = os.path.join(dir, file)
14
def header_path(header, compiler):
16
# we use include_next on gcc
18
elif compiler == 'msvc':
19
return find_in_path(header, os.environ.get('INCLUDE', ''))
21
# hope someone notices this ...
22
raise NotImplementedError, compiler
25
return re.match(r'\s*#.*', line)
27
def main(outdir, compiler, template_file, header_list_file):
28
if not os.path.isdir(outdir):
31
template = open(template_file, 'r').read()
32
path_to_new = header_path('new', compiler)
34
for header in open(header_list_file, 'r'):
35
header = header.rstrip()
36
if 0 == len(header) or is_comment(header):
39
path = header_path(header, compiler)
41
f = open(os.path.join(outdir, header), 'w')
42
f.write(string.Template(template).substitute(HEADER=header,
44
NEW_HEADER_PATH=path_to_new))
49
if __name__ == '__main__':
50
if 5 != len(sys.argv):
51
print >>sys.stderr, """Usage:
52
python %s OUT_DIR ('msvc'|'gcc') TEMPLATE_FILE HEADER_LIST_FILE