blob: 4faf12baf90a5a393e3686f0f812bc8383ac2268 [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 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
78HOSTCXX = g++
Patrick Georgib3a18ac2012-09-13 22:13:33 +020079HOSTCFLAGS := -g
80HOSTCXXFLAGS := -g
Patrick Georgi0588d192009-08-12 15:00:51 +000081
82DOXYGEN := doxygen
83DOXYGEN_OUTPUT_DIR := doxygen
84
Patrick Georgi71b84802011-02-22 14:35:05 +000085all: real-all
86
Patrick Georgie38d0a62011-03-01 08:09:22 +000087# This include must come _before_ the pattern rules below!
Patrick Georgi71b84802011-02-22 14:35:05 +000088# Order _does_ matter for pattern rules.
Patrick Georgi71b84802011-02-22 14:35:05 +000089include util/kconfig/Makefile
90
Patrick Georgicf036d12010-04-21 06:36:20 +000091# Three cases where we don't need fully populated $(obj) lists:
92# 1. when no .config exists
93# 2. when make config (in any flavour) is run
94# 3. when make distclean is run
95# Don't waste time on reading all Makefile.incs in these cases
Patrick Georgi0588d192009-08-12 15:00:51 +000096ifeq ($(strip $(HAVE_DOTCONFIG)),)
Patrick Georgicf036d12010-04-21 06:36:20 +000097NOCOMPILE:=1
98endif
99ifneq ($(MAKECMDGOALS),)
100ifneq ($(filter %config distclean,$(MAKECMDGOALS)),)
101NOCOMPILE:=1
102endif
Zheng Bao0fd93d62012-10-22 16:36:03 +0800103ifeq ($(MAKECMDGOALS), distclean)
104NOMKDIR:=1
105endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000106endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000107
Patrick Georgicf036d12010-04-21 06:36:20 +0000108ifeq ($(NOCOMPILE),1)
Patrick Georgie38d0a62011-03-01 08:09:22 +0000109include $(TOPLEVEL)/Makefile.inc
Patrick Georgi71b84802011-02-22 14:35:05 +0000110real-all: config
Patrick Georgi0588d192009-08-12 15:00:51 +0000111
112else
113
Patrick Georgi977b9852010-09-24 22:15:54 +0000114include $(HAVE_DOTCONFIG)
Patrick Georgi0588d192009-08-12 15:00:51 +0000115
Ronald G. Minniche820e5c2012-11-26 14:33:09 -0800116ARCHDIR-$(CONFIG_ARCH_ARM) := armv7
117ARCHDIR-$(CONFIG_ARCH_X86) := x86
118
119ARCH-y := $(ARCHDIR-y)
120
121# If architecture folder name is different from GCC binutils architecture name,
122# override here.
123ARCH-$(CONFIG_ARCH_ARM) := littlearm
124ARCH-$(CONFIG_ARCH_X86) := i386
125
126CC := $(CC_$(ARCH-y))
127AS := $(AS_$(ARCH-y))
128LD := $(LD_$(ARCH-y))
129NM := $(NM_$(ARCH-y))
130OBJCOPY := $(OBJCOPY_$(ARCH-y))
131OBJDUMP := $(OBJDUMP_$(ARCH-y))
132READELF := $(READELF_$(ARCH-y))
133STRIP := $(STRIP_$(ARCH-y))
134AR := $(AR_$(ARCH-y))
135
136CFLAGS += $(CFLAGS_$(ARCH-y))
137
138LIBGCC_FILE_NAME := $(shell test -r `$(CC) -print-libgcc-file-name` && \
139 $(CC) -print-libgcc-file-name)
140
Patrick Georgi23d89cc2010-03-16 01:17:19 +0000141ifneq ($(INNER_SCANBUILD),y)
142ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
Patrick Georgife9210f2012-03-11 20:44:22 +0100143CC:=clang -m32 -mno-mmx -mno-sse
Patrick Georgi23d89cc2010-03-16 01:17:19 +0000144HOSTCC:=clang
145endif
146endif
147
Patrick Georgi516a2a72010-03-25 21:45:25 +0000148ifeq ($(CONFIG_CCACHE),y)
Patrick Georgi96dafaf2011-05-20 22:14:07 +0000149CCACHE:=$(word 1,$(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH)))))
Patrick Georgi516a2a72010-03-25 21:45:25 +0000150ifeq ($(CCACHE),)
151$(error ccache selected, but not found in PATH)
152endif
Patrick Georgi977b9852010-09-24 22:15:54 +0000153CCACHE:=CCACHE_COMPILERCHECK=content CCACHE_BASEDIR=$(top) $(CCACHE)
Patrick Georgi516a2a72010-03-25 21:45:25 +0000154CC := $(CCACHE) $(CC)
155HOSTCC := $(CCACHE) $(HOSTCC)
156HOSTCXX := $(CCACHE) $(HOSTCXX)
157ROMCC := $(CCACHE) $(ROMCC)
158endif
159
Patrick Georgia84e98b2010-03-16 19:01:32 +0000160strip_quotes = $(subst ",,$(subst \",,$(1)))
161
Patrick Georgi0588d192009-08-12 15:00:51 +0000162# The primary target needs to be here before we include the
163# other files
164
Patrick Georgi020f51f2010-03-14 21:25:03 +0000165ifeq ($(INNER_SCANBUILD),y)
166CONFIG_SCANBUILD_ENABLE:=
167endif
168
169ifeq ($(CONFIG_SCANBUILD_ENABLE),y)
170ifneq ($(CONFIG_SCANBUILD_REPORT_LOCATION),)
171CONFIG_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_SCANBUILD_REPORT_LOCATION)
172endif
Patrick Georgi71b84802011-02-22 14:35:05 +0000173real-all:
Patrick Georgi020f51f2010-03-14 21:25:03 +0000174 echo '#!/bin/sh' > .ccwrap
175 echo 'CC="$(CC)"' >> .ccwrap
176 echo 'if [ "$$1" = "--hostcc" ]; then shift; CC="$(HOSTCC)"; fi' >> .ccwrap
177 echo 'if [ "$$1" = "--hostcxx" ]; then shift; CC="$(HOSTCXX)"; fi' >> .ccwrap
178 echo 'eval $$CC $$*' >> .ccwrap
179 chmod +x .ccwrap
180 scan-build $(CONFIG_SCANBUILD_REPORT_LOCATION) -analyze-headers --use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y
181else
Patrick Georgi71b84802011-02-22 14:35:05 +0000182real-all: real-target
Patrick Georgi020f51f2010-03-14 21:25:03 +0000183endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000184
Patrick Georgi51e142f2010-03-27 17:18:39 +0000185# must come rather early
186.SECONDEXPANSION:
187
Stefan Reinauer1425add2010-03-21 22:35:58 +0000188$(obj)/config.h:
189 $(MAKE) oldconfig
Patrick Georgi0588d192009-08-12 15:00:51 +0000190
Patrick Georgi58262652011-02-17 20:47:49 +0000191# Add a new class of source/object files to the build system
192add-class= \
193 $(eval $(1)-srcs:=) \
194 $(eval $(1)-objs:=) \
195 $(eval classes+=$(1))
Patrick Georgi8463dd92010-09-30 16:55:02 +0000196
Patrick Georgi58262652011-02-17 20:47:49 +0000197# Special classes are managed types with special behaviour
198# On parse time, for each entry in variable $(1)-y
199# a handler $(1)-handler is executed with the arguments:
200# * $(1): directory the parser is in
201# * $(2): current entry
202add-special-class= \
203 $(eval $(1):=) \
204 $(eval special-classes+=$(1))
205
Patrick Georgi47d68d82010-03-06 21:18:43 +0000206# Clean -y variables, include Makefile.inc
Patrick Georgi8463dd92010-09-30 16:55:02 +0000207# Add paths to files in X-y to X-srcs
Patrick Georgi47d68d82010-03-06 21:18:43 +0000208# Add subdirs-y to subdirs
209includemakefiles= \
Patrick Georgi58262652011-02-17 20:47:49 +0000210 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
Patrick Georgi47d68d82010-03-06 21:18:43 +0000211 $(eval -include $(1)) \
Patrick Georgi58262652011-02-17 20:47:49 +0000212 $(foreach class,$(classes-y), $(call add-class,$(class))) \
213 $(foreach class,$(classes), \
214 $(eval $(class)-srcs+= \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000215 $$(subst $(top)/,, \
Patrick Georgi29ddbb82011-05-20 23:31:41 +0000216 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y))))))) \
Patrick Georgi58262652011-02-17 20:47:49 +0000217 $(foreach special,$(special-classes), \
218 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
Jonathan Kollasch7ff5b442010-09-28 21:11:48 +0000219 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
Patrick Georgi47d68d82010-03-06 21:18:43 +0000220
Patrick Georgi8463dd92010-09-30 16:55:02 +0000221# For each path in $(subdirs) call includemakefiles
Patrick Georgi47d68d82010-03-06 21:18:43 +0000222# Repeat until subdirs is empty
223evaluate_subdirs= \
224 $(eval cursubdirs:=$(subdirs)) \
225 $(eval subdirs:=) \
226 $(foreach dir,$(cursubdirs), \
Patrick Georgi58262652011-02-17 20:47:49 +0000227 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000228 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000229
230# collect all object files eligible for building
Patrick Georgie38d0a62011-03-01 08:09:22 +0000231subdirs:=$(TOPLEVEL)
Patrick Georgi51e142f2010-03-27 17:18:39 +0000232$(eval $(call evaluate_subdirs))
Patrick Georgi0588d192009-08-12 15:00:51 +0000233
Patrick Georgi94a45862011-10-25 14:32:21 -0700234# Eliminate duplicate mentions of source files in a class
235$(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
236
Patrick Georgi8463dd92010-09-30 16:55:02 +0000237src-to-obj=$(addsuffix .$(1).o, $(basename $(patsubst src/%, $(obj)/%, $($(1)-srcs))))
Patrick Georgi58262652011-02-17 20:47:49 +0000238$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class))))
Patrick Georgid3428b02010-02-24 13:18:01 +0000239
Patrick Georgi79f90102012-11-25 14:31:08 +0100240# Call post-processors if they're defined
241$(foreach class,$(classes),\
242 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
243
Patrick Georgi58262652011-02-17 20:47:49 +0000244allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
245allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000246alldirs:=$(sort $(abspath $(dir $(allobjs))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000247
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000248# macro to define template macros that are used by use_template macro
249define create_cc_template
Patrick Georgi71b84802011-02-22 14:35:05 +0000250# $1 obj class
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000251# $2 source suffix (c, S)
Patrick Georgi8463dd92010-09-30 16:55:02 +0000252# $3 additional compiler flags
Patrick Georgi57205c72011-03-08 20:49:18 +0000253# $4 additional dependencies
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000254ifn$(EMPTY)def $(1)-objs_$(2)_template
Patrick Georgi8463dd92010-09-30 16:55:02 +0000255de$(EMPTY)fine $(1)-objs_$(2)_template
Patrick Georgi57205c72011-03-08 20:49:18 +0000256$(obj)/$$(1).$(1).o: src/$$(1).$(2) $(obj)/config.h $(4)
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000257 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
Patrick Georgi8463dd92010-09-30 16:55:02 +0000258 $(CC) $(3) -MMD $$$$(CFLAGS) -c -o $$$$@ $$$$<
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000259en$(EMPTY)def
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000260end$(EMPTY)if
Patrick Georgi0588d192009-08-12 15:00:51 +0000261endef
262
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000263filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
264$(foreach class,$(classes), \
265 $(foreach type,$(call filetypes-of-class,$(class)), \
Patrick Georgi57205c72011-03-08 20:49:18 +0000266 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps)))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000267
Patrick Georgi8463dd92010-09-30 16:55:02 +0000268foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(subst src/,,$(basename $(file))))))
Patrick Georgi58262652011-02-17 20:47:49 +0000269$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000270
Patrick Georgi71b84802011-02-22 14:35:05 +0000271DEPENDENCIES = $(allobjs:.o=.d)
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000272-include $(DEPENDENCIES)
273
Patrick Georgi0588d192009-08-12 15:00:51 +0000274printall:
Patrick Georgi71b84802011-02-22 14:35:05 +0000275 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
Patrick Georgi0588d192009-08-12 15:00:51 +0000276 @echo alldirs:=$(alldirs)
Patrick Georgi8463dd92010-09-30 16:55:02 +0000277 @echo allsrcs=$(allsrcs)
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000278 @echo DEPENDENCIES=$(DEPENDENCIES)
Stefan Reinauer68a564f2010-03-16 01:02:18 +0000279 @echo LIBGCC_FILE_NAME=$(LIBGCC_FILE_NAME)
Patrick Georgi71b84802011-02-22 14:35:05 +0000280 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
Patrick Georgi0588d192009-08-12 15:00:51 +0000281
282endif
283
Patrick Georgi40ad8422011-05-21 22:18:59 +0000284ifndef NOMKDIR
Patrick Georgi71b84802011-02-22 14:35:05 +0000285$(shell mkdir -p $(obj) $(objutil)/kconfig/lxdialog $(additional-dirs) $(alldirs))
Patrick Georgi40ad8422011-05-21 22:18:59 +0000286endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000287
Warren Turkala9fc3302010-09-03 08:57:32 +0000288cscope:
289 cscope -bR
290
Patrick Georgi0588d192009-08-12 15:00:51 +0000291doxy: doxygen
292doxygen:
Stefan Reinauer1bbad5c2010-02-10 15:36:53 +0000293 $(DOXYGEN) documentation/Doxyfile.coreboot
Patrick Georgi0588d192009-08-12 15:00:51 +0000294
295doxyclean: doxygen-clean
296doxygen-clean:
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000297 rm -rf $(DOXYGEN_OUTPUT_DIR)
Patrick Georgi0588d192009-08-12 15:00:51 +0000298
Patrick Georgi71b84802011-02-22 14:35:05 +0000299clean-for-update: doxygen-clean clean-for-update-target
300 rm -f $(allobjs) .xcompile
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000301 rm -f $(DEPENDENCIES)
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000302 rmdir -p $(alldirs) 2>/dev/null >/dev/null || true
Patrick Georgi0588d192009-08-12 15:00:51 +0000303
Patrick Georgi71b84802011-02-22 14:35:05 +0000304clean: clean-for-update clean-target
305 rm -f .ccwrap
Warren Turkal0e8f2042010-09-27 21:14:19 +0000306
Warren Turkala9fc3302010-09-03 08:57:32 +0000307clean-cscope:
308 rm -f cscope.out
309
zbaod086d512012-03-23 10:26:28 +0800310distclean:
Myles Watson1af297c2010-01-06 16:59:18 +0000311 rm -rf $(obj)
Patrick Georgicf036d12010-04-21 06:36:20 +0000312 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000313
Patrick Georgi71b84802011-02-22 14:35:05 +0000314.PHONY: $(PHONY) clean clean-cscope cscope distclean doxygen doxy .xcompile