blob: 8c0369c1d2958bf1486754670514870efc74e7ae [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
Nico Huber7a1fbdb2017-08-23 23:48:13 +020034
35COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
36COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
37COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_STRICT
Nico Huber533bc0a2019-01-01 19:03:33 +010038COREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE
Patrick Georgi0588d192009-08-12 15:00:51 +000039
Patrick Georgie38d0a62011-03-01 08:09:22 +000040# directory containing the toplevel Makefile.inc
41TOPLEVEL := .
42
Patrick Georgi0588d192009-08-12 15:00:51 +000043CONFIG_SHELL := sh
44KBUILD_DEFCONFIG := configs/defconfig
45UNAME_RELEASE := $(shell uname -r)
Patrick Georgi89ec3762010-12-08 19:58:30 +000046HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
Patrick Georgi0588d192009-08-12 15:00:51 +000047MAKEFLAGS += -rR --no-print-directory
48
49# Make is silent per default, but 'make V=1' will show all compiler calls.
Patrick Georgi2b7418e2009-08-25 19:38:46 +000050Q:=@
Patrick Georgi0588d192009-08-12 15:00:51 +000051ifneq ($(V),1)
Patrick Georgi2b7418e2009-08-25 19:38:46 +000052ifneq ($(Q),)
53.SILENT:
Nico Huber7325ac52020-02-16 11:47:52 +010054MAKEFLAGS += -s
Martin Rothea6a93f2021-11-21 08:42:04 -070055quiet_errors := 2>/dev/null
Patrick Georgi2b7418e2009-08-25 19:38:46 +000056endif
Patrick Georgi0588d192009-08-12 15:00:51 +000057endif
58
Julius Werner808a4292015-03-13 11:05:07 -070059# Disable implicit/built-in rules to make Makefile errors fail fast.
60.SUFFIXES:
61
Patrick Georgib3a18ac2012-09-13 22:13:33 +020062HOSTCFLAGS := -g
63HOSTCXXFLAGS := -g
Patrick Georgi0588d192009-08-12 15:00:51 +000064
Patrick Georgi828e0e82015-04-04 15:50:20 +020065PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
66
Patrick Georgi0588d192009-08-12 15:00:51 +000067DOXYGEN := doxygen
68DOXYGEN_OUTPUT_DIR := doxygen
69
Nico Huber7a1fbdb2017-08-23 23:48:13 +020070export $(COREBOOT_EXPORTS)
71
Patrick Georgi71b84802011-02-22 14:35:05 +000072all: real-all
73
Martin Roth4eea1742015-11-25 11:50:04 -070074help_coreboot help::
75 @echo '*** coreboot platform targets ***'
Martin Roth76f14b22015-11-18 13:09:23 -070076 @echo ' Use "make [target] V=1" for extra build debug information'
77 @echo ' all - Build coreboot'
78 @echo ' clean - Remove coreboot build artifacts'
79 @echo ' distclean - Remove build artifacts and config files'
80 @echo ' doxygen - Build doxygen documentation for coreboot'
Martin Rothb1574e32016-07-07 15:50:28 -060081 @echo ' doxyplatform - Build doxygen documentation for the current platform'
Patrick Rudolphf6643212020-05-17 20:04:12 +020082 @echo ' sphinx - Build sphinx documentation for coreboot'
83 @echo ' sphinx-lint - Build sphinx documenttion for coreboot with warnings as errors'
Martin Roth763e4932018-01-27 16:42:43 -070084 @echo ' filelist - Show files used in current build'
Martin Roth76f14b22015-11-18 13:09:23 -070085 @echo ' printall - print makefile info for debugging'
Werner Zeh2de64102016-01-12 12:45:49 +010086 @echo ' gitconfig - set up git to submit patches to coreboot'
Martin Roth76f14b22015-11-18 13:09:23 -070087 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
88 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
89 @echo
90
Patrick Georgie38d0a62011-03-01 08:09:22 +000091# This include must come _before_ the pattern rules below!
Patrick Georgi71b84802011-02-22 14:35:05 +000092# Order _does_ matter for pattern rules.
Patrick Georgi3e8ef102019-11-22 16:54:17 +010093include $(srck)/Makefile.inc
Patrick Georgi71b84802011-02-22 14:35:05 +000094
Patrick Georgicf036d12010-04-21 06:36:20 +000095# Three cases where we don't need fully populated $(obj) lists:
96# 1. when no .config exists
97# 2. when make config (in any flavour) is run
98# 3. when make distclean is run
99# Don't waste time on reading all Makefile.incs in these cases
Patrick Georgi0588d192009-08-12 15:00:51 +0000100ifeq ($(strip $(HAVE_DOTCONFIG)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000101NOCOMPILE:=1
102endif
103ifneq ($(MAKECMDGOALS),)
Elyes HAOUAS91fb1392020-01-20 15:33:11 +0100104ifneq ($(filter %config %clean cross% clang iasl lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000105NOCOMPILE:=1
106endif
Raul E Rangel5592cfd2019-07-23 11:13:40 -0600107ifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
Zheng Bao0fd93d62012-10-22 16:36:03 +0800108NOMKDIR:=1
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200109UNIT_TEST:=1
Zheng Bao0fd93d62012-10-22 16:36:03 +0800110endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000111endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000112
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200113ifneq ($(filter help%, $(MAKECMDGOALS)), )
114NOCOMPILE:=1
115UNIT_TEST:=1
116else
Paul Fagerburgde6cbac2021-05-11 09:56:48 -0600117ifneq ($(filter %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
118ifneq ($(filter-out %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
Jan Dabrosef1c9682020-03-28 00:15:03 +0100119$(error Cannot mix unit-tests targets with other targets)
120endif
121UNIT_TEST:=1
122NOCOMPILE:=
123endif
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200124endif
Jan Dabrosef1c9682020-03-28 00:15:03 +0100125
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600126$(xcompile): util/xcompile/xcompile
Raul E Rangel6325ce22019-07-10 16:46:34 -0600127 rm -f $@
128 $< $(XGCCPATH) > $@.tmp
129 \mv -f $@.tmp $@ 2> /dev/null
130 rm -f $@.tmp
131
Patrick Georgicf036d12010-04-21 06:36:20 +0000132ifeq ($(NOCOMPILE),1)
Patrick Georgib351875f2020-07-06 15:31:58 +0000133# We also don't use .xcompile in the no-compile situations, so
134# provide some reasonable defaults.
135HOSTCC ?= $(if $(shell type gcc 2>/dev/null),gcc,cc)
136HOSTCXX ?= g++
137
Patrick Georgie38d0a62011-03-01 08:09:22 +0000138include $(TOPLEVEL)/Makefile.inc
Martin Roth67975572016-03-07 16:38:52 -0700139include $(TOPLEVEL)/payloads/Makefile.inc
Martin Rothe624e272017-07-31 11:52:58 -0600140include $(TOPLEVEL)/util/testing/Makefile.inc
Werner Zehb7f1c2d2019-10-04 07:01:13 +0200141-include $(TOPLEVEL)/site-local/Makefile.inc
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200142include $(TOPLEVEL)/tests/Makefile.inc
Martin Roth20aa0432017-01-26 10:51:43 -0700143real-all:
144 @echo "Error: Expected config file ($(DOTCONFIG)) not present." >&2
145 @echo "Please specify a config file or run 'make menuconfig' to" >&2
146 @echo "generate a new config file." >&2
147 @exit 1
Patrick Georgi0588d192009-08-12 15:00:51 +0000148else
149
Jan Dabrosef1c9682020-03-28 00:15:03 +0100150ifneq ($(UNIT_TEST),1)
Paul Kocialkowski585c7812016-07-13 11:00:41 +0200151include $(DOTCONFIG)
Jan Dabrosef1c9682020-03-28 00:15:03 +0100152endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000153
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600154# The toolchain requires xcompile to determine the ARCH_SUPPORTED, so we can't
155# wait for make to generate the file.
156$(if $(wildcard $(xcompile)),, $(shell \
157 mkdir -p $(dir $(xcompile)) && \
158 util/xcompile/xcompile $(XGCCPATH) > $(xcompile) || rm -f $(xcompile)))
Patrick Georgi0ffef882017-01-19 23:20:14 +0100159
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600160include $(xcompile)
Patrick Georgi6dda31d2015-11-19 15:15:33 +0100161
162ifneq ($(XCOMPILE_COMPLETE),1)
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600163$(shell rm -f $(xcompile))
164$(error $(xcompile) deleted because it's invalid. \
Patrick Georgi6dda31d2015-11-19 15:15:33 +0100165 Restarting the build should fix that, or explain the problem)
166endif
Patrick Georgi7b9762f2015-06-04 13:18:11 +0200167
Patrick Georgica6e5ee2021-04-13 15:48:38 +0200168# reproducible builds
169LANG:=C
170LC_ALL:=C
171TZ:=UTC0
172ifneq ($(NOCOMPILE),1)
173SOURCE_DATE_EPOCH := $(shell $(top)/util/genbuild_h/genbuild_h.sh . | sed -n 's/^.define COREBOOT_BUILD_EPOCH\>.*"\(.*\)".*/\1/p')
174endif
175# don't use COREBOOT_EXPORTS to ensure build steps outside the coreboot build system
176# are reproducible
177export LANG LC_ALL TZ SOURCE_DATE_EPOCH
178
Patrick Georgicc84a002014-05-14 21:05:35 +0200179ifneq ($(CONFIG_MMX),y)
180CFLAGS_x86_32 += -mno-mmx
181endif
182
Jan Dabrosef1c9682020-03-28 00:15:03 +0100183ifneq ($(UNIT_TEST),1)
Patrick Georgicc84a002014-05-14 21:05:35 +0200184include toolchain.inc
Jan Dabrosef1c9682020-03-28 00:15:03 +0100185endif
Patrick Georgicc84a002014-05-14 21:05:35 +0200186
Zheng Bao07648922015-11-13 10:42:27 +0800187strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
Martin Rothbbf13992016-01-25 15:59:24 -0700188# fix makefile syntax highlighting after strip macro \" "))
Patrick Georgia84e98b2010-03-16 19:01:32 +0000189
Patrick Georgi0588d192009-08-12 15:00:51 +0000190# The primary target needs to be here before we include the
191# other files
192
Patrick Georgi71b84802011-02-22 14:35:05 +0000193real-all: real-target
Patrick Georgi0588d192009-08-12 15:00:51 +0000194
Patrick Georgi51e142f2010-03-27 17:18:39 +0000195# must come rather early
Raul E Rangeldd6efce2022-02-25 17:03:10 -0700196.SECONDARY:
Patrick Georgi51e142f2010-03-27 17:18:39 +0000197.SECONDEXPANSION:
Raul E Rangelcc6dc902018-08-06 16:13:32 -0600198.DELETE_ON_ERROR:
Patrick Georgi51e142f2010-03-27 17:18:39 +0000199
Jonathan Neuschäferd2c02422018-12-11 13:06:40 +0100200$(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
Patrick Georgi53ea1d42019-11-22 16:55:58 +0100201 $(MAKE) olddefconfig
202 $(MAKE) syncconfig
Patrick Georgi0588d192009-08-12 15:00:51 +0000203
Nico Huber533bc0a2019-01-01 19:03:33 +0100204$(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
205 true
206
Nico Hubereafc8152019-10-25 12:47:14 +0200207$(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
Nico Huber533bc0a2019-01-01 19:03:33 +0100208 $(objutil)/kconfig/toada CB.Config <$< >$@
209
Nico Huberb5679772019-01-01 22:06:01 +0100210$(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
211 cp $< $@
212
Patrick Georgi58262652011-02-17 20:47:49 +0000213# Add a new class of source/object files to the build system
214add-class= \
215 $(eval $(1)-srcs:=) \
216 $(eval $(1)-objs:=) \
217 $(eval classes+=$(1))
Patrick Georgi8463dd92010-09-30 16:55:02 +0000218
Patrick Georgi58262652011-02-17 20:47:49 +0000219# Special classes are managed types with special behaviour
220# On parse time, for each entry in variable $(1)-y
221# a handler $(1)-handler is executed with the arguments:
222# * $(1): directory the parser is in
223# * $(2): current entry
224add-special-class= \
225 $(eval $(1):=) \
226 $(eval special-classes+=$(1))
227
Nico Huber81b09f42016-01-23 00:50:00 +0100228# Converts one or more source file paths to their corresponding build/ paths.
Nico Huber2e09d2b2016-01-14 01:13:33 +0100229# Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
230# their name.
Nico Huber81b09f42016-01-23 00:50:00 +0100231# $1 stage name
232# $2 file path (list)
Nico Huber98fc4262016-01-23 01:24:33 +0100233src-to-obj=\
234 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
235 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200236 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber98fc4262016-01-23 01:24:33 +0100237 $(patsubst src/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100238 $(patsubst %.ads,%.o,\
239 $(patsubst %.adb,%.o,\
Nico Huber98fc4262016-01-23 01:24:33 +0100240 $(patsubst %.c,%.o,\
241 $(patsubst %.S,%.o,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200242 $(subst .$(1),,$(2))))))))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100243
244# Converts one or more source file paths to the corresponding build/ paths
245# of their Ada library information (.ali) files.
246# $1 stage name
247# $2 file path (list)
248src-to-ali=\
249 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
250 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200251 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100252 $(patsubst src/%,$(obj)/%,\
253 $(patsubst %.ads,%.ali,\
254 $(patsubst %.adb,%.ali,\
255 $(subst .$(1),,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200256 $(filter %.ads %.adb,$(2)))))))))
Nico Huber81b09f42016-01-23 00:50:00 +0100257
Patrick Georgi47d68d82010-03-06 21:18:43 +0000258# Clean -y variables, include Makefile.inc
Patrick Georgi8463dd92010-09-30 16:55:02 +0000259# Add paths to files in X-y to X-srcs
Patrick Georgi47d68d82010-03-06 21:18:43 +0000260# Add subdirs-y to subdirs
261includemakefiles= \
Patrick Georgi58262652011-02-17 20:47:49 +0000262 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
Patrick Georgi47d68d82010-03-06 21:18:43 +0000263 $(eval -include $(1)) \
Patrick Georgi58262652011-02-17 20:47:49 +0000264 $(foreach class,$(classes-y), $(call add-class,$(class))) \
Arthur Heymans5e5fd412019-06-04 13:16:28 +0200265 $(foreach special,$(special-classes), \
266 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
Patrick Georgi58262652011-02-17 20:47:49 +0000267 $(foreach class,$(classes), \
268 $(eval $(class)-srcs+= \
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -0700269 $$(subst $(absobj)/,$(obj)/, \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000270 $$(subst $(top)/,, \
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -0700271 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
Patrick Georgi64b8fba2017-10-28 05:26:01 -0400272 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
Patrick Georgi47d68d82010-03-06 21:18:43 +0000273
Patrick Georgi8463dd92010-09-30 16:55:02 +0000274# For each path in $(subdirs) call includemakefiles
Patrick Georgi47d68d82010-03-06 21:18:43 +0000275# Repeat until subdirs is empty
276evaluate_subdirs= \
277 $(eval cursubdirs:=$(subdirs)) \
278 $(eval subdirs:=) \
279 $(foreach dir,$(cursubdirs), \
Patrick Georgi58262652011-02-17 20:47:49 +0000280 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000281 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000282
283# collect all object files eligible for building
Patrick Georgie38d0a62011-03-01 08:09:22 +0000284subdirs:=$(TOPLEVEL)
Julius Wernere91d1702017-03-20 15:32:15 -0700285postinclude-hooks :=
Jan Dabrosef1c9682020-03-28 00:15:03 +0100286
287# Don't iterate through Makefile.incs under src/ when building tests
288ifneq ($(UNIT_TEST),1)
Patrick Georgi51e142f2010-03-27 17:18:39 +0000289$(eval $(call evaluate_subdirs))
Jan Dabrosef1c9682020-03-28 00:15:03 +0100290else
291include $(TOPLEVEL)/tests/Makefile.inc
292endif
293
Patrick Georgi70c85ea2013-02-16 01:06:57 +0100294ifeq ($(FAILBUILD),1)
295$(error cannot continue build)
296endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000297
Julius Wernere91d1702017-03-20 15:32:15 -0700298# Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
299$(eval $(postinclude-hooks))
300
Patrick Georgi94a45862011-10-25 14:32:21 -0700301# Eliminate duplicate mentions of source files in a class
302$(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
303
Nico Huberb5679772019-01-01 22:06:01 +0100304# Build Kconfig .ads if necessary
305ifeq ($(CONFIG_RAMSTAGE_ADA),y)
306ramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
307endif
308
Nico Huber2e09d2b2016-01-14 01:13:33 +0100309# To track dependencies, we need all Ada specification (.ads) files in
310# *-srcs. Extract / filter all specification files that have a matching
311# body (.adb) file here (specifications without a body are valid sources
312# in Ada).
313$(foreach class,$(classes),$(eval $(class)-extra-specs := \
314 $(filter \
315 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
316 $(filter %.ads,$($(class)-srcs)))))
317$(foreach class,$(classes),$(eval $(class)-srcs := \
318 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
319
Patrick Georgi10f86b02015-03-27 16:56:23 +0100320$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100321$(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
322
323# For Ada includes
324$(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
Patrick Georgid3428b02010-02-24 13:18:01 +0000325
Nico Huber963bed52013-05-15 11:47:51 +0200326# Save all objs before processing them (for dependency inclusion)
327originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
328
Patrick Georgi79f90102012-11-25 14:31:08 +0100329# Call post-processors if they're defined
330$(foreach class,$(classes),\
331 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
332
Patrick Georgi58262652011-02-17 20:47:49 +0000333allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
334allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000335alldirs:=$(sort $(abspath $(dir $(allobjs))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000336
Nico Huber2e09d2b2016-01-14 01:13:33 +0100337# Reads dependencies from an Ada library information (.ali) file
338# Only basenames (with suffix) are preserved so we have to look the
339# paths up in $($(stage)-srcs).
340# $1 stage name
341# $2 ali file
342create_ada_deps=$$(if $(2),\
343 gnat.adc \
344 $$(filter \
345 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
346 $$($(1)-srcs) $$($(1)-extra-specs)))
347
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000348# macro to define template macros that are used by use_template macro
349define create_cc_template
Patrick Georgi71b84802011-02-22 14:35:05 +0000350# $1 obj class
Patrick Georgi990e7c92015-04-03 10:47:15 +0200351# $2 source suffix (c, S, ld, ...)
Marc Jonesa38ccfd2014-11-06 15:50:22 -0700352# $3 additional compiler flags
353# $4 additional dependencies
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000354ifn$(EMPTY)def $(1)-objs_$(2)_template
Patrick Georgi8463dd92010-09-30 16:55:02 +0000355de$(EMPTY)fine $(1)-objs_$(2)_template
Nico Huber1850aa62017-09-03 23:42:58 +0200356ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
Nico Huberb5679772019-01-01 22:06:01 +0100357$$(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 +0200358 @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
359 $(GCC_$(1)) \
360 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
361 $(3) -c -o $$$$@ $$$$<
362el$(EMPTY)se
363$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000364 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
Nico Huber2e09d2b2016-01-14 01:13:33 +0100365 $(CC_$(1)) \
Nico Huber1850aa62017-09-03 23:42:58 +0200366 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100367 $(3) -c -o $$$$@ $$$$<
Nico Huber1850aa62017-09-03 23:42:58 +0200368end$(EMPTY)if
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000369en$(EMPTY)def
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000370end$(EMPTY)if
Patrick Georgi0588d192009-08-12 15:00:51 +0000371endef
372
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000373filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
374$(foreach class,$(classes), \
375 $(foreach type,$(call filetypes-of-class,$(class)), \
Patrick Georgi2459aee2015-03-27 15:27:21 +0100376 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
Patrick Georgi416ab382015-04-03 10:19:38 +0200377 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
378 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000379
Patrick Georgid69839b2015-04-03 10:32:17 +0200380foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
Patrick Georgi58262652011-02-17 20:47:49 +0000381$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000382
Nico Huber2e09d2b2016-01-14 01:13:33 +0100383# To supported complex package initializations, we need to call the
384# emitted code explicitly. gnatbind gathers all the calls for us
385# and exports them as a procedure $(stage)_adainit(). Every stage that
386# uses Ada code has to call it!
387define gnatbind_template
388# $1 class
389$$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
390 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
391 # We have to give gnatbind a simple filename (without leading
392 # path components) so just cd there.
393 cd $$(dir $$@) && \
394 $$(GNATBIND_$(1)) -a -n \
Nico Huberbe5492a2015-09-29 16:41:19 +0200395 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100396 -L$(1)_ada -o $$(notdir $$@) \
397 $$(subst $$(dir $$@),,$$^)
398$$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
Nico Huber1850aa62017-09-03 23:42:58 +0200399 @printf " GCC $$(subst $$(obj)/,,$$@)\n"
400 $(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
Nico Huber2e09d2b2016-01-14 01:13:33 +0100401$(1)-objs += $$(obj)/$(1)/b__$(1).o
Nico Huberddb24652016-09-19 11:50:04 +0200402$($(1)-alis): %.ali: %.o ;
Nico Huber2e09d2b2016-01-14 01:13:33 +0100403endef
404
Nico Huberbe5492a2015-09-29 16:41:19 +0200405$(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100406 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
407
Julius Wernerf97b88b2014-12-05 12:32:09 -0800408DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000409-include $(DEPENDENCIES)
410
Patrick Georgi0588d192009-08-12 15:00:51 +0000411printall:
Martin Roth09b64442016-06-05 10:52:43 -0600412 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
413 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
414 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
415 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
416 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
Patrick Georgi0588d192009-08-12 15:00:51 +0000417endif
418
Patrick Georgi40ad8422011-05-21 22:18:59 +0000419ifndef NOMKDIR
Stefan Reinauerde60c882015-06-29 14:44:37 -0700420$(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
Patrick Georgi40ad8422011-05-21 22:18:59 +0000421endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000422
Martin Roth9b0204d2017-09-18 09:25:18 -0600423$(obj)/project_filelist.txt:
424 if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
425 echo "*** Error: Project must be built before generating file list ***"; \
426 exit 1; \
427 fi
Martin Roth8a027272017-09-26 09:53:30 -0600428 find $(obj) -path "$(obj)/util" -prune -o -name "*.d" -exec cat {} \; | \
429 sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
Martin Roth9c1b33e2015-07-29 14:55:18 -0700430 grep -v '\.o$$' > $(obj)/project_filelist.txt
431
Martin Roth9b0204d2017-09-18 09:25:18 -0600432filelist: $(obj)/project_filelist.txt
Martin Rotha18353d2017-06-06 06:44:46 -0600433 printf "\nFiles used in build:\n"
434 cat $(obj)/project_filelist.txt
435
Martin Roth9c1b33e2015-07-29 14:55:18 -0700436#works with either exuberant ctags or ctags.emacs
437ctags-project: clean-ctags $(obj)/project_filelist.txt
438 cat $(obj)/project_filelist.txt | \
439 xargs ctags -o tags
440
441cscope-project: clean-cscope $(obj)/project_filelist.txt
442 cat $(obj)/project_filelist.txt | xargs cscope -b
443
Warren Turkala9fc3302010-09-03 08:57:32 +0000444cscope:
445 cscope -bR
446
Patrick Rudolphf6643212020-05-17 20:04:12 +0200447sphinx:
448 $(MAKE) -C Documentation -f Makefile.sphinx html
449
450sphinx-lint:
451 $(MAKE) SPHINXOPTS=-W -C Documentation -f Makefile.sphinx html
452
Patrick Georgi0588d192009-08-12 15:00:51 +0000453doxy: doxygen
454doxygen:
Nicky Sielickie08a2a52015-06-06 08:55:16 -0500455 $(DOXYGEN) Documentation/Doxyfile.coreboot
Patrick Georgi0588d192009-08-12 15:00:51 +0000456
Martin Rothd7689e42014-12-29 14:56:19 -0700457doxygen_simple:
Nicky Sielickie08a2a52015-06-06 08:55:16 -0500458 $(DOXYGEN) Documentation/Doxyfile.coreboot_simple
Martin Rothd7689e42014-12-29 14:56:19 -0700459
Martin Rothb1574e32016-07-07 15:50:28 -0600460doxyplatform doxygen_platform: $(obj)/project_filelist.txt
461 echo
462 echo "Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
Martin Roth09e032e2020-10-25 19:44:38 -0600463 export DOXYGEN_OUTPUT_DIR="$$( echo $(DOXYGEN_OUTPUT_DIR)/$(call strip_quotes, $(CONFIG_MAINBOARD_VENDOR))_$(call strip_quotes, $(CONFIG_MAINBOARD_PART_NUMBER)) | sed 's|[^A-Za-z0-9/]|_|g' )"; \
Martin Rothb1574e32016-07-07 15:50:28 -0600464 mkdir -p "$$DOXYGEN_OUTPUT_DIR"; \
465 export DOXYFILES="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
Martin Roth09e032e2020-10-25 19:44:38 -0600466 export DOXYGEN_PLATFORM="$(call strip_quotes, $(CONFIG_MAINBOARD_DIR)) \($(call strip_quotes, $(CONFIG_MAINBOARD_PART_NUMBER))\) version $(KERNELVERSION)"; \
Martin Rothb1574e32016-07-07 15:50:28 -0600467 $(DOXYGEN) Documentation/doxygen/Doxyfile.coreboot_platform
468
Patrick Georgi0588d192009-08-12 15:00:51 +0000469doxyclean: doxygen-clean
470doxygen-clean:
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000471 rm -rf $(DOXYGEN_OUTPUT_DIR)
Patrick Georgi0588d192009-08-12 15:00:51 +0000472
Arthur Heymansf91366f2022-03-25 16:01:05 +0100473clean-for-update: doxygen-clean
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100474 rm -rf $(obj) .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000475
Arthur Heymansf91366f2022-03-25 16:01:05 +0100476clean: clean-for-update clean-utils clean-payloads
Patrick Georgi71b84802011-02-22 14:35:05 +0000477 rm -f .ccwrap
Warren Turkal0e8f2042010-09-27 21:14:19 +0000478
Warren Turkala9fc3302010-09-03 08:57:32 +0000479clean-cscope:
480 rm -f cscope.out
481
Martin Roth9c1b33e2015-07-29 14:55:18 -0700482clean-ctags:
483 rm -f tags
484
Martin Roth20cd54f2017-03-26 18:49:02 -0600485clean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600486 $(foreach tool, $(TOOLLIST), \
487 $(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
Martin Roth20cd54f2017-03-26 18:49:02 -0600488
489distclean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600490 $(foreach tool, $(TOOLLIST), \
491 $(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
Martin Roth20cd54f2017-03-26 18:49:02 -0600492 rm -f /util/$(tool)/junit.xml;)
493
494distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
Patrick Georgi80656af2017-04-26 11:58:44 +0200495 rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
Martin Roth20cd54f2017-03-26 18:49:02 -0600496 rm -rf coreboot-builds coreboot-builds-chromeos
497 rm -f abuild*.xml junit.xml* util/lint/junit.xml
Patrick Georgi0588d192009-08-12 15:00:51 +0000498
Patrick Rudolphf6643212020-05-17 20:04:12 +0200499.PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple sphinx sphinx-lint
Martin Roth9c1b33e2015-07-29 14:55:18 -0700500.PHONY: ctags-project cscope-project clean-ctags