blob: bc6fabc2e5111dce211d34923c12fd1ee699cfdc [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
Yu-Ping Wu0beddb52020-03-09 10:58:37 +080018VBOOT_HOST_BUILD ?= $(abspath $(objutil)/vboot_lib)
19
Nico Huber7a1fbdb2017-08-23 23:48:13 +020020COREBOOT_EXPORTS := COREBOOT_EXPORTS
21COREBOOT_EXPORTS += top src srck obj objutil objk
Patrick Georgi0588d192009-08-12 15:00:51 +000022
Nico Huber7a1fbdb2017-08-23 23:48:13 +020023DOTCONFIG ?= $(top)/.config
24KCONFIG_CONFIG = $(DOTCONFIG)
Nico Huber533bc0a2019-01-01 19:03:33 +010025KCONFIG_AUTOADS := $(obj)/cb-config.ads
Patrick Georgi1cd374f2023-11-29 15:31:50 +010026KCONFIG_RUSTCCFG := $(obj)/cb-config.rustcfg
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
Patrick Georgi1cc6c542023-11-28 12:08:45 +010033KCONFIG_WERROR := 1
34KCONFIG_WARN_UNKNOWN_SYMBOLS := 1
Nico Huber533bc0a2019-01-01 19:03:33 +010035KCONFIG_PACKAGE := CB.Config
Martin Roth4d7285d2021-11-23 12:39:44 -070036KCONFIG_MAKEFILE_REAL ?= $(objk)/Makefile.real
Nico Huber7a1fbdb2017-08-23 23:48:13 +020037
38COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
39COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
Patrick Georgi1cc6c542023-11-28 12:08:45 +010040COREBOOT_EXPORTS += KCONFIG_NEGATIVES
41ifeq ($(filter %config,$(MAKECMDGOALS)),)
42COREBOOT_EXPORTS += KCONFIG_WERROR
43endif
Patrick Georgi0eab62b2023-11-20 19:49:29 +010044COREBOOT_EXPORTS += KCONFIG_WARN_UNKNOWN_SYMBOLS
Nico Huber533bc0a2019-01-01 19:03:33 +010045COREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE
Patrick Georgi1cd374f2023-11-29 15:31:50 +010046COREBOOT_EXPORTS += KCONFIG_RUSTCCFG
Patrick Georgi0588d192009-08-12 15:00:51 +000047
Christian Waltera8c10c82022-07-01 11:12:25 +020048# Make does not offer a recursive wildcard function, so here's one:
49rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
50SYMLINK_LIST = $(call rwildcard,site-local/,symlink.txt)
51
52
Martin Rothe3df1842024-01-18 10:25:18 -070053# Directory containing the toplevel Makefile.mk
Patrick Georgie38d0a62011-03-01 08:09:22 +000054TOPLEVEL := .
55
Patrick Georgi0588d192009-08-12 15:00:51 +000056CONFIG_SHELL := sh
57KBUILD_DEFCONFIG := configs/defconfig
58UNAME_RELEASE := $(shell uname -r)
Patrick Georgi89ec3762010-12-08 19:58:30 +000059HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
Martin Roth4d7285d2021-11-23 12:39:44 -070060HAVE_KCONFIG_MAKEFILE_REAL := $(wildcard $(KCONFIG_MAKEFILE_REAL))
Patrick Georgi0588d192009-08-12 15:00:51 +000061MAKEFLAGS += -rR --no-print-directory
62
63# Make is silent per default, but 'make V=1' will show all compiler calls.
Patrick Georgi2b7418e2009-08-25 19:38:46 +000064Q:=@
Patrick Georgi0588d192009-08-12 15:00:51 +000065ifneq ($(V),1)
Patrick Georgi2b7418e2009-08-25 19:38:46 +000066ifneq ($(Q),)
67.SILENT:
Nico Huber7325ac52020-02-16 11:47:52 +010068MAKEFLAGS += -s
Martin Rothea6a93f2021-11-21 08:42:04 -070069quiet_errors := 2>/dev/null
Patrick Georgi2b7418e2009-08-25 19:38:46 +000070endif
Patrick Georgi0588d192009-08-12 15:00:51 +000071endif
72
Julius Werner808a4292015-03-13 11:05:07 -070073# Disable implicit/built-in rules to make Makefile errors fail fast.
74.SUFFIXES:
75
Patrick Georgib3a18ac2012-09-13 22:13:33 +020076HOSTCFLAGS := -g
77HOSTCXXFLAGS := -g
Patrick Georgi0588d192009-08-12 15:00:51 +000078
Nico Huber710a38a2022-12-11 13:13:45 +010079HOSTPKG_CONFIG ?= pkg-config
80COREBOOT_EXPORTS += HOSTPKG_CONFIG
81
Patrick Georgi828e0e82015-04-04 15:50:20 +020082PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
83
Nico Huber7a1fbdb2017-08-23 23:48:13 +020084export $(COREBOOT_EXPORTS)
85
Patrick Georgi71b84802011-02-22 14:35:05 +000086all: real-all
87
Martin Roth4eea1742015-11-25 11:50:04 -070088help_coreboot help::
89 @echo '*** coreboot platform targets ***'
Martin Roth76f14b22015-11-18 13:09:23 -070090 @echo ' Use "make [target] V=1" for extra build debug information'
91 @echo ' all - Build coreboot'
92 @echo ' clean - Remove coreboot build artifacts'
93 @echo ' distclean - Remove build artifacts and config files'
Patrick Rudolphf6643212020-05-17 20:04:12 +020094 @echo ' sphinx - Build sphinx documentation for coreboot'
Nico Huberbfdefc22023-08-23 12:42:40 +020095 @echo ' sphinx-lint - Build sphinx documentation for coreboot with warnings as errors'
Martin Roth763e4932018-01-27 16:42:43 -070096 @echo ' filelist - Show files used in current build'
Martin Rotheedc14d2024-06-18 15:00:56 -060097 @echo ' printall - Print makefile info for debugging'
98 @echo ' gitconfig - Set up git to submit patches to coreboot'
99 @echo ' ctags / ctags-project - Make ctags file for all of coreboot or current board'
100 @echo ' cscope / cscope-project - Make cscope.out file for coreboot or current board'
101 @echo
102 @echo '*** site-local related targets ***'
103 @echo ' symlink - Create symbolic links from site-local into coreboot tree'
104 @echo ' clean-symlink - Remove symbolic links created by "make symlink"'
105 @echo ' cleanall-symlink - Remove all symbolic links in the coreboot tree'
Martin Roth76f14b22015-11-18 13:09:23 -0700106 @echo
107
Patrick Georgie38d0a62011-03-01 08:09:22 +0000108# This include must come _before_ the pattern rules below!
Patrick Georgi71b84802011-02-22 14:35:05 +0000109# Order _does_ matter for pattern rules.
Martin Rothe3df1842024-01-18 10:25:18 -0700110include $(srck)/Makefile.mk
Patrick Georgi71b84802011-02-22 14:35:05 +0000111
Martin Roth4d7285d2021-11-23 12:39:44 -0700112# The cases where we don't need fully populated $(obj) lists:
Patrick Georgicf036d12010-04-21 06:36:20 +0000113# 1. when no .config exists
Martin Roth4d7285d2021-11-23 12:39:44 -0700114# 2. When no $(obj)/util/kconfig/Makefile.real exists and we're building tools
115# 3. when make config (in any flavour) is run
116# 4. when make distclean is run
Patrick Georgicf036d12010-04-21 06:36:20 +0000117# Don't waste time on reading all Makefile.incs in these cases
Patrick Georgi0588d192009-08-12 15:00:51 +0000118ifeq ($(strip $(HAVE_DOTCONFIG)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000119NOCOMPILE:=1
120endif
Martin Roth4d7285d2021-11-23 12:39:44 -0700121ifeq ($(strip $(HAVE_KCONFIG_MAKEFILE_REAL)),)
122ifneq ($(MAKECMDGOALS),tools)
123NOCOMPILE:=1
124endif
125endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000126ifneq ($(MAKECMDGOALS),)
Elyes HAOUAS91fb1392020-01-20 15:33:11 +0100127ifneq ($(filter %config %clean cross% clang iasl lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000128NOCOMPILE:=1
129endif
Raul E Rangel5592cfd2019-07-23 11:13:40 -0600130ifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
Zheng Bao0fd93d62012-10-22 16:36:03 +0800131NOMKDIR:=1
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200132UNIT_TEST:=1
Zheng Bao0fd93d62012-10-22 16:36:03 +0800133endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000134endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000135
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200136ifneq ($(filter help%, $(MAKECMDGOALS)), )
137NOCOMPILE:=1
138UNIT_TEST:=1
139else
Paul Fagerburgde6cbac2021-05-11 09:56:48 -0600140ifneq ($(filter %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
141ifneq ($(filter-out %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
Jan Dabrosef1c9682020-03-28 00:15:03 +0100142$(error Cannot mix unit-tests targets with other targets)
143endif
144UNIT_TEST:=1
145NOCOMPILE:=
146endif
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200147endif
Jan Dabrosef1c9682020-03-28 00:15:03 +0100148
Martin Roth5ff6bf32024-02-22 16:23:20 -0700149# When building the "tools" target, the BUILD_ALL_TOOLS variable needs
150# to be set before reading the tools' Makefiles
151ifneq ($(filter tools, $(MAKECMDGOALS)), )
152BUILD_ALL_TOOLS:=1
153endif
154
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600155$(xcompile): util/xcompile/xcompile
Raul E Rangel6325ce22019-07-10 16:46:34 -0600156 rm -f $@
157 $< $(XGCCPATH) > $@.tmp
158 \mv -f $@.tmp $@ 2> /dev/null
159 rm -f $@.tmp
160
Patrick Georgicf036d12010-04-21 06:36:20 +0000161ifeq ($(NOCOMPILE),1)
Patrick Georgib351875f2020-07-06 15:31:58 +0000162# We also don't use .xcompile in the no-compile situations, so
163# provide some reasonable defaults.
164HOSTCC ?= $(if $(shell type gcc 2>/dev/null),gcc,cc)
165HOSTCXX ?= g++
166
Martin Rothe3df1842024-01-18 10:25:18 -0700167include $(TOPLEVEL)/Makefile.mk
168include $(TOPLEVEL)/payloads/Makefile.mk
169include $(TOPLEVEL)/util/testing/Makefile.mk
170-include $(TOPLEVEL)/site-local/Makefile.mk
Werner Zehb7f1c2d2019-10-04 07:01:13 +0200171-include $(TOPLEVEL)/site-local/Makefile.inc
Martin Rothe3df1842024-01-18 10:25:18 -0700172include $(TOPLEVEL)/tests/Makefile.mk
Martin Roth9fc96402022-11-27 19:04:16 -0700173printall real-all:
Martin Rothe28c7182022-06-22 17:49:31 -0600174 @echo "Error: Trying to build, but NOCOMPILE is set." >&2
175 @echo " Please file a bug with the following information:"
176 @echo "- MAKECMDGOALS: $(MAKECMDGOALS)" >&2
177 @echo "- HAVE_DOTCONFIG: $(HAVE_DOTCONFIG)" >&2
178 @echo "- HAVE_KCONFIG_MAKEFILE_REAL: $(HAVE_KCONFIG_MAKEFILE_REAL)" >&2
Martin Roth20aa0432017-01-26 10:51:43 -0700179 @exit 1
Martin Roth9fc96402022-11-27 19:04:16 -0700180
Patrick Georgi0588d192009-08-12 15:00:51 +0000181else
182
Jan Dabrosef1c9682020-03-28 00:15:03 +0100183ifneq ($(UNIT_TEST),1)
Paul Kocialkowski585c7812016-07-13 11:00:41 +0200184include $(DOTCONFIG)
Jan Dabrosef1c9682020-03-28 00:15:03 +0100185endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000186
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600187# The toolchain requires xcompile to determine the ARCH_SUPPORTED, so we can't
188# wait for make to generate the file.
189$(if $(wildcard $(xcompile)),, $(shell \
190 mkdir -p $(dir $(xcompile)) && \
191 util/xcompile/xcompile $(XGCCPATH) > $(xcompile) || rm -f $(xcompile)))
Patrick Georgi0ffef882017-01-19 23:20:14 +0100192
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600193include $(xcompile)
Patrick Georgi6dda31d2015-11-19 15:15:33 +0100194
195ifneq ($(XCOMPILE_COMPLETE),1)
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600196$(shell rm -f $(xcompile))
197$(error $(xcompile) deleted because it's invalid. \
Patrick Georgi6dda31d2015-11-19 15:15:33 +0100198 Restarting the build should fix that, or explain the problem)
199endif
Patrick Georgi7b9762f2015-06-04 13:18:11 +0200200
Patrick Georgica6e5ee2021-04-13 15:48:38 +0200201# reproducible builds
202LANG:=C
203LC_ALL:=C
204TZ:=UTC0
205ifneq ($(NOCOMPILE),1)
206SOURCE_DATE_EPOCH := $(shell $(top)/util/genbuild_h/genbuild_h.sh . | sed -n 's/^.define COREBOOT_BUILD_EPOCH\>.*"\(.*\)".*/\1/p')
207endif
208# don't use COREBOOT_EXPORTS to ensure build steps outside the coreboot build system
209# are reproducible
210export LANG LC_ALL TZ SOURCE_DATE_EPOCH
211
Jan Dabrosef1c9682020-03-28 00:15:03 +0100212ifneq ($(UNIT_TEST),1)
Martin Rothe3df1842024-01-18 10:25:18 -0700213include toolchain.mk
Jan Dabrosef1c9682020-03-28 00:15:03 +0100214endif
Patrick Georgicc84a002014-05-14 21:05:35 +0200215
Zheng Bao07648922015-11-13 10:42:27 +0800216strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
Martin Rothbbf13992016-01-25 15:59:24 -0700217# fix makefile syntax highlighting after strip macro \" "))
Patrick Georgia84e98b2010-03-16 19:01:32 +0000218
Kyösti Mälkkicad92ec2022-12-14 17:26:35 +0200219ifneq ($(NOCOMPILE),1)
220$(shell rm -f $(CCACHE_STATSLOG))
221endif
222
Patrick Georgi0588d192009-08-12 15:00:51 +0000223# The primary target needs to be here before we include the
224# other files
225
Patrick Georgi71b84802011-02-22 14:35:05 +0000226real-all: real-target
Patrick Georgi0588d192009-08-12 15:00:51 +0000227
Patrick Georgi51e142f2010-03-27 17:18:39 +0000228# must come rather early
Raul E Rangeldd6efce2022-02-25 17:03:10 -0700229.SECONDARY:
Patrick Georgi51e142f2010-03-27 17:18:39 +0000230.SECONDEXPANSION:
Raul E Rangelcc6dc902018-08-06 16:13:32 -0600231.DELETE_ON_ERROR:
Patrick Georgi51e142f2010-03-27 17:18:39 +0000232
Jonathan Neuschäferd2c02422018-12-11 13:06:40 +0100233$(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
Patrick Georgi53ea1d42019-11-22 16:55:58 +0100234 $(MAKE) olddefconfig
235 $(MAKE) syncconfig
Patrick Georgi0588d192009-08-12 15:00:51 +0000236
Nico Huber533bc0a2019-01-01 19:03:33 +0100237$(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
238 true
239
Nico Hubereafc8152019-10-25 12:47:14 +0200240$(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
Nico Huber533bc0a2019-01-01 19:03:33 +0100241 $(objutil)/kconfig/toada CB.Config <$< >$@
242
Nico Huberb5679772019-01-01 22:06:01 +0100243$(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
244 cp $< $@
245
Patrick Georgi58262652011-02-17 20:47:49 +0000246# Add a new class of source/object files to the build system
247add-class= \
248 $(eval $(1)-srcs:=) \
249 $(eval $(1)-objs:=) \
250 $(eval classes+=$(1))
Patrick Georgi8463dd92010-09-30 16:55:02 +0000251
Patrick Georgi58262652011-02-17 20:47:49 +0000252# Special classes are managed types with special behaviour
253# On parse time, for each entry in variable $(1)-y
254# a handler $(1)-handler is executed with the arguments:
255# * $(1): directory the parser is in
256# * $(2): current entry
257add-special-class= \
258 $(eval $(1):=) \
259 $(eval special-classes+=$(1))
260
Nico Huber81b09f42016-01-23 00:50:00 +0100261# Converts one or more source file paths to their corresponding build/ paths.
Nico Huber2e09d2b2016-01-14 01:13:33 +0100262# Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
263# their name.
Nico Huber81b09f42016-01-23 00:50:00 +0100264# $1 stage name
265# $2 file path (list)
Nico Huber98fc4262016-01-23 01:24:33 +0100266src-to-obj=\
267 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
268 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200269 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber98fc4262016-01-23 01:24:33 +0100270 $(patsubst src/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100271 $(patsubst %.ads,%.o,\
272 $(patsubst %.adb,%.o,\
Nico Huber98fc4262016-01-23 01:24:33 +0100273 $(patsubst %.c,%.o,\
274 $(patsubst %.S,%.o,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200275 $(subst .$(1),,$(2))))))))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100276
277# Converts one or more source file paths to the corresponding build/ paths
278# of their Ada library information (.ali) files.
279# $1 stage name
280# $2 file path (list)
281src-to-ali=\
282 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
283 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200284 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100285 $(patsubst src/%,$(obj)/%,\
286 $(patsubst %.ads,%.ali,\
287 $(patsubst %.adb,%.ali,\
288 $(subst .$(1),,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200289 $(filter %.ads %.adb,$(2)))))))))
Nico Huber81b09f42016-01-23 00:50:00 +0100290
Martin Rothe3df1842024-01-18 10:25:18 -0700291# Clean -y variables, include Makefile.mk & Makefile.inc
Patrick Georgi8463dd92010-09-30 16:55:02 +0000292# Add paths to files in X-y to X-srcs
Patrick Georgi47d68d82010-03-06 21:18:43 +0000293# Add subdirs-y to subdirs
294includemakefiles= \
Nikolai Vyssotskib9d00722022-09-24 08:48:15 -0500295 $(if $(wildcard $(1)), \
296 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
297 $(eval -include $(1)) \
298 $(foreach class,$(classes-y), $(call add-class,$(class))) \
299 $(foreach special,$(special-classes), \
300 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
301 $(foreach class,$(classes), \
302 $(eval $(class)-srcs+= \
303 $$(subst $(absobj)/,$(obj)/, \
304 $$(subst $(top)/,, \
305 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
306 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))))
Patrick Georgi47d68d82010-03-06 21:18:43 +0000307
Patrick Georgi8463dd92010-09-30 16:55:02 +0000308# For each path in $(subdirs) call includemakefiles
Patrick Georgi47d68d82010-03-06 21:18:43 +0000309# Repeat until subdirs is empty
Martin Rothe3df1842024-01-18 10:25:18 -0700310# TODO: Remove Makefile.inc support
Patrick Georgi47d68d82010-03-06 21:18:43 +0000311evaluate_subdirs= \
312 $(eval cursubdirs:=$(subdirs)) \
313 $(eval subdirs:=) \
314 $(foreach dir,$(cursubdirs), \
Martin Rothe3df1842024-01-18 10:25:18 -0700315 $(eval $(call includemakefiles,$(dir)/Makefile.mk))) \
316 $(foreach dir,$(cursubdirs), \
Patrick Georgi58262652011-02-17 20:47:49 +0000317 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000318 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000319
320# collect all object files eligible for building
Patrick Georgie38d0a62011-03-01 08:09:22 +0000321subdirs:=$(TOPLEVEL)
Julius Wernere91d1702017-03-20 15:32:15 -0700322postinclude-hooks :=
Jan Dabrosef1c9682020-03-28 00:15:03 +0100323
Martin Rothe3df1842024-01-18 10:25:18 -0700324# Don't iterate through Makefiles under src/ when building tests
Jan Dabrosef1c9682020-03-28 00:15:03 +0100325ifneq ($(UNIT_TEST),1)
Patrick Georgi51e142f2010-03-27 17:18:39 +0000326$(eval $(call evaluate_subdirs))
Jan Dabrosef1c9682020-03-28 00:15:03 +0100327else
Martin Rothe3df1842024-01-18 10:25:18 -0700328include $(TOPLEVEL)/tests/Makefile.mk
Jan Dabrosef1c9682020-03-28 00:15:03 +0100329endif
330
Patrick Georgi70c85ea2013-02-16 01:06:57 +0100331ifeq ($(FAILBUILD),1)
332$(error cannot continue build)
333endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000334
Julius Wernere91d1702017-03-20 15:32:15 -0700335# Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
336$(eval $(postinclude-hooks))
337
Patrick Georgi94a45862011-10-25 14:32:21 -0700338# Eliminate duplicate mentions of source files in a class
339$(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
340
Martin Rothb18726d2023-08-15 15:57:29 -0600341ifeq ($(CONFIG_IWYU),y)
342MAKEFLAGS += -k
343SAVE_IWYU_OUTPUT := 2>&1 | grep "should\|\#include\|---\|include-list\|^[[:blank:]]\?\'" | tee -a $$(obj)/iwyu.txt
344endif
345
Nico Huberb5679772019-01-01 22:06:01 +0100346# Build Kconfig .ads if necessary
Jeremy Compostellafa838872022-11-30 19:26:01 -0700347ifeq ($(CONFIG_ROMSTAGE_ADA),y)
348romstage-srcs += $(obj)/romstage/$(notdir $(KCONFIG_AUTOADS))
349endif
Nico Huberb5679772019-01-01 22:06:01 +0100350ifeq ($(CONFIG_RAMSTAGE_ADA),y)
351ramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
352endif
353
Nico Huber2e09d2b2016-01-14 01:13:33 +0100354# To track dependencies, we need all Ada specification (.ads) files in
355# *-srcs. Extract / filter all specification files that have a matching
356# body (.adb) file here (specifications without a body are valid sources
357# in Ada).
358$(foreach class,$(classes),$(eval $(class)-extra-specs := \
359 $(filter \
360 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
361 $(filter %.ads,$($(class)-srcs)))))
362$(foreach class,$(classes),$(eval $(class)-srcs := \
363 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
364
Patrick Georgi10f86b02015-03-27 16:56:23 +0100365$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100366$(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
367
368# For Ada includes
369$(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
Patrick Georgid3428b02010-02-24 13:18:01 +0000370
Patrick Georgi79f90102012-11-25 14:31:08 +0100371# Call post-processors if they're defined
372$(foreach class,$(classes),\
373 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
374
Patrick Georgi58262652011-02-17 20:47:49 +0000375allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
376allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000377alldirs:=$(sort $(abspath $(dir $(allobjs))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000378
Nico Huber2e09d2b2016-01-14 01:13:33 +0100379# Reads dependencies from an Ada library information (.ali) file
380# Only basenames (with suffix) are preserved so we have to look the
381# paths up in $($(stage)-srcs).
382# $1 stage name
383# $2 ali file
384create_ada_deps=$$(if $(2),\
385 gnat.adc \
386 $$(filter \
387 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
388 $$($(1)-srcs) $$($(1)-extra-specs)))
389
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000390# macro to define template macros that are used by use_template macro
391define create_cc_template
Patrick Georgi71b84802011-02-22 14:35:05 +0000392# $1 obj class
Patrick Georgi990e7c92015-04-03 10:47:15 +0200393# $2 source suffix (c, S, ld, ...)
Marc Jonesa38ccfd2014-11-06 15:50:22 -0700394# $3 additional compiler flags
395# $4 additional dependencies
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000396ifn$(EMPTY)def $(1)-objs_$(2)_template
Patrick Georgi8463dd92010-09-30 16:55:02 +0000397de$(EMPTY)fine $(1)-objs_$(2)_template
Nico Huber1850aa62017-09-03 23:42:58 +0200398ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
Nico Huberb5679772019-01-01 22:06:01 +0100399$$(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 +0200400 @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
401 $(GCC_$(1)) \
402 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
403 $(3) -c -o $$$$@ $$$$<
404el$(EMPTY)se
405$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000406 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
Nico Huber2e09d2b2016-01-14 01:13:33 +0100407 $(CC_$(1)) \
Nico Huber1850aa62017-09-03 23:42:58 +0200408 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
Martin Rothb18726d2023-08-15 15:57:29 -0600409 $(3) -c -o $$$$@ $$$$< $(SAVE_IWYU_OUTPUT)
Nico Huber1850aa62017-09-03 23:42:58 +0200410end$(EMPTY)if
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000411en$(EMPTY)def
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000412end$(EMPTY)if
Patrick Georgi0588d192009-08-12 15:00:51 +0000413endef
414
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000415filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
416$(foreach class,$(classes), \
417 $(foreach type,$(call filetypes-of-class,$(class)), \
Patrick Georgi2459aee2015-03-27 15:27:21 +0100418 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
Patrick Georgi416ab382015-04-03 10:19:38 +0200419 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
420 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000421
Patrick Georgid69839b2015-04-03 10:32:17 +0200422foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
Patrick Georgi58262652011-02-17 20:47:49 +0000423$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000424
Nico Huber2e09d2b2016-01-14 01:13:33 +0100425# To supported complex package initializations, we need to call the
426# emitted code explicitly. gnatbind gathers all the calls for us
427# and exports them as a procedure $(stage)_adainit(). Every stage that
428# uses Ada code has to call it!
429define gnatbind_template
430# $1 class
431$$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
432 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
433 # We have to give gnatbind a simple filename (without leading
434 # path components) so just cd there.
435 cd $$(dir $$@) && \
436 $$(GNATBIND_$(1)) -a -n \
Nico Huberbe5492a2015-09-29 16:41:19 +0200437 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100438 -L$(1)_ada -o $$(notdir $$@) \
439 $$(subst $$(dir $$@),,$$^)
440$$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
Nico Huber1850aa62017-09-03 23:42:58 +0200441 @printf " GCC $$(subst $$(obj)/,,$$@)\n"
442 $(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
Nico Huber2e09d2b2016-01-14 01:13:33 +0100443$(1)-objs += $$(obj)/$(1)/b__$(1).o
Nico Huberddb24652016-09-19 11:50:04 +0200444$($(1)-alis): %.ali: %.o ;
Nico Huber2e09d2b2016-01-14 01:13:33 +0100445endef
446
Nico Huberbe5492a2015-09-29 16:41:19 +0200447$(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100448 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
449
Julius Wernerf97b88b2014-12-05 12:32:09 -0800450DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000451-include $(DEPENDENCIES)
452
Patrick Georgi0588d192009-08-12 15:00:51 +0000453printall:
Martin Roth09b64442016-06-05 10:52:43 -0600454 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
455 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
456 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
457 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
458 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
Patrick Georgi0588d192009-08-12 15:00:51 +0000459endif
460
Patrick Georgi40ad8422011-05-21 22:18:59 +0000461ifndef NOMKDIR
Stefan Reinauerde60c882015-06-29 14:44:37 -0700462$(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
Patrick Georgi40ad8422011-05-21 22:18:59 +0000463endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000464
Martin Roth9b0204d2017-09-18 09:25:18 -0600465$(obj)/project_filelist.txt:
466 if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
467 echo "*** Error: Project must be built before generating file list ***"; \
468 exit 1; \
469 fi
Maximilian Brunec36b70c2022-12-26 00:29:49 +0100470 find $(obj) -path "$(obj)/util" -prune -o -path "$(obj)/external" -prune -o -name "*.d" -exec cat {} \; | \
Martin Roth8a027272017-09-26 09:53:30 -0600471 sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
Martin Roth9c1b33e2015-07-29 14:55:18 -0700472 grep -v '\.o$$' > $(obj)/project_filelist.txt
473
Martin Roth9b0204d2017-09-18 09:25:18 -0600474filelist: $(obj)/project_filelist.txt
Martin Rotha18353d2017-06-06 06:44:46 -0600475 printf "\nFiles used in build:\n"
476 cat $(obj)/project_filelist.txt
477
Martin Roth9c1b33e2015-07-29 14:55:18 -0700478#works with either exuberant ctags or ctags.emacs
479ctags-project: clean-ctags $(obj)/project_filelist.txt
480 cat $(obj)/project_filelist.txt | \
481 xargs ctags -o tags
482
483cscope-project: clean-cscope $(obj)/project_filelist.txt
484 cat $(obj)/project_filelist.txt | xargs cscope -b
485
Warren Turkala9fc3302010-09-03 08:57:32 +0000486cscope:
487 cscope -bR
488
Patrick Rudolphf6643212020-05-17 20:04:12 +0200489sphinx:
Nico Huber4f014832023-08-23 12:41:01 +0200490 $(MAKE) -C Documentation sphinx
Patrick Rudolphf6643212020-05-17 20:04:12 +0200491
492sphinx-lint:
Nico Huber4f014832023-08-23 12:41:01 +0200493 $(MAKE) SPHINXOPTS=-W -C Documentation sphinx
Patrick Rudolphf6643212020-05-17 20:04:12 +0200494
Martin Roth754fa0e2024-06-18 14:30:09 -0600495# Look at all of the files in the SYMLINK_LIST and create the symbolic links
496# into the coreboot tree. Each symlink.txt file in site-local should be in the
497# directory linked from and have a single line with the path to the location to
498# link to. The path must be relative to the top of the coreboot directory.
Christian Waltera8c10c82022-07-01 11:12:25 +0200499symlink:
Martin Roth754fa0e2024-06-18 14:30:09 -0600500 if [ -z "$(SYMLINK_LIST)" ]; then \
501 echo "No site-local symbolic links to create."; \
502 exit 0; \
503 fi; \
504 echo "Creating symbolic links.."; \
Christian Waltera8c10c82022-07-01 11:12:25 +0200505 for link in $(SYMLINK_LIST); do \
Martin Roth754fa0e2024-06-18 14:30:09 -0600506 LINKTO="$(top)/$$(head -n 1 "$${link}")"; \
507 LINKFROM=$$(dirname "$$(realpath "$${link}")"); \
508 if [ -L "$${LINKTO}" ]; then \
509 echo " $${LINKTO} exists - skipping"; \
Christian Waltera8c10c82022-07-01 11:12:25 +0200510 continue; \
Martin Roth754fa0e2024-06-18 14:30:09 -0600511 fi; \
512 LINKTO="$$(realpath -m "$${LINKTO}")" 2>/dev/null; \
513 if [ "$${LINKTO}" = "$$(echo "$${LINKTO}" | sed "s|^$(top)||" )" ]; then \
514 echo " FAILED: $${LINKTO} is outside of current directory." >&2; \
515 continue; \
516 fi; \
517 if [ ! -e "$${LINKTO}" ]; then \
518 echo " LINK $${LINKTO} -> $${LINKFROM}"; \
519 ln -s "$${LINKFROM}" "$${LINKTO}" || \
520 echo "FAILED: Could not create link." >&2; \
Christian Waltera8c10c82022-07-01 11:12:25 +0200521 else \
Martin Roth754fa0e2024-06-18 14:30:09 -0600522 echo " FAILED: $${LINKTO} exists as a file or directory." >&2; \
523 fi; \
Christian Waltera8c10c82022-07-01 11:12:25 +0200524 done
525
526clean-symlink:
Martin Rothebf6b3c2024-06-18 14:50:23 -0600527 if [ -z "$(SYMLINK_LIST)" ]; then \
528 echo "No site-local symbolic links to clean."; \
529 exit 0; \
530 fi; \
531 echo "Removing site-local symbolic links from tree.."; \
532 for link in $(SYMLINK_LIST); do \
533 SYMLINK="$(top)/$$(head -n 1 "$${link}")"; \
534 if [ "$${SYMLINK}" = "$$(echo "$${SYMLINK}" | sed "s|^$(top)||")" ]; then \
535 echo " FAILED: $${SYMLINK} is outside of current directory." >&2; \
536 continue; \
537 elif [ ! -L "$${SYMLINK}" ]; then \
538 echo " $${SYMLINK} does not exist - skipping"; \
539 continue; \
540 fi; \
541 if [ -L "$${SYMLINK}" ]; then \
542 REALDIR="$$(realpath "$${link}")"; \
543 echo " UNLINK $${link} (linked from $${REALDIR})"; \
544 rm "$${SYMLINK}"; \
545 fi; \
546 done; \
547 EXISTING_SYMLINKS="$$(find $(top) -type l | grep -v "3rdparty\|crossgcc" )"; \
548 if [ -z "$${EXISTING_SYMLINKS}" ]; then \
549 echo " No remaining symbolic links found in tree."; \
550 else \
551 echo " Remaining symbolic links found:"; \
552 for link in $${EXISTING_SYMLINKS}; do \
553 echo " $${link}"; \
554 done; \
555 fi
Martin Rothd5658fd2024-06-18 14:44:36 -0600556
557cleanall-symlink:
558 echo "Deleting all symbolic links in the coreboot tree (excluding 3rdparty & crossgcc)"; \
559 EXISTING_SYMLINKS="$$(find $(top) -type l | grep -v "3rdparty\|crossgcc" )"; \
560 for link in $${EXISTING_SYMLINKS}; do \
561 if [ -L "$${link}" ]; then \
562 REALDIR="$$(realpath "$${link}")"; \
563 echo " UNLINK $${link} (linked from $${REALDIR})"; \
564 rm "$${link}"; \
565 fi; \
Christian Waltera8c10c82022-07-01 11:12:25 +0200566 done
567
Martin Roth619086d2022-05-09 18:48:24 -0600568clean-for-update:
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100569 rm -rf $(obj) .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000570
Arthur Heymansf91366f2022-03-25 16:01:05 +0100571clean: clean-for-update clean-utils clean-payloads
Patrick Georgi71b84802011-02-22 14:35:05 +0000572 rm -f .ccwrap
Warren Turkal0e8f2042010-09-27 21:14:19 +0000573
Warren Turkala9fc3302010-09-03 08:57:32 +0000574clean-cscope:
575 rm -f cscope.out
576
Martin Roth9c1b33e2015-07-29 14:55:18 -0700577clean-ctags:
578 rm -f tags
579
Martin Roth20cd54f2017-03-26 18:49:02 -0600580clean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600581 $(foreach tool, $(TOOLLIST), \
582 $(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
Martin Roth20cd54f2017-03-26 18:49:02 -0600583
584distclean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600585 $(foreach tool, $(TOOLLIST), \
586 $(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
Martin Roth20cd54f2017-03-26 18:49:02 -0600587 rm -f /util/$(tool)/junit.xml;)
588
589distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
Patrick Georgi80656af2017-04-26 11:58:44 +0200590 rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
Martin Roth20cd54f2017-03-26 18:49:02 -0600591 rm -rf coreboot-builds coreboot-builds-chromeos
592 rm -f abuild*.xml junit.xml* util/lint/junit.xml
Patrick Georgi0588d192009-08-12 15:00:51 +0000593
Martin Roth619086d2022-05-09 18:48:24 -0600594.PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean sphinx sphinx-lint
Martin Rothd5658fd2024-06-18 14:44:36 -0600595.PHONY: ctags-project cscope-project clean-ctags
596.PHONY: symlink clean-symlink cleanall-symlink