source: mainline/uspace/lib/meson.build@ 144fafd

Last change on this file since 144fafd was 3a4c6d9, checked in by Jiri Svoboda <jiri@…>, 3 weeks ago

Packet capture (thx Nataliia Korop)

  • Property mode set to 100644
File size: 10.5 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 'fmgt',
75 'fmtutil',
76 'fs',
77 'futil',
78 'gfx',
79 'http',
80 'ipctest',
81 'label',
82 'math',
83 'minix',
84 'nettl',
85 'ofw',
86 'pcap',
87 'pcm',
88 'pcut',
89 'pixconv',
90 'posix',
91 'riff',
92 'scsi',
93 'sif',
94 'system',
95 'tbarcfg',
96 'termui',
97 'trackmod',
98 'untar',
99 'uri',
100
101 'bithenge',
102 'congfx',
103 'drv',
104 'ext4',
105 'gfxfont',
106 'gfximage',
107 'hound',
108 'ipcgfx',
109 'memgfx',
110 'nic',
111 'usb',
112 'usbdev',
113 'usbhid',
114 'usbhost',
115 'usbvirt',
116 'virtio',
117
118 'ata',
119 'ieee80211',
120 'ddev',
121 'dispcfg',
122 'display',
123 'wndmgt',
124
125 'ui',
126 'vt',
127]
128
129# Generated list of include directory paths
130include_paths = []
131
132# Generated list of test sources
133testfiles = []
134
135# Text of the install script.
136uspace_lib_devel_install_script_text = []
137
138foreach l : libs
139 # Variables that might be defined in library meson files:
140
141 # List of source files.
142 # To set it correctly, use files('list.c', 'of.c', 'files.c')
143 # Often this is the only variable that needs to be set.
144 src = files()
145
146 # Public include directories. These are used by everyone who depends
147 # on this library.
148 # Use include_directories('include_dir1', 'include_dir2') to set this.
149 # If the variable is omitted, it defaults to 'include' subdirectory
150 # if it exists, or the source directory otherwise.
151 # If the library has no headers, you can use
152 # includes += include_directories()
153 includes = []
154
155 # Private include directories.
156 # Unnecessary if you always include private headers using relative
157 # paths, but may be useful if you need to override system headers.
158 private_includes = []
159
160 # List of dependency names.
161 # E.g. to use libnic and libuntar use
162 # `deps = [ 'nic', 'untar' ]`
163 deps = []
164
165 # Extra arguments for the C compiler.
166 # Don't use for arguments involving file paths.
167 c_args = []
168
169 # Shared object version of the library.
170 version = '0.0'
171
172 # Sources of unit tests.
173 # Automatically get compiled into a test binary,
174 # but not into the library itself.
175 test_src = []
176
177 # Language of the library.
178 # Currently supported options are 'c' and 'cpp', with 'c' being default.
179 language = 'c'
180
181 # Whether the library can be dynamically linked.
182 # Eventually, all libraries will be shared by default and this will go away.
183 allow_shared = false
184
185 subdir(l)
186
187 # Add `include` or `.` subdirectory to include dirs if needed.
188 if includes.length() == 0
189 incdir = join_paths(l, 'include')
190 if run_command('[', '-d', incdir, ']').returncode() == 0
191 includes += include_directories(incdir)
192 _sdir = meson.current_source_dir() / l / 'include'
193
194 if installed_libs.contains(l)
195 uspace_lib_devel_install_script_text += 'cp -R -L -T "@0@" "${DESTDIR}include/lib@1@"'.format(_sdir, l)
196 endif
197
198 exported_devel_files += ['include', _sdir, 'lib' + l]
199 else
200 includes += include_directories(l)
201
202 if installed_libs.contains(l)
203 _sdir = meson.current_source_dir() / l
204 uspace_lib_devel_install_script_text += 'mkdir -p "${DESTDIR}include/lib@0@"'.format(l)
205 uspace_lib_devel_install_script_text += 'cp -L -t "${DESTDIR}include/lib@0@" "@1@"/*.h || true'.format(l, _sdir)
206 endif
207 endif
208 endif
209
210 # Pretty much everything depends on libc.
211 if l != 'c'
212 deps += 'c'
213 endif
214
215 if language == 'cpp' and l != 'cpp'
216 deps += 'cpp'
217 endif
218
219 mapfile = meson.current_build_dir() / 'lib' + l + '.map'
220
221 link_args = [ '-Wl,--no-undefined,--no-allow-shlib-undefined' ]
222 # We want linker to generate link map for debugging.
223 link_args += [ '-Wl,-Map,' + mapfile ]
224
225 # Convert strings to dependency objects
226 # TODO: this dependency business is way too convoluted due to issues in current Meson
227 _any_deps = []
228 _static_deps = []
229 _shared_deps = []
230 _include_deps = []
231 foreach s : deps
232 _any_deps += get_variable('lib' + s).get('any')
233 _static_deps += get_variable('lib' + s).get('static')
234 if not always_static
235 _shared_deps += get_variable('lib' + s).get('shared')
236 endif
237 _include_deps += get_variable('lib' + s).get('include')
238 endforeach
239
240 install_static_lib = CONFIG_DEVEL_FILES and installed_libs.contains(l)
241 install_shared_lib = allow_shared
242
243 _shared_dep = disabler()
244
245 if src.length() > 0
246 if not always_static
247 _libname = 'lib' + l + '.so.' + version.split('.')[0]
248
249 _shared_lib = shared_library(l, src,
250 # TODO: Include private headers using #include "quoted",
251 # and get rid of private_includes.
252 include_directories: [ private_includes, includes ],
253 dependencies: _shared_deps,
254 c_args: arch_uspace_c_args + c_args,
255 cpp_args: arch_uspace_c_args + c_args,
256 link_args: arch_uspace_c_args + arch_uspace_link_args + link_args,
257 version: version,
258 build_by_default: true,
259 )
260
261 if install_shared_lib
262 install_files += [[ 'lib', _shared_lib.full_path(), _libname ]]
263 install_deps += [ _shared_lib ]
264 exported_devel_files += [ 'sharedlib', _shared_lib, _libname ]
265 endif
266
267 if install_shared_lib and install_debug_files
268 install_files += [[ 'debug/lib', mapfile, _libname + '.map' ]]
269 endif
270
271 if disassemble
272 _disasm = custom_target('lib' + l + '.disasm',
273 command: [ objdump, '-S', '@INPUT@' ],
274 input: _shared_lib,
275 output: 'lib' + l + '.disasm',
276 capture: true,
277 build_by_default: true,
278 )
279
280 if install_shared_lib and install_debug_files
281 install_files += [[ 'debug/lib', _disasm.full_path(), _libname + '.disasm' ]]
282 install_deps += [ _disasm ]
283 endif
284 endif
285
286 _shared_dep = declare_dependency(
287 link_with: _shared_lib,
288 # TODO: Always use `include` subdirectory for public headers,
289 # and ditch the variable.
290 include_directories: includes,
291 dependencies: _shared_deps,
292 )
293 endif
294
295 _static_lib = static_library(l, src,
296 # TODO: Include private headers using #include "quoted",
297 # and get rid of private_includes.
298 include_directories: [ private_includes, includes ],
299 dependencies: _include_deps,
300 c_args: arch_uspace_c_args + c_args,
301 cpp_args: arch_uspace_c_args + c_args,
302 )
303
304 if install_static_lib
305 install_files += [[ 'lib', _static_lib.full_path(), 'lib' + l + '.a' ]]
306 install_deps += [ _static_lib ]
307 endif
308
309 exported_devel_files += ['staticlib', _static_lib, 'lib' + l + '.a']
310
311 _static_dep = declare_dependency(
312 link_with: _static_lib,
313 # TODO: Always use `include` subdirectory for public headers,
314 # and ditch the variable.
315 include_directories: includes,
316 dependencies: _static_deps,
317 )
318
319 if always_static or not allow_shared
320 _any_dep = declare_dependency(
321 link_with: _static_lib,
322 # TODO: Always use `include` subdirectory for public headers,
323 # and ditch the variable.
324 include_directories: includes,
325 dependencies: _any_deps,
326 )
327 else
328 _any_dep = declare_dependency(
329 link_with: _shared_lib,
330 # TODO: Always use `include` subdirectory for public headers,
331 # and ditch the variable.
332 include_directories: includes,
333 dependencies: _any_deps,
334 )
335 endif
336
337 _include_dep = declare_dependency(
338 # TODO: Always use `include` subdirectory for public headers,
339 # and ditch the variable.
340 include_directories: includes,
341 dependencies: _include_deps,
342 )
343 else
344 # Header-only library.
345 _any_dep = declare_dependency(
346 include_directories: includes,
347 dependencies: _any_deps,
348 )
349 _static_dep = declare_dependency(
350 include_directories: includes,
351 dependencies: _static_deps,
352 )
353 endif
354
355 if test_src.length() > 0
356 testfiles += [ {
357 'name': l,
358 'src': test_src,
359 'includes': [ private_includes, includes ],
360 } ]
361 endif
362
363 set_variable('lib' + l, {
364 'any': _any_dep,
365 'static': _static_dep,
366 'shared': _shared_dep,
367 'include': _include_dep,
368 })
369endforeach
370
371if not CONFIG_PCUT_TESTS
372 subdir_done()
373endif
374
375# Test binaries
376foreach test : testfiles
377 _testname = test['name']
378 _libname = _testname.split('-')[0]
379 _ldargs = []
380 _test_binname = 'test-lib' + _testname
381
382 if link_map
383 # We want linker to generate link map for debugging.
384 _ldargs += [ '-Wl,-Map,' + meson.current_build_dir() / _test_binname + '.map' ]
385 endif
386
387 _bin = executable(_test_binname, test.get('src'),
388 include_directories: test.get('includes'),
389 dependencies: [ get_variable('lib' + _libname).get('any'), libpcut.get('any') ],
390 link_whole: libstartfiles,
391 c_args: arch_uspace_c_args,
392 cpp_args: arch_uspace_c_args,
393 link_args: arch_uspace_c_args + arch_uspace_link_args + _ldargs,
394 build_by_default: true,
395 )
396
397 install_files += [[ 'test', _bin.full_path(), _test_binname ]]
398 install_deps += [ _bin ]
399
400 if disassemble
401 _disasm = custom_target(_test_binname + '.disasm',
402 command: [ objdump, '-S', '@INPUT@' ],
403 input: _bin,
404 output: _test_binname + '.disasm',
405 capture: true,
406 build_by_default: true,
407 )
408
409 if install_debug_files
410 install_files += [[ 'debug/test', _disasm.full_path(), _test_binname + '.disasm' ]]
411 install_deps += [ _disasm ]
412 endif
413 endif
414endforeach
Note: See TracBrowser for help on using the repository browser.