1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/build/unix/add_phony_targets.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,33 @@ 1.4 +import pymake.data 1.5 +import pymake.parser 1.6 +import pymake.parserdata 1.7 +import sys 1.8 + 1.9 +''' 1.10 +Modifies the output of Sun Studio's -xM to look more like the output 1.11 +of gcc's -MD -MP, adding phony targets for dependencies. 1.12 +''' 1.13 + 1.14 + 1.15 +def add_phony_targets(path): 1.16 + print path 1.17 + deps = set() 1.18 + targets = set() 1.19 + for stmt in pymake.parser.parsefile(path): 1.20 + if isinstance(stmt, pymake.parserdata.Rule): 1.21 + assert isinstance(stmt.depexp, pymake.data.StringExpansion) 1.22 + assert isinstance(stmt.targetexp, pymake.data.StringExpansion) 1.23 + for d in stmt.depexp.s.split(): 1.24 + deps.add(d) 1.25 + for t in stmt.targetexp.s.split(): 1.26 + targets.add(t) 1.27 + phony_targets = deps - targets 1.28 + if not phony_targets: 1.29 + return 1.30 + with open(path, 'a') as f: 1.31 + f.writelines('%s:\n' % d for d in phony_targets) 1.32 + 1.33 + 1.34 +if __name__ == '__main__': 1.35 + for f in sys.argv[1:]: 1.36 + add_phony_targets(f)