6 def __init__(self
, line
):
13 options
= line
[:-1].split(' ')
14 self
.directory
= options
.pop(0)
15 parsing_outputfile
= False
16 for option
in options
:
17 if parsing_outputfile
:
18 self
.outputfile
= option
19 parsing_outputfile
= False
21 parsing_outputfile
= True
24 elif option
.startswith('-I'):
25 self
.includeflags
.append(CxxFlag(option
))
26 elif option
.startswith('-'):
27 self
.cxxflags
.append(CxxFlag(option
))
29 self
.inputfiles
.append(option
)
31 self
.includeflags
.sort()
33 for flag
in self
.cxxflags
:
34 cxxflags_tmp
[flag
.name
] = flag
35 self
.cxxflags
= cxxflags_tmp
.values()
36 includeflags_tmp
= dict()
37 for flag
in self
.includeflags
:
38 includeflags_tmp
[flag
.name
] = flag
39 self
.includeflags
= includeflags_tmp
.values()
40 CxxTargets
.by_name
[self
.getFullOutputname()] = self
42 return '%s' % (self
.getFullOutputname())
43 def getFullOutputname(self
):
44 return self
.directory
+ '/' + self
.outputfile
45 def __cmp__(self
, other
):
46 return cmp(self
.getFullOutputname(), other
.getFullOutputname())
49 def __init__(self
, name
):
51 CxxFlags
.by_name
[self
.name
] = self
53 return 'Flag %s' % (self
.name
)
54 def __cmp__(self
, other
):
55 return cmp(self
.name
, other
.name
)
63 if __name__
== '__main__':
64 [CxxTarget(line
) for line
in sys
.stdin
.readlines()]
65 compile_targets
= [target
for target
in CxxTargets
.by_name
.values() if target
.nolink
]
66 link_targets
= [target
for target
in CxxTargets
.by_name
.values() if not target
.nolink
]
67 common_compile_flags
= []
68 for flag
in CxxFlags
.by_name
.values():
69 if sum((flag
in target
.cxxflags
for target
in compile_targets
)) == len(compile_targets
):
70 common_compile_flags
.append(flag
)
71 common_link_flags
= []
72 for flag
in CxxFlags
.by_name
.values():
73 if sum((flag
in target
.cxxflags
for target
in compile_targets
)) == len(compile_targets
):
74 common_link_flags
.append(flag
)
76 for target
in compile_targets
:
77 target
.cxxflags
= [flag
for flag
in target
.cxxflags
if flag
not in common_compile_flags
]
78 target
.cxxflags
.sort()
79 for target
in link_targets
:
80 target
.cxxflags
= [flag
for flag
in target
.cxxflags
if flag
not in common_link_flags
]
81 target
.cxxflags
.sort()
83 common_compile_flags
.sort()
84 common_link_flags
.sort()
85 print 'common compile flags: %s' % (' '.join(flag
.name
for flag
in common_compile_flags
))
86 print 'common link flags: %s' % (' '.join(flag
.name
for flag
in common_link_flags
))
89 for target
in CxxTargets
.by_name
.values():
90 flagset
= ' '.join((flag
.name
for flag
in target
.cxxflags
))
91 if flagset
not in by_flagset
:
92 by_flagset
[flagset
] = list()
93 by_flagset
[flagset
].append(target
)
94 for targetlist
in by_flagset
.values():
96 flagsets
= by_flagset
.keys()
98 print '%d compilerflag groups:' % (len(flagsets
))
99 for flagset
in flagsets
:
101 for target
in by_flagset
[flagset
]:
102 print '%s' % (target
)
106 for target
in CxxTargets
.by_name
.values():
107 flagset
= ' '.join((flag
.name
for flag
in target
.includeflags
))
108 if flagset
not in by_flagset
:
109 by_flagset
[flagset
] = list()
110 by_flagset
[flagset
].append(target
)
111 for targetlist
in by_flagset
.values():
113 flagsets
= by_flagset
.keys()
115 print '%d include flag groups:' % (len(flagsets
))
116 for flagset
in flagsets
:
118 for target
in by_flagset
[flagset
]:
119 print '%s' % (target
)
124 for target
in CxxTargets
.by_name
.values():
125 by_name
[os
.path
.basename(target
.outputfile
)] = target
126 names
= by_name
.keys()
128 for target
in CxxTargets
.by_name
.values():
129 if len(target
.inputfiles
) > 1:
130 objects
= [os
.path
.basename(object) for object in target
.inputfiles
]
132 for object in objects
:
133 if object in by_name
:
134 sources
.append(by_name
[object].inputfiles
[0])
136 sources
.append('!!!!' + object)
138 print '%s %s' % (target
.getFullOutputname(), ' '.join(sources
))