blob: 02c6288f15bdd0a3a8d6bb8e1b1121a062d293fa [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
Alexander Couzensbe756f12019-09-13 04:22:12 +020023# reproducible builds
24LANG:=C
25LC_ALL:=C
26TZ:=UTC0
Alexander Couzenscbe2ed42021-03-09 03:31:07 +010027SOURCE_DATE_EPOCH := $(shell $(top)/util/genbuild_h/genbuild_h.sh . | sed -n 's/^.define COREBOOT_BUILD_EPOCH\>.*"\(.*\)".*/\1/p')
Alexander Couzensada431e2021-03-09 03:29:18 +010028# don't use COREBOOT_EXPORTS to ensure build steps outside the coreboot build system
29# are reproducible
Alexander Couzenscbe2ed42021-03-09 03:31:07 +010030export LANG LC_ALL TZ SOURCE_DATE_EPOCH
Alexander Couzensbe756f12019-09-13 04:22:12 +020031
Nico Huber7a1fbdb2017-08-23 23:48:13 +020032DOTCONFIG ?= $(top)/.config
33KCONFIG_CONFIG = $(DOTCONFIG)
Nico Huber533bc0a2019-01-01 19:03:33 +010034KCONFIG_AUTOADS := $(obj)/cb-config.ads
Nico Huber7a1fbdb2017-08-23 23:48:13 +020035KCONFIG_AUTOHEADER := $(obj)/config.h
36KCONFIG_AUTOCONFIG := $(obj)/auto.conf
37KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
38KCONFIG_SPLITCONFIG := $(obj)/config
39KCONFIG_TRISTATE := $(obj)/tristate.conf
40KCONFIG_NEGATIVES := 1
41KCONFIG_STRICT := 1
Nico Huber533bc0a2019-01-01 19:03:33 +010042KCONFIG_PACKAGE := CB.Config
Nico Huber7a1fbdb2017-08-23 23:48:13 +020043
44COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
45COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
46COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_STRICT
Nico Huber533bc0a2019-01-01 19:03:33 +010047COREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE
Patrick Georgi0588d192009-08-12 15:00:51 +000048
Patrick Georgie38d0a62011-03-01 08:09:22 +000049# directory containing the toplevel Makefile.inc
50TOPLEVEL := .
51
Patrick Georgi0588d192009-08-12 15:00:51 +000052CONFIG_SHELL := sh
53KBUILD_DEFCONFIG := configs/defconfig
54UNAME_RELEASE := $(shell uname -r)
Patrick Georgi89ec3762010-12-08 19:58:30 +000055HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
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
Patrick Georgi2b7418e2009-08-25 19:38:46 +000064endif
Patrick Georgi0588d192009-08-12 15:00:51 +000065endif
66
Julius Werner808a4292015-03-13 11:05:07 -070067# Disable implicit/built-in rules to make Makefile errors fail fast.
68.SUFFIXES:
69
Patrick Georgib3a18ac2012-09-13 22:13:33 +020070HOSTCFLAGS := -g
71HOSTCXXFLAGS := -g
Patrick Georgi0588d192009-08-12 15:00:51 +000072
Patrick Georgi828e0e82015-04-04 15:50:20 +020073PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
74
Patrick Georgi0588d192009-08-12 15:00:51 +000075DOXYGEN := doxygen
76DOXYGEN_OUTPUT_DIR := doxygen
77
Nico Huber7a1fbdb2017-08-23 23:48:13 +020078export $(COREBOOT_EXPORTS)
79
Patrick Georgi71b84802011-02-22 14:35:05 +000080all: real-all
81
Martin Roth4eea1742015-11-25 11:50:04 -070082help_coreboot help::
83 @echo '*** coreboot platform targets ***'
Martin Roth76f14b22015-11-18 13:09:23 -070084 @echo ' Use "make [target] V=1" for extra build debug information'
85 @echo ' all - Build coreboot'
86 @echo ' clean - Remove coreboot build artifacts'
87 @echo ' distclean - Remove build artifacts and config files'
88 @echo ' doxygen - Build doxygen documentation for coreboot'
Martin Rothb1574e32016-07-07 15:50:28 -060089 @echo ' doxyplatform - Build doxygen documentation for the current platform'
Patrick Rudolphf6643212020-05-17 20:04:12 +020090 @echo ' sphinx - Build sphinx documentation for coreboot'
91 @echo ' sphinx-lint - Build sphinx documenttion for coreboot with warnings as errors'
Martin Roth763e4932018-01-27 16:42:43 -070092 @echo ' filelist - Show files used in current build'
Martin Roth76f14b22015-11-18 13:09:23 -070093 @echo ' printall - print makefile info for debugging'
Werner Zeh2de64102016-01-12 12:45:49 +010094 @echo ' gitconfig - set up git to submit patches to coreboot'
Martin Roth76f14b22015-11-18 13:09:23 -070095 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
96 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
97 @echo
98
Patrick Georgie38d0a62011-03-01 08:09:22 +000099# This include must come _before_ the pattern rules below!
Patrick Georgi71b84802011-02-22 14:35:05 +0000100# Order _does_ matter for pattern rules.
Patrick Georgi3e8ef102019-11-22 16:54:17 +0100101include $(srck)/Makefile.inc
Patrick Georgi71b84802011-02-22 14:35:05 +0000102
Patrick Georgicf036d12010-04-21 06:36:20 +0000103# Three cases where we don't need fully populated $(obj) lists:
104# 1. when no .config exists
105# 2. when make config (in any flavour) is run
106# 3. when make distclean is run
107# 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
111ifneq ($(MAKECMDGOALS),)
Elyes HAOUAS91fb1392020-01-20 15:33:11 +0100112ifneq ($(filter %config %clean cross% clang iasl lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000113NOCOMPILE:=1
114endif
Raul E Rangel5592cfd2019-07-23 11:13:40 -0600115ifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
Zheng Bao0fd93d62012-10-22 16:36:03 +0800116NOMKDIR:=1
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200117UNIT_TEST:=1
Zheng Bao0fd93d62012-10-22 16:36:03 +0800118endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000119endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000120
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200121ifneq ($(filter help%, $(MAKECMDGOALS)), )
122NOCOMPILE:=1
123UNIT_TEST:=1
124else
125ifneq ($(filter %-test %-tests, $(MAKECMDGOALS)),)
Jan Dabrosef1c9682020-03-28 00:15:03 +0100126ifneq ($(filter-out %-test %-tests, $(MAKECMDGOALS)),)
127$(error Cannot mix unit-tests targets with other targets)
128endif
129UNIT_TEST:=1
130NOCOMPILE:=
131endif
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200132endif
Jan Dabrosef1c9682020-03-28 00:15:03 +0100133
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600134$(xcompile): util/xcompile/xcompile
Raul E Rangel6325ce22019-07-10 16:46:34 -0600135 rm -f $@
136 $< $(XGCCPATH) > $@.tmp
137 \mv -f $@.tmp $@ 2> /dev/null
138 rm -f $@.tmp
139
Patrick Georgicf036d12010-04-21 06:36:20 +0000140ifeq ($(NOCOMPILE),1)
Patrick Georgib351875f2020-07-06 15:31:58 +0000141# We also don't use .xcompile in the no-compile situations, so
142# provide some reasonable defaults.
143HOSTCC ?= $(if $(shell type gcc 2>/dev/null),gcc,cc)
144HOSTCXX ?= g++
145
Patrick Georgie38d0a62011-03-01 08:09:22 +0000146include $(TOPLEVEL)/Makefile.inc
Martin Roth67975572016-03-07 16:38:52 -0700147include $(TOPLEVEL)/payloads/Makefile.inc
Martin Rothe624e272017-07-31 11:52:58 -0600148include $(TOPLEVEL)/util/testing/Makefile.inc
Werner Zehb7f1c2d2019-10-04 07:01:13 +0200149-include $(TOPLEVEL)/site-local/Makefile.inc
Jakub Czapigaa4819b32021-04-13 16:07:05 +0200150include $(TOPLEVEL)/tests/Makefile.inc
Martin Roth20aa0432017-01-26 10:51:43 -0700151real-all:
152 @echo "Error: Expected config file ($(DOTCONFIG)) not present." >&2
153 @echo "Please specify a config file or run 'make menuconfig' to" >&2
154 @echo "generate a new config file." >&2
155 @exit 1
Patrick Georgi0588d192009-08-12 15:00:51 +0000156else
157
Jan Dabrosef1c9682020-03-28 00:15:03 +0100158ifneq ($(UNIT_TEST),1)
Paul Kocialkowski585c7812016-07-13 11:00:41 +0200159include $(DOTCONFIG)
Jan Dabrosef1c9682020-03-28 00:15:03 +0100160endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000161
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600162# The toolchain requires xcompile to determine the ARCH_SUPPORTED, so we can't
163# wait for make to generate the file.
164$(if $(wildcard $(xcompile)),, $(shell \
165 mkdir -p $(dir $(xcompile)) && \
166 util/xcompile/xcompile $(XGCCPATH) > $(xcompile) || rm -f $(xcompile)))
Patrick Georgi0ffef882017-01-19 23:20:14 +0100167
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600168include $(xcompile)
Patrick Georgi6dda31d2015-11-19 15:15:33 +0100169
170ifneq ($(XCOMPILE_COMPLETE),1)
Raul E Rangel81ff33c2019-07-11 10:44:21 -0600171$(shell rm -f $(xcompile))
172$(error $(xcompile) deleted because it's invalid. \
Patrick Georgi6dda31d2015-11-19 15:15:33 +0100173 Restarting the build should fix that, or explain the problem)
174endif
Patrick Georgi7b9762f2015-06-04 13:18:11 +0200175
Patrick Georgicc84a002014-05-14 21:05:35 +0200176ifneq ($(CONFIG_MMX),y)
177CFLAGS_x86_32 += -mno-mmx
178endif
179
Jan Dabrosef1c9682020-03-28 00:15:03 +0100180ifneq ($(UNIT_TEST),1)
Patrick Georgicc84a002014-05-14 21:05:35 +0200181include toolchain.inc
Jan Dabrosef1c9682020-03-28 00:15:03 +0100182endif
Patrick Georgicc84a002014-05-14 21:05:35 +0200183
Zheng Bao07648922015-11-13 10:42:27 +0800184strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
Martin Rothbbf13992016-01-25 15:59:24 -0700185# fix makefile syntax highlighting after strip macro \" "))
Patrick Georgia84e98b2010-03-16 19:01:32 +0000186
Patrick Georgi0588d192009-08-12 15:00:51 +0000187# The primary target needs to be here before we include the
188# other files
189
Patrick Georgi71b84802011-02-22 14:35:05 +0000190real-all: real-target
Patrick Georgi0588d192009-08-12 15:00:51 +0000191
Patrick Georgi51e142f2010-03-27 17:18:39 +0000192# must come rather early
193.SECONDEXPANSION:
Raul E Rangelcc6dc902018-08-06 16:13:32 -0600194.DELETE_ON_ERROR:
Patrick Georgi51e142f2010-03-27 17:18:39 +0000195
Jonathan Neuschäferd2c02422018-12-11 13:06:40 +0100196$(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
Patrick Georgi78a5f222017-01-30 15:29:34 +0100197 +$(MAKE) oldconfig
Patrick Georgi0588d192009-08-12 15:00:51 +0000198
Nico Huber533bc0a2019-01-01 19:03:33 +0100199$(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
200 true
201
Nico Hubereafc8152019-10-25 12:47:14 +0200202$(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
Nico Huber533bc0a2019-01-01 19:03:33 +0100203 $(objutil)/kconfig/toada CB.Config <$< >$@
204
Nico Huberb5679772019-01-01 22:06:01 +0100205$(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
206 cp $< $@
207
Patrick Georgi58262652011-02-17 20:47:49 +0000208# Add a new class of source/object files to the build system
209add-class= \
210 $(eval $(1)-srcs:=) \
211 $(eval $(1)-objs:=) \
212 $(eval classes+=$(1))
Patrick Georgi8463dd92010-09-30 16:55:02 +0000213
Patrick Georgi58262652011-02-17 20:47:49 +0000214# Special classes are managed types with special behaviour
215# On parse time, for each entry in variable $(1)-y
216# a handler $(1)-handler is executed with the arguments:
217# * $(1): directory the parser is in
218# * $(2): current entry
219add-special-class= \
220 $(eval $(1):=) \
221 $(eval special-classes+=$(1))
222
Nico Huber81b09f42016-01-23 00:50:00 +0100223# Converts one or more source file paths to their corresponding build/ paths.
Nico Huber2e09d2b2016-01-14 01:13:33 +0100224# Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
225# their name.
Nico Huber81b09f42016-01-23 00:50:00 +0100226# $1 stage name
227# $2 file path (list)
Nico Huber98fc4262016-01-23 01:24:33 +0100228src-to-obj=\
229 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
230 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200231 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber98fc4262016-01-23 01:24:33 +0100232 $(patsubst src/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100233 $(patsubst %.ads,%.o,\
234 $(patsubst %.adb,%.o,\
Nico Huber98fc4262016-01-23 01:24:33 +0100235 $(patsubst %.c,%.o,\
236 $(patsubst %.S,%.o,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200237 $(subst .$(1),,$(2))))))))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100238
239# Converts one or more source file paths to the corresponding build/ paths
240# of their Ada library information (.ali) files.
241# $1 stage name
242# $2 file path (list)
243src-to-ali=\
244 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
245 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200246 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100247 $(patsubst src/%,$(obj)/%,\
248 $(patsubst %.ads,%.ali,\
249 $(patsubst %.adb,%.ali,\
250 $(subst .$(1),,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200251 $(filter %.ads %.adb,$(2)))))))))
Nico Huber81b09f42016-01-23 00:50:00 +0100252
Patrick Georgi47d68d82010-03-06 21:18:43 +0000253# Clean -y variables, include Makefile.inc
Patrick Georgi8463dd92010-09-30 16:55:02 +0000254# Add paths to files in X-y to X-srcs
Patrick Georgi47d68d82010-03-06 21:18:43 +0000255# Add subdirs-y to subdirs
256includemakefiles= \
Patrick Georgi58262652011-02-17 20:47:49 +0000257 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
Patrick Georgi47d68d82010-03-06 21:18:43 +0000258 $(eval -include $(1)) \
Patrick Georgi58262652011-02-17 20:47:49 +0000259 $(foreach class,$(classes-y), $(call add-class,$(class))) \
Arthur Heymans5e5fd412019-06-04 13:16:28 +0200260 $(foreach special,$(special-classes), \
261 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
Patrick Georgi58262652011-02-17 20:47:49 +0000262 $(foreach class,$(classes), \
263 $(eval $(class)-srcs+= \
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -0700264 $$(subst $(absobj)/,$(obj)/, \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000265 $$(subst $(top)/,, \
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -0700266 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
Patrick Georgi64b8fba2017-10-28 05:26:01 -0400267 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
Patrick Georgi47d68d82010-03-06 21:18:43 +0000268
Patrick Georgi8463dd92010-09-30 16:55:02 +0000269# For each path in $(subdirs) call includemakefiles
Patrick Georgi47d68d82010-03-06 21:18:43 +0000270# Repeat until subdirs is empty
271evaluate_subdirs= \
272 $(eval cursubdirs:=$(subdirs)) \
273 $(eval subdirs:=) \
274 $(foreach dir,$(cursubdirs), \
Patrick Georgi58262652011-02-17 20:47:49 +0000275 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000276 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000277
278# collect all object files eligible for building
Patrick Georgie38d0a62011-03-01 08:09:22 +0000279subdirs:=$(TOPLEVEL)
Julius Wernere91d1702017-03-20 15:32:15 -0700280postinclude-hooks :=
Jan Dabrosef1c9682020-03-28 00:15:03 +0100281
282# Don't iterate through Makefile.incs under src/ when building tests
283ifneq ($(UNIT_TEST),1)
Patrick Georgi51e142f2010-03-27 17:18:39 +0000284$(eval $(call evaluate_subdirs))
Jan Dabrosef1c9682020-03-28 00:15:03 +0100285else
286include $(TOPLEVEL)/tests/Makefile.inc
287endif
288
Patrick Georgi70c85ea2013-02-16 01:06:57 +0100289ifeq ($(FAILBUILD),1)
290$(error cannot continue build)
291endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000292
Julius Wernere91d1702017-03-20 15:32:15 -0700293# Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
294$(eval $(postinclude-hooks))
295
Patrick Georgi94a45862011-10-25 14:32:21 -0700296# Eliminate duplicate mentions of source files in a class
297$(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
298
Nico Huberb5679772019-01-01 22:06:01 +0100299# Build Kconfig .ads if necessary
300ifeq ($(CONFIG_RAMSTAGE_ADA),y)
301ramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
302endif
303
Nico Huber2e09d2b2016-01-14 01:13:33 +0100304# To track dependencies, we need all Ada specification (.ads) files in
305# *-srcs. Extract / filter all specification files that have a matching
306# body (.adb) file here (specifications without a body are valid sources
307# in Ada).
308$(foreach class,$(classes),$(eval $(class)-extra-specs := \
309 $(filter \
310 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
311 $(filter %.ads,$($(class)-srcs)))))
312$(foreach class,$(classes),$(eval $(class)-srcs := \
313 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
314
Patrick Georgi10f86b02015-03-27 16:56:23 +0100315$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100316$(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
317
318# For Ada includes
319$(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
Patrick Georgid3428b02010-02-24 13:18:01 +0000320
Nico Huber963bed52013-05-15 11:47:51 +0200321# Save all objs before processing them (for dependency inclusion)
322originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
323
Patrick Georgi79f90102012-11-25 14:31:08 +0100324# Call post-processors if they're defined
325$(foreach class,$(classes),\
326 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
327
Patrick Georgi58262652011-02-17 20:47:49 +0000328allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
329allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000330alldirs:=$(sort $(abspath $(dir $(allobjs))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000331
Nico Huber2e09d2b2016-01-14 01:13:33 +0100332# Reads dependencies from an Ada library information (.ali) file
333# Only basenames (with suffix) are preserved so we have to look the
334# paths up in $($(stage)-srcs).
335# $1 stage name
336# $2 ali file
337create_ada_deps=$$(if $(2),\
338 gnat.adc \
339 $$(filter \
340 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
341 $$($(1)-srcs) $$($(1)-extra-specs)))
342
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000343# macro to define template macros that are used by use_template macro
344define create_cc_template
Patrick Georgi71b84802011-02-22 14:35:05 +0000345# $1 obj class
Patrick Georgi990e7c92015-04-03 10:47:15 +0200346# $2 source suffix (c, S, ld, ...)
Marc Jonesa38ccfd2014-11-06 15:50:22 -0700347# $3 additional compiler flags
348# $4 additional dependencies
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000349ifn$(EMPTY)def $(1)-objs_$(2)_template
Patrick Georgi8463dd92010-09-30 16:55:02 +0000350de$(EMPTY)fine $(1)-objs_$(2)_template
Nico Huber1850aa62017-09-03 23:42:58 +0200351ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
Nico Huberb5679772019-01-01 22:06:01 +0100352$$(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 +0200353 @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
354 $(GCC_$(1)) \
355 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
356 $(3) -c -o $$$$@ $$$$<
357el$(EMPTY)se
358$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000359 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
Nico Huber2e09d2b2016-01-14 01:13:33 +0100360 $(CC_$(1)) \
Nico Huber1850aa62017-09-03 23:42:58 +0200361 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100362 $(3) -c -o $$$$@ $$$$<
Nico Huber1850aa62017-09-03 23:42:58 +0200363end$(EMPTY)if
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000364en$(EMPTY)def
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000365end$(EMPTY)if
Patrick Georgi0588d192009-08-12 15:00:51 +0000366endef
367
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000368filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
369$(foreach class,$(classes), \
370 $(foreach type,$(call filetypes-of-class,$(class)), \
Patrick Georgi2459aee2015-03-27 15:27:21 +0100371 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
Patrick Georgi416ab382015-04-03 10:19:38 +0200372 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
373 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000374
Patrick Georgid69839b2015-04-03 10:32:17 +0200375foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
Patrick Georgi58262652011-02-17 20:47:49 +0000376$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000377
Nico Huber2e09d2b2016-01-14 01:13:33 +0100378# To supported complex package initializations, we need to call the
379# emitted code explicitly. gnatbind gathers all the calls for us
380# and exports them as a procedure $(stage)_adainit(). Every stage that
381# uses Ada code has to call it!
382define gnatbind_template
383# $1 class
384$$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
385 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
386 # We have to give gnatbind a simple filename (without leading
387 # path components) so just cd there.
388 cd $$(dir $$@) && \
389 $$(GNATBIND_$(1)) -a -n \
Nico Huberbe5492a2015-09-29 16:41:19 +0200390 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100391 -L$(1)_ada -o $$(notdir $$@) \
392 $$(subst $$(dir $$@),,$$^)
393$$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
Nico Huber1850aa62017-09-03 23:42:58 +0200394 @printf " GCC $$(subst $$(obj)/,,$$@)\n"
395 $(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
Nico Huber2e09d2b2016-01-14 01:13:33 +0100396$(1)-objs += $$(obj)/$(1)/b__$(1).o
Nico Huberddb24652016-09-19 11:50:04 +0200397$($(1)-alis): %.ali: %.o ;
Nico Huber2e09d2b2016-01-14 01:13:33 +0100398endef
399
Nico Huberbe5492a2015-09-29 16:41:19 +0200400$(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100401 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
402
Julius Wernerf97b88b2014-12-05 12:32:09 -0800403DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000404-include $(DEPENDENCIES)
405
Patrick Georgi0588d192009-08-12 15:00:51 +0000406printall:
Martin Roth09b64442016-06-05 10:52:43 -0600407 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
408 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
409 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
410 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
411 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
Patrick Georgi0588d192009-08-12 15:00:51 +0000412endif
413
Patrick Georgi40ad8422011-05-21 22:18:59 +0000414ifndef NOMKDIR
Stefan Reinauerde60c882015-06-29 14:44:37 -0700415$(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
Patrick Georgi40ad8422011-05-21 22:18:59 +0000416endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000417
Martin Roth9b0204d2017-09-18 09:25:18 -0600418$(obj)/project_filelist.txt:
419 if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
420 echo "*** Error: Project must be built before generating file list ***"; \
421 exit 1; \
422 fi
Martin Roth8a027272017-09-26 09:53:30 -0600423 find $(obj) -path "$(obj)/util" -prune -o -name "*.d" -exec cat {} \; | \
424 sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
Martin Roth9c1b33e2015-07-29 14:55:18 -0700425 grep -v '\.o$$' > $(obj)/project_filelist.txt
426
Martin Roth9b0204d2017-09-18 09:25:18 -0600427filelist: $(obj)/project_filelist.txt
Martin Rotha18353d2017-06-06 06:44:46 -0600428 printf "\nFiles used in build:\n"
429 cat $(obj)/project_filelist.txt
430
Martin Roth9c1b33e2015-07-29 14:55:18 -0700431#works with either exuberant ctags or ctags.emacs
432ctags-project: clean-ctags $(obj)/project_filelist.txt
433 cat $(obj)/project_filelist.txt | \
434 xargs ctags -o tags
435
436cscope-project: clean-cscope $(obj)/project_filelist.txt
437 cat $(obj)/project_filelist.txt | xargs cscope -b
438
Warren Turkala9fc3302010-09-03 08:57:32 +0000439cscope:
440 cscope -bR
441
Patrick Rudolphf6643212020-05-17 20:04:12 +0200442sphinx:
443 $(MAKE) -C Documentation -f Makefile.sphinx html
444
445sphinx-lint:
446 $(MAKE) SPHINXOPTS=-W -C Documentation -f Makefile.sphinx html
447
Patrick Georgi0588d192009-08-12 15:00:51 +0000448doxy: doxygen
449doxygen:
Nicky Sielickie08a2a52015-06-06 08:55:16 -0500450 $(DOXYGEN) Documentation/Doxyfile.coreboot
Patrick Georgi0588d192009-08-12 15:00:51 +0000451
Martin Rothd7689e42014-12-29 14:56:19 -0700452doxygen_simple:
Nicky Sielickie08a2a52015-06-06 08:55:16 -0500453 $(DOXYGEN) Documentation/Doxyfile.coreboot_simple
Martin Rothd7689e42014-12-29 14:56:19 -0700454
Martin Rothb1574e32016-07-07 15:50:28 -0600455doxyplatform doxygen_platform: $(obj)/project_filelist.txt
456 echo
457 echo "Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
Martin Roth09e032e2020-10-25 19:44:38 -0600458 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 -0600459 mkdir -p "$$DOXYGEN_OUTPUT_DIR"; \
460 export DOXYFILES="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
Martin Roth09e032e2020-10-25 19:44:38 -0600461 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 -0600462 $(DOXYGEN) Documentation/doxygen/Doxyfile.coreboot_platform
463
Patrick Georgi0588d192009-08-12 15:00:51 +0000464doxyclean: doxygen-clean
465doxygen-clean:
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000466 rm -rf $(DOXYGEN_OUTPUT_DIR)
Patrick Georgi0588d192009-08-12 15:00:51 +0000467
Patrick Georgi71b84802011-02-22 14:35:05 +0000468clean-for-update: doxygen-clean clean-for-update-target
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100469 rm -rf $(obj) .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000470
Martin Roth20cd54f2017-03-26 18:49:02 -0600471clean: clean-for-update clean-target clean-utils
Patrick Georgi71b84802011-02-22 14:35:05 +0000472 rm -f .ccwrap
Warren Turkal0e8f2042010-09-27 21:14:19 +0000473
Warren Turkala9fc3302010-09-03 08:57:32 +0000474clean-cscope:
475 rm -f cscope.out
476
Martin Roth9c1b33e2015-07-29 14:55:18 -0700477clean-ctags:
478 rm -f tags
479
Martin Roth20cd54f2017-03-26 18:49:02 -0600480clean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600481 $(foreach tool, $(TOOLLIST), \
482 $(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
Martin Roth20cd54f2017-03-26 18:49:02 -0600483
484distclean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600485 $(foreach tool, $(TOOLLIST), \
486 $(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
Martin Roth20cd54f2017-03-26 18:49:02 -0600487 rm -f /util/$(tool)/junit.xml;)
488
489distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
Patrick Georgi80656af2017-04-26 11:58:44 +0200490 rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
Martin Roth20cd54f2017-03-26 18:49:02 -0600491 rm -rf coreboot-builds coreboot-builds-chromeos
492 rm -f abuild*.xml junit.xml* util/lint/junit.xml
Patrick Georgi0588d192009-08-12 15:00:51 +0000493
Patrick Rudolphf6643212020-05-17 20:04:12 +0200494.PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple sphinx sphinx-lint
Martin Roth9c1b33e2015-07-29 14:55:18 -0700495.PHONY: ctags-project cscope-project clean-ctags