efi.mk(3)
π efi.mk(3) β the group-chat guide
okay so bestie, welcome to efi.mk(3), straight out of the Library Functions Manual β¨ this whole page is literally about one makefile include that makes EFI binaries happen. buckle up π
πΈ NAME πΈ
efi.mk β the makefile include that builds EFI binaries for you, no cap π
β¨ SYNOPSIS β¨
include efi.mk
that's it. that's the whole vibe check. one line and you're in π«Ά
π DESCRIPTION π
So the gnu-efi library ships a set of makefiles that produce EFI binaries on the supported platforms, plus a whole bunch of make variables you can set to control how each step gets built π₯ You can set these in your makefile or on the command line β but ngl they're normally set to reasonable defaults already, so most of the time you're just gonna use the += operator (like in the EXAMPLES section below) rather than fully replacing them. Replacement is a whole thing; appending is the main character move π
π§ make variables
EFI_ARCH_CFLAGSβ architecture-specificgcccommand line options for building a.efi.oπ¦EFI_ARCH_LDFLAGSβ architecture-specificldcommand line options for building the.efi.soπEFI_ARCH_FORMATβ architecture-specificobjcopyarguments for building the final.efibinary βCROSS_COMPILEβ the compiler prefix for cross-compilation. like, for example,"aarch64-linux-gnu-"πEFI_CCβ the C compiler. defaults to either$(CROSS_COMPILE)gccor$(CROSS_COMPILE)clang, depending on what$(CC)was set to whengnu-efiwas built πEFI_HOSTCCβ defaults to whatever$(CC)was set to whengnu-efiwas built πEFI_HOSTARCHβ one ofaa64,arm,ia32,ia64,x64, ormips64el, representing the EFI architecture name of the host machine during the build π₯οΈEFI_ARCHβ one ofaa64,arm,ia32,ia64,x64, ormips64el, representing the EFI architecture name of the target π―EFI_BFDARCHβ the architecture name for the BFD target forobjcopyπEFI_ARCH_3264β usually empty; if you're cross compiling, this will default to e.g.-m64if you're building for an x64 target on an i686 host π€―EFI_CC_INCLUDESβ the list of default include paths for the compiler, as agcccommand 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-Iprefix on these β οΈEFI_INCLUDESβ thegnu-efiinclude paths. note that there is no-Iprefix on these either πEFI_CPPFLAGSβ flags passed togccregardless of the build target πEFI_CFLAGSβ flags passed togccfor building any binary target. defaults to$(EFI_CPPFLAGS) $(EFI_ARCH_CFLAGS)π₯EFI_LDSCRIPTβ the linker script passed told -Tfor linking.efi.sobuild targets. defaults to/usr/lib/gnuefi/$(EFI_ARCH)/efi.ldsπEFI_LIBGCCβ the path tolibgcc. defaults to the result of$(EFI_CC) $(EFI_ARCH_3264) -print-libgcc-file-nameπ§EFI_LDFLAGSβ other command line to pass toldbefore 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πEFI_CCLDFLAGSβ normally derived from$(EFI_LDFLAGS)πΈEFI_LDLIBSβ libraries to pass toldafter target object names. defaults to-lefi -lgnuefi $(EFI_LIBGCC) -T $(EFI_LDSCRIPT)πEFI_CCLDLIBSβ derived from$(EFI_LDLIBS)π«ΆEFI_ARFLAGSβ flags to pass toarto make a.efi.atarget. defaults to"rDv"ποΈEFI_ASFLAGSβ flags to pass togccto make a.efi.oobject from a.Sfile βοΈEFI_OBJCOPY_FLAGSβ flags to pass toobjcopyto make a.efibinary target. defaults to--file-alignment 512 --section-alignment 4096 -DβοΈEFI_BIN_SECTIONSβ names of sections to go into.efibinary targets. if you have special sections, add them here πEFI_DEBUG_SECTIONSβ names of sections to go into.efi.debugtargets. if you have special debug sections, add them here π
π¦ the make rules
in addition, there are several make rules defined, which those variables affect as appropriate:
%.efi : %.efi.soβ build a.efibinary β¨%.efi.debug : %efi.soβ build debuginfo π%.efi.so :β build the intermediate.efi.soto be linked as a.efibinary. add.ofiles as dependencies to a concrete.efi.sorule 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.cfile π%.efi.o : %.Sβ build an object file from a.Sfile πefi_clean :β remove all files in the current working directory with the suffixes.efi,.efi.a,.efi.debug,.efi.o, or.efi.so. the ultimate glow-up cleanse π§Ό
π EXAMPLES π
ok so here's 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> β thank you icon, we stan π«Ά
and that's the whole page bestie, go forth and build some EFI binaries π β¨
okay and for the cute sign-off β this page is dated Thu Nov 21 2019, and it's from the efi.mk(3) manual, so that's the source + version + date combo, mwah π bye!!
π¦ where this page comes from
- centos-stream 9: gnu-efi-devel 1:3.0.11-10.el9 Β· BSD
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms