Silence spurious/unwanted GCC warnings using pragmas
[helenos.git] / boot / meson.build
blob9e6a3b0c16b41999fcaff443713d68a99085df4f
2 # Copyright (c) 2006 Martin Decky
3 # All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
9 # - Redistributions of source code must retain the above copyright
10 #   notice, this list of conditions and the following disclaimer.
11 # - Redistributions in binary form must reproduce the above copyright
12 #   notice, this list of conditions and the following disclaimer in the
13 #   documentation and/or other materials provided with the distribution.
14 # - The name of the author may not be used to endorse or promote products
15 #   derived from this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 subdir('arch' / BARCH)
31 if POSTBUILD == 'uboot'
32         boot_image_format = 'binary'
33 endif
35 if BUILD
36         # Order matters.
37         modules = [ 'boot/kernel.elf' ] + rd_init + [ 'boot/initrd.img' ]
38         moddeps = []
39         name_transform = ''
41         # Collect binary references in the correct order.
42         foreach m : modules
43                 found = false
44                 foreach bin : rd_init_binaries
45                         if bin[1] == m
46                                 _dep = bin[0]
47                                 _newname = run_command(basename, bin[1], check: true).stdout().strip()
48                                 _oldname = run_command(basename, bin[0].full_path(), check: true).stdout().strip()
50                                 if CONFIG_COMPRESSED_INIT
51                                         _dep = custom_target(_newname + '.gz',
52                                                 output: _newname + '.gz',
53                                                 input: _dep,
54                                                 command: gzip,
55                                                 capture: true,
56                                         )
57                                         _newname += '.gz'
58                                         _oldname = _newname
59                                 endif
61                                 moddeps += _dep
62                                 name_transform += 's:.*/@0@:@1@:;'.format(_oldname, _newname)
63                                 found = true
64                                 break
65                         endif
66                 endforeach
68                 if not found
69                         error('Could not find dependency ' + m)
70                 endif
71         endforeach
74         boot_include_dirs = include_directories(
75                 'generic/include',
76                 'arch'/BARCH/'include',
77                 'genarch/include',
78                 '../abi/arch'/BARCH/'include',
79                 '../abi/include',
80         )
82         boot_defs = [
83                 '-imacros', meson.build_root() / 'config.h',
84                 '-D_HELENOS_SOURCE',
85                 '-DBOOT',
86                 '-DHELENOS_RELEASE=' + HELENOS_RELEASE,
87                 '-DHELENOS_COPYRIGHT=' + HELENOS_COPYRIGHT,
88                 '-DHELENOS_CODENAME=' + HELENOS_CODENAME,
89                 '-D__@0@_BITS__'.format(meson.get_cross_property('bits')),
90         ]
92         boot_c_args = arch_boot_c_args + boot_defs + [
93                 '-ffreestanding',
94         ]
96         boot_link_args = arch_boot_link_args + [
97                 '-nostdlib',
98                 '-Wl,--nmagic',
99                 '-T', meson.current_build_dir()/'_link.ld',
100                 '-Wl,--no-gc-sections',
101         ]
103         if cc.get_id() == 'clang'
104                 boot_c_args += [
105                         '-fno-stack-protector',
106                         '-fno-PIC',
107                 #       '-mllvm', '-asm-macro-max-nesting-depth=1000',
108                 ]
109         endif
111         boot_files = static_library('bootfiles', boot_src,
112                 include_directories: boot_include_dirs,
113                 implicit_include_directories: false,
114                 c_args: boot_c_args,
115                 pic: false,
116                 build_by_default: true,
117         )
119         # Preprocess linker script using C preprocessor.
120         boot_ldscript = custom_target('_link.ld',
121                 input: 'arch'/KARCH/'_link.ld.in',
122                 output: '_link.ld',
123                 command: [
124                         cc.cmd_array(),
125                         boot_c_args,
126                         '-I' + meson.current_source_dir()/'arch'/KARCH/'include',
127                         '-D__ASSEMBLER__',
128                         '-D__LINKER__',
129                         '-E',
130                         '-P',
131                         '-x', 'c',
132                         '@INPUT@',
133                 ],
134                 capture: true,
135                 build_by_default: true
136         )
138         # Create empty object file.
139         boot_empty_o = custom_target('empty.o',
140                 output: 'empty.o',
141                 command: [
142                         cc.cmd_array(),
143                         boot_c_args,
144                         '-x', 'c',
145                         '-c',
146                         '-o', '@OUTPUT@',
147                         '-',
148                 ],
149         )
151         boot_comps_tar = custom_target('components.tar',
152                 input: moddeps,
153                 output: 'components.tar',
154                 command: [ tar, '--transform', name_transform ],
155         )
157         # Add .payload section to the empty object.
158         boot_comps_o = custom_target('components.o',
159                 output: 'components.o',
160                 input: [ boot_comps_tar, boot_empty_o ],
161                 command: [
162                         objcopy,
163                         '--add-section', '.payload=@INPUT0@',
164                         '@INPUT1@',
165                         '@OUTPUT@',
166                 ],
167         )
169         boot_image_name = 'image.boot'
170         boot_image_map_path = meson.current_build_dir()/boot_image_name + '.map'
172         boot_elf = executable(boot_image_name + '.elf', boot_comps_o,
173                 include_directories: boot_include_dirs,
174                 c_args: boot_c_args,
175                 link_args: boot_c_args + boot_link_args + [
176                         '-Wl,-Map,' + boot_image_map_path,
177                 ],
178                 link_depends: boot_ldscript,
179                 link_whole: boot_files,
180                 pie: false,
181                 build_by_default: false,
182         )
184         if boot_image_format == 'elf'
185                 boot_image = boot_elf
186         endif
188         if boot_image_format == 'binary'
189                 # Some platforms can't ELF.
190                 boot_image = custom_target(boot_image_name + '.bin',
191                         input: boot_elf,
192                         output: boot_image_name + '.bin',
193                         command: [ objcopy, '-O', 'binary', '@INPUT@', '@OUTPUT@' ],
194                 )
195         endif
196 endif
198 if POSTBUILD == 'raw'
199         POST_INPUT = boot_image
200 endif
202 if POSTBUILD == 'grub'
203         subdir('grub')
204 endif
206 if POSTBUILD == 'yaboot'
207         subdir('yaboot')
208 endif
210 if POSTBUILD == 'silo'
211         subdir('silo')
212 endif
214 if POSTBUILD == 'uboot'
215         IMAGE_NAME = 'HelenOS-' + HELENOS_RELEASE
217         POST_INPUT = custom_target('uboot-image',
218                 output: 'uboot-image.bin',
219                 input: boot_image,
220                 command: [
221                         mkuimage,
222                         '-name', IMAGE_NAME,
223                         '-laddr', LADDR,
224                         '-saddr', SADDR,
225                         '-ostype', UIMAGE_OS,
226                         '@INPUT@',
227                         '@OUTPUT@',
228                 ],
229         )
230 endif