blob: 73c8b29fc1246f345ffe028a5b48889f07134bd5 [file] [log] [blame]
Austin Schuh41baf202022-01-01 14:33:40 -08001#!/usr/bin/python3
2
3import os
4import xml.dom.minidom as XML
5
6# Read base configuration
7base = ""
8with open("iar_template.ipcf") as f:
9 base = f.read()
10
11# Enumerate all device/host examples
12dir_1 = os.listdir("../examples")
13for dir_2 in dir_1:
14 if os.path.isdir("../examples/{}".format(dir_2)):
15 print(dir_2)
16 examples = os.listdir("../examples/{}".format(dir_2))
17 for example in examples:
18 if os.path.isdir("../examples/{}/{}".format(dir_2, example)):
19 print("../examples/{}/{}".format(dir_2, example))
20 conf = XML.parseString(base)
21 files = conf.getElementsByTagName("files")[0]
22 inc = conf.getElementsByTagName("includePath")[0]
23 # Add bsp inc
24 path = conf.createElement('path')
25 path_txt = conf.createTextNode("$TUSB_DIR$/hw")
26 path.appendChild(path_txt)
27 inc.appendChild(path)
28 # Add board.c/.h
29 grp = conf.createElement('group')
30 grp.setAttribute("name", "bsp")
31 path = conf.createElement('path')
32 path_txt = conf.createTextNode("$TUSB_DIR$/hw/bsp/board.c")
33 path.appendChild(path_txt)
34 grp.appendChild(path)
35 files.appendChild(grp)
36 # Add example's .c/.h
37 grp = conf.createElement('group')
38 grp.setAttribute("name", "example")
39 for file in os.listdir("../examples/{}/{}/src".format(dir_2, example)):
40 if file.endswith(".c") or file.endswith(".h"):
41 path = conf.createElement('path')
42 path.setAttribute("copyTo", "$PROJ_DIR$/{}".format(file))
43 path_txt = conf.createTextNode("$TUSB_DIR$/examples/{0}/{1}/src/{2}".format(dir_2, example, file))
44 path.appendChild(path_txt)
45 grp.appendChild(path)
46 files.appendChild(grp)
47 cfg_str = conf.toprettyxml()
48 cfg_str = '\n'.join([s for s in cfg_str.splitlines() if s.strip()])
49 #print(cfg_str)
50 with open("../examples/{0}/{1}/iar_{1}.ipcf".format(dir_2, example), 'w') as f:
51 f.write(cfg_str)