source: mainline/meson.build@ 512579c

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

arm64 wip

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