summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 4a87d2f54959395d6e05cf56e239d18f0710f2c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
## SPDX-License-Identifier: BSD-3-Clause

ifneq ($(words $(CURDIR)),1)
    $(error Error: Path to the main directory cannot contain spaces)
endif
top := $(CURDIR)
src := src
srck := $(top)/util/kconfig
obj ?= build
override obj := $(subst $(top)/,,$(abspath $(obj)))
xcompile ?= $(obj)/xcompile
objutil ?= $(obj)/util
objk := $(objutil)/kconfig
absobj := $(abspath $(obj))

additional-dirs :=

VBOOT_HOST_BUILD ?= $(abspath $(objutil)/vboot_lib)

COREBOOT_EXPORTS := COREBOOT_EXPORTS
COREBOOT_EXPORTS += top src srck obj objutil objk

DOTCONFIG ?= $(top)/.config
KCONFIG_CONFIG = $(DOTCONFIG)
KCONFIG_AUTOADS := $(obj)/cb-config.ads
KCONFIG_RUSTCCFG := $(obj)/cb-config.rustcfg
KCONFIG_AUTOHEADER := $(obj)/config.h
KCONFIG_AUTOCONFIG := $(obj)/auto.conf
KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
KCONFIG_SPLITCONFIG := $(obj)/config/
KCONFIG_TRISTATE := $(obj)/tristate.conf
KCONFIG_NEGATIVES := 1
KCONFIG_WERROR := 1
KCONFIG_WARN_UNKNOWN_SYMBOLS := 1
KCONFIG_PACKAGE := CB.Config
KCONFIG_MAKEFILE_REAL ?= $(objk)/Makefile.real

COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
COREBOOT_EXPORTS += KCONFIG_NEGATIVES
ifeq ($(filter %config,$(MAKECMDGOALS)),)
COREBOOT_EXPORTS += KCONFIG_WERROR
endif
COREBOOT_EXPORTS += KCONFIG_WARN_UNKNOWN_SYMBOLS
COREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE
COREBOOT_EXPORTS += KCONFIG_RUSTCCFG

# Make does not offer a recursive wildcard function, so here's one:
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
SYMLINK_LIST = $(call rwildcard,site-local/,symlink.txt)


# Directory containing the toplevel Makefile.mk
TOPLEVEL := .

CONFIG_SHELL := sh
KBUILD_DEFCONFIG := configs/defconfig
UNAME_RELEASE := $(shell uname -r)
HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
HAVE_KCONFIG_MAKEFILE_REAL := $(wildcard $(KCONFIG_MAKEFILE_REAL))
MAKEFLAGS += -rR --no-print-directory

# Make is silent per default, but 'make V=1' will show all compiler calls.
Q:=@
ifneq ($(V),1)
ifneq ($(Q),)
.SILENT:
MAKEFLAGS += -s
quiet_errors := 2>/dev/null
endif
endif

# Disable implicit/built-in rules to make Makefile errors fail fast.
.SUFFIXES:

HOSTCFLAGS := -g
HOSTCXXFLAGS := -g

HOSTPKG_CONFIG ?= pkg-config
COREBOOT_EXPORTS += HOSTPKG_CONFIG

PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .

export $(COREBOOT_EXPORTS)

all: real-all

help_coreboot help::
	@echo  '*** coreboot platform targets ***'
	@echo  '  Use "make [target] V=1" for extra build debug information'
	@echo  '  all                   - Build coreboot'
	@echo  '  clean                 - Remove coreboot build artifacts'
	@echo  '  distclean             - Remove build artifacts and config files'
	@echo  '  sphinx                - Build sphinx documentation for coreboot'
	@echo  '  sphinx-lint           - Build sphinx documentation for coreboot with warnings as errors'
	@echo  '  filelist              - Show files used in current build'
	@echo  '  printall              - print makefile info for debugging'
	@echo  '  gitconfig             - set up git to submit patches to coreboot'
	@echo  '  ctags / ctags-project - make ctags file for all of coreboot or current board'
	@echo  '  cscope / cscope-project - make cscope.out file for coreboot or current board'
	@echo

# This include must come _before_ the pattern rules below!
# Order _does_ matter for pattern rules.
include $(srck)/Makefile.mk

# The cases where we don't need fully populated $(obj) lists:
# 1. when no .config exists
# 2. When no $(obj)/util/kconfig/Makefile.real exists and we're building tools
# 3. when make config (in any flavour) is run
# 4. when make distclean is run
# Don't waste time on reading all Makefile.incs in these cases
ifeq ($(strip $(HAVE_DOTCONFIG)),)
NOCOMPILE:=1
endif
ifeq ($(strip $(HAVE_KCONFIG_MAKEFILE_REAL)),)
ifneq ($(MAKECMDGOALS),tools)
NOCOMPILE:=1
endif
endif
ifneq ($(MAKECMDGOALS),)
ifneq ($(filter %config %clean cross% clang iasl lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
NOCOMPILE:=1
endif
ifneq ($(filter %clean lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
NOMKDIR:=1
UNIT_TEST:=1
endif
endif

ifneq ($(filter help%, $(MAKECMDGOALS)), )
NOCOMPILE:=1
UNIT_TEST:=1
else
ifneq ($(filter %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
ifneq ($(filter-out %-test %-tests %coverage-report, $(MAKECMDGOALS)),)
$(error Cannot mix unit-tests targets with other targets)
endif
UNIT_TEST:=1
NOCOMPILE:=
endif
endif

$(xcompile): util/xcompile/xcompile
	rm -f $@
	$< $(XGCCPATH) > $@.tmp
	\mv -f $@.tmp $@ 2> /dev/null
	rm -f $@.tmp

ifeq ($(NOCOMPILE),1)
# We also don't use .xcompile in the no-compile situations, so
# provide some reasonable defaults.
HOSTCC ?= $(if $(shell type gcc 2>/dev/null),gcc,cc)
HOSTCXX ?= g++

include $(TOPLEVEL)/Makefile.mk
include $(TOPLEVEL)/payloads/Makefile.mk
include $(TOPLEVEL)/util/testing/Makefile.mk
-include $(TOPLEVEL)/site-local/Makefile.mk
-include $(TOPLEVEL)/site-local/Makefile.inc
include $(TOPLEVEL)/tests/Makefile.mk
printall real-all:
	@echo "Error: Trying to build, but NOCOMPILE is set." >&2
	@echo "  Please file a bug with the following information:"
	@echo "- MAKECMDGOALS: $(MAKECMDGOALS)" >&2
	@echo "- HAVE_DOTCONFIG: $(HAVE_DOTCONFIG)" >&2
	@echo "- HAVE_KCONFIG_MAKEFILE_REAL: $(HAVE_KCONFIG_MAKEFILE_REAL)" >&2
	@exit 1

else

ifneq ($(UNIT_TEST),1)
include $(DOTCONFIG)
endif

# The toolchain requires xcompile to determine the ARCH_SUPPORTED, so we can't
# wait for make to generate the file.
$(if $(wildcard $(xcompile)),, $(shell \
	mkdir -p $(dir $(xcompile)) && \
	util/xcompile/xcompile $(XGCCPATH) > $(xcompile) || rm -f $(xcompile)))

include $(xcompile)

ifneq ($(XCOMPILE_COMPLETE),1)
$(shell rm -f $(xcompile))
$(error $(xcompile) deleted because it's invalid. \
	Restarting the build should fix that, or explain the problem)
endif

# reproducible builds
LANG:=C
LC_ALL:=C
TZ:=UTC0
ifneq ($(NOCOMPILE),1)
SOURCE_DATE_EPOCH := $(shell $(top)/util/genbuild_h/genbuild_h.sh . | sed -n 's/^.define COREBOOT_BUILD_EPOCH\>.*"\(.*\)".*/\1/p')
endif
# don't use COREBOOT_EXPORTS to ensure build steps outside the coreboot build system
# are reproducible
export LANG LC_ALL TZ SOURCE_DATE_EPOCH

ifneq ($(UNIT_TEST),1)
include toolchain.mk
endif

strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
# fix makefile syntax highlighting after strip macro \" "))

ifneq ($(NOCOMPILE),1)
$(shell rm -f $(CCACHE_STATSLOG))
endif

# The primary target needs to be here before we include the
# other files

real-all: real-target

# must come rather early
.SECONDARY:
.SECONDEXPANSION:
.DELETE_ON_ERROR:

$(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
	$(MAKE) olddefconfig
	$(MAKE) syncconfig

$(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
	true

$(KCONFIG_AUTOADS): $(KCONFIG_CONFIG) $(KCONFIG_AUTOHEADER) $(objutil)/kconfig/toada
	$(objutil)/kconfig/toada CB.Config <$< >$@

$(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
	cp $< $@

# Add a new class of source/object files to the build system
add-class= \
	$(eval $(1)-srcs:=) \
	$(eval $(1)-objs:=) \
	$(eval classes+=$(1))

# Special classes are managed types with special behaviour
# On parse time, for each entry in variable $(1)-y
# a handler $(1)-handler is executed with the arguments:
# * $(1): directory the parser is in
# * $(2): current entry
add-special-class= \
	$(eval $(1):=) \
	$(eval special-classes+=$(1))

# Converts one or more source file paths to their corresponding build/ paths.
# Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
# their name.
# $1 stage name
# $2 file path (list)
src-to-obj=\
	$(patsubst $(obj)/%,$(obj)/$(1)/%,\
	$(patsubst $(obj)/$(1)/%,$(obj)/%,\
	$(patsubst 3rdparty/%,$(obj)/%,\
	$(patsubst src/%,$(obj)/%,\
	$(patsubst %.ads,%.o,\
	$(patsubst %.adb,%.o,\
	$(patsubst %.c,%.o,\
	$(patsubst %.S,%.o,\
	$(subst .$(1),,$(2))))))))))

# Converts one or more source file paths to the corresponding build/ paths
# of their Ada library information (.ali) files.
# $1 stage name
# $2 file path (list)
src-to-ali=\
	$(patsubst $(obj)/%,$(obj)/$(1)/%,\
	$(patsubst $(obj)/$(1)/%,$(obj)/%,\
	$(patsubst 3rdparty/%,$(obj)/%,\
	$(patsubst src/%,$(obj)/%,\
	$(patsubst %.ads,%.ali,\
	$(patsubst %.adb,%.ali,\
	$(subst .$(1),,\
	$(filter %.ads %.adb,$(2)))))))))

# Clean -y variables, include Makefile.mk & Makefile.inc
# Add paths to files in X-y to X-srcs
# Add subdirs-y to subdirs
includemakefiles= \
	$(if $(wildcard $(1)), \
		$(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
		$(eval -include $(1)) \
		$(foreach class,$(classes-y), $(call add-class,$(class))) \
		$(foreach special,$(special-classes), \
			$(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
		$(foreach class,$(classes), \
			$(eval $(class)-srcs+= \
				$$(subst $(absobj)/,$(obj)/, \
				$$(subst $(top)/,, \
				$$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
		$(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))))

# For each path in $(subdirs) call includemakefiles
# Repeat until subdirs is empty
# TODO: Remove Makefile.inc support
evaluate_subdirs= \
	$(eval cursubdirs:=$(subdirs)) \
	$(eval subdirs:=) \
	$(foreach dir,$(cursubdirs), \
		$(eval $(call includemakefiles,$(dir)/Makefile.mk))) \
	$(foreach dir,$(cursubdirs), \
		$(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
	$(if $(subdirs),$(eval $(call evaluate_subdirs)))

# collect all object files eligible for building
subdirs:=$(TOPLEVEL)
postinclude-hooks :=

# Don't iterate through Makefiles under src/ when building tests
ifneq ($(UNIT_TEST),1)
$(eval $(call evaluate_subdirs))
else
include $(TOPLEVEL)/tests/Makefile.mk
endif

ifeq ($(FAILBUILD),1)
$(error cannot continue build)
endif

# Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
$(eval $(postinclude-hooks))

# Eliminate duplicate mentions of source files in a class
$(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))

ifeq ($(CONFIG_IWYU),y)
MAKEFLAGS += -k
SAVE_IWYU_OUTPUT := 2>&1 | grep "should\|\#include\|---\|include-list\|^[[:blank:]]\?\'" | tee -a $$(obj)/iwyu.txt
endif

# Build Kconfig .ads if necessary
ifeq ($(CONFIG_ROMSTAGE_ADA),y)
romstage-srcs += $(obj)/romstage/$(notdir $(KCONFIG_AUTOADS))
endif
ifeq ($(CONFIG_RAMSTAGE_ADA),y)
ramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
endif

# To track dependencies, we need all Ada specification (.ads) files in
# *-srcs. Extract / filter all specification files that have a matching
# body (.adb) file here (specifications without a body are valid sources
# in Ada).
$(foreach class,$(classes),$(eval $(class)-extra-specs := \
	$(filter \
		$(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
		$(filter %.ads,$($(class)-srcs)))))
$(foreach class,$(classes),$(eval $(class)-srcs := \
	$(filter-out $($(class)-extra-specs),$($(class)-srcs))))

$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
$(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))

# For Ada includes
$(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))

# Save all objs before processing them (for dependency inclusion)
originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))

# Call post-processors if they're defined
$(foreach class,$(classes),\
	$(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))

allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
alldirs:=$(sort $(abspath $(dir $(allobjs))))

# Reads dependencies from an Ada library information (.ali) file
# Only basenames (with suffix) are preserved so we have to look the
# paths up in $($(stage)-srcs).
# $1 stage name
# $2 ali file
create_ada_deps=$$(if $(2),\
	gnat.adc \
	$$(filter \
		$$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
		$$($(1)-srcs) $$($(1)-extra-specs)))

# macro to define template macros that are used by use_template macro
define create_cc_template
# $1 obj class
# $2 source suffix (c, S, ld, ...)
# $3 additional compiler flags
# $4 additional dependencies
ifn$(EMPTY)def $(1)-objs_$(2)_template
de$(EMPTY)fine $(1)-objs_$(2)_template
ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $$(call create_ada_deps,$1,$$(call src-to-ali,$1,$$(1).$2)) $(4)
	@printf "    GCC        $$$$(subst $$$$(obj)/,,$$$$(@))\n"
	$(GCC_$(1)) \
		$$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
		$(3) -c -o $$$$@ $$$$<
el$(EMPTY)se
$$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
	@printf "    CC         $$$$(subst $$$$(obj)/,,$$$$(@))\n"
	$(CC_$(1)) \
		-MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
		$(3) -c -o $$$$@ $$$$< $(SAVE_IWYU_OUTPUT)
end$(EMPTY)if
en$(EMPTY)def
end$(EMPTY)if
endef

filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
$(foreach class,$(classes), \
	$(foreach type,$(call filetypes-of-class,$(class)), \
		$(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
		$(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
		$(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))

foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))

# To supported complex package initializations, we need to call the
# emitted code explicitly. gnatbind gathers all the calls for us
# and exports them as a procedure $(stage)_adainit(). Every stage that
# uses Ada code has to call it!
define gnatbind_template
# $1 class
$$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
	@printf "    BIND       $$(subst $$(obj)/,,$$@)\n"
	# We have to give gnatbind a simple filename (without leading
	# path components) so just cd there.
	cd $$(dir $$@) && \
		$$(GNATBIND_$(1)) -a -n \
			--RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
			-L$(1)_ada -o $$(notdir $$@) \
			$$(subst $$(dir $$@),,$$^)
$$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
	@printf "    GCC        $$(subst $$(obj)/,,$$@)\n"
	$(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
$(1)-objs += $$(obj)/$(1)/b__$(1).o
$($(1)-alis): %.ali: %.o ;
endef

$(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
	$(if $($(class)-alis),$(call gnatbind_template,$(class)))))

DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
-include $(DEPENDENCIES)

printall:
	@$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
	@echo alldirs: $(alldirs) | tr ' ' '\n'; echo
	@echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
	@echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
	@$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
endif

ifndef NOMKDIR
$(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
endif

$(obj)/project_filelist.txt:
	if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
		echo "*** Error: Project must be built before generating file list ***"; \
		exit 1; \
	fi
	find $(obj) -path "$(obj)/util" -prune -o -path "$(obj)/external" -prune -o -name "*.d" -exec cat {} \; | \
	  sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
	  grep -v '\.o$$' > $(obj)/project_filelist.txt

filelist: $(obj)/project_filelist.txt
	printf "\nFiles used in build:\n"
	cat $(obj)/project_filelist.txt

#works with either exuberant ctags or ctags.emacs
ctags-project: clean-ctags $(obj)/project_filelist.txt
	cat $(obj)/project_filelist.txt | \
	  xargs ctags -o tags

cscope-project: clean-cscope $(obj)/project_filelist.txt
	cat $(obj)/project_filelist.txt | xargs cscope -b

cscope:
	cscope -bR

sphinx:
	$(MAKE) -C Documentation sphinx

sphinx-lint:
	$(MAKE) SPHINXOPTS=-W -C Documentation sphinx

symlink:
	@echo "Creating Symbolic Links.."; \
	for link in $(SYMLINK_LIST); do \
		SYMLINK=`cat $$link`; \
		REALPATH=`realpath $$link`; \
		if [ -L "$$SYMLINK" ]; then \
			continue; \
		elif [ ! -e "$$SYMLINK" ]; then \
			echo -e "\tLINK $$SYMLINK -> $$(dirname $$REALPATH)"; \
			ln -s $$(dirname $$REALPATH) $$SYMLINK; \
		else \
			echo -e "\tFAILED: $$SYMLINK exists"; \
		fi \
	done

clean-symlink:
	@echo "Deleting symbolic link";\
	EXISTING_SYMLINKS=`find -L ./src -xtype l | grep -v 3rdparty`; \
	for link in $$EXISTING_SYMLINKS; do \
		echo -e "\tUNLINK $$link"; \
		rm "$$link"; \
	done

clean-for-update:
	rm -rf $(obj) .xcompile

clean: clean-for-update clean-utils clean-payloads
	rm -f .ccwrap

clean-cscope:
	rm -f cscope.out

clean-ctags:
	rm -f tags

clean-utils:
	$(foreach tool, $(TOOLLIST), \
		$(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)

distclean-utils:
	$(foreach tool, $(TOOLLIST), \
		$(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
		rm -f /util/$(tool)/junit.xml;)

distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
	rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
	rm -rf coreboot-builds coreboot-builds-chromeos
	rm -f abuild*.xml junit.xml* util/lint/junit.xml

.PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean sphinx sphinx-lint
.PHONY: ctags-project cscope-project clean-ctags symlink clean-symlink