michael@0: import pymake.data michael@0: import pymake.parser michael@0: import pymake.parserdata michael@0: import sys michael@0: michael@0: ''' michael@0: Modifies the output of Sun Studio's -xM to look more like the output michael@0: of gcc's -MD -MP, adding phony targets for dependencies. michael@0: ''' michael@0: michael@0: michael@0: def add_phony_targets(path): michael@0: print path michael@0: deps = set() michael@0: targets = set() michael@0: for stmt in pymake.parser.parsefile(path): michael@0: if isinstance(stmt, pymake.parserdata.Rule): michael@0: assert isinstance(stmt.depexp, pymake.data.StringExpansion) michael@0: assert isinstance(stmt.targetexp, pymake.data.StringExpansion) michael@0: for d in stmt.depexp.s.split(): michael@0: deps.add(d) michael@0: for t in stmt.targetexp.s.split(): michael@0: targets.add(t) michael@0: phony_targets = deps - targets michael@0: if not phony_targets: michael@0: return michael@0: with open(path, 'a') as f: michael@0: f.writelines('%s:\n' % d for d in phony_targets) michael@0: michael@0: michael@0: if __name__ == '__main__': michael@0: for f in sys.argv[1:]: michael@0: add_phony_targets(f)