[c21d4d6] | 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 |
|
---|
[5fd05862] | 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 |
|
---|
[581a54a] | 60 | if CONFIG_BAREBONE
|
---|
| 61 | drv_list = rd_essential_drv
|
---|
| 62 | else
|
---|
| 63 | drv_list = rd_drv
|
---|
| 64 | endif
|
---|
| 65 |
|
---|
[5fd05862] | 66 | foreach drv : drvs
|
---|
| 67 | _basename = run_command(basename, drv, check: true).stdout().strip()
|
---|
| 68 | _dirname = run_command(dirname, drv, check: true).stdout().strip()
|
---|
| 69 |
|
---|
| 70 | dirs += {
|
---|
| 71 | 'subdir': 'drv' / drv,
|
---|
| 72 | 'installdir': 'drv' / _basename,
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | # Install driver metadata.
|
---|
[581a54a] | 76 | if drv_list.contains('drv' / drv)
|
---|
[5852a5a] | 77 | _src = meson.current_source_dir() / 'drv' / drv / _basename + '.ma'
|
---|
| 78 | _dstdir = 'drv' / _basename
|
---|
| 79 | install_files += [[ _dstdir, _src, _basename + '.ma' ]]
|
---|
[123cd6d] | 80 | install_deps += files(_src)
|
---|
[5fd05862] | 81 | endif
|
---|
| 82 | endforeach
|
---|
| 83 |
|
---|
| 84 | bin_targets = []
|
---|
| 85 |
|
---|
| 86 | foreach appdirs : dirs
|
---|
| 87 | src = []
|
---|
| 88 | test_src = []
|
---|
| 89 | includes = []
|
---|
| 90 | deps = []
|
---|
| 91 | c_args = []
|
---|
| 92 | link_args = []
|
---|
| 93 | language = 'c'
|
---|
[5852a5a] | 94 | installed_data = []
|
---|
[4d58bac] | 95 | platform_specific = false
|
---|
[5fd05862] | 96 |
|
---|
| 97 | subdir(appdirs.get('subdir'))
|
---|
| 98 |
|
---|
| 99 | dir = appdirs.get('subdir')
|
---|
| 100 | installdir = appdirs.get('installdir')
|
---|
| 101 |
|
---|
[581a54a] | 102 | is_drv = (dir.split('/')[0] == 'drv')
|
---|
| 103 |
|
---|
| 104 | if is_drv
|
---|
| 105 | # Drivers are installed based on rd_[essential_]drv list
|
---|
| 106 | install = drv_list.contains(dir)
|
---|
| 107 | else
|
---|
| 108 | #
|
---|
[4d58bac] | 109 | # Servers and applications are installed all (unless
|
---|
| 110 | # platform-specific) or based on rd_essential in case
|
---|
| 111 | # of barebone build or platform-specific
|
---|
[581a54a] | 112 | #
|
---|
[4d58bac] | 113 | install = (not CONFIG_BAREBONE and not platform_specific) \
|
---|
| 114 | or rd_essential.contains(dir)
|
---|
[581a54a] | 115 | endif
|
---|
[5fd05862] | 116 |
|
---|
[5852a5a] | 117 | if install
|
---|
| 118 | # Install data files, if any.
|
---|
| 119 | foreach _f : installed_data
|
---|
| 120 | _dstdir = _f.get('dir')
|
---|
| 121 | _src = meson.current_source_dir() / dir / _f.get('name')
|
---|
| 122 | install_files += [[ _dstdir, _src, _f.get('name') ]]
|
---|
[123cd6d] | 123 | install_deps += files(_src)
|
---|
[5852a5a] | 124 | endforeach
|
---|
| 125 | endif
|
---|
| 126 |
|
---|
[5fd05862] | 127 | # basename/dirname will be is useful later.
|
---|
| 128 | _basename = run_command(basename, dir, check: true).stdout().strip()
|
---|
| 129 | _dirname = run_command(dirname, dir, check: true).stdout().strip()
|
---|
| 130 |
|
---|
| 131 | # Extra linker flags
|
---|
| 132 |
|
---|
[4b42382] | 133 | # TODO: only strip after disassembly
|
---|
[5fd05862] | 134 | if CONFIG_STRIP_BINARIES
|
---|
| 135 | link_args += [ '-s' ]
|
---|
| 136 | endif
|
---|
| 137 |
|
---|
| 138 | # Init binaries need to always be linked statically.
|
---|
[63660a3] | 139 | static_build = (not CONFIG_USE_SHARED_LIBS) or rd_init.contains(dir)
|
---|
[5fd05862] | 140 |
|
---|
| 141 | # Add the corresponding standard libraries to dependencies.
|
---|
| 142 |
|
---|
| 143 | deps += [ 'c' ]
|
---|
| 144 |
|
---|
| 145 | if language == 'cpp'
|
---|
| 146 | deps += 'cpp'
|
---|
| 147 | endif
|
---|
| 148 |
|
---|
| 149 | # Binaries in the 'drv' subdirectory link libdrv by default.
|
---|
| 150 |
|
---|
| 151 |
|
---|
| 152 | if is_drv
|
---|
| 153 | deps += [ 'drv' ]
|
---|
| 154 | endif
|
---|
| 155 |
|
---|
| 156 | # Convert strings to dependency objects
|
---|
| 157 |
|
---|
| 158 | _deps = []
|
---|
| 159 | foreach s : deps
|
---|
| 160 | _deps += get_variable('lib' + s).get(static_build ? 'static' : 'any')
|
---|
| 161 | endforeach
|
---|
| 162 |
|
---|
| 163 | # Build executable
|
---|
| 164 |
|
---|
| 165 | if src.length() > 0
|
---|
| 166 | bin_targets += {
|
---|
| 167 | 'src': src,
|
---|
| 168 | 'dirname': _dirname,
|
---|
| 169 | 'basename': _basename,
|
---|
| 170 | 'install': install,
|
---|
| 171 | 'install_dir': installdir,
|
---|
| 172 | 'includes': includes,
|
---|
| 173 | 'dependencies': _deps,
|
---|
| 174 | 'c_args': c_args,
|
---|
| 175 | 'link_args': link_args + (static_build ? [ '-static' ] : []),
|
---|
[28fcaee] | 176 | 'init': rd_init.contains(dir),
|
---|
[5fd05862] | 177 | }
|
---|
| 178 | endif
|
---|
| 179 |
|
---|
| 180 | # Build test executable, if any
|
---|
| 181 |
|
---|
| 182 | if test_src.length() > 0
|
---|
| 183 | bin_targets += {
|
---|
| 184 | 'src': test_src,
|
---|
| 185 | 'dirname': _dirname,
|
---|
| 186 | 'basename': 'test-' + installdir.underscorify() + (is_drv ? '' : ('_' + _basename)),
|
---|
| 187 | 'install': install and CONFIG_PCUT_TESTS,
|
---|
| 188 | 'install_dir': 'test',
|
---|
| 189 | 'includes': includes,
|
---|
| 190 | 'dependencies': [ _deps, libpcut.get('any') ],
|
---|
| 191 | 'c_args': c_args,
|
---|
| 192 | 'link_args': link_args,
|
---|
[28fcaee] | 193 | 'init': false,
|
---|
[5fd05862] | 194 | }
|
---|
| 195 | endif
|
---|
| 196 | endforeach
|
---|
| 197 |
|
---|
| 198 | foreach tst : bin_targets
|
---|
| 199 | _ldargs = tst.get('link_args')
|
---|
| 200 | _src = tst.get('src')
|
---|
| 201 |
|
---|
| 202 | _install = tst.get('install')
|
---|
[a8ccc7e] | 203 | _install_dir = tst.get('install_dir')
|
---|
| 204 | _basename = tst.get('basename')
|
---|
| 205 | _full_install_path = _install_dir / _basename
|
---|
| 206 | _build_name = _full_install_path.underscorify()
|
---|
| 207 | _full_build_name = meson.current_build_dir() / _build_name
|
---|
[28fcaee] | 208 | _is_init = tst.get('init')
|
---|
[5fd05862] | 209 |
|
---|
| 210 | if link_map
|
---|
| 211 | # We want linker to generate link map for debugging.
|
---|
[a8ccc7e] | 212 | _ldargs += [ '-Wl,-Map,' + _full_build_name + '.map' ]
|
---|
[5fd05862] | 213 | endif
|
---|
| 214 |
|
---|
[a8ccc7e] | 215 | _bin = executable(_build_name, _src,
|
---|
[5fd05862] | 216 | include_directories: tst.get('includes'),
|
---|
| 217 | dependencies: tst.get('dependencies'),
|
---|
[71069a9] | 218 | link_whole: libstartfiles,
|
---|
[63660a3] | 219 | c_args: arch_uspace_c_args + tst.get('c_args'),
|
---|
| 220 | cpp_args: arch_uspace_c_args + tst.get('c_args'),
|
---|
| 221 | link_args: arch_uspace_c_args + arch_uspace_link_args + _ldargs,
|
---|
[cd981f2a] | 222 | implicit_include_directories: true,
|
---|
[5fd05862] | 223 | build_by_default: true,
|
---|
| 224 | )
|
---|
| 225 |
|
---|
[28fcaee] | 226 | if _is_init
|
---|
| 227 | rd_init_binaries += [[ _bin, _full_install_path ]]
|
---|
| 228 | endif
|
---|
| 229 |
|
---|
[5fd05862] | 230 | if disassemble
|
---|
[5852a5a] | 231 | _disasm = custom_target(_build_name + '.disasm',
|
---|
[5fd05862] | 232 | command: [ objdump, '-S', '@INPUT@' ],
|
---|
| 233 | input: _bin,
|
---|
[a8ccc7e] | 234 | output: _build_name + '.disasm',
|
---|
[5fd05862] | 235 | capture: true,
|
---|
| 236 | build_by_default: true,
|
---|
| 237 | )
|
---|
| 238 | endif
|
---|
[5852a5a] | 239 |
|
---|
| 240 | if _install
|
---|
| 241 | # Due to certain quirks of our build, executables need to be built with a different name than what they are installed with.
|
---|
| 242 | # Meson doesn't support renaming installed files (at least not as of mid-2019) so we do it manually.
|
---|
| 243 |
|
---|
| 244 | install_files += [[ _install_dir, _full_build_name, _basename ]]
|
---|
| 245 | install_deps += [ _bin ]
|
---|
| 246 |
|
---|
| 247 | if install_debug_files
|
---|
| 248 | if disassemble
|
---|
| 249 | install_files += [[ 'debug' / _install_dir, _full_build_name + '.disasm', _basename + '.disasm' ]]
|
---|
| 250 | install_deps += [ _disasm ]
|
---|
| 251 | endif
|
---|
| 252 | if link_map
|
---|
| 253 | install_files += [[ 'debug' / _install_dir, _full_build_name + '.map', _basename + '.map' ]]
|
---|
| 254 | endif
|
---|
| 255 | endif
|
---|
| 256 | endif
|
---|
[5fd05862] | 257 | endforeach
|
---|