28045595b9eb8dafdccd133f27136ddfb8d6eb40
[refind] / Make.common
1 #
2 # Make.common
3 # Common make rules for building with gnu-efi
4 #
5
6 EFIINC = /usr/include/efi
7 GNUEFILIB = /usr/lib
8 EFILIB = /usr/lib
9 EFICRT0 = /usr/lib
10
11 # Comment out above and uncomment below if using locally-compiled GNU-EFI....
12 #EFIINC = /usr/local/include/efi
13 #GNUEFILIB = /usr/local/lib
14 #EFILIB = /usr/local/lib
15 #EFICRT0 = /usr/local/lib
16
17 HOSTARCH = $(shell uname -m | sed s,i[3456789]86,ia32,)
18 ARCH := $(HOSTARCH)
19 OS = $(shell uname -s)
20 CPPFLAGS = -I$(EFIINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)/protocol -I../include -I../refind -I../libeg -DCONFIG_$(ARCH) -D__MAKEWITH_GNUEFI
21
22 OPTIMFLAGS = -O2 -fno-strict-aliasing
23 DEBUGFLAGS = -Wall
24 #CFLAGS = $(ARCH3264) $(OPTIMFLAGS) -fpic -fshort-wchar $(DEBUGFLAGS)
25 CFLAGS = $(ARCH3264) $(OPTIMFLAGS) -fno-stack-protector -fpic -fshort-wchar $(DEBUGFLAGS)
26 ASFLAGS = $(ARCH3264)
27 export LDFLAGS = -nostdlib
28 export DRV_LDFLAGS =
29
30 prefix = /usr/bin/
31 CC = $(prefix)gcc
32 AS = $(prefix)as
33 LD = $(prefix)ld
34 AR = $(prefix)ar
35 RANLIB = $(prefix)ranlib
36 OBJCOPY = $(prefix)objcopy
37
38 ifeq ($(ARCH),ia64)
39 # EFI specs allows only lower floating point partition to be used
40 CFLAGS += -frename-registers -mfixed-range=f32-f127
41 endif
42
43 FORMAT = --target=efi-app-$(ARCH)
44 FORMAT_DRIVER = --target=efi-bsdrv-$(ARCH)
45
46 ifeq ($(ARCH),x86_64)
47 CFLAGS += -DEFI_FUNCTION_WRAPPER -mno-red-zone
48 CPPFLAGS += -DEFIX64
49 LDFLAGS += -znocombreloc -zdefs
50
51 ifeq ($(HOSTARCH),ia32)
52 ARCH3264 = -m64
53
54 GNUEFILIB := $(GNUEFILIB)64
55 EFILIB := $(EFILIB)64
56 EFICRT0 := $(EFICRT0)64
57 endif
58 endif
59
60 ifeq ($(ARCH),ia32)
61 CPPFLAGS += -DEFI32 -malign-double
62 LDFLAGS += -znocombreloc -zdefs
63
64 ifeq ($(HOSTARCH),x86_64)
65 ARCH3264 = -m32
66
67 GNUEFILIB := $(GNUEFILIB)32
68 EFILIB := $(EFILIB)32
69 EFICRT0 := $(EFICRT0)32
70 endif
71 endif
72
73 ifeq ($(ARCH), aarch64)
74 CFLAGS += -fno-stack-check -g -fno-merge-constants -ffreestanding -fno-stack-check
75 CPPFLAGS += -DEFIAARCH64
76 FORMAT = -O binary
77 FORMAT_DRIVER = -O binary
78 LDFLAGS += --defsym=EFI_SUBSYSTEM=0xa --warn-common --no-undefined --fatal-warnings
79 DRV_LDFLAGS += --defsym=EFI_SUBSYSTEM=0xb --warn-common --no-undefined --fatal-warnings
80 endif
81
82 CRTOBJS = $(EFICRT0)/crt0-efi-$(ARCH).o
83
84 ifneq (,$(findstring FreeBSD,$(OS)))
85 ifeq ($(ARCH),x86_64)
86 LDSCRIPT = $(EFICRT0)/elf_$(ARCH)_fbsd_efi.lds
87 else
88 LDSCRIPT = $(EFICRT0)/elf_$(ARCH)_efi.lds
89 endif
90 else
91 LDSCRIPT = $(EFICRT0)/elf_$(ARCH)_efi.lds
92 endif
93
94 LDFLAGS += -T $(LDSCRIPT) -shared -Bsymbolic -L$(EFILIB) -L$(GNUEFILIB) $(CRTOBJS)
95 DRV_LDFLAGS += -T $(LDSCRIPT) -shared -Bsymbolic -L$(EFILIB) -L$(GNUEFILIB) $(CRTOBJS)
96 LIBS = -lefi -lgnuefi $(shell $(CC) $(ARCH3264) -print-libgcc-file-name)
97
98
99 # general rules
100
101 %.o: %.c
102 $(CC) $(LOCAL_CPPFLAGS) $(CPPFLAGS) $(LOCAL_CFLAGS) $(CFLAGS) -c $< -o $@
103
104 # rules for EFI applications
105
106 ifneq (,$(filter %.efi,$(TARGET)))
107
108 SHLIB_TARGET = $(subst .efi,.so,$(TARGET))
109
110 endif
111
112 # rules for libraries
113
114 ifneq (,$(filter %.a,$(TARGET)))
115
116 $(TARGET): $(OBJS)
117 $(AR) cq $@ $(OBJS)
118
119 endif
120
121 # utility rules
122
123 clean:
124 rm -f $(TARGET) *~ *.so $(OBJS) *.efi *.obj refind_*.txt refind_*.dll *.lib
125
126 # EOF