source: mainline/uspace/lib/meson.build@ 88739997

Last change on this file since 88739997 was 899bdfd, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 11 months ago

Terminal scrolling and resizing support

  • Property mode set to 100644
File size: 10.4 KB
Line 
1#
2# Copyright (c) 2019 Jiří Zárevúcky
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8#
9# - Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# - Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution.
14# - The name of the author may not be used to endorse or promote products
15# derived from this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27#
28
29always_static = not CONFIG_BUILD_SHARED_LIBS
30
31# Which libraries are installed when CONFIG_DEVEL_FILES is enabled
32installed_libs = [
33 'c',
34 'math',
35 'console',
36 'display',
37 'input',
38 'output',
39 'pixconv',
40 'posix',
41 'clui',
42 'pcm',
43 'hound',
44 'gfx',
45 'gfximage',
46 'ipcgfx',
47 'congfx',
48 'display',
49 'ui',
50]
51
52# IMPORTANT: Dependencies must be listed before libs that depend on them.
53libs = [
54 'c',
55
56 'inet',
57
58 'input',
59 'output',
60 'console',
61 'device',
62
63 'block',
64 'clipboard',
65 'clui',
66 'codepage',
67 'compress',
68 'corecfg',
69 'cpp',
70 'crypto',
71 'dltest',
72 'fbfont',
73 'fdisk',
74 'fmtutil',
75 'fs',
76 'futil',
77 'gfx',
78 'http',
79 'ipctest',
80 'label',
81 'math',
82 'minix',
83 'nettl',
84 'ofw',
85 'pcm',
86 'pcut',
87 'pixconv',
88 'posix',
89 'riff',
90 'scsi',
91 'sif',
92 'tbarcfg',
93 'termui',
94 'trackmod',
95 'untar',
96 'uri',
97
98 'bithenge',
99 'congfx',
100 'drv',
101 'ext4',
102 'gfxfont',
103 'gfximage',
104 'hound',
105 'ipcgfx',
106 'memgfx',
107 'nic',
108 'usb',
109 'usbdev',
110 'usbhid',
111 'usbhost',
112 'usbvirt',
113 'virtio',
114
115 'ata',
116 'ieee80211',
117 'ddev',
118 'dispcfg',
119 'display',
120 'wndmgt',
121
122 'ui',
123]
124
125# Generated list of include directory paths
126include_paths = []
127
128# Generated list of test sources
129testfiles = []
130
131# Text of the install script.
132uspace_lib_devel_install_script_text = []
133
134foreach l : libs
135 # Variables that might be defined in library meson files:
136
137 # List of source files.
138 # To set it correctly, use files('list.c', 'of.c', 'files.c')
139 # Often this is the only variable that needs to be set.
140 src = files()
141
142 # Public include directories. These are used by everyone who depends
143 # on this library.
144 # Use include_directories('include_dir1', 'include_dir2') to set this.
145 # If the variable is omitted, it defaults to 'include' subdirectory
146 # if it exists, or the source directory otherwise.
147 # If the library has no headers, you can use
148 # includes += include_directories()
149 includes = []
150
151 # Private include directories.
152 # Unnecessary if you always include private headers using relative
153 # paths, but may be useful if you need to override system headers.
154 private_includes = []
155
156 # List of dependency names.
157 # E.g. to use libnic and libuntar use
158 # `deps = [ 'nic', 'untar' ]`
159 deps = []
160
161 # Extra arguments for the C compiler.
162 # Don't use for arguments involving file paths.
163 c_args = []
164
165 # Shared object version of the library.
166 version = '0.0'
167
168 # Sources of unit tests.
169 # Automatically get compiled into a test binary,
170 # but not into the library itself.
171 test_src = []
172
173 # Language of the library.
174 # Currently supported options are 'c' and 'cpp', with 'c' being default.
175 language = 'c'
176
177 # Whether the library can be dynamically linked.
178 # Eventually, all libraries will be shared by default and this will go away.
179 allow_shared = false
180
181 subdir(l)
182
183 # Add `include` or `.` subdirectory to include dirs if needed.
184 if includes.length() == 0
185 incdir = join_paths(l, 'include')
186 if run_command('[', '-d', incdir, ']').returncode() == 0
187 includes += include_directories(incdir)
188 _sdir = meson.current_source_dir() / l / 'include'
189
190 if installed_libs.contains(l)
191 uspace_lib_devel_install_script_text += 'cp -R -L -T "@0@" "${DESTDIR}include/lib@1@"'.format(_sdir, l)
192 endif
193
194 exported_devel_files += ['include', _sdir, 'lib' + l]
195 else
196 includes += include_directories(l)
197
198 if installed_libs.contains(l)
199 _sdir = meson.current_source_dir() / l
200 uspace_lib_devel_install_script_text += 'mkdir -p "${DESTDIR}include/lib@0@"'.format(l)
201 uspace_lib_devel_install_script_text += 'cp -L -t "${DESTDIR}include/lib@0@" "@1@"/*.h || true'.format(l, _sdir)
202 endif
203 endif
204 endif
205
206 # Pretty much everything depends on libc.
207 if l != 'c'
208 deps += 'c'
209 endif
210
211 if language == 'cpp' and l != 'cpp'
212 deps += 'cpp'
213 endif
214
215 mapfile = meson.current_build_dir() / 'lib' + l + '.map'
216
217 link_args = [ '-Wl,--no-undefined,--no-allow-shlib-undefined' ]
218 # We want linker to generate link map for debugging.
219 link_args += [ '-Wl,-Map,' + mapfile ]
220
221 # Convert strings to dependency objects
222 # TODO: this dependency business is way too convoluted due to issues in current Meson
223 _any_deps = []
224 _static_deps = []
225 _shared_deps = []
226 _include_deps = []
227 foreach s : deps
228 _any_deps += get_variable('lib' + s).get('any')
229 _static_deps += get_variable('lib' + s).get('static')
230 if not always_static
231 _shared_deps += get_variable('lib' + s).get('shared')
232 endif
233 _include_deps += get_variable('lib' + s).get('include')
234 endforeach
235
236 install_static_lib = CONFIG_DEVEL_FILES and installed_libs.contains(l)
237 install_shared_lib = allow_shared
238
239 _shared_dep = disabler()
240
241 if src.length() > 0
242 if not always_static
243 _libname = 'lib' + l + '.so.' + version.split('.')[0]
244
245 _shared_lib = shared_library(l, src,
246 # TODO: Include private headers using #include "quoted",
247 # and get rid of private_includes.
248 include_directories: [ private_includes, includes ],
249 dependencies: _shared_deps,
250 c_args: arch_uspace_c_args + c_args,
251 cpp_args: arch_uspace_c_args + c_args,
252 link_args: arch_uspace_c_args + arch_uspace_link_args + link_args,
253 version: version,
254 build_by_default: true,
255 )
256
257 if install_shared_lib
258 install_files += [[ 'lib', _shared_lib.full_path(), _libname ]]
259 install_deps += [ _shared_lib ]
260 endif
261
262 if install_shared_lib and install_debug_files
263 install_files += [[ 'debug/lib', mapfile, _libname + '.map' ]]
264 endif
265
266 if disassemble
267 _disasm = custom_target('lib' + l + '.disasm',
268 command: [ objdump, '-S', '@INPUT@' ],
269 input: _shared_lib,
270 output: 'lib' + l + '.disasm',
271 capture: true,
272 build_by_default: true,
273 )
274
275 if install_shared_lib and install_debug_files
276 install_files += [[ 'debug/lib', _disasm.full_path(), _libname + '.disasm' ]]
277 install_deps += [ _disasm ]
278 endif
279 endif
280
281 _shared_dep = declare_dependency(
282 link_with: _shared_lib,
283 # TODO: Always use `include` subdirectory for public headers,
284 # and ditch the variable.
285 include_directories: includes,
286 dependencies: _shared_deps,
287 )
288 endif
289
290 _static_lib = static_library(l, src,
291 # TODO: Include private headers using #include "quoted",
292 # and get rid of private_includes.
293 include_directories: [ private_includes, includes ],
294 dependencies: _include_deps,
295 c_args: arch_uspace_c_args + c_args,
296 cpp_args: arch_uspace_c_args + c_args,
297 )
298
299 if install_static_lib
300 install_files += [[ 'lib', _static_lib.full_path(), 'lib' + l + '.a' ]]
301 install_deps += [ _static_lib ]
302 endif
303
304 exported_devel_files += ['staticlib', _static_lib, 'lib' + l + '.a']
305
306 _static_dep = declare_dependency(
307 link_with: _static_lib,
308 # TODO: Always use `include` subdirectory for public headers,
309 # and ditch the variable.
310 include_directories: includes,
311 dependencies: _static_deps,
312 )
313
314 if always_static or not allow_shared
315 _any_dep = declare_dependency(
316 link_with: _static_lib,
317 # TODO: Always use `include` subdirectory for public headers,
318 # and ditch the variable.
319 include_directories: includes,
320 dependencies: _any_deps,
321 )
322 else
323 _any_dep = declare_dependency(
324 link_with: _shared_lib,
325 # TODO: Always use `include` subdirectory for public headers,
326 # and ditch the variable.
327 include_directories: includes,
328 dependencies: _any_deps,
329 )
330 endif
331
332 _include_dep = declare_dependency(
333 # TODO: Always use `include` subdirectory for public headers,
334 # and ditch the variable.
335 include_directories: includes,
336 dependencies: _include_deps,
337 )
338 else
339 # Header-only library.
340 _any_dep = declare_dependency(
341 include_directories: includes,
342 dependencies: _any_deps,
343 )
344 _static_dep = declare_dependency(
345 include_directories: includes,
346 dependencies: _static_deps,
347 )
348 endif
349
350 if test_src.length() > 0
351 testfiles += [ {
352 'name': l,
353 'src': test_src,
354 'includes': [ private_includes, includes ],
355 } ]
356 endif
357
358 set_variable('lib' + l, {
359 'any': _any_dep,
360 'static': _static_dep,
361 'shared': _shared_dep,
362 'include': _include_dep,
363 })
364endforeach
365
366if not CONFIG_PCUT_TESTS
367 subdir_done()
368endif
369
370# Test binaries
371foreach test : testfiles
372 _testname = test['name']
373 _libname = _testname.split('-')[0]
374 _ldargs = []
375 _test_binname = 'test-lib' + _testname
376
377 if link_map
378 # We want linker to generate link map for debugging.
379 _ldargs += [ '-Wl,-Map,' + meson.current_build_dir() / _test_binname + '.map' ]
380 endif
381
382 _bin = executable(_test_binname, test.get('src'),
383 include_directories: test.get('includes'),
384 dependencies: [ get_variable('lib' + _libname).get('any'), libpcut.get('any') ],
385 link_whole: libstartfiles,
386 c_args: arch_uspace_c_args,
387 cpp_args: arch_uspace_c_args,
388 link_args: arch_uspace_c_args + arch_uspace_link_args + _ldargs,
389 build_by_default: true,
390 )
391
392 install_files += [[ 'test', _bin.full_path(), _test_binname ]]
393 install_deps += [ _bin ]
394
395 if disassemble
396 _disasm = custom_target(_test_binname + '.disasm',
397 command: [ objdump, '-S', '@INPUT@' ],
398 input: _bin,
399 output: _test_binname + '.disasm',
400 capture: true,
401 build_by_default: true,
402 )
403
404 if install_debug_files
405 install_files += [[ 'debug/test', _disasm.full_path(), _test_binname + '.disasm' ]]
406 install_deps += [ _disasm ]
407 endif
408 endif
409endforeach
Note: See TracBrowser for help on using the repository browser.