6
6
project_path = os .path .split (os .path .realpath (__file__ ))[0 ]
7
7
8
8
9
- def build_all ():
9
+ def build (board , robot ):
10
+ target = []
11
+
10
12
os .system ("rm -rf " + project_path + '/firmware' )
11
13
for dirname in os .listdir (project_path + '/hw/bsp' ):
12
14
if os .path .isdir (project_path + '/hw/bsp/' + dirname ):
13
15
for filename in os .listdir (project_path + '/hw/bsp/' + dirname +
14
16
'/config' ):
15
17
if os .path .isfile (project_path + '/hw/bsp/' + dirname +
16
- '/config/' + filename ):
17
- if filename .endswith (".config" ):
18
+ '/config/' + filename ) and (
19
+ board == 'all' or dirname == board ):
20
+ if filename .endswith (".config" ) and (
21
+ robot == 'all' or filename [:- 7 ] == robot ):
18
22
shutil .copyfile (
19
23
project_path + '/hw/bsp/' + dirname + '/config/' +
20
24
filename , project_path + '/config/.config' )
@@ -27,6 +31,16 @@ def build_all():
27
31
project_path + '/firmware/' + dirname + '&' +
28
32
filename [:- 7 ] + '.elf' )
29
33
34
+ print ('\n ' )
35
+
36
+ target .append ([dirname , filename [:- 7 ]])
37
+ if len (target ) == 0 :
38
+ print ('ERROR:No target select.' )
39
+ else :
40
+ for item in target :
41
+ print ('Robot[' + item [1 ] + ']' + ' for board ' + item [0 ] +
42
+ ' build done.' )
43
+
30
44
31
45
def menuconfig (path ):
32
46
print ('Start menu config.' )
@@ -45,9 +59,14 @@ def config_cmake():
45
59
)
46
60
47
61
62
+ config_prefix = '_SUB_CFG_'
63
+
64
+
48
65
def add_detail (file , name : str , value : str ):
49
66
name = name [7 :]
50
67
file .write ('set(' + name + ' ' + value + ')\n ' )
68
+ if name .startswith (config_prefix ):
69
+ return
51
70
file .write ('add_compile_definitions(' + name + '=${' + name + '})\n ' )
52
71
53
72
@@ -57,13 +76,13 @@ def foreach_config_single(head, file, path):
57
76
58
77
for dirname in os .listdir (path ):
59
78
if os .path .isdir (path + '/' + dirname ):
60
- file .write ('\n \t config _SUB_CFG_ ' + dirname + ' \n \t \t bool \" ' +
61
- dirname + '\" \n ' )
79
+ file .write ('\n \t config ' + config_prefix + dirname +
80
+ ' \n \t \t bool \" ' + dirname + '\" \n ' )
62
81
file .write ('endchoice\n ' )
63
82
64
83
for dirname in os .listdir (path ):
65
84
if os .path .isdir (path + '/' + dirname ):
66
- file .write ('\n if ' + '_SUB_CFG_' + dirname + '\n \t source \" ' +
85
+ file .write ('\n if ' + config_prefix + dirname + '\n \t source \" ' +
67
86
path + '/' + dirname + '/Kconfig"\n endif\n ' )
68
87
69
88
@@ -74,10 +93,10 @@ def foreach_config(head, file, path):
74
93
for dirname in os .listdir (path ):
75
94
if os .path .isdir (path + '/' + dirname ):
76
95
file .write ('\n menu \" ' + dirname + '"\n ' )
77
- file .write ('\n \t config _SUB_CFG_ ' + dirname + ' \n \t \t tristate \" ' +
78
- dirname + '\" \n ' )
96
+ file .write ('\n \t config ' + config_prefix + dirname +
97
+ ' \n \t \t tristate \" ' + dirname + '\" \n ' )
79
98
80
- file .write ('\n if ' + '_SUB_CFG_' + dirname + '\n \t source \" ' +
99
+ file .write ('\n if ' + config_prefix + dirname + '\n \t source \" ' +
81
100
path + '/' + dirname + '/Kconfig"\n endif\n ' )
82
101
file .write ('endmenu\n ' )
83
102
file .write ('endmenu\n ' )
@@ -166,9 +185,6 @@ def generate_cmake(path):
166
185
config_cmake ()
167
186
168
187
elif cmd [1 ] == 'build' :
169
- if cmd [2 ] == 'all' :
170
- print ("Build all target." )
171
- build_all ()
172
-
188
+ build (cmd [2 ], cmd [3 ])
173
189
else :
174
190
print ('错误的参数' )
0 commit comments