xref: /aosp_15_r20/external/coreboot/Makefile (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1*b9411a12SAndroid Build Coastguard Worker## SPDX-License-Identifier: BSD-3-Clause
2*b9411a12SAndroid Build Coastguard Worker
3*b9411a12SAndroid Build Coastguard Workerifneq ($(words $(CURDIR)),1)
4*b9411a12SAndroid Build Coastguard Worker    $(error Error: Path to the main directory cannot contain spaces)
5*b9411a12SAndroid Build Coastguard Workerendif
6*b9411a12SAndroid Build Coastguard Workertop := $(CURDIR)
7*b9411a12SAndroid Build Coastguard Workersrc := src
8*b9411a12SAndroid Build Coastguard Workersrck := $(top)/util/kconfig
9*b9411a12SAndroid Build Coastguard Workerobj ?= build
10*b9411a12SAndroid Build Coastguard Workeroverride obj := $(subst $(top)/,,$(abspath $(obj)))
11*b9411a12SAndroid Build Coastguard Workerxcompile ?= $(obj)/xcompile
12*b9411a12SAndroid Build Coastguard Workerobjutil ?= $(obj)/util
13*b9411a12SAndroid Build Coastguard Workerobjk := $(objutil)/kconfig
14*b9411a12SAndroid Build Coastguard Workerabsobj := $(abspath $(obj))
15*b9411a12SAndroid Build Coastguard Worker
16*b9411a12SAndroid Build Coastguard Workeradditional-dirs :=
17*b9411a12SAndroid Build Coastguard Worker
18*b9411a12SAndroid Build Coastguard WorkerVBOOT_HOST_BUILD ?= $(abspath $(objutil)/vboot_lib)
19*b9411a12SAndroid Build Coastguard Worker
20*b9411a12SAndroid Build Coastguard WorkerCOREBOOT_EXPORTS := COREBOOT_EXPORTS
21*b9411a12SAndroid Build Coastguard WorkerCOREBOOT_EXPORTS += top src srck obj objutil objk
22*b9411a12SAndroid Build Coastguard Worker
23*b9411a12SAndroid Build Coastguard WorkerDOTCONFIG ?= $(top)/.config
24*b9411a12SAndroid Build Coastguard WorkerKCONFIG_CONFIG = $(DOTCONFIG)
25*b9411a12SAndroid Build Coastguard WorkerKCONFIG_AUTOADS := $(obj)/cb-config.ads
26*b9411a12SAndroid Build Coastguard WorkerKCONFIG_RUSTCCFG := $(obj)/cb-config.rustcfg
27*b9411a12SAndroid Build Coastguard WorkerKCONFIG_AUTOHEADER := $(obj)/config.h
28*b9411a12SAndroid Build Coastguard WorkerKCONFIG_AUTOCONFIG := $(obj)/auto.conf
29*b9411a12SAndroid Build Coastguard WorkerKCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
30*b9411a12SAndroid Build Coastguard WorkerKCONFIG_SPLITCONFIG := $(obj)/config/
31*b9411a12SAndroid Build Coastguard WorkerKCONFIG_TRISTATE := $(obj)/tristate.conf
32*b9411a12SAndroid Build Coastguard WorkerKCONFIG_NEGATIVES := 1
33*b9411a12SAndroid Build Coastguard WorkerKCONFIG_WERROR := 1
34*b9411a12SAndroid Build Coastguard WorkerKCONFIG_WARN_UNKNOWN_SYMBOLS := 1
35*b9411a12SAndroid Build Coastguard WorkerKCONFIG_PACKAGE := CB.Config
36*b9411a12SAndroid Build Coastguard WorkerKCONFIG_MAKEFILE_REAL ?= $(objk)/Makefile.real
37*b9411a12SAndroid Build Coastguard Worker
38*b9411a12SAndroid Build Coastguard WorkerCOREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
39*b9411a12SAndroid Build Coastguard WorkerCOREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
40*b9411a12SAndroid Build Coastguard WorkerCOREBOOT_EXPORTS += KCONFIG_NEGATIVES
41*b9411a12SAndroid Build Coastguard Workerifeq ($(filter %config,$(MAKECMDGOALS)),)
42*b9411a12SAndroid Build Coastguard WorkerCOREBOOT_EXPORTS += KCONFIG_WERROR
43*b9411a12SAndroid Build Coastguard Workerendif
44*b9411a12SAndroid Build Coastguard WorkerCOREBOOT_EXPORTS += KCONFIG_WARN_UNKNOWN_SYMBOLS
45*b9411a12SAndroid Build Coastguard WorkerCOREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE
46*b9411a12SAndroid Build Coastguard WorkerCOREBOOT_EXPORTS += KCONFIG_RUSTCCFG
47*b9411a12SAndroid Build Coastguard Worker
48*b9411a12SAndroid Build Coastguard Worker# Make does not offer a recursive wildcard function, so here's one:
49*b9411a12SAndroid Build Coastguard Workerrwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
50*b9411a12SAndroid Build Coastguard WorkerSYMLINK_LIST = $(call rwildcard,site-local/,symlink.txt)
51*b9411a12SAndroid Build Coastguard Worker
52*b9411a12SAndroid Build Coastguard Worker
53*b9411a12SAndroid Build Coastguard Worker# Directory containing the toplevel Makefile.mk
54*b9411a12SAndroid Build Coastguard WorkerTOPLEVEL := .
55*b9411a12SAndroid Build Coastguard Worker
56*b9411a12SAndroid Build Coastguard WorkerCONFIG_SHELL := sh
57*b9411a12SAndroid Build Coastguard WorkerKBUILD_DEFCONFIG := configs/defconfig
58*b9411a12SAndroid Build Coastguard WorkerUNAME_RELEASE := $(shell uname -r)
59*b9411a12SAndroid Build Coastguard WorkerHAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
60*b9411a12SAndroid Build Coastguard WorkerHAVE_KCONFIG_MAKEFILE_REAL := $(wildcard $(KCONFIG_MAKEFILE_REAL))
61*b9411a12SAndroid Build Coastguard WorkerMAKEFLAGS += -rR --no-print-directory
62*b9411a12SAndroid Build Coastguard Worker
63*b9411a12SAndroid Build Coastguard Worker# Make is silent per default, but 'make V=1' will show all compiler calls.
64*b9411a12SAndroid Build Coastguard WorkerQ:=@
65*b9411a12SAndroid Build Coastguard Workerifneq ($(V),1)
66*b9411a12SAndroid Build Coastguard Workerifneq ($(Q),)
67*b9411a12SAndroid Build Coastguard Worker.SILENT:
68*b9411a12SAndroid Build Coastguard WorkerMAKEFLAGS += -s
69*b9411a12SAndroid Build Coastguard Workerquiet_errors := 2>/dev/null
70*b9411a12SAndroid Build Coastguard Workerendif
71*b9411a12SAndroid Build Coastguard Workerendif
72*b9411a12SAndroid Build Coastguard Worker
73*b9411a12SAndroid Build Coastguard Worker# Disable implicit/built-in rules to make Makefile errors fail fast.
74*b9411a12SAndroid Build Coastguard Worker.SUFFIXES:
75*b9411a12SAndroid Build Coastguard Worker
76*b9411a12SAndroid Build Coastguard WorkerHOSTCFLAGS := -g
77*b9411a12SAndroid Build Coastguard WorkerHOSTCXXFLAGS := -g
78*b9411a12SAndroid Build Coastguard Worker
79*b9411a12SAndroid Build Coastguard WorkerHOSTPKG_CONFIG ?= pkg-config
80*b9411a12SAndroid Build Coastguard WorkerCOREBOOT_EXPORTS += HOSTPKG_CONFIG
81*b9411a12SAndroid Build Coastguard Worker
82*b9411a12SAndroid Build Coastguard WorkerPREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
83*b9411a12SAndroid Build Coastguard Worker
84*b9411a12SAndroid Build Coastguard Workerexport $(COREBOOT_EXPORTS)
85*b9411a12SAndroid Build Coastguard Worker
86*b9411a12SAndroid Build Coastguard Workerall: real-all
87*b9411a12SAndroid Build Coastguard Worker
88*b9411a12SAndroid Build Coastguard Workerhelp_coreboot help::
89*b9411a12SAndroid Build Coastguard Worker	@echo  '*** coreboot platform targets ***'
90*b9411a12SAndroid Build Coastguard Worker	@echo  '  Use "make [target] V=1" for extra build debug information'
91*b9411a12SAndroid Build Coastguard Worker	@echo  '  all                   - Build coreboot'
92*b9411a12SAndroid Build Coastguard Worker	@echo  '  clean                 - Remove coreboot build artifacts'
93*b9411a12SAndroid Build Coastguard Worker	@echo  '  distclean             - Remove build artifacts and config files'
94*b9411a12SAndroid Build Coastguard Worker	@echo  '  sphinx                - Build sphinx documentation for coreboot'
95*b9411a12SAndroid Build Coastguard Worker	@echo  '  sphinx-lint           - Build sphinx documentation for coreboot with warnings as errors'
96*b9411a12SAndroid Build Coastguard Worker	@echo  '  filelist              - Show files used in current build'
97*b9411a12SAndroid Build Coastguard Worker	@echo  '  printall              - Print makefile info for debugging'
98*b9411a12SAndroid Build Coastguard Worker	@echo  '  gitconfig             - Set up git to submit patches to coreboot'
99*b9411a12SAndroid Build Coastguard Worker	@echo  '  ctags / ctags-project - Make ctags file for all of coreboot or current board'
100*b9411a12SAndroid Build Coastguard Worker	@echo  '  cscope / cscope-project - Make cscope.out file for coreboot or current board'
101*b9411a12SAndroid Build Coastguard Worker	@echo
102*b9411a12SAndroid Build Coastguard Worker	@echo  '*** site-local related targets ***'
103*b9411a12SAndroid Build Coastguard Worker	@echo  '  symlink               - Create symbolic links from site-local into coreboot tree'
104*b9411a12SAndroid Build Coastguard Worker	@echo  '  clean-symlink         - Remove symbolic links created by "make symlink"'
105*b9411a12SAndroid Build Coastguard Worker	@echo  '  cleanall-symlink      - Remove all symbolic links in the coreboot tree'
106*b9411a12SAndroid Build Coastguard Worker	@echo
107*b9411a12SAndroid Build Coastguard Worker
108*b9411a12SAndroid Build Coastguard Worker# This include must come _before_ the pattern rules below!
109*b9411a12SAndroid Build Coastguard Worker# Order _does_ matter for pattern rules.
110*b9411a12SAndroid Build Coastguard Workerinclude $(srck)/Makefile.mk
111*b9411a12SAndroid Build Coastguard Worker
112*b9411a12SAndroid Build Coastguard Worker# The cases where we don't need fully populated $(obj) lists:
113*b9411a12SAndroid Build Coastguard Worker# 1. when no .config exists
114*b9411a12SAndroid Build Coastguard Worker# 2. When no $(obj)/util/kconfig/Makefile.real exists and we're building tools
115*b9411a12SAndroid Build Coastguard Worker# 3. when make config (in any flavour) is run
116*b9411a12SAndroid Build Coastguard Worker# 4. when make distclean is run
117*b9411a12SAndroid Build Coastguard Worker# Don't waste time on reading all Makefile.incs in these cases
118*b9411a12SAndroid Build Coastguard Workerifeq ($(strip $(HAVE_DOTCONFIG)),)
119*b9411a12SAndroid Build Coastguard WorkerNOCOMPILE:=1
120*b9411a12SAndroid Build Coastguard Workerendif
121*b9411a12SAndroid Build Coastguard Workerifeq ($(strip $(HAVE_KCONFIG_MAKEFILE_REAL)),)
122*b9411a12SAndroid Build Coastguard Workerifneq ($(MAKECMDGOALS),tools)
123*b9411a12SAndroid Build Coastguard WorkerNOCOMPILE:=1
124*b9411a12SAndroid Build Coastguard Workerendif
125*b9411a12SAndroid Build Coastguard Workerendif
126*b9411a12SAndroid Build Coastguard Workerifneq ($(MAKECMDGOALS),)
127*b9411a12SAndroid Build Coastguard Workerifneq ($(filter %config %clean cross% clang iasl lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
128*b9411a12SAndroid Build Coastguard WorkerNOCOMPILE:=1
129*b9411a12SAndroid Build Coastguard Workerendif
130*b9411a12SAndroid Build Coastguard Workerifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
131*b9411a12SAndroid Build Coastguard WorkerNOMKDIR:=1
132*b9411a12SAndroid Build Coastguard WorkerUNIT_TEST:=1
133*b9411a12SAndroid Build Coastguard Workerendif
134*b9411a12SAndroid Build Coastguard Workerendif
135*b9411a12SAndroid Build Coastguard Worker
136*b9411a12SAndroid Build Coastguard Workerifneq ($(filter help%, $(MAKECMDGOALS)), )
137*b9411a12SAndroid Build Coastguard WorkerNOCOMPILE:=1
138*b9411a12SAndroid Build Coastguard WorkerUNIT_TEST:=1
139*b9411a12SAndroid Build Coastguard Workerelse
140*b9411a12SAndroid Build Coastguard Workerifneq ($(filter %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
141*b9411a12SAndroid Build Coastguard Workerifneq ($(filter-out %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
142*b9411a12SAndroid Build Coastguard Worker$(error Cannot mix unit-tests targets with other targets)
143*b9411a12SAndroid Build Coastguard Workerendif
144*b9411a12SAndroid Build Coastguard WorkerUNIT_TEST:=1
145*b9411a12SAndroid Build Coastguard WorkerNOCOMPILE:=
146*b9411a12SAndroid Build Coastguard Workerendif
147*b9411a12SAndroid Build Coastguard Workerendif
148*b9411a12SAndroid Build Coastguard Worker
149*b9411a12SAndroid Build Coastguard Worker# When building the "tools" target, the BUILD_ALL_TOOLS variable needs
150*b9411a12SAndroid Build Coastguard Worker# to be set before reading the tools' Makefiles
151*b9411a12SAndroid Build Coastguard Workerifneq ($(filter tools, $(MAKECMDGOALS)), )
152*b9411a12SAndroid Build Coastguard WorkerBUILD_ALL_TOOLS:=1
153*b9411a12SAndroid Build Coastguard Workerendif
154*b9411a12SAndroid Build Coastguard Worker
155*b9411a12SAndroid Build Coastguard Worker$(xcompile): util/xcompile/xcompile
156*b9411a12SAndroid Build Coastguard Worker	rm -f $@
157*b9411a12SAndroid Build Coastguard Worker	$< $(XGCCPATH) > $@.tmp
158*b9411a12SAndroid Build Coastguard Worker	\mv -f $@.tmp $@ 2> /dev/null
159*b9411a12SAndroid Build Coastguard Worker	rm -f $@.tmp
160*b9411a12SAndroid Build Coastguard Worker
161*b9411a12SAndroid Build Coastguard Workerifeq ($(NOCOMPILE),1)
162*b9411a12SAndroid Build Coastguard Worker# We also don't use .xcompile in the no-compile situations, so
163*b9411a12SAndroid Build Coastguard Worker# provide some reasonable defaults.
164*b9411a12SAndroid Build Coastguard WorkerHOSTCC ?= $(if $(shell type gcc 2>/dev/null),gcc,cc)
165*b9411a12SAndroid Build Coastguard WorkerHOSTCXX ?= g++
166*b9411a12SAndroid Build Coastguard Worker
167*b9411a12SAndroid Build Coastguard Workerinclude $(TOPLEVEL)/Makefile.mk
168*b9411a12SAndroid Build Coastguard Workerinclude $(TOPLEVEL)/payloads/Makefile.mk
169*b9411a12SAndroid Build Coastguard Workerinclude $(TOPLEVEL)/util/testing/Makefile.mk
170*b9411a12SAndroid Build Coastguard Worker-include $(TOPLEVEL)/site-local/Makefile.mk
171*b9411a12SAndroid Build Coastguard Worker-include $(TOPLEVEL)/site-local/Makefile.inc
172*b9411a12SAndroid Build Coastguard Workerinclude $(TOPLEVEL)/tests/Makefile.mk
173*b9411a12SAndroid Build Coastguard Workerprintall real-all:
174*b9411a12SAndroid Build Coastguard Worker	@echo "Error: Trying to build, but NOCOMPILE is set." >&2
175*b9411a12SAndroid Build Coastguard Worker	@echo "  Please file a bug with the following information:"
176*b9411a12SAndroid Build Coastguard Worker	@echo "- MAKECMDGOALS: $(MAKECMDGOALS)" >&2
177*b9411a12SAndroid Build Coastguard Worker	@echo "- HAVE_DOTCONFIG: $(HAVE_DOTCONFIG)" >&2
178*b9411a12SAndroid Build Coastguard Worker	@echo "- HAVE_KCONFIG_MAKEFILE_REAL: $(HAVE_KCONFIG_MAKEFILE_REAL)" >&2
179*b9411a12SAndroid Build Coastguard Worker	@exit 1
180*b9411a12SAndroid Build Coastguard Worker
181*b9411a12SAndroid Build Coastguard Workerelse
182*b9411a12SAndroid Build Coastguard Worker
183*b9411a12SAndroid Build Coastguard Workerifneq ($(UNIT_TEST),1)
184*b9411a12SAndroid Build Coastguard Workerinclude $(DOTCONFIG)
185*b9411a12SAndroid Build Coastguard Workerendif
186*b9411a12SAndroid Build Coastguard Worker
187*b9411a12SAndroid Build Coastguard Worker# The toolchain requires xcompile to determine the ARCH_SUPPORTED, so we can't
188*b9411a12SAndroid Build Coastguard Worker# wait for make to generate the file.
189*b9411a12SAndroid Build Coastguard Worker$(if $(wildcard $(xcompile)),, $(shell \
190*b9411a12SAndroid Build Coastguard Worker	mkdir -p $(dir $(xcompile)) && \
191*b9411a12SAndroid Build Coastguard Worker	util/xcompile/xcompile $(XGCCPATH) > $(xcompile) || rm -f $(xcompile)))
192*b9411a12SAndroid Build Coastguard Worker
193*b9411a12SAndroid Build Coastguard Workerinclude $(xcompile)
194*b9411a12SAndroid Build Coastguard Worker
195*b9411a12SAndroid Build Coastguard Workerifneq ($(XCOMPILE_COMPLETE),1)
196*b9411a12SAndroid Build Coastguard Worker$(shell rm -f $(xcompile))
197*b9411a12SAndroid Build Coastguard Worker$(error $(xcompile) deleted because it's invalid. \
198*b9411a12SAndroid Build Coastguard Worker	Restarting the build should fix that, or explain the problem)
199*b9411a12SAndroid Build Coastguard Workerendif
200*b9411a12SAndroid Build Coastguard Worker
201*b9411a12SAndroid Build Coastguard Worker# reproducible builds
202*b9411a12SAndroid Build Coastguard WorkerLANG:=C
203*b9411a12SAndroid Build Coastguard WorkerLC_ALL:=C
204*b9411a12SAndroid Build Coastguard WorkerTZ:=UTC0
205*b9411a12SAndroid Build Coastguard Workerifneq ($(NOCOMPILE),1)
206*b9411a12SAndroid Build Coastguard WorkerSOURCE_DATE_EPOCH := $(shell $(top)/util/genbuild_h/genbuild_h.sh . | sed -n 's/^.define COREBOOT_BUILD_EPOCH\>.*"\(.*\)".*/\1/p')
207*b9411a12SAndroid Build Coastguard Workerendif
208*b9411a12SAndroid Build Coastguard Worker# don't use COREBOOT_EXPORTS to ensure build steps outside the coreboot build system
209*b9411a12SAndroid Build Coastguard Worker# are reproducible
210*b9411a12SAndroid Build Coastguard Workerexport LANG LC_ALL TZ SOURCE_DATE_EPOCH
211*b9411a12SAndroid Build Coastguard Worker
212*b9411a12SAndroid Build Coastguard Workerifneq ($(UNIT_TEST),1)
213*b9411a12SAndroid Build Coastguard Workerinclude toolchain.mk
214*b9411a12SAndroid Build Coastguard Workerendif
215*b9411a12SAndroid Build Coastguard Worker
216*b9411a12SAndroid Build Coastguard Workerstrip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
217*b9411a12SAndroid Build Coastguard Worker# fix makefile syntax highlighting after strip macro \" "))
218*b9411a12SAndroid Build Coastguard Worker
219*b9411a12SAndroid Build Coastguard Workerifneq ($(NOCOMPILE),1)
220*b9411a12SAndroid Build Coastguard Worker$(shell rm -f $(CCACHE_STATSLOG))
221*b9411a12SAndroid Build Coastguard Workerendif
222*b9411a12SAndroid Build Coastguard Worker
223*b9411a12SAndroid Build Coastguard Worker# The primary target needs to be here before we include the
224*b9411a12SAndroid Build Coastguard Worker# other files
225*b9411a12SAndroid Build Coastguard Workerreal-all: site-local-target real-target
226*b9411a12SAndroid Build Coastguard Worker
227*b9411a12SAndroid Build Coastguard Worker# must come rather early
228*b9411a12SAndroid Build Coastguard Worker.SECONDARY:
229*b9411a12SAndroid Build Coastguard Worker.SECONDEXPANSION:
230*b9411a12SAndroid Build Coastguard Worker.DELETE_ON_ERROR:
231*b9411a12SAndroid Build Coastguard Worker
232*b9411a12SAndroid Build Coastguard Worker$(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
233*b9411a12SAndroid Build Coastguard Worker	$(MAKE) olddefconfig
234*b9411a12SAndroid Build Coastguard Worker	$(MAKE) syncconfig
235*b9411a12SAndroid Build Coastguard Worker
236*b9411a12SAndroid Build Coastguard Worker$(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
237*b9411a12SAndroid Build Coastguard Worker	true
238*b9411a12SAndroid Build Coastguard Worker
239*b9411a12SAndroid Build Coastguard Worker$(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
240*b9411a12SAndroid Build Coastguard Worker	$(objutil)/kconfig/toada CB.Config <$< >$@
241*b9411a12SAndroid Build Coastguard Worker
242*b9411a12SAndroid Build Coastguard Worker$(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
243*b9411a12SAndroid Build Coastguard Worker	cp $< $@
244*b9411a12SAndroid Build Coastguard Worker
245*b9411a12SAndroid Build Coastguard Worker# Add a new class of source/object files to the build system
246*b9411a12SAndroid Build Coastguard Workeradd-class= \
247*b9411a12SAndroid Build Coastguard Worker	$(eval $(1)-srcs:=) \
248*b9411a12SAndroid Build Coastguard Worker	$(eval $(1)-objs:=) \
249*b9411a12SAndroid Build Coastguard Worker	$(eval classes+=$(1))
250*b9411a12SAndroid Build Coastguard Worker
251*b9411a12SAndroid Build Coastguard Worker# Special classes are managed types with special behaviour
252*b9411a12SAndroid Build Coastguard Worker# On parse time, for each entry in variable $(1)-y
253*b9411a12SAndroid Build Coastguard Worker# a handler $(1)-handler is executed with the arguments:
254*b9411a12SAndroid Build Coastguard Worker# * $(1): directory the parser is in
255*b9411a12SAndroid Build Coastguard Worker# * $(2): current entry
256*b9411a12SAndroid Build Coastguard Workeradd-special-class= \
257*b9411a12SAndroid Build Coastguard Worker	$(eval $(1):=) \
258*b9411a12SAndroid Build Coastguard Worker	$(eval special-classes+=$(1))
259*b9411a12SAndroid Build Coastguard Worker
260*b9411a12SAndroid Build Coastguard Worker# Converts one or more source file paths to their corresponding build/ paths.
261*b9411a12SAndroid Build Coastguard Worker# Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
262*b9411a12SAndroid Build Coastguard Worker# their name.
263*b9411a12SAndroid Build Coastguard Worker# $1 stage name
264*b9411a12SAndroid Build Coastguard Worker# $2 file path (list)
265*b9411a12SAndroid Build Coastguard Workersrc-to-obj=\
266*b9411a12SAndroid Build Coastguard Worker	$(patsubst $(obj)/%,$(obj)/$(1)/%,\
267*b9411a12SAndroid Build Coastguard Worker	$(patsubst $(obj)/$(1)/%,$(obj)/%,\
268*b9411a12SAndroid Build Coastguard Worker	$(patsubst 3rdparty/%,$(obj)/%,\
269*b9411a12SAndroid Build Coastguard Worker	$(patsubst src/%,$(obj)/%,\
270*b9411a12SAndroid Build Coastguard Worker	$(patsubst %.ads,%.o,\
271*b9411a12SAndroid Build Coastguard Worker	$(patsubst %.adb,%.o,\
272*b9411a12SAndroid Build Coastguard Worker	$(patsubst %.c,%.o,\
273*b9411a12SAndroid Build Coastguard Worker	$(patsubst %.S,%.o,\
274*b9411a12SAndroid Build Coastguard Worker	$(subst .$(1),,$(2))))))))))
275*b9411a12SAndroid Build Coastguard Worker
276*b9411a12SAndroid Build Coastguard Worker# Converts one or more source file paths to the corresponding build/ paths
277*b9411a12SAndroid Build Coastguard Worker# of their Ada library information (.ali) files.
278*b9411a12SAndroid Build Coastguard Worker# $1 stage name
279*b9411a12SAndroid Build Coastguard Worker# $2 file path (list)
280*b9411a12SAndroid Build Coastguard Workersrc-to-ali=\
281*b9411a12SAndroid Build Coastguard Worker	$(patsubst $(obj)/%,$(obj)/$(1)/%,\
282*b9411a12SAndroid Build Coastguard Worker	$(patsubst $(obj)/$(1)/%,$(obj)/%,\
283*b9411a12SAndroid Build Coastguard Worker	$(patsubst 3rdparty/%,$(obj)/%,\
284*b9411a12SAndroid Build Coastguard Worker	$(patsubst src/%,$(obj)/%,\
285*b9411a12SAndroid Build Coastguard Worker	$(patsubst %.ads,%.ali,\
286*b9411a12SAndroid Build Coastguard Worker	$(patsubst %.adb,%.ali,\
287*b9411a12SAndroid Build Coastguard Worker	$(subst .$(1),,\
288*b9411a12SAndroid Build Coastguard Worker	$(filter %.ads %.adb,$(2)))))))))
289*b9411a12SAndroid Build Coastguard Worker
290*b9411a12SAndroid Build Coastguard Worker# Clean -y variables, include Makefile.mk & Makefile.inc
291*b9411a12SAndroid Build Coastguard Worker# Add paths to files in X-y to X-srcs
292*b9411a12SAndroid Build Coastguard Worker# Add subdirs-y to subdirs
293*b9411a12SAndroid Build Coastguard Workerincludemakefiles= \
294*b9411a12SAndroid Build Coastguard Worker	$(if $(wildcard $(1)), \
295*b9411a12SAndroid Build Coastguard Worker		$(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
296*b9411a12SAndroid Build Coastguard Worker		$(eval -include $(1)) \
297*b9411a12SAndroid Build Coastguard Worker		$(foreach class,$(classes-y), $(call add-class,$(class))) \
298*b9411a12SAndroid Build Coastguard Worker		$(foreach special,$(special-classes), \
299*b9411a12SAndroid Build Coastguard Worker			$(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
300*b9411a12SAndroid Build Coastguard Worker		$(foreach class,$(classes), \
301*b9411a12SAndroid Build Coastguard Worker			$(eval $(class)-srcs+= \
302*b9411a12SAndroid Build Coastguard Worker				$$(subst $(absobj)/,$(obj)/, \
303*b9411a12SAndroid Build Coastguard Worker				$$(subst $(top)/,, \
304*b9411a12SAndroid Build Coastguard Worker				$$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
305*b9411a12SAndroid Build Coastguard Worker		$(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))))
306*b9411a12SAndroid Build Coastguard Worker
307*b9411a12SAndroid Build Coastguard Worker# For each path in $(subdirs) call includemakefiles
308*b9411a12SAndroid Build Coastguard Worker# Repeat until subdirs is empty
309*b9411a12SAndroid Build Coastguard Worker# TODO: Remove Makefile.inc support
310*b9411a12SAndroid Build Coastguard Workerevaluate_subdirs= \
311*b9411a12SAndroid Build Coastguard Worker	$(eval cursubdirs:=$(subdirs)) \
312*b9411a12SAndroid Build Coastguard Worker	$(eval subdirs:=) \
313*b9411a12SAndroid Build Coastguard Worker	$(foreach dir,$(cursubdirs), \
314*b9411a12SAndroid Build Coastguard Worker		$(eval $(call includemakefiles,$(dir)/Makefile.mk))) \
315*b9411a12SAndroid Build Coastguard Worker	$(foreach dir,$(cursubdirs), \
316*b9411a12SAndroid Build Coastguard Worker		$(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
317*b9411a12SAndroid Build Coastguard Worker	$(if $(subdirs),$(eval $(call evaluate_subdirs)))
318*b9411a12SAndroid Build Coastguard Worker
319*b9411a12SAndroid Build Coastguard Worker# collect all object files eligible for building
320*b9411a12SAndroid Build Coastguard Workersubdirs:=$(TOPLEVEL)
321*b9411a12SAndroid Build Coastguard Workerpostinclude-hooks :=
322*b9411a12SAndroid Build Coastguard Worker
323*b9411a12SAndroid Build Coastguard Worker# Don't iterate through Makefiles under src/ when building tests
324*b9411a12SAndroid Build Coastguard Workerifneq ($(UNIT_TEST),1)
325*b9411a12SAndroid Build Coastguard Worker$(eval $(call evaluate_subdirs))
326*b9411a12SAndroid Build Coastguard Workerelse
327*b9411a12SAndroid Build Coastguard Workerinclude $(TOPLEVEL)/tests/Makefile.mk
328*b9411a12SAndroid Build Coastguard Workerendif
329*b9411a12SAndroid Build Coastguard Worker
330*b9411a12SAndroid Build Coastguard Workerifeq ($(FAILBUILD),1)
331*b9411a12SAndroid Build Coastguard Worker$(error cannot continue build)
332*b9411a12SAndroid Build Coastguard Workerendif
333*b9411a12SAndroid Build Coastguard Worker
334*b9411a12SAndroid Build Coastguard Worker# Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
335*b9411a12SAndroid Build Coastguard Worker$(eval $(postinclude-hooks))
336*b9411a12SAndroid Build Coastguard Worker
337*b9411a12SAndroid Build Coastguard Worker# Eliminate duplicate mentions of source files in a class
338*b9411a12SAndroid Build Coastguard Worker$(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
339*b9411a12SAndroid Build Coastguard Worker
340*b9411a12SAndroid Build Coastguard Workerifeq ($(CONFIG_IWYU),y)
341*b9411a12SAndroid Build Coastguard WorkerMAKEFLAGS += -k
342*b9411a12SAndroid Build Coastguard WorkerSAVE_IWYU_OUTPUT := 2>&1 | grep "should\|\#include\|---\|include-list\|^[[:blank:]]\?\'" | tee -a $$(obj)/iwyu.txt
343*b9411a12SAndroid Build Coastguard Workerendif
344*b9411a12SAndroid Build Coastguard Worker
345*b9411a12SAndroid Build Coastguard Worker# Build Kconfig .ads if necessary
346*b9411a12SAndroid Build Coastguard Workerifeq ($(CONFIG_ROMSTAGE_ADA),y)
347*b9411a12SAndroid Build Coastguard Workerromstage-srcs += $(obj)/romstage/$(notdir $(KCONFIG_AUTOADS))
348*b9411a12SAndroid Build Coastguard Workerendif
349*b9411a12SAndroid Build Coastguard Workerifeq ($(CONFIG_RAMSTAGE_ADA),y)
350*b9411a12SAndroid Build Coastguard Workerramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
351*b9411a12SAndroid Build Coastguard Workerendif
352*b9411a12SAndroid Build Coastguard Worker
353*b9411a12SAndroid Build Coastguard Worker# To track dependencies, we need all Ada specification (.ads) files in
354*b9411a12SAndroid Build Coastguard Worker# *-srcs. Extract / filter all specification files that have a matching
355*b9411a12SAndroid Build Coastguard Worker# body (.adb) file here (specifications without a body are valid sources
356*b9411a12SAndroid Build Coastguard Worker# in Ada).
357*b9411a12SAndroid Build Coastguard Worker$(foreach class,$(classes),$(eval $(class)-extra-specs := \
358*b9411a12SAndroid Build Coastguard Worker	$(filter \
359*b9411a12SAndroid Build Coastguard Worker		$(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
360*b9411a12SAndroid Build Coastguard Worker		$(filter %.ads,$($(class)-srcs)))))
361*b9411a12SAndroid Build Coastguard Worker$(foreach class,$(classes),$(eval $(class)-srcs := \
362*b9411a12SAndroid Build Coastguard Worker	$(filter-out $($(class)-extra-specs),$($(class)-srcs))))
363*b9411a12SAndroid Build Coastguard Worker
364*b9411a12SAndroid Build Coastguard Worker$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
365*b9411a12SAndroid Build Coastguard Worker$(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
366*b9411a12SAndroid Build Coastguard Worker
367*b9411a12SAndroid Build Coastguard Worker# For Ada includes
368*b9411a12SAndroid Build Coastguard Worker$(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
369*b9411a12SAndroid Build Coastguard Worker
370*b9411a12SAndroid Build Coastguard Worker# Call post-processors if they're defined
371*b9411a12SAndroid Build Coastguard Worker$(foreach class,$(classes),\
372*b9411a12SAndroid Build Coastguard Worker	$(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
373*b9411a12SAndroid Build Coastguard Worker
374*b9411a12SAndroid Build Coastguard Workerallsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
375*b9411a12SAndroid Build Coastguard Workerallobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
376*b9411a12SAndroid Build Coastguard Workeralldirs:=$(sort $(abspath $(dir $(allobjs))))
377*b9411a12SAndroid Build Coastguard Worker
378*b9411a12SAndroid Build Coastguard Worker# Reads dependencies from an Ada library information (.ali) file
379*b9411a12SAndroid Build Coastguard Worker# Only basenames (with suffix) are preserved so we have to look the
380*b9411a12SAndroid Build Coastguard Worker# paths up in $($(stage)-srcs).
381*b9411a12SAndroid Build Coastguard Worker# $1 stage name
382*b9411a12SAndroid Build Coastguard Worker# $2 ali file
383*b9411a12SAndroid Build Coastguard Workercreate_ada_deps=$$(if $(2),\
384*b9411a12SAndroid Build Coastguard Worker	gnat.adc \
385*b9411a12SAndroid Build Coastguard Worker	$$(filter \
386*b9411a12SAndroid Build Coastguard Worker		$$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
387*b9411a12SAndroid Build Coastguard Worker		$$($(1)-srcs) $$($(1)-extra-specs)))
388*b9411a12SAndroid Build Coastguard Worker
389*b9411a12SAndroid Build Coastguard Worker# macro to define template macros that are used by use_template macro
390*b9411a12SAndroid Build Coastguard Workerdefine create_cc_template
391*b9411a12SAndroid Build Coastguard Worker# $1 obj class
392*b9411a12SAndroid Build Coastguard Worker# $2 source suffix (c, S, ld, ...)
393*b9411a12SAndroid Build Coastguard Worker# $3 additional compiler flags
394*b9411a12SAndroid Build Coastguard Worker# $4 additional dependencies
395*b9411a12SAndroid Build Coastguard Workerifn$(EMPTY)def $(1)-objs_$(2)_template
396*b9411a12SAndroid Build Coastguard Workerde$(EMPTY)fine $(1)-objs_$(2)_template
397*b9411a12SAndroid Build Coastguard Workerifn$(EMPTY)eq ($(filter ads adb,$(2)),)
398*b9411a12SAndroid Build Coastguard Worker$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $$(call create_ada_deps,$1,$$(call src-to-ali,$1,$$(1).$2)) $(4)
399*b9411a12SAndroid Build Coastguard Worker	@printf "    GCC        $$$$(subst $$$$(obj)/,,$$$$(@))\n"
400*b9411a12SAndroid Build Coastguard Worker	$(GCC_$(1)) \
401*b9411a12SAndroid Build Coastguard Worker		$$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
402*b9411a12SAndroid Build Coastguard Worker		$(3) -c -o $$$$@ $$$$<
403*b9411a12SAndroid Build Coastguard Workerel$(EMPTY)se
404*b9411a12SAndroid Build Coastguard Worker$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
405*b9411a12SAndroid Build Coastguard Worker	@printf "    CC         $$$$(subst $$$$(obj)/,,$$$$(@))\n"
406*b9411a12SAndroid Build Coastguard Worker	$(CC_$(1)) \
407*b9411a12SAndroid Build Coastguard Worker		-MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
408*b9411a12SAndroid Build Coastguard Worker		$(3) -c -o $$$$@ $$$$< $(SAVE_IWYU_OUTPUT)
409*b9411a12SAndroid Build Coastguard Workerend$(EMPTY)if
410*b9411a12SAndroid Build Coastguard Workeren$(EMPTY)def
411*b9411a12SAndroid Build Coastguard Workerend$(EMPTY)if
412*b9411a12SAndroid Build Coastguard Workerendef
413*b9411a12SAndroid Build Coastguard Worker
414*b9411a12SAndroid Build Coastguard Workerfiletypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
415*b9411a12SAndroid Build Coastguard Worker$(foreach class,$(classes), \
416*b9411a12SAndroid Build Coastguard Worker	$(foreach type,$(call filetypes-of-class,$(class)), \
417*b9411a12SAndroid Build Coastguard Worker		$(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
418*b9411a12SAndroid Build Coastguard Worker		$(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
419*b9411a12SAndroid Build Coastguard Worker		$(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
420*b9411a12SAndroid Build Coastguard Worker
421*b9411a12SAndroid Build Coastguard Workerforeach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
422*b9411a12SAndroid Build Coastguard Worker$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
423*b9411a12SAndroid Build Coastguard Worker
424*b9411a12SAndroid Build Coastguard Worker# To supported complex package initializations, we need to call the
425*b9411a12SAndroid Build Coastguard Worker# emitted code explicitly. gnatbind gathers all the calls for us
426*b9411a12SAndroid Build Coastguard Worker# and exports them as a procedure $(stage)_adainit(). Every stage that
427*b9411a12SAndroid Build Coastguard Worker# uses Ada code has to call it!
428*b9411a12SAndroid Build Coastguard Workerdefine gnatbind_template
429*b9411a12SAndroid Build Coastguard Worker# $1 class
430*b9411a12SAndroid Build Coastguard Worker$$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
431*b9411a12SAndroid Build Coastguard Worker	@printf "    BIND       $$(subst $$(obj)/,,$$@)\n"
432*b9411a12SAndroid Build Coastguard Worker	# We have to give gnatbind a simple filename (without leading
433*b9411a12SAndroid Build Coastguard Worker	# path components) so just cd there.
434*b9411a12SAndroid Build Coastguard Worker	cd $$(dir $$@) && \
435*b9411a12SAndroid Build Coastguard Worker		$$(GNATBIND_$(1)) -a -n \
436*b9411a12SAndroid Build Coastguard Worker			--RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
437*b9411a12SAndroid Build Coastguard Worker			-L$(1)_ada -o $$(notdir $$@) \
438*b9411a12SAndroid Build Coastguard Worker			$$(subst $$(dir $$@),,$$^)
439*b9411a12SAndroid Build Coastguard Worker$$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
440*b9411a12SAndroid Build Coastguard Worker	@printf "    GCC        $$(subst $$(obj)/,,$$@)\n"
441*b9411a12SAndroid Build Coastguard Worker	$(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
442*b9411a12SAndroid Build Coastguard Worker$(1)-objs += $$(obj)/$(1)/b__$(1).o
443*b9411a12SAndroid Build Coastguard Worker$($(1)-alis): %.ali: %.o ;
444*b9411a12SAndroid Build Coastguard Workerendef
445*b9411a12SAndroid Build Coastguard Worker
446*b9411a12SAndroid Build Coastguard Worker$(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
447*b9411a12SAndroid Build Coastguard Worker	$(if $($(class)-alis),$(call gnatbind_template,$(class)))))
448*b9411a12SAndroid Build Coastguard Worker
449*b9411a12SAndroid Build Coastguard WorkerDEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
450*b9411a12SAndroid Build Coastguard Worker-include $(DEPENDENCIES)
451*b9411a12SAndroid Build Coastguard Worker
452*b9411a12SAndroid Build Coastguard Workerprintall:
453*b9411a12SAndroid Build Coastguard Worker	@$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
454*b9411a12SAndroid Build Coastguard Worker	@echo alldirs: $(alldirs) | tr ' ' '\n'; echo
455*b9411a12SAndroid Build Coastguard Worker	@echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
456*b9411a12SAndroid Build Coastguard Worker	@echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
457*b9411a12SAndroid Build Coastguard Worker	@$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
458*b9411a12SAndroid Build Coastguard Workerendif
459*b9411a12SAndroid Build Coastguard Worker
460*b9411a12SAndroid Build Coastguard Workerifndef NOMKDIR
461*b9411a12SAndroid Build Coastguard Worker$(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
462*b9411a12SAndroid Build Coastguard Workerendif
463*b9411a12SAndroid Build Coastguard Worker
464*b9411a12SAndroid Build Coastguard Worker$(obj)/project_filelist.txt:
465*b9411a12SAndroid Build Coastguard Worker	if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
466*b9411a12SAndroid Build Coastguard Worker		echo "*** Error: Project must be built before generating file list ***"; \
467*b9411a12SAndroid Build Coastguard Worker		exit 1; \
468*b9411a12SAndroid Build Coastguard Worker	fi
469*b9411a12SAndroid Build Coastguard Worker	find $(obj) -path "$(obj)/util" -prune -o -path "$(obj)/external" -prune -o -name "*.d" -exec cat {} \; | \
470*b9411a12SAndroid Build Coastguard Worker	  sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
471*b9411a12SAndroid Build Coastguard Worker	  grep -v '\.o$$' > $(obj)/project_filelist.txt
472*b9411a12SAndroid Build Coastguard Worker
473*b9411a12SAndroid Build Coastguard Workerfilelist: $(obj)/project_filelist.txt
474*b9411a12SAndroid Build Coastguard Worker	printf "\nFiles used in build:\n"
475*b9411a12SAndroid Build Coastguard Worker	cat $(obj)/project_filelist.txt
476*b9411a12SAndroid Build Coastguard Worker
477*b9411a12SAndroid Build Coastguard Worker#works with either exuberant ctags or ctags.emacs
478*b9411a12SAndroid Build Coastguard Workerctags-project: clean-ctags $(obj)/project_filelist.txt
479*b9411a12SAndroid Build Coastguard Worker	cat $(obj)/project_filelist.txt | \
480*b9411a12SAndroid Build Coastguard Worker	  xargs ctags -o tags
481*b9411a12SAndroid Build Coastguard Worker
482*b9411a12SAndroid Build Coastguard Workercscope-project: clean-cscope $(obj)/project_filelist.txt
483*b9411a12SAndroid Build Coastguard Worker	cat $(obj)/project_filelist.txt | xargs cscope -b
484*b9411a12SAndroid Build Coastguard Worker
485*b9411a12SAndroid Build Coastguard Workercscope:
486*b9411a12SAndroid Build Coastguard Worker	cscope -bR
487*b9411a12SAndroid Build Coastguard Worker
488*b9411a12SAndroid Build Coastguard Workersphinx:
489*b9411a12SAndroid Build Coastguard Worker	$(MAKE) -C Documentation sphinx
490*b9411a12SAndroid Build Coastguard Worker
491*b9411a12SAndroid Build Coastguard Workersphinx-lint:
492*b9411a12SAndroid Build Coastguard Worker	$(MAKE) SPHINXOPTS=-W -C Documentation sphinx
493*b9411a12SAndroid Build Coastguard Worker
494*b9411a12SAndroid Build Coastguard Worker# Look at all of the files in the SYMLINK_LIST and create the symbolic links
495*b9411a12SAndroid Build Coastguard Worker# into the coreboot tree. Each symlink.txt file in site-local should be in the
496*b9411a12SAndroid Build Coastguard Worker# directory linked from and have a single line with the path to the location to
497*b9411a12SAndroid Build Coastguard Worker# link to. The path must be relative to the top of the coreboot directory.
498*b9411a12SAndroid Build Coastguard Workersymlink:
499*b9411a12SAndroid Build Coastguard Worker	if [ -z "$(SYMLINK_LIST)" ]; then \
500*b9411a12SAndroid Build Coastguard Worker		echo "No site-local symbolic links to create."; \
501*b9411a12SAndroid Build Coastguard Worker		exit 0; \
502*b9411a12SAndroid Build Coastguard Worker	fi; \
503*b9411a12SAndroid Build Coastguard Worker	echo "Creating symbolic links.."; \
504*b9411a12SAndroid Build Coastguard Worker	for link in $(SYMLINK_LIST); do \
505*b9411a12SAndroid Build Coastguard Worker		LINKTO="$(top)/$$(head -n 1 "$${link}")"; \
506*b9411a12SAndroid Build Coastguard Worker		LINKFROM=$$(dirname "$$(realpath "$${link}")"); \
507*b9411a12SAndroid Build Coastguard Worker		if [ -L "$${LINKTO}" ]; then \
508*b9411a12SAndroid Build Coastguard Worker			echo "  $${LINKTO} exists - skipping"; \
509*b9411a12SAndroid Build Coastguard Worker			continue; \
510*b9411a12SAndroid Build Coastguard Worker		fi; \
511*b9411a12SAndroid Build Coastguard Worker		LINKTO="$$(realpath -m "$${LINKTO}")" 2>/dev/null; \
512*b9411a12SAndroid Build Coastguard Worker		if [ "$${LINKTO}" = "$$(echo "$${LINKTO}" | sed "s|^$(top)||" )" ]; then \
513*b9411a12SAndroid Build Coastguard Worker			echo "  FAILED: $${LINKTO} is outside of current directory." >&2; \
514*b9411a12SAndroid Build Coastguard Worker			continue; \
515*b9411a12SAndroid Build Coastguard Worker		fi; \
516*b9411a12SAndroid Build Coastguard Worker		if [ ! -e "$${LINKTO}" ]; then \
517*b9411a12SAndroid Build Coastguard Worker			echo "  LINK $${LINKTO} -> $${LINKFROM}"; \
518*b9411a12SAndroid Build Coastguard Worker			ln -s "$${LINKFROM}" "$${LINKTO}" || \
519*b9411a12SAndroid Build Coastguard Worker				echo "FAILED: Could not create link." >&2; \
520*b9411a12SAndroid Build Coastguard Worker		else \
521*b9411a12SAndroid Build Coastguard Worker			echo  "  FAILED: $${LINKTO} exists as a file or directory." >&2; \
522*b9411a12SAndroid Build Coastguard Worker		fi; \
523*b9411a12SAndroid Build Coastguard Worker	done
524*b9411a12SAndroid Build Coastguard Worker
525*b9411a12SAndroid Build Coastguard Workerclean-symlink:
526*b9411a12SAndroid Build Coastguard Worker	if [ -z "$(SYMLINK_LIST)" ]; then \
527*b9411a12SAndroid Build Coastguard Worker		echo "No site-local symbolic links to clean."; \
528*b9411a12SAndroid Build Coastguard Worker		exit 0; \
529*b9411a12SAndroid Build Coastguard Worker	fi; \
530*b9411a12SAndroid Build Coastguard Worker	echo "Removing site-local symbolic links from tree.."; \
531*b9411a12SAndroid Build Coastguard Worker	for link in $(SYMLINK_LIST); do \
532*b9411a12SAndroid Build Coastguard Worker		SYMLINK="$(top)/$$(head -n 1 "$${link}")"; \
533*b9411a12SAndroid Build Coastguard Worker		if [ "$${SYMLINK}" = "$$(echo "$${SYMLINK}" | sed "s|^$(top)||")" ]; then \
534*b9411a12SAndroid Build Coastguard Worker			echo "  FAILED: $${SYMLINK} is outside of current directory." >&2; \
535*b9411a12SAndroid Build Coastguard Worker			continue; \
536*b9411a12SAndroid Build Coastguard Worker		elif [ ! -L "$${SYMLINK}" ]; then \
537*b9411a12SAndroid Build Coastguard Worker			echo "  $${SYMLINK} does not exist - skipping"; \
538*b9411a12SAndroid Build Coastguard Worker			continue; \
539*b9411a12SAndroid Build Coastguard Worker		fi; \
540*b9411a12SAndroid Build Coastguard Worker		if [ -L "$${SYMLINK}" ]; then \
541*b9411a12SAndroid Build Coastguard Worker			REALDIR="$$(realpath "$${link}")"; \
542*b9411a12SAndroid Build Coastguard Worker			echo "  UNLINK $${link} (linked from $${REALDIR})"; \
543*b9411a12SAndroid Build Coastguard Worker			rm "$${SYMLINK}"; \
544*b9411a12SAndroid Build Coastguard Worker		fi; \
545*b9411a12SAndroid Build Coastguard Worker	done; \
546*b9411a12SAndroid Build Coastguard Worker	EXISTING_SYMLINKS="$$(find $(top) -type l | grep -v "3rdparty\|crossgcc" )"; \
547*b9411a12SAndroid Build Coastguard Worker	if [ -z "$${EXISTING_SYMLINKS}" ]; then \
548*b9411a12SAndroid Build Coastguard Worker		echo "  No remaining symbolic links found in tree."; \
549*b9411a12SAndroid Build Coastguard Worker	else \
550*b9411a12SAndroid Build Coastguard Worker		echo "  Remaining symbolic links found:"; \
551*b9411a12SAndroid Build Coastguard Worker		for link in $${EXISTING_SYMLINKS}; do \
552*b9411a12SAndroid Build Coastguard Worker			echo "    $${link}"; \
553*b9411a12SAndroid Build Coastguard Worker		done; \
554*b9411a12SAndroid Build Coastguard Worker	fi
555*b9411a12SAndroid Build Coastguard Worker
556*b9411a12SAndroid Build Coastguard Workercleanall-symlink:
557*b9411a12SAndroid Build Coastguard Worker	echo "Deleting all symbolic links in the coreboot tree (excluding 3rdparty & crossgcc)"; \
558*b9411a12SAndroid Build Coastguard Worker	EXISTING_SYMLINKS="$$(find $(top) -type l | grep -v "3rdparty\|crossgcc" )"; \
559*b9411a12SAndroid Build Coastguard Worker	for link in $${EXISTING_SYMLINKS}; do \
560*b9411a12SAndroid Build Coastguard Worker		if [ -L "$${link}" ]; then \
561*b9411a12SAndroid Build Coastguard Worker			REALDIR="$$(realpath "$${link}")"; \
562*b9411a12SAndroid Build Coastguard Worker			echo "  UNLINK $${link} (linked from $${REALDIR})"; \
563*b9411a12SAndroid Build Coastguard Worker			rm "$${link}"; \
564*b9411a12SAndroid Build Coastguard Worker		fi; \
565*b9411a12SAndroid Build Coastguard Worker	done
566*b9411a12SAndroid Build Coastguard Worker
567*b9411a12SAndroid Build Coastguard Workerclean-for-update:
568*b9411a12SAndroid Build Coastguard Worker	rm -rf $(obj) .xcompile
569*b9411a12SAndroid Build Coastguard Worker
570*b9411a12SAndroid Build Coastguard Workerclean: clean-for-update clean-utils clean-payloads
571*b9411a12SAndroid Build Coastguard Worker	rm -f .ccwrap
572*b9411a12SAndroid Build Coastguard Worker
573*b9411a12SAndroid Build Coastguard Workerclean-cscope:
574*b9411a12SAndroid Build Coastguard Worker	rm -f cscope.out
575*b9411a12SAndroid Build Coastguard Worker
576*b9411a12SAndroid Build Coastguard Workerclean-ctags:
577*b9411a12SAndroid Build Coastguard Worker	rm -f tags
578*b9411a12SAndroid Build Coastguard Worker
579*b9411a12SAndroid Build Coastguard Workerclean-utils:
580*b9411a12SAndroid Build Coastguard Worker	$(foreach tool, $(TOOLLIST), \
581*b9411a12SAndroid Build Coastguard Worker		$(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
582*b9411a12SAndroid Build Coastguard Worker
583*b9411a12SAndroid Build Coastguard Workerdistclean-utils:
584*b9411a12SAndroid Build Coastguard Worker	$(foreach tool, $(TOOLLIST), \
585*b9411a12SAndroid Build Coastguard Worker		$(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
586*b9411a12SAndroid Build Coastguard Worker		rm -f /util/$(tool)/junit.xml;)
587*b9411a12SAndroid Build Coastguard Worker
588*b9411a12SAndroid Build Coastguard Workerdistclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
589*b9411a12SAndroid Build Coastguard Worker	rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
590*b9411a12SAndroid Build Coastguard Worker	rm -rf coreboot-builds coreboot-builds-chromeos
591*b9411a12SAndroid Build Coastguard Worker	rm -f abuild*.xml junit.xml* util/lint/junit.xml
592*b9411a12SAndroid Build Coastguard Worker
593*b9411a12SAndroid Build Coastguard Worker.PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean sphinx sphinx-lint
594*b9411a12SAndroid Build Coastguard Worker.PHONY: ctags-project cscope-project clean-ctags
595*b9411a12SAndroid Build Coastguard Worker.PHONY: symlink clean-symlink cleanall-symlink
596