-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
182 lines (143 loc) · 5.25 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# SPDX-License-Identifier: GPL-2.0-or-later
# ==========================================================================
# System top
# ==========================================================================
include scripts/top.mk
#####################################
# Global Config #
#####################################
include $(srctree)/platform.mk
sys-include-y += include/kconfig.h \
include/compiler/compiler-attributes.h \
include/compiler/compiler-type.h \
include/compiler/compiler-gcc.h \
include/compiler/compiler.h \
include/compiler/pointer.h \
include/compiler/sections.h \
include/compiler/stringify.h
sys-include-y += include/ arch/$(arch)/ \
arch/$(arch)/include/ \
arch/$(arch)/include/generated/
optimize-flags-$(CONFIG_CC_OPTIMIZE_FOR_DEBUG) := -O0
optimize-flags-$(CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE) := -O2
optimize-flags-$(CONFIG_CC_OPTIMIZE_FOR_SIZE) := -Os
stackp-flags-y := -fno-stack-protector
stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector
stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong
sys-ccflags-y += $(optimize-flags-y) $(stackp-flags-y)
sys-ccflags-$(CONFIG_STRICT) += -Werror
sys-acflags-y += -fno-pic -fno-pie
sys-cxflags-y += -nostdinc -fno-builtin -static
sys-cxflags-y += -fno-common
sys-cxflags-y += -ffreestanding
sys-ccflags-y += -std=gnu17
sys-cxxflags-y += -std=gnu++17 -fpermissive -Wno-pointer-arith
# disable pointer signed / unsigned warnings in gcc 4.0
sys-ccflags-y += -Wno-pointer-sign
sys-acflags-y += -D__KERNEL__
sys-asflags-y += -D__ASSEMBLY__
sys-ldsflags-y += -D__ASSEMBLY__
asflags-y := $(strip $(sys-asflags-y) $(platform-asflags-y))
ccflags-y := $(strip $(sys-ccflags-y) $(platform-ccflags-y))
cxxflags-y := $(strip $(sys-cxxflags-y) $(platform-cxxflags-y))
acflags-y := $(strip $(sys-acflags-y) $(platform-acflags-y))
cxflags-y := $(strip $(sys-cxflags-y) $(platform-cxflags-y))
ldsflags-y := $(strip $(sys-ldsflags-y) $(platform-ldsflags-y))
ldflags-y := $(strip $(sys-ldflags-y) $(platform-ldflags-y))
include-direct-y := $(strip $(sys-include-y) $(platform-include-y))
lightcore-flags-y += -nostdlib --build-id=sha1
lightcore-flags-y += -e boot_head -T arch/$(arch)/kernel.lds
lightcore-flags-$(CONFIG_KERNEL_MAP) += [email protected]
lightcore-flags-y += $(platform-elfflags-y)
ifdef CONFIG_KERNEL_DEBUG
acflags-y += -g
lightcore-flags-y += -g
endif
ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
acflags-y += -ffunction-sections -fdata-sections
lightcore-flags-y += --gc-sections
endif
export CROSS_COMPILE AS CC LD
export include-direct-y
export acflags-y cxflags-y cxxflags-y
export ccflags-y asflags-y cppflags-y
export ldsflags-y ldflags-y
#####################################
# Generic headers #
#####################################
asm-generic: FORCE
$(Q)$(MAKE) $(asm-generic)=arch/$(arch)/include/generated/asm \
generic=include/asm-generic
$(Q)$(MAKE) $(asm-generic)=arch/$(arch)/include/generated/lightcore/asm \
generic=include/lightcore/asm-generic
#####################################
# Devicetree files #
#####################################
dtstree = boot/dts
%dtb: scripts_dtc
$(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
dtbs: scripts_dtc
$(Q)$(MAKE) $(build)=$(dtstree)
ifdef CONFIG_BUILTIN_DTB
build: dtbs
endif
#####################################
# Subproject #
#####################################
obj-y += arch/
obj-y += doc/logo/
obj-y += drivers/
obj-y += fs/
obj-y += init/
obj-y += ipc/
obj-y += kernel/
obj-y += lib/
obj-y += mm/
obj-y += net/
obj-$(CONFIG_KUSR) += usr/
#####################################
# Generate romdisk #
#####################################
$(obj)/boot/romdisk.cpio: $(src)/boot/romdisk/ FORCE
$(call if_changed,cpio)
ifdef CONFIG_ROMDISK
$(obj)/drivers: $(obj)/boot/romdisk.cpio FORCE
targets += boot/romdisk.cpio
endif
#####################################
# Compiler #
#####################################
lightcore-objs += built-in.o
elf-always-y += lightcore
lightcore.dump-obj += lightcore
dump-always-$(CONFIG_KERNEL_DUMP) += lightcore.dump
build/boot/kboot: build FORCE
build/boot/preload: asm-generic FORCE
kboot: build/boot/kboot FORCE
preload: build/boot/preload FORCE
tools: build/tools/kernelcrc build/tools/mkincbin FORCE
build: asm-generic scripts_basic tools FORCE
$(Q)$(MAKE) $(build)=$(srctree)
disk uboot: kboot preload FORCE
$(Q)$(MAKE) $(build)=$(srctree)/boot $@
ifdef CONFIG_PRELOAD
start: disk
else
start: uboot
endif
#####################################
# Run & Install #
#####################################
include $(srctree)/boot/run/config.mk
ckfile := $(objtree)/boot/kboot/boot.bin
ifeq ($(wildcard $(ckfile)),)
run install uninsall: FORCE
$(Q)$(ECHO) "Please run make first"
else
run: FORCE
$(Q)$(SHELL) $(srctree)/boot/run/$(run_shell)
install: FORCE
$(Q)$(SHELL) $(srctree)/boot/install.sh \
$(KERNELVERSION) $(KBOOT_IMAGE) $(INSTALL_PATH)
endif
clean-subdir-y += boot/