forked from geoffreymbrown/stm32usb-bulk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpdsc2make.py
75 lines (55 loc) · 1.52 KB
/
gpdsc2make.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python
import sys
import untangle
import os
incs = dict()
cvpath = dict()
svpath = dict()
csources = []
asmsources = []
def processfile(file):
"""
Gather all the information about files
"""
if (os.path.sep == '/'):
name = file['name'].replace('\\','/')
else:
name = file['name']
(dir,base) = os.path.split(name)
if (file['category'] == 'header'):
incs[dir] = 1
elif (file['category'] == 'sourceC') | (file['category'] == 'source'):
cvpath[dir] = 1
csources.append(base)
elif (file['category'] == 'sourceAsm'):
if (file['condition'] == 'GCC Toolchain'):
svpath[dir] = 1
asmsources.append(base)
def makegen(path):
"""
process a single gpdsc file
"""
obj = untangle.parse(path)
print "# Vendor: " , obj.package.vendor.cdata
for file in obj.package.generators.generator.project_files.file:
processfile(file)
for component in obj.package.components.component:
for file in component.files.file:
processfile(file)
print "# Include paths\n"
for i in incs.keys():
print "INC += -I" + i
print "\n# Source paths\n"
for cv in cvpath.keys():
print "vpath %.c", cv
for sv in svpath.keys():
print "vpath %.s", sv
print "\n# Sources\n"
for cf in csources:
print "CSOURCE +=", cf
for af in asmsources:
print "ASMSOURCE +=", af
def main():
makegen(sys.argv[1])
if __name__ == "__main__":
main()