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

serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b4edc96 was 5fc8244, checked in by Jiri Svoboda <jiri@…>, 4 years ago

Move device-related stuff out of libc to libdevice

Unfortunately, we need to keep clock_dev, which pulls in hw_res
and pio_window. clock_dev is used by time.c

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