summaryrefslogtreecommitdiffstats
path: root/GNU_efi_HelloWorld/example_Makefile
blob: f62df60646b519513f4f9c60087e29839b2e28d8 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# /phoenix/kernel/boot/Makefile
#
# This file is a part of Phoenix operating system.
# Copyright (c) 2011-2012, Artyom Lebedev <artyom.lebedev@gmail.com>
# All rights reserved.
# See COPYING file for copyright details.

include $(PHOENIX_ROOT)/make/makevar.mak

LOADER_BINARY = phoenix.efi

COMPILE_DIR = build
OBJ_DIR = $(COMPILE_DIR)/$(PHOENIX_TARGET)

SUBDIRS = gnuefi lib lib/runtime lib/x86_64 loader \
	$(PHOENIX_ROOT)/lib/common $(PHOENIX_ROOT)/lib/elf

EFI_IMAGE = $(OBJ_DIR)/$(LOADER_BINARY)
EFI_DEBUG_IMAGE = $(OBJ_DIR)/debug.$(LOADER_BINARY)
ELF_IMAGE = $(OBJ_DIR)/elf_image.so

SRCS = $(foreach dir,$(SUBDIRS),$(wildcard $(dir)/*.S $(dir)/*.c  $(dir)/*.cpp))

$(foreach dir,$(SUBDIRS),$(eval vpath %.S $(dir)) $(eval vpath %.c $(dir)) $(eval vpath %.cpp $(dir)))

OBJS = $(foreach src,$(SRCS), \
	$(OBJ_DIR)/$(patsubst %.cpp,%.o,$(patsubst %.c,%.o,$(patsubst %.S,%.o,$(notdir $(src))))))
DEPS = $(OBJS:.o=.d)

CFLAGS = $(GLOBAL_C_FLAGS) $(C_STANDARD) -Wno-pointer-sign

CPP_FLAGS = $(GLOBAL_CXX_FLAGS) $(CXX_STANDARD) $(CXX_RESTRICTIONS) \
	-fno-exceptions -fno-rtti

COMMON_FLAGS = $(GLOBAL_FLAGS) -fpic -Wall -Werror -fshort-wchar \
	-fno-strict-aliasing -fno-merge-constants -DEFI_FUNCTION_WRAPPER \
	-mno-red-zone -DCONFIG_x86_64 -DBOOT_LOADER -DEFI_APP \
	-DKERNEL_ADDRESS=$(KERNEL_ADDRESS)

SECTIONS = .text .sdata .data .dynamic .dynsym .rel .rela .reloc
DEBUG_SECTIONS = .debug_info .debug_abbrev .debug_loc .debug_aranges \
	.debug_line .debug_macinfo .debug_str 

ifeq ($(PHOENIX_TARGET),RELEASE)
COMMON_FLAGS += -O2
else ifeq ($(PHOENIX_TARGET),DEBUG)
COMMON_FLAGS += -ggdb3 -O0 -DDEBUG -DEFI_DEBUG=1
else
$(error Target not supported: $(PHOENIX_TARGET))
endif

INCLUDE_DIRS = inc inc/protocol inc/x86_64 lib \
	$(PHOENIX_ROOT)/kernel/sys $(PHOENIX_ROOT)/kernel/sys/arch/$(PHOENIX_ARCH) \
	$(PHOENIX_ROOT)/include $(PHOENIX_ROOT)/lib/elf

IFLAGS = $(foreach incdir,$(INCLUDE_DIRS),-I$(incdir))

LD_SCRIPT = gnuefi/elf_x86_64_efi.lds

LDFLAGS = -nostdlib -T $(LD_SCRIPT) -shared -Bsymbolic --unresolved-symbols=report-all

.PHONY: all clean

all: $(EFI_IMAGE) $(EFI_DEBUG_IMAGE)

# include dependencies if exist
-include $(DEPS)

$(EFI_IMAGE): $(ELF_IMAGE)
	$(OBJCOPY) $(foreach sec,$(SECTIONS),-j $(sec)) --target=efi-app-x86_64 $< $@
	
$(EFI_DEBUG_IMAGE): $(ELF_IMAGE)
	$(OBJCOPY) $(foreach sec,$(SECTIONS) $(DEBUG_SECTIONS),-j $(sec)) --target=efi-app-x86_64 $< $@

$(ELF_IMAGE): $(OBJ_DIR) $(OBJS)
	$(LD) $(LDFLAGS) $(OBJS) -o $@

$(OBJ_DIR)/%.o: %.S
	$(CC) -DCONFIG_x86_64 -c -o $@ $<
	
$(OBJ_DIR)/%.o: %.c
	$(CC) $(IFLAGS) $(COMMON_FLAGS) $(CFLAGS) -c -o $@ $<
	$(CC) -MM -MT '$@' $(IFLAGS) $(COMMON_FLAGS) $(CFLAGS) -c -o $(@:.o=.d) $<

$(OBJ_DIR)/%.o: %.cpp
	$(CC) $(IFLAGS) $(COMMON_FLAGS) $(CPP_FLAGS) -c -o $@ $<
	$(CC) -MM -MT '$@' $(IFLAGS) $(COMMON_FLAGS) $(CPP_FLAGS) -c -o $(@:.o=.d) $<

$(COMPILE_DIR):
	if [ ! -d $@ ]; then mkdir $@; fi

$(OBJ_DIR): $(COMPILE_DIR)
	if [ ! -d $@ ]; then mkdir $@; fi

clean:
	$(RM) -rf $(COMPILE_DIR)