+# SPDX-License-Identifier: LGPL-2.1+
+
efi_headers = files('''
console.h
disk.h
if conf.get('ENABLE_EFI') == 1 and get_option('gnu-efi') != 'false'
efi_cc = get_option('efi-cc')
+ if efi_cc.length() == 0
+ efi_cc = cc.cmd_array()
+ endif
efi_ld = get_option('efi-ld')
-
+ if efi_ld == ''
+ efi_ld = find_program('ld', required: true)
+ endif
efi_incdir = get_option('efi-includedir')
- have_header = (gnu_efi_arch != '' and
- cc.has_header('@0@/@1@/efibind.h'.format(efi_incdir, gnu_efi_arch)))
- if have_header and EFI_MACHINE_TYPE_NAME == ''
+ gnu_efi_path_arch = ''
+ foreach name : [gnu_efi_arch, EFI_MACHINE_TYPE_NAME]
+ if (gnu_efi_path_arch == '' and name != '' and
+ cc.has_header('@0@/@1@/efibind.h'.format(efi_incdir, name)))
+ gnu_efi_path_arch = name
+ endif
+ endforeach
+
+ if gnu_efi_path_arch != '' and EFI_MACHINE_TYPE_NAME == ''
error('gnu-efi is available, but EFI_MACHINE_TYPE_NAME is unknown')
endif
efi_libdir = get_option('efi-libdir')
if efi_libdir == ''
- cmd = 'cd /usr/lib/$(@0@ -print-multi-os-directory) && pwd'.format(efi_cc)
- ret = run_command('sh', '-c', cmd)
+ ret = run_command(efi_cc + ['-print-multi-os-directory'])
if ret.returncode() == 0
- efi_libdir = ret.stdout().strip()
+ path = join_paths('/usr/lib', ret.stdout().strip())
+ ret = run_command('realpath', '-e', path)
+ if ret.returncode() == 0
+ efi_libdir = ret.stdout().strip()
+ endif
endif
endif
- have_gnu_efi = have_header and efi_libdir != ''
+ have_gnu_efi = gnu_efi_path_arch != '' and efi_libdir != ''
else
have_gnu_efi = false
endif
if have_gnu_efi
efi_conf = configuration_data()
- efi_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
efi_conf.set_quoted('EFI_MACHINE_TYPE_NAME', EFI_MACHINE_TYPE_NAME)
efi_conf.set10('ENABLE_TPM', get_option('tpm'))
efi_conf.set('SD_TPM_PCR', get_option('tpm-pcrindex'))
objcopy = find_program('objcopy')
efi_ldsdir = get_option('efi-ldsdir')
- arch_lds = 'elf_@0@_efi.lds'.format(gnu_efi_arch)
+ arch_lds = 'elf_@0@_efi.lds'.format(gnu_efi_path_arch)
if efi_ldsdir == ''
efi_ldsdir = join_paths(efi_libdir, 'gnuefi')
cmd = run_command('test', '-f', join_paths(efi_ldsdir, arch_lds))
endif
endif
- message('efi-libdir: "@0@"'.format(efi_libdir))
- message('efi-ldsdir: "@0@"'.format(efi_ldsdir))
- message('efi-includedir: "@0@"'.format(efi_incdir))
-
compile_args = ['-Wall',
'-Wextra',
'-std=gnu90',
'-Wsign-compare',
'-Wno-missing-field-initializers',
'-isystem', efi_incdir,
- '-isystem', join_paths(efi_incdir, gnu_efi_arch),
- '-include', efi_config_h]
+ '-isystem', join_paths(efi_incdir, gnu_efi_path_arch),
+ '-include', efi_config_h,
+ '-include', version_h]
if efi_arch == 'x86_64'
compile_args += ['-mno-red-zone',
'-mno-sse',
'-nostdlib',
'-znocombreloc',
'-L', efi_libdir,
- join_paths(efi_ldsdir, 'crt0-efi-@0@.o'.format(gnu_efi_arch))]
+ join_paths(efi_ldsdir, 'crt0-efi-@0@.o'.format(gnu_efi_path_arch))]
if efi_arch == 'aarch64' or efi_arch == 'arm'
# Aarch64 and ARM32 don't have an EFI capable objcopy. Use 'binary'
# instead, and add required symbols manually.
o_file = custom_target(file + '.o',
input : file,
output : file + '.o',
- command : [efi_cc, '-c', '@INPUT@', '-o', '@OUTPUT@']
+ command : efi_cc + ['-c', '@INPUT@', '-o', '@OUTPUT@']
+ compile_args,
depend_files : efi_headers)
if (common_sources + systemd_boot_sources).contains(file)
- systemd_boot_objects += [o_file]
+ systemd_boot_objects += o_file
endif
if (common_sources + stub_sources).contains(file)
- stub_objects += [o_file]
+ stub_objects += o_file
endif
endforeach
- libgcc_file_name = run_command(efi_cc, '-print-libgcc-file-name').stdout().strip()
+ libgcc_file_name = run_command(efi_cc + ['-print-libgcc-file-name']).stdout().strip()
systemd_boot_efi_name = 'systemd-boot@0@.efi'.format(EFI_MACHINE_TYPE_NAME)
stub_efi_name = 'linux@0@.efi.stub'.format(EFI_MACHINE_TYPE_NAME)
no_undefined_symbols = find_program('no-undefined-symbols.sh')
efi_ldflags + tuple[2] +
['-lefi', '-lgnuefi', libgcc_file_name])
- test('no-undefined-symbols-' + tuple[0],
- no_undefined_symbols,
- args : [so])
+ if want_tests != 'false'
+ test('no-undefined-symbols-' + tuple[0],
+ no_undefined_symbols,
+ args : [so])
+ endif
stub = custom_target(
tuple[1],
'-j', '.data',
'-j', '.dynamic',
'-j', '.dynsym',
- '-j', '.rel',
- '-j', '.rela',
- '-j', '.reloc']
+ '-j', '.rel*']
+ efi_format +
['@INPUT@', '@OUTPUT@'],
install : true,