blob: 4621c7ef6c7f9ebd7b98dd1f66b248c7f5a4a99e [file] [log] [blame]
Elly Fong-Jones0873b2b2022-11-02 19:49:51 +00001#!/usr/bin/env python3
Dale Curtis9596cc02018-10-31 14:25:55 -07002#
Avi Drissmanea62cfa2023-01-24 14:57:29 -05003# Copyright 2018 The Chromium Authors
Dale Curtis9596cc02018-10-31 14:25:55 -07004# 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):
Elly Fong-Jones0873b2b2022-11-02 19:49:51 +000013 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
Dale Curtis9596cc02018-10-31 14:25:55 -070043
44def PrintFileList(out, name, files):
Elly Fong-Jones0873b2b2022-11-02 19:49:51 +000045 if len(files) == 0:
46 print("%s = []" % (name, ), file=out)
47 elif len(files) == 1:
48 print("%s = [ \"%s\" ]" % (name, files[0]), file=out)
49 else:
50 print("%s = [" % (name, ), file=out)
51 for f in files:
52 print(" \"%s\"," % (f, ), file=out)
53 print("]", file=out)
54
Dale Curtis9596cc02018-10-31 14:25:55 -070055
56def main():
Elly Fong-Jones0873b2b2022-11-02 19:49:51 +000057 file_lists = ParseFileLists("Makefile.in")
58 with open("nasm_sources.gni", "w") as out:
59 print(
60 """# Copyright (c) 2018 The Chromium Authors. All rights reserved.
Dale Curtis9596cc02018-10-31 14:25:55 -070061# Use of this source code is governed by a BSD-style license that can be
62# found in the LICENSE file.
63
64# This file is created by generate_nasm_sources.py. Do not edit manually.
Elly Fong-Jones0873b2b2022-11-02 19:49:51 +000065""",
66 file=out)
67 # Results in duplicated symbols in nasm.c
68 file_lists['LIBOBJ'].remove('nasmlib/errfile.c')
Dale Curtise2938142020-06-29 15:29:48 -070069
Elly Fong-Jones0873b2b2022-11-02 19:49:51 +000070 PrintFileList(out, "ndisasm_sources", file_lists['NDISASM'])
71 PrintFileList(out, "nasmlib_sources", file_lists['LIBOBJ'])
72 PrintFileList(out, "nasm_sources", file_lists['NASM'])
Dale Curtis9596cc02018-10-31 14:25:55 -070073
74if __name__ == "__main__":
Elly Fong-Jones0873b2b2022-11-02 19:49:51 +000075 main()