source: mainline/uspace/lib/meson.build@ 34aad53d

Last change on this file since 34aad53d was 34aad53d, checked in by Nataliia Korop <n.corop08@…>, 18 months ago

merge master to topic/packet-capture

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