-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
233 lines (183 loc) · 5.6 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# SPDX-License-Identifier: GPL-2.0-only
VERSION := 1.6
# Check make version
MIN_MAKE_VERSION = 3.81
ifneq ($(firstword $(sort $(MAKE_VERSION) $(MIN_MAKE_VERSION))),$(MIN_MAKE_VERSION))
$(error GNU Make >= $(MIN_MAKE_VERSION) is required. You are running version $(MAKE_VERSION))
endif
PHONY += all
all:
# Do not use make's built-in rules and variables; this increases performance
# and avoids hard-to-debug behavior;
MAKEFLAGS += -rR
ifeq ("$(origin V)", "command line")
UNPH_VERBOSE = $V
endif
ifndef UNPH_VERBOSE
UNPH_VERBOSE = 0
endif
ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
quiet := silent_
Q = @
else ifneq ($(UNPH_VERBOSE),1)
quiet := quiet_
Q = @
else
quiet :=
Q =
endif
export quiet Q
SRCDIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
ifeq ("$(origin O)", "command line")
UNPH_OUTPUT := $O
endif
ifneq ($(UNPH_OUTPUT),)
saved-output := $(UNPH_OUTPUT)
$(shell mkdir -p $(UNPH_OUTPUT))
UNPH_OUTPUT := $(realpath $(UNPH_OUTPUT))
$(if $(UNPH_OUTPUT),,$(error cannot create output directory "$(saved-output)"))
endif
ifneq ($(filter-out $(CURDIR),$(UNPH_OUTPUT)),)
PHONY += $(MAKECMDGOALS)
$(filter-out all, $(MAKECMDGOALS)): all
all:
$(Q)$(MAKE) -C $(UNPH_OUTPUT) O=$(UNPH_OUTPUT) \
-f $(SRCDIR)/Makefile $(MAKECMDGOALS)
else # ($(filter-out $(CURDIR),$(UNPH_OUTPUT)),)
# Do not print "Entering directory ...",
# but we want to display it when entering to the output directory
# so that IDEs/editors are able to understand relative filenames.
MAKEFLAGS += --no-print-directory
ifeq ("$(origin C)", "command line")
UNPH_CHECKSRC = $(C)
endif
ifndef UNPH_CHECKSRC
UNPH_CHECKSRC = 0
endif
export UNPH_CHECKSRC
ifeq ($(SRCDIR),$(CURDIR))
srctree := .
else
$(shell ln -fns $(SRCDIR) srctree)
srctree := srctree
endif
export srctree
include $(srctree)/config.mk
CROSS_COMPILE ?= aarch64-linux-gnu-
ifeq ($(CONFIG_LLVM),y)
CLANG_FLAGS := --target=aarch64-linux-gnu
AR := llvm-ar
CC := clang
LD := ld.lld
OBJCOPY := llvm-objcopy
else
AR := $(CROSS_COMPILE)ar
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
OBJCOPY := $(CROSS_COMPILE)objcopy
endif
CPP := $(CC) -E
CHECK := sparse
UNPH_CPPFLAGS := -nostdinc -include include/generated/config.h \
-Iinclude -I$(srctree)/include
UNPH_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
-fno-common -Werror-implicit-function-declaration \
-Werror=date-time -std=gnu89 \
-ffreestanding -ffunction-sections -fdata-sections -Os \
-mgeneral-regs-only -mlittle-endian -mstrict-align \
$(CLANG_FLAGS)
UNPH_ASFLAGS := -D__ASSEMBLY__ -mlittle-endian $(CLANG_FLAGS)
UNPH_LDFLAGS := --gc-sections --build-id
OBJCOPYFLAGS := -O binary -R .comment --strip-all
CHECKFLAGS := -Wbitwise -Wno-return-void -Wcast-to-as
ifdef CONFIG_PIE
UNPH_LDFLAGS += -pie --no-dynamic-linker
endif
export CROSS_COMPILE AR AS CC CPP LD CHECK
export UNPH_CPPFLAGS UNPH_CFLAGS UNPH_ASFLAGS CHECKFLAGS
include $(srctree)/scripts/common.mk
define filechk_config
($(foreach v, $(filter CONFIG_%, $(.VARIABLES)), \
$(if $($v), echo \#define $v $(if $(filter y,$($v)),1,'$($v)');)))
endef
include/generated/config.h: FORCE
$(call filechk,config)
define filechk_version
echo \#define VERSION \"$(VERSION)\"
endef
include/generated/version.h: FORCE
$(call filechk,version)
PHONY += prepare
prepare: include/generated/config.h include/generated/version.h
board-$(CONFIG_SOC_LD11) += ld11_ref ld11_global
board-$(CONFIG_SOC_LD20) += ld20_ref ld20_global \
ld21_ref ld21_global
board-$(CONFIG_SOC_PXS3) += pxs3_ref
board-$(CONFIG_SOC_NX1) += nx1_ref
timestamp := common/timestamp.o
lds := common/uniphier.lds
objs := link.a
elfs := $(patsubst %,bl_%.elf, $(board-y))
bins := $(patsubst %,bl_%.bin, $(board-y))
have-cmd-files := $(elfs) $(bins)
all: $(bins)
@:
quiet_cmd_link = LD $@
cmd_link = $(LD) $(UNPH_LDFLAGS) -o $@ \
-e $(patsubst bl_%.elf,entry_%,$@) -T $(lds) \
$(timestamp) --whole-archive $(objs)
quiet_cmd_objcopy = OBJCOPY $@
cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $< $@
$(bins): %.bin: %.elf FORCE
$(call if_changed,objcopy)
$(elfs): $(objs) $(timestamp) $(lds) FORCE
$(call if_changed,link)
$(timestamp): $(objs) $(lds)
$(Q)$(MAKE) $(build)=$(@D) $@
link.a $(lds): descend
PHONY += descend
descend: prepare
$(Q)$(MAKE) $(build)=.
FIND_IGNORE := -name .git -prune -o
quiet_cmd_clean = $(if $(wildcard $($2)),CLEAN $(wildcard $($2)))
cmd_clean = rm -rf $($2)
clean-files := include/generated
PHONY += clean
clean:
$(Q)$(MAKE) $(clean)=.
$(call cmd,clean,clean-files)
@find . $(FIND_IGNORE) \
\( -name '*.[aios]' -o -name '*.elf' -o -name '*.bin' \
-o -name '.*.cmd' -o -name '.*.d' \) \
-type f -print | xargs rm -f
distclean-files := tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
PHONY += distclean
distclean: clean
$(call cmd,clean,distclean-files)
@find . $(FIND_IGNORE) \
\( -name '*.orig' -o -name '*.rej' -o -name '*~' \
-o -name '*.bak' -o -name '#*#' \) \
-type f -print | xargs rm -f
PHONY += help
help:
@echo "Generic targets:"
@echo " all - Build all board images"
@echo " clean - Remove all build artifacts"
@echo " distclean - clean + remove editor back, patch, tag files"
ifneq ($(bins),)
@echo ""
@echo "Individual board targets:"
@$(foreach b, $(bins), echo " $b";)
endif
# Single targets
single-targets := $(filter-out $(objs), $(filter %.i %o %s, $(MAKECMDGOALS)))
$(single-targets): prepare FORCE
$(Q)$(MAKE) $(build)=$(patsubst %/,%, $(dir $@)) $@
cmd_files := $(wildcard $(foreach f,$(have-cmd-files),$(dir $f).$(notdir $f).cmd))
ifneq ($(cmd_files),)
include $(cmd_files)
endif
endif # ($(filter-out $(CURDIR),$(UNPH_OUTPUT)),)
PHONY += FORCE
FORCE:
.PHONY: $(PHONY)