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 ## This program is free software; you can redistribute it and/or modify
10 ## it under the terms of the GNU General Public License as published by
11 ## the Free Software Foundation; version 2 of the License.
13 ## This program is distributed in the hope that it will be useful,
14 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ## GNU General Public License for more details.
18 ## You should have received a copy of the GNU General Public License
19 ## along with this program; if not, write to the Free Software
20 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 ifeq ($(INNER_SCANBUILD),y)
27 $(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile > .xcompile)))
30 ifeq ($(INNER_SCANBUILD),y)
32 HOSTCC:=$(CC_real) --hostcc
33 HOSTCXX:=$(CC_real) --hostcxx
36 export top := $(CURDIR)
38 export srck := $(top)/util/kconfig
40 export objutil ?= $(obj)/util
41 export objk := $(objutil)/kconfig
44 export KCONFIG_AUTOHEADER := $(obj)/config.h
45 export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
47 # directory containing the toplevel Makefile.inc
51 KBUILD_DEFCONFIG := configs/defconfig
52 UNAME_RELEASE := $(shell uname -r)
54 KCONFIG_CONFIG = $(DOTCONFIG)
56 HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
57 MAKEFLAGS += -rR --no-print-directory
59 # Make is silent per default, but 'make V=1' will show all compiler calls.
67 CPP:= $(CC) -x assembler-with-cpp -DASSEMBLY -E
70 HOSTCFLAGS := -I$(srck) -I$(objk) -g
71 HOSTCXXFLAGS := -I$(srck) -I$(objk)
72 LIBGCC_FILE_NAME := $(shell test -r `$(CC) -print-libgcc-file-name` && $(CC) -print-libgcc-file-name)
75 DOXYGEN_OUTPUT_DIR := doxygen
79 # This include must come _before_ the pattern rules below!
80 # Order _does_ matter for pattern rules.
81 include util/kconfig/Makefile
83 # Three cases where we don't need fully populated $(obj) lists:
84 # 1. when no .config exists
85 # 2. when make config (in any flavour) is run
86 # 3. when make distclean is run
87 # Don't waste time on reading all Makefile.incs in these cases
88 ifeq ($(strip $(HAVE_DOTCONFIG)),)
91 ifneq ($(MAKECMDGOALS),)
92 ifneq ($(filter %config distclean,$(MAKECMDGOALS)),)
98 include $(TOPLEVEL)/Makefile.inc
103 include $(HAVE_DOTCONFIG)
105 ifneq ($(INNER_SCANBUILD),y)
106 ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
112 ifeq ($(CONFIG_CCACHE),y)
113 CCACHE:=$(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH))))
115 $(error ccache selected, but not found in PATH)
117 CCACHE:=CCACHE_COMPILERCHECK=content CCACHE_BASEDIR=$(top) $(CCACHE)
118 CC := $(CCACHE) $(CC)
119 HOSTCC := $(CCACHE) $(HOSTCC)
120 HOSTCXX := $(CCACHE) $(HOSTCXX)
121 ROMCC := $(CCACHE) $(ROMCC)
124 strip_quotes = $(subst ",,$(subst \",,$(1)))
126 # The primary target needs to be here before we include the
129 ifeq ($(INNER_SCANBUILD),y)
130 CONFIG_SCANBUILD_ENABLE:=
133 ifeq ($(CONFIG_SCANBUILD_ENABLE),y)
134 ifneq ($(CONFIG_SCANBUILD_REPORT_LOCATION),)
135 CONFIG_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_SCANBUILD_REPORT_LOCATION)
138 echo '#!/bin/sh' > .ccwrap
139 echo 'CC="$(CC)"' >> .ccwrap
140 echo 'if [ "$$1" = "--hostcc" ]; then shift; CC="$(HOSTCC)"; fi' >> .ccwrap
141 echo 'if [ "$$1" = "--hostcxx" ]; then shift; CC="$(HOSTCXX)"; fi' >> .ccwrap
142 echo 'eval $$CC $$*' >> .ccwrap
144 scan-build $(CONFIG_SCANBUILD_REPORT_LOCATION) -analyze-headers --use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y
146 real-all: real-target
149 # must come rather early
155 # Add a new class of source/object files to the build system
157 $(eval $(1)-srcs:=) \
158 $(eval $(1)-objs:=) \
159 $(eval classes+=$(1))
161 # Special classes are managed types with special behaviour
162 # On parse time, for each entry in variable $(1)-y
163 # a handler $(1)-handler is executed with the arguments:
164 # * $(1): directory the parser is in
165 # * $(2): current entry
168 $(eval special-classes+=$(1))
170 # Clean -y variables, include Makefile.inc
171 # Add paths to files in X-y to X-srcs
172 # Add subdirs-y to subdirs
174 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
175 $(eval -include $(1)) \
176 $(foreach class,$(classes-y), $(call add-class,$(class))) \
177 $(foreach class,$(classes), \
178 $(eval $(class)-srcs+= \
180 $$(abspath $$(addprefix $(dir $(1)),$$($(class)-y)))))) \
181 $(foreach special,$(special-classes), \
182 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
183 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
185 # For each path in $(subdirs) call includemakefiles
186 # Repeat until subdirs is empty
188 $(eval cursubdirs:=$(subdirs)) \
190 $(foreach dir,$(cursubdirs), \
191 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
192 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
194 # collect all object files eligible for building
196 $(eval $(call evaluate_subdirs))
198 src-to-obj=$(addsuffix .$(1).o, $(basename $(patsubst src/%, $(obj)/%, $($(1)-srcs))))
199 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class))))
201 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
202 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
203 alldirs:=$(sort $(abspath $(dir $(allobjs))))
205 # macro to define template macros that are used by use_template macro
206 define create_cc_template
208 # $2 source suffix (c, S)
209 # $3 additional compiler flags
210 # $4 additional dependencies
211 ifn$(EMPTY)def $(1)-objs_$(2)_template
212 de$(EMPTY)fine $(1)-objs_$(2)_template
213 $(obj)/$$(1).$(1).o: src/$$(1).$(2) $(obj)/config.h $(4)
214 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
215 $(CC) $(3) -MMD $$$$(CFLAGS) -c -o $$$$@ $$$$<
220 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
221 $(foreach class,$(classes), \
222 $(foreach type,$(call filetypes-of-class,$(class)), \
223 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps)))))
225 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(subst src/,,$(basename $(file))))))
226 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
228 DEPENDENCIES = $(allobjs:.o=.d)
229 -include $(DEPENDENCIES)
232 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
233 @echo alldirs:=$(alldirs)
234 @echo allsrcs=$(allsrcs)
235 @echo DEPENDENCIES=$(DEPENDENCIES)
236 @echo LIBGCC_FILE_NAME=$(LIBGCC_FILE_NAME)
237 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
241 $(shell mkdir -p $(obj) $(objutil)/kconfig/lxdialog $(additional-dirs) $(alldirs))
248 $(DOXYGEN) documentation/Doxyfile.coreboot
250 doxyclean: doxygen-clean
252 rm -rf $(DOXYGEN_OUTPUT_DIR)
254 clean-for-update: doxygen-clean clean-for-update-target
255 rm -f $(allobjs) .xcompile
256 rm -f $(DEPENDENCIES)
257 rmdir -p $(alldirs) 2>/dev/null >/dev/null || true
259 clean: clean-for-update clean-target
265 distclean: clean-cscope
267 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
269 .PHONY: $(PHONY) clean clean-cscope cscope distclean doxygen doxy .xcompile