source: mainline/uspace/meson.build

Last change on this file was 4d58bac, checked in by Jiri Svoboda <jiri@…>, 22 months ago

Library and utility for printing OpenFirmware device tree

  • Property mode set to 100644
File size: 7.0 KB
Line 
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
30link_map = true
31disassemble = CONFIG_LINE_DEBUG
32install_nonessential_data = not CONFIG_BAREBONE
33# TODO: Allow installing debug files.
34# This is currently disabled due to boot image size restrictions.
35install_debug_files = false
36
37subdir('lib')
38subdir('app')
39subdir('srv')
40subdir('drv')
41
42dirs = []
43
44foreach app : apps
45 dirs += {
46 'subdir': join_paths('app', app),
47 'installdir': 'app',
48 }
49endforeach
50
51foreach 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 }
58endforeach
59
60if CONFIG_BAREBONE
61 drv_list = rd_essential_drv
62else
63 drv_list = rd_drv
64endif
65
66foreach 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
82endforeach
83
84bin_targets = []
85
86foreach appdirs : dirs
87 src = []
88 test_src = []
89 includes = []
90 deps = []
91 c_args = []
92 link_args = []
93 language = 'c'
94 installed_data = []
95 platform_specific = false
96
97 subdir(appdirs.get('subdir'))
98
99 dir = appdirs.get('subdir')
100 installdir = appdirs.get('installdir')
101
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 #
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
112 #
113 install = (not CONFIG_BAREBONE and not platform_specific) \
114 or rd_essential.contains(dir)
115 endif
116
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') ]]
123 install_deps += files(_src)
124 endforeach
125 endif
126
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
133 # TODO: only strip after disassembly
134 if CONFIG_STRIP_BINARIES
135 link_args += [ '-s' ]
136 endif
137
138 # Init binaries need to always be linked statically.
139 static_build = (not CONFIG_USE_SHARED_LIBS) or rd_init.contains(dir)
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' ] : []),
176 'init': rd_init.contains(dir),
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,
193 'init': false,
194 }
195 endif
196endforeach
197
198foreach tst : bin_targets
199 _ldargs = tst.get('link_args')
200 _src = tst.get('src')
201
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')
209
210 if link_map
211 # We want linker to generate link map for debugging.
212 _ldargs += [ '-Wl,-Map,' + _full_build_name + '.map' ]
213 endif
214
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,
224 )
225
226 if _is_init
227 rd_init_binaries += [[ _bin, _full_install_path ]]
228 endif
229
230 if disassemble
231 _disasm = custom_target(_build_name + '.disasm',
232 command: [ objdump, '-S', '@INPUT@' ],
233 input: _bin,
234 output: _build_name + '.disasm',
235 capture: true,
236 build_by_default: true,
237 )
238 endif
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
257endforeach
Note: See TracBrowser for help on using the repository browser.