sparc64 boot
[helenos.git] / boot / meson.build
blobde8dd7d8120922d36f9141bdc979f36f11eb16c2
1 subdir('arch' / BARCH)
3 if POSTBUILD == 'uboot'
4         boot_image_format = 'binary'
5 endif
7 if BUILD
8         # Order matters.
9         modules = [ 'boot/kernel.elf' ] + rd_init + [ 'boot/initrd.img' ]
10         moddeps = []
11         name_transform = ''
13         # Collect binary references in the correct order.
14         foreach m : modules
15                 found = false
16                 foreach bin : rd_init_binaries
17                         if bin[1] == m
18                                 _dep = bin[0]
19                                 _newname = run_command(basename, bin[1], check: true).stdout().strip()
20                                 _oldname = run_command(basename, bin[0].full_path(), check: true).stdout().strip()
22                                 if CONFIG_COMPRESSED_INIT
23                                         _dep = custom_target(_newname + '.gz',
24                                                 output: _newname + '.gz',
25                                                 input: _dep,
26                                                 command: gzip,
27                                                 capture: true,
28                                         )
29                                         _newname += '.gz'
30                                         _oldname = _newname
31                                 endif
33                                 moddeps += _dep
34                                 name_transform += 's:.*/@0@:@1@:;'.format(_oldname, _newname)
35                                 found = true
36                                 break
37                         endif
38                 endforeach
40                 if not found
41                         error('Could not find dependency ' + m)
42                 endif
43         endforeach
46         boot_include_dirs = include_directories(
47                 'generic/include',
48                 'arch'/BARCH/'include',
49                 'genarch/include',
50                 '../abi/arch'/BARCH/'include',
51                 '../abi/include',
52         )
54         boot_defs = [
55                 '-imacros', meson.source_root() / 'config.h',
56                 '-D_HELENOS_SOURCE',
57                 '-DBOOT',
58                 '-DRELEASE=' + HELENOS_RELEASE,
59                 '-DCOPYRIGHT=' + HELENOS_COPYRIGHT,
60                 '-DNAME=' + HELENOS_NAME,
61                 '-D__@0@_BITS__'.format(meson.get_cross_property('bits')),
62         ]
64         boot_c_args = arch_boot_c_args + boot_defs + [
65                 '-ffreestanding',
66         ]
68         boot_link_args = arch_boot_link_args + [
69                 '-nostdlib',
70                 '-Wl,--nmagic',
71                 '-T', meson.current_build_dir()/'_link.ld',
72                 '-Wl,--no-gc-sections',
73         ]
75         if cc.get_id() == 'clang'
76                 boot_c_args += [
77                         '-fno-stack-protector',
78                         '-fno-PIC',
79                 #       '-mllvm', '-asm-macro-max-nesting-depth=1000',
80                 ]
81         endif
83         # Preprocess linker script using C preprocessor.
84         boot_ldscript = custom_target('_link.ld',
85                 input: 'arch'/KARCH/'_link.ld.in',
86                 output: '_link.ld',
87                 command: [
88                         cc.cmd_array(),
89                         boot_c_args,
90                         '-I' + meson.current_source_dir()/'arch'/KARCH/'include',
91                         '-D__ASSEMBLER__',
92                         '-D__LINKER__',
93                         '-E',
94                         '-P',
95                         '-x', 'c',
96                         '@INPUT@',
97                 ],
98                 capture: true,
99         )
101         # Create empty object file.
102         boot_empty_o = custom_target('empty.o',
103                 output: 'empty.o',
104                 command: [
105                         cc.cmd_array(),
106                         boot_c_args,
107                         '-x', 'c',
108                         '-c',
109                         '-o', '@OUTPUT@',
110                         '-',
111                 ],
112         )
114         boot_comps_tar = custom_target('components.tar',
115                 input: moddeps,
116                 output: 'components.tar',
117                 command: [ tar, '--transform', name_transform ],
118         )
120         # Add .payload section to the empty object.
121         boot_comps_o = custom_target('components.o',
122                 output: 'components.o',
123                 input: [ boot_comps_tar, boot_empty_o ],
124                 command: [
125                         objcopy,
126                         '--add-section', '.payload=@INPUT0@',
127                         '@INPUT1@',
128                         '@OUTPUT@',
129                 ],
130         )
132         boot_image_name = 'image.boot'
133         boot_image_map_path = meson.current_build_dir()/boot_image_name + '.map'
135         boot_elf = executable(boot_image_name + '.elf', boot_src, boot_comps_o,
136                 include_directories: boot_include_dirs,
137                 implicit_include_directories: false,
138                 c_args: boot_c_args,
139                 link_args: boot_c_args + boot_link_args + [
140                         '-Wl,-Map,' + boot_image_map_path,
141                 ],
142                 link_depends: boot_ldscript,
143                 install: true,
144                 install_dir: 'boot',
145                 pie: false,
146         )
148         if boot_image_format == 'elf'
149                 boot_image = boot_elf
150         endif
152         if boot_image_format == 'binary'
153                 # Some platforms can't ELF.
154                 boot_image = custom_target(boot_image_name + '.bin',
155                         input: boot_elf,
156                         output: boot_image_name + '.bin',
157                         command: [ objcopy, '-O', 'binary', '@INPUT@', '@OUTPUT@' ],
158                 )
159         endif
160 endif
162 if POSTBUILD == 'raw'
163         POST_INPUT = boot_image
164 endif
166 if POSTBUILD == 'grub'
167         subdir('grub')
168 endif
170 if POSTBUILD == 'yaboot'
171         subdir('yaboot')
172 endif
174 if POSTBUILD == 'silo'
175         subdir('silo')
176 endif
178 if POSTBUILD == 'uboot'
179         IMAGE_NAME = 'HelenOS-' + HELENOS_RELEASE
181         POST_INPUT = custom_target('uboot-image',
182                 output: 'uboot-image.bin',
183                 input: boot_image,
184                 command: [
185                         mkuimage,
186                         '-name', IMAGE_NAME,
187                         '-laddr', LADDR,
188                         '-saddr', SADDR,
189                         '-ostype', UIMAGE_OS,
190                         '@INPUT@',
191                         '@OUTPUT@',
192                 ],
193         )
194 endif