]> git.proxmox.com Git - systemd.git/blob - src/boot/efi/meson.build
New upstream version 236
[systemd.git] / src / boot / efi / meson.build
1 # SPDX-License-Identifier: LGPL-2.1+
2 #
3 # Copyright 2017 Zbigniew Jędrzejewski-Szmek
4 #
5 # systemd is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation; either version 2.1 of the License, or
8 # (at your option) any later version.
9 #
10 # systemd is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
17
18 efi_headers = files('''
19 console.h
20 disk.h
21 graphics.h
22 linux.h
23 measure.h
24 pe.h
25 splash.h
26 util.h
27 shim.h
28 '''.split())
29
30 common_sources = '''
31 disk.c
32 graphics.c
33 measure.c
34 pe.c
35 util.c
36 '''.split()
37
38 systemd_boot_sources = '''
39 boot.c
40 console.c
41 shim.c
42 '''.split()
43
44 stub_sources = '''
45 linux.c
46 splash.c
47 stub.c
48 '''.split()
49
50 if conf.get('ENABLE_EFI') == 1 and get_option('gnu-efi') != 'false'
51 efi_cc = get_option('efi-cc')
52 efi_ld = get_option('efi-ld')
53
54 efi_incdir = get_option('efi-includedir')
55 have_header = (gnu_efi_arch != '' and
56 cc.has_header('@0@/@1@/efibind.h'.format(efi_incdir, gnu_efi_arch)))
57
58 if have_header and EFI_MACHINE_TYPE_NAME == ''
59 error('gnu-efi is available, but EFI_MACHINE_TYPE_NAME is unknown')
60 endif
61
62 efi_libdir = get_option('efi-libdir')
63 if efi_libdir == ''
64 cmd = 'cd /usr/lib/$(@0@ -print-multi-os-directory) && pwd'.format(efi_cc)
65 ret = run_command('sh', '-c', cmd)
66 if ret.returncode() == 0
67 efi_libdir = ret.stdout().strip()
68 endif
69 endif
70
71 have_gnu_efi = have_header and efi_libdir != ''
72 else
73 have_gnu_efi = false
74 endif
75
76 if get_option('gnu-efi') == 'true' and not have_gnu_efi
77 error('gnu-efi support requested, but headers were not found')
78 endif
79
80 if have_gnu_efi
81 efi_conf = configuration_data()
82 efi_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
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_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 message('efi-libdir: "@0@"'.format(efi_libdir))
108 message('efi-ldsdir: "@0@"'.format(efi_ldsdir))
109 message('efi-includedir: "@0@"'.format(efi_incdir))
110
111 compile_args = ['-Wall',
112 '-Wextra',
113 '-std=gnu90',
114 '-nostdinc',
115 '-ggdb', '-O0',
116 '-fpic',
117 '-fshort-wchar',
118 '-ffreestanding',
119 '-fno-strict-aliasing',
120 '-fno-stack-protector',
121 '-Wsign-compare',
122 '-Wno-missing-field-initializers',
123 '-isystem', efi_incdir,
124 '-isystem', join_paths(efi_incdir, gnu_efi_arch),
125 '-include', efi_config_h]
126 if efi_arch == 'x86_64'
127 compile_args += ['-mno-red-zone',
128 '-mno-sse',
129 '-mno-mmx',
130 '-DEFI_FUNCTION_WRAPPER',
131 '-DGNU_EFI_USE_MS_ABI']
132 elif efi_arch == 'ia32'
133 compile_args += ['-mno-sse',
134 '-mno-mmx']
135 endif
136
137 efi_ldflags = ['-T',
138 join_paths(efi_ldsdir, arch_lds),
139 '-shared',
140 '-Bsymbolic',
141 '-nostdlib',
142 '-znocombreloc',
143 '-L', efi_libdir,
144 join_paths(efi_ldsdir, 'crt0-efi-@0@.o'.format(gnu_efi_arch))]
145 if efi_arch == 'aarch64' or efi_arch == 'arm'
146 # Aarch64 and ARM32 don't have an EFI capable objcopy. Use 'binary'
147 # instead, and add required symbols manually.
148 efi_ldflags += ['--defsym=EFI_SUBSYSTEM=0xa']
149 efi_format = ['-O', 'binary']
150 else
151 efi_format = ['--target=efi-app-@0@'.format(gnu_efi_arch)]
152 endif
153
154 systemd_boot_objects = []
155 stub_objects = []
156 foreach file : common_sources + systemd_boot_sources + stub_sources
157 o_file = custom_target(file + '.o',
158 input : file,
159 output : file + '.o',
160 command : [efi_cc, '-c', '@INPUT@', '-o', '@OUTPUT@']
161 + compile_args,
162 depend_files : efi_headers)
163 if (common_sources + systemd_boot_sources).contains(file)
164 systemd_boot_objects += [o_file]
165 endif
166 if (common_sources + stub_sources).contains(file)
167 stub_objects += [o_file]
168 endif
169 endforeach
170
171 libgcc_file_name = run_command(efi_cc, '-print-libgcc-file-name').stdout().strip()
172 systemd_boot_efi_name = 'systemd-boot@0@.efi'.format(EFI_MACHINE_TYPE_NAME)
173 stub_efi_name = 'linux@0@.efi.stub'.format(EFI_MACHINE_TYPE_NAME)
174 no_undefined_symbols = find_program('no-undefined-symbols.sh')
175
176 foreach tuple : [['systemd_boot.so', systemd_boot_efi_name, systemd_boot_objects],
177 ['stub.so', stub_efi_name, stub_objects]]
178 so = custom_target(
179 tuple[0],
180 input : tuple[2],
181 output : tuple[0],
182 command : [efi_ld, '-o', '@OUTPUT@'] +
183 efi_ldflags + tuple[2] +
184 ['-lefi', '-lgnuefi', libgcc_file_name])
185
186 test('no-undefined-symbols-' + tuple[0],
187 no_undefined_symbols,
188 args : [so])
189
190 stub = custom_target(
191 tuple[1],
192 input : so,
193 output : tuple[1],
194 command : [objcopy,
195 '-j', '.text',
196 '-j', '.sdata',
197 '-j', '.data',
198 '-j', '.dynamic',
199 '-j', '.dynsym',
200 '-j', '.rel',
201 '-j', '.rela',
202 '-j', '.reloc']
203 + efi_format +
204 ['@INPUT@', '@OUTPUT@'],
205 install : true,
206 install_dir : bootlibdir)
207
208 set_variable(tuple[0].underscorify(), so)
209 set_variable(tuple[0].underscorify() + '_stub', stub)
210 endforeach
211 endif
212
213 ############################################################
214
215 if have_gnu_efi
216 test_efi_disk_img = custom_target(
217 'test-efi-disk.img',
218 input : [systemd_boot_so, stub_so_stub],
219 output : 'test-efi-disk.img',
220 command : [test_efi_create_disk_sh, '@OUTPUT@',
221 '@INPUT0@', '@INPUT1@', splash_bmp])
222 endif