1 efi_headers = files('''
21 systemd_boot_sources = '''
33 if conf.get('ENABLE_EFI', false) and get_option('gnu-efi') != 'false'
34 efi_cc = get_option('efi-cc')
35 efi_ld = get_option('efi-ld')
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)))
41 if have_header and EFI_MACHINE_TYPE_NAME == ''
42 error('gnu-efi is available, but EFI_MACHINE_TYPE_NAME is unknown')
45 efi_libdir = get_option('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()
54 have_gnu_efi = have_header and efi_libdir != ''
59 if get_option('gnu-efi') == 'true' and not have_gnu_efi
60 error('gnu-efi support requested, but headers were not found')
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.set('ENABLE_TPM', get_option('tpm'))
68 efi_conf.set('SD_TPM_PCR', get_option('tpm-pcrindex'))
70 efi_config_h = configure_file(
71 output : 'efi_config.h',
72 configuration : efi_conf)
74 objcopy = find_program('objcopy')
76 efi_ldsdir = get_option('efi-ldsdir')
77 arch_lds = 'elf_@0@_efi.lds'.format(gnu_efi_arch)
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))
90 message('efi-libdir: "@0@"'.format(efi_libdir))
91 message('efi-ldsdir: "@0@"'.format(efi_ldsdir))
92 message('efi-includedir: "@0@"'.format(efi_incdir))
94 compile_args = ['-Wall',
102 '-fno-strict-aliasing',
103 '-fno-stack-protector',
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',
113 '-DEFI_FUNCTION_WRAPPER',
114 '-DGNU_EFI_USE_MS_ABI']
115 elif efi_arch == 'ia32'
116 compile_args += ['-mno-sse',
121 join_paths(efi_ldsdir, arch_lds),
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']
134 efi_format = ['--target=efi-app-@0@'.format(gnu_efi_arch)]
137 systemd_boot_objects = []
139 foreach file : common_sources + systemd_boot_sources + stub_sources
140 o_file = custom_target(file + '.o',
142 output : file + '.o',
143 command : [efi_cc, '-c', '@INPUT@', '-o', '@OUTPUT@']
145 depend_files : efi_headers)
146 if (common_sources + systemd_boot_sources).contains(file)
147 systemd_boot_objects += [o_file]
149 if (common_sources + stub_sources).contains(file)
150 stub_objects += [o_file]
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')
159 foreach tuple : [['systemd_boot.so', systemd_boot_efi_name, systemd_boot_objects],
160 ['stub.so', stub_efi_name, stub_objects]]
165 command : [efi_ld, '-o', '@OUTPUT@'] +
166 efi_ldflags + tuple[2] +
167 ['-lefi', '-lgnuefi', libgcc_file_name])
169 test('no-undefined-symbols-' + tuple[0],
170 no_undefined_symbols,
173 stub = custom_target(
187 ['@INPUT@', '@OUTPUT@'],
189 install_dir : bootlibdir)
191 set_variable(tuple[0].underscorify(), so)
192 set_variable(tuple[0].underscorify() + '_stub', stub)
196 ############################################################
199 test_efi_disk_img = custom_target(
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])