-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
145 lines (103 loc) · 3.5 KB
/
Makefile
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
APP_NAME ?= kernel
DIR_NAME = kernel
PROJ_FILES = ../
BIN_NAME = $(APP_NAME).bin
HEX_NAME = $(APP_NAME).hex
ELF_NAME = $(APP_NAME).elf
IMAGE_TYPE = IMAGE_TYPE0
VERSION = 1
#############################
-include $(PROJ_FILES)/m_config.mk
-include $(PROJ_FILES)/m_generic.mk
# use an app-specific build dir
APP_BUILD_DIR = $(BUILD_DIR)/$(DIR_NAME)
BUILD_DIR ?= $(PROJ_FILE)build
AFLAGS += -I$(PROJ_FILES)include/generated
EXTRA_LDFLAGS ?= -Tkernel.ld
LDFLAGS += $(EXTRA_LDFLAGS) -L$(APP_BUILD_DIR) $(AFLAGS_GCC) -fno-builtin -nostdlib -nostartfiles -Xlinker
LD_LIBS = -lkernel -L$(APP_BUILD_DIR)/Ada/lib
LD_LIBS += -lgnat -L$(BUILD_DIR)/kernel/libgnat
SOC_ASM := startup.S
SOC_DIR := src/arch/socs/$(SOC)
SOC_OBJ := $(patsubst %.S,$(APP_BUILD_DIR)/asm/%.o,$(SOC_ASM))
# all files in Ada dir will replace C equivalent
ALIB = $(APP_BUILD_DIR)/Ada/lib/libkernel.a
ADIR = $(APP_BUILD_DIR)/Ada/lib
OUT_DIRS = $(dir $(KERNEL_OBJ)) $(dir $(ALIB))
LDSCRIPT_NAME = $(APP_BUILD_DIR)/$(APP_NAME).ld
# file to (dist)clean
# objects and compilation related
TODEL_CLEAN += $(OBJ) $(ALDIR) $(ALIB) $(DEP) $(LDSCRIPT_NAME)
# targets
TODEL_DISTCLEAN += $(APP_BUILD_DIR)
.PHONY: __clean __distclean doc prove libgnat
#############################################################
# build targets (driver, core, SoC, Board... and local)
# App C sources files
# kernel C sources files
default: all
ifeq (,$(CONFIG_PROJ_FILES))
# let's detect if the kernel is trying to be compiled out of any SDK...
all:
@echo "The Ewok kernel is not made to be compiled out of any SDK"
@echo "please use the following command:"
@echo " repo init -u https://github.com/wookey-project/manifest.git -m default.xml"
@echo " repo sync"
@echo
@echo "This will create a wookey directory in which the whole SDK (including kernel)"
@echo "is downloaded and can be compiled"
else
all: prepare $(APP_BUILD_DIR) libgnat kernel
endif
doc:
$(Q)$(MAKE) BUILDDIR=../$(APP_BUILD_DIR)/doc -C doc html latexpdf
libgnat:
$(Q)$(MAKE) -C libgnat all
prepare:
@mkdir -p src/generated
show:
$(Q)$(MAKE) -C src show
prove:
$(Q)$(MAKE) -C $@ all
__clean: libkernel.gpr
$(call cmd,ada_clean)
-rm src/generated/*
-rm $(APP_BUILD_DIR)/$(BIN_NAME) $(HEX_NAME) $(SOC_OBJ)
__distclean: libkernel.gpr
$(call cmd,ada_distclean)
kernel: $(APP_BUILD_DIR)/$(ELF_NAME) $(APP_BUILD_DIR)/$(HEX_NAME)
$(ADIR):
$(call cmd,mkdir)
$(ALIB): $(ADIR) libkernel
libkernel: libkernel.gpr
$(call cmd,ada_lib)
sanitize: $(SRC)
clang -target armv7-m -mfloat-abi=hard -mcpu=cortex-m4 $(CLANG_CFLAGS) --analyze $(SRC)
# only for ASM startup file
$(SOC_OBJ): $(SOC_DIR)/$(SOC_ASM)
$(call if_changed,cc_o_asm)
# LDSCRIPT. All are built in one time
$(LDSCRIPT_NAME):
$(call if_changed,k_ldscript)
# ELF
$(APP_BUILD_DIR)/$(ELF_NAME): $(LDSCRIPT_NAME) $(SOC_OBJ) $(ALIB)
$(call if_changed,link_o_target)
# HEX
$(APP_BUILD_DIR)/$(HEX_NAME): $(APP_BUILD_DIR)/$(ELF_NAME)
$(call if_changed,objcopy_ihex)
# BIN
$(APP_BUILD_DIR)/$(BIN_NAME): $(APP_BUILD_DIR)/$(ELF_NAME)
$(call if_changed,objcopy_bin)
$(APP_BUILD_DIR):
$(call cmd,mkdir)
#
# As any modification in the user apps permissions or configuration impact the kernel
# generated headers, the kernel headers and as a consequence the kernel binaries need
# to be built again. We decide to require a kernel rebuilt at each all target to be
# sure that the last potential configuration or userspace layout upgrade is taken into
# account in the kernel
#
clean_headers:
-rm src/generated/*
rm -rf $(APP_BUILD_DIR)/kernel.*.hex
rm -rf $(APP_BUILD_DIR)/*.elf