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.
69 HOSTCFLAGS := -I$(srck) -I$(objk) -g
70 HOSTCXXFLAGS := -I$(srck) -I$(objk)
71 LIBGCC_FILE_NAME := $(shell test -r `$(CC) -print-libgcc-file-name` && $(CC) -print-libgcc-file-name)
74 DOXYGEN_OUTPUT_DIR := doxygen
78 # This include must come _before_ the pattern rules below!
79 # Order _does_ matter for pattern rules.
80 include util/kconfig/Makefile
82 # Three cases where we don't need fully populated $(obj) lists:
83 # 1. when no .config exists
84 # 2. when make config (in any flavour) is run
85 # 3. when make distclean is run
86 # Don't waste time on reading all Makefile.incs in these cases
87 ifeq ($(strip $(HAVE_DOTCONFIG)),)
90 ifneq ($(MAKECMDGOALS),)
91 ifneq ($(filter %config distclean,$(MAKECMDGOALS)),)
97 include $(TOPLEVEL)/Makefile.inc
102 include $(HAVE_DOTCONFIG)
104 ifneq ($(INNER_SCANBUILD),y)
105 ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
111 ifeq ($(CONFIG_CCACHE),y)
112 CCACHE:=$(word 1,$(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH)))))
114 $(error ccache selected, but not found in PATH)
116 CCACHE:=CCACHE_COMPILERCHECK=content CCACHE_BASEDIR=$(top) $(CCACHE)
117 CC := $(CCACHE) $(CC)
118 HOSTCC := $(CCACHE) $(HOSTCC)
119 HOSTCXX := $(CCACHE) $(HOSTCXX)
120 ROMCC := $(CCACHE) $(ROMCC)
123 strip_quotes = $(subst ",,$(subst \",,$(1)))
125 # The primary target needs to be here before we include the
128 ifeq ($(INNER_SCANBUILD),y)
129 CONFIG_SCANBUILD_ENABLE:=
132 ifeq ($(CONFIG_SCANBUILD_ENABLE),y)
133 ifneq ($(CONFIG_SCANBUILD_REPORT_LOCATION),)
134 CONFIG_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_SCANBUILD_REPORT_LOCATION)
137 echo '#!/bin/sh' > .ccwrap
138 echo 'CC="$(CC)"' >> .ccwrap
139 echo 'if [ "$$1" = "--hostcc" ]; then shift; CC="$(HOSTCC)"; fi' >> .ccwrap
140 echo 'if [ "$$1" = "--hostcxx" ]; then shift; CC="$(HOSTCXX)"; fi' >> .ccwrap
141 echo 'eval $$CC $$*' >> .ccwrap
143 scan-build $(CONFIG_SCANBUILD_REPORT_LOCATION) -analyze-headers --use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y
145 real-all: real-target
148 # must come rather early
154 # Add a new class of source/object files to the build system
156 $(eval $(1)-srcs:=) \
157 $(eval $(1)-objs:=) \
158 $(eval classes+=$(1))
160 # Special classes are managed types with special behaviour
161 # On parse time, for each entry in variable $(1)-y
162 # a handler $(1)-handler is executed with the arguments:
163 # * $(1): directory the parser is in
164 # * $(2): current entry
167 $(eval special-classes+=$(1))
169 # Clean -y variables, include Makefile.inc
170 # Add paths to files in X-y to X-srcs
171 # Add subdirs-y to subdirs
173 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
174 $(eval -include $(1)) \
175 $(foreach class,$(classes-y), $(call add-class,$(class))) \
176 $(foreach class,$(classes), \
177 $(eval $(class)-srcs+= \
179 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y))))))) \
180 $(foreach special,$(special-classes), \
181 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
182 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
184 # For each path in $(subdirs) call includemakefiles
185 # Repeat until subdirs is empty
187 $(eval cursubdirs:=$(subdirs)) \
189 $(foreach dir,$(cursubdirs), \
190 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
191 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
193 # collect all object files eligible for building
195 $(eval $(call evaluate_subdirs))
197 src-to-obj=$(addsuffix .$(1).o, $(basename $(patsubst src/%, $(obj)/%, $($(1)-srcs))))
198 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class))))
200 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
201 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
202 alldirs:=$(sort $(abspath $(dir $(allobjs))))
204 # macro to define template macros that are used by use_template macro
205 define create_cc_template
207 # $2 source suffix (c, S)
208 # $3 additional compiler flags
209 # $4 additional dependencies
210 ifn$(EMPTY)def $(1)-objs_$(2)_template
211 de$(EMPTY)fine $(1)-objs_$(2)_template
212 $(obj)/$$(1).$(1).o: src/$$(1).$(2) $(obj)/config.h $(4)
213 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
214 $(CC) $(3) -MMD $$$$(CFLAGS) -c -o $$$$@ $$$$<
219 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
220 $(foreach class,$(classes), \
221 $(foreach type,$(call filetypes-of-class,$(class)), \
222 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps)))))
224 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(subst src/,,$(basename $(file))))))
225 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
227 DEPENDENCIES = $(allobjs:.o=.d)
228 -include $(DEPENDENCIES)
231 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
232 @echo alldirs:=$(alldirs)
233 @echo allsrcs=$(allsrcs)
234 @echo DEPENDENCIES=$(DEPENDENCIES)
235 @echo LIBGCC_FILE_NAME=$(LIBGCC_FILE_NAME)
236 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
240 $(shell mkdir -p $(obj) $(objutil)/kconfig/lxdialog $(additional-dirs) $(alldirs))
247 $(DOXYGEN) documentation/Doxyfile.coreboot
249 doxyclean: doxygen-clean
251 rm -rf $(DOXYGEN_OUTPUT_DIR)
253 clean-for-update: doxygen-clean clean-for-update-target
254 rm -f $(allobjs) .xcompile
255 rm -f $(DEPENDENCIES)
256 rmdir -p $(alldirs) 2>/dev/null >/dev/null || true
258 clean: clean-for-update clean-target
264 distclean: clean-cscope
266 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
268 .PHONY: $(PHONY) clean clean-cscope cscope distclean doxygen doxy .xcompile