blob: cc567496b805a605c8874a6c9527faacb22b5732 [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.
Patrick Georgibdb4af82015-11-19 09:53:04 +010035$(if $(wildcard .xcompile),,$(eval $(shell util/xcompile/xcompile $(XGCCPATH) > .xcompile || rm -f .xcompile)))
Patrick Georgi05560bf2014-07-19 10:55:30 +020036
Patrick Georgi18ff4f12014-07-10 21:06:04 +020037.xcompile: util/xcompile/xcompile
Patrick Georgi6dda31d2015-11-19 15:15:33 +010038 rm -f $@
Vadim Bendeburye4696022015-04-25 11:34:35 -070039 $< $(XGCCPATH) > $@.tmp
40 \mv -f $@.tmp $@ 2> /dev/null
Patrick Georgi75cdfd12015-11-20 10:32:14 +010041 rm -f $@.tmp
Patrick Georgi18ff4f12014-07-10 21:06:04 +020042
Jonathan Kollasch7ff5b442010-09-28 21:11:48 +000043export top := $(CURDIR)
Patrick Georgi51e142f2010-03-27 17:18:39 +000044export src := src
Patrick Georgi0588d192009-08-12 15:00:51 +000045export srck := $(top)/util/kconfig
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -070046obj ?= build
47override obj := $(subst $(top)/,,$(abspath $(obj)))
48export obj
Patrick Georgia2acbc72010-04-16 22:48:57 +000049export objutil ?= $(obj)/util
50export objk := $(objutil)/kconfig
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -070051absobj := $(abspath $(obj))
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
Julius Werner808a4292015-03-13 11:05:07 -070081# Disable implicit/built-in rules to make Makefile errors fail fast.
82.SUFFIXES:
83
zbao1bb40832015-11-05 15:33:33 +080084HOSTCC := $(if $(shell type gcc 2>/dev/null), gcc, cc)
Patrick Georgi0588d192009-08-12 15:00:51 +000085HOSTCXX = g++
Patrick Georgib3a18ac2012-09-13 22:13:33 +020086HOSTCFLAGS := -g
87HOSTCXXFLAGS := -g
Patrick Georgi0588d192009-08-12 15:00:51 +000088
Patrick Georgi828e0e82015-04-04 15:50:20 +020089PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
90
Patrick Georgi0588d192009-08-12 15:00:51 +000091DOXYGEN := doxygen
92DOXYGEN_OUTPUT_DIR := doxygen
93
Patrick Georgi71b84802011-02-22 14:35:05 +000094all: real-all
95
Patrick Georgie38d0a62011-03-01 08:09:22 +000096# This include must come _before_ the pattern rules below!
Patrick Georgi71b84802011-02-22 14:35:05 +000097# Order _does_ matter for pattern rules.
Stefan Reinauerde60c882015-06-29 14:44:37 -070098include $(srck)/Makefile
Patrick Georgi71b84802011-02-22 14:35:05 +000099
Patrick Georgicf036d12010-04-21 06:36:20 +0000100# Three cases where we don't need fully populated $(obj) lists:
101# 1. when no .config exists
102# 2. when make config (in any flavour) is run
103# 3. when make distclean is run
104# Don't waste time on reading all Makefile.incs in these cases
Patrick Georgi0588d192009-08-12 15:00:51 +0000105ifeq ($(strip $(HAVE_DOTCONFIG)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000106NOCOMPILE:=1
107endif
108ifneq ($(MAKECMDGOALS),)
Patrick Georgi7711c0d2015-02-17 12:21:32 +0100109ifneq ($(filter %config %clean cross% lint% what-jenkins-does,$(MAKECMDGOALS)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000110NOCOMPILE:=1
111endif
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100112ifeq ($(MAKECMDGOALS), %clean)
Zheng Bao0fd93d62012-10-22 16:36:03 +0800113NOMKDIR:=1
114endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000115endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000116
Patrick Georgicf036d12010-04-21 06:36:20 +0000117ifeq ($(NOCOMPILE),1)
Patrick Georgie38d0a62011-03-01 08:09:22 +0000118include $(TOPLEVEL)/Makefile.inc
Patrick Georgi71b84802011-02-22 14:35:05 +0000119real-all: config
Patrick Georgi0588d192009-08-12 15:00:51 +0000120
121else
122
Patrick Georgi977b9852010-09-24 22:15:54 +0000123include $(HAVE_DOTCONFIG)
Patrick Georgi0588d192009-08-12 15:00:51 +0000124
Patrick Georgi6dda31d2015-11-19 15:15:33 +0100125-include .xcompile
126
127ifneq ($(XCOMPILE_COMPLETE),1)
128$(shell rm -f .xcompile)
129$(error .xcompile deleted because it's invalid. \
130 Restarting the build should fix that, or explain the problem)
131endif
Patrick Georgi7b9762f2015-06-04 13:18:11 +0200132
Patrick Georgicc84a002014-05-14 21:05:35 +0200133ifneq ($(CONFIG_MMX),y)
134CFLAGS_x86_32 += -mno-mmx
135endif
136
Patrick Georgicc84a002014-05-14 21:05:35 +0200137include toolchain.inc
138
Zheng Bao07648922015-11-13 10:42:27 +0800139strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
Patrick Georgia84e98b2010-03-16 19:01:32 +0000140
Patrick Georgi0588d192009-08-12 15:00:51 +0000141# The primary target needs to be here before we include the
142# other files
143
Patrick Georgi71b84802011-02-22 14:35:05 +0000144real-all: real-target
Patrick Georgi0588d192009-08-12 15:00:51 +0000145
Patrick Georgi51e142f2010-03-27 17:18:39 +0000146# must come rather early
147.SECONDEXPANSION:
148
Stefan Reinauer0d869ed2015-07-17 13:31:16 -0700149$(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG)
Stefan Reinauer1425add2010-03-21 22:35:58 +0000150 $(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+= \
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -0700176 $$(subst $(absobj)/,$(obj)/, \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000177 $$(subst $(top)/,, \
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -0700178 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
Patrick Georgi58262652011-02-17 20:47:49 +0000179 $(foreach special,$(special-classes), \
180 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
Jonathan Kollasch7ff5b442010-09-28 21:11:48 +0000181 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
Patrick Georgi47d68d82010-03-06 21:18:43 +0000182
Patrick Georgi8463dd92010-09-30 16:55:02 +0000183# For each path in $(subdirs) call includemakefiles
Patrick Georgi47d68d82010-03-06 21:18:43 +0000184# Repeat until subdirs is empty
185evaluate_subdirs= \
186 $(eval cursubdirs:=$(subdirs)) \
187 $(eval subdirs:=) \
188 $(foreach dir,$(cursubdirs), \
Patrick Georgi58262652011-02-17 20:47:49 +0000189 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000190 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000191
192# collect all object files eligible for building
Patrick Georgie38d0a62011-03-01 08:09:22 +0000193subdirs:=$(TOPLEVEL)
Patrick Georgi51e142f2010-03-27 17:18:39 +0000194$(eval $(call evaluate_subdirs))
Patrick Georgi70c85ea2013-02-16 01:06:57 +0100195ifeq ($(FAILBUILD),1)
196$(error cannot continue build)
197endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000198
Patrick Georgi94a45862011-10-25 14:32:21 -0700199# Eliminate duplicate mentions of source files in a class
200$(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
201
Patrick Georgidb273062015-03-27 17:03:28 +0100202# Converts one or more source file paths to their corresponding build/ paths.
203# Only .c and .S get converted to .o, other files (like .ld) keep their name.
204# $1 stage name
205# $2 file path (list)
Julius Wernera32b6f02015-03-12 23:17:16 -0700206src-to-obj=$(foreach file,$(2),$(subst .$(1),,$(basename $(patsubst src/%,$(obj)/%,$(file)))).$(1)$(patsubst %.c,%.o,$(patsubst %.S,%.o,$(suffix $(file)))))
Patrick Georgidb273062015-03-27 17:03:28 +0100207
Patrick Georgi10f86b02015-03-27 16:56:23 +0100208$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
Patrick Georgid3428b02010-02-24 13:18:01 +0000209
Nico Huber963bed52013-05-15 11:47:51 +0200210# Save all objs before processing them (for dependency inclusion)
211originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
212
Patrick Georgi79f90102012-11-25 14:31:08 +0100213# Call post-processors if they're defined
214$(foreach class,$(classes),\
215 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
216
Patrick Georgi58262652011-02-17 20:47:49 +0000217allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
218allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000219alldirs:=$(sort $(abspath $(dir $(allobjs))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000220
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000221# macro to define template macros that are used by use_template macro
222define create_cc_template
Patrick Georgi71b84802011-02-22 14:35:05 +0000223# $1 obj class
Patrick Georgi990e7c92015-04-03 10:47:15 +0200224# $2 source suffix (c, S, ld, ...)
Marc Jonesa38ccfd2014-11-06 15:50:22 -0700225# $3 additional compiler flags
226# $4 additional dependencies
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000227ifn$(EMPTY)def $(1)-objs_$(2)_template
Patrick Georgi8463dd92010-09-30 16:55:02 +0000228de$(EMPTY)fine $(1)-objs_$(2)_template
Stefan Reinauer0d869ed2015-07-17 13:31:16 -0700229$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000230 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
Patrick Georgi75fcaf92015-04-03 10:16:12 +0200231 $(CC_$(1)) -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) $(3) -c -o $$$$@ $$$$<
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000232en$(EMPTY)def
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000233end$(EMPTY)if
Patrick Georgi0588d192009-08-12 15:00:51 +0000234endef
235
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000236filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
237$(foreach class,$(classes), \
238 $(foreach type,$(call filetypes-of-class,$(class)), \
Patrick Georgi2459aee2015-03-27 15:27:21 +0100239 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
Patrick Georgi416ab382015-04-03 10:19:38 +0200240 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
241 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000242
Patrick Georgid69839b2015-04-03 10:32:17 +0200243foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
Patrick Georgi58262652011-02-17 20:47:49 +0000244$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000245
Julius Wernerf97b88b2014-12-05 12:32:09 -0800246DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000247-include $(DEPENDENCIES)
248
Patrick Georgi0588d192009-08-12 15:00:51 +0000249printall:
Patrick Georgi71b84802011-02-22 14:35:05 +0000250 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
Patrick Georgi0588d192009-08-12 15:00:51 +0000251 @echo alldirs:=$(alldirs)
Patrick Georgi8463dd92010-09-30 16:55:02 +0000252 @echo allsrcs=$(allsrcs)
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000253 @echo DEPENDENCIES=$(DEPENDENCIES)
Patrick Georgi71b84802011-02-22 14:35:05 +0000254 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
Patrick Georgi0588d192009-08-12 15:00:51 +0000255
256endif
257
Patrick Georgi40ad8422011-05-21 22:18:59 +0000258ifndef NOMKDIR
Stefan Reinauerde60c882015-06-29 14:44:37 -0700259$(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
Patrick Georgi40ad8422011-05-21 22:18:59 +0000260endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000261
Martin Roth9c1b33e2015-07-29 14:55:18 -0700262$(obj)/project_filelist.txt: all
263 find $(obj) -name "*.d" -exec cat {} \; | \
264 sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
265 grep -v '\.o$$' > $(obj)/project_filelist.txt
266
267#works with either exuberant ctags or ctags.emacs
268ctags-project: clean-ctags $(obj)/project_filelist.txt
269 cat $(obj)/project_filelist.txt | \
270 xargs ctags -o tags
271
272cscope-project: clean-cscope $(obj)/project_filelist.txt
273 cat $(obj)/project_filelist.txt | xargs cscope -b
274
Warren Turkala9fc3302010-09-03 08:57:32 +0000275cscope:
276 cscope -bR
277
Patrick Georgi0588d192009-08-12 15:00:51 +0000278doxy: doxygen
279doxygen:
Nicky Sielickie08a2a52015-06-06 08:55:16 -0500280 $(DOXYGEN) Documentation/Doxyfile.coreboot
Patrick Georgi0588d192009-08-12 15:00:51 +0000281
Martin Rothd7689e42014-12-29 14:56:19 -0700282doxygen_simple:
Nicky Sielickie08a2a52015-06-06 08:55:16 -0500283 $(DOXYGEN) Documentation/Doxyfile.coreboot_simple
Martin Rothd7689e42014-12-29 14:56:19 -0700284
Patrick Georgi0588d192009-08-12 15:00:51 +0000285doxyclean: doxygen-clean
286doxygen-clean:
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000287 rm -rf $(DOXYGEN_OUTPUT_DIR)
Patrick Georgi0588d192009-08-12 15:00:51 +0000288
Patrick Georgi71b84802011-02-22 14:35:05 +0000289clean-for-update: doxygen-clean clean-for-update-target
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100290 rm -rf $(obj) .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000291
Patrick Georgi71b84802011-02-22 14:35:05 +0000292clean: clean-for-update clean-target
293 rm -f .ccwrap
Warren Turkal0e8f2042010-09-27 21:14:19 +0000294
Warren Turkala9fc3302010-09-03 08:57:32 +0000295clean-cscope:
296 rm -f cscope.out
297
Martin Roth9c1b33e2015-07-29 14:55:18 -0700298clean-ctags:
299 rm -f tags
300
301distclean: clean clean-ctags clean-cscope
Patrick Georgicf036d12010-04-21 06:36:20 +0000302 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000303
Martin Rothd7689e42014-12-29 14:56:19 -0700304.PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple
Martin Roth9c1b33e2015-07-29 14:55:18 -0700305.PHONY: ctags-project cscope-project clean-ctags