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 ifeq ($(INNER_SCANBUILD
),y
)
36 export top
:= $(CURDIR
)
38 export srck
:= $(abspath
$(top
)/..
/..
/util
/kconfig
)
40 export objutil ?
= $(obj
)/util
41 export objk
:= $(objutil
)/lp_kconfig
43 export KCONFIG_AUTOHEADER
:= $(obj
)/config.h
44 export KCONFIG_AUTOCONFIG
:= $(obj
)/auto.conf
45 export KCONFIG_DEPENDENCIES
:= $(obj
)/auto.conf.cmd
46 export KCONFIG_SPLITCONFIG
:= $(obj
)/config
47 export KCONFIG_TRISTATE
:= $(obj
)/tristate.conf
48 export KCONFIG_NEGATIVES
:= 1
49 export Kconfig
:= Kconfig
50 export CONFIG_
:= CONFIG_LP_
52 # directory containing the toplevel Makefile.inc
56 KBUILD_DEFCONFIG ?
= configs
/defconfig
57 UNAME_RELEASE
:= $(shell uname
-r
)
59 KCONFIG_CONFIG
= $(DOTCONFIG
)
61 HAVE_DOTCONFIG
:= $(wildcard $(DOTCONFIG
))
62 MAKEFLAGS
+= -rR
--no-print-directory
64 # Make is silent per default, but 'make V=1' will show all compiler calls.
72 CPP
:= $(CC
) -x assembler-with-cpp
-DASSEMBLY
-E
75 HOSTCFLAGS
:= -I
$(srck
) -I
$(objk
) -g
76 HOSTCXXFLAGS
:= -I
$(srck
) -I
$(objk
)
79 DOXYGEN_OUTPUT_DIR
:= doxygen
83 ifeq ($(INNER_SCANBUILD
),y
)
85 HOSTCC
:=$(CC_real
) --hostcc
86 HOSTCXX
:=$(CC_real
) --hostcxx
89 # This include must come _before_ the pattern rules below!
90 # Order _does_ matter for pattern rules.
91 include $(srck
)/Makefile
93 include $(HAVE_DOTCONFIG
)
95 ARCHDIR-
$(CONFIG_LP_ARCH_ARM
) := arm
96 ARCHDIR-
$(CONFIG_LP_ARCH_ARM64
) := arm64
97 ARCHDIR-
$(CONFIG_LP_ARCH_X86
) := x86
99 ARCH-y
:= $(ARCHDIR-y
)
101 # If architecture folder name is different from xcompile architecture name,
103 ARCH-
$(CONFIG_LP_ARCH_ARM
) := arm
104 ARCH-
$(CONFIG_LP_ARCH_ARM64
) := arm64
105 ARCH-
$(CONFIG_LP_ARCH_X86
) := x86_32
107 # Three cases where we don't need fully populated $(obj) lists:
108 # 1. when no .config exists
109 # 2. when make config (in any flavour) is run
110 # 3. when make distclean is run
111 # Don't waste time on reading all Makefile.incs in these cases
112 ifeq ($(strip $(HAVE_DOTCONFIG
)),)
115 ifneq ($(MAKECMDGOALS
),)
116 ifneq ($(filter %config
%clean,$(MAKECMDGOALS
)),)
121 xcompile ?
= $(obj
)/xcompile
122 $(xcompile
): $(top
)/..
/..
/util
/xcompile
/xcompile
123 $< $(XGCCPATH
) > $@.tmp
124 \mv
-f
$@.tmp
$@
2> /dev
/null
126 ifeq ($(NOCOMPILE
),1)
127 include $(TOPLEVEL
)/Makefile.inc
132 # in addition to the dependency below, create the file if it doesn't exist
133 # to silence stupid warnings about a file that would be generated anyway.
134 $(if
$(wildcard $(xcompile
)),,$(shell \
135 mkdir
-p
$(dir $(xcompile
)) && \
136 $(top
)/..
/..
/util
/xcompile
/xcompile
$(XGCCPATH
) > $(xcompile
) ||
rm -f
$(xcompile
)))
140 ifneq ($(XCOMPILE_COMPLETE
),1)
141 $(shell rm -f
$(xcompile
))
142 $(error
$(xcompile
) deleted because it
's invalid. \
143 Restarting the build should fix that, or explain the problem)
146 CC := $(CC_$(ARCH-y))
147 AS := $(AS_$(ARCH-y))
148 LD := $(LD_$(ARCH-y))
149 NM := $(NM_$(ARCH-y))
150 OBJCOPY := $(OBJCOPY_$(ARCH-y))
151 OBJDUMP := $(OBJDUMP_$(ARCH-y))
152 READELF := $(READELF_$(ARCH-y))
153 STRIP := $(STRIP_$(ARCH-y))
154 AR := $(AR_$(ARCH-y))
156 CFLAGS += -std=gnu11 $(CFLAGS_$(ARCH-y))
158 ifneq ($(INNER_SCANBUILD),y)
159 ifeq ($(CONFIG_LP_COMPILER_LLVM_CLANG),y)
165 ifeq ($(CONFIG_LP_CCACHE),y)
166 CCACHE:=$(word 1,$(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH)))))
168 $(error ccache selected, but not found in PATH)
170 CCACHE:=CCACHE_COMPILERCHECK=content CCACHE_BASEDIR=$(top) $(CCACHE)
171 CC := $(CCACHE) $(CC)
172 HOSTCC := $(CCACHE) $(HOSTCC)
173 HOSTCXX := $(CCACHE) $(HOSTCXX)
176 strip_quotes = $(subst ",,$(subst \",,$(1)))
178 # The primary target needs to be here before we include the
181 ifeq ($(INNER_SCANBUILD),y)
182 CONFIG_LP_SCANBUILD_ENABLE:=
185 ifeq ($(CONFIG_LP_SCANBUILD_ENABLE),y)
186 ifneq ($(CONFIG_LP_SCANBUILD_REPORT_LOCATION),)
187 CONFIG_LP_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_LP_SCANBUILD_REPORT_LOCATION)
190 echo '#!/bin/sh' > .ccwrap
191 echo
'CC="$(CC)"' >> .ccwrap
192 echo
'if [ "$$1" = "--hostcc" ]; then shift; CC="$(HOSTCC)"; fi' >> .ccwrap
193 echo
'if [ "$$1" = "--hostcxx" ]; then shift; CC="$(HOSTCXX)"; fi' >> .ccwrap
194 echo
'eval $$CC $$*' >> .ccwrap
196 scan-build
$(CONFIG_LP_SCANBUILD_REPORT_LOCATION
) -analyze-headers
--use-cc
=$(top
)/.ccwrap
--use-c
++=$(top
)/.ccwrap
$(MAKE
) INNER_SCANBUILD
=y
198 real-all
: real-target
201 # must come rather early
204 $(KCONFIG_AUTOHEADER
): $(KCONFIG_CONFIG
)
207 # Add a new class of source/object files to the build system
209 $(eval
$(1)-srcs
:=) \
210 $(eval
$(1)-objs
:=) \
211 $(eval classes
+=$(1))
213 # Special classes are managed types with special behaviour
214 # On parse time, for each entry in variable $(1)-y
215 # a handler $(1)-handler is executed with the arguments:
216 # * $(1): directory the parser is in
217 # * $(2): current entry
220 $(eval special-classes
+=$(1))
222 # Clean -y variables, include Makefile.inc
223 # Add paths to files in X-y to X-srcs
224 # Add subdirs-y to subdirs
226 $(foreach class
,classes subdirs
$(classes
) $(special-classes
), $(eval
$(class
)-y
:=)) \
227 $(eval
-include $(1)) \
228 $(foreach class
,$(classes-y
), $(call add-class
,$(class
))) \
229 $(foreach special
,$(special-classes
), \
230 $(foreach item
,$($(special
)-y
), $(call
$(special
)-handler
,$(dir $(1)),$(item
)))) \
231 $(foreach class
,$(classes
), \
232 $(eval
$(class
)-srcs
+= \
234 $$(abspath
$$(addprefix $(dir $(1)),$$($(class
)-y
)))))) \
235 $(eval subdirs
+=$$(subst $(CURDIR
)/,,$$(abspath
$$(addprefix $(dir $(1)),$$(subdirs-y
)))))
237 # For each path in $(subdirs) call includemakefiles
238 # Repeat until subdirs is empty
240 $(eval cursubdirs
:=$(subdirs
)) \
242 $(foreach dir,$(cursubdirs
), \
243 $(eval
$(call includemakefiles
,$(dir)/Makefile.inc
))) \
244 $(if
$(subdirs
),$(eval
$(call evaluate_subdirs
)))
246 # collect all object files eligible for building
248 $(eval
$(call evaluate_subdirs
))
250 src-to-obj
=$(addsuffix .
$(1).o
, $(basename $(addprefix $(obj
)/, $($(1)-srcs
))))
251 $(foreach class
,$(classes
),$(eval
$(class
)-objs
:=$(call src-to-obj
,$(class
))))
253 allsrcs
:=$(foreach var
, $(addsuffix -srcs
,$(classes
)), $($(var
)))
254 allobjs
:=$(foreach var
, $(addsuffix -objs
,$(classes
)), $($(var
)))
255 alldirs
:=$(sort $(abspath
$(dir $(allobjs
))))
257 # macro to define template macros that are used by use_template macro
258 define create_cc_template
260 # $2 source suffix (c, S)
261 # $3 additional compiler flags
262 # $4 additional dependencies
263 ifn
$(EMPTY
)def
$(1)-objs_
$(2)_template
264 de
$(EMPTY
)fine
$(1)-objs_
$(2)_template
265 $(obj
)/$$(1).
$(1).o
: $$(1).
$(2) $(obj
)/libpayload-config.h
$(4)
266 @printf
" CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
267 $(CC
) $(3) -MMD
$$$$(CFLAGS
) -c
-o
$$$$@
$$$$<
272 filetypes-of-class
=$(subst .
,,$(sort $(suffix $($(1)-srcs
))))
273 $(foreach class
,$(classes
), \
274 $(foreach type
,$(call filetypes-of-class
,$(class
)), \
275 $(eval
$(call create_cc_template
,$(class
),$(type
),$($(class
)-$(type
)-ccopts
),$($(class
)-$(type
)-deps
)))))
277 foreach-src
=$(foreach file
,$($(1)-srcs
),$(eval
$(call
$(1)-objs_
$(subst .
,,$(suffix $(file
)))_template
,$(basename $(file
)))))
278 $(eval
$(foreach class
,$(classes
),$(call foreach-src
,$(class
))))
280 DEPENDENCIES
= $(allobjs
:.o
=.d
)
281 -include $(DEPENDENCIES
)
284 @
$(foreach class
,$(classes
),echo
$(class
)-objs
:=$($(class
)-objs
); )
285 @echo alldirs
:=$(alldirs
)
286 @echo allsrcs
=$(allsrcs
)
287 @echo DEPENDENCIES
=$(DEPENDENCIES
)
288 @
$(foreach class
,$(special-classes
),echo
$(class
):='$($(class))'; )
292 $(shell mkdir
-p
$(KCONFIG_SPLITCONFIG
) $(obj
) $(objk
)/lxdialog
$(additional-dirs
) $(alldirs
))
301 doxyclean
: doxygen-clean
303 rm -rf
$(DOXYGEN_OUTPUT_DIR
)
305 clean-for-update
: doxygen-clean clean-for-update-target
306 rm -f
$(allobjs
) $(xcompile
)
307 rm -f
$(DEPENDENCIES
)
308 rmdir
-p
$(alldirs
) 2>/dev
/null
>/dev
/null || true
310 clean: clean-for-update clean-target
311 rm -f .ccwrap junit_config junit_config.old
317 distclean: clean-cscope
clean
318 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig
* .ccwrap .xcompile junit.xml
320 .PHONY
: $(PHONY
) clean clean-cscope cscope
distclean doxygen doxy