Scroll to navigation

efi.mk(3) Library Functions Manual efi.mk(3)

NAME

efi.mk

SYNOPSIS

include efi.mk

DESCRIPTION

The gnu-efi library provides a set of makefiles which produce EFI binaries on the supported platforms, as well as a number of make variables which can be set to control how each step gets built. These can be set in your makefile or on the command line, but are normally set to reasonable defaults. Usually you'll just want to use the += operator, as shown in the EXAMPLES section below, rather than fully replacing these.

make variables

Architecture specific gcc command line options for building a .efi.o
Architecture specific ld command line options for building the .efi.so
Architecture specific objcopy arguments for building the final .efi binary
Compiler prefix for cross-compilation. For example, "aarch64-linux-gnu-".

The C compiler. Defaults to either $(CROSS_COMPILE)gcc or $(CROSS_COMPILE)clang, depending on what $(CC) was set to when gnu-efi was built.
Defaults to whatever $(CC) was set to when gnu-efi was built.
One of aa64, arm, ia32, ia64, x64, or mips64el, representing the EFI architecture name of the host machine during the build.
One of aa64, arm, ia32, ia64, x64, or mips64el, representing the EFI architecture name of the target.
The architecture name for the BFD target for objcopy.
Usually empty; if you're cross compiling, this will default to e.g. -m64 if you're building for an x64 target on an i686 host.
The list of default include path for the compiler, as a gcc command line argument. Defaults to the output of $(EFI_CC) $(EFI_ARCH_3264) -print-file-name=include, for example /usr/lib/gcc/x86_64-redhat-linux/9/include. Note that there is no -I prefix on these.
The gnu-efi include paths. Note that there is no -I prefix on these.
Flags passed to gcc regardless of the build target.
Flags passed to gcc for building any binary target. Defaults to $(EFI_CPPFLAGS) $(EFI_ARCH_CFLAGS).
The linker script passed to ld -T for linking .efi.so build targets. Defaults to /usr/lib/gnuefi/$(EFI_ARCH)/efi.lds.
The path to libgcc. Defaults to the result of $(EFI_CC) $(EFI_ARCH_3264) -print-libgcc-file-name
Other command line to pass to ld before object names. Defaults to -nostdlib --warn-common --no-undefined --fatal-warnings --build-id=sha1 -shared -Bsymbolic -L/usr/lib/gnuefi/$(EFI_ARCH) /usr/lib/gnuefi/$(EFI_ARCH)/crt0.o
Normally derived from $(EFI_LDFLAGS).
Libraries to pass to ld after target object names. Defaults to -lefi -lgnuefi $(EFI_LIBGCC) -T $(EFI_LDSCRIPT)
Derived from $(EFI_LDLIBS).
Flags to pass to ar to make a .efi.a target. Defaults to "rDv".
Flags to pass to gcc to make a .efi.o object from a .S file.
Flags to pass to objcopy to make a .efi binary target. Defaults to --file-alignment 512 --section-alignment 4096 -D
Names of sections to go into .efi binary targets. If you have special sections, add them here.
Names of sections to go into .efi.debug targets. If you have special debug sections, add them here.
as appropriate:
%.efi : %.efi.so
Build a .efi binary
%.efi.debug : %efi.so
Build debuginfo
%.efi.so :
Build the intermediate .efi.so to be linked as a .efi binary. Add .o files as dependencies to a concrete .efi.so rule in order to define targets.
%.efi.a :
Build an intermediate archive file for linking into a .efi.so
%.efi.o : %.c
Build an object file from a .c file
%.efi.o : %.S
Build an object file from a .S file
Remove all files in the current working directory with the suffixes .efi, .efi.a, .efi.debug, .efi.o, or .efi.so.

EXAMPLES

This is a simple makefile used to build an EFI binary named foo.efi from source files foo.c and bar.c. It includes the special section .weird in the final binary, and the name of that is defined within the .c source files using the macro WEIRD_SECTION_NAME:


include efi.mk

all : foo.efi

%.efi.o : | EFI_CFLAGS+=-DWEIRD_SECTION_NAME=\".weird\"

foo.efi : | EFI_BIN_SECTIONS+=.weird
foo.efi.so : foo.efi.o bar.efi.o

clean : efi_clean

The following example shows how to cross-compile a binary for another architecture (in this case, ARM Aarch64, which EFI calls aa64). This assumes that you have the crt0.o, efi.lds, libgnuefi.a, and libefi.a files for Aarch64 installed in /usr/lib/gnuefi/aa64/.

$ make CROSS_COMPILE=aarch64-linux-gnu- EFI_ARCH=aa64 foo.efi

AUTHORS

Peter Jones <pjones@redhat.com>
Thu Nov 21 2019