blob: 470be945376e23f57f0d950349ff5ff0ab5ea7bb [file] [log] [blame]
Patrick Georgi0588d192009-08-12 15:00:51 +00001##
Patrick Georgi0588d192009-08-12 15:00:51 +00002##
3## Copyright (C) 2008 Advanced Micro Devices, Inc.
4## Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
Stefan Reinauer8ed1b6d2010-01-19 21:13:44 +00005## Copyright (C) 2009-2010 coresystems GmbH
Patrick Georgi71b84802011-02-22 14:35:05 +00006## Copyright (C) 2011 secunet Security Networks AG
Patrick Georgi0588d192009-08-12 15:00:51 +00007##
Patrick Georgi3bda0442011-06-30 15:48:57 +02008## Redistribution and use in source and binary forms, with or without
9## modification, are permitted provided that the following conditions
10## are met:
11## 1. Redistributions of source code must retain the above copyright
12## notice, this list of conditions and the following disclaimer.
13## 2. Redistributions in binary form must reproduce the above copyright
14## notice, this list of conditions and the following disclaimer in the
15## documentation and/or other materials provided with the distribution.
16## 3. The name of the author may not be used to endorse or promote products
17## derived from this software without specific prior written permission.
Patrick Georgi0588d192009-08-12 15:00:51 +000018##
Patrick Georgi3bda0442011-06-30 15:48:57 +020019## THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29## SUCH DAMAGE.
Patrick Georgi0588d192009-08-12 15:00:51 +000030##
31
Himanshu Sahdevd1e18d92019-09-16 15:55:03 +053032ifneq ($(words $(CURDIR)),1)
33 $(error Error: Path to the main directory cannot contain spaces)
34endif
Nico Huber7a1fbdb2017-08-23 23:48:13 +020035top := $(CURDIR)
36src := src
37srck := $(top)/util/kconfig
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -070038obj ?= build
39override obj := $(subst $(top)/,,$(abspath $(obj)))
Nico Huber7a1fbdb2017-08-23 23:48:13 +020040objutil ?= $(obj)/util
41objk := $(objutil)/kconfig
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -070042absobj := $(abspath $(obj))
Patrick Georgi0588d192009-08-12 15:00:51 +000043
Yu-Ping Wu0beddb52020-03-09 10:58:37 +080044VBOOT_HOST_BUILD ?= $(abspath $(objutil)/vboot_lib)
45
Nico Huber7a1fbdb2017-08-23 23:48:13 +020046COREBOOT_EXPORTS := COREBOOT_EXPORTS
47COREBOOT_EXPORTS += top src srck obj objutil objk
Patrick Georgi0588d192009-08-12 15:00:51 +000048
Alexander Couzensbe756f12019-09-13 04:22:12 +020049# reproducible builds
50LANG:=C
51LC_ALL:=C
52TZ:=UTC0
53COREBOOT_EXPORTS += LANG LC_ALL TZ
54
Nico Huber7a1fbdb2017-08-23 23:48:13 +020055DOTCONFIG ?= $(top)/.config
56KCONFIG_CONFIG = $(DOTCONFIG)
Nico Huber533bc0a2019-01-01 19:03:33 +010057KCONFIG_AUTOADS := $(obj)/cb-config.ads
Nico Huber7a1fbdb2017-08-23 23:48:13 +020058KCONFIG_AUTOHEADER := $(obj)/config.h
59KCONFIG_AUTOCONFIG := $(obj)/auto.conf
60KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
61KCONFIG_SPLITCONFIG := $(obj)/config
62KCONFIG_TRISTATE := $(obj)/tristate.conf
63KCONFIG_NEGATIVES := 1
64KCONFIG_STRICT := 1
Nico Huber533bc0a2019-01-01 19:03:33 +010065KCONFIG_PACKAGE := CB.Config
Nico Huber7a1fbdb2017-08-23 23:48:13 +020066
67COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
68COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
69COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_STRICT
Nico Huber533bc0a2019-01-01 19:03:33 +010070COREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE
Patrick Georgi0588d192009-08-12 15:00:51 +000071
Patrick Georgie38d0a62011-03-01 08:09:22 +000072# directory containing the toplevel Makefile.inc
73TOPLEVEL := .
74
Patrick Georgi0588d192009-08-12 15:00:51 +000075CONFIG_SHELL := sh
76KBUILD_DEFCONFIG := configs/defconfig
77UNAME_RELEASE := $(shell uname -r)
Patrick Georgi89ec3762010-12-08 19:58:30 +000078HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
Patrick Georgi0588d192009-08-12 15:00:51 +000079MAKEFLAGS += -rR --no-print-directory
80
81# Make is silent per default, but 'make V=1' will show all compiler calls.
Patrick Georgi2b7418e2009-08-25 19:38:46 +000082Q:=@
Patrick Georgi0588d192009-08-12 15:00:51 +000083ifneq ($(V),1)
Patrick Georgi2b7418e2009-08-25 19:38:46 +000084ifneq ($(Q),)
85.SILENT:
Nico Huber7325ac52020-02-16 11:47:52 +010086MAKEFLAGS += -s
Patrick Georgi2b7418e2009-08-25 19:38:46 +000087endif
Patrick Georgi0588d192009-08-12 15:00:51 +000088endif
89
Julius Werner808a4292015-03-13 11:05:07 -070090# Disable implicit/built-in rules to make Makefile errors fail fast.
91.SUFFIXES:
92
Patrick Georgif92068d2016-02-01 12:02:29 +010093HOSTCC := $(if $(shell type gcc 2>/dev/null),gcc,cc)
Patrick Georgi0588d192009-08-12 15:00:51 +000094HOSTCXX = g++
Patrick Georgib3a18ac2012-09-13 22:13:33 +020095HOSTCFLAGS := -g
96HOSTCXXFLAGS := -g
Patrick Georgi0588d192009-08-12 15:00:51 +000097
Patrick Georgi828e0e82015-04-04 15:50:20 +020098PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
99
Patrick Georgi0588d192009-08-12 15:00:51 +0000100DOXYGEN := doxygen
101DOXYGEN_OUTPUT_DIR := doxygen
102
Nico Huber7a1fbdb2017-08-23 23:48:13 +0200103export $(COREBOOT_EXPORTS)
104
Patrick Georgi71b84802011-02-22 14:35:05 +0000105all: real-all
106
Martin Roth4eea1742015-11-25 11:50:04 -0700107help_coreboot help::
108 @echo '*** coreboot platform targets ***'
Martin Roth76f14b22015-11-18 13:09:23 -0700109 @echo ' Use "make [target] V=1" for extra build debug information'
110 @echo ' all - Build coreboot'
111 @echo ' clean - Remove coreboot build artifacts'
112 @echo ' distclean - Remove build artifacts and config files'
113 @echo ' doxygen - Build doxygen documentation for coreboot'
Martin Rothb1574e32016-07-07 15:50:28 -0600114 @echo ' doxyplatform - Build doxygen documentation for the current platform'
Martin Roth763e4932018-01-27 16:42:43 -0700115 @echo ' filelist - Show files used in current build'
Martin Roth76f14b22015-11-18 13:09:23 -0700116 @echo ' printall - print makefile info for debugging'
Werner Zeh2de64102016-01-12 12:45:49 +0100117 @echo ' gitconfig - set up git to submit patches to coreboot'
Martin Roth76f14b22015-11-18 13:09:23 -0700118 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
119 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
120 @echo
121
Patrick Georgie38d0a62011-03-01 08:09:22 +0000122# This include must come _before_ the pattern rules below!
Patrick Georgi71b84802011-02-22 14:35:05 +0000123# Order _does_ matter for pattern rules.
Patrick Georgi3e8ef102019-11-22 16:54:17 +0100124include $(srck)/Makefile.inc
Patrick Georgi71b84802011-02-22 14:35:05 +0000125
Patrick Georgicf036d12010-04-21 06:36:20 +0000126# Three cases where we don't need fully populated $(obj) lists:
127# 1. when no .config exists
128# 2. when make config (in any flavour) is run
129# 3. when make distclean is run
130# Don't waste time on reading all Makefile.incs in these cases
Patrick Georgi0588d192009-08-12 15:00:51 +0000131ifeq ($(strip $(HAVE_DOTCONFIG)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000132NOCOMPILE:=1
133endif
134ifneq ($(MAKECMDGOALS),)
Martin Roth109a7db2016-08-11 18:16:59 -0600135ifneq ($(filter %config %clean cross% clang iasl gnumake lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000136NOCOMPILE:=1
137endif
Raul E Rangel5592cfd2019-07-23 11:13:40 -0600138ifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
Zheng Bao0fd93d62012-10-22 16:36:03 +0800139NOMKDIR:=1
140endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000141endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000142
Jan Dabrosef1c9682020-03-28 00:15:03 +0100143ifneq ($(filter %-test %-tests,$(MAKECMDGOALS)),)
144ifneq ($(filter-out %-test %-tests, $(MAKECMDGOALS)),)
145$(error Cannot mix unit-tests targets with other targets)
146endif
147UNIT_TEST:=1
148NOCOMPILE:=
149endif
150
Raul E Rangel6325ce22019-07-10 16:46:34 -0600151.xcompile: util/xcompile/xcompile
152 rm -f $@
153 $< $(XGCCPATH) > $@.tmp
154 \mv -f $@.tmp $@ 2> /dev/null
155 rm -f $@.tmp
156
Patrick Georgicf036d12010-04-21 06:36:20 +0000157ifeq ($(NOCOMPILE),1)
Patrick Georgie38d0a62011-03-01 08:09:22 +0000158include $(TOPLEVEL)/Makefile.inc
Martin Roth67975572016-03-07 16:38:52 -0700159include $(TOPLEVEL)/payloads/Makefile.inc
Martin Rothe624e272017-07-31 11:52:58 -0600160include $(TOPLEVEL)/util/testing/Makefile.inc
Werner Zehb7f1c2d2019-10-04 07:01:13 +0200161-include $(TOPLEVEL)/site-local/Makefile.inc
Martin Roth20aa0432017-01-26 10:51:43 -0700162real-all:
163 @echo "Error: Expected config file ($(DOTCONFIG)) not present." >&2
164 @echo "Please specify a config file or run 'make menuconfig' to" >&2
165 @echo "generate a new config file." >&2
166 @exit 1
Patrick Georgi0588d192009-08-12 15:00:51 +0000167else
168
Jan Dabrosef1c9682020-03-28 00:15:03 +0100169ifneq ($(UNIT_TEST),1)
Paul Kocialkowski585c7812016-07-13 11:00:41 +0200170include $(DOTCONFIG)
Jan Dabrosef1c9682020-03-28 00:15:03 +0100171endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000172
Patrick Georgi0ffef882017-01-19 23:20:14 +0100173# in addition to the dependency below, create the file if it doesn't exist
174# to silence stupid warnings about a file that would be generated anyway.
175$(if $(wildcard .xcompile)$(NOCOMPILE),,$(eval $(shell util/xcompile/xcompile $(XGCCPATH) > .xcompile || rm -f .xcompile)))
176
Patrick Georgi6dda31d2015-11-19 15:15:33 +0100177-include .xcompile
178
179ifneq ($(XCOMPILE_COMPLETE),1)
180$(shell rm -f .xcompile)
181$(error .xcompile deleted because it's invalid. \
182 Restarting the build should fix that, or explain the problem)
183endif
Patrick Georgi7b9762f2015-06-04 13:18:11 +0200184
Patrick Georgicc84a002014-05-14 21:05:35 +0200185ifneq ($(CONFIG_MMX),y)
186CFLAGS_x86_32 += -mno-mmx
187endif
188
Jan Dabrosef1c9682020-03-28 00:15:03 +0100189ifneq ($(UNIT_TEST),1)
Patrick Georgicc84a002014-05-14 21:05:35 +0200190include toolchain.inc
Jan Dabrosef1c9682020-03-28 00:15:03 +0100191endif
Patrick Georgicc84a002014-05-14 21:05:35 +0200192
Zheng Bao07648922015-11-13 10:42:27 +0800193strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
Martin Rothbbf13992016-01-25 15:59:24 -0700194# fix makefile syntax highlighting after strip macro \" "))
Patrick Georgia84e98b2010-03-16 19:01:32 +0000195
Patrick Georgi0588d192009-08-12 15:00:51 +0000196# The primary target needs to be here before we include the
197# other files
198
Patrick Georgi71b84802011-02-22 14:35:05 +0000199real-all: real-target
Patrick Georgi0588d192009-08-12 15:00:51 +0000200
Patrick Georgi51e142f2010-03-27 17:18:39 +0000201# must come rather early
202.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 Georgi78a5f222017-01-30 15:29:34 +0100206 +$(MAKE) oldconfig
Patrick Georgi0588d192009-08-12 15:00:51 +0000207
Nico Huber533bc0a2019-01-01 19:03:33 +0100208$(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
209 true
210
Nico Hubereafc8152019-10-25 12:47:14 +0200211$(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
Nico Huber533bc0a2019-01-01 19:03:33 +0100212 $(objutil)/kconfig/toada CB.Config <$< >$@
213
Nico Huberb5679772019-01-01 22:06:01 +0100214$(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
215 cp $< $@
216
Patrick Georgi58262652011-02-17 20:47:49 +0000217# Add a new class of source/object files to the build system
218add-class= \
219 $(eval $(1)-srcs:=) \
220 $(eval $(1)-objs:=) \
221 $(eval classes+=$(1))
Patrick Georgi8463dd92010-09-30 16:55:02 +0000222
Patrick Georgi58262652011-02-17 20:47:49 +0000223# Special classes are managed types with special behaviour
224# On parse time, for each entry in variable $(1)-y
225# a handler $(1)-handler is executed with the arguments:
226# * $(1): directory the parser is in
227# * $(2): current entry
228add-special-class= \
229 $(eval $(1):=) \
230 $(eval special-classes+=$(1))
231
Nico Huber81b09f42016-01-23 00:50:00 +0100232# Converts one or more source file paths to their corresponding build/ paths.
Nico Huber2e09d2b2016-01-14 01:13:33 +0100233# Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
234# their name.
Nico Huber81b09f42016-01-23 00:50:00 +0100235# $1 stage name
236# $2 file path (list)
Nico Huber98fc4262016-01-23 01:24:33 +0100237src-to-obj=\
238 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
239 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200240 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber98fc4262016-01-23 01:24:33 +0100241 $(patsubst src/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100242 $(patsubst %.ads,%.o,\
243 $(patsubst %.adb,%.o,\
Nico Huber98fc4262016-01-23 01:24:33 +0100244 $(patsubst %.c,%.o,\
245 $(patsubst %.S,%.o,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200246 $(subst .$(1),,$(2))))))))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100247
248# Converts one or more source file paths to the corresponding build/ paths
249# of their Ada library information (.ali) files.
250# $1 stage name
251# $2 file path (list)
252src-to-ali=\
253 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
254 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200255 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100256 $(patsubst src/%,$(obj)/%,\
257 $(patsubst %.ads,%.ali,\
258 $(patsubst %.adb,%.ali,\
259 $(subst .$(1),,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200260 $(filter %.ads %.adb,$(2)))))))))
Nico Huber81b09f42016-01-23 00:50:00 +0100261
Patrick Georgi47d68d82010-03-06 21:18:43 +0000262# Clean -y variables, include Makefile.inc
Patrick Georgi8463dd92010-09-30 16:55:02 +0000263# Add paths to files in X-y to X-srcs
Patrick Georgi47d68d82010-03-06 21:18:43 +0000264# Add subdirs-y to subdirs
265includemakefiles= \
Patrick Georgi58262652011-02-17 20:47:49 +0000266 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
Patrick Georgi47d68d82010-03-06 21:18:43 +0000267 $(eval -include $(1)) \
Patrick Georgi58262652011-02-17 20:47:49 +0000268 $(foreach class,$(classes-y), $(call add-class,$(class))) \
Arthur Heymans5e5fd412019-06-04 13:16:28 +0200269 $(foreach special,$(special-classes), \
270 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
Patrick Georgi58262652011-02-17 20:47:49 +0000271 $(foreach class,$(classes), \
272 $(eval $(class)-srcs+= \
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -0700273 $$(subst $(absobj)/,$(obj)/, \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000274 $$(subst $(top)/,, \
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -0700275 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
Patrick Georgi64b8fba2017-10-28 05:26:01 -0400276 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
Patrick Georgi47d68d82010-03-06 21:18:43 +0000277
Patrick Georgi8463dd92010-09-30 16:55:02 +0000278# For each path in $(subdirs) call includemakefiles
Patrick Georgi47d68d82010-03-06 21:18:43 +0000279# Repeat until subdirs is empty
280evaluate_subdirs= \
281 $(eval cursubdirs:=$(subdirs)) \
282 $(eval subdirs:=) \
283 $(foreach dir,$(cursubdirs), \
Patrick Georgi58262652011-02-17 20:47:49 +0000284 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000285 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000286
287# collect all object files eligible for building
Patrick Georgie38d0a62011-03-01 08:09:22 +0000288subdirs:=$(TOPLEVEL)
Julius Wernere91d1702017-03-20 15:32:15 -0700289postinclude-hooks :=
Jan Dabrosef1c9682020-03-28 00:15:03 +0100290
291# Don't iterate through Makefile.incs under src/ when building tests
292ifneq ($(UNIT_TEST),1)
Patrick Georgi51e142f2010-03-27 17:18:39 +0000293$(eval $(call evaluate_subdirs))
Jan Dabrosef1c9682020-03-28 00:15:03 +0100294else
295include $(TOPLEVEL)/tests/Makefile.inc
296endif
297
Patrick Georgi70c85ea2013-02-16 01:06:57 +0100298ifeq ($(FAILBUILD),1)
299$(error cannot continue build)
300endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000301
Julius Wernere91d1702017-03-20 15:32:15 -0700302# Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
303$(eval $(postinclude-hooks))
304
Patrick Georgi94a45862011-10-25 14:32:21 -0700305# Eliminate duplicate mentions of source files in a class
306$(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
307
Nico Huberb5679772019-01-01 22:06:01 +0100308# Build Kconfig .ads if necessary
309ifeq ($(CONFIG_RAMSTAGE_ADA),y)
310ramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
311endif
312
Nico Huber2e09d2b2016-01-14 01:13:33 +0100313# To track dependencies, we need all Ada specification (.ads) files in
314# *-srcs. Extract / filter all specification files that have a matching
315# body (.adb) file here (specifications without a body are valid sources
316# in Ada).
317$(foreach class,$(classes),$(eval $(class)-extra-specs := \
318 $(filter \
319 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
320 $(filter %.ads,$($(class)-srcs)))))
321$(foreach class,$(classes),$(eval $(class)-srcs := \
322 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
323
Patrick Georgi10f86b02015-03-27 16:56:23 +0100324$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100325$(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
326
327# For Ada includes
328$(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
Patrick Georgid3428b02010-02-24 13:18:01 +0000329
Nico Huber963bed52013-05-15 11:47:51 +0200330# Save all objs before processing them (for dependency inclusion)
331originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
332
Patrick Georgi79f90102012-11-25 14:31:08 +0100333# Call post-processors if they're defined
334$(foreach class,$(classes),\
335 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
336
Patrick Georgi58262652011-02-17 20:47:49 +0000337allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
338allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000339alldirs:=$(sort $(abspath $(dir $(allobjs))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000340
Nico Huber2e09d2b2016-01-14 01:13:33 +0100341# Reads dependencies from an Ada library information (.ali) file
342# Only basenames (with suffix) are preserved so we have to look the
343# paths up in $($(stage)-srcs).
344# $1 stage name
345# $2 ali file
346create_ada_deps=$$(if $(2),\
347 gnat.adc \
348 $$(filter \
349 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
350 $$($(1)-srcs) $$($(1)-extra-specs)))
351
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000352# macro to define template macros that are used by use_template macro
353define create_cc_template
Patrick Georgi71b84802011-02-22 14:35:05 +0000354# $1 obj class
Patrick Georgi990e7c92015-04-03 10:47:15 +0200355# $2 source suffix (c, S, ld, ...)
Marc Jonesa38ccfd2014-11-06 15:50:22 -0700356# $3 additional compiler flags
357# $4 additional dependencies
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000358ifn$(EMPTY)def $(1)-objs_$(2)_template
Patrick Georgi8463dd92010-09-30 16:55:02 +0000359de$(EMPTY)fine $(1)-objs_$(2)_template
Nico Huber1850aa62017-09-03 23:42:58 +0200360ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
Nico Huberb5679772019-01-01 22:06:01 +0100361$$(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 +0200362 @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
363 $(GCC_$(1)) \
364 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
365 $(3) -c -o $$$$@ $$$$<
366el$(EMPTY)se
367$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000368 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
Nico Huber2e09d2b2016-01-14 01:13:33 +0100369 $(CC_$(1)) \
Nico Huber1850aa62017-09-03 23:42:58 +0200370 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100371 $(3) -c -o $$$$@ $$$$<
Nico Huber1850aa62017-09-03 23:42:58 +0200372end$(EMPTY)if
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000373en$(EMPTY)def
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000374end$(EMPTY)if
Patrick Georgi0588d192009-08-12 15:00:51 +0000375endef
376
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000377filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
378$(foreach class,$(classes), \
379 $(foreach type,$(call filetypes-of-class,$(class)), \
Patrick Georgi2459aee2015-03-27 15:27:21 +0100380 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
Patrick Georgi416ab382015-04-03 10:19:38 +0200381 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
382 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000383
Patrick Georgid69839b2015-04-03 10:32:17 +0200384foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
Patrick Georgi58262652011-02-17 20:47:49 +0000385$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000386
Nico Huber2e09d2b2016-01-14 01:13:33 +0100387# To supported complex package initializations, we need to call the
388# emitted code explicitly. gnatbind gathers all the calls for us
389# and exports them as a procedure $(stage)_adainit(). Every stage that
390# uses Ada code has to call it!
391define gnatbind_template
392# $1 class
393$$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
394 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
395 # We have to give gnatbind a simple filename (without leading
396 # path components) so just cd there.
397 cd $$(dir $$@) && \
398 $$(GNATBIND_$(1)) -a -n \
Nico Huberbe5492a2015-09-29 16:41:19 +0200399 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100400 -L$(1)_ada -o $$(notdir $$@) \
401 $$(subst $$(dir $$@),,$$^)
402$$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
Nico Huber1850aa62017-09-03 23:42:58 +0200403 @printf " GCC $$(subst $$(obj)/,,$$@)\n"
404 $(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
Nico Huber2e09d2b2016-01-14 01:13:33 +0100405$(1)-objs += $$(obj)/$(1)/b__$(1).o
Nico Huberddb24652016-09-19 11:50:04 +0200406$($(1)-alis): %.ali: %.o ;
Nico Huber2e09d2b2016-01-14 01:13:33 +0100407endef
408
Nico Huberbe5492a2015-09-29 16:41:19 +0200409$(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100410 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
411
Julius Wernerf97b88b2014-12-05 12:32:09 -0800412DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000413-include $(DEPENDENCIES)
414
Patrick Georgi0588d192009-08-12 15:00:51 +0000415printall:
Martin Roth09b64442016-06-05 10:52:43 -0600416 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
417 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
418 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
419 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
420 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
Patrick Georgi0588d192009-08-12 15:00:51 +0000421endif
422
Patrick Georgi40ad8422011-05-21 22:18:59 +0000423ifndef NOMKDIR
Stefan Reinauerde60c882015-06-29 14:44:37 -0700424$(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
Patrick Georgi40ad8422011-05-21 22:18:59 +0000425endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000426
Martin Roth9b0204d2017-09-18 09:25:18 -0600427$(obj)/project_filelist.txt:
428 if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
429 echo "*** Error: Project must be built before generating file list ***"; \
430 exit 1; \
431 fi
Martin Roth8a027272017-09-26 09:53:30 -0600432 find $(obj) -path "$(obj)/util" -prune -o -name "*.d" -exec cat {} \; | \
433 sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
Martin Roth9c1b33e2015-07-29 14:55:18 -0700434 grep -v '\.o$$' > $(obj)/project_filelist.txt
435
Martin Roth9b0204d2017-09-18 09:25:18 -0600436filelist: $(obj)/project_filelist.txt
Martin Rotha18353d2017-06-06 06:44:46 -0600437 printf "\nFiles used in build:\n"
438 cat $(obj)/project_filelist.txt
439
Martin Roth9c1b33e2015-07-29 14:55:18 -0700440#works with either exuberant ctags or ctags.emacs
441ctags-project: clean-ctags $(obj)/project_filelist.txt
442 cat $(obj)/project_filelist.txt | \
443 xargs ctags -o tags
444
445cscope-project: clean-cscope $(obj)/project_filelist.txt
446 cat $(obj)/project_filelist.txt | xargs cscope -b
447
Warren Turkala9fc3302010-09-03 08:57:32 +0000448cscope:
449 cscope -bR
450
Patrick Georgi0588d192009-08-12 15:00:51 +0000451doxy: doxygen
452doxygen:
Nicky Sielickie08a2a52015-06-06 08:55:16 -0500453 $(DOXYGEN) Documentation/Doxyfile.coreboot
Patrick Georgi0588d192009-08-12 15:00:51 +0000454
Martin Rothd7689e42014-12-29 14:56:19 -0700455doxygen_simple:
Nicky Sielickie08a2a52015-06-06 08:55:16 -0500456 $(DOXYGEN) Documentation/Doxyfile.coreboot_simple
Martin Rothd7689e42014-12-29 14:56:19 -0700457
Martin Rothb1574e32016-07-07 15:50:28 -0600458doxyplatform doxygen_platform: $(obj)/project_filelist.txt
459 echo
460 echo "Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
461 export DOXYGEN_OUTPUT_DIR="$(DOXYGEN_OUTPUT_DIR)/$(CONFIG_MAINBOARD_VENDOR)/$(CONFIG_MAINBOARD_PART_NUMBER)"; \
462 mkdir -p "$$DOXYGEN_OUTPUT_DIR"; \
463 export DOXYFILES="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
464 export DOXYGEN_PLATFORM="$(CONFIG_MAINBOARD_DIR) ($(CONFIG_MAINBOARD_PART_NUMBER)) version $(KERNELVERSION)"; \
465 $(DOXYGEN) Documentation/doxygen/Doxyfile.coreboot_platform
466
Patrick Georgi0588d192009-08-12 15:00:51 +0000467doxyclean: doxygen-clean
468doxygen-clean:
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000469 rm -rf $(DOXYGEN_OUTPUT_DIR)
Patrick Georgi0588d192009-08-12 15:00:51 +0000470
Patrick Georgi71b84802011-02-22 14:35:05 +0000471clean-for-update: doxygen-clean clean-for-update-target
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100472 rm -rf $(obj) .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000473
Martin Roth20cd54f2017-03-26 18:49:02 -0600474clean: clean-for-update clean-target clean-utils
Patrick Georgi71b84802011-02-22 14:35:05 +0000475 rm -f .ccwrap
Warren Turkal0e8f2042010-09-27 21:14:19 +0000476
Warren Turkala9fc3302010-09-03 08:57:32 +0000477clean-cscope:
478 rm -f cscope.out
479
Martin Roth9c1b33e2015-07-29 14:55:18 -0700480clean-ctags:
481 rm -f tags
482
Martin Roth20cd54f2017-03-26 18:49:02 -0600483clean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600484 $(foreach tool, $(TOOLLIST), \
485 $(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
Martin Roth20cd54f2017-03-26 18:49:02 -0600486
487distclean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600488 $(foreach tool, $(TOOLLIST), \
489 $(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
Martin Roth20cd54f2017-03-26 18:49:02 -0600490 rm -f /util/$(tool)/junit.xml;)
491
492distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
Patrick Georgi80656af2017-04-26 11:58:44 +0200493 rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
Martin Roth20cd54f2017-03-26 18:49:02 -0600494 rm -rf coreboot-builds coreboot-builds-chromeos
495 rm -f abuild*.xml junit.xml* util/lint/junit.xml
Patrick Georgi0588d192009-08-12 15:00:51 +0000496
Martin Rothd7689e42014-12-29 14:56:19 -0700497.PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple
Martin Roth9c1b33e2015-07-29 14:55:18 -0700498.PHONY: ctags-project cscope-project clean-ctags