source: mainline/uspace/lib/meson.build@ 9e84d2c

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

Move TCP/IP library support out of libc to separate library

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