intel/fsp_baytrail: Fix SPI debugging
[coreboot.git] / Makefile
blob2ff4ebe0454c24375e8f3497c4c79972d1c6a64f
1 ##
2 ## This file is part of the coreboot project.
3 ##
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
8 ##
9 ## Redistribution and use in source and binary forms, with or without
10 ## modification, are permitted provided that the following conditions
11 ## are met:
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
30 ## SUCH DAMAGE.
33 # in addition to the dependency below, create the file if it doesn't exist
34 # to silence stupid warnings about a file that would be generated anyway.
35 $(if $(wildcard .xcompile),,$(eval $(shell util/xcompile/xcompile $(XGCCPATH) > .xcompile)))
37 .xcompile: util/xcompile/xcompile
38 $< $(XGCCPATH) > $@.tmp
39 \mv -f $@.tmp $@ 2> /dev/null
41 include .xcompile
43 export top := $(CURDIR)
44 export src := src
45 export srck := $(top)/util/kconfig
46 export obj ?= build
47 export objutil ?= $(obj)/util
48 export objk := $(objutil)/kconfig
51 export KCONFIG_AUTOHEADER := $(obj)/config.h
52 export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
53 export KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
54 export KCONFIG_SPLITCONFIG := $(obj)/config
55 export KCONFIG_TRISTATE := $(obj)/tristate.conf
56 export KCONFIG_NEGATIVES := 1
58 # directory containing the toplevel Makefile.inc
59 TOPLEVEL := .
61 CONFIG_SHELL := sh
62 KBUILD_DEFCONFIG := configs/defconfig
63 UNAME_RELEASE := $(shell uname -r)
64 DOTCONFIG ?= .config
65 KCONFIG_CONFIG = $(DOTCONFIG)
66 export KCONFIG_CONFIG
67 HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
68 MAKEFLAGS += -rR --no-print-directory
70 # Make is silent per default, but 'make V=1' will show all compiler calls.
71 Q:=@
72 ifneq ($(V),1)
73 ifneq ($(Q),)
74 .SILENT:
75 endif
76 endif
78 # Disable implicit/built-in rules to make Makefile errors fail fast.
79 .SUFFIXES:
81 HOSTCC := gcc
82 HOSTCXX = g++
83 HOSTCFLAGS := -g
84 HOSTCXXFLAGS := -g
86 PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
88 DOXYGEN := doxygen
89 DOXYGEN_OUTPUT_DIR := doxygen
91 all: real-all
93 # This include must come _before_ the pattern rules below!
94 # Order _does_ matter for pattern rules.
95 include util/kconfig/Makefile
97 # Three cases where we don't need fully populated $(obj) lists:
98 # 1. when no .config exists
99 # 2. when make config (in any flavour) is run
100 # 3. when make distclean is run
101 # Don't waste time on reading all Makefile.incs in these cases
102 ifeq ($(strip $(HAVE_DOTCONFIG)),)
103 NOCOMPILE:=1
104 endif
105 ifneq ($(MAKECMDGOALS),)
106 ifneq ($(filter %config %clean cross% lint% what-jenkins-does,$(MAKECMDGOALS)),)
107 NOCOMPILE:=1
108 endif
109 ifeq ($(MAKECMDGOALS), %clean)
110 NOMKDIR:=1
111 endif
112 endif
114 ifeq ($(NOCOMPILE),1)
115 include $(TOPLEVEL)/Makefile.inc
116 real-all: config
118 else
120 include $(HAVE_DOTCONFIG)
122 ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
123 # FIXME: armv7/aarch64 won't build right now
124 # NOTE: clang puts compiler-rt under lib/linux/libclang_rt.builtins-i386.a
125 # this means the triple is i386-linux-elf instead of i386-none-elf
126 CFLAGS_x86_32 = -no-integrated-as -Qunused-arguments -target i386-linux-elf -m32
127 # Tone down some clang warnings
128 CFLAGS_x86_32 += -Wno-unused-variable -Wno-unused-function -Wno-tautological-compare -Wno-shift-overflow
129 CC_x86_32:=clang
130 HOSTCC := clang
132 ifneq ($(CONFIG_MMX),y)
133 CFLAGS_x86_32 += -mno-mmx
134 endif
136 # FIXME: we end up with conflicting flags with this, not clear on this part.
137 #ifneq ($(CONFIG_SSE),y)
138 #CFLAGS_x86_32 += -mno-sse
139 #endif
141 CFLAGS_arm = -no-integrated-as -Qunused-arguments -target arm-eabi -ccc-gcc-name $(CC_arm)
142 CC_arm:=clang
144 CFLAGS_aarch64 = -no-integrated-as -Qunused-arguments -target aarch64-eabi -ccc-gcc-name $(CC_aarch64)
145 CC_aarch64:=clang
146 endif
148 include toolchain.inc
150 strip_quotes = $(subst ",,$(subst \",,$(1)))
152 # The primary target needs to be here before we include the
153 # other files
155 real-all: real-target
157 # must come rather early
158 .SECONDEXPANSION:
160 $(obj)/config.h:
161 $(MAKE) oldconfig
163 # Add a new class of source/object files to the build system
164 add-class= \
165 $(eval $(1)-srcs:=) \
166 $(eval $(1)-objs:=) \
167 $(eval classes+=$(1))
169 # Special classes are managed types with special behaviour
170 # On parse time, for each entry in variable $(1)-y
171 # a handler $(1)-handler is executed with the arguments:
172 # * $(1): directory the parser is in
173 # * $(2): current entry
174 add-special-class= \
175 $(eval $(1):=) \
176 $(eval special-classes+=$(1))
178 # Clean -y variables, include Makefile.inc
179 # Add paths to files in X-y to X-srcs
180 # Add subdirs-y to subdirs
181 includemakefiles= \
182 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
183 $(eval -include $(1)) \
184 $(foreach class,$(classes-y), $(call add-class,$(class))) \
185 $(foreach class,$(classes), \
186 $(eval $(class)-srcs+= \
187 $$(subst $(top)/,, \
188 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y))))))) \
189 $(foreach special,$(special-classes), \
190 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
191 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
193 # For each path in $(subdirs) call includemakefiles
194 # Repeat until subdirs is empty
195 evaluate_subdirs= \
196 $(eval cursubdirs:=$(subdirs)) \
197 $(eval subdirs:=) \
198 $(foreach dir,$(cursubdirs), \
199 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
200 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
202 # collect all object files eligible for building
203 subdirs:=$(TOPLEVEL)
204 $(eval $(call evaluate_subdirs))
205 ifeq ($(FAILBUILD),1)
206 $(error cannot continue build)
207 endif
209 # Eliminate duplicate mentions of source files in a class
210 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
212 # Converts one or more source file paths to their corresponding build/ paths.
213 # Only .c and .S get converted to .o, other files (like .ld) keep their name.
214 # $1 stage name
215 # $2 file path (list)
216 src-to-obj=$(foreach file,$(2),$(subst .$(1),,$(basename $(patsubst src/%,$(obj)/%,$(file)))).$(1)$(patsubst %.c,%.o,$(patsubst %.S,%.o,$(suffix $(file)))))
218 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
220 # Save all objs before processing them (for dependency inclusion)
221 originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
223 # Call post-processors if they're defined
224 $(foreach class,$(classes),\
225 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
227 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
228 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
229 alldirs:=$(sort $(abspath $(dir $(allobjs))))
231 # macro to define template macros that are used by use_template macro
232 define create_cc_template
233 # $1 obj class
234 # $2 source suffix (c, S, ld, ...)
235 # $3 additional compiler flags
236 # $4 additional dependencies
237 ifn$(EMPTY)def $(1)-objs_$(2)_template
238 de$(EMPTY)fine $(1)-objs_$(2)_template
239 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(obj)/config.h $(4)
240 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
241 $(CC_$(1)) -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) $(3) -c -o $$$$@ $$$$<
242 en$(EMPTY)def
243 end$(EMPTY)if
244 endef
246 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
247 $(foreach class,$(classes), \
248 $(foreach type,$(call filetypes-of-class,$(class)), \
249 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
250 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
251 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
253 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
254 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
256 DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
257 -include $(DEPENDENCIES)
259 printall:
260 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
261 @echo alldirs:=$(alldirs)
262 @echo allsrcs=$(allsrcs)
263 @echo DEPENDENCIES=$(DEPENDENCIES)
264 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
266 endif
268 ifndef NOMKDIR
269 $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objutil)/kconfig/lxdialog $(additional-dirs) $(alldirs))
270 endif
272 cscope:
273 cscope -bR
275 doxy: doxygen
276 doxygen:
277 $(DOXYGEN) documentation/Doxyfile.coreboot
279 doxygen_simple:
280 $(DOXYGEN) documentation/Doxyfile.coreboot_simple
282 doxyclean: doxygen-clean
283 doxygen-clean:
284 rm -rf $(DOXYGEN_OUTPUT_DIR)
286 clean-for-update: doxygen-clean clean-for-update-target
287 rm -rf $(obj) .xcompile
289 clean: clean-for-update clean-target
290 rm -f .ccwrap
292 clean-cscope:
293 rm -f cscope.out
295 distclean: clean
296 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
298 .PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple