]> code.delx.au - refind/blob - Make.common
Split off fwupx64.efi file from main loaders into second-row loaders;
[refind] / Make.common
1 #
2 # Make.common
3 # Common make rules for building with gnu-efi
4 #
5
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/>.
10
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.
14
15 #
16 # Environment definitions -- where stuff is and what sort of system is being
17 # used to compile rEFInd....
18 #
19
20 EFIINC = /usr/include/efi
21 GNUEFILIB = /usr/lib
22 EFILIB = /usr/lib
23 EFICRT0 = /usr/lib
24
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
30
31 HOSTARCH = $(shell uname -m | sed s,i[3456789]86,ia32,)
32 ARCH ?= $(HOSTARCH)
33
34 # Note: EDK2BASE is definted in master Makefile and exported
35 #EDK2BASE = /usr/local/UDK2014/MyWorkSpace
36 GENFW = $(EDK2BASE)/BaseTools/Source/C/bin/GenFw
37 prefix = /usr/bin/
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
45 else
46 CC = $(prefix)gcc
47 AS = $(prefix)as
48 LD = $(prefix)ld
49 AR = $(prefix)ar
50 RANLIB = $(prefix)ranlib
51 OBJCOPY = $(prefix)objcopy
52 endif
53
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
57 endif
58
59 #
60 # C compiler flags
61 #
62
63 # ...for both GNU-EFI and TianoCore....
64 OPTIMFLAGS = -Os -fno-strict-aliasing
65 CFLAGS = $(OPTIMFLAGS) -fno-stack-protector -fshort-wchar -Wall
66
67 # ...for GNU-EFI....
68 GNUEFI_CFLAGS = -fpic -I$(EFIINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)/protocol -I../include -I../refind -I../libeg -I../mok
69
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) \
77 -I .. \
78 -I ../refind \
79 -I ../libeg \
80 -I ../include \
81 -I ../mok
82 #
83 # Linker flags
84 #
85
86 # for GNU-EFI....
87 SUBSYSTEM_LDFLAG =
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)
93
94 # ...and for TianoCore....
95 ENTRYPOINT=efi_main
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)
99
100 #
101 # objcopy flags for GNU-EFI
102 #
103
104 FORMAT = --target=efi-app-$(ARCH)
105 FORMAT_DRIVER = --target=efi-bsdrv-$(ARCH)
106
107 #
108 # Modifications on a per-architecture basis....
109 #
110
111 ifeq ($(ARCH),x86_64)
112 GNUEFI_LDFLAGS += -znocombreloc -zdefs
113
114 ARCH_CFLAGS = -DEFIX64 -DEFI_FUNCTION_WRAPPER -m64 -mno-red-zone
115 ifeq ($(MAKEWITH),TIANO)
116 ARCH_CFLAGS += -mcmodel=large "-DEFIAPI=__attribute__((ms_abi))"
117 endif
118 ARCHDIR = X64
119 UC_ARCH = X64
120 FILENAME_CODE = x64
121 LD_CODE = elf_x86_64
122 endif
123
124 ifeq ($(ARCH),ia32)
125 GNUEFI_LDFLAGS += -znocombreloc -zdefs
126
127 # In practice, cross-compiling filesystem drivers works, but not the main
128 # rEFInd binary....
129 ifeq ($(HOSTARCH),x86_64)
130 GNUEFILIB := $(GNUEFILIB)32
131 EFILIB := $(EFILIB)32
132 EFICRT0 := $(EFICRT0)32
133 endif
134
135 ARCH_CFLAGS = -m32 -DEFI32 -malign-double
136 ARCHDIR = Ia32
137 UC_ARCH = IA32
138 FILENAME_CODE = ia32
139 LD_CODE = elf_i386
140 endif
141
142 ifeq ($(ARCH), aarch64)
143 GNUEFI_CFLAGS += -DEFIAARCH64
144 FORMAT = -O binary
145 FORMAT_DRIVER = -O binary
146 SUBSYSTEM_LDFLAG = -defsym=EFI_SUBSYSTEM=0xa
147 LDFLAGS += --warn-common --no-undefined --fatal-warnings
148
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
152 endif
153 ifeq ($(MAKEWITH),GNUEFI)
154 ARCH_CFLAGS += -fno-stack-check
155 endif
156 ARCHDIR = AArch64
157 UC_ARCH = AARCH64
158 FILENAME_CODE = aa64
159 LD_CODE = aarch64elf
160 endif
161
162 # GNU-EFI compilation path uses .o files for compiled object code
163 %.o: %.c
164 $(CC) $(CFLAGS) $(ARCH_CFLAGS) $(GNUEFI_CFLAGS) $(LOCAL_GNUEFI_CFLAGS) \
165 -D__MAKEWITH_GNUEFI -DREFIND_VERSION=$(REFIND_VERSION) -c $< -o $@
166
167 # TianoCore compilation path uses .obj files for compiled object code
168 %.obj: %.c
169 $(CC) $(CFLAGS) $(ARCH_CFLAGS) $(TIANO_INCLUDE_DIRS) -DNO_BUILTIN_VA_FUNCS \
170 -D__MAKEWITH_TIANO -DREFIND_VERSION=$(REFIND_VERSION) -c $< -o $@
171
172 # rules for EFI applications
173
174 ifneq (,$(filter %.efi,$(TARGET)))
175
176 SHLIB_TARGET = $(subst .efi,.so,$(TARGET))
177
178 endif
179
180
181 # rules for libraries
182
183 ifneq (,$(filter %.a,$(TARGET)))
184
185 $(TARGET): $(OBJS)
186 $(AR) cq $@ $(OBJS)
187
188 endif
189
190 # utility rules
191
192 #clean:
193 # rm -f $(TARGET) *~ *.so $(OBJS) *.efi *.obj refind_*.txt refind_*.dll *.lib
194
195 # EOF