3 # Module information generator
5 # Copyright Red Hat, Inc. 2015 - 2016
8 # Marc Mari <markmb@redhat.com>
10 # This work is licensed under the terms of the GNU GPL, version 2.
11 # See the COPYING file in the top-level directory.
13 from __future__
import print_function
17 def get_string_struct(line
):
20 # data[0] -> struct element name
24 return data
[2].replace('"', '')[:-1]
26 def add_module(fheader
, library
, format_name
, protocol_name
):
28 lines
.append('.library_name = "' + library
+ '",')
30 lines
.append('.format_name = "' + format_name
+ '",')
31 if protocol_name
!= "":
32 lines
.append('.protocol_name = "' + protocol_name
+ '",')
34 text
= '\n '.join(lines
)
35 fheader
.write('\n {\n ' + text
+ '\n },')
37 def process_file(fheader
, filename
):
38 # This parser assumes the coding style rules are being followed
39 with
open(filename
, "r") as cfile
:
41 library
, _
= os
.path
.splitext(os
.path
.basename(filename
))
44 line
= line
.replace('\n', '')
45 if line
.find(".format_name") != -1:
46 format_name
= get_string_struct(line
)
47 elif line
.find(".protocol_name") != -1:
48 protocol_name
= get_string_struct(line
)
50 add_module(fheader
, library
, format_name
, protocol_name
)
52 elif line
.find("static BlockDriver") != -1:
57 def print_top(fheader
):
58 fheader
.write('''/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
60 * QEMU Block Module Infrastructure
63 * Marc Mari <markmb@redhat.com>
68 fheader
.write('''#ifndef QEMU_MODULE_BLOCK_H
69 #define QEMU_MODULE_BLOCK_H
71 #include "qemu-common.h"
74 const char *format_name;
75 const char *protocol_name;
76 const char *library_name;
77 } block_driver_modules[] = {''')
79 def print_bottom(fheader
):
86 # First argument: output file
87 # All other arguments: modules source files (.c)
88 output_file
= sys
.argv
[1]
89 with
open(output_file
, 'w') as fheader
:
92 for filename
in sys
.argv
[2:]:
93 if os
.path
.isfile(filename
):
94 process_file(fheader
, filename
)
96 print("File " + filename
+ " does not exist.", file=sys
.stderr
)