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