]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/boot/efi/meson.build
network: also introduce UseDomains= for [DHCPv6] section
[thirdparty/systemd.git] / src / boot / efi / meson.build
1 # SPDX-License-Identifier: LGPL-2.1-or-later
2
3 efi_headers = files('''
4 console.h
5 crc32.h
6 disk.h
7 graphics.h
8 linux.h
9 measure.h
10 missing_efi.h
11 pe.h
12 random-seed.h
13 sha256.h
14 shim.h
15 splash.h
16 util.h
17 '''.split())
18
19 common_sources = '''
20 disk.c
21 graphics.c
22 measure.c
23 pe.c
24 secure-boot.c
25 util.c
26 '''.split()
27
28 systemd_boot_sources = '''
29 boot.c
30 console.c
31 crc32.c
32 random-seed.c
33 sha256.c
34 shim.c
35 '''.split()
36
37 stub_sources = '''
38 linux.c
39 splash.c
40 stub.c
41 '''.split()
42
43 if conf.get('ENABLE_EFI') == 1 and get_option('gnu-efi') != 'false'
44 efi_cc = get_option('efi-cc')
45 if efi_cc.length() == 0
46 efi_cc = cc.cmd_array()
47 endif
48 efi_ld = get_option('efi-ld')
49 if efi_ld == ''
50 efi_ld = find_program('ld', required: true)
51 endif
52 efi_incdir = get_option('efi-includedir')
53
54 gnu_efi_path_arch = ''
55 foreach name : [gnu_efi_arch, EFI_MACHINE_TYPE_NAME]
56 if (gnu_efi_path_arch == '' and name != '' and
57 cc.has_header('@0@/@1@/efibind.h'.format(efi_incdir, name)))
58 gnu_efi_path_arch = name
59 endif
60 endforeach
61
62 if gnu_efi_path_arch != '' and EFI_MACHINE_TYPE_NAME == ''
63 error('gnu-efi is available, but EFI_MACHINE_TYPE_NAME is unknown')
64 endif
65
66 efi_libdir = get_option('efi-libdir')
67 if efi_libdir == ''
68 # New location first introduced with gnu-efi 3.0.11
69 efi_libdir = join_paths('/usr/lib/gnuefi', EFI_MACHINE_TYPE_NAME)
70 cmd = run_command('test', '-e', efi_libdir)
71
72 if cmd.returncode() != 0
73 # Fall back to the old approach
74 cmd = run_command(efi_cc + ['-print-multi-os-directory'])
75 if cmd.returncode() == 0
76 path = join_paths('/usr/lib', cmd.stdout().strip())
77 cmd = run_command('realpath', '-e', path)
78 if cmd.returncode() == 0
79 efi_libdir = cmd.stdout().strip()
80 endif
81 endif
82 endif
83 endif
84
85 have_gnu_efi = gnu_efi_path_arch != '' and efi_libdir != ''
86 else
87 have_gnu_efi = false
88 endif
89
90 if get_option('gnu-efi') == 'true' and not have_gnu_efi
91 error('gnu-efi support requested, but headers were not found')
92 endif
93
94 if have_gnu_efi
95 efi_conf = configuration_data()
96 efi_conf.set_quoted('EFI_MACHINE_TYPE_NAME', EFI_MACHINE_TYPE_NAME)
97 efi_conf.set10('ENABLE_TPM', get_option('tpm'))
98 efi_conf.set('SD_TPM_PCR', get_option('tpm-pcrindex'))
99
100 efi_config_h = configure_file(
101 output : 'efi_config.h',
102 configuration : efi_conf)
103
104 objcopy = find_program('objcopy')
105
106 efi_location_map = [
107 # New locations first introduced with gnu-efi 3.0.11
108 [join_paths(efi_libdir, 'efi.lds'),
109 join_paths(efi_libdir, 'crt0.o')],
110 # Older locations...
111 [join_paths(efi_libdir, 'gnuefi', 'elf_@0@_efi.lds'.format(gnu_efi_path_arch)),
112 join_paths(efi_libdir, 'gnuefi', 'crt0-efi-@0@.o'.format(gnu_efi_path_arch))],
113 [join_paths(efi_libdir, 'elf_@0@_efi.lds'.format(gnu_efi_path_arch)),
114 join_paths(efi_libdir, 'crt0-efi-@0@.o'.format(gnu_efi_path_arch))]]
115 efi_lds = ''
116 foreach location : efi_location_map
117 if efi_lds == ''
118 cmd = run_command('test', '-f', location[0])
119 if cmd.returncode() == 0
120 efi_lds = location[0]
121 efi_crt0 = location[1]
122 endif
123 endif
124 endforeach
125 if efi_lds == ''
126 if get_option('gnu-efi') == 'true'
127 error('gnu-efi support requested, but cannot find efi.lds')
128 else
129 have_gnu_efi = false
130 endif
131 endif
132 endif
133
134 if have_gnu_efi
135 compile_args = ['-Wall',
136 '-Wextra',
137 '-std=gnu99',
138 '-nostdlib',
139 '-fpic',
140 '-fshort-wchar',
141 '-ffreestanding',
142 '-fno-strict-aliasing',
143 '-fno-stack-protector',
144 '-Wsign-compare',
145 '-Wno-missing-field-initializers',
146 '-isystem', efi_incdir,
147 '-isystem', join_paths(efi_incdir, gnu_efi_path_arch),
148 '-I', fundamental_path,
149 '-DSD_BOOT',
150 '-include', efi_config_h,
151 '-include', version_h]
152 if efi_arch == 'x86_64'
153 compile_args += ['-mno-red-zone',
154 '-mno-sse',
155 '-mno-mmx',
156 '-DEFI_FUNCTION_WRAPPER',
157 '-DGNU_EFI_USE_MS_ABI']
158 elif efi_arch == 'ia32'
159 compile_args += ['-mno-sse',
160 '-mno-mmx']
161 elif efi_arch == 'arm'
162 if cc.has_argument('-mgeneral-regs-only')
163 compile_args += ['-mgeneral-regs-only']
164 endif
165
166 if cc.has_argument('-mfpu=none')
167 compile_args += ['-mfpu=none']
168 endif
169 endif
170 if get_option('werror') == true
171 compile_args += ['-Werror']
172 endif
173 if get_option('buildtype') == 'debug'
174 compile_args += ['-ggdb', '-O0']
175 elif get_option('buildtype') == 'debugoptimized'
176 compile_args += ['-ggdb', '-Og']
177 else
178 compile_args += ['-O2']
179 endif
180
181 efi_ldflags = ['-T', efi_lds,
182 '-shared',
183 '-Bsymbolic',
184 '-nostdlib',
185 '-znocombreloc',
186 '-L', efi_libdir,
187 efi_crt0]
188 if efi_arch == 'aarch64' or efi_arch == 'arm'
189 # Aarch64 and ARM32 don't have an EFI capable objcopy. Use 'binary'
190 # instead, and add required symbols manually.
191 efi_ldflags += ['--defsym=EFI_SUBSYSTEM=0xa']
192 efi_format = ['-O', 'binary']
193 else
194 efi_format = ['--target=efi-app-@0@'.format(gnu_efi_arch)]
195 endif
196
197 systemd_boot_objects = []
198 stub_objects = []
199 foreach file : fundamental_source_paths + common_sources + systemd_boot_sources + stub_sources
200 o_file = custom_target(file.split('/')[-1] + '.o',
201 input : file,
202 output : file.split('/')[-1] + '.o',
203 command : efi_cc + ['-c', '@INPUT@', '-o', '@OUTPUT@']
204 + compile_args,
205 depend_files : efi_headers + fundamental_headers)
206 if (fundamental_source_paths + common_sources + systemd_boot_sources).contains(file)
207 systemd_boot_objects += o_file
208 endif
209 if (fundamental_source_paths + common_sources + stub_sources).contains(file)
210 stub_objects += o_file
211 endif
212 endforeach
213
214 libgcc_file_name = run_command(efi_cc + ['-print-libgcc-file-name']).stdout().strip()
215 systemd_boot_efi_name = 'systemd-boot@0@.efi'.format(EFI_MACHINE_TYPE_NAME)
216 stub_efi_name = 'linux@0@.efi.stub'.format(EFI_MACHINE_TYPE_NAME)
217 no_undefined_symbols = find_program('no-undefined-symbols.sh')
218
219 foreach tuple : [['systemd_boot.so', systemd_boot_efi_name, systemd_boot_objects],
220 ['stub.so', stub_efi_name, stub_objects]]
221 so = custom_target(
222 tuple[0],
223 input : tuple[2],
224 output : tuple[0],
225 command : [efi_ld, '-o', '@OUTPUT@'] +
226 efi_ldflags + tuple[2] +
227 ['-lefi', '-lgnuefi', libgcc_file_name])
228
229 if want_tests != 'false'
230 test('no-undefined-symbols-' + tuple[0],
231 no_undefined_symbols,
232 args : [so])
233 endif
234
235 stub = custom_target(
236 tuple[1],
237 input : so,
238 output : tuple[1],
239 command : [objcopy,
240 '-j', '.text',
241 '-j', '.sdata',
242 '-j', '.data',
243 '-j', '.dynamic',
244 '-j', '.dynsym',
245 '-j', '.rel*']
246 + efi_format +
247 ['@INPUT@', '@OUTPUT@'],
248 install : true,
249 install_dir : bootlibdir)
250
251 set_variable(tuple[0].underscorify(), so)
252 set_variable(tuple[0].underscorify() + '_stub', stub)
253 endforeach
254
255 ############################################################
256
257 test_efi_disk_img = custom_target(
258 'test-efi-disk.img',
259 input : [systemd_boot_so, stub_so_stub],
260 output : 'test-efi-disk.img',
261 command : [test_efi_create_disk_sh, '@OUTPUT@',
262 '@INPUT0@', '@INPUT1@', splash_bmp])
263 endif