src/arch/*/include/stdint.h: Provide definitions for bool type
[coreboot.git] / Makefile
blob017ca47ad74999b0b11e2c3d247bfba491a4067c
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 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 cross%,$(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 ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
117 # FIXME: armv7/aarch64 won't build right now
118 # NOTE: clang puts compiler-rt under lib/linux/libclang_rt.builtins-i386.a
119 # this means the triple is i386-linux-elf instead of i386-none-elf
120 CFLAGS_x86_32 = -no-integrated-as -Qunused-arguments -target i386-linux-elf -m32
121 # Tone down some clang warnings
122 CFLAGS_x86_32 += -Wno-unused-variable -Wno-unused-function -Wno-tautological-compare -Wno-shift-overflow
123 CC_x86_32:=clang
124 HOSTCC := clang
126 ifneq ($(CONFIG_MMX),y)
127 CFLAGS_x86_32 += -mno-mmx
128 endif
130 # FIXME: we end up with conflicting flags with this, not clear on this part.
131 #ifneq ($(CONFIG_SSE),y)
132 #CFLAGS_x86_32 += -mno-sse
133 #endif
135 CFLAGS_arm = -no-integrated-as -Qunused-arguments -target arm-eabi -ccc-gcc-name $(CC_arm)
136 CC_arm:=clang
138 CFLAGS_aarch64 = -no-integrated-as -Qunused-arguments -target aarch64-eabi -ccc-gcc-name $(CC_aarch64)
139 CC_aarch64:=clang
140 endif
142 include toolchain.inc
144 strip_quotes = $(subst ",,$(subst \",,$(1)))
146 # The primary target needs to be here before we include the
147 # other files
149 real-all: real-target
151 # must come rather early
152 .SECONDEXPANSION:
154 $(obj)/config.h:
155 $(MAKE) oldconfig
157 # Add a new class of source/object files to the build system
158 add-class= \
159 $(eval $(1)-srcs:=) \
160 $(eval $(1)-objs:=) \
161 $(eval classes+=$(1))
163 # Special classes are managed types with special behaviour
164 # On parse time, for each entry in variable $(1)-y
165 # a handler $(1)-handler is executed with the arguments:
166 # * $(1): directory the parser is in
167 # * $(2): current entry
168 add-special-class= \
169 $(eval $(1):=) \
170 $(eval special-classes+=$(1))
172 # Clean -y variables, include Makefile.inc
173 # Add paths to files in X-y to X-srcs
174 # Add subdirs-y to subdirs
175 includemakefiles= \
176 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
177 $(eval -include $(1)) \
178 $(foreach class,$(classes-y), $(call add-class,$(class))) \
179 $(foreach class,$(classes), \
180 $(eval $(class)-srcs+= \
181 $$(subst $(top)/,, \
182 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y))))))) \
183 $(foreach special,$(special-classes), \
184 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
185 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
187 # For each path in $(subdirs) call includemakefiles
188 # Repeat until subdirs is empty
189 evaluate_subdirs= \
190 $(eval cursubdirs:=$(subdirs)) \
191 $(eval subdirs:=) \
192 $(foreach dir,$(cursubdirs), \
193 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
194 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
196 # collect all object files eligible for building
197 subdirs:=$(TOPLEVEL)
198 $(eval $(call evaluate_subdirs))
199 ifeq ($(FAILBUILD),1)
200 $(error cannot continue build)
201 endif
203 # Eliminate duplicate mentions of source files in a class
204 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
206 src-to-obj=$(addsuffix .$(1).o, $(basename $(patsubst src/%, $(obj)/%, $($(1)-srcs))))
207 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class))))
209 # Save all objs before processing them (for dependency inclusion)
210 originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
212 # Call post-processors if they're defined
213 $(foreach class,$(classes),\
214 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
216 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
217 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
218 alldirs:=$(sort $(abspath $(dir $(allobjs))))
220 # macro to define template macros that are used by use_template macro
221 define create_cc_template
222 # $1 obj class
223 # $2 source suffix (c, S)
224 # $3 additional compiler flags
225 # $4 additional dependencies
226 ifn$(EMPTY)def $(1)-objs_$(2)_template
227 de$(EMPTY)fine $(1)-objs_$(2)_template
228 $(obj)/$$(1).$(1).o: src/$$(1).$(2) $(obj)/config.h $(4)
229 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
230 $(CC_$(1)) $(3) -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -c -o $$$$@ $$$$<
231 en$(EMPTY)def
232 end$(EMPTY)if
233 endef
235 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
236 $(foreach class,$(classes), \
237 $(foreach type,$(call filetypes-of-class,$(class)), \
238 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps)))))
240 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(subst src/,,$(basename $(file))))))
241 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
243 DEPENDENCIES = $(originalobjs:.o=.d)
244 -include $(DEPENDENCIES)
246 printall:
247 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
248 @echo alldirs:=$(alldirs)
249 @echo allsrcs=$(allsrcs)
250 @echo DEPENDENCIES=$(DEPENDENCIES)
251 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
253 endif
255 ifndef NOMKDIR
256 $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objutil)/kconfig/lxdialog $(additional-dirs) $(alldirs))
257 endif
259 cscope:
260 cscope -bR
262 doxy: doxygen
263 doxygen:
264 $(DOXYGEN) documentation/Doxyfile.coreboot
266 doxygen_simple:
267 $(DOXYGEN) documentation/Doxyfile.coreboot_simple
269 doxyclean: doxygen-clean
270 doxygen-clean:
271 rm -rf $(DOXYGEN_OUTPUT_DIR)
273 clean-for-update: doxygen-clean clean-for-update-target
274 rm -rf $(obj) .xcompile
276 clean: clean-for-update clean-target
277 rm -f .ccwrap
279 clean-cscope:
280 rm -f cscope.out
282 distclean: clean
283 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
285 .PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple