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