source: mainline/meson.build@ af7223b

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

Make building bootable images optional

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