2 # -*- coding: utf-8 -*-
7 def print_array(name
, values
):
10 list = ", ".join(values
)
11 print(" .%s = ((const char*[]){ %s, NULL })," % (name
, list))
18 for item
in line
.split():
19 if item
== "MODINFO_START":
22 if item
.startswith("MODINFO_END"):
35 def generate(name
, lines
, enabled
):
41 if line
.find("MODINFO_START") != -1:
42 (kind
, data
) = parse_line(line
)
51 elif kind
== 'kconfig':
52 # don't add a module which dependency is not enabled
54 if data
.strip() not in enabled
:
55 print(" /* module {} isn't enabled in Kconfig. */"
56 .format(data
.strip()))
60 print("unknown:", kind
)
63 print(" .name = \"%s\"," % name
)
65 print(" .arch = %s," % arch
)
66 print_array("objs", objs
)
67 print_array("deps", deps
)
68 print_array("opts", opts
)
70 return {dep
.strip('" ') for dep
in deps
}
73 print("/* generated by scripts/modinfo-generate.py */")
74 print("#include \"qemu/osdep.h\"")
75 print("#include \"qemu/module.h\"")
76 print("const QemuModinfo qemu_modinfo[] = {{")
79 print(" /* end of list */")
83 if len(args
) < 3 or args
[0] != '--devices':
84 print('Expected: modinfo-generate.py --devices '
85 'config-device.mak [modinfo files]', file=sys
.stderr
)
88 # get all devices enabled in kconfig, from *-config-device.mak
90 with
open(args
[1]) as file:
91 for line
in file.readlines():
92 config
= line
.split('=')
93 if config
[1].rstrip() == 'y':
94 enabled
.add(config
[0][7:]) # remove CONFIG_
99 for modinfo
in args
[2:]:
100 with
open(modinfo
) as f
:
101 lines
= f
.readlines()
102 print(" /* %s */" % modinfo
)
103 (basename
, _
) = os
.path
.splitext(modinfo
)
104 moddeps
= generate(basename
, lines
, enabled
)
105 if moddeps
is not None:
106 modules
.add(basename
)
111 for dep
in deps
.difference(modules
):
112 print("Dependency {} cannot be satisfied".format(dep
),
119 if __name__
== "__main__":