2 # Copyright (c) 2005 Martin Decky
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
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.
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.
29 # FIXME: somehow disabling link map makes tools/mkext4.py crash
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
46 'subdir': join_paths('app', app),
52 _dirname = run_command(dirname, srv, check: true).stdout().strip()
55 'subdir': join_paths('srv', srv),
56 'installdir': _dirname == '.' ? 'srv' : ('srv' / _dirname),
61 drv_list = rd_essential_drv
67 _basename = run_command(basename, drv, check: true).stdout().strip()
68 _dirname = run_command(dirname, drv, check: true).stdout().strip()
71 'subdir': 'drv' / drv,
72 'installdir': 'drv' / _basename,
75 # Install driver metadata.
76 if drv_list.contains('drv' / drv)
77 _src = meson.current_source_dir() / 'drv' / drv / _basename + '.ma'
78 _dstdir = 'drv' / _basename
79 install_files += [[ _dstdir, _src, _basename + '.ma' ]]
80 install_deps += files(_src)
86 foreach appdirs : dirs
95 platform_specific = false
97 subdir(appdirs.get('subdir'))
99 dir = appdirs.get('subdir')
100 installdir = appdirs.get('installdir')
102 is_drv = (dir.split('/')[0] == 'drv')
105 # Drivers are installed based on rd_[essential_]drv list
106 install = drv_list.contains(dir)
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
113 install = (not CONFIG_BAREBONE and not platform_specific) \
114 or rd_essential.contains(dir)
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') ]]
123 install_deps += files(_src)
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()
133 # TODO: only strip after disassembly
134 if CONFIG_STRIP_BINARIES
135 link_args += [ '-s' ]
138 # Init binaries need to always be linked statically.
139 static_build = (not CONFIG_USE_SHARED_LIBS) or rd_init.contains(dir)
141 # Add the corresponding standard libraries to dependencies.
149 # Binaries in the 'drv' subdirectory link libdrv by default.
156 # Convert strings to dependency objects
160 _deps += get_variable('lib' + s).get(static_build ? 'static' : 'any')
169 'basename': _basename,
171 'install_dir': installdir,
172 'includes': includes,
173 'dependencies': _deps,
175 'link_args': link_args + (static_build ? [ '-static' ] : []),
176 'init': rd_init.contains(dir),
180 # Build test executable, if any
182 if test_src.length() > 0
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') ],
192 'link_args': link_args,
198 foreach tst : bin_targets
199 _ldargs = tst.get('link_args')
200 _src = tst.get('src')
202 _install = tst.get('install')
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
208 _is_init = tst.get('init')
211 # We want linker to generate link map for debugging.
212 _ldargs += [ '-Wl,-Map,' + _full_build_name + '.map' ]
215 _bin = executable(_build_name, _src,
216 include_directories: tst.get('includes'),
217 dependencies: tst.get('dependencies'),
218 link_whole: libstartfiles,
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,
222 implicit_include_directories: true,
223 build_by_default: true,
227 rd_init_binaries += [[ _bin, _full_install_path ]]
231 _disasm = custom_target(_build_name + '.disasm',
232 command: [ objdump, '-S', '@INPUT@' ],
234 output: _build_name + '.disasm',
236 build_by_default: true,
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.
244 install_files += [[ _install_dir, _full_build_name, _basename ]]
245 install_deps += [ _bin ]
247 if install_debug_files
249 install_files += [[ 'debug' / _install_dir, _full_build_name + '.disasm', _basename + '.disasm' ]]
250 install_deps += [ _disasm ]
253 install_files += [[ 'debug' / _install_dir, _full_build_name + '.map', _basename + '.map' ]]