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