veyron_rialto: Fix boot failure in romstage.
[coreboot.git] / Makefile
blob395910f7219c662bafcb34b896dec587bfa8cef9
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 A=`mktemp $@.XXXXXX`; $< $(XGCCPATH) > $$A && mv $$A $@ 2> /dev/null
40 include .xcompile
42 export top := $(CURDIR)
43 export src := src
44 export srck := $(top)/util/kconfig
45 export obj ?= build
46 export objutil ?= $(obj)/util
47 export objk := $(objutil)/kconfig
50 export KCONFIG_AUTOHEADER := $(obj)/config.h
51 export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
52 export KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
53 export KCONFIG_SPLITCONFIG := $(obj)/config
54 export KCONFIG_TRISTATE := $(obj)/tristate.conf
55 export KCONFIG_NEGATIVES := 1
57 # directory containing the toplevel Makefile.inc
58 TOPLEVEL := .
60 CONFIG_SHELL := sh
61 KBUILD_DEFCONFIG := configs/defconfig
62 UNAME_RELEASE := $(shell uname -r)
63 DOTCONFIG ?= .config
64 KCONFIG_CONFIG = $(DOTCONFIG)
65 export KCONFIG_CONFIG
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.
70 Q:=@
71 ifneq ($(V),1)
72 ifneq ($(Q),)
73 .SILENT:
74 endif
75 endif
77 HOSTCC := gcc
78 HOSTCXX = g++
79 HOSTCFLAGS := -g
80 HOSTCXXFLAGS := -g
82 PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
84 DOXYGEN := doxygen
85 DOXYGEN_OUTPUT_DIR := doxygen
87 all: real-all
89 # This include must come _before_ the pattern rules below!
90 # Order _does_ matter for pattern rules.
91 include util/kconfig/Makefile
93 # Three cases where we don't need fully populated $(obj) lists:
94 # 1. when no .config exists
95 # 2. when make config (in any flavour) is run
96 # 3. when make distclean is run
97 # Don't waste time on reading all Makefile.incs in these cases
98 ifeq ($(strip $(HAVE_DOTCONFIG)),)
99 NOCOMPILE:=1
100 endif
101 ifneq ($(MAKECMDGOALS),)
102 ifneq ($(filter %config %clean cross% lint% what-jenkins-does,$(MAKECMDGOALS)),)
103 NOCOMPILE:=1
104 endif
105 ifeq ($(MAKECMDGOALS), %clean)
106 NOMKDIR:=1
107 endif
108 endif
110 ifeq ($(NOCOMPILE),1)
111 include $(TOPLEVEL)/Makefile.inc
112 real-all: config
114 else
116 include $(HAVE_DOTCONFIG)
118 ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
119 # FIXME: armv7/aarch64 won't build right now
120 # NOTE: clang puts compiler-rt under lib/linux/libclang_rt.builtins-i386.a
121 # this means the triple is i386-linux-elf instead of i386-none-elf
122 CFLAGS_x86_32 = -no-integrated-as -Qunused-arguments -target i386-linux-elf -m32
123 # Tone down some clang warnings
124 CFLAGS_x86_32 += -Wno-unused-variable -Wno-unused-function -Wno-tautological-compare -Wno-shift-overflow
125 CC_x86_32:=clang
126 HOSTCC := clang
128 ifneq ($(CONFIG_MMX),y)
129 CFLAGS_x86_32 += -mno-mmx
130 endif
132 # FIXME: we end up with conflicting flags with this, not clear on this part.
133 #ifneq ($(CONFIG_SSE),y)
134 #CFLAGS_x86_32 += -mno-sse
135 #endif
137 CFLAGS_arm = -no-integrated-as -Qunused-arguments -target arm-eabi -ccc-gcc-name $(CC_arm)
138 CC_arm:=clang
140 CFLAGS_aarch64 = -no-integrated-as -Qunused-arguments -target aarch64-eabi -ccc-gcc-name $(CC_aarch64)
141 CC_aarch64:=clang
142 endif
144 include toolchain.inc
146 strip_quotes = $(subst ",,$(subst \",,$(1)))
148 # The primary target needs to be here before we include the
149 # other files
151 real-all: real-target
153 # must come rather early
154 .SECONDEXPANSION:
156 $(obj)/config.h:
157 $(MAKE) oldconfig
159 # Add a new class of source/object files to the build system
160 add-class= \
161 $(eval $(1)-srcs:=) \
162 $(eval $(1)-objs:=) \
163 $(eval classes+=$(1))
165 # Special classes are managed types with special behaviour
166 # On parse time, for each entry in variable $(1)-y
167 # a handler $(1)-handler is executed with the arguments:
168 # * $(1): directory the parser is in
169 # * $(2): current entry
170 add-special-class= \
171 $(eval $(1):=) \
172 $(eval special-classes+=$(1))
174 # Clean -y variables, include Makefile.inc
175 # Add paths to files in X-y to X-srcs
176 # Add subdirs-y to subdirs
177 includemakefiles= \
178 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
179 $(eval -include $(1)) \
180 $(foreach class,$(classes-y), $(call add-class,$(class))) \
181 $(foreach class,$(classes), \
182 $(eval $(class)-srcs+= \
183 $$(subst $(top)/,, \
184 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y))))))) \
185 $(foreach special,$(special-classes), \
186 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
187 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
189 # For each path in $(subdirs) call includemakefiles
190 # Repeat until subdirs is empty
191 evaluate_subdirs= \
192 $(eval cursubdirs:=$(subdirs)) \
193 $(eval subdirs:=) \
194 $(foreach dir,$(cursubdirs), \
195 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
196 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
198 # collect all object files eligible for building
199 subdirs:=$(TOPLEVEL)
200 $(eval $(call evaluate_subdirs))
201 ifeq ($(FAILBUILD),1)
202 $(error cannot continue build)
203 endif
205 # Eliminate duplicate mentions of source files in a class
206 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
208 # Converts one or more source file paths to their corresponding build/ paths.
209 # Only .c and .S get converted to .o, other files (like .ld) keep their name.
210 # $1 stage name
211 # $2 file path (list)
212 src-to-obj=$(foreach file,$(2),$(basename $(patsubst src/%,$(obj)/%,$(file))).$(1)$(patsubst %.c,%.o,$(patsubst %.S,%.o,$(suffix $(file)))))
214 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
216 # Save all objs before processing them (for dependency inclusion)
217 originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
219 # Call post-processors if they're defined
220 $(foreach class,$(classes),\
221 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
223 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
224 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
225 alldirs:=$(sort $(abspath $(dir $(allobjs))))
227 # macro to define template macros that are used by use_template macro
228 define create_cc_template
229 # $1 obj class
230 # $2 source suffix (c, S, ld, ...)
231 # $3 additional compiler flags
232 # $4 additional dependencies
233 ifn$(EMPTY)def $(1)-objs_$(2)_template
234 de$(EMPTY)fine $(1)-objs_$(2)_template
235 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(obj)/config.h $(4)
236 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
237 $(CC_$(1)) -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) $(3) -c -o $$$$@ $$$$<
238 en$(EMPTY)def
239 end$(EMPTY)if
240 endef
242 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
243 $(foreach class,$(classes), \
244 $(foreach type,$(call filetypes-of-class,$(class)), \
245 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
246 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
247 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
249 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
250 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
252 DEPENDENCIES = $(addsuffix .d,$(basename $(allobjs)))
253 -include $(DEPENDENCIES)
255 printall:
256 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
257 @echo alldirs:=$(alldirs)
258 @echo allsrcs=$(allsrcs)
259 @echo DEPENDENCIES=$(DEPENDENCIES)
260 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
262 endif
264 ifndef NOMKDIR
265 $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objutil)/kconfig/lxdialog $(additional-dirs) $(alldirs))
266 endif
268 cscope:
269 cscope -bR
271 doxy: doxygen
272 doxygen:
273 $(DOXYGEN) documentation/Doxyfile.coreboot
275 doxygen_simple:
276 $(DOXYGEN) documentation/Doxyfile.coreboot_simple
278 doxyclean: doxygen-clean
279 doxygen-clean:
280 rm -rf $(DOXYGEN_OUTPUT_DIR)
282 clean-for-update: doxygen-clean clean-for-update-target
283 rm -rf $(obj) .xcompile
285 clean: clean-for-update clean-target
286 rm -f .ccwrap
288 clean-cscope:
289 rm -f cscope.out
291 distclean: clean
292 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
294 .PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple