blob: b0a99146ec770e92d680ad4f372d7aae2482abb2 [file] [log] [blame]
Jacob Garber005fe892020-05-12 22:37:39 -06001## SPDX-License-Identifier: BSD-3-Clause
Patrick Georgi0588d192009-08-12 15:00:51 +00002
Himanshu Sahdevd1e18d92019-09-16 15:55:03 +05303ifneq ($(words $(CURDIR)),1)
4 $(error Error: Path to the main directory cannot contain spaces)
5endif
Nico Huber7a1fbdb2017-08-23 23:48:13 +02006top := $(CURDIR)
7src := src
8srck := $(top)/util/kconfig
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -07009obj ?= build
10override obj := $(subst $(top)/,,$(abspath $(obj)))
Raul E Rangel81ff33c2019-07-11 10:44:21 -060011xcompile ?= $(obj)/xcompile
Nico Huber7a1fbdb2017-08-23 23:48:13 +020012objutil ?= $(obj)/util
13objk := $(objutil)/kconfig
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -070014absobj := $(abspath $(obj))
Patrick Georgi0588d192009-08-12 15:00:51 +000015
Nico Huber10a879e2021-03-06 13:12:34 +010016additional-dirs :=
17
roccochen@chromium.com7713a2f2023-11-02 15:49:02 +080018VBOOT_SOURCE ?= $(abspath 3rdparty/vboot)
Yu-Ping Wu0beddb52020-03-09 10:58:37 +080019VBOOT_HOST_BUILD ?= $(abspath $(objutil)/vboot_lib)
20
Nico Huber7a1fbdb2017-08-23 23:48:13 +020021COREBOOT_EXPORTS := COREBOOT_EXPORTS
22COREBOOT_EXPORTS += top src srck obj objutil objk
Patrick Georgi0588d192009-08-12 15:00:51 +000023
Nico Huber7a1fbdb2017-08-23 23:48:13 +020024DOTCONFIG ?= $(top)/.config
25KCONFIG_CONFIG = $(DOTCONFIG)
Nico Huber533bc0a2019-01-01 19:03:33 +010026KCONFIG_AUTOADS := $(obj)/cb-config.ads
Nico Huber7a1fbdb2017-08-23 23:48:13 +020027KCONFIG_AUTOHEADER := $(obj)/config.h
28KCONFIG_AUTOCONFIG := $(obj)/auto.conf
29KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
Patrick Georgi53ea1d42019-11-22 16:55:58 +010030KCONFIG_SPLITCONFIG := $(obj)/config/
Nico Huber7a1fbdb2017-08-23 23:48:13 +020031KCONFIG_TRISTATE := $(obj)/tristate.conf
32KCONFIG_NEGATIVES := 1
33KCONFIG_STRICT := 1
Nico Huber533bc0a2019-01-01 19:03:33 +010034KCONFIG_PACKAGE := CB.Config
Martin Roth4d7285d2021-11-23 12:39:44 -070035KCONFIG_MAKEFILE_REAL ?= $(objk)/Makefile.real
Nico Huber7a1fbdb2017-08-23 23:48:13 +020036
37COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
38COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
39COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_STRICT
Nico Huber533bc0a2019-01-01 19:03:33 +010040COREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE
Patrick Georgi0588d192009-08-12 15:00:51 +000041
Christian Waltera8c10c82022-07-01 11:12:25 +020042# Make does not offer a recursive wildcard function, so here's one:
43rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
44SYMLINK_LIST = $(call rwildcard,site-local/,symlink.txt)
45
46
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 +000053HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
Martin Roth4d7285d2021-11-23 12:39:44 -070054HAVE_KCONFIG_MAKEFILE_REAL := $(wildcard $(KCONFIG_MAKEFILE_REAL))
Patrick Georgi0588d192009-08-12 15:00:51 +000055MAKEFLAGS += -rR --no-print-directory
56
57# Make is silent per default, but 'make V=1' will show all compiler calls.
Patrick Georgi2b7418e2009-08-25 19:38:46 +000058Q:=@
Patrick Georgi0588d192009-08-12 15:00:51 +000059ifneq ($(V),1)
Patrick Georgi2b7418e2009-08-25 19:38:46 +000060ifneq ($(Q),)
61.SILENT:
Nico Huber7325ac52020-02-16 11:47:52 +010062MAKEFLAGS += -s
Martin Rothea6a93f2021-11-21 08:42:04 -070063quiet_errors := 2>/dev/null
Patrick Georgi2b7418e2009-08-25 19:38:46 +000064endif
Patrick Georgi0588d192009-08-12 15:00:51 +000065endif
66
Julius Werner808a4292015-03-13 11:05:07 -070067# Disable implicit/built-in rules to make Makefile errors fail fast.
68.SUFFIXES:
69
Patrick Georgib3a18ac2012-09-13 22:13:33 +020070HOSTCFLAGS := -g
71HOSTCXXFLAGS := -g
Patrick Georgi0588d192009-08-12 15:00:51 +000072
Nico Huber710a38a2022-12-11 13:13:45 +010073HOSTPKG_CONFIG ?= pkg-config
74COREBOOT_EXPORTS += HOSTPKG_CONFIG
75
Patrick Georgi828e0e82015-04-04 15:50:20 +020076PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
77
Nico Huber7a1fbdb2017-08-23 23:48:13 +020078export $(COREBOOT_EXPORTS)
79
Patrick Georgi71b84802011-02-22 14:35:05 +000080all: real-all
81
Martin Roth4eea1742015-11-25 11:50:04 -070082help_coreboot help::
83 @echo '*** coreboot platform targets ***'
Martin Roth76f14b22015-11-18 13:09:23 -070084 @echo ' Use "make [target] V=1" for extra build debug information'
85 @echo ' all - Build coreboot'
86 @echo ' clean - Remove coreboot build artifacts'
87 @echo ' distclean - Remove build artifacts and config files'
Patrick Rudolphf6643212020-05-17 20:04:12 +020088 @echo ' sphinx - Build sphinx documentation for coreboot'
Nico Huberbfdefc22023-08-23 12:42:40 +020089 @echo ' sphinx-lint - Build sphinx documentation for coreboot with warnings as errors'
Martin Roth763e4932018-01-27 16:42:43 -070090 @echo ' filelist - Show files used in current build'
Martin Roth76f14b22015-11-18 13:09:23 -070091 @echo ' printall - print makefile info for debugging'
Werner Zeh2de64102016-01-12 12:45:49 +010092 @echo ' gitconfig - set up git to submit patches to coreboot'
Martin Roth76f14b22015-11-18 13:09:23 -070093 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
94 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
95 @echo
96
Patrick Georgie38d0a62011-03-01 08:09:22 +000097# This include must come _before_ the pattern rules below!
Patrick Georgi71b84802011-02-22 14:35:05 +000098# Order _does_ matter for pattern rules.
Patrick Georgi3e8ef102019-11-22 16:54:17 +010099include $(srck)/Makefile.inc
Patrick Georgi71b84802011-02-22 14:35:05 +0000100
Martin Roth4d7285d2021-11-23 12:39:44 -0700101# The cases where we don't need fully populated $(obj) lists:
Patrick Georgicf036d12010-04-21 06:36:20 +0000102# 1. when no .config exists
Martin Roth4d7285d2021-11-23 12:39:44 -0700103# 2. When no $(obj)/util/kconfig/Makefile.real exists and we're building tools
104# 3. when make config (in any flavour) is run
105# 4. when make distclean is run
Patrick Georgicf036d12010-04-21 06:36:20 +0000106# Don't waste time on reading all Makefile.incs in these cases
Patrick Georgi0588d192009-08-12 15:00:51 +0000107ifeq ($(strip $(HAVE_DOTCONFIG)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000108NOCOMPILE:=1
109endif
Martin Roth4d7285d2021-11-23 12:39:44 -0700110ifeq ($(strip $(HAVE_KCONFIG_MAKEFILE_REAL)),)
111ifneq ($(MAKECMDGOALS),tools)
112NOCOMPILE:=1
113endif
114endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000115ifneq ($(MAKECMDGOALS),)
Elyes HAOUAS91fb1392020-01-20 15:33:11 +0100116ifneq ($(filter %config %clean cross% clang iasl lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000117NOCOMPILE:=1
118endif
Raul E Rangel5592cfd2019-07-23 11:13:40 -0600119ifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
Zheng Bao0fd93d62012-10-22 16:36:03 +0800120NOMKDIR:=1
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200121UNIT_TEST:=1
Zheng Bao0fd93d62012-10-22 16:36:03 +0800122endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000123endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000124
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200125ifneq ($(filter help%, $(MAKECMDGOALS)), )
126NOCOMPILE:=1
127UNIT_TEST:=1
128else
Paul Fagerburgde6cbac2021-05-11 09:56:48 -0600129ifneq ($(filter %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
130ifneq ($(filter-out %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
Jan Dabrosef1c9682020-03-28 00:15:03 +0100131$(error Cannot mix unit-tests targets with other targets)
132endif
133UNIT_TEST:=1
134NOCOMPILE:=
135endif
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200136endif
Jan Dabrosef1c9682020-03-28 00:15:03 +0100137
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600138$(xcompile): util/xcompile/xcompile
Raul E Rangel6325ce22019-07-10 16:46:34 -0600139 rm -f $@
140 $< $(XGCCPATH) > $@.tmp
141 \mv -f $@.tmp $@ 2> /dev/null
142 rm -f $@.tmp
143
Patrick Georgicf036d12010-04-21 06:36:20 +0000144ifeq ($(NOCOMPILE),1)
Patrick Georgib351875f2020-07-06 15:31:58 +0000145# We also don't use .xcompile in the no-compile situations, so
146# provide some reasonable defaults.
147HOSTCC ?= $(if $(shell type gcc 2>/dev/null),gcc,cc)
148HOSTCXX ?= g++
149
Patrick Georgie38d0a62011-03-01 08:09:22 +0000150include $(TOPLEVEL)/Makefile.inc
Martin Roth67975572016-03-07 16:38:52 -0700151include $(TOPLEVEL)/payloads/Makefile.inc
Martin Rothe624e272017-07-31 11:52:58 -0600152include $(TOPLEVEL)/util/testing/Makefile.inc
Werner Zehb7f1c2d2019-10-04 07:01:13 +0200153-include $(TOPLEVEL)/site-local/Makefile.inc
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200154include $(TOPLEVEL)/tests/Makefile.inc
Martin Roth9fc96402022-11-27 19:04:16 -0700155printall real-all:
Martin Rothe28c7182022-06-22 17:49:31 -0600156 @echo "Error: Trying to build, but NOCOMPILE is set." >&2
157 @echo " Please file a bug with the following information:"
158 @echo "- MAKECMDGOALS: $(MAKECMDGOALS)" >&2
159 @echo "- HAVE_DOTCONFIG: $(HAVE_DOTCONFIG)" >&2
160 @echo "- HAVE_KCONFIG_MAKEFILE_REAL: $(HAVE_KCONFIG_MAKEFILE_REAL)" >&2
Martin Roth20aa0432017-01-26 10:51:43 -0700161 @exit 1
Martin Roth9fc96402022-11-27 19:04:16 -0700162
Patrick Georgi0588d192009-08-12 15:00:51 +0000163else
164
Jan Dabrosef1c9682020-03-28 00:15:03 +0100165ifneq ($(UNIT_TEST),1)
Paul Kocialkowski585c7812016-07-13 11:00:41 +0200166include $(DOTCONFIG)
Jan Dabrosef1c9682020-03-28 00:15:03 +0100167endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000168
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600169# The toolchain requires xcompile to determine the ARCH_SUPPORTED, so we can't
170# wait for make to generate the file.
171$(if $(wildcard $(xcompile)),, $(shell \
172 mkdir -p $(dir $(xcompile)) && \
173 util/xcompile/xcompile $(XGCCPATH) > $(xcompile) || rm -f $(xcompile)))
Patrick Georgi0ffef882017-01-19 23:20:14 +0100174
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600175include $(xcompile)
Patrick Georgi6dda31d2015-11-19 15:15:33 +0100176
177ifneq ($(XCOMPILE_COMPLETE),1)
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600178$(shell rm -f $(xcompile))
179$(error $(xcompile) deleted because it's invalid. \
Patrick Georgi6dda31d2015-11-19 15:15:33 +0100180 Restarting the build should fix that, or explain the problem)
181endif
Patrick Georgi7b9762f2015-06-04 13:18:11 +0200182
Patrick Georgica6e5ee2021-04-13 15:48:38 +0200183# reproducible builds
184LANG:=C
185LC_ALL:=C
186TZ:=UTC0
187ifneq ($(NOCOMPILE),1)
188SOURCE_DATE_EPOCH := $(shell $(top)/util/genbuild_h/genbuild_h.sh . | sed -n 's/^.define COREBOOT_BUILD_EPOCH\>.*"\(.*\)".*/\1/p')
189endif
190# don't use COREBOOT_EXPORTS to ensure build steps outside the coreboot build system
191# are reproducible
192export LANG LC_ALL TZ SOURCE_DATE_EPOCH
193
Jan Dabrosef1c9682020-03-28 00:15:03 +0100194ifneq ($(UNIT_TEST),1)
Patrick Georgicc84a002014-05-14 21:05:35 +0200195include toolchain.inc
Jan Dabrosef1c9682020-03-28 00:15:03 +0100196endif
Patrick Georgicc84a002014-05-14 21:05:35 +0200197
Zheng Bao07648922015-11-13 10:42:27 +0800198strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
Martin Rothbbf13992016-01-25 15:59:24 -0700199# fix makefile syntax highlighting after strip macro \" "))
Patrick Georgia84e98b2010-03-16 19:01:32 +0000200
Kyösti Mälkkicad92ec2022-12-14 17:26:35 +0200201ifneq ($(NOCOMPILE),1)
202$(shell rm -f $(CCACHE_STATSLOG))
203endif
204
Patrick Georgi0588d192009-08-12 15:00:51 +0000205# The primary target needs to be here before we include the
206# other files
207
Patrick Georgi71b84802011-02-22 14:35:05 +0000208real-all: real-target
Patrick Georgi0588d192009-08-12 15:00:51 +0000209
Patrick Georgi51e142f2010-03-27 17:18:39 +0000210# must come rather early
Raul E Rangeldd6efce2022-02-25 17:03:10 -0700211.SECONDARY:
Patrick Georgi51e142f2010-03-27 17:18:39 +0000212.SECONDEXPANSION:
Raul E Rangelcc6dc902018-08-06 16:13:32 -0600213.DELETE_ON_ERROR:
Patrick Georgi51e142f2010-03-27 17:18:39 +0000214
Jonathan Neuschäferd2c02422018-12-11 13:06:40 +0100215$(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
Patrick Georgi53ea1d42019-11-22 16:55:58 +0100216 $(MAKE) olddefconfig
217 $(MAKE) syncconfig
Patrick Georgi0588d192009-08-12 15:00:51 +0000218
Nico Huber533bc0a2019-01-01 19:03:33 +0100219$(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
220 true
221
Nico Hubereafc8152019-10-25 12:47:14 +0200222$(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
Nico Huber533bc0a2019-01-01 19:03:33 +0100223 $(objutil)/kconfig/toada CB.Config <$< >$@
224
Nico Huberb5679772019-01-01 22:06:01 +0100225$(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
226 cp $< $@
227
Patrick Georgi58262652011-02-17 20:47:49 +0000228# Add a new class of source/object files to the build system
229add-class= \
230 $(eval $(1)-srcs:=) \
231 $(eval $(1)-objs:=) \
232 $(eval classes+=$(1))
Patrick Georgi8463dd92010-09-30 16:55:02 +0000233
Patrick Georgi58262652011-02-17 20:47:49 +0000234# Special classes are managed types with special behaviour
235# On parse time, for each entry in variable $(1)-y
236# a handler $(1)-handler is executed with the arguments:
237# * $(1): directory the parser is in
238# * $(2): current entry
239add-special-class= \
240 $(eval $(1):=) \
241 $(eval special-classes+=$(1))
242
Nico Huber81b09f42016-01-23 00:50:00 +0100243# Converts one or more source file paths to their corresponding build/ paths.
Nico Huber2e09d2b2016-01-14 01:13:33 +0100244# Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
245# their name.
Nico Huber81b09f42016-01-23 00:50:00 +0100246# $1 stage name
247# $2 file path (list)
Nico Huber98fc4262016-01-23 01:24:33 +0100248src-to-obj=\
249 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
250 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200251 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber98fc4262016-01-23 01:24:33 +0100252 $(patsubst src/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100253 $(patsubst %.ads,%.o,\
254 $(patsubst %.adb,%.o,\
Nico Huber98fc4262016-01-23 01:24:33 +0100255 $(patsubst %.c,%.o,\
256 $(patsubst %.S,%.o,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200257 $(subst .$(1),,$(2))))))))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100258
259# Converts one or more source file paths to the corresponding build/ paths
260# of their Ada library information (.ali) files.
261# $1 stage name
262# $2 file path (list)
263src-to-ali=\
264 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
265 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200266 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100267 $(patsubst src/%,$(obj)/%,\
268 $(patsubst %.ads,%.ali,\
269 $(patsubst %.adb,%.ali,\
270 $(subst .$(1),,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200271 $(filter %.ads %.adb,$(2)))))))))
Nico Huber81b09f42016-01-23 00:50:00 +0100272
Patrick Georgi47d68d82010-03-06 21:18:43 +0000273# Clean -y variables, include Makefile.inc
Patrick Georgi8463dd92010-09-30 16:55:02 +0000274# Add paths to files in X-y to X-srcs
Patrick Georgi47d68d82010-03-06 21:18:43 +0000275# Add subdirs-y to subdirs
276includemakefiles= \
Nikolai Vyssotskib9d00722022-09-24 08:48:15 -0500277 $(if $(wildcard $(1)), \
278 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
279 $(eval -include $(1)) \
280 $(foreach class,$(classes-y), $(call add-class,$(class))) \
281 $(foreach special,$(special-classes), \
282 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
283 $(foreach class,$(classes), \
284 $(eval $(class)-srcs+= \
285 $$(subst $(absobj)/,$(obj)/, \
286 $$(subst $(top)/,, \
287 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
288 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))))
Patrick Georgi47d68d82010-03-06 21:18:43 +0000289
Patrick Georgi8463dd92010-09-30 16:55:02 +0000290# For each path in $(subdirs) call includemakefiles
Patrick Georgi47d68d82010-03-06 21:18:43 +0000291# Repeat until subdirs is empty
292evaluate_subdirs= \
293 $(eval cursubdirs:=$(subdirs)) \
294 $(eval subdirs:=) \
295 $(foreach dir,$(cursubdirs), \
Patrick Georgi58262652011-02-17 20:47:49 +0000296 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000297 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000298
299# collect all object files eligible for building
Patrick Georgie38d0a62011-03-01 08:09:22 +0000300subdirs:=$(TOPLEVEL)
Julius Wernere91d1702017-03-20 15:32:15 -0700301postinclude-hooks :=
Jan Dabrosef1c9682020-03-28 00:15:03 +0100302
303# Don't iterate through Makefile.incs under src/ when building tests
304ifneq ($(UNIT_TEST),1)
Patrick Georgi51e142f2010-03-27 17:18:39 +0000305$(eval $(call evaluate_subdirs))
Jan Dabrosef1c9682020-03-28 00:15:03 +0100306else
307include $(TOPLEVEL)/tests/Makefile.inc
308endif
309
Patrick Georgi70c85ea2013-02-16 01:06:57 +0100310ifeq ($(FAILBUILD),1)
311$(error cannot continue build)
312endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000313
Julius Wernere91d1702017-03-20 15:32:15 -0700314# Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
315$(eval $(postinclude-hooks))
316
Patrick Georgi94a45862011-10-25 14:32:21 -0700317# Eliminate duplicate mentions of source files in a class
318$(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
319
Martin Rothb18726d2023-08-15 15:57:29 -0600320ifeq ($(CONFIG_IWYU),y)
321MAKEFLAGS += -k
322SAVE_IWYU_OUTPUT := 2>&1 | grep "should\|\#include\|---\|include-list\|^[[:blank:]]\?\'" | tee -a $$(obj)/iwyu.txt
323endif
324
Nico Huberb5679772019-01-01 22:06:01 +0100325# Build Kconfig .ads if necessary
Jeremy Compostellafa838872022-11-30 19:26:01 -0700326ifeq ($(CONFIG_ROMSTAGE_ADA),y)
327romstage-srcs += $(obj)/romstage/$(notdir $(KCONFIG_AUTOADS))
328endif
Nico Huberb5679772019-01-01 22:06:01 +0100329ifeq ($(CONFIG_RAMSTAGE_ADA),y)
330ramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
331endif
332
Nico Huber2e09d2b2016-01-14 01:13:33 +0100333# To track dependencies, we need all Ada specification (.ads) files in
334# *-srcs. Extract / filter all specification files that have a matching
335# body (.adb) file here (specifications without a body are valid sources
336# in Ada).
337$(foreach class,$(classes),$(eval $(class)-extra-specs := \
338 $(filter \
339 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
340 $(filter %.ads,$($(class)-srcs)))))
341$(foreach class,$(classes),$(eval $(class)-srcs := \
342 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
343
Patrick Georgi10f86b02015-03-27 16:56:23 +0100344$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100345$(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
346
347# For Ada includes
348$(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
Patrick Georgid3428b02010-02-24 13:18:01 +0000349
Nico Huber963bed52013-05-15 11:47:51 +0200350# Save all objs before processing them (for dependency inclusion)
351originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
352
Patrick Georgi79f90102012-11-25 14:31:08 +0100353# Call post-processors if they're defined
354$(foreach class,$(classes),\
355 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
356
Patrick Georgi58262652011-02-17 20:47:49 +0000357allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
358allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000359alldirs:=$(sort $(abspath $(dir $(allobjs))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000360
Nico Huber2e09d2b2016-01-14 01:13:33 +0100361# Reads dependencies from an Ada library information (.ali) file
362# Only basenames (with suffix) are preserved so we have to look the
363# paths up in $($(stage)-srcs).
364# $1 stage name
365# $2 ali file
366create_ada_deps=$$(if $(2),\
367 gnat.adc \
368 $$(filter \
369 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
370 $$($(1)-srcs) $$($(1)-extra-specs)))
371
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000372# macro to define template macros that are used by use_template macro
373define create_cc_template
Patrick Georgi71b84802011-02-22 14:35:05 +0000374# $1 obj class
Patrick Georgi990e7c92015-04-03 10:47:15 +0200375# $2 source suffix (c, S, ld, ...)
Marc Jonesa38ccfd2014-11-06 15:50:22 -0700376# $3 additional compiler flags
377# $4 additional dependencies
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000378ifn$(EMPTY)def $(1)-objs_$(2)_template
Patrick Georgi8463dd92010-09-30 16:55:02 +0000379de$(EMPTY)fine $(1)-objs_$(2)_template
Nico Huber1850aa62017-09-03 23:42:58 +0200380ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
Nico Huberb5679772019-01-01 22:06:01 +0100381$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $$(call create_ada_deps,$1,$$(call src-to-ali,$1,$$(1).$2)) $(4)
Nico Huber1850aa62017-09-03 23:42:58 +0200382 @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
383 $(GCC_$(1)) \
384 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
385 $(3) -c -o $$$$@ $$$$<
386el$(EMPTY)se
387$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000388 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
Nico Huber2e09d2b2016-01-14 01:13:33 +0100389 $(CC_$(1)) \
Nico Huber1850aa62017-09-03 23:42:58 +0200390 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
Martin Rothb18726d2023-08-15 15:57:29 -0600391 $(3) -c -o $$$$@ $$$$< $(SAVE_IWYU_OUTPUT)
Nico Huber1850aa62017-09-03 23:42:58 +0200392end$(EMPTY)if
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000393en$(EMPTY)def
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000394end$(EMPTY)if
Patrick Georgi0588d192009-08-12 15:00:51 +0000395endef
396
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000397filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
398$(foreach class,$(classes), \
399 $(foreach type,$(call filetypes-of-class,$(class)), \
Patrick Georgi2459aee2015-03-27 15:27:21 +0100400 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
Patrick Georgi416ab382015-04-03 10:19:38 +0200401 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
402 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000403
Patrick Georgid69839b2015-04-03 10:32:17 +0200404foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
Patrick Georgi58262652011-02-17 20:47:49 +0000405$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000406
Nico Huber2e09d2b2016-01-14 01:13:33 +0100407# To supported complex package initializations, we need to call the
408# emitted code explicitly. gnatbind gathers all the calls for us
409# and exports them as a procedure $(stage)_adainit(). Every stage that
410# uses Ada code has to call it!
411define gnatbind_template
412# $1 class
413$$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
414 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
415 # We have to give gnatbind a simple filename (without leading
416 # path components) so just cd there.
417 cd $$(dir $$@) && \
418 $$(GNATBIND_$(1)) -a -n \
Nico Huberbe5492a2015-09-29 16:41:19 +0200419 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100420 -L$(1)_ada -o $$(notdir $$@) \
421 $$(subst $$(dir $$@),,$$^)
422$$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
Nico Huber1850aa62017-09-03 23:42:58 +0200423 @printf " GCC $$(subst $$(obj)/,,$$@)\n"
424 $(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
Nico Huber2e09d2b2016-01-14 01:13:33 +0100425$(1)-objs += $$(obj)/$(1)/b__$(1).o
Nico Huberddb24652016-09-19 11:50:04 +0200426$($(1)-alis): %.ali: %.o ;
Nico Huber2e09d2b2016-01-14 01:13:33 +0100427endef
428
Nico Huberbe5492a2015-09-29 16:41:19 +0200429$(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100430 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
431
Julius Wernerf97b88b2014-12-05 12:32:09 -0800432DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000433-include $(DEPENDENCIES)
434
Patrick Georgi0588d192009-08-12 15:00:51 +0000435printall:
Martin Roth09b64442016-06-05 10:52:43 -0600436 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
437 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
438 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
439 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
440 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
Patrick Georgi0588d192009-08-12 15:00:51 +0000441endif
442
Patrick Georgi40ad8422011-05-21 22:18:59 +0000443ifndef NOMKDIR
Stefan Reinauerde60c882015-06-29 14:44:37 -0700444$(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
Patrick Georgi40ad8422011-05-21 22:18:59 +0000445endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000446
Martin Roth9b0204d2017-09-18 09:25:18 -0600447$(obj)/project_filelist.txt:
448 if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
449 echo "*** Error: Project must be built before generating file list ***"; \
450 exit 1; \
451 fi
Maximilian Brunec36b70c2022-12-26 00:29:49 +0100452 find $(obj) -path "$(obj)/util" -prune -o -path "$(obj)/external" -prune -o -name "*.d" -exec cat {} \; | \
Martin Roth8a027272017-09-26 09:53:30 -0600453 sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
Martin Roth9c1b33e2015-07-29 14:55:18 -0700454 grep -v '\.o$$' > $(obj)/project_filelist.txt
455
Martin Roth9b0204d2017-09-18 09:25:18 -0600456filelist: $(obj)/project_filelist.txt
Martin Rotha18353d2017-06-06 06:44:46 -0600457 printf "\nFiles used in build:\n"
458 cat $(obj)/project_filelist.txt
459
Martin Roth9c1b33e2015-07-29 14:55:18 -0700460#works with either exuberant ctags or ctags.emacs
461ctags-project: clean-ctags $(obj)/project_filelist.txt
462 cat $(obj)/project_filelist.txt | \
463 xargs ctags -o tags
464
465cscope-project: clean-cscope $(obj)/project_filelist.txt
466 cat $(obj)/project_filelist.txt | xargs cscope -b
467
Warren Turkala9fc3302010-09-03 08:57:32 +0000468cscope:
469 cscope -bR
470
Patrick Rudolphf6643212020-05-17 20:04:12 +0200471sphinx:
Nico Huber4f014832023-08-23 12:41:01 +0200472 $(MAKE) -C Documentation sphinx
Patrick Rudolphf6643212020-05-17 20:04:12 +0200473
474sphinx-lint:
Nico Huber4f014832023-08-23 12:41:01 +0200475 $(MAKE) SPHINXOPTS=-W -C Documentation sphinx
Patrick Rudolphf6643212020-05-17 20:04:12 +0200476
Christian Waltera8c10c82022-07-01 11:12:25 +0200477symlink:
478 @echo "Creating Symbolic Links.."; \
479 for link in $(SYMLINK_LIST); do \
480 SYMLINK=`cat $$link`; \
481 REALPATH=`realpath $$link`; \
482 if [ -L "$$SYMLINK" ]; then \
483 continue; \
484 elif [ ! -e "$$SYMLINK" ]; then \
485 echo -e "\tLINK $$SYMLINK -> $$(dirname $$REALPATH)"; \
486 ln -s $$(dirname $$REALPATH) $$SYMLINK; \
487 else \
488 echo -e "\tFAILED: $$SYMLINK exists"; \
489 fi \
490 done
491
492clean-symlink:
493 @echo "Deleting symbolic link";\
494 EXISTING_SYMLINKS=`find -L ./src -xtype l | grep -v 3rdparty`; \
495 for link in $$EXISTING_SYMLINKS; do \
496 echo -e "\tUNLINK $$link"; \
497 rm "$$link"; \
498 done
499
Martin Roth619086d2022-05-09 18:48:24 -0600500clean-for-update:
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100501 rm -rf $(obj) .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000502
Arthur Heymansf91366f2022-03-25 16:01:05 +0100503clean: clean-for-update clean-utils clean-payloads
Patrick Georgi71b84802011-02-22 14:35:05 +0000504 rm -f .ccwrap
Warren Turkal0e8f2042010-09-27 21:14:19 +0000505
Warren Turkala9fc3302010-09-03 08:57:32 +0000506clean-cscope:
507 rm -f cscope.out
508
Martin Roth9c1b33e2015-07-29 14:55:18 -0700509clean-ctags:
510 rm -f tags
511
Martin Roth20cd54f2017-03-26 18:49:02 -0600512clean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600513 $(foreach tool, $(TOOLLIST), \
514 $(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
Martin Roth20cd54f2017-03-26 18:49:02 -0600515
516distclean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600517 $(foreach tool, $(TOOLLIST), \
518 $(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
Martin Roth20cd54f2017-03-26 18:49:02 -0600519 rm -f /util/$(tool)/junit.xml;)
520
521distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
Patrick Georgi80656af2017-04-26 11:58:44 +0200522 rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
Martin Roth20cd54f2017-03-26 18:49:02 -0600523 rm -rf coreboot-builds coreboot-builds-chromeos
524 rm -f abuild*.xml junit.xml* util/lint/junit.xml
Patrick Georgi0588d192009-08-12 15:00:51 +0000525
Martin Roth619086d2022-05-09 18:48:24 -0600526.PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean sphinx sphinx-lint
Christian Waltera8c10c82022-07-01 11:12:25 +0200527.PHONY: ctags-project cscope-project clean-ctags symlink clean-symlink