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