efi.mk - Man Page

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

EFI_ARCH_CFLAGS

Architecture specific gcc command line options for building a .efi.o

EFI_ARCH_LDFLAGS

Architecture specific ld command line options for building the .efi.so

EFI_ARCH_FORMAT

Architecture specific objcopy arguments for building the final .efi binary

CROSS_COMPILE

Compiler prefix for cross-compilation.  For example, "aarch64-linux-gnu-".

EFI_CC

p 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.

EFI_HOSTCC

Defaults to whatever $(CC) was set to when gnu-efi was built.

EFI_HOSTARCH

One of aa64, arm, ia32, ia64, x64, or mips64el, representing the EFI architecture name of the host machine during the build.

EFI_ARCH

One of aa64, arm, ia32, ia64, x64, or mips64el, representing the EFI architecture name of the target.

EFI_BFDARCH

The architecture name for the BFD target for objcopy.

EFI_ARCH_3264

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.

EFI_CC_INCLUDES

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.

EFI_INCLUDES

The gnu-efi include paths.  Note that there is no -I prefix on these.

EFI_CPPFLAGS

Flags passed to gcc regardless of the build target.

EFI_CFLAGS

Flags passed to gcc for building any binary target.  Defaults to $(EFI_CPPFLAGS) $(EFI_ARCH_CFLAGS).

EFI_LDSCRIPT

The linker script passed to ld -T for linking .efi.so build targets. Defaults to /usr/lib/gnuefi/$(EFI_ARCH)/efi.lds.

EFI_LIBGCC

The path to libgcc.  Defaults to the result of $(EFI_CC) $(EFI_ARCH_3264) -print-libgcc-file-name

EFI_LDFLAGS

Other command line to pass to ld before object names. Defaults to -nostdlib --warn-common --no-undefined --fatal-warnings --build-id=sha1 -shared -Bsymbolic --no-warn-rwx-segments  -L/usr/lib/gnuefi/$(EFI_ARCH) /usr/lib/gnuefi/$(EFI_ARCH)/crt0.o

EFI_CCLDFLAGS

Normally derived from $(EFI_LDFLAGS).

EFI_LDLIBS

Libraries to pass to ld after target object names.  Defaults to -lefi -lgnuefi $(EFI_LIBGCC) -T $(EFI_LDSCRIPT)

EFI_CCLDLIBS

Derived from $(EFI_LDLIBS).

EFI_ARFLAGS

Flags to pass to ar to make a .efi.a target.  Defaults to "rDv".

EFI_ASFLAGS

Flags to pass to gcc to make a .efi.o object from a .S file.

EFI_OBJCOPY_FLAGS

Flags to pass to objcopy to make a .efi binary target.  Defaults to --file-alignment 512 --section-alignment 4096 -D

EFI_BIN_SECTIONS

Names of sections to go into .efi binary targets.  If you have special sections, add them here.

EFI_DEBUG_SECTIONS

Names of sections to go into .efi.debug targets.  If you have special debug sections, add them here.

In addition, there are several make rules defined, which those variables affect

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

efi_clean :

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:

p include efi.mk
p all : foo.efi
p %.efi.o : | EFI_CFLAGS+=-DWEIRD_SECTION_NAME=\".weird\"
p foo.efi : | EFI_BIN_SECTIONS+=.weird
foo.efi.so : foo.efi.o bar.efi.o
p clean : efi_clean

p 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/.

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

Authors

Peter Jones <pjones@redhat.com>

Info

Thu Nov 21 2019