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