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