-
Notifications
You must be signed in to change notification settings - Fork 1
/
Make.common
217 lines (176 loc) · 6.61 KB
/
Make.common
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#
# Make.common
# Common make rules for building with gnu-efi
#
# This program is licensed under the terms of the GNU GPL, version 3,
# or (at your option) any later version.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This file contains make definitions common to several (or all) of the make
# files in the rEFInd code subdirectories. Some options are specific to
# particular architectures or build systems and others are more universal.
#
# Environment definitions -- where stuff is and what sort of system is being
# used to compile rEFInd....
#
EFIINC = /usr/include/efi
GNUEFILIB = /usr/lib
EFILIB = /usr/lib
EFICRT0 = /usr/lib
# Below are good for compiling with Fedora on x86-64....
#EFIINC = /usr/include/efi
#GNUEFILIB = /usr/lib64
#EFILIB = /usr/lib64
#EFICRT0 = /usr/lib64/gnuefi
# Comment out above and uncomment below if using locally-compiled GNU-EFI....
#EFIINC = /usr/local/include/efi
#GNUEFILIB = /usr/local/lib
#EFILIB = /usr/local/lib
#EFICRT0 = /usr/local/lib
# Does GNU-EFI support --target=efi-app-aarch64 with objcopy?
# This support appeared in GNU-EFI 3.0.17, so set this to "y" if using that
# version or later and compiling for ARM64; but set it to "n" if using an
# earlier version of GNU-EFI on ARM64. This option has no effect on IA32/x86
# or X64/AMD64/x86-64 systems.
GNUEFI_ARM64_TARGET_SUPPORT ?= n
HOSTARCH = $(shell uname -m | sed s,i[3456789]86,ia32,)
ARCH ?= $(HOSTARCH)
# Pointer to SBAT .csv file. First is default; uncomment second (or make your
# your own) if you build your own binary. If you make changes and build your
# own binary, creating your own file is the best practice.
REFIND_SBAT_CSV = refind-sbat.csv
#REFIND_SBAT_CSV = refind-sbat-local.csv
# Note: TIANOBASE is defined in master Makefile and exported
GENFW = $(TIANOBASE)/BaseTools/Source/C/bin/GenFw
prefix = /usr/bin/
ifeq ($(ARCH),aarch64)
CC = $(prefix)aarch64-linux-gnu-gcc
AS = $(prefix)aarch64-linux-gnu-as
LD = $(prefix)aarch64-linux-gnu-ld
AR = $(prefix)aarch64-linux-gnu-ar
RANLIB = $(prefix)aarch64-linux-gnu-ranlib
OBJCOPY = $(prefix)aarch64-linux-gnu-objcopy
else
CC = $(prefix)gcc
AS = $(prefix)as
LD = $(prefix)ld
AR = $(prefix)ar
RANLIB = $(prefix)ranlib
OBJCOPY = $(prefix)objcopy
endif
ifeq ($(MAKEWITH),TIANO)
# Below file defines TARGET (RELEASE or DEBUG) and TOOL_CHAIN_TAG (GCC44, GCC45, GCC46, or GCC47)
include $(TIANOBASE)/Conf/target.txt
endif
#
# C compiler flags
#
# ...for both GNU-EFI and TianoCore....
OPTIMFLAGS = -Os -fno-strict-aliasing -fno-tree-loop-distribute-patterns
CFLAGS = $(OPTIMFLAGS) -fno-stack-protector -fshort-wchar -Wall
# ...for GNU-EFI....
GNUEFI_CFLAGS = -fpic -I$(EFIINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)/protocol -I../include -I../refind -I../libeg -I../mok -I../gzip
# ...and for TianoCore....
TIANO_INCLUDE_DIRS = -I $(TIANOBASE)/MdePkg \
-I $(TIANOBASE)/MdePkg/Include \
-I $(TIANOBASE)/MdeModulePkg/ \
-I $(TIANOBASE)/MdeModulePkg/Include \
-I $(TIANOBASE)/IntelFrameworkPkg/Include \
-I $(TIANOBASE)/MdePkg/Include/$(ARCHDIR) \
-I .. \
-I ../refind \
-I ../libeg \
-I ../gzip \
-I ../include \
-I ../mok
#
# Linker flags
#
# for GNU-EFI....
SUBSYSTEM_LDFLAG =
GNUEFI_LDSCRIPT = $(EFICRT0)/elf_$(ARCH)_efi.lds
CRTOBJS = $(EFICRT0)/crt0-efi-$(ARCH).o
GNUEFI_LDFLAGS = -T $(GNUEFI_LDSCRIPT) -shared -Bsymbolic -nostdlib -L$(EFILIB) -L$(GNUEFILIB) $(CRTOBJS)
GNUEFI_LIBS = -lefi -lgnuefi $(shell $(CC) -print-libgcc-file-name)
#LIBS = -lefi -lgnuefi $(shell $(CC) $(ARCH3264) -print-libgcc-file-name)
# ...and for TianoCore....
ENTRYPOINT=efi_main
TIANO_LDSCRIPT = $(TIANOBASE)/BaseTools/Scripts/gcc4.9-ld-script
#TIANO_LDSCRIPT = /usr/local/UDK2014/MyWorkSpace/BaseTools/Scripts/gcc4.9-ld-script
TIANO_LDFLAGS = -nostdlib -n -q --gc-sections --script=$(TIANO_LDSCRIPT) \
--entry $(ENTRYPOINT) -u $(ENTRYPOINT) -m $(LD_CODE)
#
# objcopy flags for GNU-EFI
#
FORMAT = --target=efi-app-$(ARCH)
FORMAT_DRIVER = --target=efi-bsdrv-$(ARCH)
#
# Modifications on a per-architecture basis....
#
ifeq ($(ARCH),x86_64)
GNUEFI_LDFLAGS += -znocombreloc -zdefs
ARCH_CFLAGS = -DEFIX64 -DEFI_FUNCTION_WRAPPER -m64 -mno-red-zone
ifeq ($(MAKEWITH),TIANO)
ARCH_CFLAGS += -mcmodel=large "-DEFIAPI=__attribute__((ms_abi))"
endif
ARCHDIR = X64
UC_ARCH = X64
FILENAME_CODE = x64
LD_CODE = elf_x86_64
endif
ifeq ($(ARCH),ia32)
GNUEFI_LDFLAGS += -znocombreloc -zdefs
# In practice, cross-compiling filesystem drivers works, but not the main
# rEFInd binary....
ifeq ($(HOSTARCH),x86_64)
GNUEFILIB := $(GNUEFILIB)32
EFILIB := $(EFILIB)32
EFICRT0 := $(EFICRT0)32
endif
ARCH_CFLAGS = -m32 -DEFI32 -malign-double
ARCHDIR = Ia32
UC_ARCH = IA32
FILENAME_CODE = ia32
LD_CODE = elf_i386
endif
ifeq ($(ARCH), aarch64)
GNUEFI_CFLAGS += -DEFIAARCH64
ifeq ($(GNUEFI_ARM64_TARGET_SUPPORT),n)
FORMAT = -O binary
FORMAT_DRIVER = -O binary
endif
SUBSYSTEM_LDFLAG = -defsym=EFI_SUBSYSTEM=0xa
LDFLAGS += --warn-common --no-undefined --fatal-warnings
ARCH_CFLAGS = -fno-merge-constants -ffreestanding -DEFIAARCH64
ifeq ($(MAKEWITH),TIANO)
ARCH_CFLAGS += -mcmodel=large -Wno-address -Wno-missing-braces -Wno-array-bounds -ffunction-sections -fdata-sections
endif
ifeq ($(MAKEWITH),GNUEFI)
ARCH_CFLAGS += -fno-stack-check
endif
ARCHDIR = AArch64
UC_ARCH = AARCH64
FILENAME_CODE = aa64
LD_CODE = aarch64elf
endif
# GNU-EFI compilation path uses .o files for compiled object code
%.o: %.c
$(CC) $(CFLAGS) $(ARCH_CFLAGS) $(GNUEFI_CFLAGS) $(LOCAL_GNUEFI_CFLAGS) \
-D__MAKEWITH_GNUEFI -c $< -o $@
# TianoCore compilation path uses .obj files for compiled object code
%.obj: %.c
$(CC) $(CFLAGS) $(ARCH_CFLAGS) $(TIANO_INCLUDE_DIRS) -DNO_BUILTIN_VA_FUNCS \
-D__MAKEWITH_TIANO -c $< -o $@
# rules for EFI applications
ifneq (,$(filter %.efi,$(TARGET)))
SHLIB_TARGET = $(subst .efi,.so,$(TARGET))
endif
# rules for libraries
ifneq (,$(filter %.a,$(TARGET)))
$(TARGET): $(OBJS)
$(AR) cq $@ $(OBJS)
endif
# utility rules
#clean:
# rm -f $(TARGET) *~ *.so $(OBJS) *.efi *.obj refind_*.txt refind_*.dll *.lib
# EOF