blob: 195bfe69dcb7d4d64e1842c57dd2a11466bd7569 [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
Marc Jones616da1e2011-10-07 17:20:30 -060033$(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile $(XGCCPATH) > .xcompile)))
Patrick Georgi0588d192009-08-12 15:00:51 +000034include .xcompile
Patrick Georgi23d89cc2010-03-16 01:17:19 +000035
Jonathan Kollasch7ff5b442010-09-28 21:11:48 +000036export top := $(CURDIR)
Patrick Georgi51e142f2010-03-27 17:18:39 +000037export src := src
Patrick Georgi0588d192009-08-12 15:00:51 +000038export srck := $(top)/util/kconfig
Patrick Georgi51e142f2010-03-27 17:18:39 +000039export obj ?= build
Patrick Georgia2acbc72010-04-16 22:48:57 +000040export objutil ?= $(obj)/util
41export objk := $(objutil)/kconfig
Patrick Georgi0588d192009-08-12 15:00:51 +000042
43
Patrick Georgi0588d192009-08-12 15:00:51 +000044export KCONFIG_AUTOHEADER := $(obj)/config.h
45export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
Patrick Georgid5208402014-04-11 20:24:06 +020046export KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
47export KCONFIG_SPLITCONFIG := $(obj)/config
48export KCONFIG_TRISTATE := $(obj)/tristate.conf
49export KCONFIG_NEGATIVES := 1
Patrick Georgi0588d192009-08-12 15:00:51 +000050
Patrick Georgie38d0a62011-03-01 08:09:22 +000051# directory containing the toplevel Makefile.inc
52TOPLEVEL := .
53
Patrick Georgi0588d192009-08-12 15:00:51 +000054CONFIG_SHELL := sh
55KBUILD_DEFCONFIG := configs/defconfig
56UNAME_RELEASE := $(shell uname -r)
Patrick Georgi89ec3762010-12-08 19:58:30 +000057DOTCONFIG ?= .config
58KCONFIG_CONFIG = $(DOTCONFIG)
59export KCONFIG_CONFIG
60HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
Patrick Georgi0588d192009-08-12 15:00:51 +000061MAKEFLAGS += -rR --no-print-directory
62
63# Make is silent per default, but 'make V=1' will show all compiler calls.
Patrick Georgi2b7418e2009-08-25 19:38:46 +000064Q:=@
Patrick Georgi0588d192009-08-12 15:00:51 +000065ifneq ($(V),1)
Patrick Georgi2b7418e2009-08-25 19:38:46 +000066ifneq ($(Q),)
67.SILENT:
68endif
Patrick Georgi0588d192009-08-12 15:00:51 +000069endif
70
Patrick Georgi0588d192009-08-12 15:00:51 +000071HOSTCC = gcc
72HOSTCXX = g++
Patrick Georgib3a18ac2012-09-13 22:13:33 +020073HOSTCFLAGS := -g
74HOSTCXXFLAGS := -g
Patrick Georgi0588d192009-08-12 15:00:51 +000075
76DOXYGEN := doxygen
77DOXYGEN_OUTPUT_DIR := doxygen
78
Patrick Georgi71b84802011-02-22 14:35:05 +000079all: real-all
80
Patrick Georgie38d0a62011-03-01 08:09:22 +000081# This include must come _before_ the pattern rules below!
Patrick Georgi71b84802011-02-22 14:35:05 +000082# Order _does_ matter for pattern rules.
Patrick Georgi71b84802011-02-22 14:35:05 +000083include util/kconfig/Makefile
84
Patrick Georgicf036d12010-04-21 06:36:20 +000085# Three cases where we don't need fully populated $(obj) lists:
86# 1. when no .config exists
87# 2. when make config (in any flavour) is run
88# 3. when make distclean is run
89# Don't waste time on reading all Makefile.incs in these cases
Patrick Georgi0588d192009-08-12 15:00:51 +000090ifeq ($(strip $(HAVE_DOTCONFIG)),)
Patrick Georgicf036d12010-04-21 06:36:20 +000091NOCOMPILE:=1
92endif
93ifneq ($(MAKECMDGOALS),)
Patrick Georgic38f3ae2014-04-26 15:29:10 +020094ifneq ($(filter %config %clean cross%,$(MAKECMDGOALS)),)
Patrick Georgicf036d12010-04-21 06:36:20 +000095NOCOMPILE:=1
96endif
Patrick Georgi02ae0bf2013-02-09 15:45:02 +010097ifeq ($(MAKECMDGOALS), %clean)
Zheng Bao0fd93d62012-10-22 16:36:03 +080098NOMKDIR:=1
99endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000100endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000101
Patrick Georgicf036d12010-04-21 06:36:20 +0000102ifeq ($(NOCOMPILE),1)
Patrick Georgie38d0a62011-03-01 08:09:22 +0000103include $(TOPLEVEL)/Makefile.inc
Patrick Georgi71b84802011-02-22 14:35:05 +0000104real-all: config
Patrick Georgi0588d192009-08-12 15:00:51 +0000105
106else
107
Patrick Georgi977b9852010-09-24 22:15:54 +0000108include $(HAVE_DOTCONFIG)
Patrick Georgi0588d192009-08-12 15:00:51 +0000109
Patrick Georgi23d89cc2010-03-16 01:17:19 +0000110ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
Patrick Georgicc84a002014-05-14 21:05:35 +0200111# FIXME: armv7/aarch64 won't build right now
112CFLAGS_x86_32 = -no-integrated-as -Qunused-arguments -target i386-elf -m32
113CC_x86_32:=clang
114
115ifneq ($(CONFIG_MMX),y)
116CFLAGS_x86_32 += -mno-mmx
117endif
118
119# FIXME: we end up with conflicting flags with this, not clear on this part.
120#ifneq ($(CONFIG_SSE),y)
121#CFLAGS_x86_32 += -mno-sse
122#endif
123
124CFLAGS_armv7 = -no-integrated-as -Qunused-arguments -target armv7-eabi -ccc-gcc-name $(CC_armv7)
125CC_armv7:=clang
126
127CFLAGS_aarch64 = -no-integrated-as -Qunused-arguments -target aarch64-eabi -ccc-gcc-name $(CC_aarch64)
128CC_aarch64:=clang
129
Patrick Georgi23d89cc2010-03-16 01:17:19 +0000130HOSTCC:=clang
131endif
Patrick Georgi23d89cc2010-03-16 01:17:19 +0000132
Patrick Georgicc84a002014-05-14 21:05:35 +0200133include toolchain.inc
134
Patrick Georgia84e98b2010-03-16 19:01:32 +0000135strip_quotes = $(subst ",,$(subst \",,$(1)))
136
Patrick Georgi0588d192009-08-12 15:00:51 +0000137# The primary target needs to be here before we include the
138# other files
139
Patrick Georgi71b84802011-02-22 14:35:05 +0000140real-all: real-target
Patrick Georgi0588d192009-08-12 15:00:51 +0000141
Patrick Georgi51e142f2010-03-27 17:18:39 +0000142# must come rather early
143.SECONDEXPANSION:
144
Stefan Reinauer1425add2010-03-21 22:35:58 +0000145$(obj)/config.h:
146 $(MAKE) oldconfig
Patrick Georgi0588d192009-08-12 15:00:51 +0000147
Patrick Georgi58262652011-02-17 20:47:49 +0000148# Add a new class of source/object files to the build system
149add-class= \
150 $(eval $(1)-srcs:=) \
151 $(eval $(1)-objs:=) \
152 $(eval classes+=$(1))
Patrick Georgi8463dd92010-09-30 16:55:02 +0000153
Patrick Georgi58262652011-02-17 20:47:49 +0000154# Special classes are managed types with special behaviour
155# On parse time, for each entry in variable $(1)-y
156# a handler $(1)-handler is executed with the arguments:
157# * $(1): directory the parser is in
158# * $(2): current entry
159add-special-class= \
160 $(eval $(1):=) \
161 $(eval special-classes+=$(1))
162
Patrick Georgi47d68d82010-03-06 21:18:43 +0000163# Clean -y variables, include Makefile.inc
Patrick Georgi8463dd92010-09-30 16:55:02 +0000164# Add paths to files in X-y to X-srcs
Patrick Georgi47d68d82010-03-06 21:18:43 +0000165# Add subdirs-y to subdirs
166includemakefiles= \
Patrick Georgi58262652011-02-17 20:47:49 +0000167 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
Patrick Georgi47d68d82010-03-06 21:18:43 +0000168 $(eval -include $(1)) \
Patrick Georgi58262652011-02-17 20:47:49 +0000169 $(foreach class,$(classes-y), $(call add-class,$(class))) \
170 $(foreach class,$(classes), \
171 $(eval $(class)-srcs+= \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000172 $$(subst $(top)/,, \
Patrick Georgi29ddbb82011-05-20 23:31:41 +0000173 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y))))))) \
Patrick Georgi58262652011-02-17 20:47:49 +0000174 $(foreach special,$(special-classes), \
175 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
Jonathan Kollasch7ff5b442010-09-28 21:11:48 +0000176 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
Patrick Georgi47d68d82010-03-06 21:18:43 +0000177
Patrick Georgi8463dd92010-09-30 16:55:02 +0000178# For each path in $(subdirs) call includemakefiles
Patrick Georgi47d68d82010-03-06 21:18:43 +0000179# Repeat until subdirs is empty
180evaluate_subdirs= \
181 $(eval cursubdirs:=$(subdirs)) \
182 $(eval subdirs:=) \
183 $(foreach dir,$(cursubdirs), \
Patrick Georgi58262652011-02-17 20:47:49 +0000184 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000185 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000186
187# collect all object files eligible for building
Patrick Georgie38d0a62011-03-01 08:09:22 +0000188subdirs:=$(TOPLEVEL)
Patrick Georgi51e142f2010-03-27 17:18:39 +0000189$(eval $(call evaluate_subdirs))
Patrick Georgi70c85ea2013-02-16 01:06:57 +0100190ifeq ($(FAILBUILD),1)
191$(error cannot continue build)
192endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000193
Patrick Georgi94a45862011-10-25 14:32:21 -0700194# Eliminate duplicate mentions of source files in a class
195$(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
196
Patrick Georgi8463dd92010-09-30 16:55:02 +0000197src-to-obj=$(addsuffix .$(1).o, $(basename $(patsubst src/%, $(obj)/%, $($(1)-srcs))))
Patrick Georgi58262652011-02-17 20:47:49 +0000198$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class))))
Patrick Georgid3428b02010-02-24 13:18:01 +0000199
Nico Huber963bed52013-05-15 11:47:51 +0200200# Save all objs before processing them (for dependency inclusion)
201originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
202
Patrick Georgi79f90102012-11-25 14:31:08 +0100203# Call post-processors if they're defined
204$(foreach class,$(classes),\
205 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
206
Patrick Georgi58262652011-02-17 20:47:49 +0000207allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
208allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000209alldirs:=$(sort $(abspath $(dir $(allobjs))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000210
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000211# macro to define template macros that are used by use_template macro
212define create_cc_template
Patrick Georgi71b84802011-02-22 14:35:05 +0000213# $1 obj class
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000214# $2 source suffix (c, S)
Patrick Georgi8463dd92010-09-30 16:55:02 +0000215# $3 additional compiler flags
Patrick Georgi57205c72011-03-08 20:49:18 +0000216# $4 additional dependencies
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000217ifn$(EMPTY)def $(1)-objs_$(2)_template
Patrick Georgi8463dd92010-09-30 16:55:02 +0000218de$(EMPTY)fine $(1)-objs_$(2)_template
Patrick Georgi57205c72011-03-08 20:49:18 +0000219$(obj)/$$(1).$(1).o: src/$$(1).$(2) $(obj)/config.h $(4)
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000220 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
Patrick Georgi58f73a62014-05-17 14:00:12 +0200221 $(CC_$(1)) $(3) -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -c -o $$$$@ $$$$<
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000222en$(EMPTY)def
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000223end$(EMPTY)if
Patrick Georgi0588d192009-08-12 15:00:51 +0000224endef
225
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000226filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
227$(foreach class,$(classes), \
228 $(foreach type,$(call filetypes-of-class,$(class)), \
Patrick Georgi57205c72011-03-08 20:49:18 +0000229 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps)))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000230
Patrick Georgi8463dd92010-09-30 16:55:02 +0000231foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(subst src/,,$(basename $(file))))))
Patrick Georgi58262652011-02-17 20:47:49 +0000232$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000233
Nico Huber963bed52013-05-15 11:47:51 +0200234DEPENDENCIES = $(originalobjs:.o=.d)
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000235-include $(DEPENDENCIES)
236
Patrick Georgi0588d192009-08-12 15:00:51 +0000237printall:
Patrick Georgi71b84802011-02-22 14:35:05 +0000238 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
Patrick Georgi0588d192009-08-12 15:00:51 +0000239 @echo alldirs:=$(alldirs)
Patrick Georgi8463dd92010-09-30 16:55:02 +0000240 @echo allsrcs=$(allsrcs)
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000241 @echo DEPENDENCIES=$(DEPENDENCIES)
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700242 @echo LIBGCC_FILE_NAME=$(LIBGCC_FILE_NAME_$(class))
Patrick Georgi71b84802011-02-22 14:35:05 +0000243 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
Patrick Georgi0588d192009-08-12 15:00:51 +0000244
245endif
246
Patrick Georgi40ad8422011-05-21 22:18:59 +0000247ifndef NOMKDIR
Patrick Georgid5208402014-04-11 20:24:06 +0200248$(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objutil)/kconfig/lxdialog $(additional-dirs) $(alldirs))
Patrick Georgi40ad8422011-05-21 22:18:59 +0000249endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000250
Warren Turkala9fc3302010-09-03 08:57:32 +0000251cscope:
252 cscope -bR
253
Patrick Georgi0588d192009-08-12 15:00:51 +0000254doxy: doxygen
255doxygen:
Stefan Reinauer1bbad5c2010-02-10 15:36:53 +0000256 $(DOXYGEN) documentation/Doxyfile.coreboot
Patrick Georgi0588d192009-08-12 15:00:51 +0000257
258doxyclean: doxygen-clean
259doxygen-clean:
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000260 rm -rf $(DOXYGEN_OUTPUT_DIR)
Patrick Georgi0588d192009-08-12 15:00:51 +0000261
Patrick Georgi71b84802011-02-22 14:35:05 +0000262clean-for-update: doxygen-clean clean-for-update-target
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100263 rm -rf $(obj) .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000264
Patrick Georgi71b84802011-02-22 14:35:05 +0000265clean: clean-for-update clean-target
266 rm -f .ccwrap
Warren Turkal0e8f2042010-09-27 21:14:19 +0000267
Warren Turkala9fc3302010-09-03 08:57:32 +0000268clean-cscope:
269 rm -f cscope.out
270
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100271distclean: clean
Patrick Georgicf036d12010-04-21 06:36:20 +0000272 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000273
Patrick Georgi48159132013-02-11 20:56:46 +0100274.PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy .xcompile