source: mainline/meson.build@ 5b586b9

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5b586b9 was 5b586b9, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 6 years ago

rest of arms

  • Property mode set to 100644
File size: 11.7 KB
Line 
1# TODO: Use vcs_tag() to generate version string
2# TODO: jobfile
3# TODO: lto
4# TODO: CONFIG_BUILD_SHARED_LIBS
5# TODO: fix clang build
6
7project(
8 'HelenOS',
9 [ 'c', 'cpp' ],
10 default_options : ['buildtype=plain', 'c_std=gnu11', 'cpp_std=c++17', 'warning_level=3', 'werror=false', 'b_staticpic=false', 'default_library=shared', 'prefix=/' ],
11 meson_version: '>=0.50.1',
12)
13
14cc = meson.get_compiler('c')
15basename = find_program('basename')
16dirname = find_program('dirname')
17find = find_program('find')
18grep = find_program('grep')
19mkarray = find_program('tools/mkarray_for_meson.sh')
20objdump = find_program('objdump')
21objcopy = find_program('objcopy')
22sed = find_program('sed')
23unzip = find_program('unzip')
24which = find_program('which')
25sh = [ find_program('sh'), '-x', '-u', '-e' ]
26mkext4 = find_program('tools/mkext4.py')
27mkfat = find_program('tools/mkfat.py')
28mkuimage = find_program('tools/mkuimage.py')
29cp = find_program('cp')
30
31genisoimage = find_program('genisoimage', required: false)
32
33if not genisoimage.found()
34 genisoimage = find_program('mkisofs', required: false)
35endif
36
37if not genisoimage.found()
38 xorriso = find_program('xorriso', required: false)
39
40 if xorriso.found()
41 genisoimage = [ xorriso, '-as', 'genisoimage' ]
42 else
43 error('Need genisoimage, mkisofs or xorriso.')
44 endif
45endif
46
47
48autocheck = generator(find_program('tools/autocheck.awk'),
49 arguments: [ '@INPUT@' ],
50 output: '@PLAINNAME@.check.c',
51 capture: true,
52)
53
54# Tar's arguments make sure that the archive is reproducible.
55tar = [
56 find_program('tar'),
57 '-c',
58 '-f', '@OUTPUT@',
59 '--mtime=1970-01-01 00:00:00Z',
60 '--group=0',
61 '--owner=0',
62 '--numeric-owner',
63 '--mode=go=rX,u+rw,a-s',
64 '--no-acls',
65 '--no-selinux',
66 '--no-xattrs',
67 '--format=ustar',
68 '--transform', 's:@OUTDIR@/::',
69 '@INPUT@',
70]
71
72if get_option('default_library') == 'both'
73 error('You must use either shared or static for default_library.')
74endif
75
76debug_options = false
77
78# Output compiler flags for use by third-party builds.
79# NOTE: See $srcroot/meson/cross/$arch for architecture-specific compiler flags.
80
81if debug_options
82 message('Cross c_args:')
83 message(meson.get_cross_property('c_args'))
84 message('Cross cpp_args:')
85 message(meson.get_cross_property('cpp_args'))
86 message('Cross c_link_args:')
87 message(meson.get_cross_property('c_link_args'))
88 message('Cross cpp_link_args:')
89 message(meson.get_cross_property('cpp_link_args'))
90endif
91
92# Read some variables from Makefile.common
93config_variables = [
94 # Uspace and kernel
95 'CONFIG_BAREBONE',
96 'CONFIG_BUILD_SHARED_LIBS',
97 'CONFIG_DEBUG',
98 'CONFIG_DEVEL_FILES',
99 'CONFIG_FPU',
100 'CONFIG_LINE_DEBUG',
101 'CONFIG_PCUT_SELF_TESTS',
102 'CONFIG_PCUT_TESTS',
103 'CONFIG_RTLD',
104 'CONFIG_STRIP_BINARIES',
105 'CONFIG_UBSAN',
106 'CONFIG_USE_SHARED_LIBS',
107 'CROSS_TARGET',
108 'OPTIMIZATION',
109 'PROCESSOR',
110 'QUADFLOAT',
111 'RDFMT',
112
113 # Kernel only
114 'CONFIG_ACPI',
115 'CONFIG_AM335X_TIMERS',
116 'CONFIG_ASID',
117 'CONFIG_ASID_FIFO',
118 'CONFIG_AT_KBD',
119 'CONFIG_BCM2835_MAILBOX',
120 'CONFIG_DSRLNIN',
121 'CONFIG_DSRLNOUT',
122 'CONFIG_EGA',
123 'CONFIG_FB',
124 'CONFIG_GICV2',
125 'CONFIG_I8042',
126 'CONFIG_I8259',
127 'CONFIG_IOMAP_BITMAP',
128 'CONFIG_IOMAP_DUMMY',
129 'CONFIG_KCONSOLE',
130 'CONFIG_MAC_KBD',
131 'CONFIG_MULTIBOOT',
132 'CONFIG_NS16550',
133 'CONFIG_OFW_PCI',
134 'CONFIG_OFW_TREE',
135 'CONFIG_OMAP_UART',
136 'CONFIG_PAGE_HT',
137 'CONFIG_PAGE_PT',
138 'CONFIG_PC_KBD',
139 'CONFIG_PL011_UART',
140 'CONFIG_PL050',
141 'CONFIG_S3C24XX_IRQC',
142 'CONFIG_S3C24XX_UART',
143 'CONFIG_SMP',
144 'CONFIG_SOFTINT',
145 'CONFIG_SRLN',
146 'CONFIG_SUN_KBD',
147 'CONFIG_SYMTAB',
148 'CONFIG_TEST',
149 'CONFIG_TRACE',
150 'CONFIG_TSB',
151 'CONFIG_UDEBUG',
152 'CONFIG_VIA_CUDA',
153 'MACHINE',
154 'MEMORY_MODEL',
155
156 'UARCH',
157 'KARCH',
158 'BARCH',
159 'GRUB_ARCH',
160 'UIMAGE_OS',
161]
162
163foreach varname : config_variables
164 result = run_command(grep, '^' + varname + '\\b', meson.source_root() / 'Makefile.config')
165 if result.returncode() != 0
166 # TODO: Output negative/inapplicable variables too in config, so that we can check for typos here.
167 #warning('Missing configuration variable ' + varname + ' in Makefile.config')
168 set_variable(varname, false)
169 continue
170 endif
171
172 value = result.stdout().split('\n')[0].strip().split('=')[1].strip()
173 if value == 'y'
174 value = true
175 elif value == 'n'
176 value = false
177 endif
178
179 set_variable(varname, value)
180 if debug_options
181 message([ varname, value ])
182 endif
183endforeach
184
185# Also read version information.
186version_variables = [
187 'COPYRIGHT',
188 'NAME',
189 'PATCHLEVEL',
190 'SUBLEVEL',
191 'VERSION',
192]
193
194foreach varname : version_variables
195 line = run_command(grep, '^' + varname + '\\b', meson.source_root() / 'version', check: true).stdout().strip()
196 value = line.split('=')[1].strip()
197 set_variable('HELENOS_' + varname, value)
198 if debug_options
199 message([ 'HELENOS_' + varname, value ])
200 endif
201endforeach
202
203HELENOS_RELEASE = HELENOS_VERSION + '.' + HELENOS_PATCHLEVEL + '.' + HELENOS_SUBLEVEL
204
205add_project_arguments(
206 # TODO: Remove from project arguments and only use where needed.
207 '-imacros', join_paths(meson.source_root(), 'config.h'),
208 language : [ 'c' ],
209)
210
211add_project_link_arguments(
212 cc.get_supported_link_arguments([
213 '-Wl,--gc-sections',
214 '-Wl,--warn-common',
215 ]),
216 '-Wl,--fatal-warnings',
217 language : [ 'c', 'cpp' ],
218)
219
220# TODO: enable more warnings
221# FIXME: -fno-builtin-strftime works around seemingly spurious format warning.
222# We should investigate what's going on there.
223
224extra_common_flags = [
225 '-O' + OPTIMIZATION,
226 '-fexec-charset=UTF-8',
227 '-finput-charset=UTF-8',
228
229 '-D_HELENOS_SOURCE',
230 '-Wa,--fatal-warnings',
231
232 '-Wall',
233 '-Wextra',
234
235 '-Werror-implicit-function-declaration',
236
237 '-Wwrite-strings',
238 '-Wsystem-headers',
239 '-Wunknown-pragmas',
240
241 '-Wno-unused-parameter',
242
243 '-pipe',
244 '-ffunction-sections',
245
246 '-fno-common',
247
248 '-fdebug-prefix-map=' + meson.source_root() + '=.',
249]
250
251if UARCH != 'ia64'
252 extra_common_flags += [ '-fvar-tracking-assignments' ]
253endif
254
255if CONFIG_DEBUG
256 extra_common_flags += [ '-Werror' ]
257endif
258
259if CONFIG_LINE_DEBUG
260 extra_common_flags += [ '-gdwarf-4', '-g3' ]
261endif
262
263extra_cflags = extra_common_flags + [
264 '-Wmissing-prototypes',
265
266 '-Wno-missing-braces',
267 '-Wno-missing-field-initializers',
268 '-Wno-unused-command-line-argument',
269 '-Wno-unused-parameter',
270 '-Wno-typedef-redefinition',
271 '-Wno-clobbered',
272 '-Wno-nonnull-compare',
273
274 '-fno-builtin-strftime',
275]
276
277if CONFIG_UBSAN
278 extra_cflags += '-fsanitize=undefined'
279endif
280
281extra_cppflags = extra_common_flags + [
282 '-fno-exceptions',
283 '-frtti',
284]
285
286w_flags = {
287 'c': extra_cflags,
288 'cpp': extra_cppflags,
289}
290
291# Process flags. Only sets those that compiler supports.
292foreach lang : [ 'c', 'cpp' ]
293 extra_cflags = meson.get_compiler(lang).get_supported_arguments(w_flags.get(lang))
294 add_project_arguments(extra_cflags, language : [ lang ])
295 add_project_link_arguments(extra_cflags, language : [ lang ])
296endforeach
297
298# Init binaries.
299rd_init = [
300 # IMPORTANT: The order of entries is important for bootloader!
301 'srv/ns',
302 'srv/loader',
303 'app/init',
304 'srv/locsrv',
305 'srv/bd/rd',
306 'srv/vfs',
307 'srv/logger',
308 'srv/fs/' + RDFMT,
309]
310
311# References to the actual binary files. Filled in by uspace.
312rd_init_binaries = []
313
314# Binaries allowed on the initrd image when CONFIG_BAREBONE is enabled.
315rd_essential = rd_init + [
316 'app/bdsh',
317 'app/getterm',
318 'app/kio',
319
320 'srv/devman',
321 'srv/fs/locfs',
322 'srv/hid/console',
323 'srv/hid/input',
324 'srv/hid/output',
325 'srv/klog',
326
327 'drv/root/root',
328 'drv/root/virt',
329 'drv/fb/kfb',
330]
331
332if CONFIG_FB
333 rd_essential += [
334 'app/vlaunch',
335 'app/vterm',
336
337 'srv/hid/compositor',
338 ]
339endif
340
341
342## The at-sign
343#
344# The `atsign` variable holds the ASCII character representing the at-sign
345# ('@') used in various $(AS) constructs (e.g. @progbits). On architectures that
346# don't use '@' for starting a comment, `atsign` is merely '@'. However, on
347# those that do use it for starting a comment (e.g. arm32), `atsign` must be
348# defined as the percentile-sign ('%') in the architecture-dependent files.
349#
350atsign = '@'
351
352## Some architectures need a particular string at the beginning of assembly files.
353kernel_as_prolog = ''
354uspace_as_prolog = ''
355
356subdir('meson' / 'arch' / UARCH)
357
358install_files = []
359install_deps = []
360
361subdir('kernel')
362subdir('uspace')
363
364
365## Generate config.mk
366
367# Get the directory where the compiler resides.
368
369cc_fullname = run_command(which, meson.get_compiler('c').cmd_array()[0].split(' ')[0], check: true).stdout().strip()
370cc_path = run_command(dirname, cc_fullname, check: true).stdout().strip()
371
372message(['Compiler directory is:', cc_path])
373
374export_cppflags = [
375 '-isystem', '$(HELENOS_EXPORT_ROOT)/include/posix',
376 '-isystem', '$(HELENOS_EXPORT_ROOT)/include/libc',
377 '-idirafter', '$(HELENOS_EXPORT_ROOT)/include',
378]
379
380export_ldflags = [
381 '-nostdlib',
382 '-L$(HELENOS_EXPORT_ROOT)/lib',
383 '-Wl,--whole-archive',
384 '$(HELENOS_EXPORT_ROOT)/lib/libstartfiles.a',
385 '-Wl,--no-whole-archive',
386]
387
388export_ldlibs = [
389 '-Wl,--as-needed',
390 '-lposix',
391 '-lmath',
392 '-lc',
393 '-lgcc',
394 '-Wl,--no-as-needed',
395]
396
397cc_arch = meson.get_cross_property('cc_arch')
398
399conf_data = configuration_data({
400 'HELENOS_CROSS_PATH' : cc_path,
401 'HELENOS_ARCH' : cc_arch,
402 'HELENOS_CFLAGS' : ' '.join(arch_uspace_c_args),
403 'HELENOS_CXXFLAGS' : ' '.join(arch_uspace_c_args),
404 'HELENOS_CPPFLAGS' : ' '.join(export_cppflags),
405 'HELENOS_LDFLAGS' : ' '.join(export_ldflags),
406 'HELENOS_LDLIBS' : ' '.join(export_ldlibs),
407 'HELENOS_TARGET' : cc_arch + '-helenos',
408})
409
410config_mk = configure_file(
411 input: 'config.mk.in',
412 output: 'config.mk',
413 configuration: conf_data,
414)
415
416config_sh = custom_target('config.sh',
417 input: config_mk,
418 output: 'config.sh',
419 command: [ sed, 's:$(HELENOS_EXPORT_ROOT):${HELENOS_EXPORT_ROOT}:g', '@INPUT@' ],
420 capture: true,
421)
422
423install_files += [[ 'config', meson.current_build_dir() / 'config.mk', 'config.mk' ]]
424install_deps += [ config_mk ]
425install_files += [[ 'config', meson.current_build_dir() / 'config.sh', 'config.sh' ]]
426install_deps += [ config_sh ]
427
428# TODO: remove
429install_files += [[ 'config', meson.current_source_dir() / 'Makefile.common', 'Makefile.common' ]]
430install_deps += files('Makefile.common')
431install_files += [[ 'config', meson.current_source_dir() / 'Makefile.config', 'Makefile.config' ]]
432install_deps += files('Makefile.config')
433
434if CONFIG_DEVEL_FILES
435 # Also install libgcc
436 libgcc = run_command(
437 cc.cmd_array(), arch_uspace_c_args, '-print-libgcc-file-name',
438 check: true,
439 ).stdout().strip()
440
441 install_files += [[ 'lib', libgcc, 'libgcc.a' ]]
442 install_deps += [ files(libgcc) ]
443endif
444
445
446# Emit the install script.
447
448install_script_text = []
449
450# Copy uspace/dist.
451_uspace = meson.current_source_dir() / 'uspace'
452install_script_text += 'cp -r -L -T -u "@0@/dist" "${DESTDIR}"'.format(_uspace)
453
454# Copy uspace/overlay
455install_script_text += 'if ls @0@/overlay/* >/dev/null 2>/dev/null; then'.format(_uspace)
456install_script_text += 'cp -r -L @0@/overlay/* "${DESTDIR}"'.format(_uspace)
457install_script_text += 'fi'
458
459
460foreach f : install_files
461 _cmd = 'mkdir -p "${DESTDIR}@0@" && cp -L -T "@1@" "${DESTDIR}@0@/@2@"'
462 install_script_text += _cmd.format(f[0], f[1], f[2])
463endforeach
464
465install_script_text += uspace_lib_install_script_text
466
467install_script = configure_file(
468 configuration: { 'text' : '\n'.join(install_script_text) },
469 input: 'install.sh.in',
470 output: 'install.sh',
471)
472
473# Build up dist
474
475dist_dir = meson.current_build_dir()/'dist/'
476
477dist = custom_target('DIST',
478 output: 'dist.tag',
479 input: [ install_script, install_deps ],
480 command: [ sh, '@INPUT0@', '@OUTPUT@', dist_dir ],
481)
482
483# Build initrd image
484
485if RDFMT == 'tmpfs'
486 initrd_cmd = [ 'tar', '-c', '-f', '@OUTPUT@', '-C', dist_dir, '.' ]
487elif RDFMT == 'fat'
488 initrd_cmd = [ mkfat, '1048576', dist_dir, '@OUTPUT@' ]
489elif RDFMT == 'ext4fs'
490 initrd_cmd = [ mkext4, '1048576', dist_dir, '@OUTPUT@' ]
491else
492 error('Unknown RDFMT: ' + RDFMT)
493endif
494
495initrd_img = custom_target('initrd.img',
496 output: 'initrd.img',
497 input: dist,
498 command: initrd_cmd,
499)
500
501rd_init_binaries += [[ initrd_img, 'boot/initrd.img' ]]
502
503subdir('boot')
504
505custom_target(POST_OUTPUT,
506 output: POST_OUTPUT,
507 input: POST_INPUT,
508 command: [ cp, '@INPUT@', '@OUTPUT@' ],
509 build_by_default: true,
510)
Note: See TracBrowser for help on using the repository browser.