ui: compile dbus-display1.c with -fPIC as necessary
[qemu/armbru.git] / scripts / modinfo-collect.py
blob4e7584df66766a42c0242e5db0e609a45708dcbb
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
4 import os
5 import sys
6 import json
7 import shlex
8 import subprocess
10 def find_command(src, target, compile_commands):
11 for command in compile_commands:
12 if command['file'] != src:
13 continue
14 if target != '' and command['command'].find(target) == -1:
15 continue
16 return command['command']
17 return 'false'
19 def process_command(src, command):
20 skip = False
21 out = []
22 for item in shlex.split(command):
23 if skip:
24 skip = False
25 continue
26 if item == '-MF' or item == '-MQ' or item == '-o':
27 skip = True
28 continue
29 if item == '-c':
30 skip = True
31 continue
32 out.append(item)
33 out.append('-DQEMU_MODINFO')
34 out.append('-E')
35 out.append(src)
36 return out
38 def main(args):
39 target = ''
40 if args[0] == '--target':
41 args.pop(0)
42 target = args.pop(0)
43 print("MODINFO_DEBUG target %s" % target)
44 arch = target[:-8] # cut '-softmmu'
45 print("MODINFO_START arch \"%s\" MODINFO_END" % arch)
46 with open('compile_commands.json') as f:
47 compile_commands = json.load(f)
48 for src in args:
49 if not src.endswith('.c'):
50 print("MODINFO_DEBUG skip %s" % src)
51 continue
52 print("MODINFO_DEBUG src %s" % src)
53 command = find_command(src, target, compile_commands)
54 cmdline = process_command(src, command)
55 print("MODINFO_DEBUG cmd", cmdline)
56 result = subprocess.run(cmdline, stdout = subprocess.PIPE,
57 universal_newlines = True)
58 if result.returncode != 0:
59 sys.exit(result.returncode)
60 for line in result.stdout.split('\n'):
61 if line.find('MODINFO') != -1:
62 print(line)
64 if __name__ == "__main__":
65 main(sys.argv[1:])