hc
2024-08-12 233ab1bd4c5697f5cdec94e60206e8c6ac609b4c
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
project(
  'libmali', 'c',
  version : '1.9.0',
  meson_version : '>=0.54.0',
  default_options : ['b_asneeded=false'])
 
mali_version = meson.project_version()
 
fs = import('fs')
pkgconfig = import('pkgconfig')
 
cc = meson.get_compiler('c')
 
if get_option('arch') != 'auto'
  arch = get_option('arch')
else
  arch = host_machine.cpu_family()
endif
 
gpu = get_option('gpu')
version = get_option('version')
subversion = get_option('subversion')
platform = get_option('platform')
opencl_icd = get_option('opencl-icd')
vendor_package = get_option('vendor-package')
hooks_opts = get_option('hooks')
wrappers_opts = get_option('wrappers')
optimize = get_option('optimize-level')
 
message('Building for ' + '|'.join([arch, gpu, version, subversion,
  platform, optimize]))
 
# Grab libraries with specified configs
cmd = run_command('scripts/grabber.sh',
  arch, gpu, version, subversion, platform, optimize, check : false)
libs = cmd.stdout().strip().split('\n')
 
# Use the first one as default library
default_lib = libs[0]
if default_lib == ''
  error('Failed to find matched library')
endif
 
message('Source libraries: @0@'.format(libs))
 
is_rk3288 = gpu == 'midgard-t76x'
is_utgard = gpu.split('-')[0] == 'utgard'
is_px3se = gpu == 'utgard-400' and subversion == 'r3p0'
 
# Required packages
requires = []
if platform == 'gbm'
  requires = ['libdrm']
elif platform == 'wayland'
  requires = ['libdrm', 'wayland-client', 'wayland-server']
 
  if is_px3se
    requires += ['libffi', 'libcrypto']
  endif
elif platform == 'x11'
  requires = ['libdrm', 'x11', 'xcb']
 
  if is_utgard
    requires += ['xfixes', 'xext', 'xau', 'xdmcp', 'xdamage']
  else
    requires += ['x11-xcb', 'xcb-dri2']
  endif
endif
 
if wrappers_opts.auto() and is_utgard
  wrappers = false
  warning('Wrappers are disabled for utgard by default')
else
  wrappers = not wrappers_opts.disabled()
endif
 
if wrappers
  message('Provide wrappers')
else
  # The vendor package requires soname of wrappers.
  if vendor_package
    error('Cannot provide vendor package without wrappers')
  endif
endif
 
# Install wrapper libraries into vendor dir
if vendor_package
  message('Build vendor package')
  wrapper_libdir = get_option('libdir') / 'mali'
else
  wrapper_libdir = get_option('libdir')
endif
 
# Wrap library name : version
gbm_wrappers = {'gbm' : '1'}
egl_wrappers = {'EGL' : '1'}
glesv1_wrappers = {'GLESv1_CM' : '1'}
glesv2_wrappers = {'GLESv2' : '2'}
wayland_wrappers = {'wayland-egl' : '1'}
cl_wrappers = opencl_icd ? {'MaliOpenCL' : '1'} : {'OpenCL' : '1'}
vk_wrappers = {'MaliVulkan' : '1'}
 
# Source dir : dest dir
gbm_headers = {
  'include/GBM' : '',
}
egl_headers = {
  'include/KHR' : 'KHR',
  'include/EGL' : 'EGL',
}
glesv1_headers = {
  'include/KHR' : 'KHR',
  'include/GLES' : 'GLES',
}
glesv2_headers = {
  'include/KHR' : 'KHR',
  'include/GLES2' : 'GLES2',
  'include/GLES3' : 'GLES3',
}
wayland_egl_headers = {
  'include/WAYLAND' : '',
}
cl_headers = {
  'include/CL' : 'CL',
}
 
# Load original mali library for later function checks and linking
mali = cc.find_library(fs.stem(default_lib),
  dirs : meson.current_source_dir() / fs.parent(default_lib))
 
# Provide newer GBM version with hook library
if hooks_opts
  gbm_version = '21.2.6'
elif cc.has_function('gbm_bo_get_fd_for_plane', dependencies : mali)
  gbm_version = '21.1.0'
elif cc.has_function('gbm_bo_get_modifier', dependencies : mali)
  gbm_version = '17.1.0'
else
  gbm_version = '10.4.0'
endif
 
# Package name : required symbol, wrappers, headers, package version
map = {
  'gbm' : ['gbm_create_device', gbm_wrappers, gbm_headers, gbm_version],
  'egl' : ['eglCreateContext', egl_wrappers, egl_headers, '7.10'],
  'glesv1_cm' : ['eglCreateContext', glesv1_wrappers, glesv1_headers, '7.10'],
  'glesv2' : ['eglCreateContext', glesv2_wrappers, glesv2_headers, '7.10'],
  'wayland-egl' : ['wl_egl_window_create', wayland_wrappers,
    wayland_egl_headers, '18.1.0'],
  'OpenCL' : ['clCreateContext', cl_wrappers, cl_headers, '1.2'],
  'vulkan' : ['vk_icdGetInstanceProcAddr', vk_wrappers, {}, mali_version],
}
 
libhook = []
if hooks_opts
  # Build hook library
  subdir('hook')
 
  # Recommend to link hook library before libmali
  mali_ldflags = libhook_ldflags
else
  mali_ldflags = []
endif
 
# Create dummy source for building dummy libraries
dummy_source = join_paths(meson.current_build_dir(), 'dummy.c')
run_command('touch', dummy_source, check : false)
 
# Create a dummy library which will be replaced by the prebuilt mali library
libmali = shared_library(
  'mali',
  dummy_source,
  install : true,
  version : mali_version)
 
mali_ldflags += ['-L${libdir}', '-lmali']
 
pkgconfig.generate(
  libraries : mali_ldflags,
  requires : requires,
  name : 'mali',
  description : 'Mali GPU User-Space Binary Driver')
 
if is_utgard
  # The utgard DDK requires libMali.so
  custom_target(
    'libMali',
    output : 'libMali.so',
    command : ['echo'],
    capture : true,
    install_dir : get_option('libdir'),
    install : true)
endif
 
foreach name, values : map
  symbol = values[0]
  wrapper_libs = values[1]
  headers = values[2]
  pkg_version = values[3]
  is_opencl_icd = opencl_icd and name == 'OpenCL'
  is_vulkan_icd = name == 'vulkan'
 
  if not cc.has_function(symbol, dependencies : mali)
    continue
  endif
 
  foreach wrapper, version : wrapper_libs
    shared_library(
      wrapper,
      dummy_source,
      link_with : libhook,
      install : true,
      install_dir : wrapper_libdir,
      version : version)
  endforeach
 
  # Install ICD OpenCL vendor config
  if is_opencl_icd
    custom_target(
      'OpenCL vendor icd',
      output : 'mali.icd',
      command : ['echo', 'libMaliOpenCL.so.1'],
      capture : true,
      install_dir : get_option('sysconfdir') / 'OpenCL' / 'vendors',
      install : true)
  endif
 
  # Install ICD Vulkan vendor config
  if is_vulkan_icd
    custom_target(
      'Vulkan vendor icd',
      input : 'data/vulkan/mali.json.in',
      output : 'mali.json',
      command : ['sed', 's/@LIB@/libMaliVulkan.so.1/', '@INPUT@'],
      capture : true,
      install_dir : get_option('datadir') / 'vulkan' / 'icd.d',
      install : true)
  endif
 
  # No {headers, pkgconfig} for {ICD, vendor packages}
  if is_opencl_icd or is_vulkan_icd or vendor_package
    continue
  endif
 
  foreach src, dst : headers
    install_subdir(
      src,
      install_dir : get_option('includedir') / dst,
      install_mode : ['rw-r--r--', 'root'],
      strip_directory : true)
  endforeach
 
  pkgconfig.generate(
    libraries : mali_ldflags,
    requires : requires,
    version : pkg_version,
    name : name,
    description : 'Mali GPU User-Space Binary Driver Wrappers')
endforeach
 
# Install optional overlay
if get_option('with-overlay')
  if is_px3se
    install_data('overlay/S10libmali_px3se',
      install_dir : get_option('sysconfdir') / 'init.d')
    install_data('overlay/px3seBase', install_dir : get_option('bindir'))
  endif
 
  if is_rk3288 and subversion == 'all'
    install_data('overlay/S10libmali_rk3288',
      install_dir : get_option('sysconfdir') / 'init.d')
  endif
endif
 
# Install firmwares
if gpu == 'valhall-g610'
  install_data('firmware/g610/mali_csffw.bin', install_dir : '/lib/firmware')
endif
 
if vendor_package
  # Install vendor ld config
  custom_target(
    'vendor ld config',
    output : '00-' + arch + '-mali.conf',
    command : ['echo', get_option('prefix') / wrapper_libdir],
    capture : true,
    install_dir : '/etc/ld.so.conf.d',
    install : true)
elif get_option('khr-header')
  # Install optional KHR header
  install_data(
    'include/KHR/mali_khrplatform.h',
    install_dir : get_option('includedir') / 'KHR',
    install_mode : ['rw-r--r--', 'root'],
    rename : 'khrplatform.h')
endif
 
# Install target libraries
install_data(libs, install_dir : get_option('libdir'))
 
# Replace dummy libmali library
meson.add_install_script('scripts/fixup_dummy.sh',
  get_option('libdir'), default_lib)
 
if not wrappers
  # Disable wrappers
  meson.add_install_script('scripts/fixup_nowrap.sh', get_option('libdir'))
endif
 
if platform != 'x11' and not vendor_package
  # Disable X11 in EGL header
  meson.add_install_script('scripts/fixup_nox11.sh', get_option('includedir'))
endif