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 = -I$(EFIINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)/protocol -I../include -I../refind -I../libeg -I../mok
69 #GNUEFI_CFLAGS = -I$(EFIINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)/protocol -I. -I./../include -I./../libeg -I./../mok -I../include -I../refind -I../libeg
71 # ...and for TianoCore....
72 TIANO_INCLUDE_DIRS = -I $(EDK2BASE)/MdePkg \
73 -I $(EDK2BASE)/MdePkg/Include \
74 -I $(EDK2BASE)/MdeModulePkg/ \
75 -I $(EDK2BASE)/MdeModulePkg/Include \
76 -I $(EDK2BASE)/IntelFrameworkPkg/Include \
77 -I $(EDK2BASE)/MdePkg/Include/$(ARCHDIR) \
89 GNUEFI_LDSCRIPT = $(EFICRT0)/elf_$(ARCH)_efi.lds
90 CRTOBJS = $(EFICRT0)/crt0-efi-$(ARCH).o
91 GNUEFI_LDFLAGS = -T $(GNUEFI_LDSCRIPT) -shared -Bsymbolic -nostdlib -L$(EFILIB) -L$(GNUEFILIB) $(CRTOBJS)
92 GNUEFI_LIBS = -lefi -lgnuefi $(shell $(CC) -print-libgcc-file-name)
93 #LIBS = -lefi -lgnuefi $(shell $(CC) $(ARCH3264) -print-libgcc-file-name)
95 # ...and for TianoCore....
97 TIANO_LDSCRIPT = $(EDK2BASE)/BaseTools/Scripts/gcc4.4-ld-script
98 TIANO_LDFLAGS = -nostdlib -n -q --gc-sections --script=$(EDK2BASE)/BaseTools/Scripts/gcc4.4-ld-script \
99 --entry $(ENTRYPOINT) -u $(ENTRYPOINT) -m $(LD_CODE)
104 # objcopy flags for GNU-EFI
107 FORMAT = --target=efi-app-$(ARCH)
108 FORMAT_DRIVER = --target=efi-bsdrv-$(ARCH)
112 # Modifications on a per-architecture basis....
115 ifeq ($(ARCH),x86_64)
116 # CFLAGS += -DEFI_FUNCTION_WRAPPER
117 # GNUEFI_CFLAGS += -DEFIX64
118 GNUEFI_LDFLAGS += -znocombreloc -zdefs
120 ARCH_CFLAGS = -DEFIX64 -DEFI_FUNCTION_WRAPPER -m64 -mno-red-zone
121 ifeq ($(MAKEWITH),TIANO)
122 ARCH_CFLAGS += -mcmodel=large "-DEFIAPI=__attribute__((ms_abi))"
124 ifeq ($(MAKEWITH),GNUEFI)
132 # ifeq ($(HOSTARCH),ia32)
135 # GNUEFILIB := $(GNUEFILIB)64
136 # EFILIB := $(EFILIB)64
137 # EFICRT0 := $(EFICRT0)64
142 # GNUEFI_CFLAGS += -DEFI32 -malign-double
143 GNUEFI_LDFLAGS += -znocombreloc -zdefs
145 ifeq ($(HOSTARCH),x86_64)
148 GNUEFILIB := $(GNUEFILIB)32
149 EFILIB := $(EFILIB)32
150 EFICRT0 := $(EFICRT0)32
153 ARCH_CFLAGS = -m32 -DEFI32 -malign-double
154 ifeq ($(MAKEWITH),GNUEFI)
163 ifeq ($(ARCH), aarch64)
164 # CFLAGS += -fno-stack-check
165 GNUEFI_CFLAGS += -DEFIAARCH64
167 FORMAT_DRIVER = -O binary
168 SUBSYSTEM_LDFLAG = -defsym=EFI_SUBSYSTEM=0xa
169 LDFLAGS += --warn-common --no-undefined --fatal-warnings
171 ARCH_CFLAGS = -fno-merge-constants -ffreestanding -DEFIAARCH64
172 ifeq ($(MAKEWITH),TIANO)
173 ARCH_CFLAGS += -mcmodel=large -Wno-address -Wno-missing-braces -Wno-array-bounds -ffunction-sections -fdata-sections
175 ifeq ($(MAKEWITH),GNUEFI)
176 ARCH_CFLAGS += -fno-stack-check
184 # ifneq (,$(findstring FreeBSD,$(OS)))
185 # ifeq ($(ARCH),x86_64)
186 # LDSCRIPT = $(EFICRT0)/elf_$(ARCH)_fbsd_efi.lds
188 # LDSCRIPT = $(EFICRT0)/elf_$(ARCH)_efi.lds
191 # LDSCRIPT = $(EFICRT0)/elf_$(ARCH)_efi.lds
199 $(CC) $(CFLAGS) $(ARCH_CFLAGS) $(GNUEFI_CFLAGS) $(LOCAL_GNUEFI_CFLAGS) \
200 -D__MAKEWITH_GNUEFI -DREFIND_VERSION=$(REFIND_VERSION) -c $< -o $@
203 $(CC) $(CFLAGS) $(ARCH_CFLAGS) $(TIANO_INCLUDE_DIRS) -DNO_BUILTIN_VA_FUNCS \
204 -D__MAKEWITH_TIANO -DREFIND_VERSION=$(REFIND_VERSION) -c $< -o $@
206 # rules for EFI applications
208 ifneq (,$(filter %.efi,$(TARGET)))
210 SHLIB_TARGET = $(subst .efi,.so,$(TARGET))
215 # rules for libraries
217 ifneq (,$(filter %.a,$(TARGET)))
227 # rm -f $(TARGET) *~ *.so $(OBJS) *.efi *.obj refind_*.txt refind_*.dll *.lib