forked from lvgl-micropython/lvgl_micropython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.py
235 lines (190 loc) · 5.55 KB
/
make.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/env python3
import os
import sys
import builder
from argparse import ArgumentParser
if sys.platform.startswith('win'):
raise RuntimeError('compiling on windows is not supported at this time')
SCRIPT_DIR = os.path.abspath(os.path.dirname(sys.argv[0]))
MPY_DIR = os.path.join(SCRIPT_DIR, 'micropython')
argParser = ArgumentParser(prefix_chars='-')
argParser.add_argument(
'target',
help='build target',
choices=[
'esp32', 'windows', 'stm32', 'unix', 'rp2',
'renesas-ra', 'nrf', 'mimxrt', 'samd', 'macOS'
],
action='store',
nargs=1
)
args1, extra_args = argParser.parse_known_args(sys.argv[1:])
target = args1.target[0]
argParser = ArgumentParser(prefix_chars='mscLBFDIV')
argParser.add_argument(
'mpy_cross',
dest='mpy_cross',
help='compile mpy_cross',
action='store_true'
)
argParser.add_argument(
'submodules',
dest='submodules',
help='build submodules',
action='store_true'
)
argParser.add_argument(
'clean',
dest='clean',
help='clean the build',
action='store_true'
)
argParser.add_argument(
'LV_CFLAGS',
dest='lv_cflags',
help='additional flags that gets passed to the compiler for LVGL',
action='store',
default=None
)
if target in ('windows', 'unix'):
argParser.add_argument(
'VARIANT',
dest='board',
help='optional, board to compile for.',
action='store',
default=None
)
else:
argParser.add_argument(
'BOARD',
dest='board',
help='optional, board to compile for.',
action='store',
default=None
)
argParser.add_argument(
'FROZEN_MANIFEST',
dest='frozen_manifest',
help='path to manifest file',
action='store',
default=None
)
argParser.add_argument(
'DISPLAY',
dest='displays',
help=(
'display name or path (absolute) to display driver. '
'Display name is the name of the source file under '
'driver/display (without the ".py")'
),
action='append',
default=[]
)
argParser.add_argument(
'INDEV',
dest='indevs',
help=(
'indev device name or path (absolue) to indev driver. '
'Indev name is the name of the source file under '
'driver/indev (without the ".py")'
),
action='append',
default=[]
)
args2, extra_args = argParser.parse_known_args(extra_args)
lv_cflags = args2.lv_cflags
clean = args2.clean
submodules = args2.submodules
mpy_cross = args2.mpy_cross
board = args2.board
frozen_manifest = args2.frozen_manifest
displays = args2.displays
indevs = args2.indevs
if lv_cflags is None:
lv_cflags = ''
argParser = ArgumentParser(prefix_chars='-')
argParser.add_argument(
'--LVGL_API',
dest='lvgl_api',
help=(
'Sets the API to be used. If this flag gets set '
'then the api that is used is the same as what the C API is for LVGL.'
),
action='store_true',
default=False
)
args3, extra_args = argParser.parse_known_args(extra_args)
lvgl_api = args3.lvgl_api
extra_args.append(f'FROZEN_MANIFEST="{SCRIPT_DIR}/build/manifest.py"')
if lvgl_api:
extra_args.append(f'GEN_SCRIPT=lvgl')
else:
extra_args.append(f'GEN_SCRIPT=python')
if lv_cflags is not None:
lv_cflags = lv_cflags.replace('"', '')
def get_submodules():
if not os.path.exists(
os.path.join(SCRIPT_DIR, 'lib/micropython/mpy-cross')
):
builder.get_micropython()
if not os.path.exists(os.path.join(SCRIPT_DIR, 'lib/lvgl/lvgl.h')):
builder.get_lvgl()
if not os.path.exists(os.path.join(SCRIPT_DIR, 'lib/pycparser/pycparser')):
builder.get_pycparser()
def create_lvgl_header():
header_path = f'{SCRIPT_DIR}/build/lvgl_header.h'
with open(header_path, 'w') as f:
f.write(
f'#include "{SCRIPT_DIR}/lib/lvgl/lvgl.h"\n'
)
f.write(
f'#include "{SCRIPT_DIR}/lib/lvgl/src/lvgl_private.h"\n'
)
f.write(
f'#include "{SCRIPT_DIR}/ext_mod/lvgl_addons'
f'/include/color_addons.h"\n'
)
if __name__ == '__main__':
from builder import set_mp_version
if sys.platform.startswith('win'):
from builder import setup_windows_build
setup_windows_build()
if target.lower() == 'esp32':
from builder import esp32 as mod
elif target.lower() == 'unix':
from builder import unix as mod
elif target.lower() == 'rp2':
from builder import rp2 as mod
elif target.lower() == 'stm32':
from builder import stm32 as mod
elif target.lower() == 'nrf':
from builder import nrf as mod
elif target.lower() == 'renesas-ra':
from builder import renesas as mod
elif target.lower() == 'macos':
from builder import macOS as mod
target = 'unix'
elif target.lower() == 'windows':
from builder import windows as mod
else:
import builder as mod
extra_args, lv_cflags, board = mod.parse_args(extra_args, lv_cflags, board)
extra_args = mod.build_commands(target, extra_args, SCRIPT_DIR, lv_cflags, board)
if submodules:
print('Collecting build requirements....')
get_submodules()
mod.submodules()
if clean:
print('Cleaning build....')
mod.clean(mpy_cross)
if mpy_cross:
print('Compiling mpy-cross....')
mod.mpy_cross()
print('Generating build files....')
set_mp_version(target.lower())
mod.build_manifest(
target, SCRIPT_DIR, lvgl_api, displays, indevs, frozen_manifest
)
create_lvgl_header()
print('Compiling....')
mod.compile(*extra_args)