blob: 05b54e298e67d4edca5f7f7b4ee0131b1cebcd76 [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
47CONFIG_SHELL := sh
48KBUILD_DEFCONFIG := configs/defconfig
49UNAME_RELEASE := $(shell uname -r)
Patrick Georgi89ec3762010-12-08 19:58:30 +000050DOTCONFIG ?= .config
51KCONFIG_CONFIG = $(DOTCONFIG)
52export KCONFIG_CONFIG
53HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
Patrick Georgi0588d192009-08-12 15:00:51 +000054MAKEFLAGS += -rR --no-print-directory
55
56# Make is silent per default, but 'make V=1' will show all compiler calls.
Patrick Georgi2b7418e2009-08-25 19:38:46 +000057Q:=@
Patrick Georgi0588d192009-08-12 15:00:51 +000058ifneq ($(V),1)
Patrick Georgi2b7418e2009-08-25 19:38:46 +000059ifneq ($(Q),)
60.SILENT:
61endif
Patrick Georgi0588d192009-08-12 15:00:51 +000062endif
63
64CPP:= $(CC) -x assembler-with-cpp -DASSEMBLY -E
65HOSTCC = gcc
66HOSTCXX = g++
67HOSTCFLAGS := -I$(srck) -I$(objk) -g
68HOSTCXXFLAGS := -I$(srck) -I$(objk)
Stefan Reinauer68a564f2010-03-16 01:02:18 +000069LIBGCC_FILE_NAME := $(shell test -r `$(CC) -print-libgcc-file-name` && $(CC) -print-libgcc-file-name)
Patrick Georgi0588d192009-08-12 15:00:51 +000070
71DOXYGEN := doxygen
72DOXYGEN_OUTPUT_DIR := doxygen
73
Patrick Georgi71b84802011-02-22 14:35:05 +000074all: real-all
75
76# This include must come _before_ he pattern rules below!
77# Order _does_ matter for pattern rules.
78include Makefile.inc
79include util/kconfig/Makefile
80
Patrick Georgicf036d12010-04-21 06:36:20 +000081# Three cases where we don't need fully populated $(obj) lists:
82# 1. when no .config exists
83# 2. when make config (in any flavour) is run
84# 3. when make distclean is run
85# Don't waste time on reading all Makefile.incs in these cases
Patrick Georgi0588d192009-08-12 15:00:51 +000086ifeq ($(strip $(HAVE_DOTCONFIG)),)
Patrick Georgicf036d12010-04-21 06:36:20 +000087NOCOMPILE:=1
88endif
89ifneq ($(MAKECMDGOALS),)
90ifneq ($(filter %config distclean,$(MAKECMDGOALS)),)
91NOCOMPILE:=1
92endif
93endif
Patrick Georgi0588d192009-08-12 15:00:51 +000094
Patrick Georgicf036d12010-04-21 06:36:20 +000095ifeq ($(NOCOMPILE),1)
Patrick Georgi71b84802011-02-22 14:35:05 +000096real-all: config
Patrick Georgi0588d192009-08-12 15:00:51 +000097
98else
99
Patrick Georgi977b9852010-09-24 22:15:54 +0000100include $(HAVE_DOTCONFIG)
Patrick Georgi0588d192009-08-12 15:00:51 +0000101
Patrick Georgi23d89cc2010-03-16 01:17:19 +0000102ifneq ($(INNER_SCANBUILD),y)
103ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
104CC:=clang -m32
105HOSTCC:=clang
106endif
107endif
108
Patrick Georgi516a2a72010-03-25 21:45:25 +0000109ifeq ($(CONFIG_CCACHE),y)
Patrick Georgi977b9852010-09-24 22:15:54 +0000110CCACHE:=$(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH))))
Patrick Georgi516a2a72010-03-25 21:45:25 +0000111ifeq ($(CCACHE),)
112$(error ccache selected, but not found in PATH)
113endif
Patrick Georgi977b9852010-09-24 22:15:54 +0000114CCACHE:=CCACHE_COMPILERCHECK=content CCACHE_BASEDIR=$(top) $(CCACHE)
Patrick Georgi516a2a72010-03-25 21:45:25 +0000115CC := $(CCACHE) $(CC)
116HOSTCC := $(CCACHE) $(HOSTCC)
117HOSTCXX := $(CCACHE) $(HOSTCXX)
118ROMCC := $(CCACHE) $(ROMCC)
119endif
120
Patrick Georgia84e98b2010-03-16 19:01:32 +0000121strip_quotes = $(subst ",,$(subst \",,$(1)))
122
Patrick Georgi0588d192009-08-12 15:00:51 +0000123# The primary target needs to be here before we include the
124# other files
125
Patrick Georgi020f51f2010-03-14 21:25:03 +0000126ifeq ($(INNER_SCANBUILD),y)
127CONFIG_SCANBUILD_ENABLE:=
128endif
129
130ifeq ($(CONFIG_SCANBUILD_ENABLE),y)
131ifneq ($(CONFIG_SCANBUILD_REPORT_LOCATION),)
132CONFIG_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_SCANBUILD_REPORT_LOCATION)
133endif
Patrick Georgi71b84802011-02-22 14:35:05 +0000134real-all:
Patrick Georgi020f51f2010-03-14 21:25:03 +0000135 echo '#!/bin/sh' > .ccwrap
136 echo 'CC="$(CC)"' >> .ccwrap
137 echo 'if [ "$$1" = "--hostcc" ]; then shift; CC="$(HOSTCC)"; fi' >> .ccwrap
138 echo 'if [ "$$1" = "--hostcxx" ]; then shift; CC="$(HOSTCXX)"; fi' >> .ccwrap
139 echo 'eval $$CC $$*' >> .ccwrap
140 chmod +x .ccwrap
141 scan-build $(CONFIG_SCANBUILD_REPORT_LOCATION) -analyze-headers --use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y
142else
Patrick Georgi71b84802011-02-22 14:35:05 +0000143real-all: real-target
Patrick Georgi020f51f2010-03-14 21:25:03 +0000144endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000145
Patrick Georgi51e142f2010-03-27 17:18:39 +0000146# must come rather early
147.SECONDEXPANSION:
148
Stefan Reinauer1425add2010-03-21 22:35:58 +0000149$(obj)/config.h:
150 $(MAKE) oldconfig
Patrick Georgi0588d192009-08-12 15:00:51 +0000151
Patrick Georgi58262652011-02-17 20:47:49 +0000152# Add a new class of source/object files to the build system
153add-class= \
154 $(eval $(1)-srcs:=) \
155 $(eval $(1)-objs:=) \
156 $(eval classes+=$(1))
Patrick Georgi8463dd92010-09-30 16:55:02 +0000157
Patrick Georgi58262652011-02-17 20:47:49 +0000158# Special classes are managed types with special behaviour
159# On parse time, for each entry in variable $(1)-y
160# a handler $(1)-handler is executed with the arguments:
161# * $(1): directory the parser is in
162# * $(2): current entry
163add-special-class= \
164 $(eval $(1):=) \
165 $(eval special-classes+=$(1))
166
Patrick Georgi47d68d82010-03-06 21:18:43 +0000167# Clean -y variables, include Makefile.inc
Patrick Georgi8463dd92010-09-30 16:55:02 +0000168# Add paths to files in X-y to X-srcs
Patrick Georgi47d68d82010-03-06 21:18:43 +0000169# Add subdirs-y to subdirs
170includemakefiles= \
Patrick Georgi58262652011-02-17 20:47:49 +0000171 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
Patrick Georgi47d68d82010-03-06 21:18:43 +0000172 $(eval -include $(1)) \
Patrick Georgi58262652011-02-17 20:47:49 +0000173 $(foreach class,$(classes-y), $(call add-class,$(class))) \
174 $(foreach class,$(classes), \
175 $(eval $(class)-srcs+= \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000176 $$(subst $(top)/,, \
Patrick Georgi58262652011-02-17 20:47:49 +0000177 $$(abspath $$(addprefix $(dir $(1)),$$($(class)-y)))))) \
178 $(foreach special,$(special-classes), \
179 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
Jonathan Kollasch7ff5b442010-09-28 21:11:48 +0000180 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
Patrick Georgi47d68d82010-03-06 21:18:43 +0000181
Patrick Georgi8463dd92010-09-30 16:55:02 +0000182# For each path in $(subdirs) call includemakefiles
Patrick Georgi47d68d82010-03-06 21:18:43 +0000183# Repeat until subdirs is empty
184evaluate_subdirs= \
185 $(eval cursubdirs:=$(subdirs)) \
186 $(eval subdirs:=) \
187 $(foreach dir,$(cursubdirs), \
Patrick Georgi58262652011-02-17 20:47:49 +0000188 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000189 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000190
191# collect all object files eligible for building
Patrick Georgi71b84802011-02-22 14:35:05 +0000192subdirs:=.
Patrick Georgi51e142f2010-03-27 17:18:39 +0000193$(eval $(call evaluate_subdirs))
Patrick Georgi0588d192009-08-12 15:00:51 +0000194
Patrick Georgi8463dd92010-09-30 16:55:02 +0000195src-to-obj=$(addsuffix .$(1).o, $(basename $(patsubst src/%, $(obj)/%, $($(1)-srcs))))
Patrick Georgi58262652011-02-17 20:47:49 +0000196$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class))))
Patrick Georgid3428b02010-02-24 13:18:01 +0000197
Patrick Georgi58262652011-02-17 20:47:49 +0000198allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
199allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000200alldirs:=$(sort $(abspath $(dir $(allobjs))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000201
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000202# macro to define template macros that are used by use_template macro
203define create_cc_template
Patrick Georgi71b84802011-02-22 14:35:05 +0000204# $1 obj class
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000205# $2 source suffix (c, S)
Patrick Georgi8463dd92010-09-30 16:55:02 +0000206# $3 additional compiler flags
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000207ifn$(EMPTY)def $(1)-objs_$(2)_template
Patrick Georgi8463dd92010-09-30 16:55:02 +0000208de$(EMPTY)fine $(1)-objs_$(2)_template
209$(obj)/$$(1).$(1).o: src/$$(1).$(2) $(obj)/config.h
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000210 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
Patrick Georgi8463dd92010-09-30 16:55:02 +0000211 $(CC) $(3) -MMD $$$$(CFLAGS) -c -o $$$$@ $$$$<
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000212en$(EMPTY)def
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000213end$(EMPTY)if
Patrick Georgi0588d192009-08-12 15:00:51 +0000214endef
215
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000216filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
217$(foreach class,$(classes), \
218 $(foreach type,$(call filetypes-of-class,$(class)), \
219 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts)))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000220
Patrick Georgi8463dd92010-09-30 16:55:02 +0000221foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(subst src/,,$(basename $(file))))))
Patrick Georgi58262652011-02-17 20:47:49 +0000222$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000223
Patrick Georgi71b84802011-02-22 14:35:05 +0000224DEPENDENCIES = $(allobjs:.o=.d)
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000225-include $(DEPENDENCIES)
226
Patrick Georgi0588d192009-08-12 15:00:51 +0000227printall:
Patrick Georgi71b84802011-02-22 14:35:05 +0000228 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
Patrick Georgi0588d192009-08-12 15:00:51 +0000229 @echo alldirs:=$(alldirs)
Patrick Georgi8463dd92010-09-30 16:55:02 +0000230 @echo allsrcs=$(allsrcs)
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000231 @echo DEPENDENCIES=$(DEPENDENCIES)
Stefan Reinauer68a564f2010-03-16 01:02:18 +0000232 @echo LIBGCC_FILE_NAME=$(LIBGCC_FILE_NAME)
Patrick Georgi71b84802011-02-22 14:35:05 +0000233 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
Patrick Georgi0588d192009-08-12 15:00:51 +0000234
235endif
236
Patrick Georgi71b84802011-02-22 14:35:05 +0000237$(shell mkdir -p $(obj) $(objutil)/kconfig/lxdialog $(additional-dirs) $(alldirs))
Patrick Georgi0588d192009-08-12 15:00:51 +0000238
Warren Turkala9fc3302010-09-03 08:57:32 +0000239cscope:
240 cscope -bR
241
Patrick Georgi0588d192009-08-12 15:00:51 +0000242doxy: doxygen
243doxygen:
Stefan Reinauer1bbad5c2010-02-10 15:36:53 +0000244 $(DOXYGEN) documentation/Doxyfile.coreboot
Patrick Georgi0588d192009-08-12 15:00:51 +0000245
246doxyclean: doxygen-clean
247doxygen-clean:
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000248 rm -rf $(DOXYGEN_OUTPUT_DIR)
Patrick Georgi0588d192009-08-12 15:00:51 +0000249
Patrick Georgi71b84802011-02-22 14:35:05 +0000250clean-for-update: doxygen-clean clean-for-update-target
251 rm -f $(allobjs) .xcompile
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000252 rm -f $(DEPENDENCIES)
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000253 rmdir -p $(alldirs) 2>/dev/null >/dev/null || true
Patrick Georgi0588d192009-08-12 15:00:51 +0000254
Patrick Georgi71b84802011-02-22 14:35:05 +0000255clean: clean-for-update clean-target
256 rm -f .ccwrap
Warren Turkal0e8f2042010-09-27 21:14:19 +0000257
Warren Turkala9fc3302010-09-03 08:57:32 +0000258clean-cscope:
259 rm -f cscope.out
260
Patrick Georgiafbf0722010-09-29 20:28:59 +0000261distclean: clean-cscope
Myles Watson1af297c2010-01-06 16:59:18 +0000262 rm -rf $(obj)
Patrick Georgicf036d12010-04-21 06:36:20 +0000263 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000264
Patrick Georgi71b84802011-02-22 14:35:05 +0000265.PHONY: $(PHONY) clean clean-cscope cscope distclean doxygen doxy .xcompile