3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 # This file incorporates work covered by the following license notice:
11 # Licensed to the Apache Software Foundation (ASF) under one or more
12 # contributor license agreements. See the NOTICE file distributed
13 # with this work for additional information regarding copyright
14 # ownership. The ASF licenses this file to you under the Apache
15 # License, Version 2.0 (the "License"); you may not use this file
16 # except in compliance with the License. You may obtain a copy of
17 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 def __init__(self
, line
):
26 self
.includeflags
= []
30 options
= line
[:-1].split(' ')
31 self
.directory
= options
.pop(0)
32 parsing_outputfile
= False
33 for option
in options
:
34 if parsing_outputfile
:
35 self
.outputfile
= option
36 parsing_outputfile
= False
38 parsing_outputfile
= True
41 elif option
.startswith('-I'):
42 self
.includeflags
.append(CxxFlag(option
))
43 elif option
.startswith('-'):
44 self
.cxxflags
.append(CxxFlag(option
))
46 self
.inputfiles
.append(option
)
48 self
.includeflags
.sort()
50 for flag
in self
.cxxflags
:
51 cxxflags_tmp
[flag
.name
] = flag
52 self
.cxxflags
= cxxflags_tmp
.values()
53 includeflags_tmp
= dict()
54 for flag
in self
.includeflags
:
55 includeflags_tmp
[flag
.name
] = flag
56 self
.includeflags
= includeflags_tmp
.values()
57 CxxTargets
.by_name
[self
.getFullOutputname()] = self
59 return '%s' % (self
.getFullOutputname())
60 def getFullOutputname(self
):
61 return self
.directory
+ '/' + self
.outputfile
62 def __cmp__(self
, other
):
63 return cmp(self
.getFullOutputname(), other
.getFullOutputname())
66 def __init__(self
, name
):
68 CxxFlags
.by_name
[self
.name
] = self
70 return 'Flag %s' % (self
.name
)
71 def __cmp__(self
, other
):
72 return cmp(self
.name
, other
.name
)
80 if __name__
== '__main__':
81 [CxxTarget(line
) for line
in sys
.stdin
.readlines()]
82 compile_targets
= [target
for target
in CxxTargets
.by_name
.values() if target
.nolink
]
83 link_targets
= [target
for target
in CxxTargets
.by_name
.values() if not target
.nolink
]
84 common_compile_flags
= []
85 for flag
in CxxFlags
.by_name
.values():
86 if sum((flag
in target
.cxxflags
for target
in compile_targets
)) == len(compile_targets
):
87 common_compile_flags
.append(flag
)
88 common_link_flags
= []
89 for flag
in CxxFlags
.by_name
.values():
90 if sum((flag
in target
.cxxflags
for target
in compile_targets
)) == len(compile_targets
):
91 common_link_flags
.append(flag
)
93 for target
in compile_targets
:
94 target
.cxxflags
= [flag
for flag
in target
.cxxflags
if flag
not in common_compile_flags
]
95 target
.cxxflags
.sort()
96 for target
in link_targets
:
97 target
.cxxflags
= [flag
for flag
in target
.cxxflags
if flag
not in common_link_flags
]
98 target
.cxxflags
.sort()
100 common_compile_flags
.sort()
101 common_link_flags
.sort()
102 print 'common compile flags: %s' % (' '.join(flag
.name
for flag
in common_compile_flags
))
103 print 'common link flags: %s' % (' '.join(flag
.name
for flag
in common_link_flags
))
106 for target
in CxxTargets
.by_name
.values():
107 flagset
= ' '.join((flag
.name
for flag
in target
.cxxflags
))
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 compilerflag groups:' % (len(flagsets
))
116 for flagset
in flagsets
:
118 for target
in by_flagset
[flagset
]:
119 print '%s' % (target
)
123 for target
in CxxTargets
.by_name
.values():
124 flagset
= ' '.join((flag
.name
for flag
in target
.includeflags
))
125 if flagset
not in by_flagset
:
126 by_flagset
[flagset
] = list()
127 by_flagset
[flagset
].append(target
)
128 for targetlist
in by_flagset
.values():
130 flagsets
= by_flagset
.keys()
132 print '%d include flag groups:' % (len(flagsets
))
133 for flagset
in flagsets
:
135 for target
in by_flagset
[flagset
]:
136 print '%s' % (target
)
141 for target
in CxxTargets
.by_name
.values():
142 by_name
[os
.path
.basename(target
.outputfile
)] = target
143 names
= by_name
.keys()
145 for target
in CxxTargets
.by_name
.values():
146 if len(target
.inputfiles
) > 1:
147 objects
= [os
.path
.basename(object) for object in target
.inputfiles
]
149 for object in objects
:
150 if object in by_name
:
151 sources
.append(by_name
[object].inputfiles
[0])
153 sources
.append('!!!!' + object)
155 print '%s %s' % (target
.getFullOutputname(), ' '.join(sources
))