1 | # TODO: Use vcs_tag() to generate version string
|
---|
2 | # TODO: jobfile
|
---|
3 | # TODO: lto
|
---|
4 | # TODO: -D__$(ENDIANESS)__ in cross
|
---|
5 | # TODO: CONFIG_BUILD_SHARED_LIBS
|
---|
6 | # TODO: fix clang build
|
---|
7 |
|
---|
8 | project(
|
---|
9 | 'HelenOS',
|
---|
10 | [ 'c', 'cpp' ],
|
---|
11 | default_options : ['buildtype=plain', 'c_std=gnu11', 'cpp_std=c++17', 'warning_level=3', 'werror=false', 'b_staticpic=false', 'default_library=shared', 'prefix=/' ],
|
---|
12 | )
|
---|
13 |
|
---|
14 | cc = meson.get_compiler('c')
|
---|
15 | basename = find_program('basename')
|
---|
16 | dirname = find_program('dirname')
|
---|
17 | find = find_program('find')
|
---|
18 | grep = find_program('grep')
|
---|
19 | mkarray = find_program('tools/mkarray_for_meson.sh')
|
---|
20 | objdump = find_program('objdump')
|
---|
21 | sed = find_program('sed')
|
---|
22 | unzip = find_program('unzip')
|
---|
23 | which = find_program('which')
|
---|
24 |
|
---|
25 | autocheck = generator(find_program('tools/autocheck.awk'),
|
---|
26 | arguments: [ '@INPUT@' ],
|
---|
27 | output: '@PLAINNAME@.check.c',
|
---|
28 | capture: true,
|
---|
29 | )
|
---|
30 |
|
---|
31 |
|
---|
32 | if get_option('default_library') == 'both'
|
---|
33 | error('You must use either shared or static for default_library.')
|
---|
34 | endif
|
---|
35 |
|
---|
36 | debug_options = false
|
---|
37 |
|
---|
38 | # Output compiler flags for use by third-party builds.
|
---|
39 | # NOTE: See $srcroot/meson/cross/$arch for architecture-specific compiler flags.
|
---|
40 |
|
---|
41 | if debug_options
|
---|
42 | message('Cross c_args:')
|
---|
43 | message(meson.get_cross_property('c_args'))
|
---|
44 | message('Cross cpp_args:')
|
---|
45 | message(meson.get_cross_property('cpp_args'))
|
---|
46 | message('Cross c_link_args:')
|
---|
47 | message(meson.get_cross_property('c_link_args'))
|
---|
48 | message('Cross cpp_link_args:')
|
---|
49 | message(meson.get_cross_property('cpp_link_args'))
|
---|
50 | endif
|
---|
51 |
|
---|
52 | # Read some variables from Makefile.common
|
---|
53 | config_variables = [
|
---|
54 | # Uspace and kernel
|
---|
55 | 'CONFIG_BAREBONE',
|
---|
56 | 'CONFIG_BUILD_SHARED_LIBS',
|
---|
57 | 'CONFIG_DEBUG',
|
---|
58 | 'CONFIG_DEVEL_FILES',
|
---|
59 | 'CONFIG_FPU',
|
---|
60 | 'CONFIG_LINE_DEBUG',
|
---|
61 | 'CONFIG_PCUT_SELF_TESTS',
|
---|
62 | 'CONFIG_PCUT_TESTS',
|
---|
63 | 'CONFIG_RTLD',
|
---|
64 | 'CONFIG_STRIP_BINARIES',
|
---|
65 | 'CONFIG_UBSAN',
|
---|
66 | 'CONFIG_USE_SHARED_LIBS',
|
---|
67 | 'OPTIMIZATION',
|
---|
68 | 'PROCESSOR',
|
---|
69 | 'RDFMT',
|
---|
70 |
|
---|
71 | # Kernel only
|
---|
72 | 'CONFIG_ACPI',
|
---|
73 | 'CONFIG_AM335X_TIMERS',
|
---|
74 | 'CONFIG_ASID',
|
---|
75 | 'CONFIG_ASID_FIFO',
|
---|
76 | 'CONFIG_AT_KBD',
|
---|
77 | 'CONFIG_BCM2835_MAILBOX',
|
---|
78 | 'CONFIG_DSRLNIN',
|
---|
79 | 'CONFIG_DSRLNOUT',
|
---|
80 | 'CONFIG_EGA',
|
---|
81 | 'CONFIG_FB',
|
---|
82 | 'CONFIG_GICV2',
|
---|
83 | 'CONFIG_I8042',
|
---|
84 | 'CONFIG_I8259',
|
---|
85 | 'CONFIG_IOMAP_BITMAP',
|
---|
86 | 'CONFIG_IOMAP_DUMMY',
|
---|
87 | 'CONFIG_KCONSOLE',
|
---|
88 | 'CONFIG_MAC_KBD',
|
---|
89 | 'CONFIG_MULTIBOOT',
|
---|
90 | 'CONFIG_NS16550',
|
---|
91 | 'CONFIG_OFW_PCI',
|
---|
92 | 'CONFIG_OFW_TREE',
|
---|
93 | 'CONFIG_OMAP_UART',
|
---|
94 | 'CONFIG_PAGE_HT',
|
---|
95 | 'CONFIG_PAGE_PT',
|
---|
96 | 'CONFIG_PC_KBD',
|
---|
97 | 'CONFIG_PL011_UART',
|
---|
98 | 'CONFIG_PL050',
|
---|
99 | 'CONFIG_S3C24XX_IRQC',
|
---|
100 | 'CONFIG_S3C24XX_UART',
|
---|
101 | 'CONFIG_SMP',
|
---|
102 | 'CONFIG_SOFTINT',
|
---|
103 | 'CONFIG_SRLN',
|
---|
104 | 'CONFIG_SUN_KBD',
|
---|
105 | 'CONFIG_SYMTAB',
|
---|
106 | 'CONFIG_TEST',
|
---|
107 | 'CONFIG_TRACE',
|
---|
108 | 'CONFIG_UDEBUG',
|
---|
109 | 'CONFIG_VIA_CUDA',
|
---|
110 | 'MACHINE',
|
---|
111 | 'MEMORY_MODEL',
|
---|
112 | ]
|
---|
113 |
|
---|
114 | foreach varname : config_variables
|
---|
115 | result = run_command(grep, '^' + varname + '\\b', meson.source_root() / 'Makefile.config')
|
---|
116 | if result.returncode() != 0
|
---|
117 | # TODO: Output negative/inapplicable variables too in config, so that we can check for typos here.
|
---|
118 | #warning('Missing configuration variable ' + varname + ' in Makefile.config')
|
---|
119 | set_variable(varname, false)
|
---|
120 | continue
|
---|
121 | endif
|
---|
122 |
|
---|
123 | value = result.stdout().split('\n')[0].strip().split('=')[1].strip()
|
---|
124 | if value == 'y'
|
---|
125 | value = true
|
---|
126 | elif value == 'n'
|
---|
127 | value = false
|
---|
128 | endif
|
---|
129 |
|
---|
130 | set_variable(varname, value)
|
---|
131 | if debug_options
|
---|
132 | message([ varname, value ])
|
---|
133 | endif
|
---|
134 | endforeach
|
---|
135 |
|
---|
136 | # Also read version information.
|
---|
137 | version_variables = [
|
---|
138 | 'COPYRIGHT',
|
---|
139 | 'NAME',
|
---|
140 | 'PATCHLEVEL',
|
---|
141 | 'SUBLEVEL',
|
---|
142 | 'VERSION',
|
---|
143 | ]
|
---|
144 |
|
---|
145 | foreach varname : version_variables
|
---|
146 | line = run_command(grep, '^' + varname + '\\b', meson.source_root() / 'version', check: true).stdout().strip()
|
---|
147 | value = line.split('=')[1].strip()
|
---|
148 | set_variable('HELENOS_' + varname, value)
|
---|
149 | if debug_options
|
---|
150 | message([ 'HELENOS_' + varname, value ])
|
---|
151 | endif
|
---|
152 | endforeach
|
---|
153 |
|
---|
154 | HELENOS_RELEASE = HELENOS_VERSION + '.' + HELENOS_PATCHLEVEL + '.' + HELENOS_SUBLEVEL
|
---|
155 |
|
---|
156 | h_arch = meson.get_cross_property('h_arch')
|
---|
157 |
|
---|
158 | meson.add_install_script('install.sh', CONFIG_DEVEL_FILES.to_string())
|
---|
159 |
|
---|
160 | add_project_arguments(
|
---|
161 | # TODO: Remove from project arguments and only use where needed.
|
---|
162 | '-imacros', join_paths(meson.source_root(), 'config.h'),
|
---|
163 | language : [ 'c' ],
|
---|
164 | )
|
---|
165 |
|
---|
166 | add_project_link_arguments(
|
---|
167 | cc.get_supported_link_arguments([
|
---|
168 | '-Wl,--gc-sections',
|
---|
169 | '-Wl,--warn-common',
|
---|
170 | ]),
|
---|
171 | '-Wl,--fatal-warnings',
|
---|
172 | language : [ 'c', 'cpp' ],
|
---|
173 | )
|
---|
174 |
|
---|
175 | if h_arch == 'arm32'
|
---|
176 | add_project_arguments(
|
---|
177 | '-mcpu=' + '-'.join(PROCESSOR.split('_')),
|
---|
178 | CONFIG_FPU ? '-mfloat-abi=hard' : [],
|
---|
179 | language : [ 'c', 'cpp' ],
|
---|
180 | )
|
---|
181 |
|
---|
182 | add_project_link_arguments(
|
---|
183 | '-mcpu=' + '-'.join(PROCESSOR.split('_')),
|
---|
184 | CONFIG_FPU ? '-mfloat-abi=hard' : [],
|
---|
185 | language : [ 'c', 'cpp' ],
|
---|
186 | )
|
---|
187 |
|
---|
188 | elif h_arch == 'ia32'
|
---|
189 | # FIXME: enabling -march for uspace makes malloc tests crash. Investigate.
|
---|
190 |
|
---|
191 | # if PROCESSOR == 'core'
|
---|
192 | # # FIXME
|
---|
193 | # add_project_arguments('-march=prescott', language : [ 'c', 'cpp' ])
|
---|
194 | # add_project_link_arguments('-march=prescott', language : [ 'c', 'cpp' ])
|
---|
195 | # else
|
---|
196 | # add_project_arguments('-march=' + '-'.join(PROCESSOR.split('_')), language : [ 'c', 'cpp' ])
|
---|
197 | # add_project_link_arguments('-march=' + '-'.join(PROCESSOR.split('_')), language : [ 'c', 'cpp' ])
|
---|
198 | # endif
|
---|
199 |
|
---|
200 | elif h_arch == 'mips32'
|
---|
201 |
|
---|
202 | if MACHINE == 'msim'
|
---|
203 | add_project_arguments('-march=r4000', language : [ 'c', 'cpp' ])
|
---|
204 | add_project_link_arguments('-march=r4000', language : [ 'c', 'cpp' ])
|
---|
205 |
|
---|
206 | elif MACHINE == 'bmalta'
|
---|
207 | add_project_arguments('-march=4kc', language : [ 'c', 'cpp' ])
|
---|
208 | add_project_link_arguments('-march=4kc', language : [ 'c', 'cpp' ])
|
---|
209 |
|
---|
210 | elif MACHINE == 'lmalta'
|
---|
211 | add_project_arguments('-march=4kc', language : [ 'c', 'cpp' ])
|
---|
212 | add_project_link_arguments('-march=4kc', language : [ 'c', 'cpp' ])
|
---|
213 |
|
---|
214 | else
|
---|
215 | error('Unknown machine')
|
---|
216 |
|
---|
217 | endif
|
---|
218 |
|
---|
219 | elif h_arch == 'ppc32'
|
---|
220 |
|
---|
221 | if CONFIG_FPU
|
---|
222 | float = '-mhard-float'
|
---|
223 | else
|
---|
224 | float = '-msoft-float'
|
---|
225 | endif
|
---|
226 |
|
---|
227 | add_project_arguments(float, language : [ 'c', 'cpp' ])
|
---|
228 | add_project_link_arguments(float, language : [ 'c', 'cpp' ])
|
---|
229 |
|
---|
230 | endif
|
---|
231 |
|
---|
232 | # TODO: enable more warnings
|
---|
233 | # FIXME: -fno-builtin-strftime works around seemingly spurious format warning.
|
---|
234 | # We should investigate what's going on there.
|
---|
235 |
|
---|
236 | extra_common_flags = [
|
---|
237 | '-O' + OPTIMIZATION,
|
---|
238 | '-fexec-charset=UTF-8',
|
---|
239 | '-finput-charset=UTF-8',
|
---|
240 |
|
---|
241 | '-D_HELENOS_SOURCE',
|
---|
242 | '-Wa,--fatal-warnings',
|
---|
243 |
|
---|
244 | '-Wall',
|
---|
245 | '-Wextra',
|
---|
246 |
|
---|
247 | '-Werror-implicit-function-declaration',
|
---|
248 |
|
---|
249 | '-Wwrite-strings',
|
---|
250 | '-Wsystem-headers',
|
---|
251 | '-Wunknown-pragmas',
|
---|
252 |
|
---|
253 | '-Wno-unused-parameter',
|
---|
254 |
|
---|
255 | '-pipe',
|
---|
256 | '-ffunction-sections',
|
---|
257 |
|
---|
258 | '-fno-common',
|
---|
259 |
|
---|
260 | '-fdebug-prefix-map=' + meson.source_root() + '=.',
|
---|
261 | ]
|
---|
262 |
|
---|
263 | if h_arch != 'ia64'
|
---|
264 | extra_common_flags += [ '-fvar-tracking-assignments' ]
|
---|
265 | endif
|
---|
266 |
|
---|
267 | if CONFIG_DEBUG
|
---|
268 | extra_common_flags += [ '-Werror' ]
|
---|
269 | endif
|
---|
270 |
|
---|
271 | if CONFIG_LINE_DEBUG
|
---|
272 | extra_common_flags += [ '-gdwarf-4', '-g3' ]
|
---|
273 | endif
|
---|
274 |
|
---|
275 | extra_cflags = extra_common_flags + [
|
---|
276 | '-imacros', join_paths(meson.source_root(), 'config.h'),
|
---|
277 |
|
---|
278 | '-Wmissing-prototypes',
|
---|
279 |
|
---|
280 | '-Wno-missing-braces',
|
---|
281 | '-Wno-missing-field-initializers',
|
---|
282 | '-Wno-unused-command-line-argument',
|
---|
283 | '-Wno-unused-parameter',
|
---|
284 | '-Wno-typedef-redefinition',
|
---|
285 | '-Wno-clobbered',
|
---|
286 | '-Wno-nonnull-compare',
|
---|
287 |
|
---|
288 | '-fno-builtin-strftime',
|
---|
289 | ]
|
---|
290 |
|
---|
291 | if CONFIG_UBSAN
|
---|
292 | extra_cflags += '-fsanitize=undefined'
|
---|
293 | endif
|
---|
294 |
|
---|
295 | extra_cppflags = extra_common_flags + [
|
---|
296 | '-fno-exceptions',
|
---|
297 | '-frtti',
|
---|
298 | ]
|
---|
299 |
|
---|
300 | w_flags = {
|
---|
301 | 'c': extra_cflags,
|
---|
302 | 'cpp': extra_cppflags,
|
---|
303 | }
|
---|
304 |
|
---|
305 | # Process flags. Only sets those that compiler supports.
|
---|
306 | foreach lang : [ 'c', 'cpp' ]
|
---|
307 | extra_cflags = meson.get_compiler(lang).get_supported_arguments(w_flags.get(lang))
|
---|
308 | add_project_arguments(extra_cflags, language : [ lang ])
|
---|
309 | add_project_link_arguments(extra_cflags, language : [ lang ])
|
---|
310 | endforeach
|
---|
311 |
|
---|
312 | subdir('kernel')
|
---|
313 | subdir('uspace')
|
---|
314 |
|
---|
315 |
|
---|
316 | ## Generate config.mk
|
---|
317 |
|
---|
318 | # Get the directory where the compiler resides.
|
---|
319 |
|
---|
320 | cc_fullname = run_command(which, meson.get_compiler('c').cmd_array()[0].split(' ')[0], check: true).stdout().strip()
|
---|
321 | cc_path = run_command(dirname, cc_fullname, check: true).stdout().strip()
|
---|
322 |
|
---|
323 | message(['Compiler directory is:', cc_path])
|
---|
324 |
|
---|
325 | export_cppflags = [
|
---|
326 | '-isystem', '$(HELENOS_EXPORT_ROOT)/include/posix',
|
---|
327 | '-isystem', '$(HELENOS_EXPORT_ROOT)/include/libc',
|
---|
328 | '-idirafter', '$(HELENOS_EXPORT_ROOT)/include',
|
---|
329 | ]
|
---|
330 |
|
---|
331 | export_ldflags = [
|
---|
332 | '-nostdlib',
|
---|
333 | '-L$(HELENOS_EXPORT_ROOT)/lib',
|
---|
334 | '-Wl,--whole-archive',
|
---|
335 | '$(HELENOS_EXPORT_ROOT)/lib/libstartfiles.a',
|
---|
336 | '-Wl,--no-whole-archive',
|
---|
337 | ]
|
---|
338 |
|
---|
339 | export_ldlibs = [
|
---|
340 | '-Wl,--as-needed',
|
---|
341 | '-lposix',
|
---|
342 | '-lmath',
|
---|
343 | '-lc',
|
---|
344 | '-lgcc',
|
---|
345 | '-Wl,--no-as-needed',
|
---|
346 | ]
|
---|
347 |
|
---|
348 | cc_arch = meson.get_cross_property('cc_arch')
|
---|
349 |
|
---|
350 | conf_data = configuration_data({
|
---|
351 | 'HELENOS_CROSS_PATH' : cc_path,
|
---|
352 | 'HELENOS_ARCH' : cc_arch,
|
---|
353 | 'HELENOS_CFLAGS' : ' '.join(meson.get_cross_property('c_args')),
|
---|
354 | 'HELENOS_CXXFLAGS' : ' '.join(meson.get_cross_property('cpp_args')),
|
---|
355 | 'HELENOS_CPPFLAGS' : ' '.join(export_cppflags),
|
---|
356 | 'HELENOS_LDFLAGS' : ' '.join(export_ldflags),
|
---|
357 | 'HELENOS_LDLIBS' : ' '.join(export_ldlibs),
|
---|
358 | 'HELENOS_TARGET' : cc_arch + '-helenos',
|
---|
359 | })
|
---|
360 |
|
---|
361 | config_mk = configure_file(
|
---|
362 | input: 'config.mk.in',
|
---|
363 | output: 'config.mk',
|
---|
364 | configuration: conf_data,
|
---|
365 | install: true,
|
---|
366 | install_dir: 'config',
|
---|
367 | )
|
---|
368 |
|
---|
369 | custom_target('config.sh',
|
---|
370 | input: config_mk,
|
---|
371 | output: 'config.sh',
|
---|
372 | command: [ sed, 's:$(HELENOS_EXPORT_ROOT):${HELENOS_EXPORT_ROOT}:g', '@INPUT@' ],
|
---|
373 | capture: true,
|
---|
374 | install: true,
|
---|
375 | install_dir: 'config',
|
---|
376 | )
|
---|
377 |
|
---|
378 | install_data('Makefile.common', 'Makefile.config', install_dir: 'config')
|
---|