]> code.delx.au - refind/blob - Make.common
Added remaining main project files
[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 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 ASFLAGS = $(ARCH3264)
20 LDFLAGS = -nostdlib -znocombreloc
21
22 prefix = /usr/bin/
23 CC = $(prefix)gcc
24 AS = $(prefix)as
25 LD = $(prefix)ld
26 AR = $(prefix)ar
27 RANLIB = $(prefix)ranlib
28 OBJCOPY = $(prefix)objcopy
29
30 ifeq ($(ARCH),ia64)
31 # EFI specs allows only lower floating point partition to be used
32 CFLAGS += -frename-registers -mfixed-range=f32-f127
33 endif
34
35 ifeq ($(ARCH),x86_64)
36 CFLAGS += -DEFI_FUNCTION_WRAPPER
37 CPPFLAGS += -DEFIX64
38
39 ifeq ($(HOSTARCH),ia32)
40 ARCH3264 = -m64
41
42 GNUEFILIB := $(GNUEFILIB)64
43 EFILIB := $(EFILIB)64
44 EFICRT0 := $(EFICRT0)64
45 endif
46 endif
47
48 ifeq ($(ARCH),ia32)
49 CPPFLAGS += -DEFI32
50
51 ifeq ($(HOSTARCH),x86_64)
52 ARCH3264 = -m32
53
54 GNUEFILIB := $(GNUEFILIB)32
55 EFILIB := $(EFILIB)32
56 EFICRT0 := $(EFICRT0)32
57 endif
58 endif
59
60
61 CRTOBJS = $(EFICRT0)/crt0-efi-$(ARCH).o
62
63 ifneq (,$(findstring FreeBSD,$(OS)))
64 ifeq ($(ARCH),x86_64)
65 LDSCRIPT = $(EFICRT0)/elf_$(ARCH)_fbsd_efi.lds
66 else
67 LDSCRIPT = $(EFICRT0)/elf_$(ARCH)_efi.lds
68 endif
69 else
70 LDSCRIPT = $(EFICRT0)/elf_$(ARCH)_efi.lds
71 endif
72
73 LDFLAGS += -T $(LDSCRIPT) -shared -Bsymbolic -L$(EFILIB) -L$(GNUEFILIB) $(CRTOBJS)
74 LIBS = -lefi -lgnuefi $(shell $(CC) $(ARCH3264) -print-libgcc-file-name)
75 FORMAT = efi-app-$(ARCH)
76
77
78 # general rules
79
80 %.o: %.c
81 $(CC) $(LOCAL_CPPFLAGS) $(CPPFLAGS) $(LOCAL_CFLAGS) $(CFLAGS) -c $< -o $@
82
83 # rules for EFI applications
84
85 ifneq (,$(filter %.efi,$(TARGET)))
86
87 SHLIB_TARGET = $(subst .efi,.so,$(TARGET))
88
89 $(SHLIB_TARGET): $(OBJS)
90 $(LD) $(LOCAL_LDFLAGS) $(LDFLAGS) $(OBJS) -o $@ $(LOCAL_LIBS) $(LIBS)
91
92 $(TARGET): $(SHLIB_TARGET)
93 $(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel \
94 -j .rela -j .reloc --target=$(FORMAT) $< $@
95
96 endif
97
98 # rules for libraries
99
100 ifneq (,$(filter %.a,$(TARGET)))
101
102 $(TARGET): $(OBJS)
103 $(AR) cq $@ $(OBJS)
104
105 endif
106
107 # utility rules
108
109 clean:
110 rm -f $(TARGET) *~ *.so $(OBJS)
111
112 # EOF