3 # Common make rules for building with gnu-efi
6 # This program is licensed under the terms of the GNU GPL, version 3,
7 # or (at your option) any later version.
8 # You should have received a copy of the GNU General Public License
9 # along with this program. If not, see <http://www.gnu.org/licenses/>.
11 # This file contains make definitions common to several (or all) of the make
12 # files in the rEFInd code subdirectories. Some options are specific to
13 # particular architectures or build systems and others are more universal.
16 # Environment definitions -- where stuff is and what sort of system is being
17 # used to compile rEFInd....
20 EFIINC = /usr/include/efi
25 # Comment out above and uncomment below if using locally-compiled GNU-EFI....
26 #EFIINC = /usr/local/include/efi
27 #GNUEFILIB = /usr/local/lib
28 #EFILIB = /usr/local/lib
29 #EFICRT0 = /usr/local/lib
31 HOSTARCH = $(shell uname -m | sed s,i[3456789]86,ia32,)
34 # Note: EDK2BASE is definted in master Makefile and exported
35 #EDK2BASE = /usr/local/UDK2014/MyWorkSpace
36 GENFW = $(EDK2BASE)/BaseTools/Source/C/bin/GenFw
38 ifeq ($(ARCH),aarch64)
39 CC = $(prefix)aarch64-linux-gnu-gcc
40 AS = $(prefix)aarch64-linux-gnu-as
41 LD = $(prefix)aarch64-linux-gnu-ld
42 AR = $(prefix)aarch64-linux-gnu-ar
43 RANLIB = $(prefix)aarch64-linux-gnu-ranlib
44 OBJCOPY = $(prefix)aarch64-linux-gnu-objcopy
50 RANLIB = $(prefix)ranlib
51 OBJCOPY = $(prefix)objcopy
54 ifeq ($(MAKEWITH),TIANO)
55 # Below file defines TARGET (RELEASE or DEBUG) and TOOL_CHAIN_TAG (GCC44, GCC45, GCC46, or GCC47)
56 include $(EDK2BASE)/Conf/target.txt
63 # ...for both GNU-EFI and TianoCore....
64 OPTIMFLAGS = -Os -fno-strict-aliasing
65 CFLAGS = $(OPTIMFLAGS) -fno-stack-protector -fshort-wchar -Wall
68 GNUEFI_CFLAGS = -fpic -I$(EFIINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)/protocol -I../include -I../refind -I../libeg -I../mok
70 # ...and for TianoCore....
71 TIANO_INCLUDE_DIRS = -I $(EDK2BASE)/MdePkg \
72 -I $(EDK2BASE)/MdePkg/Include \
73 -I $(EDK2BASE)/MdeModulePkg/ \
74 -I $(EDK2BASE)/MdeModulePkg/Include \
75 -I $(EDK2BASE)/IntelFrameworkPkg/Include \
76 -I $(EDK2BASE)/MdePkg/Include/$(ARCHDIR) \
88 GNUEFI_LDSCRIPT = $(EFICRT0)/elf_$(ARCH)_efi.lds
89 CRTOBJS = $(EFICRT0)/crt0-efi-$(ARCH).o
90 GNUEFI_LDFLAGS = -T $(GNUEFI_LDSCRIPT) -shared -Bsymbolic -nostdlib -L$(EFILIB) -L$(GNUEFILIB) $(CRTOBJS)
91 GNUEFI_LIBS = -lefi -lgnuefi $(shell $(CC) -print-libgcc-file-name)
92 #LIBS = -lefi -lgnuefi $(shell $(CC) $(ARCH3264) -print-libgcc-file-name)
94 # ...and for TianoCore....
96 TIANO_LDSCRIPT = $(EDK2BASE)/BaseTools/Scripts/gcc4.4-ld-script
97 TIANO_LDFLAGS = -nostdlib -n -q --gc-sections --script=$(EDK2BASE)/BaseTools/Scripts/gcc4.4-ld-script \
98 --entry $(ENTRYPOINT) -u $(ENTRYPOINT) -m $(LD_CODE)
101 # objcopy flags for GNU-EFI
104 FORMAT = --target=efi-app-$(ARCH)
105 FORMAT_DRIVER = --target=efi-bsdrv-$(ARCH)
108 # Modifications on a per-architecture basis....
111 ifeq ($(ARCH),x86_64)
112 GNUEFI_LDFLAGS += -znocombreloc -zdefs
114 ARCH_CFLAGS = -DEFIX64 -DEFI_FUNCTION_WRAPPER -m64 -mno-red-zone
115 ifeq ($(MAKEWITH),TIANO)
116 ARCH_CFLAGS += -mcmodel=large "-DEFIAPI=__attribute__((ms_abi))"
125 GNUEFI_LDFLAGS += -znocombreloc -zdefs
127 # In practice, cross-compiling filesystem drivers works, but not the main
129 ifeq ($(HOSTARCH),x86_64)
130 GNUEFILIB := $(GNUEFILIB)32
131 EFILIB := $(EFILIB)32
132 EFICRT0 := $(EFICRT0)32
135 ARCH_CFLAGS = -m32 -DEFI32 -malign-double
142 ifeq ($(ARCH), aarch64)
143 GNUEFI_CFLAGS += -DEFIAARCH64
145 FORMAT_DRIVER = -O binary
146 SUBSYSTEM_LDFLAG = -defsym=EFI_SUBSYSTEM=0xa
147 LDFLAGS += --warn-common --no-undefined --fatal-warnings
149 ARCH_CFLAGS = -fno-merge-constants -ffreestanding -DEFIAARCH64
150 ifeq ($(MAKEWITH),TIANO)
151 ARCH_CFLAGS += -mcmodel=large -Wno-address -Wno-missing-braces -Wno-array-bounds -ffunction-sections -fdata-sections
153 ifeq ($(MAKEWITH),GNUEFI)
154 ARCH_CFLAGS += -fno-stack-check
162 # GNU-EFI compilation path uses .o files for compiled object code
164 $(CC) $(CFLAGS) $(ARCH_CFLAGS) $(GNUEFI_CFLAGS) $(LOCAL_GNUEFI_CFLAGS) \
165 -D__MAKEWITH_GNUEFI -DREFIND_VERSION=$(REFIND_VERSION) -c $< -o $@
167 # TianoCore compilation path uses .obj files for compiled object code
169 $(CC) $(CFLAGS) $(ARCH_CFLAGS) $(TIANO_INCLUDE_DIRS) -DNO_BUILTIN_VA_FUNCS \
170 -D__MAKEWITH_TIANO -DREFIND_VERSION=$(REFIND_VERSION) -c $< -o $@
172 # rules for EFI applications
174 ifneq (,$(filter %.efi,$(TARGET)))
176 SHLIB_TARGET = $(subst .efi,.so,$(TARGET))
181 # rules for libraries
183 ifneq (,$(filter %.a,$(TARGET)))
193 # rm -f $(TARGET) *~ *.so $(OBJS) *.efi *.obj refind_*.txt refind_*.dll *.lib