Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added python script to help automated header dependency scanning
Takes input from gcc -MM and outputs object : source + headers
dependencies that can be included from the Makefile.

The processing done for gcc -MM output include:
- sorting of dependencies to keep future diffs cleaner
- fixing the destination path if source is not in the CWD
- generating dependency for -fPIC compilation too
  • Loading branch information
spiiroin committed Dec 3, 2012
1 parent e358d0d commit f5b598c
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions depend_filter.py
@@ -0,0 +1,70 @@
#!/usr/bin/env python
# -*- encoding: utf8 -*-

# ----------------------------------------------------------------------------
# Copyright (C) 2012 Jolla Ltd.
# Contact: Simo Piiroinen <simo.piiroinen@jollamobile.com>
# License: GPLv2
# ----------------------------------------------------------------------------

import sys,os

def is_local(path):
return not path.startswith("/")

def print_rule(dest, srce):
print "%s\\\n" % "\\\n\t".join(["%s:" % dest] + srce)

def set_extension(path, ext):
return os.path.splitext(path)[0] + ext

def normalize_path(srce):
return os.path.normpath(srce)

def fix_directory(dest, srce):
srce = os.path.dirname(srce)
dest = os.path.basename(dest)
return os.path.join(srce, dest)

if __name__ == "__main__":

data = sys.stdin.readlines()
data = map(lambda x:x.rstrip(), data)
data.reverse()

deps = []

# Note: dependencies are sorted only to keep
# future diffs cleaner

while data:
line = data.pop()
while line.endswith('\\'):
line = line[:-1] + data.pop()
if not ':' in line:
continue

dest,srce = line.split(":",1)
srce = srce.split()
srce,temp = srce[0],srce[1:]

# take dest path primary srce
dest = fix_directory(dest, srce)

# remove secondary deps with absolute path
temp = filter(is_local, temp)

# sort secondary sources
temp.sort()

srce = [srce] + temp
srce = map(normalize_path, srce)

deps.append((dest,srce))

for dest,srce in sorted(deps):
# emit normal compilation dependencies
print_rule(dest, srce)
# and for -fPIC in case it is needed
dest = set_extension(dest, ".pic.o")
print_rule(dest, srce)

0 comments on commit f5b598c

Please sign in to comment.