source: mainline/meson.build@ 667c3fc

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

Fix handling of CONFIG_BUILD_SHARED_LIBS

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