Debian Codegraph @

payloads/libpayload/Makefile

raw symbols SCIP
1 ##
2 ##
3 ## Copyright (C) 2008 Advanced Micro Devices, Inc.
4 ## Copyright (C) 2008 Uwe Hermann <[email protected]>
5 ## Copyright (C) 2009-2010 coresystems GmbH
6 ## Copyright (C) 2011 secunet Security Networks AG
7 ##
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted provided that the following conditions
10 ## are met:
11 ## 1. Redistributions of source code must retain the above copyright
12 ## notice, this list of conditions and the following disclaimer.
13 ## 2. Redistributions in binary form must reproduce the above copyright
14 ## notice, this list of conditions and the following disclaimer in the
15 ## documentation and/or other materials provided with the distribution.
16 ## 3. The name of the author may not be used to endorse or promote products
17 ## derived from this software without specific prior written permission.
18 ##
19 ## THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 ## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 ## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 ## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 ## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 ## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 ## SUCH DAMAGE.
30 ##
31
32 ifneq ($(words $(CURDIR)),1)
33 $(error ERROR: Path to the main directory cannot contain spaces)
34 endif
35
36 ifeq ($(INNER_STATIC_ANALYSIS),y)
37 CC_real:=$(CC)
38 endif
39
40 export top := $(CURDIR)
41 export coreboottop ?= $(abspath $(top)/../../)
42 export src := src
43 export srck := $(abspath $(top)/../../util/kconfig)
44 export obj ?= build
45 export objutil ?= $(obj)/util
46 export objk := $(objutil)/lp_kconfig
47 export absobj := $(abspath $(obj))
48 VBOOT_SOURCE ?= $(coreboottop)/3rdparty/vboot
49
50 export KCONFIG_AUTOHEADER := $(obj)/config.h
51 export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
52 export KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
53 export KCONFIG_SPLITCONFIG := $(obj)/config/
54 export KCONFIG_TRISTATE := $(obj)/tristate.conf
55 export KCONFIG_NEGATIVES := 1
56 export KBUILD_KCONFIG := Kconfig
57 export CONFIG_ := CONFIG_LP_
58
59 # directory containing the toplevel Makefile.mk
60 TOPLEVEL := .
61
62 CONFIG_LP_SHELL := sh
63 KBUILD_DEFCONFIG ?= configs/defconfig
64 UNAME_RELEASE := $(shell uname -r)
65 DOTCONFIG ?= .config
66 KCONFIG_CONFIG = $(DOTCONFIG)
67 export KCONFIG_CONFIG
68 HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
69 MAKEFLAGS += -rR --no-print-directory
70
71 # Make is silent per default, but 'make V=1' will show all compiler calls.
72 Q:=@
73 ifneq ($(V),1)
74 ifneq ($(Q),)
75 .SILENT:
76 endif
77 endif
78
79 CPP:= $(CC) -x assembler-with-cpp -DASSEMBLY -E
80 HOSTCC = gcc
81 HOSTCXX = g++
82 HOSTCFLAGS := -I$(srck) -I$(objk) -g
83 HOSTCXXFLAGS := -I$(srck) -I$(objk)
84 HOSTAS ?= as
85 HOSTLD ?= ld
86 HOSTNM ?= nm
87 HOSTOBJCOPY ?= objcopy
88 HOSTOBJDUMP ?= objdump
89 HOSTREADELF ?= readelf
90 HOSTSTRIP ?= strip
91 HOSTAR ?= ar
92
93 DOXYGEN := doxygen
94 DOXYGEN_OUTPUT_DIR := doxygen
95
96 all: real-all
97
98 ifeq ($(INNER_STATIC_ANALYSIS),y)
99 CC:=$(CC_real)
100 HOSTCC:=$(CC_real) --hostcc
101 HOSTCXX:=$(CC_real) --hostcxx
102 endif
103
104 # This include must come _before_ the pattern rules below!
105 # Order _does_ matter for pattern rules.
106 include $(srck)/Makefile.mk
107
108 include $(HAVE_DOTCONFIG)
109
110 ARCHDIR-$(CONFIG_LP_ARCH_ARM) := arm
111 ARCHDIR-$(CONFIG_LP_ARCH_ARM64) := arm64
112 ARCHDIR-$(CONFIG_LP_ARCH_X86) := x86
113 ARCHDIR-$(CONFIG_LP_ARCH_MOCK) := mock
114
115 ARCH-y := $(ARCHDIR-y)
116
117 # If architecture folder name is different from xcompile architecture name,
118 # override here.
119 ARCH-$(CONFIG_LP_ARCH_ARM) := arm
120 ARCH-$(CONFIG_LP_ARCH_ARM64) := arm64
121 ARCH-$(CONFIG_LP_ARCH_X86_32) := x86_32
122 ARCH-$(CONFIG_LP_ARCH_X86_64) := x86_64
123 ARCH-$(CONFIG_LP_ARCH_MOCK) := mock
124
125 # Five cases where we don't need fully populated $(obj) lists:
126 # 1. when no .config exists
127 # 2. when make config (in any flavour) is run
128 # 3. when make distclean is run
129 # 4. when make help% or make clean% is run
130 # 5. when make %-test or make %-tests or make %coverage-report is run
131 # Don't waste time on reading all Makefiles in these cases
132 ifeq ($(strip $(HAVE_DOTCONFIG)),)
133 NOCOMPILE := 1
134 endif
135 ifneq ($(MAKECMDGOALS),)
136 ifneq ($(filter %config %clean clean-% help%,$(MAKECMDGOALS)),)
137 NOCOMPILE := 1
138 endif
139 ifneq ($(filter %clean help% clean%, $(MAKECMDGOALS)),)
140 UNIT_TEST := 1
141 endif
142 endif
143
144 ifneq ($(filter help%, $(MAKECMDGOALS)),)
145 NOCOMPILE := 1
146 UNIT_TEST := 1
147 else
148 ifneq ($(filter %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
149 ifneq ($(filter-out %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
150 $(error Cannot mix unit-tests targets with other targets)
151 endif
152 NOCOMPILE :=
153 UNIT_TEST := 1
154 endif
155 endif
156
157 xcompile ?= $(obj)/xcompile
158 $(xcompile): $(top)/../../util/xcompile/xcompile
159 $< $(XGCCPATH) > [email protected]
160 \mv -f [email protected] $@ 2> /dev/null
161
162 ifeq ($(NOCOMPILE),1)
163 include $(TOPLEVEL)/Makefile.mk
164 include $(TOPLEVEL)/tests/Makefile.mk
165 real-all: config
166
167 else
168
169 ifeq ($(CONFIG_LP_ARCH_MOCK),y)
170
171 # Create empty xcompile to satisfy install script
172 $(shell echo '' > $(xcompile))
173
174 CC := $(HOSTCC)
175 CC-mock := $(HOSTCC)
176 AS := $(HOSTAS)
177 AS-mock := $(HOSTAS)
178 LD := $(HOSTLD)
179 LD-mock := $(HOSTLD)
180 NM := $(HOSTNM)
181 NM-mock := $(HOSTNM)
182 OBJCOPY := $(HOSTOBJCOPY)
183 OBJCOPY-mock := $(HOSTOBJCOPY)
184 OBJDUMP := $(HOSTOBJDUMP)
185 OBJDUMP-mock := $(HOSTOBJDUMP)
186 READELF := $(HOSTREADELF)
187 READELF-mock := $(HOSTEADELF)
188 STRIP := $(HOSTSTRIP)
189 STRIP-mock := $(HOSTSTRIP)
190 AR := $(HOSTAR)
191 AR-mock := $(HOSTAR)
192 else
193
194 # in addition to the dependency below, create the file if it doesn't exist
195 # to silence stupid warnings about a file that would be generated anyway.
196 $(if $(wildcard $(xcompile)),,$(shell \
197 mkdir -p $(dir $(xcompile)) && \
198 $(top)/../../util/xcompile/xcompile $(XGCCPATH) > $(xcompile) || rm -f $(xcompile)))
199
200 include $(xcompile)
201
202 ifneq ($(XCOMPILE_COMPLETE),1)
203 $(shell rm -f $(xcompile))
204 $(error $(xcompile) deleted because it's invalid. \
205 Restarting the build should fix that, or explain the problem)
206 endif
207
208 CC := $(CC_$(ARCH-y))
209 AS := $(AS_$(ARCH-y))
210 LD := $(LD_$(ARCH-y))
211 NM := $(NM_$(ARCH-y))
212 OBJCOPY := $(OBJCOPY_$(ARCH-y))
213 OBJDUMP := $(OBJDUMP_$(ARCH-y))
214 READELF := $(READELF_$(ARCH-y))
215 STRIP := $(STRIP_$(ARCH-y))
216 AR := $(AR_$(ARCH-y))
217 endif
218
219 CFLAGS += -std=gnu11 $(CFLAGS_$(ARCH-y))
220
221 ifeq ($(CONFIG_LP_COMPILER_LLVM_CLANG),y)
222 CC:=clang
223 ifneq ($(CONFIG_LP_ARCH_MOCK),y)
224 CC += -m32
225 endif
226 HOSTCC:=clang
227 endif
228
229 ifeq ($(CONFIG_LP_CCACHE),y)
230 CCACHE:=$(word 1,$(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH)))))
231 ifeq ($(CCACHE),)
232 $(error ccache selected, but not found in PATH)
233 endif
234 CCACHE:=CCACHE_COMPILERCHECK=content CCACHE_BASEDIR=$(top) $(CCACHE)
235 CC := $(CCACHE) $(CC)
236 HOSTCC := $(CCACHE) $(HOSTCC)
237 HOSTCXX := $(CCACHE) $(HOSTCXX)
238 endif
239
240 strip_quotes = $(subst ",,$(subst \",,$(1)))
241
242 # The primary target needs to be here before we include the
243 # other files
244
245 ifeq ($(INNER_STATIC_ANALYSIS),y)
246 CONFIG_LP_STATIC_ANALYSIS__ENABLE:=
247 endif
248
249 ifeq ($(CONFIG_LP_STATIC_ANALYSIS_ENABLE),y)
250 ifneq ($(CONFIG_LP_STATIC_ANALYSIS_REPORT_LOCATION),)
251 CONFIG_LP_STATIC_ANALYSIS_LOCATION:=-o $(CONFIG_LP_STATIC_ANALYSIS_REPORT_LOCATION)
252 endif
253 real-all:
254 find src -name '*.c' -o -name '*.h' | xargs clang-tidy $(CONFIG_LP_CLANG_TIDY_CHECKS)
255 $(MAKE) INNER_STATIC_ANALYSIS=y
256 else
257 real-all: real-target
258 endif
259
260 # must come rather early
261 .SECONDEXPANSION:
262
263 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG)
264 $(MAKE) CONFIG_=CONFIG_LP_ olddefconfig
265 $(MAKE) CONFIG_=CONFIG_LP_ syncconfig
266
267 # Add a new class of source/object files to the build system
268 add-class= \
269 $(eval $(1)-srcs:=) \
270 $(eval $(1)-objs:=) \
271 $(eval classes+=$(1))
272
273 # Special classes are managed types with special behaviour
274 # On parse time, for each entry in variable $(1)-y
275 # a handler $(1)-handler is executed with the arguments:
276 # * $(1): directory the parser is in
277 # * $(2): current entry
278 add-special-class= \
279 $(eval $(1):=) \
280 $(eval special-classes+=$(1))
281
282 # Clean -y variables, include Makefile.mk
283 # Add paths to files in X-y to X-srcs
284 # Add subdirs-y to subdirs
285 includemakefiles= \
286 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
287 $(eval -include $(1)) \
288 $(foreach class,$(classes-y), $(call add-class,$(class))) \
289 $(foreach special,$(special-classes), \
290 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
291 $(foreach class,$(classes), \
292 $(eval $(class)-srcs+= \
293 $$(subst $(absobj)/,$(obj)/, \
294 $$(subst $(top)/,, \
295 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
296 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
297
298
299 # For each path in $(subdirs) call includemakefiles
300 # Repeat until subdirs is empty
301 evaluate_subdirs= \
302 $(eval cursubdirs:=$(subdirs)) \
303 $(eval subdirs:=) \
304 $(foreach dir,$(cursubdirs), \
305 $(eval $(call includemakefiles,$(dir)/Makefile.mk))) \
306 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
307
308 # collect all object files eligible for building or run unit-tests
309 ifneq ($(UNIT_TEST),1)
310 subdirs:=$(TOPLEVEL)
311 $(eval $(call evaluate_subdirs))
312 else
313 include $(TOPLEVEL)/tests/Makefile.mk
314 endif
315
316 # Converts one or more source file paths to the corresponding build/ paths.
317 # $1 lib name
318 # $2 file path (list)
319 src-to-obj=\
320 $(addsuffix .$(1).o,\
321 $(basename \
322 $(addprefix $(obj)/,\
323 $(subst $(coreboottop)/,coreboot/,$(2)))))
324 $(foreach class,$(classes),$(eval $(class)-objs+=$(call src-to-obj,$(class),$($(class)-srcs))))
325
326 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
327 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
328 alldirs:=$(sort $(abspath $(dir $(allobjs))))
329
330 # macro to define template macros that are used by use_template macro
331 define create_cc_template
332 # $1 obj class
333 # $2 source suffix (c, S)
334 # $3 additional compiler flags
335 # $4 additional dependencies
336 ifn$(EMPTY)def $(1)-objs_$(2)_template
337 de$(EMPTY)fine $(1)-objs_$(2)_template
338 $$(call src-to-obj,$(1), $$(1).$(2)): $$(1).$(2) $(obj)/libpayload-config.h $(4)
339 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
340 $(CC) $(3) -MMD $$$$(CFLAGS) $(EXTRA_CFLAGS) -c -o $$$$@ $$$$<
341 en$(EMPTY)def
342 end$(EMPTY)if
343 endef
344
345 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
346 $(foreach class,$(classes), \
347 $(foreach type,$(call filetypes-of-class,$(class)), \
348 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps)))))
349
350 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
351 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
352
353 DEPENDENCIES = $($(filter %.o,%(allobjs)):.o=.d)
354 -include $(DEPENDENCIES)
355
356 printall:
357 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
358 @echo alldirs:=$(alldirs)
359 @echo allsrcs=$(allsrcs)
360 @echo DEPENDENCIES=$(DEPENDENCIES)
361 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
362
363 endif
364
365 $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(obj) $(objk)/lxdialog $(additional-dirs) $(alldirs))
366
367 cscope:
368 cscope -bR
369
370 doxy: doxygen
371 doxygen:
372 $(DOXYGEN) Doxyfile
373
374 doxyclean: doxygen-clean
375 doxygen-clean:
376 rm -rf $(DOXYGEN_OUTPUT_DIR)
377
378 clean-for-update: doxygen-clean clean-for-update-target
379 rm -f $(allobjs) $(xcompile)
380 rm -f $(DEPENDENCIES)
381 rmdir -p $(alldirs) 2>/dev/null >/dev/null || true
382
383 clean: clean-for-update clean-target
384 rm -f .ccwrap junit_config junit_config.old
385 rm -rf $(obj)
386
387 clean-cscope:
388 rm -f cscope.out
389
390 distclean: clean-cscope clean
391 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile junit.xml
392
393 .PHONY: $(PHONY) clean clean-cscope cscope distclean doxygen doxy