blob: 5ed69330cca810f92124386e0be540909ea6c6a1 [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
Nico Huber7a1fbdb2017-08-23 23:48:13 +020026KCONFIG_AUTOHEADER := $(obj)/config.h
27KCONFIG_AUTOCONFIG := $(obj)/auto.conf
28KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
Patrick Georgi53ea1d42019-11-22 16:55:58 +010029KCONFIG_SPLITCONFIG := $(obj)/config/
Nico Huber7a1fbdb2017-08-23 23:48:13 +020030KCONFIG_TRISTATE := $(obj)/tristate.conf
31KCONFIG_NEGATIVES := 1
Patrick Georgi0eab62b2023-11-20 19:49:29 +010032KCONFIG_WERROR:= 1
33KCONFIG_WARN_UNKNOWN_SYMBOLS:= 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
Patrick Georgi0eab62b2023-11-20 19:49:29 +010039COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_WERROR
40COREBOOT_EXPORTS += KCONFIG_WARN_UNKNOWN_SYMBOLS
Nico Huber533bc0a2019-01-01 19:03:33 +010041COREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE
Patrick Georgi0588d192009-08-12 15:00:51 +000042
Christian Waltera8c10c82022-07-01 11:12:25 +020043# Make does not offer a recursive wildcard function, so here's one:
44rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
45SYMLINK_LIST = $(call rwildcard,site-local/,symlink.txt)
46
47
Patrick Georgie38d0a62011-03-01 08:09:22 +000048# directory containing the toplevel Makefile.inc
49TOPLEVEL := .
50
Patrick Georgi0588d192009-08-12 15:00:51 +000051CONFIG_SHELL := sh
52KBUILD_DEFCONFIG := configs/defconfig
53UNAME_RELEASE := $(shell uname -r)
Patrick Georgi89ec3762010-12-08 19:58:30 +000054HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
Martin Roth4d7285d2021-11-23 12:39:44 -070055HAVE_KCONFIG_MAKEFILE_REAL := $(wildcard $(KCONFIG_MAKEFILE_REAL))
Patrick Georgi0588d192009-08-12 15:00:51 +000056MAKEFLAGS += -rR --no-print-directory
57
58# Make is silent per default, but 'make V=1' will show all compiler calls.
Patrick Georgi2b7418e2009-08-25 19:38:46 +000059Q:=@
Patrick Georgi0588d192009-08-12 15:00:51 +000060ifneq ($(V),1)
Patrick Georgi2b7418e2009-08-25 19:38:46 +000061ifneq ($(Q),)
62.SILENT:
Nico Huber7325ac52020-02-16 11:47:52 +010063MAKEFLAGS += -s
Martin Rothea6a93f2021-11-21 08:42:04 -070064quiet_errors := 2>/dev/null
Patrick Georgi2b7418e2009-08-25 19:38:46 +000065endif
Patrick Georgi0588d192009-08-12 15:00:51 +000066endif
67
Julius Werner808a4292015-03-13 11:05:07 -070068# Disable implicit/built-in rules to make Makefile errors fail fast.
69.SUFFIXES:
70
Patrick Georgib3a18ac2012-09-13 22:13:33 +020071HOSTCFLAGS := -g
72HOSTCXXFLAGS := -g
Patrick Georgi0588d192009-08-12 15:00:51 +000073
Nico Huber710a38a2022-12-11 13:13:45 +010074HOSTPKG_CONFIG ?= pkg-config
75COREBOOT_EXPORTS += HOSTPKG_CONFIG
76
Patrick Georgi828e0e82015-04-04 15:50:20 +020077PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
78
Nico Huber7a1fbdb2017-08-23 23:48:13 +020079export $(COREBOOT_EXPORTS)
80
Patrick Georgi71b84802011-02-22 14:35:05 +000081all: real-all
82
Martin Roth4eea1742015-11-25 11:50:04 -070083help_coreboot help::
84 @echo '*** coreboot platform targets ***'
Martin Roth76f14b22015-11-18 13:09:23 -070085 @echo ' Use "make [target] V=1" for extra build debug information'
86 @echo ' all - Build coreboot'
87 @echo ' clean - Remove coreboot build artifacts'
88 @echo ' distclean - Remove build artifacts and config files'
Patrick Rudolphf6643212020-05-17 20:04:12 +020089 @echo ' sphinx - Build sphinx documentation for coreboot'
Nico Huberbfdefc22023-08-23 12:42:40 +020090 @echo ' sphinx-lint - Build sphinx documentation for coreboot with warnings as errors'
Martin Roth763e4932018-01-27 16:42:43 -070091 @echo ' filelist - Show files used in current build'
Martin Roth76f14b22015-11-18 13:09:23 -070092 @echo ' printall - print makefile info for debugging'
Werner Zeh2de64102016-01-12 12:45:49 +010093 @echo ' gitconfig - set up git to submit patches to coreboot'
Martin Roth76f14b22015-11-18 13:09:23 -070094 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
95 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
96 @echo
97
Patrick Georgie38d0a62011-03-01 08:09:22 +000098# This include must come _before_ the pattern rules below!
Patrick Georgi71b84802011-02-22 14:35:05 +000099# Order _does_ matter for pattern rules.
Patrick Georgi3e8ef102019-11-22 16:54:17 +0100100include $(srck)/Makefile.inc
Patrick Georgi71b84802011-02-22 14:35:05 +0000101
Martin Roth4d7285d2021-11-23 12:39:44 -0700102# The cases where we don't need fully populated $(obj) lists:
Patrick Georgicf036d12010-04-21 06:36:20 +0000103# 1. when no .config exists
Martin Roth4d7285d2021-11-23 12:39:44 -0700104# 2. When no $(obj)/util/kconfig/Makefile.real exists and we're building tools
105# 3. when make config (in any flavour) is run
106# 4. when make distclean is run
Patrick Georgicf036d12010-04-21 06:36:20 +0000107# Don't waste time on reading all Makefile.incs in these cases
Patrick Georgi0588d192009-08-12 15:00:51 +0000108ifeq ($(strip $(HAVE_DOTCONFIG)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000109NOCOMPILE:=1
110endif
Martin Roth4d7285d2021-11-23 12:39:44 -0700111ifeq ($(strip $(HAVE_KCONFIG_MAKEFILE_REAL)),)
112ifneq ($(MAKECMDGOALS),tools)
113NOCOMPILE:=1
114endif
115endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000116ifneq ($(MAKECMDGOALS),)
Elyes HAOUAS91fb1392020-01-20 15:33:11 +0100117ifneq ($(filter %config %clean cross% clang iasl lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000118NOCOMPILE:=1
119endif
Raul E Rangel5592cfd2019-07-23 11:13:40 -0600120ifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
Zheng Bao0fd93d62012-10-22 16:36:03 +0800121NOMKDIR:=1
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200122UNIT_TEST:=1
Zheng Bao0fd93d62012-10-22 16:36:03 +0800123endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000124endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000125
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200126ifneq ($(filter help%, $(MAKECMDGOALS)), )
127NOCOMPILE:=1
128UNIT_TEST:=1
129else
Paul Fagerburgde6cbac2021-05-11 09:56:48 -0600130ifneq ($(filter %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
131ifneq ($(filter-out %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
Jan Dabrosef1c9682020-03-28 00:15:03 +0100132$(error Cannot mix unit-tests targets with other targets)
133endif
134UNIT_TEST:=1
135NOCOMPILE:=
136endif
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200137endif
Jan Dabrosef1c9682020-03-28 00:15:03 +0100138
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600139$(xcompile): util/xcompile/xcompile
Raul E Rangel6325ce22019-07-10 16:46:34 -0600140 rm -f $@
141 $< $(XGCCPATH) > $@.tmp
142 \mv -f $@.tmp $@ 2> /dev/null
143 rm -f $@.tmp
144
Patrick Georgicf036d12010-04-21 06:36:20 +0000145ifeq ($(NOCOMPILE),1)
Patrick Georgib351875f2020-07-06 15:31:58 +0000146# We also don't use .xcompile in the no-compile situations, so
147# provide some reasonable defaults.
148HOSTCC ?= $(if $(shell type gcc 2>/dev/null),gcc,cc)
149HOSTCXX ?= g++
150
Patrick Georgie38d0a62011-03-01 08:09:22 +0000151include $(TOPLEVEL)/Makefile.inc
Martin Roth67975572016-03-07 16:38:52 -0700152include $(TOPLEVEL)/payloads/Makefile.inc
Martin Rothe624e272017-07-31 11:52:58 -0600153include $(TOPLEVEL)/util/testing/Makefile.inc
Werner Zehb7f1c2d2019-10-04 07:01:13 +0200154-include $(TOPLEVEL)/site-local/Makefile.inc
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200155include $(TOPLEVEL)/tests/Makefile.inc
Martin Roth9fc96402022-11-27 19:04:16 -0700156printall real-all:
Martin Rothe28c7182022-06-22 17:49:31 -0600157 @echo "Error: Trying to build, but NOCOMPILE is set." >&2
158 @echo " Please file a bug with the following information:"
159 @echo "- MAKECMDGOALS: $(MAKECMDGOALS)" >&2
160 @echo "- HAVE_DOTCONFIG: $(HAVE_DOTCONFIG)" >&2
161 @echo "- HAVE_KCONFIG_MAKEFILE_REAL: $(HAVE_KCONFIG_MAKEFILE_REAL)" >&2
Martin Roth20aa0432017-01-26 10:51:43 -0700162 @exit 1
Martin Roth9fc96402022-11-27 19:04:16 -0700163
Patrick Georgi0588d192009-08-12 15:00:51 +0000164else
165
Jan Dabrosef1c9682020-03-28 00:15:03 +0100166ifneq ($(UNIT_TEST),1)
Paul Kocialkowski585c7812016-07-13 11:00:41 +0200167include $(DOTCONFIG)
Jan Dabrosef1c9682020-03-28 00:15:03 +0100168endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000169
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600170# The toolchain requires xcompile to determine the ARCH_SUPPORTED, so we can't
171# wait for make to generate the file.
172$(if $(wildcard $(xcompile)),, $(shell \
173 mkdir -p $(dir $(xcompile)) && \
174 util/xcompile/xcompile $(XGCCPATH) > $(xcompile) || rm -f $(xcompile)))
Patrick Georgi0ffef882017-01-19 23:20:14 +0100175
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600176include $(xcompile)
Patrick Georgi6dda31d2015-11-19 15:15:33 +0100177
178ifneq ($(XCOMPILE_COMPLETE),1)
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600179$(shell rm -f $(xcompile))
180$(error $(xcompile) deleted because it's invalid. \
Patrick Georgi6dda31d2015-11-19 15:15:33 +0100181 Restarting the build should fix that, or explain the problem)
182endif
Patrick Georgi7b9762f2015-06-04 13:18:11 +0200183
Patrick Georgica6e5ee2021-04-13 15:48:38 +0200184# reproducible builds
185LANG:=C
186LC_ALL:=C
187TZ:=UTC0
188ifneq ($(NOCOMPILE),1)
189SOURCE_DATE_EPOCH := $(shell $(top)/util/genbuild_h/genbuild_h.sh . | sed -n 's/^.define COREBOOT_BUILD_EPOCH\>.*"\(.*\)".*/\1/p')
190endif
191# don't use COREBOOT_EXPORTS to ensure build steps outside the coreboot build system
192# are reproducible
193export LANG LC_ALL TZ SOURCE_DATE_EPOCH
194
Jan Dabrosef1c9682020-03-28 00:15:03 +0100195ifneq ($(UNIT_TEST),1)
Patrick Georgicc84a002014-05-14 21:05:35 +0200196include toolchain.inc
Jan Dabrosef1c9682020-03-28 00:15:03 +0100197endif
Patrick Georgicc84a002014-05-14 21:05:35 +0200198
Zheng Bao07648922015-11-13 10:42:27 +0800199strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
Martin Rothbbf13992016-01-25 15:59:24 -0700200# fix makefile syntax highlighting after strip macro \" "))
Patrick Georgia84e98b2010-03-16 19:01:32 +0000201
Kyösti Mälkkicad92ec2022-12-14 17:26:35 +0200202ifneq ($(NOCOMPILE),1)
203$(shell rm -f $(CCACHE_STATSLOG))
204endif
205
Patrick Georgi0588d192009-08-12 15:00:51 +0000206# The primary target needs to be here before we include the
207# other files
208
Patrick Georgi71b84802011-02-22 14:35:05 +0000209real-all: real-target
Patrick Georgi0588d192009-08-12 15:00:51 +0000210
Patrick Georgi51e142f2010-03-27 17:18:39 +0000211# must come rather early
Raul E Rangeldd6efce2022-02-25 17:03:10 -0700212.SECONDARY:
Patrick Georgi51e142f2010-03-27 17:18:39 +0000213.SECONDEXPANSION:
Raul E Rangelcc6dc902018-08-06 16:13:32 -0600214.DELETE_ON_ERROR:
Patrick Georgi51e142f2010-03-27 17:18:39 +0000215
Jonathan Neuschäferd2c02422018-12-11 13:06:40 +0100216$(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
Patrick Georgi53ea1d42019-11-22 16:55:58 +0100217 $(MAKE) olddefconfig
218 $(MAKE) syncconfig
Patrick Georgi0588d192009-08-12 15:00:51 +0000219
Nico Huber533bc0a2019-01-01 19:03:33 +0100220$(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
221 true
222
Nico Hubereafc8152019-10-25 12:47:14 +0200223$(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
Nico Huber533bc0a2019-01-01 19:03:33 +0100224 $(objutil)/kconfig/toada CB.Config <$< >$@
225
Nico Huberb5679772019-01-01 22:06:01 +0100226$(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
227 cp $< $@
228
Patrick Georgi58262652011-02-17 20:47:49 +0000229# Add a new class of source/object files to the build system
230add-class= \
231 $(eval $(1)-srcs:=) \
232 $(eval $(1)-objs:=) \
233 $(eval classes+=$(1))
Patrick Georgi8463dd92010-09-30 16:55:02 +0000234
Patrick Georgi58262652011-02-17 20:47:49 +0000235# Special classes are managed types with special behaviour
236# On parse time, for each entry in variable $(1)-y
237# a handler $(1)-handler is executed with the arguments:
238# * $(1): directory the parser is in
239# * $(2): current entry
240add-special-class= \
241 $(eval $(1):=) \
242 $(eval special-classes+=$(1))
243
Nico Huber81b09f42016-01-23 00:50:00 +0100244# Converts one or more source file paths to their corresponding build/ paths.
Nico Huber2e09d2b2016-01-14 01:13:33 +0100245# Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
246# their name.
Nico Huber81b09f42016-01-23 00:50:00 +0100247# $1 stage name
248# $2 file path (list)
Nico Huber98fc4262016-01-23 01:24:33 +0100249src-to-obj=\
250 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
251 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200252 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber98fc4262016-01-23 01:24:33 +0100253 $(patsubst src/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100254 $(patsubst %.ads,%.o,\
255 $(patsubst %.adb,%.o,\
Nico Huber98fc4262016-01-23 01:24:33 +0100256 $(patsubst %.c,%.o,\
257 $(patsubst %.S,%.o,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200258 $(subst .$(1),,$(2))))))))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100259
260# Converts one or more source file paths to the corresponding build/ paths
261# of their Ada library information (.ali) files.
262# $1 stage name
263# $2 file path (list)
264src-to-ali=\
265 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
266 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200267 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100268 $(patsubst src/%,$(obj)/%,\
269 $(patsubst %.ads,%.ali,\
270 $(patsubst %.adb,%.ali,\
271 $(subst .$(1),,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200272 $(filter %.ads %.adb,$(2)))))))))
Nico Huber81b09f42016-01-23 00:50:00 +0100273
Patrick Georgi47d68d82010-03-06 21:18:43 +0000274# Clean -y variables, include Makefile.inc
Patrick Georgi8463dd92010-09-30 16:55:02 +0000275# Add paths to files in X-y to X-srcs
Patrick Georgi47d68d82010-03-06 21:18:43 +0000276# Add subdirs-y to subdirs
277includemakefiles= \
Nikolai Vyssotskib9d00722022-09-24 08:48:15 -0500278 $(if $(wildcard $(1)), \
279 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
280 $(eval -include $(1)) \
281 $(foreach class,$(classes-y), $(call add-class,$(class))) \
282 $(foreach special,$(special-classes), \
283 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
284 $(foreach class,$(classes), \
285 $(eval $(class)-srcs+= \
286 $$(subst $(absobj)/,$(obj)/, \
287 $$(subst $(top)/,, \
288 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
289 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))))
Patrick Georgi47d68d82010-03-06 21:18:43 +0000290
Patrick Georgi8463dd92010-09-30 16:55:02 +0000291# For each path in $(subdirs) call includemakefiles
Patrick Georgi47d68d82010-03-06 21:18:43 +0000292# Repeat until subdirs is empty
293evaluate_subdirs= \
294 $(eval cursubdirs:=$(subdirs)) \
295 $(eval subdirs:=) \
296 $(foreach dir,$(cursubdirs), \
Patrick Georgi58262652011-02-17 20:47:49 +0000297 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000298 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000299
300# collect all object files eligible for building
Patrick Georgie38d0a62011-03-01 08:09:22 +0000301subdirs:=$(TOPLEVEL)
Julius Wernere91d1702017-03-20 15:32:15 -0700302postinclude-hooks :=
Jan Dabrosef1c9682020-03-28 00:15:03 +0100303
304# Don't iterate through Makefile.incs under src/ when building tests
305ifneq ($(UNIT_TEST),1)
Patrick Georgi51e142f2010-03-27 17:18:39 +0000306$(eval $(call evaluate_subdirs))
Jan Dabrosef1c9682020-03-28 00:15:03 +0100307else
308include $(TOPLEVEL)/tests/Makefile.inc
309endif
310
Patrick Georgi70c85ea2013-02-16 01:06:57 +0100311ifeq ($(FAILBUILD),1)
312$(error cannot continue build)
313endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000314
Julius Wernere91d1702017-03-20 15:32:15 -0700315# Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
316$(eval $(postinclude-hooks))
317
Patrick Georgi94a45862011-10-25 14:32:21 -0700318# Eliminate duplicate mentions of source files in a class
319$(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
320
Martin Rothb18726d2023-08-15 15:57:29 -0600321ifeq ($(CONFIG_IWYU),y)
322MAKEFLAGS += -k
323SAVE_IWYU_OUTPUT := 2>&1 | grep "should\|\#include\|---\|include-list\|^[[:blank:]]\?\'" | tee -a $$(obj)/iwyu.txt
324endif
325
Nico Huberb5679772019-01-01 22:06:01 +0100326# Build Kconfig .ads if necessary
Jeremy Compostellafa838872022-11-30 19:26:01 -0700327ifeq ($(CONFIG_ROMSTAGE_ADA),y)
328romstage-srcs += $(obj)/romstage/$(notdir $(KCONFIG_AUTOADS))
329endif
Nico Huberb5679772019-01-01 22:06:01 +0100330ifeq ($(CONFIG_RAMSTAGE_ADA),y)
331ramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
332endif
333
Nico Huber2e09d2b2016-01-14 01:13:33 +0100334# To track dependencies, we need all Ada specification (.ads) files in
335# *-srcs. Extract / filter all specification files that have a matching
336# body (.adb) file here (specifications without a body are valid sources
337# in Ada).
338$(foreach class,$(classes),$(eval $(class)-extra-specs := \
339 $(filter \
340 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
341 $(filter %.ads,$($(class)-srcs)))))
342$(foreach class,$(classes),$(eval $(class)-srcs := \
343 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
344
Patrick Georgi10f86b02015-03-27 16:56:23 +0100345$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100346$(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
347
348# For Ada includes
349$(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
Patrick Georgid3428b02010-02-24 13:18:01 +0000350
Nico Huber963bed52013-05-15 11:47:51 +0200351# Save all objs before processing them (for dependency inclusion)
352originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
353
Patrick Georgi79f90102012-11-25 14:31:08 +0100354# Call post-processors if they're defined
355$(foreach class,$(classes),\
356 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
357
Patrick Georgi58262652011-02-17 20:47:49 +0000358allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
359allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000360alldirs:=$(sort $(abspath $(dir $(allobjs))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000361
Nico Huber2e09d2b2016-01-14 01:13:33 +0100362# Reads dependencies from an Ada library information (.ali) file
363# Only basenames (with suffix) are preserved so we have to look the
364# paths up in $($(stage)-srcs).
365# $1 stage name
366# $2 ali file
367create_ada_deps=$$(if $(2),\
368 gnat.adc \
369 $$(filter \
370 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
371 $$($(1)-srcs) $$($(1)-extra-specs)))
372
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000373# macro to define template macros that are used by use_template macro
374define create_cc_template
Patrick Georgi71b84802011-02-22 14:35:05 +0000375# $1 obj class
Patrick Georgi990e7c92015-04-03 10:47:15 +0200376# $2 source suffix (c, S, ld, ...)
Marc Jonesa38ccfd2014-11-06 15:50:22 -0700377# $3 additional compiler flags
378# $4 additional dependencies
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000379ifn$(EMPTY)def $(1)-objs_$(2)_template
Patrick Georgi8463dd92010-09-30 16:55:02 +0000380de$(EMPTY)fine $(1)-objs_$(2)_template
Nico Huber1850aa62017-09-03 23:42:58 +0200381ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
Nico Huberb5679772019-01-01 22:06:01 +0100382$$(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 +0200383 @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
384 $(GCC_$(1)) \
385 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
386 $(3) -c -o $$$$@ $$$$<
387el$(EMPTY)se
388$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000389 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
Nico Huber2e09d2b2016-01-14 01:13:33 +0100390 $(CC_$(1)) \
Nico Huber1850aa62017-09-03 23:42:58 +0200391 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
Martin Rothb18726d2023-08-15 15:57:29 -0600392 $(3) -c -o $$$$@ $$$$< $(SAVE_IWYU_OUTPUT)
Nico Huber1850aa62017-09-03 23:42:58 +0200393end$(EMPTY)if
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000394en$(EMPTY)def
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000395end$(EMPTY)if
Patrick Georgi0588d192009-08-12 15:00:51 +0000396endef
397
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000398filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
399$(foreach class,$(classes), \
400 $(foreach type,$(call filetypes-of-class,$(class)), \
Patrick Georgi2459aee2015-03-27 15:27:21 +0100401 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
Patrick Georgi416ab382015-04-03 10:19:38 +0200402 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
403 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000404
Patrick Georgid69839b2015-04-03 10:32:17 +0200405foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
Patrick Georgi58262652011-02-17 20:47:49 +0000406$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000407
Nico Huber2e09d2b2016-01-14 01:13:33 +0100408# To supported complex package initializations, we need to call the
409# emitted code explicitly. gnatbind gathers all the calls for us
410# and exports them as a procedure $(stage)_adainit(). Every stage that
411# uses Ada code has to call it!
412define gnatbind_template
413# $1 class
414$$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
415 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
416 # We have to give gnatbind a simple filename (without leading
417 # path components) so just cd there.
418 cd $$(dir $$@) && \
419 $$(GNATBIND_$(1)) -a -n \
Nico Huberbe5492a2015-09-29 16:41:19 +0200420 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100421 -L$(1)_ada -o $$(notdir $$@) \
422 $$(subst $$(dir $$@),,$$^)
423$$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
Nico Huber1850aa62017-09-03 23:42:58 +0200424 @printf " GCC $$(subst $$(obj)/,,$$@)\n"
425 $(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
Nico Huber2e09d2b2016-01-14 01:13:33 +0100426$(1)-objs += $$(obj)/$(1)/b__$(1).o
Nico Huberddb24652016-09-19 11:50:04 +0200427$($(1)-alis): %.ali: %.o ;
Nico Huber2e09d2b2016-01-14 01:13:33 +0100428endef
429
Nico Huberbe5492a2015-09-29 16:41:19 +0200430$(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100431 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
432
Julius Wernerf97b88b2014-12-05 12:32:09 -0800433DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000434-include $(DEPENDENCIES)
435
Patrick Georgi0588d192009-08-12 15:00:51 +0000436printall:
Martin Roth09b64442016-06-05 10:52:43 -0600437 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
438 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
439 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
440 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
441 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
Patrick Georgi0588d192009-08-12 15:00:51 +0000442endif
443
Patrick Georgi40ad8422011-05-21 22:18:59 +0000444ifndef NOMKDIR
Stefan Reinauerde60c882015-06-29 14:44:37 -0700445$(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
Patrick Georgi40ad8422011-05-21 22:18:59 +0000446endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000447
Martin Roth9b0204d2017-09-18 09:25:18 -0600448$(obj)/project_filelist.txt:
449 if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
450 echo "*** Error: Project must be built before generating file list ***"; \
451 exit 1; \
452 fi
Maximilian Brunec36b70c2022-12-26 00:29:49 +0100453 find $(obj) -path "$(obj)/util" -prune -o -path "$(obj)/external" -prune -o -name "*.d" -exec cat {} \; | \
Martin Roth8a027272017-09-26 09:53:30 -0600454 sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
Martin Roth9c1b33e2015-07-29 14:55:18 -0700455 grep -v '\.o$$' > $(obj)/project_filelist.txt
456
Martin Roth9b0204d2017-09-18 09:25:18 -0600457filelist: $(obj)/project_filelist.txt
Martin Rotha18353d2017-06-06 06:44:46 -0600458 printf "\nFiles used in build:\n"
459 cat $(obj)/project_filelist.txt
460
Martin Roth9c1b33e2015-07-29 14:55:18 -0700461#works with either exuberant ctags or ctags.emacs
462ctags-project: clean-ctags $(obj)/project_filelist.txt
463 cat $(obj)/project_filelist.txt | \
464 xargs ctags -o tags
465
466cscope-project: clean-cscope $(obj)/project_filelist.txt
467 cat $(obj)/project_filelist.txt | xargs cscope -b
468
Warren Turkala9fc3302010-09-03 08:57:32 +0000469cscope:
470 cscope -bR
471
Patrick Rudolphf6643212020-05-17 20:04:12 +0200472sphinx:
Nico Huber4f014832023-08-23 12:41:01 +0200473 $(MAKE) -C Documentation sphinx
Patrick Rudolphf6643212020-05-17 20:04:12 +0200474
475sphinx-lint:
Nico Huber4f014832023-08-23 12:41:01 +0200476 $(MAKE) SPHINXOPTS=-W -C Documentation sphinx
Patrick Rudolphf6643212020-05-17 20:04:12 +0200477
Christian Waltera8c10c82022-07-01 11:12:25 +0200478symlink:
479 @echo "Creating Symbolic Links.."; \
480 for link in $(SYMLINK_LIST); do \
481 SYMLINK=`cat $$link`; \
482 REALPATH=`realpath $$link`; \
483 if [ -L "$$SYMLINK" ]; then \
484 continue; \
485 elif [ ! -e "$$SYMLINK" ]; then \
486 echo -e "\tLINK $$SYMLINK -> $$(dirname $$REALPATH)"; \
487 ln -s $$(dirname $$REALPATH) $$SYMLINK; \
488 else \
489 echo -e "\tFAILED: $$SYMLINK exists"; \
490 fi \
491 done
492
493clean-symlink:
494 @echo "Deleting symbolic link";\
495 EXISTING_SYMLINKS=`find -L ./src -xtype l | grep -v 3rdparty`; \
496 for link in $$EXISTING_SYMLINKS; do \
497 echo -e "\tUNLINK $$link"; \
498 rm "$$link"; \
499 done
500
Martin Roth619086d2022-05-09 18:48:24 -0600501clean-for-update:
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100502 rm -rf $(obj) .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000503
Arthur Heymansf91366f2022-03-25 16:01:05 +0100504clean: clean-for-update clean-utils clean-payloads
Patrick Georgi71b84802011-02-22 14:35:05 +0000505 rm -f .ccwrap
Warren Turkal0e8f2042010-09-27 21:14:19 +0000506
Warren Turkala9fc3302010-09-03 08:57:32 +0000507clean-cscope:
508 rm -f cscope.out
509
Martin Roth9c1b33e2015-07-29 14:55:18 -0700510clean-ctags:
511 rm -f tags
512
Martin Roth20cd54f2017-03-26 18:49:02 -0600513clean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600514 $(foreach tool, $(TOOLLIST), \
515 $(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
Martin Roth20cd54f2017-03-26 18:49:02 -0600516
517distclean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600518 $(foreach tool, $(TOOLLIST), \
519 $(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
Martin Roth20cd54f2017-03-26 18:49:02 -0600520 rm -f /util/$(tool)/junit.xml;)
521
522distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
Patrick Georgi80656af2017-04-26 11:58:44 +0200523 rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
Martin Roth20cd54f2017-03-26 18:49:02 -0600524 rm -rf coreboot-builds coreboot-builds-chromeos
525 rm -f abuild*.xml junit.xml* util/lint/junit.xml
Patrick Georgi0588d192009-08-12 15:00:51 +0000526
Martin Roth619086d2022-05-09 18:48:24 -0600527.PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean sphinx sphinx-lint
Christian Waltera8c10c82022-07-01 11:12:25 +0200528.PHONY: ctags-project cscope-project clean-ctags symlink clean-symlink