source: mainline/uspace/lib/meson.build@ 9739b5a

Last change on this file since 9739b5a was 2791fbb7, checked in by Jiri Svoboda <jiri@…>, 15 months ago

Move generic ATA code out to libata

  • 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 'gfx',
77 'http',
78 'ipctest',
79 'label',
80 'math',
81 'minix',
82 'nettl',
83 'ofw',
84 'pcm',
85 'pcut',
86 'pixconv',
87 'posix',
88 'riff',
89 'scsi',
90 'sif',
91 'tbarcfg',
92 'trackmod',
93 'untar',
94 'uri',
95
96 'bithenge',
97 'congfx',
98 'drv',
99 'ext4',
100 'gfxfont',
101 'gfximage',
102 'hound',
103 'ipcgfx',
104 'memgfx',
105 'nic',
106 'usb',
107 'usbdev',
108 'usbhid',
109 'usbhost',
110 'usbvirt',
111 'virtio',
112
113 'ata',
114 'ieee80211',
115 'ddev',
116 'dispcfg',
117 'display',
118 'wndmgt',
119
120 'ui',
121]
122
123# Generated list of include directory paths
124include_paths = []
125
126# Generated list of test sources
127testfiles = []
128
129# Text of the install script.
130uspace_lib_devel_install_script_text = []
131
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)
186 _sdir = meson.current_source_dir() / l / 'include'
187
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)
190 endif
191
192 exported_devel_files += ['include', _sdir, 'lib' + l]
193 else
194 includes += include_directories(l)
195
196 if installed_libs.contains(l)
197 _sdir = meson.current_source_dir() / l
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)
200 endif
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
241 _libname = 'lib' + l + '.so.' + version.split('.')[0]
242
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,
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,
251 version: version,
252 build_by_default: true,
253 )
254
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
264 if disassemble
265 _disasm = custom_target('lib' + l + '.disasm',
266 command: [ objdump, '-S', '@INPUT@' ],
267 input: _shared_lib,
268 output: 'lib' + l + '.disasm',
269 capture: true,
270 build_by_default: true,
271 )
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
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,
293 c_args: arch_uspace_c_args + c_args,
294 cpp_args: arch_uspace_c_args + c_args,
295 )
296
297 if install_static_lib
298 install_files += [[ 'lib', _static_lib.full_path(), 'lib' + l + '.a' ]]
299 install_deps += [ _static_lib ]
300 endif
301
302 exported_devel_files += ['staticlib', _static_lib, 'lib' + l + '.a']
303
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') ],
383 link_whole: libstartfiles,
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,
387 build_by_default: true,
388 )
389
390 install_files += [[ 'test', _bin.full_path(), _test_binname ]]
391 install_deps += [ _bin ]
392
393 if disassemble
394 _disasm = custom_target(_test_binname + '.disasm',
395 command: [ objdump, '-S', '@INPUT@' ],
396 input: _bin,
397 output: _test_binname + '.disasm',
398 capture: true,
399 build_by_default: true,
400 )
401
402 if install_debug_files
403 install_files += [[ 'debug/test', _disasm.full_path(), _test_binname + '.disasm' ]]
404 install_deps += [ _disasm ]
405 endif
406 endif
407endforeach
Note: See TracBrowser for help on using the repository browser.