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