blob: 41a9b3afa42815721b1e89402327e7b4ed3bec13 [file] [log] [blame]
Patrick Georgi0588d192009-08-12 15:00:51 +00001##
2## This file is part of the coreboot project.
3##
4## Copyright (C) 2008 Advanced Micro Devices, Inc.
5## Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
Stefan Reinauer8ed1b6d2010-01-19 21:13:44 +00006## Copyright (C) 2009-2010 coresystems GmbH
Patrick Georgi71b84802011-02-22 14:35:05 +00007## Copyright (C) 2011 secunet Security Networks AG
Patrick Georgi0588d192009-08-12 15:00:51 +00008##
Patrick Georgi3bda0442011-06-30 15:48:57 +02009## Redistribution and use in source and binary forms, with or without
10## modification, are permitted provided that the following conditions
11## are met:
12## 1. Redistributions of source code must retain the above copyright
13## notice, this list of conditions and the following disclaimer.
14## 2. Redistributions in binary form must reproduce the above copyright
15## notice, this list of conditions and the following disclaimer in the
16## documentation and/or other materials provided with the distribution.
17## 3. The name of the author may not be used to endorse or promote products
18## derived from this software without specific prior written permission.
Patrick Georgi0588d192009-08-12 15:00:51 +000019##
Patrick Georgi3bda0442011-06-30 15:48:57 +020020## THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30## SUCH DAMAGE.
Patrick Georgi0588d192009-08-12 15:00:51 +000031##
32
Himanshu Sahdevd1e18d92019-09-16 15:55:03 +053033ifneq ($(words $(CURDIR)),1)
34 $(error Error: Path to the main directory cannot contain spaces)
35endif
Nico Huber7a1fbdb2017-08-23 23:48:13 +020036top := $(CURDIR)
37src := src
38srck := $(top)/util/kconfig
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -070039obj ?= build
40override obj := $(subst $(top)/,,$(abspath $(obj)))
Nico Huber7a1fbdb2017-08-23 23:48:13 +020041objutil ?= $(obj)/util
42objk := $(objutil)/kconfig
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -070043absobj := $(abspath $(obj))
Patrick Georgi0588d192009-08-12 15:00:51 +000044
Nico Huber7a1fbdb2017-08-23 23:48:13 +020045COREBOOT_EXPORTS := COREBOOT_EXPORTS
46COREBOOT_EXPORTS += top src srck obj objutil objk
Patrick Georgi0588d192009-08-12 15:00:51 +000047
Alexander Couzensbe756f12019-09-13 04:22:12 +020048# reproducible builds
49LANG:=C
50LC_ALL:=C
51TZ:=UTC0
52COREBOOT_EXPORTS += LANG LC_ALL TZ
53
Nico Huber7a1fbdb2017-08-23 23:48:13 +020054DOTCONFIG ?= $(top)/.config
55KCONFIG_CONFIG = $(DOTCONFIG)
Nico Huber533bc0a2019-01-01 19:03:33 +010056KCONFIG_AUTOADS := $(obj)/cb-config.ads
Nico Huber7a1fbdb2017-08-23 23:48:13 +020057KCONFIG_AUTOHEADER := $(obj)/config.h
58KCONFIG_AUTOCONFIG := $(obj)/auto.conf
59KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
60KCONFIG_SPLITCONFIG := $(obj)/config
61KCONFIG_TRISTATE := $(obj)/tristate.conf
62KCONFIG_NEGATIVES := 1
63KCONFIG_STRICT := 1
Nico Huber533bc0a2019-01-01 19:03:33 +010064KCONFIG_PACKAGE := CB.Config
Nico Huber7a1fbdb2017-08-23 23:48:13 +020065
66COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
67COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
68COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_STRICT
Nico Huber533bc0a2019-01-01 19:03:33 +010069COREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE
Patrick Georgi0588d192009-08-12 15:00:51 +000070
Patrick Georgie38d0a62011-03-01 08:09:22 +000071# directory containing the toplevel Makefile.inc
72TOPLEVEL := .
73
Patrick Georgi0588d192009-08-12 15:00:51 +000074CONFIG_SHELL := sh
75KBUILD_DEFCONFIG := configs/defconfig
76UNAME_RELEASE := $(shell uname -r)
Patrick Georgi89ec3762010-12-08 19:58:30 +000077HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
Patrick Georgi0588d192009-08-12 15:00:51 +000078MAKEFLAGS += -rR --no-print-directory
79
80# Make is silent per default, but 'make V=1' will show all compiler calls.
Patrick Georgi2b7418e2009-08-25 19:38:46 +000081Q:=@
Patrick Georgi0588d192009-08-12 15:00:51 +000082ifneq ($(V),1)
Patrick Georgi2b7418e2009-08-25 19:38:46 +000083ifneq ($(Q),)
84.SILENT:
85endif
Patrick Georgi0588d192009-08-12 15:00:51 +000086endif
87
Julius Werner808a4292015-03-13 11:05:07 -070088# Disable implicit/built-in rules to make Makefile errors fail fast.
89.SUFFIXES:
90
Patrick Georgif92068d2016-02-01 12:02:29 +010091HOSTCC := $(if $(shell type gcc 2>/dev/null),gcc,cc)
Patrick Georgi0588d192009-08-12 15:00:51 +000092HOSTCXX = g++
Patrick Georgib3a18ac2012-09-13 22:13:33 +020093HOSTCFLAGS := -g
94HOSTCXXFLAGS := -g
Patrick Georgi0588d192009-08-12 15:00:51 +000095
Patrick Georgi828e0e82015-04-04 15:50:20 +020096PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
97
Patrick Georgi0588d192009-08-12 15:00:51 +000098DOXYGEN := doxygen
99DOXYGEN_OUTPUT_DIR := doxygen
100
Nico Huber7a1fbdb2017-08-23 23:48:13 +0200101export $(COREBOOT_EXPORTS)
102
Patrick Georgi71b84802011-02-22 14:35:05 +0000103all: real-all
104
Martin Roth4eea1742015-11-25 11:50:04 -0700105help_coreboot help::
106 @echo '*** coreboot platform targets ***'
Martin Roth76f14b22015-11-18 13:09:23 -0700107 @echo ' Use "make [target] V=1" for extra build debug information'
108 @echo ' all - Build coreboot'
109 @echo ' clean - Remove coreboot build artifacts'
110 @echo ' distclean - Remove build artifacts and config files'
111 @echo ' doxygen - Build doxygen documentation for coreboot'
Martin Rothb1574e32016-07-07 15:50:28 -0600112 @echo ' doxyplatform - Build doxygen documentation for the current platform'
Martin Roth763e4932018-01-27 16:42:43 -0700113 @echo ' filelist - Show files used in current build'
Martin Roth76f14b22015-11-18 13:09:23 -0700114 @echo ' printall - print makefile info for debugging'
Werner Zeh2de64102016-01-12 12:45:49 +0100115 @echo ' gitconfig - set up git to submit patches to coreboot'
Martin Roth76f14b22015-11-18 13:09:23 -0700116 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
117 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
118 @echo
119
Patrick Georgie38d0a62011-03-01 08:09:22 +0000120# This include must come _before_ the pattern rules below!
Patrick Georgi71b84802011-02-22 14:35:05 +0000121# Order _does_ matter for pattern rules.
Patrick Georgi3e8ef102019-11-22 16:54:17 +0100122include $(srck)/Makefile.inc
Patrick Georgi71b84802011-02-22 14:35:05 +0000123
Patrick Georgicf036d12010-04-21 06:36:20 +0000124# Three cases where we don't need fully populated $(obj) lists:
125# 1. when no .config exists
126# 2. when make config (in any flavour) is run
127# 3. when make distclean is run
128# Don't waste time on reading all Makefile.incs in these cases
Patrick Georgi0588d192009-08-12 15:00:51 +0000129ifeq ($(strip $(HAVE_DOTCONFIG)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000130NOCOMPILE:=1
131endif
132ifneq ($(MAKECMDGOALS),)
Martin Roth109a7db2016-08-11 18:16:59 -0600133ifneq ($(filter %config %clean cross% clang iasl gnumake lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
Patrick Georgicf036d12010-04-21 06:36:20 +0000134NOCOMPILE:=1
135endif
Raul E Rangel5592cfd2019-07-23 11:13:40 -0600136ifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
Zheng Bao0fd93d62012-10-22 16:36:03 +0800137NOMKDIR:=1
138endif
Patrick Georgicf036d12010-04-21 06:36:20 +0000139endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000140
Raul E Rangel6325ce22019-07-10 16:46:34 -0600141.xcompile: util/xcompile/xcompile
142 rm -f $@
143 $< $(XGCCPATH) > $@.tmp
144 \mv -f $@.tmp $@ 2> /dev/null
145 rm -f $@.tmp
146
Patrick Georgicf036d12010-04-21 06:36:20 +0000147ifeq ($(NOCOMPILE),1)
Patrick Georgie38d0a62011-03-01 08:09:22 +0000148include $(TOPLEVEL)/Makefile.inc
Martin Roth67975572016-03-07 16:38:52 -0700149include $(TOPLEVEL)/payloads/Makefile.inc
Martin Rothe624e272017-07-31 11:52:58 -0600150include $(TOPLEVEL)/util/testing/Makefile.inc
Werner Zehb7f1c2d2019-10-04 07:01:13 +0200151-include $(TOPLEVEL)/site-local/Makefile.inc
Martin Roth20aa0432017-01-26 10:51:43 -0700152real-all:
153 @echo "Error: Expected config file ($(DOTCONFIG)) not present." >&2
154 @echo "Please specify a config file or run 'make menuconfig' to" >&2
155 @echo "generate a new config file." >&2
156 @exit 1
Patrick Georgi0588d192009-08-12 15:00:51 +0000157else
158
Paul Kocialkowski585c7812016-07-13 11:00:41 +0200159include $(DOTCONFIG)
Patrick Georgi0588d192009-08-12 15:00:51 +0000160
Patrick Georgi0ffef882017-01-19 23:20:14 +0100161# in addition to the dependency below, create the file if it doesn't exist
162# to silence stupid warnings about a file that would be generated anyway.
163$(if $(wildcard .xcompile)$(NOCOMPILE),,$(eval $(shell util/xcompile/xcompile $(XGCCPATH) > .xcompile || rm -f .xcompile)))
164
Patrick Georgi6dda31d2015-11-19 15:15:33 +0100165-include .xcompile
166
167ifneq ($(XCOMPILE_COMPLETE),1)
168$(shell rm -f .xcompile)
169$(error .xcompile deleted because it's invalid. \
170 Restarting the build should fix that, or explain the problem)
171endif
Patrick Georgi7b9762f2015-06-04 13:18:11 +0200172
Patrick Georgicc84a002014-05-14 21:05:35 +0200173ifneq ($(CONFIG_MMX),y)
174CFLAGS_x86_32 += -mno-mmx
175endif
176
Patrick Georgicc84a002014-05-14 21:05:35 +0200177include toolchain.inc
178
Zheng Bao07648922015-11-13 10:42:27 +0800179strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
Martin Rothbbf13992016-01-25 15:59:24 -0700180# fix makefile syntax highlighting after strip macro \" "))
Patrick Georgia84e98b2010-03-16 19:01:32 +0000181
Patrick Georgi0588d192009-08-12 15:00:51 +0000182# The primary target needs to be here before we include the
183# other files
184
Patrick Georgi71b84802011-02-22 14:35:05 +0000185real-all: real-target
Patrick Georgi0588d192009-08-12 15:00:51 +0000186
Patrick Georgi51e142f2010-03-27 17:18:39 +0000187# must come rather early
188.SECONDEXPANSION:
Raul E Rangelcc6dc902018-08-06 16:13:32 -0600189.DELETE_ON_ERROR:
Patrick Georgi51e142f2010-03-27 17:18:39 +0000190
Jonathan Neuschäferd2c02422018-12-11 13:06:40 +0100191$(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
Patrick Georgi78a5f222017-01-30 15:29:34 +0100192 +$(MAKE) oldconfig
Patrick Georgi0588d192009-08-12 15:00:51 +0000193
Nico Huber533bc0a2019-01-01 19:03:33 +0100194$(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
195 true
196
Nico Hubereafc8152019-10-25 12:47:14 +0200197$(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
Nico Huber533bc0a2019-01-01 19:03:33 +0100198 $(objutil)/kconfig/toada CB.Config <$< >$@
199
Nico Huberb5679772019-01-01 22:06:01 +0100200$(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
201 cp $< $@
202
Patrick Georgi58262652011-02-17 20:47:49 +0000203# Add a new class of source/object files to the build system
204add-class= \
205 $(eval $(1)-srcs:=) \
206 $(eval $(1)-objs:=) \
207 $(eval classes+=$(1))
Patrick Georgi8463dd92010-09-30 16:55:02 +0000208
Patrick Georgi58262652011-02-17 20:47:49 +0000209# Special classes are managed types with special behaviour
210# On parse time, for each entry in variable $(1)-y
211# a handler $(1)-handler is executed with the arguments:
212# * $(1): directory the parser is in
213# * $(2): current entry
214add-special-class= \
215 $(eval $(1):=) \
216 $(eval special-classes+=$(1))
217
Nico Huber81b09f42016-01-23 00:50:00 +0100218# Converts one or more source file paths to their corresponding build/ paths.
Nico Huber2e09d2b2016-01-14 01:13:33 +0100219# Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
220# their name.
Nico Huber81b09f42016-01-23 00:50:00 +0100221# $1 stage name
222# $2 file path (list)
Nico Huber98fc4262016-01-23 01:24:33 +0100223src-to-obj=\
224 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
225 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200226 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber98fc4262016-01-23 01:24:33 +0100227 $(patsubst src/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100228 $(patsubst %.ads,%.o,\
229 $(patsubst %.adb,%.o,\
Nico Huber98fc4262016-01-23 01:24:33 +0100230 $(patsubst %.c,%.o,\
231 $(patsubst %.S,%.o,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200232 $(subst .$(1),,$(2))))))))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100233
234# Converts one or more source file paths to the corresponding build/ paths
235# of their Ada library information (.ali) files.
236# $1 stage name
237# $2 file path (list)
238src-to-ali=\
239 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
240 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200241 $(patsubst 3rdparty/%,$(obj)/%,\
Nico Huber2e09d2b2016-01-14 01:13:33 +0100242 $(patsubst src/%,$(obj)/%,\
243 $(patsubst %.ads,%.ali,\
244 $(patsubst %.adb,%.ali,\
245 $(subst .$(1),,\
Nico Huberd011b6b2016-10-05 17:41:31 +0200246 $(filter %.ads %.adb,$(2)))))))))
Nico Huber81b09f42016-01-23 00:50:00 +0100247
Patrick Georgi47d68d82010-03-06 21:18:43 +0000248# Clean -y variables, include Makefile.inc
Patrick Georgi8463dd92010-09-30 16:55:02 +0000249# Add paths to files in X-y to X-srcs
Patrick Georgi47d68d82010-03-06 21:18:43 +0000250# Add subdirs-y to subdirs
251includemakefiles= \
Patrick Georgi58262652011-02-17 20:47:49 +0000252 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
Patrick Georgi47d68d82010-03-06 21:18:43 +0000253 $(eval -include $(1)) \
Patrick Georgi58262652011-02-17 20:47:49 +0000254 $(foreach class,$(classes-y), $(call add-class,$(class))) \
Arthur Heymans5e5fd412019-06-04 13:16:28 +0200255 $(foreach special,$(special-classes), \
256 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
Patrick Georgi58262652011-02-17 20:47:49 +0000257 $(foreach class,$(classes), \
258 $(eval $(class)-srcs+= \
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -0700259 $$(subst $(absobj)/,$(obj)/, \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000260 $$(subst $(top)/,, \
Vadim Bendebury5f7e4f02015-05-06 21:00:10 -0700261 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
Patrick Georgi64b8fba2017-10-28 05:26:01 -0400262 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
Patrick Georgi47d68d82010-03-06 21:18:43 +0000263
Patrick Georgi8463dd92010-09-30 16:55:02 +0000264# For each path in $(subdirs) call includemakefiles
Patrick Georgi47d68d82010-03-06 21:18:43 +0000265# Repeat until subdirs is empty
266evaluate_subdirs= \
267 $(eval cursubdirs:=$(subdirs)) \
268 $(eval subdirs:=) \
269 $(foreach dir,$(cursubdirs), \
Patrick Georgi58262652011-02-17 20:47:49 +0000270 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000271 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000272
273# collect all object files eligible for building
Patrick Georgie38d0a62011-03-01 08:09:22 +0000274subdirs:=$(TOPLEVEL)
Julius Wernere91d1702017-03-20 15:32:15 -0700275postinclude-hooks :=
Patrick Georgi51e142f2010-03-27 17:18:39 +0000276$(eval $(call evaluate_subdirs))
Patrick Georgi70c85ea2013-02-16 01:06:57 +0100277ifeq ($(FAILBUILD),1)
278$(error cannot continue build)
279endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000280
Julius Wernere91d1702017-03-20 15:32:15 -0700281# Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
282$(eval $(postinclude-hooks))
283
Patrick Georgi94a45862011-10-25 14:32:21 -0700284# Eliminate duplicate mentions of source files in a class
285$(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
286
Nico Huberb5679772019-01-01 22:06:01 +0100287# Build Kconfig .ads if necessary
288ifeq ($(CONFIG_RAMSTAGE_ADA),y)
289ramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
290endif
291
Nico Huber2e09d2b2016-01-14 01:13:33 +0100292# To track dependencies, we need all Ada specification (.ads) files in
293# *-srcs. Extract / filter all specification files that have a matching
294# body (.adb) file here (specifications without a body are valid sources
295# in Ada).
296$(foreach class,$(classes),$(eval $(class)-extra-specs := \
297 $(filter \
298 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
299 $(filter %.ads,$($(class)-srcs)))))
300$(foreach class,$(classes),$(eval $(class)-srcs := \
301 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
302
Patrick Georgi10f86b02015-03-27 16:56:23 +0100303$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
Nico Huber2e09d2b2016-01-14 01:13:33 +0100304$(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
305
306# For Ada includes
307$(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
Patrick Georgid3428b02010-02-24 13:18:01 +0000308
Nico Huber963bed52013-05-15 11:47:51 +0200309# Save all objs before processing them (for dependency inclusion)
310originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
311
Patrick Georgi79f90102012-11-25 14:31:08 +0100312# Call post-processors if they're defined
313$(foreach class,$(classes),\
314 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
315
Patrick Georgi58262652011-02-17 20:47:49 +0000316allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
317allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000318alldirs:=$(sort $(abspath $(dir $(allobjs))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000319
Nico Huber2e09d2b2016-01-14 01:13:33 +0100320# Reads dependencies from an Ada library information (.ali) file
321# Only basenames (with suffix) are preserved so we have to look the
322# paths up in $($(stage)-srcs).
323# $1 stage name
324# $2 ali file
325create_ada_deps=$$(if $(2),\
326 gnat.adc \
327 $$(filter \
328 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
329 $$($(1)-srcs) $$($(1)-extra-specs)))
330
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000331# macro to define template macros that are used by use_template macro
332define create_cc_template
Patrick Georgi71b84802011-02-22 14:35:05 +0000333# $1 obj class
Patrick Georgi990e7c92015-04-03 10:47:15 +0200334# $2 source suffix (c, S, ld, ...)
Marc Jonesa38ccfd2014-11-06 15:50:22 -0700335# $3 additional compiler flags
336# $4 additional dependencies
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000337ifn$(EMPTY)def $(1)-objs_$(2)_template
Patrick Georgi8463dd92010-09-30 16:55:02 +0000338de$(EMPTY)fine $(1)-objs_$(2)_template
Nico Huber1850aa62017-09-03 23:42:58 +0200339ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
Nico Huberb5679772019-01-01 22:06:01 +0100340$$(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 +0200341 @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
342 $(GCC_$(1)) \
343 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
344 $(3) -c -o $$$$@ $$$$<
345el$(EMPTY)se
346$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000347 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
Nico Huber2e09d2b2016-01-14 01:13:33 +0100348 $(CC_$(1)) \
Nico Huber1850aa62017-09-03 23:42:58 +0200349 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100350 $(3) -c -o $$$$@ $$$$<
Nico Huber1850aa62017-09-03 23:42:58 +0200351end$(EMPTY)if
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000352en$(EMPTY)def
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000353end$(EMPTY)if
Patrick Georgi0588d192009-08-12 15:00:51 +0000354endef
355
Patrick Georgib8cdd9b2011-02-17 20:48:45 +0000356filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
357$(foreach class,$(classes), \
358 $(foreach type,$(call filetypes-of-class,$(class)), \
Patrick Georgi2459aee2015-03-27 15:27:21 +0100359 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
Patrick Georgi416ab382015-04-03 10:19:38 +0200360 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
361 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000362
Patrick Georgid69839b2015-04-03 10:32:17 +0200363foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
Patrick Georgi58262652011-02-17 20:47:49 +0000364$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000365
Nico Huber2e09d2b2016-01-14 01:13:33 +0100366# To supported complex package initializations, we need to call the
367# emitted code explicitly. gnatbind gathers all the calls for us
368# and exports them as a procedure $(stage)_adainit(). Every stage that
369# uses Ada code has to call it!
370define gnatbind_template
371# $1 class
372$$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
373 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
374 # We have to give gnatbind a simple filename (without leading
375 # path components) so just cd there.
376 cd $$(dir $$@) && \
377 $$(GNATBIND_$(1)) -a -n \
Nico Huberbe5492a2015-09-29 16:41:19 +0200378 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100379 -L$(1)_ada -o $$(notdir $$@) \
380 $$(subst $$(dir $$@),,$$^)
381$$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
Nico Huber1850aa62017-09-03 23:42:58 +0200382 @printf " GCC $$(subst $$(obj)/,,$$@)\n"
383 $(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
Nico Huber2e09d2b2016-01-14 01:13:33 +0100384$(1)-objs += $$(obj)/$(1)/b__$(1).o
Nico Huberddb24652016-09-19 11:50:04 +0200385$($(1)-alis): %.ali: %.o ;
Nico Huber2e09d2b2016-01-14 01:13:33 +0100386endef
387
Nico Huberbe5492a2015-09-29 16:41:19 +0200388$(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
Nico Huber2e09d2b2016-01-14 01:13:33 +0100389 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
390
Julius Wernerf97b88b2014-12-05 12:32:09 -0800391DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000392-include $(DEPENDENCIES)
393
Patrick Georgi0588d192009-08-12 15:00:51 +0000394printall:
Martin Roth09b64442016-06-05 10:52:43 -0600395 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
396 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
397 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
398 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
399 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
Patrick Georgi0588d192009-08-12 15:00:51 +0000400endif
401
Patrick Georgi40ad8422011-05-21 22:18:59 +0000402ifndef NOMKDIR
Stefan Reinauerde60c882015-06-29 14:44:37 -0700403$(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
Patrick Georgi40ad8422011-05-21 22:18:59 +0000404endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000405
Martin Roth9b0204d2017-09-18 09:25:18 -0600406$(obj)/project_filelist.txt:
407 if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
408 echo "*** Error: Project must be built before generating file list ***"; \
409 exit 1; \
410 fi
Martin Roth8a027272017-09-26 09:53:30 -0600411 find $(obj) -path "$(obj)/util" -prune -o -name "*.d" -exec cat {} \; | \
412 sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
Martin Roth9c1b33e2015-07-29 14:55:18 -0700413 grep -v '\.o$$' > $(obj)/project_filelist.txt
414
Martin Roth9b0204d2017-09-18 09:25:18 -0600415filelist: $(obj)/project_filelist.txt
Martin Rotha18353d2017-06-06 06:44:46 -0600416 printf "\nFiles used in build:\n"
417 cat $(obj)/project_filelist.txt
418
Martin Roth9c1b33e2015-07-29 14:55:18 -0700419#works with either exuberant ctags or ctags.emacs
420ctags-project: clean-ctags $(obj)/project_filelist.txt
421 cat $(obj)/project_filelist.txt | \
422 xargs ctags -o tags
423
424cscope-project: clean-cscope $(obj)/project_filelist.txt
425 cat $(obj)/project_filelist.txt | xargs cscope -b
426
Warren Turkala9fc3302010-09-03 08:57:32 +0000427cscope:
428 cscope -bR
429
Patrick Georgi0588d192009-08-12 15:00:51 +0000430doxy: doxygen
431doxygen:
Nicky Sielickie08a2a52015-06-06 08:55:16 -0500432 $(DOXYGEN) Documentation/Doxyfile.coreboot
Patrick Georgi0588d192009-08-12 15:00:51 +0000433
Martin Rothd7689e42014-12-29 14:56:19 -0700434doxygen_simple:
Nicky Sielickie08a2a52015-06-06 08:55:16 -0500435 $(DOXYGEN) Documentation/Doxyfile.coreboot_simple
Martin Rothd7689e42014-12-29 14:56:19 -0700436
Martin Rothb1574e32016-07-07 15:50:28 -0600437doxyplatform doxygen_platform: $(obj)/project_filelist.txt
438 echo
439 echo "Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
440 export DOXYGEN_OUTPUT_DIR="$(DOXYGEN_OUTPUT_DIR)/$(CONFIG_MAINBOARD_VENDOR)/$(CONFIG_MAINBOARD_PART_NUMBER)"; \
441 mkdir -p "$$DOXYGEN_OUTPUT_DIR"; \
442 export DOXYFILES="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
443 export DOXYGEN_PLATFORM="$(CONFIG_MAINBOARD_DIR) ($(CONFIG_MAINBOARD_PART_NUMBER)) version $(KERNELVERSION)"; \
444 $(DOXYGEN) Documentation/doxygen/Doxyfile.coreboot_platform
445
Patrick Georgi0588d192009-08-12 15:00:51 +0000446doxyclean: doxygen-clean
447doxygen-clean:
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000448 rm -rf $(DOXYGEN_OUTPUT_DIR)
Patrick Georgi0588d192009-08-12 15:00:51 +0000449
Patrick Georgi71b84802011-02-22 14:35:05 +0000450clean-for-update: doxygen-clean clean-for-update-target
Patrick Georgi02ae0bf2013-02-09 15:45:02 +0100451 rm -rf $(obj) .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000452
Martin Roth20cd54f2017-03-26 18:49:02 -0600453clean: clean-for-update clean-target clean-utils
Patrick Georgi71b84802011-02-22 14:35:05 +0000454 rm -f .ccwrap
Warren Turkal0e8f2042010-09-27 21:14:19 +0000455
Warren Turkala9fc3302010-09-03 08:57:32 +0000456clean-cscope:
457 rm -f cscope.out
458
Martin Roth9c1b33e2015-07-29 14:55:18 -0700459clean-ctags:
460 rm -f tags
461
Martin Roth20cd54f2017-03-26 18:49:02 -0600462clean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600463 $(foreach tool, $(TOOLLIST), \
464 $(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
Martin Roth20cd54f2017-03-26 18:49:02 -0600465
466distclean-utils:
Martin Roth1d721ed2017-07-07 10:49:48 -0600467 $(foreach tool, $(TOOLLIST), \
468 $(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
Martin Roth20cd54f2017-03-26 18:49:02 -0600469 rm -f /util/$(tool)/junit.xml;)
470
471distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
Patrick Georgi80656af2017-04-26 11:58:44 +0200472 rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
Martin Roth20cd54f2017-03-26 18:49:02 -0600473 rm -rf coreboot-builds coreboot-builds-chromeos
474 rm -f abuild*.xml junit.xml* util/lint/junit.xml
Patrick Georgi0588d192009-08-12 15:00:51 +0000475
Martin Rothd7689e42014-12-29 14:56:19 -0700476.PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple
Martin Roth9c1b33e2015-07-29 14:55:18 -0700477.PHONY: ctags-project cscope-project clean-ctags