ibexpeak/azalia: Remove C4-register extended init.
[coreboot.git] / Makefile
blobb709d14a9dbcf7c824017779745c9197f5e7b81b
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 ifeq ($(INNER_SCANBUILD),y)
34 CC_real:=$(CC)
35 endif
37 $(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile $(XGCCPATH) > .xcompile)))
38 include .xcompile
40 ifeq ($(INNER_SCANBUILD),y)
41 CC:=$(CC_real)
42 HOSTCC:=$(CC_real) --hostcc
43 HOSTCXX:=$(CC_real) --hostcxx
44 endif
46 export top := $(CURDIR)
47 export src := src
48 export srck := $(top)/util/kconfig
49 export obj ?= build
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
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 DOXYGEN := doxygen
83 DOXYGEN_OUTPUT_DIR := doxygen
85 all: real-all
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)),)
97 NOCOMPILE:=1
98 endif
99 ifneq ($(MAKECMDGOALS),)
100 ifneq ($(filter %config %clean,$(MAKECMDGOALS)),)
101 NOCOMPILE:=1
102 endif
103 ifeq ($(MAKECMDGOALS), %clean)
104 NOMKDIR:=1
105 endif
106 endif
108 ifeq ($(NOCOMPILE),1)
109 include $(TOPLEVEL)/Makefile.inc
110 real-all: config
112 else
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,
122 # override here.
123 ARCH-$(CONFIG_ARCH_ARMV7) := armv7
124 ARCH-$(CONFIG_ARCH_X86) := i386
126 ifneq ($(INNER_SCANBUILD),y)
127 CC := $(CC_$(ARCH-y))
128 endif
129 CPP := $(CPP_$(ARCH-y))
130 AS := $(AS_$(ARCH-y))
131 LD := $(LD_$(ARCH-y))
132 NM := $(NM_$(ARCH-y))
133 OBJCOPY := $(OBJCOPY_$(ARCH-y))
134 OBJDUMP := $(OBJDUMP_$(ARCH-y))
135 READELF := $(READELF_$(ARCH-y))
136 STRIP := $(STRIP_$(ARCH-y))
137 AR := $(AR_$(ARCH-y))
139 CFLAGS += $(CFLAGS_$(ARCH-y))
141 LIBGCC_FILE_NAME := $(shell test -r `$(CC) -print-libgcc-file-name` && \
142 $(CC) -print-libgcc-file-name)
144 ifneq ($(INNER_SCANBUILD),y)
145 ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
146 CC:=clang -m32 -mno-mmx -mno-sse
147 HOSTCC:=clang
148 endif
149 endif
151 ifeq ($(CONFIG_CCACHE),y)
152 CCACHE:=$(word 1,$(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH)))))
153 ifeq ($(CCACHE),)
154 $(error ccache selected, but not found in PATH)
155 endif
156 CCACHE:=CCACHE_COMPILERCHECK=content CCACHE_BASEDIR=$(top) $(CCACHE)
157 CC := $(CCACHE) $(CC)
158 HOSTCC := $(CCACHE) $(HOSTCC)
159 HOSTCXX := $(CCACHE) $(HOSTCXX)
160 ROMCC := $(CCACHE) $(ROMCC)
161 endif
163 strip_quotes = $(subst ",,$(subst \",,$(1)))
165 # The primary target needs to be here before we include the
166 # other files
168 ifeq ($(INNER_SCANBUILD),y)
169 CONFIG_SCANBUILD_ENABLE:=
170 endif
172 ifeq ($(CONFIG_SCANBUILD_ENABLE),y)
173 ifneq ($(CONFIG_SCANBUILD_REPORT_LOCATION),)
174 CONFIG_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_SCANBUILD_REPORT_LOCATION)
175 endif
176 real-all:
177 echo '#!/bin/sh' > .ccwrap
178 echo 'CC="$(CC)"' >> .ccwrap
179 echo 'if [ "$$1" = "--hostcc" ]; then shift; CC="$(HOSTCC)"; fi' >> .ccwrap
180 echo 'if [ "$$1" = "--hostcxx" ]; then shift; CC="$(HOSTCXX)"; fi' >> .ccwrap
181 echo 'eval $$CC $$*' >> .ccwrap
182 chmod +x .ccwrap
183 scan-build $(CONFIG_SCANBUILD_REPORT_LOCATION) -analyze-headers --use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y
184 else
185 real-all: real-target
186 endif
188 # must come rather early
189 .SECONDEXPANSION:
191 $(obj)/config.h:
192 $(MAKE) oldconfig
194 # Add a new class of source/object files to the build system
195 add-class= \
196 $(eval $(1)-srcs:=) \
197 $(eval $(1)-objs:=) \
198 $(eval classes+=$(1))
200 # Special classes are managed types with special behaviour
201 # On parse time, for each entry in variable $(1)-y
202 # a handler $(1)-handler is executed with the arguments:
203 # * $(1): directory the parser is in
204 # * $(2): current entry
205 add-special-class= \
206 $(eval $(1):=) \
207 $(eval special-classes+=$(1))
209 # Clean -y variables, include Makefile.inc
210 # Add paths to files in X-y to X-srcs
211 # Add subdirs-y to subdirs
212 includemakefiles= \
213 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
214 $(eval -include $(1)) \
215 $(foreach class,$(classes-y), $(call add-class,$(class))) \
216 $(foreach class,$(classes), \
217 $(eval $(class)-srcs+= \
218 $$(subst $(top)/,, \
219 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y))))))) \
220 $(foreach special,$(special-classes), \
221 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
222 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
224 # For each path in $(subdirs) call includemakefiles
225 # Repeat until subdirs is empty
226 evaluate_subdirs= \
227 $(eval cursubdirs:=$(subdirs)) \
228 $(eval subdirs:=) \
229 $(foreach dir,$(cursubdirs), \
230 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
231 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
233 # collect all object files eligible for building
234 subdirs:=$(TOPLEVEL)
235 $(eval $(call evaluate_subdirs))
236 ifeq ($(FAILBUILD),1)
237 $(error cannot continue build)
238 endif
240 # Eliminate duplicate mentions of source files in a class
241 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
243 src-to-obj=$(addsuffix .$(1).o, $(basename $(patsubst src/%, $(obj)/%, $($(1)-srcs))))
244 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class))))
246 # Save all objs before processing them (for dependency inclusion)
247 originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
249 # Call post-processors if they're defined
250 $(foreach class,$(classes),\
251 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
253 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
254 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
255 alldirs:=$(sort $(abspath $(dir $(allobjs))))
257 # macro to define template macros that are used by use_template macro
258 define create_cc_template
259 # $1 obj class
260 # $2 source suffix (c, S)
261 # $3 additional compiler flags
262 # $4 additional dependencies
263 ifn$(EMPTY)def $(1)-objs_$(2)_template
264 de$(EMPTY)fine $(1)-objs_$(2)_template
265 $(obj)/$$(1).$(1).o: src/$$(1).$(2) $(obj)/config.h $(4)
266 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
267 $(CC) $(3) -MMD $$$$(CFLAGS) -c -o $$$$@ $$$$<
268 en$(EMPTY)def
269 end$(EMPTY)if
270 endef
272 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
273 $(foreach class,$(classes), \
274 $(foreach type,$(call filetypes-of-class,$(class)), \
275 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps)))))
277 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(subst src/,,$(basename $(file))))))
278 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
280 DEPENDENCIES = $(originalobjs:.o=.d)
281 -include $(DEPENDENCIES)
283 printall:
284 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
285 @echo alldirs:=$(alldirs)
286 @echo allsrcs=$(allsrcs)
287 @echo DEPENDENCIES=$(DEPENDENCIES)
288 @echo LIBGCC_FILE_NAME=$(LIBGCC_FILE_NAME)
289 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
291 endif
293 ifndef NOMKDIR
294 $(shell mkdir -p $(obj) $(objutil)/kconfig/lxdialog $(additional-dirs) $(alldirs))
295 endif
297 cscope:
298 cscope -bR
300 doxy: doxygen
301 doxygen:
302 $(DOXYGEN) documentation/Doxyfile.coreboot
304 doxyclean: doxygen-clean
305 doxygen-clean:
306 rm -rf $(DOXYGEN_OUTPUT_DIR)
308 clean-for-update: doxygen-clean clean-for-update-target
309 rm -rf $(obj) .xcompile
311 clean: clean-for-update clean-target
312 rm -f .ccwrap
314 clean-cscope:
315 rm -f cscope.out
317 distclean: clean
318 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
320 .PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy .xcompile