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