| 1 | #
|
|---|
| 2 | # Copyright (c) 2005 Martin Decky
|
|---|
| 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 | # FIXME: somehow disabling link map makes tools/mkext4.py crash
|
|---|
| 30 | link_map = true
|
|---|
| 31 | disassemble = CONFIG_LINE_DEBUG
|
|---|
| 32 | install_nonessential_data = not CONFIG_BAREBONE
|
|---|
| 33 | # TODO: Allow installing debug files.
|
|---|
| 34 | # This is currently disabled due to boot image size restrictions.
|
|---|
| 35 | install_debug_files = false
|
|---|
| 36 |
|
|---|
| 37 | subdir('lib')
|
|---|
| 38 | subdir('app')
|
|---|
| 39 | subdir('srv')
|
|---|
| 40 | subdir('drv')
|
|---|
| 41 |
|
|---|
| 42 | dirs = []
|
|---|
| 43 |
|
|---|
| 44 | foreach app : apps
|
|---|
| 45 | dirs += {
|
|---|
| 46 | 'subdir': join_paths('app', app),
|
|---|
| 47 | 'installdir': 'app',
|
|---|
| 48 | }
|
|---|
| 49 | endforeach
|
|---|
| 50 |
|
|---|
| 51 | foreach srv : srvs
|
|---|
| 52 | _dirname = run_command(dirname, srv, check: true).stdout().strip()
|
|---|
| 53 |
|
|---|
| 54 | dirs += {
|
|---|
| 55 | 'subdir': join_paths('srv', srv),
|
|---|
| 56 | 'installdir': _dirname == '.' ? 'srv' : ('srv' / _dirname),
|
|---|
| 57 | }
|
|---|
| 58 | endforeach
|
|---|
| 59 |
|
|---|
| 60 | foreach drv : drvs
|
|---|
| 61 | _basename = run_command(basename, drv, check: true).stdout().strip()
|
|---|
| 62 | _dirname = run_command(dirname, drv, check: true).stdout().strip()
|
|---|
| 63 |
|
|---|
| 64 | dirs += {
|
|---|
| 65 | 'subdir': 'drv' / drv,
|
|---|
| 66 | 'installdir': 'drv' / _basename,
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | # Install driver metadata.
|
|---|
| 70 | if not CONFIG_BAREBONE or rd_essential.contains('drv' / drv)
|
|---|
| 71 | _src = meson.current_source_dir() / 'drv' / drv / _basename + '.ma'
|
|---|
| 72 | _dstdir = 'drv' / _basename
|
|---|
| 73 | install_files += [[ _dstdir, _src, _basename + '.ma' ]]
|
|---|
| 74 | install_deps += files(_src)
|
|---|
| 75 | endif
|
|---|
| 76 | endforeach
|
|---|
| 77 |
|
|---|
| 78 | bin_targets = []
|
|---|
| 79 |
|
|---|
| 80 | foreach appdirs : dirs
|
|---|
| 81 | src = []
|
|---|
| 82 | test_src = []
|
|---|
| 83 | includes = []
|
|---|
| 84 | deps = []
|
|---|
| 85 | c_args = []
|
|---|
| 86 | link_args = []
|
|---|
| 87 | language = 'c'
|
|---|
| 88 | installed_data = []
|
|---|
| 89 |
|
|---|
| 90 | subdir(appdirs.get('subdir'))
|
|---|
| 91 |
|
|---|
| 92 | dir = appdirs.get('subdir')
|
|---|
| 93 | installdir = appdirs.get('installdir')
|
|---|
| 94 |
|
|---|
| 95 | install = not CONFIG_BAREBONE or rd_essential.contains(dir)
|
|---|
| 96 |
|
|---|
| 97 | if install
|
|---|
| 98 | # Install data files, if any.
|
|---|
| 99 | foreach _f : installed_data
|
|---|
| 100 | _dstdir = _f.get('dir')
|
|---|
| 101 | _src = meson.current_source_dir() / dir / _f.get('name')
|
|---|
| 102 | install_files += [[ _dstdir, _src, _f.get('name') ]]
|
|---|
| 103 | install_deps += files(_src)
|
|---|
| 104 | endforeach
|
|---|
| 105 | endif
|
|---|
| 106 |
|
|---|
| 107 | # basename/dirname will be is useful later.
|
|---|
| 108 | _basename = run_command(basename, dir, check: true).stdout().strip()
|
|---|
| 109 | _dirname = run_command(dirname, dir, check: true).stdout().strip()
|
|---|
| 110 |
|
|---|
| 111 | # Extra linker flags
|
|---|
| 112 |
|
|---|
| 113 | # TODO: only strip after disassembly
|
|---|
| 114 | if CONFIG_STRIP_BINARIES
|
|---|
| 115 | link_args += [ '-s' ]
|
|---|
| 116 | endif
|
|---|
| 117 |
|
|---|
| 118 | # Init binaries need to always be linked statically.
|
|---|
| 119 | static_build = (not CONFIG_USE_SHARED_LIBS) or rd_init.contains(dir)
|
|---|
| 120 |
|
|---|
| 121 | # Add the corresponding standard libraries to dependencies.
|
|---|
| 122 |
|
|---|
| 123 | deps += [ 'c' ]
|
|---|
| 124 |
|
|---|
| 125 | if language == 'cpp'
|
|---|
| 126 | deps += 'cpp'
|
|---|
| 127 | endif
|
|---|
| 128 |
|
|---|
| 129 | # Binaries in the 'drv' subdirectory link libdrv by default.
|
|---|
| 130 |
|
|---|
| 131 | is_drv = (dir.split('/')[0] == 'drv')
|
|---|
| 132 |
|
|---|
| 133 | if is_drv
|
|---|
| 134 | deps += [ 'drv' ]
|
|---|
| 135 | endif
|
|---|
| 136 |
|
|---|
| 137 | # Convert strings to dependency objects
|
|---|
| 138 |
|
|---|
| 139 | _deps = []
|
|---|
| 140 | foreach s : deps
|
|---|
| 141 | _deps += get_variable('lib' + s).get(static_build ? 'static' : 'any')
|
|---|
| 142 | endforeach
|
|---|
| 143 |
|
|---|
| 144 | # Build executable
|
|---|
| 145 |
|
|---|
| 146 | if src.length() > 0
|
|---|
| 147 | bin_targets += {
|
|---|
| 148 | 'src': src,
|
|---|
| 149 | 'dirname': _dirname,
|
|---|
| 150 | 'basename': _basename,
|
|---|
| 151 | 'install': install,
|
|---|
| 152 | 'install_dir': installdir,
|
|---|
| 153 | 'includes': includes,
|
|---|
| 154 | 'dependencies': _deps,
|
|---|
| 155 | 'c_args': c_args,
|
|---|
| 156 | 'link_args': link_args + (static_build ? [ '-static' ] : []),
|
|---|
| 157 | 'init': rd_init.contains(dir),
|
|---|
| 158 | }
|
|---|
| 159 | endif
|
|---|
| 160 |
|
|---|
| 161 | # Build test executable, if any
|
|---|
| 162 |
|
|---|
| 163 | if test_src.length() > 0
|
|---|
| 164 | bin_targets += {
|
|---|
| 165 | 'src': test_src,
|
|---|
| 166 | 'dirname': _dirname,
|
|---|
| 167 | 'basename': 'test-' + installdir.underscorify() + (is_drv ? '' : ('_' + _basename)),
|
|---|
| 168 | 'install': install and CONFIG_PCUT_TESTS,
|
|---|
| 169 | 'install_dir': 'test',
|
|---|
| 170 | 'includes': includes,
|
|---|
| 171 | 'dependencies': [ _deps, libpcut.get('any') ],
|
|---|
| 172 | 'c_args': c_args,
|
|---|
| 173 | 'link_args': link_args,
|
|---|
| 174 | 'init': false,
|
|---|
| 175 | }
|
|---|
| 176 | endif
|
|---|
| 177 | endforeach
|
|---|
| 178 |
|
|---|
| 179 | foreach tst : bin_targets
|
|---|
| 180 | _ldargs = tst.get('link_args')
|
|---|
| 181 | _src = tst.get('src')
|
|---|
| 182 |
|
|---|
| 183 | _install = tst.get('install')
|
|---|
| 184 | _install_dir = tst.get('install_dir')
|
|---|
| 185 | _basename = tst.get('basename')
|
|---|
| 186 | _full_install_path = _install_dir / _basename
|
|---|
| 187 | _build_name = _full_install_path.underscorify()
|
|---|
| 188 | _full_build_name = meson.current_build_dir() / _build_name
|
|---|
| 189 | _is_init = tst.get('init')
|
|---|
| 190 |
|
|---|
| 191 | if link_map
|
|---|
| 192 | # We want linker to generate link map for debugging.
|
|---|
| 193 | _ldargs += [ '-Wl,-Map,' + _full_build_name + '.map' ]
|
|---|
| 194 | endif
|
|---|
| 195 |
|
|---|
| 196 | _bin = executable(_build_name, _src,
|
|---|
| 197 | include_directories: tst.get('includes'),
|
|---|
| 198 | dependencies: tst.get('dependencies'),
|
|---|
| 199 | link_whole: libstartfiles,
|
|---|
| 200 | c_args: arch_uspace_c_args + tst.get('c_args'),
|
|---|
| 201 | cpp_args: arch_uspace_c_args + tst.get('c_args'),
|
|---|
| 202 | link_args: arch_uspace_c_args + arch_uspace_link_args + _ldargs,
|
|---|
| 203 | implicit_include_directories: true,
|
|---|
| 204 | build_by_default: true,
|
|---|
| 205 | )
|
|---|
| 206 |
|
|---|
| 207 | if _is_init
|
|---|
| 208 | rd_init_binaries += [[ _bin, _full_install_path ]]
|
|---|
| 209 | endif
|
|---|
| 210 |
|
|---|
| 211 | if disassemble
|
|---|
| 212 | _disasm = custom_target(_build_name + '.disasm',
|
|---|
| 213 | command: [ objdump, '-S', '@INPUT@' ],
|
|---|
| 214 | input: _bin,
|
|---|
| 215 | output: _build_name + '.disasm',
|
|---|
| 216 | capture: true,
|
|---|
| 217 | build_by_default: true,
|
|---|
| 218 | )
|
|---|
| 219 | endif
|
|---|
| 220 |
|
|---|
| 221 | if _install
|
|---|
| 222 | # Due to certain quirks of our build, executables need to be built with a different name than what they are installed with.
|
|---|
| 223 | # Meson doesn't support renaming installed files (at least not as of mid-2019) so we do it manually.
|
|---|
| 224 |
|
|---|
| 225 | install_files += [[ _install_dir, _full_build_name, _basename ]]
|
|---|
| 226 | install_deps += [ _bin ]
|
|---|
| 227 |
|
|---|
| 228 | if install_debug_files
|
|---|
| 229 | if disassemble
|
|---|
| 230 | install_files += [[ 'debug' / _install_dir, _full_build_name + '.disasm', _basename + '.disasm' ]]
|
|---|
| 231 | install_deps += [ _disasm ]
|
|---|
| 232 | endif
|
|---|
| 233 | if link_map
|
|---|
| 234 | install_files += [[ 'debug' / _install_dir, _full_build_name + '.map', _basename + '.map' ]]
|
|---|
| 235 | endif
|
|---|
| 236 | endif
|
|---|
| 237 | endif
|
|---|
| 238 | endforeach
|
|---|