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