2 ## This file is part of the libpayload project.
4 ## Copyright (C) 2008 Advanced Micro Devices, Inc.
5 ## Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
6 ## Copyright (C) 2009-2010 coresystems GmbH
7 ## Copyright (C) 2011 secunet Security Networks AG
9 ## Redistribution and use in source and binary forms, with or without
10 ## modification, are permitted provided that the following conditions
12 ## 1. Redistributions of source code must retain the above copyright
13 ## notice, this list of conditions and the following disclaimer.
14 ## 2. Redistributions in binary form must reproduce the above copyright
15 ## notice, this list of conditions and the following disclaimer in the
16 ## documentation and/or other materials provided with the distribution.
17 ## 3. The name of the author may not be used to endorse or promote products
18 ## derived from this software without specific prior written permission.
20 ## THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 ## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 ## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 ## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 ## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 ## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 ifeq ($(INNER_SCANBUILD
),y
)
37 export top
:= $(CURDIR
)
39 export srck
:= $(abspath
$(top
)/..
/..
/util
/kconfig
)
41 export objutil ?
= $(obj
)/util
42 export objk
:= $(objutil
)/lp_kconfig
44 export KCONFIG_AUTOHEADER
:= $(obj
)/config.h
45 export KCONFIG_AUTOCONFIG
:= $(obj
)/auto.conf
46 export KCONFIG_DEPENDENCIES
:= $(obj
)/auto.conf.cmd
47 export KCONFIG_SPLITCONFIG
:= $(obj
)/config
48 export KCONFIG_TRISTATE
:= $(obj
)/tristate.conf
49 export KCONFIG_NEGATIVES
:= 1
50 export Kconfig
:= Kconfig
51 export CONFIG_
:= CONFIG_LP_
53 # directory containing the toplevel Makefile.inc
57 KBUILD_DEFCONFIG ?
= configs
/defconfig
58 UNAME_RELEASE
:= $(shell uname
-r
)
60 KCONFIG_CONFIG
= $(DOTCONFIG
)
62 HAVE_DOTCONFIG
:= $(wildcard $(DOTCONFIG
))
63 MAKEFLAGS
+= -rR
--no-print-directory
65 # Make is silent per default, but 'make V=1' will show all compiler calls.
73 CPP
:= $(CC
) -x assembler-with-cpp
-DASSEMBLY
-E
76 HOSTCFLAGS
:= -I
$(srck
) -I
$(objk
) -g
77 HOSTCXXFLAGS
:= -I
$(srck
) -I
$(objk
)
80 DOXYGEN_OUTPUT_DIR
:= doxygen
84 ifeq ($(INNER_SCANBUILD
),y
)
86 HOSTCC
:=$(CC_real
) --hostcc
87 HOSTCXX
:=$(CC_real
) --hostcxx
90 # This include must come _before_ the pattern rules below!
91 # Order _does_ matter for pattern rules.
92 include $(srck
)/Makefile
94 include $(HAVE_DOTCONFIG
)
96 ARCHDIR-
$(CONFIG_LP_ARCH_ARM
) := arm
97 ARCHDIR-
$(CONFIG_LP_ARCH_ARM64
) := arm64
98 ARCHDIR-
$(CONFIG_LP_ARCH_X86
) := x86
100 ARCH-y
:= $(ARCHDIR-y
)
102 # If architecture folder name is different from xcompile architecture name,
104 ARCH-
$(CONFIG_LP_ARCH_ARM
) := arm
105 ARCH-
$(CONFIG_LP_ARCH_ARM64
) := arm64
106 ARCH-
$(CONFIG_LP_ARCH_X86
) := x86_32
108 # Three cases where we don't need fully populated $(obj) lists:
109 # 1. when no .config exists
110 # 2. when make config (in any flavour) is run
111 # 3. when make distclean is run
112 # Don't waste time on reading all Makefile.incs in these cases
113 ifeq ($(strip $(HAVE_DOTCONFIG
)),)
116 ifneq ($(MAKECMDGOALS
),)
117 ifneq ($(filter %config
%clean,$(MAKECMDGOALS
)),)
122 ifeq ($(NOCOMPILE
),1)
123 include $(TOPLEVEL
)/Makefile.inc
128 # in addition to the dependency below, create the file if it doesn't exist
129 # to silence stupid warnings about a file that would be generated anyway.
130 $(if
$(wildcard .xcompile
)$(NOCOMPILE
),,$(eval
$(shell $(top
)/..
/..
/util
/xcompile
/xcompile
$(XGCCPATH
) > .xcompile
)))
132 .xcompile
: $(top
)/..
/..
/util
/xcompile
/xcompile
133 $< $(XGCCPATH
) > $@.tmp
134 \mv
-f
$@.tmp
$@
2> /dev
/null
138 CC
:= $(CC_
$(ARCH-y
))
139 AS
:= $(AS_
$(ARCH-y
))
140 LD
:= $(LD_
$(ARCH-y
))
141 NM
:= $(NM_
$(ARCH-y
))
142 OBJCOPY
:= $(OBJCOPY_
$(ARCH-y
))
143 OBJDUMP
:= $(OBJDUMP_
$(ARCH-y
))
144 READELF
:= $(READELF_
$(ARCH-y
))
145 STRIP
:= $(STRIP_
$(ARCH-y
))
146 AR
:= $(AR_
$(ARCH-y
))
148 CFLAGS
+= -std
=gnu11
$(CFLAGS_
$(ARCH-y
))
150 ifneq ($(INNER_SCANBUILD
),y
)
151 ifeq ($(CONFIG_LP_COMPILER_LLVM_CLANG
),y
)
157 ifeq ($(CONFIG_LP_CCACHE
),y
)
158 CCACHE
:=$(word 1,$(wildcard $(addsuffix /ccache
,$(subst :, ,$(PATH
)))))
160 $(error ccache selected
, but not found in PATH
)
162 CCACHE
:=CCACHE_COMPILERCHECK
=content CCACHE_BASEDIR
=$(top
) $(CCACHE
)
163 CC
:= $(CCACHE
) $(CC
)
164 HOSTCC
:= $(CCACHE
) $(HOSTCC
)
165 HOSTCXX
:= $(CCACHE
) $(HOSTCXX
)
168 strip_quotes
= $(subst ",,$(subst \",,$(1)))
170 # The primary target needs to be here before we include the
173 ifeq ($(INNER_SCANBUILD),y)
174 CONFIG_LP_SCANBUILD_ENABLE:=
177 ifeq ($(CONFIG_LP_SCANBUILD_ENABLE),y)
178 ifneq ($(CONFIG_LP_SCANBUILD_REPORT_LOCATION),)
179 CONFIG_LP_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_LP_SCANBUILD_REPORT_LOCATION)
182 echo '#!/bin/sh' > .ccwrap
183 echo 'CC="$(CC
)"' >> .ccwrap
184 echo 'if [ "$$1" = "--hostcc
" ]; then shift; CC="$(HOSTCC
)"; fi' >> .ccwrap
185 echo 'if [ "$$1" = "--hostcxx
" ]; then shift; CC="$(HOSTCXX
)"; fi' >> .ccwrap
186 echo 'eval $$CC $$*' >> .ccwrap
188 scan-build $(CONFIG_LP_SCANBUILD_REPORT_LOCATION) -analyze-headers --use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y
190 real-all: real-target
193 # must come rather early
196 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG)
199 # Add a new class of source/object files to the build system
201 $(eval $(1)-srcs:=) \
202 $(eval $(1)-objs:=) \
203 $(eval classes+=$(1))
205 # Special classes are managed types with special behaviour
206 # On parse time, for each entry in variable $(1)-y
207 # a handler $(1)-handler is executed with the arguments:
208 # * $(1): directory the parser is in
209 # * $(2): current entry
212 $(eval special-classes+=$(1))
214 # Clean -y variables, include Makefile.inc
215 # Add paths to files in X-y to X-srcs
216 # Add subdirs-y to subdirs
218 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
219 $(eval -include $(1)) \
220 $(foreach class,$(classes-y), $(call add-class,$(class))) \
221 $(foreach special,$(special-classes), \
222 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
223 $(foreach class,$(classes), \
224 $(eval $(class)-srcs+= \
226 $$(abspath $$(addprefix $(dir $(1)),$$($(class)-y)))))) \
227 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
229 # For each path in $(subdirs) call includemakefiles
230 # Repeat until subdirs is empty
232 $(eval cursubdirs:=$(subdirs)) \
234 $(foreach dir,$(cursubdirs), \
235 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
236 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
238 # collect all object files eligible for building
240 $(eval $(call evaluate_subdirs))
242 src-to-obj=$(addsuffix .$(1).o, $(basename $(addprefix $(obj)/, $($(1)-srcs))))
243 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class))))
245 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
246 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
247 alldirs:=$(sort $(abspath $(dir $(allobjs))))
249 # macro to define template macros that are used by use_template macro
250 define create_cc_template
252 # $2 source suffix (c, S)
253 # $3 additional compiler flags
254 # $4 additional dependencies
255 ifn$(EMPTY)def $(1)-objs_$(2)_template
256 de$(EMPTY)fine $(1)-objs_$(2)_template
257 $(obj)/$$(1).$(1).o: $$(1).$(2) $(obj)/libpayload-config.h $(4)
258 @printf " CC
$$$$(subst $$$$(obj
)/,,$$$$(@
))\n"
259 $(CC) $(3) -MMD $$$$(CFLAGS) -c -o $$$$@ $$$$<
264 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
265 $(foreach class,$(classes), \
266 $(foreach type,$(call filetypes-of-class,$(class)), \
267 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps)))))
269 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
270 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
272 DEPENDENCIES = $(allobjs:.o=.d)
273 -include $(DEPENDENCIES)
276 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
277 @echo alldirs:=$(alldirs)
278 @echo allsrcs=$(allsrcs)
279 @echo DEPENDENCIES=$(DEPENDENCIES)
280 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
284 $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(obj) $(objk)/lxdialog $(additional-dirs) $(alldirs))
293 doxyclean: doxygen-clean
295 rm -rf $(DOXYGEN_OUTPUT_DIR)
297 clean-for-update: doxygen-clean clean-for-update-target
298 rm -f $(allobjs) .xcompile
299 rm -f $(DEPENDENCIES)
300 rmdir -p $(alldirs) 2>/dev/null >/dev/null || true
302 clean: clean-for-update clean-target
303 rm -f .ccwrap junit_config junit_config.old
309 distclean: clean-cscope clean
310 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile junit.xml
312 .PHONY: $(PHONY) clean clean-cscope cscope distclean doxygen doxy