3 ## Copyright (C) 2008 Advanced Micro Devices, Inc.
4 ## Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
5 ## Copyright (C) 2009-2010 coresystems GmbH
6 ## Copyright (C) 2011 secunet Security Networks AG
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted provided that the following conditions
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.
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
32 ifneq ($(words $(CURDIR
)),1)
33 $(error ERROR
: Path to the main directory cannot contain spaces
)
36 ifeq ($(INNER_SCANBUILD
),y
)
40 export top
:= $(CURDIR
)
41 export coreboottop ?
= $(abspath
$(top
)/..
/..
/)
43 export srck
:= $(abspath
$(top
)/..
/..
/util
/kconfig
)
45 export objutil ?
= $(obj
)/util
46 export objk
:= $(objutil
)/lp_kconfig
47 export absobj
:= $(abspath
$(obj
))
48 VBOOT_SOURCE ?
= $(coreboottop
)/3rdparty
/vboot
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_
59 # directory containing the toplevel Makefile.inc
63 KBUILD_DEFCONFIG ?
= configs
/defconfig
64 UNAME_RELEASE
:= $(shell uname
-r
)
66 KCONFIG_CONFIG
= $(DOTCONFIG
)
68 HAVE_DOTCONFIG
:= $(wildcard $(DOTCONFIG
))
69 MAKEFLAGS
+= -rR
--no-print-directory
71 # Make is silent per default, but 'make V=1' will show all compiler calls.
79 CPP
:= $(CC
) -x assembler-with-cpp
-DASSEMBLY
-E
82 HOSTCFLAGS
:= -I
$(srck
) -I
$(objk
) -g
83 HOSTCXXFLAGS
:= -I
$(srck
) -I
$(objk
)
87 HOSTOBJCOPY ?
= objcopy
88 HOSTOBJDUMP ?
= objdump
89 HOSTREADELF ?
= readelf
94 DOXYGEN_OUTPUT_DIR
:= doxygen
98 ifeq ($(INNER_SCANBUILD
),y
)
100 HOSTCC
:=$(CC_real
) --hostcc
101 HOSTCXX
:=$(CC_real
) --hostcxx
104 # This include must come _before_ the pattern rules below!
105 # Order _does_ matter for pattern rules.
106 include $(srck
)/Makefile.inc
108 include $(HAVE_DOTCONFIG
)
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
115 ARCH-y
:= $(ARCHDIR-y
)
117 # If architecture folder name is different from xcompile architecture name,
119 ARCH-
$(CONFIG_LP_ARCH_ARM
) := arm
120 ARCH-
$(CONFIG_LP_ARCH_ARM64
) := arm64
121 ARCH-
$(CONFIG_LP_ARCH_X86
) := x86_32
122 ARCH-
$(CONFIG_LP_ARCH_MOCK
) := mock
124 # Five cases where we don't need fully populated $(obj) lists:
125 # 1. when no .config exists
126 # 2. when make config (in any flavour) is run
127 # 3. when make distclean is run
128 # 4. when make help% or make clean% is run
129 # 5. when make %-test or make %-tests or make %coverage-report is run
130 # Don't waste time on reading all Makefile.incs in these cases
131 ifeq ($(strip $(HAVE_DOTCONFIG
)),)
134 ifneq ($(MAKECMDGOALS
),)
135 ifneq ($(filter %config
%clean clean-
% help
%,$(MAKECMDGOALS
)),)
138 ifneq ($(filter %clean help
% clean%, $(MAKECMDGOALS
)),)
143 ifneq ($(filter help
%, $(MAKECMDGOALS
)),)
147 ifneq ($(filter %-test %-tests
%coverage-report
, $(MAKECMDGOALS
)),)
148 ifneq ($(filter-out %-test %-tests
%coverage-report
, $(MAKECMDGOALS
)),)
149 $(error Cannot mix unit-tests targets with other targets
)
156 xcompile ?
= $(obj
)/xcompile
157 $(xcompile
): $(top
)/..
/..
/util
/xcompile
/xcompile
158 $< $(XGCCPATH
) > $@.tmp
159 \mv
-f
$@.tmp
$@
2> /dev
/null
161 ifeq ($(NOCOMPILE
),1)
162 include $(TOPLEVEL
)/Makefile.inc
163 include $(TOPLEVEL
)/tests
/Makefile.inc
168 ifeq ($(CONFIG_LP_ARCH_MOCK
),y
)
170 # Create empty xcompile to satisfy install script
171 $(shell echo
'' > $(xcompile
))
181 OBJCOPY
:= $(HOSTOBJCOPY
)
182 OBJCOPY-mock
:= $(HOSTOBJCOPY
)
183 OBJDUMP
:= $(HOSTOBJDUMP
)
184 OBJDUMP-mock
:= $(HOSTOBJDUMP
)
185 READELF
:= $(HOSTREADELF
)
186 READELF-mock
:= $(HOSTEADELF
)
187 STRIP
:= $(HOSTSTRIP
)
188 STRIP-mock
:= $(HOSTSTRIP
)
193 # in addition to the dependency below, create the file if it doesn't exist
194 # to silence stupid warnings about a file that would be generated anyway.
195 $(if
$(wildcard $(xcompile
)),,$(shell \
196 mkdir
-p
$(dir $(xcompile
)) && \
197 $(top
)/..
/..
/util
/xcompile
/xcompile
$(XGCCPATH
) > $(xcompile
) ||
rm -f
$(xcompile
)))
201 ifneq ($(XCOMPILE_COMPLETE
),1)
202 $(shell rm -f
$(xcompile
))
203 $(error
$(xcompile
) deleted because it
's invalid. \
204 Restarting the build should fix that, or explain the problem)
207 CC := $(CC_$(ARCH-y))
208 AS := $(AS_$(ARCH-y))
209 LD := $(LD_$(ARCH-y))
210 NM := $(NM_$(ARCH-y))
211 OBJCOPY := $(OBJCOPY_$(ARCH-y))
212 OBJDUMP := $(OBJDUMP_$(ARCH-y))
213 READELF := $(READELF_$(ARCH-y))
214 STRIP := $(STRIP_$(ARCH-y))
215 AR := $(AR_$(ARCH-y))
218 CFLAGS += -std=gnu11 $(CFLAGS_$(ARCH-y))
220 ifneq ($(INNER_SCANBUILD),y)
221 ifeq ($(CONFIG_LP_COMPILER_LLVM_CLANG),y)
223 ifneq ($(CONFIG_LP_ARCH_MOCK),y)
230 ifeq ($(CONFIG_LP_CCACHE),y)
231 CCACHE:=$(word 1,$(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH)))))
233 $(error ccache selected, but not found in PATH)
235 CCACHE:=CCACHE_COMPILERCHECK=content CCACHE_BASEDIR=$(top) $(CCACHE)
236 CC := $(CCACHE) $(CC)
237 HOSTCC := $(CCACHE) $(HOSTCC)
238 HOSTCXX := $(CCACHE) $(HOSTCXX)
241 strip_quotes = $(subst ",,$(subst \",,$(1)))
243 # The primary target needs to be here before we include the
246 ifeq ($(INNER_SCANBUILD),y)
247 CONFIG_LP_SCANBUILD_ENABLE:=
250 ifeq ($(CONFIG_LP_SCANBUILD_ENABLE),y)
251 ifneq ($(CONFIG_LP_SCANBUILD_REPORT_LOCATION),)
252 CONFIG_LP_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_LP_SCANBUILD_REPORT_LOCATION)
255 echo '#!/bin/sh' > .ccwrap
256 echo
'CC="$(CC)"' >> .ccwrap
257 echo
'if [ "$$1" = "--hostcc" ]; then shift; CC="$(HOSTCC)"; fi' >> .ccwrap
258 echo
'if [ "$$1" = "--hostcxx" ]; then shift; CC="$(HOSTCXX)"; fi' >> .ccwrap
259 echo
'eval $$CC $$*' >> .ccwrap
261 scan-build
$(CONFIG_LP_SCANBUILD_REPORT_LOCATION
) -analyze-headers
--use-cc
=$(top
)/.ccwrap
--use-c
++=$(top
)/.ccwrap
$(MAKE
) INNER_SCANBUILD
=y
263 real-all
: real-target
266 # must come rather early
269 $(KCONFIG_AUTOHEADER
): $(KCONFIG_CONFIG
)
270 $(MAKE
) CONFIG_
=CONFIG_LP_ olddefconfig
271 $(MAKE
) CONFIG_
=CONFIG_LP_ syncconfig
273 # Add a new class of source/object files to the build system
275 $(eval
$(1)-srcs
:=) \
276 $(eval
$(1)-objs
:=) \
277 $(eval classes
+=$(1))
279 # Special classes are managed types with special behaviour
280 # On parse time, for each entry in variable $(1)-y
281 # a handler $(1)-handler is executed with the arguments:
282 # * $(1): directory the parser is in
283 # * $(2): current entry
286 $(eval special-classes
+=$(1))
288 # Clean -y variables, include Makefile.inc
289 # Add paths to files in X-y to X-srcs
290 # Add subdirs-y to subdirs
292 $(foreach class
,classes subdirs
$(classes
) $(special-classes
), $(eval
$(class
)-y
:=)) \
293 $(eval
-include $(1)) \
294 $(foreach class
,$(classes-y
), $(call add-class
,$(class
))) \
295 $(foreach special
,$(special-classes
), \
296 $(foreach item
,$($(special
)-y
), $(call
$(special
)-handler
,$(dir $(1)),$(item
)))) \
297 $(foreach class
,$(classes
), \
298 $(eval
$(class
)-srcs
+= \
299 $$(subst $(absobj
)/,$(obj
)/, \
301 $$(abspath
$$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class
)-y
)))))))) \
302 $(eval subdirs
+=$$(subst $(CURDIR
)/,,$$(wildcard $$(abspath
$$(addprefix $(dir $(1)),$$(subdirs-y
))))))
305 # For each path in $(subdirs) call includemakefiles
306 # Repeat until subdirs is empty
308 $(eval cursubdirs
:=$(subdirs
)) \
310 $(foreach dir,$(cursubdirs
), \
311 $(eval
$(call includemakefiles
,$(dir)/Makefile.inc
))) \
312 $(if
$(subdirs
),$(eval
$(call evaluate_subdirs
)))
314 # collect all object files eligible for building or run unit-tests
315 ifneq ($(UNIT_TEST
),1)
317 $(eval
$(call evaluate_subdirs
))
319 include $(TOPLEVEL
)/tests
/Makefile.inc
322 # Converts one or more source file paths to the corresponding build/ paths.
324 # $2 file path (list)
326 $(addsuffix .
$(1).o
,\
328 $(addprefix $(obj
)/,\
329 $(subst $(coreboottop
)/,coreboot
/,$(2)))))
330 $(foreach class
,$(classes
),$(eval
$(class
)-objs
+=$(call src-to-obj
,$(class
),$($(class
)-srcs
))))
332 allsrcs
:=$(foreach var
, $(addsuffix -srcs
,$(classes
)), $($(var
)))
333 allobjs
:=$(foreach var
, $(addsuffix -objs
,$(classes
)), $($(var
)))
334 alldirs
:=$(sort $(abspath
$(dir $(allobjs
))))
336 # macro to define template macros that are used by use_template macro
337 define create_cc_template
339 # $2 source suffix (c, S)
340 # $3 additional compiler flags
341 # $4 additional dependencies
342 ifn
$(EMPTY
)def
$(1)-objs_
$(2)_template
343 de
$(EMPTY
)fine
$(1)-objs_
$(2)_template
344 $$(call src-to-obj
,$(1), $$(1).
$(2)): $$(1).
$(2) $(obj
)/libpayload-config.h
$(4)
345 @printf
" CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
346 $(CC
) $(3) -MMD
$$$$(CFLAGS
) $(EXTRA_CFLAGS
) -c
-o
$$$$@
$$$$<
351 filetypes-of-class
=$(subst .
,,$(sort $(suffix $($(1)-srcs
))))
352 $(foreach class
,$(classes
), \
353 $(foreach type
,$(call filetypes-of-class
,$(class
)), \
354 $(eval
$(call create_cc_template
,$(class
),$(type
),$($(class
)-$(type
)-ccopts
),$($(class
)-$(type
)-deps
)))))
356 foreach-src
=$(foreach file
,$($(1)-srcs
),$(eval
$(call
$(1)-objs_
$(subst .
,,$(suffix $(file
)))_template
,$(basename $(file
)))))
357 $(eval
$(foreach class
,$(classes
),$(call foreach-src
,$(class
))))
359 DEPENDENCIES
= $($(filter %.o
,%(allobjs
)):.o
=.d
)
360 -include $(DEPENDENCIES
)
363 @
$(foreach class
,$(classes
),echo
$(class
)-objs
:=$($(class
)-objs
); )
364 @echo alldirs
:=$(alldirs
)
365 @echo allsrcs
=$(allsrcs
)
366 @echo DEPENDENCIES
=$(DEPENDENCIES
)
367 @
$(foreach class
,$(special-classes
),echo
$(class
):='$($(class))'; )
371 $(shell mkdir
-p
$(KCONFIG_SPLITCONFIG
) $(obj
) $(objk
)/lxdialog
$(additional-dirs
) $(alldirs
))
380 doxyclean
: doxygen-clean
382 rm -rf
$(DOXYGEN_OUTPUT_DIR
)
384 clean-for-update
: doxygen-clean clean-for-update-target
385 rm -f
$(allobjs
) $(xcompile
)
386 rm -f
$(DEPENDENCIES
)
387 rmdir
-p
$(alldirs
) 2>/dev
/null
>/dev
/null || true
389 clean: clean-for-update clean-target
390 rm -f .ccwrap junit_config junit_config.old
396 distclean: clean-cscope
clean
397 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig
* .ccwrap .xcompile junit.xml
399 .PHONY
: $(PHONY
) clean clean-cscope cscope
distclean doxygen doxy