source: mainline/kernel/meson.build@ d3357e9

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since d3357e9 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: 4.7 KB
Line 
1
2arch_src = []
3
4# Fills arch_src.
5subdir('arch' / KARCH)
6
7# Defines genarch_src.
8subdir('genarch')
9
10# Defines generic_src, instrumentable_src.
11subdir('generic')
12
13# Defines test_src
14subdir('test')
15
16## Cross-platform assembly to start a symtab.data section
17#
18symtab_section = '.section symtab.data, "a", ' + atsign + 'progbits;'
19
20kernel_include_dirs = include_directories(
21 'generic/include',
22 'genarch/include',
23 'arch' / KARCH / 'include',
24 '..' / 'abi' / 'arch' / KARCH / 'include',
25 '..' / 'abi' / 'include',
26 'test',
27)
28
29kernel_defs = [
30 '-imacros', meson.build_root() / 'config.h',
31 '-D_HELENOS_SOURCE',
32 '-DKERNEL',
33 '-DRELEASE=' + HELENOS_RELEASE,
34 '-DCOPYRIGHT=' + HELENOS_COPYRIGHT,
35 '-DNAME=' + HELENOS_NAME,
36 '-D__@0@_BITS__'.format(meson.get_cross_property('bits')),
37]
38
39# Preprocess linker script using C preprocessor.
40kernel_ldscript = custom_target('_link.ld',
41 input: 'arch' / KARCH / '_link.ld.in',
42 output: '_link.ld',
43 command: [
44 cc.cmd_array(),
45 arch_kernel_c_args,
46 kernel_defs,
47 '-I' + meson.current_source_dir() / 'arch' / KARCH / 'include',
48 '-D__ASSEMBLER__',
49 '-D__LINKER__',
50 '-E',
51 '-P',
52 '-x', 'c',
53 '@INPUT@',
54 ],
55 capture: true,
56 build_by_default: true,
57)
58
59kernel_link_args = arch_kernel_link_args + [
60 '-Wl,--nmagic',
61 '-T', meson.current_build_dir() / '_link.ld',
62]
63
64if CONFIG_STRIP_BINARIES
65 # TODO: let meson do this
66 kernel_link_args += [ '-s' ]
67endif
68
69kernel_c_args = arch_kernel_c_args + kernel_defs + [
70 '-ffreestanding',
71 # TODO: remove this flag
72 '-Wno-cast-function-type',
73]
74
75if cc.get_id() == 'clang'
76 kernel_c_args += [
77 '-fno-stack-protector',
78 '-fno-PIC',
79 '-mllvm', '-asm-macro-max-nesting-depth=1000',
80 ]
81endif
82
83instrumentables = static_library('instrumentables', instrumentable_src,
84 include_directories: kernel_include_dirs,
85 implicit_include_directories: false,
86 c_args: kernel_c_args + (CONFIG_TRACE ? [ '-finstrument-functions' ] : []),
87 pic: false,
88)
89
90noninstrumentables = static_library('noninstrumentables', arch_src, genarch_src, generic_src, test_src,
91 include_directories: kernel_include_dirs,
92 implicit_include_directories: false,
93 c_args: kernel_c_args,
94 pic: false,
95)
96
97all_kernel_objects = [ instrumentables, noninstrumentables ]
98
99# We iterate the build several times to get symbol table right.
100# Three times is sufficient to get correct even symbols after symtab.
101
102if CONFIG_SYMTAB
103 # Iterate build three times.
104 iterations = [ 1, 2, 3 ]
105
106 # Generates symbol table information as an object file.
107 genmap = find_program('tools/genmap.py')
108
109 # Symbol table dump needed for genmap.
110 kernel_syms = custom_target('kernel_syms.txt',
111 input: all_kernel_objects,
112 output: 'kernel_syms.txt',
113 command: [ objdump, '-t', '@INPUT@' ],
114 capture: true,
115 )
116else
117 # Build just once.
118 iterations = [ 1 ]
119endif
120
121# Empty symbol map for first iteration.
122kernel_map_S = custom_target('empty_map.S',
123 output: 'empty_map.S',
124 capture: true,
125 command: [ 'echo', kernel_as_prolog + symtab_section ],
126)
127
128foreach iter : iterations
129 is_last = (iter == iterations.length())
130 kernel_name = 'kernel.@0@.elf'.format(iter)
131 kernel_map_name = kernel_name + '.map'
132 kernel_map_path = meson.current_build_dir() / kernel_map_name
133
134 kernel_elf = executable(kernel_name, kernel_map_S,
135 include_directories: kernel_include_dirs,
136 implicit_include_directories: false,
137 c_args: kernel_c_args,
138 link_args: kernel_c_args + kernel_link_args + [
139 '-Wl,-Map,' + kernel_map_path,
140 ],
141 link_depends: kernel_ldscript,
142 link_whole: all_kernel_objects,
143 pie: false,
144 )
145
146 # Generate symbol table if this is not the final iteration.
147 if not is_last
148
149 # TODO: Teach kernel to read its own ELF symbol table and get rid of this nonsense.
150 # Need to first make sure all architectures (even future ones with dumb bootloaders) can use ELF formatted kernel.
151
152 kernel_map_bin = custom_target(kernel_map_name + '.bin',
153 output: kernel_map_name + '.bin',
154 input: [ kernel_elf, kernel_syms ],
155 command: [ genmap, kernel_map_path, '@INPUT1@', '@OUTPUT@' ],
156 )
157
158 kernel_map_S_name = kernel_name + '.map.S'
159
160 kernel_map_S = custom_target(kernel_map_S_name,
161 input: kernel_map_bin,
162 output: kernel_map_S_name,
163 capture: true,
164 command: [ 'echo', kernel_as_prolog + symtab_section + ' .incbin "@INPUT@"' ],
165 )
166 endif
167endforeach
168
169rd_init_binaries += [[ kernel_elf, 'boot/kernel.elf' ]]
170
171install_files += [[ 'boot', kernel_elf.full_path(), 'kernel.elf' ]]
172install_deps += [ kernel_elf ]
173
174kernel_disasm = custom_target('kernel.elf.disasm',
175 command: [ objdump, '-S', '@INPUT@' ],
176 input: kernel_elf,
177 output: 'kernel.elf.disasm',
178 capture: true,
179 build_by_default: true,
180)
181
182# TODO: Add configuration option for installing debug files
183if false
184 install_files += [[ 'boot', kernel_disasm.full_path(), 'kernel.elf.disasm' ]]
185 install_deps += [ kernel_disasm ]
186endif
Note: See TracBrowser for help on using the repository browser.