2 ## This file is part of the coreboot 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 $(if
$(wildcard .xcompile
),,$(eval
$(shell bash util
/xcompile
/xcompile
$(XGCCPATH
) > .xcompile
)))
40 ifeq ($(INNER_SCANBUILD
),y
)
42 HOSTCC
:=$(CC_real
) --hostcc
43 HOSTCXX
:=$(CC_real
) --hostcxx
46 export top
:= $(CURDIR
)
48 export srck
:= $(top
)/util
/kconfig
50 export objutil ?
= $(obj
)/util
51 export objk
:= $(objutil
)/kconfig
54 export KCONFIG_AUTOHEADER
:= $(obj
)/config.h
55 export KCONFIG_AUTOCONFIG
:= $(obj
)/auto.conf
57 # directory containing the toplevel Makefile.inc
61 KBUILD_DEFCONFIG
:= configs
/defconfig
62 UNAME_RELEASE
:= $(shell uname
-r
)
64 KCONFIG_CONFIG
= $(DOTCONFIG
)
66 HAVE_DOTCONFIG
:= $(wildcard $(DOTCONFIG
))
67 MAKEFLAGS
+= -rR
--no-print-directory
69 # Make is silent per default, but 'make V=1' will show all compiler calls.
83 DOXYGEN_OUTPUT_DIR
:= doxygen
87 # This include must come _before_ the pattern rules below!
88 # Order _does_ matter for pattern rules.
89 include util
/kconfig
/Makefile
91 # Three cases where we don't need fully populated $(obj) lists:
92 # 1. when no .config exists
93 # 2. when make config (in any flavour) is run
94 # 3. when make distclean is run
95 # Don't waste time on reading all Makefile.incs in these cases
96 ifeq ($(strip $(HAVE_DOTCONFIG
)),)
99 ifneq ($(MAKECMDGOALS
),)
100 ifneq ($(filter %config
%clean,$(MAKECMDGOALS
)),)
103 ifeq ($(MAKECMDGOALS
), %clean)
108 ifeq ($(NOCOMPILE
),1)
109 include $(TOPLEVEL
)/Makefile.inc
114 include $(HAVE_DOTCONFIG
)
116 ARCHDIR-
$(CONFIG_ARCH_ARMV7
) := armv7
117 ARCHDIR-
$(CONFIG_ARCH_X86
) := x86
119 ARCH-y
:= $(ARCHDIR-y
)
121 # If architecture folder name is different from GCC binutils architecture name,
123 ARCH-
$(CONFIG_ARCH_ARMV7
) := armv7
124 ARCH-
$(CONFIG_ARCH_X86
) := i386
126 ifneq ($(INNER_SCANBUILD
),y
)
127 CC
:= $(CC_
$(ARCH-y
))
129 AS
:= $(AS_
$(ARCH-y
))
130 LD
:= $(LD_
$(ARCH-y
))
131 NM
:= $(NM_
$(ARCH-y
))
132 OBJCOPY
:= $(OBJCOPY_
$(ARCH-y
))
133 OBJDUMP
:= $(OBJDUMP_
$(ARCH-y
))
134 READELF
:= $(READELF_
$(ARCH-y
))
135 STRIP
:= $(STRIP_
$(ARCH-y
))
136 AR
:= $(AR_
$(ARCH-y
))
138 CFLAGS
+= $(CFLAGS_
$(ARCH-y
))
140 LIBGCC_FILE_NAME
:= $(shell test -r
`$(CC) -print-libgcc-file-name` && \
141 $(CC
) -print-libgcc-file-name
)
143 ifneq ($(INNER_SCANBUILD
),y
)
144 ifeq ($(CONFIG_COMPILER_LLVM_CLANG
),y
)
145 CC
:=clang
-m32
-mno-mmx
-mno-sse
150 ifeq ($(CONFIG_CCACHE
),y
)
151 CCACHE
:=$(word 1,$(wildcard $(addsuffix /ccache
,$(subst :, ,$(PATH
)))))
153 $(error ccache selected
, but not found in PATH
)
155 CCACHE
:=CCACHE_COMPILERCHECK
=content CCACHE_BASEDIR
=$(top
) $(CCACHE
)
156 CC
:= $(CCACHE
) $(CC
)
157 HOSTCC
:= $(CCACHE
) $(HOSTCC
)
158 HOSTCXX
:= $(CCACHE
) $(HOSTCXX
)
159 ROMCC
:= $(CCACHE
) $(ROMCC
)
162 strip_quotes
= $(subst ",,$(subst \",,$(1)))
164 # The primary target needs to be here before we include the
167 ifeq ($(INNER_SCANBUILD),y)
168 CONFIG_SCANBUILD_ENABLE:=
171 ifeq ($(CONFIG_SCANBUILD_ENABLE),y)
172 ifneq ($(CONFIG_SCANBUILD_REPORT_LOCATION),)
173 CONFIG_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_SCANBUILD_REPORT_LOCATION)
176 echo '#!/bin/sh' > .ccwrap
177 echo 'CC="$(CC
)"' >> .ccwrap
178 echo 'if [ "$$1" = "--hostcc
" ]; then shift; CC="$(HOSTCC
)"; fi' >> .ccwrap
179 echo 'if [ "$$1" = "--hostcxx
" ]; then shift; CC="$(HOSTCXX
)"; fi' >> .ccwrap
180 echo 'eval $$CC $$*' >> .ccwrap
182 scan-build $(CONFIG_SCANBUILD_REPORT_LOCATION) -analyze-headers --use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y
184 real-all: real-target
187 # must come rather early
193 # Add a new class of source/object files to the build system
195 $(eval $(1)-srcs:=) \
196 $(eval $(1)-objs:=) \
197 $(eval classes+=$(1))
199 # Special classes are managed types with special behaviour
200 # On parse time, for each entry in variable $(1)-y
201 # a handler $(1)-handler is executed with the arguments:
202 # * $(1): directory the parser is in
203 # * $(2): current entry
206 $(eval special-classes+=$(1))
208 # Clean -y variables, include Makefile.inc
209 # Add paths to files in X-y to X-srcs
210 # Add subdirs-y to subdirs
212 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
213 $(eval -include $(1)) \
214 $(foreach class,$(classes-y), $(call add-class,$(class))) \
215 $(foreach class,$(classes), \
216 $(eval $(class)-srcs+= \
218 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y))))))) \
219 $(foreach special,$(special-classes), \
220 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
221 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
223 # For each path in $(subdirs) call includemakefiles
224 # Repeat until subdirs is empty
226 $(eval cursubdirs:=$(subdirs)) \
228 $(foreach dir,$(cursubdirs), \
229 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
230 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
232 # collect all object files eligible for building
234 $(eval $(call evaluate_subdirs))
235 ifeq ($(FAILBUILD),1)
236 $(error cannot continue build)
239 # Eliminate duplicate mentions of source files in a class
240 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
242 src-to-obj=$(addsuffix .$(1).o, $(basename $(patsubst src/%, $(obj)/%, $($(1)-srcs))))
243 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class))))
245 # Call post-processors if they're defined
246 $(foreach class,$(classes),\
247 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
249 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
250 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
251 alldirs:=$(sort $(abspath $(dir $(allobjs))))
253 # macro to define template macros that are used by use_template macro
254 define create_cc_template
256 # $2 source suffix (c, S)
257 # $3 additional compiler flags
258 # $4 additional dependencies
259 ifn$(EMPTY)def $(1)-objs_$(2)_template
260 de$(EMPTY)fine $(1)-objs_$(2)_template
261 $(obj)/$$(1).$(1).o: src/$$(1).$(2) $(obj)/config.h $(4)
262 @printf " CC
$$$$(subst $$$$(obj
)/,,$$$$(@
))\n"
263 $(CC) $(3) -MMD $$$$(CFLAGS) -c -o $$$$@ $$$$<
268 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
269 $(foreach class,$(classes), \
270 $(foreach type,$(call filetypes-of-class,$(class)), \
271 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps)))))
273 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(subst src/,,$(basename $(file))))))
274 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
276 DEPENDENCIES = $(allobjs:.o=.d)
277 -include $(DEPENDENCIES)
280 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
281 @echo alldirs:=$(alldirs)
282 @echo allsrcs=$(allsrcs)
283 @echo DEPENDENCIES=$(DEPENDENCIES)
284 @echo LIBGCC_FILE_NAME=$(LIBGCC_FILE_NAME)
285 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
290 $(shell mkdir -p $(obj) $(objutil)/kconfig/lxdialog $(additional-dirs) $(alldirs))
298 $(DOXYGEN) documentation/Doxyfile.coreboot
300 doxyclean: doxygen-clean
302 rm -rf $(DOXYGEN_OUTPUT_DIR)
304 clean-for-update: doxygen-clean clean-for-update-target
305 rm -rf $(obj) .xcompile
307 clean: clean-for-update clean-target
314 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
316 .PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy .xcompile