blob: 04fbb026128333350c8343e76b76560f8f3a2c2d [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##
Stefan Reinauer16f515a2010-01-20 18:44:30 +00009## This program is free software; you can redistribute it and/or modify
10## it under the terms of the GNU General Public License as published by
11## the Free Software Foundation; version 2 of the License.
Patrick Georgi0588d192009-08-12 15:00:51 +000012##
Stefan Reinauer16f515a2010-01-20 18:44:30 +000013## This program is distributed in the hope that it will be useful,
14## but WITHOUT ANY WARRANTY; without even the implied warranty of
15## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16## GNU General Public License for more details.
17##
18## You should have received a copy of the GNU General Public License
19## along with this program; if not, write to the Free Software
20## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Patrick Georgi0588d192009-08-12 15:00:51 +000021##
22
Patrick Georgi020f51f2010-03-14 21:25:03 +000023ifeq ($(INNER_SCANBUILD),y)
24CC_real:=$(CC)
25endif
Patrick Georgi23d89cc2010-03-16 01:17:19 +000026
Patrick Georgi0588d192009-08-12 15:00:51 +000027$(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile > .xcompile)))
28include .xcompile
Patrick Georgi23d89cc2010-03-16 01:17:19 +000029
Patrick Georgi020f51f2010-03-14 21:25:03 +000030ifeq ($(INNER_SCANBUILD),y)
31CC:=$(CC_real)
32HOSTCC:=$(CC_real) --hostcc
33HOSTCXX:=$(CC_real) --hostcxx
34endif
Patrick Georgi0588d192009-08-12 15:00:51 +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 Georgi0588d192009-08-12 15:00:51 +000046
Patrick Georgie38d0a62011-03-01 08:09:22 +000047# directory containing the toplevel Makefile.inc
48TOPLEVEL := .
49
Patrick Georgi0588d192009-08-12 15:00:51 +000050CONFIG_SHELL := sh
51KBUILD_DEFCONFIG := configs/defconfig
52UNAME_RELEASE := $(shell uname -r)
Patrick Georgi89ec3762010-12-08 19:58:30 +000053DOTCONFIG ?= .config
54KCONFIG_CONFIG = $(DOTCONFIG)
55export KCONFIG_CONFIG
56HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
Patrick Georgi0588d192009-08-12 15:00:51 +000057MAKEFLAGS += -rR --no-print-directory
58
59# Make is silent per default, but 'make V=1' will show all compiler calls.
Patrick Georgi2b7418e2009-08-25 19:38:46 +000060Q:=@
Patrick Georgi0588d192009-08-12 15:00:51 +000061ifneq ($(V),1)
Patrick Georgi2b7418e2009-08-25 19:38:46 +000062ifneq ($(Q),)
63.SILENT:
64endif
Patrick Georgi0588d192009-08-12 15:00:51 +000065endif
66
Patrick Georgi0588d192009-08-12 15:00:51 +000067HOSTCC = gcc
68HOSTCXX = g++
69HOSTCFLAGS := -I$(srck) -I$(objk) -g
70HOSTCXXFLAGS := -I$(srck) -I$(objk)
Stefan Reinauer68a564f2010-03-16 01:02:18 +000071LIBGCC_FILE_NAME := $(shell test -r `$(CC) -print-libgcc-file-name` && $(CC) -print-libgcc-file-name)
Patrick Georgi0588d192009-08-12 15:00:51 +000072
73DOXYGEN := doxygen
74DOXYGEN_OUTPUT_DIR := doxygen
75
Patrick Georgi71b84802011-02-22 14:35:05 +000076all: real-all
77
Patrick Georgie38d0a62011-03-01 08:09:22 +000078# This include must come _before_ the pattern rules below!
Patrick Georgi71b84802011-02-22 14:35:05 +000079# Order _does_ matter for pattern rules.
Patrick Georgi71b84802011-02-22 14:35:05 +000080include util/kconfig/Makefile
81
Patrick Georgicf036d12010-04-21 06:36:20 +000082# Three cases where we don't need fully populated $(obj) lists:
83# 1. when no .config exists
84# 2. when make config (in any flavour) is run
85# 3. when make distclean is run
86# Don't waste time on reading all Makefile.incs in these cases
Patrick Georgi0588d192009-08-12 15:00:51 +000087ifeq ($(strip $(HAVE_DOTCONFIG)),)
Patrick Georgicf036d12010-04-21 06:36:20 +000088NOCOMPILE:=1
89endif
90ifneq ($(MAKECMDGOALS),)
91ifneq ($(filter %config distclean,$(MAKECMDGOALS)),)
92NOCOMPILE:=1
93endif
94endif
Patrick Georgi0588d192009-08-12 15:00:51 +000095
Patrick Georgicf036d12010-04-21 06:36:20 +000096ifeq ($(NOCOMPILE),1)
Patrick Georgie38d0a62011-03-01 08:09:22 +000097include $(TOPLEVEL)/Makefile.inc
Patrick Georgi71b84802011-02-22 14:35:05 +000098real-all: config
Patrick Georgi0588d192009-08-12 15:00:51 +000099
100else
101
Patrick Georgi977b9852010-09-24 22:15:54 +0000102include $(HAVE_DOTCONFIG)
Patrick Georgi0588d192009-08-12 15:00:51 +0000103
Patrick Georgi23d89cc2010-03-16 01:17:19 +0000104ifneq ($(INNER_SCANBUILD),y)
105ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
106CC:=clang -m32
107HOSTCC:=clang
108endif
109endif
110
Patrick Georgi516a2a72010-03-25 21:45:25 +0000111ifeq ($(CONFIG_CCACHE),y)
Patrick Georgi96dafaf2011-05-20 22:14:07 +0000112CCACHE:=$(word 1,$(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH)))))
Patrick Georgi516a2a72010-03-25 21:45:25 +0000113ifeq ($(CCACHE),)
114$(error ccache selected, but not found in PATH)
115endif
Patrick Georgi977b9852010-09-24 22:15:54 +0000116CCACHE:=CCACHE_COMPILERCHECK=content CCACHE_BASEDIR=$(top) $(CCACHE)
Patrick Georgi516a2a72010-03-25 21:45:25 +0000117CC := $(CCACHE) $(CC)
118HOSTCC := $(CCACHE) $(HOSTCC)
119HOSTCXX := $(CCACHE) $(HOSTCXX)
120ROMCC := $(CCACHE) $(ROMCC)
121endif
122
Patrick Georgia84e98b2010-03-16 19:01:32 +0000123strip_quotes = $(subst ",,$(subst \",,$(1)))
124
Patrick Georgi0588d192009-08-12 15:00:51 +0000125# The primary target needs to be here before we include the
126# other files
127
Patrick Georgi020f51f2010-03-14 21:25:03 +0000128ifeq ($(INNER_SCANBUILD),y)
129CONFIG_SCANBUILD_ENABLE:=
130endif
131
132ifeq ($(CONFIG_SCANBUILD_ENABLE),y)
133ifneq ($(CONFIG_SCANBUILD_REPORT_LOCATION),)
134CONFIG_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_SCANBUILD_REPORT_LOCATION)
135endif
Patrick Georgi71b84802011-02-22 14:35:05 +0000136real-all:
Patrick Georgi020f51f2010-03-14 21:25:03 +0000137 echo '#!/bin/sh' > .ccwrap
138 echo 'CC="$(CC)"' >> .ccwrap
139 echo 'if [ "$$1" = "--hostcc" ]; then shift; CC="$(HOSTCC)"; fi' >> .ccwrap
140 echo 'if [ "$$1" = "--hostcxx" ]; then shift; CC="$(HOSTCXX)"; fi' >> .ccwrap
141 echo 'eval $$CC $$*' >> .ccwrap
142 chmod +x .ccwrap
143 scan-build $(CONFIG_SCANBUILD_REPORT_LOCATION) -analyze-headers --use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y
144else
Patrick Georgi71b84802011-02-22 14:35:05 +0000145real-all: real-target
Patrick Georgi020f51f2010-03-14 21:25:03 +0000146endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000147
Patrick Georgi51e142f2010-03-27 17:18:39 +0000148# must come rather early
149.SECONDEXPANSION:
150
Stefan Reinauer1425add2010-03-21 22:35:58 +0000151$(obj)/config.h:
152 $(MAKE) oldconfig
Patrick Georgi0588d192009-08-12 15:00:51 +0000153
Patrick Georgi58262652011-02-17 20:47:49 +0000154# Add a new class of source/object files to the build system
155add-class= \
156 $(eval $(1)-srcs:=) \
157 $(eval $(1)-objs:=) \
158 $(eval classes+=$(1))
Patrick Georgi8463dd92010-09-30 16:55:02 +0000159
Patrick Georgi58262652011-02-17 20:47:49 +0000160# Special classes are managed types with special behaviour
161# On parse time, for each entry in variable $(1)-y
162# a handler $(1)-handler is executed with the arguments:
163# * $(1): directory the parser is in
164# * $(2): current entry
165add-special-class= \
166 $(eval $(1):=) \
167 $(eval special-classes+=$(1))
168
Patrick Georgi47d68d82010-03-06 21:18:43 +0000169# Clean -y variables, include Makefile.inc
Patrick Georgi8463dd92010-09-30 16:55:02 +0000170# Add paths to files in X-y to X-srcs
Patrick Georgi47d68d82010-03-06 21:18:43 +0000171# Add subdirs-y to subdirs
172includemakefiles= \
Patrick Georgi58262652011-02-17 20:47:49 +0000173 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
Patrick Georgi47d68d82010-03-06 21:18:43 +0000174 $(eval -include $(1)) \
Patrick Georgi58262652011-02-17 20:47:49 +0000175 $(foreach class,$(classes-y), $(call add-class,$(class))) \
176 $(foreach class,$(classes), \
177 $(eval $(class)-srcs+= \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000178 $$(subst $(top)/,, \
Patrick Georgi29ddbb82011-05-20 23:31:41 +0000179 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y))))))) \
Patrick Georgi58262652011-02-17 20:47:49 +0000180 $(foreach special,$(special-classes), \
181 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
Jonathan Kollasch7ff5b442010-09-28 21:11:48 +0000182 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
Patrick Georgi47d68d82010-03-06 21:18:43 +0000183
Patrick Georgi8463dd92010-09-30 16:55:02 +0000184# For each path in $(subdirs) call includemakefiles
Patrick Georgi47d68d82010-03-06 21:18:43 +0000185# Repeat until subdirs is empty
186evaluate_subdirs= \
187 $(eval cursubdirs:=$(subdirs)) \
188 $(eval subdirs:=) \
189 $(foreach dir,$(cursubdirs), \
Patrick Georgi58262652011-02-17 20:47:49 +0000190 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000191 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000192
193# collect all object files eligible for building
Patrick Georgie38d0a62011-03-01 08:09:22 +0000194subdirs:=$(TOPLEVEL)
Patrick Georgi51e142f2010-03-27 17:18:39 +0000195$(eval $(call evaluate_subdirs))
Patrick Georgi0588d192009-08-12 15:00:51 +0000196
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
Patrick Georgi58262652011-02-17 20:47:49 +0000200allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
201allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000202alldirs:=$(sort $(abspath $(dir $(allobjs))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000203
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000204# macro to define template macros that are used by use_template macro
205define create_cc_template
Patrick Georgi71b84802011-02-22 14:35:05 +0000206# $1 obj class
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000207# $2 source suffix (c, S)
Patrick Georgi8463dd92010-09-30 16:55:02 +0000208# $3 additional compiler flags
Patrick Georgi57205c72011-03-08 20:49:18 +0000209# $4 additional dependencies
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000210ifn$(EMPTY)def $(1)-objs_$(2)_template
Patrick Georgi8463dd92010-09-30 16:55:02 +0000211de$(EMPTY)fine $(1)-objs_$(2)_template
Patrick Georgi57205c72011-03-08 20:49:18 +0000212$(obj)/$$(1).$(1).o: src/$$(1).$(2) $(obj)/config.h $(4)
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000213 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
Patrick Georgi8463dd92010-09-30 16:55:02 +0000214 $(CC) $(3) -MMD $$$$(CFLAGS) -c -o $$$$@ $$$$<
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000215en$(EMPTY)def
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000216end$(EMPTY)if
Patrick Georgi0588d192009-08-12 15:00:51 +0000217endef
218
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000219filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
220$(foreach class,$(classes), \
221 $(foreach type,$(call filetypes-of-class,$(class)), \
Patrick Georgi57205c72011-03-08 20:49:18 +0000222 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps)))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000223
Patrick Georgi8463dd92010-09-30 16:55:02 +0000224foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(subst src/,,$(basename $(file))))))
Patrick Georgi58262652011-02-17 20:47:49 +0000225$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000226
Patrick Georgi71b84802011-02-22 14:35:05 +0000227DEPENDENCIES = $(allobjs:.o=.d)
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000228-include $(DEPENDENCIES)
229
Patrick Georgi0588d192009-08-12 15:00:51 +0000230printall:
Patrick Georgi71b84802011-02-22 14:35:05 +0000231 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
Patrick Georgi0588d192009-08-12 15:00:51 +0000232 @echo alldirs:=$(alldirs)
Patrick Georgi8463dd92010-09-30 16:55:02 +0000233 @echo allsrcs=$(allsrcs)
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000234 @echo DEPENDENCIES=$(DEPENDENCIES)
Stefan Reinauer68a564f2010-03-16 01:02:18 +0000235 @echo LIBGCC_FILE_NAME=$(LIBGCC_FILE_NAME)
Patrick Georgi71b84802011-02-22 14:35:05 +0000236 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
Patrick Georgi0588d192009-08-12 15:00:51 +0000237
238endif
239
Patrick Georgi71b84802011-02-22 14:35:05 +0000240$(shell mkdir -p $(obj) $(objutil)/kconfig/lxdialog $(additional-dirs) $(alldirs))
Patrick Georgi0588d192009-08-12 15:00:51 +0000241
Warren Turkala9fc3302010-09-03 08:57:32 +0000242cscope:
243 cscope -bR
244
Patrick Georgi0588d192009-08-12 15:00:51 +0000245doxy: doxygen
246doxygen:
Stefan Reinauer1bbad5c2010-02-10 15:36:53 +0000247 $(DOXYGEN) documentation/Doxyfile.coreboot
Patrick Georgi0588d192009-08-12 15:00:51 +0000248
249doxyclean: doxygen-clean
250doxygen-clean:
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000251 rm -rf $(DOXYGEN_OUTPUT_DIR)
Patrick Georgi0588d192009-08-12 15:00:51 +0000252
Patrick Georgi71b84802011-02-22 14:35:05 +0000253clean-for-update: doxygen-clean clean-for-update-target
254 rm -f $(allobjs) .xcompile
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000255 rm -f $(DEPENDENCIES)
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000256 rmdir -p $(alldirs) 2>/dev/null >/dev/null || true
Patrick Georgi0588d192009-08-12 15:00:51 +0000257
Patrick Georgi71b84802011-02-22 14:35:05 +0000258clean: clean-for-update clean-target
259 rm -f .ccwrap
Warren Turkal0e8f2042010-09-27 21:14:19 +0000260
Warren Turkala9fc3302010-09-03 08:57:32 +0000261clean-cscope:
262 rm -f cscope.out
263
Patrick Georgiafbf0722010-09-29 20:28:59 +0000264distclean: clean-cscope
Myles Watson1af297c2010-01-06 16:59:18 +0000265 rm -rf $(obj)
Patrick Georgicf036d12010-04-21 06:36:20 +0000266 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000267
Patrick Georgi71b84802011-02-22 14:35:05 +0000268.PHONY: $(PHONY) clean clean-cscope cscope distclean doxygen doxy .xcompile