blob: 91fc3c04f5a748ed687c8a94c554dcd60d463936 [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 Georgi020f51f2010-03-14 21:25:03 +000033ifeq ($(INNER_SCANBUILD),y)
34CC_real:=$(CC)
35endif
Patrick Georgi23d89cc2010-03-16 01:17:19 +000036
Marc Jones616da1e2011-10-07 17:20:30 -060037$(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile $(XGCCPATH) > .xcompile)))
Patrick Georgi0588d192009-08-12 15:00:51 +000038include .xcompile
Patrick Georgi23d89cc2010-03-16 01:17:19 +000039
Patrick Georgi020f51f2010-03-14 21:25:03 +000040ifeq ($(INNER_SCANBUILD),y)
41CC:=$(CC_real)
42HOSTCC:=$(CC_real) --hostcc
43HOSTCXX:=$(CC_real) --hostcxx
44endif
Patrick Georgi0588d192009-08-12 15:00:51 +000045
Jonathan Kollasch7ff5b442010-09-28 21:11:48 +000046export top := $(CURDIR)
Patrick Georgi51e142f2010-03-27 17:18:39 +000047export src := src
Patrick Georgi0588d192009-08-12 15:00:51 +000048export srck := $(top)/util/kconfig
Patrick Georgi51e142f2010-03-27 17:18:39 +000049export obj ?= build
Patrick Georgia2acbc72010-04-16 22:48:57 +000050export objutil ?= $(obj)/util
51export objk := $(objutil)/kconfig
Patrick Georgi0588d192009-08-12 15:00:51 +000052
53
Patrick Georgi0588d192009-08-12 15:00:51 +000054export KCONFIG_AUTOHEADER := $(obj)/config.h
55export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
Patrick Georgid5208402014-04-11 20:24:06 +020056export KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
57export KCONFIG_SPLITCONFIG := $(obj)/config
58export KCONFIG_TRISTATE := $(obj)/tristate.conf
59export KCONFIG_NEGATIVES := 1
Patrick Georgi0588d192009-08-12 15:00:51 +000060
Patrick Georgie38d0a62011-03-01 08:09:22 +000061# directory containing the toplevel Makefile.inc
62TOPLEVEL := .
63
Patrick Georgi0588d192009-08-12 15:00:51 +000064CONFIG_SHELL := sh
65KBUILD_DEFCONFIG := configs/defconfig
66UNAME_RELEASE := $(shell uname -r)
Patrick Georgi89ec3762010-12-08 19:58:30 +000067DOTCONFIG ?= .config
68KCONFIG_CONFIG = $(DOTCONFIG)
69export KCONFIG_CONFIG
70HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
Patrick Georgi0588d192009-08-12 15:00:51 +000071MAKEFLAGS += -rR --no-print-directory
72
73# Make is silent per default, but 'make V=1' will show all compiler calls.
Patrick Georgi2b7418e2009-08-25 19:38:46 +000074Q:=@
Patrick Georgi0588d192009-08-12 15:00:51 +000075ifneq ($(V),1)
Patrick Georgi2b7418e2009-08-25 19:38:46 +000076ifneq ($(Q),)
77.SILENT:
78endif
Patrick Georgi0588d192009-08-12 15:00:51 +000079endif
80
Patrick Georgi0588d192009-08-12 15:00:51 +000081HOSTCC = gcc
82HOSTCXX = g++
Patrick Georgib3a18ac2012-09-13 22:13:33 +020083HOSTCFLAGS := -g
84HOSTCXXFLAGS := -g
Patrick Georgi0588d192009-08-12 15:00:51 +000085
86DOXYGEN := doxygen
87DOXYGEN_OUTPUT_DIR := doxygen
88
Patrick Georgi71b84802011-02-22 14:35:05 +000089all: real-all
90
Patrick Georgie38d0a62011-03-01 08:09:22 +000091# This include must come _before_ the pattern rules below!
Patrick Georgi71b84802011-02-22 14:35:05 +000092# Order _does_ matter for pattern rules.
Patrick Georgi71b84802011-02-22 14:35:05 +000093include util/kconfig/Makefile
94
Patrick Georgicf036d12010-04-21 06:36:20 +000095# Three cases where we don't need fully populated $(obj) lists:
96# 1. when no .config exists
97# 2. when make config (in any flavour) is run
98# 3. when make distclean is run
99# Don't waste time on reading all Makefile.incs in these cases
Patrick Georgi0588d192009-08-12 15:00:51 +0000100ifeq ($(strip $(HAVE_DOTCONFIG)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000101NOCOMPILE:=1
102endif
103ifneq ($(MAKECMDGOALS),)
Patrick Georgic38f3ae2014-04-26 15:29:10 +0200104ifneq ($(filter %config %clean cross%,$(MAKECMDGOALS)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000105NOCOMPILE:=1
106endif
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100107ifeq ($(MAKECMDGOALS), %clean)
Zheng Bao0fd93d62012-10-22 16:36:03 +0800108NOMKDIR:=1
109endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000110endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000111
Patrick Georgicf036d12010-04-21 06:36:20 +0000112ifeq ($(NOCOMPILE),1)
Patrick Georgie38d0a62011-03-01 08:09:22 +0000113include $(TOPLEVEL)/Makefile.inc
Patrick Georgi71b84802011-02-22 14:35:05 +0000114real-all: config
Patrick Georgi0588d192009-08-12 15:00:51 +0000115
116else
117
Patrick Georgi977b9852010-09-24 22:15:54 +0000118include $(HAVE_DOTCONFIG)
Patrick Georgi0588d192009-08-12 15:00:51 +0000119
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700120include toolchain.inc
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800121
Patrick Georgi23d89cc2010-03-16 01:17:19 +0000122ifneq ($(INNER_SCANBUILD),y)
123ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
Patrick Georgife9210f2012-03-11 20:44:22 +0100124CC:=clang -m32 -mno-mmx -mno-sse
Patrick Georgi23d89cc2010-03-16 01:17:19 +0000125HOSTCC:=clang
126endif
127endif
128
Patrick Georgi516a2a72010-03-25 21:45:25 +0000129ifeq ($(CONFIG_CCACHE),y)
Patrick Georgi96dafaf2011-05-20 22:14:07 +0000130CCACHE:=$(word 1,$(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH)))))
Patrick Georgi516a2a72010-03-25 21:45:25 +0000131ifeq ($(CCACHE),)
132$(error ccache selected, but not found in PATH)
133endif
Patrick Georgi977b9852010-09-24 22:15:54 +0000134CCACHE:=CCACHE_COMPILERCHECK=content CCACHE_BASEDIR=$(top) $(CCACHE)
Patrick Georgi516a2a72010-03-25 21:45:25 +0000135CC := $(CCACHE) $(CC)
136HOSTCC := $(CCACHE) $(HOSTCC)
137HOSTCXX := $(CCACHE) $(HOSTCXX)
138ROMCC := $(CCACHE) $(ROMCC)
139endif
140
Patrick Georgia84e98b2010-03-16 19:01:32 +0000141strip_quotes = $(subst ",,$(subst \",,$(1)))
142
Patrick Georgi0588d192009-08-12 15:00:51 +0000143# The primary target needs to be here before we include the
144# other files
145
Patrick Georgi020f51f2010-03-14 21:25:03 +0000146ifeq ($(INNER_SCANBUILD),y)
147CONFIG_SCANBUILD_ENABLE:=
148endif
149
150ifeq ($(CONFIG_SCANBUILD_ENABLE),y)
151ifneq ($(CONFIG_SCANBUILD_REPORT_LOCATION),)
152CONFIG_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_SCANBUILD_REPORT_LOCATION)
153endif
Patrick Georgi71b84802011-02-22 14:35:05 +0000154real-all:
Patrick Georgi020f51f2010-03-14 21:25:03 +0000155 echo '#!/bin/sh' > .ccwrap
156 echo 'CC="$(CC)"' >> .ccwrap
157 echo 'if [ "$$1" = "--hostcc" ]; then shift; CC="$(HOSTCC)"; fi' >> .ccwrap
158 echo 'if [ "$$1" = "--hostcxx" ]; then shift; CC="$(HOSTCXX)"; fi' >> .ccwrap
159 echo 'eval $$CC $$*' >> .ccwrap
160 chmod +x .ccwrap
161 scan-build $(CONFIG_SCANBUILD_REPORT_LOCATION) -analyze-headers --use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y
162else
Patrick Georgi71b84802011-02-22 14:35:05 +0000163real-all: real-target
Patrick Georgi020f51f2010-03-14 21:25:03 +0000164endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000165
Patrick Georgi51e142f2010-03-27 17:18:39 +0000166# must come rather early
167.SECONDEXPANSION:
168
Stefan Reinauer1425add2010-03-21 22:35:58 +0000169$(obj)/config.h:
170 $(MAKE) oldconfig
Patrick Georgi0588d192009-08-12 15:00:51 +0000171
Patrick Georgi58262652011-02-17 20:47:49 +0000172# Add a new class of source/object files to the build system
173add-class= \
174 $(eval $(1)-srcs:=) \
175 $(eval $(1)-objs:=) \
176 $(eval classes+=$(1))
Patrick Georgi8463dd92010-09-30 16:55:02 +0000177
Patrick Georgi58262652011-02-17 20:47:49 +0000178# Special classes are managed types with special behaviour
179# On parse time, for each entry in variable $(1)-y
180# a handler $(1)-handler is executed with the arguments:
181# * $(1): directory the parser is in
182# * $(2): current entry
183add-special-class= \
184 $(eval $(1):=) \
185 $(eval special-classes+=$(1))
186
Patrick Georgi47d68d82010-03-06 21:18:43 +0000187# Clean -y variables, include Makefile.inc
Patrick Georgi8463dd92010-09-30 16:55:02 +0000188# Add paths to files in X-y to X-srcs
Patrick Georgi47d68d82010-03-06 21:18:43 +0000189# Add subdirs-y to subdirs
190includemakefiles= \
Patrick Georgi58262652011-02-17 20:47:49 +0000191 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
Patrick Georgi47d68d82010-03-06 21:18:43 +0000192 $(eval -include $(1)) \
Patrick Georgi58262652011-02-17 20:47:49 +0000193 $(foreach class,$(classes-y), $(call add-class,$(class))) \
194 $(foreach class,$(classes), \
195 $(eval $(class)-srcs+= \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000196 $$(subst $(top)/,, \
Patrick Georgi29ddbb82011-05-20 23:31:41 +0000197 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y))))))) \
Patrick Georgi58262652011-02-17 20:47:49 +0000198 $(foreach special,$(special-classes), \
199 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
Jonathan Kollasch7ff5b442010-09-28 21:11:48 +0000200 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
Patrick Georgi47d68d82010-03-06 21:18:43 +0000201
Patrick Georgi8463dd92010-09-30 16:55:02 +0000202# For each path in $(subdirs) call includemakefiles
Patrick Georgi47d68d82010-03-06 21:18:43 +0000203# Repeat until subdirs is empty
204evaluate_subdirs= \
205 $(eval cursubdirs:=$(subdirs)) \
206 $(eval subdirs:=) \
207 $(foreach dir,$(cursubdirs), \
Patrick Georgi58262652011-02-17 20:47:49 +0000208 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000209 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000210
211# collect all object files eligible for building
Patrick Georgie38d0a62011-03-01 08:09:22 +0000212subdirs:=$(TOPLEVEL)
Patrick Georgi51e142f2010-03-27 17:18:39 +0000213$(eval $(call evaluate_subdirs))
Patrick Georgi70c85ea2013-02-16 01:06:57 +0100214ifeq ($(FAILBUILD),1)
215$(error cannot continue build)
216endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000217
Patrick Georgi94a45862011-10-25 14:32:21 -0700218# Eliminate duplicate mentions of source files in a class
219$(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
220
Patrick Georgi8463dd92010-09-30 16:55:02 +0000221src-to-obj=$(addsuffix .$(1).o, $(basename $(patsubst src/%, $(obj)/%, $($(1)-srcs))))
Patrick Georgi58262652011-02-17 20:47:49 +0000222$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class))))
Patrick Georgid3428b02010-02-24 13:18:01 +0000223
Nico Huber963bed52013-05-15 11:47:51 +0200224# Save all objs before processing them (for dependency inclusion)
225originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
226
Patrick Georgi79f90102012-11-25 14:31:08 +0100227# Call post-processors if they're defined
228$(foreach class,$(classes),\
229 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
230
Patrick Georgi58262652011-02-17 20:47:49 +0000231allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
232allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000233alldirs:=$(sort $(abspath $(dir $(allobjs))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000234
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000235# macro to define template macros that are used by use_template macro
236define create_cc_template
Patrick Georgi71b84802011-02-22 14:35:05 +0000237# $1 obj class
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000238# $2 source suffix (c, S)
Patrick Georgi8463dd92010-09-30 16:55:02 +0000239# $3 additional compiler flags
Patrick Georgi57205c72011-03-08 20:49:18 +0000240# $4 additional dependencies
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000241ifn$(EMPTY)def $(1)-objs_$(2)_template
Patrick Georgi8463dd92010-09-30 16:55:02 +0000242de$(EMPTY)fine $(1)-objs_$(2)_template
Patrick Georgi57205c72011-03-08 20:49:18 +0000243$(obj)/$$(1).$(1).o: src/$$(1).$(2) $(obj)/config.h $(4)
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000244 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700245 $(CC_$(1)) $(3) -MMD $$$$(CFLAGS_$(1)) -c -o $$$$@ $$$$<
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000246en$(EMPTY)def
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000247end$(EMPTY)if
Patrick Georgi0588d192009-08-12 15:00:51 +0000248endef
249
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000250filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
251$(foreach class,$(classes), \
252 $(foreach type,$(call filetypes-of-class,$(class)), \
Patrick Georgi57205c72011-03-08 20:49:18 +0000253 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps)))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000254
Patrick Georgi8463dd92010-09-30 16:55:02 +0000255foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(subst src/,,$(basename $(file))))))
Patrick Georgi58262652011-02-17 20:47:49 +0000256$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000257
Nico Huber963bed52013-05-15 11:47:51 +0200258DEPENDENCIES = $(originalobjs:.o=.d)
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000259-include $(DEPENDENCIES)
260
Patrick Georgi0588d192009-08-12 15:00:51 +0000261printall:
Patrick Georgi71b84802011-02-22 14:35:05 +0000262 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
Patrick Georgi0588d192009-08-12 15:00:51 +0000263 @echo alldirs:=$(alldirs)
Patrick Georgi8463dd92010-09-30 16:55:02 +0000264 @echo allsrcs=$(allsrcs)
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000265 @echo DEPENDENCIES=$(DEPENDENCIES)
Furquan Shaikh99ac98f2014-04-23 10:18:48 -0700266 @echo LIBGCC_FILE_NAME=$(LIBGCC_FILE_NAME_$(class))
Patrick Georgi71b84802011-02-22 14:35:05 +0000267 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
Patrick Georgi0588d192009-08-12 15:00:51 +0000268
269endif
270
Patrick Georgi40ad8422011-05-21 22:18:59 +0000271ifndef NOMKDIR
Patrick Georgid5208402014-04-11 20:24:06 +0200272$(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objutil)/kconfig/lxdialog $(additional-dirs) $(alldirs))
Patrick Georgi40ad8422011-05-21 22:18:59 +0000273endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000274
Warren Turkala9fc3302010-09-03 08:57:32 +0000275cscope:
276 cscope -bR
277
Patrick Georgi0588d192009-08-12 15:00:51 +0000278doxy: doxygen
279doxygen:
Stefan Reinauer1bbad5c2010-02-10 15:36:53 +0000280 $(DOXYGEN) documentation/Doxyfile.coreboot
Patrick Georgi0588d192009-08-12 15:00:51 +0000281
282doxyclean: doxygen-clean
283doxygen-clean:
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000284 rm -rf $(DOXYGEN_OUTPUT_DIR)
Patrick Georgi0588d192009-08-12 15:00:51 +0000285
Patrick Georgi71b84802011-02-22 14:35:05 +0000286clean-for-update: doxygen-clean clean-for-update-target
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100287 rm -rf $(obj) .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000288
Patrick Georgi71b84802011-02-22 14:35:05 +0000289clean: clean-for-update clean-target
290 rm -f .ccwrap
Warren Turkal0e8f2042010-09-27 21:14:19 +0000291
Warren Turkala9fc3302010-09-03 08:57:32 +0000292clean-cscope:
293 rm -f cscope.out
294
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100295distclean: clean
Patrick Georgicf036d12010-04-21 06:36:20 +0000296 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000297
Patrick Georgi48159132013-02-11 20:56:46 +0100298.PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy .xcompile