blob: 49fbba5e5f8d520f993929c91a8946af3c5222d4 [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
Patrick Georgi0588d192009-08-12 15:00:51 +000077HOSTCC = gcc
Edward O'Callaghan480790b2014-06-27 18:14:47 +100078ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
79HOSTCC := clang
80endif
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
85DOXYGEN := doxygen
86DOXYGEN_OUTPUT_DIR := doxygen
87
Patrick Georgi71b84802011-02-22 14:35:05 +000088all: real-all
89
Patrick Georgie38d0a62011-03-01 08:09:22 +000090# This include must come _before_ the pattern rules below!
Patrick Georgi71b84802011-02-22 14:35:05 +000091# Order _does_ matter for pattern rules.
Patrick Georgi71b84802011-02-22 14:35:05 +000092include util/kconfig/Makefile
93
Patrick Georgicf036d12010-04-21 06:36:20 +000094# Three cases where we don't need fully populated $(obj) lists:
95# 1. when no .config exists
96# 2. when make config (in any flavour) is run
97# 3. when make distclean is run
98# Don't waste time on reading all Makefile.incs in these cases
Patrick Georgi0588d192009-08-12 15:00:51 +000099ifeq ($(strip $(HAVE_DOTCONFIG)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000100NOCOMPILE:=1
101endif
102ifneq ($(MAKECMDGOALS),)
Patrick Georgic38f3ae2014-04-26 15:29:10 +0200103ifneq ($(filter %config %clean cross%,$(MAKECMDGOALS)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000104NOCOMPILE:=1
105endif
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100106ifeq ($(MAKECMDGOALS), %clean)
Zheng Bao0fd93d62012-10-22 16:36:03 +0800107NOMKDIR:=1
108endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000109endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000110
Patrick Georgicf036d12010-04-21 06:36:20 +0000111ifeq ($(NOCOMPILE),1)
Patrick Georgie38d0a62011-03-01 08:09:22 +0000112include $(TOPLEVEL)/Makefile.inc
Patrick Georgi71b84802011-02-22 14:35:05 +0000113real-all: config
Patrick Georgi0588d192009-08-12 15:00:51 +0000114
115else
116
Patrick Georgi977b9852010-09-24 22:15:54 +0000117include $(HAVE_DOTCONFIG)
Patrick Georgi0588d192009-08-12 15:00:51 +0000118
Patrick Georgi23d89cc2010-03-16 01:17:19 +0000119ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
Gabe Black51edd542013-09-30 23:00:33 -0700120# FIXME: arm/aarch64 won't build right now
Patrick Georgicc84a002014-05-14 21:05:35 +0200121CFLAGS_x86_32 = -no-integrated-as -Qunused-arguments -target i386-elf -m32
122CC_x86_32:=clang
123
124ifneq ($(CONFIG_MMX),y)
125CFLAGS_x86_32 += -mno-mmx
126endif
127
128# FIXME: we end up with conflicting flags with this, not clear on this part.
129#ifneq ($(CONFIG_SSE),y)
130#CFLAGS_x86_32 += -mno-sse
131#endif
132
Gabe Black51edd542013-09-30 23:00:33 -0700133CFLAGS_arm = -no-integrated-as -Qunused-arguments -target arm-eabi -ccc-gcc-name $(CC_arm)
134CC_arm:=clang
Patrick Georgicc84a002014-05-14 21:05:35 +0200135
136CFLAGS_aarch64 = -no-integrated-as -Qunused-arguments -target aarch64-eabi -ccc-gcc-name $(CC_aarch64)
137CC_aarch64:=clang
Patrick Georgi23d89cc2010-03-16 01:17:19 +0000138endif
Patrick Georgi23d89cc2010-03-16 01:17:19 +0000139
Patrick Georgicc84a002014-05-14 21:05:35 +0200140include toolchain.inc
141
Patrick Georgia84e98b2010-03-16 19:01:32 +0000142strip_quotes = $(subst ",,$(subst \",,$(1)))
143
Patrick Georgi0588d192009-08-12 15:00:51 +0000144# The primary target needs to be here before we include the
145# other files
146
Patrick Georgi71b84802011-02-22 14:35:05 +0000147real-all: real-target
Patrick Georgi0588d192009-08-12 15:00:51 +0000148
Patrick Georgi51e142f2010-03-27 17:18:39 +0000149# must come rather early
150.SECONDEXPANSION:
151
Stefan Reinauer1425add2010-03-21 22:35:58 +0000152$(obj)/config.h:
153 $(MAKE) oldconfig
Patrick Georgi0588d192009-08-12 15:00:51 +0000154
Patrick Georgi58262652011-02-17 20:47:49 +0000155# Add a new class of source/object files to the build system
156add-class= \
157 $(eval $(1)-srcs:=) \
158 $(eval $(1)-objs:=) \
159 $(eval classes+=$(1))
Patrick Georgi8463dd92010-09-30 16:55:02 +0000160
Patrick Georgi58262652011-02-17 20:47:49 +0000161# Special classes are managed types with special behaviour
162# On parse time, for each entry in variable $(1)-y
163# a handler $(1)-handler is executed with the arguments:
164# * $(1): directory the parser is in
165# * $(2): current entry
166add-special-class= \
167 $(eval $(1):=) \
168 $(eval special-classes+=$(1))
169
Patrick Georgi47d68d82010-03-06 21:18:43 +0000170# Clean -y variables, include Makefile.inc
Patrick Georgi8463dd92010-09-30 16:55:02 +0000171# Add paths to files in X-y to X-srcs
Patrick Georgi47d68d82010-03-06 21:18:43 +0000172# Add subdirs-y to subdirs
173includemakefiles= \
Patrick Georgi58262652011-02-17 20:47:49 +0000174 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
Patrick Georgi47d68d82010-03-06 21:18:43 +0000175 $(eval -include $(1)) \
Patrick Georgi58262652011-02-17 20:47:49 +0000176 $(foreach class,$(classes-y), $(call add-class,$(class))) \
177 $(foreach class,$(classes), \
178 $(eval $(class)-srcs+= \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000179 $$(subst $(top)/,, \
Patrick Georgi29ddbb82011-05-20 23:31:41 +0000180 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y))))))) \
Patrick Georgi58262652011-02-17 20:47:49 +0000181 $(foreach special,$(special-classes), \
182 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
Jonathan Kollasch7ff5b442010-09-28 21:11:48 +0000183 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
Patrick Georgi47d68d82010-03-06 21:18:43 +0000184
Patrick Georgi8463dd92010-09-30 16:55:02 +0000185# For each path in $(subdirs) call includemakefiles
Patrick Georgi47d68d82010-03-06 21:18:43 +0000186# Repeat until subdirs is empty
187evaluate_subdirs= \
188 $(eval cursubdirs:=$(subdirs)) \
189 $(eval subdirs:=) \
190 $(foreach dir,$(cursubdirs), \
Patrick Georgi58262652011-02-17 20:47:49 +0000191 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000192 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000193
194# collect all object files eligible for building
Patrick Georgie38d0a62011-03-01 08:09:22 +0000195subdirs:=$(TOPLEVEL)
Patrick Georgi51e142f2010-03-27 17:18:39 +0000196$(eval $(call evaluate_subdirs))
Patrick Georgi70c85ea2013-02-16 01:06:57 +0100197ifeq ($(FAILBUILD),1)
198$(error cannot continue build)
199endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000200
Patrick Georgi94a45862011-10-25 14:32:21 -0700201# Eliminate duplicate mentions of source files in a class
202$(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
203
Patrick Georgi8463dd92010-09-30 16:55:02 +0000204src-to-obj=$(addsuffix .$(1).o, $(basename $(patsubst src/%, $(obj)/%, $($(1)-srcs))))
Patrick Georgi58262652011-02-17 20:47:49 +0000205$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class))))
Patrick Georgid3428b02010-02-24 13:18:01 +0000206
Nico Huber963bed52013-05-15 11:47:51 +0200207# Save all objs before processing them (for dependency inclusion)
208originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
209
Patrick Georgi79f90102012-11-25 14:31:08 +0100210# Call post-processors if they're defined
211$(foreach class,$(classes),\
212 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
213
Patrick Georgi58262652011-02-17 20:47:49 +0000214allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
215allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000216alldirs:=$(sort $(abspath $(dir $(allobjs))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000217
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000218# macro to define template macros that are used by use_template macro
219define create_cc_template
Patrick Georgi71b84802011-02-22 14:35:05 +0000220# $1 obj class
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000221# $2 source suffix (c, S)
Patrick Georgi25b56c32014-05-25 00:11:35 +0200222# $3 additional dependencies
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000223ifn$(EMPTY)def $(1)-objs_$(2)_template
Patrick Georgi8463dd92010-09-30 16:55:02 +0000224de$(EMPTY)fine $(1)-objs_$(2)_template
Patrick Georgi25b56c32014-05-25 00:11:35 +0200225$(obj)/$$(1).$(1).o: src/$$(1).$(2) $(obj)/config.h $(3)
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000226 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
Patrick Georgi25b56c32014-05-25 00:11:35 +0200227 $(CC_$(1)) -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -c -o $$$$@ $$$$<
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000228en$(EMPTY)def
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000229end$(EMPTY)if
Patrick Georgi0588d192009-08-12 15:00:51 +0000230endef
231
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000232filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
233$(foreach class,$(classes), \
234 $(foreach type,$(call filetypes-of-class,$(class)), \
Patrick Georgi25b56c32014-05-25 00:11:35 +0200235 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-deps)))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000236
Patrick Georgi8463dd92010-09-30 16:55:02 +0000237foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(subst src/,,$(basename $(file))))))
Patrick Georgi58262652011-02-17 20:47:49 +0000238$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000239
Nico Huber963bed52013-05-15 11:47:51 +0200240DEPENDENCIES = $(originalobjs:.o=.d)
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000241-include $(DEPENDENCIES)
242
Patrick Georgi0588d192009-08-12 15:00:51 +0000243printall:
Patrick Georgi71b84802011-02-22 14:35:05 +0000244 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
Patrick Georgi0588d192009-08-12 15:00:51 +0000245 @echo alldirs:=$(alldirs)
Patrick Georgi8463dd92010-09-30 16:55:02 +0000246 @echo allsrcs=$(allsrcs)
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000247 @echo DEPENDENCIES=$(DEPENDENCIES)
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700248 @echo LIBGCC_FILE_NAME=$(LIBGCC_FILE_NAME_$(class))
Patrick Georgi71b84802011-02-22 14:35:05 +0000249 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
Patrick Georgi0588d192009-08-12 15:00:51 +0000250
251endif
252
Patrick Georgi40ad8422011-05-21 22:18:59 +0000253ifndef NOMKDIR
Patrick Georgid5208402014-04-11 20:24:06 +0200254$(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objutil)/kconfig/lxdialog $(additional-dirs) $(alldirs))
Patrick Georgi40ad8422011-05-21 22:18:59 +0000255endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000256
Warren Turkala9fc3302010-09-03 08:57:32 +0000257cscope:
258 cscope -bR
259
Patrick Georgi0588d192009-08-12 15:00:51 +0000260doxy: doxygen
261doxygen:
Stefan Reinauer1bbad5c2010-02-10 15:36:53 +0000262 $(DOXYGEN) documentation/Doxyfile.coreboot
Patrick Georgi0588d192009-08-12 15:00:51 +0000263
264doxyclean: doxygen-clean
265doxygen-clean:
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000266 rm -rf $(DOXYGEN_OUTPUT_DIR)
Patrick Georgi0588d192009-08-12 15:00:51 +0000267
Patrick Georgi71b84802011-02-22 14:35:05 +0000268clean-for-update: doxygen-clean clean-for-update-target
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100269 rm -rf $(obj) .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000270
Patrick Georgi71b84802011-02-22 14:35:05 +0000271clean: clean-for-update clean-target
272 rm -f .ccwrap
Warren Turkal0e8f2042010-09-27 21:14:19 +0000273
Warren Turkala9fc3302010-09-03 08:57:32 +0000274clean-cscope:
275 rm -f cscope.out
276
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100277distclean: clean
Patrick Georgicf036d12010-04-21 06:36:20 +0000278 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000279
Patrick Georgi18ff4f12014-07-10 21:06:04 +0200280.PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy