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