summaryrefslogtreecommitdiffstats
path: root/GNU_efi_HelloWorld/Makefile
blob: 80f1398f23a4522bca718166f8dab5bf6ff2450e (plain) (blame)
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
ARCH		= $(shell uname -m | sed s,i[3456789]86,ia32,)

OBJS		= hello.o
TARGET		= hello.efi
TARGET_DEBUG	= hello.debug

EFIINC		= /usr/include/efi
EFFINCS		= -I$(EFIINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)/protocol
EFILIB		= /usr/lib
EFI_CRT_OBJS	= $(EFILIB)/crt0-efi-$(ARCH).o
EFI_LDS		= $(EFILIB)/elf_$(ARCH)_efi.lds

CFLAGS		= $(EFFINCS) -fno-stack-protector -fpic \
			-fshort-wchar -mno-red-zone -Wall
CFLAGS		+=	-ggdb3 -O0 -DDEBUG -DEFI_DEBUG=1

ifeq ($(ARCH),x86_64)
	CFLAGS += -DEFI_FUNCTION_WRAPPER
endif

LDFLAGS		= -nostdlib -znocombreloc -T $(EFI_LDS) -shared \
		  -Bsymbolic -L $(EFILIB) $(EFI_CRT_OBJS)

SECTIONS	= .text .sdata .data .dynamic .dynsym .rel .rela .reloc

DEBUG_SECTIONS	= .debug_info .debug_abbrev .debug_aranges \
		  .debug_line .debug_str

all: clear $(TARGET) $(TARGET_DEBUG)
	cp hello.efi ../test_code/hda-contents/

hello.so: $(OBJS)
	ld $(LDFLAGS) $(OBJS) -o $@ -lefi -lgnuefi

%.efi: %.so
	objcopy $(foreach sec,$(SECTIONS),-j $(sec)) \
	--target=efi-app-$(ARCH) $^ $@

%.debug: %.so
	objcopy $(foreach sec,$(SECTIONS) $(DEBUG_SECTIONS),-j $(sec)) \
	--target=efi-app-$(ARCH) $^ $@

clear:
	rm -f *.efi
	rm -f *.debug
	rm -f *.o
	rm -f *.so