xref: /OK3568_Linux_fs/external/libmali/meson.build (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1project(
2  'libmali', 'c',
3  version : '1.9.0',
4  meson_version : '>=0.54.0',
5  default_options : ['b_asneeded=false'])
6
7mali_version = meson.project_version()
8
9fs = import('fs')
10pkgconfig = import('pkgconfig')
11
12cc = meson.get_compiler('c')
13
14if get_option('arch') != 'auto'
15  arch = get_option('arch')
16else
17  arch = host_machine.cpu_family()
18endif
19
20gpu = get_option('gpu')
21version = get_option('version')
22subversion = get_option('subversion')
23platform = get_option('platform')
24opencl_icd = get_option('opencl-icd')
25vendor_package = get_option('vendor-package')
26hooks_opts = get_option('hooks')
27wrappers_opts = get_option('wrappers')
28optimize = get_option('optimize-level')
29
30message('Building for ' + '|'.join([arch, gpu, version, subversion,
31  platform, optimize]))
32
33# Grab libraries with specified configs
34cmd = run_command('scripts/grabber.sh',
35  arch, gpu, version, subversion, platform, optimize, check : false)
36libs = cmd.stdout().strip().split(' ')
37
38# Use the first one as default library
39default_lib = libs[0]
40if default_lib == ''
41  error('Failed to find matched library')
42endif
43
44message('Source libraries: @0@'.format(libs))
45
46is_rk3288 = gpu == 'midgard-t76x'
47is_utgard = gpu.split('-')[0] == 'utgard'
48is_px3se = gpu == 'utgard-400' and subversion == 'r3p0'
49
50platforms = platform.split('-')
51has_gbm = platforms.contains('gbm')
52has_x11 = platforms.contains('x11')
53has_wayland = platforms.contains('wayland')
54
55# Required packages
56requires = []
57if has_gbm
58  requires = ['libdrm']
59endif
60if has_wayland
61  requires = ['libdrm', 'wayland-client', 'wayland-server']
62
63  if is_px3se
64    requires += ['libffi', 'libcrypto']
65  endif
66endif
67if has_x11
68  requires = ['libdrm', 'x11', 'xcb']
69
70  if is_utgard
71    requires += ['xfixes', 'xext', 'xau', 'xdmcp', 'xdamage']
72  else
73    requires += ['x11-xcb', 'xcb-dri2']
74  endif
75endif
76
77if wrappers_opts.auto() and is_utgard
78  wrappers = false
79  warning('Wrappers are disabled for utgard by default')
80else
81  wrappers = not wrappers_opts.disabled()
82endif
83
84if wrappers
85  message('Provide wrappers')
86else
87  # The vendor package requires soname of wrappers.
88  if vendor_package
89    error('Cannot provide vendor package without wrappers')
90  endif
91endif
92
93# Install wrapper libraries into vendor dir
94if vendor_package
95  message('Build vendor package')
96  wrapper_libdir = get_option('libdir') / 'mali'
97else
98  wrapper_libdir = get_option('libdir')
99endif
100
101# Wrap library name : version
102gbm_wrappers = {'gbm' : '1'}
103egl_wrappers = {'EGL' : '1'}
104glesv1_wrappers = {'GLESv1_CM' : '1'}
105glesv2_wrappers = {'GLESv2' : '2'}
106wayland_wrappers = {'wayland-egl' : '1'}
107cl_wrappers = opencl_icd ? {'MaliOpenCL' : '1'} : {'OpenCL' : '1'}
108vk_wrappers = {'MaliVulkan' : '1'}
109
110# Source dir : dest dir
111gbm_headers = {
112  'include/GBM' : '',
113}
114egl_headers = {
115  'include/KHR' : 'KHR',
116  'include/EGL' : 'EGL',
117}
118glesv1_headers = {
119  'include/KHR' : 'KHR',
120  'include/GLES' : 'GLES',
121}
122glesv2_headers = {
123  'include/KHR' : 'KHR',
124  'include/GLES2' : 'GLES2',
125  'include/GLES3' : 'GLES3',
126}
127wayland_egl_headers = {
128  'include/WAYLAND' : '',
129}
130cl_headers = {
131  'include/CL' : 'CL',
132}
133
134# Load original mali library for later function checks and linking
135mali = cc.find_library(fs.stem(default_lib),
136  dirs : meson.current_source_dir() / fs.parent(default_lib))
137
138# Provide newer GBM version with hook library
139if hooks_opts
140  gbm_version = '21.2.6'
141elif cc.has_function('gbm_bo_get_fd_for_plane', dependencies : mali)
142  gbm_version = '21.1.0'
143elif cc.has_function('gbm_bo_get_modifier', dependencies : mali)
144  gbm_version = '17.1.0'
145else
146  gbm_version = '10.4.0'
147endif
148
149# Package name : required symbol, wrappers, headers, package version
150map = {
151  'gbm' : ['gbm_create_device', gbm_wrappers, gbm_headers, gbm_version],
152  'egl' : ['eglCreateContext', egl_wrappers, egl_headers, '7.10'],
153  'glesv1_cm' : ['eglCreateContext', glesv1_wrappers, glesv1_headers, '7.10'],
154  'glesv2' : ['eglCreateContext', glesv2_wrappers, glesv2_headers, '7.10'],
155  'wayland-egl' : ['wl_egl_window_create', wayland_wrappers,
156    wayland_egl_headers, '18.1.0'],
157  'OpenCL' : ['clCreateContext', cl_wrappers, cl_headers, '1.2'],
158  'vulkan' : ['vk_icdGetInstanceProcAddr', vk_wrappers, {}, mali_version],
159}
160
161libhook = []
162if hooks_opts
163  # Build hook library
164  subdir('hook')
165
166  # Recommend to link hook library before libmali
167  mali_ldflags = libhook_ldflags
168else
169  mali_ldflags = []
170endif
171
172# Create dummy source for building dummy libraries
173dummy_source = join_paths(meson.current_build_dir(), 'dummy.c')
174run_command('touch', dummy_source, check : false)
175
176# Create a dummy library which will be replaced by the prebuilt mali library
177libmali = shared_library(
178  'mali',
179  dummy_source,
180  install : true,
181  version : mali_version)
182
183mali_ldflags += ['-L${libdir}', '-lmali']
184
185pkgconfig.generate(
186  libraries : mali_ldflags,
187  requires : requires,
188  name : 'mali',
189  description : 'Mali GPU User-Space Binary Driver')
190
191if is_utgard
192  # The utgard DDK requires libMali.so
193  custom_target(
194    'libMali',
195    output : 'libMali.so',
196    command : ['echo'],
197    capture : true,
198    install_dir : get_option('libdir'),
199    install : true)
200endif
201
202foreach name, values : map
203  symbol = values[0]
204  wrapper_libs = values[1]
205  headers = values[2]
206  pkg_version = values[3]
207  is_opencl_icd = opencl_icd and name == 'OpenCL'
208  is_vulkan_icd = name == 'vulkan'
209
210  if not cc.has_function(symbol, dependencies : mali)
211    continue
212  endif
213
214  foreach wrapper, version : wrapper_libs
215    shared_library(
216      wrapper,
217      dummy_source,
218      link_with : [libhook, libmali],
219      install : true,
220      install_dir : wrapper_libdir,
221      version : version)
222  endforeach
223
224  # Install ICD OpenCL vendor config
225  if is_opencl_icd
226    custom_target(
227      'OpenCL vendor icd',
228      output : 'mali.icd',
229      command : ['echo', 'libMaliOpenCL.so.1'],
230      capture : true,
231      install_dir : get_option('sysconfdir') / 'OpenCL' / 'vendors',
232      install : true)
233  endif
234
235  # Install ICD Vulkan vendor config
236  if is_vulkan_icd
237    custom_target(
238      'Vulkan vendor icd',
239      input : 'data/vulkan/mali.json.in',
240      output : 'mali.json',
241      command : ['sed', 's/@LIB@/libMaliVulkan.so.1/', '@INPUT@'],
242      capture : true,
243      install_dir : get_option('datadir') / 'vulkan' / 'icd.d',
244      install : true)
245  endif
246
247  # No {headers, pkgconfig} for {ICD, vendor packages}
248  if is_opencl_icd or is_vulkan_icd or vendor_package
249    continue
250  endif
251
252  foreach src, dst : headers
253    install_subdir(
254      src,
255      install_dir : get_option('includedir') / dst,
256      install_mode : ['rw-r--r--', 'root'],
257      strip_directory : true)
258  endforeach
259
260  pkgconfig.generate(
261    libraries : mali_ldflags,
262    requires : requires,
263    version : pkg_version,
264    name : name,
265    description : 'Mali GPU User-Space Binary Driver Wrappers')
266endforeach
267
268# Install optional overlay
269if get_option('with-overlay')
270  if is_px3se
271    install_data('overlay/S10libmali_px3se',
272      install_dir : get_option('sysconfdir') / 'init.d')
273    install_data('overlay/px3seBase', install_dir : get_option('bindir'))
274  endif
275
276  if is_rk3288 and subversion == 'all'
277    install_data('overlay/S10libmali_rk3288',
278      install_dir : get_option('sysconfdir') / 'init.d')
279  endif
280endif
281
282# Install firmwares
283if gpu == 'valhall-g610'
284  install_data('firmware/g610/mali_csffw.bin', install_dir : '/lib/firmware')
285endif
286
287if vendor_package
288  # Install vendor ld config
289  custom_target(
290    'vendor ld config',
291    output : '00-' + arch + '-mali.conf',
292    command : ['echo', get_option('prefix') / wrapper_libdir],
293    capture : true,
294    install_dir : '/etc/ld.so.conf.d',
295    install : true)
296elif get_option('khr-header')
297  # Install optional KHR header
298  install_data(
299    'include/KHR/mali_khrplatform.h',
300    install_dir : get_option('includedir') / 'KHR',
301    install_mode : ['rw-r--r--', 'root'],
302    rename : 'khrplatform.h')
303endif
304
305# Install target libraries
306install_data(libs, install_dir : get_option('libdir'))
307
308# Replace dummy libmali library
309meson.add_install_script('scripts/fixup_dummy.sh',
310  get_option('libdir'), default_lib)
311
312if not wrappers
313  # Disable wrappers
314  meson.add_install_script('scripts/fixup_nowrap.sh', get_option('libdir'))
315endif
316
317if not has_x11 and not vendor_package
318  # Disable X11 in EGL header
319  meson.add_install_script('scripts/fixup_nox11.sh', get_option('includedir'))
320endif
321