Dale Curtis | 9596cc0 | 2018-10-31 14:25:55 -0700 | [diff] [blame] | 1 | #!/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 | |
| 9 | import os |
| 10 | import sys |
| 11 | |
| 12 | def 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 | |
| 44 | def 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 | |
| 55 | def 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 Curtis | e293814 | 2020-06-29 15:29:48 -0700 | [diff] [blame] | 64 | # Results in duplicated symbols in nasm.c |
| 65 | file_lists['LIBOBJ'].remove('nasmlib/errfile.c') |
| 66 | |
Dale Curtis | 9596cc0 | 2018-10-31 14:25:55 -0700 | [diff] [blame] | 67 | PrintFileList(out, "ndisasm_sources", file_lists['NDISASM']) |
| 68 | PrintFileList(out, "nasmlib_sources", file_lists['LIBOBJ']) |
| 69 | PrintFileList(out, "nasm_sources", file_lists['NASM']) |
| 70 | |
| 71 | if __name__ == "__main__": |
| 72 | main() |