blob: 6bdd44a8562e216eff2cf123a3b527553e0e62bb [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
32KCONFIG_STRICT := 1
Nico Huber533bc0a2019-01-01 19:03:33 +010033KCONFIG_PACKAGE := CB.Config
Martin Roth4d7285d2021-11-23 12:39:44 -070034KCONFIG_MAKEFILE_REAL ?= $(objk)/Makefile.real
Nico Huber7a1fbdb2017-08-23 23:48:13 +020035
36COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
37COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
38COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_STRICT
Nico Huber533bc0a2019-01-01 19:03:33 +010039COREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE
Patrick Georgi0588d192009-08-12 15:00:51 +000040
Patrick Georgie38d0a62011-03-01 08:09:22 +000041# directory containing the toplevel Makefile.inc
42TOPLEVEL := .
43
Patrick Georgi0588d192009-08-12 15:00:51 +000044CONFIG_SHELL := sh
45KBUILD_DEFCONFIG := configs/defconfig
46UNAME_RELEASE := $(shell uname -r)
Patrick Georgi89ec3762010-12-08 19:58:30 +000047HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
Martin Roth4d7285d2021-11-23 12:39:44 -070048HAVE_KCONFIG_MAKEFILE_REAL := $(wildcard $(KCONFIG_MAKEFILE_REAL))
Patrick Georgi0588d192009-08-12 15:00:51 +000049MAKEFLAGS += -rR --no-print-directory
50
51# Make is silent per default, but 'make V=1' will show all compiler calls.
Patrick Georgi2b7418e2009-08-25 19:38:46 +000052Q:=@
Patrick Georgi0588d192009-08-12 15:00:51 +000053ifneq ($(V),1)
Patrick Georgi2b7418e2009-08-25 19:38:46 +000054ifneq ($(Q),)
55.SILENT:
Nico Huber7325ac52020-02-16 11:47:52 +010056MAKEFLAGS += -s
Martin Rothea6a93f2021-11-21 08:42:04 -070057quiet_errors := 2>/dev/null
Patrick Georgi2b7418e2009-08-25 19:38:46 +000058endif
Patrick Georgi0588d192009-08-12 15:00:51 +000059endif
60
Julius Werner808a4292015-03-13 11:05:07 -070061# Disable implicit/built-in rules to make Makefile errors fail fast.
62.SUFFIXES:
63
Patrick Georgib3a18ac2012-09-13 22:13:33 +020064HOSTCFLAGS := -g
65HOSTCXXFLAGS := -g
Patrick Georgi0588d192009-08-12 15:00:51 +000066
Patrick Georgi828e0e82015-04-04 15:50:20 +020067PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
68
Nico Huber7a1fbdb2017-08-23 23:48:13 +020069export $(COREBOOT_EXPORTS)
70
Patrick Georgi71b84802011-02-22 14:35:05 +000071all: real-all
72
Martin Roth4eea1742015-11-25 11:50:04 -070073help_coreboot help::
74 @echo '*** coreboot platform targets ***'
Martin Roth76f14b22015-11-18 13:09:23 -070075 @echo ' Use "make [target] V=1" for extra build debug information'
76 @echo ' all - Build coreboot'
77 @echo ' clean - Remove coreboot build artifacts'
78 @echo ' distclean - Remove build artifacts and config files'
Patrick Rudolphf6643212020-05-17 20:04:12 +020079 @echo ' sphinx - Build sphinx documentation for coreboot'
80 @echo ' sphinx-lint - Build sphinx documenttion for coreboot with warnings as errors'
Martin Roth763e4932018-01-27 16:42:43 -070081 @echo ' filelist - Show files used in current build'
Martin Roth76f14b22015-11-18 13:09:23 -070082 @echo ' printall - print makefile info for debugging'
Werner Zeh2de64102016-01-12 12:45:49 +010083 @echo ' gitconfig - set up git to submit patches to coreboot'
Martin Roth76f14b22015-11-18 13:09:23 -070084 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
85 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
86 @echo
87
Patrick Georgie38d0a62011-03-01 08:09:22 +000088# This include must come _before_ the pattern rules below!
Patrick Georgi71b84802011-02-22 14:35:05 +000089# Order _does_ matter for pattern rules.
Patrick Georgi3e8ef102019-11-22 16:54:17 +010090include $(srck)/Makefile.inc
Patrick Georgi71b84802011-02-22 14:35:05 +000091
Martin Roth4d7285d2021-11-23 12:39:44 -070092# The cases where we don't need fully populated $(obj) lists:
Patrick Georgicf036d12010-04-21 06:36:20 +000093# 1. when no .config exists
Martin Roth4d7285d2021-11-23 12:39:44 -070094# 2. When no $(obj)/util/kconfig/Makefile.real exists and we're building tools
95# 3. when make config (in any flavour) is run
96# 4. when make distclean is run
Patrick Georgicf036d12010-04-21 06:36:20 +000097# Don't waste time on reading all Makefile.incs in these cases
Patrick Georgi0588d192009-08-12 15:00:51 +000098ifeq ($(strip $(HAVE_DOTCONFIG)),)
Patrick Georgicf036d12010-04-21 06:36:20 +000099NOCOMPILE:=1
100endif
Martin Roth4d7285d2021-11-23 12:39:44 -0700101ifeq ($(strip $(HAVE_KCONFIG_MAKEFILE_REAL)),)
102ifneq ($(MAKECMDGOALS),tools)
103NOCOMPILE:=1
104endif
105endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000106ifneq ($(MAKECMDGOALS),)
Elyes HAOUAS91fb1392020-01-20 15:33:11 +0100107ifneq ($(filter %config %clean cross% clang iasl lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000108NOCOMPILE:=1
109endif
Raul E Rangel5592cfd2019-07-23 11:13:40 -0600110ifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
Zheng Bao0fd93d62012-10-22 16:36:03 +0800111NOMKDIR:=1
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200112UNIT_TEST:=1
Zheng Bao0fd93d62012-10-22 16:36:03 +0800113endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000114endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000115
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200116ifneq ($(filter help%, $(MAKECMDGOALS)), )
117NOCOMPILE:=1
118UNIT_TEST:=1
119else
Paul Fagerburgde6cbac2021-05-11 09:56:48 -0600120ifneq ($(filter %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
121ifneq ($(filter-out %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
Jan Dabrosef1c9682020-03-28 00:15:03 +0100122$(error Cannot mix unit-tests targets with other targets)
123endif
124UNIT_TEST:=1
125NOCOMPILE:=
126endif
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200127endif
Jan Dabrosef1c9682020-03-28 00:15:03 +0100128
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600129$(xcompile): util/xcompile/xcompile
Raul E Rangel6325ce22019-07-10 16:46:34 -0600130 rm -f $@
131 $< $(XGCCPATH) > $@.tmp
132 \mv -f $@.tmp $@ 2> /dev/null
133 rm -f $@.tmp
134
Patrick Georgicf036d12010-04-21 06:36:20 +0000135ifeq ($(NOCOMPILE),1)
Patrick Georgib351875f2020-07-06 15:31:58 +0000136# We also don't use .xcompile in the no-compile situations, so
137# provide some reasonable defaults.
138HOSTCC ?= $(if $(shell type gcc 2>/dev/null),gcc,cc)
139HOSTCXX ?= g++
140
Patrick Georgie38d0a62011-03-01 08:09:22 +0000141include $(TOPLEVEL)/Makefile.inc
Martin Roth67975572016-03-07 16:38:52 -0700142include $(TOPLEVEL)/payloads/Makefile.inc
Martin Rothe624e272017-07-31 11:52:58 -0600143include $(TOPLEVEL)/util/testing/Makefile.inc
Werner Zehb7f1c2d2019-10-04 07:01:13 +0200144-include $(TOPLEVEL)/site-local/Makefile.inc
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200145include $(TOPLEVEL)/tests/Makefile.inc
Martin Roth20aa0432017-01-26 10:51:43 -0700146real-all:
Martin Rothe28c7182022-06-22 17:49:31 -0600147 @echo "Error: Trying to build, but NOCOMPILE is set." >&2
148 @echo " Please file a bug with the following information:"
149 @echo "- MAKECMDGOALS: $(MAKECMDGOALS)" >&2
150 @echo "- HAVE_DOTCONFIG: $(HAVE_DOTCONFIG)" >&2
151 @echo "- HAVE_KCONFIG_MAKEFILE_REAL: $(HAVE_KCONFIG_MAKEFILE_REAL)" >&2
Martin Roth20aa0432017-01-26 10:51:43 -0700152 @exit 1
Patrick Georgi0588d192009-08-12 15:00:51 +0000153else
154
Jan Dabrosef1c9682020-03-28 00:15:03 +0100155ifneq ($(UNIT_TEST),1)
Paul Kocialkowski585c7812016-07-13 11:00:41 +0200156include $(DOTCONFIG)
Jan Dabrosef1c9682020-03-28 00:15:03 +0100157endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000158
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600159# The toolchain requires xcompile to determine the ARCH_SUPPORTED, so we can't
160# wait for make to generate the file.
161$(if $(wildcard $(xcompile)),, $(shell \
162 mkdir -p $(dir $(xcompile)) && \
163 util/xcompile/xcompile $(XGCCPATH) > $(xcompile) || rm -f $(xcompile)))
Patrick Georgi0ffef882017-01-19 23:20:14 +0100164
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600165include $(xcompile)
Patrick Georgi6dda31d2015-11-19 15:15:33 +0100166
167ifneq ($(XCOMPILE_COMPLETE),1)
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600168$(shell rm -f $(xcompile))
169$(error $(xcompile) deleted because it's invalid. \
Patrick Georgi6dda31d2015-11-19 15:15:33 +0100170 Restarting the build should fix that, or explain the problem)
171endif
Patrick Georgi7b9762f2015-06-04 13:18:11 +0200172
Patrick Georgica6e5ee2021-04-13 15:48:38 +0200173# reproducible builds
174LANG:=C
175LC_ALL:=C
176TZ:=UTC0
177ifneq ($(NOCOMPILE),1)
178SOURCE_DATE_EPOCH := $(shell $(top)/util/genbuild_h/genbuild_h.sh . | sed -n 's/^.define COREBOOT_BUILD_EPOCH\>.*"\(.*\)".*/\1/p')
179endif
180# don't use COREBOOT_EXPORTS to ensure build steps outside the coreboot build system
181# are reproducible
182export LANG LC_ALL TZ SOURCE_DATE_EPOCH
183
Patrick Georgicc84a002014-05-14 21:05:35 +0200184ifneq ($(CONFIG_MMX),y)
185CFLAGS_x86_32 += -mno-mmx
186endif
187
Jan Dabrosef1c9682020-03-28 00:15:03 +0100188ifneq ($(UNIT_TEST),1)
Patrick Georgicc84a002014-05-14 21:05:35 +0200189include toolchain.inc
Jan Dabrosef1c9682020-03-28 00:15:03 +0100190endif
Patrick Georgicc84a002014-05-14 21:05:35 +0200191
Zheng Bao07648922015-11-13 10:42:27 +0800192strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
Martin Rothbbf13992016-01-25 15:59:24 -0700193# fix makefile syntax highlighting after strip macro \" "))
Patrick Georgia84e98b2010-03-16 19:01:32 +0000194
Patrick Georgi0588d192009-08-12 15:00:51 +0000195# The primary target needs to be here before we include the
196# other files
197
Patrick Georgi71b84802011-02-22 14:35:05 +0000198real-all: real-target
Patrick Georgi0588d192009-08-12 15:00:51 +0000199
Patrick Georgi51e142f2010-03-27 17:18:39 +0000200# must come rather early
Raul E Rangeldd6efce2022-02-25 17:03:10 -0700201.SECONDARY:
Patrick Georgi51e142f2010-03-27 17:18:39 +0000202.SECONDEXPANSION:
Raul E Rangelcc6dc902018-08-06 16:13:32 -0600203.DELETE_ON_ERROR:
Patrick Georgi51e142f2010-03-27 17:18:39 +0000204
Jonathan Neuschäferd2c02422018-12-11 13:06:40 +0100205$(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
Patrick Georgi53ea1d42019-11-22 16:55:58 +0100206 $(MAKE) olddefconfig
207 $(MAKE) syncconfig
Patrick Georgi0588d192009-08-12 15:00:51 +0000208
Nico Huber533bc0a2019-01-01 19:03:33 +0100209$(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
210 true
211
Nico Hubereafc8152019-10-25 12:47:14 +0200212$(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
Nico Huber533bc0a2019-01-01 19:03:33 +0100213 $(objutil)/kconfig/toada CB.Config <$< >$@
214
Nico Huberb5679772019-01-01 22:06:01 +0100215$(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
216 cp $< $@
217
Patrick Georgi58262652011-02-17 20:47:49 +0000218# Add a new class of source/object files to the build system
219add-class= \
220 $(eval $(1)-srcs:=) \
221 $(eval $(1)-objs:=) \
222 $(eval classes+=$(1))
Patrick Georgi8463dd92010-09-30 16:55:02 +0000223
Patrick Georgi58262652011-02-17 20:47:49 +0000224# Special classes are managed types with special behaviour
225# On parse time, for each entry in variable $(1)-y
226# a handler $(1)-handler is executed with the arguments:
227# * $(1): directory the parser is in
228# * $(2): current entry
229add-special-class= \
230 $(eval $(1):=) \
231 $(eval special-classes+=$(1))
232
Nico Huber81b09f42016-01-23 00:50:00 +0100233# Converts one or more source file paths to their corresponding build/ paths.
Nico Huber2e09d2b2016-01-14 01:13:33 +0100234# Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
235# their name.
Nico Huber81b09f42016-01-23 00:50:00 +0100236# $1 stage name
237# $2 file path (list)
Nico Huber98fc4262016-01-23 01:24:33 +0100238src-to-obj=\
239 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
240 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200241 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber98fc4262016-01-23 01:24:33 +0100242 $(patsubst src/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100243 $(patsubst %.ads,%.o,\
244 $(patsubst %.adb,%.o,\
Nico Huber98fc4262016-01-23 01:24:33 +0100245 $(patsubst %.c,%.o,\
246 $(patsubst %.S,%.o,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200247 $(subst .$(1),,$(2))))))))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100248
249# Converts one or more source file paths to the corresponding build/ paths
250# of their Ada library information (.ali) files.
251# $1 stage name
252# $2 file path (list)
253src-to-ali=\
254 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
255 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200256 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100257 $(patsubst src/%,$(obj)/%,\
258 $(patsubst %.ads,%.ali,\
259 $(patsubst %.adb,%.ali,\
260 $(subst .$(1),,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200261 $(filter %.ads %.adb,$(2)))))))))
Nico Huber81b09f42016-01-23 00:50:00 +0100262
Patrick Georgi47d68d82010-03-06 21:18:43 +0000263# Clean -y variables, include Makefile.inc
Patrick Georgi8463dd92010-09-30 16:55:02 +0000264# Add paths to files in X-y to X-srcs
Patrick Georgi47d68d82010-03-06 21:18:43 +0000265# Add subdirs-y to subdirs
266includemakefiles= \
Patrick Georgi58262652011-02-17 20:47:49 +0000267 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
Patrick Georgi47d68d82010-03-06 21:18:43 +0000268 $(eval -include $(1)) \
Patrick Georgi58262652011-02-17 20:47:49 +0000269 $(foreach class,$(classes-y), $(call add-class,$(class))) \
Arthur Heymans5e5fd412019-06-04 13:16:28 +0200270 $(foreach special,$(special-classes), \
271 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
Patrick Georgi58262652011-02-17 20:47:49 +0000272 $(foreach class,$(classes), \
273 $(eval $(class)-srcs+= \
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -0700274 $$(subst $(absobj)/,$(obj)/, \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000275 $$(subst $(top)/,, \
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -0700276 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
Patrick Georgi64b8fba2017-10-28 05:26:01 -0400277 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
Patrick Georgi47d68d82010-03-06 21:18:43 +0000278
Patrick Georgi8463dd92010-09-30 16:55:02 +0000279# For each path in $(subdirs) call includemakefiles
Patrick Georgi47d68d82010-03-06 21:18:43 +0000280# Repeat until subdirs is empty
281evaluate_subdirs= \
282 $(eval cursubdirs:=$(subdirs)) \
283 $(eval subdirs:=) \
284 $(foreach dir,$(cursubdirs), \
Patrick Georgi58262652011-02-17 20:47:49 +0000285 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000286 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000287
288# collect all object files eligible for building
Patrick Georgie38d0a62011-03-01 08:09:22 +0000289subdirs:=$(TOPLEVEL)
Julius Wernere91d1702017-03-20 15:32:15 -0700290postinclude-hooks :=
Jan Dabrosef1c9682020-03-28 00:15:03 +0100291
292# Don't iterate through Makefile.incs under src/ when building tests
293ifneq ($(UNIT_TEST),1)
Patrick Georgi51e142f2010-03-27 17:18:39 +0000294$(eval $(call evaluate_subdirs))
Jan Dabrosef1c9682020-03-28 00:15:03 +0100295else
296include $(TOPLEVEL)/tests/Makefile.inc
297endif
298
Patrick Georgi70c85ea2013-02-16 01:06:57 +0100299ifeq ($(FAILBUILD),1)
300$(error cannot continue build)
301endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000302
Julius Wernere91d1702017-03-20 15:32:15 -0700303# Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
304$(eval $(postinclude-hooks))
305
Patrick Georgi94a45862011-10-25 14:32:21 -0700306# Eliminate duplicate mentions of source files in a class
307$(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
308
Nico Huberb5679772019-01-01 22:06:01 +0100309# Build Kconfig .ads if necessary
310ifeq ($(CONFIG_RAMSTAGE_ADA),y)
311ramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
312endif
313
Nico Huber2e09d2b2016-01-14 01:13:33 +0100314# To track dependencies, we need all Ada specification (.ads) files in
315# *-srcs. Extract / filter all specification files that have a matching
316# body (.adb) file here (specifications without a body are valid sources
317# in Ada).
318$(foreach class,$(classes),$(eval $(class)-extra-specs := \
319 $(filter \
320 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
321 $(filter %.ads,$($(class)-srcs)))))
322$(foreach class,$(classes),$(eval $(class)-srcs := \
323 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
324
Patrick Georgi10f86b02015-03-27 16:56:23 +0100325$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100326$(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
327
328# For Ada includes
329$(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
Patrick Georgid3428b02010-02-24 13:18:01 +0000330
Nico Huber963bed52013-05-15 11:47:51 +0200331# Save all objs before processing them (for dependency inclusion)
332originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
333
Patrick Georgi79f90102012-11-25 14:31:08 +0100334# Call post-processors if they're defined
335$(foreach class,$(classes),\
336 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
337
Patrick Georgi58262652011-02-17 20:47:49 +0000338allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
339allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000340alldirs:=$(sort $(abspath $(dir $(allobjs))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000341
Nico Huber2e09d2b2016-01-14 01:13:33 +0100342# Reads dependencies from an Ada library information (.ali) file
343# Only basenames (with suffix) are preserved so we have to look the
344# paths up in $($(stage)-srcs).
345# $1 stage name
346# $2 ali file
347create_ada_deps=$$(if $(2),\
348 gnat.adc \
349 $$(filter \
350 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
351 $$($(1)-srcs) $$($(1)-extra-specs)))
352
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000353# macro to define template macros that are used by use_template macro
354define create_cc_template
Patrick Georgi71b84802011-02-22 14:35:05 +0000355# $1 obj class
Patrick Georgi990e7c92015-04-03 10:47:15 +0200356# $2 source suffix (c, S, ld, ...)
Marc Jonesa38ccfd2014-11-06 15:50:22 -0700357# $3 additional compiler flags
358# $4 additional dependencies
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000359ifn$(EMPTY)def $(1)-objs_$(2)_template
Patrick Georgi8463dd92010-09-30 16:55:02 +0000360de$(EMPTY)fine $(1)-objs_$(2)_template
Nico Huber1850aa62017-09-03 23:42:58 +0200361ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
Nico Huberb5679772019-01-01 22:06:01 +0100362$$(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 +0200363 @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
364 $(GCC_$(1)) \
365 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
366 $(3) -c -o $$$$@ $$$$<
367el$(EMPTY)se
368$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000369 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
Nico Huber2e09d2b2016-01-14 01:13:33 +0100370 $(CC_$(1)) \
Nico Huber1850aa62017-09-03 23:42:58 +0200371 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100372 $(3) -c -o $$$$@ $$$$<
Nico Huber1850aa62017-09-03 23:42:58 +0200373end$(EMPTY)if
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000374en$(EMPTY)def
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000375end$(EMPTY)if
Patrick Georgi0588d192009-08-12 15:00:51 +0000376endef
377
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000378filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
379$(foreach class,$(classes), \
380 $(foreach type,$(call filetypes-of-class,$(class)), \
Patrick Georgi2459aee2015-03-27 15:27:21 +0100381 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
Patrick Georgi416ab382015-04-03 10:19:38 +0200382 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
383 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000384
Patrick Georgid69839b2015-04-03 10:32:17 +0200385foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
Patrick Georgi58262652011-02-17 20:47:49 +0000386$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000387
Nico Huber2e09d2b2016-01-14 01:13:33 +0100388# To supported complex package initializations, we need to call the
389# emitted code explicitly. gnatbind gathers all the calls for us
390# and exports them as a procedure $(stage)_adainit(). Every stage that
391# uses Ada code has to call it!
392define gnatbind_template
393# $1 class
394$$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
395 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
396 # We have to give gnatbind a simple filename (without leading
397 # path components) so just cd there.
398 cd $$(dir $$@) && \
399 $$(GNATBIND_$(1)) -a -n \
Nico Huberbe5492a2015-09-29 16:41:19 +0200400 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100401 -L$(1)_ada -o $$(notdir $$@) \
402 $$(subst $$(dir $$@),,$$^)
403$$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
Nico Huber1850aa62017-09-03 23:42:58 +0200404 @printf " GCC $$(subst $$(obj)/,,$$@)\n"
405 $(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
Nico Huber2e09d2b2016-01-14 01:13:33 +0100406$(1)-objs += $$(obj)/$(1)/b__$(1).o
Nico Huberddb24652016-09-19 11:50:04 +0200407$($(1)-alis): %.ali: %.o ;
Nico Huber2e09d2b2016-01-14 01:13:33 +0100408endef
409
Nico Huberbe5492a2015-09-29 16:41:19 +0200410$(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100411 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
412
Julius Wernerf97b88b2014-12-05 12:32:09 -0800413DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000414-include $(DEPENDENCIES)
415
Patrick Georgi0588d192009-08-12 15:00:51 +0000416printall:
Martin Roth09b64442016-06-05 10:52:43 -0600417 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
418 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
419 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
420 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
421 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
Patrick Georgi0588d192009-08-12 15:00:51 +0000422endif
423
Patrick Georgi40ad8422011-05-21 22:18:59 +0000424ifndef NOMKDIR
Stefan Reinauerde60c882015-06-29 14:44:37 -0700425$(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
Patrick Georgi40ad8422011-05-21 22:18:59 +0000426endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000427
Martin Roth9b0204d2017-09-18 09:25:18 -0600428$(obj)/project_filelist.txt:
429 if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
430 echo "*** Error: Project must be built before generating file list ***"; \
431 exit 1; \
432 fi
Martin Roth8a027272017-09-26 09:53:30 -0600433 find $(obj) -path "$(obj)/util" -prune -o -name "*.d" -exec cat {} \; | \
434 sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
Martin Roth9c1b33e2015-07-29 14:55:18 -0700435 grep -v '\.o$$' > $(obj)/project_filelist.txt
436
Martin Roth9b0204d2017-09-18 09:25:18 -0600437filelist: $(obj)/project_filelist.txt
Martin Rotha18353d2017-06-06 06:44:46 -0600438 printf "\nFiles used in build:\n"
439 cat $(obj)/project_filelist.txt
440
Martin Roth9c1b33e2015-07-29 14:55:18 -0700441#works with either exuberant ctags or ctags.emacs
442ctags-project: clean-ctags $(obj)/project_filelist.txt
443 cat $(obj)/project_filelist.txt | \
444 xargs ctags -o tags
445
446cscope-project: clean-cscope $(obj)/project_filelist.txt
447 cat $(obj)/project_filelist.txt | xargs cscope -b
448
Warren Turkala9fc3302010-09-03 08:57:32 +0000449cscope:
450 cscope -bR
451
Patrick Rudolphf6643212020-05-17 20:04:12 +0200452sphinx:
453 $(MAKE) -C Documentation -f Makefile.sphinx html
454
455sphinx-lint:
456 $(MAKE) SPHINXOPTS=-W -C Documentation -f Makefile.sphinx html
457
Martin Roth619086d2022-05-09 18:48:24 -0600458clean-for-update:
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100459 rm -rf $(obj) .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000460
Arthur Heymansf91366f2022-03-25 16:01:05 +0100461clean: clean-for-update clean-utils clean-payloads
Patrick Georgi71b84802011-02-22 14:35:05 +0000462 rm -f .ccwrap
Warren Turkal0e8f2042010-09-27 21:14:19 +0000463
Warren Turkala9fc3302010-09-03 08:57:32 +0000464clean-cscope:
465 rm -f cscope.out
466
Martin Roth9c1b33e2015-07-29 14:55:18 -0700467clean-ctags:
468 rm -f tags
469
Martin Roth20cd54f2017-03-26 18:49:02 -0600470clean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600471 $(foreach tool, $(TOOLLIST), \
472 $(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
Martin Roth20cd54f2017-03-26 18:49:02 -0600473
474distclean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600475 $(foreach tool, $(TOOLLIST), \
476 $(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
Martin Roth20cd54f2017-03-26 18:49:02 -0600477 rm -f /util/$(tool)/junit.xml;)
478
479distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
Patrick Georgi80656af2017-04-26 11:58:44 +0200480 rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
Martin Roth20cd54f2017-03-26 18:49:02 -0600481 rm -rf coreboot-builds coreboot-builds-chromeos
482 rm -f abuild*.xml junit.xml* util/lint/junit.xml
Patrick Georgi0588d192009-08-12 15:00:51 +0000483
Martin Roth619086d2022-05-09 18:48:24 -0600484.PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean sphinx sphinx-lint
Martin Roth9c1b33e2015-07-29 14:55:18 -0700485.PHONY: ctags-project cscope-project clean-ctags