blob: 8b278e66b8e675b3f1ea83ea2ea5034760e1bcca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
#!/usr/bin/env python
import sys
import os
class CxxTarget:
def __init__(self, line):
self.directory = ''
self.outputfile = ''
self.includeflags = []
self.cxxflags = []
self.inputfiles = []
self.nolink = False
options = line[:-1].split(' ')
self.directory = options.pop(0)
parsing_outputfile = False
for option in options:
if parsing_outputfile:
self.outputfile = option
parsing_outputfile = False
elif option == '-o':
parsing_outputfile = True
elif option == '-c':
self.nolink = True
elif option.startswith('-I'):
self.includeflags.append(CxxFlag(option))
elif option.startswith('-'):
self.cxxflags.append(CxxFlag(option))
else:
self.inputfiles.append(option)
self.cxxflags.sort()
self.includeflags.sort()
cxxflags_tmp = dict()
for flag in self.cxxflags:
cxxflags_tmp[flag.name] = flag
self.cxxflags = cxxflags_tmp.values()
includeflags_tmp = dict()
for flag in self.includeflags:
includeflags_tmp[flag.name] = flag
self.includeflags = includeflags_tmp.values()
CxxTargets.by_name[self.getFullOutputname()] = self
def __str__(self):
return '%s' % (self.getFullOutputname())
def getFullOutputname(self):
return self.directory + '/' + self.outputfile
def __cmp__(self, other):
return cmp(self.getFullOutputname(), other.getFullOutputname())
class CxxFlag:
def __init__(self, name):
self.name = name
CxxFlags.by_name[self.name] = self
def __str__(self):
return 'Flag %s' % (self.name)
def __cmp__(self, other):
return cmp(self.name, other.name)
class CxxFlags:
by_name = dict()
class CxxTargets:
by_name = dict()
if __name__ == '__main__':
[CxxTarget(line) for line in sys.stdin.readlines()]
compile_targets = [target for target in CxxTargets.by_name.values() if target.nolink]
link_targets = [target for target in CxxTargets.by_name.values() if not target.nolink]
common_compile_flags = []
for flag in CxxFlags.by_name.values():
if sum((flag in target.cxxflags for target in compile_targets)) == len(compile_targets):
common_compile_flags.append(flag)
common_link_flags = []
for flag in CxxFlags.by_name.values():
if sum((flag in target.cxxflags for target in compile_targets)) == len(compile_targets):
common_link_flags.append(flag)
for target in compile_targets:
target.cxxflags = [flag for flag in target.cxxflags if flag not in common_compile_flags]
target.cxxflags.sort()
for target in link_targets:
target.cxxflags = [flag for flag in target.cxxflags if flag not in common_link_flags]
target.cxxflags.sort()
common_compile_flags.sort()
common_link_flags.sort()
print 'common compile flags: %s' % (' '.join(flag.name for flag in common_compile_flags))
print 'common link flags: %s' % (' '.join(flag.name for flag in common_link_flags))
by_flagset = dict()
for target in CxxTargets.by_name.values():
flagset = ' '.join((flag.name for flag in target.cxxflags))
if flagset not in by_flagset:
by_flagset[flagset] = list()
by_flagset[flagset].append(target)
for targetlist in by_flagset.values():
targetlist.sort()
flagsets = by_flagset.keys()
flagsets.sort()
print '%d compilerflag groups:' % (len(flagsets))
for flagset in flagsets:
print flagset
for target in by_flagset[flagset]:
print '%s' % (target)
print
by_flagset = dict()
for target in CxxTargets.by_name.values():
flagset = ' '.join((flag.name for flag in target.includeflags))
if flagset not in by_flagset:
by_flagset[flagset] = list()
by_flagset[flagset].append(target)
for targetlist in by_flagset.values():
targetlist.sort()
flagsets = by_flagset.keys()
flagsets.sort()
print '%d include flag groups:' % (len(flagsets))
for flagset in flagsets:
print flagset
for target in by_flagset[flagset]:
print '%s' % (target)
print
print 'sources:'
by_name = dict()
for target in CxxTargets.by_name.values():
by_name[os.path.basename(target.outputfile)] = target
names = by_name.keys()
names.sort()
for target in CxxTargets.by_name.values():
if len(target.inputfiles) > 1:
objects = [os.path.basename(object) for object in target.inputfiles]
sources = list()
for object in objects:
if object in by_name:
sources.append(by_name[object].inputfiles[0])
else:
sources.append('!!!!' + object)
sources.sort()
print '%s %s' % (target.getFullOutputname(), ' '.join(sources))
|