-
Notifications
You must be signed in to change notification settings - Fork 54
/
wscript
331 lines (274 loc) · 11.8 KB
/
wscript
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#!/usr/bin/env python3
from waflib.Build import BuildContext, CleanContext, InstallContext, UninstallContext, Logs
import os
top = '.'
out = 'build'
# the code inside fragment deliberately does an unsafe implicit cast float->char to trigger a
# compiler warning; sometimes, gcc does not tell about an unsupported parameter *unless* the
# code being compiled causes a warning
c_cflag_check_code = """
int main()
{
float f = 4.0;
char c = f;
return c - 4;
}
"""
def check_compiler_flag(conf, flag, mandatory = 0):
return conf.check(fragment = c_cflag_check_code, mandatory = mandatory, execute = 0, define_ret = 0, msg = 'Checking for compiler switch %s' % flag, cflags = [flag], okmsg = 'yes', errmsg = 'no')
def check_combined_build_flags(conf, cflags, ldflags, mandatory = 0):
if ldflags:
Logs.pprint('NORMAL', 'Now checking the combination of CFLAGS %s and LDFLAGS %s' % (' '.join(cflags), ' '.join(ldflags)))
else:
Logs.pprint('NORMAL', 'Now checking the combination of CFLAGS %s' % ' '.join(cflags))
return conf.check(fragment = c_cflag_check_code, mandatory = mandatory, execute = 0, define_ret = 0, msg = 'Checking if this combination works', cflags = cflags, ldflags = ldflags, okmsg = 'yes', errmsg = 'no')
class PlatformIMX6:
description = 'i.MX6 with Chips&Media CODA960 codec as VPU'
def configure(self, conf):
conf.check_cc(lib = 'vpu', uselib_store = 'CODA960', define_name = '', mandatory = 1)
with_sof_stuff = conf.check_cc(fragment = '''
#include <vpu_lib.h>
int main() {
return ENC_ENABLE_SOF_STUFF * 0;
}
''',
uselib = 'CODA960',
mandatory = False,
execute = False,
define_name = '',
msg = 'checking if ENC_ENABLE_SOF_STUFF exists'
)
if with_sof_stuff:
conf.define('HAVE_IMXVPUENC_ENABLE_SOF_STUFF', 1)
imx_linux_headers_path = conf.options.imx_headers
if not imx_linux_headers_path:
imx_linux_headers_path = os.path.join(conf.options.sysroot_path, 'usr/include/imx')
Logs.pprint('NORMAL', 'i.MX linux headers path: %s' % imx_linux_headers_path)
conf.env['INCLUDES_IMXHEADERS'] = [imx_linux_headers_path]
if not conf.check_cc(fragment = '''
#include <time.h>
#include <sys/types.h>
#include <linux/ipu.h>
int main() { return 0; }
''',
uselib_store = 'CODA960',
uselib = ['IMXHEADERS', 'GNU99'],
mandatory = False,
execute = False,
define_name = '',
msg = 'checking for the IPU header linux/ipu.h'
):
conf.fatal('Cannot build CODA960 backend: IPU header linux/ipu.h not found (needed for combined frame copying / de-tiling)')
def build(self, bld):
bld(
features = ['c'],
includes = ['.'],
cflags = ['-Wno-pedantic'],
uselib = ['IMXDMABUFFER', 'GNU99', 'IMXHEADERS'],
source = ['imxvpuapi2/imxvpuapi2_imx6_coda_ipu.c'],
name = 'imx6_coda_ipu'
)
bld(
features = ['c'],
includes = ['.'],
uselib = ['IMXDMABUFFER', 'C99', 'CODA960'],
source = ['imxvpuapi2/imxvpuapi2_imx6_coda.c'],
name = 'imx6_coda'
)
return {
'uselib': ['CODA960'],
'use': ['imx6_coda_ipu', 'imx6_coda']
}
class PlatformIMX8M:
description = 'i.MX8 M / M mini / M plus with Hantro G1/G2 decoder (optionally also a Hantro H1 or Hantro VC8000E encoder)'
def __init__(self, soc_type):
self.soc_type = soc_type
def configure(self, conf):
sysroot_path = conf.env['SYSROOT']
conf.env['CFLAGS_HANTRO'] += ['-pthread']
conf.env['LINKFLAGS_HANTRO'] += ['-pthread']
conf.check_cc(uselib_store = 'HANTRO', uselib = 'HANTRO', define_name = '', mandatory = 1, lib = 'hantro')
conf.check_cc(uselib_store = 'HANTRO', uselib = 'HANTRO', define_name = '', mandatory = 1, lib = 'codec')
conf.env['DEFINES_HANTRO'] += ['SET_OUTPUT_CROP_RECT', 'USE_EXTERNAL_BUFFER', 'VSI_API', 'ENABLE_CODEC_VP8']
conf.check_cc(uselib_store = 'HANTRO_DEC', uselib = 'HANTRO', define_name = '', mandatory = 1, includes = [os.path.join(sysroot_path, 'usr/include/hantro_dec')], header_name = 'dwl.h')
conf.check_cc(uselib_store = 'HANTRO_DEC', uselib = 'HANTRO', define_name = '', mandatory = 1, includes = [os.path.join(sysroot_path, 'usr/include/hantro_dec')], header_name = 'codec.h')
if self.soc_type == 'MX8MM':
# i.MX8m mini has the Hantro H1 encoder
conf.define('IMXVPUAPI2_VPU_HAS_H1_ENCODER', 1)
conf.check_cc(uselib_store = 'HANTRO', uselib = 'HANTRO', define_name = '', mandatory = 1, lib = 'hantro_h1')
conf.check_cc(uselib_store = 'HANTRO', uselib = 'HANTRO', define_name = '', mandatory = 1, lib = 'codec_enc')
conf.env['DEFINES_HANTRO_ENC'] += ['ENCH1', 'OMX_ENCODER_VIDEO_DOMAIN', 'ENABLE_HANTRO_ENC']
conf.check_cc(uselib_store = 'HANTRO_ENC', uselib = 'HANTRO', define_name = '', mandatory = 1, includes = [os.path.join(sysroot_path, 'usr/include/hantro_enc'), os.path.join(sysroot_path, 'usr/include/hantro_enc/headers')], header_name = 'encoder/codec.h')
elif self.soc_type == 'MX8MP':
# i.MX8m plus has the Hantro VC8000E encoder
conf.define('IMXVPUAPI2_VPU_HAS_VC8000E_ENCODER', 1)
conf.check_cc(uselib_store = 'HANTRO', uselib = 'HANTRO', define_name = '', mandatory = 1, lib = ['hantro_vc8000e', 'm'])
conf.check_cc(uselib_store = 'HANTRO_ENC', uselib = 'HANTRO', define_name = '', mandatory = 1, includes = [os.path.join(sysroot_path, 'usr/include')], header_name = 'hantro_VC8000E_enc/hevcencapi.h')
with_hantro_codec_error_frame_retval = conf.check_cc(fragment = '''
#include "dwl.h"
#include "codec.h"
int main() {
return CODEC_ERROR_FRAME * 0;
}
''',
uselib = ['C99', 'HANTRO', 'HANTRO_DEC'],
mandatory = False,
execute = False,
define_name = '',
msg = 'checking if CODEC_ERROR_FRAME exists'
)
if with_hantro_codec_error_frame_retval:
conf.define('HAVE_IMXVPUDEC_HANTRO_CODEC_ERROR_FRAME', 1)
conf.define('IMXVPUAPI_IMX8_SOC_TYPE_' + self.soc_type, 1)
def build(self, bld):
bld(
features = ['c'],
includes = ['.'],
uselib = ['IMXDMABUFFER', 'C99', 'HANTRO', 'HANTRO_DEC'],
source = ['imxvpuapi2/imxvpuapi2_imx8m_hantro_decoder.c'],
name = 'imx8_decoder'
)
if self.soc_type == 'MX8MM':
bld(
features = ['c'],
includes = ['.'],
uselib = ['IMXDMABUFFER', 'C99', 'HANTRO', 'HANTRO_ENC'],
source = ['imxvpuapi2/imxvpuapi2_imx8m_hantro_h1_encoder.c'],
name = 'imx8_encoder'
)
elif self.soc_type == 'MX8MP':
bld(
features = ['c'],
includes = ['.'],
uselib = ['IMXDMABUFFER', 'C99', 'HANTRO', 'HANTRO_ENC'],
source = ['imxvpuapi2/imxvpuapi2_imx8m_hantro_vc8000_encoder.c'],
name = 'imx8_encoder'
)
else:
bld(
features = ['c'],
includes = ['.'],
uselib = ['IMXDMABUFFER', 'C99'],
source = ['imxvpuapi2/imxvpuapi2_imx8m_hantro_dummy_encoder.c'],
name = 'imx8_encoder'
)
return {
'uselib': ['HANTRO', 'HANTRO_DEC', 'HANTRO_ENC'],
'use': ['imx8_decoder', 'imx8_encoder']
}
imx_platforms = {
'imx6': PlatformIMX6(),
'imx8m': PlatformIMX8M(soc_type = 'MX8M'),
'imx8mm': PlatformIMX8M(soc_type = 'MX8MM'),
'imx8mp': PlatformIMX8M(soc_type = 'MX8MP')
}
def options(opt):
opt.add_option('--enable-debug', action = 'store_true', default = False, help = 'enable debug build [default: disabled]')
opt.add_option('--enable-static', action = 'store_true', default = False, help = 'build static library [default: build shared library]')
opt.add_option('--imx-platform', action='store', default='', help='i.MX platform to build for (valid platforms: ' + ' '.join(imx_platforms.keys()) + ')')
opt.add_option('--imx-headers', action='store', default='', help='path to where linux/ipu.h etc. can be found [default: <sysroot path>/usr/include/imx]')
opt.add_option('--sysroot-path', action='store', default='', help='path to the sysroot')
opt.add_option('--disable-examples', action = 'store_true', default = False, help = 'do not compile examples [default: build examples]')
opt.load('compiler_c')
opt.load('gnu_dirs')
def configure(conf):
conf.load('compiler_c')
conf.load('gnu_dirs')
# check and add compiler flags
basic_cflags = conf.env['CFLAGS'] or []
basic_ldflags = conf.env['LINKFLAGS'] or []
basic_cflags += ['-Wextra', '-Wall', '-pedantic', '-fPIC', '-DPIC']
if conf.options.enable_debug:
basic_cflags += ['-O0', '-g3', '-ggdb']
else:
basic_cflags += ['-O2']
for cflag in basic_cflags:
check_compiler_flag(conf, cflag, 1)
for std in ['gnu99', 'c99']:
check_compiler_flag(conf, '-std=' + std)
check_combined_build_flags(conf, basic_cflags + ['-std=' + std], basic_ldflags, 1)
conf.env['CFLAGS_' + std.upper()] = ['-std=' + std]
conf.env['CFLAGS'] = basic_cflags
conf.env['LINKFLAGS'] = basic_ldflags
conf.env['BUILD_STATIC'] = conf.options.enable_static
conf.env['DISABLE_EXAMPLES'] = conf.options.disable_examples
# check libimxdmabuffer dependency
conf.check_cfg(package = 'libimxdmabuffer >= 1.1.1', uselib_store = 'IMXDMABUFFER', define_name = '', args = '--cflags --libs', mandatory = 1)
# check sysroot path
if not conf.options.sysroot_path:
conf.fatal('Sysroot path not set; add --sysroot-path switch to configure command line')
sysroot_path = os.path.abspath(os.path.expanduser(conf.options.sysroot_path))
if os.path.isdir(sysroot_path):
Logs.pprint('NORMAL', 'Using "%s" as sysroot path' % sysroot_path)
else:
conf.fatal('Path "%s" does not exist or is not a valid directory; cannot use as sysroot path' % sysroot_path)
conf.env['SYSROOT'] = sysroot_path
# check i.MX platform
if not conf.options.imx_platform:
conf.fatal('i.MX platform not defined; add --imx-platform switch to configure command line')
imx_platform_id = conf.options.imx_platform
try:
imx_platform = imx_platforms[imx_platform_id]
except KeyError:
conf.fatal('Invalid i.MX platform "%s" specified; valid platforms: %s' % (imx_platform_id, ' '.join(imx_platforms.keys())))
conf.env['IMX_PLATFORM'] = imx_platform_id
# configure platform
imx_platform.configure(conf)
# process the library version number
version_node = conf.srcnode.find_node('VERSION')
if not version_node:
conf.fatal('Could not open VERSION file')
with open(version_node.abspath()) as x:
version = x.readline().splitlines()[0]
conf.env['IMXVPUAPI2_VERSION'] = version
conf.define('IMXVPUAPI2_VERSION', version)
Logs.pprint('NORMAL', 'libimxvpuapi version %s' % version)
# write the config header
conf.write_config_header('config.h')
def build(bld):
imx_platform_id = bld.env['IMX_PLATFORM']
imx_platform = imx_platforms[imx_platform_id]
use_lists = imx_platform.build(bld)
bld(
features = ['c', 'cstlib' if bld.env['BUILD_STATIC'] else 'cshlib'],
includes = ['.'],
uselib = ['IMXDMABUFFER', 'C99'] + use_lists['uselib'],
use = use_lists['use'],
source = ['imxvpuapi2/imxvpuapi2.c', 'imxvpuapi2/imxvpuapi2_priv.c', 'imxvpuapi2/imxvpuapi2_jpeg.c'],
name = 'imxvpuapi2',
target = 'imxvpuapi2',
install_path="${LIBDIR}",
vnum = bld.env['IMXVPUAPI2_VERSION']
)
bld.install_files('${PREFIX}/include/imxvpuapi2/', ['imxvpuapi2/imxvpuapi2.h', 'imxvpuapi2/imxvpuapi2_jpeg.h'])
bld(
features = ['subst'],
source = "libimxvpuapi2.pc.in",
target="libimxvpuapi2.pc",
install_path="${LIBDIR}/pkgconfig"
)
if not bld.env['DISABLE_EXAMPLES']:
examples = [ \
{ 'name': 'decode-example', 'source': ['example/decode-example.c'] }, \
{ 'name': 'encode-example', 'source': ['example/encode-example.c'] }, \
{ 'name': 'jpeg-dec-example', 'source': ['example/jpeg-dec-example.c'] }, \
{ 'name': 'jpeg-enc-example', 'source': ['example/jpeg-enc-example.c'] }, \
]
bld(
features = ['c'],
includes = ['.', 'example'],
uselib = ['IMXDMABUFFER', 'C99'],
use = 'imxvpuapi2',
source = ['example/main.c', 'example/y4m_io.c', 'example/h264_utils.c'],
name = 'examples-common'
)
for example in examples:
bld(
features = ['c', 'cprogram'],
includes = ['.', 'example'],
uselib = ['IMXDMABUFFER', 'C99'],
use = 'imxvpuapi2 examples-common',
source = example['source'],
target = 'example/' + example['name'],
install_path = None # makes sure the example is not installed
)