source: mainline/meson.build@ 4b65f9a

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

Make tools/ew.py runnable from the build directory

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