blob: 14e159898c83dd1a0739c0db4a3fc34472f1703d [file] [log] [blame]
Patrick Georgi0588d192009-08-12 15:00:51 +00001##
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>
Stefan Reinauer8ed1b6d2010-01-19 21:13:44 +00006## Copyright (C) 2009-2010 coresystems GmbH
Patrick Georgi71b84802011-02-22 14:35:05 +00007## Copyright (C) 2011 secunet Security Networks AG
Patrick Georgi0588d192009-08-12 15:00:51 +00008##
Patrick Georgi3bda0442011-06-30 15:48:57 +02009## 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.
Patrick Georgi0588d192009-08-12 15:00:51 +000019##
Patrick Georgi3bda0442011-06-30 15:48:57 +020020## 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.
Patrick Georgi0588d192009-08-12 15:00:51 +000031##
32
Patrick Georgi05560bf2014-07-19 10:55:30 +020033# 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)))
36
Patrick Georgi18ff4f12014-07-10 21:06:04 +020037.xcompile: util/xcompile/xcompile
38 A=`mktemp $@.XXXXXX`; $< $(XGCCPATH) > $$A && mv $$A $@ 2> /dev/null
39
Patrick Georgi0588d192009-08-12 15:00:51 +000040include .xcompile
Patrick Georgi23d89cc2010-03-16 01:17:19 +000041
Jonathan Kollasch7ff5b442010-09-28 21:11:48 +000042export top := $(CURDIR)
Patrick Georgi51e142f2010-03-27 17:18:39 +000043export src := src
Patrick Georgi0588d192009-08-12 15:00:51 +000044export srck := $(top)/util/kconfig
Patrick Georgi51e142f2010-03-27 17:18:39 +000045export obj ?= build
Patrick Georgia2acbc72010-04-16 22:48:57 +000046export objutil ?= $(obj)/util
47export objk := $(objutil)/kconfig
Patrick Georgi0588d192009-08-12 15:00:51 +000048
49
Patrick Georgi0588d192009-08-12 15:00:51 +000050export KCONFIG_AUTOHEADER := $(obj)/config.h
51export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
Patrick Georgid5208402014-04-11 20:24:06 +020052export KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
53export KCONFIG_SPLITCONFIG := $(obj)/config
54export KCONFIG_TRISTATE := $(obj)/tristate.conf
55export KCONFIG_NEGATIVES := 1
Patrick Georgi0588d192009-08-12 15:00:51 +000056
Patrick Georgie38d0a62011-03-01 08:09:22 +000057# directory containing the toplevel Makefile.inc
58TOPLEVEL := .
59
Patrick Georgi0588d192009-08-12 15:00:51 +000060CONFIG_SHELL := sh
61KBUILD_DEFCONFIG := configs/defconfig
62UNAME_RELEASE := $(shell uname -r)
Patrick Georgi89ec3762010-12-08 19:58:30 +000063DOTCONFIG ?= .config
64KCONFIG_CONFIG = $(DOTCONFIG)
65export KCONFIG_CONFIG
66HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
Patrick Georgi0588d192009-08-12 15:00:51 +000067MAKEFLAGS += -rR --no-print-directory
68
69# Make is silent per default, but 'make V=1' will show all compiler calls.
Patrick Georgi2b7418e2009-08-25 19:38:46 +000070Q:=@
Patrick Georgi0588d192009-08-12 15:00:51 +000071ifneq ($(V),1)
Patrick Georgi2b7418e2009-08-25 19:38:46 +000072ifneq ($(Q),)
73.SILENT:
74endif
Patrick Georgi0588d192009-08-12 15:00:51 +000075endif
76
Julius Werner808a4292015-03-13 11:05:07 -070077# Disable implicit/built-in rules to make Makefile errors fail fast.
78.SUFFIXES:
79
Edward O'Callaghan16407ab2014-10-30 11:36:42 +110080HOSTCC := gcc
Patrick Georgi0588d192009-08-12 15:00:51 +000081HOSTCXX = g++
Patrick Georgib3a18ac2012-09-13 22:13:33 +020082HOSTCFLAGS := -g
83HOSTCXXFLAGS := -g
Patrick Georgi0588d192009-08-12 15:00:51 +000084
Patrick Georgi828e0e82015-04-04 15:50:20 +020085PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
86
Patrick Georgi0588d192009-08-12 15:00:51 +000087DOXYGEN := doxygen
88DOXYGEN_OUTPUT_DIR := doxygen
89
Patrick Georgi71b84802011-02-22 14:35:05 +000090all: real-all
91
Patrick Georgie38d0a62011-03-01 08:09:22 +000092# This include must come _before_ the pattern rules below!
Patrick Georgi71b84802011-02-22 14:35:05 +000093# Order _does_ matter for pattern rules.
Patrick Georgi71b84802011-02-22 14:35:05 +000094include util/kconfig/Makefile
95
Patrick Georgicf036d12010-04-21 06:36:20 +000096# Three cases where we don't need fully populated $(obj) lists:
97# 1. when no .config exists
98# 2. when make config (in any flavour) is run
99# 3. when make distclean is run
100# Don't waste time on reading all Makefile.incs in these cases
Patrick Georgi0588d192009-08-12 15:00:51 +0000101ifeq ($(strip $(HAVE_DOTCONFIG)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000102NOCOMPILE:=1
103endif
104ifneq ($(MAKECMDGOALS),)
Patrick Georgi7711c0d2015-02-17 12:21:32 +0100105ifneq ($(filter %config %clean cross% lint% what-jenkins-does,$(MAKECMDGOALS)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000106NOCOMPILE:=1
107endif
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100108ifeq ($(MAKECMDGOALS), %clean)
Zheng Bao0fd93d62012-10-22 16:36:03 +0800109NOMKDIR:=1
110endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000111endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000112
Patrick Georgicf036d12010-04-21 06:36:20 +0000113ifeq ($(NOCOMPILE),1)
Patrick Georgie38d0a62011-03-01 08:09:22 +0000114include $(TOPLEVEL)/Makefile.inc
Patrick Georgi71b84802011-02-22 14:35:05 +0000115real-all: config
Patrick Georgi0588d192009-08-12 15:00:51 +0000116
117else
118
Patrick Georgi977b9852010-09-24 22:15:54 +0000119include $(HAVE_DOTCONFIG)
Patrick Georgi0588d192009-08-12 15:00:51 +0000120
Patrick Georgi23d89cc2010-03-16 01:17:19 +0000121ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
Edward O'Callaghandd91c7f2014-06-28 03:02:52 +1000122# FIXME: armv7/aarch64 won't build right now
123# NOTE: clang puts compiler-rt under lib/linux/libclang_rt.builtins-i386.a
124# this means the triple is i386-linux-elf instead of i386-none-elf
125CFLAGS_x86_32 = -no-integrated-as -Qunused-arguments -target i386-linux-elf -m32
Edward O'Callaghan8916d0d2014-12-10 19:30:22 +1100126# Tone down some clang warnings
127CFLAGS_x86_32 += -Wno-unused-variable -Wno-unused-function -Wno-tautological-compare -Wno-shift-overflow
Patrick Georgicc84a002014-05-14 21:05:35 +0200128CC_x86_32:=clang
Edward O'Callaghan16407ab2014-10-30 11:36:42 +1100129HOSTCC := clang
Patrick Georgicc84a002014-05-14 21:05:35 +0200130
131ifneq ($(CONFIG_MMX),y)
132CFLAGS_x86_32 += -mno-mmx
133endif
134
135# FIXME: we end up with conflicting flags with this, not clear on this part.
136#ifneq ($(CONFIG_SSE),y)
137#CFLAGS_x86_32 += -mno-sse
138#endif
139
Gabe Black51edd542013-09-30 23:00:33 -0700140CFLAGS_arm = -no-integrated-as -Qunused-arguments -target arm-eabi -ccc-gcc-name $(CC_arm)
141CC_arm:=clang
Patrick Georgicc84a002014-05-14 21:05:35 +0200142
143CFLAGS_aarch64 = -no-integrated-as -Qunused-arguments -target aarch64-eabi -ccc-gcc-name $(CC_aarch64)
144CC_aarch64:=clang
Patrick Georgi23d89cc2010-03-16 01:17:19 +0000145endif
Patrick Georgi23d89cc2010-03-16 01:17:19 +0000146
Patrick Georgicc84a002014-05-14 21:05:35 +0200147include toolchain.inc
148
Patrick Georgia84e98b2010-03-16 19:01:32 +0000149strip_quotes = $(subst ",,$(subst \",,$(1)))
150
Patrick Georgi0588d192009-08-12 15:00:51 +0000151# The primary target needs to be here before we include the
152# other files
153
Patrick Georgi71b84802011-02-22 14:35:05 +0000154real-all: real-target
Patrick Georgi0588d192009-08-12 15:00:51 +0000155
Patrick Georgi51e142f2010-03-27 17:18:39 +0000156# must come rather early
157.SECONDEXPANSION:
158
Stefan Reinauer1425add2010-03-21 22:35:58 +0000159$(obj)/config.h:
160 $(MAKE) oldconfig
Patrick Georgi0588d192009-08-12 15:00:51 +0000161
Patrick Georgi58262652011-02-17 20:47:49 +0000162# Add a new class of source/object files to the build system
163add-class= \
164 $(eval $(1)-srcs:=) \
165 $(eval $(1)-objs:=) \
166 $(eval classes+=$(1))
Patrick Georgi8463dd92010-09-30 16:55:02 +0000167
Patrick Georgi58262652011-02-17 20:47:49 +0000168# Special classes are managed types with special behaviour
169# On parse time, for each entry in variable $(1)-y
170# a handler $(1)-handler is executed with the arguments:
171# * $(1): directory the parser is in
172# * $(2): current entry
173add-special-class= \
174 $(eval $(1):=) \
175 $(eval special-classes+=$(1))
176
Patrick Georgi47d68d82010-03-06 21:18:43 +0000177# Clean -y variables, include Makefile.inc
Patrick Georgi8463dd92010-09-30 16:55:02 +0000178# Add paths to files in X-y to X-srcs
Patrick Georgi47d68d82010-03-06 21:18:43 +0000179# Add subdirs-y to subdirs
180includemakefiles= \
Patrick Georgi58262652011-02-17 20:47:49 +0000181 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
Patrick Georgi47d68d82010-03-06 21:18:43 +0000182 $(eval -include $(1)) \
Patrick Georgi58262652011-02-17 20:47:49 +0000183 $(foreach class,$(classes-y), $(call add-class,$(class))) \
184 $(foreach class,$(classes), \
185 $(eval $(class)-srcs+= \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000186 $$(subst $(top)/,, \
Patrick Georgi29ddbb82011-05-20 23:31:41 +0000187 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y))))))) \
Patrick Georgi58262652011-02-17 20:47:49 +0000188 $(foreach special,$(special-classes), \
189 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
Jonathan Kollasch7ff5b442010-09-28 21:11:48 +0000190 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
Patrick Georgi47d68d82010-03-06 21:18:43 +0000191
Patrick Georgi8463dd92010-09-30 16:55:02 +0000192# For each path in $(subdirs) call includemakefiles
Patrick Georgi47d68d82010-03-06 21:18:43 +0000193# Repeat until subdirs is empty
194evaluate_subdirs= \
195 $(eval cursubdirs:=$(subdirs)) \
196 $(eval subdirs:=) \
197 $(foreach dir,$(cursubdirs), \
Patrick Georgi58262652011-02-17 20:47:49 +0000198 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000199 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000200
201# collect all object files eligible for building
Patrick Georgie38d0a62011-03-01 08:09:22 +0000202subdirs:=$(TOPLEVEL)
Patrick Georgi51e142f2010-03-27 17:18:39 +0000203$(eval $(call evaluate_subdirs))
Patrick Georgi70c85ea2013-02-16 01:06:57 +0100204ifeq ($(FAILBUILD),1)
205$(error cannot continue build)
206endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000207
Patrick Georgi94a45862011-10-25 14:32:21 -0700208# Eliminate duplicate mentions of source files in a class
209$(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
210
Patrick Georgidb273062015-03-27 17:03:28 +0100211# Converts one or more source file paths to their corresponding build/ paths.
212# Only .c and .S get converted to .o, other files (like .ld) keep their name.
213# $1 stage name
214# $2 file path (list)
Julius Wernera32b6f02015-03-12 23:17:16 -0700215src-to-obj=$(foreach file,$(2),$(subst .$(1),,$(basename $(patsubst src/%,$(obj)/%,$(file)))).$(1)$(patsubst %.c,%.o,$(patsubst %.S,%.o,$(suffix $(file)))))
Patrick Georgidb273062015-03-27 17:03:28 +0100216
Patrick Georgi10f86b02015-03-27 16:56:23 +0100217$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
Patrick Georgid3428b02010-02-24 13:18:01 +0000218
Nico Huber963bed52013-05-15 11:47:51 +0200219# Save all objs before processing them (for dependency inclusion)
220originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
221
Patrick Georgi79f90102012-11-25 14:31:08 +0100222# Call post-processors if they're defined
223$(foreach class,$(classes),\
224 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
225
Patrick Georgi58262652011-02-17 20:47:49 +0000226allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
227allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000228alldirs:=$(sort $(abspath $(dir $(allobjs))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000229
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000230# macro to define template macros that are used by use_template macro
231define create_cc_template
Patrick Georgi71b84802011-02-22 14:35:05 +0000232# $1 obj class
Patrick Georgi990e7c92015-04-03 10:47:15 +0200233# $2 source suffix (c, S, ld, ...)
Marc Jonesa38ccfd2014-11-06 15:50:22 -0700234# $3 additional compiler flags
235# $4 additional dependencies
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000236ifn$(EMPTY)def $(1)-objs_$(2)_template
Patrick Georgi8463dd92010-09-30 16:55:02 +0000237de$(EMPTY)fine $(1)-objs_$(2)_template
Patrick Georgid69839b2015-04-03 10:32:17 +0200238$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(obj)/config.h $(4)
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000239 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
Patrick Georgi75fcaf92015-04-03 10:16:12 +0200240 $(CC_$(1)) -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) $(3) -c -o $$$$@ $$$$<
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000241en$(EMPTY)def
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000242end$(EMPTY)if
Patrick Georgi0588d192009-08-12 15:00:51 +0000243endef
244
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000245filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
246$(foreach class,$(classes), \
247 $(foreach type,$(call filetypes-of-class,$(class)), \
Patrick Georgi2459aee2015-03-27 15:27:21 +0100248 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
Patrick Georgi416ab382015-04-03 10:19:38 +0200249 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
250 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000251
Patrick Georgid69839b2015-04-03 10:32:17 +0200252foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
Patrick Georgi58262652011-02-17 20:47:49 +0000253$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000254
Julius Wernerf97b88b2014-12-05 12:32:09 -0800255DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000256-include $(DEPENDENCIES)
257
Patrick Georgi0588d192009-08-12 15:00:51 +0000258printall:
Patrick Georgi71b84802011-02-22 14:35:05 +0000259 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
Patrick Georgi0588d192009-08-12 15:00:51 +0000260 @echo alldirs:=$(alldirs)
Patrick Georgi8463dd92010-09-30 16:55:02 +0000261 @echo allsrcs=$(allsrcs)
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000262 @echo DEPENDENCIES=$(DEPENDENCIES)
Patrick Georgi71b84802011-02-22 14:35:05 +0000263 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
Patrick Georgi0588d192009-08-12 15:00:51 +0000264
265endif
266
Patrick Georgi40ad8422011-05-21 22:18:59 +0000267ifndef NOMKDIR
Patrick Georgid5208402014-04-11 20:24:06 +0200268$(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objutil)/kconfig/lxdialog $(additional-dirs) $(alldirs))
Patrick Georgi40ad8422011-05-21 22:18:59 +0000269endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000270
Warren Turkala9fc3302010-09-03 08:57:32 +0000271cscope:
272 cscope -bR
273
Patrick Georgi0588d192009-08-12 15:00:51 +0000274doxy: doxygen
275doxygen:
Stefan Reinauer1bbad5c2010-02-10 15:36:53 +0000276 $(DOXYGEN) documentation/Doxyfile.coreboot
Patrick Georgi0588d192009-08-12 15:00:51 +0000277
Martin Rothd7689e42014-12-29 14:56:19 -0700278doxygen_simple:
279 $(DOXYGEN) documentation/Doxyfile.coreboot_simple
280
Patrick Georgi0588d192009-08-12 15:00:51 +0000281doxyclean: doxygen-clean
282doxygen-clean:
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000283 rm -rf $(DOXYGEN_OUTPUT_DIR)
Patrick Georgi0588d192009-08-12 15:00:51 +0000284
Patrick Georgi71b84802011-02-22 14:35:05 +0000285clean-for-update: doxygen-clean clean-for-update-target
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100286 rm -rf $(obj) .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000287
Patrick Georgi71b84802011-02-22 14:35:05 +0000288clean: clean-for-update clean-target
289 rm -f .ccwrap
Warren Turkal0e8f2042010-09-27 21:14:19 +0000290
Warren Turkala9fc3302010-09-03 08:57:32 +0000291clean-cscope:
292 rm -f cscope.out
293
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100294distclean: clean
Patrick Georgicf036d12010-04-21 06:36:20 +0000295 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000296
Martin Rothd7689e42014-12-29 14:56:19 -0700297.PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple