]> code.delx.au - refind/blob - Make.common
New re-scan feature: Press Esc to re-scan filesystems.
[refind] / Make.common
1 #
2 # Make.common
3 # Common make rules for building with gnu-efi
4 #
5
6 EFIINC = /usr/local/include/efi
7 GNUEFILIB = /usr/local/lib
8 EFILIB = /usr/local/lib
9 EFICRT0 = /usr/local/lib
10
11 HOSTARCH = $(shell uname -m | sed s,i[3456789]86,ia32,)
12 ARCH := $(HOSTARCH)
13 OS = $(shell uname -s)
14 CPPFLAGS = -I$(EFIINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)/protocol -DCONFIG_$(ARCH)
15
16 OPTIMFLAGS = -O2 -fno-strict-aliasing
17 DEBUGFLAGS = -Wall
18 #CFLAGS = $(ARCH3264) $(OPTIMFLAGS) -fpic -fshort-wchar $(DEBUGFLAGS)
19 CFLAGS = $(ARCH3264) $(OPTIMFLAGS) -fno-stack-protector -fpic -fshort-wchar $(DEBUGFLAGS)
20 ASFLAGS = $(ARCH3264)
21 LDFLAGS = -nostdlib -znocombreloc
22
23 prefix = /usr/bin/
24 CC = $(prefix)gcc
25 AS = $(prefix)as
26 LD = $(prefix)ld
27 AR = $(prefix)ar
28 RANLIB = $(prefix)ranlib
29 OBJCOPY = $(prefix)objcopy
30
31 ifeq ($(ARCH),ia64)
32 # EFI specs allows only lower floating point partition to be used
33 CFLAGS += -frename-registers -mfixed-range=f32-f127
34 endif
35
36 ifeq ($(ARCH),x86_64)
37 CFLAGS += -DEFI_FUNCTION_WRAPPER
38 CPPFLAGS += -DEFIX64
39
40 ifeq ($(HOSTARCH),ia32)
41 ARCH3264 = -m64
42
43 GNUEFILIB := $(GNUEFILIB)64
44 EFILIB := $(EFILIB)64
45 EFICRT0 := $(EFICRT0)64
46 endif
47 endif
48
49 ifeq ($(ARCH),ia32)
50 CPPFLAGS += -DEFI32
51
52 ifeq ($(HOSTARCH),x86_64)
53 ARCH3264 = -m32
54
55 GNUEFILIB := $(GNUEFILIB)32
56 EFILIB := $(EFILIB)32
57 EFICRT0 := $(EFICRT0)32
58 endif
59 endif
60
61
62 CRTOBJS = $(EFICRT0)/crt0-efi-$(ARCH).o
63
64 ifneq (,$(findstring FreeBSD,$(OS)))
65 ifeq ($(ARCH),x86_64)
66 LDSCRIPT = $(EFICRT0)/elf_$(ARCH)_fbsd_efi.lds
67 else
68 LDSCRIPT = $(EFICRT0)/elf_$(ARCH)_efi.lds
69 endif
70 else
71 LDSCRIPT = $(EFICRT0)/elf_$(ARCH)_efi.lds
72 endif
73
74 LDFLAGS += -T $(LDSCRIPT) -shared -Bsymbolic -L$(EFILIB) -L$(GNUEFILIB) $(CRTOBJS)
75 LIBS = -lefi -lgnuefi $(shell $(CC) $(ARCH3264) -print-libgcc-file-name)
76 FORMAT = efi-app-$(ARCH)
77
78
79 # general rules
80
81 %.o: %.c
82 $(CC) $(LOCAL_CPPFLAGS) $(CPPFLAGS) $(LOCAL_CFLAGS) $(CFLAGS) -c $< -o $@
83
84 # rules for EFI applications
85
86 ifneq (,$(filter %.efi,$(TARGET)))
87
88 SHLIB_TARGET = $(subst .efi,.so,$(TARGET))
89
90 $(SHLIB_TARGET): $(OBJS)
91 $(LD) $(LOCAL_LDFLAGS) $(LDFLAGS) $(OBJS) -o $@ $(LOCAL_LIBS) $(LIBS)
92
93 $(TARGET): $(SHLIB_TARGET)
94 $(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel \
95 -j .rela -j .reloc --target=$(FORMAT) $< $@
96
97 endif
98
99 # rules for libraries
100
101 ifneq (,$(filter %.a,$(TARGET)))
102
103 $(TARGET): $(OBJS)
104 $(AR) cq $@ $(OBJS)
105
106 endif
107
108 # utility rules
109
110 clean:
111 rm -f $(TARGET) *~ *.so $(OBJS) *.efi
112
113 # EOF