blob: 341c72992cdb17503c814b09eb22f677f56918db [file] [log] [blame]
Dale Curtis9596cc02018-10-31 14:25:55 -07001#!/usr/bin/env python
2#
3# Copyright 2018 The Chromium Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7"""A script to parse nasm's file lists out of Makefile.in."""
8
9import os
10import sys
11
12def ParseFileLists(path):
13 ret = {}
14 with open(path) as f:
15 in_file_list = False
16 split_line = ""
17 for line in f:
18 line = line.rstrip()
19 if not in_file_list:
20 if "-- Begin File Lists --" in line:
21 in_file_list = True
22 continue
23 if "-- End File Lists --" in line:
24 if split_line:
25 raise ValueError("End comment was preceded by split line")
26 break
27 line = split_line + line
28 split_line = ""
29 if line.endswith('\\'):
30 split_line = line[:-1]
31 continue
32 line = line.strip()
33 if not line:
34 continue
35 name, value = line.split('=')
36 name = name.strip()
37 value = value.replace("$(O)", "c")
38 files = value.split()
39 files.sort()
40 files = [file for file in files]
41 ret[name] = files
42 return ret
43
44def PrintFileList(out, name, files):
45 if len(files) == 0:
46 print >>out, "%s = []" % (name,)
47 elif len(files) == 1:
48 print >>out, "%s = [ \"%s\" ]" % (name, files[0])
49 else:
50 print >>out, "%s = [" % (name,)
51 for f in files:
52 print >>out, " \"%s\"," % (f,)
53 print >>out, "]"
54
55def main():
56 file_lists = ParseFileLists("Makefile.in")
57 with open("nasm_sources.gni", "w") as out:
58 print >>out, """# Copyright (c) 2018 The Chromium Authors. All rights reserved.
59# Use of this source code is governed by a BSD-style license that can be
60# found in the LICENSE file.
61
62# This file is created by generate_nasm_sources.py. Do not edit manually.
63"""
Dale Curtise2938142020-06-29 15:29:48 -070064 # Results in duplicated symbols in nasm.c
65 file_lists['LIBOBJ'].remove('nasmlib/errfile.c')
66
Dale Curtis9596cc02018-10-31 14:25:55 -070067 PrintFileList(out, "ndisasm_sources", file_lists['NDISASM'])
68 PrintFileList(out, "nasmlib_sources", file_lists['LIBOBJ'])
69 PrintFileList(out, "nasm_sources", file_lists['NASM'])
70
71if __name__ == "__main__":
72 main()