summaryrefslogtreecommitdiff
path: root/cad/plugins/CoNTub/procdeps.py
blob: 2a13bc009cf022a174581135d0a719673190bbd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python
# Copyright 2006-2007 Nanorex, Inc.  See LICENSE file for details.
# $Id$
# This is used only for "make deps"

import sys, re

srcdir = sys.argv[1]
objdir = sys.argv[2]
substitution = sys.argv[3]
objs = sys.argv[4:]

# This is a little kludgey. The idea is to allow either C files (with
# ".o:.c") or C++ files (with ".o:.cpp") and ideally as many other
# filetypes as possible. For instance, Java could use ".class:.java".
# But there will likely be reasonable situations for which this won't
# work.
obj_ending, src_ending = substitution.split(':')

# Perform a pattern find-and-replace for all occurrences in a string.
def subAll(pattern, repl, str):
    while True:
        s = re.sub(pattern, repl, str)
        if s == str:
            return str
        str = s

print '# Automatically generated dependencies from procdeps.py'

for obj in objs:
    # Generate the source file for this object file, and put it in SRCDIR.
    src = re.sub(obj_ending + '$', src_ending, obj)
    src = re.sub(objdir + '/', '$(SRCDIR)/', src)
    # Put this object file in OBJDIR.
    obj = re.sub(objdir + '/', '$(OBJDIR)/', obj)
    # Print a dependency line.
    print obj + ': ' + src
    print '\t$(CXX) $(CXXFLAGS) -c -o %s %s' % (obj, src)

for L in sys.stdin.readlines():
    L = L.rstrip()
    # Remove all absolute header files, like /usr/include stuff.
    L = subAll(' /[^ ]*\.h', '', L)
    if L and not L.startswith('#') and not L.rstrip().endswith(':'):
        obj, hfiles = L.split(':')
        # Put this object file in OBJDIR.
        obj = re.sub(srcdir + '/', '$(OBJDIR)/', obj)
        # Put the header files in SRCDIR.
        hfiles = subAll(srcdir + '/', '$(SRCDIR)/', hfiles)
        # Print the modified dependency line.
        print obj + ':' + hfiles