source: mainline/meson.build@ 45b26114

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

wip

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