blob: 421e91932602173fd746415c6d69dbd0f8be4854 [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.
35$(if $(wildcard .xcompile),,$(eval $(shell util/xcompile/xcompile $(XGCCPATH) > .xcompile)))
36
Patrick Georgi18ff4f12014-07-10 21:06:04 +020037.xcompile: util/xcompile/xcompile
Vadim Bendeburye4696022015-04-25 11:34:35 -070038 $< $(XGCCPATH) > $@.tmp
39 \mv -f $@.tmp $@ 2> /dev/null
Patrick Georgi18ff4f12014-07-10 21:06:04 +020040
Jonathan Kollasch7ff5b442010-09-28 21:11:48 +000041export top := $(CURDIR)
Patrick Georgi51e142f2010-03-27 17:18:39 +000042export src := src
Patrick Georgi0588d192009-08-12 15:00:51 +000043export srck := $(top)/util/kconfig
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -070044obj ?= build
45override obj := $(subst $(top)/,,$(abspath $(obj)))
46export obj
Patrick Georgia2acbc72010-04-16 22:48:57 +000047export objutil ?= $(obj)/util
48export objk := $(objutil)/kconfig
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -070049absobj := $(abspath $(obj))
Patrick Georgi0588d192009-08-12 15:00:51 +000050
51
Patrick Georgi0588d192009-08-12 15:00:51 +000052export KCONFIG_AUTOHEADER := $(obj)/config.h
53export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
Patrick Georgid5208402014-04-11 20:24:06 +020054export KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
55export KCONFIG_SPLITCONFIG := $(obj)/config
56export KCONFIG_TRISTATE := $(obj)/tristate.conf
57export KCONFIG_NEGATIVES := 1
Patrick Georgi0588d192009-08-12 15:00:51 +000058
Patrick Georgie38d0a62011-03-01 08:09:22 +000059# directory containing the toplevel Makefile.inc
60TOPLEVEL := .
61
Patrick Georgi0588d192009-08-12 15:00:51 +000062CONFIG_SHELL := sh
63KBUILD_DEFCONFIG := configs/defconfig
64UNAME_RELEASE := $(shell uname -r)
Patrick Georgi89ec3762010-12-08 19:58:30 +000065DOTCONFIG ?= .config
66KCONFIG_CONFIG = $(DOTCONFIG)
67export KCONFIG_CONFIG
68HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
Patrick Georgi0588d192009-08-12 15:00:51 +000069MAKEFLAGS += -rR --no-print-directory
70
71# Make is silent per default, but 'make V=1' will show all compiler calls.
Patrick Georgi2b7418e2009-08-25 19:38:46 +000072Q:=@
Patrick Georgi0588d192009-08-12 15:00:51 +000073ifneq ($(V),1)
Patrick Georgi2b7418e2009-08-25 19:38:46 +000074ifneq ($(Q),)
75.SILENT:
76endif
Patrick Georgi0588d192009-08-12 15:00:51 +000077endif
78
Julius Werner808a4292015-03-13 11:05:07 -070079# Disable implicit/built-in rules to make Makefile errors fail fast.
80.SUFFIXES:
81
Edward O'Callaghan16407ab2014-10-30 11:36:42 +110082HOSTCC := gcc
Patrick Georgi0588d192009-08-12 15:00:51 +000083HOSTCXX = g++
Patrick Georgib3a18ac2012-09-13 22:13:33 +020084HOSTCFLAGS := -g
85HOSTCXXFLAGS := -g
Patrick Georgi0588d192009-08-12 15:00:51 +000086
Patrick Georgi828e0e82015-04-04 15:50:20 +020087PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
88
Patrick Georgi0588d192009-08-12 15:00:51 +000089DOXYGEN := doxygen
90DOXYGEN_OUTPUT_DIR := doxygen
91
Patrick Georgi71b84802011-02-22 14:35:05 +000092all: real-all
93
Patrick Georgie38d0a62011-03-01 08:09:22 +000094# This include must come _before_ the pattern rules below!
Patrick Georgi71b84802011-02-22 14:35:05 +000095# Order _does_ matter for pattern rules.
Stefan Reinauerde60c882015-06-29 14:44:37 -070096include $(srck)/Makefile
Patrick Georgi71b84802011-02-22 14:35:05 +000097
Patrick Georgicf036d12010-04-21 06:36:20 +000098# Three cases where we don't need fully populated $(obj) lists:
99# 1. when no .config exists
100# 2. when make config (in any flavour) is run
101# 3. when make distclean is run
102# Don't waste time on reading all Makefile.incs in these cases
Patrick Georgi0588d192009-08-12 15:00:51 +0000103ifeq ($(strip $(HAVE_DOTCONFIG)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000104NOCOMPILE:=1
105endif
106ifneq ($(MAKECMDGOALS),)
Patrick Georgi7711c0d2015-02-17 12:21:32 +0100107ifneq ($(filter %config %clean cross% lint% what-jenkins-does,$(MAKECMDGOALS)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000108NOCOMPILE:=1
109endif
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100110ifeq ($(MAKECMDGOALS), %clean)
Zheng Bao0fd93d62012-10-22 16:36:03 +0800111NOMKDIR:=1
112endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000113endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000114
Patrick Georgicf036d12010-04-21 06:36:20 +0000115ifeq ($(NOCOMPILE),1)
Patrick Georgie38d0a62011-03-01 08:09:22 +0000116include $(TOPLEVEL)/Makefile.inc
Patrick Georgi71b84802011-02-22 14:35:05 +0000117real-all: config
Patrick Georgi0588d192009-08-12 15:00:51 +0000118
119else
120
Patrick Georgi977b9852010-09-24 22:15:54 +0000121include $(HAVE_DOTCONFIG)
Patrick Georgi0588d192009-08-12 15:00:51 +0000122
Patrick Georgi7b9762f2015-06-04 13:18:11 +0200123include .xcompile
124
Patrick Georgicc84a002014-05-14 21:05:35 +0200125ifneq ($(CONFIG_MMX),y)
126CFLAGS_x86_32 += -mno-mmx
127endif
128
Patrick Georgicc84a002014-05-14 21:05:35 +0200129include toolchain.inc
130
Patrick Georgia84e98b2010-03-16 19:01:32 +0000131strip_quotes = $(subst ",,$(subst \",,$(1)))
132
Patrick Georgi0588d192009-08-12 15:00:51 +0000133# The primary target needs to be here before we include the
134# other files
135
Patrick Georgi71b84802011-02-22 14:35:05 +0000136real-all: real-target
Patrick Georgi0588d192009-08-12 15:00:51 +0000137
Patrick Georgi51e142f2010-03-27 17:18:39 +0000138# must come rather early
139.SECONDEXPANSION:
140
Stefan Reinauer0d869ed2015-07-17 13:31:16 -0700141$(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG)
Stefan Reinauer1425add2010-03-21 22:35:58 +0000142 $(MAKE) oldconfig
Patrick Georgi0588d192009-08-12 15:00:51 +0000143
Patrick Georgi58262652011-02-17 20:47:49 +0000144# Add a new class of source/object files to the build system
145add-class= \
146 $(eval $(1)-srcs:=) \
147 $(eval $(1)-objs:=) \
148 $(eval classes+=$(1))
Patrick Georgi8463dd92010-09-30 16:55:02 +0000149
Patrick Georgi58262652011-02-17 20:47:49 +0000150# Special classes are managed types with special behaviour
151# On parse time, for each entry in variable $(1)-y
152# a handler $(1)-handler is executed with the arguments:
153# * $(1): directory the parser is in
154# * $(2): current entry
155add-special-class= \
156 $(eval $(1):=) \
157 $(eval special-classes+=$(1))
158
Patrick Georgi47d68d82010-03-06 21:18:43 +0000159# Clean -y variables, include Makefile.inc
Patrick Georgi8463dd92010-09-30 16:55:02 +0000160# Add paths to files in X-y to X-srcs
Patrick Georgi47d68d82010-03-06 21:18:43 +0000161# Add subdirs-y to subdirs
162includemakefiles= \
Patrick Georgi58262652011-02-17 20:47:49 +0000163 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
Patrick Georgi47d68d82010-03-06 21:18:43 +0000164 $(eval -include $(1)) \
Patrick Georgi58262652011-02-17 20:47:49 +0000165 $(foreach class,$(classes-y), $(call add-class,$(class))) \
166 $(foreach class,$(classes), \
167 $(eval $(class)-srcs+= \
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -0700168 $$(subst $(absobj)/,$(obj)/, \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000169 $$(subst $(top)/,, \
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -0700170 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
Patrick Georgi58262652011-02-17 20:47:49 +0000171 $(foreach special,$(special-classes), \
172 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
Jonathan Kollasch7ff5b442010-09-28 21:11:48 +0000173 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
Patrick Georgi47d68d82010-03-06 21:18:43 +0000174
Patrick Georgi8463dd92010-09-30 16:55:02 +0000175# For each path in $(subdirs) call includemakefiles
Patrick Georgi47d68d82010-03-06 21:18:43 +0000176# Repeat until subdirs is empty
177evaluate_subdirs= \
178 $(eval cursubdirs:=$(subdirs)) \
179 $(eval subdirs:=) \
180 $(foreach dir,$(cursubdirs), \
Patrick Georgi58262652011-02-17 20:47:49 +0000181 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000182 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000183
184# collect all object files eligible for building
Patrick Georgie38d0a62011-03-01 08:09:22 +0000185subdirs:=$(TOPLEVEL)
Patrick Georgi51e142f2010-03-27 17:18:39 +0000186$(eval $(call evaluate_subdirs))
Patrick Georgi70c85ea2013-02-16 01:06:57 +0100187ifeq ($(FAILBUILD),1)
188$(error cannot continue build)
189endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000190
Patrick Georgi94a45862011-10-25 14:32:21 -0700191# Eliminate duplicate mentions of source files in a class
192$(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
193
Patrick Georgidb273062015-03-27 17:03:28 +0100194# Converts one or more source file paths to their corresponding build/ paths.
195# Only .c and .S get converted to .o, other files (like .ld) keep their name.
196# $1 stage name
197# $2 file path (list)
Julius Wernera32b6f02015-03-12 23:17:16 -0700198src-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 +0100199
Patrick Georgi10f86b02015-03-27 16:56:23 +0100200$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
Patrick Georgid3428b02010-02-24 13:18:01 +0000201
Nico Huber963bed52013-05-15 11:47:51 +0200202# Save all objs before processing them (for dependency inclusion)
203originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
204
Patrick Georgi79f90102012-11-25 14:31:08 +0100205# Call post-processors if they're defined
206$(foreach class,$(classes),\
207 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
208
Patrick Georgi58262652011-02-17 20:47:49 +0000209allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
210allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000211alldirs:=$(sort $(abspath $(dir $(allobjs))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000212
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000213# macro to define template macros that are used by use_template macro
214define create_cc_template
Patrick Georgi71b84802011-02-22 14:35:05 +0000215# $1 obj class
Patrick Georgi990e7c92015-04-03 10:47:15 +0200216# $2 source suffix (c, S, ld, ...)
Marc Jonesa38ccfd2014-11-06 15:50:22 -0700217# $3 additional compiler flags
218# $4 additional dependencies
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000219ifn$(EMPTY)def $(1)-objs_$(2)_template
Patrick Georgi8463dd92010-09-30 16:55:02 +0000220de$(EMPTY)fine $(1)-objs_$(2)_template
Stefan Reinauer0d869ed2015-07-17 13:31:16 -0700221$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000222 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
Patrick Georgi75fcaf92015-04-03 10:16:12 +0200223 $(CC_$(1)) -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) $(3) -c -o $$$$@ $$$$<
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000224en$(EMPTY)def
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000225end$(EMPTY)if
Patrick Georgi0588d192009-08-12 15:00:51 +0000226endef
227
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000228filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
229$(foreach class,$(classes), \
230 $(foreach type,$(call filetypes-of-class,$(class)), \
Patrick Georgi2459aee2015-03-27 15:27:21 +0100231 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
Patrick Georgi416ab382015-04-03 10:19:38 +0200232 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
233 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000234
Patrick Georgid69839b2015-04-03 10:32:17 +0200235foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
Patrick Georgi58262652011-02-17 20:47:49 +0000236$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000237
Julius Wernerf97b88b2014-12-05 12:32:09 -0800238DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000239-include $(DEPENDENCIES)
240
Patrick Georgi0588d192009-08-12 15:00:51 +0000241printall:
Patrick Georgi71b84802011-02-22 14:35:05 +0000242 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
Patrick Georgi0588d192009-08-12 15:00:51 +0000243 @echo alldirs:=$(alldirs)
Patrick Georgi8463dd92010-09-30 16:55:02 +0000244 @echo allsrcs=$(allsrcs)
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000245 @echo DEPENDENCIES=$(DEPENDENCIES)
Patrick Georgi71b84802011-02-22 14:35:05 +0000246 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
Patrick Georgi0588d192009-08-12 15:00:51 +0000247
248endif
249
Patrick Georgi40ad8422011-05-21 22:18:59 +0000250ifndef NOMKDIR
Stefan Reinauerde60c882015-06-29 14:44:37 -0700251$(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
Patrick Georgi40ad8422011-05-21 22:18:59 +0000252endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000253
Martin Roth9c1b33e2015-07-29 14:55:18 -0700254$(obj)/project_filelist.txt: all
255 find $(obj) -name "*.d" -exec cat {} \; | \
256 sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
257 grep -v '\.o$$' > $(obj)/project_filelist.txt
258
259#works with either exuberant ctags or ctags.emacs
260ctags-project: clean-ctags $(obj)/project_filelist.txt
261 cat $(obj)/project_filelist.txt | \
262 xargs ctags -o tags
263
264cscope-project: clean-cscope $(obj)/project_filelist.txt
265 cat $(obj)/project_filelist.txt | xargs cscope -b
266
Warren Turkala9fc3302010-09-03 08:57:32 +0000267cscope:
268 cscope -bR
269
Patrick Georgi0588d192009-08-12 15:00:51 +0000270doxy: doxygen
271doxygen:
Nicky Sielickie08a2a52015-06-06 08:55:16 -0500272 $(DOXYGEN) Documentation/Doxyfile.coreboot
Patrick Georgi0588d192009-08-12 15:00:51 +0000273
Martin Rothd7689e42014-12-29 14:56:19 -0700274doxygen_simple:
Nicky Sielickie08a2a52015-06-06 08:55:16 -0500275 $(DOXYGEN) Documentation/Doxyfile.coreboot_simple
Martin Rothd7689e42014-12-29 14:56:19 -0700276
Patrick Georgi0588d192009-08-12 15:00:51 +0000277doxyclean: doxygen-clean
278doxygen-clean:
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000279 rm -rf $(DOXYGEN_OUTPUT_DIR)
Patrick Georgi0588d192009-08-12 15:00:51 +0000280
Patrick Georgi71b84802011-02-22 14:35:05 +0000281clean-for-update: doxygen-clean clean-for-update-target
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100282 rm -rf $(obj) .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000283
Patrick Georgi71b84802011-02-22 14:35:05 +0000284clean: clean-for-update clean-target
285 rm -f .ccwrap
Warren Turkal0e8f2042010-09-27 21:14:19 +0000286
Warren Turkala9fc3302010-09-03 08:57:32 +0000287clean-cscope:
288 rm -f cscope.out
289
Martin Roth9c1b33e2015-07-29 14:55:18 -0700290clean-ctags:
291 rm -f tags
292
293distclean: clean clean-ctags clean-cscope
Patrick Georgicf036d12010-04-21 06:36:20 +0000294 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000295
Martin Rothd7689e42014-12-29 14:56:19 -0700296.PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple
Martin Roth9c1b33e2015-07-29 14:55:18 -0700297.PHONY: ctags-project cscope-project clean-ctags