diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2021-06-24 12:38:05 +0200 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2021-07-09 18:20:27 +0200 |
commit | 5ebbfecc3e6fa443a506ec5fe65f0ca98973d404 (patch) | |
tree | 15cbc45b58d5a9f30b702c841b1481236b34c23f /scripts/modinfo-generate.py | |
parent | f5723ab66560a10f8461ac223e3d8369c10dc964 (diff) | |
download | qemu-5ebbfecc3e6fa443a506ec5fe65f0ca98973d404.zip qemu-5ebbfecc3e6fa443a506ec5fe65f0ca98973d404.tar.gz qemu-5ebbfecc3e6fa443a506ec5fe65f0ca98973d404.tar.bz2 |
modules: generate modinfo.c
Add script to generate C source with a small
database containing the module meta-data.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Jose R. Ziviani <jziviani@suse.de>
Message-Id: <20210624103836.2382472-4-kraxel@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'scripts/modinfo-generate.py')
-rwxr-xr-x | scripts/modinfo-generate.py | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/scripts/modinfo-generate.py b/scripts/modinfo-generate.py new file mode 100755 index 0000000..a6d98a6 --- /dev/null +++ b/scripts/modinfo-generate.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import os +import sys + +def print_array(name, values): + if len(values) == 0: + return + list = ", ".join(values) + print(" .%s = ((const char*[]){ %s, NULL })," % (name, list)) + +def parse_line(line): + kind = "" + data = "" + get_kind = False + get_data = False + for item in line.split(): + if item == "MODINFO_START": + get_kind = True + continue + if item.startswith("MODINFO_END"): + get_data = False + continue + if get_kind: + kind = item + get_kind = False + get_data = True + continue + if get_data: + data += " " + item + continue + return (kind, data) + +def generate(name, lines): + arch = "" + objs = [] + deps = [] + opts = [] + for line in lines: + if line.find("MODINFO_START") != -1: + (kind, data) = parse_line(line) + if kind == 'obj': + objs.append(data) + elif kind == 'dep': + deps.append(data) + elif kind == 'opts': + opts.append(data) + elif kind == 'arch': + arch = data; + else: + print("unknown:", kind) + exit(1) + + print(" .name = \"%s\"," % name) + if arch != "": + print(" .arch = %s," % arch) + print_array("objs", objs) + print_array("deps", deps) + print_array("opts", opts) + print("},{"); + +def print_pre(): + print("/* generated by scripts/modinfo-generate.py */") + print("#include \"qemu/osdep.h\"") + print("#include \"qemu/module.h\"") + print("const QemuModinfo qemu_modinfo[] = {{") + +def print_post(): + print(" /* end of list */") + print("}};") + +def main(args): + print_pre() + for modinfo in args: + with open(modinfo) as f: + lines = f.readlines() + print(" /* %s */" % modinfo) + (basename, ext) = os.path.splitext(modinfo) + generate(basename, lines) + print_post() + +if __name__ == "__main__": + main(sys.argv[1:]) |