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