blob: 2bc2a6fe6364a8290d3f9f40b043e42120278640 [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)))
Nico Huber7a1fbdb2017-08-23 23:48:13 +020011objutil ?= $(obj)/util
12objk := $(objutil)/kconfig
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -070013absobj := $(abspath $(obj))
Patrick Georgi0588d192009-08-12 15:00:51 +000014
Yu-Ping Wu0beddb52020-03-09 10:58:37 +080015VBOOT_HOST_BUILD ?= $(abspath $(objutil)/vboot_lib)
16
Nico Huber7a1fbdb2017-08-23 23:48:13 +020017COREBOOT_EXPORTS := COREBOOT_EXPORTS
18COREBOOT_EXPORTS += top src srck obj objutil objk
Patrick Georgi0588d192009-08-12 15:00:51 +000019
Alexander Couzensbe756f12019-09-13 04:22:12 +020020# reproducible builds
21LANG:=C
22LC_ALL:=C
23TZ:=UTC0
24COREBOOT_EXPORTS += LANG LC_ALL TZ
25
Nico Huber7a1fbdb2017-08-23 23:48:13 +020026DOTCONFIG ?= $(top)/.config
27KCONFIG_CONFIG = $(DOTCONFIG)
Nico Huber533bc0a2019-01-01 19:03:33 +010028KCONFIG_AUTOADS := $(obj)/cb-config.ads
Nico Huber7a1fbdb2017-08-23 23:48:13 +020029KCONFIG_AUTOHEADER := $(obj)/config.h
30KCONFIG_AUTOCONFIG := $(obj)/auto.conf
31KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
32KCONFIG_SPLITCONFIG := $(obj)/config
33KCONFIG_TRISTATE := $(obj)/tristate.conf
34KCONFIG_NEGATIVES := 1
35KCONFIG_STRICT := 1
Nico Huber533bc0a2019-01-01 19:03:33 +010036KCONFIG_PACKAGE := CB.Config
Nico Huber7a1fbdb2017-08-23 23:48:13 +020037
38COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
39COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
40COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_STRICT
Nico Huber533bc0a2019-01-01 19:03:33 +010041COREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE
Patrick Georgi0588d192009-08-12 15:00:51 +000042
Patrick Georgie38d0a62011-03-01 08:09:22 +000043# directory containing the toplevel Makefile.inc
44TOPLEVEL := .
45
Patrick Georgi0588d192009-08-12 15:00:51 +000046CONFIG_SHELL := sh
47KBUILD_DEFCONFIG := configs/defconfig
48UNAME_RELEASE := $(shell uname -r)
Patrick Georgi89ec3762010-12-08 19:58:30 +000049HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
Patrick Georgi0588d192009-08-12 15:00:51 +000050MAKEFLAGS += -rR --no-print-directory
51
52# Make is silent per default, but 'make V=1' will show all compiler calls.
Patrick Georgi2b7418e2009-08-25 19:38:46 +000053Q:=@
Patrick Georgi0588d192009-08-12 15:00:51 +000054ifneq ($(V),1)
Patrick Georgi2b7418e2009-08-25 19:38:46 +000055ifneq ($(Q),)
56.SILENT:
Nico Huber7325ac52020-02-16 11:47:52 +010057MAKEFLAGS += -s
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 Georgif92068d2016-02-01 12:02:29 +010064HOSTCC := $(if $(shell type gcc 2>/dev/null),gcc,cc)
Patrick Georgi0588d192009-08-12 15:00:51 +000065HOSTCXX = g++
Patrick Georgib3a18ac2012-09-13 22:13:33 +020066HOSTCFLAGS := -g
67HOSTCXXFLAGS := -g
Patrick Georgi0588d192009-08-12 15:00:51 +000068
Patrick Georgi828e0e82015-04-04 15:50:20 +020069PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
70
Patrick Georgi0588d192009-08-12 15:00:51 +000071DOXYGEN := doxygen
72DOXYGEN_OUTPUT_DIR := doxygen
73
Nico Huber7a1fbdb2017-08-23 23:48:13 +020074export $(COREBOOT_EXPORTS)
75
Patrick Georgi71b84802011-02-22 14:35:05 +000076all: real-all
77
Martin Roth4eea1742015-11-25 11:50:04 -070078help_coreboot help::
79 @echo '*** coreboot platform targets ***'
Martin Roth76f14b22015-11-18 13:09:23 -070080 @echo ' Use "make [target] V=1" for extra build debug information'
81 @echo ' all - Build coreboot'
82 @echo ' clean - Remove coreboot build artifacts'
83 @echo ' distclean - Remove build artifacts and config files'
84 @echo ' doxygen - Build doxygen documentation for coreboot'
Martin Rothb1574e32016-07-07 15:50:28 -060085 @echo ' doxyplatform - Build doxygen documentation for the current platform'
Martin Roth763e4932018-01-27 16:42:43 -070086 @echo ' filelist - Show files used in current build'
Martin Roth76f14b22015-11-18 13:09:23 -070087 @echo ' printall - print makefile info for debugging'
Werner Zeh2de64102016-01-12 12:45:49 +010088 @echo ' gitconfig - set up git to submit patches to coreboot'
Martin Roth76f14b22015-11-18 13:09:23 -070089 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
90 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
91 @echo
92
Patrick Georgie38d0a62011-03-01 08:09:22 +000093# This include must come _before_ the pattern rules below!
Patrick Georgi71b84802011-02-22 14:35:05 +000094# Order _does_ matter for pattern rules.
Patrick Georgi3e8ef102019-11-22 16:54:17 +010095include $(srck)/Makefile.inc
Patrick Georgi71b84802011-02-22 14:35:05 +000096
Patrick Georgicf036d12010-04-21 06:36:20 +000097# Three cases where we don't need fully populated $(obj) lists:
98# 1. when no .config exists
99# 2. when make config (in any flavour) is run
100# 3. when make distclean is run
101# Don't waste time on reading all Makefile.incs in these cases
Patrick Georgi0588d192009-08-12 15:00:51 +0000102ifeq ($(strip $(HAVE_DOTCONFIG)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000103NOCOMPILE:=1
104endif
105ifneq ($(MAKECMDGOALS),)
Martin Roth109a7db2016-08-11 18:16:59 -0600106ifneq ($(filter %config %clean cross% clang iasl gnumake lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000107NOCOMPILE:=1
108endif
Raul E Rangel5592cfd2019-07-23 11:13:40 -0600109ifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
Zheng Bao0fd93d62012-10-22 16:36:03 +0800110NOMKDIR:=1
111endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000112endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000113
Jan Dabrosef1c9682020-03-28 00:15:03 +0100114ifneq ($(filter %-test %-tests,$(MAKECMDGOALS)),)
115ifneq ($(filter-out %-test %-tests, $(MAKECMDGOALS)),)
116$(error Cannot mix unit-tests targets with other targets)
117endif
118UNIT_TEST:=1
119NOCOMPILE:=
120endif
121
Raul E Rangel6325ce22019-07-10 16:46:34 -0600122.xcompile: util/xcompile/xcompile
123 rm -f $@
124 $< $(XGCCPATH) > $@.tmp
125 \mv -f $@.tmp $@ 2> /dev/null
126 rm -f $@.tmp
127
Patrick Georgicf036d12010-04-21 06:36:20 +0000128ifeq ($(NOCOMPILE),1)
Patrick Georgie38d0a62011-03-01 08:09:22 +0000129include $(TOPLEVEL)/Makefile.inc
Martin Roth67975572016-03-07 16:38:52 -0700130include $(TOPLEVEL)/payloads/Makefile.inc
Martin Rothe624e272017-07-31 11:52:58 -0600131include $(TOPLEVEL)/util/testing/Makefile.inc
Werner Zehb7f1c2d2019-10-04 07:01:13 +0200132-include $(TOPLEVEL)/site-local/Makefile.inc
Martin Roth20aa0432017-01-26 10:51:43 -0700133real-all:
134 @echo "Error: Expected config file ($(DOTCONFIG)) not present." >&2
135 @echo "Please specify a config file or run 'make menuconfig' to" >&2
136 @echo "generate a new config file." >&2
137 @exit 1
Patrick Georgi0588d192009-08-12 15:00:51 +0000138else
139
Jan Dabrosef1c9682020-03-28 00:15:03 +0100140ifneq ($(UNIT_TEST),1)
Paul Kocialkowski585c7812016-07-13 11:00:41 +0200141include $(DOTCONFIG)
Jan Dabrosef1c9682020-03-28 00:15:03 +0100142endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000143
Patrick Georgi0ffef882017-01-19 23:20:14 +0100144# in addition to the dependency below, create the file if it doesn't exist
145# to silence stupid warnings about a file that would be generated anyway.
146$(if $(wildcard .xcompile)$(NOCOMPILE),,$(eval $(shell util/xcompile/xcompile $(XGCCPATH) > .xcompile || rm -f .xcompile)))
147
Patrick Georgi6dda31d2015-11-19 15:15:33 +0100148-include .xcompile
149
150ifneq ($(XCOMPILE_COMPLETE),1)
151$(shell rm -f .xcompile)
152$(error .xcompile deleted because it's invalid. \
153 Restarting the build should fix that, or explain the problem)
154endif
Patrick Georgi7b9762f2015-06-04 13:18:11 +0200155
Patrick Georgicc84a002014-05-14 21:05:35 +0200156ifneq ($(CONFIG_MMX),y)
157CFLAGS_x86_32 += -mno-mmx
158endif
159
Jan Dabrosef1c9682020-03-28 00:15:03 +0100160ifneq ($(UNIT_TEST),1)
Patrick Georgicc84a002014-05-14 21:05:35 +0200161include toolchain.inc
Jan Dabrosef1c9682020-03-28 00:15:03 +0100162endif
Patrick Georgicc84a002014-05-14 21:05:35 +0200163
Zheng Bao07648922015-11-13 10:42:27 +0800164strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
Martin Rothbbf13992016-01-25 15:59:24 -0700165# fix makefile syntax highlighting after strip macro \" "))
Patrick Georgia84e98b2010-03-16 19:01:32 +0000166
Patrick Georgi0588d192009-08-12 15:00:51 +0000167# The primary target needs to be here before we include the
168# other files
169
Patrick Georgi71b84802011-02-22 14:35:05 +0000170real-all: real-target
Patrick Georgi0588d192009-08-12 15:00:51 +0000171
Patrick Georgi51e142f2010-03-27 17:18:39 +0000172# must come rather early
173.SECONDEXPANSION:
Raul E Rangelcc6dc902018-08-06 16:13:32 -0600174.DELETE_ON_ERROR:
Patrick Georgi51e142f2010-03-27 17:18:39 +0000175
Jonathan Neuschäferd2c02422018-12-11 13:06:40 +0100176$(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
Patrick Georgi78a5f222017-01-30 15:29:34 +0100177 +$(MAKE) oldconfig
Patrick Georgi0588d192009-08-12 15:00:51 +0000178
Nico Huber533bc0a2019-01-01 19:03:33 +0100179$(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
180 true
181
Nico Hubereafc8152019-10-25 12:47:14 +0200182$(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
Nico Huber533bc0a2019-01-01 19:03:33 +0100183 $(objutil)/kconfig/toada CB.Config <$< >$@
184
Nico Huberb5679772019-01-01 22:06:01 +0100185$(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
186 cp $< $@
187
Patrick Georgi58262652011-02-17 20:47:49 +0000188# Add a new class of source/object files to the build system
189add-class= \
190 $(eval $(1)-srcs:=) \
191 $(eval $(1)-objs:=) \
192 $(eval classes+=$(1))
Patrick Georgi8463dd92010-09-30 16:55:02 +0000193
Patrick Georgi58262652011-02-17 20:47:49 +0000194# Special classes are managed types with special behaviour
195# On parse time, for each entry in variable $(1)-y
196# a handler $(1)-handler is executed with the arguments:
197# * $(1): directory the parser is in
198# * $(2): current entry
199add-special-class= \
200 $(eval $(1):=) \
201 $(eval special-classes+=$(1))
202
Nico Huber81b09f42016-01-23 00:50:00 +0100203# Converts one or more source file paths to their corresponding build/ paths.
Nico Huber2e09d2b2016-01-14 01:13:33 +0100204# Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
205# their name.
Nico Huber81b09f42016-01-23 00:50:00 +0100206# $1 stage name
207# $2 file path (list)
Nico Huber98fc4262016-01-23 01:24:33 +0100208src-to-obj=\
209 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
210 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200211 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber98fc4262016-01-23 01:24:33 +0100212 $(patsubst src/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100213 $(patsubst %.ads,%.o,\
214 $(patsubst %.adb,%.o,\
Nico Huber98fc4262016-01-23 01:24:33 +0100215 $(patsubst %.c,%.o,\
216 $(patsubst %.S,%.o,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200217 $(subst .$(1),,$(2))))))))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100218
219# Converts one or more source file paths to the corresponding build/ paths
220# of their Ada library information (.ali) files.
221# $1 stage name
222# $2 file path (list)
223src-to-ali=\
224 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
225 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200226 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100227 $(patsubst src/%,$(obj)/%,\
228 $(patsubst %.ads,%.ali,\
229 $(patsubst %.adb,%.ali,\
230 $(subst .$(1),,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200231 $(filter %.ads %.adb,$(2)))))))))
Nico Huber81b09f42016-01-23 00:50:00 +0100232
Patrick Georgi47d68d82010-03-06 21:18:43 +0000233# Clean -y variables, include Makefile.inc
Patrick Georgi8463dd92010-09-30 16:55:02 +0000234# Add paths to files in X-y to X-srcs
Patrick Georgi47d68d82010-03-06 21:18:43 +0000235# Add subdirs-y to subdirs
236includemakefiles= \
Patrick Georgi58262652011-02-17 20:47:49 +0000237 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
Patrick Georgi47d68d82010-03-06 21:18:43 +0000238 $(eval -include $(1)) \
Patrick Georgi58262652011-02-17 20:47:49 +0000239 $(foreach class,$(classes-y), $(call add-class,$(class))) \
Arthur Heymans5e5fd412019-06-04 13:16:28 +0200240 $(foreach special,$(special-classes), \
241 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
Patrick Georgi58262652011-02-17 20:47:49 +0000242 $(foreach class,$(classes), \
243 $(eval $(class)-srcs+= \
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -0700244 $$(subst $(absobj)/,$(obj)/, \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000245 $$(subst $(top)/,, \
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -0700246 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
Patrick Georgi64b8fba2017-10-28 05:26:01 -0400247 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
Patrick Georgi47d68d82010-03-06 21:18:43 +0000248
Patrick Georgi8463dd92010-09-30 16:55:02 +0000249# For each path in $(subdirs) call includemakefiles
Patrick Georgi47d68d82010-03-06 21:18:43 +0000250# Repeat until subdirs is empty
251evaluate_subdirs= \
252 $(eval cursubdirs:=$(subdirs)) \
253 $(eval subdirs:=) \
254 $(foreach dir,$(cursubdirs), \
Patrick Georgi58262652011-02-17 20:47:49 +0000255 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000256 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000257
258# collect all object files eligible for building
Patrick Georgie38d0a62011-03-01 08:09:22 +0000259subdirs:=$(TOPLEVEL)
Julius Wernere91d1702017-03-20 15:32:15 -0700260postinclude-hooks :=
Jan Dabrosef1c9682020-03-28 00:15:03 +0100261
262# Don't iterate through Makefile.incs under src/ when building tests
263ifneq ($(UNIT_TEST),1)
Patrick Georgi51e142f2010-03-27 17:18:39 +0000264$(eval $(call evaluate_subdirs))
Jan Dabrosef1c9682020-03-28 00:15:03 +0100265else
266include $(TOPLEVEL)/tests/Makefile.inc
267endif
268
Patrick Georgi70c85ea2013-02-16 01:06:57 +0100269ifeq ($(FAILBUILD),1)
270$(error cannot continue build)
271endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000272
Julius Wernere91d1702017-03-20 15:32:15 -0700273# Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
274$(eval $(postinclude-hooks))
275
Patrick Georgi94a45862011-10-25 14:32:21 -0700276# Eliminate duplicate mentions of source files in a class
277$(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
278
Nico Huberb5679772019-01-01 22:06:01 +0100279# Build Kconfig .ads if necessary
280ifeq ($(CONFIG_RAMSTAGE_ADA),y)
281ramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
282endif
283
Nico Huber2e09d2b2016-01-14 01:13:33 +0100284# To track dependencies, we need all Ada specification (.ads) files in
285# *-srcs. Extract / filter all specification files that have a matching
286# body (.adb) file here (specifications without a body are valid sources
287# in Ada).
288$(foreach class,$(classes),$(eval $(class)-extra-specs := \
289 $(filter \
290 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
291 $(filter %.ads,$($(class)-srcs)))))
292$(foreach class,$(classes),$(eval $(class)-srcs := \
293 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
294
Patrick Georgi10f86b02015-03-27 16:56:23 +0100295$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100296$(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
297
298# For Ada includes
299$(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
Patrick Georgid3428b02010-02-24 13:18:01 +0000300
Nico Huber963bed52013-05-15 11:47:51 +0200301# Save all objs before processing them (for dependency inclusion)
302originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
303
Patrick Georgi79f90102012-11-25 14:31:08 +0100304# Call post-processors if they're defined
305$(foreach class,$(classes),\
306 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
307
Patrick Georgi58262652011-02-17 20:47:49 +0000308allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
309allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000310alldirs:=$(sort $(abspath $(dir $(allobjs))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000311
Nico Huber2e09d2b2016-01-14 01:13:33 +0100312# Reads dependencies from an Ada library information (.ali) file
313# Only basenames (with suffix) are preserved so we have to look the
314# paths up in $($(stage)-srcs).
315# $1 stage name
316# $2 ali file
317create_ada_deps=$$(if $(2),\
318 gnat.adc \
319 $$(filter \
320 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
321 $$($(1)-srcs) $$($(1)-extra-specs)))
322
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000323# macro to define template macros that are used by use_template macro
324define create_cc_template
Patrick Georgi71b84802011-02-22 14:35:05 +0000325# $1 obj class
Patrick Georgi990e7c92015-04-03 10:47:15 +0200326# $2 source suffix (c, S, ld, ...)
Marc Jonesa38ccfd2014-11-06 15:50:22 -0700327# $3 additional compiler flags
328# $4 additional dependencies
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000329ifn$(EMPTY)def $(1)-objs_$(2)_template
Patrick Georgi8463dd92010-09-30 16:55:02 +0000330de$(EMPTY)fine $(1)-objs_$(2)_template
Nico Huber1850aa62017-09-03 23:42:58 +0200331ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
Nico Huberb5679772019-01-01 22:06:01 +0100332$$(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 +0200333 @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
334 $(GCC_$(1)) \
335 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
336 $(3) -c -o $$$$@ $$$$<
337el$(EMPTY)se
338$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000339 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
Nico Huber2e09d2b2016-01-14 01:13:33 +0100340 $(CC_$(1)) \
Nico Huber1850aa62017-09-03 23:42:58 +0200341 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100342 $(3) -c -o $$$$@ $$$$<
Nico Huber1850aa62017-09-03 23:42:58 +0200343end$(EMPTY)if
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000344en$(EMPTY)def
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000345end$(EMPTY)if
Patrick Georgi0588d192009-08-12 15:00:51 +0000346endef
347
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000348filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
349$(foreach class,$(classes), \
350 $(foreach type,$(call filetypes-of-class,$(class)), \
Patrick Georgi2459aee2015-03-27 15:27:21 +0100351 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
Patrick Georgi416ab382015-04-03 10:19:38 +0200352 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
353 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000354
Patrick Georgid69839b2015-04-03 10:32:17 +0200355foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
Patrick Georgi58262652011-02-17 20:47:49 +0000356$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000357
Nico Huber2e09d2b2016-01-14 01:13:33 +0100358# To supported complex package initializations, we need to call the
359# emitted code explicitly. gnatbind gathers all the calls for us
360# and exports them as a procedure $(stage)_adainit(). Every stage that
361# uses Ada code has to call it!
362define gnatbind_template
363# $1 class
364$$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
365 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
366 # We have to give gnatbind a simple filename (without leading
367 # path components) so just cd there.
368 cd $$(dir $$@) && \
369 $$(GNATBIND_$(1)) -a -n \
Nico Huberbe5492a2015-09-29 16:41:19 +0200370 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100371 -L$(1)_ada -o $$(notdir $$@) \
372 $$(subst $$(dir $$@),,$$^)
373$$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
Nico Huber1850aa62017-09-03 23:42:58 +0200374 @printf " GCC $$(subst $$(obj)/,,$$@)\n"
375 $(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
Nico Huber2e09d2b2016-01-14 01:13:33 +0100376$(1)-objs += $$(obj)/$(1)/b__$(1).o
Nico Huberddb24652016-09-19 11:50:04 +0200377$($(1)-alis): %.ali: %.o ;
Nico Huber2e09d2b2016-01-14 01:13:33 +0100378endef
379
Nico Huberbe5492a2015-09-29 16:41:19 +0200380$(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100381 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
382
Julius Wernerf97b88b2014-12-05 12:32:09 -0800383DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000384-include $(DEPENDENCIES)
385
Patrick Georgi0588d192009-08-12 15:00:51 +0000386printall:
Martin Roth09b64442016-06-05 10:52:43 -0600387 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
388 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
389 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
390 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
391 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
Patrick Georgi0588d192009-08-12 15:00:51 +0000392endif
393
Patrick Georgi40ad8422011-05-21 22:18:59 +0000394ifndef NOMKDIR
Stefan Reinauerde60c882015-06-29 14:44:37 -0700395$(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
Patrick Georgi40ad8422011-05-21 22:18:59 +0000396endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000397
Martin Roth9b0204d2017-09-18 09:25:18 -0600398$(obj)/project_filelist.txt:
399 if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
400 echo "*** Error: Project must be built before generating file list ***"; \
401 exit 1; \
402 fi
Martin Roth8a027272017-09-26 09:53:30 -0600403 find $(obj) -path "$(obj)/util" -prune -o -name "*.d" -exec cat {} \; | \
404 sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
Martin Roth9c1b33e2015-07-29 14:55:18 -0700405 grep -v '\.o$$' > $(obj)/project_filelist.txt
406
Martin Roth9b0204d2017-09-18 09:25:18 -0600407filelist: $(obj)/project_filelist.txt
Martin Rotha18353d2017-06-06 06:44:46 -0600408 printf "\nFiles used in build:\n"
409 cat $(obj)/project_filelist.txt
410
Martin Roth9c1b33e2015-07-29 14:55:18 -0700411#works with either exuberant ctags or ctags.emacs
412ctags-project: clean-ctags $(obj)/project_filelist.txt
413 cat $(obj)/project_filelist.txt | \
414 xargs ctags -o tags
415
416cscope-project: clean-cscope $(obj)/project_filelist.txt
417 cat $(obj)/project_filelist.txt | xargs cscope -b
418
Warren Turkala9fc3302010-09-03 08:57:32 +0000419cscope:
420 cscope -bR
421
Patrick Georgi0588d192009-08-12 15:00:51 +0000422doxy: doxygen
423doxygen:
Nicky Sielickie08a2a52015-06-06 08:55:16 -0500424 $(DOXYGEN) Documentation/Doxyfile.coreboot
Patrick Georgi0588d192009-08-12 15:00:51 +0000425
Martin Rothd7689e42014-12-29 14:56:19 -0700426doxygen_simple:
Nicky Sielickie08a2a52015-06-06 08:55:16 -0500427 $(DOXYGEN) Documentation/Doxyfile.coreboot_simple
Martin Rothd7689e42014-12-29 14:56:19 -0700428
Martin Rothb1574e32016-07-07 15:50:28 -0600429doxyplatform doxygen_platform: $(obj)/project_filelist.txt
430 echo
431 echo "Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
432 export DOXYGEN_OUTPUT_DIR="$(DOXYGEN_OUTPUT_DIR)/$(CONFIG_MAINBOARD_VENDOR)/$(CONFIG_MAINBOARD_PART_NUMBER)"; \
433 mkdir -p "$$DOXYGEN_OUTPUT_DIR"; \
434 export DOXYFILES="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
435 export DOXYGEN_PLATFORM="$(CONFIG_MAINBOARD_DIR) ($(CONFIG_MAINBOARD_PART_NUMBER)) version $(KERNELVERSION)"; \
436 $(DOXYGEN) Documentation/doxygen/Doxyfile.coreboot_platform
437
Patrick Georgi0588d192009-08-12 15:00:51 +0000438doxyclean: doxygen-clean
439doxygen-clean:
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000440 rm -rf $(DOXYGEN_OUTPUT_DIR)
Patrick Georgi0588d192009-08-12 15:00:51 +0000441
Patrick Georgi71b84802011-02-22 14:35:05 +0000442clean-for-update: doxygen-clean clean-for-update-target
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100443 rm -rf $(obj) .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000444
Martin Roth20cd54f2017-03-26 18:49:02 -0600445clean: clean-for-update clean-target clean-utils
Patrick Georgi71b84802011-02-22 14:35:05 +0000446 rm -f .ccwrap
Warren Turkal0e8f2042010-09-27 21:14:19 +0000447
Warren Turkala9fc3302010-09-03 08:57:32 +0000448clean-cscope:
449 rm -f cscope.out
450
Martin Roth9c1b33e2015-07-29 14:55:18 -0700451clean-ctags:
452 rm -f tags
453
Martin Roth20cd54f2017-03-26 18:49:02 -0600454clean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600455 $(foreach tool, $(TOOLLIST), \
456 $(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
Martin Roth20cd54f2017-03-26 18:49:02 -0600457
458distclean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600459 $(foreach tool, $(TOOLLIST), \
460 $(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
Martin Roth20cd54f2017-03-26 18:49:02 -0600461 rm -f /util/$(tool)/junit.xml;)
462
463distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
Patrick Georgi80656af2017-04-26 11:58:44 +0200464 rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
Martin Roth20cd54f2017-03-26 18:49:02 -0600465 rm -rf coreboot-builds coreboot-builds-chromeos
466 rm -f abuild*.xml junit.xml* util/lint/junit.xml
Patrick Georgi0588d192009-08-12 15:00:51 +0000467
Martin Rothd7689e42014-12-29 14:56:19 -0700468.PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple
Martin Roth9c1b33e2015-07-29 14:55:18 -0700469.PHONY: ctags-project cscope-project clean-ctags