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