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