blob: fddcc5c55df21185606916e12597100051ad8c19 [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 Roth76f14b22015-11-18 13:09:23 -070097 @echo ' printall - print makefile info for debugging'
Werner Zeh2de64102016-01-12 12:45:49 +010098 @echo ' gitconfig - set up git to submit patches to coreboot'
Martin Roth76f14b22015-11-18 13:09:23 -070099 @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
Patrick Georgie38d0a62011-03-01 08:09:22 +0000103# This include must come _before_ the pattern rules below!
Patrick Georgi71b84802011-02-22 14:35:05 +0000104# Order _does_ matter for pattern rules.
Martin Rothe3df1842024-01-18 10:25:18 -0700105include $(srck)/Makefile.mk
Patrick Georgi71b84802011-02-22 14:35:05 +0000106
Martin Roth4d7285d2021-11-23 12:39:44 -0700107# The cases where we don't need fully populated $(obj) lists:
Patrick Georgicf036d12010-04-21 06:36:20 +0000108# 1. when no .config exists
Martin Roth4d7285d2021-11-23 12:39:44 -0700109# 2. When no $(obj)/util/kconfig/Makefile.real exists and we're building tools
110# 3. when make config (in any flavour) is run
111# 4. when make distclean is run
Patrick Georgicf036d12010-04-21 06:36:20 +0000112# Don't waste time on reading all Makefile.incs in these cases
Patrick Georgi0588d192009-08-12 15:00:51 +0000113ifeq ($(strip $(HAVE_DOTCONFIG)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000114NOCOMPILE:=1
115endif
Martin Roth4d7285d2021-11-23 12:39:44 -0700116ifeq ($(strip $(HAVE_KCONFIG_MAKEFILE_REAL)),)
117ifneq ($(MAKECMDGOALS),tools)
118NOCOMPILE:=1
119endif
120endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000121ifneq ($(MAKECMDGOALS),)
Elyes HAOUAS91fb1392020-01-20 15:33:11 +0100122ifneq ($(filter %config %clean cross% clang iasl lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000123NOCOMPILE:=1
124endif
Raul E Rangel5592cfd2019-07-23 11:13:40 -0600125ifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
Zheng Bao0fd93d62012-10-22 16:36:03 +0800126NOMKDIR:=1
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200127UNIT_TEST:=1
Zheng Bao0fd93d62012-10-22 16:36:03 +0800128endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000129endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000130
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200131ifneq ($(filter help%, $(MAKECMDGOALS)), )
132NOCOMPILE:=1
133UNIT_TEST:=1
134else
Paul Fagerburgde6cbac2021-05-11 09:56:48 -0600135ifneq ($(filter %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
136ifneq ($(filter-out %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
Jan Dabrosef1c9682020-03-28 00:15:03 +0100137$(error Cannot mix unit-tests targets with other targets)
138endif
139UNIT_TEST:=1
140NOCOMPILE:=
141endif
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200142endif
Jan Dabrosef1c9682020-03-28 00:15:03 +0100143
Martin Roth5ff6bf32024-02-22 16:23:20 -0700144# When building the "tools" target, the BUILD_ALL_TOOLS variable needs
145# to be set before reading the tools' Makefiles
146ifneq ($(filter tools, $(MAKECMDGOALS)), )
147BUILD_ALL_TOOLS:=1
148endif
149
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600150$(xcompile): util/xcompile/xcompile
Raul E Rangel6325ce22019-07-10 16:46:34 -0600151 rm -f $@
152 $< $(XGCCPATH) > $@.tmp
153 \mv -f $@.tmp $@ 2> /dev/null
154 rm -f $@.tmp
155
Patrick Georgicf036d12010-04-21 06:36:20 +0000156ifeq ($(NOCOMPILE),1)
Patrick Georgib351875f2020-07-06 15:31:58 +0000157# We also don't use .xcompile in the no-compile situations, so
158# provide some reasonable defaults.
159HOSTCC ?= $(if $(shell type gcc 2>/dev/null),gcc,cc)
160HOSTCXX ?= g++
161
Martin Rothe3df1842024-01-18 10:25:18 -0700162include $(TOPLEVEL)/Makefile.mk
163include $(TOPLEVEL)/payloads/Makefile.mk
164include $(TOPLEVEL)/util/testing/Makefile.mk
165-include $(TOPLEVEL)/site-local/Makefile.mk
Werner Zehb7f1c2d2019-10-04 07:01:13 +0200166-include $(TOPLEVEL)/site-local/Makefile.inc
Martin Rothe3df1842024-01-18 10:25:18 -0700167include $(TOPLEVEL)/tests/Makefile.mk
Martin Roth9fc96402022-11-27 19:04:16 -0700168printall real-all:
Martin Rothe28c7182022-06-22 17:49:31 -0600169 @echo "Error: Trying to build, but NOCOMPILE is set." >&2
170 @echo " Please file a bug with the following information:"
171 @echo "- MAKECMDGOALS: $(MAKECMDGOALS)" >&2
172 @echo "- HAVE_DOTCONFIG: $(HAVE_DOTCONFIG)" >&2
173 @echo "- HAVE_KCONFIG_MAKEFILE_REAL: $(HAVE_KCONFIG_MAKEFILE_REAL)" >&2
Martin Roth20aa0432017-01-26 10:51:43 -0700174 @exit 1
Martin Roth9fc96402022-11-27 19:04:16 -0700175
Patrick Georgi0588d192009-08-12 15:00:51 +0000176else
177
Jan Dabrosef1c9682020-03-28 00:15:03 +0100178ifneq ($(UNIT_TEST),1)
Paul Kocialkowski585c7812016-07-13 11:00:41 +0200179include $(DOTCONFIG)
Jan Dabrosef1c9682020-03-28 00:15:03 +0100180endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000181
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600182# The toolchain requires xcompile to determine the ARCH_SUPPORTED, so we can't
183# wait for make to generate the file.
184$(if $(wildcard $(xcompile)),, $(shell \
185 mkdir -p $(dir $(xcompile)) && \
186 util/xcompile/xcompile $(XGCCPATH) > $(xcompile) || rm -f $(xcompile)))
Patrick Georgi0ffef882017-01-19 23:20:14 +0100187
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600188include $(xcompile)
Patrick Georgi6dda31d2015-11-19 15:15:33 +0100189
190ifneq ($(XCOMPILE_COMPLETE),1)
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600191$(shell rm -f $(xcompile))
192$(error $(xcompile) deleted because it's invalid. \
Patrick Georgi6dda31d2015-11-19 15:15:33 +0100193 Restarting the build should fix that, or explain the problem)
194endif
Patrick Georgi7b9762f2015-06-04 13:18:11 +0200195
Patrick Georgica6e5ee2021-04-13 15:48:38 +0200196# reproducible builds
197LANG:=C
198LC_ALL:=C
199TZ:=UTC0
200ifneq ($(NOCOMPILE),1)
201SOURCE_DATE_EPOCH := $(shell $(top)/util/genbuild_h/genbuild_h.sh . | sed -n 's/^.define COREBOOT_BUILD_EPOCH\>.*"\(.*\)".*/\1/p')
202endif
203# don't use COREBOOT_EXPORTS to ensure build steps outside the coreboot build system
204# are reproducible
205export LANG LC_ALL TZ SOURCE_DATE_EPOCH
206
Jan Dabrosef1c9682020-03-28 00:15:03 +0100207ifneq ($(UNIT_TEST),1)
Martin Rothe3df1842024-01-18 10:25:18 -0700208include toolchain.mk
Jan Dabrosef1c9682020-03-28 00:15:03 +0100209endif
Patrick Georgicc84a002014-05-14 21:05:35 +0200210
Zheng Bao07648922015-11-13 10:42:27 +0800211strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
Martin Rothbbf13992016-01-25 15:59:24 -0700212# fix makefile syntax highlighting after strip macro \" "))
Patrick Georgia84e98b2010-03-16 19:01:32 +0000213
Kyösti Mälkkicad92ec2022-12-14 17:26:35 +0200214ifneq ($(NOCOMPILE),1)
215$(shell rm -f $(CCACHE_STATSLOG))
216endif
217
Patrick Georgi0588d192009-08-12 15:00:51 +0000218# The primary target needs to be here before we include the
219# other files
220
Patrick Georgi71b84802011-02-22 14:35:05 +0000221real-all: real-target
Patrick Georgi0588d192009-08-12 15:00:51 +0000222
Patrick Georgi51e142f2010-03-27 17:18:39 +0000223# must come rather early
Raul E Rangeldd6efce2022-02-25 17:03:10 -0700224.SECONDARY:
Patrick Georgi51e142f2010-03-27 17:18:39 +0000225.SECONDEXPANSION:
Raul E Rangelcc6dc902018-08-06 16:13:32 -0600226.DELETE_ON_ERROR:
Patrick Georgi51e142f2010-03-27 17:18:39 +0000227
Jonathan Neuschäferd2c02422018-12-11 13:06:40 +0100228$(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
Patrick Georgi53ea1d42019-11-22 16:55:58 +0100229 $(MAKE) olddefconfig
230 $(MAKE) syncconfig
Patrick Georgi0588d192009-08-12 15:00:51 +0000231
Nico Huber533bc0a2019-01-01 19:03:33 +0100232$(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
233 true
234
Nico Hubereafc8152019-10-25 12:47:14 +0200235$(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
Nico Huber533bc0a2019-01-01 19:03:33 +0100236 $(objutil)/kconfig/toada CB.Config <$< >$@
237
Nico Huberb5679772019-01-01 22:06:01 +0100238$(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
239 cp $< $@
240
Patrick Georgi58262652011-02-17 20:47:49 +0000241# Add a new class of source/object files to the build system
242add-class= \
243 $(eval $(1)-srcs:=) \
244 $(eval $(1)-objs:=) \
245 $(eval classes+=$(1))
Patrick Georgi8463dd92010-09-30 16:55:02 +0000246
Patrick Georgi58262652011-02-17 20:47:49 +0000247# Special classes are managed types with special behaviour
248# On parse time, for each entry in variable $(1)-y
249# a handler $(1)-handler is executed with the arguments:
250# * $(1): directory the parser is in
251# * $(2): current entry
252add-special-class= \
253 $(eval $(1):=) \
254 $(eval special-classes+=$(1))
255
Nico Huber81b09f42016-01-23 00:50:00 +0100256# Converts one or more source file paths to their corresponding build/ paths.
Nico Huber2e09d2b2016-01-14 01:13:33 +0100257# Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
258# their name.
Nico Huber81b09f42016-01-23 00:50:00 +0100259# $1 stage name
260# $2 file path (list)
Nico Huber98fc4262016-01-23 01:24:33 +0100261src-to-obj=\
262 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
263 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200264 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber98fc4262016-01-23 01:24:33 +0100265 $(patsubst src/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100266 $(patsubst %.ads,%.o,\
267 $(patsubst %.adb,%.o,\
Nico Huber98fc4262016-01-23 01:24:33 +0100268 $(patsubst %.c,%.o,\
269 $(patsubst %.S,%.o,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200270 $(subst .$(1),,$(2))))))))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100271
272# Converts one or more source file paths to the corresponding build/ paths
273# of their Ada library information (.ali) files.
274# $1 stage name
275# $2 file path (list)
276src-to-ali=\
277 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
278 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200279 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100280 $(patsubst src/%,$(obj)/%,\
281 $(patsubst %.ads,%.ali,\
282 $(patsubst %.adb,%.ali,\
283 $(subst .$(1),,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200284 $(filter %.ads %.adb,$(2)))))))))
Nico Huber81b09f42016-01-23 00:50:00 +0100285
Martin Rothe3df1842024-01-18 10:25:18 -0700286# Clean -y variables, include Makefile.mk & Makefile.inc
Patrick Georgi8463dd92010-09-30 16:55:02 +0000287# Add paths to files in X-y to X-srcs
Patrick Georgi47d68d82010-03-06 21:18:43 +0000288# Add subdirs-y to subdirs
289includemakefiles= \
Nikolai Vyssotskib9d00722022-09-24 08:48:15 -0500290 $(if $(wildcard $(1)), \
291 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
292 $(eval -include $(1)) \
293 $(foreach class,$(classes-y), $(call add-class,$(class))) \
294 $(foreach special,$(special-classes), \
295 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
296 $(foreach class,$(classes), \
297 $(eval $(class)-srcs+= \
298 $$(subst $(absobj)/,$(obj)/, \
299 $$(subst $(top)/,, \
300 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
301 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))))
Patrick Georgi47d68d82010-03-06 21:18:43 +0000302
Patrick Georgi8463dd92010-09-30 16:55:02 +0000303# For each path in $(subdirs) call includemakefiles
Patrick Georgi47d68d82010-03-06 21:18:43 +0000304# Repeat until subdirs is empty
Martin Rothe3df1842024-01-18 10:25:18 -0700305# TODO: Remove Makefile.inc support
Patrick Georgi47d68d82010-03-06 21:18:43 +0000306evaluate_subdirs= \
307 $(eval cursubdirs:=$(subdirs)) \
308 $(eval subdirs:=) \
309 $(foreach dir,$(cursubdirs), \
Martin Rothe3df1842024-01-18 10:25:18 -0700310 $(eval $(call includemakefiles,$(dir)/Makefile.mk))) \
311 $(foreach dir,$(cursubdirs), \
Patrick Georgi58262652011-02-17 20:47:49 +0000312 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000313 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000314
315# collect all object files eligible for building
Patrick Georgie38d0a62011-03-01 08:09:22 +0000316subdirs:=$(TOPLEVEL)
Julius Wernere91d1702017-03-20 15:32:15 -0700317postinclude-hooks :=
Jan Dabrosef1c9682020-03-28 00:15:03 +0100318
Martin Rothe3df1842024-01-18 10:25:18 -0700319# Don't iterate through Makefiles under src/ when building tests
Jan Dabrosef1c9682020-03-28 00:15:03 +0100320ifneq ($(UNIT_TEST),1)
Patrick Georgi51e142f2010-03-27 17:18:39 +0000321$(eval $(call evaluate_subdirs))
Jan Dabrosef1c9682020-03-28 00:15:03 +0100322else
Martin Rothe3df1842024-01-18 10:25:18 -0700323include $(TOPLEVEL)/tests/Makefile.mk
Jan Dabrosef1c9682020-03-28 00:15:03 +0100324endif
325
Patrick Georgi70c85ea2013-02-16 01:06:57 +0100326ifeq ($(FAILBUILD),1)
327$(error cannot continue build)
328endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000329
Julius Wernere91d1702017-03-20 15:32:15 -0700330# Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
331$(eval $(postinclude-hooks))
332
Patrick Georgi94a45862011-10-25 14:32:21 -0700333# Eliminate duplicate mentions of source files in a class
334$(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
335
Martin Rothb18726d2023-08-15 15:57:29 -0600336ifeq ($(CONFIG_IWYU),y)
337MAKEFLAGS += -k
338SAVE_IWYU_OUTPUT := 2>&1 | grep "should\|\#include\|---\|include-list\|^[[:blank:]]\?\'" | tee -a $$(obj)/iwyu.txt
339endif
340
Nico Huberb5679772019-01-01 22:06:01 +0100341# Build Kconfig .ads if necessary
Jeremy Compostellafa838872022-11-30 19:26:01 -0700342ifeq ($(CONFIG_ROMSTAGE_ADA),y)
343romstage-srcs += $(obj)/romstage/$(notdir $(KCONFIG_AUTOADS))
344endif
Nico Huberb5679772019-01-01 22:06:01 +0100345ifeq ($(CONFIG_RAMSTAGE_ADA),y)
346ramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
347endif
348
Nico Huber2e09d2b2016-01-14 01:13:33 +0100349# To track dependencies, we need all Ada specification (.ads) files in
350# *-srcs. Extract / filter all specification files that have a matching
351# body (.adb) file here (specifications without a body are valid sources
352# in Ada).
353$(foreach class,$(classes),$(eval $(class)-extra-specs := \
354 $(filter \
355 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
356 $(filter %.ads,$($(class)-srcs)))))
357$(foreach class,$(classes),$(eval $(class)-srcs := \
358 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
359
Patrick Georgi10f86b02015-03-27 16:56:23 +0100360$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100361$(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
362
363# For Ada includes
364$(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
Patrick Georgid3428b02010-02-24 13:18:01 +0000365
Patrick Georgi79f90102012-11-25 14:31:08 +0100366# Call post-processors if they're defined
367$(foreach class,$(classes),\
368 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
369
Patrick Georgi58262652011-02-17 20:47:49 +0000370allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
371allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000372alldirs:=$(sort $(abspath $(dir $(allobjs))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000373
Nico Huber2e09d2b2016-01-14 01:13:33 +0100374# Reads dependencies from an Ada library information (.ali) file
375# Only basenames (with suffix) are preserved so we have to look the
376# paths up in $($(stage)-srcs).
377# $1 stage name
378# $2 ali file
379create_ada_deps=$$(if $(2),\
380 gnat.adc \
381 $$(filter \
382 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
383 $$($(1)-srcs) $$($(1)-extra-specs)))
384
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000385# macro to define template macros that are used by use_template macro
386define create_cc_template
Patrick Georgi71b84802011-02-22 14:35:05 +0000387# $1 obj class
Patrick Georgi990e7c92015-04-03 10:47:15 +0200388# $2 source suffix (c, S, ld, ...)
Marc Jonesa38ccfd2014-11-06 15:50:22 -0700389# $3 additional compiler flags
390# $4 additional dependencies
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000391ifn$(EMPTY)def $(1)-objs_$(2)_template
Patrick Georgi8463dd92010-09-30 16:55:02 +0000392de$(EMPTY)fine $(1)-objs_$(2)_template
Nico Huber1850aa62017-09-03 23:42:58 +0200393ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
Nico Huberb5679772019-01-01 22:06:01 +0100394$$(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 +0200395 @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
396 $(GCC_$(1)) \
397 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
398 $(3) -c -o $$$$@ $$$$<
399el$(EMPTY)se
400$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000401 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
Nico Huber2e09d2b2016-01-14 01:13:33 +0100402 $(CC_$(1)) \
Nico Huber1850aa62017-09-03 23:42:58 +0200403 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
Martin Rothb18726d2023-08-15 15:57:29 -0600404 $(3) -c -o $$$$@ $$$$< $(SAVE_IWYU_OUTPUT)
Nico Huber1850aa62017-09-03 23:42:58 +0200405end$(EMPTY)if
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000406en$(EMPTY)def
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000407end$(EMPTY)if
Patrick Georgi0588d192009-08-12 15:00:51 +0000408endef
409
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000410filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
411$(foreach class,$(classes), \
412 $(foreach type,$(call filetypes-of-class,$(class)), \
Patrick Georgi2459aee2015-03-27 15:27:21 +0100413 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
Patrick Georgi416ab382015-04-03 10:19:38 +0200414 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
415 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000416
Patrick Georgid69839b2015-04-03 10:32:17 +0200417foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
Patrick Georgi58262652011-02-17 20:47:49 +0000418$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000419
Nico Huber2e09d2b2016-01-14 01:13:33 +0100420# To supported complex package initializations, we need to call the
421# emitted code explicitly. gnatbind gathers all the calls for us
422# and exports them as a procedure $(stage)_adainit(). Every stage that
423# uses Ada code has to call it!
424define gnatbind_template
425# $1 class
426$$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
427 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
428 # We have to give gnatbind a simple filename (without leading
429 # path components) so just cd there.
430 cd $$(dir $$@) && \
431 $$(GNATBIND_$(1)) -a -n \
Nico Huberbe5492a2015-09-29 16:41:19 +0200432 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100433 -L$(1)_ada -o $$(notdir $$@) \
434 $$(subst $$(dir $$@),,$$^)
435$$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
Nico Huber1850aa62017-09-03 23:42:58 +0200436 @printf " GCC $$(subst $$(obj)/,,$$@)\n"
437 $(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
Nico Huber2e09d2b2016-01-14 01:13:33 +0100438$(1)-objs += $$(obj)/$(1)/b__$(1).o
Nico Huberddb24652016-09-19 11:50:04 +0200439$($(1)-alis): %.ali: %.o ;
Nico Huber2e09d2b2016-01-14 01:13:33 +0100440endef
441
Nico Huberbe5492a2015-09-29 16:41:19 +0200442$(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100443 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
444
Julius Wernerf97b88b2014-12-05 12:32:09 -0800445DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000446-include $(DEPENDENCIES)
447
Patrick Georgi0588d192009-08-12 15:00:51 +0000448printall:
Martin Roth09b64442016-06-05 10:52:43 -0600449 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
450 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
451 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
452 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
453 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
Patrick Georgi0588d192009-08-12 15:00:51 +0000454endif
455
Patrick Georgi40ad8422011-05-21 22:18:59 +0000456ifndef NOMKDIR
Stefan Reinauerde60c882015-06-29 14:44:37 -0700457$(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
Patrick Georgi40ad8422011-05-21 22:18:59 +0000458endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000459
Martin Roth9b0204d2017-09-18 09:25:18 -0600460$(obj)/project_filelist.txt:
461 if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
462 echo "*** Error: Project must be built before generating file list ***"; \
463 exit 1; \
464 fi
Maximilian Brunec36b70c2022-12-26 00:29:49 +0100465 find $(obj) -path "$(obj)/util" -prune -o -path "$(obj)/external" -prune -o -name "*.d" -exec cat {} \; | \
Martin Roth8a027272017-09-26 09:53:30 -0600466 sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
Martin Roth9c1b33e2015-07-29 14:55:18 -0700467 grep -v '\.o$$' > $(obj)/project_filelist.txt
468
Martin Roth9b0204d2017-09-18 09:25:18 -0600469filelist: $(obj)/project_filelist.txt
Martin Rotha18353d2017-06-06 06:44:46 -0600470 printf "\nFiles used in build:\n"
471 cat $(obj)/project_filelist.txt
472
Martin Roth9c1b33e2015-07-29 14:55:18 -0700473#works with either exuberant ctags or ctags.emacs
474ctags-project: clean-ctags $(obj)/project_filelist.txt
475 cat $(obj)/project_filelist.txt | \
476 xargs ctags -o tags
477
478cscope-project: clean-cscope $(obj)/project_filelist.txt
479 cat $(obj)/project_filelist.txt | xargs cscope -b
480
Warren Turkala9fc3302010-09-03 08:57:32 +0000481cscope:
482 cscope -bR
483
Patrick Rudolphf6643212020-05-17 20:04:12 +0200484sphinx:
Nico Huber4f014832023-08-23 12:41:01 +0200485 $(MAKE) -C Documentation sphinx
Patrick Rudolphf6643212020-05-17 20:04:12 +0200486
487sphinx-lint:
Nico Huber4f014832023-08-23 12:41:01 +0200488 $(MAKE) SPHINXOPTS=-W -C Documentation sphinx
Patrick Rudolphf6643212020-05-17 20:04:12 +0200489
Christian Waltera8c10c82022-07-01 11:12:25 +0200490symlink:
491 @echo "Creating Symbolic Links.."; \
492 for link in $(SYMLINK_LIST); do \
493 SYMLINK=`cat $$link`; \
494 REALPATH=`realpath $$link`; \
495 if [ -L "$$SYMLINK" ]; then \
496 continue; \
497 elif [ ! -e "$$SYMLINK" ]; then \
498 echo -e "\tLINK $$SYMLINK -> $$(dirname $$REALPATH)"; \
499 ln -s $$(dirname $$REALPATH) $$SYMLINK; \
500 else \
501 echo -e "\tFAILED: $$SYMLINK exists"; \
502 fi \
503 done
504
505clean-symlink:
506 @echo "Deleting symbolic link";\
507 EXISTING_SYMLINKS=`find -L ./src -xtype l | grep -v 3rdparty`; \
508 for link in $$EXISTING_SYMLINKS; do \
509 echo -e "\tUNLINK $$link"; \
510 rm "$$link"; \
511 done
512
Martin Roth619086d2022-05-09 18:48:24 -0600513clean-for-update:
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100514 rm -rf $(obj) .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000515
Arthur Heymansf91366f2022-03-25 16:01:05 +0100516clean: clean-for-update clean-utils clean-payloads
Patrick Georgi71b84802011-02-22 14:35:05 +0000517 rm -f .ccwrap
Warren Turkal0e8f2042010-09-27 21:14:19 +0000518
Warren Turkala9fc3302010-09-03 08:57:32 +0000519clean-cscope:
520 rm -f cscope.out
521
Martin Roth9c1b33e2015-07-29 14:55:18 -0700522clean-ctags:
523 rm -f tags
524
Martin Roth20cd54f2017-03-26 18:49:02 -0600525clean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600526 $(foreach tool, $(TOOLLIST), \
527 $(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
Martin Roth20cd54f2017-03-26 18:49:02 -0600528
529distclean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600530 $(foreach tool, $(TOOLLIST), \
531 $(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
Martin Roth20cd54f2017-03-26 18:49:02 -0600532 rm -f /util/$(tool)/junit.xml;)
533
534distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
Patrick Georgi80656af2017-04-26 11:58:44 +0200535 rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
Martin Roth20cd54f2017-03-26 18:49:02 -0600536 rm -rf coreboot-builds coreboot-builds-chromeos
537 rm -f abuild*.xml junit.xml* util/lint/junit.xml
Patrick Georgi0588d192009-08-12 15:00:51 +0000538
Martin Roth619086d2022-05-09 18:48:24 -0600539.PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean sphinx sphinx-lint
Christian Waltera8c10c82022-07-01 11:12:25 +0200540.PHONY: ctags-project cscope-project clean-ctags symlink clean-symlink